diff options
author | Gegham Zakaryan <zakaryan.2004@outlook.com> | 2021-04-04 15:45:42 +0400 |
---|---|---|
committer | Gegham Zakaryan <zakaryan.2004@outlook.com> | 2021-05-16 02:15:59 +0400 |
commit | 046484d57788ca7f8264cdb7ec7a74790cf284fa (patch) | |
tree | 97db164dc2e6a8821a2261fe6fbfdc4a64783819 | |
parent | 6546cd5852fdfb0ffdc10fe4aae9d5466e1818b0 (diff) |
PowerMenuActions: Add more checks for bugreport and lockdown option states
Use LockPatternUtils to check if lock screen is secure.
Use UserManager and UserInfo to check if the current user is primary.
In result, bugreport and lockdown are visible and toggled only during correct scenarios:
- Bug reporting option is disabled if development settings aren't on
- Bug reporting option is disabled if the current user isn't the primary user
- Bug reporting checkbox reflects the state of Settings.Global.BUGREPORT_IN_POWER_MENU
- Lockdown option is disabled if keyguard isn't secure
- Lockdown checkbox reflects the state of Settings.Secure.LOCKDOWN_IN_POWER_MENU
String summaries are added for each scenario.
Signed-off-by: Gegham Zakaryan <zakaryan.2004@outlook.com>
Change-Id: I8a4e4a6078e8277ce2cfee16d5b2abb4de91c746
-rw-r--r-- | res/values/strings.xml | 4 | ||||
-rw-r--r-- | src/org/lineageos/lineageparts/input/PowerMenuActions.java | 46 |
2 files changed, 41 insertions, 9 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml index f40fd0d..0aab4cb 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -259,8 +259,10 @@ <string name="power_menu_airplane_title">Airplane mode</string> <string name="power_menu_users_title">User switcher</string> <string name="power_menu_bug_report_title">Bug report</string> - <string name="power_menu_bug_report_disabled">Bug reporting is disabled in development settings</string> + <string name="power_menu_bug_report_devoptions_unavailable">Bug reporting is disabled as development settings aren\'t enabled</string> + <string name="power_menu_bug_report_unavailable_for_user">Bug reporting is disabled for non-primary users.</string> <string name="power_menu_lockdown_title">Lockdown</string> + <string name="power_menu_lockdown_unavailable">Lockdown is disabled as keyguard isn\'t secure</string> <string name="camera_double_tap_power_gesture_title">Press power button twice for camera</string> diff --git a/src/org/lineageos/lineageparts/input/PowerMenuActions.java b/src/org/lineageos/lineageparts/input/PowerMenuActions.java index a77b444..9809de4 100644 --- a/src/org/lineageos/lineageparts/input/PowerMenuActions.java +++ b/src/org/lineageos/lineageparts/input/PowerMenuActions.java @@ -27,6 +27,8 @@ import android.provider.Settings; import androidx.preference.CheckBoxPreference; import androidx.preference.Preference; +import com.android.internal.widget.LockPatternUtils; + import org.lineageos.internal.util.PowerMenuConstants; import org.lineageos.lineageparts.R; import org.lineageos.lineageparts.SettingsPreferenceFragment; @@ -51,6 +53,8 @@ public class PowerMenuActions extends SettingsPreferenceFragment { private LineageGlobalActions mLineageGlobalActions; Context mContext; + private LockPatternUtils mLockPatternUtils; + private UserManager mUserManager; private List<String> mLocalUserConfig = new ArrayList<String>(); @Override @@ -59,6 +63,8 @@ public class PowerMenuActions extends SettingsPreferenceFragment { addPreferencesFromResource(R.xml.power_menu_settings); mContext = getActivity().getApplicationContext(); + mLockPatternUtils = new LockPatternUtils(mContext); + mUserManager = UserManager.get(mContext); mLineageGlobalActions = LineageGlobalActions.getInstance(mContext); for (String action : PowerMenuConstants.getAllActions()) { @@ -97,8 +103,7 @@ public class PowerMenuActions extends SettingsPreferenceFragment { getPreferenceScreen().removePreference(findPreference(GLOBAL_ACTION_KEY_USERS)); mUsersPref = null; } else { - List<UserInfo> users = ((UserManager) mContext.getSystemService( - Context.USER_SERVICE)).getUsers(); + List<UserInfo> users = mUserManager.getUsers(); boolean enabled = (users.size() > 1); mUsersPref.setChecked(mLineageGlobalActions.userConfigContains( GLOBAL_ACTION_KEY_USERS) && enabled); @@ -139,6 +144,8 @@ public class PowerMenuActions extends SettingsPreferenceFragment { } else if (preference == mBugReportPref) { value = mBugReportPref.isChecked(); mLineageGlobalActions.updateUserConfig(value, GLOBAL_ACTION_KEY_BUGREPORT); + Settings.Global.putInt(getContentResolver(), + Settings.Global.BUGREPORT_IN_POWER_MENU, value ? 1 : 0); } else if (preference == mLockDownPref) { value = mLockDownPref.isChecked(); @@ -153,15 +160,38 @@ public class PowerMenuActions extends SettingsPreferenceFragment { } private void updatePreferences() { - boolean bugreport = Settings.Global.getInt(getContentResolver(), - Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0; - + UserInfo currentUser = mUserManager.getUserInfo(UserHandle.myUserId()); + boolean developmentSettings = Settings.Global.getInt( + getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) == 1; + boolean bugReport = Settings.Global.getInt( + getContentResolver(), Settings.Global.BUGREPORT_IN_POWER_MENU, 0) == 1; + boolean isPrimaryUser = currentUser == null || currentUser.isPrimary(); if (mBugReportPref != null) { - mBugReportPref.setEnabled(bugreport); - if (bugreport) { + mBugReportPref.setEnabled(developmentSettings && isPrimaryUser); + if (!developmentSettings) { + mBugReportPref.setChecked(false); + mBugReportPref.setSummary(R.string.power_menu_bug_report_devoptions_unavailable); + } else if (!isPrimaryUser) { + mBugReportPref.setChecked(false); + mBugReportPref.setSummary(R.string.power_menu_bug_report_unavailable_for_user); + } else { + mBugReportPref.setChecked(bugReport); mBugReportPref.setSummary(null); + } + } + + boolean isKeyguardSecure = mLockPatternUtils.isSecure(UserHandle.myUserId()); + boolean lockdown = Settings.Secure.getIntForUser( + getContentResolver(), Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0, + UserHandle.USER_CURRENT) == 1; + if (mLockDownPref != null) { + mLockDownPref.setEnabled(isKeyguardSecure); + if (isKeyguardSecure) { + mLockDownPref.setChecked(lockdown); + mLockDownPref.setSummary(null); } else { - mBugReportPref.setSummary(R.string.power_menu_bug_report_disabled); + mLockDownPref.setChecked(false); + mLockDownPref.setSummary(R.string.power_menu_lockdown_unavailable); } } } |