Merge "Remove Suggestion v1 code."
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c13e5f3..facfeab 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1287,6 +1287,28 @@
                 android:value="true" />
         </activity>
 
+        <!-- TODO(32953042) Merge with Settings$SecuritySettingsActivity -->
+        <activity android:name="Settings$SecuritySettingsActivityV2"
+                  android:label="@string/security_settings_title"
+                  android:icon="@drawable/ic_settings_security"
+                  android:enabled="false"
+                  android:configChanges="orientation|keyboardHidden|screenSize"
+                  android:taskAffinity=""
+                  android:parentActivityName="Settings">
+            <intent-filter android:priority="-1">
+                <action android:name="android.settings.SECURITY_SETTINGS" />
+                <action android:name="android.credentials.UNLOCK" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+            <intent-filter android:priority="4">
+                <action android:name="com.android.settings.action.SETTINGS" />
+            </intent-filter>
+            <meta-data android:name="com.android.settings.category"
+                       android:value="com.android.settings.category.ia.homepage" />
+            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+                       android:value="com.android.settings.security.SecuritySettingsV2" />
+        </activity>
+
         <activity android:name="MonitoringCertInfoActivity"
                 android:label=""
                 android:theme="@style/Transparent"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5cd42c3..a809c78 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -6926,7 +6926,7 @@
     <string name="notification_group_title">Notification category group</string>
 
     <!-- [CHAR LIMIT=100] Notification importance screen title -->
-    <string name="notification_importance_title">Importance</string>
+    <string name="notification_importance_title">Behavior</string>
 
     <!-- [CHAR LIMIT=100 BACKUP_MESSAGE_ID=1820188704793497324] Notification Importance: unspecified importance level description -->
     <string name="notification_importance_unspecified">Allow sound</string>
@@ -6991,6 +6991,9 @@
     <!-- [CHAR LIMIT=100] Notification Importance title: high importance level title -->
     <string name="notification_channel_summary_high">Urgent importance</string>
 
+    <!-- [CHAR LIMIT=100] Label for on/off toggle -->
+    <string name="notification_switch_label">Show notifications</string>
+
     <!-- Default Apps > Default notification assistant -->
     <string name="default_notification_assistant">Notification assistant</string>
 
@@ -7087,13 +7090,13 @@
     <string name="loading_notification_apps">Loading apps...</string>
 
     <!-- [CHAR LIMIT=NONE] Text appearing when app notifications are off -->
-    <string name="app_notifications_off_desc">Android is blocking this app\'s notifications from appearing on this device</string>
+    <string name="app_notifications_off_desc">At your request, Android is blocking this app\'s notifications from appearing on this device</string>
 
     <!-- [CHAR LIMIT=NONE] Text appearing when channel notifications are off -->
-    <string name="channel_notifications_off_desc">Android is blocking this category of notifications from appearing on this device</string>
+    <string name="channel_notifications_off_desc">At your request, Android is blocking this category of notifications from appearing on this device</string>
 
     <!-- [CHAR LIMIT=NONE] Text appearing when channel group notifications are off -->
-    <string name="channel_group_notifications_off_desc">Android is blocking this group of notifications from appearing on this device</string>
+    <string name="channel_group_notifications_off_desc">At your request, Android is blocking this group of notifications from appearing on this device</string>
 
     <!-- [CHAR LIMIT=NONE] App notification settings: channels title -->
     <string name="notification_channels">Categories</string>
diff --git a/res/xml/channel_notification_settings.xml b/res/xml/channel_notification_settings.xml
index fb2705a..c799c8b 100644
--- a/res/xml/channel_notification_settings.xml
+++ b/res/xml/channel_notification_settings.xml
@@ -15,7 +15,8 @@
 -->
 
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
-        xmlns:settings="http://schemas.android.com/apk/res-auto" >
+        xmlns:settings="http://schemas.android.com/apk/res-auto"
+        settings:initialExpandedChildrenCount="3">
 
     <com.android.settings.applications.LayoutPreference
         android:key="pref_app_header"
diff --git a/res/xml/notification_importance.xml b/res/xml/notification_importance.xml
index f801f3c..6f9cc0e 100644
--- a/res/xml/notification_importance.xml
+++ b/res/xml/notification_importance.xml
@@ -19,20 +19,15 @@
 
         <com.android.settings.widget.RadioButtonPreference
             android:key="importance_high"
-            android:title="@string/notification_importance_high_title"
-            android:summary="@string/notification_importance_high"
-        />
+            android:title="@string/notification_importance_high" />
         <com.android.settings.widget.RadioButtonPreference
             android:key="importance_default"
-            android:title="@string/notification_importance_default_title"
-            android:summary="@string/notification_importance_default" />
+            android:title="@string/notification_importance_default" />
         <com.android.settings.widget.RadioButtonPreference
             android:key="importance_low"
-            android:title="@string/notification_importance_low_title"
-            android:summary="@string/notification_importance_low" />
+            android:title="@string/notification_importance_low" />
         <com.android.settings.widget.RadioButtonPreference
             android:key="importance_min"
-            android:title="@string/notification_importance_min_title"
-            android:summary="@string/notification_importance_min" />
+            android:title="@string/notification_importance_min" />
 
 </PreferenceScreen>
diff --git a/res/xml/security_settings_v2.xml b/res/xml/security_settings_v2.xml
new file mode 100644
index 0000000..155ee70
--- /dev/null
+++ b/res/xml/security_settings_v2.xml
@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright (C) 2018 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"
+    xmlns:settings="http://schemas.android.com/apk/res-auto"
+    android:key="security_dashboard_page"
+    android:title="@string/security_settings_title"
+    settings:initialExpandedChildrenCount="9">
+
+    <!-- security_settings_status.xml -->
+    <PreferenceCategory
+        android:key="security_status"
+        android:title="@string/security_status_title" />
+
+    <!-- TODO Need security section -->
+
+    <!-- security_settings_misc.xml -->
+    <PreferenceCategory
+        android:key="security_settings_misc_category"
+        android:title="@string/security_passwords_title">
+
+        <Preference
+            android:key="location"
+            android:title="@string/location_settings_title"
+            android:fragment="com.android.settings.location.LocationSettings">
+        </Preference>
+
+        <SwitchPreference
+            android:key="show_password"
+            android:title="@string/show_password"
+            android:summary="@string/show_password_summary"/>
+
+    </PreferenceCategory>
+
+    <PreferenceCategory
+        android:key="security_settings_device_admin_category">
+
+        <Preference android:key="manage_device_admin"
+                    android:title="@string/manage_device_admin"
+                    android:persistent="false"
+                    android:fragment="com.android.settings.DeviceAdminSettings"/>
+
+        <Preference android:key="enterprise_privacy"
+                    android:title="@string/enterprise_privacy_settings"
+                    android:persistent="false"
+                    android:fragment="com.android.settings.enterprise.EnterprisePrivacySettings"/>
+
+    </PreferenceCategory>
+
+    <Preference android:key="sim_lock_settings"
+                android:title="@string/sim_lock_settings_category">
+
+        <intent android:action="android.intent.action.MAIN"
+                android:targetPackage="com.android.settings"
+                android:targetClass="com.android.settings.Settings$IccLockSettingsActivity"/>
+
+    </Preference>
+
+    <Preference
+        android:key="encryption_and_credential"
+        android:title="@string/encryption_and_credential_settings_title"
+        android:summary="@string/encryption_and_credential_settings_summary"
+        android:fragment="com.android.settings.security.EncryptionAndCredential"/>
+
+    <Preference android:key="manage_trust_agents"
+                android:title="@string/manage_trust_agents"
+                android:persistent="false"
+                android:fragment="com.android.settings.security.trustagent.TrustAgentSettings"/>
+
+    <Preference
+        android:key="screen_pinning_settings"
+        android:title="@string/screen_pinning_title"
+        android:summary="@string/summary_placeholder"
+        android:fragment="com.android.settings.security.ScreenPinningSettings"/>
+
+    <Preference android:key="security_misc_usage_access"
+                android:title="@string/usage_access_title"
+                android:fragment="com.android.settings.applications.manageapplications.ManageApplications">
+        <extra
+            android:name="classname"
+            android:value="com.android.settings.Settings$UsageAccessSettingsActivity" />
+    </Preference>
+
+</PreferenceScreen>
\ No newline at end of file
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 9314952..d21a061 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -68,6 +68,7 @@
     public static class AccessibilityContrastSettingsActivity extends SettingsActivity { /* empty */ }
     public static class AccessibilityDaltonizerSettingsActivity extends SettingsActivity { /* empty */ }
     public static class SecuritySettingsActivity extends SettingsActivity { /* empty */ }
+    public static class SecuritySettingsActivityV2 extends SettingsActivity { /* empty */ }
     public static class UsageAccessSettingsActivity extends SettingsActivity { /* empty */ }
     public static class LocationSettingsActivity extends SettingsActivity { /* empty */ }
     public static class PrivacySettingsActivity extends SettingsActivity { /* empty */ }
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index e684e5e..d3580d1 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -751,6 +751,7 @@
         PackageManager pm = getPackageManager();
         final UserManager um = UserManager.get(this);
         final boolean isAdmin = um.isAdminUser();
+        final FeatureFactory featureFactory = FeatureFactory.getFactory(this);
         boolean somethingChanged = false;
         String packageName = getPackageName();
         somethingChanged = setTileEnabled(
@@ -805,12 +806,26 @@
                 !isConnectedDeviceV2Enabled && !UserManager.isDeviceInDemoMode(this) /* enabled */,
                 isAdmin) || somethingChanged;
 
+        final boolean isSecurityV2Enabled = featureFactory.getSecurityFeatureProvider()
+                .isSecuritySettingsV2Enabled(this);
+
+        // Enable new security page if v2 enabled
+        somethingChanged = setTileEnabled(
+                new ComponentName(packageName,Settings.SecuritySettingsActivityV2.class.getName()),
+                isSecurityV2Enabled,
+                isAdmin) || somethingChanged;
+        // Enable old security page if v2 disabled
+        somethingChanged = setTileEnabled(
+                new ComponentName(packageName,Settings.SecuritySettingsActivity.class.getName()),
+                !isSecurityV2Enabled,
+                isAdmin) || somethingChanged;
+
         somethingChanged = setTileEnabled(new ComponentName(packageName,
                         Settings.SimSettingsActivity.class.getName()),
                 Utils.showSimCardTile(this), isAdmin)
                 || somethingChanged;
 
-        final boolean isBatterySettingsV2Enabled = FeatureFactory.getFactory(this)
+        final boolean isBatterySettingsV2Enabled = featureFactory
                 .getPowerUsageFeatureProvider(this)
                 .isBatteryV2Enabled();
         // Enable new battery page if v2 enabled
diff --git a/src/com/android/settings/core/FeatureFlags.java b/src/com/android/settings/core/FeatureFlags.java
index 55f0737..e88fb11 100644
--- a/src/com/android/settings/core/FeatureFlags.java
+++ b/src/com/android/settings/core/FeatureFlags.java
@@ -25,4 +25,5 @@
     public static final String CONNECTED_DEVICE_V2 = "settings_connected_device_v2";
     public static final String BATTERY_SETTINGS_V2 = "settings_battery_v2";
     public static final String BATTERY_DISPLAY_APP_LIST = "settings_battery_display_app_list";
+    public static final String SECURITY_SETTINGS_V2 = "settings_security_settings_v2";
 }
diff --git a/src/com/android/settings/core/TogglePreferenceController.java b/src/com/android/settings/core/TogglePreferenceController.java
index 99d2ecc..febd7ad 100644
--- a/src/com/android/settings/core/TogglePreferenceController.java
+++ b/src/com/android/settings/core/TogglePreferenceController.java
@@ -14,8 +14,8 @@
 package com.android.settings.core;
 
 import android.content.Context;
-import android.support.v14.preference.SwitchPreference;
 import android.support.v7.preference.Preference;
+import android.support.v7.preference.TwoStatePreference;
 
 /**
  * Abstract class that consolidates logic for updating toggle controllers.
@@ -45,7 +45,7 @@
 
     @Override
     public final void updateState(Preference preference) {
-        ((SwitchPreference) preference).setChecked(isChecked());
+        ((TwoStatePreference) preference).setChecked(isChecked());
     }
 
     @Override
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index b7c73f3..4c861fb 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -115,6 +115,7 @@
 import com.android.settings.security.CryptKeeperSettings;
 import com.android.settings.security.LockscreenDashboardFragment;
 import com.android.settings.security.SecuritySettings;
+import com.android.settings.security.SecuritySettingsV2;
 import com.android.settings.sim.SimSettings;
 import com.android.settings.support.SupportDashboardActivity;
 import com.android.settings.system.ResetDashboardFragment;
@@ -163,6 +164,7 @@
             NotificationStation.class.getName(),
             LocationSettings.class.getName(),
             SecuritySettings.class.getName(),
+            SecuritySettingsV2.class.getName(),
             UsageAccessDetails.class.getName(),
             PrivacySettings.class.getName(),
             DeviceAdminSettings.class.getName(),
diff --git a/src/com/android/settings/dashboard/DashboardFragmentRegistry.java b/src/com/android/settings/dashboard/DashboardFragmentRegistry.java
index e841496..0536403 100644
--- a/src/com/android/settings/dashboard/DashboardFragmentRegistry.java
+++ b/src/com/android/settings/dashboard/DashboardFragmentRegistry.java
@@ -33,7 +33,7 @@
 import com.android.settings.notification.ConfigureNotificationSettings;
 import com.android.settings.notification.SoundSettings;
 import com.android.settings.security.LockscreenDashboardFragment;
-import com.android.settings.security.SecuritySettings;
+import com.android.settings.security.SecuritySettingsV2;
 import com.android.settings.system.SystemDashboardFragment;
 import com.android.settingslib.drawer.CategoryKey;
 
@@ -77,7 +77,7 @@
                 CategoryKey.CATEGORY_SOUND);
         PARENT_TO_CATEGORY_KEY_MAP.put(StorageDashboardFragment.class.getName(),
                 CategoryKey.CATEGORY_STORAGE);
-        PARENT_TO_CATEGORY_KEY_MAP.put(SecuritySettings.class.getName(),
+        PARENT_TO_CATEGORY_KEY_MAP.put(SecuritySettingsV2.class.getName(),
                 CategoryKey.CATEGORY_SECURITY);
         PARENT_TO_CATEGORY_KEY_MAP.put(AccountDetailDashboardFragment.class.getName(),
                 CategoryKey.CATEGORY_ACCOUNT_DETAIL);
diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java
index af168d6..ef0f40b 100644
--- a/src/com/android/settings/notification/AppNotificationSettings.java
+++ b/src/com/android/settings/notification/AppNotificationSettings.java
@@ -135,7 +135,6 @@
         return new ArrayList<>(mControllers);
     }
 
-
     private void populateList() {
         if (!mDynamicPreferences.isEmpty()) {
             // If there's anything in mChannelGroups, we've called populateChannelList twice.
@@ -164,61 +163,41 @@
     }
 
     private void populateGroupList() {
-        PreferenceCategory groupCategory = new PreferenceCategory(getPrefContext());
-        groupCategory.setTitle(R.string.notification_channels);
-        groupCategory.setKey(KEY_GENERAL_CATEGORY);
-        groupCategory.setOrderingAsAdded(true);
-        getPreferenceScreen().addPreference(groupCategory);
-        mDynamicPreferences.add(groupCategory);
         for (NotificationChannelGroup group : mChannelGroupList) {
-            final List<NotificationChannel> channels = group.getChannels();
-            int N = channels.size();
-            // app defined groups with one channel and channels with no group display the channel
-            // name and no summary and link directly to the channel page unless the group is blocked
-            if ((group.getId() == null || N < 2) && !group.isBlocked()) {
-                Collections.sort(channels, mChannelComparator);
-                for (int i = 0; i < N; i++) {
-                    final NotificationChannel channel = channels.get(i);
-                    populateSingleChannelPrefs(groupCategory, channel, "");
-                }
+            PreferenceCategory groupCategory = new PreferenceCategory(getPrefContext());
+            groupCategory.setOrderingAsAdded(true);
+            getPreferenceScreen().addPreference(groupCategory);
+            mDynamicPreferences.add(groupCategory);
+            if (group.getId() == null) {
+                groupCategory.setTitle(mChannelGroupList.size() > 1
+                        ? R.string.notification_channels_other
+                        : R.string.notification_channels);
+                groupCategory.setKey(KEY_GENERAL_CATEGORY);
             } else {
-                populateGroupPreference(groupCategory, group, N);
+                groupCategory.setTitle(group.getName());
+                groupCategory.setKey(group.getId());
+                Bundle groupArgs = new Bundle();
+                groupArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
+                groupArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mPkg);
+                groupArgs.putString(Settings.EXTRA_CHANNEL_GROUP_ID, group.getId());
+                Intent channelIntent = Utils.onBuildStartFragmentIntent(getActivity(),
+                        ChannelGroupNotificationSettings.class.getName(),
+                        groupArgs, null, R.string.notification_group_title,
+                        null, false, getMetricsCategory());
+                groupCategory.setIntent(channelIntent);
+                populateGroupToggle(groupCategory, group);
+            }
+
+            final List<NotificationChannel> channels = group.getChannels();
+            Collections.sort(channels, mChannelComparator);
+            int N = channels.size();
+            for (int i = 0; i < N; i++) {
+                final NotificationChannel channel = channels.get(i);
+                populateSingleChannelPrefs(groupCategory, channel, group.isBlocked());
             }
         }
     }
 
-    void populateGroupPreference(PreferenceGroup parent,
-            final NotificationChannelGroup group, int channelCount) {
-        MasterSwitchPreference groupPref = new MasterSwitchPreference(
-                getPrefContext());
-        groupPref.setSwitchEnabled(mSuspendedAppsAdmin == null
-                && isChannelGroupBlockable(group));
-        groupPref.setKey(group.getId());
-        groupPref.setTitle(group.getName());
-        groupPref.setChecked(!group.isBlocked());
-        groupPref.setSummary(getResources().getQuantityString(
-                R.plurals.notification_group_summary, channelCount, channelCount));
-        Bundle groupArgs = new Bundle();
-        groupArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
-        groupArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mPkg);
-        groupArgs.putString(Settings.EXTRA_CHANNEL_GROUP_ID, group.getId());
-        Intent groupIntent = Utils.onBuildStartFragmentIntent(getActivity(),
-                ChannelGroupNotificationSettings.class.getName(),
-                groupArgs, null, R.string.notification_group_title, null, false,
-                getMetricsCategory());
-        groupPref.setIntent(groupIntent);
-
-        groupPref.setOnPreferenceChangeListener(
-                (preference, o) -> {
-                    boolean value = (Boolean) o;
-                    group.setBlocked(!value);
-                    mBackend.updateChannelGroup(mPkg, mUid, group);
-
-                    return true;
-                });
-        parent.addPreference(groupPref);
-    }
-
     private Comparator<NotificationChannelGroup> mChannelGroupComparator =
             new Comparator<NotificationChannelGroup>() {
 
diff --git a/src/com/android/settings/notification/BlockPreferenceController.java b/src/com/android/settings/notification/BlockPreferenceController.java
index 5c366ea..6b65b0f 100644
--- a/src/com/android/settings/notification/BlockPreferenceController.java
+++ b/src/com/android/settings/notification/BlockPreferenceController.java
@@ -67,6 +67,8 @@
         LayoutPreference pref = (LayoutPreference) preference;
         SwitchBar bar = pref.findViewById(R.id.switch_bar);
         if (bar != null) {
+            bar.setSwitchBarText(R.string.notification_switch_label,
+                    R.string.notification_switch_label);
             bar.show();
             try {
                 bar.addOnSwitchChangeListener(this);
diff --git a/src/com/android/settings/notification/ChannelGroupNotificationSettings.java b/src/com/android/settings/notification/ChannelGroupNotificationSettings.java
index 68dd91b..707a559 100644
--- a/src/com/android/settings/notification/ChannelGroupNotificationSettings.java
+++ b/src/com/android/settings/notification/ChannelGroupNotificationSettings.java
@@ -19,7 +19,6 @@
 import android.app.NotificationChannel;
 import android.content.Context;
 import android.support.v7.preference.Preference;
-import android.text.TextUtils;
 import android.util.Log;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
@@ -98,9 +97,7 @@
             Collections.sort(channels, mChannelComparator);
             for (NotificationChannel channel : channels) {
                 mDynamicPreferences.add(populateSingleChannelPrefs(
-                        getPreferenceScreen(), channel,
-                        ImportancePreferenceController.getImportanceSummary(
-                                getPrefContext(), channel)));
+                        getPreferenceScreen(), channel, mChannelGroup.isBlocked()));
             }
 
         }
diff --git a/src/com/android/settings/notification/ImportancePreferenceController.java b/src/com/android/settings/notification/ImportancePreferenceController.java
index ba47c54..977cd9a 100644
--- a/src/com/android/settings/notification/ImportancePreferenceController.java
+++ b/src/com/android/settings/notification/ImportancePreferenceController.java
@@ -73,7 +73,8 @@
             if (preference.isEnabled()) {
                 Intent channelIntent = Utils.onBuildStartFragmentIntent(mContext,
                         ChannelImportanceSettings.class.getName(),
-                        channelArgs, null, R.string.notification_importance_title, null,
+                        channelArgs, null,
+                        R.string.notification_importance_title, null,
                         false, getMetricsCategory());
                 preference.setIntent(channelIntent);
                 preference.setSummary(getImportanceSummary(mContext, mChannel));
@@ -82,23 +83,19 @@
     }
 
     protected static String getImportanceSummary(Context context, NotificationChannel channel) {
-        String title;
-        String summary = null;
+        String summary = "";
         int importance = channel.getImportance();
         switch (importance) {
             case IMPORTANCE_UNSPECIFIED:
-                title = context.getString(R.string.notification_importance_unspecified);
+                summary = context.getString(R.string.notification_importance_unspecified);
                 break;
             case NotificationManager.IMPORTANCE_MIN:
-                title = context.getString(R.string.notification_importance_min_title);
                 summary = context.getString(R.string.notification_importance_min);
                 break;
             case NotificationManager.IMPORTANCE_LOW:
-                title = context.getString(R.string.notification_importance_low_title);
                 summary = context.getString(R.string.notification_importance_low);
                 break;
             case NotificationManager.IMPORTANCE_DEFAULT:
-                title = context.getString(R.string.notification_importance_default_title);
                 if (SoundPreferenceController.hasValidSound(channel)) {
                     summary = context.getString(R.string.notification_importance_default);
                 } else {
@@ -107,7 +104,6 @@
                 break;
             case NotificationManager.IMPORTANCE_HIGH:
             case NotificationManager.IMPORTANCE_MAX:
-                title = context.getString(R.string.notification_importance_high_title);
                 if (SoundPreferenceController.hasValidSound(channel)) {
                     summary = context.getString(R.string.notification_importance_high);
                 } else {
@@ -118,10 +114,6 @@
                 return "";
         }
 
-        if (summary != null) {
-            return context.getString(R.string.notification_importance_divider, title, summary);
-        } else {
-            return title;
-        }
+        return summary;
     }
 }
diff --git a/src/com/android/settings/notification/NotificationSettingsBase.java b/src/com/android/settings/notification/NotificationSettingsBase.java
index 9afb618..2a7e7d5 100644
--- a/src/com/android/settings/notification/NotificationSettingsBase.java
+++ b/src/com/android/settings/notification/NotificationSettingsBase.java
@@ -61,6 +61,7 @@
 import android.provider.SearchIndexableResource;
 import android.provider.Settings;
 import android.service.notification.NotificationListenerService;
+import android.support.v14.preference.SwitchPreference;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceGroup;
 import android.support.v7.preference.PreferenceScreen;
@@ -214,7 +215,6 @@
         }
         for (ResolveInfo ri : resolveInfos) {
             final ActivityInfo activityInfo = ri.activityInfo;
-            final ApplicationInfo appInfo = activityInfo.applicationInfo;
             if (mAppRow.settingsIntent != null) {
                 if (DEBUG) {
                     Log.d(TAG, "Ignoring duplicate notification preference activity ("
@@ -225,7 +225,8 @@
             }
             mAppRow.settingsIntent = intent
                     .setPackage(null)
-                    .setClassName(activityInfo.packageName, activityInfo.name);
+                    .setClassName(activityInfo.packageName, activityInfo.name)
+                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
             if (mChannel != null) {
                 mAppRow.settingsIntent.putExtra(Notification.EXTRA_CHANNEL_ID, mChannel.getId());
             }
@@ -257,17 +258,41 @@
         return null;
     }
 
+    protected void populateGroupToggle(final PreferenceGroup parent,
+            NotificationChannelGroup group) {
+        RestrictedSwitchPreference preference = new RestrictedSwitchPreference(getPrefContext());
+        preference.setTitle(R.string.notification_switch_label);
+        preference.setEnabled(mSuspendedAppsAdmin == null
+                && isChannelGroupBlockable(group));
+        preference.setChecked(!group.isBlocked());
+        preference.setOnPreferenceClickListener(preference1 -> {
+            final boolean allowGroup = ((SwitchPreference) preference1).isChecked();
+            group.setBlocked(!allowGroup);
+            mBackend.updateChannelGroup(mAppRow.pkg, mAppRow.uid, group);
+
+            for (int i = 0; i < parent.getPreferenceCount(); i++) {
+                Preference pref = parent.getPreference(i);
+                if (pref instanceof MasterSwitchPreference) {
+                    ((MasterSwitchPreference) pref).setSwitchEnabled(allowGroup);
+                }
+            }
+            return true;
+        });
+
+        parent.addPreference(preference);
+    }
+
     protected Preference populateSingleChannelPrefs(PreferenceGroup parent,
-            final NotificationChannel channel, String summary) {
+            final NotificationChannel channel, final boolean groupBlocked) {
         MasterSwitchPreference channelPref = new MasterSwitchPreference(
                 getPrefContext());
         channelPref.setSwitchEnabled(mSuspendedAppsAdmin == null
                 && isChannelBlockable(channel)
-                && isChannelConfigurable(channel));
+                && isChannelConfigurable(channel)
+                && !groupBlocked);
         channelPref.setKey(channel.getId());
         channelPref.setTitle(channel.getName());
         channelPref.setChecked(channel.getImportance() != IMPORTANCE_NONE);
-        channelPref.setSummary(summary);
         Bundle channelArgs = new Bundle();
         channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
         channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mPkg);
@@ -288,7 +313,6 @@
                         channel.setImportance(importance);
                         channel.lockFields(
                                 NotificationChannel.USER_LOCKED_IMPORTANCE);
-                        channelPref.setSummary(summary);
                         mBackend.updateChannel(mPkg, mUid, channel);
 
                         return true;
diff --git a/src/com/android/settings/security/ScreenPinningPreferenceController.java b/src/com/android/settings/security/ScreenPinningPreferenceController.java
new file mode 100644
index 0000000..60279c7
--- /dev/null
+++ b/src/com/android/settings/security/ScreenPinningPreferenceController.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+package com.android.settings.security;
+
+import android.content.Context;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+
+public class ScreenPinningPreferenceController extends BasePreferenceController {
+
+    private static final String KEY_SCREEN_PINNING = "screen_pinning_settings";
+
+    public ScreenPinningPreferenceController(Context context) {
+        super(context, KEY_SCREEN_PINNING);
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return AVAILABLE;
+    }
+
+    @Override
+    public void displayPreference(PreferenceScreen screen) {
+        super.displayPreference(screen);
+        final Preference preference = screen.findPreference(getPreferenceKey());
+        if (preference == null) {
+            return;
+        }
+        if (Settings.System.getInt(mContext.getContentResolver(),
+                Settings.System.LOCK_TO_APP_ENABLED, 0) != 0) {
+            preference.setSummary(
+                    mContext.getString(R.string.switch_on_text));
+        } else {
+            preference.setSummary(
+                    mContext.getString(R.string.switch_off_text));
+        }
+    }
+}
diff --git a/src/com/android/settings/security/SecurityFeatureProvider.java b/src/com/android/settings/security/SecurityFeatureProvider.java
index 509446d..35ff586 100644
--- a/src/com/android/settings/security/SecurityFeatureProvider.java
+++ b/src/com/android/settings/security/SecurityFeatureProvider.java
@@ -18,7 +18,10 @@
 
 import android.content.Context;
 import android.support.v7.preference.PreferenceScreen;
+import android.util.FeatureFlagUtils;
 
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.core.FeatureFlags;
 import com.android.settings.security.trustagent.TrustAgentManager;
 import com.android.settingslib.drawer.DashboardCategory;
 
@@ -26,10 +29,19 @@
 /** FeatureProvider for security. */
 public interface SecurityFeatureProvider {
 
+    default boolean isSecuritySettingsV2Enabled(Context context) {
+        return FeatureFlagUtils.isEnabled(context, FeatureFlags.SECURITY_SETTINGS_V2);
+    }
+
     /** Update preferences with data from associated tiles. */
     void updatePreferences(Context context, PreferenceScreen preferenceScreen,
             DashboardCategory dashboardCategory);
 
     /** Returns the {@link TrustAgentManager} bound to this {@link SecurityFeatureProvider}. */
     TrustAgentManager getTrustAgentManager();
+
+    /**
+     * Returns a {@link LockPatternUtils} instance bound to application context.
+     */
+    LockPatternUtils getLockPatternUtils(Context context);
 }
diff --git a/src/com/android/settings/security/SecurityFeatureProviderImpl.java b/src/com/android/settings/security/SecurityFeatureProviderImpl.java
index 29aaefe..70b1ec1 100644
--- a/src/com/android/settings/security/SecurityFeatureProviderImpl.java
+++ b/src/com/android/settings/security/SecurityFeatureProviderImpl.java
@@ -29,6 +29,7 @@
 import android.util.ArrayMap;
 import android.util.Pair;
 
+import com.android.internal.widget.LockPatternUtils;
 import com.android.settings.R;
 import com.android.settings.security.trustagent.TrustAgentManager;
 import com.android.settingslib.drawer.DashboardCategory;
@@ -43,6 +44,7 @@
 public class SecurityFeatureProviderImpl implements SecurityFeatureProvider {
 
     private TrustAgentManager mTrustAgentManager;
+    private LockPatternUtils mLockPatternUtils;
 
     @VisibleForTesting
     static final Drawable DEFAULT_ICON = null;
@@ -195,4 +197,12 @@
         }
         return mTrustAgentManager;
     }
+
+    @Override
+    public LockPatternUtils getLockPatternUtils(Context context) {
+        if (mLockPatternUtils == null) {
+            mLockPatternUtils = new LockPatternUtils(context.getApplicationContext());
+        }
+        return mLockPatternUtils;
+    }
 }
diff --git a/src/com/android/settings/security/SecuritySettingsV2.java b/src/com/android/settings/security/SecuritySettingsV2.java
new file mode 100644
index 0000000..a957c8c
--- /dev/null
+++ b/src/com/android/settings/security/SecuritySettingsV2.java
@@ -0,0 +1,819 @@
+package com.android.settings.security;
+
+import android.app.Activity;
+import android.app.admin.DevicePolicyManager;
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.hardware.fingerprint.FingerprintManager;
+import android.os.Bundle;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.os.storage.StorageManager;
+import android.provider.SearchIndexableResource;
+import android.support.annotation.VisibleForTesting;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceGroup;
+import android.support.v7.preference.PreferenceScreen;
+import android.text.TextUtils;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.R;
+import com.android.settings.Utils;
+import com.android.settings.dashboard.DashboardFeatureProvider;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.dashboard.SummaryLoader;
+import com.android.settings.enterprise.EnterprisePrivacyPreferenceController;
+import com.android.settings.enterprise.ManageDeviceAdminPreferenceController;
+import com.android.settings.fingerprint.FingerprintSettings;
+import com.android.settings.location.LocationPreferenceController;
+import com.android.settings.notification.LockScreenNotificationPreferenceController;
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.password.ChooseLockGeneric;
+import com.android.settings.password.ChooseLockSettingsHelper;
+import com.android.settings.password.ManagedLockPasswordProvider;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.SearchIndexableRaw;
+import com.android.settings.security.screenlock.ScreenLockSettings;
+import com.android.settings.security.trustagent.ManageTrustAgentsPreferenceController;
+import com.android.settings.security.trustagent.TrustAgentManager;
+import com.android.settings.widget.GearPreference;
+import com.android.settingslib.RestrictedLockUtils;
+import com.android.settingslib.RestrictedPreference;
+import com.android.settingslib.RestrictedSwitchPreference;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.drawer.CategoryKey;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SecuritySettingsV2 extends DashboardFragment
+        implements Preference.OnPreferenceChangeListener,
+        GearPreference.OnGearClickListener {
+
+    private static final String TAG = "SecuritySettingsV2";
+
+    private static final String TRUST_AGENT_CLICK_INTENT = "trust_agent_click_intent";
+
+    // Lock Settings
+    private static final String KEY_UNLOCK_SET_OR_CHANGE = "unlock_set_or_change";
+    private static final String KEY_UNLOCK_SET_OR_CHANGE_PROFILE = "unlock_set_or_change_profile";
+    private static final String KEY_VISIBLE_PATTERN_PROFILE = "visiblepattern_profile";
+    private static final String KEY_SECURITY_CATEGORY = "security_category";
+    private static final String KEY_UNIFICATION = "unification";
+    @VisibleForTesting
+    static final String KEY_LOCKSCREEN_PREFERENCES = "lockscreen_preferences";
+    private static final String KEY_ENCRYPTION_AND_CREDENTIALS = "encryption_and_credential";
+    private static final String KEY_LOCATION_SCANNING = "location_scanning";
+    private static final String KEY_LOCATION = "location";
+
+    private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123;
+    private static final int CHANGE_TRUST_AGENT_SETTINGS = 126;
+    private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST_PROFILE = 127;
+    private static final int UNIFY_LOCK_CONFIRM_DEVICE_REQUEST = 128;
+    private static final int UNIFY_LOCK_CONFIRM_PROFILE_REQUEST = 129;
+    private static final int UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST = 130;
+    private static final String TAG_UNIFICATION_DIALOG = "unification_dialog";
+
+    // Misc Settings
+    private static final String KEY_TRUST_AGENT = "trust_agent";
+
+    // Security status
+    private static final String KEY_SECURITY_STATUS = "security_status";
+    private static final String SECURITY_STATUS_KEY_PREFIX = "security_status_";
+
+    // Device management settings
+    private static final String KEY_ENTERPRISE_PRIVACY = "enterprise_privacy";
+    private static final String KEY_MANAGE_DEVICE_ADMIN = "manage_device_admin";
+
+    // These switch preferences need special handling since they're not all stored in Settings.
+    private static final String SWITCH_PREFERENCE_KEYS[] = {
+            KEY_UNIFICATION, KEY_VISIBLE_PATTERN_PROFILE
+    };
+
+    private static final int MY_USER_ID = UserHandle.myUserId();
+
+    private DashboardFeatureProvider mDashboardFeatureProvider;
+    private DevicePolicyManager mDPM;
+    private SecurityFeatureProvider mSecurityFeatureProvider;
+    private TrustAgentManager mTrustAgentManager;
+    private UserManager mUm;
+
+    private ChooseLockSettingsHelper mChooseLockSettingsHelper;
+    private LockPatternUtils mLockPatternUtils;
+    private ManagedLockPasswordProvider mManagedPasswordProvider;
+
+    private SwitchPreference mVisiblePatternProfile;
+    private RestrictedSwitchPreference mUnifyProfile;
+
+    private Intent mTrustAgentClickIntent;
+
+    private int mProfileChallengeUserId;
+
+    private String mCurrentDevicePassword;
+    private String mCurrentProfilePassword;
+
+    private LocationPreferenceController mLocationController;
+    private ManageDeviceAdminPreferenceController mManageDeviceAdminPreferenceController;
+    private EnterprisePrivacyPreferenceController mEnterprisePrivacyPreferenceController;
+    private LockScreenNotificationPreferenceController mLockScreenNotificationPreferenceController;
+    private ManageTrustAgentsPreferenceController mManageTrustAgentsPreferenceController;
+    private ScreenPinningPreferenceController mScreenPinningPreferenceController;
+    private SimLockPreferenceController mSimLockPreferenceController;
+    private ShowPasswordPreferenceController mShowPasswordPreferenceController;
+
+    @Override
+    public int getMetricsCategory() {
+        return MetricsProto.MetricsEvent.SECURITY;
+    }
+
+    @Override
+    public void onAttach(Context context) {
+        super.onAttach(context);
+        mSecurityFeatureProvider = FeatureFactory.getFactory(context).getSecurityFeatureProvider();
+        mLocationController = new LocationPreferenceController(context, getLifecycle());
+        mLockPatternUtils = mSecurityFeatureProvider.getLockPatternUtils(context);
+        mManagedPasswordProvider = ManagedLockPasswordProvider.get(context, MY_USER_ID);
+        mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
+        mUm = UserManager.get(context);
+        mDashboardFeatureProvider = FeatureFactory.getFactory(context)
+                .getDashboardFeatureProvider(context);
+
+        mTrustAgentManager = mSecurityFeatureProvider.getTrustAgentManager();
+    }
+
+    @Override
+    protected int getPreferenceScreenResId() {
+        return R.xml.security_settings_v2;
+    }
+
+    @Override
+    protected String getLogTag() {
+        return TAG;
+    }
+
+    @Override
+    protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
+        mManageDeviceAdminPreferenceController
+                = new ManageDeviceAdminPreferenceController(context);
+        mEnterprisePrivacyPreferenceController
+                = new EnterprisePrivacyPreferenceController(context);
+        mLockScreenNotificationPreferenceController
+                = new LockScreenNotificationPreferenceController(context);
+        mManageTrustAgentsPreferenceController = new ManageTrustAgentsPreferenceController(context);
+        mScreenPinningPreferenceController = new ScreenPinningPreferenceController(context);
+        mSimLockPreferenceController = new SimLockPreferenceController(context);
+        mShowPasswordPreferenceController = new ShowPasswordPreferenceController(context);
+        return null;
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        mChooseLockSettingsHelper = new ChooseLockSettingsHelper(getActivity());
+
+        if (savedInstanceState != null
+                && savedInstanceState.containsKey(TRUST_AGENT_CLICK_INTENT)) {
+            mTrustAgentClickIntent = savedInstanceState.getParcelable(TRUST_AGENT_CLICK_INTENT);
+        }
+    }
+
+    private static int getResIdForLockUnlockScreen(LockPatternUtils lockPatternUtils,
+            ManagedLockPasswordProvider managedPasswordProvider, int userId) {
+        final boolean isMyUser = userId == MY_USER_ID;
+        int resid = 0;
+        if (!lockPatternUtils.isSecure(userId)) {
+            if (!isMyUser) {
+                resid = R.xml.security_settings_lockscreen_profile;
+            } else if (lockPatternUtils.isLockScreenDisabled(userId)) {
+                resid = R.xml.security_settings_lockscreen;
+            } else {
+                resid = R.xml.security_settings_chooser;
+            }
+        } else {
+            switch (lockPatternUtils.getKeyguardStoredPasswordQuality(userId)) {
+                case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
+                    resid = isMyUser ? R.xml.security_settings_pattern
+                            : R.xml.security_settings_pattern_profile;
+                    break;
+                case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
+                case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
+                    resid = isMyUser ? R.xml.security_settings_pin
+                            : R.xml.security_settings_pin_profile;
+                    break;
+                case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
+                case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
+                case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
+                    resid = isMyUser ? R.xml.security_settings_password
+                            : R.xml.security_settings_password_profile;
+                    break;
+                case DevicePolicyManager.PASSWORD_QUALITY_MANAGED:
+                    resid = managedPasswordProvider.getResIdForLockUnlockScreen(!isMyUser);
+                    break;
+            }
+        }
+        return resid;
+    }
+
+    /**
+     * Important!
+     *
+     * Don't forget to update the SecuritySearchIndexProvider if you are doing any change in the
+     * logic or adding/removing preferences here.
+     */
+    private PreferenceScreen createPreferenceHierarchy() {
+        PreferenceScreen root = getPreferenceScreen();
+        if (root != null) {
+            root.removeAll();
+        }
+        addPreferencesFromResource(R.xml.security_settings_v2);
+        root = getPreferenceScreen();
+
+        // Add options for lock/unlock screen
+        final int resid = getResIdForLockUnlockScreen(mLockPatternUtils,
+                mManagedPasswordProvider, MY_USER_ID);
+        addPreferencesFromResource(resid);
+
+        // DO or PO installed in the user may disallow to change password.
+        disableIfPasswordQualityManaged(KEY_UNLOCK_SET_OR_CHANGE, MY_USER_ID);
+
+        mProfileChallengeUserId = Utils.getManagedProfileId(mUm, MY_USER_ID);
+        if (mProfileChallengeUserId != UserHandle.USER_NULL
+                && mLockPatternUtils.isSeparateProfileChallengeAllowed(mProfileChallengeUserId)) {
+            addPreferencesFromResource(R.xml.security_settings_profile);
+            addPreferencesFromResource(R.xml.security_settings_unification);
+            final int profileResid = getResIdForLockUnlockScreen(mLockPatternUtils,
+                    mManagedPasswordProvider, mProfileChallengeUserId);
+            addPreferencesFromResource(profileResid);
+            maybeAddFingerprintPreference(root, mProfileChallengeUserId);
+            if (!mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId)) {
+                final Preference lockPreference =
+                        root.findPreference(KEY_UNLOCK_SET_OR_CHANGE_PROFILE);
+                final String summary = getContext().getString(
+                        R.string.lock_settings_profile_unified_summary);
+                lockPreference.setSummary(summary);
+                lockPreference.setEnabled(false);
+                // PO may disallow to change password for the profile, but screen lock and managed
+                // profile's lock is the same. Disable main "Screen lock" menu.
+                disableIfPasswordQualityManaged(KEY_UNLOCK_SET_OR_CHANGE, mProfileChallengeUserId);
+            } else {
+                // PO may disallow to change profile password, and the profile's password is
+                // separated from screen lock password. Disable profile specific "Screen lock" menu.
+                disableIfPasswordQualityManaged(KEY_UNLOCK_SET_OR_CHANGE_PROFILE,
+                        mProfileChallengeUserId);
+            }
+        }
+
+        Preference unlockSetOrChange = findPreference(KEY_UNLOCK_SET_OR_CHANGE);
+        if (unlockSetOrChange instanceof GearPreference) {
+            ((GearPreference) unlockSetOrChange).setOnGearClickListener(this);
+        }
+
+
+        // Fingerprint and trust agents
+        PreferenceGroup securityCategory = (PreferenceGroup)
+                root.findPreference(KEY_SECURITY_CATEGORY);
+        if (securityCategory != null) {
+            maybeAddFingerprintPreference(securityCategory, UserHandle.myUserId());
+            addTrustAgentSettings(securityCategory);
+            setLockscreenPreferencesSummary(securityCategory);
+        }
+
+        mVisiblePatternProfile =
+                (SwitchPreference) root.findPreference(KEY_VISIBLE_PATTERN_PROFILE);
+        mUnifyProfile = (RestrictedSwitchPreference) root.findPreference(KEY_UNIFICATION);
+
+        mSimLockPreferenceController.displayPreference(root);
+        mScreenPinningPreferenceController.displayPreference(root);
+
+        // Encryption status of device
+        if (LockPatternUtils.isDeviceEncryptionEnabled()) {
+            root.findPreference(KEY_ENCRYPTION_AND_CREDENTIALS).setSummary(
+                    R.string.encryption_and_credential_settings_summary);
+        } else {
+            root.findPreference(KEY_ENCRYPTION_AND_CREDENTIALS).setSummary(
+                    R.string.summary_placeholder);
+        }
+
+        // Advanced Security features
+        mManageTrustAgentsPreferenceController.displayPreference(root);
+
+        PreferenceGroup securityStatusPreferenceGroup =
+                (PreferenceGroup) root.findPreference(KEY_SECURITY_STATUS);
+        final List<Preference> tilePrefs = mDashboardFeatureProvider.getPreferencesForCategory(
+                getActivity(), getPrefContext(), getMetricsCategory(),
+                CategoryKey.CATEGORY_SECURITY);
+        int numSecurityStatusPrefs = 0;
+        if (tilePrefs != null && !tilePrefs.isEmpty()) {
+            for (Preference preference : tilePrefs) {
+                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);
+                }
+            }
+        }
+
+        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));
+        }
+
+        for (int i = 0; i < SWITCH_PREFERENCE_KEYS.length; i++) {
+            final Preference pref = findPreference(SWITCH_PREFERENCE_KEYS[i]);
+            if (pref != null) pref.setOnPreferenceChangeListener(this);
+        }
+
+        mLocationController.displayPreference(root);
+        mManageDeviceAdminPreferenceController.updateState(
+                root.findPreference(KEY_MANAGE_DEVICE_ADMIN));
+        mEnterprisePrivacyPreferenceController.displayPreference(root);
+        final Preference enterprisePrivacyPreference = root.findPreference(
+                mEnterprisePrivacyPreferenceController.getPreferenceKey());
+        mEnterprisePrivacyPreferenceController.updateState(enterprisePrivacyPreference);
+
+        return root;
+    }
+
+    @VisibleForTesting
+    void setLockscreenPreferencesSummary(PreferenceGroup group) {
+        final Preference lockscreenPreferences = group.findPreference(KEY_LOCKSCREEN_PREFERENCES);
+        if (lockscreenPreferences != null) {
+            lockscreenPreferences.setSummary(
+                    mLockScreenNotificationPreferenceController.getSummaryResource());
+        }
+    }
+
+    /*
+     * Sets the preference as disabled by admin if PASSWORD_QUALITY_MANAGED is set.
+     * The preference must be a RestrictedPreference.
+     */
+    private void disableIfPasswordQualityManaged(String preferenceKey, int userId) {
+        final RestrictedLockUtils.EnforcedAdmin admin =
+                RestrictedLockUtils.checkIfPasswordQualityIsSet(
+                        getActivity(), userId);
+        if (admin != null && mDPM.getPasswordQuality(admin.component, userId) ==
+                DevicePolicyManager.PASSWORD_QUALITY_MANAGED) {
+            final RestrictedPreference pref =
+                    (RestrictedPreference) getPreferenceScreen().findPreference(preferenceKey);
+            pref.setDisabledByAdmin(admin);
+        }
+    }
+
+    private void maybeAddFingerprintPreference(PreferenceGroup securityCategory, int userId) {
+        Preference fingerprintPreference =
+                FingerprintSettings.getFingerprintPreferenceForUser(
+                        securityCategory.getContext(), userId);
+        if (fingerprintPreference != null) {
+            securityCategory.addPreference(fingerprintPreference);
+        }
+    }
+
+    // Return the number of trust agents being added
+    private int addTrustAgentSettings(PreferenceGroup securityCategory) {
+        final boolean hasSecurity = mLockPatternUtils.isSecure(MY_USER_ID);
+        final List<TrustAgentManager.TrustAgentComponentInfo> agents =
+                mTrustAgentManager.getActiveTrustAgents(getActivity(), mLockPatternUtils);
+        for (TrustAgentManager.TrustAgentComponentInfo agent : agents) {
+            final RestrictedPreference trustAgentPreference =
+                    new RestrictedPreference(securityCategory.getContext());
+            trustAgentPreference.setKey(KEY_TRUST_AGENT);
+            trustAgentPreference.setTitle(agent.title);
+            trustAgentPreference.setSummary(agent.summary);
+            // Create intent for this preference.
+            Intent intent = new Intent();
+            intent.setComponent(agent.componentName);
+            intent.setAction(Intent.ACTION_MAIN);
+            trustAgentPreference.setIntent(intent);
+            // Add preference to the settings menu.
+            securityCategory.addPreference(trustAgentPreference);
+
+            trustAgentPreference.setDisabledByAdmin(agent.admin);
+            if (!trustAgentPreference.isDisabledByAdmin() && !hasSecurity) {
+                trustAgentPreference.setEnabled(false);
+                trustAgentPreference.setSummary(R.string.disabled_because_no_backup_security);
+            }
+        }
+        return agents.size();
+    }
+
+    @Override
+    public void onGearClick(GearPreference p) {
+        if (KEY_UNLOCK_SET_OR_CHANGE.equals(p.getKey())) {
+            startFragment(this, ScreenLockSettings.class.getName(), 0, 0, null);
+        }
+    }
+
+    @Override
+    public void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+        if (mTrustAgentClickIntent != null) {
+            outState.putParcelable(TRUST_AGENT_CLICK_INTENT, mTrustAgentClickIntent);
+        }
+    }
+
+    @Override
+    public void onResume() {
+        super.onResume();
+
+        // Make sure we reload the preference hierarchy since some of these settings
+        // depend on others...
+        createPreferenceHierarchy();
+
+        if (mVisiblePatternProfile != null) {
+            mVisiblePatternProfile.setChecked(mLockPatternUtils.isVisiblePatternEnabled(
+                    mProfileChallengeUserId));
+        }
+
+        updateUnificationPreference();
+        final Preference showPasswordPref = getPreferenceScreen().findPreference(
+                mShowPasswordPreferenceController.getPreferenceKey());
+        showPasswordPref.setOnPreferenceChangeListener(mShowPasswordPreferenceController);
+        mShowPasswordPreferenceController.updateState(showPasswordPref);
+        mLocationController.updateSummary();
+    }
+
+    @VisibleForTesting
+    void updateUnificationPreference() {
+        if (mUnifyProfile != null) {
+            final boolean separate =
+                    mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId);
+            mUnifyProfile.setChecked(!separate);
+            if (separate) {
+                mUnifyProfile.setDisabledByAdmin(RestrictedLockUtils.checkIfRestrictionEnforced(
+                        getContext(), UserManager.DISALLOW_UNIFIED_PASSWORD,
+                        mProfileChallengeUserId));
+            }
+        }
+    }
+
+    @Override
+    public boolean onPreferenceTreeClick(Preference preference) {
+        final String key = preference.getKey();
+        if (KEY_UNLOCK_SET_OR_CHANGE.equals(key)) {
+            // TODO(b/35930129): Remove once existing password can be passed into vold directly.
+            // Currently we need this logic to ensure that the QUIET_MODE is off for any work
+            // profile with unified challenge on FBE-enabled devices. Otherwise, vold would not be
+            // able to complete the operation due to the lack of (old) encryption key.
+            if (mProfileChallengeUserId != UserHandle.USER_NULL
+                    && !mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId)
+                    && StorageManager.isFileEncryptedNativeOnly()) {
+                if (Utils.startQuietModeDialogIfNecessary(this.getActivity(), mUm,
+                        mProfileChallengeUserId)) {
+                    return false;
+                }
+            }
+            startFragment(this, ChooseLockGeneric.ChooseLockGenericFragment.class.getName(),
+                    R.string.lock_settings_picker_title, SET_OR_CHANGE_LOCK_METHOD_REQUEST, null);
+        } else if (KEY_UNLOCK_SET_OR_CHANGE_PROFILE.equals(key)) {
+            if (Utils.startQuietModeDialogIfNecessary(this.getActivity(), mUm,
+                    mProfileChallengeUserId)) {
+                return false;
+            }
+            Bundle extras = new Bundle();
+            extras.putInt(Intent.EXTRA_USER_ID, mProfileChallengeUserId);
+            startFragment(this, ChooseLockGeneric.ChooseLockGenericFragment.class.getName(),
+                    R.string.lock_settings_picker_title_profile,
+                    SET_OR_CHANGE_LOCK_METHOD_REQUEST_PROFILE, extras);
+        } else if (KEY_TRUST_AGENT.equals(key)) {
+            ChooseLockSettingsHelper helper =
+                    new ChooseLockSettingsHelper(this.getActivity(), this);
+            mTrustAgentClickIntent = preference.getIntent();
+            boolean confirmationLaunched = helper.launchConfirmationActivity(
+                    CHANGE_TRUST_AGENT_SETTINGS, preference.getTitle());
+            if (!confirmationLaunched && mTrustAgentClickIntent != null) {
+                // If this returns false, it means no password confirmation is required.
+                startActivity(mTrustAgentClickIntent);
+                mTrustAgentClickIntent = null;
+            }
+        } else {
+            // If we didn't handle it, let preferences handle it.
+            return super.onPreferenceTreeClick(preference);
+        }
+        return true;
+    }
+
+    /**
+     * see confirmPatternThenDisableAndClear
+     */
+    @Override
+    public void onActivityResult(int requestCode, int resultCode, Intent data) {
+        super.onActivityResult(requestCode, resultCode, data);
+        if (requestCode == CHANGE_TRUST_AGENT_SETTINGS && resultCode == Activity.RESULT_OK) {
+            if (mTrustAgentClickIntent != null) {
+                startActivity(mTrustAgentClickIntent);
+                mTrustAgentClickIntent = null;
+            }
+            return;
+        } else if (requestCode == UNIFY_LOCK_CONFIRM_DEVICE_REQUEST
+                && resultCode == Activity.RESULT_OK) {
+            mCurrentDevicePassword =
+                    data.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
+            launchConfirmProfileLockForUnification();
+            return;
+        } else if (requestCode == UNIFY_LOCK_CONFIRM_PROFILE_REQUEST
+                && resultCode == Activity.RESULT_OK) {
+            mCurrentProfilePassword =
+                    data.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
+            unifyLocks();
+            return;
+        } else if (requestCode == UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST
+                && resultCode == Activity.RESULT_OK) {
+            ununifyLocks();
+            return;
+        }
+        createPreferenceHierarchy();
+    }
+
+    void launchConfirmDeviceLockForUnification() {
+        final String title = getActivity().getString(
+                R.string.unlock_set_unlock_launch_picker_title);
+        final ChooseLockSettingsHelper helper =
+                new ChooseLockSettingsHelper(getActivity(), this);
+        if (!helper.launchConfirmationActivity(
+                UNIFY_LOCK_CONFIRM_DEVICE_REQUEST, title, true, MY_USER_ID)) {
+            launchConfirmProfileLockForUnification();
+        }
+    }
+
+    private void launchConfirmProfileLockForUnification() {
+        final String title = getActivity().getString(
+                R.string.unlock_set_unlock_launch_picker_title_profile);
+        final ChooseLockSettingsHelper helper =
+                new ChooseLockSettingsHelper(getActivity(), this);
+        if (!helper.launchConfirmationActivity(
+                UNIFY_LOCK_CONFIRM_PROFILE_REQUEST, title, true, mProfileChallengeUserId)) {
+            unifyLocks();
+            createPreferenceHierarchy();
+        }
+    }
+
+    private void unifyLocks() {
+        int profileQuality =
+                mLockPatternUtils.getKeyguardStoredPasswordQuality(mProfileChallengeUserId);
+        if (profileQuality == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) {
+            mLockPatternUtils.saveLockPattern(
+                    LockPatternUtils.stringToPattern(mCurrentProfilePassword),
+                    mCurrentDevicePassword, MY_USER_ID);
+        } else {
+            mLockPatternUtils.saveLockPassword(
+                    mCurrentProfilePassword, mCurrentDevicePassword,
+                    profileQuality, MY_USER_ID);
+        }
+        mLockPatternUtils.setSeparateProfileChallengeEnabled(mProfileChallengeUserId, false,
+                mCurrentProfilePassword);
+        final boolean profilePatternVisibility =
+                mLockPatternUtils.isVisiblePatternEnabled(mProfileChallengeUserId);
+        mLockPatternUtils.setVisiblePatternEnabled(profilePatternVisibility, MY_USER_ID);
+        mCurrentDevicePassword = null;
+        mCurrentProfilePassword = null;
+    }
+
+    void unifyUncompliantLocks() {
+        mLockPatternUtils.setSeparateProfileChallengeEnabled(mProfileChallengeUserId, false,
+                mCurrentProfilePassword);
+        startFragment(this, ChooseLockGeneric.ChooseLockGenericFragment.class.getName(),
+                R.string.lock_settings_picker_title, SET_OR_CHANGE_LOCK_METHOD_REQUEST, null);
+    }
+
+    private void ununifyLocks() {
+        Bundle extras = new Bundle();
+        extras.putInt(Intent.EXTRA_USER_ID, mProfileChallengeUserId);
+        startFragment(this,
+                ChooseLockGeneric.ChooseLockGenericFragment.class.getName(),
+                R.string.lock_settings_picker_title_profile,
+                SET_OR_CHANGE_LOCK_METHOD_REQUEST_PROFILE, extras);
+    }
+
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object value) {
+        boolean result = true;
+        final String key = preference.getKey();
+        final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
+        if (KEY_VISIBLE_PATTERN_PROFILE.equals(key)) {
+            if (Utils.startQuietModeDialogIfNecessary(this.getActivity(), mUm,
+                    mProfileChallengeUserId)) {
+                return false;
+            }
+            lockPatternUtils.setVisiblePatternEnabled((Boolean) value, mProfileChallengeUserId);
+        } else if (KEY_UNIFICATION.equals(key)) {
+            if (Utils.startQuietModeDialogIfNecessary(this.getActivity(), mUm,
+                    mProfileChallengeUserId)) {
+                return false;
+            }
+            if ((Boolean) value) {
+                final boolean compliantForDevice =
+                        (mLockPatternUtils.getKeyguardStoredPasswordQuality(mProfileChallengeUserId)
+                                >= DevicePolicyManager.PASSWORD_QUALITY_SOMETHING
+                                && mLockPatternUtils.isSeparateProfileChallengeAllowedToUnify(
+                                mProfileChallengeUserId));
+                UnificationConfirmationDialog dialog =
+                        UnificationConfirmationDialog.newIntance(compliantForDevice);
+                dialog.show(getChildFragmentManager(), TAG_UNIFICATION_DIALOG);
+            } else {
+                final String title = getActivity().getString(
+                        R.string.unlock_set_unlock_launch_picker_title);
+                final ChooseLockSettingsHelper helper =
+                        new ChooseLockSettingsHelper(getActivity(), this);
+                if (!helper.launchConfirmationActivity(
+                        UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST, title, true, MY_USER_ID)) {
+                    ununifyLocks();
+                }
+            }
+        }
+        return result;
+    }
+
+    @Override
+    public int getHelpResource() {
+        return R.string.help_url_security;
+    }
+
+    /**
+     * For Search. Please keep it in sync when updating "createPreferenceHierarchy()"
+     */
+    public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+            new SecuritySearchIndexProvider();
+
+    private static class SecuritySearchIndexProvider extends BaseSearchIndexProvider {
+
+        // TODO (b/68001777) Refactor indexing to include all XML and block other settings.
+
+        @Override
+        public List<SearchIndexableResource> getXmlResourcesToIndex(
+                Context context, boolean enabled) {
+            final List<SearchIndexableResource> index = new ArrayList<>();
+
+            final LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
+            final ManagedLockPasswordProvider managedPasswordProvider =
+                    ManagedLockPasswordProvider.get(context, MY_USER_ID);
+            final DevicePolicyManager dpm = (DevicePolicyManager)
+                    context.getSystemService(Context.DEVICE_POLICY_SERVICE);
+            final UserManager um = UserManager.get(context);
+            final int profileUserId = Utils.getManagedProfileId(um, MY_USER_ID);
+
+            // To add option for unlock screen, user's password must not be managed and
+            // must not be unified with managed profile, whose password is managed.
+            if (!isPasswordManaged(MY_USER_ID, context, dpm)
+                    && (profileUserId == UserHandle.USER_NULL
+                    || lockPatternUtils.isSeparateProfileChallengeAllowed(profileUserId)
+                    || !isPasswordManaged(profileUserId, context, dpm))) {
+                // Add options for lock/unlock screen
+                final int resId = getResIdForLockUnlockScreen(lockPatternUtils,
+                        managedPasswordProvider, MY_USER_ID);
+                index.add(getSearchResource(context, resId));
+            }
+
+            if (profileUserId != UserHandle.USER_NULL
+                    && lockPatternUtils.isSeparateProfileChallengeAllowed(profileUserId)
+                    && !isPasswordManaged(profileUserId, context, dpm)) {
+                index.add(getSearchResource(context, getResIdForLockUnlockScreen(
+                        lockPatternUtils, managedPasswordProvider, profileUserId)));
+            }
+
+            // Append the rest of the settings
+            index.add(getSearchResource(context, R.xml.security_settings_misc));
+
+            return index;
+        }
+
+        private SearchIndexableResource getSearchResource(Context context, int xmlResId) {
+            final SearchIndexableResource sir = new SearchIndexableResource(context);
+            sir.xmlResId = xmlResId;
+            return sir;
+        }
+
+        private boolean isPasswordManaged(int userId, Context context, DevicePolicyManager dpm) {
+            final RestrictedLockUtils.EnforcedAdmin admin =
+                    RestrictedLockUtils.checkIfPasswordQualityIsSet(
+                            context, userId);
+            return admin != null && dpm.getPasswordQuality(admin.component, userId) ==
+                    DevicePolicyManager.PASSWORD_QUALITY_MANAGED;
+        }
+
+        @Override
+        public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
+            final List<SearchIndexableRaw> result = new ArrayList<SearchIndexableRaw>();
+            final Resources res = context.getResources();
+
+            final String screenTitle = res.getString(R.string.security_settings_title);
+
+            SearchIndexableRaw data = new SearchIndexableRaw(context);
+            data.title = screenTitle;
+            data.key = "security_settings_screen";
+            data.screenTitle = screenTitle;
+            result.add(data);
+
+            final UserManager um = UserManager.get(context);
+
+            // Fingerprint
+            final FingerprintManager fpm = Utils.getFingerprintManagerOrNull(context);
+            if (fpm != null && fpm.isHardwareDetected()) {
+                // This catches the title which can be overloaded in an overlay
+                data = new SearchIndexableRaw(context);
+                data.title = res.getString(R.string.security_settings_fingerprint_preference_title);
+                data.key = "security_fingerprint";
+                data.screenTitle = screenTitle;
+                result.add(data);
+                // Fallback for when the above doesn't contain "fingerprint"
+                data = new SearchIndexableRaw(context);
+                data.title = res.getString(R.string.fingerprint_manage_category_title);
+                data.key = "security_managed_fingerprint";
+                data.screenTitle = screenTitle;
+                result.add(data);
+            }
+
+            final LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
+            final int profileUserId = Utils.getManagedProfileId(um, MY_USER_ID);
+            if (profileUserId != UserHandle.USER_NULL
+                    && lockPatternUtils.isSeparateProfileChallengeAllowed(profileUserId)) {
+                if (lockPatternUtils.getKeyguardStoredPasswordQuality(profileUserId)
+                        >= DevicePolicyManager.PASSWORD_QUALITY_SOMETHING
+                        && lockPatternUtils.isSeparateProfileChallengeAllowedToUnify(
+                        profileUserId)) {
+                    data = new SearchIndexableRaw(context);
+                    data.title = res.getString(R.string.lock_settings_profile_unification_title);
+                    data.key = "security_use_one_lock";
+                    data.screenTitle = screenTitle;
+                    result.add(data);
+                }
+            }
+            return result;
+        }
+
+        @Override
+        public List<String> getNonIndexableKeys(Context context) {
+            final List<String> keys = super.getNonIndexableKeys(context);
+            final LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
+
+            new SimLockPreferenceController(context).updateNonIndexableKeys(keys);
+
+            // TrustAgent settings disappear when the user has no primary security.
+            if (!lockPatternUtils.isSecure(MY_USER_ID)) {
+                keys.add(KEY_TRUST_AGENT);
+            }
+
+            if (!(new EnterprisePrivacyPreferenceController(context))
+                    .isAvailable()) {
+                keys.add(KEY_ENTERPRISE_PRIVACY);
+            }
+
+            // Duplicate in special app access
+            keys.add(KEY_MANAGE_DEVICE_ADMIN);
+            // Duplicates between parent-child
+            keys.add(KEY_LOCATION);
+            keys.add(KEY_ENCRYPTION_AND_CREDENTIALS);
+            keys.add(KEY_LOCATION_SCANNING);
+
+            return keys;
+        }
+    }
+
+    static class SummaryProvider implements SummaryLoader.SummaryProvider {
+
+        private final Context mContext;
+        private final SummaryLoader mSummaryLoader;
+
+        public SummaryProvider(Context context, SummaryLoader summaryLoader) {
+            mContext = context;
+            mSummaryLoader = summaryLoader;
+        }
+
+        @Override
+        public void setListening(boolean listening) {
+            if (listening) {
+                final FingerprintManager fpm =
+                        Utils.getFingerprintManagerOrNull(mContext);
+                if (fpm != null && fpm.isHardwareDetected()) {
+                    mSummaryLoader.setSummary(this,
+                            mContext.getString(R.string.security_dashboard_summary));
+                } else {
+                    mSummaryLoader.setSummary(this, mContext.getString(
+                            R.string.security_dashboard_summary_no_fingerprint));
+                }
+            }
+        }
+    }
+
+    public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY =
+            new SummaryLoader.SummaryProviderFactory() {
+                @Override
+                public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
+                        SummaryLoader summaryLoader) {
+                    return new SummaryProvider(activity, summaryLoader);
+                }
+            };
+}
diff --git a/src/com/android/settings/security/ShowPasswordPreferenceController.java b/src/com/android/settings/security/ShowPasswordPreferenceController.java
new file mode 100644
index 0000000..9f9b52d
--- /dev/null
+++ b/src/com/android/settings/security/ShowPasswordPreferenceController.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+package com.android.settings.security;
+
+import android.content.Context;
+import android.os.UserHandle;
+import android.provider.Settings;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.core.TogglePreferenceController;
+import com.android.settings.overlay.FeatureFactory;
+
+public class ShowPasswordPreferenceController extends TogglePreferenceController {
+
+    private static final String KEY_SHOW_PASSWORD = "show_password";
+    private static final int MY_USER_ID = UserHandle.myUserId();
+    private final LockPatternUtils mLockPatternUtils;
+
+    public ShowPasswordPreferenceController(Context context) {
+        super(context, KEY_SHOW_PASSWORD);
+        mLockPatternUtils = FeatureFactory.getFactory(context)
+                .getSecurityFeatureProvider()
+                .getLockPatternUtils(context);
+    }
+
+    @Override
+    public boolean isChecked() {
+        return Settings.System.getInt(mContext.getContentResolver(),
+                Settings.System.TEXT_SHOW_PASSWORD, 1) != 0;
+    }
+
+    @Override
+    public void setChecked(boolean isChecked) {
+        Settings.System.putInt(mContext.getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD,
+                isChecked ? 1 : 0);
+        mLockPatternUtils.setVisiblePasswordEnabled(isChecked, MY_USER_ID);
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return AVAILABLE;
+    }
+}
+
diff --git a/src/com/android/settings/security/SimLockPreferenceController.java b/src/com/android/settings/security/SimLockPreferenceController.java
new file mode 100644
index 0000000..797f098
--- /dev/null
+++ b/src/com/android/settings/security/SimLockPreferenceController.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+package com.android.settings.security;
+
+import android.content.Context;
+import android.os.PersistableBundle;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.telephony.CarrierConfigManager;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+
+import com.android.settings.core.BasePreferenceController;
+
+import java.util.List;
+
+public class SimLockPreferenceController extends BasePreferenceController {
+
+    private static final String KEY_SIM_LOCK = "sim_lock_settings";
+
+    private final CarrierConfigManager mCarrierConfigManager;
+    private final UserManager mUserManager;
+    private final SubscriptionManager mSubscriptionManager;
+    private final TelephonyManager mTelephonyManager;
+
+    public SimLockPreferenceController(Context context) {
+        super(context, KEY_SIM_LOCK);
+        mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
+        mCarrierConfigManager = (CarrierConfigManager)
+                mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
+        mSubscriptionManager = (SubscriptionManager) context
+                .getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
+        mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        final PersistableBundle b = mCarrierConfigManager.getConfig();
+        final boolean IsAdmin = mUserManager.isAdminUser();
+        if (!IsAdmin || !isSimIccReady() ||
+                b.getBoolean(CarrierConfigManager.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL)) {
+            return DISABLED_FOR_USER;
+        }
+        return AVAILABLE;
+    }
+
+    @Override
+    public void displayPreference(PreferenceScreen screen) {
+        super.displayPreference(screen);
+        final Preference preference = screen.findPreference(getPreferenceKey());
+        if (preference == null) {
+            return;
+        }
+        // Disable SIM lock if there is no ready SIM card.
+        preference.setEnabled(isSimReady());
+    }
+
+    /* Return true if a SIM is ready for locking.
+     * TODO: consider adding to TelephonyManager or SubscritpionManasger.
+     */
+    private boolean isSimReady() {
+        final List<SubscriptionInfo> subInfoList =
+                mSubscriptionManager.getActiveSubscriptionInfoList();
+        if (subInfoList != null) {
+            for (SubscriptionInfo subInfo : subInfoList) {
+                final int simState = mTelephonyManager.getSimState(subInfo.getSimSlotIndex());
+                if ((simState != TelephonyManager.SIM_STATE_ABSENT) &&
+                        (simState != TelephonyManager.SIM_STATE_UNKNOWN)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Return true if a there is a Slot that has Icc
+     */
+    private boolean isSimIccReady() {
+        final List<SubscriptionInfo> subInfoList =
+                mSubscriptionManager.getActiveSubscriptionInfoList();
+
+        if (subInfoList != null) {
+            for (SubscriptionInfo subInfo : subInfoList) {
+                if (mTelephonyManager.hasIccCard(subInfo.getSimSlotIndex())) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+}
diff --git a/src/com/android/settings/security/UnificationConfirmationDialog.java b/src/com/android/settings/security/UnificationConfirmationDialog.java
new file mode 100644
index 0000000..21118d7
--- /dev/null
+++ b/src/com/android/settings/security/UnificationConfirmationDialog.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+package com.android.settings.security;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.FragmentManager;
+import android.content.DialogInterface;
+import android.os.Bundle;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
+import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+
+public class UnificationConfirmationDialog extends InstrumentedDialogFragment {
+    private static final String EXTRA_COMPLIANT = "compliant";
+
+    public static UnificationConfirmationDialog newIntance(boolean compliant) {
+        UnificationConfirmationDialog
+                dialog = new UnificationConfirmationDialog();
+        Bundle args = new Bundle();
+        args.putBoolean(EXTRA_COMPLIANT, compliant);
+        dialog.setArguments(args);
+        return dialog;
+    }
+
+    @Override
+    public void show(FragmentManager manager, String tag) {
+        if (manager.findFragmentByTag(tag) == null) {
+            // Prevent opening multiple dialogs if tapped on button quickly
+            super.show(manager, tag);
+        }
+    }
+
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        final SecuritySettingsV2 parentFragment = ((SecuritySettingsV2) getParentFragment());
+        final boolean compliant = getArguments().getBoolean(EXTRA_COMPLIANT);
+        return new AlertDialog.Builder(getActivity())
+                .setTitle(R.string.lock_settings_profile_unification_dialog_title)
+                .setMessage(compliant ? R.string.lock_settings_profile_unification_dialog_body
+                        : R.string.lock_settings_profile_unification_dialog_uncompliant_body)
+                .setPositiveButton(
+                        compliant ? R.string.lock_settings_profile_unification_dialog_confirm
+                                : R.string.lock_settings_profile_unification_dialog_uncompliant_confirm,
+                        (dialog, whichButton) -> {
+                            if (compliant) {
+                                parentFragment.launchConfirmDeviceLockForUnification();
+                            }    else {
+                                parentFragment.unifyUncompliantLocks();
+                            }
+                        }
+                )
+                .setNegativeButton(R.string.cancel, null)
+                .create();
+    }
+
+    @Override
+    public void onDismiss(DialogInterface dialog) {
+        super.onDismiss(dialog);
+        ((SecuritySettingsV2) getParentFragment()).updateUnificationPreference();
+    }
+
+    @Override
+    public int getMetricsCategory() {
+        return MetricsProto.MetricsEvent.DIALOG_UNIFICATION_CONFIRMATION;
+    }
+}
diff --git a/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceController.java b/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceController.java
new file mode 100644
index 0000000..c615eff
--- /dev/null
+++ b/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceController.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+package com.android.settings.security.trustagent;
+
+import android.content.Context;
+import android.os.UserHandle;
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.security.SecurityFeatureProvider;
+
+public class ManageTrustAgentsPreferenceController extends BasePreferenceController {
+
+    @VisibleForTesting
+    static final String KEY_MANAGE_TRUST_AGENTS = "manage_trust_agents";
+    private static final int MY_USER_ID = UserHandle.myUserId();
+
+    private final LockPatternUtils mLockPatternUtils;
+    private TrustAgentManager mTrustAgentManager;
+
+    public ManageTrustAgentsPreferenceController(Context context) {
+        super(context, KEY_MANAGE_TRUST_AGENTS);
+        final SecurityFeatureProvider securityFeatureProvider = FeatureFactory.getFactory(context)
+                .getSecurityFeatureProvider();
+        mLockPatternUtils = securityFeatureProvider.getLockPatternUtils(context);
+        mTrustAgentManager = securityFeatureProvider.getTrustAgentManager();
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return AVAILABLE;
+    }
+
+    @Override
+    public void displayPreference(PreferenceScreen screen) {
+        super.displayPreference(screen);
+        final Preference preference = screen.findPreference(getPreferenceKey());
+        if (preference == null) {
+            return;
+        }
+        final int numberOfTrustAgent = getTrustAgentCount();
+        if (!mLockPatternUtils.isSecure(MY_USER_ID)) {
+            preference.setEnabled(false);
+            preference.setSummary(R.string.disabled_because_no_backup_security);
+        } else if (numberOfTrustAgent > 0) {
+            preference.setSummary(mContext.getResources().getQuantityString(
+                    R.plurals.manage_trust_agents_summary_on,
+                    numberOfTrustAgent, numberOfTrustAgent));
+        } else {
+            preference.setSummary(R.string.manage_trust_agents_summary);
+        }
+    }
+
+    private int getTrustAgentCount() {
+        return mTrustAgentManager.getActiveTrustAgents(mContext, mLockPatternUtils).size();
+    }
+}
diff --git a/src/com/android/settings/widget/SwitchBar.java b/src/com/android/settings/widget/SwitchBar.java
index 3d30638..3c1e7c1 100644
--- a/src/com/android/settings/widget/SwitchBar.java
+++ b/src/com/android/settings/widget/SwitchBar.java
@@ -64,6 +64,8 @@
     private TextView mTextView;
     private String mLabel;
     private String mSummary;
+    private int mOnTextId;
+    private int mOffTextId;
 
     private boolean mLoggingIntialized;
     private boolean mDisabledByAdmin;
@@ -102,9 +104,7 @@
 
         mTextView = (TextView) findViewById(R.id.switch_text);
         mTextView.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
-        mLabel = getResources().getString(R.string.switch_off_text);
         mSummarySpan = new TextAppearanceSpan(mContext, R.style.TextAppearance_Small_SwitchBar);
-        updateText();
         ViewGroup.MarginLayoutParams lp = (MarginLayoutParams) mTextView.getLayoutParams();
         lp.setMarginStart(switchBarMarginStart);
 
@@ -117,6 +117,8 @@
         lp.setMarginEnd(switchBarMarginEnd);
         setBackgroundColor(switchBarBackgroundColor);
 
+        setSwitchBarText(R.string.switch_on_text, R.string.switch_off_text);
+
         addOnSwitchChangeListener(new OnSwitchChangeListener() {
             @Override
             public void onSwitchChanged(Switch switchView, boolean isChecked) {
@@ -139,11 +141,16 @@
     }
 
     public void setTextViewLabel(boolean isChecked) {
-        mLabel = getResources()
-                .getString(isChecked ? R.string.switch_on_text : R.string.switch_off_text);
+        mLabel = getResources().getString(isChecked ? mOnTextId : mOffTextId);
         updateText();
     }
 
+    public void setSwitchBarText(int onText, int offText) {
+        mOnTextId = onText;
+        mOffTextId = offText;
+        setTextViewLabel(isChecked());
+    }
+
     public void setSummary(String summary) {
         mSummary = summary;
         updateText();
diff --git a/tests/robotests/assets/grandfather_not_in_search_index_provider_registry b/tests/robotests/assets/grandfather_not_in_search_index_provider_registry
index 666b224..146893c 100644
--- a/tests/robotests/assets/grandfather_not_in_search_index_provider_registry
+++ b/tests/robotests/assets/grandfather_not_in_search_index_provider_registry
@@ -1,2 +1,3 @@
 com.android.settings.display.ScreenZoomPreferenceFragmentForSetupWizard
-com.android.settings.search.indexing.FakeSettingsFragment
\ No newline at end of file
+com.android.settings.search.indexing.FakeSettingsFragment
+com.android.settings.security.SecuritySettingsV2
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/core/XmlControllerAttributeTest.java b/tests/robotests/src/com/android/settings/core/XmlControllerAttributeTest.java
index ed4e815..c561d0d 100644
--- a/tests/robotests/src/com/android/settings/core/XmlControllerAttributeTest.java
+++ b/tests/robotests/src/com/android/settings/core/XmlControllerAttributeTest.java
@@ -16,6 +16,7 @@
 import com.android.settings.search.SearchIndexableResources;
 import com.android.settings.search.XmlParserUtils;
 import com.android.settings.security.SecuritySettings;
+import com.android.settings.security.SecuritySettingsV2;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
 import org.junit.After;
@@ -42,7 +43,8 @@
     // List of classes that are too hard to mock in order to retrieve xml information.
     private final List<Class> illegalClasses = new ArrayList<>(
             Arrays.asList(
-                    SecuritySettings.class
+                    SecuritySettings.class,
+                    SecuritySettingsV2.class
             ));
 
     // List of XML that could be retrieved from the illegalClasses list.
diff --git a/tests/robotests/src/com/android/settings/security/ScreenPinningPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/ScreenPinningPreferenceControllerTest.java
new file mode 100644
index 0000000..797e7d0
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/security/ScreenPinningPreferenceControllerTest.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+package com.android.settings.security;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class ScreenPinningPreferenceControllerTest {
+
+    @Mock
+    private PreferenceScreen mScreen;
+
+    private FakeFeatureFactory mFeatureFactory;
+    private Context mContext;
+    private ScreenPinningPreferenceController mController;
+    private Preference mPreference;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = RuntimeEnvironment.application;
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
+        mController = new ScreenPinningPreferenceController(mContext);
+        mPreference = new Preference(mContext);
+        mPreference.setKey(mController.getPreferenceKey());
+        when(mScreen.findPreference(mController.getPreferenceKey()))
+                .thenReturn(mPreference);
+    }
+
+    @After
+    public void tearDown() {
+        Settings.System.putInt(mContext.getContentResolver(),
+                Settings.System.LOCK_TO_APP_ENABLED, 0);
+    }
+
+    @Test
+    public void isAlwaysAvailable() {
+        assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+    }
+
+    @Test
+    public void displayPreference_isOff_shouldDisableOffSummary() {
+        Settings.System.putInt(mContext.getContentResolver(),
+                Settings.System.LOCK_TO_APP_ENABLED, 0);
+
+        mController.displayPreference(mScreen);
+
+        assertThat(mPreference.getSummary())
+                .isEqualTo(mContext.getString(R.string.switch_off_text));
+    }
+
+    @Test
+    public void displayPreference_isOn_shouldDisableOnSummary() {
+        Settings.System.putInt(mContext.getContentResolver(),
+                Settings.System.LOCK_TO_APP_ENABLED, 1);
+
+        mController.displayPreference(mScreen);
+
+        assertThat(mPreference.getSummary())
+                .isEqualTo(mContext.getString(R.string.switch_on_text));
+    }
+
+}
diff --git a/tests/robotests/src/com/android/settings/security/ShowPasswordPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/ShowPasswordPreferenceControllerTest.java
new file mode 100644
index 0000000..63cf00b
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/security/ShowPasswordPreferenceControllerTest.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+package com.android.settings.security;
+
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class ShowPasswordPreferenceControllerTest {
+
+    @Mock
+    private LockPatternUtils mLockPatternUtils;
+    @Mock
+    private PreferenceScreen mScreen;
+
+    private FakeFeatureFactory mFeatureFactory;
+    private Context mContext;
+    private ShowPasswordPreferenceController mController;
+    private Preference mPreference;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = RuntimeEnvironment.application;
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
+        when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
+                .thenReturn(mLockPatternUtils);
+        mController = new ShowPasswordPreferenceController(mContext);
+        mPreference = new Preference(mContext);
+        mPreference.setKey(mController.getPreferenceKey());
+        when(mScreen.findPreference(mController.getPreferenceKey()))
+                .thenReturn(mPreference);
+    }
+
+    @Test
+    public void isAlwaysAvailable() {
+        assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+    }
+
+    @Test
+    public void isChecked_settingIsOff_false() {
+        Settings.System.putInt(mContext.getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD,
+                0);
+
+        assertThat(mController.isChecked()).isFalse();
+    }
+
+    @Test
+    public void isChecked_settingIsOn_true() {
+        Settings.System.putInt(mContext.getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD,
+                1);
+        assertThat(mController.isChecked()).isTrue();
+    }
+
+    @Test
+    public void changePref_turnOn_shouldChangeSettingTo1() {
+        mController.onPreferenceChange(mPreference, true);
+
+        assertThat(mController.isChecked()).isTrue();
+        verify(mLockPatternUtils).setVisiblePasswordEnabled(true, UserHandle.myUserId());
+    }
+
+    @Test
+    public void changePref_turnOff_shouldChangeSettingTo0() {
+        mController.onPreferenceChange(mPreference, false);
+
+        assertThat(mController.isChecked()).isFalse();
+        verify(mLockPatternUtils).setVisiblePasswordEnabled(false, UserHandle.myUserId());
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/security/SimLockPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/SimLockPreferenceControllerTest.java
new file mode 100644
index 0000000..a3a4fe3
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/security/SimLockPreferenceControllerTest.java
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+package com.android.settings.security;
+
+import static android.telephony.TelephonyManager.SIM_STATE_READY;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.os.PersistableBundle;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.telephony.CarrierConfigManager;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+
+import com.android.settings.TestConfig;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class SimLockPreferenceControllerTest {
+
+    @Mock
+    private SubscriptionManager mSubscriptionManager;
+    @Mock
+    private CarrierConfigManager mCarrierManager;
+    @Mock
+    private UserManager mUserManager;
+    @Mock
+    private TelephonyManager mTelephonyManager;
+    @Mock
+    private PreferenceScreen mScreen;
+
+    private Context mContext;
+    private SimLockPreferenceController mController;
+    private Preference mPreference;
+
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = RuntimeEnvironment.application;
+        ShadowApplication shadowApplication = ShadowApplication.getInstance();
+        shadowApplication.setSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE,
+                mSubscriptionManager);
+        shadowApplication.setSystemService(Context.CARRIER_CONFIG_SERVICE, mCarrierManager);
+        shadowApplication.setSystemService(Context.USER_SERVICE, mUserManager);
+        shadowApplication.setSystemService(Context.TELEPHONY_SERVICE, mTelephonyManager);
+        mController = new SimLockPreferenceController(mContext);
+        mPreference = new Preference(mContext);
+        mPreference.setKey(mController.getPreferenceKey());
+        when(mScreen.findPreference(mController.getPreferenceKey()))
+                .thenReturn(mPreference);
+    }
+
+    @Test
+    public void isAvailable_notAdmin_false() {
+        when(mUserManager.isAdminUser()).thenReturn(false);
+
+        assertThat(mController.getAvailabilityStatus())
+                .isEqualTo(BasePreferenceController.DISABLED_FOR_USER);
+    }
+
+    @Test
+    public void isAvailable_simIccNotReady_false() {
+        when(mUserManager.isAdminUser()).thenReturn(true);
+
+        assertThat(mController.getAvailabilityStatus())
+                .isEqualTo(BasePreferenceController.DISABLED_FOR_USER);
+    }
+
+    @Test
+    public void isAvailable_carrierConfigDisabled_false() {
+        when(mUserManager.isAdminUser()).thenReturn(true);
+        setupMockIcc();
+        final PersistableBundle pb = new PersistableBundle();
+        pb.putBoolean(CarrierConfigManager.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL, true);
+        when(mCarrierManager.getConfig()).thenReturn(pb);
+
+        assertThat(mController.getAvailabilityStatus())
+                .isEqualTo(BasePreferenceController.DISABLED_FOR_USER);
+    }
+
+    @Test
+    public void isAvailable_true() {
+        when(mUserManager.isAdminUser()).thenReturn(true);
+        setupMockIcc();
+        final PersistableBundle pb = new PersistableBundle();
+        when(mCarrierManager.getConfig()).thenReturn(pb);
+
+        assertThat(mController.getAvailabilityStatus())
+                .isEqualTo(BasePreferenceController.AVAILABLE);
+    }
+
+    @Test
+    public void displayPreference_simReady_enablePreference() {
+        mController.displayPreference(mScreen);
+
+        assertThat(mPreference.isEnabled()).isFalse();
+    }
+
+    @Test
+    public void displayPreference_simNotReady_disablePreference() {
+        setupMockSimReady();
+
+        mController.displayPreference(mScreen);
+
+        assertThat(mPreference.isEnabled()).isTrue();
+    }
+
+    private void setupMockIcc() {
+        final List<SubscriptionInfo> subscriptionInfoList = new ArrayList<>();
+        SubscriptionInfo info = mock(SubscriptionInfo.class);
+        subscriptionInfoList.add(info);
+        when(mTelephonyManager.hasIccCard(anyInt()))
+                .thenReturn(true);
+        when(mSubscriptionManager.getActiveSubscriptionInfoList())
+                .thenReturn(subscriptionInfoList);
+    }
+
+    private void setupMockSimReady() {
+        final List<SubscriptionInfo> subscriptionInfoList = new ArrayList<>();
+        SubscriptionInfo info = mock(SubscriptionInfo.class);
+        subscriptionInfoList.add(info);
+        when(mTelephonyManager.getSimState(anyInt()))
+                .thenReturn(SIM_STATE_READY);
+        when(mSubscriptionManager.getActiveSubscriptionInfoList())
+                .thenReturn(subscriptionInfoList);
+    }
+
+}
diff --git a/tests/robotests/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceControllerTest.java
new file mode 100644
index 0000000..8818602
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceControllerTest.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+package com.android.settings.security.trustagent;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class ManageTrustAgentsPreferenceControllerTest {
+
+    @Mock
+    private TrustAgentManager mTrustAgentManager;
+    @Mock
+    private LockPatternUtils mLockPatternUtils;
+    @Mock
+    private PreferenceScreen mScreen;
+
+    private FakeFeatureFactory mFeatureFactory;
+    private Context mContext;
+    private ManageTrustAgentsPreferenceController mController;
+    private Preference mPreference;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = RuntimeEnvironment.application;
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
+        when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
+                .thenReturn(mLockPatternUtils);
+        when(mFeatureFactory.securityFeatureProvider.getTrustAgentManager())
+                .thenReturn(mTrustAgentManager);
+        mController = new ManageTrustAgentsPreferenceController(mContext);
+        mPreference = new Preference(mContext);
+        mPreference.setKey(mController.getPreferenceKey());
+        when(mScreen.findPreference(mController.getPreferenceKey()))
+                .thenReturn(mPreference);
+    }
+
+    @Test
+    public void isAlwaysAvailable() {
+        assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+    }
+
+    @Test
+    public void displayPreference_isNotSecure_shouldDisablePreference() {
+        when(mLockPatternUtils.isSecure(anyInt())).thenReturn(false);
+
+        mController.displayPreference(mScreen);
+
+        assertThat(mPreference.isEnabled()).isFalse();
+        assertThat(mPreference.getSummary())
+                .isEqualTo(mContext.getString(R.string.disabled_because_no_backup_security));
+    }
+
+    @Test
+    public void displayPreference_isSecure_noTrustAgent_shouldShowGenericSummary() {
+        when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
+        when(mTrustAgentManager.getActiveTrustAgents(mContext, mLockPatternUtils))
+                .thenReturn(new ArrayList<>());
+
+        mController.displayPreference(mScreen);
+
+        assertThat(mPreference.isEnabled()).isTrue();
+        assertThat(mPreference.getSummary())
+                .isEqualTo(mContext.getString(R.string.manage_trust_agents_summary));
+    }
+
+    @Test
+    public void displayPreference_isSecure_hasTrustAgent_shouldShowDetailedSummary() {
+        when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
+        when(mTrustAgentManager.getActiveTrustAgents(mContext, mLockPatternUtils))
+                .thenReturn(Arrays.asList(new TrustAgentManager.TrustAgentComponentInfo()));
+
+        mController.displayPreference(mScreen);
+
+        assertThat(mPreference.isEnabled()).isTrue();
+        assertThat(mPreference.getSummary())
+                .isEqualTo(mContext.getResources().getQuantityString(
+                        R.plurals.manage_trust_agents_summary_on, 1, 1));
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/widget/SwitchBarTest.java b/tests/robotests/src/com/android/settings/widget/SwitchBarTest.java
new file mode 100644
index 0000000..c805761
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/widget/SwitchBarTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+package com.android.settings.widget;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.robolectric.RuntimeEnvironment.application;
+
+import android.content.Context;
+import android.widget.TextView;
+
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class SwitchBarTest {
+
+    private Context mContext;
+    private SwitchBar mBar;
+
+    @Before
+    public void setUp() {
+        mContext = RuntimeEnvironment.application;
+        mBar = new SwitchBar(application, Robolectric.buildAttributeSet().build());
+    }
+
+    @Test
+    public void testDefaultLabels() {
+        int defaultOnText = R.string.switch_on_text;
+        int defaultOffText = R.string.switch_off_text;
+        assertThat(((TextView) mBar.findViewById(R.id.switch_text)).getText())
+                .isEqualTo(mContext.getString(defaultOffText));
+
+        mBar.setChecked(true);
+        assertThat(((TextView) mBar.findViewById(R.id.switch_text)).getText())
+                .isEqualTo(mContext.getString(defaultOnText));
+    }
+
+    @Test
+    public void testCustomLabels() {
+        int onText = R.string.master_clear_progress_text;
+        int offText = R.string.manage_space_text;
+        mBar.setSwitchBarText(onText, offText);
+        assertThat(((TextView) mBar.findViewById(R.id.switch_text)).getText())
+                .isEqualTo(mContext.getString(offText));
+
+        mBar.setChecked(true);
+        assertThat(((TextView) mBar.findViewById(R.id.switch_text)).getText())
+                .isEqualTo(mContext.getString(onText));
+    }
+}