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

Commit 13def43d authored by Michael Bestas's avatar Michael Bestas Committed by Sam Mortimer
Browse files

Forward port CM Screen Security settings (1/2)



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

Change-Id: Ie109e82c1fb2fd96b07e977e1cd76ae3acb865ff

Fix pattern visibility settings (1/2)

Change-Id: Ic627953c5df854c442671a98b5da539b994da18b

LockPatternUtils: Use the actual user id to set pattern size

Ticket: CYNGNOS-2462
Change-Id: Ia68e26ec2dfc23317135d933bc25204c1380bb02

LockSettings: fix build

Change-Id: Ic65b1a2af398faffb83776ee4013d47f79ab6619
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 9422492f
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -5118,10 +5118,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);
@@ -6258,6 +6261,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
@@ -48,6 +48,7 @@ interface ILockSettings {
            in ICheckCredentialProgressCallback progressCallback);
    VerifyCredentialResponse verifyCredential(in byte[] credential, int type, long challenge, int userId);
    VerifyCredentialResponse verifyTiedProfileChallenge(in byte[] credential, int type, long challenge, int userId);
    byte getLockPatternSize(int userId);
    boolean checkVoldPassword(int userId);
    @UnsupportedAppUsage
    boolean havePattern(int userId);
+78 −15
Original line number Diff line number Diff line
@@ -108,6 +108,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.
@@ -413,8 +418,8 @@ public class LockPatternUtils {
    public byte[] verifyPattern(List<LockPatternView.Cell> pattern, long challenge, int userId)
            throws RequestThrottledException {
        throwIfCalledOnMainThread();
        return verifyCredential(patternToByteArray(pattern), CREDENTIAL_TYPE_PATTERN, challenge,
                userId);
        return verifyCredential(patternToByteArray(pattern, userId),
                CREDENTIAL_TYPE_PATTERN, challenge, userId);
    }

    /**
@@ -438,8 +443,8 @@ public class LockPatternUtils {
            @Nullable CheckCredentialProgressCallback progressCallback)
            throws RequestThrottledException {
        throwIfCalledOnMainThread();
        return checkCredential(patternToByteArray(pattern), CREDENTIAL_TYPE_PATTERN, userId,
                progressCallback);
        return checkCredential(patternToByteArray(pattern, userId),
                CREDENTIAL_TYPE_PATTERN, userId, progressCallback);
    }

    /**
@@ -779,7 +784,7 @@ public class LockPatternUtils {
                    + MIN_LOCK_PATTERN_SIZE + " dots long.");
        }

        final byte[] bytePattern = patternToByteArray(pattern);
        final byte[] bytePattern = patternToByteArray(pattern, userId);
        final int currentQuality = getKeyguardStoredPasswordQuality(userId);
        setKeyguardStoredPasswordQuality(PASSWORD_QUALITY_SOMETHING, userId);
        try {
@@ -1184,11 +1189,11 @@ public class LockPatternUtils {
     * @deprecated Pass patterns as byte[] and use byteArrayToPattern
     */
    @Deprecated
    public static List<LockPatternView.Cell> stringToPattern(String string) {
    public static List<LockPatternView.Cell> stringToPattern(String string, byte gridSize) {
        if (string == null) {
            return null;
        }
        return byteArrayToPattern(string.getBytes());
        return byteArrayToPattern(string.getBytes(), gridSize);
    }

    /**
@@ -1196,16 +1201,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;
    }
@@ -1218,8 +1225,20 @@ public class LockPatternUtils {
     */
    @UnsupportedAppUsage
    @Deprecated
    public static String patternToString(List<LockPatternView.Cell> pattern) {
        return new String(patternToByteArray(pattern));
    public String patternToString(List<LockPatternView.Cell> pattern, int userId) {
        return patternToString(pattern, getLockPatternSize(userId));
    }

    /**
     * Serialize a pattern.
     * @param pattern The pattern.
     * @return The pattern in string form.
     * @deprecated Use patternToByteArray instead.
     */
    @UnsupportedAppUsage
    @Deprecated
    public static String patternToString(List<LockPatternView.Cell> pattern, byte gridSize) {
        return new String(patternToByteArray(pattern, gridSize));
    }


@@ -1228,16 +1247,26 @@ public class LockPatternUtils {
     * @param pattern The pattern.
     * @return The pattern in byte array form.
     */
    public static byte[] patternToByteArray(List<LockPatternView.Cell> pattern) {
    public byte[] patternToByteArray(List<LockPatternView.Cell> pattern, int userId) {
        return patternToByteArray(pattern, getLockPatternSize(userId));
    }

    /**
     * Serialize a pattern.
     * @param pattern The pattern.
     * @return The pattern in string form.
     */
    public static byte[] patternToByteArray(List<LockPatternView.Cell> pattern, byte gridSize) {
        if (pattern == null) {
            return new byte[0];
        }
        final int patternSize = pattern.size();
        LockPatternView.Cell.updateSize(gridSize);

        byte[] res = new byte[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;
    }
@@ -1267,7 +1296,7 @@ public class LockPatternUtils {
     * @return the hash of the pattern in a byte array.
     */
    @UnsupportedAppUsage
    public static byte[] patternToHash(List<LockPatternView.Cell> pattern) {
    public static byte[] patternToHash(List<LockPatternView.Cell> pattern, byte gridSize) {
        if (pattern == null) {
            return null;
        }
@@ -1276,7 +1305,7 @@ public class LockPatternUtils {
        byte[] res = new byte[patternSize];
        for (int i = 0; i < patternSize; i++) {
            LockPatternView.Cell cell = pattern.get(i);
            res[i] = (byte) (cell.getRow() * 3 + cell.getColumn());
            res[i] = (byte) (cell.getRow() * gridSize + cell.getColumn());
        }
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
@@ -1360,6 +1389,40 @@ public class LockPatternUtils {
        }
    }

    /**
     * @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.
Loading