mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-06-12 21:27:41 +02:00
Add several options
This commit is contained in:
@ -11,9 +11,11 @@ import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.topjohnwu.magisk.utils.Async;
|
||||
import com.topjohnwu.magisk.utils.Logger;
|
||||
import com.topjohnwu.magisk.utils.Shell;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
import butterknife.BindView;
|
||||
@ -80,18 +82,21 @@ public class SettingsActivity extends AppCompatActivity {
|
||||
themePreference = (ListPreference) findPreference("theme");
|
||||
CheckBoxPreference busyboxPreference = (CheckBoxPreference) findPreference("busybox");
|
||||
CheckBoxPreference magiskhidePreference = (CheckBoxPreference) findPreference("magiskhide");
|
||||
CheckBoxPreference hostsPreference = (CheckBoxPreference) findPreference("hosts");
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(getActivity()).registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
themePreference.setSummary(themePreference.getValue());
|
||||
|
||||
if (MagiskFragment.magiskVersion < 8) {
|
||||
magiskhidePreference.setEnabled(false);
|
||||
} else if (MagiskFragment.magiskVersion < 7) {
|
||||
if (MagiskFragment.magiskVersion < 9) {
|
||||
hostsPreference.setEnabled(false);
|
||||
busyboxPreference.setEnabled(false);
|
||||
} else if (MagiskFragment.magiskVersion < 8) {
|
||||
magiskhidePreference.setEnabled(false);
|
||||
} else {
|
||||
busyboxPreference.setEnabled(true);
|
||||
magiskhidePreference.setEnabled(true);
|
||||
hostsPreference.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,6 +115,7 @@ public class SettingsActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
Logger.dev("Settings: Prefs change " + key);
|
||||
boolean checked;
|
||||
|
||||
switch (key) {
|
||||
case "theme":
|
||||
@ -127,7 +133,7 @@ public class SettingsActivity extends AppCompatActivity {
|
||||
startActivity(intent);
|
||||
break;
|
||||
case "magiskhide":
|
||||
boolean checked = sharedPreferences.getBoolean("magiskhide", false);
|
||||
checked = sharedPreferences.getBoolean("magiskhide", false);
|
||||
if (checked) {
|
||||
new Async.RootTask<Void, Void, Void>() {
|
||||
@Override
|
||||
@ -148,7 +154,45 @@ public class SettingsActivity extends AppCompatActivity {
|
||||
break;
|
||||
case "busybox":
|
||||
checked = sharedPreferences.getBoolean("busybox", false);
|
||||
new Async.LinkBusyBox(checked).exec();
|
||||
if (checked) {
|
||||
new Async.RootTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
Utils.createFile("/magisk/.core/busybox/enable");
|
||||
return null;
|
||||
}
|
||||
}.exec();
|
||||
} else {
|
||||
new Async.RootTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
Utils.removeItem("/magisk/.core/busybox/enable");
|
||||
return null;
|
||||
}
|
||||
}.exec();
|
||||
}
|
||||
Toast.makeText(getActivity(), R.string.settings_reboot_toast, Toast.LENGTH_LONG).show();
|
||||
break;
|
||||
case "hosts":
|
||||
checked = sharedPreferences.getBoolean("hosts", false);
|
||||
if (checked) {
|
||||
new Async.RootTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
Shell.su("cp -af /system/etc/hosts /magisk/.core/hosts");
|
||||
return null;
|
||||
}
|
||||
}.exec();
|
||||
} else {
|
||||
new Async.RootTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
Shell.su("umount -l /system/etc/hosts", "rm -f /magisk/.core/hosts");
|
||||
return null;
|
||||
}
|
||||
}.exec();
|
||||
}
|
||||
Toast.makeText(getActivity(), R.string.settings_reboot_toast, Toast.LENGTH_LONG).show();
|
||||
break;
|
||||
case "developer_logging":
|
||||
Logger.devLog = sharedPreferences.getBoolean("developer_logging", false);
|
||||
|
@ -32,7 +32,8 @@ public class SplashActivity extends AppCompatActivity {
|
||||
.putBoolean("repo_done", false)
|
||||
.putBoolean("update_check_done", false)
|
||||
.putBoolean("magiskhide", Utils.itemExist(false, "/magisk/.core/magiskhide/enable"))
|
||||
.putBoolean("busybox", Utils.commandExists("unzip"))
|
||||
.putBoolean("busybox", Utils.commandExists("busybox"))
|
||||
.putBoolean("hosts", Utils.itemExist(false, "/magisk/.core/hosts"))
|
||||
.apply();
|
||||
|
||||
new Async.CheckUpdates(prefs).exec();
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.topjohnwu.magisk.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.DisplayMetrics;
|
||||
|
@ -350,28 +350,6 @@ public class Async {
|
||||
}
|
||||
}
|
||||
|
||||
public static class LinkBusyBox extends RootTask<Void, Void, Void> {
|
||||
|
||||
private boolean link;
|
||||
|
||||
public LinkBusyBox(boolean b) {
|
||||
link = b;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
if (link) {
|
||||
Shell.su(
|
||||
"rm -rf /magisk/.core/busybox",
|
||||
"ln -s /data/busybox /magisk/.core/busybox"
|
||||
);
|
||||
} else {
|
||||
Shell.su("rm -rf /magisk/.core/busybox");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MagiskHide extends RootTask<Object, Void, Void> {
|
||||
@Override
|
||||
protected Void doInBackground(Object... params) {
|
||||
|
@ -39,6 +39,9 @@ public class Shell {
|
||||
rootSTDOUT = new StreamGobbler(rootShell.getInputStream(), rootOutList, true);
|
||||
rootSTDOUT.start();
|
||||
|
||||
// Setup umask
|
||||
su("umask 022");
|
||||
|
||||
List<String> ret = su("echo -BOC-", "id");
|
||||
|
||||
if (ret == null) {
|
||||
|
@ -55,7 +55,8 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static boolean createFile(String path) {
|
||||
String command = "touch " + path + " 2>/dev/null; if [ -f " + path + " ]; then echo true; else echo false; fi";
|
||||
String folder = path.substring(0, path.lastIndexOf('/'));
|
||||
String command = "mkdir -p " + folder + " 2>/dev/null; touch " + path + " 2>/dev/null; if [ -f \"" + path + "\" ]; then echo true; else echo false; fi";
|
||||
return Shell.rootAccess() && Boolean.parseBoolean(Shell.su(command).get(0));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user