mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-26 00:37:38 +00:00
Cleanup contexts
This commit is contained in:
parent
c036f6d529
commit
896ca2ef6b
@ -176,8 +176,8 @@ public class MagiskFragment extends Fragment
|
||||
shownDialog = false;
|
||||
|
||||
// Trigger state check
|
||||
if (Utils.checkNetworkStatus(mm)) {
|
||||
new CheckUpdates(getActivity()).exec();
|
||||
if (Utils.checkNetworkStatus()) {
|
||||
new CheckUpdates().exec();
|
||||
} else {
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
@ -230,7 +230,7 @@ public class MagiskFragment extends Fragment
|
||||
private void updateUI() {
|
||||
((MainActivity) getActivity()).checkHideSection();
|
||||
|
||||
boolean hasNetwork = Utils.checkNetworkStatus(getActivity());
|
||||
boolean hasNetwork = Utils.checkNetworkStatus();
|
||||
boolean hasRoot = Shell.rootAccess();
|
||||
boolean isUpToDate = mm.magiskVersionCode > 1300;
|
||||
|
||||
|
@ -170,9 +170,9 @@ public class MagiskLogFragment extends Fragment {
|
||||
case 2:
|
||||
boolean bool = (boolean) o;
|
||||
if (bool) {
|
||||
getMagiskManager().toast(targetFile.toString(), Toast.LENGTH_LONG);
|
||||
MagiskManager.toast(targetFile.toString(), Toast.LENGTH_LONG);
|
||||
} else {
|
||||
getMagiskManager().toast(R.string.logs_save_failed, Toast.LENGTH_LONG);
|
||||
MagiskManager.toast(R.string.logs_save_failed, Toast.LENGTH_LONG);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@ -39,6 +40,9 @@ import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class MagiskManager extends Application {
|
||||
|
||||
// Global weak reference to self
|
||||
private static WeakReference<MagiskManager> weakSelf;
|
||||
|
||||
public static final String MAGISK_DISABLE_FILE = "/cache/.disable_magisk";
|
||||
public static final String MAGISK_HOST_FILE = "/magisk/.core/hosts";
|
||||
public static final String TMP_FOLDER_PATH = "/dev/tmp";
|
||||
@ -110,21 +114,17 @@ public class MagiskManager extends Application {
|
||||
private static Handler mHandler = new Handler();
|
||||
private boolean started = false;
|
||||
|
||||
private static class LoadLocale extends ParallelTask<Void, Void, Void> {
|
||||
|
||||
LoadLocale(Context context) {
|
||||
super(context);
|
||||
}
|
||||
private class LoadLocale extends ParallelTask<Void, Void, Void> {
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
getMagiskManager().locales = Utils.getAvailableLocale(getMagiskManager());
|
||||
locales = Utils.getAvailableLocale();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
getMagiskManager().localeDone.publish();
|
||||
localeDone.publish();
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,15 +137,20 @@ public class MagiskManager extends Application {
|
||||
// Don't migrate yet, wait and check Magisk version
|
||||
suDB = new SuDatabaseHelper(this);
|
||||
} else {
|
||||
suDB = new SuDatabaseHelper(Utils.getEncContext(this));
|
||||
suDB = new SuDatabaseHelper(Utils.getEncContext());
|
||||
}
|
||||
|
||||
weakSelf = new WeakReference<>(this);
|
||||
repoDB = new RepoDatabaseHelper(this);
|
||||
defaultLocale = Locale.getDefault();
|
||||
setLocale();
|
||||
loadConfig();
|
||||
}
|
||||
|
||||
public static MagiskManager get() {
|
||||
return weakSelf.get();
|
||||
}
|
||||
|
||||
public void setLocale() {
|
||||
localeConfig = prefs.getString("locale", "");
|
||||
if (localeConfig.isEmpty()) {
|
||||
@ -177,12 +182,12 @@ public class MagiskManager extends Application {
|
||||
snet_version = prefs.getInt("snet_version", -1);
|
||||
}
|
||||
|
||||
public void toast(String msg, int duration) {
|
||||
mHandler.post(() -> Toast.makeText(this, msg, duration).show());
|
||||
public static void toast(String msg, int duration) {
|
||||
mHandler.post(() -> Toast.makeText(weakSelf.get(), msg, duration).show());
|
||||
}
|
||||
|
||||
public void toast(int resId, int duration) {
|
||||
mHandler.post(() -> Toast.makeText(this, resId, duration).show());
|
||||
public static void toast(int resId, int duration) {
|
||||
mHandler.post(() -> Toast.makeText(weakSelf.get(), resId, duration).show());
|
||||
}
|
||||
|
||||
public void startup() {
|
||||
@ -190,7 +195,7 @@ public class MagiskManager extends Application {
|
||||
return;
|
||||
started = true;
|
||||
|
||||
boolean hasNetwork = Utils.checkNetworkStatus(this);
|
||||
boolean hasNetwork = Utils.checkNetworkStatus();
|
||||
|
||||
getMagiskInfo();
|
||||
|
||||
@ -204,14 +209,14 @@ public class MagiskManager extends Application {
|
||||
}
|
||||
}
|
||||
|
||||
new LoadLocale(this).exec();
|
||||
new LoadLocale().exec();
|
||||
|
||||
// Root actions
|
||||
if (Shell.rootAccess()) {
|
||||
if (hasNetwork && !Utils.itemExist(BUSYBOXPATH + "/busybox")) {
|
||||
try {
|
||||
// Force synchronous, make sure we have busybox to use
|
||||
new DownloadBusybox(this).exec().get();
|
||||
new DownloadBusybox().exec().get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -265,7 +270,7 @@ public class MagiskManager extends Application {
|
||||
getSystemService(NotificationManager.class).createNotificationChannel(channel);
|
||||
}
|
||||
|
||||
LoadModules loadModuleTask = new LoadModules(this);
|
||||
LoadModules loadModuleTask = new LoadModules();
|
||||
// Start update check job
|
||||
if (hasNetwork) {
|
||||
ComponentName service = new ComponentName(this, UpdateCheckService.class);
|
||||
@ -275,7 +280,7 @@ public class MagiskManager extends Application {
|
||||
.setPeriodic(8 * 60 * 60 * 1000)
|
||||
.build();
|
||||
((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(jobInfo);
|
||||
loadModuleTask.setCallBack(() -> new UpdateRepos(this, false).exec());
|
||||
loadModuleTask.setCallBack(() -> new UpdateRepos(false).exec());
|
||||
}
|
||||
// Fire asynctasks
|
||||
loadModuleTask.exec();
|
||||
@ -284,7 +289,6 @@ public class MagiskManager extends Application {
|
||||
|
||||
public void getMagiskInfo() {
|
||||
List<String> ret;
|
||||
Shell.registerShell(this);
|
||||
ret = Shell.sh("su -v");
|
||||
if (Utils.isValidShellResponse(ret)) {
|
||||
suVersion = ret.get(0);
|
||||
|
@ -118,7 +118,7 @@ public class MainActivity extends Activity
|
||||
&& prefs.getBoolean("magiskhide", false));
|
||||
menu.findItem(R.id.modules).setVisible(
|
||||
Shell.rootAccess() && getMagiskManager().magiskVersionCode >= 0);
|
||||
menu.findItem(R.id.downloads).setVisible(Utils.checkNetworkStatus(this) &&
|
||||
menu.findItem(R.id.downloads).setVisible(Utils.checkNetworkStatus() &&
|
||||
Shell.rootAccess() && getMagiskManager().magiskVersionCode >= 0);
|
||||
menu.findItem(R.id.log).setVisible(Shell.rootAccess());
|
||||
menu.findItem(R.id.superuser).setVisible(
|
||||
|
@ -54,7 +54,7 @@ public class ModulesFragment extends Fragment implements Topic.Subscriber {
|
||||
|
||||
mSwipeRefreshLayout.setOnRefreshListener(() -> {
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
new LoadModules(getActivity()).exec();
|
||||
new LoadModules().exec();
|
||||
});
|
||||
|
||||
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
|
@ -47,7 +47,7 @@ public class ReposFragment extends Fragment implements Topic.Subscriber {
|
||||
mSwipeRefreshLayout.setOnRefreshListener(() -> {
|
||||
recyclerView.setVisibility(View.VISIBLE);
|
||||
emptyRv.setVisibility(View.GONE);
|
||||
new UpdateRepos(getActivity(), true).exec();
|
||||
new UpdateRepos(true).exec();
|
||||
});
|
||||
|
||||
getActivity().setTitle(R.string.downloads);
|
||||
|
@ -121,14 +121,14 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
||||
findPreference("clear").setOnPreferenceClickListener((pref) -> {
|
||||
mm.prefs.edit().remove(UpdateRepos.ETAG_KEY).apply();
|
||||
mm.repoDB.clearRepo();
|
||||
mm.toast(R.string.repo_cache_cleared, Toast.LENGTH_SHORT);
|
||||
MagiskManager.toast(R.string.repo_cache_cleared, Toast.LENGTH_SHORT);
|
||||
return true;
|
||||
});
|
||||
|
||||
hideManager.setOnPreferenceClickListener((pref) -> {
|
||||
Utils.runWithPermission(getActivity(),
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
() -> new HideManager(getActivity()).exec());
|
||||
() -> new HideManager().exec());
|
||||
return true;
|
||||
});
|
||||
|
||||
@ -239,7 +239,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
||||
break;
|
||||
case "update_channel":
|
||||
mm.updateChannel = Utils.getPrefsInt(prefs, "update_channel");
|
||||
new CheckUpdates(mm, true).exec();
|
||||
new CheckUpdates(true).exec();
|
||||
break;
|
||||
}
|
||||
mm.loadConfig();
|
||||
|
@ -33,7 +33,7 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
MagiskManager mm = getMagiskManager();
|
||||
MagiskManager mm = MagiskManager.get();
|
||||
if (mm.snet_version != CheckSafetyNet.SNET_VER) {
|
||||
Shell.sh("rm -rf " + dexPath.getParent());
|
||||
}
|
||||
@ -72,13 +72,13 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
|
||||
Object helper = helperClazz.getConstructors()[0].newInstance(
|
||||
getActivity(), Proxy.newProxyInstance(
|
||||
loader, new Class[] { callbackClazz }, (proxy, method, args) -> {
|
||||
getMagiskManager().safetyNetDone.publish(false, args[0]);
|
||||
MagiskManager.get().safetyNetDone.publish(false, args[0]);
|
||||
return null;
|
||||
}));
|
||||
helperClazz.getMethod("attest").invoke(helper);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
getMagiskManager().safetyNetDone.publish(false, -1);
|
||||
MagiskManager.get().safetyNetDone.publish(false, -1);
|
||||
}
|
||||
super.onPostExecute(err);
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.topjohnwu.magisk.asyncs;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.topjohnwu.magisk.BuildConfig;
|
||||
import com.topjohnwu.magisk.MagiskManager;
|
||||
import com.topjohnwu.magisk.utils.ShowUI;
|
||||
@ -18,21 +16,19 @@ public class CheckUpdates extends ParallelTask<Void, Void, Void> {
|
||||
private static final String STABLE_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/stable.json";
|
||||
private static final String BETA_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/beta.json";
|
||||
|
||||
private boolean showNotification = false;
|
||||
private boolean showNotification;
|
||||
|
||||
public CheckUpdates(Context context) {
|
||||
super(context);
|
||||
public CheckUpdates() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public CheckUpdates(Context context, boolean b) {
|
||||
super(context);
|
||||
public CheckUpdates(boolean b) {
|
||||
showNotification = b;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
MagiskManager mm = getMagiskManager();
|
||||
if (mm == null) return null;
|
||||
MagiskManager mm = MagiskManager.get();
|
||||
String jsonStr;
|
||||
switch (mm.updateChannel) {
|
||||
case STABLE_CHANNEL:
|
||||
@ -61,13 +57,12 @@ public class CheckUpdates extends ParallelTask<Void, Void, Void> {
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void v) {
|
||||
MagiskManager mm = getMagiskManager();
|
||||
if (mm == null) return;
|
||||
MagiskManager mm = MagiskManager.get();
|
||||
if (showNotification && mm.updateNotification) {
|
||||
if (BuildConfig.VERSION_CODE < mm.remoteManagerVersionCode) {
|
||||
ShowUI.showManagerUpdateNotification(mm);
|
||||
ShowUI.showManagerUpdateNotification();
|
||||
} else if (mm.magiskVersionCode < mm.remoteMagiskVersionCode) {
|
||||
ShowUI.showMagiskUpdateNotification(mm);
|
||||
ShowUI.showMagiskUpdateNotification();
|
||||
}
|
||||
}
|
||||
mm.updateCheckDone.publish();
|
||||
|
@ -21,14 +21,10 @@ public class DownloadBusybox extends ParallelTask<Void, Void, Void> {
|
||||
|
||||
private File busybox;
|
||||
|
||||
public DownloadBusybox(Context context) {
|
||||
super(context);
|
||||
busybox = new File(context.getCacheDir(), "busybox");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
Context context = getMagiskManager();
|
||||
Context context = MagiskManager.get();
|
||||
busybox = new File(context.getCacheDir(), "busybox");
|
||||
Utils.removeItem(context.getApplicationInfo().dataDir + "/busybox");
|
||||
try {
|
||||
FileOutputStream out = new FileOutputStream(busybox);
|
||||
|
@ -53,8 +53,7 @@ public class FlashZip extends ParallelTask<Void, Void, Integer> {
|
||||
|
||||
@Override
|
||||
protected Integer doInBackground(Void... voids) {
|
||||
MagiskManager mm = getMagiskManager();
|
||||
if (mm == null) return -1;
|
||||
MagiskManager mm = MagiskManager.get();
|
||||
try {
|
||||
mList.add("- Copying zip to temp directory");
|
||||
|
||||
@ -94,8 +93,7 @@ public class FlashZip extends ParallelTask<Void, Void, Integer> {
|
||||
// -1 = error, manual install; 0 = invalid zip; 1 = success
|
||||
@Override
|
||||
protected void onPostExecute(Integer result) {
|
||||
MagiskManager mm = getMagiskManager();
|
||||
if (mm == null) return;
|
||||
MagiskManager mm = MagiskManager.get();
|
||||
Shell.su_raw(
|
||||
"rm -rf " + mCachedFile.getParent(),
|
||||
"rm -rf " + MagiskManager.TMP_FOLDER_PATH
|
||||
@ -110,7 +108,7 @@ public class FlashZip extends ParallelTask<Void, Void, Integer> {
|
||||
break;
|
||||
case 1:
|
||||
// Success
|
||||
new LoadModules(mm).exec();
|
||||
new LoadModules().exec();
|
||||
break;
|
||||
}
|
||||
super.onPostExecute(result);
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.topjohnwu.magisk.asyncs;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Environment;
|
||||
import android.widget.Toast;
|
||||
@ -24,10 +23,6 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
|
||||
private static final String ANDROID_MANIFEST = "AndroidManifest.xml";
|
||||
private static final byte[] UNHIDE_PKG_NAME = "com.topjohnwu.unhide\0".getBytes();
|
||||
|
||||
public HideManager(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
private String genPackageName(String prefix, int length) {
|
||||
StringBuilder builder = new StringBuilder(length);
|
||||
builder.append(prefix);
|
||||
@ -51,14 +46,12 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
getMagiskManager().toast(R.string.hide_manager_toast, Toast.LENGTH_SHORT);
|
||||
MagiskManager.toast(R.string.hide_manager_toast, Toast.LENGTH_SHORT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... voids) {
|
||||
MagiskManager mm = getMagiskManager();
|
||||
if (mm == null)
|
||||
return false;
|
||||
MagiskManager mm = MagiskManager.get();
|
||||
|
||||
// Generate a new unhide app with random package name
|
||||
File unhideAPK = new File(Environment.getExternalStorageDirectory() + "/MagiskManager", "unhide.apk");
|
||||
@ -127,11 +120,8 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean b) {
|
||||
MagiskManager mm = getMagiskManager();
|
||||
if (mm == null)
|
||||
return;
|
||||
if (!b) {
|
||||
mm.toast(R.string.hide_manager_fail_toast, Toast.LENGTH_LONG);
|
||||
MagiskManager.toast(R.string.hide_manager_fail_toast, Toast.LENGTH_LONG);
|
||||
}
|
||||
super.onPostExecute(b);
|
||||
}
|
||||
|
@ -72,10 +72,9 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... voids) {
|
||||
MagiskManager mm = getMagiskManager();
|
||||
if (mm == null) return false;
|
||||
MagiskManager mm = MagiskManager.get();
|
||||
|
||||
File install = new File(Utils.getEncContext(mm).getFilesDir().getParent(), "install");
|
||||
File install = new File(Utils.getEncContext().getFilesDir().getParent(), "install");
|
||||
Shell.sh_raw("rm -rf " + install);
|
||||
|
||||
List<String> abis = Arrays.asList(Build.SUPPORTED_ABIS);
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.topjohnwu.magisk.asyncs;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.topjohnwu.magisk.MagiskManager;
|
||||
import com.topjohnwu.magisk.container.Module;
|
||||
import com.topjohnwu.magisk.container.ValueSortedMap;
|
||||
@ -11,10 +9,6 @@ import java.util.List;
|
||||
|
||||
public class LoadModules extends ParallelTask<Void, Void, Void> {
|
||||
|
||||
public LoadModules(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
private List<String> getModList() {
|
||||
String command = "ls -d " + MagiskManager.MAGISK_PATH + "/* | grep -v lost+found";
|
||||
return Shell.su(command);
|
||||
@ -22,8 +16,7 @@ public class LoadModules extends ParallelTask<Void, Void, Void> {
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
MagiskManager mm = getMagiskManager();
|
||||
if (mm == null) return null;
|
||||
MagiskManager mm = MagiskManager.get();
|
||||
mm.moduleMap = new ValueSortedMap<>();
|
||||
|
||||
for (String path : getModList()) {
|
||||
@ -36,9 +29,7 @@ public class LoadModules extends ParallelTask<Void, Void, Void> {
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void v) {
|
||||
MagiskManager mm = getMagiskManager();
|
||||
if (mm == null) return;
|
||||
mm.moduleLoadDone.publish();
|
||||
MagiskManager.get().moduleLoadDone.publish();
|
||||
super.onPostExecute(v);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import android.app.Activity;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import com.topjohnwu.magisk.MagiskManager;
|
||||
import com.topjohnwu.magisk.R;
|
||||
import com.topjohnwu.magisk.utils.WebService;
|
||||
|
||||
@ -29,7 +30,7 @@ public class MarkDownWindow extends ParallelTask<Void, Void, String> {
|
||||
Node doc = parser.parse(md);
|
||||
return String.format(
|
||||
"<link rel='stylesheet' type='text/css' href='file:///android_asset/%s.css'/> %s",
|
||||
getMagiskManager().isDarkTheme ? "dark" : "light", renderer.render(doc));
|
||||
MagiskManager.get().isDarkTheme ? "dark" : "light", renderer.render(doc));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.topjohnwu.magisk.asyncs;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import com.topjohnwu.magisk.MagiskManager;
|
||||
@ -12,18 +11,12 @@ import java.lang.ref.WeakReference;
|
||||
public abstract class ParallelTask<Params, Progress, Result> extends AsyncTask<Params, Progress, Result> {
|
||||
|
||||
private WeakReference<Activity> weakActivity;
|
||||
private WeakReference<MagiskManager> weakMagiskManager;
|
||||
|
||||
private Runnable callback = null;
|
||||
|
||||
public ParallelTask() {}
|
||||
|
||||
public ParallelTask(Context context) {
|
||||
weakMagiskManager = new WeakReference<>(Utils.getMagiskManager(context));
|
||||
}
|
||||
|
||||
public ParallelTask(Activity context) {
|
||||
this((Context) context);
|
||||
weakActivity = new WeakReference<>(context);
|
||||
}
|
||||
|
||||
@ -31,10 +24,6 @@ public abstract class ParallelTask<Params, Progress, Result> extends AsyncTask<P
|
||||
return weakActivity.get();
|
||||
}
|
||||
|
||||
protected MagiskManager getMagiskManager() {
|
||||
return weakMagiskManager.get();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public ParallelTask<Params, Progress, Result> exec(Params... params) {
|
||||
executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
|
||||
|
@ -10,6 +10,7 @@ import android.support.annotation.NonNull;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.topjohnwu.magisk.FlashActivity;
|
||||
import com.topjohnwu.magisk.MagiskManager;
|
||||
import com.topjohnwu.magisk.R;
|
||||
import com.topjohnwu.magisk.container.InputStreamWrapper;
|
||||
import com.topjohnwu.magisk.utils.Shell;
|
||||
@ -175,7 +176,7 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
|
||||
Utils.showUriSnack(activity, uri);
|
||||
}
|
||||
} else {
|
||||
Utils.getMagiskManager(activity).toast(R.string.process_error, Toast.LENGTH_LONG);
|
||||
MagiskManager.toast(R.string.process_error, Toast.LENGTH_LONG);
|
||||
}
|
||||
super.onPostExecute(result);
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.topjohnwu.magisk.asyncs;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.topjohnwu.magisk.MagiskManager;
|
||||
import com.topjohnwu.magisk.R;
|
||||
import com.topjohnwu.magisk.utils.Shell;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
@ -13,8 +13,7 @@ public class RestoreStockBoot extends ParallelTask<Void, Void, Boolean> {
|
||||
|
||||
private String mBoot;
|
||||
|
||||
public RestoreStockBoot(Context context, String boot) {
|
||||
super(context);
|
||||
public RestoreStockBoot(String boot) {
|
||||
mBoot = boot;
|
||||
}
|
||||
|
||||
@ -33,9 +32,9 @@ public class RestoreStockBoot extends ParallelTask<Void, Void, Boolean> {
|
||||
@Override
|
||||
protected void onPostExecute(Boolean result) {
|
||||
if (result) {
|
||||
getMagiskManager().toast(R.string.restore_done, Toast.LENGTH_SHORT);
|
||||
MagiskManager.toast(R.string.restore_done, Toast.LENGTH_SHORT);
|
||||
} else {
|
||||
getMagiskManager().toast(R.string.restore_fail, Toast.LENGTH_LONG);
|
||||
MagiskManager.toast(R.string.restore_fail, Toast.LENGTH_LONG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.topjohnwu.magisk.asyncs;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
@ -44,13 +43,13 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
|
||||
|
||||
private int tasks = 0;
|
||||
|
||||
public UpdateRepos(Context context, boolean force) {
|
||||
super(context);
|
||||
prefs = getMagiskManager().prefs;
|
||||
repoDB = getMagiskManager().repoDB;
|
||||
getMagiskManager().repoLoadDone.hasPublished = false;
|
||||
public UpdateRepos(boolean force) {
|
||||
MagiskManager mm = MagiskManager.get();
|
||||
prefs = mm.prefs;
|
||||
repoDB = mm.repoDB;
|
||||
mm.repoLoadDone.hasPublished = false;
|
||||
// Legacy data cleanup
|
||||
File old = new File(context.getApplicationInfo().dataDir + "/shared_prefs", "RepoMap.xml");
|
||||
File old = new File(mm.getApplicationInfo().dataDir + "/shared_prefs", "RepoMap.xml");
|
||||
if (old.exists() || prefs.getString("repomap", null) != null) {
|
||||
old.delete();
|
||||
prefs.edit().remove("version").remove("repomap").remove(ETAG_KEY).apply();
|
||||
@ -211,9 +210,7 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void v) {
|
||||
MagiskManager mm = getMagiskManager();
|
||||
if (mm == null) return;
|
||||
mm.repoLoadDone.publish();
|
||||
MagiskManager.get().repoLoadDone.publish();
|
||||
super.onPostExecute(v);
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.topjohnwu.magisk.MagiskManager;
|
||||
import com.topjohnwu.magisk.R;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
@ -34,7 +35,7 @@ public abstract class DownloadReceiver extends BroadcastReceiver {
|
||||
onDownloadDone(uri);
|
||||
break;
|
||||
default:
|
||||
Utils.getMagiskManager(context).toast(R.string.download_file_error, Toast.LENGTH_LONG);
|
||||
MagiskManager.toast(R.string.download_file_error, Toast.LENGTH_LONG);
|
||||
break;
|
||||
}
|
||||
context.unregisterReceiver(this);
|
||||
|
@ -11,7 +11,7 @@ public class UpdateCheckService extends JobService {
|
||||
@Override
|
||||
public boolean onStartJob(JobParameters params) {
|
||||
Utils.getMagiskManager(this).getMagiskInfo();
|
||||
new CheckUpdates(this, true)
|
||||
new CheckUpdates(true)
|
||||
.setCallBack(() -> jobFinished(params, false)).exec();
|
||||
return true;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class SuReceiver extends BroadcastReceiver {
|
||||
if (mode < 0) return;
|
||||
|
||||
if (mode == NOTIFY_USER_TO_OWNER) {
|
||||
magiskManager.toast(R.string.multiuser_hint_owner_request, Toast.LENGTH_LONG);
|
||||
MagiskManager.toast(R.string.multiuser_hint_owner_request, Toast.LENGTH_LONG);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.topjohnwu.magisk.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.topjohnwu.magisk.MagiskManager;
|
||||
@ -10,7 +9,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -21,8 +19,6 @@ import java.util.List;
|
||||
|
||||
public class Shell {
|
||||
|
||||
private static WeakReference<MagiskManager> weakMm;
|
||||
|
||||
// -1 = no shell; 0 = non root shell; 1 = root shell
|
||||
public static int status;
|
||||
|
||||
@ -47,12 +43,8 @@ public class Shell {
|
||||
STDOUT = process.getInputStream();
|
||||
}
|
||||
|
||||
public static void registerShell(Context context) {
|
||||
weakMm = new WeakReference<>(Utils.getMagiskManager(context));
|
||||
}
|
||||
|
||||
public static Shell getShell() {
|
||||
MagiskManager mm = weakMm.get();
|
||||
MagiskManager mm = MagiskManager.get();
|
||||
boolean needNewShell = mm.shell == null;
|
||||
|
||||
if (!needNewShell) {
|
||||
|
@ -34,7 +34,8 @@ public class ShowUI {
|
||||
private static final int MAGISK_UPDATE_NOTIFICATION_ID = 1;
|
||||
private static final int APK_UPDATE_NOTIFICATION_ID = 2;
|
||||
|
||||
public static void showMagiskUpdateNotification(MagiskManager mm) {
|
||||
public static void showMagiskUpdateNotification() {
|
||||
MagiskManager mm = MagiskManager.get();
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, MagiskManager.NOTIFICATION_CHANNEL);
|
||||
builder.setSmallIcon(R.drawable.ic_magisk)
|
||||
.setContentTitle(mm.getString(R.string.magisk_update_title))
|
||||
@ -54,7 +55,8 @@ public class ShowUI {
|
||||
notificationManager.notify(MAGISK_UPDATE_NOTIFICATION_ID, builder.build());
|
||||
}
|
||||
|
||||
public static void showManagerUpdateNotification(MagiskManager mm) {
|
||||
public static void showManagerUpdateNotification() {
|
||||
MagiskManager mm = MagiskManager.get();
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, MagiskManager.NOTIFICATION_CHANNEL);
|
||||
builder.setSmallIcon(R.drawable.ic_magisk)
|
||||
.setContentTitle(mm.getString(R.string.manager_update_title))
|
||||
@ -73,7 +75,7 @@ public class ShowUI {
|
||||
}
|
||||
|
||||
public static void showMagiskInstallDialog(MagiskFragment fragment, boolean enc, boolean verity) {
|
||||
MagiskManager mm = Utils.getMagiskManager(fragment.getActivity());
|
||||
MagiskManager mm = Utils.getMagiskManager(fragment.getContext());
|
||||
String filename = Utils.getLegalFilename("Magisk-v" + mm.remoteMagiskVersionString + ".zip");
|
||||
new AlertDialogBuilder(fragment.getActivity())
|
||||
.setTitle(mm.getString(R.string.repo_install_title, mm.getString(R.string.magisk)))
|
||||
@ -101,10 +103,10 @@ public class ShowUI {
|
||||
switch (idx) {
|
||||
case 1:
|
||||
if (mm.remoteMagiskVersionCode < 1400) {
|
||||
mm.toast(R.string.no_boot_file_patch_support, Toast.LENGTH_LONG);
|
||||
MagiskManager.toast(R.string.no_boot_file_patch_support, Toast.LENGTH_LONG);
|
||||
return;
|
||||
}
|
||||
mm.toast(R.string.boot_file_patch_msg, Toast.LENGTH_LONG);
|
||||
MagiskManager.toast(R.string.boot_file_patch_msg, Toast.LENGTH_LONG);
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.setType("*/*");
|
||||
fragment.startActivityForResult(intent, SELECT_BOOT_IMG,
|
||||
@ -256,7 +258,7 @@ public class ShowUI {
|
||||
"cat " + uninstaller + " > /cache/" + UNINSTALLER,
|
||||
"cat " + utils + " > /data/magisk/" + Utils.UTIL_FUNCTIONS
|
||||
);
|
||||
mm.toast(R.string.uninstall_toast, Toast.LENGTH_LONG);
|
||||
MagiskManager.toast(R.string.uninstall_toast, Toast.LENGTH_LONG);
|
||||
Shell.su_raw(
|
||||
"sleep 5",
|
||||
"pm uninstall " + mm.getApplicationInfo().packageName
|
||||
@ -268,7 +270,7 @@ public class ShowUI {
|
||||
.setNeutralButton(R.string.restore_stock_boot, (d, i) -> {
|
||||
String boot = fragment.getSelectedBootImage();
|
||||
if (boot == null) return;
|
||||
new RestoreStockBoot(mm, boot).exec();
|
||||
new RestoreStockBoot(boot).exec();
|
||||
})
|
||||
.setNegativeButton(R.string.no_thanks, null)
|
||||
.show();
|
||||
|
@ -143,41 +143,43 @@ public class Utils {
|
||||
.setAction(R.string.ok, (v)->{}).show();
|
||||
}
|
||||
|
||||
public static boolean checkNetworkStatus(Context context) {
|
||||
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
public static boolean checkNetworkStatus() {
|
||||
ConnectivityManager manager = (ConnectivityManager)
|
||||
MagiskManager.get().getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
|
||||
return networkInfo != null && networkInfo.isConnected();
|
||||
}
|
||||
|
||||
public static String getLocaleString(Context context, Locale locale, @StringRes int id) {
|
||||
public static String getLocaleString(Locale locale, @StringRes int id) {
|
||||
Context context = MagiskManager.get();
|
||||
Configuration config = context.getResources().getConfiguration();
|
||||
config.setLocale(locale);
|
||||
Context localizedContext = context.createConfigurationContext(config);
|
||||
return localizedContext.getString(id);
|
||||
}
|
||||
|
||||
public static List<Locale> getAvailableLocale(Context context) {
|
||||
public static List<Locale> getAvailableLocale() {
|
||||
List<Locale> locales = new ArrayList<>();
|
||||
HashSet<String> set = new HashSet<>();
|
||||
Locale locale;
|
||||
|
||||
int compareId = R.string.download_file_error;
|
||||
@StringRes int compareId = R.string.download_file_error;
|
||||
|
||||
// Add default locale
|
||||
locales.add(Locale.ENGLISH);
|
||||
set.add(getLocaleString(context, Locale.ENGLISH, compareId));
|
||||
set.add(getLocaleString(Locale.ENGLISH, compareId));
|
||||
|
||||
// Add some special locales
|
||||
locales.add(Locale.TAIWAN);
|
||||
set.add(getLocaleString(context, Locale.TAIWAN, compareId));
|
||||
set.add(getLocaleString(Locale.TAIWAN, compareId));
|
||||
locale = new Locale("pt", "BR");
|
||||
locales.add(locale);
|
||||
set.add(getLocaleString(context, locale, compareId));
|
||||
set.add(getLocaleString(locale, compareId));
|
||||
|
||||
// Other locales
|
||||
for (String s : context.getAssets().getLocales()) {
|
||||
for (String s : MagiskManager.get().getAssets().getLocales()) {
|
||||
locale = Locale.forLanguageTag(s);
|
||||
if (set.add(getLocaleString(context, locale, compareId))) {
|
||||
if (set.add(getLocaleString(locale, compareId))) {
|
||||
locales.add(locale);
|
||||
}
|
||||
}
|
||||
@ -206,7 +208,8 @@ public class Utils {
|
||||
== DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE_PER_USER;
|
||||
}
|
||||
|
||||
public static Context getEncContext(Context context) {
|
||||
public static Context getEncContext() {
|
||||
Context context = MagiskManager.get();
|
||||
if (useFDE(context))
|
||||
return context.createDeviceProtectedStorageContext();
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user