From 7955711d5f9f55e889f65a8ec48c812ff900c4b3 Mon Sep 17 00:00:00 2001 From: Marcos Marado Date: Mon, 17 Oct 2016 19:31:46 +0100 Subject: SecuritySettings: Fix KeyStore related NPE's Both "Show password" and "Credential storage" options depend on having a KeyStore. However, KeyStore assumes that there's an android.security.keystore service around. Let's validate if it indeed exists and not show those two sections if it doesn't, in order to avoid breakage. Issue: BUGDUMP-7995106 Change-Id: I30b74057aae42e72387087d1c1d847dd8524f87f --- src/com/android/settings/SecuritySettings.java | 45 +++++++++++++++----------- 1 file changed, 27 insertions(+), 18 deletions(-) (limited to 'src/com') diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java index 3513126..7db4a4e 100644 --- a/src/com/android/settings/SecuritySettings.java +++ b/src/com/android/settings/SecuritySettings.java @@ -31,6 +31,7 @@ import android.hardware.fingerprint.Fingerprint; import android.hardware.fingerprint.FingerprintManager; import android.os.Bundle; import android.os.PersistableBundle; +import android.os.ServiceManager; import android.os.UserHandle; import android.os.UserManager; import android.preference.ListPreference; @@ -449,26 +450,34 @@ public class SecuritySettings extends SettingsPreferenceFragment updateSmsSecuritySummary(smsSecurityCheck); } - // Show password - mShowPassword = (SwitchPreference) root.findPreference(KEY_SHOW_PASSWORD); - mResetCredentials = root.findPreference(KEY_RESET_CREDENTIALS); - - // Credential storage + // needed by Credential storage and Application install sections final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE); - mKeyStore = KeyStore.getInstance(); // needs to be initialized for onResume() - if (!um.hasUserRestriction(UserManager.DISALLOW_CONFIG_CREDENTIALS)) { - Preference credentialStorageType = root.findPreference(KEY_CREDENTIAL_STORAGE_TYPE); - final int storageSummaryRes = - mKeyStore.isHardwareBacked() ? R.string.credential_storage_type_hardware - : R.string.credential_storage_type_software; - credentialStorageType.setSummary(storageSummaryRes); - } else { - PreferenceGroup credentialsManager = (PreferenceGroup) - root.findPreference(KEY_CREDENTIALS_MANAGER); - credentialsManager.removePreference(root.findPreference(KEY_RESET_CREDENTIALS)); - credentialsManager.removePreference(root.findPreference(KEY_CREDENTIALS_INSTALL)); - credentialsManager.removePreference(root.findPreference(KEY_CREDENTIAL_STORAGE_TYPE)); + // Both "Show password" and "Credential storage" options depend on having a KeyStore. + // However, KeyStore assumes that there's an android.security.keystore service around. + // Let's validate if it indeed exists here, to avoid breakage. + if (ServiceManager.getService("android.security.keystore") != null) { + // Show password + mShowPassword = (SwitchPreference) root.findPreference(KEY_SHOW_PASSWORD); + mResetCredentials = root.findPreference(KEY_RESET_CREDENTIALS); + + // Credential storage + mKeyStore = KeyStore.getInstance(); // needs to be initialized for onResume() + + if (!um.hasUserRestriction(UserManager.DISALLOW_CONFIG_CREDENTIALS)) { + Preference credentialStorageType = root.findPreference(KEY_CREDENTIAL_STORAGE_TYPE); + + final int storageSummaryRes = + mKeyStore.isHardwareBacked() ? R.string.credential_storage_type_hardware + : R.string.credential_storage_type_software; + credentialStorageType.setSummary(storageSummaryRes); + } else { + PreferenceGroup credentialsManager = (PreferenceGroup) + root.findPreference(KEY_CREDENTIALS_MANAGER); + credentialsManager.removePreference(root.findPreference(KEY_RESET_CREDENTIALS)); + credentialsManager.removePreference(root.findPreference(KEY_CREDENTIALS_INSTALL)); + credentialsManager.removePreference(root.findPreference(KEY_CREDENTIAL_STORAGE_TYPE)); + } } // Application install -- cgit v1.1