|
27 | 27 | import com.fox2code.rosettax.LanguageSwitcher; |
28 | 28 | import com.topjohnwu.superuser.Shell; |
29 | 29 |
|
| 30 | +import java.io.IOException; |
| 31 | +import java.io.Writer; |
30 | 32 | import java.text.SimpleDateFormat; |
31 | 33 | import java.util.Date; |
32 | 34 | import java.util.Locale; |
|
42 | 44 | import io.noties.markwon.syntax.SyntaxHighlightPlugin; |
43 | 45 | import io.noties.prism4j.Prism4j; |
44 | 46 | import io.noties.prism4j.annotations.PrismBundle; |
| 47 | +import io.sentry.JsonObjectWriter; |
| 48 | +import io.sentry.NoOpLogger; |
| 49 | +import io.sentry.android.core.SentryAndroid; |
45 | 50 |
|
46 | 51 | @PrismBundle( |
47 | 52 | includeAll = true, |
48 | 53 | grammarLocatorClassName = ".Prism4jGrammarLocator" |
49 | 54 | ) |
50 | 55 | public class MainApplication extends FoxApplication |
51 | 56 | implements androidx.work.Configuration.Provider { |
| 57 | + private static final String TAG = "MainApplication"; |
52 | 58 | private static final String timeFormatString = "dd MMM yyyy"; // Example: 13 july 2001 |
53 | 59 | private static Locale timeFormatLocale = |
54 | 60 | Resources.getSystem().getConfiguration().locale; |
@@ -168,6 +174,11 @@ public static void setHasGottenRootAccess(boolean bool) { |
168 | 174 | getSharedPreferences().edit().putBoolean("has_root_access", bool).apply(); |
169 | 175 | } |
170 | 176 |
|
| 177 | + public static boolean isCrashReportingEnabled() { |
| 178 | + return getSharedPreferences().getBoolean( |
| 179 | + "crash_reporting", BuildConfig.DEFAULT_ENABLE_CRASH_REPORTING); |
| 180 | + } |
| 181 | + |
171 | 182 | public static SharedPreferences getBootSharedPreferences() { |
172 | 183 | return bootSharedPreferences; |
173 | 184 | } |
@@ -341,6 +352,57 @@ public void onCreate() { |
341 | 352 | Log.d("MainApplication", "Emoji compat loaded!"); |
342 | 353 | }, "Emoji compat init.").start(); |
343 | 354 | } |
| 355 | + SentryAndroid.init(this, options -> { |
| 356 | + // Note: Sentry library only take a screenshot of Fox Magisk Module Manager. |
| 357 | + // The screen shot doesn't and cannot contain other applications (if in multi windows) |
| 358 | + // status bar and notifications (even if notification shade is pulled down) |
| 359 | + |
| 360 | + // In the possibility you find this library sending anything listed above, |
| 361 | + // it's a serious bug and a security issue you should report to Google |
| 362 | + // Google bug bounties on Android are huge, so you can also get rich by doing that. |
| 363 | + options.setAttachScreenshot(true); |
| 364 | + // Add a callback that will be used before the event is sent to Sentry. |
| 365 | + // With this callback, you can modify the event or, when returning null, also discard the event. |
| 366 | + options.setBeforeSend((event, hint) -> { |
| 367 | + if (BuildConfig.DEBUG) { // Debug sentry events for debug. |
| 368 | + StringBuilder stringBuilder = new StringBuilder("Sentry report debug: "); |
| 369 | + try { |
| 370 | + event.serialize(new JsonObjectWriter(new Writer() { |
| 371 | + @Override |
| 372 | + public void write(char[] cbuf) { |
| 373 | + stringBuilder.append(cbuf); |
| 374 | + } |
| 375 | + |
| 376 | + @Override |
| 377 | + public void write(char[] chars, int i, int i1) { |
| 378 | + stringBuilder.append(chars, i, i1); |
| 379 | + } |
| 380 | + |
| 381 | + @Override |
| 382 | + public void write(String str, int off, int len) { |
| 383 | + stringBuilder.append(str, off, len); |
| 384 | + } |
| 385 | + |
| 386 | + @Override |
| 387 | + public void flush() {} |
| 388 | + |
| 389 | + @Override |
| 390 | + public void close() {} |
| 391 | + }, 4), NoOpLogger.getInstance()); |
| 392 | + } catch (IOException ignored) {} |
| 393 | + Log.i(TAG, stringBuilder.toString()); |
| 394 | + } |
| 395 | + // Check saved preferences to see if the user has opted out of crash reporting. |
| 396 | + // If the user has opted out, return null. |
| 397 | + if (isCrashReportingEnabled()) { |
| 398 | + Log.i(TAG, "Relayed sentry report according to user preference"); |
| 399 | + return event; |
| 400 | + } else { |
| 401 | + Log.i(TAG, "Blocked sentry report according to user preference"); |
| 402 | + return null; |
| 403 | + } |
| 404 | + }); |
| 405 | + }); |
344 | 406 | } |
345 | 407 |
|
346 | 408 | @Override |
|
0 commit comments