Handle MagiskHide at boot

This commit is contained in:
topjohnwu 2017-02-01 23:54:32 +08:00
parent 0efb4da0ee
commit 99ef0b8cb4
17 changed files with 49 additions and 73 deletions

View File

@ -56,6 +56,7 @@ public class Global {
public static boolean isDarkTheme; public static boolean isDarkTheme;
public static boolean shellLogging; public static boolean shellLogging;
public static boolean devLogging; public static boolean devLogging;
public static boolean magiskHide;
public static int suRequestTimeout; public static int suRequestTimeout;
public static int suLogTimeout = 14; public static int suLogTimeout = 14;
public static int suAccessState; public static int suAccessState;
@ -68,13 +69,14 @@ public class Global {
Configs.isDarkTheme = prefs.getBoolean("dark_theme", false); Configs.isDarkTheme = prefs.getBoolean("dark_theme", false);
Configs.devLogging = prefs.getBoolean("developer_logging", false); Configs.devLogging = prefs.getBoolean("developer_logging", false);
Configs.shellLogging = prefs.getBoolean("shell_logging", false); Configs.shellLogging = prefs.getBoolean("shell_logging", false);
Configs.magiskHide = prefs.getBoolean("magiskhide", false);
updateMagiskInfo(); updateMagiskInfo();
initSuAccess(); initSuAccess();
initSuConfigs(context); initSuConfigs(context);
// Initialize prefs // Initialize prefs
prefs.edit() prefs.edit()
.putBoolean("dark_theme", Configs.isDarkTheme) .putBoolean("dark_theme", Configs.isDarkTheme)
.putBoolean("magiskhide", Utils.itemExist(false, "/magisk/.core/magiskhide/enable")) .putBoolean("magiskhide", Configs.magiskHide)
.putBoolean("busybox", Utils.commandExists("busybox")) .putBoolean("busybox", Utils.commandExists("busybox"))
.putBoolean("hosts", Utils.itemExist(false, "/magisk/.core/hosts")) .putBoolean("hosts", Utils.itemExist(false, "/magisk/.core/hosts"))
.putString("su_request_timeout", String.valueOf(Configs.suRequestTimeout)) .putString("su_request_timeout", String.valueOf(Configs.suRequestTimeout))

View File

@ -95,10 +95,6 @@ public class SettingsActivity extends AppCompatActivity {
setSummary(); setSummary();
CheckBoxPreference busyboxPreference = (CheckBoxPreference) findPreference("busybox");
CheckBoxPreference magiskhidePreference = (CheckBoxPreference) findPreference("magiskhide");
SwitchPreference hostsPreference = (SwitchPreference) findPreference("hosts");
findPreference("clear").setOnPreferenceClickListener((pref) -> { findPreference("clear").setOnPreferenceClickListener((pref) -> {
ModuleHelper.clearRepoCache(getActivity()); ModuleHelper.clearRepoCache(getActivity());
return true; return true;
@ -108,16 +104,10 @@ public class SettingsActivity extends AppCompatActivity {
prefScreen.removePreference(magiskCategory); prefScreen.removePreference(magiskCategory);
prefScreen.removePreference(suCategory); prefScreen.removePreference(suCategory);
} else { } else {
if (!Global.Info.isSuClient) { if (!Global.Info.isSuClient)
prefScreen.removePreference(suCategory); prefScreen.removePreference(suCategory);
} if (Global.Info.magiskVersion < 11)
if (Global.Info.magiskVersion < 9) { prefScreen.removePreference(magiskCategory);
hostsPreference.setEnabled(false);
busyboxPreference.setEnabled(false);
}
if (Global.Info.magiskVersion < 8) {
magiskhidePreference.setEnabled(false);
}
} }
} }
@ -149,20 +139,10 @@ public class SettingsActivity extends AppCompatActivity {
break; break;
case "magiskhide": case "magiskhide":
enabled = prefs.getBoolean("magiskhide", false); enabled = prefs.getBoolean("magiskhide", false);
new Async.RootTask<Void, Void, Void>() { if (enabled)
private boolean enable = enabled; new Async.MagiskHide().enable();
@Override else
protected Void doInBackground(Void... params) { new Async.MagiskHide().disable();
if (enable) {
Utils.createFile("/magisk/.core/magiskhide/enable");
} else {
Utils.removeItem("/magisk/.core/magiskhide/enable");
}
return null;
}
}.exec();
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);
@ -170,11 +150,10 @@ public class SettingsActivity extends AppCompatActivity {
private boolean enable = enabled; private boolean enable = enabled;
@Override @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) {
if (enable) { if (enable)
Utils.createFile("/magisk/.core/busybox/enable"); Utils.createFile("/magisk/.core/busybox/enable");
} else { else
Utils.removeItem("/magisk/.core/busybox/enable"); Utils.removeItem("/magisk/.core/busybox/enable");
}
return null; return null;
} }
}.exec(); }.exec();

View File

@ -76,8 +76,11 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
if (SNLIST.contains(info.packageName)) { if (SNLIST.contains(info.packageName)) {
holder.checkBox.setChecked(true); holder.checkBox.setChecked(true);
holder.checkBox.setEnabled(false); holder.checkBox.setEnabled(false);
holder.itemView.setOnClickListener(v -> holder.itemView.setOnClickListener(v -> {
Snackbar.make(holder.itemView, R.string.safetyNet_hide_notice, Snackbar.LENGTH_LONG).show()); Snackbar snackbar = Snackbar.make(holder.itemView, R.string.safetyNet_hide_notice, Snackbar.LENGTH_LONG);
((TextView) snackbar.getView().findViewById(android.support.design.R.id.snackbar_text)).setMaxLines(2);
snackbar.show();
});
} else { } else {
holder.checkBox.setEnabled(true); holder.checkBox.setEnabled(true);
holder.checkBox.setChecked(mHideList.contains(info.packageName)); holder.checkBox.setChecked(mHideList.contains(info.packageName));

View File

@ -3,12 +3,22 @@ package com.topjohnwu.magisk.receivers;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.widget.Toast;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.R;
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);
Global.initSuAccess(); Global.initSuAccess();
if (prefs.getBoolean("magiskhide", false)) {
Toast.makeText(context, R.string.start_magiskhide, Toast.LENGTH_SHORT).show();
new Async.MagiskHide().enable();
}
} }
} }

View File

@ -12,13 +12,13 @@ public class RequestActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Global.initSuConfigs(this);
Intent intent = getIntent(); Intent intent = getIntent();
if (intent == null) { if (intent == null) {
finish(); finish();
return; return;
} }
Global.initSuConfigs(this);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClass(this, SuRequestActivity.class); intent.setClass(this, SuRequestActivity.class);
startActivity(intent); startActivity(intent);

View File

@ -293,18 +293,25 @@ public class Async {
public static class MagiskHide extends RootTask<Object, Void, Void> { public static class MagiskHide extends RootTask<Object, Void, Void> {
@Override @Override
protected Void doInBackground(Object... params) { protected Void doInBackground(Object... params) {
boolean add = (boolean) params[0]; String command = (String) params[0];
String packageName = (String) params[1]; Shell.su(MAGISK_HIDE_PATH + command);
Shell.su(MAGISK_HIDE_PATH + (add ? "add " : "rm ") + packageName);
return null; return null;
} }
public void add(CharSequence packageName) { public void add(CharSequence packageName) {
exec(true, packageName); exec("add " + packageName);
} }
public void rm(CharSequence packageName) { public void rm(CharSequence packageName) {
exec(false, packageName); exec("rm " + packageName);
}
public void enable() {
exec("enable");
}
public void disable() {
exec("disable");
} }
} }

View File

@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M2.01,21L23,12 2.01,3 2,10l15,2 -15,2z"/>
</vector>

View File

@ -39,7 +39,6 @@
<!--Log Fragment--> <!--Log Fragment-->
<string name="menuSaveToSd">حفظ إلى بطاقة ذاكرة SD</string> <string name="menuSaveToSd">حفظ إلى بطاقة ذاكرة SD</string>
<string name="menuSend">إرسال</string>
<string name="menuReload">إعادة تحميل</string> <string name="menuReload">إعادة تحميل</string>
<string name="menuClearLog">حذف السجل الآن</string> <string name="menuClearLog">حذف السجل الآن</string>
<string name="logs_cleared">تم حذف السجل بنجاح</string> <string name="logs_cleared">تم حذف السجل بنجاح</string>
@ -86,7 +85,6 @@
<string name="settings_dark_theme_title">السمة</string> <string name="settings_dark_theme_title">السمة</string>
<string name="settings_dark_theme_summary">أختر سمة</string> <string name="settings_dark_theme_summary">أختر سمة</string>
<string name="settings_magiskhide_title">تمكين إخفاء Magisk</string>
<string name="settings_magiskhide_summary">إخفاء Magisk من مختلف حالات الإكتشاف</string> <string name="settings_magiskhide_summary">إخفاء Magisk من مختلف حالات الإكتشاف</string>
<string name="settings_busybox_title">تمكين BusyBox</string> <string name="settings_busybox_title">تمكين BusyBox</string>
<string name="settings_busybox_summary">ربط تحميل Magisk\'s المدمج في busybox إلى xbin</string> <string name="settings_busybox_summary">ربط تحميل Magisk\'s المدمج في busybox إلى xbin</string>

View File

@ -65,7 +65,6 @@
<!--Log Fragment--> <!--Log Fragment-->
<string name="menuSaveToSd">Auf SD-Karte speichern</string> <string name="menuSaveToSd">Auf SD-Karte speichern</string>
<string name="menuSend">Senden</string>
<string name="menuReload">Erneut laden</string> <string name="menuReload">Erneut laden</string>
<string name="menuClearLog">Log löschen</string> <string name="menuClearLog">Log löschen</string>
<string name="logs_cleared">Log erfolgreich gelöscht</string> <string name="logs_cleared">Log erfolgreich gelöscht</string>
@ -126,7 +125,6 @@
<string name="settings_clear_cache_title">Repo-Cache löschen</string> <string name="settings_clear_cache_title">Repo-Cache löschen</string>
<string name="settings_clear_cache_summary">Löscht die zwischengespeicherten Informtionen der Online-Repos. Erzwingt eine Aktualisierung</string> <string name="settings_clear_cache_summary">Löscht die zwischengespeicherten Informtionen der Online-Repos. Erzwingt eine Aktualisierung</string>
<string name="settings_magiskhide_title">Magisk Hide aktivieren</string>
<string name="settings_magiskhide_summary">Versteckt Magisk vor diversen Entdeckungsmethoden\nErfordert einen Neustart</string> <string name="settings_magiskhide_summary">Versteckt Magisk vor diversen Entdeckungsmethoden\nErfordert einen Neustart</string>
<string name="settings_busybox_title">BusyBox aktivieren</string> <string name="settings_busybox_title">BusyBox aktivieren</string>
<string name="settings_busybox_summary">Magisk\'s integriertes BusyBox nach xbin mounten\nErfordert einen Neustart</string> <string name="settings_busybox_summary">Magisk\'s integriertes BusyBox nach xbin mounten\nErfordert einen Neustart</string>

View File

@ -39,7 +39,6 @@
<!--Log Fragment--> <!--Log Fragment-->
<string name="menuSaveToSd">Salvar a SD</string> <string name="menuSaveToSd">Salvar a SD</string>
<string name="menuSend">Enviar</string>
<string name="menuReload">Recargar</string> <string name="menuReload">Recargar</string>
<string name="menuClearLog">Vaciar Log ahora</string> <string name="menuClearLog">Vaciar Log ahora</string>
<string name="logs_cleared">Log vaciado correctamente</string> <string name="logs_cleared">Log vaciado correctamente</string>
@ -83,7 +82,6 @@
<string name="settings_dark_theme_title">Tema</string> <string name="settings_dark_theme_title">Tema</string>
<string name="settings_dark_theme_summary">Selecciona un tema</string> <string name="settings_dark_theme_summary">Selecciona un tema</string>
<string name="settings_magiskhide_title">Habilitar Magisk Hide</string>
<string name="settings_magiskhide_summary">Ocultar Magisk de varias detecciones</string> <string name="settings_magiskhide_summary">Ocultar Magisk de varias detecciones</string>
<string name="settings_busybox_title">Habilitar BusyBox</string> <string name="settings_busybox_title">Habilitar BusyBox</string>
<string name="settings_busybox_summary">Montar el busybox interno de Magisk en xbin</string> <string name="settings_busybox_summary">Montar el busybox interno de Magisk en xbin</string>

View File

@ -37,7 +37,6 @@
<!--Log Fragment--> <!--Log Fragment-->
<string name="menuSaveToSd">Salva nella SD</string> <string name="menuSaveToSd">Salva nella SD</string>
<string name="menuSend">Invia</string>
<string name="menuReload">Ricarica</string> <string name="menuReload">Ricarica</string>
<string name="menuClearLog">Cancella log</string> <string name="menuClearLog">Cancella log</string>
<string name="logs_cleared">Log creato con successo</string> <string name="logs_cleared">Log creato con successo</string>

View File

@ -37,7 +37,6 @@
<!--Log Fragment--> <!--Log Fragment-->
<string name="menuSaveToSd">Opslaan op SD-kaart</string> <string name="menuSaveToSd">Opslaan op SD-kaart</string>
<string name="menuSend">Verzenden</string>
<string name="menuReload">Herladen</string> <string name="menuReload">Herladen</string>
<string name="menuClearLog">Maak log leeg</string> <string name="menuClearLog">Maak log leeg</string>
<string name="logs_cleared">Log succesvol geleegd</string> <string name="logs_cleared">Log succesvol geleegd</string>
@ -89,7 +88,6 @@
<string name="settings_developer_logging_summary">Schakel dit in voor uitgebreidere logging.</string> <string name="settings_developer_logging_summary">Schakel dit in voor uitgebreidere logging.</string>
<string name="settings_shell_logging_title">Shell command debug loggin</string> <string name="settings_shell_logging_title">Shell command debug loggin</string>
<string name="settings_shell_logging_summary">Schakel dit in om alle shell commands en output te loggen</string> <string name="settings_shell_logging_summary">Schakel dit in om alle shell commands en output te loggen</string>
<string name="settings_magiskhide_title">Magisk verbergen</string>
<string name="settings_magiskhide_summary">Reboot om de instellingen toe te passen</string> <string name="settings_magiskhide_summary">Reboot om de instellingen toe te passen</string>
<!-- Strings related to Settings --> <!-- Strings related to Settings -->

View File

@ -65,7 +65,6 @@
<!--Log Fragment--> <!--Log Fragment-->
<string name="menuSaveToSd">Zapisz na SD</string> <string name="menuSaveToSd">Zapisz na SD</string>
<string name="menuSend">Wyślij</string>
<string name="menuReload">Załaduj ponownie</string> <string name="menuReload">Załaduj ponownie</string>
<string name="menuClearLog">Wyczyść Log</string> <string name="menuClearLog">Wyczyść Log</string>
<string name="logs_cleared">Log wyczyszczony</string> <string name="logs_cleared">Log wyczyszczony</string>
@ -126,7 +125,6 @@
<string name="settings_clear_cache_title">Wyczyść Cache Repozytorium</string> <string name="settings_clear_cache_title">Wyczyść Cache Repozytorium</string>
<string name="settings_clear_cache_summary">Wyczyść cache dla repozytorium, wymusza odświeżenie online przez aplikację</string> <string name="settings_clear_cache_summary">Wyczyść cache dla repozytorium, wymusza odświeżenie online przez aplikację</string>
<string name="settings_magiskhide_title">Włącz Magisk Hide</string>
<string name="settings_magiskhide_summary">Włącz Hide Magisk dla wykrytych aplikacji</string> <string name="settings_magiskhide_summary">Włącz Hide Magisk dla wykrytych aplikacji</string>
<string name="settings_busybox_title">Włącz BusyBox</string> <string name="settings_busybox_title">Włącz BusyBox</string>
<string name="settings_busybox_summary">Bind mount Magisk\'s built-in busybox to xbin</string> <string name="settings_busybox_summary">Bind mount Magisk\'s built-in busybox to xbin</string>

View File

@ -59,7 +59,6 @@
<!--Log Fragment--> <!--Log Fragment-->
<string name="menuSaveToSd">Salvar no SD</string> <string name="menuSaveToSd">Salvar no SD</string>
<string name="menuSend">Enviar</string>
<string name="menuReload">Recarregar</string> <string name="menuReload">Recarregar</string>
<string name="menuClearLog">Limpar registro agora</string> <string name="menuClearLog">Limpar registro agora</string>
<string name="logs_cleared">Registro limpado com sucesso</string> <string name="logs_cleared">Registro limpado com sucesso</string>
@ -110,7 +109,6 @@
<string name="settings_dark_theme_title">Tema</string> <string name="settings_dark_theme_title">Tema</string>
<string name="settings_dark_theme_summary">Escolha um tema</string> <string name="settings_dark_theme_summary">Escolha um tema</string>
<string name="settings_magiskhide_title">Ativar Magisk Hide</string>
<string name="settings_magiskhide_summary">Ocultar Magisk de várias detecções</string> <string name="settings_magiskhide_summary">Ocultar Magisk de várias detecções</string>
<string name="settings_busybox_title">Ativar BusyBox</string> <string name="settings_busybox_title">Ativar BusyBox</string>
<string name="settings_busybox_summary">Monta a busybox interna do Magisk\'s para xbin</string> <string name="settings_busybox_summary">Monta a busybox interna do Magisk\'s para xbin</string>

View File

@ -57,7 +57,6 @@
<!--Log Fragment--> <!--Log Fragment-->
<string name="menuSaveToSd">保存到 SD 卡</string> <string name="menuSaveToSd">保存到 SD 卡</string>
<string name="menuSend">发送</string>
<string name="menuReload">重载</string> <string name="menuReload">重载</string>
<string name="menuClearLog">清除日志</string> <string name="menuClearLog">清除日志</string>
<string name="logs_cleared">日志已成功清除</string> <string name="logs_cleared">日志已成功清除</string>
@ -107,7 +106,6 @@
<string name="settings_dark_theme_title">主题</string> <string name="settings_dark_theme_title">主题</string>
<string name="settings_dark_theme_summary">选择一个主题</string> <string name="settings_dark_theme_summary">选择一个主题</string>
<string name="settings_magiskhide_title">启用 Magisk 隐藏</string>
<string name="settings_magiskhide_summary">隐藏 Magisk 使其不被多种方法检测到</string> <string name="settings_magiskhide_summary">隐藏 Magisk 使其不被多种方法检测到</string>
<string name="settings_busybox_title">启用 BusyBox</string> <string name="settings_busybox_title">启用 BusyBox</string>
<string name="settings_busybox_summary">将 Magisk 内置的 Busybox 挂载到 xbin</string> <string name="settings_busybox_summary">将 Magisk 内置的 Busybox 挂载到 xbin</string>

View File

@ -65,7 +65,6 @@
<!--Log Fragment--> <!--Log Fragment-->
<string name="menuSaveToSd">Save to SD</string> <string name="menuSaveToSd">Save to SD</string>
<string name="menuSend">Send</string>
<string name="menuReload">Reload</string> <string name="menuReload">Reload</string>
<string name="menuClearLog">Clear log now</string> <string name="menuClearLog">Clear log now</string>
<string name="logs_cleared">Log successfully cleared</string> <string name="logs_cleared">Log successfully cleared</string>
@ -114,6 +113,7 @@
<string name="check_release_notes">Check release notes</string> <string name="check_release_notes">Check release notes</string>
<string name="repo_cache_cleared">Repo cache cleared</string> <string name="repo_cache_cleared">Repo cache cleared</string>
<string name="safetyNet_hide_notice">This app uses SafetyNet\nAlready handled by MagiskHide by default</string> <string name="safetyNet_hide_notice">This app uses SafetyNet\nAlready handled by MagiskHide by default</string>
<string name="start_magiskhide">Starting MagiskHide …</string>
<!--URL Templates--> <!--URL Templates-->
<string name="url_main" translatable="false">https://api.github.com/orgs/Magisk-Modules-Repo/repos</string> <string name="url_main" translatable="false">https://api.github.com/orgs/Magisk-Modules-Repo/repos</string>
@ -127,8 +127,7 @@
<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_magiskhide_title">Enable Magisk Hide</string> <string name="settings_magiskhide_summary">Hide Magisk from various detections</string>
<string name="settings_magiskhide_summary">Hide Magisk from various detections\nRequires reboot</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>
<string name="settings_hosts_title">Systemless hosts</string> <string name="settings_hosts_title">Systemless hosts</string>

View File

@ -21,18 +21,18 @@
android:key="magisk" android:key="magisk"
android:title="@string/magisk"> android:title="@string/magisk">
<CheckBoxPreference
android:key="magiskhide"
android:defaultValue="false"
android:title="@string/settings_magiskhide_title"
android:summary="@string/settings_magiskhide_summary" />
<CheckBoxPreference <CheckBoxPreference
android:key="busybox" android:key="busybox"
android:defaultValue="false" android:defaultValue="false"
android:title="@string/settings_busybox_title" android:title="@string/settings_busybox_title"
android:summary="@string/settings_busybox_summary" /> android:summary="@string/settings_busybox_summary" />
<SwitchPreference
android:key="magiskhide"
android:defaultValue="false"
android:title="@string/magiskhide"
android:summary="@string/settings_magiskhide_summary" />
<SwitchPreference <SwitchPreference
android:key="hosts" android:key="hosts"
android:defaultValue="false" android:defaultValue="false"