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

Commit e181fd1

Browse files
Merge pull request #1 from Fox2CodeCoProcessor/master
Fix and improve previous commit & Update libraries
2 parents 9c2d361 + c6482ca commit e181fd1

File tree

5 files changed

+72
-24
lines changed

5 files changed

+72
-24
lines changed

app/build.gradle

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ android {
1212
minSdk 21
1313
targetSdk 33
1414
versionCode 54
15-
versionName "0.7.0-dev"
15+
versionName "0.6.2"
1616

1717
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1818
}
@@ -35,6 +35,7 @@ android {
3535
"default" {
3636
dimension "type"
3737
buildConfigField "boolean", "ENABLE_AUTO_UPDATER", "true"
38+
buildConfigField "boolean", "DEFAULT_ENABLE_CRASH_REPORTING", "true"
3839
buildConfigField(
3940
"java.util.List<String>",
4041
"ENABLED_REPOS",
@@ -51,6 +52,9 @@ android {
5152
// with our keys, so the APK wouldn't install anyways).
5253
buildConfigField "boolean", "ENABLE_AUTO_UPDATER", "false"
5354

55+
// Respect privacy paranoiac nature of F-Droid builds
56+
buildConfigField "boolean", "DEFAULT_ENABLE_CRASH_REPORTING", "false"
57+
5458
// Repo with ads or tracking feature are disabled by default for the
5559
// F-Droid flavor.
5660
buildConfigField(
@@ -88,9 +92,10 @@ dependencies {
8892
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
8993
implementation 'androidx.recyclerview:recyclerview:1.2.1'
9094
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
91-
implementation 'androidx.webkit:webkit:1.4.0'
95+
implementation 'androidx.webkit:webkit:1.5.0'
9296
implementation 'com.google.android.material:material:1.6.1'
93-
implementation 'com.mikepenz:aboutlibraries:10.4.1-a01'
97+
// Update root build.gradle instead.
98+
implementation "com.mikepenz:aboutlibraries:${latestAboutLibsRelease}"
9499
implementation "dev.rikka.rikkax.layoutinflater:layoutinflater:1.2.0"
95100
implementation "dev.rikka.rikkax.insets:insets:1.3.0"
96101
implementation 'com.github.Dimezis:BlurView:version-1.6.6'

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,6 @@ protected void onResume() {
7474

7575
@Override
7676
protected void onCreate(Bundle savedInstanceState) {
77-
SentryAndroid.init(this, options -> {
78-
// Add a callback that will be used before the event is sent to Sentry.
79-
// With this callback, you can modify the event or, when returning null, also discard the event.
80-
options.setBeforeSend((event, hint) -> {
81-
// Check saved preferences to see if the user has opted out of crash reporting.
82-
// If the user has opted out, return null.
83-
if (SettingsActivity.getCrashReporting(this)) {
84-
return event;
85-
} else {
86-
return null;
87-
}
88-
});
89-
});
9077
this.initMode = true;
9178
BackgroundUpdateChecker.onMainActivityCreate(this);
9279
super.onCreate(savedInstanceState);

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import com.fox2code.rosettax.LanguageSwitcher;
2828
import com.topjohnwu.superuser.Shell;
2929

30+
import java.io.IOException;
31+
import java.io.Writer;
3032
import java.text.SimpleDateFormat;
3133
import java.util.Date;
3234
import java.util.Locale;
@@ -42,13 +44,17 @@
4244
import io.noties.markwon.syntax.SyntaxHighlightPlugin;
4345
import io.noties.prism4j.Prism4j;
4446
import io.noties.prism4j.annotations.PrismBundle;
47+
import io.sentry.JsonObjectWriter;
48+
import io.sentry.NoOpLogger;
49+
import io.sentry.android.core.SentryAndroid;
4550

4651
@PrismBundle(
4752
includeAll = true,
4853
grammarLocatorClassName = ".Prism4jGrammarLocator"
4954
)
5055
public class MainApplication extends FoxApplication
5156
implements androidx.work.Configuration.Provider {
57+
private static final String TAG = "MainApplication";
5258
private static final String timeFormatString = "dd MMM yyyy"; // Example: 13 july 2001
5359
private static Locale timeFormatLocale =
5460
Resources.getSystem().getConfiguration().locale;
@@ -168,6 +174,11 @@ public static void setHasGottenRootAccess(boolean bool) {
168174
getSharedPreferences().edit().putBoolean("has_root_access", bool).apply();
169175
}
170176

177+
public static boolean isCrashReportingEnabled() {
178+
return getSharedPreferences().getBoolean(
179+
"crash_reporting", BuildConfig.DEFAULT_ENABLE_CRASH_REPORTING);
180+
}
181+
171182
public static SharedPreferences getBootSharedPreferences() {
172183
return bootSharedPreferences;
173184
}
@@ -341,6 +352,57 @@ public void onCreate() {
341352
Log.d("MainApplication", "Emoji compat loaded!");
342353
}, "Emoji compat init.").start();
343354
}
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+
});
344406
}
345407

346408
@Override

app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
6262
private static final String TAG = "SettingsActivity";
6363
private static int devModeStep = 0;
6464

65-
public static boolean getCrashReporting(MainActivity mainActivity) {
66-
return mainActivity.getPreferences(Context.MODE_PRIVATE)
67-
.getBoolean("crash_reporting", true);
68-
}
69-
7065
@Override
7166
protected void onCreate(Bundle savedInstanceState) {
7267
devModeStep = 0;
@@ -132,8 +127,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
132127
});
133128
// Crash reporting
134129
TwoStatePreference crashReportingPreference = findPreference("pref_crash_reporting");
135-
crashReportingPreference.setChecked(getCrashReporting(
136-
(MainActivity) requireActivity()));
130+
crashReportingPreference.setChecked(MainApplication.isCrashReportingEnabled());
137131
crashReportingPreference.setOnPreferenceChangeListener((preference, newValue) -> {
138132
devModeStep = 0;
139133
getCrashReportingEditor(requireActivity()).putBoolean("crash_reporting",

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
project.ext.latestAboutLibsRelease = "10.4.1-a01"
99
dependencies {
1010
classpath 'com.android.tools.build:gradle:7.2.2'
11-
classpath "com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:10.4.1-a01"
11+
classpath "com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:${latestAboutLibsRelease}"
1212

1313
// NOTE: Do not place your application dependencies here; they belong
1414
// in the individual module build.gradle files

0 commit comments

Comments
 (0)