Update to the latest settings

This commit is contained in:
topjohnwu 2017-02-05 04:40:52 +08:00
parent 43b7ef8110
commit 7239c2e31a
10 changed files with 116 additions and 73 deletions

View File

@ -17,6 +17,8 @@ import java.util.List;
public class Global {
public static final String MAGISK_DISABLE_FILE = "/cache/.disable_magisk";
public static class Info {
public static double magiskVersion;
public static String magiskVersionString = "(none)";
@ -27,6 +29,7 @@ public class Global {
public static String bootBlock = null;
public static boolean isSuClient = false;
public static String suVersion = null;
public static boolean disabled = false;
}
public static class Data {
public static ValueSortedMap<String, Repo> repoMap;
@ -64,28 +67,6 @@ public class Global {
public static int suNotificationType;
}
public static void init(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
Configs.isDarkTheme = prefs.getBoolean("dark_theme", false);
Configs.devLogging = prefs.getBoolean("developer_logging", false);
Configs.shellLogging = prefs.getBoolean("shell_logging", false);
Configs.magiskHide = prefs.getBoolean("magiskhide", false);
updateMagiskInfo();
initSuAccess();
initSuConfigs(context);
// Initialize prefs
prefs.edit()
.putBoolean("dark_theme", Configs.isDarkTheme)
.putBoolean("magiskhide", Configs.magiskHide)
.putBoolean("busybox", Utils.commandExists("busybox"))
.putBoolean("hosts", Utils.itemExist(false, "/magisk/.core/hosts"))
.putString("su_request_timeout", String.valueOf(Configs.suRequestTimeout))
.putString("su_auto_response", String.valueOf(Configs.suResponseType))
.putString("su_notification", String.valueOf(Configs.suNotificationType))
.putString("su_access", String.valueOf(Configs.suAccessState))
.apply();
}
public static void initSuConfigs(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
Configs.suRequestTimeout = Utils.getPrefsInt(prefs, "su_request_timeout", 10);
@ -110,7 +91,7 @@ public class Global {
}
}
static void updateMagiskInfo() {
public static void updateMagiskInfo() {
List<String> ret = Shell.sh("getprop magisk.version");
if (!Utils.isValidShellResponse(ret)) {
Info.magiskVersion = -1;
@ -123,6 +104,9 @@ public class Global {
Info.magiskVersion = Double.POSITIVE_INFINITY;
}
}
ret = Shell.sh("getprop ro.magisk.disable");
if (Utils.isValidShellResponse(ret))
Info.disabled = Integer.parseInt(ret.get(0)) != 0;
}
}

View File

@ -101,8 +101,6 @@ public class MainActivity extends AppCompatActivity
@Override
protected void onDestroy() {
CallbackHandler.unRegister(Global.Events.reloadMainActivity, this);
// Let garbage collector remove them
Global.Data.clear();
super.onDestroy();
}

View File

@ -2,7 +2,6 @@ package com.topjohnwu.magisk;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment;
@ -21,9 +20,6 @@ import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils;
import java.io.File;
import java.io.IOException;
import butterknife.BindView;
import butterknife.ButterKnife;
@ -88,6 +84,10 @@ public class SettingsActivity extends AppCompatActivity {
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
prefScreen = getPreferenceScreen();
SwitchPreference busybox = (SwitchPreference) findPreference("busybox");
SwitchPreference magiskHide = (SwitchPreference) findPreference("magiskhide");
SwitchPreference hosts = (SwitchPreference) findPreference("hosts");
PreferenceCategory magiskCategory = (PreferenceCategory) findPreference("magisk");
PreferenceCategory suCategory = (PreferenceCategory) findPreference("superuser");
@ -111,6 +111,11 @@ public class SettingsActivity extends AppCompatActivity {
prefScreen.removePreference(suCategory);
if (Global.Info.magiskVersion < 11)
prefScreen.removePreference(magiskCategory);
if (Global.Info.disabled) {
busybox.setEnabled(false);
magiskHide.setEnabled(false);
hosts.setEnabled(false);
}
}
}
@ -142,31 +147,38 @@ public class SettingsActivity extends AppCompatActivity {
break;
case "disable":
enabled = prefs.getBoolean("disable", false);
File disable = new File(getActivity().getFilesDir() + "/disable");
if (enabled)
try {
disable.createNewFile();
} catch (IOException e) {
e.printStackTrace();
prefs.edit().putBoolean("disable", false).apply();
new Async.RootTask<Void, Void, Void>() {
private boolean enable = enabled;
@Override
protected Void doInBackground(Void... voids) {
if (enable) {
Utils.createFile(Global.MAGISK_DISABLE_FILE);
} else {
Utils.removeItem(Global.MAGISK_DISABLE_FILE);
}
return null;
}
else
disable.delete();
}.exec();
Toast.makeText(getActivity(), R.string.settings_reboot_toast, Toast.LENGTH_LONG).show();
break;
case "busybox":
enabled = prefs.getBoolean("busybox", false);
File busybox = new File(getActivity().getFilesDir() + "/busybox");
if (enabled)
try {
busybox.createNewFile();
} catch (IOException e) {
e.printStackTrace();
prefs.edit().putBoolean("busybox", false).apply();
new Async.RootTask<Void, Void, Void>() {
private boolean enable = enabled;
@Override
protected Void doInBackground(Void... voids) {
if (enable) {
Shell.su(
"setprop persist.magisk.busybox 1",
"sh /sbin/magic_mask.sh mount_busybox");
} else {
Shell.su(
"setprop persist.magisk.busybox 0",
"umount /system/xbin");
}
return null;
}
else
busybox.delete();
Toast.makeText(getActivity(), R.string.settings_reboot_toast, Toast.LENGTH_LONG).show();
}.exec();
break;
case "magiskhide":
enabled = prefs.getBoolean("magiskhide", false);

View File

@ -1,9 +1,7 @@
package com.topjohnwu.magisk;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import com.topjohnwu.magisk.utils.Async;
@ -14,15 +12,17 @@ public class SplashActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Global.init(getApplicationContext());
if (Global.Configs.isDarkTheme) {
setTheme(R.style.AppTheme_dh);
}
// Start all async tasks
new Async.InitConfigs(getApplicationContext()){
@Override
protected void onPostExecute(Void v) {
// Start main activity only after configs are loaded
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
}
}.exec();
new Async.GetBootBlocks().exec();
new Async.CheckUpdates().exec();
new Async.LoadModules() {
@ -33,10 +33,5 @@ public class SplashActivity extends AppCompatActivity {
}
}.exec();
new Async.LoadApps(getPackageManager()).exec();
// Start main activity
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
}
}

View File

@ -163,6 +163,8 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis
if (Global.Info.magiskVersion < 0) {
magiskVersionText.setText(R.string.magisk_version_error);
} else if (Global.Info.disabled) {
magiskVersionText.setText(getString(R.string.magisk_version_disable, Global.Info.magiskVersionString));
} else {
magiskVersionText.setText(getString(R.string.magisk_version, Global.Info.magiskVersionString));
}
@ -215,7 +217,11 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis
if (Global.Info.magiskVersion < 0) {
color = colorBad;
image = R.drawable.ic_cancel;
} else if (Global.Info.disabled) {
color = colorNeutral;
image = R.drawable.ic_cancel;
}
magiskStatusContainer.setBackgroundColor(color);
magiskVersionText.setTextColor(color);
magiskUpdateText.setTextColor(color);
@ -231,7 +237,7 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis
.setPositiveButton(R.string.goto_install, (dialogInterface, i) -> {
((MainActivity) getActivity()).navigationView.setCheckedItem(R.id.install);
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
transaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
try {
transaction.replace(R.id.content_frame, new InstallFragment(), "install").commit();
} catch (IllegalStateException ignored) {}

View File

@ -14,11 +14,22 @@ import com.topjohnwu.magisk.utils.Async;
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
Global.initSuAccess();
if (prefs.getBoolean("magiskhide", false)) {
Toast.makeText(context, R.string.start_magiskhide, Toast.LENGTH_SHORT).show();
new Async.MagiskHide().enable();
}
new Async.RootTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
Global.initSuAccess();
Global.updateMagiskInfo();
return null;
}
@Override
protected void onPostExecute(Void v) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (prefs.getBoolean("magiskhide", false) && !Global.Info.disabled && Global.Info.magiskVersion >= 11) {
Toast.makeText(context, R.string.start_magiskhide, Toast.LENGTH_SHORT).show();
new Async.MagiskHide().enable();
}
}
}.exec();
}
}

View File

@ -2,11 +2,13 @@ package com.topjohnwu.magisk.utils;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.provider.OpenableColumns;
import android.widget.Toast;
@ -49,6 +51,40 @@ public class Async {
public static final String MAGISK_HIDE_PATH = "/magisk/.core/magiskhide/";
public static final String TMP_FOLDER_PATH = "/dev/tmp";
public static class InitConfigs extends RootTask<Void, Void, Void> {
Context mContext;
public InitConfigs(Context context) {
mContext = context;
}
@Override
protected Void doInBackground(Void... params) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
Global.Configs.isDarkTheme = prefs.getBoolean("dark_theme", false);
Global.Configs.devLogging = prefs.getBoolean("developer_logging", false);
Global.Configs.shellLogging = prefs.getBoolean("shell_logging", false);
Global.Configs.magiskHide = prefs.getBoolean("magiskhide", false);
Global.updateMagiskInfo();
Global.initSuAccess();
Global.initSuConfigs(mContext);
// Initialize prefs
prefs.edit()
.putBoolean("dark_theme", Global.Configs.isDarkTheme)
.putBoolean("magiskhide", Global.Configs.magiskHide)
.putBoolean("busybox", Utils.commandExists("busybox"))
.putBoolean("hosts", Utils.itemExist(false, "/magisk/.core/hosts"))
.putBoolean("disable", Utils.itemExist(Global.MAGISK_DISABLE_FILE))
.putString("su_request_timeout", String.valueOf(Global.Configs.suRequestTimeout))
.putString("su_auto_response", String.valueOf(Global.Configs.suResponseType))
.putString("su_notification", String.valueOf(Global.Configs.suNotificationType))
.putString("su_access", String.valueOf(Global.Configs.suAccessState))
.apply();
return null;
}
}
public static class CheckUpdates extends NormalTask<Void, Void, Void> {
@Override

View File

@ -41,7 +41,7 @@ public class Shell {
// Setup umask and PATH
su("umask 022");
su("PATH=/data/busybox:$PATH");
su("PATH=`[ -e /dev/busybox ] && echo /dev/busybox || echo /data/busybox`:$PATH");
List<String> ret = su("echo -BOC-", "id");

View File

@ -17,6 +17,7 @@
<!--Status Fragment-->
<string name="magisk_version">Installed Magisk v%1$s</string>
<string name="magisk_version_disable">Magisk v%1$s disabled</string>
<string name="magisk_version_error">Magisk not installed</string>
<string name="checking_for_updates">Checking for updates…</string>
@ -127,6 +128,8 @@
<string name="settings_clear_cache_title">Clear Repo Cache</string>
<string name="settings_clear_cache_summary">Clear the cached information for online repos, forces the app to refresh online</string>
<string name="settings_disable_title">Disable Magisk</string>
<string name="settings_disable_summary">Everything will be disabled except root (MagiskSU)</string>
<string name="settings_magiskhide_summary">Hide Magisk from various detections</string>
<string name="settings_busybox_title">Enable BusyBox</string>
<string name="settings_busybox_summary">Bind mount Magisk\'s built-in busybox to xbin\nRequires reboot</string>
@ -185,7 +188,5 @@
<string name="pid">PID:\u0020</string>
<string name="target_uid">Target UID:\u0020</string>
<string name="command">Command:\u0020</string>
<string name="settings_disable_title">Disable Magic Mount</string>
<string name="settings_disable_summary">Disable Magic Mount, which will prevent all modules to work</string>
</resources>

View File

@ -26,7 +26,7 @@
android:title="@string/settings_disable_title"
android:summary="@string/settings_disable_summary" />
<CheckBoxPreference
<SwitchPreference
android:key="busybox"
android:defaultValue="false"
android:title="@string/settings_busybox_title"