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

Commit 30f0ff2a authored by Clara Bayarri's avatar Clara Bayarri Committed by Android (Google) Code Review
Browse files

Merge "Unlock Keystore/Keymaster separately for Work Challenge" into nyc-dev

parents 2bb39839 0a587d28
Loading
Loading
Loading
Loading
+34 −6
Original line number Diff line number Diff line
@@ -545,21 +545,49 @@ public class LockSettingsService extends ILockSettings.Stub {
        final UserManager um = (UserManager) mContext.getSystemService(USER_SERVICE);
        final KeyStore ks = KeyStore.getInstance();

        if (um.getUserInfo(userHandle).isManagedProfile()) {
            if (mLockPatternUtils.isSeparateProfileChallengeEnabled(userHandle)) {
                ks.onUserPasswordChanged(userHandle, password);
            } else {
                throw new RuntimeException("Can't set keystore password on a profile that "
                        + "doesn't have a profile challenge.");
            }
        } else {
            final List<UserInfo> profiles = um.getProfiles(userHandle);
            for (UserInfo pi : profiles) {
                // Change password on the given user and all its profiles that don't have
                // their own profile challenge enabled.
                if (pi.id == userHandle || (pi.isManagedProfile()
                        && !mLockPatternUtils.isSeparateProfileChallengeEnabled(pi.id))) {
                    ks.onUserPasswordChanged(pi.id, password);
                }
            }
        }
    }

    private void unlockKeystore(String password, int userHandle) {
        final UserManager um = (UserManager) mContext.getSystemService(USER_SERVICE);
        final KeyStore ks = KeyStore.getInstance();

        if (um.getUserInfo(userHandle).isManagedProfile()) {
            if (mLockPatternUtils.isSeparateProfileChallengeEnabled(userHandle)) {
                ks.unlock(userHandle, password);
            } else {
                throw new RuntimeException("Can't unlock a profile explicitly if it "
                        + "doesn't have a profile challenge.");
            }
        } else {
            final List<UserInfo> profiles = um.getProfiles(userHandle);
            for (UserInfo pi : profiles) {
                // Unlock the given user and all its profiles that don't have
                // their own profile challenge enabled.
                if (pi.id == userHandle || (pi.isManagedProfile()
                        && !mLockPatternUtils.isSeparateProfileChallengeEnabled(pi.id))) {
                    ks.unlock(pi.id, password);
                }
            }
        }
    }

    private void unlockUser(int userId, byte[] token, byte[] secret) {
        try {