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

Commit bf92f58

Browse files
committed
Disable sentry on F-Droid flavor
1 parent 7a7b829 commit bf92f58

File tree

11 files changed

+212
-103
lines changed

11 files changed

+212
-103
lines changed

app/build.gradle

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ aboutLibraries {
7979
}
8080

8181
sentry {
82+
// Disable sentry on F-Droid flavor
83+
ignoredFlavors = [ "fdroid" ]
84+
8285
// Disables or enables the handling of Proguard mapping for Sentry.
8386
// If enabled the plugin will generate a UUID and will take care of
8487
// uploading the mapping to Sentry. If disabled, all the logic
@@ -137,7 +140,6 @@ sentry {
137140

138141
configurations {
139142
implementation.exclude group: 'org.jetbrains', module: 'annotations'
140-
implementation.exclude group: 'io.sentry', module: 'sentry-android-okhttp'
141143
}
142144

143145
dependencies {
@@ -156,7 +158,7 @@ dependencies {
156158
implementation "dev.rikka.rikkax.insets:insets:1.3.0"
157159
implementation 'com.github.Dimezis:BlurView:version-1.6.6'
158160
implementation 'com.github.KieronQuinn:MonetCompat:0.4.1'
159-
implementation 'com.github.Fox2Code:FoxCompat:0.1.4b'
161+
implementation 'com.github.Fox2Code:FoxCompat:0.1.5'
160162

161163
// Utils
162164
implementation 'androidx.work:work-runtime:2.7.1'
@@ -167,11 +169,11 @@ dependencies {
167169
implementation 'com.github.Fox2Code:AndroidANSI:1.0.1'
168170

169171
// Error reporting
170-
implementation 'io.sentry:sentry-android:6.4.1'
171-
implementation 'io.sentry:sentry-android-fragment:6.4.1'
172-
implementation 'io.sentry:sentry-android-okhttp:6.4.1'
173-
implementation 'io.sentry:sentry-android-core:6.4.1'
174-
implementation 'io.sentry:sentry-android-ndk:6.4.1'
172+
defaultImplementation 'io.sentry:sentry-android:6.4.1'
173+
defaultImplementation 'io.sentry:sentry-android-fragment:6.4.1'
174+
defaultImplementation 'io.sentry:sentry-android-okhttp:6.4.1'
175+
defaultImplementation 'io.sentry:sentry-android-core:6.4.1'
176+
defaultImplementation 'io.sentry:sentry-android-ndk:6.4.1'
175177

176178
// Markdown
177179
implementation "io.noties.markwon:core:4.6.2"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
tools:ignore="QueryAllPackagesPermission">
5+
6+
<application android:icon="@mipmap/ic_launcher">
7+
<meta-data android:name="io.sentry.auto-init" android:value="false" />
8+
<meta-data
9+
android:name="io.sentry.dsn"
10+
android:value="https://cdcdb0efca4a42a28df90e4b7f087347@sentry.androidacy.com/2" />
11+
<!-- Sane value, but feel free to lower it -->
12+
<meta-data
13+
android:name="io.sentry.traces.sample-rate"
14+
android:value="0.5" />
15+
<!-- Doesn't actually monitor anything, just used to get the activities the user went through -->
16+
<meta-data
17+
android:name="io.sentry.traces.user-interaction.enable"
18+
android:value="true" />
19+
<!-- Just a screenshot of ONLY the current activity at the time of the crash -->
20+
<meta-data
21+
android:name="io.sentry.attach-screenshot"
22+
android:value="true" />
23+
</application>
24+
</manifest>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.fox2code.mmm.sentry;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
import org.jetbrains.annotations.Nullable;
5+
6+
import java.util.Objects;
7+
8+
import io.sentry.Breadcrumb;
9+
import io.sentry.SentryLevel;
10+
11+
public class SentryBreadcrumb {
12+
final Breadcrumb breadcrumb;
13+
14+
public SentryBreadcrumb() {
15+
breadcrumb = new Breadcrumb();
16+
breadcrumb.setLevel(SentryLevel.INFO);
17+
}
18+
19+
public void setType(@Nullable String type) {
20+
breadcrumb.setType(type);
21+
}
22+
23+
public void setData(@NotNull String key, @NotNull Object value) {
24+
Objects.requireNonNull(key);
25+
Objects.requireNonNull(value);
26+
breadcrumb.setData(key, value);
27+
}
28+
29+
public void setCategory(@Nullable String category) {
30+
breadcrumb.setCategory(category);
31+
}
32+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.fox2code.mmm.sentry;
2+
3+
import android.util.Log;
4+
5+
import com.fox2code.mmm.BuildConfig;
6+
import com.fox2code.mmm.MainApplication;
7+
8+
import java.io.IOException;
9+
import java.io.Writer;
10+
11+
import io.sentry.JsonObjectWriter;
12+
import io.sentry.NoOpLogger;
13+
import io.sentry.Sentry;
14+
import io.sentry.TypeCheckHint;
15+
import io.sentry.android.core.SentryAndroid;
16+
import io.sentry.android.fragment.FragmentLifecycleIntegration;
17+
import io.sentry.hints.DiskFlushNotification;
18+
19+
public class SentryMain {
20+
public static final boolean IS_SENTRY_INSTALLED = true;
21+
private static final String TAG = "SentryMain";
22+
23+
public static void initialize(final MainApplication mainApplication) {
24+
SentryAndroid.init(mainApplication, options -> {
25+
// If crash reporting is disabled, stop here.
26+
if (!MainApplication.isCrashReportingEnabled()) {
27+
options.setDsn("");
28+
} else {
29+
options.addIntegration(new FragmentLifecycleIntegration(mainApplication, true, true));
30+
// Sentry sends ABSOLUTELY NO Personally Identifiable Information (PII) by default.
31+
// Already set to false by default, just set it again to make peoples feel safer.
32+
options.setSendDefaultPii(false);
33+
// It just tell if sentry should ping the sentry dsn to tell the app is running.
34+
// This is not needed at all for crash reporting purposes, so disable it.
35+
options.setEnableAutoSessionTracking(false);
36+
// A screenshot of the app itself is only sent if the app crashes, and it only shows the last activity
37+
// In addition, sentry is configured with a trusted third party other than sentry.io, and only trusted people have access to the sentry instance
38+
// Add a callback that will be used before the event is sent to Sentry.
39+
// With this callback, you can modify the event or, when returning null, also discard the event.
40+
options.setBeforeSend((event, hint) -> {
41+
if (BuildConfig.DEBUG) { // Debug sentry events for debug.
42+
StringBuilder stringBuilder = new StringBuilder("Sentry report debug: ");
43+
try {
44+
event.serialize(new JsonObjectWriter(new Writer() {
45+
@Override
46+
public void write(char[] cbuf) {
47+
stringBuilder.append(cbuf);
48+
}
49+
50+
@Override
51+
public void write(String str) {
52+
stringBuilder.append(str);
53+
}
54+
55+
@Override
56+
public void write(char[] chars, int i, int i1) {
57+
stringBuilder.append(chars, i, i1);
58+
}
59+
60+
@Override
61+
public void write(String str, int off, int len) {
62+
stringBuilder.append(str, off, len);
63+
}
64+
65+
@Override
66+
public void flush() {
67+
}
68+
69+
@Override
70+
public void close() {
71+
}
72+
}, 4), NoOpLogger.getInstance());
73+
} catch (IOException ignored) {
74+
}
75+
Log.i(TAG, stringBuilder.toString());
76+
}
77+
if (MainApplication.isCrashReportingEnabled()) {
78+
return event;
79+
} else {
80+
// We need to do this to avoid crash delay on crash when the event is dropped
81+
DiskFlushNotification diskFlushNotification = hint.getAs(
82+
TypeCheckHint.SENTRY_TYPE_CHECK_HINT, DiskFlushNotification.class);
83+
if (diskFlushNotification != null) diskFlushNotification.markFlushed();
84+
return null;
85+
}
86+
});
87+
}
88+
89+
});
90+
}
91+
92+
public static void addSentryBreadcrumb(SentryBreadcrumb sentryBreadcrumb) {
93+
if (MainApplication.isCrashReportingEnabled()) {
94+
Sentry.addBreadcrumb(sentryBreadcrumb.breadcrumb);
95+
}
96+
}
97+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.fox2code.mmm.sentry;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
import org.jetbrains.annotations.Nullable;
5+
6+
import java.util.Objects;
7+
8+
public class SentryBreadcrumb {
9+
public SentryBreadcrumb() {}
10+
11+
public void setType(@Nullable String type) {}
12+
13+
public void setData(@NotNull String key, @NotNull Object value) {
14+
Objects.requireNonNull(key);
15+
Objects.requireNonNull(value);
16+
}
17+
18+
public void setCategory(@Nullable String category) {}
19+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.fox2code.mmm.sentry;
2+
3+
import com.fox2code.mmm.MainApplication;
4+
5+
public class SentryMain {
6+
public static final boolean IS_SENTRY_INSTALLED = false;
7+
8+
public static void initialize(MainApplication mainApplication) {}
9+
10+
public static void addSentryBreadcrumb(SentryBreadcrumb sentryBreadcrumb) {}
11+
}

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
</queries>
1111

1212
<!-- Wifi is not the only way to get an internet connection -->
13-
<uses-feature
14-
android:name="android.hardware.wifi"
15-
android:required="false" />
13+
<uses-feature android:name="android.hardware.wifi" android:required="false" />
1614

1715
<!-- Retrieve online modules -->
1816
<uses-permission android:name="android.permission.INTERNET" />
@@ -113,21 +111,5 @@
113111
android:name="androidx.work.WorkManagerInitializer"
114112
tools:node="remove" />
115113
</provider>
116-
<meta-data android:name="io.sentry.auto-init" android:value="false" />
117-
<meta-data
118-
android:name="io.sentry.dsn"
119-
android:value="https://cdcdb0efca4a42a28df90e4b7f087347@sentry.androidacy.com/2" />
120-
<!-- Sane value, but feel free to lower it -->
121-
<meta-data
122-
android:name="io.sentry.traces.sample-rate"
123-
android:value="0.5" />
124-
<!-- Doesn't actually monitor anything, just used to get the activities the user went through -->
125-
<meta-data
126-
android:name="io.sentry.traces.user-interaction.enable"
127-
android:value="true" />
128-
<!-- Just a screenshot of ONLY the current activity at the time of the crash -->
129-
<meta-data
130-
android:name="io.sentry.attach-screenshot"
131-
android:value="true" />
132114
</application>
133115
</manifest>

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

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.fox2code.foxcompat.FoxThemeWrapper;
2424
import com.fox2code.foxcompat.internal.FoxProcessExt;
2525
import com.fox2code.mmm.installer.InstallerInitializer;
26+
import com.fox2code.mmm.sentry.SentryMain;
2627
import com.fox2code.mmm.utils.GMSProviderInstaller;
2728
import com.fox2code.mmm.utils.Http;
2829
import com.fox2code.rosettax.LanguageSwitcher;
@@ -366,60 +367,7 @@ public void onCreate() {
366367
}, "Emoji compat init.").start();
367368
}
368369

369-
SentryAndroid.init(this, options -> {
370-
// If crash reporting is disabled, stop here.
371-
if (!isCrashReportingEnabled()) {
372-
options.setDsn("");
373-
} else {
374-
options.addIntegration(new FragmentLifecycleIntegration(this, true, true));
375-
// Sentry sends ABSOLUTELY NO Personally Identifiable Information (PII) by default.
376-
// A screenshot of the app itself is only sent if the app crashes, and it only shows the last activity
377-
// In addition, sentry is configured with a trusted third party other than sentry.io, and only trusted people have access to the sentry instance
378-
// Add a callback that will be used before the event is sent to Sentry.
379-
// With this callback, you can modify the event or, when returning null, also discard the event.
380-
options.setBeforeSend((event, hint) -> {
381-
if (BuildConfig.DEBUG) { // Debug sentry events for debug.
382-
StringBuilder stringBuilder = new StringBuilder("Sentry report debug: ");
383-
try {
384-
event.serialize(new JsonObjectWriter(new Writer() {
385-
@Override
386-
public void write(char[] cbuf) {
387-
stringBuilder.append(cbuf);
388-
}
389-
390-
@Override
391-
public void write(String str) {
392-
stringBuilder.append(str);
393-
}
394-
395-
@Override
396-
public void write(char[] chars, int i, int i1) {
397-
stringBuilder.append(chars, i, i1);
398-
}
399-
400-
@Override
401-
public void write(String str, int off, int len) {
402-
stringBuilder.append(str, off, len);
403-
}
404-
405-
@Override
406-
public void flush() {
407-
}
408-
409-
@Override
410-
public void close() {
411-
}
412-
}, 4), NoOpLogger.getInstance());
413-
} catch (IOException ignored) {
414-
}
415-
Log.i(TAG, stringBuilder.toString());
416-
}
417-
// We already know that the user has opted in to crash reporting, so we don't need to ask again.
418-
return event;
419-
});
420-
}
421-
422-
});
370+
SentryMain.initialize(this);
423371
}
424372

425373
@Override

app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import com.fox2code.mmm.R;
2525
import com.fox2code.mmm.XHooks;
2626
import com.fox2code.mmm.module.ActionButtonType;
27+
import com.fox2code.mmm.sentry.SentryBreadcrumb;
28+
import com.fox2code.mmm.sentry.SentryMain;
2729
import com.fox2code.mmm.utils.FastException;
2830
import com.fox2code.mmm.utils.Files;
2931
import com.fox2code.mmm.utils.Hashes;
@@ -50,10 +52,6 @@
5052
import java.util.zip.ZipFile;
5153
import java.util.zip.ZipInputStream;
5254

53-
import io.sentry.Breadcrumb;
54-
import io.sentry.Sentry;
55-
import io.sentry.SentryLevel;
56-
5755
public class InstallerActivity extends FoxActivity {
5856
private static final String TAG = "InstallerActivity";
5957
public LinearProgressIndicator progressIndicator;
@@ -109,14 +107,13 @@ protected void onCreate(Bundle savedInstanceState) {
109107
Log.i(TAG, "Install link: " + target);
110108
// Note: Sentry only send this info on crash.
111109
if (MainApplication.isCrashReportingEnabled()) {
112-
Breadcrumb breadcrumb = new Breadcrumb();
110+
SentryBreadcrumb breadcrumb = new SentryBreadcrumb();
113111
breadcrumb.setType("install");
114112
breadcrumb.setData("target", target);
115113
breadcrumb.setData("name", name);
116114
breadcrumb.setData("checksum", checksum);
117115
breadcrumb.setCategory("app.action.preinstall");
118-
breadcrumb.setLevel(SentryLevel.INFO);
119-
Sentry.addBreadcrumb(breadcrumb);
116+
SentryMain.addSentryBreadcrumb(breadcrumb);
120117
}
121118
boolean urlMode = target.startsWith("http://") || target.startsWith("https://");
122119
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
@@ -450,7 +447,7 @@ private void doInstall(File file, boolean noExtensions, boolean rootless) {
450447
}
451448
// Note: Sentry only send this info on crash.
452449
if (MainApplication.isCrashReportingEnabled()) {
453-
Breadcrumb breadcrumb = new Breadcrumb();
450+
SentryBreadcrumb breadcrumb = new SentryBreadcrumb();
454451
breadcrumb.setType("install");
455452
breadcrumb.setData("moduleId", moduleId == null ? "<null>" : moduleId);
456453
breadcrumb.setData("mmtReborn", mmtReborn ? "true" : "false");
@@ -460,8 +457,7 @@ private void doInstall(File file, boolean noExtensions, boolean rootless) {
460457
breadcrumb.setData("ansi", this.installerTerminal
461458
.isAnsiEnabled() ? "enabled" : "disabled");
462459
breadcrumb.setCategory("app.action.install");
463-
breadcrumb.setLevel(SentryLevel.INFO);
464-
Sentry.addBreadcrumb(breadcrumb);
460+
SentryMain.addSentryBreadcrumb(breadcrumb);
465461
}
466462
if (mmtReborn && magiskCmdLine) {
467463
Log.w(TAG, "mmtReborn and magiskCmdLine may not work well together");

0 commit comments

Comments
 (0)