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
implementation("org.chromium.net:cronet-embedded:113.5672.61")
// protobuf - fixes a crash on some devices
// 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"
val libsuVersion = "5.1.0"
// The core module that provides APIs to a shell
implementation("com.github.topjohnwu.libsu:core:${libsuVersion}")

@ -51,26 +51,32 @@ class CrashHandler : FoxActivity() {
stacktrace = stacktrace.replace(",", "\n ")
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(
"CrashHandler.onCreate: lastEventId=%s, crashReportingEnabled=%s",
lastEventId,
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
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.")
} else {
// if lastEventId is not null, show the feedback button
findViewById<View>(R.id.feedback).visibility = View.VISIBLE
// if lastEventId is not null, enable the feedback name, email, message, and submit button
email.isEnabled = true
name.isEnabled = true
description.isEnabled = true
submit.isEnabled = true
}
// disable feedback if sentry is disabled
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
findViewById<View>(R.id.feedback_submit).setOnClickListener { _: View? ->
// require the feedback_message, rest is optional
@ -84,12 +90,10 @@ class CrashHandler : FoxActivity() {
arrayOf(if (name.text.toString() == "") "Anonymous" else name.text.toString())
val emailString =
arrayOf(if (email.text.toString() == "") "Anonymous" else email.text.toString())
// get sentryException passed in intent
@Suppress("NAME_SHADOWING") val lastEventId = Sentry.getLastEventId()
Thread {
try {
val userFeedback =
UserFeedback(SentryId(lastEventId.toString()))
UserFeedback(SentryId(lastEventId))
// Setups the JSON body
if (nameString[0] == "") nameString[0] = "Anonymous"
if (emailString[0] == "") emailString[0] = "Anonymous"
@ -132,19 +136,9 @@ class CrashHandler : FoxActivity() {
startActivity(packageManager.getLaunchIntentForPackage(packageName))
}
} 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"
(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(
this, R.string.sentry_dialogue_disabled, Toast.LENGTH_LONG
).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.SentryMain
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.progressindicator.LinearProgressIndicator
import com.topjohnwu.superuser.CallbackList
@ -206,7 +205,7 @@ class InstallerActivity : FoxActivity() {
)
var errMessage = "Failed to download module zip"
// Set this to the error message if it's a HTTP error
var rawModule: ByteArray? = ByteArray(0)
var rawModule: ByteArray?
try {
Timber.i(
"%s%s", if (urlMode) "Downloading: " else "Loading: ", AndroidacyUtil.hideToken(
@ -239,7 +238,7 @@ class InstallerActivity : FoxActivity() {
}
}
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
fixSourceArchiveShit(rawModule)
var noPatch = false

@ -10,6 +10,7 @@ import android.content.Intent
import android.content.SharedPreferences
import android.net.Uri
import android.os.Process
import com.fox2code.mmm.BuildConfig
import com.fox2code.mmm.CrashHandler
import com.fox2code.mmm.MainApplication
import com.fox2code.mmm.androidacy.AndroidacyUtil.Companion.hideToken
@ -37,32 +38,17 @@ object SentryMain {
* Sentry is used for crash reporting and performance monitoring.
*/
@JvmStatic
@SuppressLint("RestrictedApi", "UnspecifiedImmutableFlag")
@SuppressLint("RestrictedApi", "UnspecifiedImmutableFlag", "ApplySharedPref")
fun initialize(mainApplication: MainApplication) {
Thread.setDefaultUncaughtExceptionHandler { _: Thread?, throwable: Throwable ->
isCrashing = true
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
val intent = Intent(mainApplication, CrashHandler::class.java)
// pass the entire exception to the crash handler
intent.putExtra("exception", throwable)
// add stacktrace as string
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
intent.putExtra("sentryException", throwable)
// pass crashReportingEnabled to crash handler
@ -127,11 +113,21 @@ object SentryMain {
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.environment = BuildConfig.BUILD_TYPE
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
if (!isSentryEnabled || isCrashing) {
if (!isSentryEnabled) {
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
}
// Filter breadcrumb content from crash report.

@ -107,6 +107,7 @@
<!-- feedback form name -->
<EditText
android:id="@+id/feedback_name"
android:enabled="false"
android:layout_width="320dp"
android:layout_height="48dp"
android:layout_margin="10dp"
@ -118,6 +119,7 @@
android:id="@+id/feedback_email"
android:layout_width="320dp"
android:layout_height="48dp"
android:enabled="false"
android:layout_margin="10dp"
android:hint="@string/feedback_email"
android:inputType="textEmailAddress" />
@ -125,57 +127,62 @@
<!-- feedback form message -->
<EditText
android:id="@+id/feedback_message"
android:enabled="false"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="@string/feedback_message"
android:inputType="textMultiLine" />
<!-- button group for submit feedback & restart / restart only -->
<LinearLayout
android:layout_width="match_parent"
</LinearLayout>
<!-- button group for submit feedback & restart / restart only -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!-- submit feedback button -->
<com.google.android.material.button.MaterialButton
android:id="@+id/feedback_submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!-- submit feedback button -->
<com.google.android.material.button.MaterialButton
android:id="@+id/feedback_submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="@string/feedback_submit" />
<!-- restart button -->
<com.google.android.material.button.MaterialButton
android:id="@+id/restart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="@string/restart" />
</LinearLayout>
<LinearLayout
android:enabled="false"
android:layout_margin="10dp"
android:text="@string/submit_feedback" />
<!-- restart button -->
<com.google.android.material.button.MaterialButton
android:id="@+id/restart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="@string/restart" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.textview.MaterialTextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:gravity="fill"
android:text="@string/reset_warning"
android:textSize="16sp" />
<!-- reset app button -->
<com.google.android.material.button.MaterialButton
android:id="@+id/reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.textview.MaterialTextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:gravity="fill"
android:text="@string/reset_warning"
android:textSize="16sp" />
<!-- reset app button -->
<com.google.android.material.button.MaterialButton
android:id="@+id/reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="@string/reset_app" />
</LinearLayout>
android:layout_margin="10dp"
android:text="@string/reset_app" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

@ -385,4 +385,5 @@
<string name="download_latest">Download latest</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="submit_feedback">Submit feedback</string>
</resources>

Loading…
Cancel
Save