Skip to content

Commit 8af585e

Browse files
fix a crash or two
can't catch em all Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent e5b839b commit 8af585e

6 files changed

Lines changed: 83 additions & 93 deletions

File tree

app/build.gradle.kts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -473,14 +473,7 @@ dependencies {
473473
// Chromium cronet from androidacy
474474
implementation("org.chromium.net:cronet-embedded:113.5672.61")
475475

476-
// protobuf - fixes a crash on some devices
477-
// implementation("com.google.protobuf:protobuf-javalite:3.22.2")
478-
479-
// google guava, maybe fix a bug
480-
implementation("com.google.guava:guava:32.0.1-jre")
481-
482-
483-
val libsuVersion = "5.0.5"
476+
val libsuVersion = "5.1.0"
484477
// The core module that provides APIs to a shell
485478
implementation("com.github.topjohnwu.libsu:core:${libsuVersion}")
486479

app/src/main/kotlin/com/fox2code/mmm/CrashHandler.kt

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,32 @@ class CrashHandler : FoxActivity() {
5151
stacktrace = stacktrace.replace(",", "\n ")
5252
crashDetails.text = getString(R.string.crash_full_stacktrace, stacktrace)
5353
}
54-
val lastEventId = intent.getStringExtra("lastEventId")
54+
// force sentry to send all events
55+
Sentry.flush(2000)
56+
val lastEventId = MainApplication.getSharedPreferences("sentry")?.getString("lastEventId", "")
5557
Timber.d(
5658
"CrashHandler.onCreate: lastEventId=%s, crashReportingEnabled=%s",
5759
lastEventId,
5860
crashReportingEnabled
5961
)
60-
if (lastEventId == null && crashReportingEnabled) {
62+
63+
// get name, email, and message fields
64+
val name = findViewById<EditText>(R.id.feedback_name)
65+
val email = findViewById<EditText>(R.id.feedback_email)
66+
val description = findViewById<EditText>(R.id.feedback_message)
67+
val submit = findViewById<View>(R.id.feedback_submit)
68+
if (lastEventId == "" && crashReportingEnabled) {
6169
// if lastEventId is null, hide the feedback button
62-
findViewById<View>(R.id.feedback).visibility = View.GONE
6370
Timber.d("CrashHandler.onCreate: lastEventId is null but crash reporting is enabled. This may indicate a bug in the crash reporting system.")
6471
} else {
65-
// if lastEventId is not null, show the feedback button
66-
findViewById<View>(R.id.feedback).visibility = View.VISIBLE
72+
// if lastEventId is not null, enable the feedback name, email, message, and submit button
73+
email.isEnabled = true
74+
name.isEnabled = true
75+
description.isEnabled = true
76+
submit.isEnabled = true
6777
}
6878
// disable feedback if sentry is disabled
6979
if (crashReportingEnabled && lastEventId != null) {
70-
// get name, email, and message fields
71-
val name = findViewById<EditText>(R.id.feedback_name)
72-
val email = findViewById<EditText>(R.id.feedback_email)
73-
val description = findViewById<EditText>(R.id.feedback_message)
7480
// get submit button
7581
findViewById<View>(R.id.feedback_submit).setOnClickListener { _: View? ->
7682
// require the feedback_message, rest is optional
@@ -84,12 +90,10 @@ class CrashHandler : FoxActivity() {
8490
arrayOf(if (name.text.toString() == "") "Anonymous" else name.text.toString())
8591
val emailString =
8692
arrayOf(if (email.text.toString() == "") "Anonymous" else email.text.toString())
87-
// get sentryException passed in intent
88-
@Suppress("NAME_SHADOWING") val lastEventId = Sentry.getLastEventId()
8993
Thread {
9094
try {
9195
val userFeedback =
92-
UserFeedback(SentryId(lastEventId.toString()))
96+
UserFeedback(SentryId(lastEventId))
9397
// Setups the JSON body
9498
if (nameString[0] == "") nameString[0] = "Anonymous"
9599
if (emailString[0] == "") emailString[0] = "Anonymous"
@@ -132,19 +136,9 @@ class CrashHandler : FoxActivity() {
132136
startActivity(packageManager.getLaunchIntentForPackage(packageName))
133137
}
134138
} else {
135-
// disable feedback if sentry is disabled
136-
findViewById<View>(R.id.feedback_name).isEnabled = false
137-
findViewById<View>(R.id.feedback_email).isEnabled = false
138-
findViewById<View>(R.id.feedback_message).isEnabled = false
139-
// fade out all the fields
140-
findViewById<View>(R.id.feedback_name).alpha = 0.5f
141-
findViewById<View>(R.id.feedback_email).alpha = 0.5f
142-
findViewById<View>(R.id.feedback_message).alpha = 0.5f
143-
// fade out the submit button
144-
findViewById<View>(R.id.feedback_submit).alpha = 0.5f
145139
// set feedback_text to "Crash reporting is disabled"
146140
(findViewById<View>(R.id.feedback_text) as MaterialTextView).setText(R.string.sentry_enable_nag)
147-
findViewById<View>(R.id.feedback_submit).setOnClickListener { _: View? ->
141+
submit.setOnClickListener { _: View? ->
148142
Toast.makeText(
149143
this, R.string.sentry_dialogue_disabled, Toast.LENGTH_LONG
150144
).show()

app/src/main/kotlin/com/fox2code/mmm/installer/InstallerActivity.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import com.fox2code.mmm.utils.io.net.Http
5252
import com.fox2code.mmm.utils.sentry.SentryBreadcrumb
5353
import com.fox2code.mmm.utils.sentry.SentryMain
5454
import com.google.android.material.bottomnavigation.BottomNavigationItemView
55-
import com.google.android.material.bottomnavigation.BottomNavigationView
5655
import com.google.android.material.dialog.MaterialAlertDialogBuilder
5756
import com.google.android.material.progressindicator.LinearProgressIndicator
5857
import com.topjohnwu.superuser.CallbackList
@@ -206,7 +205,7 @@ class InstallerActivity : FoxActivity() {
206205
)
207206
var errMessage = "Failed to download module zip"
208207
// Set this to the error message if it's a HTTP error
209-
var rawModule: ByteArray? = ByteArray(0)
208+
var rawModule: ByteArray?
210209
try {
211210
Timber.i(
212211
"%s%s", if (urlMode) "Downloading: " else "Loading: ", AndroidacyUtil.hideToken(
@@ -239,7 +238,7 @@ class InstallerActivity : FoxActivity() {
239238
}
240239
}
241240
if (canceled) return@Runnable
242-
fixJavaZipHax(rawModule!!)
241+
fixJavaZipHax(rawModule)
243242
// 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
244243
fixSourceArchiveShit(rawModule)
245244
var noPatch = false

app/src/main/kotlin/com/fox2code/mmm/utils/sentry/SentryMain.kt

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import android.content.Intent
1010
import android.content.SharedPreferences
1111
import android.net.Uri
1212
import android.os.Process
13+
import com.fox2code.mmm.BuildConfig
1314
import com.fox2code.mmm.CrashHandler
1415
import com.fox2code.mmm.MainApplication
1516
import com.fox2code.mmm.androidacy.AndroidacyUtil.Companion.hideToken
@@ -37,32 +38,17 @@ object SentryMain {
3738
* Sentry is used for crash reporting and performance monitoring.
3839
*/
3940
@JvmStatic
40-
@SuppressLint("RestrictedApi", "UnspecifiedImmutableFlag")
41+
@SuppressLint("RestrictedApi", "UnspecifiedImmutableFlag", "ApplySharedPref")
4142
fun initialize(mainApplication: MainApplication) {
4243
Thread.setDefaultUncaughtExceptionHandler { _: Thread?, throwable: Throwable ->
4344
isCrashing = true
4445
TrackHelper.track().exception(throwable).with(MainApplication.INSTANCE!!.tracker)
45-
val editor =
46-
MainApplication.INSTANCE!!.getSharedPreferences("sentry", Context.MODE_PRIVATE)
47-
.edit()
48-
editor.putString("lastExitReason", "crash")
49-
editor.putLong("lastExitTime", System.currentTimeMillis())
50-
editor.putString("lastExitReason", "crash")
51-
editor.putString("lastExitId", Sentry.getLastEventId().toString())
52-
editor.apply()
53-
Timber.e(
54-
"Uncaught exception with sentry ID %s and stacktrace %s",
55-
Sentry.getLastEventId(),
56-
throwable.stackTrace
57-
)
5846
// open crash handler and exit
5947
val intent = Intent(mainApplication, CrashHandler::class.java)
6048
// pass the entire exception to the crash handler
6149
intent.putExtra("exception", throwable)
6250
// add stacktrace as string
6351
intent.putExtra("stacktrace", throwable.stackTrace)
64-
// put lastEventId in intent (get from preferences)
65-
intent.putExtra("lastEventId", Sentry.getLastEventId().toString())
6652
// serialize Sentry.captureException and pass it to the crash handler
6753
intent.putExtra("sentryException", throwable)
6854
// pass crashReportingEnabled to crash handler
@@ -127,11 +113,21 @@ object SentryMain {
127113
options.isEnableUncaughtExceptionHandler = true
128114
// Add a callback that will be used before the event is sent to Sentry.
129115
// With this callback, you can modify the event or, when returning null, also discard the event.
116+
options.environment = BuildConfig.BUILD_TYPE
130117
options.beforeSend = BeforeSendCallback { event: SentryEvent?, _: Hint? ->
131118
// in the rare event that crash reporting has been disabled since we started the app, we don't want to send the crash report
132-
if (!isSentryEnabled || isCrashing) {
119+
if (!isSentryEnabled) {
133120
return@BeforeSendCallback null
134121
}
122+
// store eventid in prefs
123+
val editor =
124+
MainApplication.INSTANCE!!.getSharedPreferences(
125+
"sentry",
126+
Context.MODE_PRIVATE
127+
)
128+
.edit()
129+
editor.putString("lastEventId", event!!.eventId.toString())
130+
editor.commit() // commit so we immediately cache if crashing
135131
event
136132
}
137133
// Filter breadcrumb content from crash report.

app/src/main/res/layout/activity_crash_handler.xml

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
<!-- feedback form name -->
108108
<EditText
109109
android:id="@+id/feedback_name"
110+
android:enabled="false"
110111
android:layout_width="320dp"
111112
android:layout_height="48dp"
112113
android:layout_margin="10dp"
@@ -118,64 +119,70 @@
118119
android:id="@+id/feedback_email"
119120
android:layout_width="320dp"
120121
android:layout_height="48dp"
122+
android:enabled="false"
121123
android:layout_margin="10dp"
122124
android:hint="@string/feedback_email"
123125
android:inputType="textEmailAddress" />
124126

125127
<!-- feedback form message -->
126128
<EditText
127129
android:id="@+id/feedback_message"
130+
android:enabled="false"
128131
android:layout_width="320dp"
129132
android:layout_height="wrap_content"
130133
android:layout_margin="10dp"
131134
android:hint="@string/feedback_message"
132135
android:inputType="textMultiLine" />
133136

134-
<!-- button group for submit feedback & restart / restart only -->
135-
<LinearLayout
136-
android:layout_width="match_parent"
137+
</LinearLayout>
138+
139+
140+
<!-- button group for submit feedback & restart / restart only -->
141+
<LinearLayout
142+
android:layout_width="match_parent"
143+
android:layout_height="wrap_content"
144+
android:orientation="horizontal">
145+
146+
<!-- submit feedback button -->
147+
<com.google.android.material.button.MaterialButton
148+
android:id="@+id/feedback_submit"
149+
android:layout_width="wrap_content"
137150
android:layout_height="wrap_content"
138-
android:orientation="horizontal">
139-
140-
<!-- submit feedback button -->
141-
<com.google.android.material.button.MaterialButton
142-
android:id="@+id/feedback_submit"
143-
android:layout_width="wrap_content"
144-
android:layout_height="wrap_content"
145-
android:layout_margin="10dp"
146-
android:text="@string/feedback_submit" />
147-
148-
<!-- restart button -->
149-
<com.google.android.material.button.MaterialButton
150-
android:id="@+id/restart"
151-
android:layout_width="wrap_content"
152-
android:layout_height="wrap_content"
153-
android:layout_margin="10dp"
154-
android:text="@string/restart" />
155-
156-
</LinearLayout>
157-
158-
<LinearLayout
151+
android:enabled="false"
152+
android:layout_margin="10dp"
153+
android:text="@string/submit_feedback" />
154+
155+
<!-- restart button -->
156+
<com.google.android.material.button.MaterialButton
157+
android:id="@+id/restart"
158+
android:layout_width="wrap_content"
159+
android:layout_height="wrap_content"
160+
android:layout_margin="10dp"
161+
android:text="@string/restart" />
162+
163+
</LinearLayout>
164+
165+
166+
<LinearLayout
167+
android:layout_width="match_parent"
168+
android:layout_height="wrap_content"
169+
android:orientation="vertical">
170+
171+
<com.google.android.material.textview.MaterialTextView
159172
android:layout_width="match_parent"
173+
android:layout_height="match_parent"
174+
android:layout_margin="10dp"
175+
android:gravity="fill"
176+
android:text="@string/reset_warning"
177+
android:textSize="16sp" />
178+
179+
<!-- reset app button -->
180+
<com.google.android.material.button.MaterialButton
181+
android:id="@+id/reset"
182+
android:layout_width="wrap_content"
160183
android:layout_height="wrap_content"
161-
android:orientation="vertical">
162-
163-
<com.google.android.material.textview.MaterialTextView
164-
android:layout_width="match_parent"
165-
android:layout_height="match_parent"
166-
android:layout_margin="10dp"
167-
android:gravity="fill"
168-
android:text="@string/reset_warning"
169-
android:textSize="16sp" />
170-
171-
<!-- reset app button -->
172-
<com.google.android.material.button.MaterialButton
173-
android:id="@+id/reset"
174-
android:layout_width="wrap_content"
175-
android:layout_height="wrap_content"
176-
android:layout_margin="10dp"
177-
android:text="@string/reset_app" />
178-
</LinearLayout>
184+
android:layout_margin="10dp"
185+
android:text="@string/reset_app" />
179186
</LinearLayout>
180187
</LinearLayout>
181188
</LinearLayout>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,4 +385,5 @@
385385
<string name="download_latest">Download latest</string>
386386
<string name="logs_saved">Saved logs successfully</string>
387387
<string name="error_opening_notes">Error in opening module notes. Logs may have the reason.</string>
388+
<string name="submit_feedback">Submit feedback</string>
388389
</resources>

0 commit comments

Comments
 (0)