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

Commit 62b56b32 authored by Rubin Xu's avatar Rubin Xu
Browse files

Fix LockSettingsShellCommand handling of empty old credentials

Fix a crash when the device is secure but the user did not supply
the old credential when invoking LockSettingsShellCommand

Bug: 65239740
Test: adb shell cmd lock_settings set-pin  1254 when device has password
Change-Id: Id94f26c98984c6c09865ff45daeb76307f66dffb
parent 5387827d
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static com.android.internal.widget.LockPatternUtils.CREDENTIAL_TYPE_PATTE
import android.app.ActivityManager;
import android.app.admin.PasswordMetrics;
import android.os.ShellCommand;
import android.text.TextUtils;

import com.android.internal.widget.LockPatternUtils;
import com.android.internal.widget.LockPatternUtils.RequestThrottledException;
@@ -195,6 +196,9 @@ class LockSettingsShellCommand extends ShellCommand {
    }

    private LockscreenCredential getOldCredential() {
        if (TextUtils.isEmpty(mOld)) {
            return LockscreenCredential.createNone();
        }
        if (mLockPatternUtils.isLockPasswordEnabled(mCurrentUserId)) {
            final int quality = mLockPatternUtils.getKeyguardStoredPasswordQuality(mCurrentUserId);
            if (LockPatternUtils.isQualityAlphabeticPassword(quality)) {
@@ -202,12 +206,15 @@ class LockSettingsShellCommand extends ShellCommand {
            } else {
                return LockscreenCredential.createPin(mOld);
            }
        } else if (mLockPatternUtils.isLockPatternEnabled(mCurrentUserId)) {
        }
        if (mLockPatternUtils.isLockPatternEnabled(mCurrentUserId)) {
            return LockscreenCredential.createPattern(LockPatternUtils.byteArrayToPattern(
                    mOld.getBytes()));
        } else {
            return LockscreenCredential.createNone();
        }
        // User supplied some old credential but the device has neither password nor pattern,
        // so just return a password credential (and let it be rejected during LSS verification)
        return LockscreenCredential.createPassword(mOld);

    }

    private boolean runSetPattern() {