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

Commit 552992ac authored by Janis Danisevskis's avatar Janis Danisevskis
Browse files

Enable the clear credentials buttons when wifi keys are installed.

This patch updates the ResetCredentialsPreferenceController to check the
WIFI keystore namespace if called by the primary user.

Test: Install a WIFI certificate or key and watch the
      "Clear credentials" button become enabled in the credential
      storage dialog of Settings.
Bug: 189601008
Merged-In: I69828b64a7e3c707c27b4582d64ff0ddb863a4ff
Change-Id: I69828b64a7e3c707c27b4582d64ff0ddb863a4ff
parent c0245bb9
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.settings.security;

import android.content.Context;
import android.os.UserManager;
import android.security.keystore.KeyProperties;
import android.security.keystore2.AndroidKeyStoreLoadStoreParameter;

import androidx.preference.PreferenceScreen;

@@ -35,6 +37,7 @@ public class ResetCredentialsPreferenceController extends RestrictedEncryptionPr
    private static final String KEY_RESET_CREDENTIALS = "credentials_reset";

    private final KeyStore mKeyStore;
    private final KeyStore mWifiKeyStore;

    private RestrictedPreference mPreference;

@@ -45,8 +48,19 @@ public class ResetCredentialsPreferenceController extends RestrictedEncryptionPr
            keyStore = KeyStore.getInstance("AndroidKeyStore");
            keyStore.load(null);
        } catch (Exception e) {
            keyStore = null;
        }
        mKeyStore = keyStore;
        keyStore = null;
        if (context.getUser().isSystem()) {
            try {
                keyStore = KeyStore.getInstance("AndroidKeyStore");
                keyStore.load(new AndroidKeyStoreLoadStoreParameter(KeyProperties.NAMESPACE_WIFI));
            } catch (Exception e) {
                keyStore = null;
            }
        }
        mWifiKeyStore = keyStore;
        if (lifecycle != null) {
            lifecycle.addObserver(this);
        }
@@ -68,9 +82,11 @@ public class ResetCredentialsPreferenceController extends RestrictedEncryptionPr
        if (mPreference != null && !mPreference.isDisabledByAdmin()) {
            boolean isEnabled = false;
            try {
                if (mKeyStore != null) {
                    isEnabled = mKeyStore.aliases().hasMoreElements();
                }
                isEnabled = (mKeyStore != null
                        && mKeyStore.aliases().hasMoreElements())
                        || (mWifiKeyStore != null
                        && mWifiKeyStore.aliases().hasMoreElements());

            } catch (KeyStoreException e) {
                // If access to keystore fails, treat as disabled.
            }