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 class Global {
public static final String MAGISK_DISABLE_FILE = "/cache/.disable_magisk";
public static class Info { public static class Info {
public static double magiskVersion; public static double magiskVersion;
public static String magiskVersionString = "(none)"; public static String magiskVersionString = "(none)";
@ -27,6 +29,7 @@ public class Global {
public static String bootBlock = null; public static String bootBlock = null;
public static boolean isSuClient = false; public static boolean isSuClient = false;
public static String suVersion = null; public static String suVersion = null;
public static boolean disabled = false;
} }
public static class Data { public static class Data {
public static ValueSortedMap<String, Repo> repoMap; public static ValueSortedMap<String, Repo> repoMap;
@ -64,28 +67,6 @@ public class Global {
public static int suNotificationType; 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) { public static void initSuConfigs(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
Configs.suRequestTimeout = Utils.getPrefsInt(prefs, "su_request_timeout", 10); 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"); List<String> ret = Shell.sh("getprop magisk.version");
if (!Utils.isValidShellResponse(ret)) { if (!Utils.isValidShellResponse(ret)) {
Info.magiskVersion = -1; Info.magiskVersion = -1;
@ -123,6 +104,9 @@ public class Global {
Info.magiskVersion = Double.POSITIVE_INFINITY; 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 @Override
protected void onDestroy() { protected void onDestroy() {
CallbackHandler.unRegister(Global.Events.reloadMainActivity, this); CallbackHandler.unRegister(Global.Events.reloadMainActivity, this);
// Let garbage collector remove them
Global.Data.clear();
super.onDestroy(); super.onDestroy();
} }

View File

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

View File

@ -1,9 +1,7 @@
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import com.topjohnwu.magisk.utils.Async; import com.topjohnwu.magisk.utils.Async;
@ -14,15 +12,17 @@ public class SplashActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(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 // 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.GetBootBlocks().exec();
new Async.CheckUpdates().exec(); new Async.CheckUpdates().exec();
new Async.LoadModules() { new Async.LoadModules() {
@ -33,10 +33,5 @@ public class SplashActivity extends AppCompatActivity {
} }
}.exec(); }.exec();
new Async.LoadApps(getPackageManager()).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) { if (Global.Info.magiskVersion < 0) {
magiskVersionText.setText(R.string.magisk_version_error); magiskVersionText.setText(R.string.magisk_version_error);
} else if (Global.Info.disabled) {
magiskVersionText.setText(getString(R.string.magisk_version_disable, Global.Info.magiskVersionString));
} else { } else {
magiskVersionText.setText(getString(R.string.magisk_version, Global.Info.magiskVersionString)); 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) { if (Global.Info.magiskVersion < 0) {
color = colorBad; color = colorBad;
image = R.drawable.ic_cancel; image = R.drawable.ic_cancel;
} else if (Global.Info.disabled) {
color = colorNeutral;
image = R.drawable.ic_cancel;
} }
magiskStatusContainer.setBackgroundColor(color); magiskStatusContainer.setBackgroundColor(color);
magiskVersionText.setTextColor(color); magiskVersionText.setTextColor(color);
magiskUpdateText.setTextColor(color); magiskUpdateText.setTextColor(color);
@ -231,7 +237,7 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis
.setPositiveButton(R.string.goto_install, (dialogInterface, i) -> { .setPositiveButton(R.string.goto_install, (dialogInterface, i) -> {
((MainActivity) getActivity()).navigationView.setCheckedItem(R.id.install); ((MainActivity) getActivity()).navigationView.setCheckedItem(R.id.install);
FragmentTransaction transaction = getFragmentManager().beginTransaction(); 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 { try {
transaction.replace(R.id.content_frame, new InstallFragment(), "install").commit(); transaction.replace(R.id.content_frame, new InstallFragment(), "install").commit();
} catch (IllegalStateException ignored) {} } catch (IllegalStateException ignored) {}

View File

@ -14,11 +14,22 @@ import com.topjohnwu.magisk.utils.Async;
public class BootReceiver extends BroadcastReceiver { public class BootReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); new Async.RootTask<Void, Void, Void>() {
Global.initSuAccess(); @Override
if (prefs.getBoolean("magiskhide", false)) { protected Void doInBackground(Void... params) {
Toast.makeText(context, R.string.start_magiskhide, Toast.LENGTH_SHORT).show(); Global.initSuAccess();
new Async.MagiskHide().enable(); 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.app.ProgressDialog;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.provider.OpenableColumns; import android.provider.OpenableColumns;
import android.widget.Toast; 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 MAGISK_HIDE_PATH = "/magisk/.core/magiskhide/";
public static final String TMP_FOLDER_PATH = "/dev/tmp"; 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> { public static class CheckUpdates extends NormalTask<Void, Void, Void> {
@Override @Override

View File

@ -41,7 +41,7 @@ public class Shell {
// Setup umask and PATH // Setup umask and PATH
su("umask 022"); 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"); List<String> ret = su("echo -BOC-", "id");

View File

@ -17,6 +17,7 @@
<!--Status Fragment--> <!--Status Fragment-->
<string name="magisk_version">Installed Magisk v%1$s</string> <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="magisk_version_error">Magisk not installed</string>
<string name="checking_for_updates">Checking for updates…</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_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_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_magiskhide_summary">Hide Magisk from various detections</string>
<string name="settings_busybox_title">Enable BusyBox</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> <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="pid">PID:\u0020</string>
<string name="target_uid">Target UID:\u0020</string> <string name="target_uid">Target UID:\u0020</string>
<string name="command">Command:\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> </resources>

View File

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