My brain is melting right now.

pull/258/head
Fox2Code 1 year ago
parent 93c4789107
commit ce03a0b36a

@ -15,11 +15,14 @@ android {
Properties properties = new Properties()
if (project.rootProject.file('local.properties').exists()) {
properties.load(project.rootProject.file('local.properties').newDataInputStream())
// FFS DO NOT CHANGE THIS, IT WILL BREAK THE BUILD
storeFile file(properties.getProperty('keystore.file'))
storePassword properties.getProperty('keystore.password')
keyAlias 'key0'
keyPassword properties.getProperty('keystore.password')
// java.lang.IllegalArgumentException: path may not be null or empty string. path='null'
if (properties.getProperty('keystore.file') != null) {
// FFS DO NOT CHANGE THIS, IT WILL BREAK THE BUILD
storeFile file(properties.getProperty('keystore.file'))
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.ModuleViewListBuilder;
import com.fox2code.mmm.repo.RepoManager;
import com.fox2code.mmm.sentry.SentryMain;
import com.fox2code.mmm.settings.SettingsActivity;
import com.fox2code.mmm.utils.BlurUtils;
import com.fox2code.mmm.utils.ExternalHelper;
import com.fox2code.mmm.utils.Http;
import com.fox2code.mmm.utils.IntentHelper;
import com.fox2code.mmm.utils.ProcessHelper;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.materialswitch.MaterialSwitch;
import com.google.android.material.progressindicator.LinearProgressIndicator;
@ -88,6 +90,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
private SearchView searchView;
private boolean initMode;
private boolean doSetupNowRunning;
private boolean doSetupRestarting;
private boolean urlFactoryInstalled = false;
public MainActivity() {
@ -180,6 +183,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
this.cardIconifyUpdate();
this.updateScreenInsets(this.getResources().getConfiguration());
checkShowInitialSetup();
InstallerInitializer.tryGetMagiskPathAsync(new InstallerInitializer.Callback() {
@Override
public void onPathReceived(String path) {
@ -201,23 +205,15 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
}
public void commonNext() {
doSetupNowRunning = true;
doSetupNow();
// Wait for doSetupNow to finish
while (doSetupNowRunning) {
try {
//noinspection BusyWait
Thread.sleep(100);
} catch (InterruptedException ignored) {
}
updateScreenInsets(); // Fix an edge case
if (waitInitialSetupFinished()) {
return;
}
/*if (BuildConfig.DEBUG) {
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)));
}*/
swipeRefreshBlocker = System.currentTimeMillis() + 5_000L;
updateScreenInsets(); // Fix an edge case
if (MainApplication.isShowcaseMode())
moduleViewListBuilder.addNotification(NotificationType.SHOWCASE_MODE);
if (!Http.hasWebView()) // Check Http for WebView availability
@ -518,7 +514,10 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
@Override
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);
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
@SuppressLint({"InflateParams", "RestrictedApi", "UnspecifiedImmutableFlag", "ApplySharedPref"})
private void doSetupNow() {
private void checkShowInitialSetup() {
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Do setup now");
// Check if this is the first launch
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 (firstLaunch) {
doSetupNowRunning = true;
// Show setup box
runOnUiThread(() -> {
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 now, we'll just have the positive button save the preferences and dismiss the dialog
builder.setPositiveButton(R.string.setup_button, (dialog, which) -> {
// Set the preferences
prefs.edit().putBoolean("pref_background_update_check",
((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_background_update_check))).isChecked()).commit();
prefs.edit().putBoolean("pref_crash_reporting", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_crash_reporting))).isChecked()).commit();
prefs.edit().putBoolean("pref_androidacy_repo_enabled", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_androidacy_repo))).isChecked()).commit();
prefs.edit().putBoolean("pref_magisk_alt_repo_enabled", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_magisk_alt_repo))).isChecked()).commit();
// Set the preferences and pref_first_launch to false
prefs.edit().putBoolean("first_launch", false)
.putBoolean("pref_background_update_check", ((MaterialSwitch)
Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_background_update_check))).isChecked())
.putBoolean("pref_crash_reporting",
((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) {
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();
});
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();
ensurePermissions();
});
@ -755,4 +759,22 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
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")
private static MainApplication INSTANCE;
private static boolean firstBoot;
private static boolean loadSentryInitialized;
static {
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() {
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() {
@ -306,7 +309,6 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
Log.d("MainApplication", "Emoji compat loaded!");
}, "Emoji compat init.").start();
}
SentryMain.initialize(this);
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.");

@ -62,6 +62,7 @@ import com.fox2code.mmm.sentry.SentryMain;
import com.fox2code.mmm.utils.ExternalHelper;
import com.fox2code.mmm.utils.Http;
import com.fox2code.mmm.utils.IntentHelper;
import com.fox2code.mmm.utils.ProcessHelper;
import com.fox2code.rosettax.LanguageActivity;
import com.fox2code.rosettax.LanguageSwitcher;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
@ -148,14 +149,7 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
@Override
@SuppressLint("InlinedApi")
public void refreshRosettaX() {
Intent mStartActivity = new Intent(this, MainActivity.class);
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
ProcessHelper.restartApplicationProcess(this);
}
@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 static final boolean IS_SENTRY_INSTALLED = true;
private static final String TAG = "SentryMain";
private static boolean sentryEnabled = false;
/**
* Initialize Sentry
@ -39,6 +40,7 @@ public class SentryMain {
if (!MainApplication.isCrashReportingEnabled()) {
options.setDsn("");
} else {
sentryEnabled = true; // Set sentry state to enabled
options.addIntegration(new FragmentLifecycleIntegration(mainApplication, true, true));
options.setCollectAdditionalContext(true);
options.setAttachThreads(true);
@ -82,4 +84,8 @@ public class SentryMain {
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 addSentryBreadcrumb(SentryBreadcrumb sentryBreadcrumb) {}
public static boolean isSentryEnabled() { return false; }
}

Loading…
Cancel
Save