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

View File

@ -30,7 +30,6 @@
android:scaleType="centerCrop"/>
<LinearLayout
android:id="@+id/textLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignBottom="@+id/app_icon"
@ -63,7 +62,6 @@
</LinearLayout>
<LinearLayout
android:id="@+id/Linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"

View File

@ -19,7 +19,6 @@ android:orientation="vertical">
android:layout_height="match_parent"
android:clipToPadding="false"
android:dividerHeight="@dimen/card_divider_space"
android:paddingBottom="60dip"
app:layoutManager="android.support.v7.widget.LinearLayoutManager" />

View File

@ -12,7 +12,6 @@
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/llayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize"
@ -24,7 +23,6 @@
android:layout_height="match_parent"
android:clipToPadding="false"
android:dividerHeight="@dimen/card_divider_space"
android:paddingBottom="60dip"
app:layoutManager="android.support.v7.widget.LinearLayoutManager" />
<TextView

View File

@ -1,9 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group
android:id="@+id/main_items"
android:checkableBehavior="single">
<group android:checkableBehavior="single">
<item
android:id="@+id/magisk"
@ -32,9 +30,7 @@
android:title="@string/log"/>
</group>
<group
android:id="@+id/option_items"
android:checkableBehavior="none">
<group android:checkableBehavior="none">
<item
android:id="@+id/settings"

View File

@ -44,7 +44,6 @@
<string name="menuReload">erneut laden</string>
<string name="menuClearLog">Log jetzt löschen</string>
<string name="logs_cleared">Log erfolgreich gelöscht</string>
<string name="logs_clear_failed">Konnte Log nicht löschen:</string>
<string name="log_is_empty">Log ist leer</string>
<string name="logs_save_failed">Konnte Log nicht auf SD Karte speichern:</string>

View File

@ -44,7 +44,6 @@
<string name="menuReload">Ricarica</string>
<string name="menuClearLog">Cancella log</string>
<string name="logs_cleared">Log creato con successo</string>
<string name="logs_clear_failed">Impossibile cancellare il registro:</string>
<string name="log_is_empty">Il log è vuoto</string>
<string name="logs_save_failed">Impossibile scrivere il log sulla SD</string>

View File

@ -44,7 +44,6 @@
<string name="menuReload">Herladen</string>
<string name="menuClearLog">Maak log leeg</string>
<string name="logs_cleared">Log succesvol geleegd</string>
<string name="logs_clear_failed">Kon de log niet legen.</string>
<string name="log_is_empty">Log is leeg</string>
<string name="logs_save_failed">Kon niet naar SD-kaart schrijven:</string>

View File

@ -40,7 +40,6 @@
<string name="menuReload">Recarregar</string>
<string name="menuClearLog">Limpar registro agora</string>
<string name="logs_cleared">Registro limpado com sucesso</string>
<string name="logs_clear_failed">Não foi possível limpar o registro:</string>
<string name="log_is_empty">Registro está vazio</string>
<string name="logs_save_failed">Não foi possível gravar o registro para o cartão SD:</string>

View File

@ -6,7 +6,7 @@
<!--Welcome Activity-->
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="magiskhide">MagiskHide</string>
<string name="magiskhide">Magisk Hide</string>
<string name="modules">Modules</string>
<string name="downloads">Downloads</string>
<string name="log">Log</string>
@ -45,7 +45,6 @@
<string name="menuReload">Reload</string>
<string name="menuClearLog">Clear log now</string>
<string name="logs_cleared">Log successfully cleared</string>
<string name="logs_clear_failed">Could not clear the log:</string>
<string name="log_is_empty">Log is empty</string>
<string name="logs_save_failed">Could not write log to SD card:</string>
@ -87,27 +86,24 @@
<string name="file_url">https://raw.githubusercontent.com/Magisk-Modules-Repo/%1$s/master/%2$s</string>
<string name="zip_url">https://github.com/Magisk-Modules-Repo/%1$s/archive/master.zip</string>
<!--Settings Fragment -->
<!--Settings Activity -->
<string name="settings_general_category">General</string>
<string name="settings_theme_title">Theme</string>
<string name="settings_theme_summary">Select a theme</string>
<string name="settings_magiskhide_title">Enable Magisk Hide</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">Make Magisk\'s built-in BusyBox be visible in PATH</string>
<string name="settings_busybox_summary">Bind mount Magisk\'s built-in busybox to xbin</string>
<string name="settings_hosts_title">Enable systemless hosts</string>
<string name="settings_hosts_summary">Systemless support for Adblock apps</string>
<string name="settings_development_category">Development</string>
<string name="settings_developer_logging_title">Enable advanced debug logging</string>
<string name="settings_developer_logging_summary">Check this to enable more verbose logging.</string>
<string name="settings_shell_logging_title">Enable shell command debug logging</string>
<string name="settings_shell_logging_summary">Check this to enable logging all shell commands and output</string>
<string name="settings_magiskhide_title">Enable Magisk Hide</string>
<string name="settings_magiskhide_summary">Reboot to apply settings</string>
<!-- Strings related to Settings -->
<!-- Example General settings -->
<!-- Example settings for Data & Sync -->
<!-- Example settings for Notifications -->
<string name="settings_reboot_toast">Reboot to apply settings</string>
</resources>

View File

@ -29,6 +29,12 @@
android:title="@string/settings_busybox_title"
android:summary="@string/settings_busybox_summary" />
<CheckBoxPreference
android:key="hosts"
android:defaultValue="false"
android:title="@string/settings_hosts_title"
android:summary="@string/settings_hosts_summary" />
</PreferenceCategory>
<PreferenceCategory