OSDN Git Service

Fix NPE in SecuritySettings.onResume()
authorMaggie Benthall <mbenthall@google.com>
Tue, 20 Aug 2013 15:03:05 +0000 (11:03 -0400)
committerMaggie Benthall <mbenthall@google.com>
Tue, 20 Aug 2013 15:03:05 +0000 (11:03 -0400)
when DISALLOW_CONFIG_CREDENTIALS is true.

Bug: 10405192
Change-Id: Id364ba3cd86151b504158bc253559d0da5e26273

src/com/android/settings/SecuritySettings.java

index f893c36..e5b5c45 100644 (file)
@@ -83,7 +83,7 @@ public class SecuritySettings extends RestrictedSettingsFragment
     private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
 
     private PackageManager mPM;
-    DevicePolicyManager mDPM;
+    private DevicePolicyManager mDPM;
 
     private ChooseLockSettingsHelper mChooseLockSettingsHelper;
     private LockPatternUtils mLockPatternUtils;
@@ -165,9 +165,6 @@ public class SecuritySettings extends RestrictedSettingsFragment
 
 
         // Add options for device encryption
-        DevicePolicyManager dpm =
-                (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
-
         mIsPrimary = UserHandle.myUserId() == UserHandle.USER_OWNER;
 
         if (!mIsPrimary) {
@@ -183,7 +180,7 @@ public class SecuritySettings extends RestrictedSettingsFragment
         }
 
         if (mIsPrimary) {
-            switch (dpm.getStorageEncryptionStatus()) {
+            switch (mDPM.getStorageEncryptionStatus()) {
             case DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE:
                 // The device is currently encrypted.
                 addPreferencesFromResource(R.xml.security_settings_encrypted);
@@ -247,8 +244,8 @@ public class SecuritySettings extends RestrictedSettingsFragment
 
         // 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)) {
-            mKeyStore = KeyStore.getInstance();
             Preference credentialStorageType = root.findPreference(KEY_CREDENTIAL_STORAGE_TYPE);
 
             final int storageSummaryRes =