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

Commit cc4e5c54 authored by Ricky Wai's avatar Ricky Wai Committed by android-build-merger
Browse files

Merge "Use LockPatternUtils.resetKeyStore() to clear keystore" into nyc-dev

am: fec38d06

* commit 'fec38d06':
  Use LockPatternUtils.resetKeyStore() to clear keystore

Change-Id: I1231288f2e7c5166885992b103e720f467358858
parents ec4ea60b fec38d06
Loading
Loading
Loading
Loading
+16 −17
Original line number Diff line number Diff line
@@ -103,15 +103,10 @@ public final class CredentialStorage extends Activity {
    static final int MIN_PASSWORD_QUALITY = DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;

    private static final int CONFIRM_KEY_GUARD_REQUEST = 1;
    private static final int CONFIRM_CLEAR_SYSTEM_CREDENTIAL_REQUEST = 2;

    private final KeyStore mKeyStore = KeyStore.getInstance();

    /**
     * The UIDs that are used for system credential storage in keystore.
     */
    private static final int[] SYSTEM_CREDENTIAL_UIDS = {Process.WIFI_UID, Process.VPN_UID,
        Process.ROOT_UID, Process.SYSTEM_UID};

    /**
     * When non-null, the bundle containing credentials to install.
     */
@@ -197,7 +192,7 @@ public final class CredentialStorage extends Activity {
            return;
        }
        // force key guard confirmation
        if (confirmKeyGuard()) {
        if (confirmKeyGuard(CONFIRM_KEY_GUARD_REQUEST)) {
            // will return password value via onActivityResult
            return;
        }
@@ -328,9 +323,11 @@ public final class CredentialStorage extends Activity {
        @Override public void onDismiss(DialogInterface dialog) {
            if (mResetConfirmed) {
                mResetConfirmed = false;
                new ResetKeyStoreAndKeyChain().execute();
                if (confirmKeyGuard(CONFIRM_CLEAR_SYSTEM_CREDENTIAL_REQUEST)) {
                    // will return password value via onActivityResult
                    return;
                }
            }
            finish();
        }
    }
@@ -343,12 +340,7 @@ public final class CredentialStorage extends Activity {
        @Override protected Boolean doInBackground(Void... unused) {

            // Clear all the users credentials could have been installed in for this user.
            final UserManager um = (UserManager) getSystemService(USER_SERVICE);
            for (int userId : um.getProfileIdsWithDisabled(UserHandle.myUserId())) {
                for (int uid : SYSTEM_CREDENTIAL_UIDS) {
                    mKeyStore.clearUid(UserHandle.getUid(userId, uid));
                }
            }
            new LockPatternUtils(CredentialStorage.this).resetKeyStore(UserHandle.myUserId());

            try {
                KeyChainConnection keyChainConnection = KeyChain.bind(CredentialStorage.this);
@@ -454,10 +446,10 @@ public final class CredentialStorage extends Activity {
    /**
     * Confirm existing key guard, returning password via onActivityResult.
     */
    private boolean confirmKeyGuard() {
    private boolean confirmKeyGuard(int requestCode) {
        Resources res = getResources();
        boolean launched = new ChooseLockSettingsHelper(this)
                .launchConfirmationActivity(CONFIRM_KEY_GUARD_REQUEST,
                .launchConfirmationActivity(requestCode,
                        res.getText(R.string.credentials_title), true);
        return launched;
    }
@@ -481,6 +473,13 @@ public final class CredentialStorage extends Activity {
            }
            // failed confirmation, bail
            finish();
        } else if (requestCode == CONFIRM_CLEAR_SYSTEM_CREDENTIAL_REQUEST) {
            if (resultCode == Activity.RESULT_OK) {
                new ResetKeyStoreAndKeyChain().execute();
                return;
            }
            // failed confirmation, bail
            finish();
        }
    }