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

Commit 2b98c25b authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Enable the clear credentials buttons when wifi keys are installed." am: 5f1034bc

Original change: https://android-review.googlesource.com/c/platform/packages/apps/Settings/+/1725994

Change-Id: I7a48bd13efccbb49ebd57ee298b7b71dd5410060
parents 38f9e01f 5f1034bc
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.
            }