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

Unverified Commit 324e1c54 authored by Michael Bestas's avatar Michael Bestas Committed by Michael Bestas
Browse files

Forward port CM Screen Security settings (1/2)



 * Variable size pattern lockscreen
 * Toggle dots/error pattern visibility

Co-authored-by: default avatarDhina17 <dhinalogu@gmail.com>
Co-authored-by: default avatarRoman Birg <roman@cyngn.com>
Co-authored-by: default avatarScott Mertz <scott@cyngn.com>
Change-Id: Ic65b1a2af398faffb83776ee4013d47f79ab6619
parent 0c9cbec9
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -1336,9 +1336,11 @@ public class KeyguardManager {
                CharSequence pinStr = new String(password);
                return LockscreenCredential.createPin(pinStr);
            case PATTERN:
                byte patternSize = new LockPatternUtils(mContext).getLockPatternSize(
                        mContext.getUserId());
                List<LockPatternView.Cell> pattern =
                        LockPatternUtils.byteArrayToPattern(password);
                return LockscreenCredential.createPattern(pattern);
                        LockPatternUtils.byteArrayToPattern(password, patternSize);
                return LockscreenCredential.createPattern(pattern, patternSize);
            default:
                throw new IllegalArgumentException("Unknown lock type " + lockType);
        }
+22 −1
Original line number Diff line number Diff line
@@ -7060,10 +7060,13 @@ public final class Settings {
        @UnsupportedAppUsage
        private static final HashSet<String> MOVED_TO_GLOBAL;
        static {
            MOVED_TO_LOCK_SETTINGS = new HashSet<>(3);
            MOVED_TO_LOCK_SETTINGS = new HashSet<>(6);
            MOVED_TO_LOCK_SETTINGS.add(Secure.LOCK_PATTERN_ENABLED);
            MOVED_TO_LOCK_SETTINGS.add(Secure.LOCK_PATTERN_VISIBLE);
            MOVED_TO_LOCK_SETTINGS.add(Secure.LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED);
            MOVED_TO_LOCK_SETTINGS.add(Secure.LOCK_PATTERN_SIZE);
            MOVED_TO_LOCK_SETTINGS.add(Secure.LOCK_DOTS_VISIBLE);
            MOVED_TO_LOCK_SETTINGS.add(Secure.LOCK_SHOW_ERROR_PATH);
            MOVED_TO_GLOBAL = new HashSet<>();
            MOVED_TO_GLOBAL.add(Settings.Global.ADB_ENABLED);
@@ -8587,6 +8590,24 @@ public final class Settings {
        public static final String
                LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED = "lock_pattern_tactile_feedback_enabled";
        /**
         * Determines the width and height of the LockPatternView widget
         * @hide
         */
        public static final String LOCK_PATTERN_SIZE = "lock_pattern_size";
        /**
         * Whether lock pattern will show dots (0 = false, 1 = true)
         * @hide
         */
        public static final String LOCK_DOTS_VISIBLE = "lock_pattern_dotsvisible";
        /**
         * Whether lockscreen error pattern is visible (0 = false, 1 = true)
         * @hide
         */
        public static final String LOCK_SHOW_ERROR_PATH = "lock_pattern_show_error_path";
        /**
         * This preference allows the device to be locked given time after screen goes off,
         * subject to current DeviceAdmin policy limits.
+1 −0
Original line number Diff line number Diff line
@@ -110,4 +110,5 @@ interface ILockSettings {
    boolean isWeakEscrowTokenValid(long handle, in byte[] token, int userId);
    void unlockUserKeyIfUnsecured(int userId);
    boolean writeRepairModeCredential(int userId);
    byte getLockPatternSize(int userId);
}
+45 −4
Original line number Diff line number Diff line
@@ -106,6 +106,11 @@ public class LockPatternUtils {
     */
    public static final int MIN_LOCK_PASSWORD_SIZE = 4;

    /*
     * The default size of the pattern lockscreen. Ex: 3x3
     */
    public static final byte PATTERN_SIZE_DEFAULT = 3;

    /**
     * The minimum number of dots the user must include in a wrong pattern attempt for it to be
     * counted.
@@ -1014,16 +1019,18 @@ public class LockPatternUtils {
     * @param  bytes The pattern serialized with {@link #patternToByteArray}
     * @return The pattern.
     */
    public static List<LockPatternView.Cell> byteArrayToPattern(byte[] bytes) {
    public static List<LockPatternView.Cell> byteArrayToPattern(byte[] bytes, byte gridSize) {
        if (bytes == null) {
            return null;
        }

        List<LockPatternView.Cell> result = Lists.newArrayList();

        LockPatternView.Cell.updateSize(gridSize);

        for (int i = 0; i < bytes.length; i++) {
            byte b = (byte) (bytes[i] - '1');
            result.add(LockPatternView.Cell.of(b / 3, b % 3));
            result.add(LockPatternView.Cell.of(b / gridSize, b % gridSize, gridSize));
        }
        return result;
    }
@@ -1033,7 +1040,7 @@ public class LockPatternUtils {
     * @param pattern The pattern.
     * @return The pattern in byte array form.
     */
    public static byte[] patternToByteArray(List<LockPatternView.Cell> pattern) {
    public static byte[] patternToByteArray(List<LockPatternView.Cell> pattern, byte gridSize) {
        if (pattern == null) {
            return new byte[0];
        }
@@ -1042,7 +1049,7 @@ public class LockPatternUtils {
        byte[] res = newNonMovableByteArray(patternSize);
        for (int i = 0; i < patternSize; i++) {
            LockPatternView.Cell cell = pattern.get(i);
            res[i] = (byte) (cell.getRow() * 3 + cell.getColumn() + '1');
            res[i] = (byte) (cell.getRow() * gridSize + cell.getColumn() + '1');
        }
        return res;
    }
@@ -1112,6 +1119,40 @@ public class LockPatternUtils {
        return mCredentialTypeCache.query(userHandle);
    }

    /**
     * @return the pattern lockscreen size
     */
    public byte getLockPatternSize(int userId) {
        long size = getLong(Settings.Secure.LOCK_PATTERN_SIZE, -1, userId);
        if (size > 0 && size < 128) {
            return (byte) size;
        }
        return LockPatternUtils.PATTERN_SIZE_DEFAULT;
    }

    /**
     * Set the pattern lockscreen size
     */
    public void setLockPatternSize(long size, int userId) {
        setLong(Settings.Secure.LOCK_PATTERN_SIZE, size, userId);
    }

    public void setVisibleDotsEnabled(boolean enabled, int userId) {
        setBoolean(Settings.Secure.LOCK_DOTS_VISIBLE, enabled, userId);
    }

    public boolean isVisibleDotsEnabled(int userId) {
        return getBoolean(Settings.Secure.LOCK_DOTS_VISIBLE, true, userId);
    }

    public void setShowErrorPath(boolean enabled, int userId) {
        setBoolean(Settings.Secure.LOCK_SHOW_ERROR_PATH, enabled, userId);
    }

    public boolean isShowErrorPath(int userId) {
        return getBoolean(Settings.Secure.LOCK_SHOW_ERROR_PATH, true, userId);
    }

    /**
     * @param userId the user for which to report the value
     * @return Whether the lock screen is secured.
+177 −96

File changed.

Preview size limit exceeded, changes collapsed.

Loading