Create security status preference category.

Bug: 31002801
Test: make RunSettingsRoboTests
Change-Id: I513253e79f91e41686bad9abac8548bb366fc98d
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 4b93d8c..275193c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -752,6 +752,8 @@
     <string name="security_passwords_title">Passwords</string>
     <!-- Summary for settings preference disabled by administrator [CHAR LIMIT=50] -->
     <string name="disabled_by_administrator_summary">Disabled by administrator</string>
+    <!-- In the security screen, the header title for security statuses -->
+    <string name="security_status_title">Security status</string>
 
     <!-- Fingerprint enrollment and settings --><skip />
     <!-- Title shown for menu item that launches fingerprint settings or enrollment [CHAR LIMIT=22] -->
diff --git a/res/xml/security_settings_status.xml b/res/xml/security_settings_status.xml
new file mode 100644
index 0000000..06930f9
--- /dev/null
+++ b/res/xml/security_settings_status.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+                  android:title="@string/security_settings_title">
+
+    <PreferenceCategory
+        android:key="security_status"
+        android:title="@string/security_status_title"/>
+
+</PreferenceScreen>
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index c06f872..436745f 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -126,9 +126,13 @@
     private static final String KEY_TRUST_AGENT = "trust_agent";
     private static final String KEY_SCREEN_PINNING = "screen_pinning_settings";
 
+    // Security status
+    private static final String KEY_SECURITY_STATUS = "security_status";
+    private static final String SECURITY_STATUS_KEY_PREFIX = "security_status_";
+
     // Package verifier Settings
     @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
-    static final String KEY_PACKAGE_VERIFIER_STATE = "package_verifier_state";
+    static final String KEY_PACKAGE_VERIFIER_STATUS = "security_status_package_verifier";
     private static final int PACKAGE_VERIFIER_STATE_ENABLED = 1;
 
     // These switch preferences need special handling since they're not all stored in Settings.
@@ -261,6 +265,9 @@
         addPreferencesFromResource(R.xml.security_settings);
         root = getPreferenceScreen();
 
+        // Add category for security status
+        addPreferencesFromResource(R.xml.security_settings_status);
+
         // Add options for lock/unlock screen
         final int resid = getResIdForLockUnlockScreen(getActivity(), mLockPatternUtils,
                 mManagedPasswordProvider, MY_USER_ID);
@@ -428,19 +435,38 @@
         Index.getInstance(getActivity())
                 .updateFromClassNameResource(SecuritySettings.class.getName(), true, true);
 
+        PreferenceGroup securityStatusPreferenceGroup =
+                (PreferenceGroup) root.findPreference(KEY_SECURITY_STATUS);
         if (mDashboardFeatureProvider.isEnabled()) {
             final List<Preference> tilePrefs = mDashboardFeatureProvider.getPreferencesForCategory(
                     getActivity(), getPrefContext(), CategoryKey.CATEGORY_SECURITY);
+            int numSecurityStatusPrefs = 0;
             if (tilePrefs != null && !tilePrefs.isEmpty()) {
                 for (Preference preference : tilePrefs) {
-                    root.addPreference(preference);
+                    if (!TextUtils.isEmpty(preference.getKey())
+                            && preference.getKey().startsWith(SECURITY_STATUS_KEY_PREFIX)) {
+                        // Injected security status settings are placed under the Security status
+                        // category.
+                        securityStatusPreferenceGroup.addPreference(preference);
+                        numSecurityStatusPrefs++;
+                    } else {
+                        // Other injected settings are placed under the Security preference screen.
+                        root.addPreference(preference);
+                    }
                 }
             }
 
-            // Update preference data with tile data. Security feature provider only updates the
-            // data if it actually needs to be changed.
-            mSecurityFeatureProvider.updatePreferences(getActivity(), root,
-                    mDashboardFeatureProvider.getTilesForCategory(CategoryKey.CATEGORY_SECURITY));
+            if (numSecurityStatusPrefs == 0) {
+                root.removePreference(securityStatusPreferenceGroup);
+            } else if (numSecurityStatusPrefs > 0) {
+                // Update preference data with tile data. Security feature provider only updates the
+                // data if it actually needs to be changed.
+                mSecurityFeatureProvider.updatePreferences(getActivity(), root,
+                        mDashboardFeatureProvider.getTilesForCategory(
+                                CategoryKey.CATEGORY_SECURITY));
+            }
+        } else {
+            root.removePreference(root.findPreference(KEY_SECURITY_STATUS));
         }
 
         for (int i = 0; i < SWITCH_PREFERENCE_KEYS.length; i++) {
@@ -1365,7 +1391,7 @@
             }
             for (int i = 0; i < tilesCount; i++) {
                 Tile tile = dashboardCategory.getTile(i);
-                if (!KEY_PACKAGE_VERIFIER_STATE.equals(tile.key)) {
+                if (!KEY_PACKAGE_VERIFIER_STATUS.equals(tile.key)) {
                     continue;
                 }
                 String summaryUri = tile.metaData.getString(
diff --git a/tests/robotests/src/com/android/settings/SecuritySettingsTest.java b/tests/robotests/src/com/android/settings/SecuritySettingsTest.java
index af853dc..92214e3 100644
--- a/tests/robotests/src/com/android/settings/SecuritySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/SecuritySettingsTest.java
@@ -144,7 +144,7 @@
     public void testGetPackageVerifierSummary_matchingTile() {
         when(mDashboardCategory.getTilesCount()).thenReturn(1);
         Tile tile = new Tile();
-        tile.key = SecuritySettings.KEY_PACKAGE_VERIFIER_STATE;
+        tile.key = SecuritySettings.KEY_PACKAGE_VERIFIER_STATUS;
         Bundle bundle = new Bundle();
         bundle.putString(TileUtils.META_DATA_PREFERENCE_SUMMARY_URI, "content://host/path");
         tile.metaData = bundle;