summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarcos Marado <mmarado@cyngn.com>2016-10-17 19:31:46 +0100
committerGerrit Code Review <gerrit@cyanogenmod.org>2016-10-28 03:03:00 -0700
commit7955711d5f9f55e889f65a8ec48c812ff900c4b3 (patch)
tree398faee53402f091645c9a9a4406c23848b6a307 /src
parenta12c0a3ff1fdaecf15813de454a5db2de966d5e5 (diff)
downloadpackages_apps_Settings-7955711d5f9f55e889f65a8ec48c812ff900c4b3.zip
packages_apps_Settings-7955711d5f9f55e889f65a8ec48c812ff900c4b3.tar.gz
packages_apps_Settings-7955711d5f9f55e889f65a8ec48c812ff900c4b3.tar.bz2
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
Diffstat (limited to 'src')
-rw-r--r--src/com/android/settings/SecuritySettings.java45
1 files changed, 27 insertions, 18 deletions
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