Start moving things outside of top Application class
This commit is contained in:
parent
e39f83edbf
commit
914b7ee056
@ -75,7 +75,7 @@ public class FlashActivity extends Activity {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MagiskManager.toast(logFile.getPath(), Toast.LENGTH_LONG);
|
Global.toast(logFile.getPath(), Toast.LENGTH_LONG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
58
app/src/full/java/com/topjohnwu/magisk/Global.java
Normal file
58
app/src/full/java/com/topjohnwu/magisk/Global.java
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package com.topjohnwu.magisk;
|
||||||
|
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
|
import com.topjohnwu.superuser.ShellUtils;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
|
public class Global {
|
||||||
|
// Global app instance
|
||||||
|
public static WeakReference<MagiskManager> weakApp;
|
||||||
|
public static Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
|
|
||||||
|
// Current status
|
||||||
|
public static String magiskVersionString;
|
||||||
|
public static int magiskVersionCode = -1;
|
||||||
|
public static boolean magiskHide;
|
||||||
|
|
||||||
|
// Update Info
|
||||||
|
public static String remoteMagiskVersionString;
|
||||||
|
public static int remoteMagiskVersionCode = -1;
|
||||||
|
public static String magiskLink;
|
||||||
|
public static String magiskNoteLink;
|
||||||
|
public static String remoteManagerVersionString;
|
||||||
|
public static int remoteManagerVersionCode = -1;
|
||||||
|
public static String managerLink;
|
||||||
|
public static String managerNoteLink;
|
||||||
|
public static String uninstallerLink;
|
||||||
|
|
||||||
|
// Install flags
|
||||||
|
public static boolean keepVerity = false;
|
||||||
|
public static boolean keepEnc = false;
|
||||||
|
|
||||||
|
public static void loadMagiskInfo() {
|
||||||
|
try {
|
||||||
|
magiskVersionString = ShellUtils.fastCmd("magisk -v").split(":")[0];
|
||||||
|
magiskVersionCode = Integer.parseInt(ShellUtils.fastCmd("magisk -V"));
|
||||||
|
String s = ShellUtils.fastCmd((magiskVersionCode >= Const.MAGISK_VER.RESETPROP_PERSIST ?
|
||||||
|
"resetprop -p " : "getprop ") + Const.MAGISKHIDE_PROP);
|
||||||
|
magiskHide = s.isEmpty() || Integer.parseInt(s) != 0;
|
||||||
|
} catch (NumberFormatException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MagiskManager MM() {
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
@ -119,7 +119,7 @@ public class MagiskFragment extends Fragment
|
|||||||
shownDialog = true;
|
shownDialog = true;
|
||||||
|
|
||||||
// Show Manager update first
|
// Show Manager update first
|
||||||
if (mm.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
|
if (Global.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(mm.keepVerity);
|
keepVerityChkbox.setChecked(Global.keepVerity);
|
||||||
keepVerityChkbox.setOnCheckedChangeListener((view, checked) -> mm.keepVerity = checked);
|
keepVerityChkbox.setOnCheckedChangeListener((view, checked) -> Global.keepVerity = checked);
|
||||||
keepEncChkbox.setChecked(mm.keepEnc);
|
keepEncChkbox.setChecked(Global.keepEnc);
|
||||||
keepEncChkbox.setOnCheckedChangeListener((view, checked) -> mm.keepEnc = checked);
|
keepEncChkbox.setOnCheckedChangeListener((view, checked) -> Global.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() {
|
||||||
mm.loadMagiskInfo();
|
Global.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();
|
||||||
mm.remoteMagiskVersionString = null;
|
Global.remoteMagiskVersionString = null;
|
||||||
mm.remoteMagiskVersionCode = -1;
|
Global.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 = mm.magiskVersionCode > Const.MAGISK_VER.UNIFIED;
|
boolean isUpToDate = Global.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 (mm.magiskVersionCode < 0) {
|
if (Global.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" + mm.magiskVersionString));
|
magiskVersionText.setText(getString(R.string.current_magisk_title, "v" + Global.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 (mm.remoteMagiskVersionCode < 0) {
|
if (Global.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" + mm.remoteMagiskVersionString));
|
magiskUpdateText.setText(getString(R.string.install_magisk_title, "v" + Global.remoteMagiskVersionString));
|
||||||
installButton.setVisibility(View.VISIBLE);
|
installButton.setVisibility(View.VISIBLE);
|
||||||
if (mm.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
|
if (Global.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 (mm.magiskVersionCode > 0 && mm.remoteMagiskVersionCode > mm.magiskVersionCode) {
|
} else if (Global.magiskVersionCode > 0 && Global.remoteMagiskVersionCode > Global.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 (mm.remoteMagiskVersionCode > mm.magiskVersionCode
|
if (Global.remoteMagiskVersionCode > Global.magiskVersionCode
|
||||||
|| mm.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
|
|| Global.remoteManagerVersionCode > BuildConfig.VERSION_CODE) {
|
||||||
install();
|
install();
|
||||||
} else if (mm.remoteMagiskVersionCode >= Const.MAGISK_VER.FIX_ENV &&
|
} else if (Global.remoteMagiskVersionCode >= Const.MAGISK_VER.FIX_ENV &&
|
||||||
!ShellUtils.fastCmdResult("env_check")) {
|
!ShellUtils.fastCmdResult("env_check")) {
|
||||||
new EnvFixDialog(requireActivity()).show();
|
new EnvFixDialog(requireActivity()).show();
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
package com.topjohnwu.magisk;
|
package com.topjohnwu.magisk;
|
||||||
|
|
||||||
import android.app.job.JobInfo;
|
|
||||||
import android.app.job.JobScheduler;
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
@ -16,14 +13,12 @@ import android.widget.Toast;
|
|||||||
import com.topjohnwu.magisk.container.Module;
|
import com.topjohnwu.magisk.container.Module;
|
||||||
import com.topjohnwu.magisk.database.MagiskDatabaseHelper;
|
import com.topjohnwu.magisk.database.MagiskDatabaseHelper;
|
||||||
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
|
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
|
||||||
import com.topjohnwu.magisk.services.UpdateCheckService;
|
|
||||||
import com.topjohnwu.magisk.utils.Const;
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
import com.topjohnwu.magisk.utils.RootUtils;
|
import com.topjohnwu.magisk.utils.RootUtils;
|
||||||
import com.topjohnwu.magisk.utils.Topic;
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
import com.topjohnwu.superuser.ContainerApp;
|
import com.topjohnwu.superuser.ContainerApp;
|
||||||
import com.topjohnwu.superuser.Shell;
|
import com.topjohnwu.superuser.Shell;
|
||||||
import com.topjohnwu.superuser.ShellUtils;
|
|
||||||
import com.topjohnwu.superuser.io.SuFile;
|
import com.topjohnwu.superuser.io.SuFile;
|
||||||
import com.topjohnwu.superuser.io.SuFileInputStream;
|
import com.topjohnwu.superuser.io.SuFileInputStream;
|
||||||
|
|
||||||
@ -39,8 +34,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class MagiskManager extends ContainerApp {
|
public class MagiskManager extends ContainerApp {
|
||||||
|
|
||||||
public static WeakReference<MagiskManager> weakSelf;
|
|
||||||
public static Handler mHandler = new Handler();
|
|
||||||
public static Locale locale;
|
public static Locale locale;
|
||||||
public static Locale defaultLocale;
|
public static Locale defaultLocale;
|
||||||
|
|
||||||
@ -55,27 +48,11 @@ public class MagiskManager extends ContainerApp {
|
|||||||
|
|
||||||
// Info
|
// Info
|
||||||
public boolean hasInit = false;
|
public boolean hasInit = false;
|
||||||
public String magiskVersionString;
|
|
||||||
public int magiskVersionCode = -1;
|
|
||||||
public String remoteMagiskVersionString;
|
|
||||||
public int remoteMagiskVersionCode = -1;
|
|
||||||
public String remoteManagerVersionString;
|
|
||||||
public int remoteManagerVersionCode = -1;
|
|
||||||
|
|
||||||
public String magiskLink;
|
|
||||||
public String magiskNoteLink;
|
|
||||||
public String managerLink;
|
|
||||||
public String managerNoteLink;
|
|
||||||
public String uninstallerLink;
|
|
||||||
|
|
||||||
public boolean keepVerity = false;
|
|
||||||
public boolean keepEnc = false;
|
|
||||||
|
|
||||||
// Data
|
// Data
|
||||||
public Map<String, Module> moduleMap;
|
public Map<String, Module> moduleMap;
|
||||||
public List<Locale> locales;
|
public List<Locale> locales;
|
||||||
|
|
||||||
public boolean magiskHide;
|
|
||||||
public boolean isDarkTheme;
|
public boolean isDarkTheme;
|
||||||
public int suRequestTimeout;
|
public int suRequestTimeout;
|
||||||
public int suLogTimeout = 14;
|
public int suLogTimeout = 14;
|
||||||
@ -95,15 +72,7 @@ public class MagiskManager extends ContainerApp {
|
|||||||
public RepoDatabaseHelper repoDB;
|
public RepoDatabaseHelper repoDB;
|
||||||
|
|
||||||
public MagiskManager() {
|
public MagiskManager() {
|
||||||
weakSelf = new WeakReference<>(this);
|
Global.weakApp = new WeakReference<>(this);
|
||||||
}
|
|
||||||
|
|
||||||
public static void toast(CharSequence msg, int duration) {
|
|
||||||
mHandler.post(() -> Toast.makeText(weakSelf.get(), msg, duration).show());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void toast(int resId, int duration) {
|
|
||||||
mHandler.post(() -> Toast.makeText(weakSelf.get(), resId, duration).show());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -135,10 +104,6 @@ public class MagiskManager extends ContainerApp {
|
|||||||
loadConfig();
|
loadConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MagiskManager get() {
|
|
||||||
return weakSelf.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLocale() {
|
public void setLocale() {
|
||||||
localeConfig = prefs.getString(Const.Key.LOCALE, "");
|
localeConfig = prefs.getString(Const.Key.LOCALE, "");
|
||||||
if (localeConfig.isEmpty()) {
|
if (localeConfig.isEmpty()) {
|
||||||
@ -171,7 +136,7 @@ public class MagiskManager extends ContainerApp {
|
|||||||
public void writeConfig() {
|
public void writeConfig() {
|
||||||
prefs.edit()
|
prefs.edit()
|
||||||
.putBoolean(Const.Key.DARK_THEME, isDarkTheme)
|
.putBoolean(Const.Key.DARK_THEME, isDarkTheme)
|
||||||
.putBoolean(Const.Key.MAGISKHIDE, magiskHide)
|
.putBoolean(Const.Key.MAGISKHIDE, Global.magiskHide)
|
||||||
.putBoolean(Const.Key.HOSTS, Const.MAGISK_HOST_FILE.exists())
|
.putBoolean(Const.Key.HOSTS, Const.MAGISK_HOST_FILE.exists())
|
||||||
.putBoolean(Const.Key.COREONLY, Const.MAGISK_DISABLE_FILE.exists())
|
.putBoolean(Const.Key.COREONLY, Const.MAGISK_DISABLE_FILE.exists())
|
||||||
.putString(Const.Key.SU_REQUEST_TIMEOUT, String.valueOf(suRequestTimeout))
|
.putString(Const.Key.SU_REQUEST_TIMEOUT, String.valueOf(suRequestTimeout))
|
||||||
@ -188,40 +153,6 @@ public class MagiskManager extends ContainerApp {
|
|||||||
.apply();
|
.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadMagiskInfo() {
|
|
||||||
try {
|
|
||||||
magiskVersionString = ShellUtils.fastCmd("magisk -v").split(":")[0];
|
|
||||||
magiskVersionCode = Integer.parseInt(ShellUtils.fastCmd("magisk -V"));
|
|
||||||
String s = ShellUtils.fastCmd((magiskVersionCode >= Const.MAGISK_VER.RESETPROP_PERSIST ?
|
|
||||||
"resetprop -p " : "getprop ") + Const.MAGISKHIDE_PROP);
|
|
||||||
magiskHide = s.isEmpty() || Integer.parseInt(s) != 0;
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getDefaultInstallFlags() {
|
|
||||||
keepVerity = Boolean.parseBoolean(ShellUtils.fastCmd("echo $KEEPVERITY"));
|
|
||||||
keepEnc = Boolean.parseBoolean(ShellUtils.fastCmd("echo $KEEPFORCEENCRYPT"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setupUpdateCheck() {
|
|
||||||
JobScheduler scheduler = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE);
|
|
||||||
|
|
||||||
if (prefs.getBoolean(Const.Key.CHECK_UPDATES, true)) {
|
|
||||||
if (scheduler.getAllPendingJobs().isEmpty() ||
|
|
||||||
Const.UPDATE_SERVICE_VER > prefs.getInt(Const.Key.UPDATE_SERVICE_VER, -1)) {
|
|
||||||
ComponentName service = new ComponentName(this, UpdateCheckService.class);
|
|
||||||
JobInfo info = new JobInfo.Builder(Const.ID.UPDATE_SERVICE_ID, service)
|
|
||||||
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
|
|
||||||
.setPersisted(true)
|
|
||||||
.setPeriodic(8 * 60 * 60 * 1000)
|
|
||||||
.build();
|
|
||||||
scheduler.schedule(info);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
scheduler.cancel(Const.UPDATE_SERVICE_VER);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void dumpPrefs() {
|
public void dumpPrefs() {
|
||||||
// Flush prefs to disk
|
// Flush prefs to disk
|
||||||
prefs.edit().commit();
|
prefs.edit().commit();
|
||||||
|
@ -125,12 +125,12 @@ 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() && mm.magiskVersionCode >= Const.MAGISK_VER.UNIFIED
|
Shell.rootAccess() && Global.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() && mm.magiskVersionCode >= 0);
|
Shell.rootAccess() && Global.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() && mm.magiskVersionCode >= 0);
|
&& Download.checkNetworkStatus(this) && Shell.rootAccess() && Global.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 && mm.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED));
|
!(Const.USER_ID > 0 && mm.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED));
|
||||||
|
@ -108,7 +108,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();
|
||||||
MagiskManager.toast(R.string.repo_cache_cleared, Toast.LENGTH_SHORT);
|
Global.toast(R.string.repo_cache_cleared, Toast.LENGTH_SHORT);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
|||||||
fingerprint.setSummary(R.string.disable_fingerprint);
|
fingerprint.setSummary(R.string.disable_fingerprint);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mm.magiskVersionCode >= Const.MAGISK_VER.MANAGER_HIDE) {
|
if (Global.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();
|
||||||
@ -183,8 +183,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();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mm.managerLink,
|
Global.managerLink,
|
||||||
Utils.fmt("MagiskManager-v%s.apk", mm.remoteManagerVersionString)
|
Utils.fmt("MagiskManager-v%s.apk", Global.remoteManagerVersionString)
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@ -206,7 +206,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
|||||||
if (!Shell.rootAccess()) {
|
if (!Shell.rootAccess()) {
|
||||||
prefScreen.removePreference(magiskCategory);
|
prefScreen.removePreference(magiskCategory);
|
||||||
generalCatagory.removePreference(hideManager);
|
generalCatagory.removePreference(hideManager);
|
||||||
} else if (mm.magiskVersionCode < Const.MAGISK_VER.UNIFIED) {
|
} else if (Global.magiskVersionCode < Const.MAGISK_VER.UNIFIED) {
|
||||||
prefScreen.removePreference(magiskCategory);
|
prefScreen.removePreference(magiskCategory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -289,7 +289,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
|||||||
new CheckUpdates().exec();
|
new CheckUpdates().exec();
|
||||||
break;
|
break;
|
||||||
case Const.Key.CHECK_UPDATES:
|
case Const.Key.CHECK_UPDATES:
|
||||||
mm.setupUpdateCheck();
|
Utils.setupUpdateCheck();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mm.loadConfig();
|
mm.loadConfig();
|
||||||
|
@ -25,10 +25,10 @@ public class SplashActivity extends Activity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
MagiskManager mm = getMagiskManager();
|
MagiskManager mm = getMagiskManager();
|
||||||
|
// Force create a shell if not created yet
|
||||||
|
boolean root = Shell.rootAccess();
|
||||||
|
|
||||||
mm.repoDB = new RepoDatabaseHelper(this);
|
mm.repoDB = new RepoDatabaseHelper(this);
|
||||||
mm.loadMagiskInfo();
|
|
||||||
mm.getDefaultInstallFlags();
|
|
||||||
mm.loadPrefs();
|
mm.loadPrefs();
|
||||||
|
|
||||||
// Dynamic detect all locales
|
// Dynamic detect all locales
|
||||||
@ -54,9 +54,9 @@ public class SplashActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Magisk working as expected
|
// Magisk working as expected
|
||||||
if (Shell.rootAccess() && mm.magiskVersionCode > 0) {
|
if (root && Global.magiskVersionCode > 0) {
|
||||||
// Update check service
|
// Update check service
|
||||||
mm.setupUpdateCheck();
|
Utils.setupUpdateCheck();
|
||||||
// Fire asynctasks
|
// Fire asynctasks
|
||||||
loadModuleTask.exec();
|
loadModuleTask.exec();
|
||||||
}
|
}
|
||||||
@ -76,12 +76,12 @@ public class SplashActivity extends Activity {
|
|||||||
static class LoadLocale extends ParallelTask<Void, Void, Void> {
|
static class LoadLocale extends ParallelTask<Void, Void, Void> {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
MagiskManager.get().locales = Utils.getAvailableLocale();
|
Global.MM().locales = Utils.getAvailableLocale();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void aVoid) {
|
protected void onPostExecute(Void aVoid) {
|
||||||
MagiskManager.get().localeDone.publish();
|
Global.MM().localeDone.publish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.MagiskManager;
|
import com.topjohnwu.magisk.Global;
|
||||||
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 = MagiskManager.get().getPackageManager();
|
pm = Global.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) {
|
||||||
MagiskManager.get().magiskHideDone.publish(false);
|
Global.MM().magiskHideDone.publish(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package com.topjohnwu.magisk.asyncs;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.Global;
|
||||||
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(MagiskManager.get().getFilesDir().getParent() + "/snet", "snet.apk");
|
new File(Global.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 ->
|
||||||
MagiskManager.get().safetyNetDone.publish(false, code));
|
Global.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();
|
||||||
MagiskManager.get().safetyNetDone.publish(false, -1);
|
Global.MM().safetyNetDone.publish(false, -1);
|
||||||
}
|
}
|
||||||
super.onPostExecute(e);
|
super.onPostExecute(e);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +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.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;
|
||||||
@ -51,7 +52,7 @@ public class CheckUpdates extends ParallelTask<Void, Void, Void> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
MagiskManager mm = MagiskManager.get();
|
MagiskManager mm = Global.MM();
|
||||||
String jsonStr = "";
|
String jsonStr = "";
|
||||||
switch (mm.updateChannel) {
|
switch (mm.updateChannel) {
|
||||||
case Const.Value.STABLE_CHANNEL:
|
case Const.Value.STABLE_CHANNEL:
|
||||||
@ -73,30 +74,30 @@ public class CheckUpdates extends ParallelTask<Void, Void, Void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JSONObject magisk = getJson(json, "magisk");
|
JSONObject magisk = getJson(json, "magisk");
|
||||||
mm.remoteMagiskVersionString = getString(magisk, "version", null);
|
Global.remoteMagiskVersionString = getString(magisk, "version", null);
|
||||||
mm.remoteMagiskVersionCode = getInt(magisk, "versionCode", -1);
|
Global.remoteMagiskVersionCode = getInt(magisk, "versionCode", -1);
|
||||||
mm.magiskLink = getString(magisk, "link", null);
|
Global.magiskLink = getString(magisk, "link", null);
|
||||||
mm.magiskNoteLink = getString(magisk, "note", null);
|
Global.magiskNoteLink = getString(magisk, "note", null);
|
||||||
|
|
||||||
JSONObject manager = getJson(json, "app");
|
JSONObject manager = getJson(json, "app");
|
||||||
mm.remoteManagerVersionString = getString(manager, "version", null);
|
Global.remoteManagerVersionString = getString(manager, "version", null);
|
||||||
mm.remoteManagerVersionCode = getInt(manager, "versionCode", -1);
|
Global.remoteManagerVersionCode = getInt(manager, "versionCode", -1);
|
||||||
mm.managerLink = getString(manager, "link", null);
|
Global.managerLink = getString(manager, "link", null);
|
||||||
mm.managerNoteLink = getString(manager, "note", null);
|
Global.managerNoteLink = getString(manager, "note", null);
|
||||||
|
|
||||||
JSONObject uninstaller = getJson(json, "uninstaller");
|
JSONObject uninstaller = getJson(json, "uninstaller");
|
||||||
mm.uninstallerLink = getString(uninstaller, "link", null);
|
Global.uninstallerLink = getString(uninstaller, "link", null);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void v) {
|
protected void onPostExecute(Void v) {
|
||||||
MagiskManager mm = MagiskManager.get();
|
MagiskManager mm = Global.MM();
|
||||||
if (showNotification) {
|
if (showNotification) {
|
||||||
if (BuildConfig.VERSION_CODE < mm.remoteManagerVersionCode) {
|
if (BuildConfig.VERSION_CODE < Global.remoteManagerVersionCode) {
|
||||||
NotificationMgr.managerUpdate();
|
NotificationMgr.managerUpdate();
|
||||||
} else if (mm.magiskVersionCode < mm.remoteMagiskVersionCode) {
|
} else if (Global.magiskVersionCode < Global.remoteMagiskVersionCode) {
|
||||||
NotificationMgr.magiskUpdate();
|
NotificationMgr.magiskUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import android.net.Uri;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
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;
|
||||||
@ -44,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 = MagiskManager.get();
|
MagiskManager mm = Global.MM();
|
||||||
try {
|
try {
|
||||||
console.add("- Copying zip to temp directory");
|
console.add("- Copying zip to temp directory");
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ 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.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;
|
||||||
@ -55,7 +56,7 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Boolean doInBackground(Void... voids) {
|
protected Boolean doInBackground(Void... voids) {
|
||||||
MagiskManager mm = MagiskManager.get();
|
MagiskManager mm = Global.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");
|
||||||
@ -88,7 +89,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) {
|
||||||
MagiskManager.toast(R.string.hide_manager_fail_toast, Toast.LENGTH_LONG);
|
Global.toast(R.string.hide_manager_fail_toast, Toast.LENGTH_LONG);
|
||||||
}
|
}
|
||||||
super.onPostExecute(b);
|
super.onPostExecute(b);
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import android.text.TextUtils;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.Global;
|
||||||
import com.topjohnwu.magisk.FlashActivity;
|
import com.topjohnwu.magisk.FlashActivity;
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
@ -59,7 +60,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
|
|||||||
|
|
||||||
public InstallMagisk(Activity context) {
|
public InstallMagisk(Activity context) {
|
||||||
super(context);
|
super(context);
|
||||||
mm = MagiskManager.get();
|
mm = Global.MM();
|
||||||
mode = FIX_ENV_MODE;
|
mode = FIX_ENV_MODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,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",
|
||||||
mm.remoteMagiskVersionString, mm.remoteMagiskVersionCode);
|
Global.remoteMagiskVersionString, Global.remoteMagiskVersionCode);
|
||||||
HttpURLConnection conn = WebService.mustRequest(mm.magiskLink, null);
|
HttpURLConnection conn = WebService.mustRequest(Global.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))) {
|
||||||
@ -204,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",
|
||||||
mm.keepEnc, mm.keepVerity, mBoot))
|
Global.keepEnc, Global.keepVerity, mBoot))
|
||||||
.to(console, logs).exec().isSuccess())
|
.to(console, logs).exec().isSuccess())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@ -258,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 (!mm.keepVerity)
|
if (!Global.keepVerity)
|
||||||
job.add("find_dtbo_image", "patch_dtbo_image");
|
job.add("find_dtbo_image", "patch_dtbo_image");
|
||||||
job.exec();
|
job.exec();
|
||||||
break;
|
break;
|
||||||
@ -331,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 (mm.remoteMagiskVersionCode >= Const.MAGISK_VER.SEPOL_REFACTOR) {
|
if (Global.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";
|
||||||
@ -368,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();
|
||||||
MagiskManager.toast(result ? R.string.setup_done : R.string.setup_fail, Toast.LENGTH_LONG);
|
Global.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();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.topjohnwu.magisk.asyncs;
|
package com.topjohnwu.magisk.asyncs;
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.Global;
|
||||||
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;
|
||||||
@ -15,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 = MagiskManager.get();
|
MagiskManager mm = Global.MM();
|
||||||
mm.moduleMap = new ValueSortedMap<>();
|
mm.moduleMap = new ValueSortedMap<>();
|
||||||
|
|
||||||
for (String name : getModList()) {
|
for (String name : getModList()) {
|
||||||
@ -28,7 +29,7 @@ public class LoadModules extends ParallelTask<Void, Void, Void> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void v) {
|
protected void onPostExecute(Void v) {
|
||||||
MagiskManager.get().moduleLoadDone.publish();
|
Global.MM().moduleLoadDone.publish();
|
||||||
super.onPostExecute(v);
|
super.onPostExecute(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +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.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;
|
||||||
@ -38,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 = MagiskManager.get();
|
MagiskManager mm = Global.MM();
|
||||||
String md;
|
String md;
|
||||||
if (mUrl != null) {
|
if (mUrl != null) {
|
||||||
md = WebService.getString(mUrl);
|
md = WebService.getString(mUrl);
|
||||||
|
@ -9,7 +9,7 @@ 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.MagiskManager;
|
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;
|
||||||
@ -148,7 +148,7 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
|
|||||||
SnackbarMaker.showUri(activity, uri);
|
SnackbarMaker.showUri(activity, uri);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MagiskManager.toast(R.string.process_error, Toast.LENGTH_LONG);
|
Global.toast(R.string.process_error, Toast.LENGTH_LONG);
|
||||||
}
|
}
|
||||||
super.onPostExecute(result);
|
super.onPostExecute(result);
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import android.app.Activity;
|
|||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.Global;
|
||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
import com.topjohnwu.superuser.ShellUtils;
|
import com.topjohnwu.superuser.ShellUtils;
|
||||||
|
|
||||||
@ -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) {
|
||||||
MagiskManager.toast(R.string.restore_done, Toast.LENGTH_SHORT);
|
Global.toast(R.string.restore_done, Toast.LENGTH_SHORT);
|
||||||
} else {
|
} else {
|
||||||
MagiskManager.toast(R.string.restore_fail, Toast.LENGTH_LONG);
|
Global.toast(R.string.restore_fail, Toast.LENGTH_LONG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +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.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;
|
||||||
@ -48,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 = MagiskManager.get();
|
mm = Global.MM();
|
||||||
mm.repoLoadDone.reset();
|
mm.repoLoadDone.reset();
|
||||||
forceUpdate = force;
|
forceUpdate = force;
|
||||||
threadPool = Executors.newFixedThreadPool(CORE_POOL_SIZE);
|
threadPool = Executors.newFixedThreadPool(CORE_POOL_SIZE);
|
||||||
|
@ -7,6 +7,7 @@ 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.Global;
|
||||||
import com.topjohnwu.magisk.FlashActivity;
|
import com.topjohnwu.magisk.FlashActivity;
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
@ -27,12 +28,12 @@ class InstallMethodDialog extends AlertDialog.Builder {
|
|||||||
Intent intent;
|
Intent intent;
|
||||||
switch (idx) {
|
switch (idx) {
|
||||||
case 1:
|
case 1:
|
||||||
if (mm.remoteMagiskVersionCode < 1400) {
|
if (Global.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;
|
||||||
}
|
}
|
||||||
MagiskManager.toast(R.string.boot_file_patch_msg, Toast.LENGTH_LONG);
|
Global.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) -> {
|
||||||
@ -51,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);
|
||||||
}
|
}
|
||||||
}, mm.magiskLink, filename);
|
}, Global.magiskLink, filename);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
intent = new Intent(activity, FlashActivity.class)
|
intent = new Intent(activity, FlashActivity.class)
|
||||||
|
@ -4,6 +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.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,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",
|
||||||
mm.remoteMagiskVersionString, mm.remoteMagiskVersionCode);
|
Global.remoteMagiskVersionString, Global.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);
|
||||||
@ -37,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(mm.magiskNoteLink)) {
|
if (!TextUtils.isEmpty(Global.magiskNoteLink)) {
|
||||||
setNeutralButton(R.string.release_notes, (d, i) -> {
|
setNeutralButton(R.string.release_notes, (d, i) -> {
|
||||||
if (mm.magiskNoteLink.contains("forum.xda-developers")) {
|
if (Global.magiskNoteLink.contains("forum.xda-developers")) {
|
||||||
// Open forum links in browser
|
// Open forum links in browser
|
||||||
Intent openLink = new Intent(Intent.ACTION_VIEW, Uri.parse(mm.magiskNoteLink));
|
Intent openLink = new Intent(Intent.ACTION_VIEW, Uri.parse(Global.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, mm.magiskNoteLink).exec();
|
new MarkDownWindow(activity, null, Global.magiskNoteLink).exec();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -5,6 +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.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;
|
||||||
@ -18,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",
|
||||||
mm.remoteManagerVersionString, mm.remoteManagerVersionCode);
|
Global.remoteManagerVersionString, Global.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, mm.managerLink);
|
intent.putExtra(Const.Key.INTENT_SET_LINK, Global.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(mm.managerNoteLink)) {
|
if (!TextUtils.isEmpty(Global.managerNoteLink)) {
|
||||||
setNeutralButton(R.string.app_changelog, (d, i) ->
|
setNeutralButton(R.string.app_changelog, (d, i) ->
|
||||||
new MarkDownWindow(activity, null, mm.managerNoteLink).exec());
|
new MarkDownWindow(activity, null, Global.managerNoteLink).exec());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ 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.Global;
|
||||||
import com.topjohnwu.magisk.FlashActivity;
|
import com.topjohnwu.magisk.FlashActivity;
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
@ -24,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(mm.uninstallerLink)) {
|
if (!TextUtils.isEmpty(Global.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
|
||||||
@ -35,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);
|
||||||
}
|
}
|
||||||
}, mm.uninstallerLink, "magisk-uninstaller.zip"));
|
}, Global.uninstallerLink, "magisk-uninstaller.zip"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +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.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;
|
||||||
@ -72,13 +73,12 @@ public class MagiskDatabaseHelper {
|
|||||||
// We don't want the app to crash, create a db and return
|
// We don't want the app to crash, create a db and return
|
||||||
return mm.openOrCreateDatabase("su.db", Context.MODE_PRIVATE, null);
|
return mm.openOrCreateDatabase("su.db", Context.MODE_PRIVATE, null);
|
||||||
}
|
}
|
||||||
mm.loadMagiskInfo();
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
Shell.su("db_clean " + Const.USER_ID).exec();
|
Shell.su("db_clean " + Const.USER_ID).exec();
|
||||||
if (mm.magiskVersionCode < Const.MAGISK_VER.FBE_AWARE) {
|
if (Global.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 (mm.magiskVersionCode < Const.MAGISK_VER.HIDDEN_PATH) {
|
} else if (Global.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");
|
||||||
@ -89,7 +89,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 (mm.magiskVersionCode < Const.MAGISK_VER.SEPOL_REFACTOR) {
|
if (Global.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();
|
||||||
}
|
}
|
||||||
@ -123,7 +123,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));
|
||||||
|
|
||||||
MagiskManager.get().deleteDatabase("sulog.db");
|
Global.MM().deleteDatabase("sulog.db");
|
||||||
++oldVersion;
|
++oldVersion;
|
||||||
}
|
}
|
||||||
if (oldVersion == 2) {
|
if (oldVersion == 2) {
|
||||||
@ -142,7 +142,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) {
|
||||||
MagiskManager.toast(R.string.su_db_corrupt, Toast.LENGTH_LONG);
|
Global.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);
|
||||||
@ -174,7 +174,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() - MagiskManager.get().suLogTimeout * 86400000), null);
|
db.delete(LOG_TABLE, Utils.fmt("time < %d", System.currentTimeMillis() - Global.MM().suLogTimeout * 86400000), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deletePolicy(Policy policy) {
|
public void deletePolicy(Policy policy) {
|
||||||
|
@ -5,6 +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.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;
|
||||||
@ -108,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(mm.magiskVersionCode), String.valueOf(Const.MIN_MODULE_VER()) },
|
new String[] { String.valueOf(Global.magiskVersionCode), String.valueOf(Const.MIN_MODULE_VER()) },
|
||||||
null, null, orderBy);
|
null, null, orderBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,8 +8,8 @@ import android.content.pm.ShortcutManager;
|
|||||||
import android.graphics.drawable.Icon;
|
import android.graphics.drawable.Icon;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.support.annotation.RequiresApi;
|
import android.support.annotation.RequiresApi;
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
|
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.SplashActivity;
|
import com.topjohnwu.magisk.SplashActivity;
|
||||||
@ -25,10 +25,6 @@ public class ShortcutReceiver extends BroadcastReceiver {
|
|||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||||
MagiskManager mm = Utils.getMagiskManager(context);
|
MagiskManager mm = Utils.getMagiskManager(context);
|
||||||
ShortcutManager manager = context.getSystemService(ShortcutManager.class);
|
ShortcutManager manager = context.getSystemService(ShortcutManager.class);
|
||||||
if (TextUtils.equals(intent.getAction(), Intent.ACTION_LOCALE_CHANGED)) {
|
|
||||||
// It is triggered with locale change, manual load Magisk info
|
|
||||||
mm.loadMagiskInfo();
|
|
||||||
}
|
|
||||||
manager.setDynamicShortcuts(getShortCuts(mm));
|
manager.setDynamicShortcuts(getShortCuts(mm));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -36,8 +32,8 @@ public class ShortcutReceiver extends BroadcastReceiver {
|
|||||||
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
|
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
|
||||||
private ArrayList<ShortcutInfo> getShortCuts(MagiskManager mm) {
|
private ArrayList<ShortcutInfo> getShortCuts(MagiskManager mm) {
|
||||||
ArrayList<ShortcutInfo> shortCuts = new ArrayList<>();
|
ArrayList<ShortcutInfo> shortCuts = new ArrayList<>();
|
||||||
if (Shell.rootAccess() &&
|
boolean root = Shell.rootAccess();
|
||||||
!(Const.USER_ID > 0 &&
|
if (root && !(Const.USER_ID > 0 &&
|
||||||
mm.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) {
|
mm.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))
|
||||||
@ -49,7 +45,7 @@ public class ShortcutReceiver extends BroadcastReceiver {
|
|||||||
.setRank(0)
|
.setRank(0)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
if (Shell.rootAccess() && mm.magiskVersionCode >= Const.MAGISK_VER.UNIFIED
|
if (root && Global.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))
|
||||||
@ -61,8 +57,7 @@ public class ShortcutReceiver extends BroadcastReceiver {
|
|||||||
.setRank(1)
|
.setRank(1)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
if (!mm.prefs.getBoolean(Const.Key.COREONLY, false) &&
|
if (!mm.prefs.getBoolean(Const.Key.COREONLY, false) && root && Global.magiskVersionCode >= 0) {
|
||||||
Shell.rootAccess() && mm.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)
|
||||||
|
@ -4,15 +4,14 @@ import android.app.job.JobParameters;
|
|||||||
import android.app.job.JobService;
|
import android.app.job.JobService;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.asyncs.CheckUpdates;
|
import com.topjohnwu.magisk.asyncs.CheckUpdates;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.superuser.Shell;
|
||||||
|
|
||||||
public class UpdateCheckService extends JobService {
|
public class UpdateCheckService extends JobService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onStartJob(JobParameters params) {
|
public boolean onStartJob(JobParameters params) {
|
||||||
Utils.getMagiskManager(this).loadMagiskInfo();
|
Shell.getShell();
|
||||||
new CheckUpdates(true)
|
new CheckUpdates(true).setCallBack(() -> jobFinished(params, false)).exec();
|
||||||
.setCallBack(() -> jobFinished(params, false)).exec();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +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.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;
|
||||||
@ -32,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) {
|
||||||
MagiskManager.toast(R.string.multiuser_hint_owner_request, Toast.LENGTH_LONG);
|
Global.toast(R.string.multiuser_hint_owner_request, Toast.LENGTH_LONG);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +71,7 @@ public class SuReceiver extends BroadcastReceiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (policy.notification && mm.suNotificationType == Const.Value.NOTIFICATION_TOAST) {
|
if (policy.notification && mm.suNotificationType == Const.Value.NOTIFICATION_TOAST) {
|
||||||
MagiskManager.toast(message, Toast.LENGTH_SHORT);
|
Global.toast(message, Toast.LENGTH_SHORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == Const.Value.NOTIFY_NORMAL_LOG && policy.logging) {
|
if (mode == Const.Value.NOTIFY_NORMAL_LOG && policy.logging) {
|
||||||
|
@ -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.MagiskManager;
|
import com.topjohnwu.magisk.Global;
|
||||||
|
|
||||||
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 MagiskManager.get().magiskVersionCode >= MAGISK_VER.REMOVE_LEGACY_LINK ? 1500 : 1400;
|
return Global.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",
|
||||||
MagiskManager.get().getPackageName(),
|
Global.MM().getPackageName(),
|
||||||
"com.google.android.gms"
|
"com.google.android.gms"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -9,6 +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.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
|
|
||||||
import java.security.KeyStore;
|
import java.security.KeyStore;
|
||||||
@ -27,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 = MagiskManager.get();
|
MagiskManager mm = Global.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 = MagiskManager.get();
|
MagiskManager mm = Global.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 + "/"
|
||||||
|
@ -7,6 +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.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;
|
||||||
@ -16,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 = MagiskManager.get();
|
MagiskManager mm = Global.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");
|
||||||
@ -29,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, mm.remoteMagiskVersionString))
|
.setContentText(mm.getString(R.string.magisk_update_available, Global.remoteMagiskVersionString))
|
||||||
.setVibrate(new long[]{0, 100, 100, 100})
|
.setVibrate(new long[]{0, 100, 100, 100})
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.setContentIntent(pendingIntent);
|
.setContentIntent(pendingIntent);
|
||||||
@ -40,12 +41,12 @@ public class NotificationMgr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void managerUpdate() {
|
public static void managerUpdate() {
|
||||||
MagiskManager mm = MagiskManager.get();
|
MagiskManager mm = Global.MM();
|
||||||
String filename = Utils.fmt("MagiskManager-v%s(%d).apk",
|
String filename = Utils.fmt("MagiskManager-v%s(%d).apk",
|
||||||
mm.remoteManagerVersionString, mm.remoteManagerVersionCode);
|
Global.remoteManagerVersionString, Global.remoteManagerVersionCode);
|
||||||
|
|
||||||
Intent intent = new Intent(mm, ManagerUpdate.class);
|
Intent intent = new Intent(mm, ManagerUpdate.class);
|
||||||
intent.putExtra(Const.Key.INTENT_SET_LINK, mm.managerLink);
|
intent.putExtra(Const.Key.INTENT_SET_LINK, Global.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);
|
||||||
@ -64,7 +65,7 @@ public class NotificationMgr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void dtboPatched() {
|
public static void dtboPatched() {
|
||||||
MagiskManager mm = MagiskManager.get();
|
MagiskManager mm = Global.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,
|
||||||
|
@ -3,9 +3,11 @@ 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.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;
|
||||||
|
import com.topjohnwu.superuser.ShellUtils;
|
||||||
import com.topjohnwu.superuser.io.SuFile;
|
import com.topjohnwu.superuser.io.SuFile;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -18,26 +20,10 @@ public class RootUtils extends Shell.Initializer {
|
|||||||
BusyBox.BB_PATH = new File(Const.BUSYBOX_PATH);
|
BusyBox.BB_PATH = new File(Const.BUSYBOX_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean fileInit = false;
|
|
||||||
|
|
||||||
public static void uninstallPkg(String pkg) {
|
public static void uninstallPkg(String pkg) {
|
||||||
Shell.su("db_clean " + Const.USER_ID, "pm uninstall " + pkg).exec();
|
Shell.su("db_clean " + Const.USER_ID, "pm uninstall " + pkg).exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initConsts() {
|
|
||||||
Const.MAGISK_DISABLE_FILE = new SuFile("/cache/.disable_magisk");
|
|
||||||
SuFile file = new SuFile("/sbin/.core/img");
|
|
||||||
if (file.exists()) {
|
|
||||||
Const.MAGISK_PATH = file;
|
|
||||||
} else if ((file = new SuFile("/dev/magisk/img")).exists()) {
|
|
||||||
Const.MAGISK_PATH = file;
|
|
||||||
} else {
|
|
||||||
Const.MAGISK_PATH = new SuFile("/magisk");
|
|
||||||
}
|
|
||||||
Const.MAGISK_HOST_FILE = new SuFile(Const.MAGISK_PATH + "/.core/hosts");
|
|
||||||
fileInit = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onInit(Context context, @NonNull Shell shell) {
|
public boolean onInit(Context context, @NonNull Shell shell) {
|
||||||
if (shell.isRoot()) {
|
if (shell.isRoot()) {
|
||||||
@ -51,8 +37,22 @@ public class RootUtils extends Shell.Initializer {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!fileInit)
|
|
||||||
initConsts();
|
Const.MAGISK_DISABLE_FILE = new SuFile("/cache/.disable_magisk");
|
||||||
|
SuFile file = new SuFile("/sbin/.core/img");
|
||||||
|
if (file.exists()) {
|
||||||
|
Const.MAGISK_PATH = file;
|
||||||
|
} else if ((file = new SuFile("/dev/magisk/img")).exists()) {
|
||||||
|
Const.MAGISK_PATH = file;
|
||||||
|
} else {
|
||||||
|
Const.MAGISK_PATH = new SuFile("/magisk");
|
||||||
|
}
|
||||||
|
Const.MAGISK_HOST_FILE = new SuFile(Const.MAGISK_PATH + "/.core/hosts");
|
||||||
|
|
||||||
|
Global.loadMagiskInfo();
|
||||||
|
|
||||||
|
Global.keepVerity = Boolean.parseBoolean(ShellUtils.fastCmd("echo $KEEPVERITY"));
|
||||||
|
Global.keepEnc = Boolean.parseBoolean(ShellUtils.fastCmd("echo $KEEPFORCEENCRYPT"));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package com.topjohnwu.magisk.utils;
|
package com.topjohnwu.magisk.utils;
|
||||||
|
|
||||||
|
import android.app.job.JobInfo;
|
||||||
|
import android.app.job.JobScheduler;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
@ -8,8 +11,10 @@ import android.net.Uri;
|
|||||||
import android.provider.OpenableColumns;
|
import android.provider.OpenableColumns;
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.StringRes;
|
||||||
|
|
||||||
|
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.services.UpdateCheckService;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -50,7 +55,7 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getLocaleString(Locale locale, @StringRes int id) {
|
public static String getLocaleString(Locale locale, @StringRes int id) {
|
||||||
Context context = MagiskManager.get();
|
Context context = Global.MM();
|
||||||
Configuration config = context.getResources().getConfiguration();
|
Configuration config = context.getResources().getConfiguration();
|
||||||
config.setLocale(locale);
|
config.setLocale(locale);
|
||||||
Context localizedContext = context.createConfigurationContext(config);
|
Context localizedContext = context.createConfigurationContext(config);
|
||||||
@ -76,7 +81,7 @@ public class Utils {
|
|||||||
set.add(getLocaleString(locale, compareId));
|
set.add(getLocaleString(locale, compareId));
|
||||||
|
|
||||||
// Other locales
|
// Other locales
|
||||||
for (String s : MagiskManager.get().getAssets().getLocales()) {
|
for (String s : Global.MM().getAssets().getLocales()) {
|
||||||
locale = Locale.forLanguageTag(s);
|
locale = Locale.forLanguageTag(s);
|
||||||
if (set.add(getLocaleString(locale, compareId))) {
|
if (set.add(getLocaleString(locale, compareId))) {
|
||||||
locales.add(locale);
|
locales.add(locale);
|
||||||
@ -89,7 +94,7 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int dpInPx(int dp) {
|
public static int dpInPx(int dp) {
|
||||||
Context context = MagiskManager.get();
|
Context context = Global.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);
|
||||||
}
|
}
|
||||||
@ -106,4 +111,24 @@ public class Utils {
|
|||||||
return newString;
|
return newString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setupUpdateCheck() {
|
||||||
|
MagiskManager mm = Global.MM();
|
||||||
|
JobScheduler scheduler = (JobScheduler) mm.getSystemService(Context.JOB_SCHEDULER_SERVICE);
|
||||||
|
|
||||||
|
if (mm.prefs.getBoolean(Const.Key.CHECK_UPDATES, true)) {
|
||||||
|
if (scheduler.getAllPendingJobs().isEmpty() ||
|
||||||
|
Const.UPDATE_SERVICE_VER > mm.prefs.getInt(Const.Key.UPDATE_SERVICE_VER, -1)) {
|
||||||
|
ComponentName service = new ComponentName(mm, UpdateCheckService.class);
|
||||||
|
JobInfo info = new JobInfo.Builder(Const.ID.UPDATE_SERVICE_ID, service)
|
||||||
|
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
|
||||||
|
.setPersisted(true)
|
||||||
|
.setPeriodic(8 * 60 * 60 * 1000)
|
||||||
|
.build();
|
||||||
|
scheduler.schedule(info);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
scheduler.cancel(Const.UPDATE_SERVICE_VER);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user