99import android .graphics .Color ;
1010import android .os .Build ;
1111import android .os .SystemClock ;
12+ import android .system .ErrnoException ;
13+ import android .system .Os ;
1214import android .text .SpannableStringBuilder ;
1315import android .util .Log ;
1416
2123import com .fox2code .foxcompat .FoxActivity ;
2224import com .fox2code .foxcompat .FoxApplication ;
2325import com .fox2code .foxcompat .FoxThemeWrapper ;
26+ import com .fox2code .foxcompat .internal .FoxProcessExt ;
2427import com .fox2code .mmm .installer .InstallerInitializer ;
2528import com .fox2code .mmm .utils .GMSProviderInstaller ;
2629import com .fox2code .mmm .utils .Http ;
4649import io .noties .prism4j .annotations .PrismBundle ;
4750import io .sentry .JsonObjectWriter ;
4851import io .sentry .NoOpLogger ;
52+ import io .sentry .TypeCheckHint ;
53+ import io .sentry .UncaughtExceptionHandlerIntegration ;
4954import io .sentry .android .core .SentryAndroid ;
55+ import io .sentry .hints .DiskFlushNotification ;
5056
5157@ PrismBundle (
5258 includeAll = true ,
@@ -62,7 +68,10 @@ public class MainApplication extends FoxApplication
6268 new SimpleDateFormat (timeFormatString , timeFormatLocale );
6369 private static final Shell .Builder shellBuilder ;
6470 private static final long secret ;
71+ @ SuppressLint ("RestrictedApi" ) // Use FoxProcess wrapper helper.
72+ private static final boolean wrapped = !FoxProcessExt .isRootLoader ();
6573 private static SharedPreferences bootSharedPreferences ;
74+ private static String relPackageName = BuildConfig .APPLICATION_ID ;
6675 private static MainApplication INSTANCE ;
6776 private static boolean firstBoot ;
6877
@@ -88,13 +97,20 @@ public static void addSecret(Intent intent) {
8897 ComponentName componentName = intent .getComponent ();
8998 String packageName = componentName != null ?
9099 componentName .getPackageName () : intent .getPackage ();
91- if (!BuildConfig .APPLICATION_ID .equalsIgnoreCase (packageName )) {
100+ if (!BuildConfig .APPLICATION_ID .equalsIgnoreCase (packageName ) &&
101+ !relPackageName .equals (packageName )) {
92102 // Code safeguard, we should never reach here.
93103 throw new IllegalArgumentException ("Can't add secret to outbound Intent" );
94104 }
95105 intent .putExtra ("secret" , secret );
96106 }
97107
108+ // Is application wrapped, and therefore must reduce it's feature set.
109+ @ SuppressWarnings ("BooleanMethodIsAlwaysInverted" )
110+ public static boolean isWrapped () {
111+ return wrapped ;
112+ }
113+
98114 public static boolean checkSecret (Intent intent ) {
99115 return intent != null && intent .getLongExtra ("secret" , ~secret ) == secret ;
100116 }
@@ -154,7 +170,7 @@ && getSharedPreferences().getBoolean("pref_use_magisk_install_command", false)
154170 }
155171
156172 public static boolean isBackgroundUpdateCheckEnabled () {
157- return getSharedPreferences ().getBoolean ("pref_background_update_check" , true );
173+ return ! wrapped && getSharedPreferences ().getBoolean ("pref_background_update_check" , true );
158174 }
159175
160176 public static boolean isAndroidacyTestMode () {
@@ -175,8 +191,8 @@ public static void setHasGottenRootAccess(boolean bool) {
175191 }
176192
177193 public static boolean isCrashReportingEnabled () {
178- return getSharedPreferences ().getBoolean (
179- "crash_reporting" , BuildConfig .DEFAULT_ENABLE_CRASH_REPORTING );
194+ return getSharedPreferences ().getBoolean ("pref_crash_reporting" ,
195+ BuildConfig .DEFAULT_ENABLE_CRASH_REPORTING && ! BuildConfig . DEBUG );
180196 }
181197
182198 public static SharedPreferences getBootSharedPreferences () {
@@ -310,6 +326,7 @@ public boolean isLightTheme() {
310326 @ Override
311327 public void onCreate () {
312328 if (INSTANCE == null ) INSTANCE = this ;
329+ relPackageName = this .getPackageName ();
313330 super .onCreate ();
314331 /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
315332 DynamicColors.applyToActivitiesIfAvailable(this,
@@ -352,6 +369,7 @@ public void onCreate() {
352369 Log .d ("MainApplication" , "Emoji compat loaded!" );
353370 }, "Emoji compat init." ).start ();
354371 }
372+
355373 SentryAndroid .init (this , options -> {
356374 // Note: Sentry library only take a screenshot of Fox Magisk Module Manager.
357375 // The screen shot doesn't and cannot contain other applications (if in multi windows)
@@ -361,6 +379,8 @@ public void onCreate() {
361379 // it's a serious bug and a security issue you should report to Google
362380 // Google bug bounties on Android are huge, so you can also get rich by doing that.
363381 options .setAttachScreenshot (true );
382+ // User interaction tracing is not needed to get context of crash
383+ options .setEnableUserInteractionTracing (false );
364384 // Add a callback that will be used before the event is sent to Sentry.
365385 // With this callback, you can modify the event or, when returning null, also discard the event.
366386 options .setBeforeSend ((event , hint ) -> {
@@ -373,6 +393,11 @@ public void write(char[] cbuf) {
373393 stringBuilder .append (cbuf );
374394 }
375395
396+ @ Override
397+ public void write (String str ) {
398+ stringBuilder .append (str );
399+ }
400+
376401 @ Override
377402 public void write (char [] chars , int i , int i1 ) {
378403 stringBuilder .append (chars , i , i1 );
@@ -399,6 +424,10 @@ public void close() {}
399424 return event ;
400425 } else {
401426 Log .i (TAG , "Blocked sentry report according to user preference" );
427+ // We need to do this to avoid crash delay on crash when the event is dropped
428+ DiskFlushNotification diskFlushNotification = hint .getAs (
429+ TypeCheckHint .SENTRY_TYPE_CHECK_HINT , DiskFlushNotification .class );
430+ if (diskFlushNotification != null ) diskFlushNotification .markFlushed ();
402431 return null ;
403432 }
404433 });
0 commit comments