various optimizations

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/299/head
androidacy-user 1 year ago
parent 71722c89b0
commit f8b95e663d

@ -285,6 +285,8 @@ sentry {
configurations { configurations {
implementation.exclude group: 'org.jetbrains', module: 'annotations' implementation.exclude group: 'org.jetbrains', module: 'annotations'
// exclude chromium cronet-api
implementation.exclude group: 'org.chromium.net', module: 'cronet-api'
} }
dependencies { dependencies {
@ -296,7 +298,7 @@ dependencies {
implementation 'androidx.emoji2:emoji2-views-helper:1.2.0' implementation 'androidx.emoji2:emoji2-views-helper:1.2.0'
implementation 'androidx.preference:preference-ktx:1.2.0' implementation 'androidx.preference:preference-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.recyclerview:recyclerview:1.2.1' implementation 'androidx.recyclerview:recyclerview:1.3.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.webkit:webkit:1.6.0' implementation 'androidx.webkit:webkit:1.6.0'
implementation 'com.google.android.material:material:1.8.0' implementation 'com.google.android.material:material:1.8.0'
@ -313,14 +315,18 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.10' implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.10'
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:5.0.0-alpha.10' implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:5.0.0-alpha.10'
// Chromium cronet from androidacy // Chromium cronet from androidacy
implementation 'org.chromium.net:cronet-embedded:108.5359.79' implementation 'com.androidacy:cronet-common:111.0.5563.75'
implementation 'com.androidacy:cronet-native:111.0.5563.75'
implementation 'com.androidacy:cronet-api:111.0.5563.75'
// protobuf - fixes a crash on some devicesa
implementation 'com.google.protobuf:protobuf-javalite:3.22.2'
implementation 'com.github.topjohnwu.libsu:io:5.0.1' implementation 'com.github.topjohnwu.libsu:io:5.0.1'
implementation 'com.github.Fox2Code:RosettaX:1.0.9' implementation 'com.github.Fox2Code:RosettaX:1.0.9'
implementation 'com.github.Fox2Code:AndroidANSI:1.0.1' implementation 'com.github.Fox2Code:AndroidANSI:1.0.1'
// sentry // sentry
implementation platform('io.sentry:sentry-bom:6.14.0') implementation platform('io.sentry:sentry-bom:6.15.0')
implementation "io.sentry:sentry-android" implementation "io.sentry:sentry-android"
implementation "io.sentry:sentry-android-timber" implementation "io.sentry:sentry-android-timber"
implementation "io.sentry:sentry-android-fragment" implementation "io.sentry:sentry-android-fragment"

@ -101,11 +101,18 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
this.initMode = true; this.initMode = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// per process webview data dir
try {
WebView.setDataDirectorySuffix(FoxApplication.getProcessName());
} catch (IllegalStateException e) {
Timber.d("Could not set webview data dir, possibly already set or webview already initialized");
}
}
// Ensure HTTP Cache directories are created // Ensure HTTP Cache directories are created
Http.ensureCacheDirs(this); Http.ensureCacheDirs(this);
if (!urlFactoryInstalled) { if (!urlFactoryInstalled) {
try { try (HttpResponseCache cache = HttpResponseCache.getInstalled()) {
HttpResponseCache cache = HttpResponseCache.getInstalled();
if (cache == null) { if (cache == null) {
File cacheDir = new File(getCacheDir(), "http"); File cacheDir = new File(getCacheDir(), "http");
//noinspection ResultOfMethodCallIgnored //noinspection ResultOfMethodCallIgnored
@ -131,10 +138,6 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
} }
BackgroundUpdateChecker.onMainActivityCreate(this); BackgroundUpdateChecker.onMainActivityCreate(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// per process webview data dir
WebView.setDataDirectorySuffix(FoxApplication.getProcessName());
}
if (!isOfficial) { if (!isOfficial) {
Timber.w("You may be running an untrusted build."); Timber.w("You may be running an untrusted build.");
// Show a toast to warn the user // Show a toast to warn the user
@ -293,7 +296,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
// On every preferences change, log the change if debug is enabled // On every preferences change, log the change if debug is enabled
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
// Log all preferences changes // Log all preferences changes
MainApplication.getSharedPreferences().registerOnSharedPreferenceChangeListener((prefs, key) -> Timber.i("onSharedPreferenceChanged: " + key + " = " + prefs.getAll().get(key))); MainApplication.getSharedPreferences("mmm").registerOnSharedPreferenceChangeListener((prefs, key) -> Timber.i("onSharedPreferenceChanged: " + key + " = " + prefs.getAll().get(key)));
} }
Timber.i("Scanning for modules!"); Timber.i("Scanning for modules!");
@ -716,7 +719,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG)
Timber.i("Checking if we need to run setup"); 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.getSharedPreferences(); 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

@ -20,6 +20,8 @@ import androidx.core.app.NotificationManagerCompat;
import androidx.emoji2.text.DefaultEmojiCompatConfig; import androidx.emoji2.text.DefaultEmojiCompatConfig;
import androidx.emoji2.text.EmojiCompat; import androidx.emoji2.text.EmojiCompat;
import androidx.emoji2.text.FontRequestEmojiCompatConfig; import androidx.emoji2.text.FontRequestEmojiCompatConfig;
import androidx.security.crypto.EncryptedSharedPreferences;
import androidx.security.crypto.MasterKey;
import com.fox2code.foxcompat.app.FoxActivity; import com.fox2code.foxcompat.app.FoxActivity;
import com.fox2code.foxcompat.app.FoxApplication; import com.fox2code.foxcompat.app.FoxApplication;
@ -34,6 +36,8 @@ import com.google.common.hash.Hashing;
import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.Shell;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
@ -67,7 +71,6 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
private static long secret; private static long secret;
private static Locale timeFormatLocale = Resources.getSystem().getConfiguration().getLocales().get(0); private static Locale timeFormatLocale = Resources.getSystem().getConfiguration().getLocales().get(0);
private static SimpleDateFormat timeFormat = new SimpleDateFormat(timeFormatString, timeFormatLocale); private static SimpleDateFormat timeFormat = new SimpleDateFormat(timeFormatString, timeFormatLocale);
private static SharedPreferences bootSharedPreferences;
private static String relPackageName = BuildConfig.APPLICATION_ID; private static String relPackageName = BuildConfig.APPLICATION_ID;
@SuppressLint("StaticFieldLeak") @SuppressLint("StaticFieldLeak")
private static MainApplication INSTANCE; private static MainApplication INSTANCE;
@ -106,8 +109,21 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
intent.putExtra("secret", secret); intent.putExtra("secret", secret);
} }
public static SharedPreferences getSharedPreferences() { public static SharedPreferences getSharedPreferences(String name) {
return INSTANCE.getSharedPreferences("mmm", MODE_PRIVATE); // encryptedSharedPreferences is used
MasterKey mainKeyAlias;
try {
mainKeyAlias = new MasterKey.Builder(MainApplication.getINSTANCE().getApplicationContext()).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build();
} catch (GeneralSecurityException | IOException e) {
throw new RuntimeException(e);
}
SharedPreferences mSharedPreferences;
try {
mSharedPreferences = EncryptedSharedPreferences.create(MainApplication.getINSTANCE().getApplicationContext(), name, mainKeyAlias, EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM);
} catch (GeneralSecurityException | IOException e) {
throw new RuntimeException(e);
}
return mSharedPreferences;
} }
// Is application wrapped, and therefore must reduce it's feature set. // Is application wrapped, and therefore must reduce it's feature set.
@ -121,57 +137,57 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
} }
public static boolean isShowcaseMode() { public static boolean isShowcaseMode() {
return getSharedPreferences().getBoolean("pref_showcase_mode", false); return getSharedPreferences("mmm").getBoolean("pref_showcase_mode", false);
} }
public static boolean shouldPreventReboot() { public static boolean shouldPreventReboot() {
return getSharedPreferences().getBoolean("pref_prevent_reboot", true); return getSharedPreferences("mmm").getBoolean("pref_prevent_reboot", true);
} }
public static boolean isShowIncompatibleModules() { public static boolean isShowIncompatibleModules() {
return getSharedPreferences().getBoolean("pref_show_incompatible", false); return getSharedPreferences("mmm").getBoolean("pref_show_incompatible", false);
} }
public static boolean isForceDarkTerminal() { public static boolean isForceDarkTerminal() {
return getSharedPreferences().getBoolean("pref_force_dark_terminal", false); return getSharedPreferences("mmm").getBoolean("pref_force_dark_terminal", false);
} }
public static boolean isTextWrapEnabled() { public static boolean isTextWrapEnabled() {
return getSharedPreferences().getBoolean("pref_wrap_text", false); return getSharedPreferences("mmm").getBoolean("pref_wrap_text", false);
} }
public static boolean isDohEnabled() { public static boolean isDohEnabled() {
return getSharedPreferences().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 && getSharedPreferences().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 getSharedPreferences().getBoolean("pref_enable_blur", false); return getSharedPreferences("mmm").getBoolean("pref_enable_blur", false);
} }
public static boolean isDeveloper() { public static boolean isDeveloper() {
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG)
return true; return true;
return getSharedPreferences().getBoolean("developer", false); return getSharedPreferences("mmm").getBoolean("developer", false);
} }
public static boolean isDisableLowQualityModuleFilter() { public static boolean isDisableLowQualityModuleFilter() {
return getSharedPreferences().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 && getSharedPreferences().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() {
return !wrapped && getSharedPreferences().getBoolean("pref_background_update_check", true); return !wrapped && getSharedPreferences("mmm").getBoolean("pref_background_update_check", true);
} }
public static boolean isAndroidacyTestMode() { public static boolean isAndroidacyTestMode() {
return isDeveloper() && getSharedPreferences().getBoolean("pref_androidacy_test_mode", false); return isDeveloper() && getSharedPreferences("mmm").getBoolean("pref_androidacy_test_mode", false);
} }
public static boolean isFirstBoot() { public static boolean isFirstBoot() {
@ -179,15 +195,15 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
} }
public static void setHasGottenRootAccess(boolean bool) { public static void setHasGottenRootAccess(boolean bool) {
getSharedPreferences().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 && getSharedPreferences().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 bootSharedPreferences; return getSharedPreferences("mmm_boot");
} }
public static MainApplication getINSTANCE() { public static MainApplication getINSTANCE() {
@ -224,7 +240,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 = getSharedPreferences().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":
@ -324,6 +340,8 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
relPackageName = this.getPackageName(); relPackageName = this.getPackageName();
Timber.d("Starting FoxMMM version " + BuildConfig.VERSION_NAME + " (" + BuildConfig.VERSION_CODE + "), commit " + BuildConfig.COMMIT_HASH); Timber.d("Starting FoxMMM version " + BuildConfig.VERSION_NAME + " (" + BuildConfig.VERSION_CODE + "), commit " + BuildConfig.COMMIT_HASH);
super.onCreate(); super.onCreate();
// Update SSL Ciphers if update is possible
GMSProviderInstaller.installIfNeeded(this);
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
Timber.d("Initializing FoxMMM"); Timber.d("Initializing FoxMMM");
Timber.d("Started from background: %s", !isInForeground()); Timber.d("Started from background: %s", !isInForeground());
@ -342,9 +360,9 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
} catch ( } catch (
PackageManager.NameNotFoundException ignored) { PackageManager.NameNotFoundException ignored) {
} }
SharedPreferences sharedPreferences = MainApplication.getSharedPreferences(); 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.bootSharedPreferences = MainApplication.getINSTANCE().getSharedPreferences("mmm_boot", Context.MODE_PRIVATE); 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) {
@ -360,8 +378,6 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
// Force initialize language early. // Force initialize language early.
new LanguageSwitcher(this); new LanguageSwitcher(this);
this.updateTheme(); this.updateTheme();
// Update SSL Ciphers if update is possible
GMSProviderInstaller.installIfNeeded(this);
// Update emoji config // Update emoji config
FontRequestEmojiCompatConfig fontRequestEmojiCompatConfig = DefaultEmojiCompatConfig.create(this); FontRequestEmojiCompatConfig fontRequestEmojiCompatConfig = DefaultEmojiCompatConfig.create(this);
if (fontRequestEmojiCompatConfig != null) { if (fontRequestEmojiCompatConfig != null) {

@ -14,7 +14,6 @@ import android.util.Base64;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
@ -59,7 +58,7 @@ public class SetupActivity extends FoxActivity implements LanguageActivity {
createFiles(); createFiles();
disableUpdateActivityForFdroidFlavor(); disableUpdateActivityForFdroidFlavor();
// Set theme // Set theme
SharedPreferences prefs = MainApplication.getSharedPreferences(); 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);
@ -215,7 +214,7 @@ public class SetupActivity extends FoxActivity implements LanguageActivity {
public Resources.Theme getTheme() { public Resources.Theme getTheme() {
Resources.Theme theme = super.getTheme(); Resources.Theme theme = super.getTheme();
// Set the theme // Set the theme
SharedPreferences prefs = MainApplication.getSharedPreferences(); SharedPreferences prefs = MainApplication.getSharedPreferences("mmm");
switch (prefs.getString("pref_theme", "system")) { switch (prefs.getString("pref_theme", "system")) {
case "light" -> theme.applyStyle(R.style.Theme_MagiskModuleManager_Monet_Light, true); case "light" -> theme.applyStyle(R.style.Theme_MagiskModuleManager_Monet_Light, true);
case "dark" -> theme.applyStyle(R.style.Theme_MagiskModuleManager_Monet_Dark, true); case "dark" -> theme.applyStyle(R.style.Theme_MagiskModuleManager_Monet_Dark, true);
@ -244,51 +243,52 @@ public class SetupActivity extends FoxActivity implements LanguageActivity {
Timber.d("Creating Realm databases"); Timber.d("Creating Realm databases");
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
// create encryption key // create encryption key
Timber.d("Creating encryption key"); // Timber.d("Creating encryption key");
// create the realm database for ReposList // create the realm database for ReposList
// next, create the realm database for ReposList // next, create the realm database for ReposList
RealmConfiguration config2 = new RealmConfiguration.Builder().name("ReposList.realm").allowQueriesOnUiThread(true).allowWritesOnUiThread(true).directory(MainApplication.getINSTANCE().getDataDirWithPath("realms")).schemaVersion(1).build(); new Thread(() -> {
// get the instance // create the realm database for ReposList
Realm.getInstanceAsync(config2, new Realm.Callback() { // create the realm configuration
@Override RealmConfiguration config2 = new RealmConfiguration.Builder().name("ReposList.realm").allowQueriesOnUiThread(true).allowWritesOnUiThread(true).directory(MainApplication.getINSTANCE().getDataDirWithPath("realms")).schemaVersion(1).build();
public void onSuccess(@NonNull Realm realm1) { // get the instance
// create androidacy_repo and magisk_alt_repo if they don't exist under ReposList Realm realm1 = Realm.getInstance(config2);
// each has id, name, donate, website, support, enabled, and lastUpdate and name // create androidacy_repo and magisk_alt_repo if they don't exist under ReposList
// create androidacy_repo // each has id, name, donate, website, support, enabled, and lastUpdate and name
realm1.beginTransaction(); // create androidacy_repo
if (realm1.where(ReposList.class).equalTo("id", "androidacy_repo").findFirst() == null) { realm1.beginTransaction();
// cant use createObject because it crashes because reasons. use copyToRealm instead if (realm1.where(ReposList.class).equalTo("id", "androidacy_repo").findFirst() == null) {
ReposList androidacy_repo = realm1.createObject(ReposList.class, "androidacy_repo"); // cant use createObject because it crashes because reasons. use copyToRealm instead
androidacy_repo.setName("Androidacy Repo"); ReposList androidacy_repo = realm1.createObject(ReposList.class, "androidacy_repo");
androidacy_repo.setDonate(AndroidacyRepoData.getInstance().getDonate()); androidacy_repo.setName("Androidacy Repo");
androidacy_repo.setSupport(AndroidacyRepoData.getInstance().getSupport()); androidacy_repo.setDonate(AndroidacyRepoData.getInstance().getDonate());
androidacy_repo.setSubmitModule(AndroidacyRepoData.getInstance().getSubmitModule()); androidacy_repo.setSupport(AndroidacyRepoData.getInstance().getSupport());
androidacy_repo.setUrl(RepoManager.ANDROIDACY_MAGISK_REPO_ENDPOINT); androidacy_repo.setSubmitModule(AndroidacyRepoData.getInstance().getSubmitModule());
androidacy_repo.setEnabled(true); androidacy_repo.setUrl(RepoManager.ANDROIDACY_MAGISK_REPO_ENDPOINT);
androidacy_repo.setLastUpdate(0); androidacy_repo.setEnabled(true);
androidacy_repo.setWebsite(RepoManager.ANDROIDACY_MAGISK_REPO_HOMEPAGE); androidacy_repo.setLastUpdate(0);
// now copy the data from the data class to the realm object using copyToRealmOrUpdate androidacy_repo.setWebsite(RepoManager.ANDROIDACY_MAGISK_REPO_HOMEPAGE);
realm1.insertOrUpdate(androidacy_repo); // now copy the data from the data class to the realm object using copyToRealmOrUpdate
} realm1.insertOrUpdate(androidacy_repo);
// create magisk_alt_repo
if (realm1.where(ReposList.class).equalTo("id", "magisk_alt_repo").findFirst() == null) {
ReposList magisk_alt_repo = realm1.createObject(ReposList.class, "magisk_alt_repo");
magisk_alt_repo.setName("Magisk Alt Repo");
magisk_alt_repo.setDonate(null);
magisk_alt_repo.setWebsite(RepoManager.MAGISK_ALT_REPO_HOMEPAGE);
magisk_alt_repo.setSupport(null);
magisk_alt_repo.setEnabled(true);
magisk_alt_repo.setUrl(RepoManager.MAGISK_ALT_REPO);
magisk_alt_repo.setSubmitModule(RepoManager.MAGISK_ALT_REPO_HOMEPAGE + "/submission");
magisk_alt_repo.setLastUpdate(0);
// commit the changes
realm1.insertOrUpdate(magisk_alt_repo);
}
realm1.commitTransaction();
} }
}); // create magisk_alt_repo
long endTime = System.currentTimeMillis(); if (realm1.where(ReposList.class).equalTo("id", "magisk_alt_repo").findFirst() == null) {
Timber.d("Realm databases created in %d ms", endTime - startTime); ReposList magisk_alt_repo = realm1.createObject(ReposList.class, "magisk_alt_repo");
magisk_alt_repo.setName("Magisk Alt Repo");
magisk_alt_repo.setDonate(null);
magisk_alt_repo.setWebsite(RepoManager.MAGISK_ALT_REPO_HOMEPAGE);
magisk_alt_repo.setSupport(null);
magisk_alt_repo.setEnabled(true);
magisk_alt_repo.setUrl(RepoManager.MAGISK_ALT_REPO);
magisk_alt_repo.setSubmitModule(RepoManager.MAGISK_ALT_REPO_HOMEPAGE + "/submission");
magisk_alt_repo.setLastUpdate(0);
// commit the changes
realm1.insertOrUpdate(magisk_alt_repo);
}
realm1.commitTransaction();
realm1.close();
long endTime = System.currentTimeMillis();
Timber.d("Realm databases created in %d ms", endTime - startTime);
}).start();
} }
public void createFiles() { public void createFiles() {

@ -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 token = MainApplication.getINSTANCE().getSharedPreferences("androidacy", Context.MODE_PRIVATE).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");
@ -55,7 +55,7 @@ public final class AndroidacyRepoData extends RepoData {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public final String ClientID = BuildConfig.ANDROIDACY_CLIENT_ID; public final String ClientID = BuildConfig.ANDROIDACY_CLIENT_ID;
public final SharedPreferences cachedPreferences = MainApplication.getINSTANCE().getSharedPreferences("androidacy", Context.MODE_PRIVATE); public final SharedPreferences cachedPreferences = MainApplication.getSharedPreferences("androidacy");
private final boolean testMode; private final boolean testMode;
private final String host; private final String host;
public String[][] userInfo = new String[][]{{"role", null}, {"permissions", null}}; public String[][] userInfo = new String[][]{{"role", null}, {"permissions", null}};
@ -89,7 +89,7 @@ public final class AndroidacyRepoData extends RepoData {
// limiting and fraud detection. // limiting and fraud detection.
public static String generateDeviceId() { public static String generateDeviceId() {
// Try to get the device ID from the shared preferences // Try to get the device ID from the shared preferences
SharedPreferences sharedPreferences = MainApplication.getINSTANCE().getSharedPreferences("androidacy", Context.MODE_PRIVATE); 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) {
return deviceIdPref; return deviceIdPref;
@ -182,7 +182,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.getSharedPreferences().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();
return false; return false;

@ -12,6 +12,8 @@ public class BackgroundBootListener extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (!BOOT_COMPLETED.equals(intent.getAction())) return; if (!BOOT_COMPLETED.equals(intent.getAction())) return;
// clear boot shared prefs
MainApplication.getBootSharedPreferences().edit().clear().apply();
synchronized (BackgroundUpdateChecker.lock) { synchronized (BackgroundUpdateChecker.lock) {
new Thread(() -> { new Thread(() -> {
BackgroundUpdateChecker.onMainActivityCreate(context); BackgroundUpdateChecker.onMainActivityCreate(context);

@ -60,7 +60,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.getSharedPreferences().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()) {
@ -68,7 +68,7 @@ public class BackgroundUpdateChecker extends Worker {
return; return;
} }
// next, check if user requires wifi // next, check if user requires wifi
if (MainApplication.getSharedPreferences().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();
@ -107,7 +107,7 @@ public class BackgroundUpdateChecker extends Worker {
continue; 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.getSharedPreferences().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 ( } catch (
Exception ignored) { Exception ignored) {
@ -127,7 +127,7 @@ public class BackgroundUpdateChecker extends Worker {
} }
}); });
// check for app updates // check for app updates
if (MainApplication.getSharedPreferences().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) {
@ -209,7 +209,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.getSharedPreferences().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) {

@ -55,7 +55,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", them=n refuse to continue // if last_shown_setup is not "v1", them=n refuse to continue
if (!MainApplication.getSharedPreferences().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);

@ -148,7 +148,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.getSharedPreferences().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

@ -22,7 +22,7 @@ public class EncryptedPreferenceDataStore extends PreferenceDataStore {
private static EncryptedPreferenceDataStore mInstance; private static EncryptedPreferenceDataStore mInstance;
private SharedPreferences mSharedPreferences; private SharedPreferences mSharedPreferences;
private EncryptedPreferenceDataStore(Context context) { EncryptedPreferenceDataStore(Context context) {
try { try {
MasterKey mainKeyAlias; MasterKey mainKeyAlias;
try { try {

@ -194,6 +194,7 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
PreferenceManager preferenceManager = getPreferenceManager(); PreferenceManager preferenceManager = getPreferenceManager();
preferenceManager.setPreferenceDataStore(new EncryptedPreferenceDataStore(this.getContext()));
preferenceManager.setSharedPreferencesName("mmm"); preferenceManager.setSharedPreferencesName("mmm");
setPreferencesFromResource(R.xml.root_preferences, rootKey); setPreferencesFromResource(R.xml.root_preferences, rootKey);
applyMaterial3(getPreferenceScreen()); applyMaterial3(getPreferenceScreen());
@ -456,7 +457,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.getSharedPreferences().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();
@ -493,7 +494,7 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
int i = 0; int i = 0;
for (LocalModuleInfo localModuleInfo : localModuleInfos) { for (LocalModuleInfo localModuleInfo : localModuleInfos) {
moduleNames[i] = localModuleInfo.name; moduleNames[i] = localModuleInfo.name;
SharedPreferences sharedPreferences = MainApplication.getSharedPreferences(); SharedPreferences sharedPreferences = MainApplication.getSharedPreferences("mmm");
// get the stringset pref_background_update_check_excludes // get the stringset pref_background_update_check_excludes
Set<String> stringSet = sharedPreferences.getStringSet("pref_background_update_check_excludes", new HashSet<>()); Set<String> stringSet = sharedPreferences.getStringSet("pref_background_update_check_excludes", new HashSet<>());
// Stringset uses id, we show name // Stringset uses id, we show name
@ -503,7 +504,7 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
} }
new MaterialAlertDialogBuilder(this.requireContext()).setTitle(R.string.background_update_check_excludes).setMultiChoiceItems(moduleNames, checkedItems, (dialog, which, isChecked) -> { new MaterialAlertDialogBuilder(this.requireContext()).setTitle(R.string.background_update_check_excludes).setMultiChoiceItems(moduleNames, checkedItems, (dialog, which, isChecked) -> {
// get the stringset pref_background_update_check_excludes // get the stringset pref_background_update_check_excludes
SharedPreferences sharedPreferences = MainApplication.getSharedPreferences(); SharedPreferences sharedPreferences = MainApplication.getSharedPreferences("mmm");
Set<String> stringSet = new HashSet<>(sharedPreferences.getStringSet("pref_background_update_check_excludes", new HashSet<>())); Set<String> stringSet = new HashSet<>(sharedPreferences.getStringSet("pref_background_update_check_excludes", new HashSet<>()));
// get id from name // get id from name
String id; String id;
@ -591,11 +592,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.getSharedPreferences().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.getSharedPreferences().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();
} }
@ -807,7 +808,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.getSharedPreferences().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);
@ -825,10 +826,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.getSharedPreferences().edit().putBoolean("androidacy_test_mode", false).apply(); MainApplication.getSharedPreferences("mmm").edit().putBoolean("androidacy_test_mode", false).apply();
}).show(); }).show();
} else { } else {
MainApplication.getSharedPreferences().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

@ -28,7 +28,7 @@ public class SentryMain {
@SuppressLint({"RestrictedApi", "UnspecifiedImmutableFlag"}) @SuppressLint({"RestrictedApi", "UnspecifiedImmutableFlag"})
public static void initialize(final MainApplication mainApplication) { public static void initialize(final MainApplication mainApplication) {
// 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.getSharedPreferences(); SharedPreferences sharedPreferences = MainApplication.getSharedPreferences("sentry");
if (!Objects.equals(sharedPreferences.getString("last_shown_setup", null), "v1")) { if (!Objects.equals(sharedPreferences.getString("last_shown_setup", null), "v1")) {
return; return;
} }
@ -81,7 +81,7 @@ public class SentryMain {
// With this callback, you can modify the event or, when returning null, also discard the event. // With this callback, you can modify the event or, when returning null, also discard the event.
options.setBeforeSend((event, hint) -> { options.setBeforeSend((event, hint) -> {
// Save lastEventId to private shared preferences // Save lastEventId to private shared preferences
SharedPreferences sentryPrefs = MainApplication.getINSTANCE().getSharedPreferences("sentry", Context.MODE_PRIVATE); SharedPreferences sentryPrefs = MainApplication.getSharedPreferences("sentry");
String lastEventId = Objects.requireNonNull(event.getEventId()).toString(); String lastEventId = Objects.requireNonNull(event.getEventId()).toString();
SharedPreferences.Editor editor = sentryPrefs.edit(); SharedPreferences.Editor editor = sentryPrefs.edit();
editor.putString("lastEventId", lastEventId); editor.putString("lastEventId", lastEventId);

@ -7,9 +7,6 @@ buildscript {
maven { maven {
url 'https://jitpack.io' url 'https://jitpack.io'
} }
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
} }
project.ext.latestAboutLibsRelease = "10.5.2" project.ext.latestAboutLibsRelease = "10.5.2"
project.ext.sentryConfigFile = new File(rootDir, "sentry.properties").getAbsoluteFile() project.ext.sentryConfigFile = new File(rootDir, "sentry.properties").getAbsoluteFile()
@ -24,12 +21,11 @@ buildscript {
classpath 'com.android.tools.build:gradle:7.4.2' classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10"
classpath "com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:${latestAboutLibsRelease}" classpath "com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:${latestAboutLibsRelease}"
classpath 'io.sentry:sentry-android:6.14.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
//noinspection GradleDependency //noinspection GradleDependency
classpath "io.realm:realm-gradle-plugin:10.13.3-transformer-api-SNAPSHOT" classpath "io.realm:realm-gradle-plugin:10.13.2-transformer-api"
} }
} }

@ -6,9 +6,6 @@ dependencyResolutionManagement {
maven { maven {
url 'https://jitpack.io' url 'https://jitpack.io'
} }
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
} }
} }
rootProject.name = "MagiskModuleManager" rootProject.name = "MagiskModuleManager"

Loading…
Cancel
Save