OSDN Git Service

Show trust agent entries as disabled rather than removing them.
authorJim Miller <jaggies@google.com>
Fri, 22 Aug 2014 02:24:47 +0000 (19:24 -0700)
committerJim Miller <jaggies@google.com>
Fri, 22 Aug 2014 02:46:26 +0000 (19:46 -0700)
Fixes bug 17108810

Change-Id: I646f5c299cd680d5c3a4978610f3852eba4b116b

res/values/strings.xml
src/com/android/settings/SecuritySettings.java

index 6e962d1..27509a5 100644 (file)
     <!-- Title of preference to manage trust agents -->
     <string name="manage_trust_agents">Trust agents</string>
 
+    <!-- Summary shown when trust agent settings is disabled because the user hasn't set up primary security -->
+    <string name="disabled_because_no_backup_security">To use, first set a screen lock</string>
+
     <!-- Summary of preference to manage device policies -->
     <string name="manage_trust_agents_summary">View or deactivate trust agents</string>
 
index d3a290b..7798937 100644 (file)
@@ -225,7 +225,8 @@ public class SecuritySettings extends SettingsPreferenceFragment
         // Trust Agent preferences
         PreferenceGroup securityCategory = (PreferenceGroup)
                 root.findPreference(KEY_SECURITY_CATEGORY);
-        if (securityCategory != null && mLockPatternUtils.isSecure()) {
+        if (securityCategory != null) {
+            final boolean hasSecurity = mLockPatternUtils.isSecure();
             ArrayList<TrustAgentComponentInfo> agents =
                     getActiveTrustAgents(getPackageManager(), mLockPatternUtils);
             for (int i = 0; i < agents.size(); i++) {
@@ -242,6 +243,10 @@ public class SecuritySettings extends SettingsPreferenceFragment
                 trustAgentPreference.setIntent(intent);
                 // Add preference to the settings menu.
                 securityCategory.addPreference(trustAgentPreference);
+                if (!hasSecurity) {
+                    trustAgentPreference.setEnabled(false);
+                    trustAgentPreference.setSummary(R.string.disabled_because_no_backup_security);
+                }
             }
         }
 
@@ -340,9 +345,12 @@ public class SecuritySettings extends SettingsPreferenceFragment
         // Advanced Security features
         PreferenceGroup advancedCategory =
                 (PreferenceGroup)root.findPreference(KEY_ADVANCED_SECURITY);
-        if (advancedCategory != null && !mLockPatternUtils.isSecure()) {
+        if (advancedCategory != null) {
             Preference manageAgents = advancedCategory.findPreference(KEY_MANAGE_TRUST_AGENTS);
-            if (manageAgents != null) advancedCategory.removePreference(manageAgents);
+            if (manageAgents != null && !mLockPatternUtils.isSecure()) {
+                manageAgents.setEnabled(false);
+                manageAgents.setSummary(R.string.disabled_because_no_backup_security);
+            }
         }
 
         // The above preferences come and go based on security state, so we need to update