Merge "Hide "Magnify with button" if no navbar is shown" into oc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c7610f6..4f94bf8 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -166,7 +166,7 @@
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                 android:value="com.android.settings.network.NetworkDashboardFragment"/>
             <meta-data android:name="com.android.settings.summary"
-                android:value="@string/network_dashboard_summary"/>
+                android:resource="@string/network_dashboard_summary"/>
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
                 android:value="true" />
         </activity>
@@ -193,7 +193,7 @@
             <meta-data android:name="com.android.settings.category"
                 android:value="com.android.settings.category.ia.homepage"/>
             <meta-data android:name="com.android.settings.summary"
-                android:value="@string/connected_devices_dashboard_summary"/>
+                android:resource="@string/connected_devices_dashboard_summary"/>
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
                 android:value="true" />
         </activity>
@@ -877,7 +877,7 @@
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
                 android:value="true" />
             <meta-data android:name="com.android.settings.summary"
-                android:value="@string/display_dashboard_summary"/>
+                android:resource="@string/display_dashboard_summary"/>
         </activity>
 
         <!-- Keep compatibility with old shortcuts. -->
@@ -2519,7 +2519,7 @@
                 <category android:name="android.intent.category.DEFAULT" />
                 <category android:name="com.android.settings.SHORTCUT" />
             </intent-filter>
-            <intent-filter android:priority="120">
+            <intent-filter android:priority="160">
                 <action android:name="com.android.settings.action.SETTINGS"/>
             </intent-filter>
             <meta-data android:name="com.android.settings.category"
@@ -2560,7 +2560,7 @@
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
                 android:value="true" />
             <meta-data android:name="com.android.settings.summary"
-                android:value="@string/sound_dashboard_summary"/>
+                android:resource="@string/sound_dashboard_summary"/>
         </activity>
 
         <!-- Keep compatibility with old shortcuts. -->
@@ -2582,7 +2582,7 @@
                 <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" />
+                       android:value="com.android.settings.category.ia.notifications" />
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                 android:value="com.android.settings.applications.NotificationApps" />
         </activity>
@@ -2645,6 +2645,10 @@
                 android:value="true" />
         </activity>
 
+        <!-- Confirmation dialog for enabling notification access from CompanionDeviceManager -->
+        <activity android:name=".notification.NotificationAccessConfirmationActivity"
+                  android:theme="@android:style/Theme.DeviceDefault.Light.Dialog.Alert" />
+
         <receiver android:name=".widget.SettingsAppWidgetProvider"
                 android:label="@string/gadget_title"
                 android:exported="false"
@@ -2966,7 +2970,7 @@
             <meta-data android:name="com.android.settings.category"
                        android:value="com.android.settings.category.ia.homepage"/>
             <meta-data android:name="com.android.settings.summary"
-                       android:value="@string/app_and_notification_dashboard_summary"/>
+                       android:resource="@string/app_and_notification_dashboard_summary"/>
         </activity>
 
         <activity android:name=".Settings$UserAndAccountDashboardActivity"
@@ -2998,7 +3002,7 @@
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                        android:value="com.android.settings.system.SystemDashboardFragment"/>
             <meta-data android:name="com.android.settings.summary"
-                       android:value="@string/system_dashboard_summary"/>
+                       android:resource="@string/system_dashboard_summary"/>
         </activity>
 
         <activity android:name=".Settings$SupportDashboardActivity"
diff --git a/res/color/battery_icon_color_error.xml b/res/color/battery_icon_color_error.xml
new file mode 100644
index 0000000..3a71aae
--- /dev/null
+++ b/res/color/battery_icon_color_error.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:alpha="@*android:dimen/secondary_content_alpha_material_dark"
+          android:color="?android:attr/colorError"/>
+</selector>
\ No newline at end of file
diff --git a/res/drawable/action_bar_dropshadow.xml b/res/drawable/action_bar_dropshadow.xml
new file mode 100644
index 0000000..dd85877
--- /dev/null
+++ b/res/drawable/action_bar_dropshadow.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright (C) 2017 The Android Open Source Project
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  -->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+       android:shape="rectangle">
+    <gradient
+        android:angle="270"
+        android:startColor="#4D000000"
+        android:endColor="@android:color/transparent"
+        android:type="linear" />
+    <size android:height="8dp" />
+</shape>
\ No newline at end of file
diff --git a/res/drawable/ic_media_stream_on_24dp.xml b/res/drawable/ic_media_stream_on_24dp.xml
new file mode 100644
index 0000000..3db55dd
--- /dev/null
+++ b/res/drawable/ic_media_stream_on_24dp.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright (C) 2017 The Android Open Source Project
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF000000"
+        android:pathData="M18,3h-5c-0.55,0 -1,0.45 -1,1v8.3a3.88,3.88 0,0 0,-2.9 -0.04c-1.79,0.67 -3.11,2.35 -3.1,4.26A4.483,4.483 0,0 0,10.5 21c2.5,0 4.5,-2.3 4.5,-4.5V6h3c0.55,0 1,-0.45 1,-1V4c0,-0.55 -0.45,-1 -1,-1z"/>
+</vector>
diff --git a/res/drawable/ic_theaters_vd_theme_24.xml b/res/drawable/ic_theaters_vd_theme_24.xml
new file mode 100644
index 0000000..d0bad19
--- /dev/null
+++ b/res/drawable/ic_theaters_vd_theme_24.xml
@@ -0,0 +1,25 @@
+<!--
+    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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0"
+        android:tint="?android:attr/colorControlNormal">
+    <path
+        android:fillColor="@android:color/white"
+        android:pathData="M18,3v2h-2L16,3L8,3v2L6,5L6,3L4,3v18h2v-2h2v2h8v-2h2v2h2L20,3h-2zM8,17L6,17v-2h2v2zM8,13L6,13v-2h2v2zM8,9L6,9L6,7h2v2zM18,17h-2v-2h2v2zM18,13h-2v-2h2v2zM18,9h-2L16,7h2v2z"/>
+</vector>
\ No newline at end of file
diff --git a/res/layout/app_details.xml b/res/layout/app_details.xml
index 5ffeec5..8cfa8b9 100644
--- a/res/layout/app_details.xml
+++ b/res/layout/app_details.xml
@@ -17,30 +17,24 @@
 
 <LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/app_snippet"
-    style="@style/EntityHeader"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:layout_gravity="center_horizontal|top"
-    android:orientation="vertical"
-    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
-    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
-    android:paddingTop="24dp"
-    android:paddingBottom="24dp"
-    android:clipChildren="false"
-    android:clipToPadding="false">
+    android:orientation="vertical">
 
     <!-- App snippet with buttons -->
     <RelativeLayout
+        android:id="@+id/app_snippet"
+        style="@style/EntityHeader"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:paddingStart="8dp"
-        android:clipChildren="false"
-        android:clipToPadding="false">
+        android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+        android:paddingEnd="0dp"
+        android:paddingTop="24dp"
+        android:paddingBottom="24dp">
 
         <FrameLayout android:id="@+id/app_icon_frame"
-                     android:layout_width="80dp"
-                     android:layout_height="80dp"
+                     android:layout_width="56dp"
+                     android:layout_height="56dp"
                      android:clipChildren="false"
                      android:clipToPadding="false">
             <ImageView
@@ -54,8 +48,7 @@
                 android:layout_width="22dp"
                 android:layout_height="22dp"
                 android:layout_gravity="end|bottom"
-                android:layout_margin="8dp"
-                android:visibility="gone"
+                android:layout_margin="4dp"
                 android:elevation="20dp"
                 android:background="@drawable/ic_instant_apps_badge_bg"
                 android:src="@drawable/ic_instant_apps_badge" />
@@ -70,19 +63,22 @@
 
             <ImageButton
                 android:id="@+id/right_button"
-                style="@android:style/Widget.Material.Button.Borderless"
+                style="?android:attr/actionOverflowButtonStyle"
                 android:layout_width="wrap_content"
                 android:layout_weight="1"
                 android:layout_height="0dp"
+                android:minWidth="@dimen/min_tap_target_size"
                 android:src="@drawable/ic_settings_24dp"
                 android:tint="?android:attr/colorAccent"/>
 
             <ImageButton
                 android:id="@+id/left_button"
-                style="@android:style/Widget.Material.Button.Borderless"
+                style="?android:attr/actionOverflowButtonStyle"
                 android:layout_width="wrap_content"
                 android:layout_weight="1"
                 android:layout_height="0dp"
+                android:minWidth="@dimen/min_tap_target_size"
+                android:src="@null"
                 android:tint="?android:attr/colorAccent"/>
 
         </LinearLayout>
@@ -131,4 +127,9 @@
 
     </RelativeLayout>
 
+    <!-- Drop shadow -->
+    <View android:layout_width="match_parent"
+          android:layout_height="5dp"
+          android:background="@drawable/action_bar_dropshadow"/>
+
 </LinearLayout>
\ No newline at end of file
diff --git a/res/layout/preference_wallpaper_type.xml b/res/layout/preference_wallpaper_type.xml
deleted file mode 100644
index a35a24e..0000000
--- a/res/layout/preference_wallpaper_type.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2015 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:minHeight="?android:attr/listPreferredItemHeight"
-              android:gravity="center_vertical"
-              android:paddingStart="?android:attr/listPreferredItemPaddingStart"
-              android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" >
-
-    <ImageView
-            android:id="@android:id/icon"
-            android:layout_width="40dp"
-            android:layout_height="40dp"
-            android:layout_gravity="center"
-            android:scaleType="fitXY"
-            android:layout_marginEnd="16dip"
-            android:contentDescription="@null" />
-
-    <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:ellipsize="marquee"
-              android:fadingEdge="horizontal"
-              android:layout_weight="1" />
-
-</LinearLayout>
diff --git a/res/layout/storage_item.xml b/res/layout/storage_item.xml
index 33f4f9e..0c1f60c 100644
--- a/res/layout/storage_item.xml
+++ b/res/layout/storage_item.xml
@@ -76,6 +76,7 @@
         android:id="@android:id/progress"
         android:layout_width="match_parent"
         android:layout_height="8dp"
+        android:layout_marginStart="60dp"
         android:layout_marginTop="16dp"
         android:layout_marginBottom="8dp"
         android:visibility="gone"
diff --git a/res/mipmap-hdpi/ic_accessibility_generic.png b/res/mipmap-hdpi/ic_accessibility_generic.png
new file mode 100755
index 0000000..e54166b
--- /dev/null
+++ b/res/mipmap-hdpi/ic_accessibility_generic.png
Binary files differ
diff --git a/res/mipmap-hdpi/ic_accessibility_magnification.png b/res/mipmap-hdpi/ic_accessibility_magnification.png
new file mode 100755
index 0000000..a91bc6e
--- /dev/null
+++ b/res/mipmap-hdpi/ic_accessibility_magnification.png
Binary files differ
diff --git a/res/mipmap-mdpi/ic_accessibility_generic.png b/res/mipmap-mdpi/ic_accessibility_generic.png
new file mode 100755
index 0000000..77dc47b
--- /dev/null
+++ b/res/mipmap-mdpi/ic_accessibility_generic.png
Binary files differ
diff --git a/res/mipmap-mdpi/ic_accessibility_magnification.png b/res/mipmap-mdpi/ic_accessibility_magnification.png
new file mode 100755
index 0000000..9ec5107
--- /dev/null
+++ b/res/mipmap-mdpi/ic_accessibility_magnification.png
Binary files differ
diff --git a/res/mipmap-xhdpi/ic_accessibility_generic.png b/res/mipmap-xhdpi/ic_accessibility_generic.png
new file mode 100755
index 0000000..1152c42
--- /dev/null
+++ b/res/mipmap-xhdpi/ic_accessibility_generic.png
Binary files differ
diff --git a/res/mipmap-xhdpi/ic_accessibility_magnification.png b/res/mipmap-xhdpi/ic_accessibility_magnification.png
new file mode 100755
index 0000000..0b3a32e
--- /dev/null
+++ b/res/mipmap-xhdpi/ic_accessibility_magnification.png
Binary files differ
diff --git a/res/mipmap-xxhdpi/ic_accessibility_generic.png b/res/mipmap-xxhdpi/ic_accessibility_generic.png
new file mode 100755
index 0000000..48f39c2
--- /dev/null
+++ b/res/mipmap-xxhdpi/ic_accessibility_generic.png
Binary files differ
diff --git a/res/mipmap-xxhdpi/ic_accessibility_magnification.png b/res/mipmap-xxhdpi/ic_accessibility_magnification.png
new file mode 100755
index 0000000..3eeb1c9
--- /dev/null
+++ b/res/mipmap-xxhdpi/ic_accessibility_magnification.png
Binary files differ
diff --git a/res/mipmap-xxxhdpi/ic_accessibility_generic.png b/res/mipmap-xxxhdpi/ic_accessibility_generic.png
new file mode 100755
index 0000000..e9ca879
--- /dev/null
+++ b/res/mipmap-xxxhdpi/ic_accessibility_generic.png
Binary files differ
diff --git a/res/mipmap-xxxhdpi/ic_accessibility_magnification.png b/res/mipmap-xxxhdpi/ic_accessibility_magnification.png
new file mode 100755
index 0000000..7d37612
--- /dev/null
+++ b/res/mipmap-xxxhdpi/ic_accessibility_magnification.png
Binary files differ
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 09f7cda..8173d8a 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -22,6 +22,7 @@
     <dimen name="action_bar_switch_padding">16dip</dimen>
 
     <dimen name="app_icon_size">40dip</dimen>
+    <dimen name="min_tap_target_size">48dp</dimen>
     <dimen name="screen_margin_sides">64dip</dimen>
     <dimen name="screen_margin_top">72dip</dimen>
     <dimen name="screen_margin_bottom">48dip</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 019712d..863d27f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1628,6 +1628,8 @@
     <string name="wifi_wakeup">Turn on Wi\u2011Fi automatically</string>
     <!-- Checkbox summary for option to enable Wi-Fi when high quality saved networks are nearby-->
     <string name="wifi_wakeup_summary">Wi\u2011Fi will turn back on near high\u2011quality saved networks, like your home network</string>
+    <!-- Checkbox summary for Wi-Fi wakeup option to explain that Wi-Fi wakeup is disabled because Wi-Fi scanning is turned off -->
+    <string name="wifi_wakeup_summary_scanning_disabled">Unavailable because Wi\u2011Fi scanning is turned off</string>
     <!-- Checkbox title for option to toggle poor network detection -->
     <string name="wifi_poor_network_detection">Avoid poor connections</string>
     <!-- Checkbox summary for option to toggle poor network detection -->
@@ -3740,6 +3742,9 @@
     <!-- Manage applications, individual application info screen, summary for the option which will trigger application info in it's installer [CHAR_LIMIT=50] -->
     <string name="app_install_details_summary">App installed from <xliff:g id="app_store">%1$s</xliff:g></string>
 
+    <!-- Manage applications, individual application info screen, summary for the option which will trigger instant app info in it's installer [CHAR_LIMIT=50] -->
+    <string name="instant_app_details_summary">More info on <xliff:g id="app_store">%1$s</xliff:g></string>
+
     <!-- App Ops Settings --> <skip />
     <!-- [CHAR LIMIT=NONE] App ops settings title, on main settings screen. If clicked, the user is taken to a settings screen for app operations -->
     <string name="app_ops_settings">App ops</string>
@@ -4683,9 +4688,9 @@
     <string name="battery_last_full_charge">Last full charge</string>
     <!-- Description for text in battery footer. [CHAR LIMIT=120] -->
     <string name="battery_footer_summary">Remaining battery time is approximate and can change based on usage</string>
-    <!-- Title for battery usage detail in foreground. [CHAR LIMIT=80] -->
+    <!-- Title for text that shows the amount of time an app has been running while in the foreground. [CHAR LIMIT=80] -->
     <string name="battery_detail_foreground">While in active use</string>
-    <!-- Title for battery usage detail in background. [CHAR LIMIT=80] -->
+    <!-- Title for text that shows the amount of time an app has been running while in the background. [CHAR LIMIT=80] -->
     <string name="battery_detail_background">While in background</string>
     <!-- Title for battery usage amount by this app. [CHAR LIMIT=80] -->
     <string name="battery_detail_power_usage">Battery usage</string>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index e9d25ff..bae36b3 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -416,7 +416,7 @@
     <style name="TextAppearance.EntityHeaderTitle"
            parent="@android:style/TextAppearance.Material.Subhead">
         <item name="android:textColor">?android:attr/textColorPrimary</item>
-        <item name="android:textSize">24sp</item>
+        <item name="android:textSize">16sp</item>
     </style>
 
     <style name="AppActionPrimaryButton" parent="android:Widget.Material.Button.Colored"/>
diff --git a/res/xml/accessibility_settings.xml b/res/xml/accessibility_settings.xml
index 48e11af..795d35e 100644
--- a/res/xml/accessibility_settings.xml
+++ b/res/xml/accessibility_settings.xml
@@ -54,7 +54,8 @@
         <Preference
             android:fragment="com.android.settings.accessibility.MagnificationPreferenceFragment"
             android:key="magnification_preference_screen"
-            android:title="@string/accessibility_screen_magnification_title"/>
+            android:title="@string/accessibility_screen_magnification_title"
+            android:icon="@mipmap/ic_accessibility_magnification" />
 
         <Preference
                 android:fragment="com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment"
diff --git a/res/xml/app_memory_settings.xml b/res/xml/app_memory_settings.xml
index 53a71ff..308f189 100644
--- a/res/xml/app_memory_settings.xml
+++ b/res/xml/app_memory_settings.xml
@@ -18,26 +18,25 @@
                   android:title="@string/memory_usage">
 
     <PreferenceCategory
-        android:title="@string/average_memory_use"/>
+        android:title="@string/average_memory_use">
 
-    <com.android.settings.SummaryPreference
-        android:key="status_header"
-        android:selectable="false" />
+        <com.android.settings.SummaryPreference
+            android:key="status_header"
+            android:selectable="false" />
 
-    <com.android.settings.applications.SpacePreference
-        android:layout_height="5dp" />
+        <Preference
+            android:key="frequency"
+            android:selectable="false"
+            android:layout="@layout/horizontal_preference"
+            android:title="@string/running_frequency" />
 
-    <Preference
-        android:key="frequency"
-        android:selectable="false"
-        android:layout="@layout/horizontal_preference"
-        android:title="@string/running_frequency" />
+        <Preference
+            android:key="max_usage"
+            android:selectable="false"
+            android:layout="@layout/horizontal_preference"
+            android:title="@string/memory_maximum_usage" />
 
-    <Preference
-        android:key="max_usage"
-        android:selectable="false"
-        android:layout="@layout/horizontal_preference"
-        android:title="@string/memory_maximum_usage" />
+    </PreferenceCategory>
 
     <PreferenceCategory
         android:key="processes"
diff --git a/res/xml/app_storage_settings.xml b/res/xml/app_storage_settings.xml
index 6bd8ae3..1c71bfa 100644
--- a/res/xml/app_storage_settings.xml
+++ b/res/xml/app_storage_settings.xml
@@ -15,8 +15,14 @@
 -->
 
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+                  xmlns:settings="http://schemas.android.com/apk/res-auto"
                   android:title="@string/application_info_label">
 
+    <com.android.settings.applications.LayoutPreference
+        android:key="header_view"
+        android:layout="@layout/app_action_buttons"
+        android:selectable="false" />
+
     <com.android.settings.applications.SpacePreference
         android:key="storage_space"
         android:layout_height="8dp" />
@@ -36,13 +42,9 @@
     <PreferenceCategory
         android:key="storage_category"
         android:layout="@layout/tall_preference_category"
-        android:title="@string/storage_label">
-
-        <Preference
-            android:key="total_size"
-            android:title="@string/total_size_label"
-            android:selectable="false"
-            android:layout="@layout/horizontal_preference" />
+        android:title="@string/app_info_storage_title"
+        settings:allowDividerAbove="false"
+        settings:allowDividerBelow="false">
 
         <Preference
             android:key="app_size"
@@ -56,32 +58,28 @@
             android:selectable="false"
             android:layout="@layout/horizontal_preference" />
 
-        <com.android.settings.applications.LayoutPreference
-            android:key="clear_data_button"
+        <Preference
+            android:key="cache_size"
+            android:title="@string/cache_size_label"
             android:selectable="false"
-            android:layout="@layout/single_button_panel" />
+            android:layout="@layout/horizontal_preference" />
+
+        <Preference
+            android:key="total_size"
+            android:title="@string/total_size_label"
+            android:selectable="false"
+            android:layout="@layout/horizontal_preference" />
+
+        <com.android.settings.applications.SpacePreference
+            android:layout_height="8dp" />
+
     </PreferenceCategory>
 
-    <com.android.settings.applications.SpacePreference
-        android:layout_height="8dp" />
-
-    <Preference
-        android:key="cache_size"
-        android:title="@string/cache_size_label"
-        android:selectable="false"
-        android:layout="@layout/horizontal_preference" />
-
-    <com.android.settings.applications.LayoutPreference
-        android:key="clear_cache_button"
-        android:selectable="false"
-        android:layout="@layout/single_button_panel" />
-
-    <com.android.settings.applications.SpacePreference
-        android:layout_height="8dp" />
-
     <PreferenceCategory
         android:key="uri_category"
-        android:layout="@layout/headerless_preference_category" >
+        android:layout="@layout/headerless_preference_category"
+        settings:allowDividerAbove="false"
+        settings:allowDividerBelow="false">
         <com.android.settings.applications.LayoutPreference
             android:key="clear_uri_button"
             android:layout="@layout/single_button_panel"
diff --git a/res/xml/configure_notification_settings.xml b/res/xml/configure_notification_settings.xml
index 626cd33..a6ffff4 100644
--- a/res/xml/configure_notification_settings.xml
+++ b/res/xml/configure_notification_settings.xml
@@ -18,6 +18,10 @@
                   android:title="@string/configure_notification_settings"
                   android:key="configure_notification_settings">
 
+    <PreferenceCategory
+        android:key="dashboard_tile_placeholder"
+        android:order="1"/>
+
     <!-- Pulse notification light -->
     <SwitchPreference
         android:key="notification_pulse"
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index e870539..54eb878 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -209,6 +209,11 @@
             android:title="@string/bluetooth_disable_absolute_volume"
             android:summary="@string/bluetooth_disable_absolute_volume_summary"/>
 
+        <SwitchPreference
+            android:key="bluetooth_enable_inband_ringing"
+            android:title="@string/bluetooth_enable_inband_ringing"
+            android:summary="@string/bluetooth_enable_inband_ringing_summary"/>
+
         <ListPreference
             android:key="bluetooth_select_avrcp_version"
             android:title="@string/bluetooth_select_avrcp_version_string"
diff --git a/res/xml/installed_app_details_ia.xml b/res/xml/installed_app_details_ia.xml
index b092753..538205f 100644
--- a/res/xml/installed_app_details_ia.xml
+++ b/res/xml/installed_app_details_ia.xml
@@ -52,6 +52,11 @@
         android:summary="@string/summary_placeholder"
         android:selectable="true"/>
 
+    <com.android.settings.applications.AppDomainsPreference
+        android:key="instant_app_launch_supported_domain_urls"
+        android:title="@string/app_launch_supported_domain_urls_title"
+        android:selectable="true" />
+
     <Preference
         android:key="data_settings"
         android:title="@string/data_usage_summary_title"
diff --git a/res/xml/power_usage_detail_ia.xml b/res/xml/power_usage_detail_ia.xml
index cfaa712..39e6c38 100644
--- a/res/xml/power_usage_detail_ia.xml
+++ b/res/xml/power_usage_detail_ia.xml
@@ -56,7 +56,7 @@
 
         <Preference
             android:key="battery_optimization"
-            android:title="@string/battery_detail_background"
+            android:title="@string/high_power_apps"
             android:summary="@string/high_power_off"
             android:selectable="true"/>
 
diff --git a/res/xml/storage_dashboard_fragment.xml b/res/xml/storage_dashboard_fragment.xml
index 354a700..b31d0eb 100644
--- a/res/xml/storage_dashboard_fragment.xml
+++ b/res/xml/storage_dashboard_fragment.xml
@@ -47,15 +47,20 @@
         android:icon="@drawable/ic_videogame_vd_theme_24"
         android:order="4" />
     <com.android.settings.deviceinfo.StorageItemPreference
+        android:key="pref_movies"
+        android:title="@string/storage_movies_tv"
+        android:icon="@drawable/ic_theaters_vd_theme_24"
+        android:order="5" />
+    <com.android.settings.deviceinfo.StorageItemPreference
         android:key="pref_other_apps"
         android:title="@string/storage_other_apps"
         android:icon="@drawable/ic_apps_vd_theme_24"
-        android:order="5" />
+        android:order="6" />
     <com.android.settings.deviceinfo.StorageItemPreference
         android:key="pref_files"
         android:title="@string/storage_files"
         android:icon="@drawable/ic_folder_vd_theme_24"
-        android:order="6" />
+        android:order="7" />
     <com.android.settings.deviceinfo.StorageItemPreference
         android:key="pref_system"
         android:title="@string/storage_detail_system"
diff --git a/res/xml/storage_profile_fragment.xml b/res/xml/storage_profile_fragment.xml
index 98cb1dc..0485279 100644
--- a/res/xml/storage_profile_fragment.xml
+++ b/res/xml/storage_profile_fragment.xml
@@ -34,6 +34,9 @@
         android:icon="@drawable/ic_videogame_vd_theme_24"
         android:order="4" />
     <com.android.settings.deviceinfo.StorageItemPreference
+        android:key="pref_movies"
+        android:title="@string/storage_movies_tv" />
+    <com.android.settings.deviceinfo.StorageItemPreference
         android:key="pref_other_apps"
         android:title="@string/storage_other_apps"
         android:icon="@drawable/ic_apps_vd_theme_24"
diff --git a/src/com/android/settings/ChooseLockGeneric.java b/src/com/android/settings/ChooseLockGeneric.java
index 3e9304d..546b11e 100644
--- a/src/com/android/settings/ChooseLockGeneric.java
+++ b/src/com/android/settings/ChooseLockGeneric.java
@@ -129,6 +129,7 @@
         private boolean mHideDrawer = false;
         private ManagedLockPasswordProvider mManagedPasswordProvider;
         private boolean mIsSetNewPassword = false;
+        private UserManager mUserManager;
 
         protected boolean mForFingerprint = false;
 
@@ -166,6 +167,7 @@
                     ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, false);
             mForChangeCredRequiredForBoot = getArguments() != null && getArguments().getBoolean(
                     ChooseLockSettingsHelper.EXTRA_KEY_FOR_CHANGE_CRED_REQUIRED_FOR_BOOT);
+            mUserManager = UserManager.get(getActivity());
 
             if (savedInstanceState != null) {
                 mPasswordConfirmed = savedInstanceState.getBoolean(PASSWORD_CONFIRMED);
@@ -751,11 +753,10 @@
             if (mFingerprintManager != null && mFingerprintManager.isHardwareDetected()) {
                 mFingerprintManager.setActiveUser(UserHandle.myUserId());
             }
-            final UserManager um = UserManager.get(getActivity());
             boolean hasChildProfile = false;
-            if (!um.getUserInfo(parentUserId).isManagedProfile()) {
+            if (!mUserManager.getUserInfo(parentUserId).isManagedProfile()) {
                 // Current user is primary profile, remove work profile fingerprints if necessary
-                final List<UserInfo> profiles = um.getProfiles(parentUserId);
+                final List<UserInfo> profiles = mUserManager.getProfiles(parentUserId);
                 final int profilesSize = profiles.size();
                 for (int i = 0; i < profilesSize; i++) {
                     final UserInfo userInfo = profiles.get(i);
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index 1e64b7f..bdf9644 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -1227,55 +1227,18 @@
 
         @Override
         public void setListening(boolean listening) {
-            if (!listening) {
-                return;
-            }
-            int packageVerifierState = Settings.Secure.getInt(mContext.getContentResolver(),
-                    Settings.Secure.PACKAGE_VERIFIER_STATE, 0);
-            DashboardFeatureProvider dashboardFeatureProvider =
-                    FeatureFactory.getFactory(mContext).getDashboardFeatureProvider(mContext);
-            if (packageVerifierState == PACKAGE_VERIFIER_STATE_ENABLED) {
-                // Calling the feature provider could potentially be slow, so do this on a separate
-                // thread so as to not block the loading of Settings.
-                Executors.newSingleThreadExecutor().execute(new Runnable() {
-                    @Override
-                    public void run() {
-                        DashboardCategory dashboardCategory =
-                                dashboardFeatureProvider.getTilesForCategory(
-                                        CategoryKey.CATEGORY_SECURITY);
-                        mSummaryLoader.setSummary(SummaryProvider.this,
-                                getPackageVerifierSummary(dashboardCategory));
-                    }
-                });
-            } else {
-                final FingerprintManager fpm = Utils.getFingerprintManagerOrNull(mContext);
+            if (listening) {
+                final FingerprintManager fpm =
+                    Utils.getFingerprintManagerOrNull(mContext);
                 if (fpm != null && fpm.isHardwareDetected()) {
                     mSummaryLoader.setSummary(this,
-                            mContext.getString(R.string.security_dashboard_summary));
+                        mContext.getString(R.string.security_dashboard_summary));
                 } else {
-                    mSummaryLoader.setSummary(this, null);
+                    mSummaryLoader.setSummary(this, mContext.getString(
+                        R.string.security_dashboard_summary_no_fingerprint));
                 }
             }
         }
-
-        @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
-        String getPackageVerifierSummary(DashboardCategory dashboardCategory) {
-            int tilesCount = (dashboardCategory != null) ? dashboardCategory.getTilesCount() : 0;
-            if (tilesCount == 0) {
-                return null;
-            }
-            for (int i = 0; i < tilesCount; i++) {
-                Tile tile = dashboardCategory.getTile(i);
-                if (!KEY_PACKAGE_VERIFIER_STATUS.equals(tile.key)) {
-                    continue;
-                }
-                String summaryUri = tile.metaData.getString(
-                        TileUtils.META_DATA_PREFERENCE_SUMMARY_URI, null);
-                return TileUtils.getTextFromUri(mContext, summaryUri,
-                        new ArrayMap<>(), TileUtils.META_DATA_PREFERENCE_SUMMARY);
-            }
-            return null;
-        }
     }
 
     public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY =
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 589421f..1db185e 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -121,6 +121,7 @@
     public static class ManageDomainUrlsActivity extends SettingsActivity { /* empty */ }
     public static class AutomaticStorageManagerSettingsActivity extends SettingsActivity { /* empty */ }
     public static class GamesStorageActivity extends SettingsActivity { /* empty */ }
+    public static class MoviesStorageActivity extends SettingsActivity { /* empty */ }
 
     public static class TopLevelSettings extends SettingsActivity { /* empty */ }
     public static class ApnSettingsActivity extends SettingsActivity { /* empty */ }
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 015af17..34990ec 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -83,7 +83,10 @@
 
     // Constants for state save/restore
     private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
-    private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
+    @VisibleForTesting
+    static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
+    @VisibleForTesting
+    static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
 
     /**
      * When starting this activity, the invoking Intent can contain this extra
@@ -192,8 +195,10 @@
 
     private Button mNextButton;
 
-    private boolean mDisplayHomeAsUpEnabled;
-    private boolean mDisplaySearch;
+    @VisibleForTesting
+    boolean mDisplayHomeAsUpEnabled;
+    @VisibleForTesting
+    boolean mDisplaySearch;
 
     private boolean mIsShowingDashboard;
     private boolean mIsShortcut;
@@ -230,7 +235,6 @@
         if (!mDisplaySearch) {
             return false;
         }
-
         mSearchFeatureProvider.setUpSearchMenu(menu, this);
         return true;
     }
@@ -513,12 +517,28 @@
     @Override
     protected void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
+        saveState(outState);
+    }
 
+    /**
+     * For testing purposes to avoid crashes from final variables in Activity's onSaveInstantState.
+     */
+    @VisibleForTesting
+    void saveState(Bundle outState) {
         if (mCategories.size() > 0) {
             outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
         }
 
         outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
+        outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
+    }
+
+    @Override
+    protected void onRestoreInstanceState(Bundle savedInstanceState) {
+        super.onRestoreInstanceState(savedInstanceState);
+
+        mDisplayHomeAsUpEnabled = savedInstanceState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
+        mDisplaySearch = savedInstanceState.getBoolean(SAVE_KEY_SHOW_SEARCH);
     }
 
     @Override
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
index 70743e2..761e8cf 100644
--- a/src/com/android/settings/SettingsPreferenceFragment.java
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -440,6 +440,7 @@
 
     @Override
     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+        super.onCreateOptionsMenu(menu, inflater);
         if (mHelpUri != null && getActivity() != null) {
             HelpUtils.prepareHelpMenuItem(getActivity(), menu, mHelpUri, getClass().getName());
         }
diff --git a/src/com/android/settings/SetupChooseLockGeneric.java b/src/com/android/settings/SetupChooseLockGeneric.java
index 61545a6..2c8195d 100644
--- a/src/com/android/settings/SetupChooseLockGeneric.java
+++ b/src/com/android/settings/SetupChooseLockGeneric.java
@@ -17,10 +17,8 @@
 package com.android.settings;
 
 import android.app.admin.DevicePolicyManager;
-import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
-import android.content.pm.PackageManager;
 import android.content.res.Resources;
 import android.os.Bundle;
 import android.os.UserHandle;
@@ -120,12 +118,6 @@
                 data.putExtra(EXTRA_PASSWORD_QUALITY,
                         lockPatternUtils.getKeyguardStoredPasswordQuality(UserHandle.myUserId()));
 
-                PackageManager packageManager = getPackageManager();
-                ComponentName componentName = new ComponentName("com.android.settings",
-                        "com.android.settings.SetupRedactionInterstitial");
-                packageManager.setComponentEnabledSetting(componentName,
-                        PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
-                        PackageManager.DONT_KILL_APP);
                 super.onActivityResult(requestCode, resultCode, data);
             }
             // If the started activity was cancelled (e.g. the user presses back), then this
diff --git a/src/com/android/settings/SetupChooseLockPassword.java b/src/com/android/settings/SetupChooseLockPassword.java
index f0a9a26..f2c24d0 100644
--- a/src/com/android/settings/SetupChooseLockPassword.java
+++ b/src/com/android/settings/SetupChooseLockPassword.java
@@ -87,6 +87,9 @@
 
         @Override
         protected Intent getRedactionInterstitialIntent(Context context) {
+            // Setup wizard's redaction interstitial is deferred to optional step. Enable that
+            // optional step if the lock screen was set up.
+            SetupRedactionInterstitial.setEnabled(context, true);
             return null;
         }
     }
diff --git a/src/com/android/settings/SetupChooseLockPattern.java b/src/com/android/settings/SetupChooseLockPattern.java
index 09b951e..30a3c7c 100644
--- a/src/com/android/settings/SetupChooseLockPattern.java
+++ b/src/com/android/settings/SetupChooseLockPattern.java
@@ -73,6 +73,9 @@
 
         @Override
         protected Intent getRedactionInterstitialIntent(Context context) {
+            // Setup wizard's redaction interstitial is deferred to optional step. Enable that
+            // optional step if the lock screen was set up.
+            SetupRedactionInterstitial.setEnabled(context, false);
             return null;
         }
     }
diff --git a/src/com/android/settings/SetupRedactionInterstitial.java b/src/com/android/settings/SetupRedactionInterstitial.java
index d527585..321040e 100644
--- a/src/com/android/settings/SetupRedactionInterstitial.java
+++ b/src/com/android/settings/SetupRedactionInterstitial.java
@@ -16,11 +16,11 @@
 
 package com.android.settings;
 
+import android.content.ComponentName;
+import android.content.Context;
 import android.content.Intent;
+import android.content.pm.PackageManager;
 import android.content.res.Resources;
-import android.os.Bundle;
-import android.view.View;
-import android.widget.Button;
 
 import com.android.settings.notification.RedactionInterstitial;
 
@@ -33,6 +33,20 @@
  */
 public class SetupRedactionInterstitial extends RedactionInterstitial {
 
+    /**
+     * Set the enabled state of SetupRedactionInterstitial activity to configure whether it is shown
+     * as part of setup wizard's optional steps.
+     */
+    public static void setEnabled(Context context, boolean enabled) {
+        PackageManager packageManager = context.getPackageManager();
+        ComponentName componentName = new ComponentName(context, SetupRedactionInterstitial.class);
+        packageManager.setComponentEnabledSetting(
+                componentName,
+                enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
+                        : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
+                PackageManager.DONT_KILL_APP);
+    }
+
     @Override
     public Intent getIntent() {
         Intent modIntent = new Intent(super.getIntent());
diff --git a/src/com/android/settings/accessibility/AccessibilitySettings.java b/src/com/android/settings/accessibility/AccessibilitySettings.java
index c08131b..1d3e125 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettings.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettings.java
@@ -31,6 +31,7 @@
 import android.provider.SearchIndexableResource;
 import android.provider.Settings;
 import android.support.v14.preference.SwitchPreference;
+import android.support.v4.content.ContextCompat;
 import android.support.v7.preference.ListPreference;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceCategory;
@@ -76,11 +77,12 @@
     private static final String CATEGORY_AUDIO_AND_CAPTIONS = "audio_and_captions_category";
     private static final String CATEGORY_DISPLAY = "display_category";
     private static final String CATEGORY_INTERACTION_CONTROL = "interaction_control_category";
+    private static final String CATEGORY_EXPERIMENTAL = "experimental_category";
     private static final String CATEGORY_DOWNLOADED_SERVICES = "user_installed_services_category";
 
     private static final String[] CATEGORIES = new String[] {
         CATEGORY_SCREEN_READER, CATEGORY_AUDIO_AND_CAPTIONS, CATEGORY_DISPLAY,
-        CATEGORY_INTERACTION_CONTROL, CATEGORY_DOWNLOADED_SERVICES
+        CATEGORY_INTERACTION_CONTROL, CATEGORY_EXPERIMENTAL, CATEGORY_DOWNLOADED_SERVICES
     };
 
     // Preferences
@@ -455,9 +457,11 @@
                     new RestrictedPreference(downloadedServicesCategory.getContext());
             String title = info.getResolveInfo().loadLabel(getPackageManager()).toString();
 
-            Drawable icon = info.getResolveInfo().loadIcon(getPackageManager());
-            if (icon == null) {
-                // todo (saigem): add a default
+            Drawable icon;
+            if (info.getResolveInfo().getIconResource() == 0) {
+                icon = ContextCompat.getDrawable(getContext(), R.mipmap.ic_accessibility_generic);
+            } else {
+                icon = info.getResolveInfo().loadIcon(getPackageManager());
             }
 
             ServiceInfo serviceInfo = info.getResolveInfo().serviceInfo;
diff --git a/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java b/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
index 9018d9b..51225aa 100644
--- a/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
+++ b/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
@@ -25,6 +25,7 @@
 import com.android.settings.dashboard.DashboardFragment;
 import com.android.settings.search.BaseSearchIndexProvider;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
@@ -55,7 +56,13 @@
 
     @Override
     protected List<PreferenceController> getPreferenceControllers(Context context) {
-        return null;
+        return buildPreferenceControllers(context);
+    }
+
+    private static List<PreferenceController> buildPreferenceControllers(Context context) {
+        final List<PreferenceController> controllers = new ArrayList<>();
+        controllers.add(new SpecialAppAccessPreferenceController(context));
+        return controllers;
     }
 
     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
@@ -67,5 +74,10 @@
                     sir.xmlResId = R.xml.app_and_notification;
                     return Arrays.asList(sir);
                 }
+
+                @Override
+                public List<PreferenceController> getPreferenceControllers(Context context) {
+                    return buildPreferenceControllers(context);
+                }
             };
 }
diff --git a/src/com/android/settings/applications/AppHeaderController.java b/src/com/android/settings/applications/AppHeaderController.java
index f3a086b..29acaa4 100644
--- a/src/com/android/settings/applications/AppHeaderController.java
+++ b/src/com/android/settings/applications/AppHeaderController.java
@@ -18,25 +18,25 @@
 
 import android.annotation.IdRes;
 import android.annotation.UserIdInt;
+import android.app.ActionBar;
+import android.app.Activity;
 import android.app.Fragment;
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.PackageInfo;
 import android.content.pm.ResolveInfo;
-import android.content.res.Resources;
-import android.graphics.Outline;
-import android.graphics.drawable.AdaptiveIconDrawable;
 import android.graphics.drawable.Drawable;
 import android.os.UserHandle;
 import android.support.annotation.IntDef;
+import android.support.annotation.VisibleForTesting;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
-import android.view.ViewOutlineProvider;
 import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.TextView;
+
 import com.android.settings.AppHeader;
 import com.android.settings.R;
 import com.android.settings.Utils;
@@ -69,7 +69,6 @@
     private final Fragment mFragment;
     private final int mMetricsCategory;
     private final View mAppHeader;
-    private final int mIconElevation;
 
     private Drawable mIcon;
     private CharSequence mLabel;
@@ -96,8 +95,6 @@
             mAppHeader = LayoutInflater.from(fragment.getContext())
                     .inflate(R.layout.app_details, null /* root */);
         }
-        mIconElevation = mContext.getResources()
-            .getDimensionPixelSize(R.dimen.launcher_icon_elevation);
     }
 
     public AppHeaderController setIcon(Drawable icon) {
@@ -164,39 +161,10 @@
     }
 
     /**
-     * Binds app header view and data from {@code PackageInfo} and {@code AppEntry}.
-     */
-    public void bindAppHeader(PackageInfo packageInfo, ApplicationsState.AppEntry appEntry) {
-        final String versionName = packageInfo == null ? null : packageInfo.versionName;
-        final Resources res = mAppHeader.getResources();
-
-        // Set Icon
-        final ImageView iconView = (ImageView) mAppHeader.findViewById(R.id.app_detail_icon);
-        if (appEntry.icon != null) {
-            iconView.setImageDrawable(appEntry.icon.getConstantState().newDrawable(res));
-        }
-
-        // Set application name.
-        final TextView labelView = (TextView) mAppHeader.findViewById(R.id.app_detail_title);
-        labelView.setText(appEntry.label);
-
-        // Version number of application
-        final TextView appVersion = (TextView) mAppHeader.findViewById(R.id.app_detail_summary);
-
-        if (!TextUtils.isEmpty(versionName)) {
-            appVersion.setSelected(true);
-            appVersion.setVisibility(View.VISIBLE);
-            appVersion.setText(res.getString(R.string.version_text, String.valueOf(versionName)));
-        } else {
-            appVersion.setVisibility(View.INVISIBLE);
-        }
-    }
-
-    /**
      * Done mutating appheader, rebinds everything and return a new {@link LayoutPreference}.
      */
-    public LayoutPreference done(Context context) {
-        final LayoutPreference pref = new LayoutPreference(context, done());
+    public LayoutPreference done(Activity activity, Context uiContext) {
+        final LayoutPreference pref = new LayoutPreference(uiContext, done(activity));
         // Makes sure it's the first preference onscreen.
         pref.setOrder(-1000);
         pref.setKey(PREF_KEY_APP_HEADER);
@@ -204,17 +172,11 @@
     }
 
     /**
-     * Done mutating appheader, rebinds everything.
-     */
-    public View done() {
-        return done(true);
-    }
-
-    /**
      * Done mutating appheader, rebinds everything (optionally skip rebinding buttons).
      */
-    public View done(boolean rebindActions) {
-        ImageView iconView = (ImageView) mAppHeader.findViewById(R.id.app_detail_icon);
+    public View done(Activity activity, boolean rebindActions) {
+        styleActionBar(activity);
+        ImageView iconView = mAppHeader.findViewById(R.id.app_detail_icon);
         if (iconView != null) {
             iconView.setImageDrawable(mIcon);
             ImageView badgeView = mAppHeader.findViewById(R.id.app_icon_instant_apps_badge);
@@ -239,12 +201,39 @@
     /**
      * Only binds app header with button actions.
      */
-    public void bindAppHeaderButtons() {
-        ImageButton leftButton = (ImageButton) mAppHeader.findViewById(R.id.left_button);
-        ImageButton rightButton = (ImageButton) mAppHeader.findViewById(R.id.right_button);
+    public AppHeaderController bindAppHeaderButtons() {
+        ImageButton leftButton = mAppHeader.findViewById(R.id.left_button);
+        ImageButton rightButton = mAppHeader.findViewById(R.id.right_button);
 
         bindButton(leftButton, mLeftAction);
         bindButton(rightButton, mRightAction);
+        return this;
+    }
+
+    public AppHeaderController styleActionBar(Activity activity) {
+        if (activity == null) {
+            Log.w(TAG, "No activity, cannot style actionbar.");
+            return this;
+        }
+        final ActionBar actionBar = activity.getActionBar();
+        if (actionBar == null) {
+            Log.w(TAG, "No actionbar, cannot style actionbar.");
+            return this;
+        }
+        final Drawable appHeaderBackground =
+                mAppHeader.findViewById(R.id.app_snippet).getBackground();
+        actionBar.setBackgroundDrawable(appHeaderBackground);
+        actionBar.setElevation(0);
+
+        return this;
+    }
+
+    /**
+     * Done mutating appheader, rebinds everything.
+     */
+    @VisibleForTesting
+    View done(Activity activity) {
+        return done(activity, true /* rebindActions */);
     }
 
     private void bindButton(ImageButton button, @ActionType int action) {
@@ -328,7 +317,7 @@
     }
 
     private void setText(@IdRes int id, CharSequence text) {
-        TextView textView = (TextView) mAppHeader.findViewById(id);
+        TextView textView = mAppHeader.findViewById(id);
         if (textView != null) {
             textView.setText(text);
             textView.setVisibility(TextUtils.isEmpty(text) ? View.GONE : View.VISIBLE);
diff --git a/src/com/android/settings/applications/AppInfoWithHeader.java b/src/com/android/settings/applications/AppInfoWithHeader.java
index 768a726..2c9599b 100644
--- a/src/com/android/settings/applications/AppInfoWithHeader.java
+++ b/src/com/android/settings/applications/AppInfoWithHeader.java
@@ -16,6 +16,8 @@
 
 package com.android.settings.applications;
 
+import static com.android.settings.applications.AppHeaderController.ActionType;
+
 import android.app.Activity;
 import android.os.Bundle;
 import android.support.v7.preference.Preference;
@@ -24,8 +26,6 @@
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settingslib.applications.AppUtils;
 
-import static com.android.settings.applications.AppHeaderController.ActionType;
-
 public abstract class AppInfoWithHeader extends AppInfoBase {
 
     private boolean mCreated;
@@ -41,16 +41,16 @@
         if (mPackageInfo == null) return;
         final Activity activity = getActivity();
         final Preference pref = FeatureFactory.getFactory(activity)
-            .getApplicationFeatureProvider(activity)
-            .newAppHeaderController(this, null /* appHeader */)
-            .setIcon(mPackageInfo.applicationInfo.loadIcon(mPm))
-            .setLabel(mPackageInfo.applicationInfo.loadLabel(mPm))
-            .setSummary(mPackageInfo)
-            .setIsInstantApp(AppUtils.isInstant(mPackageInfo.applicationInfo))
-            .setPackageName(mPackageName)
-            .setUid(mPackageInfo.applicationInfo.uid)
-            .setButtonActions(ActionType.ACTION_APP_INFO, ActionType.ACTION_NONE)
-            .done(getPrefContext());
+                .getApplicationFeatureProvider(activity)
+                .newAppHeaderController(this, null /* appHeader */)
+                .setIcon(mPackageInfo.applicationInfo.loadIcon(mPm))
+                .setLabel(mPackageInfo.applicationInfo.loadLabel(mPm))
+                .setSummary(mPackageInfo)
+                .setIsInstantApp(AppUtils.isInstant(mPackageInfo.applicationInfo))
+                .setPackageName(mPackageName)
+                .setUid(mPackageInfo.applicationInfo.uid)
+                .setButtonActions(ActionType.ACTION_APP_INFO, ActionType.ACTION_NONE)
+                .done(activity, getPrefContext());
         getPreferenceScreen().addPreference(pref);
     }
 }
diff --git a/src/com/android/settings/applications/AppStorageSettings.java b/src/com/android/settings/applications/AppStorageSettings.java
index 8d41558..0676f56 100644
--- a/src/com/android/settings/applications/AppStorageSettings.java
+++ b/src/com/android/settings/applications/AppStorageSettings.java
@@ -90,13 +90,10 @@
 
     private static final String KEY_TOTAL_SIZE = "total_size";
     private static final String KEY_APP_SIZE = "app_size";
-    private static final String KEY_EXTERNAL_CODE_SIZE = "external_code_size";
     private static final String KEY_DATA_SIZE = "data_size";
-    private static final String KEY_EXTERNAL_DATA_SIZE = "external_data_size";
     private static final String KEY_CACHE_SIZE = "cache_size";
 
-    private static final String KEY_CLEAR_DATA = "clear_data_button";
-    private static final String KEY_CLEAR_CACHE = "clear_cache_button";
+    private static final String KEY_HEADER_BUTTONS = "header_view";
 
     private static final String KEY_URI_CATEGORY = "uri_category";
     private static final String KEY_CLEAR_URI = "clear_uri_button";
@@ -119,16 +116,11 @@
     private boolean mCanClearData = true;
     private boolean mCacheCleared;
 
-    private AppStorageStats mLastResult;
     private AppStorageSizesController mSizeController;
 
     private ClearCacheObserver mClearCacheObserver;
     private ClearUserDataObserver mClearDataObserver;
 
-    // Resource strings
-    private CharSequence mInvalidSizeStr;
-    private CharSequence mComputingStr;
-
     private VolumeInfo[] mCandidates;
     private AlertDialog.Builder mDialogBuilder;
     private ApplicationInfo mInfo;
@@ -158,9 +150,6 @@
     }
 
     private void setupViews() {
-        mComputingStr = getActivity().getText(R.string.computing_size);
-        mInvalidSizeStr = getActivity().getText(R.string.invalid_size_value);
-
         // Set default values on sizes
         mSizeController = new AppStorageSizesController.Builder()
                 .setTotalSizePreference(findPreference(KEY_TOTAL_SIZE))
@@ -171,8 +160,8 @@
                 .setErrorString(R.string.invalid_size_value)
                 .build();
 
-        mClearDataButton = (Button) ((LayoutPreference) findPreference(KEY_CLEAR_DATA))
-                .findViewById(R.id.button);
+        mClearDataButton = (Button) ((LayoutPreference) findPreference(KEY_HEADER_BUTTONS))
+                .findViewById(R.id.left_button);
 
         mStorageUsed = findPreference(KEY_STORAGE_USED);
         mChangeStorageButton = (Button) ((LayoutPreference) findPreference(KEY_CHANGE_STORAGE))
@@ -182,8 +171,8 @@
 
         // Cache section
         mCacheSize = findPreference(KEY_CACHE_SIZE);
-        mClearCacheButton = (Button) ((LayoutPreference) findPreference(KEY_CLEAR_CACHE))
-                .findViewById(R.id.button);
+        mClearCacheButton = (Button) ((LayoutPreference) findPreference(KEY_HEADER_BUTTONS))
+                .findViewById(R.id.right_button);
         mClearCacheButton.setText(R.string.clear_cache_btn_text);
 
         // URI permissions section
@@ -267,7 +256,7 @@
         if (mAppEntry == null) {
             return false;
         }
-        updateUiWithSize(mLastResult);
+        updateUiWithSize(mSizeController.getLastResult());
         refreshGrantedUriPermissions();
 
         final VolumeInfo currentVol = getActivity().getPackageManager()
diff --git a/src/com/android/settings/applications/AppStorageSizesController.java b/src/com/android/settings/applications/AppStorageSizesController.java
index 94935bd..23a3eb2 100644
--- a/src/com/android/settings/applications/AppStorageSizesController.java
+++ b/src/com/android/settings/applications/AppStorageSizesController.java
@@ -110,6 +110,13 @@
         mCachedCleared = isCleared;
     }
 
+    /**
+     * Returns the last result calculated, if it exists. If it does not, returns null.
+     */
+    public StorageStatsSource.AppStorageStats getLastResult() {
+        return mLastResult;
+    }
+
     private String getSizeStr(Context context, long size) {
         return Formatter.formatFileSize(context, size);
     }
diff --git a/src/com/android/settings/applications/FetchPackageStorageAsyncLoader.java b/src/com/android/settings/applications/FetchPackageStorageAsyncLoader.java
index 97e5b7b..b39ec3b 100644
--- a/src/com/android/settings/applications/FetchPackageStorageAsyncLoader.java
+++ b/src/com/android/settings/applications/FetchPackageStorageAsyncLoader.java
@@ -19,6 +19,7 @@
 import android.annotation.NonNull;
 import android.content.Context;
 import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
 import android.os.UserHandle;
 import android.util.Log;
 
@@ -27,6 +28,8 @@
 import com.android.settingslib.applications.StorageStatsSource;
 import com.android.settingslib.applications.StorageStatsSource.AppStorageStats;
 
+import java.io.IOException;
+
 /**
  * Fetches the storage stats using the StorageStatsManager for a given package and user tuple.
  */
@@ -49,7 +52,7 @@
         AppStorageStats result = null;
         try {
             result = mSource.getStatsForPackage(mInfo.volumeUuid, mInfo.packageName, mUser);
-        } catch (IllegalStateException e) {
+        } catch (NameNotFoundException | IOException e) {
             Log.w(TAG, "Package may have been removed during query, failing gracefully", e);
         }
         return result;
diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java
index 2fcecd8..09771f2 100755
--- a/src/com/android/settings/applications/InstalledAppDetails.java
+++ b/src/com/android/settings/applications/InstalledAppDetails.java
@@ -16,6 +16,8 @@
 
 package com.android.settings.applications;
 
+import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+
 import android.Manifest.permission;
 import android.app.Activity;
 import android.app.ActivityManager;
@@ -112,8 +114,7 @@
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
-
-import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+import java.util.Set;
 
 /**
  * Activity to display application information from Settings. This activity presents
@@ -158,6 +159,8 @@
     private static final String KEY_BATTERY = "battery";
     private static final String KEY_MEMORY = "memory";
     private static final String KEY_VERSION = "app_version";
+    private static final String KEY_INSTANT_APP_SUPPORTED_LINKS =
+            "instant_app_launch_supported_domain_urls";
 
     private final HashSet<String> mHomePackages = new HashSet<>();
 
@@ -175,6 +178,7 @@
     private Preference mDataPreference;
     private Preference mMemoryPreference;
     private Preference mVersionPreference;
+    private AppDomainsPreference mInstantAppDomainsPreference;
 
     private boolean mDisableAfterUninstall;
 
@@ -408,12 +412,13 @@
         mHeader = (LayoutPreference) findPreference(KEY_HEADER);
         mActionButtons = (LayoutPreference) findPreference(KEY_ACTION_BUTTONS);
         FeatureFactory.getFactory(activity)
-            .getApplicationFeatureProvider(activity)
-            .newAppHeaderController(this, mHeader.findViewById(R.id.app_snippet))
-            .setPackageName(mPackageName)
-            .setButtonActions(AppHeaderController.ActionType.ACTION_STORE_DEEP_LINK,
-                AppHeaderController.ActionType.ACTION_APP_PREFERENCE)
-            .bindAppHeaderButtons();
+                .getApplicationFeatureProvider(activity)
+                .newAppHeaderController(this, mHeader.findViewById(R.id.app_snippet))
+                .setPackageName(mPackageName)
+                .setButtonActions(AppHeaderController.ActionType.ACTION_STORE_DEEP_LINK,
+                        AppHeaderController.ActionType.ACTION_APP_PREFERENCE)
+                .styleActionBar(activity)
+                .bindAppHeaderButtons();
         prepareUninstallAndStop();
 
         mNotificationPreference = findPreference(KEY_NOTIFICATION);
@@ -432,7 +437,8 @@
         mMemoryPreference = findPreference(KEY_MEMORY);
         mMemoryPreference.setOnPreferenceClickListener(this);
         mVersionPreference = findPreference(KEY_VERSION);
-
+        mInstantAppDomainsPreference =
+                (AppDomainsPreference) findPreference(KEY_INSTANT_APP_SUPPORTED_LINKS);
         mLaunchPreference = findPreference(KEY_LAUNCH);
         if (mAppEntry != null && mAppEntry.info != null) {
             if ((mAppEntry.info.flags&ApplicationInfo.FLAG_INSTALLED) == 0 ||
@@ -550,6 +556,25 @@
     public void onLoaderReset(Loader<AppStorageStats> loader) {
     }
 
+    /**
+     * Utility method to hide and show specific preferences based on whether the app being displayed
+     * is an Instant App or an installed app.
+     */
+    @VisibleForTesting
+    void prepareInstantAppPrefs() {
+        final boolean isInstant = AppUtils.isInstant(mPackageInfo.applicationInfo);
+        if (isInstant) {
+            Set<String> handledDomainSet = Utils.getHandledDomains(mPm, mPackageInfo.packageName);
+            String[] handledDomains = handledDomainSet.toArray(new String[handledDomainSet.size()]);
+            mInstantAppDomainsPreference.setTitles(handledDomains);
+            // Dummy values, unused in the implementation
+            mInstantAppDomainsPreference.setValues(new int[handledDomains.length]);
+            getPreferenceScreen().removePreference(mLaunchPreference);
+        } else {
+            getPreferenceScreen().removePreference(mInstantAppDomainsPreference);
+        }
+    }
+
     // Utility method to set application label and icon.
     private void setAppLabelAndIcon(PackageInfo pkgInfo) {
         final View appSnippet = mHeader.findViewById(R.id.app_snippet);
@@ -565,7 +590,7 @@
             .setIcon(mAppEntry)
             .setSummary(summary)
             .setIsInstantApp(isInstantApp)
-            .done(false /* rebindActions */);
+            .done(activity, false /* rebindActions */);
         mVersionPreference.setSummary(getString(R.string.version_text, pkgInfo.versionName));
     }
 
@@ -641,6 +666,7 @@
         checkForceStop();
         setAppLabelAndIcon(mPackageInfo);
         initUninstallButtons();
+        prepareInstantAppPrefs();
 
         // Update the preference summaries.
         Activity context = getActivity();
@@ -1114,13 +1140,16 @@
         if (installerLabel == null) {
             return;
         }
+        final int detailsStringId = AppUtils.isInstant(mPackageInfo.applicationInfo)
+                ? R.string.instant_app_details_summary
+                : R.string.app_install_details_summary;
         PreferenceCategory category = new PreferenceCategory(getPrefContext());
         category.setTitle(R.string.app_install_details_group_title);
         screen.addPreference(category);
         Preference pref = new Preference(getPrefContext());
         pref.setTitle(R.string.app_install_details_title);
         pref.setKey("app_info_store");
-        pref.setSummary(getString(R.string.app_install_details_summary, installerLabel));
+        pref.setSummary(getString(detailsStringId, installerLabel));
 
         Intent intent =
                 AppStoreUtil.getAppStoreLink(getContext(), installerPackageName, mPackageName);
diff --git a/src/com/android/settings/applications/ManageApplications.java b/src/com/android/settings/applications/ManageApplications.java
index 0c28461..3cc40151 100644
--- a/src/com/android/settings/applications/ManageApplications.java
+++ b/src/com/android/settings/applications/ManageApplications.java
@@ -63,6 +63,7 @@
 import com.android.settings.Settings.GamesStorageActivity;
 import com.android.settings.Settings.HighPowerApplicationsActivity;
 import com.android.settings.Settings.ManageExternalSourcesActivity;
+import com.android.settings.Settings.MoviesStorageActivity;
 import com.android.settings.Settings.NotificationAppListActivity;
 import com.android.settings.Settings.OverlaySettingsActivity;
 import com.android.settings.Settings.StorageUseActivity;
@@ -256,6 +257,7 @@
     public static final int LIST_TYPE_WRITE_SETTINGS = 7;
     public static final int LIST_TYPE_MANAGE_SOURCES = 8;
     public static final int LIST_TYPE_GAMES = 9;
+    public static final int LIST_TYPE_MOVIES = 10;
 
 
     // List types that should show instant apps.
@@ -316,6 +318,9 @@
         } else if (className.equals(GamesStorageActivity.class.getName())) {
             mListType = LIST_TYPE_GAMES;
             mSortOrder = R.id.sort_order_size;
+        } else if (className.equals(MoviesStorageActivity.class.getName())) {
+            mListType = LIST_TYPE_MOVIES;
+            mSortOrder = R.id.sort_order_size;
         } else {
             mListType = LIST_TYPE_MAIN;
         }
@@ -424,6 +429,8 @@
         }
         if (mListType == LIST_TYPE_GAMES) {
             mApplications.setOverrideFilter(ApplicationsState.FILTER_GAMES);
+        } else if (mListType == LIST_TYPE_MOVIES) {
+            mApplications.setOverrideFilter(ApplicationsState.FILTER_MOVIES);
         }
     }
 
@@ -450,6 +457,7 @@
             case LIST_TYPE_NOTIFICATION:
             case LIST_TYPE_STORAGE:
             case LIST_TYPE_GAMES:
+            case LIST_TYPE_MOVIES:
                 return mSortOrder == R.id.sort_order_alpha;
             default:
                 return false;
@@ -470,6 +478,8 @@
                 return MetricsEvent.APPLICATIONS_STORAGE_APPS;
             case LIST_TYPE_GAMES:
                 return MetricsEvent.APPLICATIONS_STORAGE_GAMES;
+            case LIST_TYPE_MOVIES:
+                return MetricsEvent.APPLICATIONS_STORAGE_MOVIES;
             case LIST_TYPE_USAGE_ACCESS:
                 return MetricsEvent.USAGE_ACCESS;
             case LIST_TYPE_HIGH_POWER:
@@ -577,6 +587,9 @@
             case LIST_TYPE_GAMES:
                 startAppInfoFragment(AppStorageSettings.class, R.string.game_storage_settings);
                 break;
+            case LIST_TYPE_MOVIES:
+                startAppInfoFragment(AppStorageSettings.class, R.string.storage_movies_tv);
+                break;
             // TODO: Figure out if there is a way where we can spin up the profile's settings
             // process ahead of time, to avoid a long load of data when user clicks on a managed app.
             // Maybe when they load the list of apps that contains managed profile apps.
diff --git a/src/com/android/settings/applications/MusicViewHolderController.java b/src/com/android/settings/applications/MusicViewHolderController.java
index 4599fcc..1bca26a 100644
--- a/src/com/android/settings/applications/MusicViewHolderController.java
+++ b/src/com/android/settings/applications/MusicViewHolderController.java
@@ -23,15 +23,20 @@
 import android.provider.DocumentsContract;
 import android.support.annotation.WorkerThread;
 import android.text.format.Formatter;
+import android.util.Log;
 
 import com.android.settings.R;
 import com.android.settings.Utils;
 import com.android.settingslib.applications.StorageStatsSource;
 
+import java.io.IOException;
+
 /**
  * MusicViewHolderController controls an Audio/Music file view in the ManageApplications view.
  */
 public class MusicViewHolderController implements FileViewHolderController {
+    private static final String TAG = "MusicViewHolderController";
+
     private static final String AUTHORITY_MEDIA = "com.android.providers.media.documents";
 
     private Context mContext;
@@ -51,7 +56,12 @@
     @Override
     @WorkerThread
     public void queryStats() {
-        mMusicSize = mSource.getExternalStorageStats(mVolumeUuid, mUser).audioBytes;
+        try {
+            mMusicSize = mSource.getExternalStorageStats(mVolumeUuid, mUser).audioBytes;
+        } catch (IOException e) {
+            mMusicSize = 0;
+            Log.w(TAG, e);
+        }
     }
 
     @Override
@@ -61,7 +71,7 @@
 
     @Override
     public void setupView(AppViewHolder holder) {
-        holder.appIcon.setImageDrawable(mContext.getDrawable(R.drawable.empty_icon));
+        holder.appIcon.setImageDrawable(mContext.getDrawable(R.drawable.ic_media_stream_on_24dp));
         holder.appName.setText(mContext.getText(R.string.audio_files_title));
         holder.summary.setText(Formatter.formatFileSize(mContext, mMusicSize));
     }
diff --git a/src/com/android/settings/applications/ProcessStatsDetail.java b/src/com/android/settings/applications/ProcessStatsDetail.java
index 9b6f41e..c23da04 100644
--- a/src/com/android/settings/applications/ProcessStatsDetail.java
+++ b/src/com/android/settings/applications/ProcessStatsDetail.java
@@ -16,6 +16,8 @@
 
 package com.android.settings.applications;
 
+import static com.android.settings.applications.AppHeaderController.ActionType;
+
 import android.app.Activity;
 import android.app.ActivityManager;
 import android.app.ActivityManager.RunningServiceInfo;
@@ -58,8 +60,6 @@
 import java.util.HashMap;
 import java.util.List;
 
-import static com.android.settings.applications.AppHeaderController.ActionType;
-
 public class ProcessStatsDetail extends SettingsPreferenceFragment {
 
     private static final String TAG = "ProcessStatsDetail";
@@ -137,7 +137,7 @@
                 ? mApp.mUiTargetApp.uid
                 : UserHandle.USER_NULL)
             .setButtonActions(ActionType.ACTION_APP_INFO, ActionType.ACTION_NONE)
-            .done(getPrefContext());
+            .done(activity, getPrefContext());
         getPreferenceScreen().addPreference(pref);
     }
 
diff --git a/src/com/android/settings/applications/SpecialAppAccessPreferenceController.java b/src/com/android/settings/applications/SpecialAppAccessPreferenceController.java
new file mode 100644
index 0000000..5b05602
--- /dev/null
+++ b/src/com/android/settings/applications/SpecialAppAccessPreferenceController.java
@@ -0,0 +1,49 @@
+/*
+ * 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 android.content.Context;
+import android.support.v7.preference.Preference;
+import com.android.settings.R;
+import com.android.settings.core.PreferenceController;
+import com.android.settings.datausage.DataSaverBackend;
+
+public class SpecialAppAccessPreferenceController extends PreferenceController {
+
+    private static final String KEY_SPECIAL_ACCESS = "special_access";
+
+    private DataSaverBackend mDataSaverBackend;
+
+    public SpecialAppAccessPreferenceController(Context context) {
+        super(context);
+        mDataSaverBackend = new DataSaverBackend(context);
+    }
+
+    @Override
+    public boolean isAvailable() {
+        return true;
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return KEY_SPECIAL_ACCESS;
+    }
+
+    @Override
+    public void updateState(Preference preference) {
+        final int count = mDataSaverBackend.getWhitelistedCount();
+        preference.setSummary(mContext.getResources().getQuantityString(
+            R.plurals.special_access_summary, count, count));
+    }
+}
diff --git a/src/com/android/settings/applications/assist/DefaultAssistPreferenceController.java b/src/com/android/settings/applications/assist/DefaultAssistPreferenceController.java
index 747ce4d..b8d6a87 100644
--- a/src/com/android/settings/applications/assist/DefaultAssistPreferenceController.java
+++ b/src/com/android/settings/applications/assist/DefaultAssistPreferenceController.java
@@ -24,6 +24,7 @@
 import android.service.voice.VoiceInteractionService;
 import android.service.voice.VoiceInteractionServiceInfo;
 
+import android.support.annotation.VisibleForTesting;
 import com.android.internal.app.AssistUtils;
 import com.android.settings.applications.defaultapps.DefaultAppInfo;
 import com.android.settings.applications.defaultapps.DefaultAppPreferenceController;
@@ -56,13 +57,10 @@
         if (services == null || services.isEmpty()) {
             return null;
         }
-        final ResolveInfo resolveInfo = services.get(0);
-        final VoiceInteractionServiceInfo voiceInfo =
-                new VoiceInteractionServiceInfo(pm, resolveInfo.serviceInfo);
-        if (!voiceInfo.getSupportsAssist()) {
+        final String activity = getAssistSettingsActivity(cn, services.get(0), pm);
+        if (activity == null) {
             return null;
         }
-        final String activity = voiceInfo.getSettingsActivity();
         return new Intent(Intent.ACTION_MAIN)
                 .setComponent(new ComponentName(cn.getPackageName(), activity));
     }
@@ -85,4 +83,14 @@
         }
         return new DefaultAppInfo(mPackageManager, mUserId, cn);
     }
+
+    @VisibleForTesting
+    String getAssistSettingsActivity(ComponentName cn, ResolveInfo resolveInfo, PackageManager pm) {
+        final VoiceInteractionServiceInfo voiceInfo =
+            new VoiceInteractionServiceInfo(pm, resolveInfo.serviceInfo);
+        if (!voiceInfo.getSupportsAssist()) {
+            return null;
+        }
+        return voiceInfo.getSettingsActivity();
+    }
 }
diff --git a/src/com/android/settings/dashboard/DashboardFragmentRegistry.java b/src/com/android/settings/dashboard/DashboardFragmentRegistry.java
index c65c316..dddfb1b 100644
--- a/src/com/android/settings/dashboard/DashboardFragmentRegistry.java
+++ b/src/com/android/settings/dashboard/DashboardFragmentRegistry.java
@@ -30,6 +30,7 @@
 import com.android.settings.fuelgauge.PowerUsageSummary;
 import com.android.settings.language.LanguageAndInputSettings;
 import com.android.settings.network.NetworkDashboardFragment;
+import com.android.settings.notification.ConfigureNotificationSettings;
 import com.android.settings.notification.SoundSettings;
 import com.android.settings.system.SystemDashboardFragment;
 import com.android.settingslib.drawer.CategoryKey;
@@ -83,6 +84,8 @@
                 CategoryKey.CATEGORY_SYSTEM_LANGUAGE);
         PARENT_TO_CATEGORY_KEY_MAP.put(DevelopmentSettings.class.getName(),
                 CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT);
+        PARENT_TO_CATEGORY_KEY_MAP.put(ConfigureNotificationSettings.class.getName(),
+                CategoryKey.CATEGORY_NOTIFICATIONS);
 
         CATEGORY_KEY_TO_PARENT_MAP = new ArrayMap<>(PARENT_TO_CATEGORY_KEY_MAP.size());
 
diff --git a/src/com/android/settings/datausage/AppDataUsage.java b/src/com/android/settings/datausage/AppDataUsage.java
index 0431ce5..e98ca20 100644
--- a/src/com/android/settings/datausage/AppDataUsage.java
+++ b/src/com/android/settings/datausage/AppDataUsage.java
@@ -14,6 +14,8 @@
 
 package com.android.settings.datausage;
 
+import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
+
 import android.app.Activity;
 import android.app.LoaderManager;
 import android.content.Context;
@@ -57,8 +59,6 @@
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 
-import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
-
 public class AppDataUsage extends DataUsageBase implements Preference.OnPreferenceChangeListener,
         DataSaverBackend.Listener {
 
@@ -362,7 +362,7 @@
             .setUid(uid)
             .setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
                 AppHeaderController.ActionType.ACTION_NONE)
-            .done(getPrefContext());
+            .done(activity, getPrefContext());
         getPreferenceScreen().addPreference(pref);
     }
 
diff --git a/src/com/android/settings/development/DevelopmentSettings.java b/src/com/android/settings/development/DevelopmentSettings.java
index 3deedaf..bfb9f0f 100644
--- a/src/com/android/settings/development/DevelopmentSettings.java
+++ b/src/com/android/settings/development/DevelopmentSettings.java
@@ -28,6 +28,7 @@
 import android.bluetooth.BluetoothAdapter;
 import android.bluetooth.BluetoothCodecConfig;
 import android.bluetooth.BluetoothCodecStatus;
+import android.bluetooth.BluetoothHeadset;
 import android.bluetooth.BluetoothProfile;
 import android.content.BroadcastReceiver;
 import android.content.ContentResolver;
@@ -205,7 +206,10 @@
             "persist.bluetooth.disableabsvol";
     private static final String BLUETOOTH_AVRCP_VERSION_PROPERTY =
                                     "persist.bluetooth.avrcpversion";
+    private static final String BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY =
+                                    "persist.bluetooth.enableinbandringing";
 
+    private static final String BLUETOOTH_ENABLE_INBAND_RINGING_KEY = "bluetooth_enable_inband_ringing";
     private static final String BLUETOOTH_SELECT_AVRCP_VERSION_KEY = "bluetooth_select_avrcp_version";
     private static final String BLUETOOTH_SELECT_A2DP_CODEC_KEY = "bluetooth_select_a2dp_codec";
     private static final String BLUETOOTH_SELECT_A2DP_SAMPLE_RATE_KEY = "bluetooth_select_a2dp_sample_rate";
@@ -278,6 +282,7 @@
     private SwitchPreference mWifiAggressiveHandover;
     private SwitchPreference mMobileDataAlwaysOn;
     private SwitchPreference mBluetoothDisableAbsVolume;
+    private SwitchPreference mBluetoothEnableInbandRinging;
 
     private BluetoothA2dp mBluetoothA2dp;
     private final Object mBluetoothA2dpLock = new Object();
@@ -494,6 +499,11 @@
         mUsbConfiguration = addListPreference(USB_CONFIGURATION_KEY);
         mWebViewMultiprocess = findAndInitSwitchPref(WEBVIEW_MULTIPROCESS_KEY);
         mBluetoothDisableAbsVolume = findAndInitSwitchPref(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY);
+        mBluetoothEnableInbandRinging = findAndInitSwitchPref(BLUETOOTH_ENABLE_INBAND_RINGING_KEY);
+        if (!BluetoothHeadset.isInbandRingingSupported(getContext())) {
+            removePreference(mBluetoothEnableInbandRinging);
+            mBluetoothEnableInbandRinging = null;
+        }
 
         mBluetoothSelectAvrcpVersion = addListPreference(BLUETOOTH_SELECT_AVRCP_VERSION_KEY);
         mBluetoothSelectA2dpCodec = addListPreference(BLUETOOTH_SELECT_A2DP_CODEC_KEY);
@@ -810,6 +820,7 @@
             updateColorTemperature();
         }
         updateBluetoothDisableAbsVolumeOptions();
+        updateBluetoothEnableInbandRingingOptions();
         updateBluetoothA2dpConfigurationValues();
     }
 
@@ -1503,6 +1514,20 @@
                 mBluetoothDisableAbsVolume.isChecked() ? "true" : "false");
     }
 
+    private void updateBluetoothEnableInbandRingingOptions() {
+        if (mBluetoothEnableInbandRinging != null) {
+            updateSwitchPreference(mBluetoothEnableInbandRinging,
+                SystemProperties.getBoolean(BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY, false));
+        }
+    }
+
+    private void writeBluetoothEnableInbandRingingOptions() {
+        if (mBluetoothEnableInbandRinging != null) {
+            SystemProperties.set(BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY,
+                mBluetoothEnableInbandRinging.isChecked() ? "true" : "false");
+        }
+    }
+
     private void updateMobileDataAlwaysOnOptions() {
         updateSwitchPreference(mMobileDataAlwaysOn, Settings.Global.getInt(
                 getActivity().getContentResolver(),
@@ -2524,6 +2549,8 @@
             writeForceResizableOptions();
         } else if (preference == mBluetoothDisableAbsVolume) {
             writeBluetoothDisableAbsVolumeOptions();
+        } else if (preference == mBluetoothEnableInbandRinging) {
+            writeBluetoothEnableInbandRingingOptions();
         } else if (preference == mWebViewMultiprocess) {
             writeWebViewMultiprocessOptions();
         } else if (SHORTCUT_MANAGER_RESET_KEY.equals(preference.getKey())) {
diff --git a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
index b5d7ddf..10df004 100644
--- a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
+++ b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
@@ -59,7 +59,6 @@
 import com.android.settings.Utils;
 import com.android.settings.applications.ManageApplications;
 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
-import com.android.settings.deletionhelper.AutomaticStorageManagerSettings;
 import com.android.settings.deviceinfo.StorageSettings.MountTask;
 import com.android.settingslib.deviceinfo.StorageMeasurement;
 import com.android.settingslib.deviceinfo.StorageMeasurement.MeasurementDetails;
@@ -126,7 +125,6 @@
     private int mItemPoolIndex;
 
     private Preference mExplore;
-    private Preference mAutomaticStorageManagement;
 
     private boolean mNeedsUpdate;
 
@@ -185,7 +183,6 @@
         mCurrentUser = mUserManager.getUserInfo(UserHandle.myUserId());
 
         mExplore = buildAction(R.string.storage_menu_explore);
-        mAutomaticStorageManagement = buildAction(R.string.storage_menu_manage);
 
         mNeedsUpdate = true;
 
@@ -212,9 +209,6 @@
 
         screen.removeAll();
 
-        if (getResources().getBoolean(R.bool.config_storage_manager_settings_enabled)) {
-            addPreference(screen, mAutomaticStorageManagement);
-        }
         addPreference(screen, mSummary);
 
         List<UserInfo> allUsers = mUserManager.getUsers();
@@ -331,6 +325,7 @@
 
     private StorageItemPreference buildItem() {
         final StorageItemPreference item = new StorageItemPreference(getPrefContext());
+        item.setIcon(R.drawable.empty_icon);
         return item;
     }
 
@@ -511,11 +506,6 @@
             case R.string.storage_menu_explore: {
                 intent = mSharedVolume.buildBrowseIntent();
             } break;
-            case R.string.storage_menu_manage: {
-                startFragment(this, AutomaticStorageManagerSettings.class.getCanonicalName(),
-                        R.string.automatic_storage_manager_settings, 0, null);
-                return true;
-            }
             case 0: {
                 UserInfoFragment.show(this, pref.getTitle(), pref.getSummary());
                 return true;
diff --git a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
index 602e65f..f7bb95d 100644
--- a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
+++ b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
@@ -16,6 +16,7 @@
 
 package com.android.settings.deviceinfo;
 
+import android.app.Activity;
 import android.app.LoaderManager;
 import android.content.Context;
 import android.content.Intent;
@@ -78,16 +79,15 @@
         super.onCreate(icicle);
 
         // Initialize the storage sizes that we can quickly calc.
-        final Context context = getActivity();
-        StorageManager sm = context.getSystemService(StorageManager.class);
+        final Activity activity = getActivity();
+        StorageManager sm = activity.getSystemService(StorageManager.class);
         mVolume = Utils.maybeInitializeVolume(sm, getArguments());
         if (mVolume == null) {
-            getActivity().finish();
+            activity.finish();
             return;
         }
 
-        mOptionMenuController = new PrivateVolumeOptionMenuController(
-                context, mVolume, new PackageManagerWrapperImpl(context.getPackageManager()));
+        initializeOptionsMenu(activity);
 
         final long sharedDataSize = mVolume.getPath().getTotalSpace();
         long totalSize = sm.getPrimaryStorageSize();
@@ -114,10 +114,19 @@
         }
     }
 
+    @VisibleForTesting
+    void initializeOptionsMenu(Activity activity) {
+        mOptionMenuController = new PrivateVolumeOptionMenuController(
+                activity, mVolume, new PackageManagerWrapperImpl(activity.getPackageManager()));
+        getLifecycle().addObserver(mOptionMenuController);
+        setHasOptionsMenu(true);
+        activity.invalidateOptionsMenu();
+    }
+
     @Override
     public void onResume() {
         super.onResume();
-        getLoaderManager().initLoader(STORAGE_JOB_ID, Bundle.EMPTY, this);
+        getLoaderManager().restartLoader(STORAGE_JOB_ID, Bundle.EMPTY, this);
         getLoaderManager().initLoader(ICON_JOB_ID, Bundle.EMPTY, new IconLoaderCallbacks());
     }
 
@@ -156,7 +165,6 @@
                 new AutomaticStorageManagementSwitchPreferenceController(
                         context, mMetricsFeatureProvider, getFragmentManager());
         getLifecycle().addObserver(asmController);
-        getLifecycle().addObserver(mOptionMenuController);
         controllers.add(asmController);
         return controllers;
     }
diff --git a/src/com/android/settings/deviceinfo/StorageProfileFragment.java b/src/com/android/settings/deviceinfo/StorageProfileFragment.java
index c5d1045..7e2d941 100644
--- a/src/com/android/settings/deviceinfo/StorageProfileFragment.java
+++ b/src/com/android/settings/deviceinfo/StorageProfileFragment.java
@@ -140,6 +140,7 @@
         // TODO(b/35927909): Attribute app sizes better than zeroing out for profiles.
         result.gamesSize = 0;
         result.musicAppsSize = 0;
+        result.videoAppsSize = 0;
         result.otherAppsSize = 0;
         return result;
     }
diff --git a/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java b/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
index ae5e5f1..8652804 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
@@ -18,10 +18,12 @@
 
 import static android.content.pm.ApplicationInfo.CATEGORY_AUDIO;
 import static android.content.pm.ApplicationInfo.CATEGORY_GAME;
+import static android.content.pm.ApplicationInfo.CATEGORY_VIDEO;
 
 import android.content.Context;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.UserInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
 import android.os.UserHandle;
 import android.util.Log;
 import android.util.SparseArray;
@@ -31,6 +33,7 @@
 import com.android.settings.utils.AsyncLoader;
 import com.android.settingslib.applications.StorageStatsSource;
 
+import java.io.IOException;
 import java.util.List;
 
 /**
@@ -78,8 +81,15 @@
         UserHandle myUser = UserHandle.of(userId);
         for (int i = 0, size = applicationInfos.size(); i < size; i++) {
             ApplicationInfo app = applicationInfos.get(i);
-            StorageStatsSource.AppStorageStats stats =
-                    mStatsManager.getStatsForPackage(mUuid, app.packageName, myUser);
+
+            StorageStatsSource.AppStorageStats stats;
+            try {
+                stats = mStatsManager.getStatsForPackage(mUuid, app.packageName, myUser);
+            } catch (NameNotFoundException | IOException e) {
+                // This may happen if the package was removed during our calculation.
+                Log.w("App unexpectedly not found", e);
+                continue;
+            }
 
             long attributedAppSizeInBytes = stats.getDataBytes();
             // This matches how the package manager calculates sizes -- by zeroing out code sizes of
@@ -99,6 +109,9 @@
                 case CATEGORY_AUDIO:
                     result.musicAppsSize += attributedAppSizeInBytes;
                     break;
+                case CATEGORY_VIDEO:
+                    result.videoAppsSize += attributedAppSizeInBytes;
+                    break;
                 default:
                     // The deprecated game flag does not set the category.
                     if ((app.flags & ApplicationInfo.FLAG_IS_GAME) != 0) {
@@ -111,7 +124,11 @@
         }
 
         Log.d(TAG, "Loading external stats");
-        result.externalStats = mStatsManager.getExternalStorageStats(mUuid, UserHandle.of(userId));
+        try {
+            result.externalStats = mStatsManager.getExternalStorageStats(mUuid, UserHandle.of(userId));
+        } catch (IOException e) {
+            Log.w(TAG, e);
+        }
         Log.d(TAG, "Obtaining result completed");
         return result;
     }
@@ -123,6 +140,7 @@
     public static class AppsStorageResult {
         public long gamesSize;
         public long musicAppsSize;
+        public long videoAppsSize;
         public long otherAppsSize;
         public long systemSize;
         public StorageStatsSource.ExternalStorageStats externalStats;
diff --git a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
index 5b27592..36694f0 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
@@ -65,6 +65,8 @@
     @VisibleForTesting
     static final String GAME_KEY = "pref_games";
     @VisibleForTesting
+    static final String MOVIES_KEY = "pref_movies";
+    @VisibleForTesting
     static final String OTHER_APPS_KEY = "pref_other_apps";
     @VisibleForTesting
     static final String SYSTEM_KEY = "pref_system";
@@ -82,6 +84,7 @@
     private StorageItemPreference mPhotoPreference;
     private StorageItemPreference mAudioPreference;
     private StorageItemPreference mGamePreference;
+    private StorageItemPreference mMoviesPreference;
     private StorageItemPreference mAppPreference;
     private StorageItemPreference mFilePreference;
     private StorageItemPreference mSystemPreference;
@@ -123,6 +126,9 @@
             case GAME_KEY:
                 intent = getGamesIntent();
                 break;
+            case MOVIES_KEY:
+                intent = getMoviesIntent();
+                break;
             case OTHER_APPS_KEY:
                 // Because we are likely constructed with a null volume, this is theoretically
                 // possible.
@@ -204,6 +210,7 @@
         mPhotoPreference = (StorageItemPreference) screen.findPreference(PHOTO_KEY);
         mAudioPreference = (StorageItemPreference) screen.findPreference(AUDIO_KEY);
         mGamePreference = (StorageItemPreference) screen.findPreference(GAME_KEY);
+        mMoviesPreference = (StorageItemPreference) screen.findPreference(MOVIES_KEY);
         mAppPreference = (StorageItemPreference) screen.findPreference(OTHER_APPS_KEY);
         mSystemPreference = (StorageItemPreference) screen.findPreference(SYSTEM_KEY);
         mFilePreference = (StorageItemPreference) screen.findPreference(FILES_KEY);
@@ -217,6 +224,7 @@
         mAudioPreference.setStorageSize(
                 data.musicAppsSize + data.externalStats.audioBytes, mTotalSize);
         mGamePreference.setStorageSize(data.gamesSize, mTotalSize);
+        mMoviesPreference.setStorageSize(data.videoAppsSize, mTotalSize);
         mAppPreference.setStorageSize(data.otherAppsSize, mTotalSize);
         if (mSystemPreference != null) {
             mSystemPreference.setStorageSize(mSystemSize + data.systemSize, mTotalSize);
@@ -243,6 +251,7 @@
         list.add(PHOTO_KEY);
         list.add(AUDIO_KEY);
         list.add(GAME_KEY);
+        list.add(MOVIES_KEY);
         list.add(OTHER_APPS_KEY);
         list.add(SYSTEM_KEY);
         list.add(FILES_KEY);
@@ -281,12 +290,21 @@
     }
 
     private Intent getGamesIntent() {
-            Bundle args = new Bundle(1);
-            args.putString(ManageApplications.EXTRA_CLASSNAME,
-                    Settings.GamesStorageActivity.class.getName());
-            return Utils.onBuildStartFragmentIntent(mContext,
-                    ManageApplications.class.getName(), args, null, R.string.game_storage_settings,
-                    null, false, mMetricsFeatureProvider.getMetricsCategory(mFragment));
+        Bundle args = new Bundle(1);
+        args.putString(ManageApplications.EXTRA_CLASSNAME,
+                Settings.GamesStorageActivity.class.getName());
+        return Utils.onBuildStartFragmentIntent(mContext,
+                ManageApplications.class.getName(), args, null, R.string.game_storage_settings,
+                null, false, mMetricsFeatureProvider.getMetricsCategory(mFragment));
+    }
+
+    private Intent getMoviesIntent() {
+        Bundle args = new Bundle(1);
+        args.putString(ManageApplications.EXTRA_CLASSNAME,
+                Settings.MoviesStorageActivity.class.getName());
+        return Utils.onBuildStartFragmentIntent(mContext,
+                ManageApplications.class.getName(), args, null, R.string.storage_movies_tv,
+                null, false, mMetricsFeatureProvider.getMetricsCategory(mFragment));
     }
 
     private Intent getFilesIntent() {
diff --git a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
index 2f8e28e..0c798a6 100644
--- a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
@@ -17,16 +17,12 @@
 package com.android.settings.fuelgauge;
 
 import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
 import android.app.admin.DevicePolicyManager;
 import android.content.Context;
-import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.os.BatteryStats;
 import android.os.Bundle;
-import android.os.SystemClock;
 import android.os.UserHandle;
 import android.os.UserManager;
 import android.support.annotation.VisibleForTesting;
@@ -179,7 +175,7 @@
     @VisibleForTesting
     void initHeader() {
         final View appSnippet = mHeaderPreference.findViewById(R.id.app_snippet);
-        final Context context = getContext();
+        final Activity context = getActivity();
         final Bundle bundle = getArguments();
         AppHeaderController controller = FeatureFactory.getFactory(context)
                 .getApplicationFeatureProvider(context)
@@ -203,7 +199,7 @@
             controller.setSummary(getString(Utils.getInstallationStatus(mAppEntry.info)));
         }
 
-        controller.done(true /* rebindActions */);
+        controller.done(context, true /* rebindActions */);
     }
 
     @Override
diff --git a/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceController.java b/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceController.java
index 463d4dc..60a94dd 100644
--- a/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceController.java
@@ -55,16 +55,14 @@
     public void updateState(Preference preference) {
         final int mode = mAppOpsManager
                 .checkOpNoThrow(AppOpsManager.OP_RUN_IN_BACKGROUND, mUid, mTargetPackage);
-
         if (mode == AppOpsManager.MODE_ERRORED) {
             preference.setEnabled(false);
-            preference.setSummary(R.string.background_activity_summary_disabled);
         } else {
             final boolean checked = mode != AppOpsManager.MODE_IGNORED;
             ((SwitchPreference) preference).setChecked(checked);
-            preference.setSummary(checked ? R.string.background_activity_summary_on
-                    : R.string.background_activity_summary_off);
         }
+
+        updateSummary(preference);
     }
 
     @Override
@@ -92,6 +90,8 @@
         boolean switchOn = (Boolean) newValue;
         mAppOpsManager.setMode(AppOpsManager.OP_RUN_IN_BACKGROUND, mUid, mTargetPackage,
                 switchOn ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_IGNORED);
+
+        updateSummary(preference);
         return true;
     }
 
@@ -113,4 +113,18 @@
 
         return false;
     }
+
+    @VisibleForTesting
+    void updateSummary(Preference preference) {
+        final int mode = mAppOpsManager
+                .checkOpNoThrow(AppOpsManager.OP_RUN_IN_BACKGROUND, mUid, mTargetPackage);
+
+        if (mode == AppOpsManager.MODE_ERRORED) {
+            preference.setSummary(R.string.background_activity_summary_disabled);
+        } else {
+            final boolean checked = mode != AppOpsManager.MODE_IGNORED;
+            preference.setSummary(checked ? R.string.background_activity_summary_on
+                    : R.string.background_activity_summary_off);
+        }
+    }
 }
diff --git a/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java b/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java
new file mode 100644
index 0000000..9d37333
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java
@@ -0,0 +1,87 @@
+/*
+ * 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.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.support.annotation.VisibleForTesting;
+
+import com.android.settings.Utils;
+
+/**
+ * Use this broadcastReceiver to listen to the battery change, and it will invoke
+ * {@link OnBatteryChangedListener} if any of the following happens:
+ *
+ * 1. Battery level has been changed
+ * 2. Battery status has been changed
+ */
+public class BatteryBroadcastReceiver extends BroadcastReceiver {
+
+    interface OnBatteryChangedListener {
+        void onBatteryChanged();
+    }
+
+    @VisibleForTesting
+    String mBatteryLevel;
+    @VisibleForTesting
+    String mBatteryStatus;
+    private OnBatteryChangedListener mBatteryListener;
+    private Context mContext;
+
+    public BatteryBroadcastReceiver(Context context) {
+        mContext = context;
+    }
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        String action = intent.getAction();
+        if (mBatteryListener != null && Intent.ACTION_BATTERY_CHANGED.equals(action)
+                && updateBatteryStatus(intent)) {
+            mBatteryListener.onBatteryChanged();
+        }
+    }
+
+    public void setBatteryChangedListener(OnBatteryChangedListener lsn) {
+        mBatteryListener = lsn;
+    }
+
+    public void register() {
+        mContext.registerReceiver(this,
+                new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
+    }
+
+    public void unRegister() {
+        mContext.unregisterReceiver(this);
+    }
+
+    private boolean updateBatteryStatus(Intent intent) {
+        if (intent != null) {
+            String batteryLevel = Utils.getBatteryPercentage(intent);
+            String batteryStatus = Utils.getBatteryStatus(
+                    mContext.getResources(), intent);
+            if (!batteryLevel.equals(mBatteryLevel) || !batteryStatus.equals(mBatteryStatus)) {
+                mBatteryLevel = batteryLevel;
+                mBatteryStatus = batteryStatus;
+                return true;
+            }
+        }
+        return false;
+    }
+
+}
\ No newline at end of file
diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java
index 7b89fb1..8588f77 100644
--- a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java
+++ b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java
@@ -511,7 +511,7 @@
                 elapsedRealtimeUs);
         mDrainString = "";
         mChargeDurationString = "";
-        setContentDescription(mInfo.mChargeLabelString);
+        setContentDescription(mInfo.chargeLabelString);
 
         int pos = 0;
         int lastInteresting = 0;
@@ -589,7 +589,7 @@
         mMaxPercentLabelStringWidth = (int)mTextPaint.measureText(mMaxPercentLabelString);
         mMinPercentLabelStringWidth = (int)mTextPaint.measureText(mMinPercentLabelString);
         mDrainStringWidth = (int)mHeaderTextPaint.measureText(mDrainString);
-        mChargeLabelStringWidth = (int)mHeaderTextPaint.measureText(mInfo.mChargeLabelString);
+        mChargeLabelStringWidth = (int)mHeaderTextPaint.measureText(mInfo.chargeLabelString);
         mChargeDurationStringWidth = (int)mHeaderTextPaint.measureText(mChargeDurationString);
         mTextAscent = (int)mTextPaint.ascent();
         mTextDescent = (int)mTextPaint.descent();
@@ -974,7 +974,7 @@
                         }
                     }
                 }
-                
+
                 i++;
             }
             mStats.finishIteratingHistoryLocked();
@@ -983,9 +983,9 @@
         if (lastY < 0 || lastX < 0) {
             // Didn't get any data...
             x = lastX = mLevelLeft;
-            y = lastY = mLevelTop + levelh - ((mInfo.mBatteryLevel-batLow)*(levelh-1))/batChange;
+            y = lastY = mLevelTop + levelh - ((mInfo.batteryLevel -batLow)*(levelh-1))/batChange;
             Path path;
-            byte value = (byte)mInfo.mBatteryLevel;
+            byte value = (byte)mInfo.batteryLevel;
             if (value <= mBatteryCriticalLevel) path = mBatCriticalPath;
             else if (value <= mBatteryWarnLevel) path = mBatWarnPath;
             else path = null; //mBatGoodPath;
@@ -1014,7 +1014,7 @@
             mTimeRemainPath.moveTo(x, lastY);
             int fullY = mLevelTop + levelh - ((100-batLow)*(levelh-1))/batChange;
             int emptyY = mLevelTop + levelh - ((0-batLow)*(levelh-1))/batChange;
-            if (mInfo.mDischarging) {
+            if (mInfo.discharging) {
                 mTimeRemainPath.lineTo(mLevelRight, emptyY);
             } else {
                 mTimeRemainPath.lineTo(mLevelRight, fullY);
@@ -1211,8 +1211,8 @@
 
         int headerTop = -mHeaderTextAscent + (mHeaderTextDescent-mHeaderTextAscent)/3;
         mHeaderTextPaint.setTextAlign(textAlignLeft);
-        if (DEBUG) Log.d(TAG, "Drawing charge label string: " + mInfo.mChargeLabelString);
-        canvas.drawText(mInfo.mChargeLabelString, textStartX, headerTop, mHeaderTextPaint);
+        if (DEBUG) Log.d(TAG, "Drawing charge label string: " + mInfo.chargeLabelString);
+        canvas.drawText(mInfo.chargeLabelString, textStartX, headerTop, mHeaderTextPaint);
         int stringHalfWidth = mChargeDurationStringWidth / 2;
         if (layoutRtl) stringHalfWidth = -stringHalfWidth;
         int headerCenter = ((width-mChargeDurationStringWidth-mDrainStringWidth)/2)
diff --git a/src/com/android/settings/fuelgauge/BatteryMeterView.java b/src/com/android/settings/fuelgauge/BatteryMeterView.java
index dcbf472..c450b90 100644
--- a/src/com/android/settings/fuelgauge/BatteryMeterView.java
+++ b/src/com/android/settings/fuelgauge/BatteryMeterView.java
@@ -18,17 +18,25 @@
 
 import android.annotation.Nullable;
 import android.content.Context;
+import android.graphics.Color;
+import android.graphics.ColorFilter;
 import android.graphics.PorterDuff;
 import android.graphics.PorterDuffColorFilter;
 import android.support.annotation.VisibleForTesting;
 import android.util.AttributeSet;
 import android.widget.ImageView;
+
 import com.android.settings.R;
 import com.android.settings.Utils;
 import com.android.settingslib.graph.BatteryMeterDrawableBase;
 
 public class BatteryMeterView extends ImageView {
-    private BatteryMeterDrawable mDrawable;
+    @VisibleForTesting
+    BatteryMeterDrawable mDrawable;
+    @VisibleForTesting
+    ColorFilter mErrorColorFilter;
+    @VisibleForTesting
+    ColorFilter mAccentColorFilter;
 
     public BatteryMeterView(Context context) {
         this(context, null, 0);
@@ -42,21 +50,30 @@
         super(context, attrs, defStyleAttr);
 
         final int frameColor = context.getColor(R.color.batterymeter_frame_color);
-        final int tintColor = Utils.getColorAttr(context, android.R.attr.colorAccent);
+        mAccentColorFilter = new PorterDuffColorFilter(
+                Utils.getColorAttr(context, android.R.attr.colorAccent), PorterDuff.Mode.SRC_IN);
+        mErrorColorFilter = new PorterDuffColorFilter(
+                context.getColor(R.color.battery_icon_color_error), PorterDuff.Mode.SRC_IN);
 
         mDrawable = new BatteryMeterDrawable(context, frameColor);
-        mDrawable.setColorFilter(new PorterDuffColorFilter(tintColor, PorterDuff.Mode.SRC_IN));
         mDrawable.setShowPercent(false);
+        mDrawable.setBatteryColorFilter(mAccentColorFilter);
+        mDrawable.setWarningColorFilter(
+                new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN));
         setImageDrawable(mDrawable);
     }
 
-    public void setBatteryInfo(int level) {
+    public void setBatteryLevel(int level) {
         mDrawable.setBatteryLevel(level);
+        if (level < mDrawable.getCriticalLevel()) {
+            mDrawable.setBatteryColorFilter(mErrorColorFilter);
+        } else {
+            mDrawable.setBatteryColorFilter(mAccentColorFilter);
+        }
     }
 
-    @VisibleForTesting
-    void setBatteryDrawable(BatteryMeterDrawable drawable) {
-        mDrawable = drawable;
+    public void setCharging(boolean charging) {
+        mDrawable.setCharging(charging);
     }
 
     public static class BatteryMeterDrawable extends BatteryMeterDrawableBase {
@@ -81,6 +98,16 @@
         public int getIntrinsicHeight() {
             return mIntrinsicHeight;
         }
+
+        public void setWarningColorFilter(@Nullable ColorFilter colorFilter) {
+            mWarningTextPaint.setColorFilter(colorFilter);
+        }
+
+        public void setBatteryColorFilter(@Nullable ColorFilter colorFilter) {
+            mFramePaint.setColorFilter(colorFilter);
+            mBatteryPaint.setColorFilter(colorFilter);
+            mBoltPaint.setColorFilter(colorFilter);
+        }
     }
 
 }
diff --git a/src/com/android/settings/fuelgauge/FakeUid.java b/src/com/android/settings/fuelgauge/FakeUid.java
index 770c567..8bb7d88 100644
--- a/src/com/android/settings/fuelgauge/FakeUid.java
+++ b/src/com/android/settings/fuelgauge/FakeUid.java
@@ -266,11 +266,6 @@
     }
 
     @Override
-    public long getCpuPowerMaUs(int which) {
-        return 0;
-    }
-
-    @Override
     public BatteryStats.ControllerActivityCounter getWifiControllerActivity() {
         return null;
     }
diff --git a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
index 3509834..a0ebba8 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
@@ -172,7 +172,7 @@
         mUsageListGroup.removeAll();
         for (int i = 0, size = dataList.size(); i < size; i++) {
             final PowerUsageData batteryData = dataList.get(i);
-            if (shouldHide(batteryData)) {
+            if (shouldHideCategory(batteryData)) {
                 continue;
             }
             final PowerGaugePreference pref = new PowerGaugePreference(getPrefContext());
@@ -217,7 +217,7 @@
     }
 
     @VisibleForTesting
-    boolean shouldHide(PowerUsageData powerUsageData) {
+    boolean shouldHideCategory(PowerUsageData powerUsageData) {
         if (powerUsageData.usageType == UsageType.UNACCOUNTED
                 || powerUsageData.usageType == UsageType.OVERCOUNTED) {
             return true;
@@ -264,6 +264,9 @@
 
     @VisibleForTesting
     void updateUsageDataSummary(PowerUsageData usageData, double totalPower, int dischargeAmount) {
+        if (shouldHideSummary(usageData)) {
+            return;
+        }
         if (usageData.usageList.size() <= 1) {
             usageData.summary = getString(R.string.battery_used_for,
                     Utils.formatElapsedTime(getContext(), usageData.totalUsageTimeMs, false));
@@ -278,6 +281,13 @@
     }
 
     @VisibleForTesting
+    boolean shouldHideSummary(PowerUsageData powerUsageData) {
+        @UsageType final int usageType = powerUsageData.usageType;
+
+        return usageType == UsageType.CELL;
+    }
+
+    @VisibleForTesting
     BatterySipper findBatterySipperWithMaxBatteryUsage(List<BatterySipper> usageList) {
         BatterySipper sipper = usageList.get(0);
         for (int i = 1, size = usageList.size(); i < size; i++) {
diff --git a/src/com/android/settings/fuelgauge/PowerUsageBase.java b/src/com/android/settings/fuelgauge/PowerUsageBase.java
index 0236a30..1d9a228 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageBase.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageBase.java
@@ -45,9 +45,7 @@
 
     protected BatteryStatsHelper mStatsHelper;
     protected UserManager mUm;
-
-    private String mBatteryLevel;
-    private String mBatteryStatus;
+    private BatteryBroadcastReceiver mBatteryBroadcastReceiver;
 
     @Override
     public void onAttach(Activity activity) {
@@ -61,6 +59,13 @@
         super.onCreate(icicle);
         mStatsHelper.create(icicle);
         setHasOptionsMenu(true);
+
+        mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(getContext());
+        mBatteryBroadcastReceiver.setBatteryChangedListener(() -> {
+            if (!mHandler.hasMessages(MSG_REFRESH_STATS)) {
+                mHandler.sendEmptyMessageDelayed(MSG_REFRESH_STATS, 500);
+            }
+        });
     }
 
     @Override
@@ -73,8 +78,7 @@
     public void onResume() {
         super.onResume();
         BatteryStatsHelper.dropFile(getActivity(), BatteryHistoryDetail.BATTERY_HISTORY_FILE);
-        updateBatteryStatus(getActivity().registerReceiver(mBatteryInfoReceiver,
-                new IntentFilter(Intent.ACTION_BATTERY_CHANGED)));
+        mBatteryBroadcastReceiver.register();
         if (mHandler.hasMessages(MSG_REFRESH_STATS)) {
             mHandler.removeMessages(MSG_REFRESH_STATS);
             mStatsHelper.clearStats();
@@ -84,7 +88,7 @@
     @Override
     public void onPause() {
         super.onPause();
-        getActivity().unregisterReceiver(mBatteryInfoReceiver);
+        mBatteryBroadcastReceiver.unRegister();
     }
 
     @Override
@@ -109,20 +113,6 @@
         historyPref.setStats(mStatsHelper);
     }
 
-    private boolean updateBatteryStatus(Intent intent) {
-        if (intent != null) {
-            String batteryLevel = com.android.settings.Utils.getBatteryPercentage(intent);
-            String batteryStatus = com.android.settings.Utils.getBatteryStatus(getResources(),
-                    intent);
-            if (!batteryLevel.equals(mBatteryLevel) || !batteryStatus.equals(mBatteryStatus)) {
-                mBatteryLevel = batteryLevel;
-                mBatteryStatus = batteryStatus;
-                return true;
-            }
-        }
-        return false;
-    }
-
     static final int MSG_REFRESH_STATS = 100;
 
     private final Handler mHandler = new Handler() {
@@ -137,17 +127,4 @@
         }
     };
 
-    private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            String action = intent.getAction();
-            if (Intent.ACTION_BATTERY_CHANGED.equals(action)
-                    && updateBatteryStatus(intent)) {
-                if (!mHandler.hasMessages(MSG_REFRESH_STATS)) {
-                    mHandler.sendEmptyMessageDelayed(MSG_REFRESH_STATS, 500);
-                }
-            }
-        }
-    };
-
 }
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index f701684..5f12d7c 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -561,14 +561,15 @@
                 .findViewById(R.id.battery_header_icon);
         final TextView timeText = (TextView) mBatteryLayoutPref.findViewById(R.id.battery_percent);
         final TextView summary1 = (TextView) mBatteryLayoutPref.findViewById(R.id.summary1);
-        timeText.setText(Utils.formatPercentage(info.mBatteryLevel));
+        timeText.setText(Utils.formatPercentage(info.batteryLevel));
         if (info.remainingLabel == null ) {
             summary1.setText(info.statusLabel);
         } else {
             summary1.setText(info.remainingLabel);
         }
 
-        batteryView.setBatteryInfo(info.mBatteryLevel);
+        batteryView.setBatteryLevel(info.batteryLevel);
+        batteryView.setCharging(!info.discharging);
     }
 
     @VisibleForTesting
@@ -682,22 +683,28 @@
     private static class SummaryProvider implements SummaryLoader.SummaryProvider {
         private final Context mContext;
         private final SummaryLoader mLoader;
+        private final BatteryBroadcastReceiver mBatteryBroadcastReceiver;
 
         private SummaryProvider(Context context, SummaryLoader loader) {
             mContext = context;
             mLoader = loader;
+            mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(mContext);
+            mBatteryBroadcastReceiver.setBatteryChangedListener(() -> {
+                BatteryInfo.getBatteryInfo(mContext, new BatteryInfo.Callback() {
+                    @Override
+                    public void onBatteryInfoLoaded(BatteryInfo info) {
+                        mLoader.setSummary(SummaryProvider.this, info.chargeLabelString);
+                    }
+                });
+            });
         }
 
         @Override
         public void setListening(boolean listening) {
             if (listening) {
-                // TODO: Listen.
-                BatteryInfo.getBatteryInfo(mContext, new BatteryInfo.Callback() {
-                    @Override
-                    public void onBatteryInfoLoaded(BatteryInfo info) {
-                        mLoader.setSummary(SummaryProvider.this, info.mChargeLabelString);
-                    }
-                });
+                mBatteryBroadcastReceiver.register();
+            } else {
+                mBatteryBroadcastReceiver.unRegister();
             }
         }
     }
diff --git a/src/com/android/settings/network/NetworkResetActionMenuController.java b/src/com/android/settings/network/NetworkResetActionMenuController.java
index 028ac7b..254834b 100644
--- a/src/com/android/settings/network/NetworkResetActionMenuController.java
+++ b/src/com/android/settings/network/NetworkResetActionMenuController.java
@@ -17,9 +17,6 @@
 package com.android.settings.network;
 
 import android.content.Context;
-import android.os.UserHandle;
-import android.os.UserManager;
-import android.support.annotation.VisibleForTesting;
 import android.view.Menu;
 import android.view.MenuItem;
 
@@ -27,15 +24,16 @@
 import com.android.settings.R;
 import com.android.settings.ResetNetwork;
 import com.android.settings.Utils;
-import com.android.settingslib.RestrictedLockUtils;
 
 public class NetworkResetActionMenuController {
 
     private static final int MENU_NETWORK_RESET = Menu.FIRST + 200;
     private final Context mContext;
+    private final NetworkResetRestrictionChecker mRestrictionChecker;
 
     public NetworkResetActionMenuController(Context context) {
         mContext = context;
+        mRestrictionChecker = new NetworkResetRestrictionChecker(context);
     }
 
     public void buildMenuItem(Menu menu) {
@@ -53,14 +51,8 @@
         }
     }
 
-    @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+
     boolean isAvailable() {
-        return isAvailable(mContext);
+        return !mRestrictionChecker.hasRestriction();
     }
-
-    static boolean isAvailable(Context context) {
-        return !RestrictedLockUtils.hasBaseUserRestriction(context,
-                UserManager.DISALLOW_NETWORK_RESET, UserHandle.myUserId());
-    }
-
 }
diff --git a/src/com/android/settings/network/NetworkResetPreferenceController.java b/src/com/android/settings/network/NetworkResetPreferenceController.java
index 04573c9..ce36a7f 100644
--- a/src/com/android/settings/network/NetworkResetPreferenceController.java
+++ b/src/com/android/settings/network/NetworkResetPreferenceController.java
@@ -22,13 +22,16 @@
 
 public class NetworkResetPreferenceController extends PreferenceController {
 
+    private final NetworkResetRestrictionChecker mRestrictionChecker;
+
     public NetworkResetPreferenceController(Context context) {
         super(context);
+        mRestrictionChecker = new NetworkResetRestrictionChecker(context);
     }
 
     @Override
     public boolean isAvailable() {
-        return NetworkResetActionMenuController.isAvailable(mContext);
+        return !mRestrictionChecker.hasRestriction();
     }
 
     @Override
diff --git a/src/com/android/settings/network/NetworkResetRestrictionChecker.java b/src/com/android/settings/network/NetworkResetRestrictionChecker.java
new file mode 100644
index 0000000..4fe9f59
--- /dev/null
+++ b/src/com/android/settings/network/NetworkResetRestrictionChecker.java
@@ -0,0 +1,53 @@
+/*
+ * 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.network;
+
+import android.content.Context;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.support.annotation.VisibleForTesting;
+
+import com.android.settingslib.RestrictedLockUtils;
+
+public class NetworkResetRestrictionChecker {
+
+    private final Context mContext;
+    private final UserManager mUserManager;
+
+    public NetworkResetRestrictionChecker(Context context) {
+        mContext = context;
+        mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
+    }
+
+    @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+    boolean hasUserBaseRestriction() {
+        return RestrictedLockUtils.hasBaseUserRestriction(mContext,
+                UserManager.DISALLOW_NETWORK_RESET, UserHandle.myUserId());
+    }
+
+    @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+    boolean isRestrictionEnforcedByAdmin() {
+        return RestrictedLockUtils.checkIfRestrictionEnforced(
+                mContext, UserManager.DISALLOW_NETWORK_RESET, UserHandle.myUserId()) != null;
+    }
+
+    boolean hasRestriction() {
+        return !mUserManager.isAdminUser()
+                || hasUserBaseRestriction()
+                || isRestrictionEnforcedByAdmin();
+    }
+}
diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java
index e359da6..8f7f2c5 100644
--- a/src/com/android/settings/notification/AppNotificationSettings.java
+++ b/src/com/android/settings/notification/AppNotificationSettings.java
@@ -49,7 +49,6 @@
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
-import java.util.Objects;
 
 /** These settings are per app, so should not be returned in global search results. */
 public class AppNotificationSettings extends NotificationSettingsBase {
@@ -109,8 +108,9 @@
             }
         }.execute();
 
-        final Preference pref = FeatureFactory.getFactory(getActivity())
-                .getApplicationFeatureProvider(getActivity())
+        final Activity activity = getActivity();
+        final Preference pref = FeatureFactory.getFactory(activity)
+                .getApplicationFeatureProvider(activity)
                 .newAppHeaderController(this /* fragment */, null /* appHeader */)
                 .setIcon(mAppRow.icon)
                 .setLabel(mAppRow.label)
@@ -118,7 +118,7 @@
                 .setUid(mAppRow.uid)
                 .setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
                         AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
-                .done(getPrefContext());
+                .done(activity, getPrefContext());
         getPreferenceScreen().addPreference(pref);
 
         if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) {
diff --git a/src/com/android/settings/notification/ChannelNotificationSettings.java b/src/com/android/settings/notification/ChannelNotificationSettings.java
index bec4845..c115672 100644
--- a/src/com/android/settings/notification/ChannelNotificationSettings.java
+++ b/src/com/android/settings/notification/ChannelNotificationSettings.java
@@ -21,6 +21,7 @@
 import static android.app.NotificationManager.IMPORTANCE_MIN;
 import static android.app.NotificationManager.IMPORTANCE_NONE;
 
+import android.app.Activity;
 import android.app.Notification;
 import android.app.NotificationChannel;
 import android.app.NotificationManager;
@@ -111,8 +112,9 @@
             setupBlockAndImportance();
             updateDependents();
         }
-        final Preference pref = FeatureFactory.getFactory(getActivity())
-                .getApplicationFeatureProvider(getActivity())
+        final Activity activity = getActivity();
+        final Preference pref = FeatureFactory.getFactory(activity)
+                .getApplicationFeatureProvider(activity)
                 .newAppHeaderController(this /* fragment */, null /* appHeader */)
                 .setIcon(mAppRow.icon)
                 .setLabel(mChannel.getName())
@@ -121,7 +123,7 @@
                 .setUid(mAppRow.uid)
                 .setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
                         AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
-                .done(getPrefContext());
+                .done(activity, getPrefContext());
         getPreferenceScreen().addPreference(pref);
 
         if (mAppRow.settingsIntent != null) {
diff --git a/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java b/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java
new file mode 100644
index 0000000..a78fed7
--- /dev/null
+++ b/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java
@@ -0,0 +1,137 @@
+/*
+ * 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.notification;
+
+import static com.android.internal.notification.NotificationAccessConfirmationActivityContract
+        .EXTRA_COMPONENT_NAME;
+import static com.android.internal.notification.NotificationAccessConfirmationActivityContract
+        .EXTRA_PACKAGE_TITLE;
+import static com.android.internal.notification.NotificationAccessConfirmationActivityContract
+        .EXTRA_USER_ID;
+
+import android.Manifest;
+import android.annotation.Nullable;
+import android.app.Activity;
+import android.content.ComponentName;
+import android.content.DialogInterface;
+import android.content.pm.PackageManager;
+import android.content.pm.ServiceInfo;
+import android.os.Bundle;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.provider.SettingsStringUtil;
+import android.util.Slog;
+import android.view.accessibility.AccessibilityEvent;
+
+import com.android.internal.app.AlertActivity;
+import com.android.internal.app.AlertController;
+import com.android.settings.R;
+import com.android.settings.core.TouchOverlayManager;
+
+/** @hide */
+public class NotificationAccessConfirmationActivity extends Activity
+        implements DialogInterface {
+
+    private static final boolean DEBUG = false;
+    private static final String LOG_TAG = "NotificationAccessConfirmationActivity";
+
+    private int mUserId;
+    private ComponentName mComponentName;
+    private TouchOverlayManager mTouchOverlayManager;
+
+    @Override
+    protected void onCreate(@Nullable Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        mTouchOverlayManager = new TouchOverlayManager(this);
+
+        mComponentName = getIntent().getParcelableExtra(EXTRA_COMPONENT_NAME);
+        mUserId = getIntent().getIntExtra(EXTRA_USER_ID, UserHandle.USER_NULL);
+        String pkgTitle = getIntent().getStringExtra(EXTRA_PACKAGE_TITLE);
+
+        AlertController.AlertParams p = new AlertController.AlertParams(this);
+        p.mTitle = getString(
+                R.string.notification_listener_security_warning_title,
+                pkgTitle);
+        p.mMessage = getString(
+                R.string.notification_listener_security_warning_summary,
+                pkgTitle);
+        p.mPositiveButtonText = getString(R.string.allow);
+        p.mPositiveButtonListener = (a, b) -> onAllow();
+        p.mNegativeButtonText = getString(R.string.deny);
+        p.mNegativeButtonListener = (a, b) -> cancel();
+        AlertController
+                .create(this, this, getWindow())
+                .installContent(p);
+    }
+
+    private void onAllow() {
+        String requiredPermission = Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE;
+        try {
+            ServiceInfo serviceInfo = getPackageManager().getServiceInfo(mComponentName, 0);
+            if (!requiredPermission.equals(serviceInfo.permission)) {
+                Slog.e(LOG_TAG,
+                        "Service " + mComponentName + " lacks permission " + requiredPermission);
+                return;
+            }
+        } catch (PackageManager.NameNotFoundException e) {
+            Slog.e(LOG_TAG, "Failed to get service info for " + mComponentName, e);
+            return;
+        }
+
+        final SettingsStringUtil.SettingStringHelper setting =
+                 new SettingsStringUtil.SettingStringHelper(
+                         getContentResolver(),
+                         Settings.Secure.ENABLED_NOTIFICATION_LISTENERS,
+                         mUserId);
+        setting.write(SettingsStringUtil.ComponentNameSet.add(setting.read(), mComponentName));
+
+        finish();
+    }
+
+    @Override
+    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
+        return AlertActivity.dispatchPopulateAccessibilityEvent(this, event);
+    }
+
+    @Override
+    public void cancel() {
+        finish();
+    }
+
+    @Override
+    public void dismiss() {
+        // This is called after the click, since we finish when handling the
+        // click, don't do that again here.
+        if (!isFinishing()) {
+            finish();
+        }
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        mTouchOverlayManager.setOverlayAllowed(false);
+    }
+
+    @Override
+    protected void onPause() {
+        super.onPause();
+        mTouchOverlayManager.setOverlayAllowed(true);
+    }
+}
diff --git a/src/com/android/settings/notification/RedactionInterstitial.java b/src/com/android/settings/notification/RedactionInterstitial.java
index 08474a0..b269062 100644
--- a/src/com/android/settings/notification/RedactionInterstitial.java
+++ b/src/com/android/settings/notification/RedactionInterstitial.java
@@ -16,7 +16,11 @@
 
 package com.android.settings.notification;
 
-import android.app.admin.DevicePolicyManager;
+import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS;
+import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS;
+
+import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+
 import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
@@ -26,7 +30,6 @@
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.Button;
-import android.widget.CompoundButton;
 import android.widget.LinearLayout;
 import android.widget.RadioButton;
 import android.widget.RadioGroup;
@@ -34,18 +37,13 @@
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
-import com.android.settings.RestrictedCheckBox;
 import com.android.settings.RestrictedRadioButton;
 import com.android.settings.SettingsActivity;
 import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.SetupRedactionInterstitial;
 import com.android.settings.Utils;
 import com.android.settingslib.RestrictedLockUtils;
 
-import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS;
-import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS;
-
-import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
-
 public class RedactionInterstitial extends SettingsActivity {
 
     @Override
@@ -128,6 +126,7 @@
         @Override
         public void onClick(View v) {
             if (v.getId() == R.id.redaction_done_button) {
+                SetupRedactionInterstitial.setEnabled(getContext(), false);
                 final RedactionInterstitial activity = (RedactionInterstitial) getActivity();
                 if (activity != null) {
                     activity.setResult(RESULT_OK, null);
diff --git a/src/com/android/settings/wallpaper/WallpaperTypeSettings.java b/src/com/android/settings/wallpaper/WallpaperTypeSettings.java
index 6efdcf72..bef4777 100644
--- a/src/com/android/settings/wallpaper/WallpaperTypeSettings.java
+++ b/src/com/android/settings/wallpaper/WallpaperTypeSettings.java
@@ -67,7 +67,6 @@
         // Add Preference items for each of the matching activities
         for (ResolveInfo info : rList) {
             Preference pref = new Preference(getPrefContext());
-            pref.setLayoutResource(R.layout.preference_wallpaper_type);
             Intent prefIntent = new Intent(intent);
             prefIntent.setComponent(new ComponentName(
                     info.activityInfo.packageName, info.activityInfo.name));
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 38f5a43..01551da 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -90,6 +90,7 @@
         WifiDialog.WifiDialogListener {
 
     private static final String TAG = "WifiSettings";
+    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
 
     /* package */ static final int MENU_ID_WPS_PBC = Menu.FIRST;
     private static final int MENU_ID_WPS_PIN = Menu.FIRST + 1;
@@ -203,6 +204,9 @@
         mConfigureWifiSettingsPreference = findPreference(PREF_KEY_CONFIGURE_WIFI_SETTINGS);
         mSavedNetworksPreference = findPreference(PREF_KEY_SAVED_NETWORKS);
 
+        // Hide additional settings until access points are shown during onStart
+        showAdditionalSettings(false);
+
         Context prefContext = getPrefContext();
         mAddPreference = new Preference(prefContext);
         mAddPreference.setIcon(R.drawable.ic_menu_add_inset);
@@ -220,6 +224,17 @@
         mBgThread.start();
     }
 
+    // TODO(b/37429702): Figure out how to temporarily disable animations during startup and remove
+    // this method.
+    private void showAdditionalSettings(boolean visible) {
+        mAdditionalSettingsPreferenceCategory.setVisible(visible);
+        mAdditionalSettingsPreferenceCategory.removeAll();
+        if (visible) {
+            mAdditionalSettingsPreferenceCategory.addPreference(mConfigureWifiSettingsPreference);
+            mAdditionalSettingsPreferenceCategory.addPreference(mSavedNetworksPreference);
+        }
+    }
+
     @Override
     public void onDestroy() {
         mBgThread.quit();
@@ -335,6 +350,17 @@
         mWifiEnabler = createWifiEnabler();
 
         mWifiTracker.startTracking();
+
+        if (!isUiRestricted() && mWifiManager.isWifiEnabled()) {
+            setProgressBarVisible(true);
+            mWifiTracker.forceUpdate();
+            if (DEBUG) Log.d(TAG, "WifiSettings onStart APs: " + mWifiTracker.getAccessPoints());
+
+            getView().removeCallbacks(mUpdateAccessPointsRunnable);
+            updateAccessPointPreferences();
+        }
+
+        showAdditionalSettings(true);
     }
 
     /**
@@ -353,8 +379,6 @@
         if (mWifiEnabler != null) {
             mWifiEnabler.resume(activity);
         }
-
-        activity.invalidateOptionsMenu();
     }
 
     @Override
@@ -370,6 +394,7 @@
         mWifiTracker.stopTracking();
         getView().removeCallbacks(mUpdateAccessPointsRunnable);
         getView().removeCallbacks(mHideProgressBarRunnable);
+        showAdditionalSettings(false);
         super.onStop();
     }
 
@@ -733,7 +758,7 @@
         removeCachedPrefs(mAccessPointsPreferenceCategory);
         mAddPreference.setOrder(index);
         mAccessPointsPreferenceCategory.addPreference(mAddPreference);
-        setConfigureWifiSettingsVisibility();
+        setAdditionalSettingsSummaries();
 
         if (!hasAvailableAccessPoints) {
             setProgressBarVisible(true);
@@ -812,8 +837,8 @@
         // in the Wifi Network Details Fragment
         pref.getAccessPoint().saveWifiState(pref.getExtras());
         pref.setFragment(WifiNetworkDetailsFragment.class.getName());
-
         pref.refresh();
+
         mConnectedAccessPointPreferenceCategory.addPreference(pref);
         mConnectedAccessPointPreferenceCategory.setVisible(true);
     }
@@ -824,7 +849,7 @@
         mConnectedAccessPointPreferenceCategory.setVisible(false);
     }
 
-    private void setConfigureWifiSettingsVisibility() {
+    private void setAdditionalSettingsSummaries() {
         mAdditionalSettingsPreferenceCategory.addPreference(mConfigureWifiSettingsPreference);
         boolean wifiWakeupEnabled = Settings.Global.getInt(
                 getContentResolver(), Settings.Global.WIFI_WAKEUP_ENABLED, 0) == 1;
diff --git a/src/com/android/settings/wifi/WifiWakeupPreferenceController.java b/src/com/android/settings/wifi/WifiWakeupPreferenceController.java
index 122e524..2c33fc5 100644
--- a/src/com/android/settings/wifi/WifiWakeupPreferenceController.java
+++ b/src/com/android/settings/wifi/WifiWakeupPreferenceController.java
@@ -26,6 +26,7 @@
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceScreen;
 import android.text.TextUtils;
+import com.android.settings.R;
 
 import com.android.settings.core.PreferenceController;
 import com.android.settings.core.lifecycle.Lifecycle;
@@ -97,10 +98,20 @@
             return;
         }
         final SwitchPreference enableWifiWakeup = (SwitchPreference) preference;
+
         enableWifiWakeup.setChecked(Settings.Global.getInt(mContext.getContentResolver(),
                 Settings.Global.WIFI_WAKEUP_ENABLED, 0) == 1);
-        enableWifiWakeup.setEnabled(Settings.Global.getInt(mContext.getContentResolver(),
-                Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0) == 1);
+
+        boolean wifiScanningEnabled = Settings.Global.getInt(mContext.getContentResolver(),
+                Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1;
+        boolean networkRecommendationsEnabled = Settings.Global.getInt(
+                mContext.getContentResolver(),
+                Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0) == 1;
+        enableWifiWakeup.setEnabled(networkRecommendationsEnabled && wifiScanningEnabled);
+
+        enableWifiWakeup.setSummary(wifiScanningEnabled ?
+                R.string.wifi_wakeup_summary :
+                R.string.wifi_wakeup_summary_scanning_disabled);
     }
 
     class SettingObserver extends ContentObserver {
diff --git a/tests/robotests/src/com/android/settings/SecuritySettingsTest.java b/tests/robotests/src/com/android/settings/SecuritySettingsTest.java
index 9bdf502..c636748 100644
--- a/tests/robotests/src/com/android/settings/SecuritySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/SecuritySettingsTest.java
@@ -101,24 +101,7 @@
     }
 
     @Test
-    @Config(shadows = {
-            ShadowSecureSettings.class,
-    })
-    public void testSummaryProvider_packageVerifierDisabled() {
-        // Package verifier state is set to disabled.
-        ShadowSecureSettings.putInt(null, Settings.Secure.PACKAGE_VERIFIER_STATE, -1);
-        mSummaryProvider.setListening(true);
-
-        verify(mSummaryLoader, times(1)).setSummary(any(), isNull(String.class));
-    }
-
-    @Test
-    @Config(shadows = {
-            ShadowSecureSettings.class,
-    })
     public void testSummaryProvider_hasFingerPrint_hasStaticSummary() {
-        // Package verifier state is set to disabled.
-        ShadowSecureSettings.putInt(null, Settings.Secure.PACKAGE_VERIFIER_STATE, -1);
         final FingerprintManager fpm = mock(FingerprintManager.class);
         when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
                 .thenReturn(true);
@@ -133,37 +116,29 @@
     }
 
     @Test
-    public void testGetPackageVerifierSummary_nullInput() {
-        assertThat(mSummaryProvider.getPackageVerifierSummary(null)).isNull();
+    public void testSummaryProvider_noFpFeature_shouldSetSummaryWithNoFingerprint() {
+        final FingerprintManager fpm = mock(FingerprintManager.class);
+        when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
+            .thenReturn(false);
 
-        when(mDashboardCategory.getTilesCount()).thenReturn(0);
+        mSummaryProvider.setListening(true);
 
-        assertThat(mSummaryProvider.getPackageVerifierSummary(mDashboardCategory)).isNull();
+        verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
     }
 
     @Test
-    public void testGetPackageVerifierSummary_noMatchingTile() {
-        when(mDashboardCategory.getTilesCount()).thenReturn(1);
-        when(mDashboardCategory.getTile(0)).thenReturn(new Tile());
+    public void testSummaryProvider_noFpHardware_shouldSetSummaryWithNoFingerprint() {
+        final FingerprintManager fpm = mock(FingerprintManager.class);
+        when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
+            .thenReturn(true);
 
-        assertThat(mSummaryProvider.getPackageVerifierSummary(mDashboardCategory)).isNull();
-    }
+        // Cast to Object to workaround a robolectric casting bug
+        when((Object) mContext.getSystemService(FingerprintManager.class)).thenReturn(fpm);
+        when(fpm.isHardwareDetected()).thenReturn(false);
 
-    @Test
-    @Config(shadows = {
-            ShadowTileUtils.class,
-    })
-    public void testGetPackageVerifierSummary_matchingTile() {
-        when(mDashboardCategory.getTilesCount()).thenReturn(1);
-        Tile tile = new Tile();
-        tile.key = SecuritySettings.KEY_PACKAGE_VERIFIER_STATUS;
-        Bundle bundle = new Bundle();
-        bundle.putString(TileUtils.META_DATA_PREFERENCE_SUMMARY_URI, "content://host/path");
-        tile.metaData = bundle;
-        when(mDashboardCategory.getTile(0)).thenReturn(tile);
+        mSummaryProvider.setListening(true);
 
-        assertThat(mSummaryProvider.getPackageVerifierSummary(mDashboardCategory))
-                .isEqualTo(MOCK_SUMMARY);
+        verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/SettingsActivityTest.java b/tests/robotests/src/com/android/settings/SettingsActivityTest.java
index 9d53bc8..65e9708 100644
--- a/tests/robotests/src/com/android/settings/SettingsActivityTest.java
+++ b/tests/robotests/src/com/android/settings/SettingsActivityTest.java
@@ -16,20 +16,28 @@
 
 package com.android.settings;
 
+import android.app.Activity;
 import android.app.ActivityManager;
 import android.app.FragmentManager;
 import android.app.FragmentTransaction;
+import android.content.Context;
 import android.content.Intent;
 import android.graphics.Bitmap;
 
+import android.os.Bundle;
+import android.view.Menu;
+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.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
 
+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;
@@ -42,6 +50,9 @@
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public class SettingsActivityTest {
 
+    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    private Context mContext;
+
     @Mock
     private FragmentManager mFragmentManager;
     @Mock
@@ -50,10 +61,15 @@
     private Bitmap mBitmap;
     private SettingsActivity mActivity;
 
+    private FakeFeatureFactory mFeatureFactory;
+
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
 
+        FakeFeatureFactory.setupForTest(mContext);
+        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+
         mActivity = spy(new SettingsActivity());
         doReturn(mBitmap).when(mActivity).getBitmapFromXmlResource(anyInt());
     }
@@ -61,7 +77,6 @@
     @Test
     public void launchSettingFragment_nullExtraShowFragment_shouldNotCrash()
             throws ClassNotFoundException {
-        mActivity = spy(new SettingsActivity());
         when(mActivity.getFragmentManager()).thenReturn(mFragmentManager);
         when(mFragmentManager.beginTransaction()).thenReturn(mock(FragmentTransaction.class));
 
@@ -76,4 +91,51 @@
 
         verify(mTaskDescription).setIcon(any());
     }
+
+    @Test
+    public void testCreateOptionsMenu_setsUpSearch() {
+        ReflectionHelpers.setField(mActivity, "mSearchFeatureProvider",
+                mFeatureFactory.getSearchFeatureProvider());
+        mActivity.mDisplaySearch = true;
+        mActivity.onCreateOptionsMenu(null);
+
+        verify(mFeatureFactory.getSearchFeatureProvider()).setUpSearchMenu(any(Menu.class),
+                any(Activity.class));
+    }
+
+    @Test
+    public void testSaveState_DisplaySearchSaved() {
+        mActivity.mDisplaySearch = true;
+        Bundle bundle = new Bundle();
+        mActivity.saveState(bundle);
+
+        assertThat((boolean) bundle.get(SettingsActivity.SAVE_KEY_SHOW_SEARCH)).isTrue();
+    }
+
+    @Test
+    public void testSaveState_EnabledHomeSaved() {
+        mActivity.mDisplayHomeAsUpEnabled = true;
+        Bundle bundle = new Bundle();
+        mActivity.saveState(bundle);
+
+        assertThat((boolean) bundle.get(SettingsActivity.SAVE_KEY_SHOW_HOME_AS_UP)).isTrue();
+    }
+
+    @Test
+    public void testRestoreState_DisplaySearchRestored() {
+        Bundle bundle = new Bundle();
+        bundle.putBoolean(SettingsActivity.SAVE_KEY_SHOW_SEARCH, true);
+        mActivity.onRestoreInstanceState(bundle);
+
+        assertThat(mActivity.mDisplaySearch).isTrue();
+    }
+
+    @Test
+    public void testRestoreState_EnabledHomeRestored() {
+        Bundle bundle = new Bundle();
+        bundle.putBoolean(SettingsActivity.SAVE_KEY_SHOW_SEARCH, true);
+        mActivity.onRestoreInstanceState(bundle);
+
+        assertThat(mActivity.mDisplaySearch).isTrue();
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java b/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java
index 0d878ed..030978f 100644
--- a/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java
@@ -17,6 +17,15 @@
 package com.android.settings.applications;
 
 
+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.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.ActionBar;
 import android.app.Activity;
 import android.app.Fragment;
 import android.content.Context;
@@ -24,6 +33,7 @@
 import android.content.pm.ActivityInfo;
 import android.content.pm.PackageInfo;
 import android.content.pm.ResolveInfo;
+import android.graphics.drawable.Drawable;
 import android.os.UserHandle;
 import android.support.v7.preference.Preference;
 import android.view.LayoutInflater;
@@ -34,7 +44,6 @@
 import com.android.settings.R;
 import com.android.settings.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
-import com.android.settingslib.applications.ApplicationsState;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -45,14 +54,6 @@
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 
-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.eq;
-import static org.mockito.Mockito.mock;
-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 AppHeaderControllerTest {
@@ -60,11 +61,9 @@
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Context mContext;
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private ApplicationsState.AppEntry mAppEntry;
+    private Activity mActivity;
     @Mock
     private Fragment mFragment;
-    @Mock
-    private View mAppHeader;
 
     private Context mShadowContext;
     private LayoutInflater mLayoutInflater;
@@ -85,7 +84,7 @@
     @Test
     public void testBuildView_constructedWithoutView_shouldCreateNewView() {
         mController = new AppHeaderController(mShadowContext, mFragment, null);
-        View view = mController.done();
+        View view = mController.done(mActivity);
 
         assertThat(view).isNotNull();
     }
@@ -93,7 +92,7 @@
     @Test
     public void testBuildView_withContext_shouldBuildPreference() {
         mController = new AppHeaderController(mShadowContext, mFragment, null);
-        Preference preference = mController.done(mShadowContext);
+        Preference preference = mController.done(mActivity, mShadowContext);
 
         assertThat(preference instanceof LayoutPreference).isTrue();
     }
@@ -102,7 +101,7 @@
     public void testBuildView_constructedWithView_shouldReturnSameView() {
         View inputView = mLayoutInflater.inflate(R.layout.app_details, null /* root */);
         mController = new AppHeaderController(mShadowContext, mFragment, inputView);
-        View view = mController.done();
+        View view = mController.done(mActivity);
 
         assertThat(view).isSameAs(inputView);
     }
@@ -111,14 +110,14 @@
     public void bindViews_shouldBindAllData() {
         final String testString = "test";
         final View appHeader = mLayoutInflater.inflate(R.layout.app_details, null /* root */);
-        final TextView label = (TextView) appHeader.findViewById(R.id.app_detail_title);
-        final TextView version = (TextView) appHeader.findViewById(R.id.app_detail_summary);
+        final TextView label = appHeader.findViewById(R.id.app_detail_title);
+        final TextView version = appHeader.findViewById(R.id.app_detail_summary);
 
         mController = new AppHeaderController(mShadowContext, mFragment, appHeader);
         mController.setLabel(testString);
         mController.setSummary(testString);
         mController.setIcon(mShadowContext.getDrawable(R.drawable.ic_add));
-        mController.done();
+        mController.done(mActivity);
 
         assertThat(label.getText()).isEqualTo(testString);
         assertThat(version.getText()).isEqualTo(testString);
@@ -139,7 +138,7 @@
         mController.setButtonActions(
                 AppHeaderController.ActionType.ACTION_APP_PREFERENCE,
                 AppHeaderController.ActionType.ACTION_NONE);
-        mController.done();
+        mController.done(mActivity);
 
         assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
                 .isEqualTo(View.VISIBLE);
@@ -164,7 +163,7 @@
         mController.setButtonActions(
                 AppHeaderController.ActionType.ACTION_APP_PREFERENCE,
                 AppHeaderController.ActionType.ACTION_NONE);
-        mController.done();
+        mController.done(mActivity);
 
         assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
                 .isEqualTo(View.GONE);
@@ -183,7 +182,7 @@
         mController.setButtonActions(
                 AppHeaderController.ActionType.ACTION_STORE_DEEP_LINK,
                 AppHeaderController.ActionType.ACTION_NONE);
-        mController.done();
+        mController.done(mActivity);
 
         assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
                 .isEqualTo(View.GONE);
@@ -201,7 +200,7 @@
                 .setButtonActions(
                         AppHeaderController.ActionType.ACTION_APP_INFO,
                         AppHeaderController.ActionType.ACTION_NONE);
-        mController.done();
+        mController.done(mActivity);
 
         assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
                 .isEqualTo(View.GONE);
@@ -221,7 +220,7 @@
                 .setButtonActions(
                         AppHeaderController.ActionType.ACTION_APP_INFO,
                         AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE);
-        mController.done();
+        mController.done(mActivity);
 
         assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
                 .isEqualTo(View.VISIBLE);
@@ -242,7 +241,7 @@
                 .setButtonActions(
                         AppHeaderController.ActionType.ACTION_APP_INFO,
                         AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE);
-        mController.done();
+        mController.done(mActivity);
 
         assertThat(appLinks.findViewById(R.id.left_button).getContentDescription())
                 .isEqualTo("App Info");
@@ -258,7 +257,7 @@
                 .setButtonActions(
                         AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE,
                         AppHeaderController.ActionType.ACTION_NONE);
-        mController.done();
+        mController.done(mActivity);
 
         assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
                 .isEqualTo(View.VISIBLE);
@@ -272,7 +271,7 @@
     public void instantApps_normalAppsDontGetLabel() {
         final View appHeader = mLayoutInflater.inflate(R.layout.app_details, null /* root */);
         mController = new AppHeaderController(mContext, mFragment, appHeader);
-        mController.done();
+        mController.done(mActivity);
         assertThat(appHeader.findViewById(R.id.install_type).getVisibility())
                 .isEqualTo(View.GONE);
     }
@@ -283,7 +282,7 @@
     public void instantApps_normalAppsDontGetInstantAppsBadge() {
         final View appHeader = mLayoutInflater.inflate(R.layout.app_details, null /* root */);
         mController = new AppHeaderController(mContext, mFragment, appHeader);
-        mController.done();
+        mController.done(mActivity);
         assertThat(appHeader.findViewById(R.id.app_icon_instant_apps_badge).getVisibility())
                 .isEqualTo(View.GONE);
     }
@@ -294,8 +293,8 @@
         final View appHeader = mLayoutInflater.inflate(R.layout.app_details, null /* root */);
         mController = new AppHeaderController(mContext, mFragment, appHeader);
         mController.setIsInstantApp(true);
-        mController.done();
-        TextView label = (TextView)appHeader.findViewById(R.id.install_type);
+        mController.done(mActivity);
+        TextView label = appHeader.findViewById(R.id.install_type);
         ImageView badgeView = appHeader.findViewById(R.id.app_icon_instant_apps_badge);
         assertThat(badgeView.getVisibility()).isEqualTo(View.VISIBLE);
         assertThat(label.getVisibility()).isEqualTo(View.VISIBLE);
@@ -306,6 +305,29 @@
     }
 
     @Test
+    public void styleActionBar_invalidObjects_shouldNotCrash() {
+        mController = new AppHeaderController(mShadowContext, mFragment, null);
+        mController.styleActionBar(null);
+
+        when(mActivity.getActionBar()).thenReturn(null);
+        mController.styleActionBar(mActivity);
+
+        verify(mActivity).getActionBar();
+    }
+
+    @Test
+    public void styleActionBar_setElevationAndBackground() {
+        final ActionBar actionBar = mActivity.getActionBar();
+
+        mController = new AppHeaderController(mShadowContext, mFragment, null);
+        mController.styleActionBar(mActivity);
+
+        verify(actionBar).setElevation(0);
+        verify(actionBar).setBackgroundDrawable(any(Drawable.class));
+    }
+
+
+    @Test
     public void initAppHeaderController_appHeaderNull_useFragmentContext() {
         mController = new AppHeaderController(mContext, mFragment, null);
 
diff --git a/tests/robotests/src/com/android/settings/applications/FetchPackageStorageAsyncLoaderTest.java b/tests/robotests/src/com/android/settings/applications/FetchPackageStorageAsyncLoaderTest.java
index 04eeb02..36116c0 100644
--- a/tests/robotests/src/com/android/settings/applications/FetchPackageStorageAsyncLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/applications/FetchPackageStorageAsyncLoaderTest.java
@@ -40,6 +40,8 @@
 import org.mockito.MockitoAnnotations;
 import org.robolectric.annotation.Config;
 
+import java.io.IOException;
+
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public class FetchPackageStorageAsyncLoaderTest {
@@ -56,7 +58,7 @@
     }
 
     @Test
-    public void worksForValidPackageNameAndUid() {
+    public void worksForValidPackageNameAndUid() throws Exception {
         AppStorageStats stats = mock(AppStorageStats.class);
         when(stats.getCodeBytes()).thenReturn(1L);
         when(stats.getDataBytes()).thenReturn(2L);
@@ -72,9 +74,9 @@
     }
 
     @Test
-    public void installerExceptionHandledCleanly() {
+    public void installerExceptionHandledCleanly() throws Exception {
         when(mSource.getStatsForPackage(anyString(), anyString(), any(UserHandle.class))).
-                thenThrow(new IllegalStateException("intentional failure"));
+                thenThrow(new IOException("intentional failure"));
         ApplicationInfo info = new ApplicationInfo();
         info.packageName = PACKAGE_NAME;
         FetchPackageStorageAsyncLoader task = new FetchPackageStorageAsyncLoader(
diff --git a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
index 5b1019e..f372836 100644
--- a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
@@ -17,21 +17,34 @@
 package com.android.settings.applications;
 
 
-import android.app.Activity;
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
 import android.app.AlertDialog;
 import android.app.admin.DevicePolicyManager;
 import android.content.Context;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
 import android.os.BatteryStats;
 import android.os.UserManager;
 import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceManager;
+import android.support.v7.preference.PreferenceScreen;
 import android.view.View;
 import android.widget.Button;
 
 import com.android.internal.os.BatterySipper;
 import com.android.internal.os.BatteryStatsHelper;
-import com.android.settings.R;
 import com.android.settings.SettingsActivity;
 import com.android.settings.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
@@ -39,8 +52,8 @@
 import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settingslib.applications.AppUtils;
 import com.android.settingslib.applications.ApplicationsState.AppEntry;
-import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
 import com.android.settingslib.applications.StorageStatsSource.AppStorageStats;
+import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -52,18 +65,6 @@
 import org.robolectric.annotation.Config;
 import org.robolectric.util.ReflectionHelpers;
 
-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.anyString;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-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)
@@ -315,4 +316,43 @@
         verify(buttonsController).setPackageName(anyString());
         verify(buttonsController).show();
     }
+
+    @Test
+    public void instantApps_removeCorrectPref() {
+        PreferenceScreen mockPreferenceScreen = mock(PreferenceScreen.class);
+        PreferenceManager mockPreferenceManager = mock(PreferenceManager.class);
+        AppDomainsPreference mockAppDomainsPref = mock(AppDomainsPreference.class);
+        Preference mockLaunchPreference = mock(Preference.class);
+        PackageInfo mockPackageInfo = mock(PackageInfo.class);
+        PackageManager mockPackageManager = mock(PackageManager.class);
+        ReflectionHelpers.setField(
+                mAppDetail, "mLaunchPreference", mockLaunchPreference);
+        ReflectionHelpers.setField(
+                mAppDetail, "mInstantAppDomainsPreference", mockAppDomainsPref);
+        ReflectionHelpers.setField(
+                mAppDetail, "mPreferenceManager", mockPreferenceManager);
+        ReflectionHelpers.setField(
+                mAppDetail, "mPackageInfo", mockPackageInfo);
+        ReflectionHelpers.setField(
+                mAppDetail, "mPm", mockPackageManager);
+        when(mockPreferenceManager.getPreferenceScreen()).thenReturn(mockPreferenceScreen);
+
+        ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
+                (InstantAppDataProvider) (i -> false));
+        mAppDetail.prepareInstantAppPrefs();
+
+        // For the non instant case we remove the app domain pref, and leave the launch pref
+        verify(mockPreferenceScreen).removePreference(mockAppDomainsPref);
+        verify(mockPreferenceScreen, never()).removePreference(mockLaunchPreference);
+
+        // For the instant app case we remove the launch preff, and leave the app domain pref
+        ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
+                (InstantAppDataProvider) (i -> true));
+
+        mAppDetail.prepareInstantAppPrefs();
+        verify(mockPreferenceScreen).removePreference(mockLaunchPreference);
+        // Will be 1 still due to above call
+        verify(mockPreferenceScreen, times(1))
+                .removePreference(mockAppDomainsPref);
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java b/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java
index 9bc7482..6440141 100644
--- a/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java
@@ -81,7 +81,7 @@
     }
 
     @Test
-    public void storageShouldRepresentStorageStatsQuery() {
+    public void storageShouldRepresentStorageStatsQuery() throws Exception {
         when(mSource.getExternalStorageStats(any(String.class), any(UserHandle.class))).thenReturn(
                 new StorageStatsSource.ExternalStorageStats(1, 1, 0, 0));
 
diff --git a/tests/robotests/src/com/android/settings/applications/SpecialAppAccessPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/SpecialAppAccessPreferenceControllerTest.java
new file mode 100644
index 0000000..44ca9f7
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/SpecialAppAccessPreferenceControllerTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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 com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+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.datausage.DataSaverBackend;
+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;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class SpecialAppAccessPreferenceControllerTest {
+    private Context mContext;
+    @Mock
+    private DataSaverBackend mBackend;
+    @Mock
+    private Preference mPreference;
+
+    private SpecialAppAccessPreferenceController mController;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = RuntimeEnvironment.application;
+        mController = new SpecialAppAccessPreferenceController(mContext);
+        ReflectionHelpers.setField(mController, "mDataSaverBackend", mBackend);
+    }
+
+    @Test
+    public void isAvailable_shouldAlwaysReturnTrue() {
+        assertThat(mController.isAvailable()).isTrue();
+    }
+
+    @Test
+    public void updateState_shouldSetSummary() {
+        when(mBackend.getWhitelistedCount()).thenReturn(0);
+
+        mController.updateState(mPreference);
+
+        verify(mPreference).setSummary(mContext.getResources().getQuantityString(
+            R.plurals.special_access_summary, 0, 0));
+
+        when(mBackend.getWhitelistedCount()).thenReturn(1);
+
+        mController.updateState(mPreference);
+
+        verify(mPreference).setSummary(mContext.getResources().getQuantityString(
+            R.plurals.special_access_summary, 1, 1));
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPreferenceControllerTest.java
index 1182762..728a8a5 100644
--- a/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPreferenceControllerTest.java
@@ -16,7 +16,16 @@
 
 package com.android.settings.applications.assist;
 
+import android.Manifest;
+import android.app.SearchManager;
+import android.content.ComponentName;
 import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
 import android.provider.Settings;
 
 import com.android.settings.SettingsRobolectricTestRunner;
@@ -24,6 +33,8 @@
 import com.android.settings.applications.defaultapps.DefaultAppInfo;
 import com.android.settings.testutils.shadow.ShadowSecureSettings;
 
+import java.util.ArrayList;
+import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -32,6 +43,13 @@
 import org.robolectric.annotation.Config;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyBoolean;
+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.when;
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@@ -39,6 +57,10 @@
 
     @Mock
     private Context mContext;
+    @Mock
+    private SearchManager mSearchManager;
+    @Mock
+    private PackageManager mPackageManager;
     private DefaultAssistPreferenceController mController;
 
     @Before
@@ -61,4 +83,33 @@
 
         assertThat(appInfo.getKey()).isEqualTo(flattenKey);
     }
+
+    @Test
+    public void getSettingIntent_noSettingsActivity_shouldNotCrash() {
+        final String flattenKey = "com.android.settings/assist";
+        ShadowSecureSettings.putString(null, Settings.Secure.ASSISTANT, flattenKey);
+        when(mContext.getPackageManager()).thenReturn(mPackageManager);
+        DefaultAssistPreferenceController controller =
+            spy(new DefaultAssistPreferenceController(mContext));
+        final ResolveInfo resolveInfo = new ResolveInfo();
+        resolveInfo.activityInfo = new ActivityInfo();
+        resolveInfo.activityInfo.name = "assist";
+        resolveInfo.activityInfo.applicationInfo = new ApplicationInfo();
+        resolveInfo.activityInfo.applicationInfo.packageName = "com.android.settings";
+        when(mPackageManager.resolveActivityAsUser(any(Intent.class), anyInt(), anyInt()))
+            .thenReturn(resolveInfo);
+        when(mContext.getSystemService(Context.SEARCH_SERVICE)).thenReturn(mSearchManager);
+        when(mSearchManager.getAssistIntent(anyBoolean())).thenReturn(mock(Intent.class));
+        final ServiceInfo serviceInfo = new ServiceInfo();
+        serviceInfo.permission = Manifest.permission.BIND_VOICE_INTERACTION;
+        resolveInfo.serviceInfo = serviceInfo;
+        final List<ResolveInfo> services = new ArrayList<>();
+        services.add(resolveInfo);
+        when(mPackageManager.queryIntentServices(any(Intent.class), anyInt())).thenReturn(services);
+        doReturn(null).when(controller).getAssistSettingsActivity(
+            ComponentName.unflattenFromString(flattenKey), resolveInfo, mPackageManager);
+
+        controller.getSettingIntent(null);
+        // should not crash
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/StorageDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/deviceinfo/StorageDashboardFragmentTest.java
index b3253f9..0c9988b 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/StorageDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/StorageDashboardFragmentTest.java
@@ -18,6 +18,10 @@
 
 import static com.google.common.truth.Truth.assertThat;
 
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import android.app.Activity;
 import android.os.storage.StorageManager;
 import android.provider.SearchIndexableResource;
 
@@ -56,6 +60,15 @@
     }
 
     @Test
+    public void test_initializeOptionsMenuInvalidatesExistingMenu() {
+        Activity activity = mock(Activity.class);
+
+        mFragment.initializeOptionsMenu(activity);
+
+        verify(activity).invalidateOptionsMenu();
+    }
+
+    @Test
     public void testSearchIndexProvider_shouldIndexResource() {
         final List<SearchIndexableResource> indexRes =
                 StorageDashboardFragment.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/StorageProfileFragmentTest.java b/tests/robotests/src/com/android/settings/deviceinfo/StorageProfileFragmentTest.java
index 8da2a9c..8d48e63 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/StorageProfileFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/StorageProfileFragmentTest.java
@@ -44,6 +44,7 @@
         result.musicAppsSize = 100;
         result.otherAppsSize = 200;
         result.gamesSize = 300;
+        result.videoAppsSize = 400;
         result.externalStats = new StorageStatsSource.ExternalStorageStats(6, 1, 2, 3);
         SparseArray<StorageAsyncLoader.AppsStorageResult> resultsArray = new SparseArray<>();
         resultsArray.put(0, result);
@@ -57,6 +58,7 @@
 
         StorageAsyncLoader.AppsStorageResult extractedResult = resultCaptor.getValue();
         assertThat(extractedResult.musicAppsSize).isEqualTo(0);
+        assertThat(extractedResult.videoAppsSize).isEqualTo(0);
         assertThat(extractedResult.otherAppsSize).isEqualTo(0);
         assertThat(extractedResult.gamesSize).isEqualTo(0);
         assertThat(extractedResult.externalStats.audioBytes).isEqualTo(1);
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/StorageSettingsTest.java b/tests/robotests/src/com/android/settings/deviceinfo/StorageSettingsTest.java
index 95f9fbe..17abab1 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/StorageSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/StorageSettingsTest.java
@@ -70,7 +70,7 @@
     }
 
     @Test
-    public void updateSummary_shouldDisplayUsedPercentAndFreeSpace() {
+    public void updateSummary_shouldDisplayUsedPercentAndFreeSpace() throws Exception {
         final SummaryLoader loader = mock(SummaryLoader.class);
         final SummaryLoader.SummaryProvider provider =
                 StorageSettings.SUMMARY_PROVIDER_FACTORY.createSummaryProvider(mActivity, loader);
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 7d1f79b..47faf92 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
@@ -190,6 +190,24 @@
     }
 
     @Test
+    public void testClickMovies() {
+        mPreference.setKey("pref_movies");
+        mController.handlePreferenceTreeClick(mPreference);
+
+        final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
+        verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
+                any(UserHandle.class));
+
+        Intent intent = argumentCaptor.getValue();
+        assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
+        assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
+        assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT)).isEqualTo(
+                ManageApplications.class.getName());
+        assertThat(intent.getIntExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, 0))
+                .isEqualTo(R.string.storage_movies_tv);
+    }
+
+    @Test
     public void testClickSystem() {
         mPreference.setKey("pref_system");
         assertThat(mController.handlePreferenceTreeClick(mPreference)).isTrue();
@@ -203,6 +221,7 @@
         StorageItemPreference audio = new StorageItemPreference(mContext);
         StorageItemPreference image = new StorageItemPreference(mContext);
         StorageItemPreference games = new StorageItemPreference(mContext);
+        StorageItemPreference movies = new StorageItemPreference(mContext);
         StorageItemPreference apps = new StorageItemPreference(mContext);
         StorageItemPreference system = new StorageItemPreference(mContext);
         StorageItemPreference files = new StorageItemPreference(mContext);
@@ -214,6 +233,8 @@
         when(screen.findPreference(
                 eq(StorageItemPreferenceController.GAME_KEY))).thenReturn(games);
         when(screen.findPreference(
+                eq(StorageItemPreferenceController.MOVIES_KEY))).thenReturn(movies);
+        when(screen.findPreference(
                 eq(StorageItemPreferenceController.OTHER_APPS_KEY))).thenReturn(apps);
         when(screen.findPreference(
                 eq(StorageItemPreferenceController.SYSTEM_KEY))).thenReturn(system);
@@ -224,6 +245,7 @@
         mController.setSystemSize(KILOBYTE * 6);
         StorageAsyncLoader.AppsStorageResult result = new StorageAsyncLoader.AppsStorageResult();
         result.gamesSize = KILOBYTE * 8;
+        result.videoAppsSize = KILOBYTE * 16;
         result.musicAppsSize = KILOBYTE * 4;
         result.otherAppsSize = KILOBYTE * 9;
         result.systemSize = KILOBYTE * 10;
@@ -240,6 +262,7 @@
         assertThat(audio.getSummary().toString()).isEqualTo("14.00KB"); // 4KB apps + 10KB files
         assertThat(image.getSummary().toString()).isEqualTo("35.00KB"); // 15KB video + 20KB images
         assertThat(games.getSummary().toString()).isEqualTo("8.00KB");
+        assertThat(movies.getSummary().toString()).isEqualTo("16.00KB");
         assertThat(apps.getSummary().toString()).isEqualTo("9.00KB");
         assertThat(system.getSummary().toString()).isEqualTo("16.00KB");
         assertThat(files.getSummary().toString()).isEqualTo("5.00KB");
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
index 03892a3..801034c 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
@@ -17,7 +17,18 @@
 package com.android.settings.fuelgauge;
 
 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.anyLong;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doAnswer;
+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 android.app.Activity;
 import android.app.Fragment;
 import android.content.Context;
 import android.content.pm.ApplicationInfo;
@@ -25,12 +36,12 @@
 import android.graphics.drawable.Drawable;
 import android.os.BatteryStats;
 import android.os.Bundle;
-import android.os.UserHandle;
 import android.view.View;
 
 import com.android.internal.os.BatterySipper;
 import com.android.internal.os.BatteryStatsHelper;
 import com.android.settings.SettingsActivity;
+import com.android.settings.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.applications.AppHeaderController;
 import com.android.settings.applications.LayoutPreference;
@@ -46,22 +57,10 @@
 import org.mockito.MockitoAnnotations;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
-import org.robolectric.RobolectricTestRunner;
 import org.robolectric.annotation.Config;
 import org.robolectric.util.ReflectionHelpers;
 
-import static org.mockito.Matchers.anyLong;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-
-@RunWith(RobolectricTestRunner.class)
+@RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public class AdvancedPowerUsageDetailTest {
     private static final String APP_LABEL = "app label";
@@ -77,6 +76,8 @@
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Context mContext;
+    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    private Activity mActivity;
     @Mock
     private AppHeaderController mAppHeaderController;
     @Mock
@@ -86,8 +87,6 @@
     @Mock
     private ApplicationsState.AppEntry mAppEntry;
     @Mock
-    private Drawable mIconDrawable;
-    @Mock
     private Bundle mBundle;
     @Mock
     private BatteryEntry mBatteryEntry;
@@ -111,6 +110,7 @@
 
         mFragment = spy(new AdvancedPowerUsageDetail());
         doReturn(mContext).when(mFragment).getContext();
+        doReturn(mActivity).when(mFragment).getActivity();
         doReturn(SUMMARY).when(mFragment).getString(anyInt());
         doReturn(APP_LABEL).when(mBundle).getString(anyString());
         doReturn(mBundle).when(mFragment).getArguments();
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
index 0813478..4f48945 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
@@ -23,7 +23,9 @@
 import android.os.Build;
 import android.support.v14.preference.SwitchPreference;
 
+import com.android.settings.R;
 import com.android.settings.TestConfig;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -31,9 +33,12 @@
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 
 import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -54,17 +59,18 @@
     @Mock
     private AppOpsManager mAppOpsManager;
     @Mock
-    private SwitchPreference mPreference;
-    @Mock
     private ApplicationInfo mHighApplicationInfo;
     @Mock
     private ApplicationInfo mLowApplicationInfo;
     private BackgroundActivityPreferenceController mController;
+    private SwitchPreference mPreference;
+    private Context mShadowContext;
 
     @Before
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
 
+        mShadowContext = RuntimeEnvironment.application;
         when(mContext.getPackageManager()).thenReturn(mPackageManager);
         when(mContext.getSystemService(Context.APP_OPS_SERVICE)).thenReturn(mAppOpsManager);
         when(mPackageManager.getPackagesForUid(UID_NORMAL)).thenReturn(PACKAGES_NORMAL);
@@ -77,7 +83,8 @@
         mHighApplicationInfo.targetSdkVersion = Build.VERSION_CODES.O;
         mLowApplicationInfo.targetSdkVersion = Build.VERSION_CODES.L;
 
-        mController = new BackgroundActivityPreferenceController(mContext, UID_NORMAL);
+        mPreference = new SwitchPreference(mShadowContext);
+        mController = spy(new BackgroundActivityPreferenceController(mContext, UID_NORMAL));
         mController.isAvailable();
     }
 
@@ -87,14 +94,16 @@
 
         verify(mAppOpsManager).setMode(AppOpsManager.OP_RUN_IN_BACKGROUND, UID_NORMAL,
                 mController.getTargetPackage(), AppOpsManager.MODE_ALLOWED);
+        verify(mController).updateSummary(mPreference);
     }
 
     @Test
     public void testOnPreferenceChange_TurnOffCheck_MethodInvoked() {
-        mController.onPreferenceChange(null, false);
+        mController.onPreferenceChange(mPreference, false);
 
         verify(mAppOpsManager).setMode(AppOpsManager.OP_RUN_IN_BACKGROUND, UID_NORMAL,
                 mController.getTargetPackage(), AppOpsManager.MODE_IGNORED);
+        verify(mController).updateSummary(mPreference);
     }
 
     @Test
@@ -105,7 +114,8 @@
 
         mController.updateState(mPreference);
 
-        verify(mPreference).setChecked(true);
+        assertThat(mPreference.isChecked()).isTrue();
+        verify(mController).updateSummary(mPreference);
     }
 
     @Test
@@ -116,7 +126,46 @@
 
         mController.updateState(mPreference);
 
-        verify(mPreference).setChecked(false);
+        assertThat(mPreference.isChecked()).isFalse();
+        verify(mController).updateSummary(mPreference);
+    }
+
+    @Test
+    public void testUpdateSummary_modeError_showSummaryDisabled() {
+        when(mAppOpsManager
+                .checkOpNoThrow(AppOpsManager.OP_RUN_IN_BACKGROUND, UID_NORMAL, LOW_SDK_PACKAGE))
+                .thenReturn(AppOpsManager.MODE_ERRORED);
+        final CharSequence expectedSummary = mShadowContext.getText(
+                R.string.background_activity_summary_disabled);
+        mController.updateSummary(mPreference);
+
+        assertThat(mPreference.getSummary()).isEqualTo(expectedSummary);
+    }
+
+    @Test
+    public void testUpdateSummary_modeDefault_showSummaryOn() {
+        when(mAppOpsManager
+                .checkOpNoThrow(AppOpsManager.OP_RUN_IN_BACKGROUND, UID_NORMAL, LOW_SDK_PACKAGE))
+                .thenReturn(AppOpsManager.MODE_DEFAULT);
+        final CharSequence expectedSummary = mShadowContext.getText(
+                R.string.background_activity_summary_on);
+
+        mController.updateSummary(mPreference);
+
+        assertThat(mPreference.getSummary()).isEqualTo(expectedSummary);
+    }
+
+    @Test
+    public void testUpdateSummary_modeIgnored_showSummaryOff() {
+        when(mAppOpsManager
+                .checkOpNoThrow(AppOpsManager.OP_RUN_IN_BACKGROUND, UID_NORMAL, LOW_SDK_PACKAGE))
+                .thenReturn(AppOpsManager.MODE_IGNORED);
+        final CharSequence expectedSummary = mShadowContext.getText(
+                R.string.background_activity_summary_off);
+
+        mController.updateSummary(mPreference);
+
+        assertThat(mPreference.getSummary()).isEqualTo(expectedSummary);
     }
 
     @Test
@@ -144,6 +193,6 @@
 
         assertThat(available).isTrue();
         // Should get status from LOW_SDK_PACKAGE
-        verify(mPreference).setChecked(true);
+        assertThat(mPreference.isChecked()).isTrue();
     }
 }
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java
new file mode 100644
index 0000000..799dab9
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.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.fuelgauge;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.BatteryManager;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.Utils;
+
+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 static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class BatteryBroadcastReceiverTest {
+    private static final String BATTERY_INIT_LEVEL = "100%";
+    private static final String BATTERY_INIT_STATUS = "Not charging";
+    private static final int BATTERY_INTENT_LEVEL = 80;
+    private static final int BATTERY_INTENT_SCALE = 100;
+
+    @Mock
+    private BatteryBroadcastReceiver.OnBatteryChangedListener mBatteryListener;
+    private BatteryBroadcastReceiver mBatteryBroadcastReceiver;
+    private Context mContext;
+    private Intent mChargingIntent;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = RuntimeEnvironment.application;
+
+        mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(mContext);
+        mBatteryBroadcastReceiver.mBatteryLevel = BATTERY_INIT_LEVEL;
+        mBatteryBroadcastReceiver.mBatteryStatus = BATTERY_INIT_STATUS;
+        mBatteryBroadcastReceiver.setBatteryChangedListener(mBatteryListener);
+
+        mChargingIntent = new Intent(Intent.ACTION_BATTERY_CHANGED);
+        mChargingIntent.putExtra(BatteryManager.EXTRA_LEVEL, BATTERY_INTENT_LEVEL);
+        mChargingIntent.putExtra(BatteryManager.EXTRA_SCALE, BATTERY_INTENT_SCALE);
+        mChargingIntent.putExtra(BatteryManager.EXTRA_STATUS,
+                BatteryManager.BATTERY_STATUS_CHARGING);
+    }
+
+    @Test
+    public void testOnReceive_batteryDataChanged_dataUpdated() {
+        mBatteryBroadcastReceiver.onReceive(mContext, mChargingIntent);
+
+        assertThat(mBatteryBroadcastReceiver.mBatteryLevel).isEqualTo(
+                Utils.getBatteryPercentage(mChargingIntent));
+        assertThat(mBatteryBroadcastReceiver.mBatteryStatus).isEqualTo(
+                Utils.getBatteryStatus(mContext.getResources(), mChargingIntent));
+        verify(mBatteryListener).onBatteryChanged();
+    }
+
+    @Test
+    public void testOnReceive_batteryDataNotChanged_listenerNotInvoked() {
+        final String batteryLevel = Utils.getBatteryPercentage(mChargingIntent);
+        final String batteryStatus = Utils.getBatteryStatus(mContext.getResources(),
+                mChargingIntent);
+        mBatteryBroadcastReceiver.mBatteryLevel = batteryLevel;
+        mBatteryBroadcastReceiver.mBatteryStatus = batteryStatus;
+
+        mBatteryBroadcastReceiver.onReceive(mContext, mChargingIntent);
+
+        assertThat(mBatteryBroadcastReceiver.mBatteryLevel).isEqualTo(batteryLevel);
+        assertThat(mBatteryBroadcastReceiver.mBatteryStatus).isEqualTo(batteryStatus);
+        verify(mBatteryListener, never()).onBatteryChanged();
+    }
+
+}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java
index 85b893a..cb37a6e 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java
@@ -15,12 +15,17 @@
  */
 package com.android.settings.fuelgauge;
 
+import static com.google.common.truth.Truth.assertThat;
+
 import android.content.Context;
+import android.graphics.ColorFilter;
+
 import com.android.settings.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.shadow.SettingsShadowResources;
 import com.android.settings.testutils.shadow.SettingsShadowResources.SettingsShadowTheme;
 import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -29,6 +34,8 @@
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 
 @RunWith(SettingsRobolectricTestRunner.class)
@@ -42,10 +49,15 @@
         })
 public class BatteryMeterViewTest {
     private static final int BATTERY_LEVEL = 100;
+    private static final int BATTERY_CRITICAL_LEVEL = 15;
+    private static final int BATTERY_LOW_LEVEL = 3;
     @Mock
-    private BatteryMeterView.BatteryMeterDrawable mDrawable;
+    private ColorFilter mErrorColorFilter;
+    @Mock
+    private ColorFilter mAccentColorFilter;
     private Context mContext;
     private BatteryMeterView mBatteryMeterView;
+    private BatteryMeterView.BatteryMeterDrawable mDrawable;
 
     @Before
     public void setUp() {
@@ -53,13 +65,33 @@
 
         mContext = RuntimeEnvironment.application;
         mBatteryMeterView = new BatteryMeterView(mContext);
-        mBatteryMeterView.setBatteryDrawable(mDrawable);
+        mDrawable = spy(new BatteryMeterView.BatteryMeterDrawable(mContext, 0));
+
+        mBatteryMeterView.mDrawable = mDrawable;
+        mBatteryMeterView.mAccentColorFilter = mAccentColorFilter;
+        mBatteryMeterView.mErrorColorFilter = mErrorColorFilter;
+
+        doReturn(BATTERY_CRITICAL_LEVEL).when(mDrawable).getCriticalLevel();
     }
 
     @Test
-    public void testSetBatteryInfo_SetCorrectly() {
-        mBatteryMeterView.setBatteryInfo(BATTERY_LEVEL);
+    public void testSetBatteryInfo_setCorrectly() {
+        mBatteryMeterView.setBatteryLevel(BATTERY_LEVEL);
 
-        verify(mDrawable).setBatteryLevel(BATTERY_LEVEL);
+        assertThat(mDrawable.getBatteryLevel()).isEqualTo(BATTERY_LEVEL);
+    }
+
+    @Test
+    public void testSetBatteryInfo_levelLow_setErrorColor() {
+        mBatteryMeterView.setBatteryLevel(BATTERY_LOW_LEVEL);
+
+        verify(mDrawable).setBatteryColorFilter(mErrorColorFilter);
+    }
+
+    @Test
+    public void testSetBatteryInfo_levelNormal_setNormalColor() {
+        mBatteryMeterView.setBatteryLevel(BATTERY_LEVEL);
+
+        verify(mDrawable).setBatteryColorFilter(mAccentColorFilter);
     }
 }
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
index 4216d57..3f87bb4 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
@@ -228,22 +228,36 @@
     public void testShouldHide_typeUnAccounted_returnTrue() {
         mPowerUsageData.usageType = UsageType.UNACCOUNTED;
 
-        assertThat(mPowerUsageAdvanced.shouldHide(mPowerUsageData)).isTrue();
+        assertThat(mPowerUsageAdvanced.shouldHideCategory(mPowerUsageData)).isTrue();
     }
 
 
     @Test
-    public void testShouldHide_typeOverCounted_returnTrue() {
+    public void testShouldHideCategory_typeOverCounted_returnTrue() {
         mPowerUsageData.usageType = UsageType.OVERCOUNTED;
 
-        assertThat(mPowerUsageAdvanced.shouldHide(mPowerUsageData)).isTrue();
+        assertThat(mPowerUsageAdvanced.shouldHideCategory(mPowerUsageData)).isTrue();
     }
 
-
     @Test
-    public void testShouldHide_typeNormal_returnFalse() {
+    public void testShouldHideCategory_typeNormal_returnFalse() {
         mPowerUsageData.usageType = UsageType.APP;
 
-        assertThat(mPowerUsageAdvanced.shouldHide(mPowerUsageData)).isFalse();
+        assertThat(mPowerUsageAdvanced.shouldHideCategory(mPowerUsageData)).isFalse();
     }
+
+    @Test
+    public void testShouldHideSummary_typeCell_returnTrue() {
+        mPowerUsageData.usageType = UsageType.CELL;
+
+        assertThat(mPowerUsageAdvanced.shouldHideSummary(mPowerUsageData)).isTrue();
+    }
+
+    @Test
+    public void testShouldHideSummary_typeNormal_returnFalse() {
+        mPowerUsageData.usageType = UsageType.APP;
+
+        assertThat(mPowerUsageAdvanced.shouldHideSummary(mPowerUsageData)).isFalse();
+    }
+
 }
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
index 72dd28e..39c386b 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
@@ -37,6 +37,8 @@
 import com.android.settings.Utils;
 import com.android.settings.applications.LayoutPreference;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
+import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
 import com.android.settingslib.BatteryInfo;
 
 import org.junit.Before;
@@ -74,7 +76,13 @@
  */
 // TODO: Improve this test class so that it starts up the real activity and fragment.
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH,
+        sdk = TestConfig.SDK_VERSION,
+        shadows = {
+                SettingsShadowResources.class,
+                SettingsShadowResources.SettingsShadowTheme.class,
+                ShadowDynamicIndexableContentMonitor.class
+        })
 public class PowerUsageSummaryTest {
     private static final String[] PACKAGE_NAMES = {"com.app1", "com.app2"};
     private static final String TIME_LEFT = "2h30min";
@@ -119,8 +127,6 @@
     @Mock
     private LayoutPreference mBatteryLayoutPref;
     @Mock
-    private BatteryMeterView mBatteryMeterView;
-    @Mock
     private TextView mBatteryPercentText;
     @Mock
     private TextView mSummary1;
@@ -141,6 +147,7 @@
     private Context mRealContext;
     private TestFragment mFragment;
     private FakeFeatureFactory mFeatureFactory;
+    private BatteryMeterView mBatteryMeterView;
 
     @Before
     public void setUp() {
@@ -153,6 +160,8 @@
 
         mFragment = spy(new TestFragment(mContext));
         mFragment.initFeatureProvider();
+        mBatteryMeterView = new BatteryMeterView(mRealContext);
+        mBatteryMeterView.mDrawable = new BatteryMeterView.BatteryMeterDrawable(mRealContext, 0);
 
         when(mFragment.getActivity()).thenReturn(mSettingsActivity);
         when(mAdditionalBatteryInfoMenu.getItemId())
@@ -192,7 +201,7 @@
         mFragment.mScreenUsagePref = mScreenUsagePref;
         mFragment.mLastFullChargePref = mLastFullChargePref;
 
-        mBatteryInfo.mBatteryLevel = BATTERY_LEVEL;
+        mBatteryInfo.batteryLevel = BATTERY_LEVEL;
     }
 
     @Test
@@ -317,6 +326,18 @@
     }
 
     @Test
+    public void testUpdatePreference_updateBatteryInfo() {
+        mBatteryInfo.remainingLabel = TIME_LEFT;
+        mBatteryInfo.batteryLevel = BATTERY_LEVEL;
+        mBatteryInfo.discharging = true;
+
+        mFragment.updateHeaderPreference(mBatteryInfo);
+
+        assertThat(mBatteryMeterView.mDrawable.getBatteryLevel()).isEqualTo(BATTERY_LEVEL);
+        assertThat(mBatteryMeterView.mDrawable.getCharging()).isEqualTo(false);
+    }
+
+    @Test
     public void testUpdatePreference_noRemainingTime_showStatusLabel() {
         mBatteryInfo.remainingLabel = null;
 
diff --git a/tests/robotests/src/com/android/settings/network/NetworkResetActionMenuControllerTest.java b/tests/robotests/src/com/android/settings/network/NetworkResetActionMenuControllerTest.java
index 7cd76d3..ee6ef69 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkResetActionMenuControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkResetActionMenuControllerTest.java
@@ -19,9 +19,7 @@
 
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyInt;
-import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -39,6 +37,7 @@
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@@ -50,19 +49,21 @@
     private Menu mMenu;
     @Mock
     private MenuItem mMenuItem;
+    @Mock
+    private NetworkResetRestrictionChecker mRestrictionChecker;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         mContext = RuntimeEnvironment.application;
-        mController = spy(new NetworkResetActionMenuController(mContext));
+        mController = new NetworkResetActionMenuController(mContext);
+        ReflectionHelpers.setField(mController, "mRestrictionChecker", mRestrictionChecker);
         when(mMenu.add(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(mMenuItem);
     }
 
     @Test
     public void buildMenuItem_available_shouldAddToMenu() {
-        doReturn(true).when(mController).isAvailable();
-
+        when(mRestrictionChecker.hasRestriction()).thenReturn(false);
         mController.buildMenuItem(mMenu);
 
         verify(mMenu).add(anyInt(), anyInt(), anyInt(), anyInt());
@@ -71,7 +72,7 @@
 
     @Test
     public void buildMenuItem_notAvailable_shouldNotAddToMenu() {
-        doReturn(false).when(mController).isAvailable();
+        when(mRestrictionChecker.hasRestriction()).thenReturn(true);
 
         mController.buildMenuItem(mMenu);
 
diff --git a/tests/robotests/src/com/android/settings/network/NetworkResetRestrictionCheckerTest.java b/tests/robotests/src/com/android/settings/network/NetworkResetRestrictionCheckerTest.java
new file mode 100644
index 0000000..b1c88d5
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/NetworkResetRestrictionCheckerTest.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.network;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.os.UserManager;
+
+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.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class NetworkResetRestrictionCheckerTest {
+
+    @Mock
+    private UserManager mUserManager;
+    @Mock
+    private Context mContext;
+    private NetworkResetRestrictionChecker mRestrictionChecker;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
+        mRestrictionChecker = spy(new NetworkResetRestrictionChecker(mContext));
+    }
+
+    @Test
+    public void testHasRestriction_notAdmin_shouldReturnTrue() {
+        final Context context = mock(Context.class);
+        when(context.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
+        when(mUserManager.isAdminUser()).thenReturn(false);
+
+        assertThat(mRestrictionChecker.hasRestriction()).isTrue();
+    }
+
+    @Test
+    public void testHasRestriction_hasUserRestriction_shouldReturnTrue() {
+        when(mUserManager.isAdminUser()).thenReturn(true);
+        doReturn(true).when(mRestrictionChecker).hasUserBaseRestriction();
+        doReturn(false).when(mRestrictionChecker).isRestrictionEnforcedByAdmin();
+
+        assertThat(mRestrictionChecker.hasRestriction()).isTrue();
+    }
+
+    @Test
+    public void testHasRestriction_hasAdminRestriction_shouldReturnTrue() {
+        when(mUserManager.isAdminUser()).thenReturn(true);
+        doReturn(false).when(mRestrictionChecker).hasUserBaseRestriction();
+        doReturn(true).when(mRestrictionChecker).isRestrictionEnforcedByAdmin();
+
+        assertThat(mRestrictionChecker.hasRestriction()).isTrue();
+    }
+
+    @Test
+    public void testHasRestriction_noRestriction_shouldReturnFalse() {
+        when(mUserManager.isAdminUser()).thenReturn(true);
+        doReturn(false).when(mRestrictionChecker).hasUserBaseRestriction();
+        doReturn(false).when(mRestrictionChecker).isRestrictionEnforcedByAdmin();
+
+        assertThat(mRestrictionChecker.hasRestriction()).isFalse();
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java b/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java
index e87e9c5..724909d 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java
@@ -5,9 +5,12 @@
 import android.content.res.Resources.NotFoundException;
 import android.content.res.Resources.Theme;
 import android.content.res.TypedArray;
+import android.graphics.Color;
 import android.graphics.drawable.ColorDrawable;
 import android.graphics.drawable.Drawable;
 import android.support.annotation.ArrayRes;
+import android.support.annotation.ColorRes;
+import android.support.annotation.Nullable;
 import android.util.AttributeSet;
 import android.util.TypedValue;
 
@@ -53,6 +56,14 @@
     }
 
     @Implementation
+    public int getColor(@ColorRes int id, @Nullable Theme theme) throws NotFoundException {
+        if (id == R.color.battery_icon_color_error) {
+            return Color.WHITE;
+        }
+        return directlyOn(realResources, Resources.class).getColor(id, theme);
+    }
+
+    @Implementation
     public Drawable loadDrawable(TypedValue value, int id, Theme theme)
             throws NotFoundException {
         // The drawable item in switchbar_background.xml refers to a very recent color attribute
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
index d6243ac..7df5c9a 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
@@ -17,6 +17,7 @@
 package com.android.settings.wifi;
 
 import static android.provider.Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED;
+import static android.provider.Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE;
 import static android.provider.Settings.Global.WIFI_WAKEUP_ENABLED;
 
 import static com.google.common.truth.Truth.assertThat;
@@ -29,6 +30,7 @@
 import android.support.v14.preference.SwitchPreference;
 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.core.lifecycle.Lifecycle;
@@ -52,6 +54,7 @@
         MockitoAnnotations.initMocks(this);
         mContext = RuntimeEnvironment.application;
         mController = new WifiWakeupPreferenceController(mContext, mock(Lifecycle.class));
+        Settings.System.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 1);
     }
 
     @Test
@@ -95,6 +98,7 @@
 
         verify(preference).setChecked(true);
         verify(preference).setEnabled(true);
+        verify(preference).setSummary(R.string.wifi_wakeup_summary);
     }
 
     @Test
@@ -107,5 +111,20 @@
 
         verify(preference).setChecked(false);
         verify(preference).setEnabled(false);
+        verify(preference).setSummary(R.string.wifi_wakeup_summary);
+    }
+
+    @Test
+    public void updateState_preferenceSetUncheckedAndSetDisabledWhenWifiScanningDisabled() {
+        final SwitchPreference preference = mock(SwitchPreference.class);
+        Settings.System.putInt(mContext.getContentResolver(), NETWORK_RECOMMENDATIONS_ENABLED, 1);
+        Settings.System.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
+        Settings.System.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 0);
+
+        mController.updateState(preference);
+
+        verify(preference).setChecked(true);
+        verify(preference).setEnabled(false);
+        verify(preference).setSummary(R.string.wifi_wakeup_summary_scanning_disabled);
     }
 }
diff --git a/tests/unit/src/com/android/settings/WallpaperPreferenceLayoutTest.java b/tests/unit/src/com/android/settings/WallpaperPreferenceLayoutTest.java
deleted file mode 100644
index 4448307..0000000
--- a/tests/unit/src/com/android/settings/WallpaperPreferenceLayoutTest.java
+++ /dev/null
@@ -1,34 +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;
-
-import android.support.test.InstrumentationRegistry;
-import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
-import android.view.LayoutInflater;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@SmallTest
-@RunWith(AndroidJUnit4.class)
-public class WallpaperPreferenceLayoutTest {
-    @Test
-    public void testInflateWallpaperPreferenceLayout_doesNotCrash() {
-      LayoutInflater.from(InstrumentationRegistry.getTargetContext())
-          .inflate(R.layout.preference_wallpaper_type, null, false);
-    }
-}
diff --git a/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java b/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java
index 617e9bb..546ea4b 100644
--- a/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java
+++ b/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java
@@ -169,8 +169,33 @@
         assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(11L);
     }
 
-    private ApplicationInfo addPackage(
-            String packageName, long cacheSize, long codeSize, long dataSize, int category) {
+    @Test
+    public void testVideoAppsAreFiltered() throws Exception {
+        addPackage(PACKAGE_NAME_1, 0, 1, 10, ApplicationInfo.CATEGORY_VIDEO);
+
+        SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
+
+        assertThat(result.size()).isEqualTo(1);
+        assertThat(result.get(PRIMARY_USER_ID).videoAppsSize).isEqualTo(11L);
+        assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(0);
+    }
+
+    @Test
+    public void testRemovedPackageDoesNotCrash() throws Exception {
+        ApplicationInfo info = new ApplicationInfo();
+        info.packageName = PACKAGE_NAME_1;
+        info.category = ApplicationInfo.CATEGORY_UNDEFINED;
+        mInfo.add(info);
+        when(mSource.getStatsForPackage(anyString(), anyString(), any(UserHandle.class)))
+                .thenThrow(new IllegalStateException());
+
+        SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
+
+        // Should not crash.
+    }
+
+    private ApplicationInfo addPackage(String packageName, long cacheSize, long codeSize,
+            long dataSize, int category) throws Exception {
         StorageStatsSource.AppStorageStats storageStats =
                 mock(StorageStatsSource.AppStorageStats.class);
         when(storageStats.getCodeBytes()).thenReturn(codeSize);
diff --git a/tests/unit/src/com/android/settings/display/NightDisplaySettingsActivityTest.java b/tests/unit/src/com/android/settings/display/NightDisplaySettingsActivityTest.java
new file mode 100644
index 0000000..4011d9a
--- /dev/null
+++ b/tests/unit/src/com/android/settings/display/NightDisplaySettingsActivityTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.display;
+
+import android.app.Instrumentation;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.provider.Settings;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+
+import com.android.settings.Settings.NightDisplaySettingsActivity;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class NightDisplaySettingsActivityTest {
+
+    private Context mTargetContext;
+
+    @Before
+    public void setUp() throws Exception {
+        Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
+        mTargetContext = instrumentation.getTargetContext();
+    }
+
+    @Test
+    public void nightDisplaySettingsIntent_resolvesCorrectly() {
+        final boolean nightDisplayAvailable = mTargetContext.getResources().getBoolean(
+                com.android.internal.R.bool.config_nightDisplayAvailable);
+        final PackageManager pm = mTargetContext.getPackageManager();
+        final Intent intent = new Intent(Settings.ACTION_NIGHT_DISPLAY_SETTINGS);
+        final ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
+
+        if (nightDisplayAvailable) {
+            Assert.assertNotNull("No activity for " + Settings.ACTION_NIGHT_DISPLAY_SETTINGS, ri);
+            Assert.assertEquals(mTargetContext.getPackageName(), ri.activityInfo.packageName);
+            Assert.assertEquals(NightDisplaySettingsActivity.class.getName(),
+                    ri.activityInfo.name);
+        } else {
+            Assert.assertNull("Should have no activity for "
+                    + Settings.ACTION_NIGHT_DISPLAY_SETTINGS, ri);
+        }
+    }
+
+}