From 702048e6c849e1885ee99a07097ed9c31b1da6fd Mon Sep 17 00:00:00 2001 From: androidacy-user Date: Thu, 27 Apr 2023 21:39:42 -0400 Subject: [PATCH] (misc) fix race condition Signed-off-by: androidacy-user --- .../main/java/com/fox2code/mmm/CrashHandler.java | 4 +++- .../java/com/fox2code/mmm/MainApplication.java | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/fox2code/mmm/CrashHandler.java b/app/src/main/java/com/fox2code/mmm/CrashHandler.java index f1d1052..af6d4f0 100644 --- a/app/src/main/java/com/fox2code/mmm/CrashHandler.java +++ b/app/src/main/java/com/fox2code/mmm/CrashHandler.java @@ -11,6 +11,7 @@ import com.fox2code.foxcompat.app.FoxActivity; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.textview.MaterialTextView; +import java.io.PrintWriter; import java.io.StringWriter; import io.sentry.Sentry; @@ -27,6 +28,7 @@ public class CrashHandler extends FoxActivity { Timber.d("CrashHandler.onCreate: intent=%s", getIntent()); super.onCreate(savedInstanceState); setContentView(R.layout.activity_crash_handler); + // unlock webview // set crash_details MaterialTextView to the exception passed in the intent or unknown if null // convert stacktrace from array to string, and pretty print it (first line is the exception, the rest is the stacktrace, with each line indented by 4 spaces) MaterialTextView crashDetails = findViewById(R.id.crash_details); @@ -42,7 +44,7 @@ public class CrashHandler extends FoxActivity { // if the exception is not null, set the crash details to the exception and stacktrace // stacktrace is an StacktraceElement, so convert it to a string and replace the commas with newlines StringWriter stringWriter = new StringWriter(); - exception.printStackTrace(new java.io.PrintWriter(stringWriter)); + exception.printStackTrace(new PrintWriter(stringWriter)); String stacktrace = stringWriter.toString(); stacktrace = stacktrace.replace(",", "\n "); crashDetails.setText(getString(R.string.crash_full_stacktrace, stacktrace)); diff --git a/app/src/main/java/com/fox2code/mmm/MainApplication.java b/app/src/main/java/com/fox2code/mmm/MainApplication.java index 7a520ba..c184c3f 100644 --- a/app/src/main/java/com/fox2code/mmm/MainApplication.java +++ b/app/src/main/java/com/fox2code/mmm/MainApplication.java @@ -124,6 +124,7 @@ public class MainApplication extends FoxApplication implements androidx.work.Con private byte[] existingKey; private Tracker tracker; private boolean makingNewKey = false; + private boolean isCrashHandler; public MainApplication() { if (INSTANCE != null && INSTANCE != this) @@ -291,6 +292,7 @@ public class MainApplication extends FoxApplication implements androidx.work.Con } public Markwon getMarkwon() { + if (isCrashHandler) return null; if (this.markwon != null) return this.markwon; FoxThemeWrapper contextThemeWrapper = this.markwonThemeContext; if (contextThemeWrapper == null) { @@ -389,8 +391,18 @@ public class MainApplication extends FoxApplication implements androidx.work.Con Timber.i("Starting FoxMMM version %s (%d) - commit %s", BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE, BuildConfig.COMMIT_HASH); // Update SSL Ciphers if update is possible GMSProviderInstaller.installIfNeeded(this); - Http.ensureCacheDirs(); - Http.ensureURLHandler(getApplicationContext()); + // detect if we're launching the crashhandler + // get intent that started the crashhandler + Intent intent = getIntent(); + if (intent != null) { + if (intent.getClass().getName().equals("com.fox2code.mmm.CrashHandler")) { + isCrashHandler = true; + } + } + if (!isCrashHandler) { + Http.ensureCacheDirs(); + Http.ensureURLHandler(getApplicationContext()); + } Timber.d("Initializing FoxMMM"); Timber.d("Started from background: %s", !isInForeground()); Timber.d("FoxMMM is running in debug mode");