Add several options

This commit is contained in:
topjohnwu
2016-11-09 05:17:50 +08:00
parent e76dba0f84
commit 8a8f24f93e
16 changed files with 73 additions and 58 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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;

View File

@ -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) {

View File

@ -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) {

View File

@ -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));
}