From e5b839b82354f8f62fe1a4e67276511626ba37fd Mon Sep 17 00:00:00 2001 From: androidacy-user Date: Thu, 29 Jun 2023 21:45:47 -0400 Subject: [PATCH] fix a crash or two can't catch em all Signed-off-by: androidacy-user --- app/build.gradle.kts | 5 +- .../kotlin/com/fox2code/mmm/CrashHandler.kt | 35 +++++------- .../mmm/installer/InstallerInitializer.kt | 9 ++- .../fox2code/mmm/module/ActionButtonType.kt | 55 +++++++++++++------ .../com/fox2code/mmm/repo/RepoManager.kt | 4 +- .../fox2code/mmm/utils/sentry/SentryMain.kt | 3 +- app/src/main/res/values/strings.xml | 1 + build.gradle.kts | 9 +-- 8 files changed, 68 insertions(+), 53 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e168c45..75afeb4 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -53,8 +53,8 @@ android { applicationId = "com.fox2code.mmm" minSdk = 24 targetSdk = 33 - versionCode = 78 - versionName = "2.2.1" + versionCode = 79 + versionName = "2.2.2" vectorDrawables { useSupportLibrary = true } @@ -118,6 +118,7 @@ android { ) renderscriptOptimLevel = 3 signingConfig = signingConfigs.getByName("release") + multiDexEnabled = true } getByName("debug") { applicationIdSuffix = ".debug" diff --git a/app/src/main/kotlin/com/fox2code/mmm/CrashHandler.kt b/app/src/main/kotlin/com/fox2code/mmm/CrashHandler.kt index 57a1902..99efc43 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/CrashHandler.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/CrashHandler.kt @@ -17,6 +17,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.textview.MaterialTextView import io.sentry.Sentry import io.sentry.UserFeedback +import io.sentry.protocol.SentryId import timber.log.Timber import java.io.PrintWriter import java.io.StringWriter @@ -84,20 +85,18 @@ class CrashHandler : FoxActivity() { val emailString = arrayOf(if (email.text.toString() == "") "Anonymous" else email.text.toString()) // get sentryException passed in intent - val sentryException = intent.getSerializableExtra("sentryException") as Throwable? + @Suppress("NAME_SHADOWING") val lastEventId = Sentry.getLastEventId() Thread { try { - val userFeedback: UserFeedback - if (sentryException != null) { - userFeedback = UserFeedback(Sentry.captureException(sentryException)) - // Setups the JSON body - if (nameString[0] == "") nameString[0] = "Anonymous" - if (emailString[0] == "") emailString[0] = "Anonymous" - userFeedback.name = nameString[0] - userFeedback.email = emailString[0] - userFeedback.comments = description.text.toString() - Sentry.captureUserFeedback(userFeedback) - } + val userFeedback = + UserFeedback(SentryId(lastEventId.toString())) + // Setups the JSON body + if (nameString[0] == "") nameString[0] = "Anonymous" + if (emailString[0] == "") emailString[0] = "Anonymous" + userFeedback.name = nameString[0] + userFeedback.email = emailString[0] + userFeedback.comments = description.text.toString() + Sentry.captureUserFeedback(userFeedback) Timber.i( "Submitted user feedback: name %s email %s comment %s", nameString[0], @@ -106,9 +105,7 @@ class CrashHandler : FoxActivity() { ) runOnUiThread { Toast.makeText( - this, - R.string.sentry_dialogue_success, - Toast.LENGTH_LONG + this, R.string.sentry_dialogue_success, Toast.LENGTH_LONG ).show() } // Close the activity @@ -120,9 +117,7 @@ class CrashHandler : FoxActivity() { // Show a toast if the user feedback could not be submitted runOnUiThread { Toast.makeText( - this, - R.string.sentry_dialogue_failed_toast, - Toast.LENGTH_LONG + this, R.string.sentry_dialogue_failed_toast, Toast.LENGTH_LONG ).show() } } @@ -151,9 +146,7 @@ class CrashHandler : FoxActivity() { (findViewById(R.id.feedback_text) as MaterialTextView).setText(R.string.sentry_enable_nag) findViewById(R.id.feedback_submit).setOnClickListener { _: View? -> Toast.makeText( - this, - R.string.sentry_dialogue_disabled, - Toast.LENGTH_LONG + this, R.string.sentry_dialogue_disabled, Toast.LENGTH_LONG ).show() } // handle restart button diff --git a/app/src/main/kotlin/com/fox2code/mmm/installer/InstallerInitializer.kt b/app/src/main/kotlin/com/fox2code/mmm/installer/InstallerInitializer.kt index 886812e..f34d834 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/installer/InstallerInitializer.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/installer/InstallerInitializer.kt @@ -68,7 +68,6 @@ class InstallerInitializer : Shell.Initializer() { /** * Note: Used to detect which modules are currently loaded. * - * * For read/write only "/data/adb/modules" should be used */ fun peekModulesPath(): String? { @@ -161,8 +160,14 @@ class InstallerInitializer : Shell.Initializer() { Companion.mgskVerCode = mgskVerCode return mgskPth } catch (ignored: Exception) { - return if (tries < 5) { + return if (tries <= 5) { tries++ + // sleep tries * 25ms + try { + Thread.sleep(tries * 25L) + } catch (e: InterruptedException) { + Timber.e(e) + } tryGetMagiskPath(true) } else { null diff --git a/app/src/main/kotlin/com/fox2code/mmm/module/ActionButtonType.kt b/app/src/main/kotlin/com/fox2code/mmm/module/ActionButtonType.kt index 43dc815..cc5346d 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/module/ActionButtonType.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/module/ActionButtonType.kt @@ -51,25 +51,44 @@ enum class ActionButtonType { TrackHelper.track().event("view_notes", name).with(INSTANCE!!.getTracker()) val notesUrl = moduleHolder.repoModule?.notesUrl if (isAndroidacyLink(notesUrl)) { - openUrlAndroidacy( - button.context, - notesUrl, - false, - moduleHolder.repoModule?.moduleInfo?.name, - moduleHolder.mainModuleConfig - ) + try { + openUrlAndroidacy( + button.context, + notesUrl, + false, + moduleHolder.repoModule?.moduleInfo?.name, + moduleHolder.mainModuleConfig + ) + } catch (e: Exception) { + Timber.e(e) + Timber.e("Error opening notes - androidacy link. This should never happen.") + Toast.makeText( + button.context, + R.string.error_opening_notes, + Toast.LENGTH_SHORT + ).show() + } } else { - openMarkdown( - button.context, - notesUrl, - moduleHolder.repoModule?.moduleInfo?.name, - moduleHolder.mainModuleConfig, - moduleHolder.repoModule?.moduleInfo?.changeBoot, - moduleHolder.repoModule?.moduleInfo?.needRamdisk, - moduleHolder.repoModule?.moduleInfo?.minMagisk ?: 0, - moduleHolder.repoModule?.moduleInfo?.minApi ?: 0, - moduleHolder.repoModule?.moduleInfo?.maxApi ?: 9999 - ) + try { + openMarkdown( + button.context, + notesUrl, + moduleHolder.repoModule?.moduleInfo?.name, + moduleHolder.mainModuleConfig, + moduleHolder.repoModule?.moduleInfo?.changeBoot, + moduleHolder.repoModule?.moduleInfo?.needRamdisk, + moduleHolder.repoModule?.moduleInfo?.minMagisk ?: 0, + moduleHolder.repoModule?.moduleInfo?.minApi ?: 0, + moduleHolder.repoModule?.moduleInfo?.maxApi ?: 9999 + ) + } catch (e: Exception) { + Timber.e(e) + Toast.makeText( + button.context, + R.string.error_opening_notes, + Toast.LENGTH_SHORT + ).show() + } } } diff --git a/app/src/main/kotlin/com/fox2code/mmm/repo/RepoManager.kt b/app/src/main/kotlin/com/fox2code/mmm/repo/RepoManager.kt index 3841e07..51ffcbf 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/repo/RepoManager.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/repo/RepoManager.kt @@ -70,7 +70,7 @@ class RepoManager private constructor(mainApplication: MainApplication) : SyncMa for (repoData in repoData.values) { if (repoData === androidacyRepoData) { if (x) { - Timber.e("Multiple Androidacy repo detected") + // } else { x = true } @@ -229,7 +229,7 @@ class RepoManager private constructor(mainApplication: MainApplication) : SyncMa for (i in repoDatas.indices) { // If repo is not enabled, skip if (!repoDatas[i].isEnabled) { - if (BuildConfig.DEBUG) Timber.d("Skipping " + repoDatas[i].name + " because it's disabled") + if (BuildConfig.DEBUG) Timber.d("Skipping ${repoDatas[i].name} because it's disabled") continue } if (BuildConfig.DEBUG) Timber.d("Finishing: %s", repoUpdaters[i]!!.repoData.name) diff --git a/app/src/main/kotlin/com/fox2code/mmm/utils/sentry/SentryMain.kt b/app/src/main/kotlin/com/fox2code/mmm/utils/sentry/SentryMain.kt index 6f49cf7..ecd9319 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/utils/sentry/SentryMain.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/utils/sentry/SentryMain.kt @@ -115,6 +115,7 @@ object SentryMain { options.addInAppInclude("com.fox2code.mmm.debug") options.addInAppInclude("com.fox2code.mmm.fdroid") options.addInAppExclude("com.fox2code.mmm.utils.sentry.SentryMain") + options.addInAppInclude("com.fox2code.mmm.utils") // Respect user preference for sending PII. default is true on non fdroid builds, false on fdroid builds options.isSendDefaultPii = crashReportingPii options.enableAllAutoBreadcrumbs(true) @@ -123,7 +124,7 @@ object SentryMain { // It just tell if sentry should ping the sentry dsn to tell the app is running. Useful for performance and profiling. options.isEnableAutoSessionTracking = true // disable crash tracking - we handle that ourselves - options.isEnableUncaughtExceptionHandler = false + options.isEnableUncaughtExceptionHandler = true // Add a callback that will be used before the event is sent to Sentry. // With this callback, you can modify the event or, when returning null, also discard the event. options.beforeSend = BeforeSendCallback { event: SentryEvent?, _: Hint? -> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f037c44..f58a26b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -384,4 +384,5 @@ The build you are using is expired and will no longer run. Please update to the latest stable build. Download latest Saved logs successfully + Error in opening module notes. Logs may have the reason. diff --git a/build.gradle.kts b/build.gradle.kts index 927fa41..b94c5e1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,20 +12,15 @@ buildscript { } gradlePluginPortal() } - extra.apply { - set("sentryConfigFile", rootProject.file("sentry.properties")) - set("hasSentryConfig", false) - set("sentryVersion", "6.18.1") - } dependencies { classpath("com.android.tools.build:gradle:8.1.0-rc01") classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.22") - classpath("com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:10.6.2") + classpath("com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:10.8.0") // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files classpath("io.sentry:sentry-android-gradle-plugin:3.11.0") - classpath("org.gradle.android.cache-fix:org.gradle.android.cache-fix.gradle.plugin:2.7.1") + classpath("org.gradle.android.cache-fix:org.gradle.android.cache-fix.gradle.plugin:2.7.2") } }