diff --git a/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java b/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java index 3e04cff8f..96acf3667 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java +++ b/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java @@ -12,11 +12,14 @@ import android.os.Handler; import android.preference.PreferenceManager; import android.widget.Toast; +import com.topjohnwu.magisk.asyncs.CheckUpdates; import com.topjohnwu.magisk.asyncs.DownloadBusybox; import com.topjohnwu.magisk.asyncs.ParallelTask; import com.topjohnwu.magisk.database.RepoDatabaseHelper; import com.topjohnwu.magisk.database.SuDatabaseHelper; import com.topjohnwu.magisk.module.Module; +import com.topjohnwu.magisk.superuser.SuReceiver; +import com.topjohnwu.magisk.superuser.SuRequestActivity; import com.topjohnwu.magisk.utils.SafetyNetHelper; import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Topic; @@ -88,6 +91,7 @@ public class MagiskManager extends Application { public int suNotificationType; public int suNamespaceMode; public String localeConfig; + public int updateChannel; // Global resources public SharedPreferences prefs; @@ -154,14 +158,15 @@ public class MagiskManager extends Application { // su suRequestTimeout = Utils.getPrefsInt(prefs, "su_request_timeout", 10); - suResponseType = Utils.getPrefsInt(prefs, "su_auto_response", 0); - suNotificationType = Utils.getPrefsInt(prefs, "su_notification", 1); + suResponseType = Utils.getPrefsInt(prefs, "su_auto_response", SuRequestActivity.PROMPT); + suNotificationType = Utils.getPrefsInt(prefs, "su_notification", SuReceiver.TOAST); suReauth = prefs.getBoolean("su_reauth", false); - suAccessState = suDB.getSettings(SuDatabaseHelper.ROOT_ACCESS, 3); - multiuserMode = suDB.getSettings(SuDatabaseHelper.MULTIUSER_MODE, 0); - suNamespaceMode = suDB.getSettings(SuDatabaseHelper.MNT_NS, 1); + suAccessState = suDB.getSettings(SuDatabaseHelper.ROOT_ACCESS, SuDatabaseHelper.ROOT_ACCESS_APPS_AND_ADB); + multiuserMode = suDB.getSettings(SuDatabaseHelper.MULTIUSER_MODE, SuDatabaseHelper.MULTIUSER_MODE_OWNER_ONLY); + suNamespaceMode = suDB.getSettings(SuDatabaseHelper.MNT_NS, SuDatabaseHelper.NAMESPACE_MODE_REQUESTER); updateNotification = prefs.getBoolean("notification", true); + updateChannel = Utils.getPrefsInt(prefs, "update_channel", CheckUpdates.STABLE_CHANNEL); } public void toast(String msg, int duration) { @@ -192,6 +197,7 @@ public class MagiskManager extends Application { .putString("su_access", String.valueOf(suAccessState)) .putString("multiuser_mode", String.valueOf(multiuserMode)) .putString("mnt_ns", String.valueOf(suNamespaceMode)) + .putString("update_channel", String.valueOf(updateChannel)) .putString("busybox_version", BUSYBOX_VERSION) .putString("locale", localeConfig) .apply(); diff --git a/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java b/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java index 4dec24ba2..3ea1f9890 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java @@ -14,6 +14,7 @@ import android.support.v7.app.ActionBar; import android.support.v7.widget.Toolbar; import android.widget.Toast; +import com.topjohnwu.magisk.asyncs.CheckUpdates; import com.topjohnwu.magisk.asyncs.HideManager; import com.topjohnwu.magisk.components.Activity; import com.topjohnwu.magisk.database.SuDatabaseHelper; @@ -76,7 +77,8 @@ public class SettingsActivity extends Activity implements Topic.Subscriber { private SharedPreferences prefs; private PreferenceScreen prefScreen; - private ListPreference suAccess, autoRes, suNotification, requestTimeout, multiuserMode, namespaceMode; + private ListPreference updateChannel, suAccess, autoRes, suNotification, + requestTimeout, multiuserMode, namespaceMode; private MagiskManager magiskManager; private PreferenceCategory generalCatagory; @@ -93,6 +95,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber { PreferenceCategory suCategory = (PreferenceCategory) findPreference("superuser"); PreferenceCategory developer = (PreferenceCategory) findPreference("developer"); + updateChannel = (ListPreference) findPreference("update_channel"); suAccess = (ListPreference) findPreference("su_access"); autoRes = (ListPreference) findPreference("su_auto_response"); requestTimeout = (ListPreference) findPreference("su_request_timeout"); @@ -224,25 +227,25 @@ public class SettingsActivity extends Activity implements Topic.Subscriber { } break; case "su_access": - magiskManager.suAccessState = Utils.getPrefsInt(prefs, "su_access", 3); + magiskManager.suAccessState = Utils.getPrefsInt(prefs, "su_access"); magiskManager.suDB.setSettings(SuDatabaseHelper.ROOT_ACCESS, magiskManager.suAccessState); break; case "multiuser_mode": - magiskManager.multiuserMode = Utils.getPrefsInt(prefs, "multiuser_mode", 0); + magiskManager.multiuserMode = Utils.getPrefsInt(prefs, "multiuser_mode"); magiskManager.suDB.setSettings(SuDatabaseHelper.MULTIUSER_MODE, magiskManager.multiuserMode); break; case "mnt_ns": - magiskManager.suNamespaceMode = Utils.getPrefsInt(prefs, "mnt_ns", 1); + magiskManager.suNamespaceMode = Utils.getPrefsInt(prefs, "mnt_ns"); magiskManager.suDB.setSettings(SuDatabaseHelper.MNT_NS, magiskManager.suNamespaceMode); break; case "su_request_timeout": - magiskManager.suRequestTimeout = Utils.getPrefsInt(prefs, "su_request_timeout", 10); + magiskManager.suRequestTimeout = Utils.getPrefsInt(prefs, "su_request_timeout"); break; case "su_auto_response": - magiskManager.suResponseType = Utils.getPrefsInt(prefs, "su_auto_response", 0); + magiskManager.suResponseType = Utils.getPrefsInt(prefs, "su_auto_response"); break; case "su_notification": - magiskManager.suNotificationType = Utils.getPrefsInt(prefs, "su_notification", 1); + magiskManager.suNotificationType = Utils.getPrefsInt(prefs, "su_notification"); break; case "developer_logging": MagiskManager.devLogging = prefs.getBoolean("developer_logging", false); @@ -254,6 +257,10 @@ public class SettingsActivity extends Activity implements Topic.Subscriber { magiskManager.setLocale(); magiskManager.reloadActivity.publish(false); break; + case "update_channel": + magiskManager.updateChannel = Utils.getPrefsInt(prefs, "update_channel"); + new CheckUpdates(magiskManager, true).exec(); + break; } setSummary(); } @@ -263,6 +270,8 @@ public class SettingsActivity extends Activity implements Topic.Subscriber { } private void setSummary() { + updateChannel.setSummary(getResources() + .getStringArray(R.array.update_channel)[magiskManager.updateChannel]); suAccess.setSummary(getResources() .getStringArray(R.array.su_access)[magiskManager.suAccessState]); autoRes.setSummary(getResources() diff --git a/app/src/main/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java b/app/src/main/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java index e57588003..5a1c59492 100644 --- a/app/src/main/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java +++ b/app/src/main/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java @@ -12,7 +12,11 @@ import org.json.JSONObject; public class CheckUpdates extends ParallelTask { - private static final String UPDATE_JSON = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/magisk_update.json"; + public static final int STABLE_CHANNEL = 0; + public static final int BETA_CHANNEL = 1; + + private static final String STABLE_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/stable.json"; + private static final String BETA_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/beta.json"; private boolean showNotification = false; @@ -29,7 +33,17 @@ public class CheckUpdates extends ParallelTask { protected Void doInBackground(Void... voids) { MagiskManager magiskManager = getMagiskManager(); if (magiskManager == null) return null; - String jsonStr = WebService.getString(UPDATE_JSON); + String jsonStr; + switch (magiskManager.updateChannel) { + case STABLE_CHANNEL: + jsonStr = WebService.getString(STABLE_URL); + break; + case BETA_CHANNEL: + jsonStr = WebService.getString(BETA_URL); + break; + default: + jsonStr = null; + } try { JSONObject json = new JSONObject(jsonStr); JSONObject magisk = json.getJSONObject("magisk"); diff --git a/app/src/main/java/com/topjohnwu/magisk/database/SuDatabaseHelper.java b/app/src/main/java/com/topjohnwu/magisk/database/SuDatabaseHelper.java index fb934ff9c..ae3bc41e2 100644 --- a/app/src/main/java/com/topjohnwu/magisk/database/SuDatabaseHelper.java +++ b/app/src/main/java/com/topjohnwu/magisk/database/SuDatabaseHelper.java @@ -24,8 +24,20 @@ import java.util.List; public class SuDatabaseHelper extends SQLiteOpenHelper { public static final String ROOT_ACCESS = "root_access"; + public static final int ROOT_ACCESS_DISABLED = 0; + public static final int ROOT_ACCESS_APPS_ONLY = 1; + public static final int ROOT_ACCESS_ADB_ONLY = 2; + public static final int ROOT_ACCESS_APPS_AND_ADB = 3; + public static final String MULTIUSER_MODE = "multiuser_mode"; + public static final int MULTIUSER_MODE_OWNER_ONLY = 0; + public static final int MULTIUSER_MODE_OWNER_MANAGED = 1; + public static final int MULTIUSER_MODE_USER = 2; + public static final String MNT_NS = "mnt_ns"; + public static final int NAMESPACE_MODE_GLOBAL = 0; + public static final int NAMESPACE_MODE_REQUESTER = 1; + public static final int NAMESPACE_MODE_ISOLATE = 2; private static final int DATABASE_VER = 3; private static final String POLICY_TABLE = "policies"; diff --git a/app/src/main/java/com/topjohnwu/magisk/superuser/SuReceiver.java b/app/src/main/java/com/topjohnwu/magisk/superuser/SuReceiver.java index 150f00a2e..02e8b0097 100644 --- a/app/src/main/java/com/topjohnwu/magisk/superuser/SuReceiver.java +++ b/app/src/main/java/com/topjohnwu/magisk/superuser/SuReceiver.java @@ -14,8 +14,9 @@ import java.util.Date; public class SuReceiver extends BroadcastReceiver { - private static final int NO_NOTIFICATION = 0; - private static final int TOAST = 1; + public static final int NO_NOTIFICATION = 0; + public static final int TOAST = 1; + private static final int NOTIFY_NORMAL_LOG = 0; private static final int NOTIFY_USER_TOASTS = 1; private static final int NOTIFY_USER_TO_OWNER = 2; diff --git a/app/src/main/java/com/topjohnwu/magisk/superuser/SuRequestActivity.java b/app/src/main/java/com/topjohnwu/magisk/superuser/SuRequestActivity.java index 8bfa1cdac..d61d00abc 100644 --- a/app/src/main/java/com/topjohnwu/magisk/superuser/SuRequestActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/superuser/SuRequestActivity.java @@ -30,10 +30,11 @@ import butterknife.ButterKnife; public class SuRequestActivity extends Activity { + public static final int PROMPT = 0; + public static final int AUTO_DENY = 1; + public static final int AUTO_ALLOW = 2; + private static final int[] timeoutList = {0, -1, 10, 20, 30, 60}; - private static final int PROMPT = 0; - private static final int AUTO_DENY = 1; - private static final int AUTO_ALLOW = 2; @BindView(R.id.su_popup) LinearLayout suPopup; @BindView(R.id.timeout) Spinner timeout; diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java index 64316a1e7..b7738a1dd 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -132,6 +132,10 @@ public class Utils { return Integer.parseInt(prefs.getString(key, String.valueOf(def))); } + public static int getPrefsInt(SharedPreferences prefs, String key) { + return getPrefsInt(prefs, key, 0); + } + public static MagiskManager getMagiskManager(Context context) { return (MagiskManager) context.getApplicationContext(); } diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 8eddee08b..9742781fb 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -14,7 +14,6 @@ @string/settings_su_app @string/settings_su_adb @string/settings_su_app_adb - @@ -73,4 +72,9 @@ @string/isolate_summary + + @string/settings_update_stable + @string/settings_update_beta + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7bad2f666..d5c3a7ce8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -151,6 +151,9 @@ Temporarily hide Magisk Manager.\nThis will install a new app called \"Unhide Magisk Manager\" Language (System Default) + Update Channel + Stable + Beta Magisk Core Only Mode Enable only core features, all modules will not be loaded. MagiskSU, MagiskHide, and systemless hosts will still be enabled diff --git a/app/src/main/res/xml/app_settings.xml b/app/src/main/res/xml/app_settings.xml index 0529547b5..ffa838e18 100644 --- a/app/src/main/res/xml/app_settings.xml +++ b/app/src/main/res/xml/app_settings.xml @@ -15,6 +15,12 @@ android:title="@string/settings_notification_title" android:summary="@string/settings_notification_summary" /> + +