From fa351b4335b89c25fd81ae2796abcbb7012f8aac Mon Sep 17 00:00:00 2001 From: Adnan Date: Sun, 3 Aug 2014 15:52:05 -0700 Subject: [PATCH] Settings: Add option to scramble pin layout when unlocking (1/2). Change-Id: I3e2c200a0a31d3c765831bc30280029a50c88051 --- res/values/cm_strings.xml | 4 + res/xml/screen_lock_settings.xml | 8 +- .../PinScramblePreferenceController.java | 78 +++++++++++++++++++ .../screenlock/ScreenLockSettings.java | 2 + 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 src/com/android/settings/security/screenlock/PinScramblePreferenceController.java diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index 4059f1d7d35..ab2fa9d86e4 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -60,6 +60,10 @@ Navigation hint Show navigation hint bar at the bottom of the screen + + Scramble layout + Scramble PIN layout when unlocking device + Touchscreen gestures Perform various touchscreen gestures for quick actions diff --git a/res/xml/screen_lock_settings.xml b/res/xml/screen_lock_settings.xml index 9d6b6cb2ad3..e46d70c1bb2 100644 --- a/res/xml/screen_lock_settings.xml +++ b/res/xml/screen_lock_settings.xml @@ -45,7 +45,7 @@ android:key="enhancedPinPrivacy" android:title="@string/lockpattern_settings_enhanced_pin_privacy_title" android:summary="@string/lockpattern_settings_enhanced_pin_privacy_summary" /> - + + + + diff --git a/src/com/android/settings/security/screenlock/PinScramblePreferenceController.java b/src/com/android/settings/security/screenlock/PinScramblePreferenceController.java new file mode 100644 index 00000000000..6d7ae8a20cb --- /dev/null +++ b/src/com/android/settings/security/screenlock/PinScramblePreferenceController.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2018 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.security.screenlock; + +import android.app.admin.DevicePolicyManager; +import android.content.Context; +import androidx.preference.Preference; +import androidx.preference.TwoStatePreference; + +import com.android.internal.widget.LockPatternUtils; +import com.android.settings.core.PreferenceControllerMixin; +import com.android.settingslib.core.AbstractPreferenceController; + +import lineageos.providers.LineageSettings; + +public class PinScramblePreferenceController extends AbstractPreferenceController + implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener { + + static final String KEY_LOCKSCREEN_SCRAMBLE_PIN_LAYOUT = "lockscreen_scramble_pin_layout"; + + private final int mUserId; + private final LockPatternUtils mLockPatternUtils; + + public PinScramblePreferenceController(Context context, int userId, + LockPatternUtils lockPatternUtils) { + super(context); + mUserId = userId; + mLockPatternUtils = lockPatternUtils; + } + + @Override + public boolean isAvailable() { + return isPinLock(); + } + + @Override + public String getPreferenceKey() { + return KEY_LOCKSCREEN_SCRAMBLE_PIN_LAYOUT; + } + + @Override + public void updateState(Preference preference) { + ((TwoStatePreference) preference).setChecked(LineageSettings.System.getInt( + mContext.getContentResolver(), + LineageSettings.System.LOCKSCREEN_PIN_SCRAMBLE_LAYOUT, + 0) == 1); + } + + private boolean isPinLock() { + int quality = mLockPatternUtils.getKeyguardStoredPasswordQuality(mUserId); + boolean hasPin = quality == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC || + quality == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX; + return mLockPatternUtils.isSecure(mUserId) && hasPin; + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + LineageSettings.System.putInt( + mContext.getContentResolver(), + LineageSettings.System.LOCKSCREEN_PIN_SCRAMBLE_LAYOUT, + (Boolean) newValue ? 1 : 0); + return true; + } +} diff --git a/src/com/android/settings/security/screenlock/ScreenLockSettings.java b/src/com/android/settings/security/screenlock/ScreenLockSettings.java index c49ec43e6a1..f811872ee59 100644 --- a/src/com/android/settings/security/screenlock/ScreenLockSettings.java +++ b/src/com/android/settings/security/screenlock/ScreenLockSettings.java @@ -92,6 +92,8 @@ public class ScreenLockSettings extends DashboardFragment context, MY_USER_ID, lockPatternUtils)); controllers.add(new AutoPinConfirmPreferenceController( context, MY_USER_ID, lockPatternUtils, parent)); + controllers.add(new PinScramblePreferenceController( + context, MY_USER_ID, lockPatternUtils)); controllers.add(new OwnerInfoPreferenceController(context, parent)); return controllers; }