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

Commit 5f1034bc authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Enable the clear credentials buttons when wifi keys are installed."

parents c0245bb9 552992ac
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.
            }