From dbf0d6d35c74f7c21f7b496afd58f107c71b5547 Mon Sep 17 00:00:00 2001 From: androidacy-user Date: Mon, 19 Dec 2022 12:18:11 -0500 Subject: [PATCH] Work on Sentry, fix some crashing Signed-off-by: androidacy-user --- app/build.gradle | 23 ++----------- app/src/main/AndroidManifest.xml | 33 +++++++++++++++++++ .../com/fox2code/mmm/MainApplication.java | 11 ++++--- .../mmm/installer/InstallerActivity.java | 4 +-- .../mmm/settings/SettingsActivity.java | 2 +- .../fox2code/mmm/utils}/SentryBreadcrumb.java | 4 +-- .../com/fox2code/mmm/utils}/SentryMain.java | 13 +++++--- app/src/main/res/layout/activity_main.xml | 1 + app/src/main/res/layout/module_entry.xml | 23 ++++++------- 9 files changed, 69 insertions(+), 45 deletions(-) rename app/src/{sentry/java/com/fox2code/mmm/sentry => main/java/com/fox2code/mmm/utils}/SentryBreadcrumb.java (90%) rename app/src/{sentry/java/com/fox2code/mmm/sentry => main/java/com/fox2code/mmm/utils}/SentryMain.java (87%) diff --git a/app/build.gradle b/app/build.gradle index f188139..4997317 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,8 +31,8 @@ android { applicationId "com.fox2code.mmm" minSdk 23 targetSdk 33 - versionCode 63 - versionName "1.0.3" + versionCode 64 + versionName "1.1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" signingConfig signingConfigs.release archivesBaseName = "FoxMMM-v$versionName" @@ -251,7 +251,6 @@ dependencies { implementation 'androidx.work:work-runtime:2.7.1' implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.10' implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:5.0.0-alpha.10' - implementation 'com.squareup.okhttp3:okhttp-brotli:5.0.0-alpha.10' // Chromium cronet from androidacy implementation 'com.androidacy:cronet-common:108.0.5359.125' implementation 'com.androidacy:cronet-native:108.0.5359.125' @@ -292,25 +291,7 @@ if (hasSentryConfig) { } } -final String sentrySrc = hasSentryConfig ? 'src/sentry/java' : 'src/sentryless/java' -final String sentryManifestSrc = hasSentryConfig ? 'src/sentry/AndroidManifest.xml' : 'src/sentryless/AndroidManifest.xml' - android { - sourceSets { - main { - java.srcDirs += sentrySrc - // manifest.srcFile += sentryManifestSrc // Not supported - } - - // Workaround useless gradle restriction - "default" { - manifest.srcFile sentryManifestSrc - } - - fdroid { - manifest.srcFile sentryManifestSrc - } - } ndkVersion '25.1.8937393' dependenciesInfo { includeInApk false diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5c61a76..134a051 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -3,6 +3,8 @@ xmlns:tools="http://schemas.android.com/tools" tools:ignore="QueryAllPackagesPermission"> + + @@ -122,5 +124,36 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/shared_file_paths" /> + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/fox2code/mmm/MainApplication.java b/app/src/main/java/com/fox2code/mmm/MainApplication.java index cde5881..2fe8227 100644 --- a/app/src/main/java/com/fox2code/mmm/MainApplication.java +++ b/app/src/main/java/com/fox2code/mmm/MainApplication.java @@ -25,9 +25,9 @@ import com.fox2code.foxcompat.FoxApplication; import com.fox2code.foxcompat.FoxThemeWrapper; import com.fox2code.foxcompat.internal.FoxProcessExt; import com.fox2code.mmm.installer.InstallerInitializer; -import com.fox2code.mmm.sentry.SentryMain; import com.fox2code.mmm.utils.GMSProviderInstaller; import com.fox2code.mmm.utils.Http; +import com.fox2code.mmm.utils.SentryMain; import com.fox2code.rosettax.LanguageSwitcher; import com.topjohnwu.superuser.Shell; @@ -138,7 +138,7 @@ public class MainApplication extends FoxApplication implements androidx.work.Con } public static boolean isBlurEnabled() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && getSharedPreferences().getBoolean("pref_enable_blur", false); + return getSharedPreferences().getBoolean("pref_enable_blur", false); } public static boolean isDeveloper() { @@ -313,13 +313,14 @@ public class MainApplication extends FoxApplication implements androidx.work.Con } SentryMain.initialize(this); if (Objects.equals(BuildConfig.ANDROIDACY_CLIENT_ID, "")) { - Log.w("MainApplication", "Androidacy client id is empty! Please set it in androidacy" + ".properties. Will not enable Androidacy."); + Log.w("MainApplication", "Androidacy client id is empty! Please set it in androidacy.properties. Will not enable Androidacy."); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putBoolean("pref_androidacy_repo_enabled", false); editor.apply(); } } + @SuppressWarnings("unused") private Intent getIntent() { return this.getPackageManager().getLaunchIntentForPackage(this.getPackageName()); } @@ -363,7 +364,9 @@ public class MainApplication extends FoxApplication implements androidx.work.Con for (String s : children) { if (BuildConfig.DEBUG) Log.w("MainApplication", "Deleting " + s); if (!s.equals("lib")) { - new File(cacheDir, s).delete(); + if (!new File(cacheDir, s).delete()) { + if (BuildConfig.DEBUG) Log.w("MainApplication", "Failed to delete " + s); + } } } } diff --git a/app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java b/app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java index 40ac127..07cd4b7 100644 --- a/app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java +++ b/app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java @@ -26,14 +26,14 @@ import com.fox2code.mmm.R; import com.fox2code.mmm.XHooks; import com.fox2code.mmm.androidacy.AndroidacyUtil; import com.fox2code.mmm.module.ActionButtonType; -import com.fox2code.mmm.sentry.SentryBreadcrumb; -import com.fox2code.mmm.sentry.SentryMain; import com.fox2code.mmm.utils.FastException; import com.fox2code.mmm.utils.Files; import com.fox2code.mmm.utils.Hashes; import com.fox2code.mmm.utils.Http; import com.fox2code.mmm.utils.IntentHelper; import com.fox2code.mmm.utils.PropUtils; +import com.fox2code.mmm.utils.SentryBreadcrumb; +import com.fox2code.mmm.utils.SentryMain; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton; import com.google.android.material.progressindicator.LinearProgressIndicator; 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 a72f1af..0ed1f7b 100644 --- a/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java +++ b/app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java @@ -59,11 +59,11 @@ import com.fox2code.mmm.repo.CustomRepoData; import com.fox2code.mmm.repo.CustomRepoManager; import com.fox2code.mmm.repo.RepoData; import com.fox2code.mmm.repo.RepoManager; -import com.fox2code.mmm.sentry.SentryMain; import com.fox2code.mmm.utils.ExternalHelper; import com.fox2code.mmm.utils.Http; import com.fox2code.mmm.utils.IntentHelper; import com.fox2code.mmm.utils.ProcessHelper; +import com.fox2code.mmm.utils.SentryMain; import com.fox2code.rosettax.LanguageActivity; import com.fox2code.rosettax.LanguageSwitcher; import com.google.android.material.dialog.MaterialAlertDialogBuilder; diff --git a/app/src/sentry/java/com/fox2code/mmm/sentry/SentryBreadcrumb.java b/app/src/main/java/com/fox2code/mmm/utils/SentryBreadcrumb.java similarity index 90% rename from app/src/sentry/java/com/fox2code/mmm/sentry/SentryBreadcrumb.java rename to app/src/main/java/com/fox2code/mmm/utils/SentryBreadcrumb.java index 623aaa2..53e04f5 100644 --- a/app/src/sentry/java/com/fox2code/mmm/sentry/SentryBreadcrumb.java +++ b/app/src/main/java/com/fox2code/mmm/utils/SentryBreadcrumb.java @@ -1,4 +1,4 @@ -package com.fox2code.mmm.sentry; +package com.fox2code.mmm.utils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -9,7 +9,7 @@ import io.sentry.Breadcrumb; import io.sentry.SentryLevel; public class SentryBreadcrumb { - final Breadcrumb breadcrumb; + public final Breadcrumb breadcrumb; public SentryBreadcrumb() { breadcrumb = new Breadcrumb(); diff --git a/app/src/sentry/java/com/fox2code/mmm/sentry/SentryMain.java b/app/src/main/java/com/fox2code/mmm/utils/SentryMain.java similarity index 87% rename from app/src/sentry/java/com/fox2code/mmm/sentry/SentryMain.java rename to app/src/main/java/com/fox2code/mmm/utils/SentryMain.java index 30c390f..316d501 100644 --- a/app/src/sentry/java/com/fox2code/mmm/sentry/SentryMain.java +++ b/app/src/main/java/com/fox2code/mmm/utils/SentryMain.java @@ -1,4 +1,4 @@ -package com.fox2code.mmm.sentry; +package com.fox2code.mmm.utils; import android.annotation.SuppressLint; import android.content.Context; @@ -25,6 +25,11 @@ public class SentryMain { */ @SuppressLint({"RestrictedApi", "UnspecifiedImmutableFlag"}) public static void initialize(final MainApplication mainApplication) { + // If first_launch pref is not false, refuse to initialize Sentry + SharedPreferences sharedPreferences = MainApplication.getSharedPreferences(); + if (sharedPreferences.getBoolean("first_launch", true)) { + return; + } Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> { SharedPreferences.Editor editor = mainApplication.getSharedPreferences("sentry", Context.MODE_PRIVATE).edit(); editor.putString("lastExitReason", "crash"); @@ -58,9 +63,9 @@ public class SentryMain { // With this callback, you can modify the event or, when returning null, also discard the event. options.setBeforeSend((event, hint) -> { // Save lastEventId to private shared preferences - SharedPreferences sharedPreferences = MainApplication.getINSTANCE().getSharedPreferences("sentry", Context.MODE_PRIVATE); + SharedPreferences sentryPrefs = MainApplication.getINSTANCE().getSharedPreferences("sentry", Context.MODE_PRIVATE); String lastEventId = Objects.requireNonNull(event.getEventId()).toString(); - SharedPreferences.Editor editor = sharedPreferences.edit(); + SharedPreferences.Editor editor = sentryPrefs.edit(); editor.putString("lastEventId", lastEventId); editor.apply(); return event; @@ -79,7 +84,7 @@ public class SentryMain { }); } - public static void addSentryBreadcrumb(SentryBreadcrumb sentryBreadcrumb) { + public static void addSentryBreadcrumb(com.fox2code.mmm.utils.SentryBreadcrumb sentryBreadcrumb) { if (MainApplication.isCrashReportingEnabled()) { Sentry.addBreadcrumb(sentryBreadcrumb.breadcrumb); } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 2b43e94..660d5a7 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -69,6 +69,7 @@ android:layout_marginRight="12dp" android:layout_marginBottom="8dp" android:gravity="right" + android:filterTouchesWhenObscured="true" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_fitsSystemWindowsInsets="bottom" diff --git a/app/src/main/res/layout/module_entry.xml b/app/src/main/res/layout/module_entry.xml index 84eada8..7ff8527 100644 --- a/app/src/main/res/layout/module_entry.xml +++ b/app/src/main/res/layout/module_entry.xml @@ -1,16 +1,17 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginLeft="8dp" + android:layout_marginTop="2dp" + android:layout_marginRight="8dp" + android:layout_marginBottom="2dp" + android:filterTouchesWhenObscured="true" + android:gravity="center_vertical" + android:orientation="vertical" + tools:ignore="RtlHardcoded,RtlSymmetry">