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.Looper;
import android.util.Xml;
import android.widget.Toast;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Utils;
@ -20,7 +19,7 @@ import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
public class Global {
public class Data {
// Global app instance
public static WeakReference<MagiskManager> weakApp;
public static Handler mainHandler = new Handler(Looper.getMainLooper());
@ -73,14 +72,6 @@ public class Global {
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() {
// Flush prefs to disk
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.Download;
import com.topjohnwu.magisk.utils.RootUtils;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.superuser.CallbackList;
import com.topjohnwu.superuser.Shell;
@ -75,7 +76,7 @@ public class FlashActivity extends Activity {
e.printStackTrace();
return;
}
Global.toast(logFile.getPath(), Toast.LENGTH_LONG);
Utils.toast(logFile.getPath(), Toast.LENGTH_LONG);
}
@Override

View File

@ -34,7 +34,7 @@ public class LogFragment extends Fragment {
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 MagiskLogFragment(), getString(R.string.magisk));

View File

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

View File

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

View File

@ -125,15 +125,15 @@ public class MainActivity extends Activity
MagiskManager mm = getMagiskManager();
Menu menu = navigationView.getMenu();
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));
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)
&& 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.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) {

View File

@ -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, Global.repoOrder, (d, which) -> {
Global.repoOrder = which;
mm.prefs.edit().putInt(Const.Key.REPO_ORDER, Global.repoOrder).apply();
.setSingleChoiceItems(R.array.sorting_orders, Data.repoOrder, (d, which) -> {
Data.repoOrder = which;
mm.prefs.edit().putInt(Const.Key.REPO_ORDER, Data.repoOrder).apply();
adapter.notifyDBChanged();
d.dismiss();
}).show();

View File

@ -109,7 +109,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
findPreference("clear").setOnPreferenceClickListener((pref) -> {
prefs.edit().remove(Const.Key.ETAG_KEY).apply();
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;
});
@ -124,8 +124,8 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
SwitchPreference fingerprint = (SwitchPreference) findPreference(Const.Key.SU_FINGERPRINT);
updateChannel.setOnPreferenceChangeListener((pref, o) -> {
Global.updateChannel = Integer.parseInt((String) o);
if (Global.updateChannel == Const.Value.CUSTOM_CHANNEL) {
Data.updateChannel = Integer.parseInt((String) o);
if (Data.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, ""));
@ -160,7 +160,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
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)) {
hideManager.setOnPreferenceClickListener((pref) -> {
new HideManager(getActivity()).exec();
@ -174,7 +174,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
getActivity(), new DownloadReceiver() {
@Override
public void onDownloadDone(Context context, Uri uri) {
Global.exportPrefs();
Data.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();
@ -184,8 +184,8 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
Shell.su("rm -f /data/local/tmp/manager.apk").exec();
}
},
Global.managerLink,
Utils.fmt("MagiskManager-v%s.apk", Global.remoteManagerVersionString)
Data.managerLink,
Utils.fmt("MagiskManager-v%s.apk", Data.remoteManagerVersionString)
);
return true;
});
@ -200,14 +200,14 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
}
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);
}
if (!Shell.rootAccess()) {
prefScreen.removePreference(magiskCategory);
generalCatagory.removePreference(hideManager);
} else if (Global.magiskVersionCode < Const.MAGISK_VER.UNIFIED) {
} else if (Data.magiskVersionCode < Const.MAGISK_VER.UNIFIED) {
prefScreen.removePreference(magiskCategory);
}
}
@ -246,7 +246,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
switch (key) {
case Const.Key.DARK_THEME:
Global.isDarkTheme = prefs.getBoolean(key, false);
Data.isDarkTheme = prefs.getBoolean(key, false);
mm.reloadActivity.publish(false);
return;
case Const.Key.COREONLY:
@ -293,25 +293,25 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
Utils.setupUpdateCheck();
break;
}
Global.loadConfig();
Data.loadConfig();
setSummary();
}
private void setSummary() {
updateChannel.setSummary(getResources()
.getStringArray(R.array.update_channel)[Global.updateChannel]);
.getStringArray(R.array.update_channel)[Data.updateChannel]);
suAccess.setSummary(getResources()
.getStringArray(R.array.su_access)[Global.suAccessState]);
.getStringArray(R.array.su_access)[Data.suAccessState]);
autoRes.setSummary(getResources()
.getStringArray(R.array.auto_response)[Global.suResponseType]);
.getStringArray(R.array.auto_response)[Data.suResponseType]);
suNotification.setSummary(getResources()
.getStringArray(R.array.su_notification)[Global.suNotificationType]);
.getStringArray(R.array.su_notification)[Data.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)[Global.multiuserMode]);
.getStringArray(R.array.multiuser_summary)[Data.multiuserMode]);
namespaceMode.setSummary(getResources()
.getStringArray(R.array.namespace_summary)[Global.suNamespaceMode]);
.getStringArray(R.array.namespace_summary)[Data.suNamespaceMode]);
}
@Override

View File

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

View File

@ -12,7 +12,7 @@ import android.widget.Filter;
import android.widget.ImageView;
import android.widget.TextView;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.asyncs.ParallelTask;
import com.topjohnwu.magisk.utils.Const;
@ -37,7 +37,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
fullList = showList = Collections.emptyList();
hideList = Collections.emptyList();
filter = new ApplicationFilter();
pm = Global.MM().getPackageManager();
pm = Data.MM().getPackageManager();
new LoadApps().exec();
}
@ -152,7 +152,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
@Override
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 com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.ISafetyNetHelper;
import com.topjohnwu.magisk.utils.WebService;
@ -22,7 +22,7 @@ import dalvik.system.DexClassLoader;
public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
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;
public CheckSafetyNet(Activity activity) {
@ -50,7 +50,7 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
Class.class, String.class, Activity.class, Object.class)
.invoke(null, ISafetyNetHelper.class, dexPath.getPath(), getActivity(),
(ISafetyNetHelper.Callback) code ->
Global.MM().safetyNetDone.publish(false, code));
Data.MM().safetyNetDone.publish(false, code));
if (helper.getVersion() != Const.SNET_VER) {
throw new Exception();
}
@ -79,7 +79,7 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
helper.attest();
} else {
e.printStackTrace();
Global.MM().safetyNetDone.publish(false, -1);
Data.MM().safetyNetDone.publish(false, -1);
}
super.onPostExecute(e);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@ import android.app.Activity;
import android.support.v7.app.AlertDialog;
import android.webkit.WebView;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.WebService;
@ -39,7 +39,7 @@ public class MarkDownWindow extends ParallelTask<Void, Void, String> {
@Override
protected String doInBackground(Void... voids) {
MagiskManager mm = Global.MM();
MagiskManager mm = Data.MM();
String md;
if (mUrl != null) {
md = WebService.getString(mUrl);
@ -56,7 +56,7 @@ public class MarkDownWindow extends ParallelTask<Void, Void, String> {
String css;
try (
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()
) {
ShellUtils.pump(in, out);

View File

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

View File

@ -4,8 +4,8 @@ import android.app.Activity;
import android.app.ProgressDialog;
import android.widget.Toast;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.superuser.ShellUtils;
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) {
dialog.cancel();
if (result) {
Global.toast(R.string.restore_done, Toast.LENGTH_SHORT);
Utils.toast(R.string.restore_done, Toast.LENGTH_SHORT);
} 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.text.TextUtils;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.ReposFragment;
import com.topjohnwu.magisk.container.Repo;
@ -49,7 +49,7 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
private ExecutorService threadPool;
public UpdateRepos(boolean force) {
mm = Global.MM();
mm = Data.MM();
mm.repoLoadDone.reset();
forceUpdate = force;
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.view.WindowManager;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.LocaleManager;
@ -40,7 +40,7 @@ public abstract class FlavorActivity extends AppCompatActivity {
if (this instanceof Topic.Subscriber) {
((Topic.Subscriber) this).subscribeTopics();
}
if (Global.isDarkTheme && getDarkTheme() != -1) {
if (Data.isDarkTheme && getDarkTheme() != -1) {
setTheme(getDarkTheme());
}
}

View File

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

View File

@ -4,7 +4,7 @@ import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.asyncs.MarkDownWindow;
@ -20,7 +20,7 @@ public class MagiskInstallDialog extends CustomAlertDialog {
super(activity);
MagiskManager mm = Utils.getMagiskManager(activity);
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)));
setMessage(mm.getString(R.string.repo_install_msg, filename));
setCancelable(true);
@ -38,15 +38,15 @@ public class MagiskInstallDialog extends CustomAlertDialog {
new InstallMethodDialog(activity, options, filename).show();
});
setNegativeButton(R.string.no_thanks, null);
if (!TextUtils.isEmpty(Global.magiskNoteLink)) {
if (!TextUtils.isEmpty(Data.magiskNoteLink)) {
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
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);
mm.startActivity(openLink);
} 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.text.TextUtils;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.asyncs.MarkDownWindow;
@ -19,21 +19,21 @@ public class ManagerInstallDialog extends CustomAlertDialog {
super(activity);
MagiskManager mm = Utils.getMagiskManager(activity);
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)));
setMessage(mm.getString(R.string.repo_install_msg, filename));
setCancelable(true);
setPositiveButton(R.string.install, (d, i) -> activity.runWithPermission(
new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, () -> {
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);
mm.sendBroadcast(intent);
}))
.setNegativeButton(R.string.no_thanks, null);
if (!TextUtils.isEmpty(Global.managerNoteLink)) {
if (!TextUtils.isEmpty(Data.managerNoteLink)) {
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.text.TextUtils;
import com.topjohnwu.magisk.Data;
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;
@ -25,7 +25,7 @@ public class UninstallDialog extends CustomAlertDialog {
setTitle(R.string.uninstall_magisk_title);
setMessage(R.string.uninstall_magisk_msg);
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) ->
Download.receive(activity, new DownloadReceiver() {
@Override
@ -36,7 +36,7 @@ public class UninstallDialog extends CustomAlertDialog {
.putExtra(Const.Key.FLASH_ACTION, Const.Value.UNINSTALL);
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.widget.Toast;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.container.Policy;
@ -76,10 +76,10 @@ public class MagiskDatabaseHelper {
}
// Cleanup
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
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
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
de.moveDatabaseFrom(mm, "su.db");
@ -90,7 +90,7 @@ public class MagiskDatabaseHelper {
final SuFile GLOBAL_DB = new SuFile("/data/adb/magisk.db");
mm.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
Shell.su("db_sepatch").exec();
}
@ -124,7 +124,7 @@ public class MagiskDatabaseHelper {
POLICY_TABLE, POLICY_TABLE));
db.execSQL(Utils.fmt("DROP TABLE %s_old", POLICY_TABLE));
Global.MM().deleteDatabase("sulog.db");
Data.MM().deleteDatabase("sulog.db");
++oldVersion;
}
if (oldVersion == 2) {
@ -143,7 +143,7 @@ public class MagiskDatabaseHelper {
// Remove everything, we do not support downgrade
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 " + LOG_TABLE);
db.execSQL("DROP TABLE IF EXISTS " + SETTINGS_TABLE);
@ -175,7 +175,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.suLogTimeout * 86400000), null);
db.delete(LOG_TABLE, Utils.fmt("time < %d", System.currentTimeMillis() - Data.suLogTimeout * 86400000), null);
}
public void deletePolicy(Policy policy) {

View File

@ -5,7 +5,7 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.container.Repo;
import com.topjohnwu.magisk.utils.Const;
@ -101,7 +101,7 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
public Cursor getRepoCursor() {
String orderBy = null;
switch (Global.repoOrder) {
switch (Data.repoOrder) {
case Const.Value.ORDER_NAME:
orderBy = "name COLLATE NOCASE";
break;
@ -109,7 +109,7 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
orderBy = "last_update DESC";
}
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);
}

View File

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

View File

@ -19,7 +19,7 @@ import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.asyncs.ParallelTask;
@ -103,7 +103,7 @@ public class RequestActivity extends Activity {
}
private void showRequest() {
switch (Global.suResponseType) {
switch (Data.suResponseType) {
case Const.Value.SU_AUTO_DENY:
handleAction(Policy.DENY, 0);
return;
@ -132,7 +132,7 @@ public class RequestActivity extends Activity {
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
timeout.setAdapter(adapter);
timer = new CountDownTimer(Global.suRequestTimeout * 1000, 1000) {
timer = new CountDownTimer(Data.suRequestTimeout * 1000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
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.widget.Toast;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.container.Policy;
@ -33,7 +33,7 @@ public class SuReceiver extends BroadcastReceiver {
if (mode < 0) return;
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;
}
@ -70,8 +70,8 @@ public class SuReceiver extends BroadcastReceiver {
return;
}
if (policy.notification && Global.suNotificationType == Const.Value.NOTIFICATION_TOAST) {
Global.toast(message, Toast.LENGTH_SHORT);
if (policy.notification && Data.suNotificationType == Const.Value.NOTIFICATION_TOAST) {
Utils.toast(message, Toast.LENGTH_SHORT);
}
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 com.topjohnwu.magisk.BuildConfig;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.Data;
import java.io.File;
import java.util.Arrays;
@ -40,13 +40,13 @@ public class Const {
public static final int SNET_VER = 10;
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 */
public static final List<String> HIDE_BLACKLIST = Arrays.asList(
"android",
Global.MM().getPackageName(),
Data.MM().getPackageName(),
"com.google.android.gms"
);

View File

@ -9,7 +9,7 @@ import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyPermanentlyInvalidatedException;
import android.security.keystore.KeyProperties;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager;
import java.security.KeyStore;
@ -28,14 +28,14 @@ public abstract class FingerprintHelper {
public static boolean canUseFingerprint() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
return false;
MagiskManager mm = Global.MM();
MagiskManager mm = Data.MM();
KeyguardManager km = mm.getSystemService(KeyguardManager.class);
FingerprintManager fm = mm.getSystemService(FingerprintManager.class);
return km.isKeyguardSecure() && fm != null && fm.isHardwareDetected() && fm.hasEnrolledFingerprints();
}
protected FingerprintHelper() throws Exception {
MagiskManager mm = Global.MM();
MagiskManager mm = Data.MM();
KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
manager = mm.getSystemService(FingerprintManager.class);
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.support.annotation.StringRes;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.asyncs.ParallelTask;
@ -21,12 +21,12 @@ public class LocaleManager {
public static List<Locale> locales;
public static void setLocale() {
MagiskManager mm = Global.MM();
Global.localeConfig = mm.prefs.getString(Const.Key.LOCALE, "");
if (Global.localeConfig.isEmpty()) {
MagiskManager mm = Data.MM();
Data.localeConfig = mm.prefs.getString(Const.Key.LOCALE, "");
if (Data.localeConfig.isEmpty()) {
locale = defaultLocale;
} else {
locale = Locale.forLanguageTag(Global.localeConfig);
locale = Locale.forLanguageTag(Data.localeConfig);
}
Resources res = mm.getResources();
Configuration config = new Configuration(res.getConfiguration());
@ -35,19 +35,19 @@ public class LocaleManager {
}
public static String getString(Locale locale, @StringRes int id) {
Configuration config = Global.MM().getResources().getConfiguration();
Configuration config = Data.MM().getResources().getConfiguration();
config.setLocale(locale);
return getString(config, 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() {
List<Locale> locales = new ArrayList<>();
HashSet<String> set = new HashSet<>();
MagiskManager mm = Global.MM();
MagiskManager mm = Data.MM();
Locale locale;
@StringRes int compareId = R.string.download_file_error;
@ -86,7 +86,7 @@ public class LocaleManager {
}
@Override
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.TaskStackBuilder;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.SplashActivity;
@ -17,7 +17,7 @@ import com.topjohnwu.magisk.receivers.RebootReceiver;
public class NotificationMgr {
public static void magiskUpdate() {
MagiskManager mm = Global.MM();
MagiskManager mm = Data.MM();
Intent intent = new Intent(mm, SplashActivity.class);
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);
builder.setSmallIcon(R.drawable.ic_magisk_outline)
.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})
.setAutoCancel(true)
.setContentIntent(pendingIntent);
@ -41,12 +41,12 @@ public class NotificationMgr {
}
public static void managerUpdate() {
MagiskManager mm = Global.MM();
MagiskManager mm = Data.MM();
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.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);
PendingIntent pendingIntent = PendingIntent.getBroadcast(mm,
Const.ID.APK_UPDATE_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
@ -65,7 +65,7 @@ public class NotificationMgr {
}
public static void dtboPatched() {
MagiskManager mm = Global.MM();
MagiskManager mm = Data.MM();
Intent intent = new Intent(mm, RebootReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(mm,

View File

@ -3,7 +3,7 @@ package com.topjohnwu.magisk.utils;
import android.content.Context;
import android.support.annotation.NonNull;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.R;
import com.topjohnwu.superuser.BusyBox;
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");
Global.loadMagiskInfo();
Data.loadMagiskInfo();
Global.keepVerity = Boolean.parseBoolean(ShellUtils.fastCmd("echo $KEEPVERITY"));
Global.keepEnc = Boolean.parseBoolean(ShellUtils.fastCmd("echo $KEEPFORCEENCRYPT"));
Data.keepVerity = Boolean.parseBoolean(ShellUtils.fastCmd("echo $KEEPVERITY"));
Data.keepEnc = Boolean.parseBoolean(ShellUtils.fastCmd("echo $KEEPFORCEENCRYPT"));
}
return true;
}

View File

@ -8,8 +8,9 @@ import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
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.services.UpdateCheckService;
@ -48,7 +49,7 @@ public class Utils {
}
public static int dpInPx(int dp) {
Context context = Global.MM();
Context context = Data.MM();
float scale = context.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5);
}
@ -67,7 +68,7 @@ public class Utils {
}
public static void setupUpdateCheck() {
MagiskManager mm = Global.MM();
MagiskManager mm = Data.MM();
JobScheduler scheduler = (JobScheduler) mm.getSystemService(Context.JOB_SCHEDULER_SERVICE);
if (mm.prefs.getBoolean(Const.Key.CHECK_UPDATES, true)) {
@ -85,4 +86,12 @@ public class Utils {
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());
}
}