Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit df166d7

Browse files
committed
Fix Error reporting and update libraries.
1 parent bcc988a commit df166d7

File tree

5 files changed

+97
-32
lines changed

5 files changed

+97
-32
lines changed

app/build.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ configurations {
8383
}
8484

8585
dependencies {
86-
// Error reporting
87-
implementation 'io.sentry:sentry-android:6.4.0'
8886
// UI
8987
implementation 'androidx.appcompat:appcompat:1.5.0'
9088
implementation 'androidx.emoji2:emoji2:1.2.0'
@@ -100,16 +98,20 @@ dependencies {
10098
implementation "dev.rikka.rikkax.insets:insets:1.3.0"
10199
implementation 'com.github.Dimezis:BlurView:version-1.6.6'
102100
implementation 'com.github.KieronQuinn:MonetCompat:0.4.1'
103-
implementation 'com.github.Fox2Code:FoxCompat:0.1.0'
101+
implementation 'com.github.Fox2Code:FoxCompat:0.1.2'
104102

105103
// Utils
106104
implementation 'androidx.work:work-runtime:2.7.1'
107105
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.9.3'
108106
implementation 'com.squareup.okhttp3:okhttp-brotli:4.9.3'
109107
implementation 'com.github.topjohnwu.libsu:io:5.0.1'
110-
implementation 'com.github.Fox2Code:RosettaX:1.0.8'
108+
implementation 'com.github.Fox2Code:RosettaX:1.0.9'
111109
implementation 'com.github.Fox2Code:AndroidANSI:1.0.1'
112110

111+
// Error reporting
112+
implementation 'io.sentry:sentry-android:6.4.0'
113+
implementation 'io.sentry:sentry-android-fragment:6.4.0'
114+
113115
// Markdown
114116
implementation "io.noties.markwon:core:4.6.2"
115117
implementation "io.noties.markwon:html:4.6.2"

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,23 @@
7474
android:parentActivityName=".MainActivity"
7575
android:screenOrientation="portrait"
7676
tools:ignore="LockedOrientationActivity">
77-
<intent-filter>
77+
<!-- <intent-filter>
7878
<action android:name="${applicationId}.intent.action.INSTALL_MODULE_INTERNAL" />
79-
</intent-filter>
79+
</intent-filter> -->
8080
</activity>
8181
<activity
8282
android:name=".markdown.MarkdownActivity"
8383
android:exported="false"
8484
android:parentActivityName=".MainActivity"
85-
android:theme="@style/Theme.MagiskModuleManager"></activity>
85+
android:theme="@style/Theme.MagiskModuleManager" />
8686
<activity
8787
android:name=".androidacy.AndroidacyActivity"
8888
android:exported="false"
8989
android:parentActivityName=".MainActivity"
9090
android:theme="@style/Theme.MagiskModuleManager">
91-
<intent-filter>
91+
<!-- <intent-filter>
9292
<action android:name="${applicationId}.intent.action.OPEN_ANDROIDACY_INTERNAL" />
93-
</intent-filter>
93+
</intent-filter> -->
9494
</activity>
9595
<activity
9696
android:name="com.mikepenz.aboutlibraries.ui.LibsActivity"

app/src/main/java/com/fox2code/mmm/MainApplication.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import android.graphics.Color;
1010
import android.os.Build;
1111
import android.os.SystemClock;
12+
import android.system.ErrnoException;
13+
import android.system.Os;
1214
import android.text.SpannableStringBuilder;
1315
import android.util.Log;
1416

@@ -21,6 +23,7 @@
2123
import com.fox2code.foxcompat.FoxActivity;
2224
import com.fox2code.foxcompat.FoxApplication;
2325
import com.fox2code.foxcompat.FoxThemeWrapper;
26+
import com.fox2code.foxcompat.internal.FoxProcessExt;
2427
import com.fox2code.mmm.installer.InstallerInitializer;
2528
import com.fox2code.mmm.utils.GMSProviderInstaller;
2629
import com.fox2code.mmm.utils.Http;
@@ -46,7 +49,10 @@
4649
import io.noties.prism4j.annotations.PrismBundle;
4750
import io.sentry.JsonObjectWriter;
4851
import io.sentry.NoOpLogger;
52+
import io.sentry.TypeCheckHint;
53+
import io.sentry.UncaughtExceptionHandlerIntegration;
4954
import 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

Comments
 (0)