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

Unverified Commit 546f5f35 authored by Marcos Marado's avatar Marcos Marado Committed by Adrian DC
Browse files

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.

RM-290

Issue: BUGDUMP-7995106

Change-Id: I30b74057aae42e72387087d1c1d847dd8524f87f
parent c8119566
Loading
Loading
Loading
Loading
+27 −18
Original line number Diff line number Diff line
@@ -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,13 +450,20 @@ public class SecuritySettings extends SettingsPreferenceFragment
                updateSmsSecuritySummary(smsSecurityCheck);
            }

            // needed by Credential storage and Application install sections
            final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);

            // 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
            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);

@@ -470,6 +478,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
                    credentialsManager.removePreference(root.findPreference(KEY_CREDENTIALS_INSTALL));
                    credentialsManager.removePreference(root.findPreference(KEY_CREDENTIAL_STORAGE_TYPE));
                }
            }

            // Application install
            PreferenceGroup deviceAdminCategory = (PreferenceGroup)