Merge "Rename remaining layouts to original search names"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index a6d066b..0404d0b 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -564,11 +564,11 @@
                 <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.system"/>
+                       android:value="com.android.settings.category.ia.system"/>
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
-                android:value="com.android.settings.language.LanguageAndInputSettings"/>
+                       android:value="com.android.settings.language.LanguageAndInputSettings"/>
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
-                android:value="true"/>
+                       android:value="true"/>
         </activity>
 
         <activity android:name="Settings$AvailableVirtualKeyboardActivity"
@@ -943,6 +943,8 @@
                 android:value="com.android.settings.category.ia.system" />
             <meta-data android:name="com.android.settings.title"
                 android:resource="@string/about_settings" />
+            <meta-data android:name="com.android.settings.summary"
+                android:resource="@string/summary_empty"/>
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                 android:value="com.android.settings.DeviceInfoSettings" />
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -1889,6 +1891,8 @@
             </intent-filter>
             <meta-data android:name="com.android.settings.category"
                 android:value="com.android.settings.category.ia.system" />
+            <meta-data android:name="com.android.settings.summary"
+                android:resource="@string/summary_empty"/>
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                 android:value="com.android.settings.development.DevelopmentSettings" />
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -1937,7 +1941,7 @@
                   android:label="@string/development_settings_title"
                   android:targetActivity="Settings$DevelopmentSettingsActivity">
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
-                android:value="com.android.settings.DevelopmentSettings" />
+                android:value="com.android.settings.development.DevelopmentSettings" />
         </activity-alias>
 
         <activity android:name=".development.AppPicker"
@@ -2388,6 +2392,8 @@
             </intent-filter>
             <meta-data android:name="com.android.settings.category"
                 android:value="com.android.settings.category.ia.accounts" />
+            <meta-data android:name="com.android.settings.summary"
+                android:resource="@string/summary_empty"/>
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                 android:value="com.android.settings.users.UserSettings" />
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -2490,6 +2496,18 @@
                 android:value="com.android.settings.applications.PictureInPictureSettings" />
         </activity>
 
+        <activity android:name="Settings$AppPictureInPictureSettingsActivity"
+            android:label="@string/picture_in_picture_title"
+            android:taskAffinity="">
+            <intent-filter>
+                <action android:name="android.settings.PICTURE_IN_PICTURE_SETTINGS" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <data android:scheme="package" />
+            </intent-filter>
+            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+                android:value="com.android.settings.applications.PictureInPictureDetails" />
+        </activity>
+
         <activity android:name="Settings$ZenAccessSettingsActivity"
                   android:label="@string/manage_zen_access_title"
                   android:taskAffinity="">
@@ -2519,6 +2537,13 @@
                 <category android:name="android.intent.category.DEFAULT" />
                 <category android:name="com.android.settings.SHORTCUT" />
             </intent-filter>
+            <intent-filter android:priority="120">
+                <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.apps"/>
+            <meta-data android:name="com.android.settings.summary"
+                android:resource="@string/summary_empty"/>
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                 android:value="com.android.settings.notification.ConfigureNotificationSettings" />
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -2873,16 +2898,25 @@
 
         <activity android:name="Settings$AdvancedAppsActivity"
                   android:taskAffinity=""
-                  android:exported="true">
+                  android:exported="true"
+                  android:label="@string/app_default_dashboard_title"
+                  android:icon="@drawable/ic_adb">
             <intent-filter android:priority="1">
                 <action android:name="android.settings.MANAGE_DEFAULT_APPS_SETTINGS" />
                 <action android:name="android.settings.HOME_SETTINGS" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
+            <intent-filter android:priority="130">
+                <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.apps"/>
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                        android:value="com.android.settings.applications.AdvancedAppSettings" />
+            <meta-data android:name="com.android.settings.summary"
+                       android:resource="@string/summary_empty"/>
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
-                        android:value="true" />
+                       android:value="true" />
         </activity>
 
         <!-- Keep compatibility with old WebView-picker implementation -->
@@ -2921,6 +2955,8 @@
             </intent-filter>
             <meta-data android:name="com.android.settings.category"
                        android:value="com.android.settings.category.ia.system" />
+            <meta-data android:name="com.android.settings.summary"
+                       android:resource="@string/summary_empty"/>
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
                        android:value="true" />
         </activity>
@@ -3001,34 +3037,6 @@
                        android:resource="@string/support_summary"/>
         </activity>
 
-        <activity-alias android:name="ConfigureNotificationDashboardAlias"
-                  android:targetActivity="Settings$ConfigureNotificationSettingsActivity">
-            <intent-filter android:priority="120">
-                <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.apps"/>
-            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
-                       android:value="com.android.settings.notification.ConfigureNotificationSettings" />
-            <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
-                       android:value="true" />
-        </activity-alias>
-
-        <activity-alias android:name="AppDefaultDashboardAlias"
-                        android:targetActivity="Settings$AdvancedAppsActivity"
-                        android:label="@string/app_default_dashboard_title"
-                        android:icon="@drawable/ic_adb">
-            <intent-filter android:priority="130">
-                <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.apps"/>
-            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
-                       android:value="com.android.settings.applications.AdvancedAppSettings" />
-            <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
-                       android:value="true" />
-        </activity-alias>
-
         <!-- End of information architecture host activities -->
 
         <service
diff --git a/res/drawable/ic_settings_battery.xml b/res/drawable/ic_settings_battery.xml
index c8e053d..6afc5d0 100644
--- a/res/drawable/ic_settings_battery.xml
+++ b/res/drawable/ic_settings_battery.xml
@@ -14,13 +14,12 @@
     limitations under the License.
 -->
 <vector xmlns:android="http://schemas.android.com/apk/res/android"
-        android:width="24.0dp"
-        android:height="24.0dp"
+        android:width="24dp"
+        android:height="24dp"
         android:viewportWidth="24.0"
         android:viewportHeight="24.0"
         android:tint="?android:attr/colorControlNormal">
     <path
-        android:fillColor="#FFFFFFFF"
-        android:pathData="M15.67,4.0L14.0,4.0L14.0,2.0l-4.0,0.0l0.0,2.0L8.33,4.0C7.6,4.0 7.0,4.6 7.0,5.33l0.0,15.33C7.0,21.4 7.6,22.0 8.33,22.0l7.33,0.0c0.74,0.0 1.34,-0.6 1.34,-1.33L17.0,5.33C17.0,4.6 16.4,4.0 15.67,4.0z
-        M16,5l0,5.5l-8,0l0,-5.5l3,0l0,-2l2,0l0,2l3,0z"/>
+        android:fillColor="#FF000000"
+        android:pathData="M15.67,4H14V2h-4v2H8.33C7.6,4 7,4.6 7,5.33v15.33C7,21.4 7.6,22 8.33,22h7.33c0.74,0 1.34,-0.6 1.34,-1.33V5.33C17,4.6 16.4,4 15.67,4z"/>
 </vector>
diff --git a/res/layout/app_details.xml b/res/layout/app_details.xml
index 15cb38a..00d4cca 100644
--- a/res/layout/app_details.xml
+++ b/res/layout/app_details.xml
@@ -18,7 +18,7 @@
 <LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/app_snippet"
-    style="@style/AppInfoHeader"
+    style="@style/EntityHeader"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_gravity="center_horizontal|top"
@@ -79,7 +79,7 @@
 
             <TextView
                 android:id="@+id/app_detail_title"
-                style="@style/TextAppearance.AppInfoTitle"
+                style="@style/TextAppearance.EntityHeaderTitle"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:singleLine="false"
@@ -89,22 +89,24 @@
 
             <TextView
                 android:id="@+id/install_type"
-                style="@style/TextAppearance.AppInfoSummary"
                 android:visibility="gone"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:gravity="start"
                 android:singleLine="true"
-                android:ellipsize="marquee"/>
+                android:ellipsize="marquee"
+                android:textAppearance="@android:style/TextAppearance.Material.Body1"
+                android:textColor="?android:attr/textColorSecondary"/>
 
             <TextView
                 android:id="@+id/app_detail_summary"
-                style="@style/TextAppearance.AppInfoSummary"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:gravity="start"
                 android:singleLine="true"
-                android:ellipsize="marquee"/>
+                android:ellipsize="marquee"
+                android:textAppearance="@android:style/TextAppearance.Material.Body1"
+                android:textColor="?android:attr/textColorSecondary"/>
 
         </LinearLayout>
 
diff --git a/res/layout/battery_usage_graph.xml b/res/layout/battery_usage_graph.xml
index bd6e7a5..80f966b 100644
--- a/res/layout/battery_usage_graph.xml
+++ b/res/layout/battery_usage_graph.xml
@@ -18,6 +18,7 @@
     xmlns:settings="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
+    android:paddingTop="16dp"
     android:paddingStart="@dimen/preference_no_icon_padding_start"
     android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
     android:orientation="vertical">
@@ -26,22 +27,16 @@
         android:id="@+id/charge"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:layout_marginBottom="16dp"
         android:textAppearance="?android:attr/textAppearanceLarge"
         android:textSize="36sp"
         android:textColor="?android:attr/colorAccent" />
 
-    <TextView
-        android:id="@+id/estimation"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:paddingBottom="8dp"
-        android:textAppearance="?android:attr/textAppearanceMedium"
-        android:textColor="?android:attr/textColorSecondary" />
-
     <com.android.settingslib.graph.UsageView
         android:id="@+id/battery_usage"
         android:layout_width="match_parent"
         android:layout_height="141dp"
+        android:layout_marginBottom="16dp"
         settings:sideLabels="@array/battery_labels"
         android:colorAccent="?android:attr/colorAccent"
         android:gravity="end"
diff --git a/res/layout/preference_widget_seekbar_settings.xml b/res/layout/preference_widget_seekbar_settings.xml
index 77c27a4..87fea99 100644
--- a/res/layout/preference_widget_seekbar_settings.xml
+++ b/res/layout/preference_widget_seekbar_settings.xml
@@ -15,81 +15,49 @@
 -->
 
 <!-- Layout used by SeekBarPreference for the seekbar widget style. -->
-<!-- Same as frameworks/base/core/res/res/layout/preference_widget_seekbar_material.xml with
-     reserved icon space -->
-<LinearLayout
+<RelativeLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:minHeight="?android:attr/listPreferredItemHeight"
     android:gravity="center_vertical"
     android:paddingStart="?android:attr/listPreferredItemPaddingStart"
-    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
+    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
+    android:paddingBottom="6dp"
+    android:paddingTop="6dp">
 
-    <LinearLayout
-        android:id="@+id/icon_container"
+    <TextView
+        android:id="@android:id/title"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:minWidth="60dp"
-        android:gravity="start|center_vertical"
-        android:orientation="horizontal"
-        android:paddingEnd="12dp"
-        android:paddingTop="4dp"
-        android:paddingBottom="4dp">
-        <com.android.internal.widget.PreferenceImageView
-            android:id="@android:id/icon"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:maxWidth="48dp"
-            android:maxHeight="48dp"/>
-    </LinearLayout>
+        android:layout_marginStart="60dp"
+        android:layout_marginEnd="8dp"
+        android:singleLine="true"
+        android:textAppearance="@android:style/TextAppearance.Material.Subhead"
+        android:textColor="?android:attr/textColorPrimary"
+        android:ellipsize="marquee"
+        android:fadingEdge="horizontal" />
 
-    <RelativeLayout
+    <TextView
+        android:id="@android:id/summary"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginEnd="8dip"
-        android:layout_marginTop="6dip"
-        android:layout_marginBottom="6dip"
-        android:layout_weight="1">
+        android:layout_marginStart="60dp"
+        android:layout_marginEnd="8dp"
+        android:layout_below="@android:id/title"
+        android:layout_alignStart="@android:id/title"
+        android:textAppearance="?android:attr/textAppearanceListItemSecondary"
+        android:textColor="?android:attr/textColorSecondary"
+        android:maxLines="4" />
 
-        <TextView
-            android:id="@android:id/title"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:singleLine="true"
-            android:textAppearance="@android:style/TextAppearance.Material.Subhead"
-            android:textColor="?android:attr/textColorPrimary"
-            android:ellipsize="marquee"
-            android:fadingEdge="horizontal"/>
+    <com.android.settings.widget.DefaultIndicatorSeekBar
+        android:id="@*android:id/seekbar"
+        style="@android:style/Widget.Material.SeekBar.Discrete"
+        android:layout_width="match_parent"
+        android:layout_height="48dp"
+        android:layout_alignParentEnd="true"
+        android:layout_below="@android:id/summary"
+        android:layout_marginEnd="8dp"
+        android:layout_marginStart="44dp" />
 
-        <TextView
-            android:id="@android:id/summary"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_below="@android:id/title"
-            android:layout_alignStart="@android:id/title"
-            android:textAppearance="?android:attr/textAppearanceListItemSecondary"
-            android:textColor="?android:attr/textColorSecondary"
-            android:maxLines="4"/>
-
-        <!-- Preference should place its actual preference widget here. -->
-        <LinearLayout
-            android:id="@android:id/widget_frame"
-            android:layout_width="wrap_content"
-            android:layout_height="match_parent"
-            android:layout_below="@android:id/summary"
-            android:layout_alignStart="@android:id/title"
-            android:gravity="center"
-            android:orientation="vertical"/>
-
-        <SeekBar
-            android:id="@*android:id/seekbar"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:layout_below="@android:id/summary"
-            android:layout_toEndOf="@android:id/widget_frame"
-            android:layout_alignParentEnd="true"/>
-
-    </RelativeLayout>
-
-</LinearLayout>
+</RelativeLayout>
diff --git a/res/layout/storage_item.xml b/res/layout/storage_item.xml
index de73543..520f5ce 100644
--- a/res/layout/storage_item.xml
+++ b/res/layout/storage_item.xml
@@ -31,25 +31,25 @@
         android:layout_height="wrap_content"
         android:orientation="horizontal">
 
-      <TextView
-          android:id="@android:id/title"
-          android:layout_width="0dp"
-          android:layout_height="wrap_content"
-          android:layout_weight="1"
-          android:singleLine="true"
-          android:textAppearance="@android:style/TextAppearance.Material.Subhead"
-          android:textAlignment="viewStart"
-          android:ellipsize="marquee"
-          android:fadingEdge="horizontal" />
+        <TextView
+            android:id="@android:id/title"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_weight="1"
+            android:singleLine="true"
+            android:textAppearance="@android:style/TextAppearance.Material.Subhead"
+            android:textAlignment="viewStart"
+            android:ellipsize="marquee"
+            android:fadingEdge="horizontal" />
 
-      <TextView
-          android:id="@android:id/summary"
-          android:layout_width="wrap_content"
-          android:layout_height="wrap_content"
-          android:textAlignment="viewStart"
-          android:textAppearance="@android:style/TextAppearance.Material.Body1"
-          android:textColor="?android:attr/textColorSecondaryNoDisable"
-          android:maxLines="10" />
+        <TextView
+            android:id="@android:id/summary"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textAlignment="viewStart"
+            android:textAppearance="@android:style/TextAppearance.Material.Body1"
+            android:textColor="?android:attr/textColorSecondaryNoDisable"
+            android:maxLines="10" />
 
     </LinearLayout>
 
diff --git a/res/layout/storage_item_alternate.xml b/res/layout/storage_item_alternate.xml
deleted file mode 100644
index b41c82b..0000000
--- a/res/layout/storage_item_alternate.xml
+++ /dev/null
@@ -1,56 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2016 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.
--->
-
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-              android:layout_width="match_parent"
-              android:layout_height="wrap_content"
-              android:orientation="vertical"
-              android:minHeight="?android:attr/listPreferredItemHeightSmall"
-              android:gravity="center_vertical"
-              android:paddingStart="@dimen/preference_no_icon_padding_start"
-              android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
-              android:paddingTop="16dip"
-              android:paddingBottom="16dip"
-              android:background="?android:attr/selectableItemBackground">
-
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:orientation="horizontal">
-
-        <TextView
-            android:id="@android:id/title"
-            android:layout_width="0dp"
-            android:layout_height="wrap_content"
-            android:layout_weight="1"
-            android:singleLine="true"
-            android:textAppearance="@android:style/TextAppearance.Material.Subhead"
-            android:textAlignment="viewStart"
-            android:ellipsize="marquee"
-            android:fadingEdge="horizontal" />
-
-        <TextView
-            android:id="@android:id/summary"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:textAlignment="viewStart"
-            android:textAppearance="@android:style/TextAppearance.Material.Body1"
-            android:textColor="?android:attr/textColorSecondaryNoDisable"
-            android:maxLines="10" />
-
-    </LinearLayout>
-
-</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index ddb1bf1..d37d9d9 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -71,7 +71,7 @@
     <!-- Wifi Calling provisioning flag on. Only shown in diagnostic screen, so precise translation is not needed. -->
     <string name="wfc_provisioned_switch_string">Wifi Calling Provisioned</string>
 
-    <!-- Cell Radio Power. Only shown in diagnostic screen, so precise translation is not needed. -->
+    <!-- Title for controlling on/off for Mobile phone's radio power. Only shown in diagnostic screen, so precise translation is not needed. -->
     <string name="radio_info_radio_power">Mobile Radio Power</string>
 
     <!-- Phone Info screen. Menu item label.  Used for diagnostic info screens, precise translation isn't needed -->
@@ -629,7 +629,7 @@
     <string name="calls_title">Calls</string>
     <!-- check box SMS Messges title [CHAR LIMIT=30] -->
     <string name="sms_messages_title">SMS messages</string>
-    <!-- check box cellular data summary [CHAR LIMIT=41] -->
+    <!-- check box cellular data summary [CHAR LIMIT=85] -->
     <string name="cellular_data_summary">Allow data usage over mobile network</string>
     <!-- check box to allow data usage when roaming [CHAR LIMIT=41] -->
     <string name="allow_data_usage_title">Allow data usage when roaming</string>
@@ -1300,12 +1300,12 @@
     <!-- Toast shown when lock pattern or password successfully setup. [CHAR LIMIT=64] -->
     <string name="lock_setup" msgid="5507462851158901718">Setup is complete.</string>
 
-    <!-- In the security screen, the header title for settings related to device admins -->
-    <string name="device_admin_title">Device administration</string>
-
     <!-- Title of preference to manage device admins -->
     <string name="manage_device_admin">Device admin apps</string>
 
+    <!-- Summary of preference to manage device administrators, informing the user that currently no device administrator apps are installed and active -->
+    <string name="number_of_device_admins_none">No active apps</string>
+
     <!-- Summary of preference to manage device administrators, informing the user how many device administrator apps are installed and active -->
     <plurals name="number_of_device_admins">
         <item quantity="one"><xliff:g id="count">%d</xliff:g> active app</item>
@@ -1639,7 +1639,7 @@
     <string name="wifi_switch_away_when_unvalidated">Switch to mobile data if Wi\u2011Fi loses Internet access.</string>
     <!-- Preference title for option to automatically switch away from bad wifi networks [CHAR LIMIT=60]-->
     <string name="wifi_cellular_data_fallback_title">Switch to mobile data automatically</string>
-    <!-- Preference summary for option to automatically switch away from bad wifi networks [CHAR LIMIT=None]-->
+    <!-- Preference summary to automatically switch away from bad wifi networks [CHAR LIMIT=None]-->
     <string name="wifi_cellular_data_fallback_summary">Use mobile data when Wi\u2011Fi has no Internet access. Data usage may apply.</string>
     <!-- Action bar text message to manually add a wifi network [CHAR LIMIT=20]-->
     <string name="wifi_add_network">Add network</string>
@@ -1806,7 +1806,8 @@
 
     <!-- Dialog text to tell the user that the selected network has lost Internet access, and asking the user whether they want to avoid this network. -->
     <string name="lost_internet_access_title">Wi\u2011Fi is not connected to the Internet</string>
-    <string name="lost_internet_access_text">You can switch to the mobile network whenever Wi\u2011Fi has a bad connection. Data usage may apply.</string>
+    <string name="lost_internet_access_text">You can switch to the mobile network whenever Wi\u2011Fi has a bad connection. Data usage charges may apply.</string>
+    <!-- Button text to let user switch to mobile data -->
     <string name="lost_internet_access_switch">Switch to mobile</string>
     <string name="lost_internet_access_cancel">Stay on Wi\u2011Fi</string>
     <string name="lost_internet_access_persist">Never show again</string>
@@ -2075,8 +2076,10 @@
     <string name="display_settings_title">Display</string>
     <!-- Sound settings screen heading -->
     <string name="sound_settings">Sound</string>
-    <!-- Sound settings screen, setting option summary text -->
-    <string name="ringtone_summary">&#160;</string>
+    <!-- DO NOT TRANSLATE Summary placeholder -->
+    <string name="summary_placeholder" translatable="false">&#160;</string>
+    <!-- DO NOT TRANSLATE Empty summary for dynamic preferences -->
+    <string name="summary_empty" translatable="false"></string>
     <!-- Sound settings screen, volume title -->
     <string name="all_volume_title">Volumes</string>
     <!-- Sound settings screen, music effects title [CHAR LIMIT=30]-->
@@ -2230,6 +2233,8 @@
     <string name="night_display_start_time_title">Start time</string>
     <!-- Night display screen, setting option name to configure time to automatically turn off night display. [CHAR LIMIT=30] -->
     <string name="night_display_end_time_title">End time</string>
+    <!-- Night display screen, setting the color temperature of the display. [CHAR LIMIT=30] -->
+    <string name="night_display_temperature_title">Intensity</string>
     <!-- Display settings screen, summary format of night display when off. [CHAR LIMIT=NONE] -->
     <string name="night_display_summary_off">Off. <xliff:g name="auto_mode_summary" example="Never turn on automatically">%1$s</xliff:g></string>
     <!-- Display settings screen, summary of night display when off and will *never* turn on automatically. [CHAR LIMIT=NONE] -->
@@ -2905,8 +2910,6 @@
     <string name="reset_network_complete_toast">Network settings have been reset</string>
 
     <!-- Master Clear -->
-    <!-- SD card & phone storage settings screen, setting option name under Internal phone storage heading [CHAR LIMIT=30] -->
-    <string name="device_reset_title">Reset device</string>
     <!-- SD card & phone storage settings screen, setting option name under Internal phone storage heading -->
     <string name="master_clear_title">Factory data reset</string>
     <!-- SD card & phone storage settings screen, message on screen after user selects Factory data reset [CHAR LIMIT=NONE] -->
@@ -3362,20 +3365,25 @@
     <string name="install_applications">Unknown sources</string>
     <!-- Applications settings screen, setting check box title. If checked, the system allows installation of applications that are downloaded from random places, such as web sites.  [CHAR LIMIT=30] -->
     <string name="install_applications_title">Allow all app sources</string>
-    <!-- Applications settings screen, setting check box summary.  This is the summary for "Unknown sources" checkbox  [CHAR LIMIT=65] -->
-    <string name="install_unknown_applications_title">Lets you install apps from sources other than Google Play</string>
-    <!-- Applications settings screen, setting check box summary.  This is the summary for "Unknown sources" checkbox  -->
-    <string name="install_unknown_applications">Allow installation of apps from unknown sources</string>
-    <!-- Applications settings screen, message text of alert that appears if user selects the "Unknown sources" check box -->
-    <string name="install_all_warning" product="tablet">Your tablet and personal data are more vulnerable to attack by apps
- from unknown sources. You agree that you are solely responsible for any
- damage to your tablet or loss of data that may result from using
- these apps.</string>
-    <!-- Applications settings screen, message text of alert that appears if user selects the "Unknown sources" check box -->
-    <string name="install_all_warning" product="default">Your phone and personal data are more vulnerable to attack by apps
- from unknown sources. You agree that you are solely responsible for any
- damage to your phone or loss of data that may result from using
- these apps.</string>
+
+    <!-- Warning that appears below the unknown sources switch in settings -->
+    <string name="install_all_warning" product="tablet">
+        Your tablet and personal data are more vulnerable
+        to attack by unknown apps. By installing apps from
+        this source, you agree that you are responsible for
+        any damage to your tablet or loss of data that may
+        result from their use.
+    </string>
+
+    <!-- Warning that appears below the unknown sources switch in settings -->
+    <string name="install_all_warning" product="default">
+        Your phone and personal data are more vulnerable
+        to attack by unknown apps. By installing apps from
+        this source, you agree that you are responsible for
+        any damage to your phone or loss of data that may
+        result from their use.
+    </string>
+
     <!-- Applications settings screen, setting check box title. If checked, applications show more settings options. -->
     <string name="advanced_settings">Advanced settings</string>
     <!-- Applications settings screen, setting check box summary.  This is the summary for "Advanced settings" checkbox  -->
@@ -3759,6 +3767,8 @@
     <string name="language_settings">Languages&#160;&amp; input</string>
     <!-- Title of Languages & input settings screen -->
     <string name="language_keyboard_settings_title">Languages&#160;&amp; input</string>
+    <!-- Title of preference category that lists all settings about helping user input such as spell checker [CHAR LIMIT=60]-->
+    <string name="input_assistance">Input assistance</string>
     <!-- On Languages & input settings screen, heading. Inside the "Languages & input settings" screen, this is the header for settings that relate to keyboard (enable/disable each keyboard, settings for each keyboard). -->
     <string name="keyboard_settings_category">Keyboard &amp; input methods</string>
     <!-- On Text & language settings screen, setting option name. title of the setting to take the user to a screen to select the locale. -->
@@ -3805,9 +3815,9 @@
     <string name="failed_to_open_app_settings_toast">Failed to open settings for <xliff:g id="spell_application_name">%1$s</xliff:g></string>
 
     <!-- Title for the 'keyboard and input methods' preference category. [CHAR LIMIT=45] -->
-    <string name="keyboard_and_input_methods_category">Keyboard and input methods</string>
+    <string name="keyboard_and_input_methods_category">Keyboard &amp; inputs</string>
     <!-- Title for the 'virtual keyboard' preference sub-screen. [CHAR LIMIT=35] -->
-    <string name="virtual_keyboard_category">Virtual keyboard</string>
+    <string name="virtual_keyboard_category">Virtual keyboards</string>
     <!-- Title for the 'available virtual keyboard' preference sub-screen. [CHAR LIMIT=35] -->
     <string name="available_virtual_keyboard_category">Available virtual keyboard</string>
     <!-- Title for the button to trigger the 'Manage keyboards' preference sub-screen, where the user can turn on/off installed virtual keyboards.[CHAR LIMIT=35] -->
@@ -5277,7 +5287,7 @@
     <!-- Checkbox label that restricts background data usage of a specific application. [CHAR LIMIT=40] -->
     <string name="data_usage_app_restrict_background">Background data</string>
     <!-- Summary message for checkbox that restricts background data usage of a specific application. [CHAR LIMIT=NONE] -->
-    <string name="data_usage_app_restrict_background_summary">Enable usage of Mobile data in the background</string>
+    <string name="data_usage_app_restrict_background_summary">Enable usage of mobile data in the background</string>
     <!-- Summary message for checkbox that restricts background data usage of a specific application when no networks have been limited. [CHAR LIMIT=84] -->
     <string name="data_usage_app_restrict_background_summary_disabled">To restrict background data for this app, first set a mobile data limit.</string>
     <!-- Title of dialog shown when user restricts background data usage of a specific application. [CHAR LIMIT=48] -->
@@ -6459,8 +6469,17 @@
     <!-- Apps > App Details > Advanced section string title. [CHAR LIMIT=NONE] -->
     <string name="picture_in_picture_app_detail_title">Picture-in-picture</string>
 
-    <!-- Apps > App Details > Advanced section string description. [CHAR LIMIT=NONE] -->
-    <string name="picture_in_picture_app_detail_summary">Permit entering picture-in-picture when leaving app</string>
+    <!-- Apps > App Details > Picture-in-picture > Switch title. [CHAR LIMIT=NONE] -->
+    <string name="picture_in_picture_app_detail_switch">Allow picture-in-picture</string>
+
+    <!-- Apps > App Details > Picture-in-picture > Description. [CHAR LIMIT=NONE] -->
+    <string name="picture_in_picture_app_detail_summary">Allow this app to create a picture-in-picture window while the app is open or after you leave it (for example, to continue watching a video).  This window displays on top of other apps you're using.</string>
+
+    <!-- Summary of app allowed to enter picture-in-picture. [CHAR LIMIT=60] -->
+    <string name="picture_in_picture_on">Yes</string>
+
+    <!-- Summary of app not allowed to enter picture-in-picture. [CHAR LIMIT=60] -->
+    <string name="picture_in_picture_off">No</string>
 
     <!-- Sound & notification > Advanced section: Title for managing Do Not Disturb access option. [CHAR LIMIT=40] -->
     <string name="manage_zen_access_title">Do Not Disturb access</string>
@@ -7383,9 +7402,9 @@
     <string name="system_alert_window_off">No</string>
 
     <!-- Title for settings screen for controlling apps that can install other apps on device [CHAR LIMIT=50] -->
-    <string name="install_other_apps">Install other apps</string>
+    <string name="install_other_apps">Install unknown apps</string>
     <!-- Keywords for setting screen for controlling apps that can install other apps on device -->
-    <string name="keywords_install_other_apps">install apps external unknown sources</string>
+    <string name="keywords_install_other_apps">install apps unknown sources</string>
 
     <!-- Write Settings settings -->
     <!-- Settings title in main settings screen for WRITE_SETTINGS [CHAR LIMIT=30] -->
@@ -7418,7 +7437,7 @@
     <!-- Summary of app not trusted to install apps [CHAR LIMIT=45] -->
     <string name="external_source_untrusted">No</string>
     <!-- Title of switch preference that controls whether an external app source is trusted or not [CHAR LIMIT=50] -->
-    <string name="external_source_switch_title">Trust apps from this source</string>
+    <string name="external_source_switch_title">Allow app installs</string>
 
     <!-- Title of setting that controls gesture to open camera [CHAR LIMIT=40] -->
     <string name="camera_gesture_title">Double twist for camera</string>
@@ -7517,7 +7536,7 @@
     <string name="backup_disabled">Back up disabled</string>
 
     <!-- Summary of device info page [CHAR LIMIT=NONE] -->
-    <string name="about_summary">Android <xliff:g id="version" example="6.0">%1$s</xliff:g></string>
+    <string name="about_summary">Updated to Android <xliff:g id="version" example="6.0">%1$s</xliff:g></string>
 
     <!-- Title for dialog displayed when user clicks on a setting locked by an admin [CHAR LIMIT=30] -->
     <string name="disabled_by_policy_title">Action not allowed</string>
@@ -8100,8 +8119,8 @@
     <!-- Summary text for ambient display (device) [CHAR LIMIT=160]-->
     <string name="ambient_display_pickup_summary" product="device">To quickly check your notifications, pick up your device.</string>
 
-    <!-- Title text for fingerprint swipe for notifications [CHAR LIMIT=60]-->
-    <string name="fingerprint_swipe_for_notifications_title">Swipe for notifications</string>
+    <!-- Title text for fingerprint swipe for notifications [CHAR LIMIT=80]-->
+    <string name="fingerprint_swipe_for_notifications_title">Swipe fingerprint for notifications</string>
 
     <!-- Summary text for fingerprint swipe for notifications (phone) [CHAR LIMIT=160]-->
     <string name="fingerprint_swipe_for_notifications_summary" product="default">To check your notifications, swipe down on the fingerprint sensor on the back of your phone.</string>
@@ -8168,7 +8187,7 @@
     <!-- Enterprise Privacy --> <skip />
 
     <!-- Title of setting on security settings screen. This will take the user to a screen with information about admin powers and their impact on the user's privacy on a managed device. Shown on enterprise-managed devices only. Note: "Device" is singular and refers to the device (e.g. phone or tablet) that the user is holding in their hand. -->
-    <string name="enterprise_privacy_settings">Managed device details</string>
+    <string name="enterprise_privacy_settings">Managed device info</string>
     <!-- Summary for Enterprise Privacy settings, explaining what the user can expect to find under it [CHAR LIMIT=NONE]-->
     <string name="enterprise_privacy_settings_summary_generic">Changes &amp; settings managed by your organization</string>
     <!-- Summary for Enterprise Privacy settings, explaining what the user can expect to find under it [CHAR LIMIT=NONE]-->
@@ -8208,13 +8227,13 @@
     <!-- Label indicating that the admin installed one or more apps on the device. -->
     <string name="enterprise_privacy_enterprise_installed_packages">Apps installed</string>
     <!-- Label indicating that the admin granted one or more apps access to the device's location. [CHAR LIMIT=NONE] -->
-    <string name="enterprise_privacy_location_access">Apps allowed to access your location</string>
+    <string name="enterprise_privacy_location_access">Location permissions</string>
     <!-- Label indicating that the admin granted one or more apps access to the microphone. [CHAR LIMIT=NONE] -->
-    <string name="enterprise_privacy_microphone_access">Apps allowed to access your microphone</string>
+    <string name="enterprise_privacy_microphone_access">Microphone permissions</string>
     <!-- Label indicating that the admin granted one or more apps access to the camera. [CHAR LIMIT=NONE] -->
-    <string name="enterprise_privacy_camera_access">Apps allowed to access your camera</string>
+    <string name="enterprise_privacy_camera_access">Camera permissions</string>
     <!-- Label indicating that the admin set one or more apps as defaults for common actions (e.g. open browser, send e-mail). [CHAR LIMIT=NONE] -->
-    <string name="enterprise_privacy_enterprise_set_default_apps">Default apps set</string>
+    <string name="enterprise_privacy_enterprise_set_default_apps">Default apps</string>
     <!-- Label explaining that the current input method was set by the admin. [CHAR LIMIT=NONE] -->
     <string name="enterprise_privacy_input_method">Default keyboard</string>
     <!-- Summary indicating the input method set by the admin. [CHAR LIMIT=NONE] -->
@@ -8227,30 +8246,17 @@
     <string name="enterprise_privacy_always_on_vpn_work">Always-on VPN turned on in your work profile</string>
     <!-- Label explaining that a global HTTP proxy was set by the admin. [CHAR LIMIT=NONE] -->
     <string name="enterprise_privacy_global_http_proxy">Global HTTP proxy set</string>
-    <!-- Label explaining that the admin installed trusted CA certificates for the current user. [CHAR LIMIT=NONE] -->
-    <plurals name="enterprise_privacy_ca_certs_user">
-        <item quantity="one">Trusted CA Certificate installed</item>
-        <item quantity="other">Trusted CA Certificates installed</item>
-    </plurals>
-    <!-- Label explaining that the admin installed trusted CA certificates for the personal profile. [CHAR LIMIT=NONE] -->
-    <plurals name="enterprise_privacy_ca_certs_personal">
-        <item quantity="one">Trusted CA Certificate installed in your personal profile</item>
-        <item quantity="other">Trusted CA Certificates installed in your personal profile</item>
-    </plurals>
+    <!-- Label explaining that the admin installed trusted CA certificates. [CHAR LIMIT=NONE] -->
+    <string name="enterprise_privacy_ca_certs">Trusted credentials</string>
     <!-- Summary indicating the number of trusted CA certificates installed by the admin. [CHAR LIMIT=NONE] -->
     <plurals name="enterprise_privacy_number_ca_certs">
-        <item quantity="one"><xliff:g id="count">%d</xliff:g> certificate</item>
-        <item quantity="other"><xliff:g id="count">%d</xliff:g> certificates</item>
+        <item quantity="one"><xliff:g id="count">%d</xliff:g> CA certificate</item>
+        <item quantity="other"><xliff:g id="count">%d</xliff:g> CA certificates</item>
     </plurals>
     <!-- Summary indicating the number of trusted CA certificates installed by the admin. [CHAR LIMIT=NONE] -->
     <plurals name="enterprise_privacy_number_ca_certs_actionable">
-        <item quantity="one"><xliff:g id="count">%d</xliff:g> certificate. Tap to view.</item>
-        <item quantity="other"><xliff:g id="count">%d</xliff:g> certificates. Tap to view.</item>
-    </plurals>
-    <!-- Label explaining that the admin installed trusted CA certificates for the work profile. [CHAR LIMIT=NONE] -->
-    <plurals name="enterprise_privacy_ca_certs_work">
-        <item quantity="one">Trusted CA Certificate installed in your work profile</item>
-        <item quantity="other">Trusted CA Certificates installed in your work profile</item>
+        <item quantity="one"><xliff:g id="count">%d</xliff:g> CA certificate. Tap to view.</item>
+        <item quantity="other"><xliff:g id="count">%d</xliff:g> CA certificates. Tap to view.</item>
     </plurals>
     <!-- Label explaining that the admin can lock the device and change the user's password. [CHAR LIMIT=NONE] -->
     <string name="enterprise_privacy_lock_device">Admin can lock the device and reset password</string>
@@ -8312,8 +8318,8 @@
     <string name="webview_disabled_for_user">(disabled for user <xliff:g id="user" example="John Doe">%s</xliff:g>)</string>
 
     <!-- AutoFill strings -->
-    <!-- Preference label for the auto-fill app. [CHAR LIMIT=60] -->
-    <string name="autofill_app">Autofill app</string>
+    <!-- Preference label for choosing auto-fill service. [CHAR LIMIT=60] -->
+    <string name="autofill_app">Autofill service</string>
     <!-- Keywords for the auto-fill feature. [CHAR LIMIT=NONE] -->
     <string name="autofill_keywords">auto, fill, autofill</string>
     <!-- Title of the warning dialog for setting the auto-fill app. [CHAR_LIMIT=NONE] -->
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 95efaec..fa40932 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -428,19 +428,6 @@
         <item name="android:textSize">24sp</item>
     </style>
 
-    <style name="AppInfoHeader" parent="EntityHeader">
-        <item name="android:background">?android:attr/colorAccent</item>
-    </style>
-
-    <style name="TextAppearance.AppInfoTitle" parent="TextAppearance.EntityHeaderTitle">
-        <item name="android:textColor">?android:attr/textColorPrimaryInverse</item>
-    </style>
-
-    <style name="TextAppearance.AppInfoSummary"
-           parent="@android:style/TextAppearance.Material.Body1">
-        <item name="android:textColor">?android:attr/textColorPrimaryInverse</item>
-    </style>
-
     <style name="AppActionPrimaryButton" parent="android:Widget.Material.Button.Colored"/>
 
     <style name="LockPatternStyle">
diff --git a/res/xml/app_default_settings.xml b/res/xml/app_default_settings.xml
index e96c070..11acb24 100644
--- a/res/xml/app_default_settings.xml
+++ b/res/xml/app_default_settings.xml
@@ -29,7 +29,6 @@
     <Preference
         android:key="default_browser"
         android:title="@string/default_browser_title"
-        android:summary="@string/default_browser_title_none"
         android:fragment="com.android.settings.applications.defaultapps.DefaultBrowserPicker"
         android:order="-19">
         <extra android:name="for_work" android:value="false"/>
@@ -38,7 +37,6 @@
     <Preference
         android:key="default_home"
         android:title="@string/home_app"
-        android:summary="@string/no_default_home"
         android:fragment="com.android.settings.applications.defaultapps.DefaultHomePicker"
         settings:keywords="@string/keywords_home"
         android:order="-18"/>
@@ -63,14 +61,6 @@
         settings:keywords="@string/keywords_emergency_app"
         android:order="-15"/>
 
-    <com.android.settings.widget.GearPreference
-        android:key="default_autofill"
-        android:title="@string/autofill_app"
-        android:summary="@string/app_list_preference_none"
-        android:fragment="com.android.settings.applications.defaultapps.DefaultAutofillPicker"
-        settings:keywords="@string/autofill_keywords"
-        android:order="-14"/>
-
     <!--
     <Preference
         android:key="default_notification_asst_app"
@@ -91,7 +81,6 @@
         <Preference
             android:key="work_default_browser"
             android:title="@string/default_browser_title"
-            android:summary="@string/default_browser_title_none"
             android:fragment="com.android.settings.applications.defaultapps.DefaultBrowserPicker">
             <extra android:name="for_work" android:value="true"/>
         </Preference>
diff --git a/res/xml/channel_notification_settings.xml b/res/xml/channel_notification_settings.xml
index fde1bfa..5b848e6 100644
--- a/res/xml/channel_notification_settings.xml
+++ b/res/xml/channel_notification_settings.xml
@@ -69,5 +69,4 @@
             android:title="@string/app_notification_override_dnd_title"
             android:summary="@string/app_notification_override_dnd_summary"
             settings:useAdditionalSummary="true" />
-
 </PreferenceScreen>
diff --git a/res/xml/enterprise_privacy_settings.xml b/res/xml/enterprise_privacy_settings.xml
index 68403c5..e6246c2 100644
--- a/res/xml/enterprise_privacy_settings.xml
+++ b/res/xml/enterprise_privacy_settings.xml
@@ -90,10 +90,8 @@
                 android:title="@string/enterprise_privacy_global_http_proxy"
                 settings:multiLine="true"/>
         <com.android.settings.DividerPreference
-                android:key="ca_certs_current_user"
-                settings:multiLine="true"/>
-        <com.android.settings.DividerPreference
-                android:key="ca_certs_managed_profile"
+                android:key="ca_certs"
+                android:title="@string/enterprise_privacy_ca_certs"
                 settings:multiLine="true"/>
     </PreferenceCategory>
 
diff --git a/res/xml/language_and_input.xml b/res/xml/language_and_input.xml
index 6303fbd..79f441f 100644
--- a/res/xml/language_and_input.xml
+++ b/res/xml/language_and_input.xml
@@ -17,6 +17,7 @@
 
 <PreferenceScreen
     xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
     android:title="@string/language_keyboard_settings_title" >
 
     <Preference
@@ -34,19 +35,28 @@
             android:fragment="com.android.settings.inputmethod.PhysicalKeyboardFragment"/>
     </PreferenceCategory>
 
-    <!-- Spell checker preference title, summary and fragment will be set programmatically. -->
-    <!-- Note: Mark this as persistent="false" to remove unnecessarily saved shared preference.
-         See: InputMethodAndSubtypeUtil.removeUnnecessaryNonPersistentPreference. -->
-    <Preference
-        android:key="spellcheckers_settings"
-        android:title="@string/spellcheckers_settings_title"
-        android:persistent="false"
-        android:fragment="com.android.settings.inputmethod.SpellCheckersSettings"/>
+    <PreferenceCategory
+        android:title="@string/input_assistance">
+        <!-- Spell checker preference title, summary and fragment will be set programmatically. -->
+        <!-- Note: Mark this as persistent="false" to remove unnecessarily saved shared preference.
+             See: InputMethodAndSubtypeUtil.removeUnnecessaryNonPersistentPreference. -->
+        <Preference
+            android:key="spellcheckers_settings"
+            android:title="@string/spellcheckers_settings_title"
+            android:persistent="false"
+            android:fragment="com.android.settings.inputmethod.SpellCheckersSettings"/>
 
-    <!-- User dictionary preference title and fragment will be set programmatically. -->
-    <Preference
-        android:key="key_user_dictionary_settings"
-        android:title="@string/user_dict_settings_title"/>
+        <com.android.settings.widget.GearPreference
+            android:key="default_autofill"
+            android:title="@string/autofill_app"
+            android:fragment="com.android.settings.applications.defaultapps.DefaultAutofillPicker"
+            settings:keywords="@string/autofill_keywords" />
+
+        <!-- User dictionary preference title and fragment will be set programmatically. -->
+        <Preference
+            android:key="key_user_dictionary_settings"
+            android:title="@string/user_dict_settings_title"/>
+    </PreferenceCategory>
 
     <PreferenceCategory
         android:key="gesture_settings_category"
diff --git a/res/xml/network_and_internet.xml b/res/xml/network_and_internet.xml
index d7a6355..7feffca 100644
--- a/res/xml/network_and_internet.xml
+++ b/res/xml/network_and_internet.xml
@@ -23,6 +23,7 @@
         android:fragment="com.android.settings.wifi.WifiSettings"
         android:key="toggle_wifi"
         android:title="@string/wifi_settings"
+        android:summary="@string/summary_placeholder"
         android:icon="@drawable/ic_settings_wireless"
         android:order="-30">
         <intent
@@ -30,13 +31,6 @@
             android:targetClass="Settings$WifiSettingsActivity"/>
     </com.android.settings.widget.MasterSwitchPreference>
 
-    <SwitchPreference
-        android:key="toggle_airplane"
-        android:title="@string/airplane_mode"
-        android:icon="@drawable/ic_airplanemode_active"
-        android:disableDependentsState="true"
-        android:order="5"/>
-
     <com.android.settingslib.RestrictedPreference
         android:key="mobile_network_settings"
         android:title="@string/network_settings_title"
@@ -58,6 +52,7 @@
         android:title="@string/tether_settings_title_all"
         android:icon="@drawable/ic_wifi_tethering"
         android:order="-5"
+        android:summary="@string/summary_placeholder"
         settings:userRestriction="no_config_tethering"
         settings:useAdminDisabledSummary="true"/>
 
@@ -67,6 +62,7 @@
         android:title="@string/vpn_settings_title"
         android:icon="@drawable/ic_vpn_key"
         android:order="0"
+        android:summary="@string/summary_placeholder"
         settings:userRestriction="no_config_vpn"
         settings:useAdminDisabledSummary="true"/>
 
@@ -77,6 +73,13 @@
         settings:userRestriction="no_config_mobile_networks"
         settings:useAdminDisabledSummary="true"/>
 
+    <SwitchPreference
+        android:key="toggle_airplane"
+        android:title="@string/airplane_mode"
+        android:icon="@drawable/ic_airplanemode_active"
+        android:disableDependentsState="true"
+        android:order="5"/>
+
     <Preference
         android:fragment="com.android.settings.ProxySelector"
         android:key="proxy_settings"
diff --git a/res/xml/night_display_settings.xml b/res/xml/night_display_settings.xml
index c0b91ae..f78a769 100644
--- a/res/xml/night_display_settings.xml
+++ b/res/xml/night_display_settings.xml
@@ -16,7 +16,6 @@
 
 <PreferenceScreen
         xmlns:android="http://schemas.android.com/apk/res/android"
-        xmlns:settings="http://schemas.android.com/apk/res-auto"
         android:title="@string/night_display_title">
 
     <PreferenceCategory
@@ -44,6 +43,10 @@
                 android:key="night_display_activated"
                 android:title="@string/night_display_title" />
 
+        <com.android.settings.SeekBarPreference
+            android:key="night_display_temperature"
+            android:title="@string/night_display_temperature_title"/>
+
     </PreferenceCategory>
 
 </PreferenceScreen>
\ No newline at end of file
diff --git a/res/xml/security_settings_misc.xml b/res/xml/security_settings_misc.xml
index e058b3e..943f04c 100644
--- a/res/xml/security_settings_misc.xml
+++ b/res/xml/security_settings_misc.xml
@@ -33,9 +33,7 @@
 
     </PreferenceCategory>
 
-    <PreferenceCategory android:key="device_admin_category"
-            android:title="@string/device_admin_title"
-            android:persistent="false">
+    <PreferenceCategory>
 
         <Preference android:key="manage_device_admin"
                 android:title="@string/manage_device_admin"
diff --git a/res/xml/sound_settings.xml b/res/xml/sound_settings.xml
index a34d875..0aaaff1 100644
--- a/res/xml/sound_settings.xml
+++ b/res/xml/sound_settings.xml
@@ -67,7 +67,7 @@
                     android:key="ringtone"
                     android:title="@string/ringtone_title"
                     android:dialogTitle="@string/ringtone_title"
-                    android:summary="@string/ringtone_summary"
+                    android:summary="@string/summary_placeholder"
                     android:ringtoneType="ringtone" />
 
                 <!-- Default notification ringtone -->
@@ -75,7 +75,7 @@
                     android:key="notification_ringtone"
                     android:title="@string/notification_ringtone_title"
                     android:dialogTitle="@string/notification_ringtone_title"
-                    android:summary="@string/ringtone_summary"
+                    android:summary="@string/summary_placeholder"
                     android:ringtoneType="notification" />
 
                 <!-- Default alarm ringtone -->
@@ -83,7 +83,7 @@
                     android:key="alarm_ringtone"
                     android:title="@string/alarm_ringtone_title"
                     android:dialogTitle="@string/alarm_ringtone_title"
-                    android:summary="@string/ringtone_summary"
+                    android:summary="@string/summary_placeholder"
                     android:persistent="false"
                     android:ringtoneType="alarm" />
 
diff --git a/res/xml/special_access.xml b/res/xml/special_access.xml
index 8bf5c56..6eaede9 100644
--- a/res/xml/special_access.xml
+++ b/res/xml/special_access.xml
@@ -79,6 +79,7 @@
         android:title="@string/picture_in_picture_title"
         android:fragment="com.android.settings.applications.PictureInPictureSettings"
         settings:keywords="@string/picture_in_picture_keywords" />
+
     <Preference
         android:key="premium_sms"
         android:title="@string/premium_sms_access"
diff --git a/res/xml/storage_dashboard_fragment.xml b/res/xml/storage_dashboard_fragment.xml
index bf8483f..64a2aba 100644
--- a/res/xml/storage_dashboard_fragment.xml
+++ b/res/xml/storage_dashboard_fragment.xml
@@ -30,28 +30,28 @@
         android:order="1"
         settings:allowDividerAbove="true"
         settings:allowDividerBelow="true"/>
-    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
+    <com.android.settings.deviceinfo.StorageItemPreference
         android:key="pref_photos_videos"
         android:title="@string/storage_photos_videos"
-        android:order="2"
-        settings:allowDividerAbove="true" />
-    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
+        settings:allowDividerAbove="true"
+        android:order="2" />
+    <com.android.settings.deviceinfo.StorageItemPreference
         android:key="pref_music_audio"
         android:title="@string/storage_music_audio"
         android:order="3" />
-    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
+    <com.android.settings.deviceinfo.StorageItemPreference
         android:key="pref_games"
         android:title="@string/storage_games"
         android:order="4" />
-    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
+    <com.android.settings.deviceinfo.StorageItemPreference
         android:key="pref_other_apps"
         android:title="@string/storage_other_apps"
         android:order="5" />
-    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
+    <com.android.settings.deviceinfo.StorageItemPreference
         android:key="pref_files"
         android:title="@string/storage_files"
         android:order="6" />
-    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
+    <com.android.settings.deviceinfo.StorageItemPreference
         android:key="pref_system"
         android:title="@string/storage_detail_system"
         android:order="100" />
diff --git a/res/xml/storage_profile_fragment.xml b/res/xml/storage_profile_fragment.xml
index d0c5c3a..c675744 100644
--- a/res/xml/storage_profile_fragment.xml
+++ b/res/xml/storage_profile_fragment.xml
@@ -18,24 +18,24 @@
 <PreferenceScreen
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:title="@string/storage_settings">
-    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
+    <com.android.settings.deviceinfo.StorageItemPreference
         android:key="pref_photos_videos"
         android:title="@string/storage_photos_videos">
-    </com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate>
-    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
+    </com.android.settings.deviceinfo.StorageItemPreference>
+    <com.android.settings.deviceinfo.StorageItemPreference
         android:key="pref_music_audio"
         android:title="@string/storage_music_audio">
-    </com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate>
-    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
+    </com.android.settings.deviceinfo.StorageItemPreference>
+    <com.android.settings.deviceinfo.StorageItemPreference
         android:key="pref_games"
         android:title="@string/storage_games">
-    </com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate>
-    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
+    </com.android.settings.deviceinfo.StorageItemPreference>
+    <com.android.settings.deviceinfo.StorageItemPreference
         android:key="pref_other_apps"
         android:title="@string/storage_other_apps">
-    </com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate>
-    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
+    </com.android.settings.deviceinfo.StorageItemPreference>
+    <com.android.settings.deviceinfo.StorageItemPreference
         android:key="pref_files"
         android:title="@string/storage_files">
-    </com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate>
+    </com.android.settings.deviceinfo.StorageItemPreference>
 </PreferenceScreen>
diff --git a/res/xml/system_dashboard_fragment.xml b/res/xml/system_dashboard_fragment.xml
index 14579c5..b03fab6 100644
--- a/res/xml/system_dashboard_fragment.xml
+++ b/res/xml/system_dashboard_fragment.xml
@@ -23,7 +23,7 @@
     <Preference
         android:key="system_update_settings"
         android:title="@string/system_update_settings_list_item_title"
-        android:summary="@string/system_update_settings_list_item_summary"
+        android:summary="@string/summary_placeholder"
         android:icon="@drawable/ic_system_update"
         android:order="-30">
         <intent android:action="android.settings.SYSTEM_UPDATE_SETTINGS"/>
@@ -41,7 +41,7 @@
     <!-- Factory reset -->
     <com.android.settingslib.RestrictedPreference
         android:key="factory_reset"
-        android:title="@string/device_reset_title"
+        android:title="@string/master_clear_title"
         android:icon="@drawable/ic_restore"
         android:order="-20"
         settings:keywords="@string/keywords_factory_data_reset"
diff --git a/src/com/android/settings/DeviceInfoSettings.java b/src/com/android/settings/DeviceInfoSettings.java
index e9d3f86..b1c9e2c 100644
--- a/src/com/android/settings/DeviceInfoSettings.java
+++ b/src/com/android/settings/DeviceInfoSettings.java
@@ -20,14 +20,12 @@
 import android.app.Fragment;
 import android.content.Context;
 import android.content.Intent;
-import android.os.Build;
 import android.provider.SearchIndexableResource;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.core.PreferenceController;
 import com.android.settings.core.lifecycle.Lifecycle;
 import com.android.settings.dashboard.DashboardFragment;
-import com.android.settings.dashboard.SummaryLoader;
 import com.android.settings.deviceinfo.AdditionalSystemUpdatePreferenceController;
 import com.android.settings.deviceinfo.BasebandVersionPreferenceController;
 import com.android.settings.deviceinfo.BuildNumberPreferenceController;
@@ -88,34 +86,6 @@
                 getLifecycle());
     }
 
-    private 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) {
-                mSummaryLoader.setSummary(this, mContext.getString(R.string.about_summary,
-                        Build.VERSION.RELEASE));
-            }
-        }
-    }
-
-    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);
-        }
-    };
-
     private static List<PreferenceController> buildPreferenceControllers(Context context,
             Activity activity, Fragment fragment, Lifecycle lifecycle) {
         final List<PreferenceController> controllers = new ArrayList<>();
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index edefaf7..1cb763b 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -102,7 +102,6 @@
     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_DEVICE_ADMIN_CATEGORY = "device_admin_category";
     private static final String KEY_MANAGE_TRUST_AGENTS = "manage_trust_agents";
     private static final String KEY_UNIFICATION = "unification";
 
@@ -351,10 +350,6 @@
         // Credential storage
         final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
 
-        // Application install
-        PreferenceGroup deviceAdminCategory = (PreferenceGroup)
-                root.findPreference(KEY_DEVICE_ADMIN_CATEGORY);
-
         // Advanced Security features
         Preference manageAgents = root.findPreference(KEY_MANAGE_TRUST_AGENTS);
         if (manageAgents != null && !mLockPatternUtils.isSecure(MY_USER_ID)) {
diff --git a/src/com/android/settings/SeekBarPreference.java b/src/com/android/settings/SeekBarPreference.java
index 26b69db..a8d5fbf 100644
--- a/src/com/android/settings/SeekBarPreference.java
+++ b/src/com/android/settings/SeekBarPreference.java
@@ -21,7 +21,6 @@
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.support.v4.content.res.TypedArrayUtils;
-import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceViewHolder;
 import android.util.AttributeSet;
 import android.view.KeyEvent;
@@ -29,6 +28,7 @@
 import android.widget.SeekBar;
 import android.widget.SeekBar.OnSeekBarChangeListener;
 
+import com.android.settings.widget.DefaultIndicatorSeekBar;
 import com.android.settingslib.RestrictedPreference;
 
 /**
@@ -41,6 +41,11 @@
     private int mMax;
     private boolean mTrackingTouch;
 
+    private boolean mContinuousUpdates;
+    private int mDefaultProgress = -1;
+
+    private SeekBar mSeekBar;
+
     public SeekBarPreference(
             Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
         super(context, attrs, defStyleAttr, defStyleRes);
@@ -78,12 +83,15 @@
     public void onBindViewHolder(PreferenceViewHolder view) {
         super.onBindViewHolder(view);
         view.itemView.setOnKeyListener(this);
-        SeekBar seekBar = (SeekBar) view.findViewById(
+        mSeekBar = (SeekBar) view.findViewById(
                 com.android.internal.R.id.seekbar);
-        seekBar.setOnSeekBarChangeListener(this);
-        seekBar.setMax(mMax);
-        seekBar.setProgress(mProgress);
-        seekBar.setEnabled(isEnabled());
+        mSeekBar.setOnSeekBarChangeListener(this);
+        mSeekBar.setMax(mMax);
+        mSeekBar.setProgress(mProgress);
+        mSeekBar.setEnabled(isEnabled());
+        if (mSeekBar instanceof DefaultIndicatorSeekBar) {
+            ((DefaultIndicatorSeekBar) mSeekBar).setDefaultProgress(mDefaultProgress);
+        }
     }
 
     @Override
@@ -126,6 +134,27 @@
         setProgress(progress, true);
     }
 
+    /**
+     * Sets the progress point to draw a single tick mark representing a default value.
+     */
+    public void setDefaultProgress(int defaultProgress) {
+        if (mDefaultProgress != defaultProgress) {
+            mDefaultProgress = defaultProgress;
+            if (mSeekBar instanceof DefaultIndicatorSeekBar) {
+                ((DefaultIndicatorSeekBar) mSeekBar).setDefaultProgress(mDefaultProgress);
+            }
+        }
+    }
+
+    /**
+     * When {@code continuousUpdates} is true, update the persisted setting immediately as the thumb
+     * is dragged along the SeekBar. Otherwise, only update the value of the setting when the thumb
+     * is dropped.
+     */
+    public void setContinuousUpdates(boolean continuousUpdates) {
+        mContinuousUpdates = continuousUpdates;
+    }
+
     private void setProgress(int progress, boolean notifyChanged) {
         if (progress > mMax) {
             progress = mMax;
@@ -164,7 +193,7 @@
     @Override
     public void onProgressChanged(
             SeekBar seekBar, int progress, boolean fromUser) {
-        if (fromUser && !mTrackingTouch) {
+        if (fromUser && (mContinuousUpdates || !mTrackingTouch)) {
             syncProgress(seekBar);
         }
     }
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index f2d6452..8f645f8 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -95,6 +95,7 @@
     public static class NotificationAccessSettingsActivity extends SettingsActivity { /* empty */ }
     public static class VrListenersSettingsActivity extends SettingsActivity { /* empty */ }
     public static class PictureInPictureSettingsActivity extends SettingsActivity { /* empty */ }
+    public static class AppPictureInPictureSettingsActivity extends SettingsActivity { /* empty */ }
     public static class ZenAccessSettingsActivity extends SettingsActivity { /* empty */ }
     public static class ConditionProviderSettingsActivity extends SettingsActivity { /* empty */ }
     public static class UsbSettingsActivity extends SettingsActivity { /* empty */ }
diff --git a/src/com/android/settings/TetherSettings.java b/src/com/android/settings/TetherSettings.java
index 0a0eed2..61cad39 100644
--- a/src/com/android/settings/TetherSettings.java
+++ b/src/com/android/settings/TetherSettings.java
@@ -132,6 +132,8 @@
         super.onCreate(icicle);
 
         addPreferencesFromResource(R.xml.tether_prefs);
+        mFooterPreferenceMixin.createFooterPreference()
+            .setTitle(R.string.tethering_footer_info);
 
         mDataSaverBackend = new DataSaverBackend(getContext());
         mDataSaverEnabled = mDataSaverBackend.isDataSaverEnabled();
diff --git a/src/com/android/settings/accessibility/AccessibilitySettings.java b/src/com/android/settings/accessibility/AccessibilitySettings.java
index 86c340d..eaadf13 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettings.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettings.java
@@ -775,8 +775,6 @@
                 SearchIndexableRaw indexable = new SearchIndexableRaw(context);
                 indexable.key = componentName.flattenToString();
                 indexable.title = service.getResolveInfo().loadLabel(packageManager).toString();
-                indexable.summaryOn = context.getString(R.string.accessibility_feature_state_on);
-                indexable.summaryOff = context.getString(R.string.accessibility_feature_state_off);
                 indexable.screenTitle = screenTitle;
                 indexables.add(indexable);
             }
diff --git a/src/com/android/settings/applications/AdvancedAppSettings.java b/src/com/android/settings/applications/AdvancedAppSettings.java
index b8ebeb4..e59f94b 100644
--- a/src/com/android/settings/applications/AdvancedAppSettings.java
+++ b/src/com/android/settings/applications/AdvancedAppSettings.java
@@ -20,7 +20,6 @@
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
-import com.android.settings.applications.defaultapps.DefaultAutofillPreferenceController;
 import com.android.settings.applications.defaultapps.DefaultBrowserPreferenceController;
 import com.android.settings.applications.defaultapps.DefaultEmergencyPreferenceController;
 import com.android.settings.applications.defaultapps.DefaultHomePreferenceController;
@@ -61,7 +60,6 @@
         controllers.add(new DefaultSmsPreferenceController(context));
         controllers.add(new DefaultEmergencyPreferenceController(context));
         controllers.add(new DefaultHomePreferenceController(context));
-        controllers.add(new DefaultAutofillPreferenceController(context));
         return controllers;
     }
 
diff --git a/src/com/android/settings/applications/AppCounter.java b/src/com/android/settings/applications/AppCounter.java
index 9464531..09a10e2 100644
--- a/src/com/android/settings/applications/AppCounter.java
+++ b/src/com/android/settings/applications/AppCounter.java
@@ -57,6 +57,10 @@
         onCountComplete(count);
     }
 
+    void executeInForeground() {
+        onPostExecute(doInBackground());
+    }
+
     protected abstract void onCountComplete(int num);
     protected abstract List<UserInfo> getUsersToCount();
     protected abstract boolean includeInCount(ApplicationInfo info);
diff --git a/src/com/android/settings/applications/AppStateInstallAppsBridge.java b/src/com/android/settings/applications/AppStateInstallAppsBridge.java
index 39a31e6..cc7fb62 100644
--- a/src/com/android/settings/applications/AppStateInstallAppsBridge.java
+++ b/src/com/android/settings/applications/AppStateInstallAppsBridge.java
@@ -43,12 +43,10 @@
 
     private final IPackageManager mIpm;
     private final AppOpsManager mAppOpsManager;
-    private final Context mContext;
 
     public AppStateInstallAppsBridge(Context context, ApplicationsState appState,
             Callback callback) {
         super(appState, callback);
-        mContext = context;
         mIpm = AppGlobals.getPackageManager();
         mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
     }
diff --git a/src/com/android/settings/applications/ApplicationFeatureProvider.java b/src/com/android/settings/applications/ApplicationFeatureProvider.java
index fccbbd3..51e79d8 100644
--- a/src/com/android/settings/applications/ApplicationFeatureProvider.java
+++ b/src/com/android/settings/applications/ApplicationFeatureProvider.java
@@ -35,15 +35,17 @@
     public static final int IGNORE_INSTALL_REASON = -1;
 
     /**
-     * Asynchronously calculates the total number of apps installed on the device, across all users
-     * and managed profiles.
+     * Calculates the total number of apps installed on the device, across all users and managed
+     * profiles.
      *
      * @param installReason Only consider apps with this install reason; may be any install reason
      *         defined in {@link android.content.pm.PackageManager} or
      *         {@link #IGNORE_INSTALL_REASON} to count all apps, irrespective of install reason.
+     * @param async Whether to count asynchronously in a background thread
      * @param callback The callback to invoke with the result
      */
-    void calculateNumberOfInstalledApps(int installReason, NumberOfAppsCallback callback);
+    void calculateNumberOfInstalledApps(int installReason, boolean async,
+            NumberOfAppsCallback callback);
 
     /**
      * Asynchronously calculates the total number of apps installed on the device, across all users
@@ -52,9 +54,10 @@
      *
      * @param permissions Only consider apps that have been granted one or more of these permissions
      *        by the admin, either at run-time or install-time
+     * @param async Whether to count asynchronously in a background thread
      * @param callback The callback to invoke with the result
      */
-    void calculateNumberOfAppsWithAdminGrantedPermissions(String[] permissions,
+    void calculateNumberOfAppsWithAdminGrantedPermissions(String[] permissions, boolean async,
             NumberOfAppsCallback callback);
 
     /**
diff --git a/src/com/android/settings/applications/ApplicationFeatureProviderImpl.java b/src/com/android/settings/applications/ApplicationFeatureProviderImpl.java
index 31d26ed..77c9f3e 100644
--- a/src/com/android/settings/applications/ApplicationFeatureProviderImpl.java
+++ b/src/com/android/settings/applications/ApplicationFeatureProviderImpl.java
@@ -56,15 +56,28 @@
     }
 
     @Override
-    public void calculateNumberOfInstalledApps(int installReason, NumberOfAppsCallback callback) {
-        new AllUserInstalledAppCounter(mContext, installReason, mPm, callback).execute();
+    public void calculateNumberOfInstalledApps(int installReason, boolean async,
+            NumberOfAppsCallback callback) {
+        final AllUserInstalledAppCounter counter = new AllUserInstalledAppCounter(mContext,
+                installReason, mPm, callback);
+        if (async) {
+            counter.execute();
+        } else {
+            counter.executeInForeground();
+        }
     }
 
     @Override
     public void calculateNumberOfAppsWithAdminGrantedPermissions(String[] permissions,
-            NumberOfAppsCallback callback) {
-        new AllUserAppWithAdminGrantedPermissionsCounter(mContext, permissions, mPm, mPms, mDpm,
-                callback).execute();
+            boolean async, NumberOfAppsCallback callback) {
+        final AllUserAppWithAdminGrantedPermissionsCounter counter =
+                new AllUserAppWithAdminGrantedPermissionsCounter(mContext, permissions, mPm, mPms,
+                        mDpm, callback);
+        if (async) {
+            counter.execute();
+        } else {
+            counter.executeInForeground();
+        }
     }
 
     @Override
diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java
index 08be7f7..e00ba92 100755
--- a/src/com/android/settings/applications/InstalledAppDetails.java
+++ b/src/com/android/settings/applications/InstalledAppDetails.java
@@ -52,7 +52,6 @@
 import android.os.UserHandle;
 import android.os.UserManager;
 import android.support.annotation.VisibleForTesting;
-import android.support.v14.preference.SwitchPreference;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.Preference.OnPreferenceClickListener;
 import android.support.v7.preference.PreferenceCategory;
@@ -1041,17 +1040,16 @@
                 category.addPreference(pref);
             }
             if (hasPictureInPictureActivities) {
-                final SwitchPreference pref = new SwitchPreference(getPrefContext());
-                pref.setPersistent(false);
+                Preference pref = new Preference(getPrefContext());
                 pref.setTitle(R.string.picture_in_picture_app_detail_title);
-                pref.setSummary(R.string.picture_in_picture_app_detail_summary);
-                pref.setChecked(PictureInPictureSettings.getEnterPipOnHideStateForPackage(
-                        getContext(), mPackageInfo.applicationInfo.uid, mPackageName));
-                pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+                pref.setKey("picture_in_picture");
+                pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                     @Override
-                    public boolean onPreferenceChange(Preference preference, Object newValue) {
-                        PictureInPictureSettings.setEnterPipOnHideStateForPackage(getContext(),
-                                mPackageInfo.applicationInfo.uid, mPackageName, (Boolean) newValue);
+                    public boolean onPreferenceClick(Preference preference) {
+                        AppInfoBase.startAppInfoFragment(PictureInPictureDetails.class,
+                                R.string.picture_in_picture_app_detail_title, mPackageName,
+                                mPackageInfo.applicationInfo.uid, InstalledAppDetails.this,
+                                -1, getMetricsCategory());
                         return true;
                     }
                 });
@@ -1164,6 +1162,11 @@
         if (pref != null) {
             pref.setSummary(DrawOverlayDetails.getSummary(getContext(), mAppEntry));
         }
+        pref = findPreference("picture_in_picture");
+        if (pref != null) {
+            pref.setSummary(PictureInPictureDetails.getPreferenceSummary(getContext(),
+                    mPackageInfo.applicationInfo.uid, mPackageName));
+        }
         pref = findPreference("write_settings_apps");
         if (pref != null) {
             pref.setSummary(WriteSettingsDetails.getSummary(getContext(), mAppEntry));
diff --git a/src/com/android/settings/applications/PictureInPictureDetails.java b/src/com/android/settings/applications/PictureInPictureDetails.java
new file mode 100644
index 0000000..41f006a
--- /dev/null
+++ b/src/com/android/settings/applications/PictureInPictureDetails.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.applications;
+
+import static android.app.AppOpsManager.MODE_ALLOWED;
+import static android.app.AppOpsManager.MODE_ERRORED;
+import static android.app.AppOpsManager.OP_PICTURE_IN_PICTURE;
+
+import android.app.AlertDialog;
+import android.app.AppOpsManager;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.provider.Settings;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.Preference.OnPreferenceChangeListener;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.R;
+import com.android.settings.overlay.FeatureFactory;
+
+public class PictureInPictureDetails extends AppInfoWithHeader
+        implements OnPreferenceChangeListener {
+
+    private static final String KEY_APP_OPS_SETTINGS_SWITCH = "app_ops_settings_switch";
+    private static final String KEY_APP_OPS_SETTINGS_PREFS = "app_ops_settings_preference";
+    private static final String KEY_APP_OPS_SETTINGS_DESC = "app_ops_settings_description";
+    private static final String LOG_TAG = "PictureInPictureDetails";
+
+    private SwitchPreference mSwitchPref;
+    private Preference mOverlayDesc;
+    private Intent mSettingsIntent;
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        // find preferences
+        addPreferencesFromResource(R.xml.app_ops_permissions_details);
+        mSwitchPref = (SwitchPreference) findPreference(KEY_APP_OPS_SETTINGS_SWITCH);
+        mOverlayDesc = findPreference(KEY_APP_OPS_SETTINGS_DESC);
+        getPreferenceScreen().removePreference(findPreference(KEY_APP_OPS_SETTINGS_PREFS));
+
+        // set title/summary for all of them
+        getPreferenceScreen().setTitle(R.string.picture_in_picture_app_detail_title);
+        mSwitchPref.setTitle(R.string.picture_in_picture_app_detail_switch);
+        mOverlayDesc.setSummary(R.string.picture_in_picture_app_detail_summary);
+
+        // install event listeners
+        mSwitchPref.setOnPreferenceChangeListener(this);
+
+        mSettingsIntent = new Intent(Intent.ACTION_MAIN)
+                .setAction(Settings.ACTION_PICTURE_IN_PICTURE_SETTINGS);
+    }
+
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        if (preference == mSwitchPref) {
+            logSpecialPermissionChange((Boolean) newValue, mPackageName);
+            setEnterPipStateForPackage(getActivity(), mPackageInfo.applicationInfo.uid, mPackageName,
+                    (Boolean) newValue);
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    protected boolean refreshUi() {
+        boolean isAllowed = getEnterPipStateForPackage(getActivity(),
+                mPackageInfo.applicationInfo.uid, mPackageName);
+        mSwitchPref.setChecked(isAllowed);
+        return true;
+    }
+
+    @Override
+    protected AlertDialog createDialog(int id, int errorCode) {
+        return null;
+    }
+
+    @Override
+    public int getMetricsCategory() {
+        return MetricsEvent.SETTINGS_MANAGE_PICTURE_IN_PICTURE;
+    }
+
+    /**
+     * Sets whether the app associated with the given {@param packageName} is allowed to enter
+     * picture-in-picture.
+     */
+    static void setEnterPipStateForPackage(Context context, int uid, String packageName,
+            boolean value) {
+        final AppOpsManager appOps = context.getSystemService(AppOpsManager.class);
+        final int newMode = value ? MODE_ALLOWED : MODE_ERRORED;
+        appOps.setMode(OP_PICTURE_IN_PICTURE, uid, packageName, newMode);
+    }
+
+    /**
+     * @return whether the app associated with the given {@param packageName} is allowed to enter
+     *         picture-in-picture.
+     */
+    static boolean getEnterPipStateForPackage(Context context, int uid, String packageName) {
+        final AppOpsManager appOps = context.getSystemService(AppOpsManager.class);
+        return appOps.checkOpNoThrow(OP_PICTURE_IN_PICTURE, uid, packageName) == MODE_ALLOWED;
+    }
+
+    /**
+     * @return the summary for the current state of whether the app associated with the given
+     *         {@param packageName} is allowed to enter picture-in-picture.
+     */
+    static int getPreferenceSummary(Context context, int uid, String packageName) {
+        final boolean enabled = PictureInPictureDetails.getEnterPipStateForPackage(context, uid,
+                packageName);
+        return enabled ? R.string.picture_in_picture_on : R.string.picture_in_picture_off;
+    }
+
+    @VisibleForTesting
+    void logSpecialPermissionChange(boolean newState, String packageName) {
+        int logCategory = newState
+                ? MetricsEvent.APP_PICTURE_IN_PICTURE_ALLOW
+                : MetricsEvent.APP_PICTURE_IN_PICTURE_DENY;
+        FeatureFactory.getFactory(getContext())
+                .getMetricsFeatureProvider().action(getContext(), logCategory, packageName);
+    }
+}
diff --git a/src/com/android/settings/applications/PictureInPictureSettings.java b/src/com/android/settings/applications/PictureInPictureSettings.java
index df73572..b1c544a 100644
--- a/src/com/android/settings/applications/PictureInPictureSettings.java
+++ b/src/com/android/settings/applications/PictureInPictureSettings.java
@@ -15,13 +15,9 @@
  */
 package com.android.settings.applications;
 
-import static android.app.AppOpsManager.MODE_ALLOWED;
-import static android.app.AppOpsManager.MODE_ERRORED;
-import static android.app.AppOpsManager.OP_ENTER_PICTURE_IN_PICTURE_ON_HIDE;
 import static android.content.pm.PackageManager.GET_ACTIVITIES;
 
 import android.annotation.Nullable;
-import android.app.AppOpsManager;
 import android.content.Context;
 import android.content.pm.ActivityInfo;
 import android.content.pm.ApplicationInfo;
@@ -30,8 +26,8 @@
 import android.content.pm.PackageManager;
 import android.os.Bundle;
 import android.os.UserHandle;
-import android.support.v14.preference.SwitchPreference;
 import android.support.v7.preference.Preference;
+import android.support.v7.preference.Preference.OnPreferenceClickListener;
 import android.support.v7.preference.PreferenceScreen;
 import android.util.ArrayMap;
 import android.view.View;
@@ -40,7 +36,6 @@
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
 import com.android.settings.notification.EmptyTextSettings;
-import com.android.settings.overlay.FeatureFactory;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -98,28 +93,6 @@
         return false;
     }
 
-    /**
-     * Sets whether the app associated with the given {@param packageName} is allowed to enter
-     * picture-in-picture when it is hidden.
-     */
-    static void setEnterPipOnHideStateForPackage(Context context, int uid, String packageName,
-            boolean value) {
-        final AppOpsManager appOps = context.getSystemService(AppOpsManager.class);
-        final int newMode = value ? MODE_ALLOWED : MODE_ERRORED;
-        appOps.setMode(OP_ENTER_PICTURE_IN_PICTURE_ON_HIDE,
-                uid, packageName, newMode);
-    }
-
-    /**
-     * @return whether the app associated with the given {@param packageName} is allowed to enter
-     *         picture-in-picture when it is hidden.
-     */
-    static boolean getEnterPipOnHideStateForPackage(Context context, int uid, String packageName) {
-        final AppOpsManager appOps = context.getSystemService(AppOpsManager.class);
-        return appOps.checkOpNoThrow(OP_ENTER_PICTURE_IN_PICTURE_ON_HIDE,
-                uid, packageName) == MODE_ALLOWED;
-    }
-
     @Override
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
@@ -147,8 +120,8 @@
             if (checkPackageHasPictureInPictureActivities(packageInfo.packageName,
                     packageInfo.activities)) {
                 final String packageName = packageInfo.applicationInfo.packageName;
-                final boolean state = getEnterPipOnHideStateForPackage(mContext,
-                        packageInfo.applicationInfo.uid, packageName);
+                final boolean state = PictureInPictureDetails.getEnterPipStateForPackage(
+                        mContext, packageInfo.applicationInfo.uid, packageName);
                 pipApps.add(packageInfo.applicationInfo);
                 packageToState.put(packageName, state);
             }
@@ -160,17 +133,18 @@
         for (final ApplicationInfo appInfo : pipApps) {
             final String packageName = appInfo.packageName;
             final CharSequence label = appInfo.loadLabel(mPackageManager);
-            final SwitchPreference pref = new SwitchPreference(prefContext);
-            pref.setPersistent(false);
+
+            final Preference pref = new Preference(prefContext);
             pref.setIcon(appInfo.loadIcon(mPackageManager));
             pref.setTitle(label);
-            pref.setChecked(packageToState.get(packageName));
-            pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+            pref.setSummary(PictureInPictureDetails.getPreferenceSummary(prefContext,
+                    appInfo.uid, packageName));
+            pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                 @Override
-                public boolean onPreferenceChange(Preference preference, Object newValue) {
-                    logSpecialPermissionChange((Boolean) newValue, packageName);
-                    setEnterPipOnHideStateForPackage(mContext, appInfo.uid, packageName,
-                            (Boolean) newValue);
+                public boolean onPreferenceClick(Preference preference) {
+                    AppInfoBase.startAppInfoFragment(PictureInPictureDetails.class,
+                            R.string.picture_in_picture_app_detail_title, packageName, appInfo.uid,
+                            PictureInPictureSettings.this, -1, getMetricsCategory());
                     return true;
                 }
             });
@@ -188,13 +162,4 @@
     public int getMetricsCategory() {
         return MetricsEvent.SETTINGS_MANAGE_PICTURE_IN_PICTURE;
     }
-
-    @VisibleForTesting
-    void logSpecialPermissionChange(boolean newState, String packageName) {
-        int logCategory = newState
-                ? MetricsEvent.APP_PICTURE_IN_PICTURE_ON_HIDE_ALLOW
-                : MetricsEvent.APP_PICTURE_IN_PICTURE_ON_HIDE_DENY;
-        FeatureFactory.getFactory(getContext())
-                .getMetricsFeatureProvider().action(getContext(), logCategory, packageName);
-    }
 }
diff --git a/src/com/android/settings/applications/defaultapps/DefaultAppPreferenceController.java b/src/com/android/settings/applications/defaultapps/DefaultAppPreferenceController.java
index d8fb225..4c65fca 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultAppPreferenceController.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultAppPreferenceController.java
@@ -24,6 +24,7 @@
 import android.text.TextUtils;
 import android.util.Log;
 
+import com.android.settings.R;
 import com.android.settings.applications.PackageManagerWrapper;
 import com.android.settings.applications.PackageManagerWrapperImpl;
 import com.android.settings.core.PreferenceController;
@@ -56,7 +57,7 @@
             preference.setSummary(defaultAppLabel);
         } else {
             Log.d(TAG, "No default app");
-            preference.setSummary(null);
+            preference.setSummary(R.string.app_list_preference_none);
         }
         mayUpdateGearIcon(app, preference);
     }
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingService.java b/src/com/android/settings/bluetooth/BluetoothPairingService.java
index a24a3f0..5dfd283 100644
--- a/src/com/android/settings/bluetooth/BluetoothPairingService.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingService.java
@@ -80,6 +80,7 @@
         Log.d(TAG, "Dismiss pairing for " + mDevice.getAddress() + " (" + mDevice.getName() + "), Cancelled.");
       }
       stopForeground(true);
+      stopSelf();
     }
   };
 
@@ -89,6 +90,12 @@
 
   @Override
   public int onStartCommand(Intent intent, int flags, int startId) {
+    if (intent == null) {
+      Log.e(TAG, "Can't start: null intent!");
+      stopSelf();
+      return START_NOT_STICKY;
+    }
+
     Resources res = getResources();
     Notification.Builder builder = new Notification.Builder(this)
         .setSmallIcon(android.R.drawable.stat_sys_data_bluetooth)
@@ -99,6 +106,12 @@
 
     mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
 
+    if (mDevice.getBondState() != BluetoothDevice.BOND_BONDING) {
+      Log.w(TAG, "Device " + mDevice + " not bonding: " + mDevice.getBondState());
+      stopSelf();
+      return START_NOT_STICKY;
+    }
+
     String name = intent.getStringExtra(BluetoothDevice.EXTRA_NAME);
     if (TextUtils.isEmpty(name)) {
       BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
@@ -119,7 +132,7 @@
     registerReceiver(mCancelReceiver, filter);
 
     startForeground(NOTIFICATION_ID, builder.getNotification());
-    return START_STICKY;
+    return START_REDELIVER_INTENT;
   }
 
   @Override
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index fb2c9ce..467b848 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -52,6 +52,7 @@
 import com.android.settings.applications.ManageApplications;
 import com.android.settings.applications.ManageDomainUrls;
 import com.android.settings.applications.NotificationApps;
+import com.android.settings.applications.PictureInPictureDetails;
 import com.android.settings.applications.PictureInPictureSettings;
 import com.android.settings.applications.ProcessStatsSummary;
 import com.android.settings.applications.ProcessStatsUi;
@@ -218,6 +219,7 @@
             WallpaperTypeSettings.class.getName(),
             VrListenerSettings.class.getName(),
             PictureInPictureSettings.class.getName(),
+            PictureInPictureDetails.class.getName(),
             ManagedProfileSettings.class.getName(),
             ChooseAccountActivity.class.getName(),
             IccLockSettings.class.getName(),
diff --git a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
index 722f9e1..78d6122 100644
--- a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
+++ b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
@@ -28,6 +28,7 @@
 import android.util.Log;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.R;
 import com.android.settings.SettingsActivity;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
 import com.android.settings.overlay.FeatureFactory;
@@ -124,7 +125,11 @@
         } else {
             pref.setKey(getDashboardKeyForTile(tile));
         }
-        pref.setSummary(tile.summary);
+        if (tile.summary != null) {
+            pref.setSummary(tile.summary);
+        } else {
+            pref.setSummary(R.string.summary_placeholder);
+        }
         if (tile.icon != null) {
             pref.setIcon(tile.icon.loadDrawable(activity));
         }
diff --git a/src/com/android/settings/datausage/DataUsageList.java b/src/com/android/settings/datausage/DataUsageList.java
index e12f89e..de92154 100644
--- a/src/com/android/settings/datausage/DataUsageList.java
+++ b/src/com/android/settings/datausage/DataUsageList.java
@@ -477,7 +477,7 @@
 
         final ConnectivityManager conn = ConnectivityManager.from(context);
         final TelephonyManager tele = TelephonyManager.from(context);
-        final int slotId = SubscriptionManager.getSlotId(subId);
+        final int slotId = SubscriptionManager.getSlotIndex(subId);
         final boolean isReady = tele.getSimState(slotId) == SIM_STATE_READY;
 
         boolean retVal = conn.isNetworkSupported(TYPE_MOBILE) && isReady;
diff --git a/src/com/android/settings/datausage/DataUsageSummary.java b/src/com/android/settings/datausage/DataUsageSummary.java
index 41dc78f..8eb1f61 100644
--- a/src/com/android/settings/datausage/DataUsageSummary.java
+++ b/src/com/android/settings/datausage/DataUsageSummary.java
@@ -20,13 +20,18 @@
 import android.content.Intent;
 import android.net.ConnectivityManager;
 import android.net.INetworkStatsSession;
+import android.net.NetworkPolicy;
+import android.net.NetworkPolicyManager;
 import android.net.NetworkTemplate;
 import android.net.TrafficStats;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
 import android.os.Bundle;
 import android.os.RemoteException;
 import android.os.SystemProperties;
 import android.os.UserManager;
 import android.provider.SearchIndexableResource;
+import android.support.annotation.VisibleForTesting;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceScreen;
 import android.telephony.SubscriptionInfo;
@@ -56,6 +61,7 @@
 
 import static android.net.ConnectivityManager.TYPE_ETHERNET;
 import static android.net.ConnectivityManager.TYPE_WIFI;
+import static android.net.NetworkPolicy.LIMIT_DISABLED;
 
 public class DataUsageSummary extends DataUsageBase implements Indexable, DataUsageEditController {
 
@@ -68,6 +74,7 @@
     private static final String KEY_STATUS_HEADER = "status_header";
     private static final String KEY_LIMIT_SUMMARY = "limit_summary";
     private static final String KEY_RESTRICT_BACKGROUND = "restrict_background";
+    private static final String KEY_NETWORK_RESTRICTIONS = "network_restrictions";
 
     private DataUsageController mDataUsageController;
     private DataUsageInfoController mDataInfoController;
@@ -75,6 +82,10 @@
     private Preference mLimitPreference;
     private NetworkTemplate mDefaultTemplate;
     private int mDataUsageTemplate;
+    private NetworkRestrictionsPreference mNetworkRestrcitionPreference;
+    private WifiManager mWifiManager;
+    private NetworkPolicyManager mPolicyManager;
+    private NetworkPolicyEditor mPolicyEditor;
 
     @Override
     protected int getHelpResource() {
@@ -85,16 +96,21 @@
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
 
-        boolean hasMobileData = hasMobileData(getContext());
-        mDataUsageController = new DataUsageController(getContext());
+        final Context context = getContext();
+        mPolicyManager = NetworkPolicyManager.from(context);
+        mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
+        mPolicyEditor = new NetworkPolicyEditor(mPolicyManager);
+
+        boolean hasMobileData = hasMobileData(context);
+        mDataUsageController = new DataUsageController(context);
         mDataInfoController = new DataUsageInfoController();
         addPreferencesFromResource(R.xml.data_usage);
 
-        int defaultSubId = getDefaultSubscriptionId(getContext());
+        int defaultSubId = getDefaultSubscriptionId(context);
         if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
             hasMobileData = false;
         }
-        mDefaultTemplate = getDefaultTemplate(getContext(), defaultSubId);
+        mDefaultTemplate = getDefaultTemplate(context, defaultSubId);
         mSummaryPreference = (SummaryPreference) findPreference(KEY_STATUS_HEADER);
 
         if (!hasMobileData || !isAdmin()) {
@@ -115,11 +131,11 @@
             removePreference(KEY_LIMIT_SUMMARY);
             mSummaryPreference.setSelectable(false);
         }
-        boolean hasWifiRadio = hasWifiRadio(getContext());
+        boolean hasWifiRadio = hasWifiRadio(context);
         if (hasWifiRadio) {
             addWifiSection();
         }
-        if (hasEthernet(getContext())) {
+        if (hasEthernet(context)) {
             addEthernetSection();
         }
         mDataUsageTemplate = hasMobileData ? R.string.cell_data_template
@@ -171,6 +187,8 @@
         TemplatePreferenceCategory category = (TemplatePreferenceCategory)
                 inflatePreferences(R.xml.data_usage_wifi);
         category.setTemplate(NetworkTemplate.buildTemplateWifiWildcard(), 0, services);
+        mNetworkRestrcitionPreference =
+            (NetworkRestrictionsPreference) category.findPreference(KEY_NETWORK_RESTRICTIONS);
     }
 
     private void addEthernetSection() {
@@ -259,6 +277,8 @@
             mLimitPreference.setSummary(null);
         }
 
+        updateNetworkRestrictionSummary(mNetworkRestrcitionPreference);
+
         PreferenceScreen screen = getPreferenceScreen();
         for (int i = 1; i < screen.getPreferenceCount(); i++) {
             ((TemplatePreferenceCategory) screen.getPreference(i)).pushTemplates(services);
@@ -362,6 +382,39 @@
         }
     }
 
+    @VisibleForTesting
+    void updateNetworkRestrictionSummary(NetworkRestrictionsPreference preference) {
+        if (preference == null) {
+            return;
+        }
+        mPolicyEditor.read();
+        int count = 0;
+        for (WifiConfiguration config : mWifiManager.getConfiguredNetworks()) {
+            if (isMetered(config)) {
+                count++;
+            }
+        }
+        preference.setSummary(getResources().getQuantityString(
+            R.plurals.network_restrictions_summary, count, count));
+    }
+
+    @VisibleForTesting
+    boolean isMetered(WifiConfiguration config) {
+        if (config.SSID == null) {
+            return false;
+        }
+        final String networkId = config.isPasspoint() ? config.providerFriendlyName : config.SSID;
+        final NetworkPolicy policy =
+            mPolicyEditor.getPolicyMaybeUnquoted(NetworkTemplate.buildTemplateWifi(networkId));
+        if (policy == null) {
+            return false;
+        }
+        if (policy.limitBytes != LIMIT_DISABLED) {
+            return true;
+        }
+        return policy.metered;
+    }
+
     private static class SummaryProvider
             implements SummaryLoader.SummaryProvider {
 
diff --git a/src/com/android/settings/development/DevelopmentSettings.java b/src/com/android/settings/development/DevelopmentSettings.java
index 2a4a231..0a3351a 100644
--- a/src/com/android/settings/development/DevelopmentSettings.java
+++ b/src/com/android/settings/development/DevelopmentSettings.java
@@ -23,7 +23,6 @@
 import android.app.AppOpsManager;
 import android.app.AppOpsManager.PackageOps;
 import android.app.Dialog;
-import android.app.admin.DevicePolicyManager;
 import android.app.backup.IBackupManager;
 import android.bluetooth.BluetoothA2dp;
 import android.bluetooth.BluetoothAdapter;
@@ -246,17 +245,15 @@
     private IWindowManager mWindowManager;
     private IBackupManager mBackupManager;
     private IWebViewUpdateService mWebViewUpdateService;
-    private DevicePolicyManager mDpm;
     private UserManager mUm;
     private WifiManager mWifiManager;
     private PersistentDataBlockManager mOemUnlockManager;
     private TelephonyManager mTelephonyManager;
 
     private SwitchBar mSwitchBar;
-    private boolean mLastEnabledState;
+
     private boolean mHaveDebugSettings;
     private boolean mDontPokeProperties;
-
     private SwitchPreference mEnableAdb;
     private Preference mClearAdbKeys;
     private SwitchPreference mEnableTerminal;
@@ -350,6 +347,7 @@
     private boolean mLogpersistCleared;
     private Dialog mLogpersistClearDialog;
     private DashboardFeatureProvider mDashboardFeatureProvider;
+    private DevelopmentSettingsEnabler mSettingsEnabler;
     private BugReportPreferenceController mBugReportController;
     private BugReportInPowerPreferenceController mBugReportInPowerController;
     private TelephonyMonitorPreferenceController mTelephonyMonitorController;
@@ -366,6 +364,7 @@
     @Override
     public void onAttach(Context context) {
         super.onAttach(context);
+        mSettingsEnabler = new DevelopmentSettingsEnabler(context, getLifecycle());
         mDashboardFeatureProvider = FeatureFactory.getFactory(context)
                 .getDashboardFeatureProvider(context);
     }
@@ -382,7 +381,6 @@
                 .getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
         mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
 
-        mDpm = (DevicePolicyManager) getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
         mUm = (UserManager) getSystemService(Context.USER_SERVICE);
 
         mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
@@ -671,22 +669,18 @@
             mDisabledPrefs.add(mKeepScreenOn);
         }
 
-        final ContentResolver cr = getActivity().getContentResolver();
-        mLastEnabledState = Settings.Global.getInt(cr,
-                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
-        mSwitchBar.setChecked(mLastEnabledState);
-        setPrefsEnabledState(mLastEnabledState);
+        final boolean lastEnabledState = mSettingsEnabler.getLastEnabledState();
+        mSwitchBar.setChecked(lastEnabledState);
+        setPrefsEnabledState(lastEnabledState);
 
-        if (mHaveDebugSettings && !mLastEnabledState) {
+        if (mHaveDebugSettings && !lastEnabledState) {
             // Overall debugging is disabled, but there are some debug
             // settings that are enabled.  This is an invalid state.  Switch
             // to debug settings being enabled, so the user knows there is
             // stuff enabled and can turn it all off if they want.
-            Settings.Global.putInt(getActivity().getContentResolver(),
-                    Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
-            mLastEnabledState = true;
-            mSwitchBar.setChecked(mLastEnabledState);
-            setPrefsEnabledState(mLastEnabledState);
+            mSettingsEnabler.enableDevelopmentSettings();
+            mSwitchBar.setChecked(lastEnabledState);
+            setPrefsEnabledState(lastEnabledState);
         }
         mSwitchBar.show();
 
@@ -1560,7 +1554,7 @@
                         || currentValue.equals(SELECT_LOGD_OFF_SIZE_MARKER_VALUE)) {
                     writeLogpersistOption(null, true);
                     mLogpersist.setEnabled(false);
-                } else if (mLastEnabledState) {
+                } else if (mSettingsEnabler.getLastEnabledState()) {
                     mLogpersist.setEnabled(true);
                 }
             }
@@ -1848,8 +1842,9 @@
                 }
             }
         }
-        if (codecConfig == null)
+        if (codecConfig == null) {
             return;
+        }
 
         try {
             resources = getResources();
@@ -2329,7 +2324,8 @@
         if (switchView != mSwitchBar.getSwitch()) {
             return;
         }
-        if (isChecked != mLastEnabledState) {
+        final boolean lastEnabledState = mSettingsEnabler.getLastEnabledState();
+        if (isChecked != lastEnabledState) {
             if (isChecked) {
                 mDialogClicked = false;
                 if (mEnableDialog != null) dismissDialogs();
@@ -2343,10 +2339,8 @@
                 mEnableDialog.setOnDismissListener(this);
             } else {
                 resetDangerousOptions();
-                Settings.Global.putInt(getActivity().getContentResolver(),
-                        Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
-                mLastEnabledState = isChecked;
-                setPrefsEnabledState(mLastEnabledState);
+                mSettingsEnabler.disableDevelopmentSettings();
+                setPrefsEnabledState(false);
             }
         }
     }
@@ -2629,10 +2623,8 @@
         } else if (dialog == mEnableDialog) {
             if (which == DialogInterface.BUTTON_POSITIVE) {
                 mDialogClicked = true;
-                Settings.Global.putInt(getActivity().getContentResolver(),
-                        Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
-                mLastEnabledState = true;
-                setPrefsEnabledState(mLastEnabledState);
+                mSettingsEnabler.enableDevelopmentSettings();
+                setPrefsEnabledState(true);
             } else {
                 // Reset the toggle
                 mSwitchBar.setChecked(false);
diff --git a/src/com/android/settings/development/DevelopmentSettingsEnabler.java b/src/com/android/settings/development/DevelopmentSettingsEnabler.java
new file mode 100644
index 0000000..e97997e
--- /dev/null
+++ b/src/com/android/settings/development/DevelopmentSettingsEnabler.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.development;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.provider.Settings;
+
+import com.android.settings.core.lifecycle.Lifecycle;
+import com.android.settings.core.lifecycle.LifecycleObserver;
+import com.android.settings.core.lifecycle.events.OnResume;
+
+public class DevelopmentSettingsEnabler implements LifecycleObserver, OnResume {
+
+    private final Context mContext;
+    private final SharedPreferences mDevelopmentPreferences;
+    private boolean mLastEnabledState;
+
+    public DevelopmentSettingsEnabler(Context context, Lifecycle lifecycle) {
+        mContext = context;
+        mDevelopmentPreferences = context.getSharedPreferences(DevelopmentSettings.PREF_FILE,
+                Context.MODE_PRIVATE);
+        if (lifecycle != null) {
+            lifecycle.addObserver(this);
+        }
+    }
+
+    @Override
+    public void onResume() {
+        mLastEnabledState = Settings.Global.getInt(mContext.getContentResolver(),
+                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
+    }
+
+    public static boolean enableDevelopmentSettings(Context context, SharedPreferences prefs) {
+        prefs.edit()
+                .putBoolean(DevelopmentSettings.PREF_SHOW, true)
+                .commit();
+        return Settings.Global.putInt(context.getContentResolver(),
+                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
+    }
+
+    public boolean getLastEnabledState() {
+        return mLastEnabledState;
+    }
+
+    public void enableDevelopmentSettings() {
+        mLastEnabledState = enableDevelopmentSettings(mContext, mDevelopmentPreferences);
+    }
+
+    public void disableDevelopmentSettings() {
+        mDevelopmentPreferences.edit()
+                .putBoolean(DevelopmentSettings.PREF_SHOW, false)
+                .commit();
+        Settings.Global.putInt(mContext.getContentResolver(),
+                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
+        mLastEnabledState = false;
+    }
+}
diff --git a/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java b/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
index 4062be8..f174e10 100644
--- a/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
@@ -39,8 +39,8 @@
 import com.android.settings.core.lifecycle.LifecycleObserver;
 import com.android.settings.core.lifecycle.events.OnResume;
 import com.android.settings.development.DevelopmentSettings;
+import com.android.settings.development.DevelopmentSettingsEnabler;
 import com.android.settings.overlay.FeatureFactory;
-import com.android.settings.search2.SearchFeatureProvider;
 import com.android.settingslib.RestrictedLockUtils;
 
 public class BuildNumberPreferenceController extends PreferenceController
@@ -210,10 +210,9 @@
     private void enableDevelopmentSettings() {
         mDevHitCountdown = 0;
         mProcessingLastDevHit = false;
-        mContext.getSharedPreferences(DevelopmentSettings.PREF_FILE,
-                Context.MODE_PRIVATE).edit()
-                .putBoolean(DevelopmentSettings.PREF_SHOW, true)
-                .apply();
+        DevelopmentSettingsEnabler.enableDevelopmentSettings(mContext,
+                mContext.getSharedPreferences(DevelopmentSettings.PREF_FILE,
+                        Context.MODE_PRIVATE));
         if (mDevHitToast != null) {
             mDevHitToast.cancel();
         }
diff --git a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
index 133c56c..18393ac 100644
--- a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
+++ b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
@@ -114,6 +114,16 @@
         mSummaryController.updateBytes(usedBytes, totalSize);
         mPreferenceController.setVolume(mVolume);
         mPreferenceController.setSystemSize(systemSize);
+
+        mPreferenceController.setTotalSize(totalSize);
+        for (int i = 0, size = mSecondaryUsers.size(); i < size; i++) {
+            PreferenceController controller = mSecondaryUsers.get(i);
+            if (controller instanceof SecondaryUserController) {
+                SecondaryUserController userController = (SecondaryUserController) controller;
+                userController.setTotalSize(totalSize);
+
+            }
+        }
     }
 
     @Override
diff --git a/src/com/android/settings/deviceinfo/StorageItemPreference.java b/src/com/android/settings/deviceinfo/StorageItemPreference.java
index b15794e..763b6d4 100644
--- a/src/com/android/settings/deviceinfo/StorageItemPreference.java
+++ b/src/com/android/settings/deviceinfo/StorageItemPreference.java
@@ -20,6 +20,7 @@
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceViewHolder;
 import android.text.format.Formatter;
+import android.util.AttributeSet;
 import android.view.View;
 import android.widget.ProgressBar;
 
@@ -28,13 +29,18 @@
 public class StorageItemPreference extends Preference {
     public int userHandle;
 
-    private ProgressBar progressBar;
+    private ProgressBar mProgressBar;
     private static final int PROGRESS_MAX = 100;
-    private int progress = -1;
+    private int mProgressPercent = -1;
 
     public StorageItemPreference(Context context) {
-        super(context);
+        this(context, null);
+    }
+
+    public StorageItemPreference(Context context, AttributeSet attrs) {
+        super(context, attrs);
         setLayoutResource(R.layout.storage_item);
+        setSummary(R.string.memory_calculating_size);
     }
 
     public void setStorageSize(long size, long total) {
@@ -42,30 +48,30 @@
                 ? String.valueOf(0)
                 : Formatter.formatFileSize(getContext(), size));
         if (total == 0) {
-            progress = 0;
+            mProgressPercent = 0;
         } else {
-            progress = (int)(size * PROGRESS_MAX / total);
+            mProgressPercent = (int)(size * PROGRESS_MAX / total);
         }
         updateProgressBar();
     }
 
     protected void updateProgressBar() {
-        if (progressBar == null)
+        if (mProgressBar == null)
             return;
 
-        if (progress == -1) {
-            progressBar.setVisibility(View.GONE);
+        if (mProgressPercent == -1) {
+            mProgressBar.setVisibility(View.GONE);
             return;
         }
 
-        progressBar.setVisibility(View.VISIBLE);
-        progressBar.setMax(PROGRESS_MAX);
-        progressBar.setProgress(progress);
+        mProgressBar.setVisibility(View.VISIBLE);
+        mProgressBar.setMax(PROGRESS_MAX);
+        mProgressBar.setProgress(mProgressPercent);
     }
 
     @Override
     public void onBindViewHolder(PreferenceViewHolder view) {
-        progressBar = (ProgressBar) view.findViewById(android.R.id.progress);
+        mProgressBar = (ProgressBar) view.findViewById(android.R.id.progress);
         updateProgressBar();
         super.onBindViewHolder(view);
     }
diff --git a/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java b/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java
index 4fcacd8..c2e2ad8 100644
--- a/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java
+++ b/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java
@@ -17,6 +17,7 @@
 
 import android.content.Context;
 import android.content.Intent;
+import android.os.Build;
 import android.os.PersistableBundle;
 import android.os.UserManager;
 import android.support.v7.preference.Preference;
@@ -25,6 +26,7 @@
 import android.text.TextUtils;
 import android.util.Log;
 
+import com.android.settings.R;
 import com.android.settings.Utils;
 import com.android.settings.core.PreferenceController;
 
@@ -78,6 +80,12 @@
         return false;
     }
 
+    @Override
+    public void updateState(Preference preference) {
+        preference.setSummary(mContext.getString(R.string.about_summary,
+                Build.VERSION.RELEASE));
+    }
+
     /**
      * Trigger client initiated action (send intent) on system update
      */
diff --git a/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java b/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java
index 4fd9e52..eb589ca 100644
--- a/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java
+++ b/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java
@@ -28,6 +28,7 @@
 import com.android.settings.Utils;
 import com.android.settings.applications.UserManagerWrapper;
 import com.android.settings.core.PreferenceController;
+import com.android.settings.deviceinfo.StorageItemPreference;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -46,8 +47,9 @@
     private static final int SIZE_NOT_SET = -1;
 
     private @NonNull UserInfo mUser;
-    private @Nullable StorageItemPreferenceAlternate mStoragePreference;
+    private @Nullable StorageItemPreference mStoragePreference;
     private long mSize;
+    private long mTotalSizeBytes;
 
     /**
      * Adds the appropriate controllers to a controller list for handling all secondary users on
@@ -98,14 +100,14 @@
     @Override
     public void displayPreference(PreferenceScreen screen) {
         if (mStoragePreference == null) {
-            mStoragePreference = new StorageItemPreferenceAlternate(screen.getContext());
+            mStoragePreference = new StorageItemPreference(screen.getContext());
 
             PreferenceGroup group =
                     (PreferenceGroup) screen.findPreference(TARGET_PREFERENCE_GROUP_KEY);
             mStoragePreference.setTitle(mUser.name);
             mStoragePreference.setKey(PREFERENCE_KEY_BASE + mUser.id);
             if (mSize != SIZE_NOT_SET) {
-                mStoragePreference.setStorageSize(mSize);
+                mStoragePreference.setStorageSize(mSize, mTotalSizeBytes);
             }
             group.setVisible(true);
             group.addPreference(mStoragePreference);
@@ -137,10 +139,18 @@
     public void setSize(long size) {
         mSize = size;
         if (mStoragePreference != null) {
-            mStoragePreference.setStorageSize(mSize);
+            mStoragePreference.setStorageSize(mSize, mTotalSizeBytes);
         }
     }
 
+    /**
+     * Sets the total size for the preference for the progress bar.
+     * @param totalSizeBytes Total size in bytes.
+     */
+    public void setTotalSize(long totalSizeBytes) {
+        mTotalSizeBytes = totalSizeBytes;
+    }
+
     public void handleResult(SparseArray<StorageAsyncLoader.AppsStorageResult> stats) {
         int userId = getUser().id;
         StorageAsyncLoader.AppsStorageResult result = stats.get(userId);
diff --git a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceAlternate.java b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceAlternate.java
deleted file mode 100644
index d5a36b9..0000000
--- a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceAlternate.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2011 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.deviceinfo.storage;
-
-import android.content.Context;
-import android.support.v7.preference.Preference;
-import android.text.format.Formatter;
-import android.util.AttributeSet;
-
-import com.android.settings.R;
-
-public class StorageItemPreferenceAlternate extends Preference {
-    public StorageItemPreferenceAlternate(Context context) {
-        this(context, null);
-    }
-
-    public StorageItemPreferenceAlternate(Context context, AttributeSet attrs) {
-        super(context, attrs);
-        setLayoutResource(R.layout.storage_item_alternate);
-        setSummary(R.string.memory_calculating_size);
-    }
-
-    public void setStorageSize(long size) {
-        setSummary(size == 0
-                ? String.valueOf(0)
-                : Formatter.formatFileSize(getContext(), size));
-    }
-}
\ No newline at end of file
diff --git a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
index 36cf73e..eec9487 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
@@ -35,6 +35,7 @@
 import com.android.settings.applications.ManageApplications;
 import com.android.settings.core.PreferenceController;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.settings.deviceinfo.StorageItemPreference;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settingslib.deviceinfo.StorageMeasurement;
 import com.android.settingslib.deviceinfo.StorageVolumeProvider;
@@ -71,13 +72,14 @@
     private VolumeInfo mVolume;
     private int mUserId;
     private long mSystemSize;
+    private long mTotalSize;
 
-    private StorageItemPreferenceAlternate mPhotoPreference;
-    private StorageItemPreferenceAlternate mAudioPreference;
-    private StorageItemPreferenceAlternate mGamePreference;
-    private StorageItemPreferenceAlternate mAppPreference;
-    private StorageItemPreferenceAlternate mFilePreference;
-    private StorageItemPreferenceAlternate mSystemPreference;
+    private StorageItemPreference mPhotoPreference;
+    private StorageItemPreference mAudioPreference;
+    private StorageItemPreference mGamePreference;
+    private StorageItemPreference mAppPreference;
+    private StorageItemPreference mFilePreference;
+    private StorageItemPreference mSystemPreference;
 
     private static final String AUTHORITY_MEDIA = "com.android.providers.media.documents";
 
@@ -164,37 +166,38 @@
 
     @Override
     public void displayPreference(PreferenceScreen screen) {
-        mPhotoPreference = (StorageItemPreferenceAlternate) screen.findPreference(PHOTO_KEY);
-        mAudioPreference = (StorageItemPreferenceAlternate) screen.findPreference(AUDIO_KEY);
-        mGamePreference = (StorageItemPreferenceAlternate) screen.findPreference(GAME_KEY);
-        mAppPreference = (StorageItemPreferenceAlternate) screen.findPreference(OTHER_APPS_KEY);
-        mSystemPreference = (StorageItemPreferenceAlternate) screen.findPreference(SYSTEM_KEY);
-        mFilePreference = (StorageItemPreferenceAlternate) screen.findPreference(FILES_KEY);
+        mPhotoPreference = (StorageItemPreference) screen.findPreference(PHOTO_KEY);
+        mAudioPreference = (StorageItemPreference) screen.findPreference(AUDIO_KEY);
+        mGamePreference = (StorageItemPreference) screen.findPreference(GAME_KEY);
+        mAppPreference = (StorageItemPreference) screen.findPreference(OTHER_APPS_KEY);
+        mSystemPreference = (StorageItemPreference) screen.findPreference(SYSTEM_KEY);
+        mFilePreference = (StorageItemPreference) screen.findPreference(FILES_KEY);
     }
 
     public void onLoadFinished(StorageAsyncLoader.AppsStorageResult data) {
         // TODO(b/35927909): Figure out how to split out apps which are only installed for work
         //       profiles in order to attribute those app's code bytes only to that profile.
         mPhotoPreference.setStorageSize(
-                data.externalStats.imageBytes + data.externalStats.videoBytes);
-        mAudioPreference.setStorageSize(data.musicAppsSize + data.externalStats.audioBytes);
-        mGamePreference.setStorageSize(data.gamesSize);
-        mAppPreference.setStorageSize(data.otherAppsSize);
+                data.externalStats.imageBytes + data.externalStats.videoBytes, mTotalSize);
+        mAudioPreference.setStorageSize(
+                data.musicAppsSize + data.externalStats.audioBytes, mTotalSize);
+        mGamePreference.setStorageSize(data.gamesSize, mTotalSize);
+        mAppPreference.setStorageSize(data.otherAppsSize, mTotalSize);
         if (mSystemPreference != null) {
-            mSystemPreference.setStorageSize(mSystemSize + data.systemSize);
+            mSystemPreference.setStorageSize(mSystemSize + data.systemSize, mTotalSize);
         }
 
         long unattributedBytes = data.externalStats.totalBytes - data.externalStats.audioBytes
                 - data.externalStats.videoBytes - data.externalStats.imageBytes;
-        mFilePreference.setStorageSize(unattributedBytes);
+        mFilePreference.setStorageSize(unattributedBytes, mTotalSize);
     }
 
-    /**
-     * Sets the system size for the system size preference.
-     * @param systemSize the size of the system in bytes
-     */
-    public void setSystemSize(long systemSize) {
-        mSystemSize = systemSize;
+    public void setSystemSize(long systemSizeBytes) {
+        mSystemSize = systemSizeBytes;
+    }
+
+    public void setTotalSize(long totalSizeBytes) {
+        mTotalSize = totalSizeBytes;
     }
 
     /**
diff --git a/src/com/android/settings/deviceinfo/storage/UserProfileController.java b/src/com/android/settings/deviceinfo/storage/UserProfileController.java
index 963784d..ef8b21e 100644
--- a/src/com/android/settings/deviceinfo/storage/UserProfileController.java
+++ b/src/com/android/settings/deviceinfo/storage/UserProfileController.java
@@ -29,6 +29,7 @@
 import com.android.internal.util.Preconditions;
 import com.android.settings.Utils;
 import com.android.settings.core.PreferenceController;
+import com.android.settings.deviceinfo.StorageItemPreference;
 import com.android.settings.deviceinfo.StorageProfileFragment;
 import com.android.settingslib.drawer.SettingsDrawerActivity;
 
@@ -38,8 +39,9 @@
 public class UserProfileController extends PreferenceController implements
         StorageAsyncLoader.ResultHandler {
     private static final String PREFERENCE_KEY_BASE = "pref_profile_";
-    private StorageItemPreferenceAlternate mStoragePreference;
+    private StorageItemPreference mStoragePreference;
     private UserInfo mUser;
+    private long mTotalSizeBytes;
     private final int mPreferenceOrder;
 
     public UserProfileController(Context context, UserInfo info, int preferenceOrder) {
@@ -60,7 +62,7 @@
 
     @Override
     public void displayPreference(PreferenceScreen screen) {
-        mStoragePreference = new StorageItemPreferenceAlternate(screen.getContext());
+        mStoragePreference = new StorageItemPreference(screen.getContext());
         mStoragePreference.setOrder(mPreferenceOrder);
         mStoragePreference.setKey(PREFERENCE_KEY_BASE + mUser.id);
         mStoragePreference.setTitle(mUser.name);
@@ -91,16 +93,20 @@
         int userId = mUser.id;
         StorageAsyncLoader.AppsStorageResult result = stats.get(userId);
         if (result != null) {
-            setSize(result.externalStats.totalBytes);
+            setSize(result.externalStats.totalBytes, mTotalSizeBytes);
         }
     }
 
     /**
      * Sets the size for the preference using a byte count.
      */
-    public void setSize(long size) {
+    public void setSize(long size, long totalSize) {
         if (mStoragePreference != null) {
-            mStoragePreference.setStorageSize(size);
+            mStoragePreference.setStorageSize(size, totalSize);
         }
     }
+
+    public void setTotalSize(long totalSize) {
+        mTotalSizeBytes = totalSize;
+    }
 }
diff --git a/src/com/android/settings/display/NightDisplaySettings.java b/src/com/android/settings/display/NightDisplaySettings.java
index 619c0d4..bc90eb9 100644
--- a/src/com/android/settings/display/NightDisplaySettings.java
+++ b/src/com/android/settings/display/NightDisplaySettings.java
@@ -28,6 +28,7 @@
 import com.android.internal.app.NightDisplayController;
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
+import com.android.settings.SeekBarPreference;
 import com.android.settings.SettingsPreferenceFragment;
 
 import java.text.DateFormat;
@@ -44,6 +45,7 @@
     private static final String KEY_NIGHT_DISPLAY_START_TIME = "night_display_start_time";
     private static final String KEY_NIGHT_DISPLAY_END_TIME = "night_display_end_time";
     private static final String KEY_NIGHT_DISPLAY_ACTIVATED = "night_display_activated";
+    private static final String KEY_NIGHT_DISPLAY_TEMPERATURE = "night_display_temperature";
 
     private static final int DIALOG_START_TIME = 0;
     private static final int DIALOG_END_TIME = 1;
@@ -55,6 +57,7 @@
     private Preference mStartTimePreference;
     private Preference mEndTimePreference;
     private TwoStatePreference mActivatedPreference;
+    private SeekBarPreference mTemperaturePreference;
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
@@ -65,6 +68,11 @@
 
         mTimeFormatter = android.text.format.DateFormat.getTimeFormat(context);
         mTimeFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
+
+        mTemperaturePreference.setMax(convertTemperature(mController.getMinimumColorTemperature()));
+        mTemperaturePreference.setDefaultProgress(convertTemperature(
+                mController.getDefaultColorTemperature()));
+        mTemperaturePreference.setContinuousUpdates(true);
     }
 
     @Override
@@ -78,6 +86,7 @@
         mStartTimePreference = findPreference(KEY_NIGHT_DISPLAY_START_TIME);
         mEndTimePreference = findPreference(KEY_NIGHT_DISPLAY_END_TIME);
         mActivatedPreference = (TwoStatePreference) findPreference(KEY_NIGHT_DISPLAY_ACTIVATED);
+        mTemperaturePreference = (SeekBarPreference) findPreference(KEY_NIGHT_DISPLAY_TEMPERATURE);
 
         mAutoModePreference.setEntries(new CharSequence[] {
                 getString(R.string.night_display_auto_mode_never),
@@ -91,6 +100,7 @@
         });
         mAutoModePreference.setOnPreferenceChangeListener(this);
         mActivatedPreference.setOnPreferenceChangeListener(this);
+        mTemperaturePreference.setOnPreferenceChangeListener(this);
     }
 
     @Override
@@ -105,6 +115,7 @@
         onAutoModeChanged(mController.getAutoMode());
         onCustomStartTimeChanged(mController.getCustomStartTime());
         onCustomEndTimeChanged(mController.getCustomEndTime());
+        onColorTemperatureChanged(mController.getColorTemperature());
     }
 
     @Override
@@ -166,9 +177,11 @@
                 return 0;
         }
     }
+
     @Override
     public void onActivated(boolean activated) {
         mActivatedPreference.setChecked(activated);
+        mTemperaturePreference.setEnabled(activated);
     }
 
     @Override
@@ -180,6 +193,11 @@
         mEndTimePreference.setVisible(showCustomSchedule);
     }
 
+    @Override
+    public void onColorTemperatureChanged(int colorTemperature) {
+        mTemperaturePreference.setProgress(convertTemperature(colorTemperature));
+    }
+
     private String getFormattedTimeString(NightDisplayController.LocalTime localTime) {
         final Calendar c = Calendar.getInstance();
         c.setTimeZone(mTimeFormatter.getTimeZone());
@@ -190,6 +208,15 @@
         return mTimeFormatter.format(c.getTime());
     }
 
+    /**
+     * Inverts and range-adjusts a raw value from the SeekBar (i.e. [0, maxTemp-minTemp]), or
+     * converts an inverted and range-adjusted value to the raw SeekBar value, depending on the
+     * adjustment status of the input.
+     */
+    private int convertTemperature(int temperature) {
+        return mController.getMaximumColorTemperature() - temperature;
+    }
+
     @Override
     public void onCustomStartTimeChanged(NightDisplayController.LocalTime startTime) {
         mStartTimePreference.setSummary(getFormattedTimeString(startTime));
@@ -206,6 +233,8 @@
             return mController.setAutoMode(Integer.parseInt((String) newValue));
         } else if (preference == mActivatedPreference) {
             return mController.setActivated((Boolean) newValue);
+        } else if (preference == mTemperaturePreference) {
+            return mController.setColorTemperature(convertTemperature((Integer) newValue));
         }
         return false;
     }
diff --git a/src/com/android/settings/enterprise/AdminGrantedCameraPermissionPreferenceController.java b/src/com/android/settings/enterprise/AdminGrantedCameraPermissionPreferenceController.java
index 8394262..003ed11 100644
--- a/src/com/android/settings/enterprise/AdminGrantedCameraPermissionPreferenceController.java
+++ b/src/com/android/settings/enterprise/AdminGrantedCameraPermissionPreferenceController.java
@@ -17,14 +17,18 @@
 import android.Manifest;
 import android.content.Context;
 
+import com.android.settings.core.lifecycle.Lifecycle;
+
 public class AdminGrantedCameraPermissionPreferenceController extends
         AdminGrantedPermissionsPreferenceControllerBase {
 
     private static final String KEY_ENTERPRISE_PRIVACY_NUMBER_CAMERA_ACCESS_PACKAGES
             = "enterprise_privacy_number_camera_access_packages";
 
-    public AdminGrantedCameraPermissionPreferenceController(Context context) {
-        super(context, new String[] {Manifest.permission.CAMERA}, Manifest.permission_group.CAMERA);
+    public AdminGrantedCameraPermissionPreferenceController(Context context, Lifecycle lifecycle,
+            boolean async) {
+        super(context, lifecycle, async, new String[] {Manifest.permission.CAMERA},
+                Manifest.permission_group.CAMERA);
     }
 
     @Override
diff --git a/src/com/android/settings/enterprise/AdminGrantedLocationPermissionsPreferenceController.java b/src/com/android/settings/enterprise/AdminGrantedLocationPermissionsPreferenceController.java
index 4dfc4be..5343483 100644
--- a/src/com/android/settings/enterprise/AdminGrantedLocationPermissionsPreferenceController.java
+++ b/src/com/android/settings/enterprise/AdminGrantedLocationPermissionsPreferenceController.java
@@ -17,14 +17,17 @@
 import android.Manifest;
 import android.content.Context;
 
+import com.android.settings.core.lifecycle.Lifecycle;
+
 public class AdminGrantedLocationPermissionsPreferenceController extends
         AdminGrantedPermissionsPreferenceControllerBase {
 
     private static final String KEY_ENTERPRISE_PRIVACY_NUMBER_LOCATION_ACCESS_PACKAGES
             = "enterprise_privacy_number_location_access_packages";
 
-    public AdminGrantedLocationPermissionsPreferenceController(Context context) {
-        super(context, new String[] {Manifest.permission.ACCESS_COARSE_LOCATION,
+    public AdminGrantedLocationPermissionsPreferenceController(Context context, Lifecycle lifecycle,
+            boolean async) {
+        super(context, lifecycle, async, new String[] {Manifest.permission.ACCESS_COARSE_LOCATION,
                 Manifest.permission.ACCESS_FINE_LOCATION}, Manifest.permission_group.LOCATION);
     }
 
diff --git a/src/com/android/settings/enterprise/AdminGrantedMicrophonePermissionPreferenceController.java b/src/com/android/settings/enterprise/AdminGrantedMicrophonePermissionPreferenceController.java
index e2ab555..64396c5 100644
--- a/src/com/android/settings/enterprise/AdminGrantedMicrophonePermissionPreferenceController.java
+++ b/src/com/android/settings/enterprise/AdminGrantedMicrophonePermissionPreferenceController.java
@@ -17,14 +17,17 @@
 import android.Manifest;
 import android.content.Context;
 
+import com.android.settings.core.lifecycle.Lifecycle;
+
 public class AdminGrantedMicrophonePermissionPreferenceController extends
         AdminGrantedPermissionsPreferenceControllerBase {
 
     private static final String KEY_ENTERPRISE_PRIVACY_NUMBER_MICROPHONE_ACCESS_PACKAGES
             = "enterprise_privacy_number_microphone_access_packages";
 
-    public AdminGrantedMicrophonePermissionPreferenceController(Context context) {
-        super(context, new String[] {Manifest.permission.RECORD_AUDIO},
+    public AdminGrantedMicrophonePermissionPreferenceController(Context context,
+            Lifecycle lifecycle, boolean async) {
+        super(context, lifecycle, async, new String[] {Manifest.permission.RECORD_AUDIO},
                 Manifest.permission_group.MICROPHONE);
     }
 
diff --git a/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerBase.java b/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerBase.java
index 5263817..c60d7e0 100644
--- a/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerBase.java
+++ b/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerBase.java
@@ -1,3 +1,4 @@
+
 /*
  * Copyright (C) 2017 The Android Open Source Project
  *
@@ -20,28 +21,32 @@
 
 import com.android.settings.R;
 import com.android.settings.applications.ApplicationFeatureProvider;
-import com.android.settings.core.PreferenceController;
+import com.android.settings.core.DynamicAvailabilityPreferenceController;
+import com.android.settings.core.lifecycle.Lifecycle;
 import com.android.settings.overlay.FeatureFactory;
 
-public abstract class AdminGrantedPermissionsPreferenceControllerBase extends PreferenceController {
+public abstract class AdminGrantedPermissionsPreferenceControllerBase
+        extends DynamicAvailabilityPreferenceController {
 
     private final String[] mPermissions;
     private final String mPermissionGroup;
     private final ApplicationFeatureProvider mFeatureProvider;
+    private final boolean mAsync;
 
-    public AdminGrantedPermissionsPreferenceControllerBase(Context context,
-                                                           String[] permissions,
-                                                           String permissionGroup) {
-        super(context);
+    public AdminGrantedPermissionsPreferenceControllerBase(Context context, Lifecycle lifecycle,
+            boolean async, String[] permissions, String permissionGroup) {
+        super(context, lifecycle);
         mPermissions = permissions;
         mPermissionGroup = permissionGroup;
         mFeatureProvider = FeatureFactory.getFactory(context)
                 .getApplicationFeatureProvider(context);
+        mAsync = async;
     }
 
     @Override
     public void updateState(Preference preference) {
         mFeatureProvider.calculateNumberOfAppsWithAdminGrantedPermissions(mPermissions,
+                true /* async */,
                 (num) -> {
                     if (num == 0) {
                         preference.setVisible(false);
@@ -55,7 +60,22 @@
 
     @Override
     public boolean isAvailable() {
-        return true;
+        if (mAsync) {
+            // When called on the main UI thread, we must not block. Since calculating the number of
+            // apps that the admin has granted a given permissions takes a bit of time, we always
+            // return true here and determine the pref's actual visibility asynchronously in
+            // updateState().
+            return true;
+        }
+
+        // When called by the search indexer, we are on a background thread that we can block. Also,
+        // changes to the pref's visibility made in updateState() would not be seen by the indexer.
+        // We block and return synchronously whether the admin has granted the given permissions to
+        // any apps or not.
+        final Boolean[] haveAppsWithAdminGrantedPermissions = { null };
+        mFeatureProvider.calculateNumberOfAppsWithAdminGrantedPermissions(mPermissions,
+                false /* async */, (num) -> haveAppsWithAdminGrantedPermissions[0] = num > 0);
+        return haveAppsWithAdminGrantedPermissions[0];
     }
 
     @Override
diff --git a/src/com/android/settings/enterprise/AlwaysOnVpnManagedProfilePreferenceController.java b/src/com/android/settings/enterprise/AlwaysOnVpnManagedProfilePreferenceController.java
index 52625ec..4796b75 100644
--- a/src/com/android/settings/enterprise/AlwaysOnVpnManagedProfilePreferenceController.java
+++ b/src/com/android/settings/enterprise/AlwaysOnVpnManagedProfilePreferenceController.java
@@ -14,30 +14,26 @@
 package com.android.settings.enterprise;
 
 import android.content.Context;
-import android.support.v7.preference.Preference;
 
-import com.android.settings.core.PreferenceController;
+import com.android.settings.core.DynamicAvailabilityPreferenceController;
+import com.android.settings.core.lifecycle.Lifecycle;
 import com.android.settings.overlay.FeatureFactory;
 
-public class AlwaysOnVpnManagedProfilePreferenceController extends PreferenceController {
+public class AlwaysOnVpnManagedProfilePreferenceController
+        extends DynamicAvailabilityPreferenceController {
 
     private static final String KEY_ALWAYS_ON_VPN_MANAGED_PROFILE = "always_on_vpn_managed_profile";
     private final EnterprisePrivacyFeatureProvider mFeatureProvider;
 
-    public AlwaysOnVpnManagedProfilePreferenceController(Context context) {
-        super(context);
+    public AlwaysOnVpnManagedProfilePreferenceController(Context context, Lifecycle lifecycle) {
+        super(context, lifecycle);
         mFeatureProvider = FeatureFactory.getFactory(context)
                 .getEnterprisePrivacyFeatureProvider(context);
     }
 
     @Override
-    public void updateState(Preference preference) {
-        preference.setVisible(mFeatureProvider.isAlwaysOnVpnSetInManagedProfile());
-    }
-
-    @Override
     public boolean isAvailable() {
-        return true;
+        return mFeatureProvider.isAlwaysOnVpnSetInManagedProfile();
     }
 
     @Override
diff --git a/src/com/android/settings/enterprise/AlwaysOnVpnPrimaryUserPreferenceController.java b/src/com/android/settings/enterprise/AlwaysOnVpnPrimaryUserPreferenceController.java
index c7ffeaf..e5823fe 100644
--- a/src/com/android/settings/enterprise/AlwaysOnVpnPrimaryUserPreferenceController.java
+++ b/src/com/android/settings/enterprise/AlwaysOnVpnPrimaryUserPreferenceController.java
@@ -17,16 +17,18 @@
 import android.support.v7.preference.Preference;
 
 import com.android.settings.R;
-import com.android.settings.core.PreferenceController;
+import com.android.settings.core.DynamicAvailabilityPreferenceController;
+import com.android.settings.core.lifecycle.Lifecycle;
 import com.android.settings.overlay.FeatureFactory;
 
-public class AlwaysOnVpnPrimaryUserPreferenceController extends PreferenceController {
+public class AlwaysOnVpnPrimaryUserPreferenceController
+        extends DynamicAvailabilityPreferenceController {
 
     private static final String KEY_ALWAYS_ON_VPN_PRIMARY_USER = "always_on_vpn_primary_user";
     private final EnterprisePrivacyFeatureProvider mFeatureProvider;
 
-    public AlwaysOnVpnPrimaryUserPreferenceController(Context context) {
-        super(context);
+    public AlwaysOnVpnPrimaryUserPreferenceController(Context context, Lifecycle lifecycle) {
+        super(context, lifecycle);
         mFeatureProvider = FeatureFactory.getFactory(context)
                 .getEnterprisePrivacyFeatureProvider(context);
     }
@@ -36,12 +38,11 @@
         preference.setTitle(mFeatureProvider.isInCompMode()
                 ? R.string.enterprise_privacy_always_on_vpn_personal
                 : R.string.enterprise_privacy_always_on_vpn_device);
-        preference.setVisible(mFeatureProvider.isAlwaysOnVpnSetInPrimaryUser());
     }
 
     @Override
     public boolean isAvailable() {
-        return true;
+        return mFeatureProvider.isAlwaysOnVpnSetInPrimaryUser();
     }
 
     @Override
diff --git a/src/com/android/settings/enterprise/CaCertsCurrentUserPreferenceController.java b/src/com/android/settings/enterprise/CaCertsCurrentUserPreferenceController.java
deleted file mode 100644
index c8ea551..0000000
--- a/src/com/android/settings/enterprise/CaCertsCurrentUserPreferenceController.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the
- * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language governing
- * permissions and limitations under the License.
- */
-
-package com.android.settings.enterprise;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.support.v7.preference.Preference;
-
-import com.android.settings.R;
-import com.android.settings.core.PreferenceController;
-import com.android.settings.overlay.FeatureFactory;
-
-public class CaCertsCurrentUserPreferenceController extends PreferenceController {
-
-    private static final String CA_CERTS_CURRENT_USER = "ca_certs_current_user";
-    private final EnterprisePrivacyFeatureProvider mFeatureProvider;
-
-    public CaCertsCurrentUserPreferenceController(Context context) {
-        super(context);
-        mFeatureProvider = FeatureFactory.getFactory(context)
-                .getEnterprisePrivacyFeatureProvider(context);
-    }
-
-    @Override
-    public void updateState(Preference preference) {
-        final int certs = mFeatureProvider.getNumberOfOwnerInstalledCaCertsInCurrentUser();
-        if (certs == 0) {
-            preference.setVisible(false);
-            return;
-        }
-        preference.setTitle(mContext.getResources().getQuantityString(
-                mFeatureProvider.isInCompMode() ? R.plurals.enterprise_privacy_ca_certs_personal :
-                        R.plurals.enterprise_privacy_ca_certs_user, certs));
-        preference.setSummary(mContext.getResources().getQuantityString(
-                R.plurals.enterprise_privacy_number_ca_certs, certs, certs));
-        preference.setVisible(true);
-    }
-
-    @Override
-    public boolean isAvailable() {
-        return true;
-    }
-
-    @Override
-    public String getPreferenceKey() {
-        return CA_CERTS_CURRENT_USER;
-    }
-}
diff --git a/src/com/android/settings/enterprise/CaCertsManagedProfilePreferenceController.java b/src/com/android/settings/enterprise/CaCertsPreferenceController.java
similarity index 64%
rename from src/com/android/settings/enterprise/CaCertsManagedProfilePreferenceController.java
rename to src/com/android/settings/enterprise/CaCertsPreferenceController.java
index 33224ae..d020676 100644
--- a/src/com/android/settings/enterprise/CaCertsManagedProfilePreferenceController.java
+++ b/src/com/android/settings/enterprise/CaCertsPreferenceController.java
@@ -19,41 +19,37 @@
 import android.support.v7.preference.Preference;
 
 import com.android.settings.R;
-import com.android.settings.core.PreferenceController;
+import com.android.settings.core.DynamicAvailabilityPreferenceController;
+import com.android.settings.core.lifecycle.Lifecycle;
 import com.android.settings.overlay.FeatureFactory;
 
-public class CaCertsManagedProfilePreferenceController extends PreferenceController {
+public class CaCertsPreferenceController extends DynamicAvailabilityPreferenceController {
 
-    private static final String KEY_CA_CERTS_MANAGED_PROFILE = "ca_certs_managed_profile";
+    private static final String CA_CERTS = "ca_certs";
     private final EnterprisePrivacyFeatureProvider mFeatureProvider;
 
-    public CaCertsManagedProfilePreferenceController(Context context) {
-        super(context);
+    public CaCertsPreferenceController(Context context, Lifecycle lifecycle) {
+        super(context, lifecycle);
         mFeatureProvider = FeatureFactory.getFactory(context)
                 .getEnterprisePrivacyFeatureProvider(context);
     }
 
     @Override
     public void updateState(Preference preference) {
-        final int certs = mFeatureProvider.getNumberOfOwnerInstalledCaCertsInManagedProfile();
-        if (certs == 0) {
-            preference.setVisible(false);
-            return;
-        }
-        preference.setTitle(mContext.getResources().getQuantityString(
-                R.plurals.enterprise_privacy_ca_certs_work, certs));
+        final int certs =
+                mFeatureProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile();
         preference.setSummary(mContext.getResources().getQuantityString(
                 R.plurals.enterprise_privacy_number_ca_certs, certs, certs));
-        preference.setVisible(true);
     }
 
     @Override
     public boolean isAvailable() {
-        return true;
+        return mFeatureProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile()
+                > 0;
     }
 
     @Override
     public String getPreferenceKey() {
-        return KEY_CA_CERTS_MANAGED_PROFILE;
+        return CA_CERTS;
     }
 }
diff --git a/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceController.java b/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceController.java
index 9b4be3a..93c1909 100644
--- a/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceController.java
+++ b/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceController.java
@@ -20,25 +20,30 @@
 
 import com.android.settings.R;
 import com.android.settings.applications.ApplicationFeatureProvider;
-import com.android.settings.core.PreferenceController;
+import com.android.settings.core.DynamicAvailabilityPreferenceController;
+import com.android.settings.core.lifecycle.Lifecycle;
 import com.android.settings.overlay.FeatureFactory;
 
-public class EnterpriseInstalledPackagesPreferenceController extends PreferenceController {
+public class EnterpriseInstalledPackagesPreferenceController
+        extends DynamicAvailabilityPreferenceController {
 
     private static final String KEY_NUMBER_ENTERPRISE_INSTALLED_PACKAGES
             = "number_enterprise_installed_packages";
     private final ApplicationFeatureProvider mFeatureProvider;
+    private final boolean mAsync;
 
-    public EnterpriseInstalledPackagesPreferenceController(Context context) {
-        super(context);
+    public EnterpriseInstalledPackagesPreferenceController(Context context, Lifecycle lifecycle,
+            boolean async) {
+        super(context, lifecycle);
         mFeatureProvider = FeatureFactory.getFactory(context)
                 .getApplicationFeatureProvider(context);
+        mAsync = async;
     }
 
     @Override
     public void updateState(Preference preference) {
         mFeatureProvider.calculateNumberOfInstalledApps(
-                PackageManager.INSTALL_REASON_POLICY,
+                PackageManager.INSTALL_REASON_POLICY, true /* async */,
                 (num) -> {
                     if (num == 0) {
                         preference.setVisible(false);
@@ -52,7 +57,20 @@
 
     @Override
     public boolean isAvailable() {
-        return true;
+        if (mAsync) {
+            // When called on the main UI thread, we must not block. Since calculating the number of
+            // enterprise-installed apps takes a bit of time, we always return true here and
+            // determine the pref's actual visibility asynchronously in updateState().
+            return true;
+        }
+
+        // When called by the search indexer, we are on a background thread that we can block. Also,
+        // changes to the pref's visibility made in updateState() would not be seen by the indexer.
+        // We block and return synchronously whether there are enterprise-installed apps or not.
+        final Boolean[] haveEnterpriseInstalledPackages = { null };
+        mFeatureProvider.calculateNumberOfInstalledApps(PackageManager.INSTALL_REASON_POLICY,
+                false /* async */, (num) -> haveEnterpriseInstalledPackages[0] = num > 0);
+        return haveEnterpriseInstalledPackages[0];
     }
 
     @Override
diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java
index 2270efa..4478865 100644
--- a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java
+++ b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java
@@ -98,15 +98,9 @@
 
     /**
      * Returns the number of CA certificates that the Device Owner or Profile Owner installed in
-     * the current user.
+     * the current user and the user's managed profile (if any).
      */
-    int getNumberOfOwnerInstalledCaCertsInCurrentUser();
-
-    /**
-     * Returns the number of CA certificates that the Profile Owner installed in the current user's
-     * managed profile (if any).
-     */
-    int getNumberOfOwnerInstalledCaCertsInManagedProfile();
+    int getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile();
 
     /**
      * Returns the number of Device Admin apps active in the current user and the user's managed
diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
index 6cff807..69eaa2e 100644
--- a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
+++ b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
@@ -189,19 +189,20 @@
     }
 
     @Override
-    public int getNumberOfOwnerInstalledCaCertsInCurrentUser() {
-        final List<String> certs = mDpm.getOwnerInstalledCaCerts(new UserHandle(MY_USER_ID));
-        return certs != null ? certs.size() : 0;
-    }
-
-    @Override
-    public int getNumberOfOwnerInstalledCaCertsInManagedProfile() {
-        final int userId = getManagedProfileUserId();
-        if (userId == UserHandle.USER_NULL) {
-            return 0;
+    public int getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile() {
+        int num = 0;
+        List<String> certs = mDpm.getOwnerInstalledCaCerts(new UserHandle(MY_USER_ID));
+        if (certs != null) {
+            num += certs.size();
         }
-        final List<String> certs = mDpm.getOwnerInstalledCaCerts(new UserHandle(userId));
-        return certs != null ? certs.size() : 0;
+        final int userId = getManagedProfileUserId();
+        if (userId != UserHandle.USER_NULL) {
+            certs = mDpm.getOwnerInstalledCaCerts(new UserHandle(userId));
+            if (certs != null) {
+                num += certs.size();
+            }
+        }
+        return num;
     }
 
     @Override
diff --git a/src/com/android/settings/enterprise/EnterprisePrivacySettings.java b/src/com/android/settings/enterprise/EnterprisePrivacySettings.java
index 3f66f02..55ec3ea 100644
--- a/src/com/android/settings/enterprise/EnterprisePrivacySettings.java
+++ b/src/com/android/settings/enterprise/EnterprisePrivacySettings.java
@@ -22,6 +22,7 @@
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
 import com.android.settings.core.PreferenceController;
+import com.android.settings.core.lifecycle.Lifecycle;
 import com.android.settings.dashboard.DashboardFragment;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.search.BaseSearchIndexProvider;
@@ -51,24 +52,33 @@
 
     @Override
     protected List<PreferenceController> getPreferenceControllers(Context context) {
+        return buildPreferenceControllers(context, getLifecycle(), true /* async */);
+    }
+
+    private static List<PreferenceController> buildPreferenceControllers(Context context,
+            Lifecycle lifecycle, boolean async) {
         final List controllers = new ArrayList<PreferenceController>();
         controllers.add(new InstalledPackagesPreferenceController(context));
         controllers.add(new NetworkLogsPreferenceController(context));
         controllers.add(new BugReportsPreferenceController(context));
         controllers.add(new SecurityLogsPreferenceController(context));
-        controllers.add(new EnterpriseInstalledPackagesPreferenceController(context));
-        controllers.add(new AdminGrantedLocationPermissionsPreferenceController(context));
-        controllers.add(new AdminGrantedMicrophonePermissionPreferenceController(context));
-        controllers.add(new AdminGrantedCameraPermissionPreferenceController(context));
-        controllers.add(new EnterpriseSetDefaultAppsPreferenceController(context));
-        controllers.add(new AlwaysOnVpnPrimaryUserPreferenceController(context));
-        controllers.add(new AlwaysOnVpnManagedProfilePreferenceController(context));
-        controllers.add(new GlobalHttpProxyPreferenceController(context));
-        controllers.add(new CaCertsCurrentUserPreferenceController(context));
-        controllers.add(new CaCertsManagedProfilePreferenceController(context));
-        controllers.add(new FailedPasswordWipePrimaryUserPreferenceController(context));
-        controllers.add(new FailedPasswordWipeManagedProfilePreferenceController(context));
-        controllers.add(new ImePreferenceController(context));
+        controllers.add(new EnterpriseInstalledPackagesPreferenceController(context, lifecycle,
+                async));
+        controllers.add(new AdminGrantedLocationPermissionsPreferenceController(context, lifecycle,
+                async));
+        controllers.add(new AdminGrantedMicrophonePermissionPreferenceController(context, lifecycle,
+                async));
+        controllers.add(new AdminGrantedCameraPermissionPreferenceController(context, lifecycle,
+                async));
+        controllers.add(new EnterpriseSetDefaultAppsPreferenceController(context, lifecycle));
+        controllers.add(new AlwaysOnVpnPrimaryUserPreferenceController(context, lifecycle));
+        controllers.add(new AlwaysOnVpnManagedProfilePreferenceController(context, lifecycle));
+        controllers.add(new GlobalHttpProxyPreferenceController(context, lifecycle));
+        controllers.add(new CaCertsPreferenceController(context, lifecycle));
+        controllers.add(new FailedPasswordWipePrimaryUserPreferenceController(context, lifecycle));
+        controllers.add(new FailedPasswordWipeManagedProfilePreferenceController(context,
+                lifecycle));
+        controllers.add(new ImePreferenceController(context, lifecycle));
         return controllers;
     }
 
@@ -91,6 +101,11 @@
                     final SearchIndexableResource sir = new SearchIndexableResource(context);
                     sir.xmlResId = R.xml.enterprise_privacy_settings;
                     return Arrays.asList(sir);
+            }
+
+            @Override
+            public List<PreferenceController> getPreferenceControllers(Context context) {
+                return buildPreferenceControllers(context, null /* lifecycle */, false /* async */);
                 }
             };
 }
diff --git a/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceController.java b/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceController.java
index 08a72e3..ae76d63 100644
--- a/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceController.java
+++ b/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceController.java
@@ -22,22 +22,40 @@
 
 import com.android.settings.R;
 import com.android.settings.applications.ApplicationFeatureProvider;
-import com.android.settings.core.PreferenceController;
+import com.android.settings.core.DynamicAvailabilityPreferenceController;
+import com.android.settings.core.lifecycle.Lifecycle;
 import com.android.settings.overlay.FeatureFactory;
 
-public class EnterpriseSetDefaultAppsPreferenceController extends PreferenceController {
+public class EnterpriseSetDefaultAppsPreferenceController
+        extends DynamicAvailabilityPreferenceController {
 
     private static final String KEY_DEFAULT_APPS = "number_enterprise_set_default_apps";
     private final ApplicationFeatureProvider mFeatureProvider;
 
-    public EnterpriseSetDefaultAppsPreferenceController(Context context) {
-        super(context);
+    public EnterpriseSetDefaultAppsPreferenceController(Context context, Lifecycle lifecycle) {
+        super(context, lifecycle);
         mFeatureProvider = FeatureFactory.getFactory(context)
                 .getApplicationFeatureProvider(context);
     }
 
     @Override
     public void updateState(Preference preference) {
+        final int num = getNumberOfEnterpriseSetDefaultApps();
+        preference.setSummary(mContext.getResources().getQuantityString(
+                R.plurals.enterprise_privacy_number_packages, num, num));
+    }
+
+    @Override
+    public boolean isAvailable() {
+        return getNumberOfEnterpriseSetDefaultApps() > 0;
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return KEY_DEFAULT_APPS;
+    }
+
+    private int getNumberOfEnterpriseSetDefaultApps() {
         // Browser
         int num = mFeatureProvider.findPersistentPreferredActivities(new Intent[] {
                 buildIntent(Intent.ACTION_VIEW, Intent.CATEGORY_BROWSABLE, "http:", null)}).size();
@@ -64,23 +82,7 @@
         num += mFeatureProvider.findPersistentPreferredActivities(new Intent[] {
                 new Intent(Intent.ACTION_DIAL), new Intent(Intent.ACTION_CALL)}).size();
 
-        if (num == 0) {
-            preference.setVisible(false);
-        } else {
-            preference.setVisible(true);
-            preference.setSummary(mContext.getResources().getQuantityString(
-                    R.plurals.enterprise_privacy_number_packages, num, num));
-        }
-    }
-
-    @Override
-    public boolean isAvailable() {
-        return true;
-    }
-
-    @Override
-    public String getPreferenceKey() {
-        return KEY_DEFAULT_APPS;
+        return num;
     }
 
     private static Intent buildIntent(String action, String category, String protocol,
diff --git a/src/com/android/settings/enterprise/FailedPasswordWipeManagedProfilePreferenceController.java b/src/com/android/settings/enterprise/FailedPasswordWipeManagedProfilePreferenceController.java
index 5a0e7c8..205d7c1 100644
--- a/src/com/android/settings/enterprise/FailedPasswordWipeManagedProfilePreferenceController.java
+++ b/src/com/android/settings/enterprise/FailedPasswordWipeManagedProfilePreferenceController.java
@@ -14,6 +14,7 @@
 package com.android.settings.enterprise;
 
 import android.content.Context;
+import com.android.settings.core.lifecycle.Lifecycle;
 
 public class FailedPasswordWipeManagedProfilePreferenceController
         extends FailedPasswordWipePreferenceControllerBase {
@@ -21,8 +22,9 @@
     private static final String KEY_FAILED_PASSWORD_WIPE_MANAGED_PROFILE
             = "failed_password_wipe_managed_profile";
 
-    public FailedPasswordWipeManagedProfilePreferenceController(Context context) {
-        super(context);
+    public FailedPasswordWipeManagedProfilePreferenceController(Context context,
+            Lifecycle lifecycle) {
+        super(context, lifecycle);
     }
 
     @Override
diff --git a/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerBase.java b/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerBase.java
index ee4aecf..2f35da6 100644
--- a/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerBase.java
+++ b/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerBase.java
@@ -19,15 +19,17 @@
 import android.support.v7.preference.Preference;
 
 import com.android.settings.R;
-import com.android.settings.core.PreferenceController;
+import com.android.settings.core.DynamicAvailabilityPreferenceController;
+import com.android.settings.core.lifecycle.Lifecycle;
 import com.android.settings.overlay.FeatureFactory;
 
-public abstract class FailedPasswordWipePreferenceControllerBase extends PreferenceController {
+public abstract class FailedPasswordWipePreferenceControllerBase
+        extends DynamicAvailabilityPreferenceController {
 
     protected final EnterprisePrivacyFeatureProvider mFeatureProvider;
 
-    public FailedPasswordWipePreferenceControllerBase(Context context) {
-        super(context);
+    public FailedPasswordWipePreferenceControllerBase(Context context, Lifecycle lifecycle) {
+        super(context, lifecycle);
         mFeatureProvider = FeatureFactory.getFactory(context)
                 .getEnterprisePrivacyFeatureProvider(context);
     }
@@ -37,18 +39,13 @@
     @Override
     public void updateState(Preference preference) {
         final int failedPasswordsBeforeWipe = getMaximumFailedPasswordsBeforeWipe();
-        if (failedPasswordsBeforeWipe == 0) {
-            preference.setVisible(false);
-        } else {
-            preference.setVisible(true);
-            preference.setSummary(mContext.getResources().getQuantityString(
-                    R.plurals.enterprise_privacy_number_failed_password_wipe,
-                    failedPasswordsBeforeWipe, failedPasswordsBeforeWipe));
-        }
+        preference.setSummary(mContext.getResources().getQuantityString(
+                R.plurals.enterprise_privacy_number_failed_password_wipe,
+                failedPasswordsBeforeWipe, failedPasswordsBeforeWipe));
     }
 
     @Override
     public boolean isAvailable() {
-        return true;
+        return getMaximumFailedPasswordsBeforeWipe() > 0;
     }
 }
diff --git a/src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceController.java b/src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceController.java
index 44c6383..2e18f89 100644
--- a/src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceController.java
+++ b/src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceController.java
@@ -15,14 +15,16 @@
 
 import android.content.Context;
 
+import com.android.settings.core.lifecycle.Lifecycle;
+
 public class FailedPasswordWipePrimaryUserPreferenceController
         extends FailedPasswordWipePreferenceControllerBase {
 
     private static final String KEY_FAILED_PASSWORD_WIPE_PRIMARY_USER
             = "failed_password_wipe_primary_user";
 
-    public FailedPasswordWipePrimaryUserPreferenceController(Context context) {
-        super(context);
+    public FailedPasswordWipePrimaryUserPreferenceController(Context context, Lifecycle lifecycle) {
+        super(context, lifecycle);
     }
 
     @Override
diff --git a/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceController.java b/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceController.java
index e2f2ab9..6ee7fc4 100644
--- a/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceController.java
+++ b/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceController.java
@@ -14,30 +14,25 @@
 package com.android.settings.enterprise;
 
 import android.content.Context;
-import android.support.v7.preference.Preference;
 
-import com.android.settings.core.PreferenceController;
+import com.android.settings.core.DynamicAvailabilityPreferenceController;
+import com.android.settings.core.lifecycle.Lifecycle;
 import com.android.settings.overlay.FeatureFactory;
 
-public class GlobalHttpProxyPreferenceController extends PreferenceController {
+public class GlobalHttpProxyPreferenceController extends DynamicAvailabilityPreferenceController {
 
     private static final String KEY_GLOBAL_HTTP_PROXY = "global_http_proxy";
     private final EnterprisePrivacyFeatureProvider mFeatureProvider;
 
-    public GlobalHttpProxyPreferenceController(Context context) {
-        super(context);
+    public GlobalHttpProxyPreferenceController(Context context, Lifecycle lifecycle) {
+        super(context, lifecycle);
         mFeatureProvider = FeatureFactory.getFactory(context)
                 .getEnterprisePrivacyFeatureProvider(context);
     }
 
     @Override
-    public void updateState(Preference preference) {
-        preference.setVisible(mFeatureProvider.isGlobalHttpProxySet());
-    }
-
-    @Override
     public boolean isAvailable() {
-        return true;
+        return mFeatureProvider.isGlobalHttpProxySet();
     }
 
     @Override
diff --git a/src/com/android/settings/enterprise/ImePreferenceController.java b/src/com/android/settings/enterprise/ImePreferenceController.java
index 3c0cc26..b090bed 100644
--- a/src/com/android/settings/enterprise/ImePreferenceController.java
+++ b/src/com/android/settings/enterprise/ImePreferenceController.java
@@ -19,35 +19,31 @@
 import android.support.v7.preference.Preference;
 
 import com.android.settings.R;
-import com.android.settings.core.PreferenceController;
+import com.android.settings.core.DynamicAvailabilityPreferenceController;
+import com.android.settings.core.lifecycle.Lifecycle;
 import com.android.settings.overlay.FeatureFactory;
 
-public class ImePreferenceController extends PreferenceController {
+public class ImePreferenceController extends DynamicAvailabilityPreferenceController {
 
     private static final String KEY_INPUT_METHOD = "input_method";
     private final EnterprisePrivacyFeatureProvider mFeatureProvider;
 
-    public ImePreferenceController(Context context) {
-        super(context);
+    public ImePreferenceController(Context context, Lifecycle lifecycle) {
+        super(context, lifecycle);
         mFeatureProvider = FeatureFactory.getFactory(context)
                 .getEnterprisePrivacyFeatureProvider(context);
     }
 
     @Override
     public void updateState(Preference preference) {
-        final String ownerSetIme = mFeatureProvider.getImeLabelIfOwnerSet();
-        if (ownerSetIme == null) {
-            preference.setVisible(false);
-            return;
-        }
         preference.setSummary(mContext.getResources().getString(
-            R.string.enterprise_privacy_input_method_name, ownerSetIme));
-        preference.setVisible(true);
+            R.string.enterprise_privacy_input_method_name,
+            mFeatureProvider.getImeLabelIfOwnerSet()));
     }
 
     @Override
     public boolean isAvailable() {
-        return true;
+        return mFeatureProvider.getImeLabelIfOwnerSet() != null;
     }
 
     @Override
diff --git a/src/com/android/settings/enterprise/InstalledPackagesPreferenceController.java b/src/com/android/settings/enterprise/InstalledPackagesPreferenceController.java
index 4252429..43436b1 100644
--- a/src/com/android/settings/enterprise/InstalledPackagesPreferenceController.java
+++ b/src/com/android/settings/enterprise/InstalledPackagesPreferenceController.java
@@ -36,7 +36,7 @@
     @Override
     public void updateState(Preference preference) {
         mFeatureProvider.calculateNumberOfInstalledApps(
-                ApplicationFeatureProvider.IGNORE_INSTALL_REASON,
+                ApplicationFeatureProvider.IGNORE_INSTALL_REASON, true /* async */,
                 (num) -> {
                     if (num == 0) {
                         preference.setSummary("");
diff --git a/src/com/android/settings/enterprise/ManageDeviceAdminPreferenceController.java b/src/com/android/settings/enterprise/ManageDeviceAdminPreferenceController.java
index 55937ec..6317afe 100644
--- a/src/com/android/settings/enterprise/ManageDeviceAdminPreferenceController.java
+++ b/src/com/android/settings/enterprise/ManageDeviceAdminPreferenceController.java
@@ -36,8 +36,10 @@
     public void updateState(Preference preference) {
         final int activeAdmins
                 = mFeatureProvider.getNumberOfActiveDeviceAdminsForCurrentUserAndManagedProfile();
-        preference.setSummary(mContext.getResources().getQuantityString(
-                R.plurals.number_of_device_admins, activeAdmins, activeAdmins));
+        preference.setSummary(activeAdmins == 0
+                ? mContext.getResources().getString(R.string.number_of_device_admins_none)
+                : mContext.getResources().getQuantityString(R.plurals.number_of_device_admins,
+                        activeAdmins, activeAdmins));
     }
 
     @Override
diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java b/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java
index bed2dc5..1f6030e 100644
--- a/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java
+++ b/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java
@@ -19,6 +19,7 @@
 import android.content.Context;
 import android.os.Bundle;
 import android.os.SystemClock;
+import android.support.annotation.VisibleForTesting;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceViewHolder;
 import android.util.AttributeSet;
@@ -36,7 +37,8 @@
  */
 public class BatteryHistoryPreference extends Preference {
 
-    private BatteryInfo mBatteryInfo;
+    @VisibleForTesting
+    BatteryInfo mBatteryInfo;
 
     public BatteryHistoryPreference(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -57,11 +59,8 @@
         if (mBatteryInfo == null) {
             return;
         }
-        view.setDividerAllowedAbove(true);
+
         ((TextView) view.findViewById(R.id.charge)).setText(mBatteryInfo.batteryPercentString);
-        ((TextView) view.findViewById(R.id.estimation)).setText(
-                mBatteryInfo.remainingLabel != null ?
-                        mBatteryInfo.remainingLabel : mBatteryInfo.statusLabel);
         UsageView usageView = (UsageView) view.findViewById(R.id.battery_usage);
         usageView.findViewById(R.id.label_group).setAlpha(.7f);
         mBatteryInfo.bindHistory(usageView);
diff --git a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
index c3a4d90..93e7810 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
@@ -15,6 +15,7 @@
 
 import android.content.Context;
 import android.content.pm.PackageManager;
+import android.os.BatteryStats;
 import android.os.Bundle;
 import android.provider.SearchIndexableResource;
 import android.support.annotation.ColorInt;
@@ -46,6 +47,7 @@
     private static final String TAG = "AdvancedBatteryUsage";
     private static final String KEY_BATTERY_GRAPH = "battery_graph";
     private static final String KEY_BATTERY_USAGE_LIST = "battery_usage_list";
+    private static final int STATUS_TYPE = BatteryStats.STATS_SINCE_CHARGED;
 
     @VisibleForTesting
     final int[] mUsageTypes = {
@@ -165,9 +167,10 @@
 
         // TODO(b/35396770): add logic to extract the summary
         final List<PowerUsageData> batteryDataList = new ArrayList<>(batteryDataMap.values());
+        final int dischargeAmount = statusHelper.getStats().getDischargeAmount(STATUS_TYPE);
         final double totalPower = statusHelper.getTotalPower();
         for (final PowerUsageData usageData : batteryDataList) {
-            usageData.percentage = (usageData.totalPowerMah / totalPower) * 100;
+            usageData.percentage = (usageData.totalPowerMah / totalPower) * dischargeAmount;
         }
 
         Collections.sort(batteryDataList);
diff --git a/src/com/android/settings/language/LanguageAndInputSettings.java b/src/com/android/settings/language/LanguageAndInputSettings.java
index ef9f84b..5a2c0c7 100644
--- a/src/com/android/settings/language/LanguageAndInputSettings.java
+++ b/src/com/android/settings/language/LanguageAndInputSettings.java
@@ -16,26 +16,34 @@
 
 package com.android.settings.language;
 
+import android.content.ComponentName;
 import android.content.Context;
+import android.content.pm.PackageManager;
 import android.os.UserHandle;
 import android.provider.SearchIndexableResource;
+import android.provider.Settings;
 import android.speech.tts.TtsEngines;
 import android.support.annotation.VisibleForTesting;
+import android.text.TextUtils;
+import android.view.inputmethod.InputMethodInfo;
+import android.view.inputmethod.InputMethodManager;
 
 import com.android.internal.hardware.AmbientDisplayConfiguration;
 import com.android.internal.logging.nano.MetricsProto;
 import com.android.settings.R;
+import com.android.settings.applications.defaultapps.DefaultAutofillPreferenceController;
 import com.android.settings.core.PreferenceController;
 import com.android.settings.core.lifecycle.Lifecycle;
 import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.dashboard.SummaryLoader;
 import com.android.settings.gestures.AssistGesturePreferenceController;
 import com.android.settings.gestures.DoubleTapPowerPreferenceController;
 import com.android.settings.gestures.DoubleTapScreenPreferenceController;
 import com.android.settings.gestures.DoubleTwistPreferenceController;
 import com.android.settings.gestures.PickupGesturePreferenceController;
+import com.android.settings.gestures.SwipeToNotificationPreferenceController;
 import com.android.settings.inputmethod.GameControllerPreferenceController;
 import com.android.settings.inputmethod.SpellCheckerPreferenceController;
-import com.android.settings.gestures.SwipeToNotificationPreferenceController;
 import com.android.settings.search.BaseSearchIndexProvider;
 
 import java.util.ArrayList;
@@ -96,6 +104,7 @@
                 context, lifecycle, mAmbientDisplayConfig, UserHandle.myUserId()));
         controllers.add(new DoubleTapScreenPreferenceController(
                 context, lifecycle, mAmbientDisplayConfig, UserHandle.myUserId()));
+        controllers.add(new DefaultAutofillPreferenceController(context));
         return controllers;
     }
 
@@ -104,6 +113,43 @@
         mAmbientDisplayConfig = ambientConfig;
     }
 
+    private 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 String flattenComponent = Settings.Secure.getString(
+                        mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
+                if (!TextUtils.isEmpty(flattenComponent)) {
+                    final PackageManager packageManage = mContext.getPackageManager();
+                    final String pkg = ComponentName.unflattenFromString(flattenComponent)
+                            .getPackageName();
+                    final InputMethodManager imm = (InputMethodManager) mContext.getSystemService(
+                            Context.INPUT_METHOD_SERVICE);
+                    final List<InputMethodInfo> imis = imm.getInputMethodList();
+                    for (InputMethodInfo imi : imis) {
+                        if (TextUtils.equals(imi.getPackageName(), pkg)) {
+                            mSummaryLoader.setSummary(this, imi.loadLabel(packageManage));
+                            return;
+                        }
+                    }
+                }
+                mSummaryLoader.setSummary(this, "");
+            }
+        }
+    }
+
+    public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
+            = (activity, summaryLoader) -> new SummaryProvider(activity, summaryLoader);
+
     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
             new BaseSearchIndexProvider() {
                 @Override
diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java
index 24405b3..fec489a 100644
--- a/src/com/android/settings/notification/AppNotificationSettings.java
+++ b/src/com/android/settings/notification/AppNotificationSettings.java
@@ -203,7 +203,7 @@
             int deletedChannelCount = mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid);
             if (deletedChannelCount > 0) {
                 DimmableIconPreference deletedPref = new DimmableIconPreference(getPrefContext());
-                deletedPref.setEnabled(false);
+                deletedPref.setSelectable(false);
                 deletedPref.setTitle(getResources().getQuantityString(
                         R.plurals.deleted_channels, deletedChannelCount, deletedChannelCount));
                 deletedPref.setIcon(R.drawable.ic_info);
diff --git a/src/com/android/settings/notification/ChannelNotificationSettings.java b/src/com/android/settings/notification/ChannelNotificationSettings.java
index 7f7aa08..b24e92c 100644
--- a/src/com/android/settings/notification/ChannelNotificationSettings.java
+++ b/src/com/android/settings/notification/ChannelNotificationSettings.java
@@ -40,6 +40,7 @@
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.DimmableIconPreference;
 import com.android.settings.R;
 import com.android.settings.RingtonePreference;
 import com.android.settings.applications.AppHeaderController;
@@ -131,6 +132,14 @@
             intentPref.setTitle(mContext.getString(R.string.app_settings_link));
             getPreferenceScreen().addPreference(intentPref);
         }
+
+        if (!TextUtils.isEmpty(mChannel.getDescription())) {
+            DimmableIconPreference descPref = new DimmableIconPreference(getPrefContext());
+            descPref.setSelectable(false);
+            descPref.setSummary(mChannel.getDescription());
+            descPref.setIcon(R.drawable.ic_info);
+            getPreferenceScreen().addPreference(descPref);
+        }
     }
 
     private void setupLights() {
diff --git a/src/com/android/settings/print/PrintSettingsFragment.java b/src/com/android/settings/print/PrintSettingsFragment.java
index b0f698f..07d6931 100644
--- a/src/com/android/settings/print/PrintSettingsFragment.java
+++ b/src/com/android/settings/print/PrintSettingsFragment.java
@@ -597,8 +597,6 @@
                     data = new SearchIndexableRaw(context);
                     data.key = componentName.flattenToString();
                     data.title = service.getResolveInfo().loadLabel(packageManager).toString();
-                    data.summaryOn = context.getString(R.string.print_feature_state_on);
-                    data.summaryOff = context.getString(R.string.print_feature_state_off);
                     data.screenTitle = screenTitle;
                     indexables.add(data);
                 }
diff --git a/src/com/android/settings/widget/DefaultIndicatorSeekBar.java b/src/com/android/settings/widget/DefaultIndicatorSeekBar.java
new file mode 100644
index 0000000..d8edf03
--- /dev/null
+++ b/src/com/android/settings/widget/DefaultIndicatorSeekBar.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.widget;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.drawable.Drawable;
+import android.util.AttributeSet;
+import android.widget.SeekBar;
+
+public class DefaultIndicatorSeekBar extends SeekBar {
+
+    private int mDefaultProgress = -1;
+
+    public DefaultIndicatorSeekBar(Context context) {
+        super(context);
+    }
+
+    public DefaultIndicatorSeekBar(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    public DefaultIndicatorSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+    }
+
+    public DefaultIndicatorSeekBar(Context context, AttributeSet attrs, int defStyleAttr,
+            int defStyleRes) {
+        super(context, attrs, defStyleAttr, defStyleRes);
+    }
+
+    /**
+     * N.B. Only draws the default indicator tick mark, NOT equally spaced tick marks.
+     */
+    @Override
+    protected void drawTickMarks(Canvas canvas) {
+        if (isEnabled() && mDefaultProgress <= getMax() && mDefaultProgress >= getMin()) {
+            final Drawable defaultIndicator = getTickMark();
+
+            // Adjust the drawable's bounds to center it at the point where it's drawn.
+            final int w = defaultIndicator.getIntrinsicWidth();
+            final int h = defaultIndicator.getIntrinsicHeight();
+            final int halfW = w >= 0 ? w / 2 : 1;
+            final int halfH = h >= 0 ? h / 2 : 1;
+            defaultIndicator.setBounds(-halfW, -halfH, halfW, halfH);
+
+            // This mimics the computation of the thumb position, to get the true "default."
+            final int availableWidth = getWidth() - mPaddingLeft - mPaddingRight;
+            final int range = getMax() - getMin();
+            final float scale = range > 0f ? mDefaultProgress / (float) range : 0f;
+            final int offset = (int) ((scale * availableWidth) + 0.5f);
+            final int indicatorPosition = isLayoutRtl() && getMirrorForRtl()
+                    ? availableWidth - offset + mPaddingRight : offset + mPaddingLeft;
+
+            final int saveCount = canvas.save();
+            canvas.translate(indicatorPosition, getHeight() / 2);
+            defaultIndicator.draw(canvas);
+            canvas.restoreToCount(saveCount);
+        }
+    }
+
+    /**
+     * N.B. This sets the default *unadjusted* progress, i.e. in the SeekBar's [0 - max] terms.
+     */
+    public void setDefaultProgress(int defaultProgress) {
+        if (mDefaultProgress != defaultProgress) {
+            mDefaultProgress = defaultProgress;
+            invalidate();
+        }
+    }
+
+    public int getDefaultProgress() {
+        return mDefaultProgress;
+    }
+}
diff --git a/src/com/android/settings/wifi/WifiApEnabler.java b/src/com/android/settings/wifi/WifiApEnabler.java
index 760879e..8e577a4 100644
--- a/src/com/android/settings/wifi/WifiApEnabler.java
+++ b/src/com/android/settings/wifi/WifiApEnabler.java
@@ -28,7 +28,6 @@
 
 import com.android.settings.R;
 import com.android.settings.datausage.DataSaverBackend;
-import com.android.settingslib.TetherUtil;
 
 import java.util.ArrayList;
 
@@ -140,6 +139,8 @@
             updateConfigSummary(wifiConfig);
         } else if (wifiErrored) {
             mSwitch.setSummary(R.string.wifi_error);
+        } else {
+            mSwitch.setSummary(R.string.wifi_hotspot_off_subtext);
         }
     }
 
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index dd17a64..ab1e04e 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -16,6 +16,8 @@
 
 package com.android.settings.wifi;
 
+import static android.os.UserManager.DISALLOW_CONFIG_WIFI;
+
 import android.annotation.NonNull;
 import android.app.Activity;
 import android.app.Dialog;
@@ -70,12 +72,11 @@
 import com.android.settingslib.wifi.AccessPoint.AccessPointListener;
 import com.android.settingslib.wifi.AccessPointPreference;
 import com.android.settingslib.wifi.WifiTracker;
+import com.android.settingslib.wifi.WifiTrackerFactory;
 
 import java.util.ArrayList;
 import java.util.List;
 
-import static android.os.UserManager.DISALLOW_CONFIG_WIFI;
-
 /**
  * Two types of UI are provided here.
  *
@@ -231,8 +232,8 @@
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
 
-        mWifiTracker =
-                new WifiTracker(getActivity(), this, mBgThread.getLooper(), true, true, false);
+        mWifiTracker = WifiTrackerFactory.create(
+                getActivity(), this, mBgThread.getLooper(), true, true, false);
         mWifiManager = mWifiTracker.getManager();
 
         mConnectListener = new WifiManager.ActionListener() {
@@ -629,71 +630,11 @@
 
         switch (wifiState) {
             case WifiManager.WIFI_STATE_ENABLED:
-                // AccessPoints are sorted by the WifiTracker
-                final List<AccessPoint> accessPoints = mWifiTracker.getAccessPoints();
-
-                boolean hasAvailableAccessPoints = false;
-                mAccessPointsPreferenceCategory.removePreference(mStatusMessagePreference);
-                cacheRemoveAllPrefs(mAccessPointsPreferenceCategory);
-
-                int index = configureConnectedAccessPointPreferenceCategory(accessPoints) ? 1 : 0;
-                boolean fewerNetworksThanLimit =
-                        accessPoints.size() <= index + NETWORKS_TO_INITIALLY_SHOW;
-                int numAccessPointsToShow = mSeeAllNetworks || fewerNetworksThanLimit
-                        ? accessPoints.size() : index + NETWORKS_TO_INITIALLY_SHOW;
-
-                for (; index < numAccessPointsToShow; index++) {
-                    AccessPoint accessPoint = accessPoints.get(index);
-                    // Ignore access points that are out of range.
-                    if (accessPoint.isReachable()) {
-                        String key = accessPoint.getBssid();
-                        if (TextUtils.isEmpty(key)) {
-                            key = accessPoint.getSsidStr();
-                        }
-                        hasAvailableAccessPoints = true;
-                        LongPressAccessPointPreference pref = (LongPressAccessPointPreference)
-                                getCachedPreference(key);
-                        if (pref != null) {
-                            pref.setOrder(index);
-                            continue;
-                        }
-                        LongPressAccessPointPreference
-                                preference = createLongPressActionPointPreference(accessPoint);
-                        preference.setKey(key);
-                        preference.setOrder(index);
-                        if (mOpenSsid != null && mOpenSsid.equals(accessPoint.getSsidStr())
-                                && !accessPoint.isSaved()
-                                && accessPoint.getSecurity() != AccessPoint.SECURITY_NONE) {
-                            onPreferenceTreeClick(preference);
-                            mOpenSsid = null;
-                        }
-                        mAccessPointsPreferenceCategory.addPreference(preference);
-                        accessPoint.setListener(this);
-                        preference.refresh();
-                    }
-                }
-                removeCachedPrefs(mAccessPointsPreferenceCategory);
-                if (!hasAvailableAccessPoints) {
-                    setProgressBarVisible(true);
-                    Preference pref = new Preference(getPrefContext());
-                    pref.setSelectable(false);
-                    pref.setSummary(R.string.wifi_empty_list_wifi_on);
-                    pref.setOrder(index++);
-                    pref.setKey(PREF_KEY_EMPTY_WIFI_LIST);
-                    mAccessPointsPreferenceCategory.addPreference(pref);
-                } else {
-                    setProgressBarVisible(false);
-                }
-                if (mSeeAllNetworks || fewerNetworksThanLimit) {
-                    mAccessPointsPreferenceCategory.removePreference(mSeeAllNetworksPreference);
-                    mAddPreference.setOrder(index);
-                    mAccessPointsPreferenceCategory.addPreference(mAddPreference);
-                } else {
-                    mAccessPointsPreferenceCategory.removePreference(mAddPreference);
-                    mSeeAllNetworksPreference.setOrder(index);
-                    mAccessPointsPreferenceCategory.addPreference(mSeeAllNetworksPreference);
-                }
-                setConfigureWifiSettingsVisibility();
+                setProgressBarVisible(true);
+                // Have the progress bar displayed before starting to modify APs
+                getView().postDelayed(() -> {
+                        updateAccessPointPreferences();
+                    }, 300 /* delay milliseconds */);
                 break;
 
             case WifiManager.WIFI_STATE_ENABLING:
@@ -715,6 +656,79 @@
         }
     }
 
+    private void updateAccessPointPreferences() {
+        // AccessPoints are sorted by the WifiTracker
+        final List<AccessPoint> accessPoints = mWifiTracker.getAccessPoints();
+
+        boolean hasAvailableAccessPoints = false;
+        mAccessPointsPreferenceCategory.removePreference(mStatusMessagePreference);
+        cacheRemoveAllPrefs(mAccessPointsPreferenceCategory);
+
+        int index =
+                configureConnectedAccessPointPreferenceCategory(accessPoints) ? 1 : 0;
+        boolean fewerNetworksThanLimit =
+                accessPoints.size() <= index + NETWORKS_TO_INITIALLY_SHOW;
+        int numAccessPointsToShow = mSeeAllNetworks || fewerNetworksThanLimit
+                ? accessPoints.size() : index + NETWORKS_TO_INITIALLY_SHOW;
+
+        for (; index < numAccessPointsToShow; index++) {
+            AccessPoint accessPoint = accessPoints.get(index);
+            // Ignore access points that are out of range.
+            if (accessPoint.isReachable()) {
+                String key = accessPoint.getBssid();
+                if (TextUtils.isEmpty(key)) {
+                    key = accessPoint.getSsidStr();
+                }
+                hasAvailableAccessPoints = true;
+                LongPressAccessPointPreference pref =
+                        (LongPressAccessPointPreference) getCachedPreference(key);
+                if (pref != null) {
+                    pref.setOrder(index);
+                    continue;
+                }
+                LongPressAccessPointPreference preference =
+                        createLongPressActionPointPreference(accessPoint);
+                preference.setKey(key);
+                preference.setOrder(index);
+                if (mOpenSsid != null && mOpenSsid.equals(accessPoint.getSsidStr())
+                        && !accessPoint.isSaved()
+                        && accessPoint.getSecurity() != AccessPoint.SECURITY_NONE) {
+                    onPreferenceTreeClick(preference);
+                    mOpenSsid = null;
+                }
+                mAccessPointsPreferenceCategory.addPreference(preference);
+                accessPoint.setListener(WifiSettings.this);
+                preference.refresh();
+            }
+        }
+        removeCachedPrefs(mAccessPointsPreferenceCategory);
+        if (mSeeAllNetworks || fewerNetworksThanLimit) {
+            mAccessPointsPreferenceCategory.removePreference(mSeeAllNetworksPreference);
+            mAddPreference.setOrder(index);
+            mAccessPointsPreferenceCategory.addPreference(mAddPreference);
+        } else {
+            mAccessPointsPreferenceCategory.removePreference(mAddPreference);
+            mSeeAllNetworksPreference.setOrder(index);
+            mAccessPointsPreferenceCategory.addPreference(mSeeAllNetworksPreference);
+        }
+        setConfigureWifiSettingsVisibility();
+
+        if (!hasAvailableAccessPoints) {
+            setProgressBarVisible(true);
+            Preference pref = new Preference(getPrefContext());
+            pref.setSelectable(false);
+            pref.setSummary(R.string.wifi_empty_list_wifi_on);
+            pref.setOrder(index++);
+            pref.setKey(PREF_KEY_EMPTY_WIFI_LIST);
+            mAccessPointsPreferenceCategory.addPreference(pref);
+        } else {
+            // Continuing showing progress bar for an additional delay to overlap with animation
+            getView().postDelayed(() -> {
+                    setProgressBarVisible(false);
+                }, 1700 /* delay millis */);
+        }
+    }
+
     @NonNull
     private LongPressAccessPointPreference createLongPressActionPointPreference(
             AccessPoint accessPoint) {
@@ -844,7 +858,8 @@
 
     protected void setProgressBarVisible(boolean visible) {
         if (mProgressHeader != null) {
-            mProgressHeader.setVisibility(visible && !isUiRestricted() ? View.VISIBLE : View.GONE);
+            mProgressHeader.setVisibility(
+                    visible && !isUiRestricted() ? View.VISIBLE : View.INVISIBLE);
         }
     }
 
diff --git a/src/com/android/settings/wifi/WifiSummaryUpdater.java b/src/com/android/settings/wifi/WifiSummaryUpdater.java
index 533ee07..c0d4468 100644
--- a/src/com/android/settings/wifi/WifiSummaryUpdater.java
+++ b/src/com/android/settings/wifi/WifiSummaryUpdater.java
@@ -26,6 +26,8 @@
 import com.android.settings.widget.SummaryUpdater;
 import com.android.settingslib.wifi.WifiStatusTracker;
 
+import static android.net.wifi.WifiInfo.removeDoubleQuotes;
+
 /**
  * Helper class that listeners to wifi callback and notify client when there is update in
  * wifi summary info.
@@ -78,7 +80,7 @@
         if (!mWifiTracker.connected) {
             return mContext.getString(R.string.disconnected);
         }
-        return mWifiTracker.ssid;
+        return removeDoubleQuotes(mWifiTracker.ssid);
     }
 
 }
diff --git a/tests/robotests/assets/grandfather_not_implementing_indexable b/tests/robotests/assets/grandfather_not_implementing_indexable
index d7ea14c..0f65f89 100644
--- a/tests/robotests/assets/grandfather_not_implementing_indexable
+++ b/tests/robotests/assets/grandfather_not_implementing_indexable
@@ -91,3 +91,4 @@
 com.android.settings.qstile.DevelopmentTileConfigActivity$DevelopmentTileConfigFragment
 com.android.settings.applications.ExternalSourcesDetails
 com.android.settings.applications.PictureInPictureSettings
+com.android.settings.applications.PictureInPictureDetails
diff --git a/tests/robotests/src/com/android/settings/TestUtils.java b/tests/robotests/src/com/android/settings/TestUtils.java
new file mode 100644
index 0000000..16d35f3
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/TestUtils.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.settings;
+
+/**
+ * Convenience methods and constants for testing.
+ */
+public class TestUtils {
+    public static final long KILOBYTE = 1024L; // TODO: Change to 1000 in O Robolectric.
+    public static final long MEGABYTE = KILOBYTE * KILOBYTE;
+    public static final long GIGABYTE = KILOBYTE * MEGABYTE;
+}
diff --git a/tests/robotests/src/com/android/settings/applications/AppWithAdminGrantedPermissionsCounterTest.java b/tests/robotests/src/com/android/settings/applications/AppWithAdminGrantedPermissionsCounterTest.java
index 3dd3a65..dfef3b8 100644
--- a/tests/robotests/src/com/android/settings/applications/AppWithAdminGrantedPermissionsCounterTest.java
+++ b/tests/robotests/src/com/android/settings/applications/AppWithAdminGrantedPermissionsCounterTest.java
@@ -89,8 +89,7 @@
         MockitoAnnotations.initMocks(this);
     }
 
-    @Test
-    public void testCountInstalledAppsAcrossAllUsers() throws Exception {
+    private void verifyCountInstalledAppsAcrossAllUsers(boolean async) throws Exception {
         // There are two users.
         mUsersToCount = Arrays.asList(
                 new UserInfo(MAIN_USER_ID, "main", UserInfo.FLAG_ADMIN),
@@ -181,10 +180,14 @@
                 .thenReturn(PackageManager.INSTALL_REASON_UNKNOWN);
 
         // Count the number of all apps installed that were granted on or more permissions by the
-        // admin.  Wait for the background task to finish.
-        (new AppWithAdminGrantedPermissionsCounterTestable(PERMISSIONS)).execute();
-        ShadowApplication.runBackgroundTasks();
-
+        // admin.
+        if (async) {
+            (new AppWithAdminGrantedPermissionsCounterTestable(PERMISSIONS)).execute();
+            // Wait for the background task to finish.
+            ShadowApplication.runBackgroundTasks();
+        } else {
+            (new AppWithAdminGrantedPermissionsCounterTestable(PERMISSIONS)).executeInForeground();
+        }
         assertThat(mAppCount).isEqualTo(3);
 
         // Verify that installed packages were retrieved for the users returned by
@@ -194,7 +197,16 @@
                 eq(MANAGED_PROFILE_ID));
         verify(mPackageManager, atLeast(0)).getInstallReason(anyObject(), anyObject());
         verifyNoMoreInteractions(mPackageManager);
+    }
 
+    @Test
+    public void testCountInstalledAppsAcrossAllUsersSync() throws Exception {
+        verifyCountInstalledAppsAcrossAllUsers(false /* async */);
+    }
+
+    @Test
+    public void testCountInstalledAppsAcrossAllUsersAync() throws Exception {
+        verifyCountInstalledAppsAcrossAllUsers(true /* async */);
     }
 
     private class AppWithAdminGrantedPermissionsCounterTestable extends
diff --git a/tests/robotests/src/com/android/settings/applications/ApplicationFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/applications/ApplicationFeatureProviderImplTest.java
index 2f344dc..a513f71 100644
--- a/tests/robotests/src/com/android/settings/applications/ApplicationFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/applications/ApplicationFeatureProviderImplTest.java
@@ -88,8 +88,7 @@
                 mPackageManagerService, mDevicePolicyManager);
     }
 
-    @Test
-    public void testCalculateNumberOfInstalledApps() {
+    private void verifyCalculateNumberOfInstalledApps(boolean async) {
         setUpUsersAndInstalledApps();
 
         when(mPackageManager.getInstallReason(APP_1, new UserHandle(MAIN_USER_ID)))
@@ -100,24 +99,34 @@
         // Count all installed apps.
         mAppCount = -1;
         mProvider.calculateNumberOfInstalledApps(ApplicationFeatureProvider.IGNORE_INSTALL_REASON,
-                (num) -> {
-                    mAppCount = num;
-                });
-        ShadowApplication.runBackgroundTasks();
+                async, (num) -> mAppCount = num);
+        if (async) {
+            ShadowApplication.runBackgroundTasks();
+        }
         assertThat(mAppCount).isEqualTo(2);
 
         // Count apps with specific install reason only.
         mAppCount = -1;
-        mProvider.calculateNumberOfInstalledApps(PackageManager.INSTALL_REASON_POLICY,
-                (num) -> {
-                    mAppCount = num;
-                });
-        ShadowApplication.runBackgroundTasks();
+        mProvider.calculateNumberOfInstalledApps(PackageManager.INSTALL_REASON_POLICY, async,
+                (num) -> mAppCount = num);
+        if (async) {
+            ShadowApplication.runBackgroundTasks();
+        }
         assertThat(mAppCount).isEqualTo(1);
     }
 
     @Test
-    public void testCalculateNumberOfAppsWithAdminGrantedPermissions() throws Exception {
+    public void testCalculateNumberOfInstalledAppsSync() {
+        verifyCalculateNumberOfInstalledApps(false /* async */);
+    }
+
+    @Test
+    public void testCalculateNumberOfInstalledAppsAsync() {
+        verifyCalculateNumberOfInstalledApps(true /* async */);
+    }
+
+    private void verifyCalculateNumberOfAppsWithAdminGrantedPermissions(boolean async)
+            throws Exception {
         setUpUsersAndInstalledApps();
 
         when(mDevicePolicyManager.getPermissionGrantState(null, APP_1, PERMISSION))
@@ -134,16 +143,26 @@
                 .thenReturn(PackageManager.INSTALL_REASON_POLICY);
 
         mAppCount = -1;
-        mProvider.calculateNumberOfAppsWithAdminGrantedPermissions(new String[] {PERMISSION},
-                (num) -> {
-                    mAppCount = num;
-                });
-        ShadowApplication.runBackgroundTasks();
+        mProvider.calculateNumberOfAppsWithAdminGrantedPermissions(new String[] {PERMISSION}, async,
+                (num) -> mAppCount = num);
+        if (async) {
+            ShadowApplication.runBackgroundTasks();
+        }
         assertThat(mAppCount).isEqualTo(2);
 
     }
 
     @Test
+    public void testCalculateNumberOfAppsWithAdminGrantedPermissionsSync() throws Exception {
+        verifyCalculateNumberOfAppsWithAdminGrantedPermissions(false /* async */);
+    }
+
+    @Test
+    public void testCalculateNumberOfAppsWithAdminGrantedPermissionsAsync() throws Exception {
+        verifyCalculateNumberOfAppsWithAdminGrantedPermissions(true /* async */);
+    }
+
+    @Test
     public void testFindPersistentPreferredActivities() throws Exception {
         when(mUserManager.getUserProfiles()).thenReturn(Arrays.asList(new UserHandle(MAIN_USER_ID),
                 new UserHandle(MANAGED_PROFILE_ID)));
diff --git a/tests/robotests/src/com/android/settings/applications/InstalledAppCounterTest.java b/tests/robotests/src/com/android/settings/applications/InstalledAppCounterTest.java
index 458959c..8b1c9c9 100644
--- a/tests/robotests/src/com/android/settings/applications/InstalledAppCounterTest.java
+++ b/tests/robotests/src/com/android/settings/applications/InstalledAppCounterTest.java
@@ -97,8 +97,7 @@
                         : new ArrayList<ResolveInfo>());
     }
 
-    @Test
-    public void testCountInstalledAppsAcrossAllUsers() {
+    private void testCountInstalledAppsAcrossAllUsers(boolean async) {
         // There are two users.
         mUsersToCount = Arrays.asList(
                 new UserInfo(MAIN_USER_ID, "main", UserInfo.FLAG_ADMIN),
@@ -156,12 +155,8 @@
         when(mPackageManager.getInstallReason(APP_6, managedProfileUser))
                 .thenReturn(PackageManager.INSTALL_REASON_UNKNOWN);
 
-        // Count the number of all apps installed, irrespective of install reason. Wait for the
-        // background task to finish.
-        (new InstalledAppCounterTestable(ApplicationFeatureProvider.IGNORE_INSTALL_REASON))
-                .execute();
-        ShadowApplication.runBackgroundTasks();
-
+        // Count the number of all apps installed, irrespective of install reason.
+        count(ApplicationFeatureProvider.IGNORE_INSTALL_REASON, async);
         assertThat(mInstalledAppCount).isEqualTo(5);
 
         // Verify that installed packages were retrieved for the users returned by
@@ -173,15 +168,34 @@
                 anyInt());
         verifyNoMoreInteractions(mPackageManager);
 
-        // Count once more, considering apps installed by enterprise policy only. Wait for the
-        // background task to finish.
-        mInstalledAppCount = -1;
-        (new InstalledAppCounterTestable(PackageManager.INSTALL_REASON_POLICY)).execute();
-        ShadowApplication.runBackgroundTasks();
-
+        // Count once more, considering apps installed by enterprise policy only.
+        count(PackageManager.INSTALL_REASON_POLICY, async);
         assertThat(mInstalledAppCount).isEqualTo(3);
     }
 
+    @Test
+    public void testCountInstalledAppsAcrossAllUsersSync() {
+        testCountInstalledAppsAcrossAllUsers(false /* async */);
+    }
+
+    @Test
+    public void testCountInstalledAppsAcrossAllUsersAsync() {
+        testCountInstalledAppsAcrossAllUsers(true /* async */);
+    }
+
+    private void count(int installReason, boolean async) {
+        mInstalledAppCount = -1;
+        final InstalledAppCounterTestable counter = new InstalledAppCounterTestable(installReason);
+        if (async) {
+            counter.execute();
+            // Wait for the background task to finish.
+            ShadowApplication.runBackgroundTasks();
+        } else {
+            counter.executeInForeground();
+        }
+    }
+
+
     private class InstalledAppCounterTestable extends InstalledAppCounter {
         public InstalledAppCounterTestable(int installReason) {
             super(mContext, installReason, mPackageManager);
diff --git a/tests/robotests/src/com/android/settings/applications/PictureInPictureSettingsTest.java b/tests/robotests/src/com/android/settings/applications/PictureInPictureDetailsTest.java
similarity index 86%
rename from tests/robotests/src/com/android/settings/applications/PictureInPictureSettingsTest.java
rename to tests/robotests/src/com/android/settings/applications/PictureInPictureDetailsTest.java
index 262c9e0..96a10f1 100644
--- a/tests/robotests/src/com/android/settings/applications/PictureInPictureSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/PictureInPictureDetailsTest.java
@@ -17,8 +17,6 @@
 package com.android.settings.applications;
 
 import android.content.Context;
-import android.content.pm.ActivityInfo;
-import android.content.pm.PackageInfo;
 
 import com.android.internal.logging.nano.MetricsProto;
 import com.android.settings.SettingsRobolectricTestRunner;
@@ -34,40 +32,32 @@
 import org.robolectric.annotation.Config;
 import org.robolectric.util.ReflectionHelpers;
 
-import java.lang.reflect.Field;
-
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Matchers.anyObject;
 import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.atLeast;
 import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class PictureInPictureSettingsTest {
+public class PictureInPictureDetailsTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Context mContext;
 
     private FakeFeatureFactory mFeatureFactory;
-    private PictureInPictureSettings mFragment;
+    private PictureInPictureDetails mFragment;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         FakeFeatureFactory.setupForTest(mContext);
         mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
-        mFragment = new PictureInPictureSettings();
+        mFragment = new PictureInPictureDetails();
     }
 
     @Test
     public void testIgnoredApp() {
-        for (String ignoredPackage : mFragment.IGNORE_PACKAGE_LIST) {
+        for (String ignoredPackage : PictureInPictureSettings.IGNORE_PACKAGE_LIST) {
             assertThat(checkPackageHasPictureInPictureActivities(ignoredPackage, true))
                             .isFalse();
         }
@@ -94,11 +84,11 @@
     public void logSpecialPermissionChange() {
         mFragment.logSpecialPermissionChange(true, "app");
         verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
-                eq(MetricsProto.MetricsEvent.APP_PICTURE_IN_PICTURE_ON_HIDE_ALLOW), eq("app"));
+                eq(MetricsProto.MetricsEvent.APP_PICTURE_IN_PICTURE_ALLOW), eq("app"));
 
         mFragment.logSpecialPermissionChange(false, "app");
         verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
-                eq(MetricsProto.MetricsEvent.APP_PICTURE_IN_PICTURE_ON_HIDE_DENY), eq("app"));
+                eq(MetricsProto.MetricsEvent.APP_PICTURE_IN_PICTURE_DENY), eq("app"));
     }
 
     private boolean checkPackageHasPictureInPictureActivities(String packageName,
diff --git a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAppPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAppPreferenceControllerTest.java
index 550addb..6dc2e64 100644
--- a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAppPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAppPreferenceControllerTest.java
@@ -21,6 +21,7 @@
 import android.os.UserManager;
 import android.support.v7.preference.Preference;
 
+import com.android.settings.R;
 import com.android.settings.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 
@@ -75,7 +76,7 @@
 
         mController.updateState(mPreference);
 
-        verify(mPreference).setSummary(null);
+        verify(mPreference).setSummary(R.string.app_list_preference_none);
     }
 
     private static class TestPreferenceController extends DefaultAppPreferenceController {
diff --git a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceControllerTest.java
index 7bcbcb0..74612e3 100644
--- a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceControllerTest.java
@@ -23,6 +23,7 @@
 import android.provider.Settings;
 import android.support.v7.preference.Preference;
 
+import com.android.settings.R;
 import com.android.settings.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.applications.PackageManagerWrapper;
@@ -75,7 +76,7 @@
         final Preference pref = mock(Preference.class);
 
         mController.updateState(pref);
-        verify(pref).setSummary(null);
+        verify(pref).setSummary(R.string.app_list_preference_none);
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceControllerTest.java
index 644a942..ee2cd1d 100644
--- a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceControllerTest.java
@@ -23,6 +23,7 @@
 import android.os.UserManager;
 import android.support.v7.preference.Preference;
 
+import com.android.settings.R;
 import com.android.settings.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.applications.PackageManagerWrapper;
@@ -92,7 +93,7 @@
         final Preference pref = mock(Preference.class);
 
         mController.updateState(pref);
-        verify(pref).setSummary(null);
+        verify(pref).setSummary(R.string.app_list_preference_none);
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
index 4eea05e..28bed3e 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
@@ -28,6 +28,7 @@
 import android.support.v7.preference.Preference;
 
 import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
 import com.android.settings.SettingsActivity;
 import com.android.settings.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
@@ -217,6 +218,32 @@
     }
 
     @Test
+    public void bindPreference_noSummary_shouldSetSummaryToPlaceholder() {
+        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Tile tile = new Tile();
+        tile.intent = new Intent();
+        tile.intent.setComponent(new ComponentName("pkg", "class"));
+        mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN,
+                preference, tile, null /*key */, Preference.DEFAULT_ORDER);
+
+        assertThat(preference.getSummary())
+                .isEqualTo(RuntimeEnvironment.application.getString(R.string.summary_placeholder));
+    }
+
+    @Test
+    public void bindPreference_hasSummary_shouldSetSummary() {
+        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Tile tile = new Tile();
+        tile.summary = "test";
+        tile.intent = new Intent();
+        tile.intent.setComponent(new ComponentName("pkg", "class"));
+        mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN,
+                preference, tile, null /*key */, Preference.DEFAULT_ORDER);
+
+        assertThat(preference.getSummary()).isEqualTo(tile.summary);
+    }
+
+    @Test
     public void bindPreference_withNullKeyTileKey_shouldUseTileKey() {
         final Preference preference = new Preference(RuntimeEnvironment.application);
         final Tile tile = new Tile();
diff --git a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
index e8a2ee4..71d9ea1 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
@@ -18,8 +18,15 @@
 
 import android.content.Context;
 import android.net.ConnectivityManager;
+import android.net.NetworkPolicy;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
+
+import com.android.settings.R;
 import com.android.settings.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
+import com.android.settingslib.NetworkPolicyEditor;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -27,9 +34,17 @@
 import org.mockito.MockitoAnnotations;
 import org.robolectric.annotation.Config;
 import org.robolectric.shadows.ShadowApplication;
+import org.robolectric.util.ReflectionHelpers;
+
+import java.util.ArrayList;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 @RunWith(SettingsRobolectricTestRunner.class)
@@ -57,4 +72,75 @@
         boolean hasMobileData = DataUsageSummary.hasMobileData(mContext);
         assertThat(hasMobileData).isTrue();
     }
+
+    @Test
+    public void testUpdateNetworkRestrictionSummary_shouldSetSummary() {
+        final DataUsageSummary dataUsageSummary = spy(new DataUsageSummary());
+        final NetworkRestrictionsPreference preference = mock(NetworkRestrictionsPreference.class);
+        final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
+        final WifiManager wifiManager = mock(WifiManager.class);
+        ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
+        ReflectionHelpers.setField(dataUsageSummary, "mWifiManager", wifiManager);
+        when(wifiManager.getConfiguredNetworks()).thenReturn(new ArrayList<WifiConfiguration>());
+        doReturn(mContext.getResources()).when(dataUsageSummary).getResources();
+
+        dataUsageSummary.updateNetworkRestrictionSummary(preference);
+
+        verify(preference).setSummary(mContext.getResources().getQuantityString(
+            R.plurals.network_restrictions_summary, 0, 0));
+    }
+
+    @Test
+    public void testIsMetered_noSsid_shouldReturnFalse() {
+        final DataUsageSummary dataUsageSummary = new DataUsageSummary();
+        final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
+        ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
+        WifiConfiguration config = mock(WifiConfiguration.class);
+
+        assertThat(dataUsageSummary.isMetered(config)).isFalse();
+    }
+
+    @Test
+    public void testIsMetered_noNetworkPolicy_shouldReturnFalse() {
+        final DataUsageSummary dataUsageSummary = new DataUsageSummary();
+        final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
+        ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
+        WifiConfiguration config = mock(WifiConfiguration.class);
+        config.SSID = "network1";
+        doReturn(null).when(policyEditor).getPolicyMaybeUnquoted(any());
+
+        assertThat(dataUsageSummary.isMetered(config)).isFalse();
+    }
+
+    @Test
+    public void testIsMetered_policyHasLimit_shouldReturnTrue() {
+        final DataUsageSummary dataUsageSummary = new DataUsageSummary();
+        final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
+        ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
+        WifiConfiguration config = mock(WifiConfiguration.class);
+        config.SSID = "network1";
+        NetworkPolicy policy = mock(NetworkPolicy.class);
+        policy.limitBytes = 100;
+        doReturn(policy).when(policyEditor).getPolicyMaybeUnquoted(any());
+
+        assertThat(dataUsageSummary.isMetered(config)).isTrue();
+    }
+
+    @Test
+    public void testIsMetered_noPolicyLimit_shouldReturnMeteredValue() {
+        final DataUsageSummary dataUsageSummary = new DataUsageSummary();
+        final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
+        ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
+        WifiConfiguration config = mock(WifiConfiguration.class);
+        config.SSID = "network1";
+        NetworkPolicy policy = mock(NetworkPolicy.class);
+        policy.limitBytes = NetworkPolicy.LIMIT_DISABLED;
+        doReturn(policy).when(policyEditor).getPolicyMaybeUnquoted(any());
+
+        policy.metered = true;
+        assertThat(dataUsageSummary.isMetered(config)).isTrue();
+
+        policy.metered = false;
+        assertThat(dataUsageSummary.isMetered(config)).isFalse();
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/development/DevelopmentSettingsEnablerTest.java b/tests/robotests/src/com/android/settings/development/DevelopmentSettingsEnablerTest.java
new file mode 100644
index 0000000..87905aa
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/DevelopmentSettingsEnablerTest.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.development;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.provider.Settings;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+import static com.google.common.truth.Truth.assertThat;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class DevelopmentSettingsEnablerTest {
+
+    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    private SharedPreferences mDevelopmentPreferences;
+    private Context mContext;
+    private DevelopmentSettingsEnabler mEnabler;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = RuntimeEnvironment.application;
+        mEnabler = new DevelopmentSettingsEnabler(mContext, null);
+        ReflectionHelpers.setField(mEnabler, "mDevelopmentPreferences", mDevelopmentPreferences);
+    }
+
+    @Test
+    public void onResume_shouldReadStateFromSettingProvider() {
+        Settings.Global.putInt(mContext.getContentResolver(),
+                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
+
+        mEnabler.onResume();
+
+        assertThat(mEnabler.getLastEnabledState()).isTrue();
+
+        Settings.Global.putInt(mContext.getContentResolver(),
+                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
+
+        mEnabler.onResume();
+
+        assertThat(mEnabler.getLastEnabledState()).isFalse();
+    }
+
+    @Test
+    public void disable_shouldChangeSettingProviderValue() {
+        Settings.Global.putInt(mContext.getContentResolver(),
+                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
+
+        mEnabler.disableDevelopmentSettings();
+
+        assertThat(mEnabler.getLastEnabledState()).isFalse();
+        assertThat(Settings.Global.getInt(mContext.getContentResolver(),
+                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1)).isEqualTo(0);
+    }
+
+    @Test
+    public void enable_shouldChangeSettingProviderValue() {
+        Settings.Global.putInt(mContext.getContentResolver(),
+                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
+
+        mEnabler.enableDevelopmentSettings();
+
+        assertThat(mEnabler.getLastEnabledState()).isTrue();
+        assertThat(Settings.Global.getInt(mContext.getContentResolver(),
+                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0)).isEqualTo(1);
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/StorageItemPreferenceTest.java b/tests/robotests/src/com/android/settings/deviceinfo/StorageItemPreferenceTest.java
new file mode 100644
index 0000000..f9d26c7
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/StorageItemPreferenceTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2016 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.deviceinfo;
+
+import static com.android.settings.TestUtils.KILOBYTE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.support.v7.preference.PreferenceViewHolder;
+import android.view.LayoutInflater;
+import android.widget.ProgressBar;
+
+import com.android.settings.R;
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class StorageItemPreferenceTest {
+    private Context mContext;
+    private StorageItemPreference mPreference;
+
+    @Before
+    public void setUp() throws Exception {
+        mContext = RuntimeEnvironment.application;
+        mPreference = new StorageItemPreference(mContext);
+    }
+
+    @Test
+    public void testBeforeLoad() {
+        assertThat(mPreference.getSummary()).isEqualTo(
+                mContext.getString(R.string.memory_calculating_size));
+    }
+
+    @Test
+    public void testAfterLoad() {
+        mPreference.setStorageSize(KILOBYTE, KILOBYTE * 10);
+        assertThat(((String) mPreference.getSummary())).isEqualTo("1.00KB");
+    }
+
+    @Test
+    public void testProgressBarPercentageSet() {
+        final PreferenceViewHolder holder = new PreferenceViewHolder(
+                LayoutInflater.from(mContext).inflate(R.layout.storage_item, null));
+        final ProgressBar progressBar =
+                (ProgressBar) holder.itemView.findViewById(android.R.id.progress);
+
+        mPreference.onBindViewHolder(holder);
+        mPreference.setStorageSize(KILOBYTE, KILOBYTE * 10);
+
+        assertThat(progressBar.getProgress()).isEqualTo(10);
+    }
+
+}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/SystemUpdatePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/SystemUpdatePreferenceControllerTest.java
index b35c60a..30c6dc9 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/SystemUpdatePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/SystemUpdatePreferenceControllerTest.java
@@ -16,21 +16,26 @@
 package com.android.settings.deviceinfo;
 
 import android.content.Context;
+import android.os.Build;
 import android.os.UserManager;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceScreen;
+
 import com.android.settings.R;
 import com.android.settings.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
-import java.util.ArrayList;
-import java.util.List;
+
 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.List;
+
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.Answers.RETURNS_DEEP_STUBS;
 import static org.mockito.Matchers.any;
@@ -92,6 +97,18 @@
     }
 
     @Test
+    public void updateState_shouldSetToAndroidVersion() {
+        final Preference preference = new Preference(RuntimeEnvironment.application);
+        mController = new SystemUpdatePreferenceController(
+                RuntimeEnvironment.application, mUserManager);
+        mController.updateState(preference);
+
+        assertThat(preference.getSummary())
+                .isEqualTo(RuntimeEnvironment.application.getString(R.string.about_summary,
+                        Build.VERSION.RELEASE));
+    }
+
+    @Test
     public void displayPrefs_oneAvailable_shouldDisplayOne() {
         final Preference preference = mock(Preference.class);
         when(mScreen.getPreferenceCount()).thenReturn(1);
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceAlternateTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceAlternateTest.java
deleted file mode 100644
index d2fc504..0000000
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceAlternateTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2016 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.deviceinfo.storage;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import android.content.Context;
-
-import com.android.settings.R;
-import com.android.settings.SettingsRobolectricTestRunner;
-import com.android.settings.TestConfig;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.annotation.Config;
-
-
-@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class StorageItemPreferenceAlternateTest {
-    private Context mContext;
-
-    @Before
-    public void setUp() throws Exception {
-        mContext = RuntimeEnvironment.application;
-    }
-
-    @Test
-    public void testBeforeLoad() {
-        StorageItemPreferenceAlternate pref = new StorageItemPreferenceAlternate(mContext);
-        assertThat(((String) pref.getSummary())).isEqualTo(
-                mContext.getString(R.string.memory_calculating_size));
-    }
-
-    @Test
-    public void testAfterLoad() {
-        StorageItemPreferenceAlternate pref = new StorageItemPreferenceAlternate(mContext);
-        pref.setStorageSize(1024L);
-        assertThat(((String) pref.getSummary())).isEqualTo("1.00KB");
-    }
-}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
index 961a6c7..387bc43 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
@@ -15,6 +15,8 @@
  */
 package com.android.settings.deviceinfo.storage;
 
+import static com.android.settings.TestUtils.KILOBYTE;
+
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.mockito.Matchers.any;
@@ -43,6 +45,7 @@
 import com.android.settings.TestConfig;
 import com.android.settings.applications.ManageApplications;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.settings.deviceinfo.StorageItemPreference;
 import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settingslib.applications.StorageStatsSource;
 import com.android.settingslib.deviceinfo.StorageVolumeProvider;
@@ -60,11 +63,6 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public class StorageItemPreferenceControllerTest {
-    /**
-     *  In O, this will change to 1000 instead of 1024 due to the formatter properly defining a
-     *  kilobyte.
-     */
-    private static long KILOBYTE = 1024L;
     private Context mContext;
     private VolumeInfo mVolume;
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -72,7 +70,7 @@
     @Mock
     private StorageVolumeProvider mSvp;
     private StorageItemPreferenceController mController;
-    private StorageItemPreferenceAlternate mPreference;
+    private StorageItemPreference mPreference;
     private FakeFeatureFactory mFakeFeatureFactory;
     private MetricsFeatureProvider mMetricsFeatureProvider;
 
@@ -87,7 +85,7 @@
         // Note: null is passed as the Lifecycle because we are handling it outside of the normal
         //       Settings fragment lifecycle for test purposes.
         mController = new StorageItemPreferenceController(mContext, mFragment, mVolume, mSvp);
-        mPreference = new StorageItemPreferenceAlternate(mContext);
+        mPreference = new StorageItemPreference(mContext);
 
         // Inflate the preference and the widget.
         LayoutInflater inflater = LayoutInflater.from(mContext);
@@ -190,12 +188,12 @@
 
     @Test
     public void testMeasurementCompletedUpdatesPreferences() {
-        StorageItemPreferenceAlternate audio = new StorageItemPreferenceAlternate(mContext);
-        StorageItemPreferenceAlternate image = new StorageItemPreferenceAlternate(mContext);
-        StorageItemPreferenceAlternate games = new StorageItemPreferenceAlternate(mContext);
-        StorageItemPreferenceAlternate apps = new StorageItemPreferenceAlternate(mContext);
-        StorageItemPreferenceAlternate system = new StorageItemPreferenceAlternate(mContext);
-        StorageItemPreferenceAlternate files = new StorageItemPreferenceAlternate(mContext);
+        StorageItemPreference audio = new StorageItemPreference(mContext);
+        StorageItemPreference image = new StorageItemPreference(mContext);
+        StorageItemPreference games = new StorageItemPreference(mContext);
+        StorageItemPreference apps = new StorageItemPreference(mContext);
+        StorageItemPreference system = new StorageItemPreference(mContext);
+        StorageItemPreference files = new StorageItemPreference(mContext);
         PreferenceScreen screen = mock(PreferenceScreen.class);
         when(screen.findPreference(
                 eq(StorageItemPreferenceController.AUDIO_KEY))).thenReturn(audio);
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java
index 2c091f2..444a0d1 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java
@@ -52,12 +52,13 @@
 
 import java.io.File;
 
+import static com.android.settings.TestUtils.KILOBYTE;
+import static com.android.settings.TestUtils.MEGABYTE;
+import static com.android.settings.TestUtils.GIGABYTE;
+
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public class StorageSummaryDonutPreferenceControllerTest {
-    private static final long KILOBYTE = 1024; // Note: When O comes around, this value changes!
-    private static final long MEGABYTE = KILOBYTE * KILOBYTE;
-    private static final long GIGABYTE = KILOBYTE * MEGABYTE;
     private Context mContext;
     private StorageSummaryDonutPreferenceController mController;
     private StorageSummaryDonutPreference mPreference;
diff --git a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedCameraPermissionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedCameraPermissionPreferenceControllerTest.java
index a998fb5..0281ce5 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedCameraPermissionPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedCameraPermissionPreferenceControllerTest.java
@@ -39,8 +39,8 @@
     }
 
     @Override
-    public void setUp() {
-        super.setUp();
-        mController = new AdminGrantedCameraPermissionPreferenceController(mContext);
+    protected AdminGrantedPermissionsPreferenceControllerBase createController(boolean async) {
+        return new AdminGrantedCameraPermissionPreferenceController(mContext,null /* lifecycle */,
+                async);
     }
 }
diff --git a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedLocationPermissionsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedLocationPermissionsPreferenceControllerTest.java
index e7aa358..d556296 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedLocationPermissionsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedLocationPermissionsPreferenceControllerTest.java
@@ -40,8 +40,8 @@
     }
 
     @Override
-    public void setUp() {
-        super.setUp();
-        mController = new AdminGrantedLocationPermissionsPreferenceController(mContext);
+    protected AdminGrantedPermissionsPreferenceControllerBase createController(boolean async) {
+        return new AdminGrantedLocationPermissionsPreferenceController(mContext,
+                null /* lifecycle */, async);
     }
 }
diff --git a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedMicrophonePermissionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedMicrophonePermissionPreferenceControllerTest.java
index 8c84af2..e2a45ec 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedMicrophonePermissionPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedMicrophonePermissionPreferenceControllerTest.java
@@ -39,8 +39,8 @@
     }
 
     @Override
-    public void setUp() {
-        super.setUp();
-        mController = new AdminGrantedMicrophonePermissionPreferenceController(mContext);
+    protected AdminGrantedPermissionsPreferenceControllerBase createController(boolean async) {
+        return new AdminGrantedMicrophonePermissionPreferenceController(mContext,
+                null /* lifecycle */, async);
     }
 }
diff --git a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerBaseTest.java b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerBaseTest.java
index 0d53fb6..4da1cd2 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerBaseTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerBaseTest.java
@@ -40,17 +40,16 @@
     }
 
     @Override
-    public void setUp() {
-        super.setUp();
-        mController = new AdminGrantedPermissionsPreferenceControllerBaseTestable();
+    protected AdminGrantedPermissionsPreferenceControllerBase createController(boolean async) {
+        return new AdminGrantedPermissionsPreferenceControllerBaseTestable(async);
     }
 
     private class AdminGrantedPermissionsPreferenceControllerBaseTestable extends
             AdminGrantedPermissionsPreferenceControllerBase {
 
-        AdminGrantedPermissionsPreferenceControllerBaseTestable() {
-            super(AdminGrantedPermissionsPreferenceControllerBaseTest.this.mContext, mPermissions,
-                    mPermissionGroup);
+        AdminGrantedPermissionsPreferenceControllerBaseTestable(boolean async) {
+            super(AdminGrantedPermissionsPreferenceControllerBaseTest.this.mContext,
+                    null /* lifecycle */, async, mPermissions, mPermissionGroup);
         }
 
         @Override
diff --git a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerTestBase.java b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerTestBase.java
index 5a70b7a..69e6237 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerTestBase.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerTestBase.java
@@ -68,39 +68,56 @@
         MockitoAnnotations.initMocks(this);
         FakeFeatureFactory.setupForTest(mContext);
         mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mController = createController(true /* async */);
     }
 
-    private void setNumberOfPackagesWithAdminGrantedPermissions(int number) {
+    private void setNumberOfPackagesWithAdminGrantedPermissions(int number, boolean async) {
         doAnswer(new Answer() {
             public Object answer(InvocationOnMock invocation) {
                 ((ApplicationFeatureProvider.NumberOfAppsCallback)
-                        invocation.getArguments()[1]).onNumberOfAppsResult(number);
+                        invocation.getArguments()[2]).onNumberOfAppsResult(number);
                 return null;
             }}).when(mFeatureFactory.applicationFeatureProvider)
                     .calculateNumberOfAppsWithAdminGrantedPermissions(eq(mPermissions),
-                            anyObject());
+                            eq(async), anyObject());
     }
 
     @Test
     public void testUpdateState() {
         final Preference preference = new Preference(mContext, null, 0, 0);
-        preference.setVisible(false);
+        preference.setVisible(true);
 
-        setNumberOfPackagesWithAdminGrantedPermissions(20);
+        setNumberOfPackagesWithAdminGrantedPermissions(0, true /* async */);
+        mController.updateState(preference);
+        assertThat(preference.isVisible()).isFalse();
+
+        setNumberOfPackagesWithAdminGrantedPermissions(20, true /* async */);
         when(mContext.getResources().getQuantityString(
                 R.plurals.enterprise_privacy_number_packages_actionable,20, 20))
                 .thenReturn("20 packages");
         mController.updateState(preference);
         assertThat(preference.getSummary()).isEqualTo("20 packages");
         assertThat(preference.isVisible()).isTrue();
-
-        setNumberOfPackagesWithAdminGrantedPermissions(0);
-        mController.updateState(preference);
-        assertThat(preference.isVisible()).isFalse();
     }
 
     @Test
-    public void testIsAvailable() {
+    public void testIsAvailableSync() {
+        final AdminGrantedPermissionsPreferenceControllerBase controller
+                = createController(false /* async */);
+
+        setNumberOfPackagesWithAdminGrantedPermissions(0, false /* async */);
+        assertThat(controller.isAvailable()).isFalse();
+
+        setNumberOfPackagesWithAdminGrantedPermissions(20, false /* async */);
+        assertThat(controller.isAvailable()).isTrue();
+    }
+
+    @Test
+    public void testIsAvailableAsync() {
+        setNumberOfPackagesWithAdminGrantedPermissions(0, true /* async */);
+        assertThat(mController.isAvailable()).isTrue();
+
+        setNumberOfPackagesWithAdminGrantedPermissions(20, true /* async */);
         assertThat(mController.isAvailable()).isTrue();
     }
 
@@ -125,4 +142,7 @@
     public void testGetPreferenceKey() {
         assertThat(mController.getPreferenceKey()).isEqualTo(mKey);
     }
+
+    protected abstract AdminGrantedPermissionsPreferenceControllerBase createController(
+            boolean async);
 }
diff --git a/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnManagedProfilePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnManagedProfilePreferenceControllerTest.java
index a52e049..8ac10d1 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnManagedProfilePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnManagedProfilePreferenceControllerTest.java
@@ -52,27 +52,18 @@
         MockitoAnnotations.initMocks(this);
         FakeFeatureFactory.setupForTest(mContext);
         mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
-        mController = new AlwaysOnVpnManagedProfilePreferenceController(mContext);
-    }
-
-    @Test
-    public void testUpdateState() {
-        final Preference preference = new Preference(mContext, null, 0, 0);
-        preference.setVisible(true);
-
-        when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInManagedProfile())
-                .thenReturn(false);
-        mController.updateState(preference);
-        assertThat(preference.isVisible()).isFalse();
-
-        when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInManagedProfile())
-                .thenReturn(true);
-        mController.updateState(preference);
-        assertThat(preference.isVisible()).isTrue();
+        mController = new AlwaysOnVpnManagedProfilePreferenceController(mContext,
+                null /* lifecycle */);
     }
 
     @Test
     public void testIsAvailable() {
+        when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInManagedProfile())
+                .thenReturn(false);
+        assertThat(mController.isAvailable()).isFalse();
+
+        when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInManagedProfile())
+                .thenReturn(true);
         assertThat(mController.isAvailable()).isTrue();
     }
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnPrimaryUserPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnPrimaryUserPreferenceControllerTest.java
index d504b84..12fdb4f 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnPrimaryUserPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnPrimaryUserPreferenceControllerTest.java
@@ -56,7 +56,8 @@
         MockitoAnnotations.initMocks(this);
         FakeFeatureFactory.setupForTest(mContext);
         mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
-        mController = new AlwaysOnVpnPrimaryUserPreferenceController(mContext);
+        mController = new AlwaysOnVpnPrimaryUserPreferenceController(mContext,
+                null /* lifecycle */);
         when(mContext.getString(R.string.enterprise_privacy_always_on_vpn_device))
                 .thenReturn(VPN_SET_DEVICE);
         when(mContext.getString(R.string.enterprise_privacy_always_on_vpn_personal))
@@ -66,37 +67,27 @@
     @Test
     public void testUpdateState() {
         final Preference preference = new Preference(mContext, null, 0, 0);
-        preference.setVisible(true);
-
-        when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode()).thenReturn(false);
-
-        when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInPrimaryUser())
-                .thenReturn(false);
-        mController.updateState(preference);
-        assertThat(preference.isVisible()).isFalse();
 
         when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInPrimaryUser())
                 .thenReturn(true);
+
+        when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode()).thenReturn(false);
         mController.updateState(preference);
-        assertThat(preference.isVisible()).isTrue();
         assertThat(preference.getTitle()).isEqualTo(VPN_SET_DEVICE);
 
         when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode()).thenReturn(true);
-
-        when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInPrimaryUser())
-                .thenReturn(false);
         mController.updateState(preference);
-        assertThat(preference.isVisible()).isFalse();
-
-        when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInPrimaryUser())
-                .thenReturn(true);
-        mController.updateState(preference);
-        assertThat(preference.isVisible()).isTrue();
         assertThat(preference.getTitle()).isEqualTo(VPN_SET_PERSONAL);
     }
 
     @Test
     public void testIsAvailable() {
+        when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInPrimaryUser())
+                .thenReturn(false);
+        assertThat(mController.isAvailable()).isFalse();
+
+        when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInPrimaryUser())
+                .thenReturn(true);
         assertThat(mController.isAvailable()).isTrue();
     }
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/CaCertsCurrentUserPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/CaCertsCurrentUserPreferenceControllerTest.java
deleted file mode 100644
index 3cd63bb..0000000
--- a/tests/robotests/src/com/android/settings/enterprise/CaCertsCurrentUserPreferenceControllerTest.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.enterprise;
-
-import android.content.Context;
-import android.content.res.Resources;
-import com.android.settings.R;
-import android.support.v7.preference.Preference;
-
-import com.android.settings.SettingsRobolectricTestRunner;
-import com.android.settings.TestConfig;
-import com.android.settings.testutils.FakeFeatureFactory;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.annotation.Config;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.when;
-
-/**
- * Tests for {@link CaCertsCurrentUserPreferenceController}.
- */
-@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public final class CaCertsCurrentUserPreferenceControllerTest {
-
-    private final String INSTALLED_CERTS_USER_1 = "cert installed";
-    private final String INSTALLED_CERTS_USER_10 = "certs installed";
-    private final String INSTALLED_CERTS_PERSONAL_1 = "cert installed in personal profile";
-    private final String INSTALLED_CERTS_PERSONAL_10 = "certs installed in personal profile";
-    private final String NUMBER_INSTALLED_CERTS_1 = "1 cert";
-    private final String NUMBER_INSTALLED_CERTS_10 = "10 certs";
-
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
-    private FakeFeatureFactory mFeatureFactory;
-
-    private CaCertsCurrentUserPreferenceController mController;
-
-    @Before
-    public void setUp() {
-        MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
-        mController = new CaCertsCurrentUserPreferenceController(mContext);
-
-        when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_ca_certs_user,
-                1)).thenReturn(INSTALLED_CERTS_USER_1);
-        when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_ca_certs_user,
-                10)).thenReturn(INSTALLED_CERTS_USER_10);
-        when(mContext.getResources().getQuantityString(
-                R.plurals.enterprise_privacy_ca_certs_personal, 1))
-                .thenReturn(INSTALLED_CERTS_PERSONAL_1);
-        when(mContext.getResources().getQuantityString(
-                R.plurals.enterprise_privacy_ca_certs_personal, 10))
-                .thenReturn(INSTALLED_CERTS_PERSONAL_10);
-        when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_ca_certs,
-                1, 1)).thenReturn(NUMBER_INSTALLED_CERTS_1);
-        when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_ca_certs,
-                10, 10)).thenReturn(NUMBER_INSTALLED_CERTS_10);
-    }
-
-    @Test
-    public void testUpdateState() {
-        final Preference preference = new Preference(mContext, null, 0, 0);
-        preference.setVisible(true);
-
-        when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode()).thenReturn(false);
-
-        when(mFeatureFactory.enterprisePrivacyFeatureProvider
-                .getNumberOfOwnerInstalledCaCertsInCurrentUser()).thenReturn(0);
-        mController.updateState(preference);
-        assertThat(preference.isVisible()).isFalse();
-
-        when(mFeatureFactory.enterprisePrivacyFeatureProvider
-                .getNumberOfOwnerInstalledCaCertsInCurrentUser()).thenReturn(1);
-        mController.updateState(preference);
-        assertThat(preference.isVisible()).isTrue();
-        assertThat(preference.getTitle()).isEqualTo(INSTALLED_CERTS_USER_1);
-        assertThat(preference.getSummary()).isEqualTo(NUMBER_INSTALLED_CERTS_1);
-
-        preference.setVisible(false);
-        when(mFeatureFactory.enterprisePrivacyFeatureProvider
-                .getNumberOfOwnerInstalledCaCertsInCurrentUser()).thenReturn(10);
-        mController.updateState(preference);
-        assertThat(preference.isVisible()).isTrue();
-        assertThat(preference.getTitle()).isEqualTo(INSTALLED_CERTS_USER_10);
-        assertThat(preference.getSummary()).isEqualTo(NUMBER_INSTALLED_CERTS_10);
-
-        when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode()).thenReturn(true);
-
-        when(mFeatureFactory.enterprisePrivacyFeatureProvider
-                .getNumberOfOwnerInstalledCaCertsInCurrentUser()).thenReturn(0);
-        mController.updateState(preference);
-        assertThat(preference.isVisible()).isFalse();
-
-        when(mFeatureFactory.enterprisePrivacyFeatureProvider
-                .getNumberOfOwnerInstalledCaCertsInCurrentUser()).thenReturn(1);
-        mController.updateState(preference);
-        assertThat(preference.isVisible()).isTrue();
-        assertThat(preference.getTitle()).isEqualTo(INSTALLED_CERTS_PERSONAL_1);
-        assertThat(preference.getSummary()).isEqualTo(NUMBER_INSTALLED_CERTS_1);
-
-        preference.setVisible(false);
-        when(mFeatureFactory.enterprisePrivacyFeatureProvider
-                .getNumberOfOwnerInstalledCaCertsInCurrentUser()).thenReturn(10);
-        mController.updateState(preference);
-        assertThat(preference.isVisible()).isTrue();
-        assertThat(preference.getTitle()).isEqualTo(INSTALLED_CERTS_PERSONAL_10);
-        assertThat(preference.getSummary()).isEqualTo(NUMBER_INSTALLED_CERTS_10);
-    }
-
-    @Test
-    public void testIsAvailable() {
-        assertThat(mController.isAvailable()).isTrue();
-    }
-
-    @Test
-    public void testHandlePreferenceTreeClick() {
-        assertThat(mController.handlePreferenceTreeClick(new Preference(mContext, null, 0, 0)))
-                .isFalse();
-    }
-
-    @Test
-    public void testGetPreferenceKey() {
-        assertThat(mController.getPreferenceKey()).isEqualTo("ca_certs_current_user");
-    }
-}
diff --git a/tests/robotests/src/com/android/settings/enterprise/CaCertsManagedProfilePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/CaCertsManagedProfilePreferenceControllerTest.java
deleted file mode 100644
index c66128b..0000000
--- a/tests/robotests/src/com/android/settings/enterprise/CaCertsManagedProfilePreferenceControllerTest.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.enterprise;
-
-import android.content.Context;
-import android.content.res.Resources;
-import com.android.settings.R;
-import android.support.v7.preference.Preference;
-
-import com.android.settings.SettingsRobolectricTestRunner;
-import com.android.settings.TestConfig;
-import com.android.settings.testutils.FakeFeatureFactory;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.annotation.Config;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.when;
-
-/**
- * Tests for {@link CaCertsManagedProfilePreferenceController}.
- */
-@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public final class CaCertsManagedProfilePreferenceControllerTest {
-
-    private final String INSTALLED_CERTS_1 = "cert installed";
-    private final String INSTALLED_CERTS_10 = "certs installed";
-    private final String NUMBER_INSTALLED_CERTS_1 = "1 cert";
-    private final String NUMBER_INSTALLED_CERTS_10 = "10 certs";
-
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
-    private FakeFeatureFactory mFeatureFactory;
-
-    private CaCertsManagedProfilePreferenceController mController;
-
-    @Before
-    public void setUp() {
-        MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
-        mController = new CaCertsManagedProfilePreferenceController(mContext);
-
-        when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_ca_certs_work,
-                1)).thenReturn(INSTALLED_CERTS_1);
-        when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_ca_certs_work,
-                10)).thenReturn(INSTALLED_CERTS_10);
-        when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_ca_certs,
-                1, 1)).thenReturn(NUMBER_INSTALLED_CERTS_1);
-        when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_ca_certs,
-                10, 10)).thenReturn(NUMBER_INSTALLED_CERTS_10);
-    }
-
-    @Test
-    public void testUpdateState() {
-        final Preference preference = new Preference(mContext, null, 0, 0);
-        preference.setVisible(true);
-
-        when(mFeatureFactory.enterprisePrivacyFeatureProvider
-                .getNumberOfOwnerInstalledCaCertsInManagedProfile()).thenReturn(0);
-        mController.updateState(preference);
-        assertThat(preference.isVisible()).isFalse();
-
-        when(mFeatureFactory.enterprisePrivacyFeatureProvider
-                .getNumberOfOwnerInstalledCaCertsInManagedProfile()).thenReturn(1);
-        mController.updateState(preference);
-        assertThat(preference.isVisible()).isTrue();
-        assertThat(preference.getTitle()).isEqualTo(INSTALLED_CERTS_1);
-        assertThat(preference.getSummary()).isEqualTo(NUMBER_INSTALLED_CERTS_1);
-
-        preference.setVisible(false);
-        when(mFeatureFactory.enterprisePrivacyFeatureProvider
-                .getNumberOfOwnerInstalledCaCertsInManagedProfile()).thenReturn(10);
-        mController.updateState(preference);
-        assertThat(preference.isVisible()).isTrue();
-        assertThat(preference.getTitle()).isEqualTo(INSTALLED_CERTS_10);
-        assertThat(preference.getSummary()).isEqualTo(NUMBER_INSTALLED_CERTS_10);
-    }
-
-    @Test
-    public void testIsAvailable() {
-        assertThat(mController.isAvailable()).isTrue();
-    }
-
-    @Test
-    public void testHandlePreferenceTreeClick() {
-        assertThat(mController.handlePreferenceTreeClick(new Preference(mContext, null, 0, 0)))
-                .isFalse();
-    }
-
-    @Test
-    public void testGetPreferenceKey() {
-        assertThat(mController.getPreferenceKey()).isEqualTo("ca_certs_managed_profile");
-    }
-}
diff --git a/tests/robotests/src/com/android/settings/enterprise/CaCertsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/CaCertsPreferenceControllerTest.java
new file mode 100644
index 0000000..fef2e0f
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/enterprise/CaCertsPreferenceControllerTest.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.enterprise;
+
+import android.content.Context;
+import android.content.res.Resources;
+import com.android.settings.R;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests for {@link CaCertsPreferenceController}.
+ */
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public final class CaCertsPreferenceControllerTest {
+
+    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    private Context mContext;
+    private FakeFeatureFactory mFeatureFactory;
+
+    private CaCertsPreferenceController mController;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        FakeFeatureFactory.setupForTest(mContext);
+        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mController = new CaCertsPreferenceController(mContext, null /* lifecycle */);
+    }
+
+    @Test
+    public void testUpdateState() {
+        final Preference preference = new Preference(mContext, null, 0, 0);
+
+        when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_ca_certs,
+                10, 10)).thenReturn("10 certs");
+        when(mFeatureFactory.enterprisePrivacyFeatureProvider
+                .getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile()).thenReturn(10);
+        mController.updateState(preference);
+        assertThat(preference.getSummary()).isEqualTo("10 certs");
+    }
+
+    @Test
+    public void testIsAvailable() {
+        when(mFeatureFactory.enterprisePrivacyFeatureProvider
+                .getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile()).thenReturn(0);
+        assertThat(mController.isAvailable()).isFalse();
+
+        when(mFeatureFactory.enterprisePrivacyFeatureProvider
+                .getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile()).thenReturn(10);
+        assertThat(mController.isAvailable()).isTrue();
+    }
+
+    @Test
+    public void testHandlePreferenceTreeClick() {
+        assertThat(mController.handlePreferenceTreeClick(new Preference(mContext, null, 0, 0)))
+                .isFalse();
+    }
+
+    @Test
+    public void testGetPreferenceKey() {
+        assertThat(mController.getPreferenceKey()).isEqualTo("ca_certs");
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceControllerTest.java
index 46c29b2..98d0fa6 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceControllerTest.java
@@ -62,18 +62,19 @@
         MockitoAnnotations.initMocks(this);
         FakeFeatureFactory.setupForTest(mContext);
         mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
-        mController = new EnterpriseInstalledPackagesPreferenceController(mContext);
+        mController = new EnterpriseInstalledPackagesPreferenceController(mContext,
+                null /* lifecycle */, true /* async */);
     }
 
-    private void setNumberOfEnterpriseInstalledPackages(int number) {
+    private void setNumberOfEnterpriseInstalledPackages(int number, boolean async) {
         doAnswer(new Answer() {
             public Object answer(InvocationOnMock invocation) {
                 ((ApplicationFeatureProvider.NumberOfAppsCallback)
-                        invocation.getArguments()[1]).onNumberOfAppsResult(number);
+                        invocation.getArguments()[2]).onNumberOfAppsResult(number);
                 return null;
             }}).when(mFeatureFactory.applicationFeatureProvider)
                     .calculateNumberOfInstalledApps(eq(PackageManager.INSTALL_REASON_POLICY),
-                            anyObject());
+                            eq(async), anyObject());
     }
 
     @Test
@@ -81,11 +82,11 @@
         final Preference preference = new Preference(mContext, null, 0, 0);
         preference.setVisible(true);
 
-        setNumberOfEnterpriseInstalledPackages(0);
+        setNumberOfEnterpriseInstalledPackages(0, true /* async */);
         mController.updateState(preference);
         assertThat(preference.isVisible()).isFalse();
 
-        setNumberOfEnterpriseInstalledPackages(20);
+        setNumberOfEnterpriseInstalledPackages(20, true /* async */);
         when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_packages,
                 20, 20)).thenReturn("20 packages");
         mController.updateState(preference);
@@ -94,7 +95,24 @@
     }
 
     @Test
-    public void testIsAvailable() {
+    public void testIsAvailableSync() {
+        final EnterpriseInstalledPackagesPreferenceController controller
+                = new EnterpriseInstalledPackagesPreferenceController(mContext,
+                        null /* lifecycle */, false /* async */);
+
+        setNumberOfEnterpriseInstalledPackages(0, false /* async */);
+        assertThat(controller.isAvailable()).isFalse();
+
+        setNumberOfEnterpriseInstalledPackages(20, false /* async */);
+        assertThat(controller.isAvailable()).isTrue();
+    }
+
+    @Test
+    public void testIsAvailableAsync() {
+        setNumberOfEnterpriseInstalledPackages(0, true /* async */);
+        assertThat(mController.isAvailable()).isTrue();
+
+        setNumberOfEnterpriseInstalledPackages(20, true /* async */);
         assertThat(mController.isAvailable()).isTrue();
     }
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
index d4eec19..2afcab9 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
@@ -268,39 +268,45 @@
     }
 
     @Test
-    public void testGetNumberOfOwnerInstalledCaCertsInCurrentUser() {
+    public void testGetNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile() {
         final UserHandle userHandle = new UserHandle(UserHandle.USER_SYSTEM);
-
-        when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle))
-                .thenReturn(null);
-        assertThat(mProvider.getNumberOfOwnerInstalledCaCertsInCurrentUser()).isEqualTo(0);
-        when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle))
-                .thenReturn(new ArrayList<String>());
-        assertThat(mProvider.getNumberOfOwnerInstalledCaCertsInCurrentUser()).isEqualTo(0);
-        when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle))
-                .thenReturn(Arrays.asList(new String[] {"ca1", "ca2"}));
-        assertThat(mProvider.getNumberOfOwnerInstalledCaCertsInCurrentUser()).isEqualTo(2);
-    }
-
-    @Test
-    public void testGetNumberOfOwnerInstalledCaCertsInManagedProfile() {
-        final UserHandle userHandle = new UserHandle(MANAGED_PROFILE_USER_ID);
+        final UserHandle managedProfileUserHandle = new UserHandle(MANAGED_PROFILE_USER_ID);
         final UserInfo managedProfile =
                 new UserInfo(MANAGED_PROFILE_USER_ID, "", "", UserInfo.FLAG_MANAGED_PROFILE);
 
-        mProfiles.add(managedProfile);
+        when(mDevicePolicyManager.getOwnerInstalledCaCerts(managedProfileUserHandle))
+                .thenReturn(Arrays.asList(new String[] {"ca1", "ca2"}));
+
         when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle))
                 .thenReturn(null);
-        assertThat(mProvider.getNumberOfOwnerInstalledCaCertsInManagedProfile()).isEqualTo(0);
+        assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile())
+                .isEqualTo(0);
         when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle))
                 .thenReturn(new ArrayList<String>());
-        assertThat(mProvider.getNumberOfOwnerInstalledCaCertsInManagedProfile()).isEqualTo(0);
+        assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile())
+                .isEqualTo(0);
         when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle))
                 .thenReturn(Arrays.asList(new String[] {"ca1", "ca2"}));
-        assertThat(mProvider.getNumberOfOwnerInstalledCaCertsInManagedProfile()).isEqualTo(2);
+        assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile())
+                .isEqualTo(2);
+
+        mProfiles.add(managedProfile);
+        when(mDevicePolicyManager.getOwnerInstalledCaCerts(managedProfileUserHandle))
+                .thenReturn(null);
+        assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile())
+                .isEqualTo(2);
+        when(mDevicePolicyManager.getOwnerInstalledCaCerts(managedProfileUserHandle))
+                .thenReturn(new ArrayList<String>());
+        assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile())
+                .isEqualTo(2);
+        when(mDevicePolicyManager.getOwnerInstalledCaCerts(managedProfileUserHandle))
+                .thenReturn(Arrays.asList(new String[] {"ca1", "ca2"}));
+        assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile())
+                .isEqualTo(4);
 
         mProfiles.remove(managedProfile);
-        assertThat(mProvider.getNumberOfOwnerInstalledCaCertsInManagedProfile()).isEqualTo(0);
+        assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile())
+                .isEqualTo(2);
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java
index 29ca4cd..8a11779 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java
@@ -104,8 +104,20 @@
     public void getPreferenceControllers() {
         final List<PreferenceController> controllers = mSettings.getPreferenceControllers(
                 ShadowApplication.getInstance().getApplicationContext());
+        verifyPreferenceControllers(controllers);
+    }
+
+    @Test
+    public void getSearchIndexProviderPreferenceControllers() {
+        final List<PreferenceController> controllers
+                = EnterprisePrivacySettings.SEARCH_INDEX_DATA_PROVIDER.getPreferenceControllers(
+                        ShadowApplication.getInstance().getApplicationContext());
+        verifyPreferenceControllers(controllers);
+    }
+
+    private void verifyPreferenceControllers(List<PreferenceController> controllers) {
         assertThat(controllers).isNotNull();
-        assertThat(controllers.size()).isEqualTo(17);
+        assertThat(controllers.size()).isEqualTo(16);
         assertThat(controllers.get(0)).isInstanceOf(InstalledPackagesPreferenceController.class);
         assertThat(controllers.get(1)).isInstanceOf(NetworkLogsPreferenceController.class);
         assertThat(controllers.get(2)).isInstanceOf(BugReportsPreferenceController.class);
@@ -125,13 +137,11 @@
         assertThat(controllers.get(10)).isInstanceOf(
                 AlwaysOnVpnManagedProfilePreferenceController.class);
         assertThat(controllers.get(11)).isInstanceOf(GlobalHttpProxyPreferenceController.class);
-        assertThat(controllers.get(12)).isInstanceOf(CaCertsCurrentUserPreferenceController.class);
+        assertThat(controllers.get(12)).isInstanceOf(CaCertsPreferenceController.class);
         assertThat(controllers.get(13)).isInstanceOf(
-                CaCertsManagedProfilePreferenceController.class);
-        assertThat(controllers.get(14)).isInstanceOf(
                 FailedPasswordWipePrimaryUserPreferenceController.class);
-        assertThat(controllers.get(15)).isInstanceOf(
+        assertThat(controllers.get(14)).isInstanceOf(
                 FailedPasswordWipeManagedProfilePreferenceController.class);
-        assertThat(controllers.get(16)).isInstanceOf(ImePreferenceController.class);
+        assertThat(controllers.get(15)).isInstanceOf(ImePreferenceController.class);
     }
 }
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceControllerTest.java
index 093ce20..3455e80 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceControllerTest.java
@@ -65,7 +65,8 @@
         MockitoAnnotations.initMocks(this);
         FakeFeatureFactory.setupForTest(mContext);
         mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
-        mController = new EnterpriseSetDefaultAppsPreferenceController(mContext);
+        mController = new EnterpriseSetDefaultAppsPreferenceController(mContext,
+                null /* lifecycle */);
     }
 
     private static Intent buildIntent(String action, String category, String protocol,
@@ -95,15 +96,6 @@
 
     @Test
     public void testUpdateState() {
-        final Preference preference = new Preference(mContext, null, 0, 0);
-        preference.setVisible(true);
-
-        when(mFeatureFactory.applicationFeatureProvider.findPersistentPreferredActivities(
-                anyObject())).thenReturn(
-                        new ArraySet<ApplicationFeatureProvider.PersistentPreferredActivityInfo>());
-        mController.updateState(preference);
-        assertThat(preference.isVisible()).isFalse();
-
         setEnterpriseSetDefaultApps(new Intent[] {buildIntent(Intent.ACTION_VIEW,
                 Intent.CATEGORY_BROWSABLE, "http:", null)}, 1);
         setEnterpriseSetDefaultApps(new Intent[] {new Intent(MediaStore.ACTION_IMAGE_CAPTURE),
@@ -120,13 +112,21 @@
                 new Intent(Intent.ACTION_CALL)}, 64);
         when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_packages,
                 127, 127)).thenReturn("127 apps");
+
+        final Preference preference = new Preference(mContext, null, 0, 0);
         mController.updateState(preference);
         assertThat(preference.getSummary()).isEqualTo("127 apps");
-        assertThat(preference.isVisible()).isTrue();
     }
 
     @Test
     public void testIsAvailable() {
+        when(mFeatureFactory.applicationFeatureProvider.findPersistentPreferredActivities(
+                anyObject())).thenReturn(
+                        new ArraySet<ApplicationFeatureProvider.PersistentPreferredActivityInfo>());
+        assertThat(mController.isAvailable()).isFalse();
+
+        setEnterpriseSetDefaultApps(new Intent[] {buildIntent(Intent.ACTION_VIEW,
+                Intent.CATEGORY_BROWSABLE, "http:", null)}, 1);
         assertThat(mController.isAvailable()).isTrue();
     }
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipeManagedProfilePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipeManagedProfilePreferenceControllerTest.java
index c9981f9..99c68f8 100644
--- a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipeManagedProfilePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipeManagedProfilePreferenceControllerTest.java
@@ -43,7 +43,8 @@
     @Override
     public void setUp() {
         super.setUp();
-        mController = new FailedPasswordWipeManagedProfilePreferenceController(mContext);
+        mController = new FailedPasswordWipeManagedProfilePreferenceController(mContext,
+                null /* lifecycle */);
     }
 
     @Override
diff --git a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerBaseTest.java b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerBaseTest.java
index 1c7b448..74c3de5 100644
--- a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerBaseTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerBaseTest.java
@@ -50,7 +50,8 @@
     private class FailedPasswordWipePreferenceControllerBaseTestable extends
             FailedPasswordWipePreferenceControllerBase {
         FailedPasswordWipePreferenceControllerBaseTestable() {
-            super(FailedPasswordWipePreferenceControllerBaseTest.this.mContext);
+            super(FailedPasswordWipePreferenceControllerBaseTest.this.mContext,
+                    null /* lifecycle */);
         }
 
         @Override
diff --git a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerTestBase.java b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerTestBase.java
index aa189e2..c14b71e 100644
--- a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerTestBase.java
+++ b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerTestBase.java
@@ -61,7 +61,6 @@
     @Test
     public void testUpdateState() {
         final Preference preference = new Preference(mContext, null, 0, 0);
-        preference.setVisible(false);
 
         setMaximumFailedPasswordsBeforeWipe(10);
         when(mContext.getResources().getQuantityString(
@@ -69,14 +68,14 @@
                 .thenReturn("10 attempts");
         mController.updateState(preference);
         assertThat(preference.getSummary()).isEqualTo("10 attempts");
-
-        setMaximumFailedPasswordsBeforeWipe(0);
-        mController.updateState(preference);
-        assertThat(preference.isVisible()).isFalse();
     }
 
     @Test
     public void testIsAvailable() {
+        setMaximumFailedPasswordsBeforeWipe(0);
+        assertThat(mController.isAvailable()).isFalse();
+
+        setMaximumFailedPasswordsBeforeWipe(10);
         assertThat(mController.isAvailable()).isTrue();
     }
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceControllerTest.java
index 65c9828..d74b9b8 100644
--- a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceControllerTest.java
@@ -43,7 +43,8 @@
     @Override
     public void setUp() {
         super.setUp();
-        mController = new FailedPasswordWipePrimaryUserPreferenceController(mContext);
+        mController = new FailedPasswordWipePrimaryUserPreferenceController(mContext,
+                null /* lifecycle */);
     }
 
     @Override
diff --git a/tests/robotests/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceControllerTest.java
index d505bad..a0bc9ee 100644
--- a/tests/robotests/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceControllerTest.java
@@ -51,27 +51,17 @@
         MockitoAnnotations.initMocks(this);
         FakeFeatureFactory.setupForTest(mContext);
         mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
-        mController = new GlobalHttpProxyPreferenceController(mContext);
-    }
-
-    @Test
-    public void testUpdateState() {
-        final Preference preference = new Preference(mContext, null, 0, 0);
-        preference.setVisible(true);
-
-        when(mFeatureFactory.enterprisePrivacyFeatureProvider.isGlobalHttpProxySet())
-                .thenReturn(false);
-        mController.updateState(preference);
-        assertThat(preference.isVisible()).isFalse();
-
-        when(mFeatureFactory.enterprisePrivacyFeatureProvider.isGlobalHttpProxySet())
-                .thenReturn(true);
-        mController.updateState(preference);
-        assertThat(preference.isVisible()).isTrue();
+        mController = new GlobalHttpProxyPreferenceController(mContext, null /* lifecycle */);
     }
 
     @Test
     public void testIsAvailable() {
+        when(mFeatureFactory.enterprisePrivacyFeatureProvider.isGlobalHttpProxySet())
+                .thenReturn(false);
+        assertThat(mController.isAvailable()).isFalse();
+
+        when(mFeatureFactory.enterprisePrivacyFeatureProvider.isGlobalHttpProxySet())
+                .thenReturn(true);
         assertThat(mController.isAvailable()).isTrue();
     }
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/ImePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/ImePreferenceControllerTest.java
index 547746c..05d0535 100644
--- a/tests/robotests/src/com/android/settings/enterprise/ImePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/ImePreferenceControllerTest.java
@@ -57,7 +57,7 @@
         MockitoAnnotations.initMocks(this);
         FakeFeatureFactory.setupForTest(mContext);
         mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
-        mController = new ImePreferenceController(mContext);
+        mController = new ImePreferenceController(mContext, null /* lifecycle */);
         when(mContext.getResources().getString(R.string.enterprise_privacy_input_method_name,
                 DEFAULT_IME_LABEL)).thenReturn(DEFAULT_IME_TEXT);
     }
@@ -65,22 +65,21 @@
     @Test
     public void testUpdateState() {
         final Preference preference = new Preference(mContext, null, 0, 0);
-        preference.setVisible(true);
-
-        when(mFeatureFactory.enterprisePrivacyFeatureProvider.getImeLabelIfOwnerSet())
-            .thenReturn(null);
-        mController.updateState(preference);
-        assertThat(preference.isVisible()).isFalse();
 
         when(mFeatureFactory.enterprisePrivacyFeatureProvider.getImeLabelIfOwnerSet())
             .thenReturn(DEFAULT_IME_LABEL);
         mController.updateState(preference);
-        assertThat(preference.isVisible()).isTrue();
         assertThat(preference.getSummary()).isEqualTo(DEFAULT_IME_TEXT);
     }
 
     @Test
     public void testIsAvailable() {
+        when(mFeatureFactory.enterprisePrivacyFeatureProvider.getImeLabelIfOwnerSet())
+            .thenReturn(null);
+        assertThat(mController.isAvailable()).isFalse();
+
+        when(mFeatureFactory.enterprisePrivacyFeatureProvider.getImeLabelIfOwnerSet())
+            .thenReturn(DEFAULT_IME_LABEL);
         assertThat(mController.isAvailable()).isTrue();
     }
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/InstalledPackagesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/InstalledPackagesPreferenceControllerTest.java
index 60ceed6..4a5a183 100644
--- a/tests/robotests/src/com/android/settings/enterprise/InstalledPackagesPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/InstalledPackagesPreferenceControllerTest.java
@@ -68,11 +68,10 @@
         doAnswer(new Answer() {
             public Object answer(InvocationOnMock invocation) {
                 ((ApplicationFeatureProvider.NumberOfAppsCallback)
-                        invocation.getArguments()[1]).onNumberOfAppsResult(number);
+                        invocation.getArguments()[2]).onNumberOfAppsResult(number);
                 return null;
-            }}).when(mFeatureFactory.applicationFeatureProvider)
-                    .calculateNumberOfInstalledApps(
-                            eq(ApplicationFeatureProvider.IGNORE_INSTALL_REASON), anyObject());
+            }}).when(mFeatureFactory.applicationFeatureProvider).calculateNumberOfInstalledApps(
+                    eq(ApplicationFeatureProvider.IGNORE_INSTALL_REASON), eq(true), anyObject());
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/enterprise/ManageDeviceAdminPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/ManageDeviceAdminPreferenceControllerTest.java
index 5cb6377..d3f5e97 100644
--- a/tests/robotests/src/com/android/settings/enterprise/ManageDeviceAdminPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/ManageDeviceAdminPreferenceControllerTest.java
@@ -62,6 +62,13 @@
         final Preference preference = new Preference(mContext, null, 0, 0);
 
         when(mFeatureFactory.enterprisePrivacyFeatureProvider
+                .getNumberOfActiveDeviceAdminsForCurrentUserAndManagedProfile()).thenReturn(0);
+        when(mContext.getResources().getString(R.string.number_of_device_admins_none))
+                .thenReturn("no apps");
+        mController.updateState(preference);
+        assertThat(preference.getSummary()).isEqualTo("no apps");
+
+        when(mFeatureFactory.enterprisePrivacyFeatureProvider
                 .getNumberOfActiveDeviceAdminsForCurrentUserAndManagedProfile()).thenReturn(5);
         when(mContext.getResources().getQuantityString(R.plurals.number_of_device_admins, 5, 5))
                 .thenReturn("5 active apps");
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java
new file mode 100644
index 0000000..471f9ea
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.fuelgauge;
+
+import android.content.Context;
+import android.os.PowerManager;
+import android.support.v7.preference.PreferenceViewHolder;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.TextView;
+
+import com.android.settings.R;
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settingslib.BatteryInfo;
+import com.android.settingslib.graph.UsageView;
+
+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.util.ReflectionHelpers;
+
+import static org.mockito.AdditionalMatchers.not;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class BatteryHistoryPreferenceTest {
+    @Mock
+    private PreferenceViewHolder mViewHolder;
+    @Mock
+    private BatteryInfo mBatteryInfo;
+    @Mock
+    private TextView mTextView;
+    @Mock
+    private View mItemView;
+    @Mock
+    private UsageView mUsageView;
+    @Mock
+    private View mLabelView;
+    private BatteryHistoryPreference mBatteryHistoryPreference;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        final Context context = RuntimeEnvironment.application;
+        final View itemView = LayoutInflater.from(context).inflate(R.layout.battery_usage_graph,
+                null);
+
+        mBatteryHistoryPreference = new BatteryHistoryPreference(context, null);
+        mBatteryHistoryPreference.mBatteryInfo = mBatteryInfo;
+        mViewHolder = spy(new PreferenceViewHolder(itemView));
+        when(mViewHolder.findViewById(R.id.battery_usage)).thenReturn(mUsageView);
+        when(mViewHolder.findViewById(R.id.charge)).thenReturn(mTextView);
+        when(mUsageView.findViewById(anyInt())).thenReturn(mLabelView);
+    }
+
+    @Test
+    public void testOnBindViewHolder_updateBatteryUsage() {
+        mBatteryHistoryPreference.onBindViewHolder(mViewHolder);
+
+        verify(mViewHolder).findViewById(R.id.battery_usage);
+        verify(mTextView).setText(anyString());
+        verify(mBatteryInfo).bindHistory(mUsageView);
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
index 494ac67..eb96604 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
@@ -27,6 +27,7 @@
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.Answers;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.annotation.Config;
@@ -38,6 +39,7 @@
 
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
 import static org.mockito.Mockito.when;
 
 @RunWith(SettingsRobolectricTestRunner.class)
@@ -45,6 +47,7 @@
 public class PowerUsageAdvancedTest {
     private static final int FAKE_UID_1 = 50;
     private static final int FAKE_UID_2 = 100;
+    private static final int DISCHARGE_AMOUNT = 60;
     private static final double TYPE_APP_USAGE = 80;
     private static final double TYPE_BLUETOOTH_USAGE = 50;
     private static final double TYPE_WIFI_USAGE = 0;
@@ -53,7 +56,7 @@
     private static final double PRECISION = 0.001;
     @Mock
     private BatterySipper mBatterySipper;
-    @Mock
+    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private BatteryStatsHelper mBatteryStatsHelper;
     @Mock
     private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
@@ -76,6 +79,8 @@
         batterySippers.add(new BatterySipper(DrainType.WIFI, new FakeUid(FAKE_UID_1),
                 TYPE_WIFI_USAGE));
 
+        when(mBatteryStatsHelper.getStats().getDischargeAmount(anyInt())).thenReturn(
+                DISCHARGE_AMOUNT);
         when(mBatteryStatsHelper.getUsageList()).thenReturn(batterySippers);
         when(mBatteryStatsHelper.getTotalPower()).thenReturn(TOTAL_USAGE);
         mPowerUsageAdvanced.setPackageManager(mPackageManager);
@@ -118,9 +123,9 @@
 
     @Test
     public void testParsePowerUsageData_PercentageCalculatedCorrectly() {
-        final double percentApp = TYPE_APP_USAGE * 2 / TOTAL_USAGE * 100;
-        final double percentWifi = TYPE_WIFI_USAGE / TOTAL_USAGE * 100;
-        final double percentBluetooth = TYPE_BLUETOOTH_USAGE / TOTAL_USAGE * 100;
+        final double percentApp = TYPE_APP_USAGE * 2 / TOTAL_USAGE * DISCHARGE_AMOUNT;
+        final double percentWifi = TYPE_WIFI_USAGE / TOTAL_USAGE * DISCHARGE_AMOUNT;
+        final double percentBluetooth = TYPE_BLUETOOTH_USAGE / TOTAL_USAGE * DISCHARGE_AMOUNT;
 
         List<PowerUsageData> batteryData =
                 mPowerUsageAdvanced.parsePowerUsageData(mBatteryStatsHelper);
diff --git a/tests/robotests/src/com/android/settings/language/LanguageAndInputSettingsTest.java b/tests/robotests/src/com/android/settings/language/LanguageAndInputSettingsTest.java
index f693fd3..026264e 100644
--- a/tests/robotests/src/com/android/settings/language/LanguageAndInputSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/language/LanguageAndInputSettingsTest.java
@@ -16,8 +16,15 @@
 
 package com.android.settings.language;
 
+import android.app.Activity;
+import android.content.ComponentName;
 import android.content.Context;
+import android.content.pm.PackageManager;
 import android.hardware.input.InputManager;
+import android.os.UserManager;
+import android.provider.Settings;
+import android.view.inputmethod.InputMethodInfo;
+import android.view.inputmethod.InputMethodManager;
 import android.view.textservice.TextServicesManager;
 
 import com.android.internal.hardware.AmbientDisplayConfiguration;
@@ -27,6 +34,8 @@
 import com.android.settings.core.PreferenceController;
 import com.android.settings.core.lifecycle.Lifecycle;
 import com.android.settings.core.lifecycle.LifecycleObserver;
+import com.android.settings.dashboard.SummaryLoader;
+import com.android.settings.testutils.shadow.ShadowSecureSettings;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -36,6 +45,7 @@
 import org.mockito.MockitoAnnotations;
 import org.robolectric.annotation.Config;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import static com.google.common.truth.Truth.assertThat;
@@ -51,14 +61,19 @@
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Context mContext;
+    @Mock
+    private PackageManager mPackageManager;
+    @Mock
+    private InputMethodManager mInputMethodManager;
     private TestFragment mFragment;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
+        when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mock(UserManager.class));
         when(mContext.getSystemService(Context.INPUT_SERVICE)).thenReturn(mock(InputManager.class));
         when(mContext.getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE))
-            .thenReturn(mock(TextServicesManager.class));
+                .thenReturn(mock(TextServicesManager.class));
         mFragment = new TestFragment(mContext);
     }
 
@@ -87,6 +102,33 @@
         assertThat(controllers.isEmpty()).isFalse();
     }
 
+    @Test
+    @Config(shadows = {
+            ShadowSecureSettings.class,
+    })
+    public void testSummary_shouldSetToCurrentImeName() {
+        final Activity activity = mock(Activity.class);
+        final SummaryLoader loader = mock(SummaryLoader.class);
+        final ComponentName componentName = new ComponentName("pkg", "cls");
+        ShadowSecureSettings.putString(null, Settings.Secure.DEFAULT_INPUT_METHOD,
+                componentName.flattenToString());
+        when(activity.getSystemService(Context.INPUT_METHOD_SERVICE))
+                .thenReturn(mInputMethodManager);
+        when(activity.getPackageManager()).thenReturn(mPackageManager);
+        final List<InputMethodInfo> imis = new ArrayList<>();
+        imis.add(mock(InputMethodInfo.class));
+        when(imis.get(0).getPackageName()).thenReturn(componentName.getPackageName());
+        when(mInputMethodManager.getInputMethodList()).thenReturn(imis);
+
+        SummaryLoader.SummaryProvider provider = mFragment.SUMMARY_PROVIDER_FACTORY
+                .createSummaryProvider(activity, loader);
+
+        provider.setListening(true);
+
+        verify(imis.get(0)).loadLabel(mPackageManager);
+        verify(loader).setSummary(provider, null);
+    }
+
     /**
      * Test fragment to expose lifecycle and context so we can verify behavior for observables.
      */
diff --git a/tests/robotests/src/com/android/settings/widget/DefaultIndicatorSeekBarTest.java b/tests/robotests/src/com/android/settings/widget/DefaultIndicatorSeekBarTest.java
new file mode 100644
index 0000000..cf4be56
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/widget/DefaultIndicatorSeekBarTest.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.widget;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import static junit.framework.Assert.assertEquals;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class DefaultIndicatorSeekBarTest {
+
+    private DefaultIndicatorSeekBar mDefaultIndicatorSeekBar;
+
+    @Before
+    public void setUp() {
+        mDefaultIndicatorSeekBar = new DefaultIndicatorSeekBar(RuntimeEnvironment.application);
+        mDefaultIndicatorSeekBar.setMax(100);
+    }
+
+    @After
+    public void tearDown() {
+        mDefaultIndicatorSeekBar = null;
+    }
+
+    @Test
+    public void defaultProgress_setSucceeds() {
+        mDefaultIndicatorSeekBar.setDefaultProgress(40);
+        assertEquals(40, mDefaultIndicatorSeekBar.getDefaultProgress());
+    }
+
+}