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

Commit deb0af00 authored by Eric Biggers's avatar Eric Biggers
Browse files

locksettings: only log profile key removal when actually done

The message "Remove keystore profile key for user" is always being
logged at INFO level when a user's locksettings state is removed.
However, that step is only applicable for profiles, so usually it's
irrelevant and is a no-op.

It could serve as a hint that the user's locksettings state is being
removed.  However, there's already a proper log message for that.

So, let's first check whether the user actually has a profile key,
before attempting to remove it and logging that removal.

Bug: 268526331
Change-Id: I90f46bc4cf5bfe096b0b037c5b88a9a9be2dcdd6
parent 0b76af4d
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -2311,13 +2311,18 @@ public class LockSettingsService extends ILockSettings.Stub {
    }

    private void removeKeystoreProfileKey(int targetUserId) {
        Slog.i(TAG, "Remove keystore profile key for user: " + targetUserId);
        final String encryptAlias = PROFILE_KEY_NAME_ENCRYPT + targetUserId;
        final String decryptAlias = PROFILE_KEY_NAME_DECRYPT + targetUserId;
        try {
            mJavaKeyStore.deleteEntry(PROFILE_KEY_NAME_ENCRYPT + targetUserId);
            mJavaKeyStore.deleteEntry(PROFILE_KEY_NAME_DECRYPT + targetUserId);
            if (mJavaKeyStore.containsAlias(encryptAlias) ||
                    mJavaKeyStore.containsAlias(decryptAlias)) {
                Slogf.i(TAG, "Removing keystore profile key for user %d", targetUserId);
                mJavaKeyStore.deleteEntry(encryptAlias);
                mJavaKeyStore.deleteEntry(decryptAlias);
            }
        } catch (KeyStoreException e) {
            // We have tried our best to remove all keys
            Slog.e(TAG, "Unable to remove keystore profile key for user:" + targetUserId, e);
            // We have tried our best to remove the key.
            Slogf.e(TAG, e, "Error removing keystore profile key for user %d", targetUserId);
        }
    }