diff --git a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java index 9b8e4cfb7..ca6cdc13f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java @@ -35,6 +35,8 @@ public class MainActivity extends AppCompatActivity private static final String SELECTED_ITEM_ID = "SELECTED_ITEM_ID"; + public static CallbackHandler.Event recreate = new CallbackHandler.Event(); + private final Handler mDrawerHandler = new Handler(); private SharedPreferences prefs; @@ -90,23 +92,29 @@ public class MainActivity extends AppCompatActivity } navigationView.setNavigationItemSelectedListener(this); - - if (StatusFragment.updateCheckDone.isTriggered) { - onTrigger(StatusFragment.updateCheckDone); - } } @Override protected void onResume() { super.onResume(); CallbackHandler.register(StatusFragment.updateCheckDone, this); + CallbackHandler.register(recreate, this); + if (StatusFragment.updateCheckDone.isTriggered) { + onTrigger(StatusFragment.updateCheckDone); + } checkHideSection(); } + @Override + protected void onPause() { + super.onPause(); + CallbackHandler.unRegister(StatusFragment.updateCheckDone, this); + } + @Override protected void onDestroy() { super.onDestroy(); - CallbackHandler.unRegister(StatusFragment.updateCheckDone, this); + CallbackHandler.unRegister(recreate, this); } @Override @@ -135,18 +143,22 @@ public class MainActivity extends AppCompatActivity @Override public void onTrigger(CallbackHandler.Event event) { - Menu menu = navigationView.getMenu(); - menu.findItem(R.id.install).setVisible(StatusFragment.remoteMagiskVersion > 0 && - Shell.rootAccess()); + if (event == StatusFragment.updateCheckDone) { + Menu menu = navigationView.getMenu(); + menu.findItem(R.id.install).setVisible(StatusFragment.remoteMagiskVersion > 0 && + Shell.rootAccess()); + } else if (event == recreate) { + recreate(); + } } private void checkHideSection() { Menu menu = navigationView.getMenu(); - menu.findItem(R.id.magiskhide).setVisible(StatusFragment.magiskVersion > 0 && + menu.findItem(R.id.magiskhide).setVisible(StatusFragment.magiskVersion >= 8 && prefs.getBoolean("magiskhide", false) && Shell.rootAccess()); - menu.findItem(R.id.modules).setVisible(StatusFragment.magiskVersion > 0 && + menu.findItem(R.id.modules).setVisible(StatusFragment.magiskVersion >= 4 && Shell.rootAccess()); - menu.findItem(R.id.downloads).setVisible(StatusFragment.magiskVersion > 0 && + menu.findItem(R.id.downloads).setVisible(StatusFragment.magiskVersion >= 4 && Shell.rootAccess()); menu.findItem(R.id.log).setVisible(Shell.rootAccess()); menu.findItem(R.id.install).setVisible(Shell.rootAccess()); diff --git a/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java b/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java index 2a4c50a21..6d31c663d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java @@ -1,10 +1,11 @@ package com.topjohnwu.magisk; -import android.content.Intent; +import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.CheckBoxPreference; import android.preference.ListPreference; +import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; import android.support.v7.app.ActionBar; @@ -15,6 +16,7 @@ import android.widget.Toast; import com.topjohnwu.magisk.utils.Async; import com.topjohnwu.magisk.utils.Logger; +import com.topjohnwu.magisk.utils.ModuleHelper; import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Utils; @@ -86,14 +88,34 @@ public class SettingsActivity extends AppCompatActivity { CheckBoxPreference busyboxPreference = (CheckBoxPreference) findPreference("busybox"); CheckBoxPreference magiskhidePreference = (CheckBoxPreference) findPreference("magiskhide"); CheckBoxPreference hostsPreference = (CheckBoxPreference) findPreference("hosts"); + Preference clear = findPreference("clear"); - themePreference.setSummary(themePreference.getValue()); + clear.setOnPreferenceClickListener((pref) -> { + SharedPreferences repoMap = getActivity().getSharedPreferences(ModuleHelper.FILE_KEY, Context.MODE_PRIVATE); + repoMap.edit() + .putString(ModuleHelper.ETAG_KEY, "") + .putInt(ModuleHelper.VERSION_KEY, 0) + .apply(); + new Async.LoadRepos(getActivity()).exec(); + Toast.makeText(getActivity(), R.string.repo_cache_cleared, Toast.LENGTH_LONG).show(); + return true; + }); + + if (Utils.isDarkTheme) { + themePreference.setSummary(R.string.theme_dark); + } else { + themePreference.setSummary(R.string.theme_default); + } if (StatusFragment.magiskVersion < 9) { hostsPreference.setEnabled(false); busyboxPreference.setEnabled(false); } else if (StatusFragment.magiskVersion < 8) { magiskhidePreference.setEnabled(false); + } else if (! Shell.rootAccess()) { + busyboxPreference.setEnabled(false); + magiskhidePreference.setEnabled(false); + hostsPreference.setEnabled(false); } else { busyboxPreference.setEnabled(true); magiskhidePreference.setEnabled(true); @@ -121,81 +143,61 @@ public class SettingsActivity extends AppCompatActivity { switch (key) { case "theme": String theme = prefs.getString("theme", getString(R.string.theme_default_value)); - Utils.isDarkTheme = theme.equalsIgnoreCase(getString(R.string.theme_dark_value)); - - themePreference.setSummary(theme); - if (Utils.isDarkTheme) { - getActivity().getApplication().setTheme(R.style.AppTheme_dh); - } else { - getActivity().getApplication().setTheme(R.style.AppTheme); + if (Utils.isDarkTheme != theme.equalsIgnoreCase(getString(R.string.theme_dark_value))) { + Utils.isDarkTheme = !Utils.isDarkTheme; + getActivity().recreate(); + MainActivity.recreate.trigger(); } - Intent intent = new Intent(getActivity(), MainActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(intent); break; case "magiskhide": - checked = prefs.getBoolean("magiskhide", false); - if (checked) { - new Async.RootTask() { - @Override - protected Void doInBackground(Void... params) { + checked = prefs.getBoolean("magiskhide", false); + new Async.RootTask() { + private boolean enable = checked; + @Override + protected Void doInBackground(Void... params) { + if (enable) { Utils.createFile("/magisk/.core/magiskhide/enable"); - return null; - } - }.exec(); - } else { - new Async.RootTask() { - @Override - protected Void doInBackground(Void... params) { + } else { Utils.removeItem("/magisk/.core/magiskhide/enable"); - return null; } - }.exec(); - } + + return null; + } + }.exec(); Toast.makeText(getActivity(), R.string.settings_reboot_toast, Toast.LENGTH_LONG).show(); break; case "busybox": checked = prefs.getBoolean("busybox", false); - if (checked) { - new Async.RootTask() { - @Override - protected Void doInBackground(Void... params) { + new Async.RootTask() { + private boolean enable = checked; + @Override + protected Void doInBackground(Void... params) { + if (enable) { Utils.createFile("/magisk/.core/busybox/enable"); - return null; - } - }.exec(); - } else { - new Async.RootTask() { - @Override - protected Void doInBackground(Void... params) { + } else { Utils.removeItem("/magisk/.core/busybox/enable"); - return null; } - }.exec(); - } + return null; + } + }.exec(); Toast.makeText(getActivity(), R.string.settings_reboot_toast, Toast.LENGTH_LONG).show(); break; case "hosts": checked = prefs.getBoolean("hosts", false); - if (checked) { - new Async.RootTask() { - @Override - protected Void doInBackground(Void... voids) { - Shell.su("cp -af /system/etc/hosts /magisk/.core/hosts"); - return null; + new Async.RootTask() { + private boolean enable = checked; + @Override + protected Void doInBackground(Void... voids) { + if (enable) { + Shell.su("cp -af /system/etc/hosts /magisk/.core/hosts", + "mount -o bind /magisk/.core/hosts /system/etc/hosts"); + } else { + Shell.su("umount -l /system/etc/hosts", + "rm -f /magisk/.core/hosts"); } - }.exec(); - } else { - new Async.RootTask() { - @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(); + return null; + } + }.exec(); break; case "developer_logging": Logger.devLog = prefs.getBoolean("developer_logging", false); diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/ModuleHelper.java b/app/src/main/java/com/topjohnwu/magisk/utils/ModuleHelper.java index 719c9d5a3..112edc42e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/ModuleHelper.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/ModuleHelper.java @@ -28,10 +28,10 @@ import java.util.Map; public class ModuleHelper { private static final String MAGISK_PATH = "/magisk"; - private static final String FILE_KEY = "RepoMap"; + public static final String FILE_KEY = "RepoMap"; private static final String REPO_KEY = "repomap"; - private static final String VERSION_KEY = "version"; - private static final String ETAG_KEY = "ETag"; + public static final String VERSION_KEY = "version"; + public static final String ETAG_KEY = "ETag"; private static final int DATABASE_VER = 1; private static ValueSortedMap repoMap = new ValueSortedMap<>(); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4635b2199..fd85acf62 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -108,7 +108,9 @@ Downloading %1$s New Magisk Update Available! Magisk v%1$.1f update is live, do you want to install? + Reboot to apply settings Check release notes + Repo cache cleared https://api.github.com/orgs/Magisk-Modules-Repo/repos @@ -121,6 +123,8 @@ Select a theme Default Dark + Clear Repo Cache + Clear the cached information for online repos, forces the app to refresh online Enable Magisk Hide Hide Magisk from various detections @@ -131,14 +135,13 @@ Development Enable advanced debug logging - Check this to enable more verbose logging. + Check this to enable verbose logging Enable shell command debug logging - Check this to enable logging all shell commands and output - - Reboot to apply settings + Check this to enable logging all shell commands and its output default dark + diff --git a/app/src/main/res/xml/app_settings.xml b/app/src/main/res/xml/app_settings.xml index 2a2c0a83d..8f382eb75 100644 --- a/app/src/main/res/xml/app_settings.xml +++ b/app/src/main/res/xml/app_settings.xml @@ -12,6 +12,11 @@ android:entries="@array/themes" android:entryValues="@array/themes_values"/> + +