My brain is melting right now.

pull/27/head
Fox2Code 3 years ago
parent 93c4789107
commit ce03a0b36a

@ -15,11 +15,14 @@ android {
Properties properties = new Properties() Properties properties = new Properties()
if (project.rootProject.file('local.properties').exists()) { if (project.rootProject.file('local.properties').exists()) {
properties.load(project.rootProject.file('local.properties').newDataInputStream()) properties.load(project.rootProject.file('local.properties').newDataInputStream())
// FFS DO NOT CHANGE THIS, IT WILL BREAK THE BUILD // java.lang.IllegalArgumentException: path may not be null or empty string. path='null'
storeFile file(properties.getProperty('keystore.file')) if (properties.getProperty('keystore.file') != null) {
storePassword properties.getProperty('keystore.password') // FFS DO NOT CHANGE THIS, IT WILL BREAK THE BUILD
keyAlias 'key0' storeFile file(properties.getProperty('keystore.file'))
keyPassword properties.getProperty('keystore.password') storePassword properties.getProperty('keystore.password')
keyAlias 'key0'
keyPassword properties.getProperty('keystore.password')
}
} }
} }
} }

@ -47,11 +47,13 @@ import com.fox2code.mmm.manager.ModuleManager;
import com.fox2code.mmm.module.ModuleViewAdapter; import com.fox2code.mmm.module.ModuleViewAdapter;
import com.fox2code.mmm.module.ModuleViewListBuilder; import com.fox2code.mmm.module.ModuleViewListBuilder;
import com.fox2code.mmm.repo.RepoManager; import com.fox2code.mmm.repo.RepoManager;
import com.fox2code.mmm.sentry.SentryMain;
import com.fox2code.mmm.settings.SettingsActivity; import com.fox2code.mmm.settings.SettingsActivity;
import com.fox2code.mmm.utils.BlurUtils; import com.fox2code.mmm.utils.BlurUtils;
import com.fox2code.mmm.utils.ExternalHelper; import com.fox2code.mmm.utils.ExternalHelper;
import com.fox2code.mmm.utils.Http; import com.fox2code.mmm.utils.Http;
import com.fox2code.mmm.utils.IntentHelper; import com.fox2code.mmm.utils.IntentHelper;
import com.fox2code.mmm.utils.ProcessHelper;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.materialswitch.MaterialSwitch; import com.google.android.material.materialswitch.MaterialSwitch;
import com.google.android.material.progressindicator.LinearProgressIndicator; import com.google.android.material.progressindicator.LinearProgressIndicator;
@ -88,6 +90,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
private SearchView searchView; private SearchView searchView;
private boolean initMode; private boolean initMode;
private boolean doSetupNowRunning; private boolean doSetupNowRunning;
private boolean doSetupRestarting;
private boolean urlFactoryInstalled = false; private boolean urlFactoryInstalled = false;
public MainActivity() { public MainActivity() {
@ -180,6 +183,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
this.cardIconifyUpdate(); this.cardIconifyUpdate();
this.updateScreenInsets(this.getResources().getConfiguration()); this.updateScreenInsets(this.getResources().getConfiguration());
checkShowInitialSetup();
InstallerInitializer.tryGetMagiskPathAsync(new InstallerInitializer.Callback() { InstallerInitializer.tryGetMagiskPathAsync(new InstallerInitializer.Callback() {
@Override @Override
public void onPathReceived(String path) { public void onPathReceived(String path) {
@ -201,23 +205,15 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
} }
public void commonNext() { public void commonNext() {
doSetupNowRunning = true; updateScreenInsets(); // Fix an edge case
doSetupNow(); if (waitInitialSetupFinished()) {
return;
// Wait for doSetupNow to finish
while (doSetupNowRunning) {
try {
//noinspection BusyWait
Thread.sleep(100);
} catch (InterruptedException ignored) {
}
} }
/*if (BuildConfig.DEBUG) { /*if (BuildConfig.DEBUG) {
SharedPreferences prefs = MainApplication.getSharedPreferences(); SharedPreferences prefs = MainApplication.getSharedPreferences();
if (BuildConfig.DEBUG) Log.d("MainActivity", String.format("Background update check: %s, Crash reporting: %s, Androidacy repo: %s, Magisk alt repo: %s", prefs.getBoolean("pref_background_update_check", false), prefs.getBoolean("pref_crash_reporting", false), prefs.getBoolean("pref_androidacy_repo_enabled", false), prefs.getBoolean("pref_magisk_alt_repo_enabled", false))); if (BuildConfig.DEBUG) Log.d("MainActivity", String.format("Background update check: %s, Crash reporting: %s, Androidacy repo: %s, Magisk alt repo: %s", prefs.getBoolean("pref_background_update_check", false), prefs.getBoolean("pref_crash_reporting", false), prefs.getBoolean("pref_androidacy_repo_enabled", false), prefs.getBoolean("pref_magisk_alt_repo_enabled", false)));
}*/ }*/
swipeRefreshBlocker = System.currentTimeMillis() + 5_000L; swipeRefreshBlocker = System.currentTimeMillis() + 5_000L;
updateScreenInsets(); // Fix an edge case
if (MainApplication.isShowcaseMode()) if (MainApplication.isShowcaseMode())
moduleViewListBuilder.addNotification(NotificationType.SHOWCASE_MODE); moduleViewListBuilder.addNotification(NotificationType.SHOWCASE_MODE);
if (!Http.hasWebView()) // Check Http for WebView availability if (!Http.hasWebView()) // Check Http for WebView availability
@ -518,7 +514,10 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
@Override @Override
public void onRefresh() { public void onRefresh() {
if (this.swipeRefreshBlocker > System.currentTimeMillis() || this.initMode || this.progressIndicator == null || this.progressIndicator.getVisibility() == View.VISIBLE) { if (this.swipeRefreshBlocker > System.currentTimeMillis() ||
this.initMode || this.progressIndicator == null ||
this.progressIndicator.getVisibility() == View.VISIBLE ||
this.doSetupNowRunning) {
this.swipeRefreshLayout.setRefreshing(false); this.swipeRefreshLayout.setRefreshing(false);
return; // Do not double scan return; // Do not double scan
} }
@ -702,13 +701,14 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
// Method to show a setup box on first launch // Method to show a setup box on first launch
@SuppressLint({"InflateParams", "RestrictedApi", "UnspecifiedImmutableFlag", "ApplySharedPref"}) @SuppressLint({"InflateParams", "RestrictedApi", "UnspecifiedImmutableFlag", "ApplySharedPref"})
private void doSetupNow() { private void checkShowInitialSetup() {
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Do setup now"); if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Do setup now");
// Check if this is the first launch // Check if this is the first launch
SharedPreferences prefs = MainApplication.getSharedPreferences(); SharedPreferences prefs = MainApplication.getSharedPreferences();
boolean firstLaunch = MainApplication.getSharedPreferences().getBoolean("first_launch", true); boolean firstLaunch = prefs.getBoolean("first_launch", true);
if (BuildConfig.DEBUG) Log.d("Noodle", "First launch: " + firstLaunch); if (BuildConfig.DEBUG) Log.d("Noodle", "First launch: " + firstLaunch);
if (firstLaunch) { if (firstLaunch) {
doSetupNowRunning = true;
// Show setup box // Show setup box
runOnUiThread(() -> { runOnUiThread(() -> {
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this); MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this);
@ -720,26 +720,30 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
// For sdk >= 31, use MaterialSwitch instead of MaterialSwitch // For sdk >= 31, use MaterialSwitch instead of MaterialSwitch
// For now, we'll just have the positive button save the preferences and dismiss the dialog // For now, we'll just have the positive button save the preferences and dismiss the dialog
builder.setPositiveButton(R.string.setup_button, (dialog, which) -> { builder.setPositiveButton(R.string.setup_button, (dialog, which) -> {
// Set the preferences // Set the preferences and pref_first_launch to false
prefs.edit().putBoolean("pref_background_update_check", prefs.edit().putBoolean("first_launch", false)
((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_background_update_check))).isChecked()).commit(); .putBoolean("pref_background_update_check", ((MaterialSwitch)
prefs.edit().putBoolean("pref_crash_reporting", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_crash_reporting))).isChecked()).commit(); Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_background_update_check))).isChecked())
prefs.edit().putBoolean("pref_androidacy_repo_enabled", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_androidacy_repo))).isChecked()).commit(); .putBoolean("pref_crash_reporting",
prefs.edit().putBoolean("pref_magisk_alt_repo_enabled", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_magisk_alt_repo))).isChecked()).commit(); ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_crash_reporting))).isChecked())
.putBoolean("pref_androidacy_repo_enabled", ((MaterialSwitch)
Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_androidacy_repo))).isChecked())
.putBoolean("pref_magisk_alt_repo_enabled", ((MaterialSwitch)
Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_magisk_alt_repo))).isChecked()).apply();
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
Log.d("MainActivity", String.format("Background update check: %s, Crash reporting: %s, Androidacy repo: %s, Magisk alt repo: %s", prefs.getBoolean("pref_background_update_check", false), prefs.getBoolean("pref_crash_reporting", false), prefs.getBoolean("pref_androidacy_repo_enabled", false), prefs.getBoolean("pref_magisk_alt_repo_enabled", false))); Log.d("MainActivity", String.format("Background update check: %s, Crash reporting: %s, Androidacy repo: %s, Magisk alt repo: %s",
prefs.getBoolean("pref_background_update_check", false), prefs.getBoolean("pref_crash_reporting", false),
prefs.getBoolean("pref_androidacy_repo_enabled", false), prefs.getBoolean("pref_magisk_alt_repo_enabled", false)));
}
// Only for sentry switching we need to restart I think?
if (SentryMain.isSentryEnabled() != MainApplication.isCrashReportingEnabled()) {
doSetupRestarting = true;
ProcessHelper.restartApplicationProcess(this);
} }
// Set pref_first_launch to false
MainApplication.getSharedPreferences().edit().putBoolean("first_launch", false).commit();
// Restart the app
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(intent);
ensurePermissions(); ensurePermissions();
}); });
builder.setNegativeButton(R.string.setup_button_skip, (dialog, which) -> { builder.setNegativeButton(R.string.setup_button_skip, (dialog, which) -> {
MainApplication.getSharedPreferences().edit().putBoolean("first_launch", false).commit(); MainApplication.getSharedPreferences().edit().putBoolean("first_launch", false).apply();
dialog.dismiss(); dialog.dismiss();
ensurePermissions(); ensurePermissions();
}); });
@ -755,4 +759,22 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
ensurePermissions(); ensurePermissions();
} }
} }
/**
* @return true if the load workflow must be stopped.
*/
private boolean waitInitialSetupFinished() {
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "waitInitialSetupFinished");
if (doSetupNowRunning) updateScreenInsets(); // Fix an edge case
try {
// Wait for doSetupNow to finish
while (doSetupNowRunning) {
//noinspection BusyWait
Thread.sleep(50);
}
} catch (InterruptedException e) {
return true;
}
return doSetupRestarting;
}
} }

@ -61,6 +61,7 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
@SuppressLint("StaticFieldLeak") @SuppressLint("StaticFieldLeak")
private static MainApplication INSTANCE; private static MainApplication INSTANCE;
private static boolean firstBoot; private static boolean firstBoot;
private static boolean loadSentryInitialized;
static { static {
Shell.setDefaultBuilder(shellBuilder = Shell.Builder.create().setFlags(Shell.FLAG_REDIRECT_STDERR).setTimeout(10).setInitializers(InstallerInitializer.class)); Shell.setDefaultBuilder(shellBuilder = Shell.Builder.create().setFlags(Shell.FLAG_REDIRECT_STDERR).setTimeout(10).setInitializers(InstallerInitializer.class));
@ -168,7 +169,9 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
} }
public static boolean isCrashReportingEnabled() { public static boolean isCrashReportingEnabled() {
return getSharedPreferences().getBoolean("pref_crash_reporting", BuildConfig.DEFAULT_ENABLE_CRASH_REPORTING); return SentryMain.IS_SENTRY_INSTALLED &&
getSharedPreferences().getBoolean("pref_crash_reporting",
BuildConfig.DEFAULT_ENABLE_CRASH_REPORTING);
} }
public static SharedPreferences getBootSharedPreferences() { public static SharedPreferences getBootSharedPreferences() {
@ -306,7 +309,6 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
Log.d("MainApplication", "Emoji compat loaded!"); Log.d("MainApplication", "Emoji compat loaded!");
}, "Emoji compat init.").start(); }, "Emoji compat init.").start();
} }
SentryMain.initialize(this); SentryMain.initialize(this);
if (Objects.equals(BuildConfig.ANDROIDACY_CLIENT_ID, "")) { if (Objects.equals(BuildConfig.ANDROIDACY_CLIENT_ID, "")) {
Log.w("MainApplication", "Androidacy client id is empty! Please set it in androidacy" + ".properties. Will not enable Androidacy."); Log.w("MainApplication", "Androidacy client id is empty! Please set it in androidacy" + ".properties. Will not enable Androidacy.");

@ -62,6 +62,7 @@ import com.fox2code.mmm.sentry.SentryMain;
import com.fox2code.mmm.utils.ExternalHelper; import com.fox2code.mmm.utils.ExternalHelper;
import com.fox2code.mmm.utils.Http; import com.fox2code.mmm.utils.Http;
import com.fox2code.mmm.utils.IntentHelper; import com.fox2code.mmm.utils.IntentHelper;
import com.fox2code.mmm.utils.ProcessHelper;
import com.fox2code.rosettax.LanguageActivity; import com.fox2code.rosettax.LanguageActivity;
import com.fox2code.rosettax.LanguageSwitcher; import com.fox2code.rosettax.LanguageSwitcher;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
@ -148,14 +149,7 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
@Override @Override
@SuppressLint("InlinedApi") @SuppressLint("InlinedApi")
public void refreshRosettaX() { public void refreshRosettaX() {
Intent mStartActivity = new Intent(this, MainActivity.class); ProcessHelper.restartApplicationProcess(this);
mStartActivity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
int mPendingIntentId = 123456;
PendingIntent mPendingIntent = PendingIntent.getActivity(this, mPendingIntentId,
mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE);
AlarmManager mgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
System.exit(0); // Exit app process
} }
@Override @Override

@ -0,0 +1,22 @@
package com.fox2code.mmm.utils;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import com.fox2code.mmm.MainActivity;
public class ProcessHelper {
private static final int sPendingIntentId = 123456;
public static void restartApplicationProcess(Context context) {
Intent mStartActivity = new Intent(context, MainActivity.class);
mStartActivity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent mPendingIntent = PendingIntent.getActivity(context, sPendingIntentId,
mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE);
AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
System.exit(0); // Exit app process
}
}

@ -17,6 +17,7 @@ import io.sentry.android.fragment.FragmentLifecycleIntegration;
public class SentryMain { public class SentryMain {
public static final boolean IS_SENTRY_INSTALLED = true; public static final boolean IS_SENTRY_INSTALLED = true;
private static final String TAG = "SentryMain"; private static final String TAG = "SentryMain";
private static boolean sentryEnabled = false;
/** /**
* Initialize Sentry * Initialize Sentry
@ -39,6 +40,7 @@ public class SentryMain {
if (!MainApplication.isCrashReportingEnabled()) { if (!MainApplication.isCrashReportingEnabled()) {
options.setDsn(""); options.setDsn("");
} else { } else {
sentryEnabled = true; // Set sentry state to enabled
options.addIntegration(new FragmentLifecycleIntegration(mainApplication, true, true)); options.addIntegration(new FragmentLifecycleIntegration(mainApplication, true, true));
options.setCollectAdditionalContext(true); options.setCollectAdditionalContext(true);
options.setAttachThreads(true); options.setAttachThreads(true);
@ -82,4 +84,8 @@ public class SentryMain {
Sentry.addBreadcrumb(sentryBreadcrumb.breadcrumb); Sentry.addBreadcrumb(sentryBreadcrumb.breadcrumb);
} }
} }
public static boolean isSentryEnabled() {
return sentryEnabled;
}
} }

@ -8,4 +8,6 @@ public class SentryMain {
public static void initialize(MainApplication mainApplication) {} public static void initialize(MainApplication mainApplication) {}
public static void addSentryBreadcrumb(SentryBreadcrumb sentryBreadcrumb) {} public static void addSentryBreadcrumb(SentryBreadcrumb sentryBreadcrumb) {}
public static boolean isSentryEnabled() { return false; }
} }

Loading…
Cancel
Save