Rename and move methods

This commit is contained in:
topjohnwu 2018-07-31 17:41:54 +08:00
parent 7c74be2790
commit f900189f90
36 changed files with 182 additions and 180 deletions

View File

@ -4,7 +4,6 @@ import android.content.SharedPreferences;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.util.Xml; import android.util.Xml;
import android.widget.Toast;
import com.topjohnwu.magisk.utils.Const; import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
@ -20,7 +19,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
public class Global { public class Data {
// Global app instance // Global app instance
public static WeakReference<MagiskManager> weakApp; public static WeakReference<MagiskManager> weakApp;
public static Handler mainHandler = new Handler(Looper.getMainLooper()); public static Handler mainHandler = new Handler(Looper.getMainLooper());
@ -73,14 +72,6 @@ public class Global {
return weakApp.get(); return weakApp.get();
} }
public static void toast(CharSequence msg, int duration) {
mainHandler.post(() -> Toast.makeText(MM(), msg, duration).show());
}
public static void toast(int resId, int duration) {
mainHandler.post(() -> Toast.makeText(MM(), resId, duration).show());
}
public static void exportPrefs() { public static void exportPrefs() {
// Flush prefs to disk // Flush prefs to disk
MagiskManager mm = MM(); MagiskManager mm = MM();

View File

@ -20,6 +20,7 @@ import com.topjohnwu.magisk.components.Activity;
import com.topjohnwu.magisk.utils.Const; import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Download; import com.topjohnwu.magisk.utils.Download;
import com.topjohnwu.magisk.utils.RootUtils; import com.topjohnwu.magisk.utils.RootUtils;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.superuser.CallbackList; import com.topjohnwu.superuser.CallbackList;
import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.Shell;
@ -75,7 +76,7 @@ public class FlashActivity extends Activity {
e.printStackTrace(); e.printStackTrace();
return; return;
} }
Global.toast(logFile.getPath(), Toast.LENGTH_LONG); Utils.toast(logFile.getPath(), Toast.LENGTH_LONG);
} }
@Override @Override

View File

@ -34,7 +34,7 @@ public class LogFragment extends Fragment {
TabFragmentAdapter adapter = new TabFragmentAdapter(getChildFragmentManager()); TabFragmentAdapter adapter = new TabFragmentAdapter(getChildFragmentManager());
if (!(Const.USER_ID > 0 && Global.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) { if (!(Const.USER_ID > 0 && Data.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) {
adapter.addTab(new SuLogFragment(), getString(R.string.superuser)); adapter.addTab(new SuLogFragment(), getString(R.string.superuser));
} }
adapter.addTab(new MagiskLogFragment(), getString(R.string.magisk)); adapter.addTab(new MagiskLogFragment(), getString(R.string.magisk));

View File

@ -119,7 +119,7 @@ public class MagiskFragment extends Fragment
shownDialog = true; shownDialog = true;
// Show Manager update first // Show Manager update first
if (Global.remoteManagerVersionCode > BuildConfig.VERSION_CODE) { if (Data.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
new ManagerInstallDialog((Activity) requireActivity()).show(); new ManagerInstallDialog((Activity) requireActivity()).show();
return; return;
} }
@ -146,10 +146,10 @@ public class MagiskFragment extends Fragment
expandableContainer.expandLayout = expandLayout; expandableContainer.expandLayout = expandLayout;
setupExpandable(); setupExpandable();
keepVerityChkbox.setChecked(Global.keepVerity); keepVerityChkbox.setChecked(Data.keepVerity);
keepVerityChkbox.setOnCheckedChangeListener((view, checked) -> Global.keepVerity = checked); keepVerityChkbox.setOnCheckedChangeListener((view, checked) -> Data.keepVerity = checked);
keepEncChkbox.setChecked(Global.keepEnc); keepEncChkbox.setChecked(Data.keepEnc);
keepEncChkbox.setOnCheckedChangeListener((view, checked) -> Global.keepEnc = checked); keepEncChkbox.setOnCheckedChangeListener((view, checked) -> Data.keepEnc = checked);
mSwipeRefreshLayout.setOnRefreshListener(this); mSwipeRefreshLayout.setOnRefreshListener(this);
updateUI(); updateUI();
@ -159,7 +159,7 @@ public class MagiskFragment extends Fragment
@Override @Override
public void onRefresh() { public void onRefresh() {
Global.loadMagiskInfo(); Data.loadMagiskInfo();
updateUI(); updateUI();
magiskUpdateText.setText(R.string.checking_for_updates); magiskUpdateText.setText(R.string.checking_for_updates);
@ -170,8 +170,8 @@ public class MagiskFragment extends Fragment
mm.safetyNetDone.reset(); mm.safetyNetDone.reset();
mm.updateCheckDone.reset(); mm.updateCheckDone.reset();
Global.remoteMagiskVersionString = null; Data.remoteMagiskVersionString = null;
Global.remoteMagiskVersionCode = -1; Data.remoteMagiskVersionCode = -1;
collapse(); collapse();
shownDialog = false; shownDialog = false;
@ -214,7 +214,7 @@ public class MagiskFragment extends Fragment
boolean hasNetwork = Download.checkNetworkStatus(mm); boolean hasNetwork = Download.checkNetworkStatus(mm);
boolean hasRoot = Shell.rootAccess(); boolean hasRoot = Shell.rootAccess();
boolean isUpToDate = Global.magiskVersionCode > Const.MAGISK_VER.UNIFIED; boolean isUpToDate = Data.magiskVersionCode > Const.MAGISK_VER.UNIFIED;
magiskUpdate.setVisibility(hasNetwork ? View.VISIBLE : View.GONE); magiskUpdate.setVisibility(hasNetwork ? View.VISIBLE : View.GONE);
safetyNetCard.setVisibility(hasNetwork ? View.VISIBLE : View.GONE); safetyNetCard.setVisibility(hasNetwork ? View.VISIBLE : View.GONE);
@ -223,14 +223,14 @@ public class MagiskFragment extends Fragment
int image, color; int image, color;
if (Global.magiskVersionCode < 0) { if (Data.magiskVersionCode < 0) {
color = colorBad; color = colorBad;
image = R.drawable.ic_cancel; image = R.drawable.ic_cancel;
magiskVersionText.setText(R.string.magisk_version_error); magiskVersionText.setText(R.string.magisk_version_error);
} else { } else {
color = colorOK; color = colorOK;
image = R.drawable.ic_check_circle; image = R.drawable.ic_check_circle;
magiskVersionText.setText(getString(R.string.current_magisk_title, "v" + Global.magiskVersionString)); magiskVersionText.setText(getString(R.string.current_magisk_title, "v" + Data.magiskVersionString));
} }
magiskStatusIcon.setImageResource(image); magiskStatusIcon.setImageResource(image);
@ -240,7 +240,7 @@ public class MagiskFragment extends Fragment
private void updateCheckUI() { private void updateCheckUI() {
int image, color; int image, color;
if (Global.remoteMagiskVersionCode < 0) { if (Data.remoteMagiskVersionCode < 0) {
color = colorNeutral; color = colorNeutral;
image = R.drawable.ic_help; image = R.drawable.ic_help;
magiskUpdateText.setText(R.string.invalid_update_channel); magiskUpdateText.setText(R.string.invalid_update_channel);
@ -248,11 +248,11 @@ public class MagiskFragment extends Fragment
} else { } else {
color = colorOK; color = colorOK;
image = R.drawable.ic_check_circle; image = R.drawable.ic_check_circle;
magiskUpdateText.setText(getString(R.string.install_magisk_title, "v" + Global.remoteMagiskVersionString)); magiskUpdateText.setText(getString(R.string.install_magisk_title, "v" + Data.remoteMagiskVersionString));
installButton.setVisibility(View.VISIBLE); installButton.setVisibility(View.VISIBLE);
if (Global.remoteManagerVersionCode > BuildConfig.VERSION_CODE) { if (Data.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
installText.setText(getString(R.string.update, getString(R.string.app_name))); installText.setText(getString(R.string.update, getString(R.string.app_name)));
} else if (Global.magiskVersionCode > 0 && Global.remoteMagiskVersionCode > Global.magiskVersionCode) { } else if (Data.magiskVersionCode > 0 && Data.remoteMagiskVersionCode > Data.magiskVersionCode) {
installText.setText(getString(R.string.update, getString(R.string.magisk))); installText.setText(getString(R.string.update, getString(R.string.magisk)));
} else { } else {
installText.setText(R.string.install); installText.setText(R.string.install);
@ -267,10 +267,10 @@ public class MagiskFragment extends Fragment
mSwipeRefreshLayout.setRefreshing(false); mSwipeRefreshLayout.setRefreshing(false);
if (!shownDialog) { if (!shownDialog) {
if (Global.remoteMagiskVersionCode > Global.magiskVersionCode if (Data.remoteMagiskVersionCode > Data.magiskVersionCode
|| Global.remoteManagerVersionCode > BuildConfig.VERSION_CODE) { || Data.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
install(); install();
} else if (Global.remoteMagiskVersionCode >= Const.MAGISK_VER.FIX_ENV && } else if (Data.remoteMagiskVersionCode >= Const.MAGISK_VER.FIX_ENV &&
!ShellUtils.fastCmdResult("env_check")) { !ShellUtils.fastCmdResult("env_check")) {
new EnvFixDialog(requireActivity()).show(); new EnvFixDialog(requireActivity()).show();
} }

View File

@ -42,7 +42,7 @@ public class MagiskManager extends ContainerApp {
public RepoDatabaseHelper repoDB; public RepoDatabaseHelper repoDB;
public MagiskManager() { public MagiskManager() {
Global.weakApp = new WeakReference<>(this); Data.weakApp = new WeakReference<>(this);
} }
@Override @Override
@ -71,7 +71,7 @@ public class MagiskManager extends ContainerApp {
} }
LocaleManager.setLocale(); LocaleManager.setLocale();
Global.loadConfig(); Data.loadConfig();
} }
} }

View File

@ -125,15 +125,15 @@ public class MainActivity extends Activity
MagiskManager mm = getMagiskManager(); MagiskManager mm = getMagiskManager();
Menu menu = navigationView.getMenu(); Menu menu = navigationView.getMenu();
menu.findItem(R.id.magiskhide).setVisible( menu.findItem(R.id.magiskhide).setVisible(
Shell.rootAccess() && Global.magiskVersionCode >= Const.MAGISK_VER.UNIFIED Shell.rootAccess() && Data.magiskVersionCode >= Const.MAGISK_VER.UNIFIED
&& mm.prefs.getBoolean(Const.Key.MAGISKHIDE, false)); && mm.prefs.getBoolean(Const.Key.MAGISKHIDE, false));
menu.findItem(R.id.modules).setVisible(!mm.prefs.getBoolean(Const.Key.COREONLY, false) && menu.findItem(R.id.modules).setVisible(!mm.prefs.getBoolean(Const.Key.COREONLY, false) &&
Shell.rootAccess() && Global.magiskVersionCode >= 0); Shell.rootAccess() && Data.magiskVersionCode >= 0);
menu.findItem(R.id.downloads).setVisible(!mm.prefs.getBoolean(Const.Key.COREONLY, false) menu.findItem(R.id.downloads).setVisible(!mm.prefs.getBoolean(Const.Key.COREONLY, false)
&& Download.checkNetworkStatus(this) && Shell.rootAccess() && Global.magiskVersionCode >= 0); && Download.checkNetworkStatus(this) && Shell.rootAccess() && Data.magiskVersionCode >= 0);
menu.findItem(R.id.log).setVisible(Shell.rootAccess()); menu.findItem(R.id.log).setVisible(Shell.rootAccess());
menu.findItem(R.id.superuser).setVisible(Shell.rootAccess() && menu.findItem(R.id.superuser).setVisible(Shell.rootAccess() &&
!(Const.USER_ID > 0 && Global.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)); !(Const.USER_ID > 0 && Data.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED));
} }
public void navigate(String item) { public void navigate(String item) {

View File

@ -108,9 +108,9 @@ public class ReposFragment extends Fragment implements Topic.Subscriber {
if (item.getItemId() == R.id.repo_sort) { if (item.getItemId() == R.id.repo_sort) {
new AlertDialog.Builder(getActivity()) new AlertDialog.Builder(getActivity())
.setTitle(R.string.sorting_order) .setTitle(R.string.sorting_order)
.setSingleChoiceItems(R.array.sorting_orders, Global.repoOrder, (d, which) -> { .setSingleChoiceItems(R.array.sorting_orders, Data.repoOrder, (d, which) -> {
Global.repoOrder = which; Data.repoOrder = which;
mm.prefs.edit().putInt(Const.Key.REPO_ORDER, Global.repoOrder).apply(); mm.prefs.edit().putInt(Const.Key.REPO_ORDER, Data.repoOrder).apply();
adapter.notifyDBChanged(); adapter.notifyDBChanged();
d.dismiss(); d.dismiss();
}).show(); }).show();

View File

@ -109,7 +109,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
findPreference("clear").setOnPreferenceClickListener((pref) -> { findPreference("clear").setOnPreferenceClickListener((pref) -> {
prefs.edit().remove(Const.Key.ETAG_KEY).apply(); prefs.edit().remove(Const.Key.ETAG_KEY).apply();
mm.repoDB.clearRepo(); mm.repoDB.clearRepo();
Global.toast(R.string.repo_cache_cleared, Toast.LENGTH_SHORT); Utils.toast(R.string.repo_cache_cleared, Toast.LENGTH_SHORT);
return true; return true;
}); });
@ -124,8 +124,8 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
SwitchPreference fingerprint = (SwitchPreference) findPreference(Const.Key.SU_FINGERPRINT); SwitchPreference fingerprint = (SwitchPreference) findPreference(Const.Key.SU_FINGERPRINT);
updateChannel.setOnPreferenceChangeListener((pref, o) -> { updateChannel.setOnPreferenceChangeListener((pref, o) -> {
Global.updateChannel = Integer.parseInt((String) o); Data.updateChannel = Integer.parseInt((String) o);
if (Global.updateChannel == Const.Value.CUSTOM_CHANNEL) { if (Data.updateChannel == Const.Value.CUSTOM_CHANNEL) {
View v = LayoutInflater.from(getActivity()).inflate(R.layout.custom_channel_dialog, null); View v = LayoutInflater.from(getActivity()).inflate(R.layout.custom_channel_dialog, null);
EditText url = v.findViewById(R.id.custom_url); EditText url = v.findViewById(R.id.custom_url);
url.setText(mm.prefs.getString(Const.Key.CUSTOM_CHANNEL, "")); url.setText(mm.prefs.getString(Const.Key.CUSTOM_CHANNEL, ""));
@ -160,7 +160,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
fingerprint.setSummary(R.string.disable_fingerprint); fingerprint.setSummary(R.string.disable_fingerprint);
} }
if (Global.magiskVersionCode >= Const.MAGISK_VER.MANAGER_HIDE) { if (Data.magiskVersionCode >= Const.MAGISK_VER.MANAGER_HIDE) {
if (mm.getPackageName().equals(Const.ORIG_PKG_NAME)) { if (mm.getPackageName().equals(Const.ORIG_PKG_NAME)) {
hideManager.setOnPreferenceClickListener((pref) -> { hideManager.setOnPreferenceClickListener((pref) -> {
new HideManager(getActivity()).exec(); new HideManager(getActivity()).exec();
@ -174,7 +174,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
getActivity(), new DownloadReceiver() { getActivity(), new DownloadReceiver() {
@Override @Override
public void onDownloadDone(Context context, Uri uri) { public void onDownloadDone(Context context, Uri uri) {
Global.exportPrefs(); Data.exportPrefs();
Shell.su("cp " + uri.getPath() + " /data/local/tmp/manager.apk").exec(); Shell.su("cp " + uri.getPath() + " /data/local/tmp/manager.apk").exec();
if (ShellUtils.fastCmdResult("pm install /data/local/tmp/manager.apk")) { if (ShellUtils.fastCmdResult("pm install /data/local/tmp/manager.apk")) {
Shell.su("rm -f /data/local/tmp/manager.apk").exec(); Shell.su("rm -f /data/local/tmp/manager.apk").exec();
@ -184,8 +184,8 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
Shell.su("rm -f /data/local/tmp/manager.apk").exec(); Shell.su("rm -f /data/local/tmp/manager.apk").exec();
} }
}, },
Global.managerLink, Data.managerLink,
Utils.fmt("MagiskManager-v%s.apk", Global.remoteManagerVersionString) Utils.fmt("MagiskManager-v%s.apk", Data.remoteManagerVersionString)
); );
return true; return true;
}); });
@ -200,14 +200,14 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
} }
if (!Shell.rootAccess() || (Const.USER_ID > 0 && if (!Shell.rootAccess() || (Const.USER_ID > 0 &&
Global.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) { Data.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) {
prefScreen.removePreference(suCategory); prefScreen.removePreference(suCategory);
} }
if (!Shell.rootAccess()) { if (!Shell.rootAccess()) {
prefScreen.removePreference(magiskCategory); prefScreen.removePreference(magiskCategory);
generalCatagory.removePreference(hideManager); generalCatagory.removePreference(hideManager);
} else if (Global.magiskVersionCode < Const.MAGISK_VER.UNIFIED) { } else if (Data.magiskVersionCode < Const.MAGISK_VER.UNIFIED) {
prefScreen.removePreference(magiskCategory); prefScreen.removePreference(magiskCategory);
} }
} }
@ -246,7 +246,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
switch (key) { switch (key) {
case Const.Key.DARK_THEME: case Const.Key.DARK_THEME:
Global.isDarkTheme = prefs.getBoolean(key, false); Data.isDarkTheme = prefs.getBoolean(key, false);
mm.reloadActivity.publish(false); mm.reloadActivity.publish(false);
return; return;
case Const.Key.COREONLY: case Const.Key.COREONLY:
@ -293,25 +293,25 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
Utils.setupUpdateCheck(); Utils.setupUpdateCheck();
break; break;
} }
Global.loadConfig(); Data.loadConfig();
setSummary(); setSummary();
} }
private void setSummary() { private void setSummary() {
updateChannel.setSummary(getResources() updateChannel.setSummary(getResources()
.getStringArray(R.array.update_channel)[Global.updateChannel]); .getStringArray(R.array.update_channel)[Data.updateChannel]);
suAccess.setSummary(getResources() suAccess.setSummary(getResources()
.getStringArray(R.array.su_access)[Global.suAccessState]); .getStringArray(R.array.su_access)[Data.suAccessState]);
autoRes.setSummary(getResources() autoRes.setSummary(getResources()
.getStringArray(R.array.auto_response)[Global.suResponseType]); .getStringArray(R.array.auto_response)[Data.suResponseType]);
suNotification.setSummary(getResources() suNotification.setSummary(getResources()
.getStringArray(R.array.su_notification)[Global.suNotificationType]); .getStringArray(R.array.su_notification)[Data.suNotificationType]);
requestTimeout.setSummary( requestTimeout.setSummary(
getString(R.string.request_timeout_summary, prefs.getString(Const.Key.SU_REQUEST_TIMEOUT, "10"))); getString(R.string.request_timeout_summary, prefs.getString(Const.Key.SU_REQUEST_TIMEOUT, "10")));
multiuserMode.setSummary(getResources() multiuserMode.setSummary(getResources()
.getStringArray(R.array.multiuser_summary)[Global.multiuserMode]); .getStringArray(R.array.multiuser_summary)[Data.multiuserMode]);
namespaceMode.setSummary(getResources() namespaceMode.setSummary(getResources()
.getStringArray(R.array.namespace_summary)[Global.suNamespaceMode]); .getStringArray(R.array.namespace_summary)[Data.suNamespaceMode]);
} }
@Override @Override

View File

@ -29,7 +29,7 @@ public class SplashActivity extends Activity {
boolean root = Shell.rootAccess(); boolean root = Shell.rootAccess();
mm.repoDB = new RepoDatabaseHelper(this); mm.repoDB = new RepoDatabaseHelper(this);
Global.importPrefs(); Data.importPrefs();
// Dynamic detect all locales // Dynamic detect all locales
new LocaleManager.LoadLocale().exec(); new LocaleManager.LoadLocale().exec();
@ -54,7 +54,7 @@ public class SplashActivity extends Activity {
} }
// Magisk working as expected // Magisk working as expected
if (root && Global.magiskVersionCode > 0) { if (root && Data.magiskVersionCode > 0) {
// Update check service // Update check service
Utils.setupUpdateCheck(); Utils.setupUpdateCheck();
// Fire asynctasks // Fire asynctasks
@ -62,7 +62,7 @@ public class SplashActivity extends Activity {
} }
// Write back default values // Write back default values
Global.writeConfig(); Data.writeConfig();
mm.hasInit = true; mm.hasInit = true;

View File

@ -12,7 +12,7 @@ import android.widget.Filter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.asyncs.ParallelTask; import com.topjohnwu.magisk.asyncs.ParallelTask;
import com.topjohnwu.magisk.utils.Const; import com.topjohnwu.magisk.utils.Const;
@ -37,7 +37,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
fullList = showList = Collections.emptyList(); fullList = showList = Collections.emptyList();
hideList = Collections.emptyList(); hideList = Collections.emptyList();
filter = new ApplicationFilter(); filter = new ApplicationFilter();
pm = Global.MM().getPackageManager(); pm = Data.MM().getPackageManager();
new LoadApps().exec(); new LoadApps().exec();
} }
@ -152,7 +152,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
@Override @Override
protected void onPostExecute(Void v) { protected void onPostExecute(Void v) {
Global.MM().magiskHideDone.publish(false); Data.MM().magiskHideDone.publish(false);
} }
} }
} }

View File

@ -2,7 +2,7 @@ package com.topjohnwu.magisk.asyncs;
import android.app.Activity; import android.app.Activity;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.utils.Const; import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.ISafetyNetHelper; import com.topjohnwu.magisk.utils.ISafetyNetHelper;
import com.topjohnwu.magisk.utils.WebService; import com.topjohnwu.magisk.utils.WebService;
@ -22,7 +22,7 @@ import dalvik.system.DexClassLoader;
public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> { public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
public static final File dexPath = public static final File dexPath =
new File(Global.MM().getFilesDir().getParent() + "/snet", "snet.apk"); new File(Data.MM().getFilesDir().getParent() + "/snet", "snet.apk");
private ISafetyNetHelper helper; private ISafetyNetHelper helper;
public CheckSafetyNet(Activity activity) { public CheckSafetyNet(Activity activity) {
@ -50,7 +50,7 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
Class.class, String.class, Activity.class, Object.class) Class.class, String.class, Activity.class, Object.class)
.invoke(null, ISafetyNetHelper.class, dexPath.getPath(), getActivity(), .invoke(null, ISafetyNetHelper.class, dexPath.getPath(), getActivity(),
(ISafetyNetHelper.Callback) code -> (ISafetyNetHelper.Callback) code ->
Global.MM().safetyNetDone.publish(false, code)); Data.MM().safetyNetDone.publish(false, code));
if (helper.getVersion() != Const.SNET_VER) { if (helper.getVersion() != Const.SNET_VER) {
throw new Exception(); throw new Exception();
} }
@ -79,7 +79,7 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
helper.attest(); helper.attest();
} else { } else {
e.printStackTrace(); e.printStackTrace();
Global.MM().safetyNetDone.publish(false, -1); Data.MM().safetyNetDone.publish(false, -1);
} }
super.onPostExecute(e); super.onPostExecute(e);
} }

View File

@ -1,7 +1,7 @@
package com.topjohnwu.magisk.asyncs; package com.topjohnwu.magisk.asyncs;
import com.topjohnwu.magisk.BuildConfig; import com.topjohnwu.magisk.BuildConfig;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.utils.Const; import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.NotificationMgr; import com.topjohnwu.magisk.utils.NotificationMgr;
@ -52,9 +52,9 @@ public class CheckUpdates extends ParallelTask<Void, Void, Void> {
@Override @Override
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
MagiskManager mm = Global.MM(); MagiskManager mm = Data.MM();
String jsonStr = ""; String jsonStr = "";
switch (Global.updateChannel) { switch (Data.updateChannel) {
case Const.Value.STABLE_CHANNEL: case Const.Value.STABLE_CHANNEL:
jsonStr = WebService.getString(Const.Url.STABLE_URL); jsonStr = WebService.getString(Const.Url.STABLE_URL);
break; break;
@ -74,30 +74,30 @@ public class CheckUpdates extends ParallelTask<Void, Void, Void> {
} }
JSONObject magisk = getJson(json, "magisk"); JSONObject magisk = getJson(json, "magisk");
Global.remoteMagiskVersionString = getString(magisk, "version", null); Data.remoteMagiskVersionString = getString(magisk, "version", null);
Global.remoteMagiskVersionCode = getInt(magisk, "versionCode", -1); Data.remoteMagiskVersionCode = getInt(magisk, "versionCode", -1);
Global.magiskLink = getString(magisk, "link", null); Data.magiskLink = getString(magisk, "link", null);
Global.magiskNoteLink = getString(magisk, "note", null); Data.magiskNoteLink = getString(magisk, "note", null);
JSONObject manager = getJson(json, "app"); JSONObject manager = getJson(json, "app");
Global.remoteManagerVersionString = getString(manager, "version", null); Data.remoteManagerVersionString = getString(manager, "version", null);
Global.remoteManagerVersionCode = getInt(manager, "versionCode", -1); Data.remoteManagerVersionCode = getInt(manager, "versionCode", -1);
Global.managerLink = getString(manager, "link", null); Data.managerLink = getString(manager, "link", null);
Global.managerNoteLink = getString(manager, "note", null); Data.managerNoteLink = getString(manager, "note", null);
JSONObject uninstaller = getJson(json, "uninstaller"); JSONObject uninstaller = getJson(json, "uninstaller");
Global.uninstallerLink = getString(uninstaller, "link", null); Data.uninstallerLink = getString(uninstaller, "link", null);
return null; return null;
} }
@Override @Override
protected void onPostExecute(Void v) { protected void onPostExecute(Void v) {
MagiskManager mm = Global.MM(); MagiskManager mm = Data.MM();
if (showNotification) { if (showNotification) {
if (BuildConfig.VERSION_CODE < Global.remoteManagerVersionCode) { if (BuildConfig.VERSION_CODE < Data.remoteManagerVersionCode) {
NotificationMgr.managerUpdate(); NotificationMgr.managerUpdate();
} else if (Global.magiskVersionCode < Global.remoteMagiskVersionCode) { } else if (Data.magiskVersionCode < Data.remoteMagiskVersionCode) {
NotificationMgr.magiskUpdate(); NotificationMgr.magiskUpdate();
} }
} }

View File

@ -4,8 +4,8 @@ import android.app.Activity;
import android.net.Uri; import android.net.Uri;
import android.view.View; import android.view.View;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.FlashActivity; import com.topjohnwu.magisk.FlashActivity;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.components.SnackbarMaker; import com.topjohnwu.magisk.components.SnackbarMaker;
import com.topjohnwu.magisk.utils.Const; import com.topjohnwu.magisk.utils.Const;
@ -45,7 +45,7 @@ public class FlashZip extends ParallelTask<Void, Void, Integer> {
@Override @Override
protected Integer doInBackground(Void... voids) { protected Integer doInBackground(Void... voids) {
MagiskManager mm = Global.MM(); MagiskManager mm = Data.MM();
try { try {
console.add("- Copying zip to temp directory"); console.add("- Copying zip to temp directory");

View File

@ -4,12 +4,13 @@ import android.app.Activity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.widget.Toast; import android.widget.Toast;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.Const; import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.PatchAPK; import com.topjohnwu.magisk.utils.PatchAPK;
import com.topjohnwu.magisk.utils.RootUtils; import com.topjohnwu.magisk.utils.RootUtils;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.Shell;
import com.topjohnwu.superuser.ShellUtils; import com.topjohnwu.superuser.ShellUtils;
import com.topjohnwu.superuser.io.SuFile; import com.topjohnwu.superuser.io.SuFile;
@ -56,7 +57,7 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
@Override @Override
protected Boolean doInBackground(Void... voids) { protected Boolean doInBackground(Void... voids) {
MagiskManager mm = Global.MM(); MagiskManager mm = Data.MM();
// Generate a new app with random package name // Generate a new app with random package name
SuFile repack = new SuFile("/data/local/tmp/repack.apk"); SuFile repack = new SuFile("/data/local/tmp/repack.apk");
@ -79,7 +80,7 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
repack.delete(); repack.delete();
mm.mDB.setStrings(Const.Key.SU_MANAGER, pkg); mm.mDB.setStrings(Const.Key.SU_MANAGER, pkg);
Global.exportPrefs(); Data.exportPrefs();
RootUtils.uninstallPkg(Const.ORIG_PKG_NAME); RootUtils.uninstallPkg(Const.ORIG_PKG_NAME);
return true; return true;
@ -89,7 +90,7 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
protected void onPostExecute(Boolean b) { protected void onPostExecute(Boolean b) {
dialog.dismiss(); dialog.dismiss();
if (!b) { if (!b) {
Global.toast(R.string.hide_manager_fail_toast, Toast.LENGTH_LONG); Utils.toast(R.string.hide_manager_fail_toast, Toast.LENGTH_LONG);
} }
super.onPostExecute(b); super.onPostExecute(b);
} }

View File

@ -9,8 +9,8 @@ import android.text.TextUtils;
import android.view.View; import android.view.View;
import android.widget.Toast; import android.widget.Toast;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.FlashActivity; import com.topjohnwu.magisk.FlashActivity;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.container.TarEntry; import com.topjohnwu.magisk.container.TarEntry;
@ -60,7 +60,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
public InstallMagisk(Activity context) { public InstallMagisk(Activity context) {
super(context); super(context);
mm = Global.MM(); mm = Data.MM();
mode = FIX_ENV_MODE; mode = FIX_ENV_MODE;
} }
@ -130,8 +130,8 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
private void extractFiles(String arch) throws IOException { private void extractFiles(String arch) throws IOException {
console.add("- Downloading zip"); console.add("- Downloading zip");
String filename = Utils.fmt("Magisk-v%s(%d).zip", String filename = Utils.fmt("Magisk-v%s(%d).zip",
Global.remoteMagiskVersionString, Global.remoteMagiskVersionCode); Data.remoteMagiskVersionString, Data.remoteMagiskVersionCode);
HttpURLConnection conn = WebService.mustRequest(Global.magiskLink, null); HttpURLConnection conn = WebService.mustRequest(Data.magiskLink, null);
BufferedInputStream buf = new BufferedInputStream(new ProgressStream(conn)); BufferedInputStream buf = new BufferedInputStream(new ProgressStream(conn));
buf.mark(Integer.MAX_VALUE); buf.mark(Integer.MAX_VALUE);
try (OutputStream out = new FileOutputStream(new File(Download.EXTERNAL_PATH, filename))) { try (OutputStream out = new FileOutputStream(new File(Download.EXTERNAL_PATH, filename))) {
@ -205,7 +205,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
// Patch boot image // Patch boot image
if (!Shell.sh("cd " + installDir, Utils.fmt( if (!Shell.sh("cd " + installDir, Utils.fmt(
"KEEPFORCEENCRYPT=%b KEEPVERITY=%b sh update-binary indep boot_patch.sh %s", "KEEPFORCEENCRYPT=%b KEEPVERITY=%b sh update-binary indep boot_patch.sh %s",
Global.keepEnc, Global.keepVerity, mBoot)) Data.keepEnc, Data.keepVerity, mBoot))
.to(console, logs).exec().isSuccess()) .to(console, logs).exec().isSuccess())
return null; return null;
@ -231,10 +231,10 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
private void outputBoot(File patched) throws IOException { private void outputBoot(File patched) throws IOException {
switch (mode) { switch (mode) {
case PATCH_MODE: case PATCH_MODE:
File dest = new File(Download.EXTERNAL_PATH, "patched_boot" + Global.bootFormat); File dest = new File(Download.EXTERNAL_PATH, "patched_boot" + Data.bootFormat);
dest.getParentFile().mkdirs(); dest.getParentFile().mkdirs();
OutputStream out; OutputStream out;
switch (Global.bootFormat) { switch (Data.bootFormat) {
case ".img.tar": case ".img.tar":
out = new TarOutputStream(new BufferedOutputStream(new FileOutputStream(dest))); out = new TarOutputStream(new BufferedOutputStream(new FileOutputStream(dest)));
((TarOutputStream) out).putNextEntry(new TarEntry(patched, "boot.img")); ((TarOutputStream) out).putNextEntry(new TarEntry(patched, "boot.img"));
@ -259,7 +259,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
case DIRECT_MODE: case DIRECT_MODE:
Shell.Job job = Shell.su(Utils.fmt("direct_install %s %s %s", patched, mBoot, installDir)) Shell.Job job = Shell.su(Utils.fmt("direct_install %s %s %s", patched, mBoot, installDir))
.to(console, logs); .to(console, logs);
if (!Global.keepVerity) if (!Data.keepVerity)
job.add("find_dtbo_image", "patch_dtbo_image"); job.add("find_dtbo_image", "patch_dtbo_image");
job.exec(); job.exec();
break; break;
@ -332,7 +332,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
List<String> abis = Arrays.asList(Build.SUPPORTED_ABIS); List<String> abis = Arrays.asList(Build.SUPPORTED_ABIS);
String arch; String arch;
if (Global.remoteMagiskVersionCode >= Const.MAGISK_VER.SEPOL_REFACTOR) { if (Data.remoteMagiskVersionCode >= Const.MAGISK_VER.SEPOL_REFACTOR) {
// 32-bit only // 32-bit only
if (abis.contains("x86")) arch = "x86"; if (abis.contains("x86")) arch = "x86";
else arch = "arm"; else arch = "arm";
@ -369,7 +369,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
protected void onPostExecute(Boolean result) { protected void onPostExecute(Boolean result) {
if (mode == FIX_ENV_MODE) { if (mode == FIX_ENV_MODE) {
dialog.dismiss(); dialog.dismiss();
Global.toast(result ? R.string.setup_done : R.string.setup_fail, Toast.LENGTH_LONG); Utils.toast(result ? R.string.setup_done : R.string.setup_fail, Toast.LENGTH_LONG);
} else { } else {
// Running in FlashActivity // Running in FlashActivity
FlashActivity activity = (FlashActivity) getActivity(); FlashActivity activity = (FlashActivity) getActivity();

View File

@ -1,6 +1,6 @@
package com.topjohnwu.magisk.asyncs; package com.topjohnwu.magisk.asyncs;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.container.Module; import com.topjohnwu.magisk.container.Module;
import com.topjohnwu.magisk.container.ValueSortedMap; import com.topjohnwu.magisk.container.ValueSortedMap;
@ -16,7 +16,7 @@ public class LoadModules extends ParallelTask<Void, Void, Void> {
@Override @Override
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
MagiskManager mm = Global.MM(); MagiskManager mm = Data.MM();
mm.moduleMap = new ValueSortedMap<>(); mm.moduleMap = new ValueSortedMap<>();
for (String name : getModList()) { for (String name : getModList()) {
@ -29,7 +29,7 @@ public class LoadModules extends ParallelTask<Void, Void, Void> {
@Override @Override
protected void onPostExecute(Void v) { protected void onPostExecute(Void v) {
Global.MM().moduleLoadDone.publish(); Data.MM().moduleLoadDone.publish();
super.onPostExecute(v); super.onPostExecute(v);
} }
} }

View File

@ -4,7 +4,7 @@ import android.app.Activity;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.webkit.WebView; import android.webkit.WebView;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.WebService; import com.topjohnwu.magisk.utils.WebService;
@ -39,7 +39,7 @@ public class MarkDownWindow extends ParallelTask<Void, Void, String> {
@Override @Override
protected String doInBackground(Void... voids) { protected String doInBackground(Void... voids) {
MagiskManager mm = Global.MM(); MagiskManager mm = Data.MM();
String md; String md;
if (mUrl != null) { if (mUrl != null) {
md = WebService.getString(mUrl); md = WebService.getString(mUrl);
@ -56,7 +56,7 @@ public class MarkDownWindow extends ParallelTask<Void, Void, String> {
String css; String css;
try ( try (
InputStream in = mm.getResources().openRawResource( InputStream in = mm.getResources().openRawResource(
Global.isDarkTheme ? R.raw.dark : R.raw.light); Data.isDarkTheme ? R.raw.dark : R.raw.light);
ByteArrayOutputStream out = new ByteArrayOutputStream() ByteArrayOutputStream out = new ByteArrayOutputStream()
) { ) {
ShellUtils.pump(in, out); ShellUtils.pump(in, out);

View File

@ -9,12 +9,12 @@ import android.support.annotation.NonNull;
import android.widget.Toast; import android.widget.Toast;
import com.topjohnwu.magisk.FlashActivity; import com.topjohnwu.magisk.FlashActivity;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.components.Activity; import com.topjohnwu.magisk.components.Activity;
import com.topjohnwu.magisk.components.SnackbarMaker; import com.topjohnwu.magisk.components.SnackbarMaker;
import com.topjohnwu.magisk.utils.Const; import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Download; import com.topjohnwu.magisk.utils.Download;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.WebService; import com.topjohnwu.magisk.utils.WebService;
import com.topjohnwu.magisk.utils.ZipUtils; import com.topjohnwu.magisk.utils.ZipUtils;
import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.Shell;
@ -148,7 +148,7 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
SnackbarMaker.showUri(activity, uri); SnackbarMaker.showUri(activity, uri);
} }
} else { } else {
Global.toast(R.string.process_error, Toast.LENGTH_LONG); Utils.toast(R.string.process_error, Toast.LENGTH_LONG);
} }
super.onPostExecute(result); super.onPostExecute(result);
} }

View File

@ -4,8 +4,8 @@ import android.app.Activity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.widget.Toast; import android.widget.Toast;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.superuser.ShellUtils; import com.topjohnwu.superuser.ShellUtils;
public class RestoreImages extends ParallelTask<Void, Void, Boolean> { public class RestoreImages extends ParallelTask<Void, Void, Boolean> {
@ -31,9 +31,9 @@ public class RestoreImages extends ParallelTask<Void, Void, Boolean> {
protected void onPostExecute(Boolean result) { protected void onPostExecute(Boolean result) {
dialog.cancel(); dialog.cancel();
if (result) { if (result) {
Global.toast(R.string.restore_done, Toast.LENGTH_SHORT); Utils.toast(R.string.restore_done, Toast.LENGTH_SHORT);
} else { } else {
Global.toast(R.string.restore_fail, Toast.LENGTH_LONG); Utils.toast(R.string.restore_fail, Toast.LENGTH_LONG);
} }
} }
} }

View File

@ -3,7 +3,7 @@ package com.topjohnwu.magisk.asyncs;
import android.database.Cursor; import android.database.Cursor;
import android.text.TextUtils; import android.text.TextUtils;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.ReposFragment; import com.topjohnwu.magisk.ReposFragment;
import com.topjohnwu.magisk.container.Repo; import com.topjohnwu.magisk.container.Repo;
@ -49,7 +49,7 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
private ExecutorService threadPool; private ExecutorService threadPool;
public UpdateRepos(boolean force) { public UpdateRepos(boolean force) {
mm = Global.MM(); mm = Data.MM();
mm.repoLoadDone.reset(); mm.repoLoadDone.reset();
forceUpdate = force; forceUpdate = force;
threadPool = Executors.newFixedThreadPool(CORE_POOL_SIZE); threadPool = Executors.newFixedThreadPool(CORE_POOL_SIZE);

View File

@ -8,7 +8,7 @@ import android.support.annotation.StyleRes;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager; import android.view.WindowManager;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.LocaleManager; import com.topjohnwu.magisk.utils.LocaleManager;
@ -40,7 +40,7 @@ public abstract class FlavorActivity extends AppCompatActivity {
if (this instanceof Topic.Subscriber) { if (this instanceof Topic.Subscriber) {
((Topic.Subscriber) this).subscribeTopics(); ((Topic.Subscriber) this).subscribeTopics();
} }
if (Global.isDarkTheme && getDarkTheme() != -1) { if (Data.isDarkTheme && getDarkTheme() != -1) {
setTheme(getDarkTheme()); setTheme(getDarkTheme());
} }
} }

View File

@ -7,8 +7,8 @@ import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.widget.Toast; import android.widget.Toast;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.FlashActivity; import com.topjohnwu.magisk.FlashActivity;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.receivers.DownloadReceiver; import com.topjohnwu.magisk.receivers.DownloadReceiver;
@ -28,12 +28,12 @@ class InstallMethodDialog extends AlertDialog.Builder {
Intent intent; Intent intent;
switch (idx) { switch (idx) {
case 1: case 1:
if (Global.remoteMagiskVersionCode < 1400) { if (Data.remoteMagiskVersionCode < 1400) {
SnackbarMaker.make(activity, R.string.no_boot_file_patch_support, SnackbarMaker.make(activity, R.string.no_boot_file_patch_support,
Snackbar.LENGTH_LONG).show(); Snackbar.LENGTH_LONG).show();
return; return;
} }
Global.toast(R.string.boot_file_patch_msg, Toast.LENGTH_LONG); Utils.toast(R.string.boot_file_patch_msg, Toast.LENGTH_LONG);
intent = new Intent(Intent.ACTION_GET_CONTENT).setType("*/*"); intent = new Intent(Intent.ACTION_GET_CONTENT).setType("*/*");
activity.startActivityForResult(intent, Const.ID.SELECT_BOOT, activity.startActivityForResult(intent, Const.ID.SELECT_BOOT,
(requestCode, resultCode, data) -> { (requestCode, resultCode, data) -> {
@ -52,7 +52,7 @@ class InstallMethodDialog extends AlertDialog.Builder {
public void onDownloadDone(Context context, Uri uri) { public void onDownloadDone(Context context, Uri uri) {
SnackbarMaker.showUri(activity, uri); SnackbarMaker.showUri(activity, uri);
} }
}, Global.magiskLink, filename); }, Data.magiskLink, filename);
break; break;
case 2: case 2:
intent = new Intent(activity, FlashActivity.class) intent = new Intent(activity, FlashActivity.class)

View File

@ -4,7 +4,7 @@ import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.asyncs.MarkDownWindow; import com.topjohnwu.magisk.asyncs.MarkDownWindow;
@ -20,7 +20,7 @@ public class MagiskInstallDialog extends CustomAlertDialog {
super(activity); super(activity);
MagiskManager mm = Utils.getMagiskManager(activity); MagiskManager mm = Utils.getMagiskManager(activity);
String filename = Utils.fmt("Magisk-v%s(%d).zip", String filename = Utils.fmt("Magisk-v%s(%d).zip",
Global.remoteMagiskVersionString, Global.remoteMagiskVersionCode); Data.remoteMagiskVersionString, Data.remoteMagiskVersionCode);
setTitle(mm.getString(R.string.repo_install_title, mm.getString(R.string.magisk))); setTitle(mm.getString(R.string.repo_install_title, mm.getString(R.string.magisk)));
setMessage(mm.getString(R.string.repo_install_msg, filename)); setMessage(mm.getString(R.string.repo_install_msg, filename));
setCancelable(true); setCancelable(true);
@ -38,15 +38,15 @@ public class MagiskInstallDialog extends CustomAlertDialog {
new InstallMethodDialog(activity, options, filename).show(); new InstallMethodDialog(activity, options, filename).show();
}); });
setNegativeButton(R.string.no_thanks, null); setNegativeButton(R.string.no_thanks, null);
if (!TextUtils.isEmpty(Global.magiskNoteLink)) { if (!TextUtils.isEmpty(Data.magiskNoteLink)) {
setNeutralButton(R.string.release_notes, (d, i) -> { setNeutralButton(R.string.release_notes, (d, i) -> {
if (Global.magiskNoteLink.contains("forum.xda-developers")) { if (Data.magiskNoteLink.contains("forum.xda-developers")) {
// Open forum links in browser // Open forum links in browser
Intent openLink = new Intent(Intent.ACTION_VIEW, Uri.parse(Global.magiskNoteLink)); Intent openLink = new Intent(Intent.ACTION_VIEW, Uri.parse(Data.magiskNoteLink));
openLink.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); openLink.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mm.startActivity(openLink); mm.startActivity(openLink);
} else { } else {
new MarkDownWindow(activity, null, Global.magiskNoteLink).exec(); new MarkDownWindow(activity, null, Data.magiskNoteLink).exec();
} }
}); });
} }

View File

@ -5,7 +5,7 @@ import android.content.Intent;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.text.TextUtils; import android.text.TextUtils;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.asyncs.MarkDownWindow; import com.topjohnwu.magisk.asyncs.MarkDownWindow;
@ -19,21 +19,21 @@ public class ManagerInstallDialog extends CustomAlertDialog {
super(activity); super(activity);
MagiskManager mm = Utils.getMagiskManager(activity); MagiskManager mm = Utils.getMagiskManager(activity);
String filename = Utils.fmt("MagiskManager-v%s(%d).apk", String filename = Utils.fmt("MagiskManager-v%s(%d).apk",
Global.remoteManagerVersionString, Global.remoteManagerVersionCode); Data.remoteManagerVersionString, Data.remoteManagerVersionCode);
setTitle(mm.getString(R.string.repo_install_title, mm.getString(R.string.app_name))); setTitle(mm.getString(R.string.repo_install_title, mm.getString(R.string.app_name)));
setMessage(mm.getString(R.string.repo_install_msg, filename)); setMessage(mm.getString(R.string.repo_install_msg, filename));
setCancelable(true); setCancelable(true);
setPositiveButton(R.string.install, (d, i) -> activity.runWithPermission( setPositiveButton(R.string.install, (d, i) -> activity.runWithPermission(
new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, () -> { new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, () -> {
Intent intent = new Intent(mm, ManagerUpdate.class); Intent intent = new Intent(mm, ManagerUpdate.class);
intent.putExtra(Const.Key.INTENT_SET_LINK, Global.managerLink); intent.putExtra(Const.Key.INTENT_SET_LINK, Data.managerLink);
intent.putExtra(Const.Key.INTENT_SET_FILENAME, filename); intent.putExtra(Const.Key.INTENT_SET_FILENAME, filename);
mm.sendBroadcast(intent); mm.sendBroadcast(intent);
})) }))
.setNegativeButton(R.string.no_thanks, null); .setNegativeButton(R.string.no_thanks, null);
if (!TextUtils.isEmpty(Global.managerNoteLink)) { if (!TextUtils.isEmpty(Data.managerNoteLink)) {
setNeutralButton(R.string.app_changelog, (d, i) -> setNeutralButton(R.string.app_changelog, (d, i) ->
new MarkDownWindow(activity, null, Global.managerNoteLink).exec()); new MarkDownWindow(activity, null, Data.managerNoteLink).exec());
} }
} }
} }

View File

@ -7,8 +7,8 @@ import android.net.Uri;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.text.TextUtils; import android.text.TextUtils;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.FlashActivity; import com.topjohnwu.magisk.FlashActivity;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.asyncs.RestoreImages; import com.topjohnwu.magisk.asyncs.RestoreImages;
@ -25,7 +25,7 @@ public class UninstallDialog extends CustomAlertDialog {
setTitle(R.string.uninstall_magisk_title); setTitle(R.string.uninstall_magisk_title);
setMessage(R.string.uninstall_magisk_msg); setMessage(R.string.uninstall_magisk_msg);
setNeutralButton(R.string.restore_img, (d, i) -> new RestoreImages(activity).exec()); setNeutralButton(R.string.restore_img, (d, i) -> new RestoreImages(activity).exec());
if (!TextUtils.isEmpty(Global.uninstallerLink)) { if (!TextUtils.isEmpty(Data.uninstallerLink)) {
setPositiveButton(R.string.complete_uninstall, (d, i) -> setPositiveButton(R.string.complete_uninstall, (d, i) ->
Download.receive(activity, new DownloadReceiver() { Download.receive(activity, new DownloadReceiver() {
@Override @Override
@ -36,7 +36,7 @@ public class UninstallDialog extends CustomAlertDialog {
.putExtra(Const.Key.FLASH_ACTION, Const.Value.UNINSTALL); .putExtra(Const.Key.FLASH_ACTION, Const.Value.UNINSTALL);
context.startActivity(intent); context.startActivity(intent);
} }
}, Global.uninstallerLink, "magisk-uninstaller.zip")); }, Data.uninstallerLink, "magisk-uninstaller.zip"));
} }
} }
} }

View File

@ -11,7 +11,7 @@ import android.support.annotation.NonNull;
import android.text.TextUtils; import android.text.TextUtils;
import android.widget.Toast; import android.widget.Toast;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.container.Policy; import com.topjohnwu.magisk.container.Policy;
@ -76,10 +76,10 @@ public class MagiskDatabaseHelper {
} }
// Cleanup // Cleanup
Shell.su("db_clean " + Const.USER_ID).exec(); Shell.su("db_clean " + Const.USER_ID).exec();
if (Global.magiskVersionCode < Const.MAGISK_VER.FBE_AWARE) { if (Data.magiskVersionCode < Const.MAGISK_VER.FBE_AWARE) {
// Super old legacy mode // Super old legacy mode
return mm.openOrCreateDatabase("su.db", Context.MODE_PRIVATE, null); return mm.openOrCreateDatabase("su.db", Context.MODE_PRIVATE, null);
} else if (Global.magiskVersionCode < Const.MAGISK_VER.HIDDEN_PATH) { } else if (Data.magiskVersionCode < Const.MAGISK_VER.HIDDEN_PATH) {
// Legacy mode with FBE aware // Legacy mode with FBE aware
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
de.moveDatabaseFrom(mm, "su.db"); de.moveDatabaseFrom(mm, "su.db");
@ -90,7 +90,7 @@ public class MagiskDatabaseHelper {
final SuFile GLOBAL_DB = new SuFile("/data/adb/magisk.db"); final SuFile GLOBAL_DB = new SuFile("/data/adb/magisk.db");
mm.deleteDatabase("su.db"); mm.deleteDatabase("su.db");
de.deleteDatabase("su.db"); de.deleteDatabase("su.db");
if (Global.magiskVersionCode < Const.MAGISK_VER.SEPOL_REFACTOR) { if (Data.magiskVersionCode < Const.MAGISK_VER.SEPOL_REFACTOR) {
// We need some additional policies on old versions // We need some additional policies on old versions
Shell.su("db_sepatch").exec(); Shell.su("db_sepatch").exec();
} }
@ -124,7 +124,7 @@ public class MagiskDatabaseHelper {
POLICY_TABLE, POLICY_TABLE)); POLICY_TABLE, POLICY_TABLE));
db.execSQL(Utils.fmt("DROP TABLE %s_old", POLICY_TABLE)); db.execSQL(Utils.fmt("DROP TABLE %s_old", POLICY_TABLE));
Global.MM().deleteDatabase("sulog.db"); Data.MM().deleteDatabase("sulog.db");
++oldVersion; ++oldVersion;
} }
if (oldVersion == 2) { if (oldVersion == 2) {
@ -143,7 +143,7 @@ public class MagiskDatabaseHelper {
// Remove everything, we do not support downgrade // Remove everything, we do not support downgrade
public void onDowngrade(SQLiteDatabase db) { public void onDowngrade(SQLiteDatabase db) {
Global.toast(R.string.su_db_corrupt, Toast.LENGTH_LONG); Utils.toast(R.string.su_db_corrupt, Toast.LENGTH_LONG);
db.execSQL("DROP TABLE IF EXISTS " + POLICY_TABLE); db.execSQL("DROP TABLE IF EXISTS " + POLICY_TABLE);
db.execSQL("DROP TABLE IF EXISTS " + LOG_TABLE); db.execSQL("DROP TABLE IF EXISTS " + LOG_TABLE);
db.execSQL("DROP TABLE IF EXISTS " + SETTINGS_TABLE); db.execSQL("DROP TABLE IF EXISTS " + SETTINGS_TABLE);
@ -175,7 +175,7 @@ public class MagiskDatabaseHelper {
// Clear outdated policies // Clear outdated policies
db.delete(POLICY_TABLE, Utils.fmt("until > 0 AND until < %d", System.currentTimeMillis() / 1000), null); db.delete(POLICY_TABLE, Utils.fmt("until > 0 AND until < %d", System.currentTimeMillis() / 1000), null);
// Clear outdated logs // Clear outdated logs
db.delete(LOG_TABLE, Utils.fmt("time < %d", System.currentTimeMillis() - Global.suLogTimeout * 86400000), null); db.delete(LOG_TABLE, Utils.fmt("time < %d", System.currentTimeMillis() - Data.suLogTimeout * 86400000), null);
} }
public void deletePolicy(Policy policy) { public void deletePolicy(Policy policy) {

View File

@ -5,7 +5,7 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.container.Repo; import com.topjohnwu.magisk.container.Repo;
import com.topjohnwu.magisk.utils.Const; import com.topjohnwu.magisk.utils.Const;
@ -101,7 +101,7 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
public Cursor getRepoCursor() { public Cursor getRepoCursor() {
String orderBy = null; String orderBy = null;
switch (Global.repoOrder) { switch (Data.repoOrder) {
case Const.Value.ORDER_NAME: case Const.Value.ORDER_NAME:
orderBy = "name COLLATE NOCASE"; orderBy = "name COLLATE NOCASE";
break; break;
@ -109,7 +109,7 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
orderBy = "last_update DESC"; orderBy = "last_update DESC";
} }
return mDb.query(TABLE_NAME, null, "minMagisk<=? AND minMagisk>=?", return mDb.query(TABLE_NAME, null, "minMagisk<=? AND minMagisk>=?",
new String[] { String.valueOf(Global.magiskVersionCode), String.valueOf(Const.MIN_MODULE_VER()) }, new String[] { String.valueOf(Data.magiskVersionCode), String.valueOf(Const.MIN_MODULE_VER()) },
null, null, orderBy); null, null, orderBy);
} }

View File

@ -9,7 +9,7 @@ import android.graphics.drawable.Icon;
import android.os.Build; import android.os.Build;
import android.support.annotation.RequiresApi; import android.support.annotation.RequiresApi;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.SplashActivity; import com.topjohnwu.magisk.SplashActivity;
@ -34,7 +34,7 @@ public class ShortcutReceiver extends BroadcastReceiver {
ArrayList<ShortcutInfo> shortCuts = new ArrayList<>(); ArrayList<ShortcutInfo> shortCuts = new ArrayList<>();
boolean root = Shell.rootAccess(); boolean root = Shell.rootAccess();
if (root && !(Const.USER_ID > 0 && if (root && !(Const.USER_ID > 0 &&
Global.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) { Data.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) {
shortCuts.add(new ShortcutInfo.Builder(mm, "superuser") shortCuts.add(new ShortcutInfo.Builder(mm, "superuser")
.setShortLabel(mm.getString(R.string.superuser)) .setShortLabel(mm.getString(R.string.superuser))
.setIntent(new Intent(mm, SplashActivity.class) .setIntent(new Intent(mm, SplashActivity.class)
@ -45,7 +45,7 @@ public class ShortcutReceiver extends BroadcastReceiver {
.setRank(0) .setRank(0)
.build()); .build());
} }
if (root && Global.magiskVersionCode >= Const.MAGISK_VER.UNIFIED if (root && Data.magiskVersionCode >= Const.MAGISK_VER.UNIFIED
&& mm.prefs.getBoolean(Const.Key.MAGISKHIDE, false)) { && mm.prefs.getBoolean(Const.Key.MAGISKHIDE, false)) {
shortCuts.add(new ShortcutInfo.Builder(mm, "magiskhide") shortCuts.add(new ShortcutInfo.Builder(mm, "magiskhide")
.setShortLabel(mm.getString(R.string.magiskhide)) .setShortLabel(mm.getString(R.string.magiskhide))
@ -57,7 +57,7 @@ public class ShortcutReceiver extends BroadcastReceiver {
.setRank(1) .setRank(1)
.build()); .build());
} }
if (!mm.prefs.getBoolean(Const.Key.COREONLY, false) && root && Global.magiskVersionCode >= 0) { if (!mm.prefs.getBoolean(Const.Key.COREONLY, false) && root && Data.magiskVersionCode >= 0) {
shortCuts.add(new ShortcutInfo.Builder(mm, "modules") shortCuts.add(new ShortcutInfo.Builder(mm, "modules")
.setShortLabel(mm.getString(R.string.modules)) .setShortLabel(mm.getString(R.string.modules))
.setIntent(new Intent(mm, SplashActivity.class) .setIntent(new Intent(mm, SplashActivity.class)

View File

@ -19,7 +19,7 @@ import android.widget.LinearLayout;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.asyncs.ParallelTask; import com.topjohnwu.magisk.asyncs.ParallelTask;
@ -103,7 +103,7 @@ public class RequestActivity extends Activity {
} }
private void showRequest() { private void showRequest() {
switch (Global.suResponseType) { switch (Data.suResponseType) {
case Const.Value.SU_AUTO_DENY: case Const.Value.SU_AUTO_DENY:
handleAction(Policy.DENY, 0); handleAction(Policy.DENY, 0);
return; return;
@ -132,7 +132,7 @@ public class RequestActivity extends Activity {
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
timeout.setAdapter(adapter); timeout.setAdapter(adapter);
timer = new CountDownTimer(Global.suRequestTimeout * 1000, 1000) { timer = new CountDownTimer(Data.suRequestTimeout * 1000, 1000) {
@Override @Override
public void onTick(long millisUntilFinished) { public void onTick(long millisUntilFinished) {
deny_btn.setText(getString(R.string.deny_with_str, "(" + millisUntilFinished / 1000 + ")")); deny_btn.setText(getString(R.string.deny_with_str, "(" + millisUntilFinished / 1000 + ")"));

View File

@ -7,7 +7,7 @@ import android.content.pm.PackageManager;
import android.os.Process; import android.os.Process;
import android.widget.Toast; import android.widget.Toast;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.container.Policy; import com.topjohnwu.magisk.container.Policy;
@ -33,7 +33,7 @@ public class SuReceiver extends BroadcastReceiver {
if (mode < 0) return; if (mode < 0) return;
if (mode == Const.Value.NOTIFY_USER_TO_OWNER) { if (mode == Const.Value.NOTIFY_USER_TO_OWNER) {
Global.toast(R.string.multiuser_hint_owner_request, Toast.LENGTH_LONG); Utils.toast(R.string.multiuser_hint_owner_request, Toast.LENGTH_LONG);
return; return;
} }
@ -70,8 +70,8 @@ public class SuReceiver extends BroadcastReceiver {
return; return;
} }
if (policy.notification && Global.suNotificationType == Const.Value.NOTIFICATION_TOAST) { if (policy.notification && Data.suNotificationType == Const.Value.NOTIFICATION_TOAST) {
Global.toast(message, Toast.LENGTH_SHORT); Utils.toast(message, Toast.LENGTH_SHORT);
} }
if (mode == Const.Value.NOTIFY_NORMAL_LOG && policy.logging) { if (mode == Const.Value.NOTIFY_NORMAL_LOG && policy.logging) {

View File

@ -3,7 +3,7 @@ package com.topjohnwu.magisk.utils;
import android.os.Process; import android.os.Process;
import com.topjohnwu.magisk.BuildConfig; import com.topjohnwu.magisk.BuildConfig;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Data;
import java.io.File; import java.io.File;
import java.util.Arrays; import java.util.Arrays;
@ -40,13 +40,13 @@ public class Const {
public static final int SNET_VER = 10; public static final int SNET_VER = 10;
public static int MIN_MODULE_VER() { public static int MIN_MODULE_VER() {
return Global.magiskVersionCode >= MAGISK_VER.REMOVE_LEGACY_LINK ? 1500 : 1400; return Data.magiskVersionCode >= MAGISK_VER.REMOVE_LEGACY_LINK ? 1500 : 1400;
} }
/* A list of apps that should not be shown as hide-able */ /* A list of apps that should not be shown as hide-able */
public static final List<String> HIDE_BLACKLIST = Arrays.asList( public static final List<String> HIDE_BLACKLIST = Arrays.asList(
"android", "android",
Global.MM().getPackageName(), Data.MM().getPackageName(),
"com.google.android.gms" "com.google.android.gms"
); );

View File

@ -9,7 +9,7 @@ import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyPermanentlyInvalidatedException; import android.security.keystore.KeyPermanentlyInvalidatedException;
import android.security.keystore.KeyProperties; import android.security.keystore.KeyProperties;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import java.security.KeyStore; import java.security.KeyStore;
@ -28,14 +28,14 @@ public abstract class FingerprintHelper {
public static boolean canUseFingerprint() { public static boolean canUseFingerprint() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
return false; return false;
MagiskManager mm = Global.MM(); MagiskManager mm = Data.MM();
KeyguardManager km = mm.getSystemService(KeyguardManager.class); KeyguardManager km = mm.getSystemService(KeyguardManager.class);
FingerprintManager fm = mm.getSystemService(FingerprintManager.class); FingerprintManager fm = mm.getSystemService(FingerprintManager.class);
return km.isKeyguardSecure() && fm != null && fm.isHardwareDetected() && fm.hasEnrolledFingerprints(); return km.isKeyguardSecure() && fm != null && fm.isHardwareDetected() && fm.hasEnrolledFingerprints();
} }
protected FingerprintHelper() throws Exception { protected FingerprintHelper() throws Exception {
MagiskManager mm = Global.MM(); MagiskManager mm = Data.MM();
KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore"); KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
manager = mm.getSystemService(FingerprintManager.class); manager = mm.getSystemService(FingerprintManager.class);
cipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" cipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/"

View File

@ -4,7 +4,7 @@ import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.asyncs.ParallelTask; import com.topjohnwu.magisk.asyncs.ParallelTask;
@ -21,12 +21,12 @@ public class LocaleManager {
public static List<Locale> locales; public static List<Locale> locales;
public static void setLocale() { public static void setLocale() {
MagiskManager mm = Global.MM(); MagiskManager mm = Data.MM();
Global.localeConfig = mm.prefs.getString(Const.Key.LOCALE, ""); Data.localeConfig = mm.prefs.getString(Const.Key.LOCALE, "");
if (Global.localeConfig.isEmpty()) { if (Data.localeConfig.isEmpty()) {
locale = defaultLocale; locale = defaultLocale;
} else { } else {
locale = Locale.forLanguageTag(Global.localeConfig); locale = Locale.forLanguageTag(Data.localeConfig);
} }
Resources res = mm.getResources(); Resources res = mm.getResources();
Configuration config = new Configuration(res.getConfiguration()); Configuration config = new Configuration(res.getConfiguration());
@ -35,19 +35,19 @@ public class LocaleManager {
} }
public static String getString(Locale locale, @StringRes int id) { public static String getString(Locale locale, @StringRes int id) {
Configuration config = Global.MM().getResources().getConfiguration(); Configuration config = Data.MM().getResources().getConfiguration();
config.setLocale(locale); config.setLocale(locale);
return getString(config, id); return getString(config, id);
} }
private static String getString(Configuration config, @StringRes int id) { private static String getString(Configuration config, @StringRes int id) {
return Global.MM().createConfigurationContext(config).getString(id); return Data.MM().createConfigurationContext(config).getString(id);
} }
private static List<Locale> getAvailableLocale() { private static List<Locale> getAvailableLocale() {
List<Locale> locales = new ArrayList<>(); List<Locale> locales = new ArrayList<>();
HashSet<String> set = new HashSet<>(); HashSet<String> set = new HashSet<>();
MagiskManager mm = Global.MM(); MagiskManager mm = Data.MM();
Locale locale; Locale locale;
@StringRes int compareId = R.string.download_file_error; @StringRes int compareId = R.string.download_file_error;
@ -86,7 +86,7 @@ public class LocaleManager {
} }
@Override @Override
protected void onPostExecute(Void aVoid) { protected void onPostExecute(Void aVoid) {
Global.MM().localeDone.publish(); Data.MM().localeDone.publish();
} }
} }
} }

View File

@ -7,7 +7,7 @@ import android.content.Intent;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder; import android.support.v4.app.TaskStackBuilder;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.SplashActivity; import com.topjohnwu.magisk.SplashActivity;
@ -17,7 +17,7 @@ import com.topjohnwu.magisk.receivers.RebootReceiver;
public class NotificationMgr { public class NotificationMgr {
public static void magiskUpdate() { public static void magiskUpdate() {
MagiskManager mm = Global.MM(); MagiskManager mm = Data.MM();
Intent intent = new Intent(mm, SplashActivity.class); Intent intent = new Intent(mm, SplashActivity.class);
intent.putExtra(Const.Key.OPEN_SECTION, "magisk"); intent.putExtra(Const.Key.OPEN_SECTION, "magisk");
@ -30,7 +30,7 @@ public class NotificationMgr {
NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, Const.ID.NOTIFICATION_CHANNEL); NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, Const.ID.NOTIFICATION_CHANNEL);
builder.setSmallIcon(R.drawable.ic_magisk_outline) builder.setSmallIcon(R.drawable.ic_magisk_outline)
.setContentTitle(mm.getString(R.string.magisk_update_title)) .setContentTitle(mm.getString(R.string.magisk_update_title))
.setContentText(mm.getString(R.string.magisk_update_available, Global.remoteMagiskVersionString)) .setContentText(mm.getString(R.string.magisk_update_available, Data.remoteMagiskVersionString))
.setVibrate(new long[]{0, 100, 100, 100}) .setVibrate(new long[]{0, 100, 100, 100})
.setAutoCancel(true) .setAutoCancel(true)
.setContentIntent(pendingIntent); .setContentIntent(pendingIntent);
@ -41,12 +41,12 @@ public class NotificationMgr {
} }
public static void managerUpdate() { public static void managerUpdate() {
MagiskManager mm = Global.MM(); MagiskManager mm = Data.MM();
String filename = Utils.fmt("MagiskManager-v%s(%d).apk", String filename = Utils.fmt("MagiskManager-v%s(%d).apk",
Global.remoteManagerVersionString, Global.remoteManagerVersionCode); Data.remoteManagerVersionString, Data.remoteManagerVersionCode);
Intent intent = new Intent(mm, ManagerUpdate.class); Intent intent = new Intent(mm, ManagerUpdate.class);
intent.putExtra(Const.Key.INTENT_SET_LINK, Global.managerLink); intent.putExtra(Const.Key.INTENT_SET_LINK, Data.managerLink);
intent.putExtra(Const.Key.INTENT_SET_FILENAME, filename); intent.putExtra(Const.Key.INTENT_SET_FILENAME, filename);
PendingIntent pendingIntent = PendingIntent.getBroadcast(mm, PendingIntent pendingIntent = PendingIntent.getBroadcast(mm,
Const.ID.APK_UPDATE_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT); Const.ID.APK_UPDATE_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
@ -65,7 +65,7 @@ public class NotificationMgr {
} }
public static void dtboPatched() { public static void dtboPatched() {
MagiskManager mm = Global.MM(); MagiskManager mm = Data.MM();
Intent intent = new Intent(mm, RebootReceiver.class); Intent intent = new Intent(mm, RebootReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(mm, PendingIntent pendingIntent = PendingIntent.getBroadcast(mm,

View File

@ -3,7 +3,7 @@ package com.topjohnwu.magisk.utils;
import android.content.Context; import android.content.Context;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.superuser.BusyBox; import com.topjohnwu.superuser.BusyBox;
import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.Shell;
@ -49,10 +49,10 @@ public class RootUtils extends Shell.Initializer {
} }
Const.MAGISK_HOST_FILE = new SuFile(Const.MAGISK_PATH + "/.core/hosts"); Const.MAGISK_HOST_FILE = new SuFile(Const.MAGISK_PATH + "/.core/hosts");
Global.loadMagiskInfo(); Data.loadMagiskInfo();
Global.keepVerity = Boolean.parseBoolean(ShellUtils.fastCmd("echo $KEEPVERITY")); Data.keepVerity = Boolean.parseBoolean(ShellUtils.fastCmd("echo $KEEPVERITY"));
Global.keepEnc = Boolean.parseBoolean(ShellUtils.fastCmd("echo $KEEPFORCEENCRYPT")); Data.keepEnc = Boolean.parseBoolean(ShellUtils.fastCmd("echo $KEEPFORCEENCRYPT"));
} }
return true; return true;
} }

View File

@ -8,8 +8,9 @@ import android.content.SharedPreferences;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.provider.OpenableColumns; import android.provider.OpenableColumns;
import android.widget.Toast;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.services.UpdateCheckService; import com.topjohnwu.magisk.services.UpdateCheckService;
@ -48,7 +49,7 @@ public class Utils {
} }
public static int dpInPx(int dp) { public static int dpInPx(int dp) {
Context context = Global.MM(); Context context = Data.MM();
float scale = context.getResources().getDisplayMetrics().density; float scale = context.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5); return (int) (dp * scale + 0.5);
} }
@ -67,7 +68,7 @@ public class Utils {
} }
public static void setupUpdateCheck() { public static void setupUpdateCheck() {
MagiskManager mm = Global.MM(); MagiskManager mm = Data.MM();
JobScheduler scheduler = (JobScheduler) mm.getSystemService(Context.JOB_SCHEDULER_SERVICE); JobScheduler scheduler = (JobScheduler) mm.getSystemService(Context.JOB_SCHEDULER_SERVICE);
if (mm.prefs.getBoolean(Const.Key.CHECK_UPDATES, true)) { if (mm.prefs.getBoolean(Const.Key.CHECK_UPDATES, true)) {
@ -85,4 +86,12 @@ public class Utils {
scheduler.cancel(Const.UPDATE_SERVICE_VER); scheduler.cancel(Const.UPDATE_SERVICE_VER);
} }
} }
public static void toast(CharSequence msg, int duration) {
Data.mainHandler.post(() -> Toast.makeText(Data.MM(), msg, duration).show());
}
public static void toast(int resId, int duration) {
Data.mainHandler.post(() -> Toast.makeText(Data.MM(), resId, duration).show());
}
} }