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

Commit 4bbe003c authored by Adnan's avatar Adnan Committed by Luca Stefani
Browse files

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

Change-Id: I3e2c200a0a31d3c765831bc30280029a50c88051
parent ec0098cc
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -45,4 +45,8 @@

    <!-- Lock screen cover art -->
    <string name="lockscreen_media_art_title">Display media cover art</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>
+6 −0
Original line number Diff line number Diff line
@@ -40,4 +40,10 @@
        android:key="power_button_instantly_locks"
        android:title="@string/lockpattern_settings_enable_power_button_instantly_locks" />

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

</PreferenceScreen>
+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;
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -81,6 +81,8 @@ public class ScreenLockSettings extends DashboardFragment
                context, MY_USER_ID, lockPatternUtils));
        controllers.add(new LockAfterTimeoutPreferenceController(
                context, MY_USER_ID, lockPatternUtils));
        controllers.add(new PinScramblePreferenceController(
                context, MY_USER_ID, lockPatternUtils));
        controllers.add(new OwnerInfoPreferenceController(context, parent, lifecycle));
        return controllers;
    }