From 70dd2d4829377317df4557ead3e74109cb300225 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 31 Jul 2018 16:57:52 +0800 Subject: [PATCH] More moving --- .../java/com/topjohnwu/magisk/Global.java | 132 +++++++++++++++++ .../com/topjohnwu/magisk/LogFragment.java | 2 +- .../com/topjohnwu/magisk/MagiskManager.java | 135 +----------------- .../com/topjohnwu/magisk/MainActivity.java | 2 +- .../com/topjohnwu/magisk/ReposFragment.java | 6 +- .../topjohnwu/magisk/SettingsActivity.java | 24 ++-- .../com/topjohnwu/magisk/SplashActivity.java | 4 +- .../topjohnwu/magisk/asyncs/CheckUpdates.java | 2 +- .../topjohnwu/magisk/asyncs/HideManager.java | 2 +- .../magisk/asyncs/InstallMagisk.java | 6 +- .../magisk/asyncs/MarkDownWindow.java | 6 +- .../magisk/components/FlavorActivity.java | 3 +- .../components/InstallMethodDialog.java | 2 +- .../magisk/components/UninstallDialog.java | 2 +- .../magisk/database/MagiskDatabaseHelper.java | 2 +- .../magisk/database/RepoDatabaseHelper.java | 2 +- .../magisk/receivers/ShortcutReceiver.java | 2 +- .../magisk/superuser/RequestActivity.java | 5 +- .../magisk/superuser/SuReceiver.java | 2 +- 19 files changed, 174 insertions(+), 167 deletions(-) diff --git a/app/src/full/java/com/topjohnwu/magisk/Global.java b/app/src/full/java/com/topjohnwu/magisk/Global.java index 4e6c943fa..53d781809 100644 --- a/app/src/full/java/com/topjohnwu/magisk/Global.java +++ b/app/src/full/java/com/topjohnwu/magisk/Global.java @@ -1,12 +1,23 @@ package com.topjohnwu.magisk; +import android.content.SharedPreferences; import android.os.Handler; import android.os.Looper; +import android.util.Xml; import android.widget.Toast; import com.topjohnwu.magisk.utils.Const; +import com.topjohnwu.magisk.utils.Utils; +import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.ShellUtils; +import com.topjohnwu.superuser.io.SuFile; +import com.topjohnwu.superuser.io.SuFileInputStream; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + +import java.io.File; +import java.io.IOException; import java.lang.ref.WeakReference; public class Global { @@ -34,6 +45,20 @@ public class Global { public static boolean keepVerity = false; public static boolean keepEnc = false; + // Configs + public static boolean isDarkTheme; + public static int suRequestTimeout; + public static int suLogTimeout = 14; + public static int suAccessState; + public static int multiuserMode; + public static int suResponseType; + public static int suNotificationType; + public static int suNamespaceMode; + public static String localeConfig; + public static int updateChannel; + public static String bootFormat; + public static int repoOrder; + public static void loadMagiskInfo() { try { magiskVersionString = ShellUtils.fastCmd("magisk -v").split(":")[0]; @@ -55,4 +80,111 @@ public class Global { public static void toast(int resId, int duration) { mainHandler.post(() -> Toast.makeText(MM(), resId, duration).show()); } + + public static void exportPrefs() { + // Flush prefs to disk + MagiskManager mm = MM(); + mm.prefs.edit().commit(); + File xml = new File(mm.getFilesDir().getParent() + "/shared_prefs", + mm.getPackageName() + "_preferences.xml"); + Shell.su(Utils.fmt("for usr in /data/user/*; do cat %s > ${usr}/%s; done", xml, Const.MANAGER_CONFIGS)).exec(); + } + + public static void importPrefs() { + MagiskManager mm = MM(); + SuFile config = new SuFile(Utils.fmt("/data/user/%d/%s", Const.USER_ID, Const.MANAGER_CONFIGS)); + if (config.exists()) { + SharedPreferences.Editor editor = mm.prefs.edit(); + try { + SuFileInputStream is = new SuFileInputStream(config); + XmlPullParser parser = Xml.newPullParser(); + parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); + parser.setInput(is, "UTF-8"); + parser.nextTag(); + parser.require(XmlPullParser.START_TAG, null, "map"); + while (parser.next() != XmlPullParser.END_TAG) { + if (parser.getEventType() != XmlPullParser.START_TAG) + continue; + String key = parser.getAttributeValue(null, "name"); + String value = parser.getAttributeValue(null, "value"); + switch (parser.getName()) { + case "string": + parser.require(XmlPullParser.START_TAG, null, "string"); + editor.putString(key, parser.nextText()); + parser.require(XmlPullParser.END_TAG, null, "string"); + break; + case "boolean": + parser.require(XmlPullParser.START_TAG, null, "boolean"); + editor.putBoolean(key, Boolean.parseBoolean(value)); + parser.nextTag(); + parser.require(XmlPullParser.END_TAG, null, "boolean"); + break; + case "int": + parser.require(XmlPullParser.START_TAG, null, "int"); + editor.putInt(key, Integer.parseInt(value)); + parser.nextTag(); + parser.require(XmlPullParser.END_TAG, null, "int"); + break; + case "long": + parser.require(XmlPullParser.START_TAG, null, "long"); + editor.putLong(key, Long.parseLong(value)); + parser.nextTag(); + parser.require(XmlPullParser.END_TAG, null, "long"); + break; + case "float": + parser.require(XmlPullParser.START_TAG, null, "int"); + editor.putFloat(key, Float.parseFloat(value)); + parser.nextTag(); + parser.require(XmlPullParser.END_TAG, null, "int"); + break; + default: + parser.next(); + } + } + } catch (IOException | XmlPullParserException e) { + e.printStackTrace(); + } + editor.remove(Const.Key.ETAG_KEY); + editor.apply(); + loadConfig(); + config.delete(); + } + } + + public static void loadConfig() { + MagiskManager mm = MM(); + // su + suRequestTimeout = Utils.getPrefsInt(mm.prefs, Const.Key.SU_REQUEST_TIMEOUT, Const.Value.timeoutList[2]); + suResponseType = Utils.getPrefsInt(mm.prefs, Const.Key.SU_AUTO_RESPONSE, Const.Value.SU_PROMPT); + suNotificationType = Utils.getPrefsInt(mm.prefs, Const.Key.SU_NOTIFICATION, Const.Value.NOTIFICATION_TOAST); + suAccessState = mm.mDB.getSettings(Const.Key.ROOT_ACCESS, Const.Value.ROOT_ACCESS_APPS_AND_ADB); + multiuserMode = mm.mDB.getSettings(Const.Key.SU_MULTIUSER_MODE, Const.Value.MULTIUSER_MODE_OWNER_ONLY); + suNamespaceMode = mm.mDB.getSettings(Const.Key.SU_MNT_NS, Const.Value.NAMESPACE_MODE_REQUESTER); + + // config + isDarkTheme = mm.prefs.getBoolean(Const.Key.DARK_THEME, false); + updateChannel = Utils.getPrefsInt(mm.prefs, Const.Key.UPDATE_CHANNEL, Const.Value.STABLE_CHANNEL); + bootFormat = mm.prefs.getString(Const.Key.BOOT_FORMAT, ".img"); + repoOrder = mm.prefs.getInt(Const.Key.REPO_ORDER, Const.Value.ORDER_NAME); + } + + public static void writeConfig() { + MM().prefs.edit() + .putBoolean(Const.Key.DARK_THEME, isDarkTheme) + .putBoolean(Const.Key.MAGISKHIDE, magiskHide) + .putBoolean(Const.Key.HOSTS, Const.MAGISK_HOST_FILE.exists()) + .putBoolean(Const.Key.COREONLY, Const.MAGISK_DISABLE_FILE.exists()) + .putString(Const.Key.SU_REQUEST_TIMEOUT, String.valueOf(suRequestTimeout)) + .putString(Const.Key.SU_AUTO_RESPONSE, String.valueOf(suResponseType)) + .putString(Const.Key.SU_NOTIFICATION, String.valueOf(suNotificationType)) + .putString(Const.Key.ROOT_ACCESS, String.valueOf(suAccessState)) + .putString(Const.Key.SU_MULTIUSER_MODE, String.valueOf(multiuserMode)) + .putString(Const.Key.SU_MNT_NS, String.valueOf(suNamespaceMode)) + .putString(Const.Key.UPDATE_CHANNEL, String.valueOf(updateChannel)) + .putString(Const.Key.LOCALE, localeConfig) + .putString(Const.Key.BOOT_FORMAT, bootFormat) + .putInt(Const.Key.UPDATE_SERVICE_VER, Const.UPDATE_SERVICE_VER) + .putInt(Const.Key.REPO_ORDER, repoOrder) + .apply(); + } } diff --git a/app/src/full/java/com/topjohnwu/magisk/LogFragment.java b/app/src/full/java/com/topjohnwu/magisk/LogFragment.java index e61e275e1..762057c45 100644 --- a/app/src/full/java/com/topjohnwu/magisk/LogFragment.java +++ b/app/src/full/java/com/topjohnwu/magisk/LogFragment.java @@ -34,7 +34,7 @@ public class LogFragment extends Fragment { TabFragmentAdapter adapter = new TabFragmentAdapter(getChildFragmentManager()); - if (!(Const.USER_ID > 0 && getApplication().multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) { + if (!(Const.USER_ID > 0 && Global.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) { adapter.addTab(new SuLogFragment(), getString(R.string.superuser)); } adapter.addTab(new MagiskLogFragment(), getString(R.string.magisk)); diff --git a/app/src/full/java/com/topjohnwu/magisk/MagiskManager.java b/app/src/full/java/com/topjohnwu/magisk/MagiskManager.java index 18a74463b..3b1d30b3b 100644 --- a/app/src/full/java/com/topjohnwu/magisk/MagiskManager.java +++ b/app/src/full/java/com/topjohnwu/magisk/MagiskManager.java @@ -4,11 +4,8 @@ import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.content.res.Resources; -import android.os.Handler; import android.preference.PreferenceManager; import android.text.TextUtils; -import android.util.Xml; -import android.widget.Toast; import com.topjohnwu.magisk.container.Module; import com.topjohnwu.magisk.database.MagiskDatabaseHelper; @@ -16,17 +13,9 @@ import com.topjohnwu.magisk.database.RepoDatabaseHelper; import com.topjohnwu.magisk.utils.Const; import com.topjohnwu.magisk.utils.RootUtils; import com.topjohnwu.magisk.utils.Topic; -import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.superuser.ContainerApp; import com.topjohnwu.superuser.Shell; -import com.topjohnwu.superuser.io.SuFile; -import com.topjohnwu.superuser.io.SuFileInputStream; -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; - -import java.io.File; -import java.io.IOException; import java.lang.ref.WeakReference; import java.util.List; import java.util.Locale; @@ -53,19 +42,6 @@ public class MagiskManager extends ContainerApp { public Map moduleMap; public List locales; - public boolean isDarkTheme; - public int suRequestTimeout; - public int suLogTimeout = 14; - public int suAccessState; - public int multiuserMode; - public int suResponseType; - public int suNotificationType; - public int suNamespaceMode; - public String localeConfig; - public int updateChannel; - public String bootFormat; - public int repoOrder; - // Global resources public SharedPreferences prefs; public MagiskDatabaseHelper mDB; @@ -101,15 +77,15 @@ public class MagiskManager extends ContainerApp { } setLocale(); - loadConfig(); + Global.loadConfig(); } public void setLocale() { - localeConfig = prefs.getString(Const.Key.LOCALE, ""); - if (localeConfig.isEmpty()) { + Global.localeConfig = prefs.getString(Const.Key.LOCALE, ""); + if (Global.localeConfig.isEmpty()) { locale = defaultLocale; } else { - locale = Locale.forLanguageTag(localeConfig); + locale = Locale.forLanguageTag(Global.localeConfig); } Resources res = getBaseContext().getResources(); Configuration config = new Configuration(res.getConfiguration()); @@ -117,107 +93,4 @@ public class MagiskManager extends ContainerApp { res.updateConfiguration(config, res.getDisplayMetrics()); } - public void loadConfig() { - // su - suRequestTimeout = Utils.getPrefsInt(prefs, Const.Key.SU_REQUEST_TIMEOUT, Const.Value.timeoutList[2]); - suResponseType = Utils.getPrefsInt(prefs, Const.Key.SU_AUTO_RESPONSE, Const.Value.SU_PROMPT); - suNotificationType = Utils.getPrefsInt(prefs, Const.Key.SU_NOTIFICATION, Const.Value.NOTIFICATION_TOAST); - suAccessState = mDB.getSettings(Const.Key.ROOT_ACCESS, Const.Value.ROOT_ACCESS_APPS_AND_ADB); - multiuserMode = mDB.getSettings(Const.Key.SU_MULTIUSER_MODE, Const.Value.MULTIUSER_MODE_OWNER_ONLY); - suNamespaceMode = mDB.getSettings(Const.Key.SU_MNT_NS, Const.Value.NAMESPACE_MODE_REQUESTER); - - // config - isDarkTheme = prefs.getBoolean(Const.Key.DARK_THEME, false); - updateChannel = Utils.getPrefsInt(prefs, Const.Key.UPDATE_CHANNEL, Const.Value.STABLE_CHANNEL); - bootFormat = prefs.getString(Const.Key.BOOT_FORMAT, ".img"); - repoOrder = prefs.getInt(Const.Key.REPO_ORDER, Const.Value.ORDER_NAME); - } - - public void writeConfig() { - prefs.edit() - .putBoolean(Const.Key.DARK_THEME, isDarkTheme) - .putBoolean(Const.Key.MAGISKHIDE, Global.magiskHide) - .putBoolean(Const.Key.HOSTS, Const.MAGISK_HOST_FILE.exists()) - .putBoolean(Const.Key.COREONLY, Const.MAGISK_DISABLE_FILE.exists()) - .putString(Const.Key.SU_REQUEST_TIMEOUT, String.valueOf(suRequestTimeout)) - .putString(Const.Key.SU_AUTO_RESPONSE, String.valueOf(suResponseType)) - .putString(Const.Key.SU_NOTIFICATION, String.valueOf(suNotificationType)) - .putString(Const.Key.ROOT_ACCESS, String.valueOf(suAccessState)) - .putString(Const.Key.SU_MULTIUSER_MODE, String.valueOf(multiuserMode)) - .putString(Const.Key.SU_MNT_NS, String.valueOf(suNamespaceMode)) - .putString(Const.Key.UPDATE_CHANNEL, String.valueOf(updateChannel)) - .putString(Const.Key.LOCALE, localeConfig) - .putString(Const.Key.BOOT_FORMAT, bootFormat) - .putInt(Const.Key.UPDATE_SERVICE_VER, Const.UPDATE_SERVICE_VER) - .putInt(Const.Key.REPO_ORDER, repoOrder) - .apply(); - } - - public void dumpPrefs() { - // Flush prefs to disk - prefs.edit().commit(); - File xml = new File(getFilesDir().getParent() + "/shared_prefs", - getPackageName() + "_preferences.xml"); - Shell.su(Utils.fmt("for usr in /data/user/*; do cat %s > ${usr}/%s; done", xml, Const.MANAGER_CONFIGS)).exec(); - } - - public void loadPrefs() { - SuFile config = new SuFile(Utils.fmt("/data/user/%d/%s", Const.USER_ID, Const.MANAGER_CONFIGS)); - if (config.exists()) { - SharedPreferences.Editor editor = prefs.edit(); - try { - SuFileInputStream is = new SuFileInputStream(config); - XmlPullParser parser = Xml.newPullParser(); - parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); - parser.setInput(is, "UTF-8"); - parser.nextTag(); - parser.require(XmlPullParser.START_TAG, null, "map"); - while (parser.next() != XmlPullParser.END_TAG) { - if (parser.getEventType() != XmlPullParser.START_TAG) - continue; - String key = parser.getAttributeValue(null, "name"); - String value = parser.getAttributeValue(null, "value"); - switch (parser.getName()) { - case "string": - parser.require(XmlPullParser.START_TAG, null, "string"); - editor.putString(key, parser.nextText()); - parser.require(XmlPullParser.END_TAG, null, "string"); - break; - case "boolean": - parser.require(XmlPullParser.START_TAG, null, "boolean"); - editor.putBoolean(key, Boolean.parseBoolean(value)); - parser.nextTag(); - parser.require(XmlPullParser.END_TAG, null, "boolean"); - break; - case "int": - parser.require(XmlPullParser.START_TAG, null, "int"); - editor.putInt(key, Integer.parseInt(value)); - parser.nextTag(); - parser.require(XmlPullParser.END_TAG, null, "int"); - break; - case "long": - parser.require(XmlPullParser.START_TAG, null, "long"); - editor.putLong(key, Long.parseLong(value)); - parser.nextTag(); - parser.require(XmlPullParser.END_TAG, null, "long"); - break; - case "float": - parser.require(XmlPullParser.START_TAG, null, "int"); - editor.putFloat(key, Float.parseFloat(value)); - parser.nextTag(); - parser.require(XmlPullParser.END_TAG, null, "int"); - break; - default: - parser.next(); - } - } - } catch (IOException | XmlPullParserException e) { - e.printStackTrace(); - } - editor.remove(Const.Key.ETAG_KEY); - editor.apply(); - loadConfig(); - config.delete(); - } - } } diff --git a/app/src/full/java/com/topjohnwu/magisk/MainActivity.java b/app/src/full/java/com/topjohnwu/magisk/MainActivity.java index 222400197..38e7cfb7e 100644 --- a/app/src/full/java/com/topjohnwu/magisk/MainActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/MainActivity.java @@ -133,7 +133,7 @@ public class MainActivity extends Activity && Download.checkNetworkStatus(this) && Shell.rootAccess() && Global.magiskVersionCode >= 0); menu.findItem(R.id.log).setVisible(Shell.rootAccess()); menu.findItem(R.id.superuser).setVisible(Shell.rootAccess() && - !(Const.USER_ID > 0 && mm.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)); + !(Const.USER_ID > 0 && Global.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)); } public void navigate(String item) { diff --git a/app/src/full/java/com/topjohnwu/magisk/ReposFragment.java b/app/src/full/java/com/topjohnwu/magisk/ReposFragment.java index d80dfc855..91876d9a9 100644 --- a/app/src/full/java/com/topjohnwu/magisk/ReposFragment.java +++ b/app/src/full/java/com/topjohnwu/magisk/ReposFragment.java @@ -108,9 +108,9 @@ public class ReposFragment extends Fragment implements Topic.Subscriber { if (item.getItemId() == R.id.repo_sort) { new AlertDialog.Builder(getActivity()) .setTitle(R.string.sorting_order) - .setSingleChoiceItems(R.array.sorting_orders, mm.repoOrder, (d, which) -> { - mm.repoOrder = which; - mm.prefs.edit().putInt(Const.Key.REPO_ORDER, mm.repoOrder).apply(); + .setSingleChoiceItems(R.array.sorting_orders, Global.repoOrder, (d, which) -> { + Global.repoOrder = which; + mm.prefs.edit().putInt(Const.Key.REPO_ORDER, Global.repoOrder).apply(); adapter.notifyDBChanged(); d.dismiss(); }).show(); diff --git a/app/src/full/java/com/topjohnwu/magisk/SettingsActivity.java b/app/src/full/java/com/topjohnwu/magisk/SettingsActivity.java index ea65238e9..373422595 100644 --- a/app/src/full/java/com/topjohnwu/magisk/SettingsActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/SettingsActivity.java @@ -123,8 +123,8 @@ public class SettingsActivity extends Activity implements Topic.Subscriber { SwitchPreference fingerprint = (SwitchPreference) findPreference(Const.Key.SU_FINGERPRINT); updateChannel.setOnPreferenceChangeListener((pref, o) -> { - mm.updateChannel = Integer.parseInt((String) o); - if (mm.updateChannel == Const.Value.CUSTOM_CHANNEL) { + Global.updateChannel = Integer.parseInt((String) o); + if (Global.updateChannel == Const.Value.CUSTOM_CHANNEL) { View v = LayoutInflater.from(getActivity()).inflate(R.layout.custom_channel_dialog, null); EditText url = v.findViewById(R.id.custom_url); url.setText(mm.prefs.getString(Const.Key.CUSTOM_CHANNEL, "")); @@ -173,7 +173,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber { getActivity(), new DownloadReceiver() { @Override public void onDownloadDone(Context context, Uri uri) { - mm.dumpPrefs(); + Global.exportPrefs(); Shell.su("cp " + uri.getPath() + " /data/local/tmp/manager.apk").exec(); if (ShellUtils.fastCmdResult("pm install /data/local/tmp/manager.apk")) { Shell.su("rm -f /data/local/tmp/manager.apk").exec(); @@ -199,7 +199,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber { } if (!Shell.rootAccess() || (Const.USER_ID > 0 && - mm.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) { + Global.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) { prefScreen.removePreference(suCategory); } @@ -245,7 +245,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber { switch (key) { case Const.Key.DARK_THEME: - mm.isDarkTheme = prefs.getBoolean(key, false); + Global.isDarkTheme = prefs.getBoolean(key, false); mm.reloadActivity.publish(false); return; case Const.Key.COREONLY: @@ -292,25 +292,25 @@ public class SettingsActivity extends Activity implements Topic.Subscriber { Utils.setupUpdateCheck(); break; } - mm.loadConfig(); + Global.loadConfig(); setSummary(); } private void setSummary() { updateChannel.setSummary(getResources() - .getStringArray(R.array.update_channel)[mm.updateChannel]); + .getStringArray(R.array.update_channel)[Global.updateChannel]); suAccess.setSummary(getResources() - .getStringArray(R.array.su_access)[mm.suAccessState]); + .getStringArray(R.array.su_access)[Global.suAccessState]); autoRes.setSummary(getResources() - .getStringArray(R.array.auto_response)[mm.suResponseType]); + .getStringArray(R.array.auto_response)[Global.suResponseType]); suNotification.setSummary(getResources() - .getStringArray(R.array.su_notification)[mm.suNotificationType]); + .getStringArray(R.array.su_notification)[Global.suNotificationType]); requestTimeout.setSummary( getString(R.string.request_timeout_summary, prefs.getString(Const.Key.SU_REQUEST_TIMEOUT, "10"))); multiuserMode.setSummary(getResources() - .getStringArray(R.array.multiuser_summary)[mm.multiuserMode]); + .getStringArray(R.array.multiuser_summary)[Global.multiuserMode]); namespaceMode.setSummary(getResources() - .getStringArray(R.array.namespace_summary)[mm.suNamespaceMode]); + .getStringArray(R.array.namespace_summary)[Global.suNamespaceMode]); } @Override diff --git a/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java b/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java index 15a57aaec..cade7ec8e 100644 --- a/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java @@ -29,7 +29,7 @@ public class SplashActivity extends Activity { boolean root = Shell.rootAccess(); mm.repoDB = new RepoDatabaseHelper(this); - mm.loadPrefs(); + Global.importPrefs(); // Dynamic detect all locales new LoadLocale().exec(); @@ -62,7 +62,7 @@ public class SplashActivity extends Activity { } // Write back default values - mm.writeConfig(); + Global.writeConfig(); mm.hasInit = true; diff --git a/app/src/full/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java b/app/src/full/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java index 621fa917f..410367073 100644 --- a/app/src/full/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java +++ b/app/src/full/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java @@ -54,7 +54,7 @@ public class CheckUpdates extends ParallelTask { protected Void doInBackground(Void... voids) { MagiskManager mm = Global.MM(); String jsonStr = ""; - switch (mm.updateChannel) { + switch (Global.updateChannel) { case Const.Value.STABLE_CHANNEL: jsonStr = WebService.getString(Const.Url.STABLE_URL); break; diff --git a/app/src/full/java/com/topjohnwu/magisk/asyncs/HideManager.java b/app/src/full/java/com/topjohnwu/magisk/asyncs/HideManager.java index 6f202a078..e6381a14e 100644 --- a/app/src/full/java/com/topjohnwu/magisk/asyncs/HideManager.java +++ b/app/src/full/java/com/topjohnwu/magisk/asyncs/HideManager.java @@ -79,7 +79,7 @@ public class HideManager extends ParallelTask { repack.delete(); mm.mDB.setStrings(Const.Key.SU_MANAGER, pkg); - mm.dumpPrefs(); + Global.exportPrefs(); RootUtils.uninstallPkg(Const.ORIG_PKG_NAME); return true; diff --git a/app/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java b/app/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java index d53d99cb5..42a3cd1ac 100644 --- a/app/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java +++ b/app/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java @@ -9,8 +9,8 @@ import android.text.TextUtils; import android.view.View; import android.widget.Toast; -import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.FlashActivity; +import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.container.TarEntry; @@ -231,10 +231,10 @@ public class InstallMagisk extends ParallelTask { private void outputBoot(File patched) throws IOException { switch (mode) { case PATCH_MODE: - File dest = new File(Download.EXTERNAL_PATH, "patched_boot" + mm.bootFormat); + File dest = new File(Download.EXTERNAL_PATH, "patched_boot" + Global.bootFormat); dest.getParentFile().mkdirs(); OutputStream out; - switch (mm.bootFormat) { + switch (Global.bootFormat) { case ".img.tar": out = new TarOutputStream(new BufferedOutputStream(new FileOutputStream(dest))); ((TarOutputStream) out).putNextEntry(new TarEntry(patched, "boot.img")); diff --git a/app/src/full/java/com/topjohnwu/magisk/asyncs/MarkDownWindow.java b/app/src/full/java/com/topjohnwu/magisk/asyncs/MarkDownWindow.java index 2383835c3..6e7bbd94c 100644 --- a/app/src/full/java/com/topjohnwu/magisk/asyncs/MarkDownWindow.java +++ b/app/src/full/java/com/topjohnwu/magisk/asyncs/MarkDownWindow.java @@ -55,9 +55,9 @@ public class MarkDownWindow extends ParallelTask { } String css; try ( - InputStream in = mm.getResources().openRawResource( - mm.isDarkTheme ? R.raw.dark : R.raw.light); - ByteArrayOutputStream out = new ByteArrayOutputStream() + InputStream in = mm.getResources().openRawResource( + Global.isDarkTheme ? R.raw.dark : R.raw.light); + ByteArrayOutputStream out = new ByteArrayOutputStream() ) { ShellUtils.pump(in, out); css = out.toString(); diff --git a/app/src/full/java/com/topjohnwu/magisk/components/FlavorActivity.java b/app/src/full/java/com/topjohnwu/magisk/components/FlavorActivity.java index 55f9b450c..f577f3e3d 100644 --- a/app/src/full/java/com/topjohnwu/magisk/components/FlavorActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/components/FlavorActivity.java @@ -8,6 +8,7 @@ import android.support.annotation.StyleRes; import android.support.v7.app.AppCompatActivity; import android.view.WindowManager; +import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.utils.Topic; @@ -38,7 +39,7 @@ public abstract class FlavorActivity extends AppCompatActivity { if (this instanceof Topic.Subscriber) { ((Topic.Subscriber) this).subscribeTopics(); } - if (getMagiskManager().isDarkTheme && getDarkTheme() != -1) { + if (Global.isDarkTheme && getDarkTheme() != -1) { setTheme(getDarkTheme()); } } diff --git a/app/src/full/java/com/topjohnwu/magisk/components/InstallMethodDialog.java b/app/src/full/java/com/topjohnwu/magisk/components/InstallMethodDialog.java index 5527cc002..6c8242874 100644 --- a/app/src/full/java/com/topjohnwu/magisk/components/InstallMethodDialog.java +++ b/app/src/full/java/com/topjohnwu/magisk/components/InstallMethodDialog.java @@ -7,8 +7,8 @@ import android.support.design.widget.Snackbar; import android.support.v7.app.AlertDialog; import android.widget.Toast; -import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.FlashActivity; +import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.receivers.DownloadReceiver; diff --git a/app/src/full/java/com/topjohnwu/magisk/components/UninstallDialog.java b/app/src/full/java/com/topjohnwu/magisk/components/UninstallDialog.java index 3ed2941dd..8cba4853f 100644 --- a/app/src/full/java/com/topjohnwu/magisk/components/UninstallDialog.java +++ b/app/src/full/java/com/topjohnwu/magisk/components/UninstallDialog.java @@ -7,8 +7,8 @@ import android.net.Uri; import android.support.annotation.NonNull; import android.text.TextUtils; -import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.FlashActivity; +import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.asyncs.RestoreImages; diff --git a/app/src/full/java/com/topjohnwu/magisk/database/MagiskDatabaseHelper.java b/app/src/full/java/com/topjohnwu/magisk/database/MagiskDatabaseHelper.java index 529b93c13..bcd3f5d2f 100644 --- a/app/src/full/java/com/topjohnwu/magisk/database/MagiskDatabaseHelper.java +++ b/app/src/full/java/com/topjohnwu/magisk/database/MagiskDatabaseHelper.java @@ -174,7 +174,7 @@ public class MagiskDatabaseHelper { // Clear outdated policies db.delete(POLICY_TABLE, Utils.fmt("until > 0 AND until < %d", System.currentTimeMillis() / 1000), null); // Clear outdated logs - db.delete(LOG_TABLE, Utils.fmt("time < %d", System.currentTimeMillis() - Global.MM().suLogTimeout * 86400000), null); + db.delete(LOG_TABLE, Utils.fmt("time < %d", System.currentTimeMillis() - Global.suLogTimeout * 86400000), null); } public void deletePolicy(Policy policy) { diff --git a/app/src/full/java/com/topjohnwu/magisk/database/RepoDatabaseHelper.java b/app/src/full/java/com/topjohnwu/magisk/database/RepoDatabaseHelper.java index 7995fee28..f4f94912d 100644 --- a/app/src/full/java/com/topjohnwu/magisk/database/RepoDatabaseHelper.java +++ b/app/src/full/java/com/topjohnwu/magisk/database/RepoDatabaseHelper.java @@ -101,7 +101,7 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper { public Cursor getRepoCursor() { String orderBy = null; - switch (mm.repoOrder) { + switch (Global.repoOrder) { case Const.Value.ORDER_NAME: orderBy = "name COLLATE NOCASE"; break; diff --git a/app/src/full/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java b/app/src/full/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java index 80ee13ae4..7d99fe0d4 100644 --- a/app/src/full/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java +++ b/app/src/full/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java @@ -34,7 +34,7 @@ public class ShortcutReceiver extends BroadcastReceiver { ArrayList shortCuts = new ArrayList<>(); boolean root = Shell.rootAccess(); if (root && !(Const.USER_ID > 0 && - mm.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) { + Global.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) { shortCuts.add(new ShortcutInfo.Builder(mm, "superuser") .setShortLabel(mm.getString(R.string.superuser)) .setIntent(new Intent(mm, SplashActivity.class) diff --git a/app/src/full/java/com/topjohnwu/magisk/superuser/RequestActivity.java b/app/src/full/java/com/topjohnwu/magisk/superuser/RequestActivity.java index 10bb42c68..62f748c56 100644 --- a/app/src/full/java/com/topjohnwu/magisk/superuser/RequestActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/superuser/RequestActivity.java @@ -19,6 +19,7 @@ import android.widget.LinearLayout; import android.widget.Spinner; import android.widget.TextView; +import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.asyncs.ParallelTask; @@ -102,7 +103,7 @@ public class RequestActivity extends Activity { } private void showRequest() { - switch (mm.suResponseType) { + switch (Global.suResponseType) { case Const.Value.SU_AUTO_DENY: handleAction(Policy.DENY, 0); return; @@ -131,7 +132,7 @@ public class RequestActivity extends Activity { adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); timeout.setAdapter(adapter); - timer = new CountDownTimer(mm.suRequestTimeout * 1000, 1000) { + timer = new CountDownTimer(Global.suRequestTimeout * 1000, 1000) { @Override public void onTick(long millisUntilFinished) { deny_btn.setText(getString(R.string.deny_with_str, "(" + millisUntilFinished / 1000 + ")")); diff --git a/app/src/full/java/com/topjohnwu/magisk/superuser/SuReceiver.java b/app/src/full/java/com/topjohnwu/magisk/superuser/SuReceiver.java index b561e6dde..772f936ed 100644 --- a/app/src/full/java/com/topjohnwu/magisk/superuser/SuReceiver.java +++ b/app/src/full/java/com/topjohnwu/magisk/superuser/SuReceiver.java @@ -70,7 +70,7 @@ public class SuReceiver extends BroadcastReceiver { return; } - if (policy.notification && mm.suNotificationType == Const.Value.NOTIFICATION_TOAST) { + if (policy.notification && Global.suNotificationType == Const.Value.NOTIFICATION_TOAST) { Global.toast(message, Toast.LENGTH_SHORT); }