(fix) updates to pref handling

Signed-off-by: androidacy-user <opensource@androidacy.com>
master
androidacy-user 1 year ago
parent 767a1fa7cd
commit 2925b6a8c6

@ -415,7 +415,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
} }
Timber.d("Preference changed: %s", key); Timber.d("Preference changed: %s", key);
}; };
MainApplication.getPreferences("mmm").registerOnSharedPreferenceChangeListener(listener); MainApplication.getSharedPreferences("mmm").registerOnSharedPreferenceChangeListener(listener);
} }
private void cardIconifyUpdate() { private void cardIconifyUpdate() {
@ -760,7 +760,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
private void checkShowInitialSetup() { private void checkShowInitialSetup() {
if (BuildConfig.DEBUG) Timber.i("Checking if we need to run setup"); if (BuildConfig.DEBUG) Timber.i("Checking if we need to run setup");
// Check if this is the first launch using prefs and if doSetupRestarting was passed in the intent // Check if this is the first launch using prefs and if doSetupRestarting was passed in the intent
SharedPreferences prefs = MainApplication.getPreferences("mmm"); SharedPreferences prefs = MainApplication.getSharedPreferences("mmm");
boolean firstLaunch = !Objects.equals(prefs.getString("last_shown_setup", null), "v1"); boolean firstLaunch = !Objects.equals(prefs.getString("last_shown_setup", null), "v1");
// First launch // First launch
// this is intentionally separate from the above if statement, because it needs to be checked even if the first launch check is true due to some weird edge cases // this is intentionally separate from the above if statement, because it needs to be checked even if the first launch check is true due to some weird edge cases

@ -146,9 +146,10 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
intent.putExtra("secret", secret); intent.putExtra("secret", secret);
} }
public static SharedPreferences getPreferences(String name) { public static SharedPreferences getSharedPreferences(String name) {
// encryptedSharedPreferences is used // encryptedSharedPreferences is used
Context mContext = getINSTANCE(); Context mContext = getINSTANCE();
name = name + "x";
if (mSharedPrefs == null) { if (mSharedPrefs == null) {
Timber.d("Creating shared prefs map"); Timber.d("Creating shared prefs map");
mSharedPrefs = new HashMap<>(); mSharedPrefs = new HashMap<>();
@ -202,50 +203,50 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
// convert from String to boolean // convert from String to boolean
return Boolean.parseBoolean(SHOWCASE_MODE_TRUE); return Boolean.parseBoolean(SHOWCASE_MODE_TRUE);
} }
boolean showcaseMode = getPreferences("mmm").getBoolean("pref_showcase_mode", false); boolean showcaseMode = getSharedPreferences("mmm").getBoolean("pref_showcase_mode", false);
SHOWCASE_MODE_TRUE = String.valueOf(showcaseMode); SHOWCASE_MODE_TRUE = String.valueOf(showcaseMode);
return showcaseMode; return showcaseMode;
} }
public static boolean shouldPreventReboot() { public static boolean shouldPreventReboot() {
return getPreferences("mmm").getBoolean("pref_prevent_reboot", true); return getSharedPreferences("mmm").getBoolean("pref_prevent_reboot", true);
} }
public static boolean isShowIncompatibleModules() { public static boolean isShowIncompatibleModules() {
return getPreferences("mmm").getBoolean("pref_show_incompatible", false); return getSharedPreferences("mmm").getBoolean("pref_show_incompatible", false);
} }
public static boolean isForceDarkTerminal() { public static boolean isForceDarkTerminal() {
return getPreferences("mmm").getBoolean("pref_force_dark_terminal", false); return getSharedPreferences("mmm").getBoolean("pref_force_dark_terminal", false);
} }
public static boolean isTextWrapEnabled() { public static boolean isTextWrapEnabled() {
return getPreferences("mmm").getBoolean("pref_wrap_text", false); return getSharedPreferences("mmm").getBoolean("pref_wrap_text", false);
} }
public static boolean isDohEnabled() { public static boolean isDohEnabled() {
return getPreferences("mmm").getBoolean("pref_dns_over_https", true); return getSharedPreferences("mmm").getBoolean("pref_dns_over_https", true);
} }
public static boolean isMonetEnabled() { public static boolean isMonetEnabled() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && getPreferences("mmm").getBoolean("pref_enable_monet", true); return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && getSharedPreferences("mmm").getBoolean("pref_enable_monet", true);
} }
public static boolean isBlurEnabled() { public static boolean isBlurEnabled() {
return getPreferences("mmm").getBoolean("pref_enable_blur", false); return getSharedPreferences("mmm").getBoolean("pref_enable_blur", false);
} }
public static boolean isDeveloper() { public static boolean isDeveloper() {
if (BuildConfig.DEBUG) return true; if (BuildConfig.DEBUG) return true;
return getPreferences("mmm").getBoolean("developer", false); return getSharedPreferences("mmm").getBoolean("developer", false);
} }
public static boolean isDisableLowQualityModuleFilter() { public static boolean isDisableLowQualityModuleFilter() {
return getPreferences("mmm").getBoolean("pref_disable_low_quality_module_filter", false) && isDeveloper(); return getSharedPreferences("mmm").getBoolean("pref_disable_low_quality_module_filter", false) && isDeveloper();
} }
public static boolean isUsingMagiskCommand() { public static boolean isUsingMagiskCommand() {
return InstallerInitializer.peekMagiskVersion() >= Constants.MAGISK_VER_CODE_INSTALL_COMMAND && getPreferences("mmm").getBoolean("pref_use_magisk_install_command", false) && isDeveloper(); return InstallerInitializer.peekMagiskVersion() >= Constants.MAGISK_VER_CODE_INSTALL_COMMAND && getSharedPreferences("mmm").getBoolean("pref_use_magisk_install_command", false) && isDeveloper();
} }
public static boolean isBackgroundUpdateCheckEnabled() { public static boolean isBackgroundUpdateCheckEnabled() {
@ -253,13 +254,13 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
return Boolean.parseBoolean(updateCheckBg); return Boolean.parseBoolean(updateCheckBg);
} }
boolean wrapped = isWrapped(); boolean wrapped = isWrapped();
boolean updateCheckBgTemp = !wrapped && getPreferences("mmm").getBoolean("pref_background_update_check", true); boolean updateCheckBgTemp = !wrapped && getSharedPreferences("mmm").getBoolean("pref_background_update_check", true);
updateCheckBg = String.valueOf(updateCheckBgTemp); updateCheckBg = String.valueOf(updateCheckBgTemp);
return Boolean.parseBoolean(updateCheckBg); return Boolean.parseBoolean(updateCheckBg);
} }
public static boolean isAndroidacyTestMode() { public static boolean isAndroidacyTestMode() {
return isDeveloper() && getPreferences("mmm").getBoolean("pref_androidacy_test_mode", false); return isDeveloper() && getSharedPreferences("mmm").getBoolean("pref_androidacy_test_mode", false);
} }
public static boolean isFirstBoot() { public static boolean isFirstBoot() {
@ -267,15 +268,15 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
} }
public static void setHasGottenRootAccess(boolean bool) { public static void setHasGottenRootAccess(boolean bool) {
getPreferences("mmm").edit().putBoolean("has_root_access", bool).apply(); getSharedPreferences("mmm").edit().putBoolean("has_root_access", bool).apply();
} }
public static boolean isCrashReportingEnabled() { public static boolean isCrashReportingEnabled() {
return SentryMain.IS_SENTRY_INSTALLED && getPreferences("mmm").getBoolean("pref_crash_reporting", BuildConfig.DEFAULT_ENABLE_CRASH_REPORTING); return SentryMain.IS_SENTRY_INSTALLED && getSharedPreferences("mmm").getBoolean("pref_crash_reporting", BuildConfig.DEFAULT_ENABLE_CRASH_REPORTING);
} }
public static SharedPreferences getBootSharedPreferences() { public static SharedPreferences getBootSharedPreferences() {
return getPreferences("mmm_boot"); return getSharedPreferences("mmm_boot");
} }
public static MainApplication getINSTANCE() { public static MainApplication getINSTANCE() {
@ -312,7 +313,7 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
@StyleRes int themeResId; @StyleRes int themeResId;
String theme; String theme;
boolean monet = isMonetEnabled(); boolean monet = isMonetEnabled();
switch (theme = getPreferences("mmm").getString("pref_theme", "system")) { switch (theme = getSharedPreferences("mmm").getString("pref_theme", "system")) {
default: default:
Timber.w("Unknown theme id: %s", theme); Timber.w("Unknown theme id: %s", theme);
case "system": case "system":
@ -353,7 +354,7 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
@SuppressLint("NonConstantResourceId") @SuppressLint("NonConstantResourceId")
public boolean isLightTheme() { public boolean isLightTheme() {
return switch (getPreferences("mmm").getString("pref_theme", "system")) { return switch (getSharedPreferences("mmm").getString("pref_theme", "system")) {
case "system" -> this.isSystemLightTheme(); case "system" -> this.isSystemLightTheme();
case "dark", "black" -> false; case "dark", "black" -> false;
default -> true; default -> true;
@ -419,10 +420,10 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
} else { } else {
tracker.setOptOut(false); tracker.setOptOut(false);
} }
if (getPreferences("matomo").getBoolean("install_tracked", false)) { if (getSharedPreferences("matomo").getBoolean("install_tracked", false)) {
TrackHelper.track().download().with(MainApplication.getINSTANCE().getTracker()); TrackHelper.track().download().with(MainApplication.getINSTANCE().getTracker());
Timber.d("Sent install event to matomo"); Timber.d("Sent install event to matomo");
getPreferences("matomo").edit().putBoolean("install_tracked", true).apply(); getSharedPreferences("matomo").edit().putBoolean("install_tracked", true).apply();
} else { } else {
Timber.d("Matomo already has install"); Timber.d("Matomo already has install");
} }
@ -434,9 +435,9 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
Iof = Arrays.asList(osh).contains(oosh); Iof = Arrays.asList(osh).contains(oosh);
} catch (PackageManager.NameNotFoundException ignored) { } catch (PackageManager.NameNotFoundException ignored) {
} }
SharedPreferences sharedPreferences = MainApplication.getPreferences("mmm"); SharedPreferences sharedPreferences = MainApplication.getSharedPreferences("mmm");
// We are only one process so it's ok to do this // We are only one process so it's ok to do this
SharedPreferences bootPrefs = MainApplication.getPreferences("mmm_boot"); SharedPreferences bootPrefs = MainApplication.getSharedPreferences("mmm_boot");
long lastBoot = System.currentTimeMillis() - SystemClock.elapsedRealtime(); long lastBoot = System.currentTimeMillis() - SystemClock.elapsedRealtime();
long lastBootPrefs = bootPrefs.getLong("last_boot", 0); long lastBootPrefs = bootPrefs.getLong("last_boot", 0);
if (lastBootPrefs == 0 || Math.abs(lastBoot - lastBootPrefs) > 100) { if (lastBootPrefs == 0 || Math.abs(lastBoot - lastBootPrefs) > 100) {
@ -474,7 +475,7 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
} }
private boolean isMatomoAllowed() { private boolean isMatomoAllowed() {
return getPreferences("mmm").getBoolean("pref_analytics_enabled", BuildConfig.DEFAULT_ENABLE_ANALYTICS); return getSharedPreferences("mmm").getBoolean("pref_analytics_enabled", BuildConfig.DEFAULT_ENABLE_ANALYTICS);
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -592,7 +593,7 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
return existingKey; return existingKey;
} }
// check if we have a key already // check if we have a key already
SharedPreferences sharedPreferences = MainApplication.getPreferences("realm_key"); SharedPreferences sharedPreferences = MainApplication.getSharedPreferences("realm_key");
if (sharedPreferences.contains("iv_and_encrypted_key")) { if (sharedPreferences.contains("iv_and_encrypted_key")) {
return getExistingKey(); return getExistingKey();
} else { } else {
@ -661,7 +662,7 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
buffer.put(initializationVector); buffer.put(initializationVector);
buffer.put(encryptedKeyForRealm); buffer.put(encryptedKeyForRealm);
Timber.d("Created all keys successfully."); Timber.d("Created all keys successfully.");
MainApplication.getPreferences("realm_key").edit().putString("iv_and_encrypted_key", Base64.encodeToString(initializationVectorAndEncryptedKey, Base64.NO_WRAP)).apply(); MainApplication.getSharedPreferences("realm_key").edit().putString("iv_and_encrypted_key", Base64.encodeToString(initializationVectorAndEncryptedKey, Base64.NO_WRAP)).apply();
Timber.d("Saved the encrypted key in shared preferences."); Timber.d("Saved the encrypted key in shared preferences.");
makingNewKey = false; makingNewKey = false;
return realmKey; // pass to a realm configuration via encryptionKey() return realmKey; // pass to a realm configuration via encryptionKey()
@ -686,7 +687,7 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
} }
Timber.v("Keystore opened."); Timber.v("Keystore opened.");
// access the encrypted key that's stored in shared preferences // access the encrypted key that's stored in shared preferences
byte[] initializationVectorAndEncryptedKey = Base64.decode(MainApplication.getPreferences("realm_key").getString("iv_and_encrypted_key", null), Base64.DEFAULT); byte[] initializationVectorAndEncryptedKey = Base64.decode(MainApplication.getSharedPreferences("realm_key").getString("iv_and_encrypted_key", null), Base64.DEFAULT);
Timber.d("Retrieved the encrypted key from shared preferences. Key length: %d", initializationVectorAndEncryptedKey.length); Timber.d("Retrieved the encrypted key from shared preferences. Key length: %d", initializationVectorAndEncryptedKey.length);
ByteBuffer buffer = ByteBuffer.wrap(initializationVectorAndEncryptedKey); ByteBuffer buffer = ByteBuffer.wrap(initializationVectorAndEncryptedKey);
buffer.order(ByteOrder.BIG_ENDIAN); buffer.order(ByteOrder.BIG_ENDIAN);

@ -53,7 +53,7 @@ public class SetupActivity extends FoxActivity implements LanguageActivity {
createFiles(); createFiles();
disableUpdateActivityForFdroidFlavor(); disableUpdateActivityForFdroidFlavor();
// Set theme // Set theme
SharedPreferences prefs = MainApplication.getPreferences("mmm"); SharedPreferences prefs = MainApplication.getSharedPreferences("mmm");
switch (prefs.getString("theme", "system")) { switch (prefs.getString("theme", "system")) {
case "light" -> setTheme(R.style.Theme_MagiskModuleManager_Monet_Light); case "light" -> setTheme(R.style.Theme_MagiskModuleManager_Monet_Light);
case "dark" -> setTheme(R.style.Theme_MagiskModuleManager_Monet_Dark); case "dark" -> setTheme(R.style.Theme_MagiskModuleManager_Monet_Dark);
@ -245,7 +245,7 @@ public class SetupActivity extends FoxActivity implements LanguageActivity {
return theme; return theme;
} }
// Set the theme // Set the theme
SharedPreferences prefs = MainApplication.getPreferences("mmm"); SharedPreferences prefs = MainApplication.getSharedPreferences("mmm");
String themePref = prefs.getString("pref_theme", "system"); String themePref = prefs.getString("pref_theme", "system");
switch (themePref) { switch (themePref) {
case "light" -> { case "light" -> {

@ -44,7 +44,7 @@ import timber.log.Timber;
@SuppressWarnings("KotlinInternalInJava") @SuppressWarnings("KotlinInternalInJava")
public final class AndroidacyRepoData extends RepoData { public final class AndroidacyRepoData extends RepoData {
public static String ANDROIDACY_DEVICE_ID = null; public static String ANDROIDACY_DEVICE_ID = null;
public static String token = MainApplication.getPreferences("androidacy").getString("pref_androidacy_api_token", null); public static String token = MainApplication.getSharedPreferences("androidacy").getString("pref_androidacy_api_token", null);
static { static {
HttpUrl.Builder OK_HTTP_URL_BUILDER = new HttpUrl.Builder().scheme("https"); HttpUrl.Builder OK_HTTP_URL_BUILDER = new HttpUrl.Builder().scheme("https");
@ -92,7 +92,7 @@ public final class AndroidacyRepoData extends RepoData {
return ANDROIDACY_DEVICE_ID; return ANDROIDACY_DEVICE_ID;
} }
// Try to get the device ID from the shared preferences // Try to get the device ID from the shared preferences
SharedPreferences sharedPreferences = MainApplication.getPreferences("androidacy"); SharedPreferences sharedPreferences = MainApplication.getSharedPreferences("androidacy");
String deviceIdPref = sharedPreferences.getString("device_id", null); String deviceIdPref = sharedPreferences.getString("device_id", null);
if (deviceIdPref != null) { if (deviceIdPref != null) {
ANDROIDACY_DEVICE_ID = deviceIdPref; ANDROIDACY_DEVICE_ID = deviceIdPref;
@ -164,7 +164,7 @@ public final class AndroidacyRepoData extends RepoData {
if (e.getErrorCode() == 401) { if (e.getErrorCode() == 401) {
Timber.w("Invalid token, resetting..."); Timber.w("Invalid token, resetting...");
// Remove saved preference // Remove saved preference
SharedPreferences.Editor editor = MainApplication.getPreferences("androidacy").edit(); SharedPreferences.Editor editor = MainApplication.getSharedPreferences("androidacy").edit();
editor.remove("pref_androidacy_api_token"); editor.remove("pref_androidacy_api_token");
editor.apply(); editor.apply();
return false; return false;
@ -175,7 +175,7 @@ public final class AndroidacyRepoData extends RepoData {
Timber.w("Invalid token, resetting..."); Timber.w("Invalid token, resetting...");
Timber.w(e); Timber.w(e);
// Remove saved preference // Remove saved preference
SharedPreferences.Editor editor = MainApplication.getPreferences("androidacy").edit(); SharedPreferences.Editor editor = MainApplication.getSharedPreferences("androidacy").edit();
editor.remove("pref_androidacy_api_token"); editor.remove("pref_androidacy_api_token");
editor.apply(); editor.apply();
return false; return false;
@ -187,7 +187,7 @@ public final class AndroidacyRepoData extends RepoData {
protected boolean prepare() { protected boolean prepare() {
// If ANDROIDACY_CLIENT_ID is not set or is empty, disable this repo and return // If ANDROIDACY_CLIENT_ID is not set or is empty, disable this repo and return
if (Objects.equals(BuildConfig.ANDROIDACY_CLIENT_ID, "")) { if (Objects.equals(BuildConfig.ANDROIDACY_CLIENT_ID, "")) {
SharedPreferences.Editor editor = MainApplication.getPreferences("mmm").edit(); SharedPreferences.Editor editor = MainApplication.getSharedPreferences("mmm").edit();
editor.putBoolean("pref_androidacy_repo_enabled", false); editor.putBoolean("pref_androidacy_repo_enabled", false);
editor.apply(); editor.apply();
Timber.w("ANDROIDACY_CLIENT_ID is empty, disabling AndroidacyRepoData 2"); Timber.w("ANDROIDACY_CLIENT_ID is empty, disabling AndroidacyRepoData 2");
@ -226,7 +226,7 @@ public final class AndroidacyRepoData extends RepoData {
this.androidacyBlockade = time + 30_000L; this.androidacyBlockade = time + 30_000L;
try { try {
if (token == null) { if (token == null) {
token = MainApplication.getPreferences("androidacy").getString("pref_androidacy_api_token", null); token = MainApplication.getSharedPreferences("androidacy").getString("pref_androidacy_api_token", null);
if (token != null && !this.isValidToken(token)) { if (token != null && !this.isValidToken(token)) {
Timber.i("Token expired or invalid, requesting new one..."); Timber.i("Token expired or invalid, requesting new one...");
token = null; token = null;
@ -278,7 +278,7 @@ public final class AndroidacyRepoData extends RepoData {
return false; return false;
} else { } else {
// Save token to shared preference // Save token to shared preference
SharedPreferences.Editor editor = MainApplication.getPreferences("androidacy").edit(); SharedPreferences.Editor editor = MainApplication.getSharedPreferences("androidacy").edit();
editor.putString("pref_androidacy_api_token", token); editor.putString("pref_androidacy_api_token", token);
editor.apply(); editor.apply();
Timber.i("Token saved to shared preference"); Timber.i("Token saved to shared preference");

@ -88,7 +88,7 @@ public class BackgroundUpdateChecker extends Worker {
static void doCheck(Context context) { static void doCheck(Context context) {
// first, check if the user has enabled background update checking // first, check if the user has enabled background update checking
if (!MainApplication.getPreferences("mmm").getBoolean("pref_background_update_check", false)) { if (!MainApplication.getSharedPreferences("mmm").getBoolean("pref_background_update_check", false)) {
return; return;
} }
if (MainApplication.getINSTANCE().isInForeground()) { if (MainApplication.getINSTANCE().isInForeground()) {
@ -96,7 +96,7 @@ public class BackgroundUpdateChecker extends Worker {
return; return;
} }
// next, check if user requires wifi // next, check if user requires wifi
if (MainApplication.getPreferences("mmm").getBoolean("pref_background_update_check_wifi", true)) { if (MainApplication.getSharedPreferences("mmm").getBoolean("pref_background_update_check_wifi", true)) {
// check if wifi is connected // check if wifi is connected
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Network networkInfo = connectivityManager.getActiveNetwork(); Network networkInfo = connectivityManager.getActiveNetwork();
@ -136,7 +136,7 @@ public class BackgroundUpdateChecker extends Worker {
if ("twrp-keep".equals(localModuleInfo.id)) continue; if ("twrp-keep".equals(localModuleInfo.id)) continue;
// exclude all modules with id's stored in the pref pref_background_update_check_excludes // exclude all modules with id's stored in the pref pref_background_update_check_excludes
try { try {
if (MainApplication.getPreferences("mmm").getStringSet("pref_background_update_check_excludes", null).contains(localModuleInfo.id)) if (MainApplication.getSharedPreferences("mmm").getStringSet("pref_background_update_check_excludes", null).contains(localModuleInfo.id))
continue; continue;
} catch (Exception ignored) { } catch (Exception ignored) {
} }
@ -156,7 +156,7 @@ public class BackgroundUpdateChecker extends Worker {
} }
}); });
// check for app updates // check for app updates
if (MainApplication.getPreferences("mmm").getBoolean("pref_background_update_check_app", false)) { if (MainApplication.getSharedPreferences("mmm").getBoolean("pref_background_update_check_app", false)) {
try { try {
boolean shouldUpdate = AppUpdateManager.getAppUpdateManager().checkUpdate(true); boolean shouldUpdate = AppUpdateManager.getAppUpdateManager().checkUpdate(true);
if (shouldUpdate) { if (shouldUpdate) {
@ -175,7 +175,7 @@ public class BackgroundUpdateChecker extends Worker {
} }
} }
// increment or create counter in shared preferences // increment or create counter in shared preferences
MainApplication.getPreferences("mmm").edit().putInt("pref_background_update_counter", MainApplication.getPreferences("mmm").getInt("pref_background_update_counter", 0) + 1).apply(); MainApplication.getSharedPreferences("mmm").edit().putInt("pref_background_update_counter", MainApplication.getSharedPreferences("mmm").getInt("pref_background_update_counter", 0) + 1).apply();
} }
public static void postNotification(Context context, HashMap<String, String> updateable, int updateCount, boolean test) { public static void postNotification(Context context, HashMap<String, String> updateable, int updateCount, boolean test) {
@ -213,7 +213,7 @@ public class BackgroundUpdateChecker extends Worker {
public static void onMainActivityCreate(Context context) { public static void onMainActivityCreate(Context context) {
// Refuse to run if first_launch pref is not false // Refuse to run if first_launch pref is not false
if (!Objects.equals(MainApplication.getPreferences("mmm").getString("last_shown_setup", null), "v1")) if (!Objects.equals(MainApplication.getSharedPreferences("mmm").getString("last_shown_setup", null), "v1"))
return; return;
// create notification channel group // create notification channel group
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

@ -58,7 +58,7 @@ public final class ModuleManager extends SyncManager {
protected void scanInternal(@NonNull UpdateListener updateListener) { protected void scanInternal(@NonNull UpdateListener updateListener) {
// if last_shown_setup is not "v1", then refuse to continue // if last_shown_setup is not "v1", then refuse to continue
if (!MainApplication.getPreferences("mmm").getString("last_shown_setup", "").equals("v1")) { if (!MainApplication.getSharedPreferences("mmm").getString("last_shown_setup", "").equals("v1")) {
return; return;
} }
boolean firstScan = this.bootPrefs.getBoolean("mm_first_scan", true); boolean firstScan = this.bootPrefs.getBoolean("mm_first_scan", true);

@ -28,7 +28,7 @@ public class CustomRepoManager {
this.customRepos = new String[MAX_CUSTOM_REPOS]; this.customRepos = new String[MAX_CUSTOM_REPOS];
this.customReposCount = 0; this.customReposCount = 0;
// refuse to load if setup is not complete // refuse to load if setup is not complete
if (MainApplication.getPreferences("mmm").getString("last_shown_setup", "").equals("")) { if (MainApplication.getSharedPreferences("mmm").getString("last_shown_setup", "").equals("")) {
return; return;
} }
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().name("ReposList.realm").encryptionKey(MainApplication.getINSTANCE().getKey()).allowQueriesOnUiThread(true).allowWritesOnUiThread(true).directory(MainApplication.getINSTANCE().getDataDirWithPath("realms")).schemaVersion(1).build(); RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().name("ReposList.realm").encryptionKey(MainApplication.getINSTANCE().getKey()).allowQueriesOnUiThread(true).allowWritesOnUiThread(true).directory(MainApplication.getINSTANCE().getDataDirWithPath("realms")).schemaVersion(1).build();

@ -65,7 +65,7 @@ public final class RepoManager extends SyncManager {
this.repoData = new LinkedHashMap<>(); this.repoData = new LinkedHashMap<>();
this.modules = new HashMap<>(); this.modules = new HashMap<>();
// refuse to load if setup is not complete // refuse to load if setup is not complete
if (MainApplication.getPreferences("mmm").getString("last_shown_setup", "").equals("")) { if (MainApplication.getSharedPreferences("mmm").getString("last_shown_setup", "").equals("")) {
return; return;
} }
// We do not have repo list config yet. // We do not have repo list config yet.
@ -150,7 +150,7 @@ public final class RepoManager extends SyncManager {
@SuppressWarnings("StatementWithEmptyBody") @SuppressWarnings("StatementWithEmptyBody")
private void populateDefaultCache(RepoData repoData) { private void populateDefaultCache(RepoData repoData) {
// if last_shown_setup is not "v1", them=n refuse to continue // if last_shown_setup is not "v1", them=n refuse to continue
if (!MainApplication.getPreferences("mmm").getString("last_shown_setup", "").equals("v1")) { if (!MainApplication.getSharedPreferences("mmm").getString("last_shown_setup", "").equals("v1")) {
return; return;
} }
// make sure repodata is not null // make sure repodata is not null
@ -311,7 +311,7 @@ public final class RepoManager extends SyncManager {
builder.setPositiveButton(android.R.string.ok, null); builder.setPositiveButton(android.R.string.ok, null);
if (repoUpdaters[finalI].repoData instanceof AndroidacyRepoData) { if (repoUpdaters[finalI].repoData instanceof AndroidacyRepoData) {
builder.setNeutralButton(R.string.reset_api_key, (dialog, which) -> { builder.setNeutralButton(R.string.reset_api_key, (dialog, which) -> {
SharedPreferences.Editor editor = MainApplication.getPreferences("androidacy").edit(); SharedPreferences.Editor editor = MainApplication.getSharedPreferences("androidacy").edit();
editor.putString("androidacy_api_key", ""); editor.putString("androidacy_api_key", "");
editor.apply(); editor.apply();
Toast.makeText(context, R.string.api_key_removed, Toast.LENGTH_SHORT).show(); Toast.makeText(context, R.string.api_key_removed, Toast.LENGTH_SHORT).show();

@ -543,7 +543,7 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
// set the box to unchecked // set the box to unchecked
((SwitchPreferenceCompat) backgroundUpdateCheck).setChecked(false); ((SwitchPreferenceCompat) backgroundUpdateCheck).setChecked(false);
// ensure that the preference is false // ensure that the preference is false
MainApplication.getPreferences("mmm").edit().putBoolean("pref_background_update_check", false).apply(); MainApplication.getSharedPreferences("mmm").edit().putBoolean("pref_background_update_check", false).apply();
new MaterialAlertDialogBuilder(this.requireContext()).setTitle(R.string.permission_notification_title).setMessage(R.string.permission_notification_message).setPositiveButton(R.string.ok, (dialog, which) -> { new MaterialAlertDialogBuilder(this.requireContext()).setTitle(R.string.permission_notification_title).setMessage(R.string.permission_notification_message).setPositiveButton(R.string.ok, (dialog, which) -> {
// Open the app settings // Open the app settings
Intent intent = new Intent(); Intent intent = new Intent();
@ -676,11 +676,11 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
if (devModeStep == 2) { if (devModeStep == 2) {
devModeStep = 0; devModeStep = 0;
if (MainApplication.isDeveloper() && !BuildConfig.DEBUG) { if (MainApplication.isDeveloper() && !BuildConfig.DEBUG) {
MainApplication.getPreferences("mmm").edit().putBoolean("developer", false).apply(); MainApplication.getSharedPreferences("mmm").edit().putBoolean("developer", false).apply();
Toast.makeText(getContext(), // Tell the user something changed Toast.makeText(getContext(), // Tell the user something changed
R.string.dev_mode_disabled, Toast.LENGTH_SHORT).show(); R.string.dev_mode_disabled, Toast.LENGTH_SHORT).show();
} else { } else {
MainApplication.getPreferences("mmm").edit().putBoolean("developer", true).apply(); MainApplication.getSharedPreferences("mmm").edit().putBoolean("developer", true).apply();
Toast.makeText(getContext(), // Tell the user something changed Toast.makeText(getContext(), // Tell the user something changed
R.string.dev_mode_enabled, Toast.LENGTH_SHORT).show(); R.string.dev_mode_enabled, Toast.LENGTH_SHORT).show();
} }
@ -948,7 +948,7 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
// Use MaterialAlertDialogBuilder // Use MaterialAlertDialogBuilder
new MaterialAlertDialogBuilder(this.requireContext()).setTitle(R.string.warning).setCancelable(false).setMessage(R.string.androidacy_test_mode_warning).setPositiveButton(android.R.string.ok, (dialog, which) -> { new MaterialAlertDialogBuilder(this.requireContext()).setTitle(R.string.warning).setCancelable(false).setMessage(R.string.androidacy_test_mode_warning).setPositiveButton(android.R.string.ok, (dialog, which) -> {
// User clicked OK button // User clicked OK button
MainApplication.getPreferences("mmm").edit().putBoolean("androidacy_test_mode", true).apply(); MainApplication.getSharedPreferences("mmm").edit().putBoolean("androidacy_test_mode", true).apply();
// Check the switch // Check the switch
Intent mStartActivity = new Intent(requireContext(), MainActivity.class); Intent mStartActivity = new Intent(requireContext(), MainActivity.class);
mStartActivity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); mStartActivity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
@ -966,10 +966,10 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
SwitchPreferenceCompat switchPreferenceCompat = (SwitchPreferenceCompat) androidacyTestMode; SwitchPreferenceCompat switchPreferenceCompat = (SwitchPreferenceCompat) androidacyTestMode;
switchPreferenceCompat.setChecked(false); switchPreferenceCompat.setChecked(false);
// There's probably a better way to do this than duplicate code but I'm too lazy to figure it out // There's probably a better way to do this than duplicate code but I'm too lazy to figure it out
MainApplication.getPreferences("mmm").edit().putBoolean("androidacy_test_mode", false).apply(); MainApplication.getSharedPreferences("mmm").edit().putBoolean("androidacy_test_mode", false).apply();
}).show(); }).show();
} else { } else {
MainApplication.getPreferences("mmm").edit().putBoolean("androidacy_test_mode", false).apply(); MainApplication.getSharedPreferences("mmm").edit().putBoolean("androidacy_test_mode", false).apply();
// Show dialog to restart app with ok button // Show dialog to restart app with ok button
new MaterialAlertDialogBuilder(this.requireContext()).setTitle(R.string.warning).setCancelable(false).setMessage(R.string.androidacy_test_mode_disable_warning).setNeutralButton(android.R.string.ok, (dialog, which) -> { new MaterialAlertDialogBuilder(this.requireContext()).setTitle(R.string.warning).setCancelable(false).setMessage(R.string.androidacy_test_mode_disable_warning).setNeutralButton(android.R.string.ok, (dialog, which) -> {
// User clicked OK button // User clicked OK button
@ -1076,7 +1076,7 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
prefAndroidacyRepoApiD.setVisible(false); prefAndroidacyRepoApiD.setVisible(false);
} }
} }
String[] originalApiKeyRef = new String[]{MainApplication.getPreferences("androidacy").getString("pref_androidacy_api_token", "")}; String[] originalApiKeyRef = new String[]{MainApplication.getSharedPreferences("androidacy").getString("pref_androidacy_api_token", "")};
// Get the dummy pref_androidacy_repo_api_token preference with id pref_androidacy_repo_api_token // Get the dummy pref_androidacy_repo_api_token preference with id pref_androidacy_repo_api_token
// we have to use the id because the key is different // we have to use the id because the key is different
EditTextPreference prefAndroidacyRepoApiKey = Objects.requireNonNull(findPreference("pref_androidacy_repo_api_token")); EditTextPreference prefAndroidacyRepoApiKey = Objects.requireNonNull(findPreference("pref_androidacy_repo_api_token"));
@ -1122,7 +1122,7 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
new Thread(() -> { new Thread(() -> {
// If key is empty, just remove it and change the text of the snack bar // If key is empty, just remove it and change the text of the snack bar
if (apiKey.isEmpty()) { if (apiKey.isEmpty()) {
MainApplication.getPreferences("androidacy").edit().remove("pref_androidacy_api_token").apply(); MainApplication.getSharedPreferences("androidacy").edit().remove("pref_androidacy_api_token").apply();
new Handler(Looper.getMainLooper()).post(() -> { new Handler(Looper.getMainLooper()).post(() -> {
Snackbar.make(requireView(), R.string.api_key_removed, BaseTransientBottomBar.LENGTH_SHORT).show(); Snackbar.make(requireView(), R.string.api_key_removed, BaseTransientBottomBar.LENGTH_SHORT).show();
// Show dialog to restart app with ok button // Show dialog to restart app with ok button
@ -1146,7 +1146,7 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
new Handler(Looper.getMainLooper()).post(() -> { new Handler(Looper.getMainLooper()).post(() -> {
Snackbar.make(requireView(), R.string.api_key_invalid, BaseTransientBottomBar.LENGTH_SHORT).show(); Snackbar.make(requireView(), R.string.api_key_invalid, BaseTransientBottomBar.LENGTH_SHORT).show();
// Save the original key // Save the original key
MainApplication.getPreferences("androidacy").edit().putString("pref_androidacy_api_token", originalApiKeyRef[0]).apply(); MainApplication.getSharedPreferences("androidacy").edit().putString("pref_androidacy_api_token", originalApiKeyRef[0]).apply();
// Re-show the dialog with an error // Re-show the dialog with an error
prefAndroidacyRepoApiKey.performClick(); prefAndroidacyRepoApiKey.performClick();
// Show error // Show error
@ -1167,7 +1167,7 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
if (valid) { if (valid) {
originalApiKeyRef[0] = apiKey; originalApiKeyRef[0] = apiKey;
RepoManager.getINSTANCE().getAndroidacyRepoData().setToken(apiKey); RepoManager.getINSTANCE().getAndroidacyRepoData().setToken(apiKey);
MainApplication.getPreferences("androidacy").edit().putString("pref_androidacy_api_token", apiKey).apply(); MainApplication.getSharedPreferences("androidacy").edit().putString("pref_androidacy_api_token", apiKey).apply();
// Snackbar with success and restart button // Snackbar with success and restart button
new Handler(Looper.getMainLooper()).post(() -> { new Handler(Looper.getMainLooper()).post(() -> {
Snackbar.make(requireView(), R.string.api_key_valid, BaseTransientBottomBar.LENGTH_SHORT).show(); Snackbar.make(requireView(), R.string.api_key_valid, BaseTransientBottomBar.LENGTH_SHORT).show();

@ -60,7 +60,7 @@ public class SentryMain {
android.os.Process.killProcess(android.os.Process.myPid()); android.os.Process.killProcess(android.os.Process.myPid());
}); });
// If first_launch pref is not false, refuse to initialize Sentry // If first_launch pref is not false, refuse to initialize Sentry
SharedPreferences sharedPreferences = MainApplication.getPreferences("mmm"); SharedPreferences sharedPreferences = MainApplication.getSharedPreferences("mmm");
if (!Objects.equals(sharedPreferences.getString("last_shown_setup", null), "v1")) { if (!Objects.equals(sharedPreferences.getString("last_shown_setup", null), "v1")) {
return; return;
} }

Loading…
Cancel
Save