Cleanup prefs

This commit is contained in:
topjohnwu 2017-12-03 04:15:17 +08:00
parent 1cd2c5e653
commit f3c3b5a649
11 changed files with 29 additions and 43 deletions

View File

@ -8,7 +8,7 @@ android {
applicationId "com.topjohnwu.magisk"
minSdkVersion 21
targetSdkVersion 27
versionCode 68
versionCode 69
versionName "5.4.3"
ndk {
moduleName 'zipadjust'

View File

@ -1,5 +1,6 @@
### v5.4.3 (68)
- Fix dynamic resource loading, should prevent crashing when chacking SafetyNet
### v5.4.3 (69)
- Fix dynamic resource loading, should prevent crashing when checking SafetyNet
- Update SignAPK to use very little RAM, should expand old device support
- Support settings migration after hiding Magisk Manager
- Add changelog in app
- Add reboot menu in modules section
- Add changelog in app

View File

@ -91,7 +91,7 @@ public class MagiskFragment extends Fragment
new CheckSafetyNet(getActivity()).exec();
collapse();
};
if (mm.snet_version < 0) {
if (mm.snetVersion < 0) {
// Show dialog
new AlertDialogBuilder(getActivity())
.setTitle(R.string.proprietary_title)

View File

@ -50,9 +50,7 @@ public class MagiskManager extends Application {
public int remoteManagerVersionCode = -1;
public String managerLink;
public String bootBlock = null;
public int snet_version;
public int updateServiceVersion;
public int appVersion;
public int snetVersion;
// Data
public Map<String, Module> moduleMap;
@ -66,7 +64,6 @@ public class MagiskManager extends Application {
public boolean isDarkTheme;
public boolean updateNotification;
public boolean suReauth;
public boolean coreOnly;
public int suRequestTimeout;
public int suLogTimeout = 14;
public int suAccessState;
@ -146,8 +143,6 @@ public class MagiskManager extends Application {
}
public void loadConfig() {
isDarkTheme = prefs.getBoolean(Const.Key.DARK_THEME, false);
// su
suRequestTimeout = Utils.getPrefsInt(prefs, Const.Key.SU_REQUEST_TIMEOUT, Const.Value.timeoutList[2]);
suResponseType = Utils.getPrefsInt(prefs, Const.Key.SU_AUTO_RESPONSE, Const.Value.SU_PROMPT);
@ -157,14 +152,13 @@ public class MagiskManager extends Application {
multiuserMode = suDB.getSettings(Const.Key.SU_MULTIUSER_MODE, Const.Value.MULTIUSER_MODE_OWNER_ONLY);
suNamespaceMode = suDB.getSettings(Const.Key.SU_MNT_NS, Const.Value.NAMESPACE_MODE_REQUESTER);
coreOnly = prefs.getBoolean(Const.Key.DISABLE, false);
// config
isDarkTheme = prefs.getBoolean(Const.Key.DARK_THEME, false);
updateNotification = prefs.getBoolean(Const.Key.UPDATE_NOTIFICATION, true);
updateChannel = Utils.getPrefsInt(prefs, Const.Key.UPDATE_CHANNEL, Const.Value.STABLE_CHANNEL);
bootFormat = prefs.getString(Const.Key.BOOT_FORMAT, ".img");
snet_version = prefs.getInt(Const.Key.SNET_VER, -1);
updateServiceVersion = prefs.getInt(Const.Key.UPDATE_SERVICE_VER, -1);
snetVersion = prefs.getInt(Const.Key.SNET_VER, -1);
customChannelUrl = prefs.getString(Const.Key.CUSTOM_CHANNEL, "");
appVersion = prefs.getInt(Const.Key.APP_VER, 0);
}
public static void toast(String msg, int duration) {

View File

@ -92,9 +92,8 @@ public class MainActivity extends Activity
navigationView.setNavigationItemSelectedListener(this);
if (mm.appVersion < BuildConfig.VERSION_CODE) {
if (mm.prefs.getInt(Const.Key.APP_VER, -1) < BuildConfig.VERSION_CODE) {
prefs.edit().putInt(Const.Key.APP_VER, BuildConfig.VERSION_CODE).apply();
mm.appVersion = BuildConfig.VERSION_CODE;
try {
InputStream is = getAssets().open("changelog.md");
new MarkDownWindow(this, getString(R.string.app_changelog), is).exec();
@ -149,7 +148,7 @@ public class MainActivity extends Activity
Shell.rootAccess() && mm.magiskVersionCode >= 0);
menu.findItem(R.id.downloads).setVisible(Utils.checkNetworkStatus() &&
Shell.rootAccess() && mm.magiskVersionCode >= 0);
menu.setGroupVisible(R.id.second_group, !mm.coreOnly);
menu.setGroupVisible(R.id.second_group, !mm.prefs.getBoolean(Const.Key.COREONLY, false));
menu.findItem(R.id.log).setVisible(Shell.rootAccess());
menu.findItem(R.id.superuser).setVisible(Shell.rootAccess());
}

View File

@ -141,7 +141,8 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
// Remove re-authentication option on Android O, it will not work
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
suCategory.removePreference(reauth);
reauth.setEnabled(false);
reauth.setSummary(R.string.android_o_not_support);
}
if (mm.getPackageName().equals(Const.ORIG_PKG_NAME) && mm.magiskVersionCode >= 1440) {
@ -204,18 +205,14 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
boolean enabled;
switch (key) {
case Const.Key.DARK_THEME:
enabled = prefs.getBoolean(Const.Key.DARK_THEME, false);
if (mm.isDarkTheme != enabled) {
mm.reloadActivity.publish(false);
}
mm.isDarkTheme = prefs.getBoolean(key, false);
mm.reloadActivity.publish(false);
break;
case Const.Key.DISABLE:
enabled = prefs.getBoolean(Const.Key.DISABLE, false);
if (enabled) {
case Const.Key.COREONLY:
if (prefs.getBoolean(key, false)) {
Utils.createFile(Const.MAGISK_DISABLE_FILE);
} else {
Utils.removeItem(Const.MAGISK_DISABLE_FILE);
@ -223,16 +220,14 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
Toast.makeText(getActivity(), R.string.settings_reboot_toast, Toast.LENGTH_LONG).show();
break;
case Const.Key.MAGISKHIDE:
enabled = prefs.getBoolean(Const.Key.MAGISKHIDE, false);
if (enabled) {
if (prefs.getBoolean(key, false)) {
Shell.su_raw("magiskhide --enable");
} else {
Shell.su_raw("magiskhide --disable");
}
break;
case Const.Key.HOSTS:
enabled = prefs.getBoolean(Const.Key.HOSTS, false);
if (enabled) {
if (prefs.getBoolean(key, false)) {
Shell.su_raw(
"cp -af /system/etc/hosts " + Const.MAGISK_HOST_FILE(),
"mount -o bind " + Const.MAGISK_HOST_FILE() + " /system/etc/hosts");
@ -243,13 +238,9 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
}
break;
case Const.Key.ROOT_ACCESS:
mm.suDB.setSettings(Const.Key.ROOT_ACCESS, Utils.getPrefsInt(prefs, Const.Key.ROOT_ACCESS));
break;
case Const.Key.SU_MULTIUSER_MODE:
mm.suDB.setSettings(Const.Key.SU_MULTIUSER_MODE, Utils.getPrefsInt(prefs, Const.Key.SU_MULTIUSER_MODE));
break;
case Const.Key.SU_MNT_NS:
mm.suDB.setSettings(Const.Key.SU_MNT_NS, Utils.getPrefsInt(prefs, Const.Key.SU_MNT_NS));
mm.suDB.setSettings(key, Utils.getPrefsInt(prefs, key));
break;
case Const.Key.LOCALE:
mm.setLocale();

View File

@ -69,7 +69,7 @@ public class SplashActivity extends Activity {
SuDatabaseHelper.setupSuDB();
// Add update checking service
if (Const.Value.UPDATE_SERVICE_VER > mm.updateServiceVersion) {
if (Const.Value.UPDATE_SERVICE_VER > mm.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)
@ -77,7 +77,6 @@ public class SplashActivity extends Activity {
.setPeriodic(8 * 60 * 60 * 1000)
.build();
((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(info);
mm.updateServiceVersion = Const.Value.UPDATE_SERVICE_VER;
}
// Fire asynctasks
@ -93,7 +92,7 @@ public class SplashActivity extends Activity {
.putBoolean(Const.Key.MAGISKHIDE, mm.magiskHide)
.putBoolean(Const.Key.UPDATE_NOTIFICATION, mm.updateNotification)
.putBoolean(Const.Key.HOSTS, Utils.itemExist(Const.MAGISK_HOST_FILE()))
.putBoolean(Const.Key.DISABLE, Utils.itemExist(Const.MAGISK_DISABLE_FILE))
.putBoolean(Const.Key.COREONLY, Utils.itemExist(Const.MAGISK_DISABLE_FILE))
.putBoolean(Const.Key.SU_REAUTH, mm.suReauth)
.putString(Const.Key.SU_REQUEST_TIMEOUT, String.valueOf(mm.suRequestTimeout))
.putString(Const.Key.SU_AUTO_RESPONSE, String.valueOf(mm.suResponseType))
@ -104,7 +103,7 @@ public class SplashActivity extends Activity {
.putString(Const.Key.UPDATE_CHANNEL, String.valueOf(mm.updateChannel))
.putString(Const.Key.LOCALE, mm.localeConfig)
.putString(Const.Key.BOOT_FORMAT, mm.bootFormat)
.putInt(Const.Key.UPDATE_SERVICE_VER, mm.updateServiceVersion)
.putInt(Const.Key.UPDATE_SERVICE_VER, Const.Value.UPDATE_SERVICE_VER)
.apply();
mm.hasInit = true;

View File

@ -32,10 +32,10 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
@Override
protected void onPreExecute() {
MagiskManager mm = MagiskManager.get();
if (mm.snet_version != Const.Value.SNET_VER) {
if (mm.snetVersion != Const.Value.SNET_VER) {
Shell.sh("rm -rf " + dexPath.getParent());
}
mm.snet_version = Const.Value.SNET_VER;
mm.snetVersion = Const.Value.SNET_VER;
mm.prefs.edit().putInt(Const.Key.SNET_VER, Const.Value.SNET_VER).apply();
}

View File

@ -121,7 +121,7 @@ public class Const {
public static final String APP_VER = "app_version";
public static final String MAGISKHIDE = "magiskhide";
public static final String HOSTS = "hosts";
public static final String DISABLE = "disable";
public static final String COREONLY = "disable";
public static final String LOCALE = "locale";
public static final String DARK_THEME = "dark_theme";
public static final String ETAG_KEY = "ETag";

View File

@ -210,5 +210,6 @@
<string name="reboot_recovery">重啟到 Recovery</string>
<string name="reboot_bootloader">重啟到 Bootloader</string>
<string name="reboot_download">重啟到 Download</string>
<string name="android_o_not_support">不支援 Android 8.0+</string>
</resources>

View File

@ -180,6 +180,7 @@
<string name="global_summary">All root sessions use the global mount namespace</string>
<string name="requester_summary">Root sessions will inherit its requester\'s namespace</string>
<string name="isolate_summary">Each root session will have its own isolated namespace</string>
<string name="android_o_not_support">Does not support on Android 8.0+</string>
<!--Superuser-->
<string name="su_request_title">Superuser Request</string>