From 75ab1fa570bbf079e35388bac3e615871ed49e84 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 28 Oct 2018 00:54:56 -0400 Subject: [PATCH] Micro optimizations --- .../full/java/com/topjohnwu/magisk/Const.java | 5 +- .../full/java/com/topjohnwu/magisk/Data.java | 19 +---- .../com/topjohnwu/magisk/MagiskManager.java | 16 +---- .../com/topjohnwu/magisk/MainActivity.java | 4 +- .../com/topjohnwu/magisk/SplashActivity.java | 18 ++++- .../topjohnwu/magisk/SuRequestActivity.java | 12 ++-- .../magisk/adapters/PolicyAdapter.java | 3 +- .../com/topjohnwu/magisk/container/Repo.java | 2 +- .../magisk/database/RepoDatabaseHelper.java | 5 +- .../magisk/fragments/LogFragment.java | 6 +- .../magisk/fragments/SettingsFragment.java | 69 ++++++++++++------- .../magisk/receivers/ShortcutReceiver.java | 4 +- .../magisk/utils/FingerprintHelper.java | 10 +++ .../com/topjohnwu/magisk/utils/Utils.java | 9 +++ 14 files changed, 99 insertions(+), 83 deletions(-) diff --git a/app/src/full/java/com/topjohnwu/magisk/Const.java b/app/src/full/java/com/topjohnwu/magisk/Const.java index 5db6fb5bc..31f7f7047 100644 --- a/app/src/full/java/com/topjohnwu/magisk/Const.java +++ b/app/src/full/java/com/topjohnwu/magisk/Const.java @@ -34,10 +34,7 @@ public class Const { // Versions public static final int UPDATE_SERVICE_VER = 1; - - public static int MIN_MODULE_VER() { - return Data.magiskVersionCode >= MAGISK_VER.REMOVE_LEGACY_LINK ? 1500 : 1400; - } + public static final int MIN_MODULE_VER = 1500; /* A list of apps that should not be shown as hide-able */ public static final List HIDE_BLACKLIST = Arrays.asList( diff --git a/app/src/full/java/com/topjohnwu/magisk/Data.java b/app/src/full/java/com/topjohnwu/magisk/Data.java index 1aa3f33e1..24cf8eb60 100644 --- a/app/src/full/java/com/topjohnwu/magisk/Data.java +++ b/app/src/full/java/com/topjohnwu/magisk/Data.java @@ -13,7 +13,6 @@ import com.topjohnwu.magisk.receivers.RebootReceiver; import com.topjohnwu.magisk.receivers.ShortcutReceiver; import com.topjohnwu.magisk.services.OnBootService; import com.topjohnwu.magisk.services.UpdateCheckService; -import com.topjohnwu.magisk.utils.FingerprintHelper; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.ShellUtils; @@ -62,12 +61,9 @@ public class Data { public static boolean isDarkTheme; public static int suRequestTimeout; public static int suLogTimeout = 14; - public static int suAccessState; - public static boolean suFingerprint; - public static int multiuserMode; + public static int multiuserState = -1; public static int suResponseType; public static int suNotificationType; - public static int suNamespaceMode; public static int updateChannel; public static int repoOrder; @@ -180,15 +176,6 @@ public class Data { suRequestTimeout = Utils.getPrefsInt(mm.prefs, Const.Key.SU_REQUEST_TIMEOUT, Const.Value.timeoutList[2]); suResponseType = Utils.getPrefsInt(mm.prefs, Const.Key.SU_AUTO_RESPONSE, Const.Value.SU_PROMPT); suNotificationType = Utils.getPrefsInt(mm.prefs, Const.Key.SU_NOTIFICATION, Const.Value.NOTIFICATION_TOAST); - suAccessState = mm.mDB.getSettings(Const.Key.ROOT_ACCESS, Const.Value.ROOT_ACCESS_APPS_AND_ADB); - multiuserMode = mm.mDB.getSettings(Const.Key.SU_MULTIUSER_MODE, Const.Value.MULTIUSER_MODE_OWNER_ONLY); - suNamespaceMode = mm.mDB.getSettings(Const.Key.SU_MNT_NS, Const.Value.NAMESPACE_MODE_REQUESTER); - suFingerprint = mm.mDB.getSettings(Const.Key.SU_FINGERPRINT, 0) != 0; - if (suFingerprint && !FingerprintHelper.canUseFingerprint()) { - // User revoked the fingerprint - mm.mDB.setSettings(Const.Key.SU_FINGERPRINT, 0); - suFingerprint = false; - } // config isDarkTheme = mm.prefs.getBoolean(Const.Key.DARK_THEME, false); @@ -202,13 +189,9 @@ public class Data { .putBoolean(Const.Key.MAGISKHIDE, magiskHide) .putBoolean(Const.Key.HOSTS, Const.MAGISK_HOST_FILE.exists()) .putBoolean(Const.Key.COREONLY, Const.MAGISK_DISABLE_FILE.exists()) - .putBoolean(Const.Key.SU_FINGERPRINT, suFingerprint) .putString(Const.Key.SU_REQUEST_TIMEOUT, String.valueOf(suRequestTimeout)) .putString(Const.Key.SU_AUTO_RESPONSE, String.valueOf(suResponseType)) .putString(Const.Key.SU_NOTIFICATION, String.valueOf(suNotificationType)) - .putString(Const.Key.ROOT_ACCESS, String.valueOf(suAccessState)) - .putString(Const.Key.SU_MULTIUSER_MODE, String.valueOf(multiuserMode)) - .putString(Const.Key.SU_MNT_NS, String.valueOf(suNamespaceMode)) .putString(Const.Key.UPDATE_CHANNEL, String.valueOf(updateChannel)) .putInt(Const.Key.UPDATE_SERVICE_VER, Const.UPDATE_SERVICE_VER) .putInt(Const.Key.REPO_ORDER, repoOrder) diff --git a/app/src/full/java/com/topjohnwu/magisk/MagiskManager.java b/app/src/full/java/com/topjohnwu/magisk/MagiskManager.java index 96e01bb2d..d3281fb1b 100644 --- a/app/src/full/java/com/topjohnwu/magisk/MagiskManager.java +++ b/app/src/full/java/com/topjohnwu/magisk/MagiskManager.java @@ -1,10 +1,8 @@ package com.topjohnwu.magisk; import android.content.SharedPreferences; -import android.content.pm.PackageManager; import android.content.res.Configuration; import android.preference.PreferenceManager; -import android.text.TextUtils; import com.topjohnwu.magisk.database.MagiskDB; import com.topjohnwu.magisk.database.RepoDatabaseHelper; @@ -39,19 +37,7 @@ public class MagiskManager extends ContainerApp { prefs = PreferenceManager.getDefaultSharedPreferences(this); mDB = MagiskDB.getInstance(); - - String pkg = mDB.getStrings(Const.Key.SU_MANAGER, null); - if (pkg != null && getPackageName().equals(Const.ORIG_PKG_NAME)) { - mDB.setStrings(Const.Key.SU_MANAGER, null); - Shell.su("pm uninstall " + pkg).exec(); - } - if (TextUtils.equals(pkg, getPackageName())) { - try { - // We are the manager, remove com.topjohnwu.magisk as it could be malware - getPackageManager().getApplicationInfo(Const.ORIG_PKG_NAME, 0); - RootUtils.uninstallPkg(Const.ORIG_PKG_NAME); - } catch (PackageManager.NameNotFoundException ignored) {} - } + repoDB = new RepoDatabaseHelper(this); LocaleManager.setLocale(this); Data.loadConfig(); diff --git a/app/src/full/java/com/topjohnwu/magisk/MainActivity.java b/app/src/full/java/com/topjohnwu/magisk/MainActivity.java index 502a4eafc..8ffff2fb0 100644 --- a/app/src/full/java/com/topjohnwu/magisk/MainActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/MainActivity.java @@ -18,6 +18,7 @@ import com.topjohnwu.magisk.fragments.SettingsFragment; import com.topjohnwu.magisk.fragments.SuperuserFragment; import com.topjohnwu.magisk.utils.Download; import com.topjohnwu.magisk.utils.Topic; +import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.superuser.Shell; import androidx.annotation.NonNull; @@ -124,8 +125,7 @@ public class MainActivity extends BaseActivity menu.findItem(R.id.downloads).setVisible(Download.checkNetworkStatus(this) && Shell.rootAccess() && Data.magiskVersionCode >= 0); menu.findItem(R.id.log).setVisible(Shell.rootAccess()); - menu.findItem(R.id.superuser).setVisible(Shell.rootAccess() && - !(Const.USER_ID > 0 && Data.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)); + menu.findItem(R.id.superuser).setVisible(Utils.showSuperUser()); } public void navigate(String item) { diff --git a/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java b/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java index c49561330..f7c077c33 100644 --- a/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java @@ -3,16 +3,18 @@ package com.topjohnwu.magisk; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Intent; +import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; +import android.text.TextUtils; import com.topjohnwu.magisk.asyncs.CheckUpdates; import com.topjohnwu.magisk.asyncs.UpdateRepos; import com.topjohnwu.magisk.components.BaseActivity; -import com.topjohnwu.magisk.database.RepoDatabaseHelper; import com.topjohnwu.magisk.receivers.ShortcutReceiver; import com.topjohnwu.magisk.utils.Download; import com.topjohnwu.magisk.utils.LocaleManager; +import com.topjohnwu.magisk.utils.RootUtils; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.superuser.Shell; @@ -22,6 +24,19 @@ public class SplashActivity extends BaseActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + String pkg = mm.mDB.getStrings(Const.Key.SU_MANAGER, null); + if (pkg != null && getPackageName().equals(Const.ORIG_PKG_NAME)) { + mm.mDB.setStrings(Const.Key.SU_MANAGER, null); + Shell.su("pm uninstall " + pkg).exec(); + } + if (TextUtils.equals(pkg, getPackageName())) { + try { + // We are the manager, remove com.topjohnwu.magisk as it could be malware + getPackageManager().getApplicationInfo(Const.ORIG_PKG_NAME, 0); + RootUtils.uninstallPkg(Const.ORIG_PKG_NAME); + } catch (PackageManager.NameNotFoundException ignored) {} + } + // Magisk working as expected if (Shell.rootAccess() && Data.magiskVersionCode > 0) { // Update check service @@ -30,7 +45,6 @@ public class SplashActivity extends BaseActivity { Utils.loadModules(); } - mm.repoDB = new RepoDatabaseHelper(this); Data.importPrefs(); // Dynamic detect all locales diff --git a/app/src/full/java/com/topjohnwu/magisk/SuRequestActivity.java b/app/src/full/java/com/topjohnwu/magisk/SuRequestActivity.java index f88ce7467..0adf95651 100644 --- a/app/src/full/java/com/topjohnwu/magisk/SuRequestActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/SuRequestActivity.java @@ -181,9 +181,9 @@ public class SuRequestActivity extends BaseActivity { } }; - boolean useFingerprint = Data.suFingerprint && FingerprintHelper.canUseFingerprint(); + boolean useFP = FingerprintHelper.useFingerPrint(); - if (useFingerprint) { + if (useFP) { try { fingerprintHelper = new FingerprintHelper() { @Override @@ -209,11 +209,11 @@ public class SuRequestActivity extends BaseActivity { fingerprintHelper.authenticate(); } catch (Exception e) { e.printStackTrace(); - useFingerprint = false; + useFP = false; } } - if (!useFingerprint) { + if (!useFP) { grant_btn.setOnClickListener(v -> { handleAction(Policy.ALLOW); timer.cancel(); @@ -221,8 +221,8 @@ public class SuRequestActivity extends BaseActivity { grant_btn.requestFocus(); } - grant_btn.setVisibility(useFingerprint ? View.GONE : View.VISIBLE); - fingerprintImg.setVisibility(useFingerprint ? View.VISIBLE : View.GONE); + grant_btn.setVisibility(useFP ? View.GONE : View.VISIBLE); + fingerprintImg.setVisibility(useFP ? View.VISIBLE : View.GONE); deny_btn.setOnClickListener(v -> { handleAction(Policy.DENY); diff --git a/app/src/full/java/com/topjohnwu/magisk/adapters/PolicyAdapter.java b/app/src/full/java/com/topjohnwu/magisk/adapters/PolicyAdapter.java index 8a9d622d7..cd430aa77 100644 --- a/app/src/full/java/com/topjohnwu/magisk/adapters/PolicyAdapter.java +++ b/app/src/full/java/com/topjohnwu/magisk/adapters/PolicyAdapter.java @@ -10,7 +10,6 @@ import android.widget.Switch; import android.widget.TextView; import com.google.android.material.snackbar.Snackbar; -import com.topjohnwu.magisk.Data; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.components.CustomAlertDialog; import com.topjohnwu.magisk.components.ExpandableView; @@ -86,7 +85,7 @@ public class PolicyAdapter extends RecyclerView.Adapter { holder.masterSwitch.setChecked(isChecked); diff --git a/app/src/full/java/com/topjohnwu/magisk/container/Repo.java b/app/src/full/java/com/topjohnwu/magisk/container/Repo.java index 5729d227a..ffea3a08a 100644 --- a/app/src/full/java/com/topjohnwu/magisk/container/Repo.java +++ b/app/src/full/java/com/topjohnwu/magisk/container/Repo.java @@ -36,7 +36,7 @@ public class Repo extends BaseModule { if (getVersionCode() < 0) { throw new IllegalRepoException("Repo [" + getId() + "] does not contain versionCode"); } - if (getMinMagiskVersion() < Const.MIN_MODULE_VER()) { + if (getMinMagiskVersion() < Const.MIN_MODULE_VER) { Logger.debug("Repo [" + getId() + "] is outdated"); } } diff --git a/app/src/full/java/com/topjohnwu/magisk/database/RepoDatabaseHelper.java b/app/src/full/java/com/topjohnwu/magisk/database/RepoDatabaseHelper.java index fa6f85b2e..d50375f6a 100644 --- a/app/src/full/java/com/topjohnwu/magisk/database/RepoDatabaseHelper.java +++ b/app/src/full/java/com/topjohnwu/magisk/database/RepoDatabaseHelper.java @@ -29,8 +29,7 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper { mDb = getWritableDatabase(); // Remove outdated repos - mDb.delete(TABLE_NAME, "minMagisk=?", - new String[] { String.valueOf(Data.magiskVersionCode), String.valueOf(Const.MIN_MODULE_VER()) }, + new String[] { String.valueOf(Data.magiskVersionCode), String.valueOf(Const.MIN_MODULE_VER) }, null, null, orderBy); } diff --git a/app/src/full/java/com/topjohnwu/magisk/fragments/LogFragment.java b/app/src/full/java/com/topjohnwu/magisk/fragments/LogFragment.java index b78513a40..904363604 100644 --- a/app/src/full/java/com/topjohnwu/magisk/fragments/LogFragment.java +++ b/app/src/full/java/com/topjohnwu/magisk/fragments/LogFragment.java @@ -7,8 +7,6 @@ import android.view.View; import android.view.ViewGroup; import com.google.android.material.tabs.TabLayout; -import com.topjohnwu.magisk.Const; -import com.topjohnwu.magisk.Data; import com.topjohnwu.magisk.MainActivity; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.adapters.TabFragmentAdapter; @@ -33,9 +31,7 @@ public class LogFragment extends BaseFragment { TabFragmentAdapter adapter = new TabFragmentAdapter(getChildFragmentManager()); - if (!(Const.USER_ID > 0 && Data.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) { - adapter.addTab(new SuLogFragment(), getString(R.string.superuser)); - } + adapter.addTab(new SuLogFragment(), getString(R.string.superuser)); adapter.addTab(new MagiskLogFragment(), getString(R.string.magisk)); tab.setupWithViewPager(viewPager); tab.setVisibility(View.VISIBLE); diff --git a/app/src/full/java/com/topjohnwu/magisk/fragments/SettingsFragment.java b/app/src/full/java/com/topjohnwu/magisk/fragments/SettingsFragment.java index 907729f93..f5d414178 100644 --- a/app/src/full/java/com/topjohnwu/magisk/fragments/SettingsFragment.java +++ b/app/src/full/java/com/topjohnwu/magisk/fragments/SettingsFragment.java @@ -46,20 +46,36 @@ public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener, Topic.Subscriber, Topic.AutoSubscriber { - private PreferenceScreen prefScreen; - - private ListPreference updateChannel, suAccess, autoRes, suNotification, - requestTimeout, multiuserMode, namespaceMode; private MagiskManager mm; - private PreferenceCategory generalCatagory; + + private ListPreference updateChannel, autoRes, suNotification, + requestTimeout, rootConfig, multiuserConfig, nsConfig; + + private int rootState, namespaceState; + private boolean showSuperuser; + + private void prefsSync() { + rootState = mm.mDB.getSettings(Const.Key.ROOT_ACCESS, Const.Value.ROOT_ACCESS_APPS_AND_ADB); + namespaceState = mm.mDB.getSettings(Const.Key.SU_MNT_NS, Const.Value.NAMESPACE_MODE_REQUESTER); + showSuperuser = Utils.showSuperUser(); + mm.prefs.edit() + .putString(Const.Key.ROOT_ACCESS, String.valueOf(rootState)) + .putString(Const.Key.SU_MNT_NS, String.valueOf(namespaceState)) + .putString(Const.Key.SU_MULTIUSER_MODE, String.valueOf(Data.multiuserState)) + .putBoolean(Const.Key.SU_FINGERPRINT, FingerprintHelper.useFingerPrint()) + .apply(); + } @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { - setPreferencesFromResource(R.xml.app_settings, rootKey); mm = Data.MM(); - prefScreen = getPreferenceScreen(); + prefsSync(); - generalCatagory = (PreferenceCategory) findPreference("general"); + setPreferencesFromResource(R.xml.app_settings, rootKey); + + PreferenceScreen prefScreen = getPreferenceScreen(); + + PreferenceCategory generalCatagory = (PreferenceCategory) findPreference("general"); PreferenceCategory magiskCategory = (PreferenceCategory) findPreference("magisk"); PreferenceCategory suCategory = (PreferenceCategory) findPreference("superuser"); Preference hideManager = findPreference("hide"); @@ -72,12 +88,12 @@ public class SettingsFragment extends PreferenceFragmentCompat }); updateChannel = (ListPreference) findPreference(Const.Key.UPDATE_CHANNEL); - suAccess = (ListPreference) findPreference(Const.Key.ROOT_ACCESS); + rootConfig = (ListPreference) findPreference(Const.Key.ROOT_ACCESS); autoRes = (ListPreference) findPreference(Const.Key.SU_AUTO_RESPONSE); requestTimeout = (ListPreference) findPreference(Const.Key.SU_REQUEST_TIMEOUT); suNotification = (ListPreference) findPreference(Const.Key.SU_NOTIFICATION); - multiuserMode = (ListPreference) findPreference(Const.Key.SU_MULTIUSER_MODE); - namespaceMode = (ListPreference) findPreference(Const.Key.SU_MNT_NS); + multiuserConfig = (ListPreference) findPreference(Const.Key.SU_MULTIUSER_MODE); + nsConfig = (ListPreference) findPreference(Const.Key.SU_MNT_NS); SwitchPreference reauth = (SwitchPreference) findPreference(Const.Key.SU_REAUTH); SwitchPreference fingerprint = (SwitchPreference) findPreference(Const.Key.SU_FINGERPRINT); @@ -107,7 +123,7 @@ public class SettingsFragment extends PreferenceFragmentCompat // Disable dangerous settings in secondary user if (Const.USER_ID > 0) { - suCategory.removePreference(multiuserMode); + suCategory.removePreference(multiuserConfig); } // Disable re-authentication option on Android O, it will not work @@ -163,8 +179,7 @@ public class SettingsFragment extends PreferenceFragmentCompat generalCatagory.removePreference(hideManager); } - if (!Shell.rootAccess() || (Const.USER_ID > 0 && - Data.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) { + if (!showSuperuser) { prefScreen.removePreference(suCategory); } @@ -213,9 +228,16 @@ public class SettingsFragment extends PreferenceFragmentCompat mm.mDB.setSettings(key, Utils.getPrefsInt(prefs, key)); break; } - Data.loadConfig(); - setSummary(); switch (key) { + case Const.Key.ROOT_ACCESS: + rootState = Utils.getPrefsInt(prefs, key); + break; + case Const.Key.SU_MULTIUSER_MODE: + Data.multiuserState = Utils.getPrefsInt(prefs, key); + break; + case Const.Key.SU_MNT_NS: + namespaceState = Utils.getPrefsInt(prefs, key); + break; case Const.Key.DARK_THEME: requireActivity().recreate(); break; @@ -259,6 +281,8 @@ public class SettingsFragment extends PreferenceFragmentCompat Utils.setupUpdateCheck(); break; } + Data.loadConfig(); + setSummary(); } @Override @@ -270,7 +294,6 @@ public class SettingsFragment extends PreferenceFragmentCompat ((SwitchPreference) preference).setChecked(!checked); FingerprintHelper.showAuthDialog(requireActivity(), () -> { ((SwitchPreference) preference).setChecked(checked); - Data.suFingerprint = checked; mm.mDB.setSettings(key, checked ? 1 : 0); }); break; @@ -281,8 +304,8 @@ public class SettingsFragment extends PreferenceFragmentCompat private void setSummary() { updateChannel.setSummary(getResources() .getStringArray(R.array.update_channel)[Data.updateChannel]); - suAccess.setSummary(getResources() - .getStringArray(R.array.su_access)[Data.suAccessState]); + rootConfig.setSummary(getResources() + .getStringArray(R.array.su_access)[rootState]); autoRes.setSummary(getResources() .getStringArray(R.array.auto_response)[Data.suResponseType]); suNotification.setSummary(getResources() @@ -290,10 +313,10 @@ public class SettingsFragment extends PreferenceFragmentCompat requestTimeout.setSummary( getString(R.string.request_timeout_summary, mm.prefs.getString(Const.Key.SU_REQUEST_TIMEOUT, "10"))); - multiuserMode.setSummary(getResources() - .getStringArray(R.array.multiuser_summary)[Data.multiuserMode]); - namespaceMode.setSummary(getResources() - .getStringArray(R.array.namespace_summary)[Data.suNamespaceMode]); + multiuserConfig.setSummary(getResources() + .getStringArray(R.array.multiuser_summary)[Data.multiuserState]); + nsConfig.setSummary(getResources() + .getStringArray(R.array.namespace_summary)[namespaceState]); } @Override diff --git a/app/src/full/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java b/app/src/full/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java index 88247da25..08fb631aa 100644 --- a/app/src/full/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java +++ b/app/src/full/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java @@ -13,6 +13,7 @@ import com.topjohnwu.magisk.Data; import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.SplashActivity; +import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.superuser.Shell; import java.util.ArrayList; @@ -33,8 +34,7 @@ public class ShortcutReceiver extends BroadcastReceiver { private ArrayList getShortCuts(MagiskManager mm) { ArrayList shortCuts = new ArrayList<>(); boolean root = Shell.rootAccess(); - if (root && !(Const.USER_ID > 0 && - Data.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) { + if (Utils.showSuperUser()) { shortCuts.add(new ShortcutInfo.Builder(mm, "superuser") .setShortLabel(mm.getString(R.string.superuser)) .setIntent(new Intent(mm, Data.classMap.get(SplashActivity.class)) diff --git a/app/src/full/java/com/topjohnwu/magisk/utils/FingerprintHelper.java b/app/src/full/java/com/topjohnwu/magisk/utils/FingerprintHelper.java index 701ba8dd0..e1382e3b6 100644 --- a/app/src/full/java/com/topjohnwu/magisk/utils/FingerprintHelper.java +++ b/app/src/full/java/com/topjohnwu/magisk/utils/FingerprintHelper.java @@ -35,6 +35,16 @@ public abstract class FingerprintHelper { private Cipher cipher; private CancellationSignal cancel; + public static boolean useFingerPrint() { + MagiskManager mm = Data.MM(); + boolean fp = mm.mDB.getSettings(Const.Key.SU_FINGERPRINT, 0) != 0; + if (fp && !canUseFingerprint()) { + mm.mDB.setSettings(Const.Key.SU_FINGERPRINT, 0); + fp = false; + } + return fp; + } + public static boolean canUseFingerprint() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false; diff --git a/app/src/full/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/full/java/com/topjohnwu/magisk/utils/Utils.java index 86a8ee036..9bf8e65db 100644 --- a/app/src/full/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/full/java/com/topjohnwu/magisk/utils/Utils.java @@ -22,6 +22,7 @@ import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.container.Module; import com.topjohnwu.magisk.container.ValueSortedMap; +import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.io.SuFile; import java.util.Locale; @@ -140,4 +141,12 @@ public class Utils { } catch (Exception ignored) {} return info.loadLabel(pm).toString(); } + + public static boolean showSuperUser() { + if (Data.multiuserState < 0) + Data.multiuserState = Data.MM().mDB.getSettings(Const.Key.SU_MULTIUSER_MODE, + Const.Value.MULTIUSER_MODE_OWNER_ONLY); + return Shell.rootAccess() && (Const.USER_ID == 0 || + Data.multiuserState != Const.Value.MULTIUSER_MODE_OWNER_MANAGED); + } } \ No newline at end of file