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

This commit is contained in:
Treehugger Robot
2021-06-03 09:56:49 +00:00
committed by Gerrit Code Review

View File

@@ -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.
}