Properly detect hosts file

This commit is contained in:
topjohnwu 2017-09-25 17:55:40 +08:00
parent a3abb86daa
commit 5762ded601
2 changed files with 5 additions and 4 deletions

View File

@ -44,6 +44,7 @@ import java.util.concurrent.ExecutionException;
public class MagiskManager extends Application {
public static final String MAGISK_DISABLE_FILE = "/cache/.disable_magisk";
public static final String MAGISK_HOST_FILE = "/magisk/.core/hosts";
public static final String TMP_FOLDER_PATH = "/dev/tmp";
public static final String MAGISK_PATH = "/magisk";
public static final String INTENT_SECTION = "section";
@ -264,7 +265,7 @@ public class MagiskManager extends Application {
.putBoolean("dark_theme", isDarkTheme)
.putBoolean("magiskhide", magiskHide)
.putBoolean("notification", updateNotification)
.putBoolean("hosts", new File("/magisk/.core/hosts").exists())
.putBoolean("hosts", Utils.itemExist(shell, MAGISK_HOST_FILE))
.putBoolean("disable", Utils.itemExist(shell, MAGISK_DISABLE_FILE))
.putBoolean("su_reauth", suReauth)
.putString("su_request_timeout", String.valueOf(suRequestTimeout))

View File

@ -221,12 +221,12 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
enabled = prefs.getBoolean("hosts", false);
if (enabled) {
getShell().su_raw(
"cp -af /system/etc/hosts /magisk/.core/hosts",
"mount -o bind /magisk/.core/hosts /system/etc/hosts");
"cp -af /system/etc/hosts " + MagiskManager.MAGISK_HOST_FILE,
"mount -o bind " + MagiskManager.MAGISK_HOST_FILE + " /system/etc/hosts");
} else {
getShell().su_raw(
"umount -l /system/etc/hosts",
"rm -f /magisk/.core/hosts");
"rm -f " + MagiskManager.MAGISK_HOST_FILE);
}
break;
case "su_access":