From 9ac56c371b42deba10d47c24e894870dcb566b45 Mon Sep 17 00:00:00 2001 From: androidacy-user Date: Thu, 23 Mar 2023 21:29:31 -0400 Subject: [PATCH] rework ui a bit Signed-off-by: androidacy-user --- app/build.gradle | 12 +- .../com/fox2code/mmm/repo/CustomRepoData.java | 3 +- .../fox2code/mmm/repo/CustomRepoManager.java | 51 +++- .../mmm/settings/SettingsActivity.java | 5 +- .../com/fox2code/mmm/utils/io/Hashes.java | 20 +- .../com/fox2code/mmm/utils/io/net/Http.java | 26 +- app/src/main/res/layout/activity_setup.xml | 245 +++++++++++++++++- app/src/main/res/layout/content_scrolling.xml | 236 ----------------- app/src/main/res/values/strings.xml | 1 + build.gradle | 1 + gradle/wrapper/gradle-wrapper.properties | 2 +- 11 files changed, 331 insertions(+), 271 deletions(-) delete mode 100644 app/src/main/res/layout/content_scrolling.xml diff --git a/app/build.gradle b/app/build.gradle index 8bbd4cd..e1a4557 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -66,6 +66,7 @@ android { vectorDrawables { useSupportLibrary true } + multiDexEnabled true } splits { @@ -110,7 +111,6 @@ android { } } - //noinspection GrDeprecatedAPIUsage flavorDimensions "type" productFlavors { "default" { @@ -138,6 +138,7 @@ android { buildConfigField "String", "SENTRY_TOKEN", '""' } // Get the androidacy client ID from the androidacy.properties + Properties properties = new Properties() // If androidacy.properties doesn't exist, use the default client ID which is heavily // rate limited to 30 requests per minute @@ -146,7 +147,7 @@ android { } else { properties.setProperty('client_id', '"5KYccdYxWB2RxMq5FTbkWisXi2dS6yFN9R7RVlFCG98FRdz6Mf5ojY2fyJCUlXJZ"') } - buildConfigField("String", "ANDROIDACY_CLIENT_ID", properties.getProperty('client_id')) + buildConfigField("String", "ANDROIDACY_CLIENT_ID", "\"" + properties.getProperty('client_id') + "\"") // If client ID is empty, disable androidacy if (properties.getProperty('client_id').isEmpty()) { buildConfigField("java.util.List", @@ -314,11 +315,13 @@ dependencies { implementation 'androidx.work:work-runtime:2.8.0' implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.10' implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:5.0.0-alpha.10' + // logging interceptor + implementation 'com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.10' // Chromium cronet from androidacy implementation 'com.androidacy:cronet-common:111.0.5563.75' implementation 'com.androidacy:cronet-native:111.0.5563.75' implementation 'com.androidacy:cronet-api:111.0.5563.75' - // protobuf - fixes a crash on some devicesa + // protobuf - fixes a crash on some devices implementation 'com.google.protobuf:protobuf-javalite:3.22.2' implementation 'com.github.topjohnwu.libsu:io:5.0.1' @@ -377,13 +380,14 @@ android { } buildFeatures { viewBinding true + buildConfig true } kotlinOptions { jvmTarget = JavaVersion.VERSION_17 } //noinspection GrDeprecatedAPIUsage - buildToolsVersion '33.0.2' + buildToolsVersion '34.0.0 rc2' } diff --git a/app/src/main/java/com/fox2code/mmm/repo/CustomRepoData.java b/app/src/main/java/com/fox2code/mmm/repo/CustomRepoData.java index 00f4762..1b40536 100644 --- a/app/src/main/java/com/fox2code/mmm/repo/CustomRepoData.java +++ b/app/src/main/java/com/fox2code/mmm/repo/CustomRepoData.java @@ -10,7 +10,6 @@ import org.json.JSONObject; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.security.NoSuchAlgorithmException; public final class CustomRepoData extends RepoData { boolean loadedExternal; @@ -31,7 +30,7 @@ public final class CustomRepoData extends RepoData { this.id : this.override; } - public void quickPrePopulate() throws IOException, JSONException, NoSuchAlgorithmException { + public void quickPrePopulate() throws IOException, JSONException { JSONObject jsonObject = new JSONObject( new String(Http.doHttpGet(this.getUrl(), false), StandardCharsets.UTF_8)); diff --git a/app/src/main/java/com/fox2code/mmm/repo/CustomRepoManager.java b/app/src/main/java/com/fox2code/mmm/repo/CustomRepoManager.java index 64a2aea..d087e6e 100644 --- a/app/src/main/java/com/fox2code/mmm/repo/CustomRepoManager.java +++ b/app/src/main/java/com/fox2code/mmm/repo/CustomRepoManager.java @@ -4,6 +4,11 @@ import android.content.SharedPreferences; import com.fox2code.mmm.MainApplication; import com.fox2code.mmm.utils.io.PropUtils; +import com.fox2code.mmm.utils.realm.ReposList; + +import io.realm.Realm; +import io.realm.RealmConfiguration; +import timber.log.Timber; public class CustomRepoManager { public static final int MAX_CUSTOM_REPOS = 5; @@ -21,7 +26,19 @@ public class CustomRepoManager { SharedPreferences sharedPreferences = this.getSharedPreferences(); int lastFilled = 0; for (int i = 0; i < MAX_CUSTOM_REPOS; i++) { - String repo = sharedPreferences.getString("repo_" + i, ""); + RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().name("ReposList.realm").allowQueriesOnUiThread(true).allowWritesOnUiThread(true).directory(MainApplication.getINSTANCE().getDataDirWithPath("realms")).schemaVersion(1).build(); + Realm realm = Realm.getInstance(realmConfiguration); + try { + realm.beginTransaction(); + } catch (IllegalStateException e) { + Timber.w(e, "Failed to begin transaction"); + } + // find the matching entry for repo_0, repo_1, etc. + ReposList reposList = realm.where(ReposList.class).equalTo("id", "repo_" + i).findFirst(); + if (reposList == null) { + continue; + } + String repo = reposList.getUrl(); if (!PropUtils.isNullString(repo) && !RepoManager.isBuiltInRepo(repo)) { lastFilled = i; int index = AUTO_RECOMPILE ? @@ -33,12 +50,23 @@ public class CustomRepoManager { } } if (AUTO_RECOMPILE && (lastFilled + 1) != this.customReposCount) { - SharedPreferences.Editor editor = sharedPreferences.edit().clear(); + RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().name("ReposList.realm").allowQueriesOnUiThread(true).allowWritesOnUiThread(true).directory(MainApplication.getINSTANCE().getDataDirWithPath("realms")).schemaVersion(1).build(); + Realm realm = Realm.getInstance(realmConfiguration); + try { + realm.beginTransaction(); + } catch (IllegalStateException e) { + Timber.w(e, "Failed to begin transaction"); + } for (int i = 0; i < MAX_CUSTOM_REPOS; i++) { - if (this.customRepos[i] != null) - editor.putString("repo_" + i, this.customRepos[i]); + if (this.customRepos[i] != null) { + // find the matching entry for repo_0, repo_1, etc. + ReposList reposList = realm.where(ReposList.class).equalTo("id", "repo_" + i).findFirst(); + if (reposList == null) { + continue; + } + reposList.setUrl(this.customRepos[i]); + } } - editor.apply(); } } @@ -57,8 +85,17 @@ public class CustomRepoManager { int i = 0; while (customRepos[i] != null) i++; customRepos[i] = repo; - this.getSharedPreferences().edit() - .putString("repo_" + i, repo).apply(); + RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().name("ReposList.realm").allowQueriesOnUiThread(true).allowWritesOnUiThread(true).directory(MainApplication.getINSTANCE().getDataDirWithPath("realms")).schemaVersion(1).build(); + Realm realm = Realm.getInstance(realmConfiguration); + realm.beginTransaction(); + // find the matching entry for repo_0, repo_1, etc. + ReposList reposList = realm.where(ReposList.class).equalTo("id", "repo_" + i).findFirst(); + if (reposList == null) { + reposList = realm.createObject(ReposList.class, "repo_" + i); + } + reposList.setUrl(repo); + realm.commitTransaction(); + customReposCount++; this.dirty = true; CustomRepoData customRepoData = (CustomRepoData) this.repoManager.addOrGet(repo); diff --git a/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java b/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java index 92fb851..a83af8b 100644 --- a/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java +++ b/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java @@ -428,7 +428,7 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity { debugNotification.setEnabled(MainApplication.isBackgroundUpdateCheckEnabled()); debugNotification.setVisible(MainApplication.isDeveloper() && !MainApplication.isWrapped() && MainApplication.isBackgroundUpdateCheckEnabled()); debugNotification.setOnPreferenceClickListener(preference -> { - // fake updateable modules hashmap + // fake updatable modules hashmap HashMap updateableModules = new HashMap<>(); // count of modules to fake must match the count in the random number generator Random random = new Random(); @@ -797,7 +797,8 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity { @SuppressLint({"RestrictedApi", "UnspecifiedImmutableFlag"}) public void onCreatePreferencesAndroidacy() { // Bind the pref_show_captcha_webview to captchaWebview('https://production-api.androidacy.com/') - // Also require dev modeowCaptchaWebview.setVisible(false); + // Also require dev mode + // CaptchaWebview.setVisible(false); Preference androidacyTestMode = Objects.requireNonNull(findPreference("pref_androidacy_test_mode")); if (!MainApplication.isDeveloper()) { androidacyTestMode.setVisible(false); diff --git a/app/src/main/java/com/fox2code/mmm/utils/io/Hashes.java b/app/src/main/java/com/fox2code/mmm/utils/io/Hashes.java index 5da5af6..1c40abe 100644 --- a/app/src/main/java/com/fox2code/mmm/utils/io/Hashes.java +++ b/app/src/main/java/com/fox2code/mmm/utils/io/Hashes.java @@ -111,19 +111,13 @@ public enum Hashes { public static String checkSumName(String checksum) { if (checksum == null) return null; - switch (checksum.length()) { - case 0: - default: - return null; - case 32: - return "MD5"; - case 40: - return "SHA-1"; - case 64: - return "SHA-256"; - case 128: - return "SHA-512"; - } + return switch (checksum.length()) { + default -> null; + case 32 -> "MD5"; + case 40 -> "SHA-1"; + case 64 -> "SHA-256"; + case 128 -> "SHA-512"; + }; } public static String checkSumFormat(String checksum) { diff --git a/app/src/main/java/com/fox2code/mmm/utils/io/net/Http.java b/app/src/main/java/com/fox2code/mmm/utils/io/net/Http.java index 2eb8b9b..3dc1676 100644 --- a/app/src/main/java/com/fox2code/mmm/utils/io/net/Http.java +++ b/app/src/main/java/com/fox2code/mmm/utils/io/net/Http.java @@ -52,6 +52,7 @@ import okhttp3.RequestBody; import okhttp3.Response; import okhttp3.ResponseBody; import okhttp3.dnsoverhttps.DnsOverHttps; +import okhttp3.logging.HttpLoggingInterceptor; import okio.BufferedSink; import timber.log.Timber; @@ -140,8 +141,29 @@ public enum Http { request.header("Accept-Language", // Send system language to the server mainApplication.getResources().getConfiguration().getLocales().get(0).toLanguageTag()); } + // add client hints + request.header("Sec-CH-UA", androidacyUA); + request.header("Sec-CH-UA-Mobile", "?1"); + request.header("Sec-CH-UA-Platform", "Android"); + request.header("Sec-CH-UA-Platform-Version", Build.VERSION.RELEASE); + request.header("Sec-CH-UA-Arch", Build.SUPPORTED_ABIS[0]); + request.header("Sec-CH-UA-Full-Version", BuildConfig.VERSION_NAME); + request.header("Sec-CH-UA-Model", Build.DEVICE); + request.header("Sec-CH-UA-Bitness", Build.SUPPORTED_64_BIT_ABIS.length > 0 ? "64" : "32"); return chain.proceed(request.build()); }); + // add sentry interceptor + if (MainApplication.isCrashReportingEnabled()) { + httpclientBuilder.addInterceptor(new SentryOkHttpInterceptor()); + } + + // for debug builds, add a logging interceptor + if (BuildConfig.DEBUG) { + HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); + loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); + httpclientBuilder.addInterceptor(loggingInterceptor); + } + // Add cronet interceptor // init cronet try { @@ -173,10 +195,6 @@ public enum Http { Timber.e(e, "Failed to init cronet"); // Gracefully fallback to okhttp } - // add sentry interceptor - if (MainApplication.isCrashReportingEnabled()) { - httpclientBuilder.addInterceptor(new SentryOkHttpInterceptor()); - } // Fallback DNS cache responses in case request fail but already succeeded once in the past fallbackDNS = new FallBackDNS(mainApplication, dns, "github.com", "api.github.com", "raw.githubusercontent.com", "camo.githubusercontent.com", "user-images.githubusercontent.com", "cdn.jsdelivr.net", "img.shields.io", "magisk-modules-repo.github.io", "www.androidacy.com", "api.androidacy.com", "production-api.androidacy.com"); httpclientBuilder.dns(Dns.SYSTEM); diff --git a/app/src/main/res/layout/activity_setup.xml b/app/src/main/res/layout/activity_setup.xml index bacde20..8930210 100644 --- a/app/src/main/res/layout/activity_setup.xml +++ b/app/src/main/res/layout/activity_setup.xml @@ -5,10 +5,251 @@ xmlns:tools="http://schemas.android.com/tools" android:id="@+id/setup_box" android:layout_width="match_parent" + android:paddingVertical="0dp" android:layout_height="match_parent" - app:fitsSystemWindowsInsets="left|right" + app:fitsSystemWindowsInsets="start|end|bottom|top" tools:context=".SetupActivity"> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/content_scrolling.xml b/app/src/main/res/layout/content_scrolling.xml deleted file mode 100644 index aad5a1b..0000000 --- a/app/src/main/res/layout/content_scrolling.xml +++ /dev/null @@ -1,236 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e21f47e..a9c20fd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -379,4 +379,5 @@ Update checks Require wifi for update checks Require wifi or an otherwise unmetered connection to do update checks + Allow app analytics diff --git a/build.gradle b/build.gradle index 1f0d93d..42d8137 100644 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,7 @@ buildscript { project.ext.kotlin_version = "1.8.0" project.ext.sentry_version = "6.16.0" dependencies { + //noinspection AndroidGradlePluginVersion classpath 'com.android.tools.build:gradle:7.4.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10" classpath "com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:${latestAboutLibsRelease}" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2e5f7c7..812cf6a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Sun Jun 05 10:40:53 EDT 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME \ No newline at end of file