fix a crash or two

can't catch em all

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/89/head
androidacy-user 2 years ago
parent e5b839b823
commit 8af585e12e

@ -473,14 +473,7 @@ dependencies {
// Chromium cronet from androidacy // Chromium cronet from androidacy
implementation("org.chromium.net:cronet-embedded:113.5672.61") implementation("org.chromium.net:cronet-embedded:113.5672.61")
// protobuf - fixes a crash on some devices val libsuVersion = "5.1.0"
// implementation("com.google.protobuf:protobuf-javalite:3.22.2")
// google guava, maybe fix a bug
implementation("com.google.guava:guava:32.0.1-jre")
val libsuVersion = "5.0.5"
// The core module that provides APIs to a shell // The core module that provides APIs to a shell
implementation("com.github.topjohnwu.libsu:core:${libsuVersion}") implementation("com.github.topjohnwu.libsu:core:${libsuVersion}")

@ -51,26 +51,32 @@ class CrashHandler : FoxActivity() {
stacktrace = stacktrace.replace(",", "\n ") stacktrace = stacktrace.replace(",", "\n ")
crashDetails.text = getString(R.string.crash_full_stacktrace, stacktrace) crashDetails.text = getString(R.string.crash_full_stacktrace, stacktrace)
} }
val lastEventId = intent.getStringExtra("lastEventId") // force sentry to send all events
Sentry.flush(2000)
val lastEventId = MainApplication.getSharedPreferences("sentry")?.getString("lastEventId", "")
Timber.d( Timber.d(
"CrashHandler.onCreate: lastEventId=%s, crashReportingEnabled=%s", "CrashHandler.onCreate: lastEventId=%s, crashReportingEnabled=%s",
lastEventId, lastEventId,
crashReportingEnabled crashReportingEnabled
) )
if (lastEventId == null && crashReportingEnabled) {
// get name, email, and message fields
val name = findViewById<EditText>(R.id.feedback_name)
val email = findViewById<EditText>(R.id.feedback_email)
val description = findViewById<EditText>(R.id.feedback_message)
val submit = findViewById<View>(R.id.feedback_submit)
if (lastEventId == "" && crashReportingEnabled) {
// if lastEventId is null, hide the feedback button // if lastEventId is null, hide the feedback button
findViewById<View>(R.id.feedback).visibility = View.GONE
Timber.d("CrashHandler.onCreate: lastEventId is null but crash reporting is enabled. This may indicate a bug in the crash reporting system.") Timber.d("CrashHandler.onCreate: lastEventId is null but crash reporting is enabled. This may indicate a bug in the crash reporting system.")
} else { } else {
// if lastEventId is not null, show the feedback button // if lastEventId is not null, enable the feedback name, email, message, and submit button
findViewById<View>(R.id.feedback).visibility = View.VISIBLE email.isEnabled = true
name.isEnabled = true
description.isEnabled = true
submit.isEnabled = true
} }
// disable feedback if sentry is disabled // disable feedback if sentry is disabled
if (crashReportingEnabled && lastEventId != null) { if (crashReportingEnabled && lastEventId != null) {
// get name, email, and message fields
val name = findViewById<EditText>(R.id.feedback_name)
val email = findViewById<EditText>(R.id.feedback_email)
val description = findViewById<EditText>(R.id.feedback_message)
// get submit button // get submit button
findViewById<View>(R.id.feedback_submit).setOnClickListener { _: View? -> findViewById<View>(R.id.feedback_submit).setOnClickListener { _: View? ->
// require the feedback_message, rest is optional // require the feedback_message, rest is optional
@ -84,12 +90,10 @@ class CrashHandler : FoxActivity() {
arrayOf(if (name.text.toString() == "") "Anonymous" else name.text.toString()) arrayOf(if (name.text.toString() == "") "Anonymous" else name.text.toString())
val emailString = val emailString =
arrayOf(if (email.text.toString() == "") "Anonymous" else email.text.toString()) arrayOf(if (email.text.toString() == "") "Anonymous" else email.text.toString())
// get sentryException passed in intent
@Suppress("NAME_SHADOWING") val lastEventId = Sentry.getLastEventId()
Thread { Thread {
try { try {
val userFeedback = val userFeedback =
UserFeedback(SentryId(lastEventId.toString())) UserFeedback(SentryId(lastEventId))
// Setups the JSON body // Setups the JSON body
if (nameString[0] == "") nameString[0] = "Anonymous" if (nameString[0] == "") nameString[0] = "Anonymous"
if (emailString[0] == "") emailString[0] = "Anonymous" if (emailString[0] == "") emailString[0] = "Anonymous"
@ -132,19 +136,9 @@ class CrashHandler : FoxActivity() {
startActivity(packageManager.getLaunchIntentForPackage(packageName)) startActivity(packageManager.getLaunchIntentForPackage(packageName))
} }
} else { } else {
// disable feedback if sentry is disabled
findViewById<View>(R.id.feedback_name).isEnabled = false
findViewById<View>(R.id.feedback_email).isEnabled = false
findViewById<View>(R.id.feedback_message).isEnabled = false
// fade out all the fields
findViewById<View>(R.id.feedback_name).alpha = 0.5f
findViewById<View>(R.id.feedback_email).alpha = 0.5f
findViewById<View>(R.id.feedback_message).alpha = 0.5f
// fade out the submit button
findViewById<View>(R.id.feedback_submit).alpha = 0.5f
// set feedback_text to "Crash reporting is disabled" // set feedback_text to "Crash reporting is disabled"
(findViewById<View>(R.id.feedback_text) as MaterialTextView).setText(R.string.sentry_enable_nag) (findViewById<View>(R.id.feedback_text) as MaterialTextView).setText(R.string.sentry_enable_nag)
findViewById<View>(R.id.feedback_submit).setOnClickListener { _: View? -> submit.setOnClickListener { _: View? ->
Toast.makeText( Toast.makeText(
this, R.string.sentry_dialogue_disabled, Toast.LENGTH_LONG this, R.string.sentry_dialogue_disabled, Toast.LENGTH_LONG
).show() ).show()

@ -52,7 +52,6 @@ import com.fox2code.mmm.utils.io.net.Http
import com.fox2code.mmm.utils.sentry.SentryBreadcrumb import com.fox2code.mmm.utils.sentry.SentryBreadcrumb
import com.fox2code.mmm.utils.sentry.SentryMain import com.fox2code.mmm.utils.sentry.SentryMain
import com.google.android.material.bottomnavigation.BottomNavigationItemView import com.google.android.material.bottomnavigation.BottomNavigationItemView
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.progressindicator.LinearProgressIndicator import com.google.android.material.progressindicator.LinearProgressIndicator
import com.topjohnwu.superuser.CallbackList import com.topjohnwu.superuser.CallbackList
@ -206,7 +205,7 @@ class InstallerActivity : FoxActivity() {
) )
var errMessage = "Failed to download module zip" var errMessage = "Failed to download module zip"
// Set this to the error message if it's a HTTP error // Set this to the error message if it's a HTTP error
var rawModule: ByteArray? = ByteArray(0) var rawModule: ByteArray?
try { try {
Timber.i( Timber.i(
"%s%s", if (urlMode) "Downloading: " else "Loading: ", AndroidacyUtil.hideToken( "%s%s", if (urlMode) "Downloading: " else "Loading: ", AndroidacyUtil.hideToken(
@ -239,7 +238,7 @@ class InstallerActivity : FoxActivity() {
} }
} }
if (canceled) return@Runnable if (canceled) return@Runnable
fixJavaZipHax(rawModule!!) fixJavaZipHax(rawModule)
// checks to make sure zip is not a source archive, and if it is, unzips the folder within, switches to it, and zips up the contents of it // checks to make sure zip is not a source archive, and if it is, unzips the folder within, switches to it, and zips up the contents of it
fixSourceArchiveShit(rawModule) fixSourceArchiveShit(rawModule)
var noPatch = false var noPatch = false

@ -10,6 +10,7 @@ import android.content.Intent
import android.content.SharedPreferences import android.content.SharedPreferences
import android.net.Uri import android.net.Uri
import android.os.Process import android.os.Process
import com.fox2code.mmm.BuildConfig
import com.fox2code.mmm.CrashHandler import com.fox2code.mmm.CrashHandler
import com.fox2code.mmm.MainApplication import com.fox2code.mmm.MainApplication
import com.fox2code.mmm.androidacy.AndroidacyUtil.Companion.hideToken import com.fox2code.mmm.androidacy.AndroidacyUtil.Companion.hideToken
@ -37,32 +38,17 @@ object SentryMain {
* Sentry is used for crash reporting and performance monitoring. * Sentry is used for crash reporting and performance monitoring.
*/ */
@JvmStatic @JvmStatic
@SuppressLint("RestrictedApi", "UnspecifiedImmutableFlag") @SuppressLint("RestrictedApi", "UnspecifiedImmutableFlag", "ApplySharedPref")
fun initialize(mainApplication: MainApplication) { fun initialize(mainApplication: MainApplication) {
Thread.setDefaultUncaughtExceptionHandler { _: Thread?, throwable: Throwable -> Thread.setDefaultUncaughtExceptionHandler { _: Thread?, throwable: Throwable ->
isCrashing = true isCrashing = true
TrackHelper.track().exception(throwable).with(MainApplication.INSTANCE!!.tracker) TrackHelper.track().exception(throwable).with(MainApplication.INSTANCE!!.tracker)
val editor =
MainApplication.INSTANCE!!.getSharedPreferences("sentry", Context.MODE_PRIVATE)
.edit()
editor.putString("lastExitReason", "crash")
editor.putLong("lastExitTime", System.currentTimeMillis())
editor.putString("lastExitReason", "crash")
editor.putString("lastExitId", Sentry.getLastEventId().toString())
editor.apply()
Timber.e(
"Uncaught exception with sentry ID %s and stacktrace %s",
Sentry.getLastEventId(),
throwable.stackTrace
)
// open crash handler and exit // open crash handler and exit
val intent = Intent(mainApplication, CrashHandler::class.java) val intent = Intent(mainApplication, CrashHandler::class.java)
// pass the entire exception to the crash handler // pass the entire exception to the crash handler
intent.putExtra("exception", throwable) intent.putExtra("exception", throwable)
// add stacktrace as string // add stacktrace as string
intent.putExtra("stacktrace", throwable.stackTrace) intent.putExtra("stacktrace", throwable.stackTrace)
// put lastEventId in intent (get from preferences)
intent.putExtra("lastEventId", Sentry.getLastEventId().toString())
// serialize Sentry.captureException and pass it to the crash handler // serialize Sentry.captureException and pass it to the crash handler
intent.putExtra("sentryException", throwable) intent.putExtra("sentryException", throwable)
// pass crashReportingEnabled to crash handler // pass crashReportingEnabled to crash handler
@ -127,11 +113,21 @@ object SentryMain {
options.isEnableUncaughtExceptionHandler = true options.isEnableUncaughtExceptionHandler = true
// Add a callback that will be used before the event is sent to Sentry. // 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. // With this callback, you can modify the event or, when returning null, also discard the event.
options.environment = BuildConfig.BUILD_TYPE
options.beforeSend = BeforeSendCallback { event: SentryEvent?, _: Hint? -> options.beforeSend = BeforeSendCallback { event: SentryEvent?, _: Hint? ->
// in the rare event that crash reporting has been disabled since we started the app, we don't want to send the crash report // in the rare event that crash reporting has been disabled since we started the app, we don't want to send the crash report
if (!isSentryEnabled || isCrashing) { if (!isSentryEnabled) {
return@BeforeSendCallback null return@BeforeSendCallback null
} }
// store eventid in prefs
val editor =
MainApplication.INSTANCE!!.getSharedPreferences(
"sentry",
Context.MODE_PRIVATE
)
.edit()
editor.putString("lastEventId", event!!.eventId.toString())
editor.commit() // commit so we immediately cache if crashing
event event
} }
// Filter breadcrumb content from crash report. // Filter breadcrumb content from crash report.

@ -107,6 +107,7 @@
<!-- feedback form name --> <!-- feedback form name -->
<EditText <EditText
android:id="@+id/feedback_name" android:id="@+id/feedback_name"
android:enabled="false"
android:layout_width="320dp" android:layout_width="320dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_margin="10dp" android:layout_margin="10dp"
@ -118,6 +119,7 @@
android:id="@+id/feedback_email" android:id="@+id/feedback_email"
android:layout_width="320dp" android:layout_width="320dp"
android:layout_height="48dp" android:layout_height="48dp"
android:enabled="false"
android:layout_margin="10dp" android:layout_margin="10dp"
android:hint="@string/feedback_email" android:hint="@string/feedback_email"
android:inputType="textEmailAddress" /> android:inputType="textEmailAddress" />
@ -125,12 +127,16 @@
<!-- feedback form message --> <!-- feedback form message -->
<EditText <EditText
android:id="@+id/feedback_message" android:id="@+id/feedback_message"
android:enabled="false"
android:layout_width="320dp" android:layout_width="320dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="10dp" android:layout_margin="10dp"
android:hint="@string/feedback_message" android:hint="@string/feedback_message"
android:inputType="textMultiLine" /> android:inputType="textMultiLine" />
</LinearLayout>
<!-- button group for submit feedback & restart / restart only --> <!-- button group for submit feedback & restart / restart only -->
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -142,8 +148,9 @@
android:id="@+id/feedback_submit" android:id="@+id/feedback_submit"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:enabled="false"
android:layout_margin="10dp" android:layout_margin="10dp"
android:text="@string/feedback_submit" /> android:text="@string/submit_feedback" />
<!-- restart button --> <!-- restart button -->
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
@ -155,6 +162,7 @@
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -178,5 +186,4 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout>
</ScrollView> </ScrollView>

@ -385,4 +385,5 @@
<string name="download_latest">Download latest</string> <string name="download_latest">Download latest</string>
<string name="logs_saved">Saved logs successfully</string> <string name="logs_saved">Saved logs successfully</string>
<string name="error_opening_notes">Error in opening module notes. Logs may have the reason.</string> <string name="error_opening_notes">Error in opening module notes. Logs may have the reason.</string>
<string name="submit_feedback">Submit feedback</string>
</resources> </resources>

Loading…
Cancel
Save