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
This commit is contained in:
@@ -18,6 +18,8 @@ package com.android.settings.security;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
|
import android.security.keystore.KeyProperties;
|
||||||
|
import android.security.keystore2.AndroidKeyStoreLoadStoreParameter;
|
||||||
|
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
@@ -35,6 +37,7 @@ public class ResetCredentialsPreferenceController extends RestrictedEncryptionPr
|
|||||||
private static final String KEY_RESET_CREDENTIALS = "credentials_reset";
|
private static final String KEY_RESET_CREDENTIALS = "credentials_reset";
|
||||||
|
|
||||||
private final KeyStore mKeyStore;
|
private final KeyStore mKeyStore;
|
||||||
|
private final KeyStore mWifiKeyStore;
|
||||||
|
|
||||||
private RestrictedPreference mPreference;
|
private RestrictedPreference mPreference;
|
||||||
|
|
||||||
@@ -45,8 +48,19 @@ public class ResetCredentialsPreferenceController extends RestrictedEncryptionPr
|
|||||||
keyStore = KeyStore.getInstance("AndroidKeyStore");
|
keyStore = KeyStore.getInstance("AndroidKeyStore");
|
||||||
keyStore.load(null);
|
keyStore.load(null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
keyStore = null;
|
||||||
}
|
}
|
||||||
mKeyStore = keyStore;
|
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) {
|
if (lifecycle != null) {
|
||||||
lifecycle.addObserver(this);
|
lifecycle.addObserver(this);
|
||||||
}
|
}
|
||||||
@@ -68,9 +82,11 @@ public class ResetCredentialsPreferenceController extends RestrictedEncryptionPr
|
|||||||
if (mPreference != null && !mPreference.isDisabledByAdmin()) {
|
if (mPreference != null && !mPreference.isDisabledByAdmin()) {
|
||||||
boolean isEnabled = false;
|
boolean isEnabled = false;
|
||||||
try {
|
try {
|
||||||
if (mKeyStore != null) {
|
isEnabled = (mKeyStore != null
|
||||||
isEnabled = mKeyStore.aliases().hasMoreElements();
|
&& mKeyStore.aliases().hasMoreElements())
|
||||||
}
|
|| (mWifiKeyStore != null
|
||||||
|
&& mWifiKeyStore.aliases().hasMoreElements());
|
||||||
|
|
||||||
} catch (KeyStoreException e) {
|
} catch (KeyStoreException e) {
|
||||||
// If access to keystore fails, treat as disabled.
|
// If access to keystore fails, treat as disabled.
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user