Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit d4c32444 authored by Adnan's avatar Adnan Committed by Michael Bestas
Browse files

Settings: Add option to scramble pin layout when unlocking (1/2).

Change-Id: I3e2c200a0a31d3c765831bc30280029a50c88051
parent 82d0f82d
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -47,4 +47,8 @@
    <!-- Navigation bar hint -->
    <string name="show_navbar_hint_title">Navigation hint</string>
    <string name="show_navbar_hint_summary">Show navigation hint bar at the bottom of the screen</string>

    <!-- PIN scramble -->
    <string name="unlock_scramble_pin_layout_title">Scramble layout</string>
    <string name="unlock_scramble_pin_layout_summary">Scramble PIN layout when unlocking device</string>
</resources>
+5 −0
Original line number Diff line number Diff line
@@ -88,6 +88,11 @@
            android:title="@string/lockpattern_settings_enhanced_pin_privacy_title"
            android:summary="@string/lockpattern_settings_enhanced_pin_privacy_summary" />

        <!-- Lineage additions, available in pin -->
        <SwitchPreferenceCompat
            android:key="lockscreen_scramble_pin_layout"
            android:title="@string/unlock_scramble_pin_layout_title"
            android:summary="@string/unlock_scramble_pin_layout_summary" />

        <!-- available in pin/pattern/password -->
        <com.android.settings.security.screenlock.ProtectedTimeoutListPreference
+3 −0
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ import com.android.settings.security.screenlock.AutoPinConfirmPreferenceControll
import com.android.settings.security.screenlock.LockAfterTimeoutPreferenceController;
import com.android.settings.security.screenlock.PatternVisiblePreferenceController;
import com.android.settings.security.screenlock.PinPrivacyPreferenceController;
import com.android.settings.security.screenlock.PinScramblePreferenceController;
import com.android.settings.security.screenlock.PowerButtonInstantLockPreferenceController;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -711,6 +712,8 @@ public class ChooseLockGeneric extends SettingsActivity {
                    getContext(), mUserId, mLockPatternUtils));
            mUnlockSettingsControllers.add(new PinPrivacyPreferenceController(
                    getContext(), mUserId, mLockPatternUtils));
            mUnlockSettingsControllers.add(new PinScramblePreferenceController(
                    getContext(), mUserId, mLockPatternUtils));
            mUnlockSettingsControllers.add(new PowerButtonInstantLockPreferenceController(
                    getContext(), mUserId, mLockPatternUtils));
            mUnlockSettingsControllers.add(new LockAfterTimeoutPreferenceController(
+78 −0
Original line number Diff line number Diff line
/*
 * 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;
    }
}