Merge "Renamed "Demo mode" to "System UI demo mode""
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 87b6372..f4a972b 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -758,11 +758,6 @@
                   android:icon="@drawable/ic_settings_notifications"
                   android:exported="true"
                   android:taskAffinity="">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.DEFAULT" />
-                <category android:name="com.android.settings.SHORTCUT" />
-            </intent-filter>
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                        android:value="com.android.settings.notification.ZenModeVisualInterruptionSettings" />
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -778,11 +773,6 @@
                 <action android:name="android.settings.ZEN_MODE_PRIORITY_SETTINGS" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.DEFAULT" />
-                <category android:name="com.android.settings.SHORTCUT" />
-            </intent-filter>
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                 android:value="com.android.settings.notification.ZenModePrioritySettings" />
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -802,11 +792,6 @@
                 <action android:name="android.settings.ACTION_CONDITION_PROVIDER_SETTINGS" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.DEFAULT" />
-                <category android:name="com.android.settings.SHORTCUT" />
-            </intent-filter>
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                 android:value="com.android.settings.notification.ZenModeAutomationSettings" />
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -950,11 +935,6 @@
                 <action android:name="android.settings.NIGHT_DISPLAY_SETTINGS" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.DEFAULT" />
-                <category android:name="com.android.settings.SHORTCUT" />
-            </intent-filter>
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                 android:value="com.android.settings.display.NightDisplaySettings" />
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -1343,11 +1323,6 @@
                 <action android:name="com.android.settings.TRUSTED_CREDENTIALS_USER" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.DEFAULT" />
-                <category android:name="com.android.settings.SHORTCUT" />
-            </intent-filter>
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                 android:value="com.android.settings.TrustedCredentialsSettings" />
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -2293,11 +2268,6 @@
                 <action android:name="android.settings.BATTERY_SAVER_SETTINGS" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.DEFAULT" />
-                <category android:name="com.android.settings.SHORTCUT" />
-            </intent-filter>
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                 android:value="com.android.settings.fuelgauge.BatterySaverSettings" />
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
diff --git a/res/layout/battery_usage_graph.xml b/res/layout/battery_usage_graph.xml
index 79a64a9..bd6e7a5 100644
--- a/res/layout/battery_usage_graph.xml
+++ b/res/layout/battery_usage_graph.xml
@@ -18,7 +18,7 @@
     xmlns:settings="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+    android:paddingStart="@dimen/preference_no_icon_padding_start"
     android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
     android:orientation="vertical">
 
diff --git a/res/layout/horizontal_preference.xml b/res/layout/horizontal_preference.xml
index 722e053..b5871d9 100644
--- a/res/layout/horizontal_preference.xml
+++ b/res/layout/horizontal_preference.xml
@@ -21,7 +21,7 @@
     android:layout_height="wrap_content"
     android:orientation="horizontal"
     android:paddingTop="1dp"
-    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+    android:paddingStart="@dimen/preference_no_icon_padding_start"
     android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
 
     <TextView
diff --git a/res/layout/master_clear.xml b/res/layout/master_clear.xml
index 5d844b1..662b7db 100644
--- a/res/layout/master_clear.xml
+++ b/res/layout/master_clear.xml
@@ -21,6 +21,7 @@
     >
 
     <ScrollView
+            android:id="@+id/master_clear_scrollview"
             android:layout_width="match_parent"
             android:layout_height="0dip"
             android:layout_marginStart="12dp"
diff --git a/res/layout/preference_bt_icon.xml b/res/layout/preference_bt_icon.xml
deleted file mode 100644
index 8f8b532..0000000
--- a/res/layout/preference_bt_icon.xml
+++ /dev/null
@@ -1,75 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2014 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/listPreferredItemHeightSmall"
-    android:gravity="center_vertical"
-    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
-    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
-    android:background="?android:attr/selectableItemBackground">
-
-    <ImageView
-        android:id="@android:id/icon"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_marginStart="6dip"
-        android:layout_marginEnd="6dip"
-        android:layout_gravity="center"
-        android:contentDescription="@null" />
-
-    <RelativeLayout
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_weight="1"
-        android:layout_marginStart="15dip"
-        android:paddingTop="16dip"
-        android:paddingBottom="16dip">
-
-        <TextView
-            android:id="@android:id/title"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:singleLine="true"
-            android:textAppearance="@android:style/TextAppearance.Material.Subhead"
-            android:textColor="?android:attr/textColorPrimary"
-            android:ellipsize="marquee"
-            android:fadingEdge="horizontal" />
-
-        <TextView
-            android:id="@android:id/summary"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_below="@android:id/title"
-            android:layout_alignStart="@android:id/title"
-            android:visibility="gone"
-            android:textAlignment="viewStart"
-            android:textAppearance="@android:style/TextAppearance.Material.Body1"
-            android:textColor="?android:attr/textColorSecondary"
-            android:maxLines="10" />
-
-    </RelativeLayout>
-
-    <LinearLayout
-        android:id="@android:id/widget_frame"
-        android:layout_width="wrap_content"
-        android:layout_height="match_parent"
-        android:minWidth="58dip"
-        android:gravity="end|center_vertical"
-        android:orientation="vertical" />
-
-</LinearLayout>
diff --git a/res/layout/preference_category_material_settings.xml b/res/layout/preference_category_material_settings.xml
index 13cefdb..2a25bbc 100644
--- a/res/layout/preference_category_material_settings.xml
+++ b/res/layout/preference_category_material_settings.xml
@@ -35,6 +35,7 @@
             android:id="@android:id/icon"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
+            android:tint="?android:attr/textColorPrimary"
             android:maxWidth="18dp"
             android:maxHeight="18dp"/>
     </LinearLayout>
diff --git a/res/layout/preference_category_short.xml b/res/layout/preference_category_short.xml
deleted file mode 100644
index 452d0bc..0000000
--- a/res/layout/preference_category_short.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2016 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-
-<!-- Layout used for PreferenceCategory in a PreferenceActivity. -->
-<TextView xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@android:id/title"
-    android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:layout_marginBottom="0dp"
-    android:textAppearance="@android:style/TextAppearance.Material.Body2"
-    android:textColor="?android:attr/colorAccent"
-    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
-    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
-    android:paddingTop="16dip" />
diff --git a/res/layout/preference_progress_category.xml b/res/layout/preference_progress_category.xml
index 6ed6df3..1380698 100644
--- a/res/layout/preference_progress_category.xml
+++ b/res/layout/preference_progress_category.xml
@@ -16,37 +16,46 @@
 
 <!-- Layout used for ProgressCategory in bluetooth settings. -->
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    style="?android:attr/listSeparatorTextViewStyle"
-    android:background="@null"
-    android:gravity="center_vertical"
-    android:orientation="horizontal"
-    android:layout_height="wrap_content"
-    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
-    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" >
+              android:layout_width="match_parent"
+              android:layout_height="wrap_content"
+              android:gravity="center_vertical"
+              android:orientation="horizontal"
+              android:layout_marginBottom="16dp"
+              android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+              android:paddingTop="16dp"
+              android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
+
+    <LinearLayout
+        android:id="@+id/icon_container"
+        android:layout_width="60dp"
+        android:layout_height="wrap_content"
+        android:gravity="start|center_vertical"
+        android:orientation="horizontal">
+        <com.android.internal.widget.PreferenceImageView
+            android:id="@android:id/icon"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:tint="?android:attr/textColorPrimary"
+            android:maxWidth="18dp"
+            android:maxHeight="18dp"/>
+    </LinearLayout>
 
     <!-- This text view has the style of the list separator text view without the background and padding. -->
     <TextView
-        android:textAppearance="@android:style/TextAppearance.Material.Body2"
-        android:textColor="?android:attr/colorAccent"
-        android:background="@null"
         android:id="@android:id/title"
-        android:paddingStart="0dp"
-        android:paddingTop="6dp"
         android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_weight="1"
         android:layout_gravity="start|center"
-    />
+        android:textAppearance="@android:style/TextAppearance.Material.Body2"/>
 
     <ProgressBar
         android:id="@+id/scanning_progress"
-        android:text="@string/progress_scanning"
-        android:paddingTop="6dp"
+        style="?android:attr/progressBarStyleSmallTitle"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_gravity="center_vertical"
         android:layout_marginStart="16dip"
-        style="?android:attr/progressBarStyleSmallTitle"
-        />
+        android:text="@string/progress_scanning"/>
 
 </LinearLayout>
diff --git a/res/layout/running_processes_header.xml b/res/layout/running_processes_header.xml
index 615d30e..aa106ac 100644
--- a/res/layout/running_processes_header.xml
+++ b/res/layout/running_processes_header.xml
@@ -20,18 +20,18 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+    android:paddingStart="@dimen/preference_no_icon_padding_start"
     android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
     android:orientation="vertical">
 
     <TextView
         android:id="@+id/title"
         android:layout_width="wrap_content"
-        android:layout_height="48sp"
+        android:layout_height="48dp"
         android:singleLine="true"
         android:ellipsize="marquee"
         android:textAppearance="@android:style/TextAppearance.Material.Body2"
-        android:textColor="?android:attr/colorAccent"
+        android:textColor="?android:attr/textColorPrimary"
         android:textAlignment="viewStart"
         android:gravity="left|center_vertical"
         android:text="@string/running_processes_header_title" />
@@ -44,12 +44,12 @@
 
     <LinearLayout
         android:layout_width="match_parent"
-        android:layout_height="32sp"
-        android:layout_marginTop="8sp"
+        android:layout_height="32dp"
+        android:layout_marginTop="8dp"
         android:orientation="horizontal">
         <ImageView
-            android:layout_width="16sp"
-            android:layout_height="16sp"
+            android:layout_width="16dp"
+            android:layout_height="16dp"
             android:layout_gravity="center"
             android:scaleType="centerInside"
             android:src="@color/running_processes_system_ram"
@@ -90,11 +90,11 @@
 
     <LinearLayout
         android:layout_width="match_parent"
-        android:layout_height="32sp"
+        android:layout_height="32dp"
         android:orientation="horizontal">
         <ImageView
-            android:layout_width="16sp"
-            android:layout_height="16sp"
+            android:layout_width="16dp"
+            android:layout_height="16dp"
             android:layout_gravity="center"
             android:scaleType="centerInside"
             android:src="?android:attr/colorAccent"
@@ -135,11 +135,11 @@
 
     <LinearLayout
         android:layout_width="match_parent"
-        android:layout_height="32sp"
+        android:layout_height="32dp"
         android:orientation="horizontal">
         <ImageView
-            android:layout_width="16sp"
-            android:layout_height="16sp"
+            android:layout_width="16dp"
+            android:layout_height="16dp"
             android:layout_gravity="center"
             android:scaleType="centerInside"
             android:src="@color/running_processes_free_ram"
@@ -182,11 +182,11 @@
         android:id="@+id/listHeader"
         android:layout_width="wrap_content"
         android:layout_height="48dp"
-        android:layout_marginTop="8sp"
+        android:layout_marginTop="8dp"
         android:singleLine="true"
         android:ellipsize="marquee"
         android:textAppearance="@android:style/TextAppearance.Material.Body2"
-        android:textColor="?android:attr/colorAccent"
+        android:textColor="?android:attr/textColorPrimary"
         android:textAlignment="viewStart"
         android:gravity="left|center_vertical"
         android:text="@string/running_processes_header_footer" />
diff --git a/res/layout/settings_summary_preference.xml b/res/layout/settings_summary_preference.xml
index 7614fca..a5dee52 100644
--- a/res/layout/settings_summary_preference.xml
+++ b/res/layout/settings_summary_preference.xml
@@ -18,7 +18,7 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+    android:paddingStart="@dimen/preference_no_icon_padding_start"
     android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
     android:orientation="vertical">
 
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8696c7e..ef9cbc4 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5367,6 +5367,12 @@
     <string name="vpn_always_on_inactive">Always-on inactive</string>
     <!-- Preference summary for app not supporting always-on vpn [CHAR LIMIT=NONE] -->
     <string name="vpn_not_supported_by_this_app">Not supported by this app</string>
+    <!-- Preference title for forcing all network connections to go through VPN. -->
+    <string name="vpn_require_connection">Only allow connections through VPN</string>
+    <!-- Preference summary for network connections being forced to go through VPN. -->
+    <string name="vpn_lockdown_active">Lockdown active</string>
+    <!-- Preference summary for network connections not being forced to go through VPN. -->
+    <string name="vpn_lockdown_inactive">Lockdown inactive</string>
 
     <!-- Summary describing the always-on VPN feature. [CHAR LIMIT=NONE] -->
     <string name="vpn_lockdown_summary">Select a VPN profile to always remain connected to. Network traffic will only be allowed when connected to this VPN.</string>
@@ -6958,6 +6964,9 @@
     <!-- Label for list to control apps that ignore battery saving restrictions [CHAR LIMIT=27]-->
     <string name="high_power_apps">Battery optimization</string>
 
+    <!-- Label for menu to launch additional battery info -->
+    <string name="additional_battery_info" translatable="false">Additional battery info</string>
+
     <!-- Filter for apps allowed to use a lot of power [CHAR LIMIT=25] -->
     <string name="high_power_filter_on">Not optimized</string>
 
diff --git a/res/values/styles_preference.xml b/res/values/styles_preference.xml
index a504166..1eedd4d 100644
--- a/res/values/styles_preference.xml
+++ b/res/values/styles_preference.xml
@@ -18,6 +18,9 @@
 <!-- This file only contains custom attribute and style definition for preferences -->
 <!-- Things unrelated to preference framework UI customization should go to other styles files -->
 <resources>
+
+    <dimen name="preference_no_icon_padding_start">72dp</dimen>
+
     <style name="ApnPreference">
         <item name="android:layout">@layout/apn_preference_layout</item>
     </style>
diff --git a/res/xml/app_memory_settings.xml b/res/xml/app_memory_settings.xml
index 56d1824..53a71ff 100644
--- a/res/xml/app_memory_settings.xml
+++ b/res/xml/app_memory_settings.xml
@@ -18,8 +18,7 @@
                   android:title="@string/memory_usage">
 
     <PreferenceCategory
-        android:title="@string/average_memory_use"
-        android:layout="@layout/preference_category_short" />
+        android:title="@string/average_memory_use"/>
 
     <com.android.settings.SummaryPreference
         android:key="status_header"
diff --git a/res/xml/data_usage.xml b/res/xml/data_usage.xml
index 95e16ce..f7c66bc 100644
--- a/res/xml/data_usage.xml
+++ b/res/xml/data_usage.xml
@@ -19,8 +19,7 @@
     android:title="@string/data_usage_summary_title">
 
     <PreferenceCategory
-        android:title="@string/usage"
-        android:layout="@layout/preference_category_short">
+        android:title="@string/usage">
 
         <com.android.settings.SummaryPreference
             android:key="status_header"
diff --git a/res/xml/data_usage_list.xml b/res/xml/data_usage_list.xml
index 725105a..64df9c3 100644
--- a/res/xml/data_usage_list.xml
+++ b/res/xml/data_usage_list.xml
@@ -18,8 +18,7 @@
     android:title="@string/data_usage_summary_title">
 
     <PreferenceCategory
-        android:key="usage_amount"
-        android:layout="@layout/preference_category_short">
+        android:key="usage_amount">
 
         <com.android.settings.datausage.ChartDataUsagePreference
             android:key="chart_data" />
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index 804ede9..bdbd86f 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -380,4 +380,8 @@
             android:title="@string/reset_shortcut_manager_throttling" />
      </PreferenceCategory>
 
+    <PreferenceCategory
+      android:key="dashboard_tile_placeholder"
+      android:order="200"/>
+
 </PreferenceScreen>
diff --git a/res/xml/device_info_status.xml b/res/xml/device_info_status.xml
index a0b7590..1b173f1 100644
--- a/res/xml/device_info_status.xml
+++ b/res/xml/device_info_status.xml
@@ -29,18 +29,18 @@
         android:title="@string/battery_level_title"
         android:summary="@string/device_info_not_available"
         android:persistent="false" />
-    <PreferenceScreen android:key="sim_status"
+    <Preference android:key="sim_status"
         android:title="@string/sim_status_title"
         android:persistent="false">
         <intent android:targetPackage="com.android.settings"
             android:targetClass="com.android.settings.Settings$SimStatusActivity" />
-    </PreferenceScreen>
-    <PreferenceScreen android:key="imei_info"
+    </Preference>
+    <Preference android:key="imei_info"
         android:title="@string/imei_information_title"
         android:persistent="false">
         <intent android:targetPackage="com.android.settings"
             android:targetClass="com.android.settings.Settings$ImeiInformationActivity" />
-    </PreferenceScreen>
+    </Preference>
     <com.android.settings.CopyablePreference android:key="wifi_ip_address"
         android:enabled="false"
         android:shouldDisableView="false"
diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml
index b5e2848..1440c3f 100644
--- a/res/xml/display_settings.xml
+++ b/res/xml/display_settings.xml
@@ -36,7 +36,7 @@
                 android:key="night_display"
                 android:title="@string/night_display_title"
                 android:fragment="com.android.settings.display.NightDisplaySettings"
-                android:widgetLayout="@null"
+                settings:widgetLayout="@null"
                 settings:keywords="@string/keywords_display_night_display" />
 
         <!-- Hide night mode for now
diff --git a/res/xml/ia_display_settings.xml b/res/xml/ia_display_settings.xml
index 756d551..946466b 100644
--- a/res/xml/ia_display_settings.xml
+++ b/res/xml/ia_display_settings.xml
@@ -40,7 +40,7 @@
             android:key="night_display"
             android:title="@string/night_display_title"
             android:fragment="com.android.settings.display.NightDisplaySettings"
-            android:widgetLayout="@null"
+            settings:widgetLayout="@null"
             settings:keywords="@string/keywords_display_night_display" />
 
         <com.android.settings.TimeoutListPreference
diff --git a/res/xml/process_stats_summary.xml b/res/xml/process_stats_summary.xml
index f36fd11..3b3271d 100644
--- a/res/xml/process_stats_summary.xml
+++ b/res/xml/process_stats_summary.xml
@@ -20,8 +20,7 @@
     android:key="app_list">
 
     <PreferenceCategory
-        android:title="@string/average_memory_use"
-        android:layout="@layout/preference_category_short" />
+        android:title="@string/average_memory_use"/>
 
     <com.android.settings.SummaryPreference
         android:key="status_header"
diff --git a/res/xml/vpn_app_management.xml b/res/xml/vpn_app_management.xml
index 93e15bc..1b6f37b 100644
--- a/res/xml/vpn_app_management.xml
+++ b/res/xml/vpn_app_management.xml
@@ -33,6 +33,17 @@
                 settings:useAdditionalSummary="true"
                 settings:restrictedSwitchSummary="@string/disabled_by_admin_summary_text" />
 
+        <com.android.settingslib.RestrictedSwitchPreference
+                android:key="lockdown_vpn"
+                android:title="@string/vpn_require_connection"
+                android:defaultValue="false"
+                android:summaryOn="@string/vpn_lockdown_active"
+                android:summaryOff="@string/vpn_lockdown_inactive"
+                android:dependency="always_on_vpn"
+                settings:userRestriction="no_config_vpn"
+                settings:useAdditionalSummary="true"
+                settings:restrictedSwitchSummary="@string/disabled_by_admin_summary_text" />
+
         <com.android.settings.DimmableIconPreference
                 android:key="forget_vpn"
                 android:title="@string/vpn_forget_long"
diff --git a/src/com/android/settings/MasterClear.java b/src/com/android/settings/MasterClear.java
index b03b583..4ed38d1 100644
--- a/src/com/android/settings/MasterClear.java
+++ b/src/com/android/settings/MasterClear.java
@@ -31,14 +31,18 @@
 import android.os.SystemProperties;
 import android.os.UserHandle;
 import android.os.UserManager;
+import android.support.annotation.VisibleForTesting;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
+import android.view.View.OnScrollChangeListener;
 import android.view.ViewGroup;
+import android.view.ViewTreeObserver.OnGlobalLayoutListener;
 import android.widget.Button;
 import android.widget.CheckBox;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
+import android.widget.ScrollView;
 import android.widget.TextView;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
@@ -69,6 +73,15 @@
     private Button mInitiateButton;
     private View mExternalStorageContainer;
     private CheckBox mExternalStorage;
+    private ScrollView mScrollView;
+
+    private final OnGlobalLayoutListener mOnGlobalLayoutListener = new OnGlobalLayoutListener() {
+        @Override
+        public void onGlobalLayout() {
+            mScrollView.getViewTreeObserver().removeOnGlobalLayoutListener(mOnGlobalLayoutListener);
+            mInitiateButton.setEnabled(hasReachedBottom(mScrollView));
+        }
+    };
 
     /**
      * Keyguard validation is run using the standard {@link ConfirmLockPattern}
@@ -137,6 +150,7 @@
         mInitiateButton.setOnClickListener(mInitiateListener);
         mExternalStorageContainer = mContentView.findViewById(R.id.erase_external_container);
         mExternalStorage = (CheckBox) mContentView.findViewById(R.id.erase_external);
+        mScrollView = (ScrollView) mContentView.findViewById(R.id.master_clear_scrollview);
 
         /*
          * If the external storage is emulated, it will be erased with a factory
@@ -175,6 +189,32 @@
         View masterClearContainer = mContentView.findViewById(R.id.master_clear_container);
         getContentDescription(masterClearContainer, contentDescription);
         masterClearContainer.setContentDescription(contentDescription);
+
+        // Set the status of initiateButton based on scrollview
+        mScrollView.setOnScrollChangeListener(new OnScrollChangeListener() {
+            @Override
+            public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX,
+                int oldScrollY) {
+                if (v instanceof ScrollView && hasReachedBottom((ScrollView) v)) {
+                    mInitiateButton.setEnabled(true);
+                }
+            }
+        });
+
+        // Set the initial state of the initiateButton
+        mScrollView.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);
+    }
+
+    @VisibleForTesting
+    boolean hasReachedBottom(final ScrollView scrollView) {
+        if (scrollView.getChildCount() < 1) {
+            return true;
+        }
+
+        final View view = scrollView.getChildAt(0);
+        final int diff = view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY());
+
+        return diff <= 0;
     }
 
     private void getContentDescription(View v, StringBuffer description) {
diff --git a/src/com/android/settings/ProgressCategory.java b/src/com/android/settings/ProgressCategory.java
index 0c4a782..dd19de8 100644
--- a/src/com/android/settings/ProgressCategory.java
+++ b/src/com/android/settings/ProgressCategory.java
@@ -33,16 +33,19 @@
     private boolean mNoDeviceFoundAdded;
 
     public ProgressCategory(Context context) {
-        this(context, null);
+        super(context);
+        setLayoutResource(R.layout.preference_progress_category);
     }
 
     public ProgressCategory(Context context, AttributeSet attrs) {
-        super(context, attrs, 0);
+        super(context, attrs);
+        setLayoutResource(R.layout.preference_progress_category);
     }
 
     public ProgressCategory(Context context, AttributeSet attrs,
             int defStyleAttr) {
-        this(context, attrs, defStyleAttr, 0);
+        super(context, attrs, defStyleAttr);
+        setLayoutResource(R.layout.preference_progress_category);
     }
 
     public ProgressCategory(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
@@ -71,7 +74,7 @@
         } else {
             if (!mNoDeviceFoundAdded) {
                 if (mNoDeviceFoundPreference == null) {
-                    mNoDeviceFoundPreference = new Preference(getPreferenceManager().getContext());
+                    mNoDeviceFoundPreference = new Preference(getContext());
                     mNoDeviceFoundPreference.setLayoutResource(R.layout.preference_empty_list);
                     mNoDeviceFoundPreference.setTitle(mEmptyTextRes);
                     mNoDeviceFoundPreference.setSelectable(false);
diff --git a/src/com/android/settings/ProgressCategoryBase.java b/src/com/android/settings/ProgressCategoryBase.java
index 79ed51f..fb634f3 100644
--- a/src/com/android/settings/ProgressCategoryBase.java
+++ b/src/com/android/settings/ProgressCategoryBase.java
@@ -22,24 +22,25 @@
 
 public abstract class ProgressCategoryBase extends PreferenceCategory {
     public ProgressCategoryBase(Context context) {
-        this(context, null);
+        super(context);
     }
 
     public ProgressCategoryBase(Context context, AttributeSet attrs) {
-        this(context, attrs, 0);
+        super(context, attrs);
     }
 
     public ProgressCategoryBase(Context context, AttributeSet attrs, int defStyleAttr) {
-        super(context, attrs, defStyleAttr, 0);
+        super(context, attrs, defStyleAttr);
     }
 
     public ProgressCategoryBase(Context context, AttributeSet attrs, int defStyleAttr,
-                                int defStyleRes) {
+            int defStyleRes) {
         super(context, attrs, defStyleAttr, defStyleRes);
     }
 
     /**
      * Turn on/off the progress indicator and text on the right.
+     *
      * @param progressOn whether or not the progress should be displayed
      */
     public abstract void setProgress(boolean progressOn);
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index aa76517..cc203f7 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -329,7 +329,7 @@
         }
 
         MenuInflater inflater = getMenuInflater();
-        if (mSearchFeatureProvider.isEnabled()) {
+        if (mSearchFeatureProvider.isEnabled(this)) {
             mSearchFeatureProvider.setUpSearchMenu(menu, this);
             return true;
         }
@@ -405,7 +405,7 @@
         final FeatureFactory factory = FeatureFactory.getFactory(this);
 
         mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
-        mSearchFeatureProvider = factory.getSearchFeatureProvider(this);
+        mSearchFeatureProvider = factory.getSearchFeatureProvider();
 
         // Should happen before any call to getIntent()
         getMetaData();
@@ -1097,7 +1097,7 @@
     @Deprecated
     @Override
     public boolean onQueryTextSubmit(String query) {
-        if (mSearchFeatureProvider.isEnabled()) {
+        if (mSearchFeatureProvider.isEnabled(this)) {
             return false;
         }
         mSearchQuery = query;
@@ -1109,7 +1109,7 @@
     @Override
     public boolean onQueryTextChange(String newText) {
         mSearchQuery = newText;
-        if (mSearchFeatureProvider.isEnabled() || mSearchResultsFragment == null) {
+        if (mSearchFeatureProvider.isEnabled(this) || mSearchResultsFragment == null) {
             return false;
         }
         return mSearchResultsFragment.onQueryTextChange(newText);
diff --git a/src/com/android/settings/applications/RunningProcessesView.java b/src/com/android/settings/applications/RunningProcessesView.java
index 7ba83c2..917d3ab 100644
--- a/src/com/android/settings/applications/RunningProcessesView.java
+++ b/src/com/android/settings/applications/RunningProcessesView.java
@@ -52,25 +52,25 @@
 public class RunningProcessesView extends FrameLayout
         implements AdapterView.OnItemClickListener, RecyclerListener,
         RunningState.OnRefreshUiListener {
-    
+
     final int mMyUserId;
 
     long SECONDARY_SERVER_MEM;
-    
+
     final HashMap<View, ActiveItem> mActiveItems = new HashMap<View, ActiveItem>();
 
     ActivityManager mAm;
-    
+
     RunningState mState;
-    
+
     Fragment mOwner;
-    
+
     Runnable mDataAvail;
 
     StringBuilder mBuilder = new StringBuilder(128);
-    
+
     RunningState.BaseItem mCurSelected;
-    
+
     ListView mListView;
     View mHeader;
     ServiceListAdapter mAdapter;
@@ -102,19 +102,19 @@
 
         void updateTime(Context context, StringBuilder builder) {
             TextView uptimeView = null;
-            
+
             if (mItem instanceof RunningState.ServiceItem) {
                 // If we are displaying a service, then the service
                 // uptime goes at the top.
                 uptimeView = mHolder.size;
-                
+
             } else {
                 String size = mItem.mSizeStr != null ? mItem.mSizeStr : "";
                 if (!size.equals(mItem.mCurSizeStr)) {
                     mItem.mCurSizeStr = size;
                     mHolder.size.setText(size);
                 }
-                
+
                 if (mItem.mBackground) {
                     // This is a background process; no uptime.
                     if (!mSetBackground) {
@@ -150,7 +150,7 @@
             }
         }
     }
-    
+
     public static class ViewHolder {
         public View rootView;
         public ImageView icon;
@@ -158,7 +158,7 @@
         public TextView description;
         public TextView size;
         public TextView uptime;
-        
+
         public ViewHolder(View v) {
             rootView = v;
             icon = (ImageView)v.findViewById(R.id.icon);
@@ -168,7 +168,7 @@
             uptime = (TextView)v.findViewById(R.id.uptime);
             v.setTag(this);
         }
-        
+
         public ActiveItem bind(RunningState state, RunningState.BaseItem item,
                 StringBuilder builder) {
             synchronized (state.mLock) {
@@ -202,13 +202,7 @@
             }
         }
     }
-    
-    static class TimeTicker extends TextView {
-        public TimeTicker(Context context, AttributeSet attrs) {
-            super(context, attrs);
-        }
-    }
-    
+
     class ServiceListAdapter extends BaseAdapter {
         final RunningState mState;
         final LayoutInflater mInflater;
@@ -216,7 +210,7 @@
         ArrayList<RunningState.MergedItem> mOrigItems;
         final ArrayList<RunningState.MergedItem> mItems
                 = new ArrayList<RunningState.MergedItem>();
-        
+
         ServiceListAdapter(RunningState state) {
             mState = state;
             mInflater = (LayoutInflater)getContext().getSystemService(
@@ -254,11 +248,11 @@
                 }
             }
         }
-        
+
         public boolean hasStableIds() {
             return true;
         }
-        
+
         public int getCount() {
             return mItems.size();
         }
@@ -294,13 +288,13 @@
             bindView(v, position);
             return v;
         }
-        
+
         public View newView(ViewGroup parent) {
             View v = mInflater.inflate(R.layout.running_processes_item, parent, false);
             new ViewHolder(v);
             return v;
         }
-        
+
         public void bindView(View view, int position) {
             synchronized (mState.mLock) {
                 if (position >= mItems.size()) {
@@ -323,7 +317,7 @@
             adapter.refreshItems();
             adapter.notifyDataSetChanged();
         }
-        
+
         if (mDataAvail != null) {
             mDataAvail.run();
             mDataAvail = null;
@@ -396,7 +390,7 @@
             }
         }
     }
-    
+
     public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
         ListView l = (ListView)parent;
         RunningState.MergedItem mi = (RunningState.MergedItem)l.getAdapter().getItem(position);
@@ -421,7 +415,7 @@
                     R.string.runningservicedetails_settings_title, null, null, 0);
         }
     }
-    
+
     public void onMovedToScrapHeap(View view) {
         mActiveItems.remove(view);
     }
@@ -430,7 +424,7 @@
         super(context, attrs);
         mMyUserId = UserHandle.myUserId();
     }
-    
+
     public void doCreate() {
         mAm = (ActivityManager)getContext().getSystemService(Context.ACTIVITY_SERVICE);
         mState = RunningState.getInstance(getContext());
@@ -464,7 +458,7 @@
         mAm.getMemoryInfo(memInfo);
         SECONDARY_SERVER_MEM = memInfo.secondaryServerThreshold;
     }
-    
+
     public void doPause() {
         mState.pause();
         mDataAvail = null;
diff --git a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
index a45e7b4..b956aa5 100644
--- a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
+++ b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
@@ -65,9 +65,9 @@
 
     /* Talk-back descriptions for various BT icons */
     Resources r = getContext().getResources();
-    public final String COMPUTER =  r.getString(R.string.bluetooth_talkback_computer);
+    public final String COMPUTER = r.getString(R.string.bluetooth_talkback_computer);
     public final String INPUT_PERIPHERAL = r.getString(
-        R.string.bluetooth_talkback_input_peripheral);
+            R.string.bluetooth_talkback_input_peripheral);
     public final String HEADSET = r.getString(R.string.bluetooth_talkback_headset);
     public final String PHONE = r.getString(R.string.bluetooth_talkback_phone);
     public final String IMAGING = r.getString(R.string.bluetooth_talkback_imaging);
@@ -85,11 +85,9 @@
 
         mCachedDevice = cachedDevice;
 
-        setLayoutResource(R.layout.preference_bt_icon);
-
         if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
             UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
-            if (! um.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)) {
+            if (!um.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)) {
                 setWidgetLayoutResource(R.layout.preference_bluetooth);
             }
         }
@@ -266,7 +264,7 @@
 
                 case BluetoothClass.Device.Major.PERIPHERAL:
                     return new Pair<Integer, String>(HidProfile.getHidClassDrawable(btClass),
-                                                     INPUT_PERIPHERAL);
+                            INPUT_PERIPHERAL);
 
                 case BluetoothClass.Device.Major.IMAGING:
                     return new Pair<Integer, String>(R.drawable.ic_bt_imaging, IMAGING);
diff --git a/src/com/android/settings/bluetooth/BluetoothProgressCategory.java b/src/com/android/settings/bluetooth/BluetoothProgressCategory.java
index ae94981..a36c98b 100644
--- a/src/com/android/settings/bluetooth/BluetoothProgressCategory.java
+++ b/src/com/android/settings/bluetooth/BluetoothProgressCategory.java
@@ -27,21 +27,28 @@
  */
 public class BluetoothProgressCategory extends ProgressCategory {
     public BluetoothProgressCategory(Context context) {
-        this(context, null);
+        super(context);
+        init();
     }
 
     public BluetoothProgressCategory(Context context, AttributeSet attrs) {
-        this(context, attrs, 0);
+        super(context, attrs);
+        init();
     }
 
     public BluetoothProgressCategory(Context context, AttributeSet attrs, int defStyleAttr) {
-        this(context, attrs, defStyleAttr, 0);
+        super(context, attrs, defStyleAttr);
+        init();
     }
 
     public BluetoothProgressCategory(Context context, AttributeSet attrs, int defStyleAttr,
             int defStyleRes) {
         super(context, attrs, defStyleAttr, defStyleRes);
+        init();
+    }
 
+    private void init() {
+        setIcon(R.drawable.ic_settings_bluetooth);
         setEmptyTextRes(R.string.bluetooth_no_devices_found);
     }
 }
diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java
index 1dd0471..5c18d66 100644
--- a/src/com/android/settings/bluetooth/BluetoothSettings.java
+++ b/src/com/android/settings/bluetooth/BluetoothSettings.java
@@ -161,13 +161,13 @@
     @Override
     void addPreferencesForActivity() {
         addPreferencesFromResource(R.xml.bluetooth_settings);
-
-        mPairedDevicesCategory = new PreferenceCategory(getPrefContext());
+        final Context prefContext = getPrefContext();
+        mPairedDevicesCategory = new PreferenceCategory(prefContext);
         mPairedDevicesCategory.setKey(KEY_PAIRED_DEVICES);
         mPairedDevicesCategory.setOrder(1);
         getPreferenceScreen().addPreference(mPairedDevicesCategory);
 
-        mAvailableDevicesCategory = new BluetoothProgressCategory(getActivity());
+        mAvailableDevicesCategory = new BluetoothProgressCategory(prefContext);
         mAvailableDevicesCategory.setSelectable(false);
         mAvailableDevicesCategory.setOrder(2);
         getPreferenceScreen().addPreference(mAvailableDevicesCategory);
diff --git a/src/com/android/settings/dashboard/DashboardFeatureProvider.java b/src/com/android/settings/dashboard/DashboardFeatureProvider.java
index dee9f36..2a5e800 100644
--- a/src/com/android/settings/dashboard/DashboardFeatureProvider.java
+++ b/src/com/android/settings/dashboard/DashboardFeatureProvider.java
@@ -88,5 +88,9 @@
     ProgressiveDisclosureMixin getProgressiveDisclosureMixin(Context context,
             DashboardFragment fragment);
 
+    /**
+     * Returns additional intent filter action for dashboard tiles
+     */
+    String getExtraIntentAction();
 
 }
diff --git a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
index 2245487..e7d2b58 100644
--- a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
+++ b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
@@ -51,7 +51,8 @@
     private final CategoryManager mCategoryManager;
 
     public DashboardFeatureProviderImpl(Context context) {
-        this(context.getApplicationContext(), CategoryManager.get(context));
+        mContext = context;
+        mCategoryManager = CategoryManager.get(context, getExtraIntentAction());
     }
 
     @VisibleForTesting
@@ -182,4 +183,9 @@
             DashboardFragment fragment) {
         return new ProgressiveDisclosureMixin(context, this, fragment);
     }
+
+    @Override
+    public String getExtraIntentAction() {
+        return null;
+    }
 }
diff --git a/src/com/android/settings/dashboard/SupportFragment.java b/src/com/android/settings/dashboard/SupportFragment.java
index 163bece..8a1a79b 100644
--- a/src/com/android/settings/dashboard/SupportFragment.java
+++ b/src/com/android/settings/dashboard/SupportFragment.java
@@ -84,6 +84,7 @@
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+        setHasOptionsMenu(true);
         mActivity = getActivity();
         mAccountManager = AccountManager.get(mActivity);
         mSupportFeatureProvider =
@@ -118,6 +119,7 @@
                         .build(),
                 mNetworkCallback);
         mSupportItemAdapter.setHasInternet(hasInternet());
+        mSupportItemAdapter.refreshData();
     }
 
     @Override
diff --git a/src/com/android/settings/dashboard/SupportItemAdapter.java b/src/com/android/settings/dashboard/SupportItemAdapter.java
index b125fff..54c5ae6 100644
--- a/src/com/android/settings/dashboard/SupportItemAdapter.java
+++ b/src/com/android/settings/dashboard/SupportItemAdapter.java
@@ -192,7 +192,7 @@
      * Create data for the adapter. If there is already data in the adapter, they will be
      * destroyed and recreated.
      */
-    private void refreshData() {
+    void refreshData() {
         mSupportData.clear();
         addEscalationCards();
         addMoreHelpItems();
@@ -601,7 +601,8 @@
     /**
      * Data for a single support item.
      */
-    private static class SupportData {
+    @VisibleForTesting
+    static class SupportData {
 
         final Intent intent;
         final int metricsEvent;
@@ -688,7 +689,8 @@
     /**
      * Data model for escalation cards.
      */
-    private static class EscalationData extends SupportData {
+    @VisibleForTesting
+    static class EscalationData extends SupportData {
 
         @StringRes
         final int text1;
@@ -813,4 +815,9 @@
             }
         }
     }
+
+    @VisibleForTesting
+    List<SupportData> getSupportData() {
+        return mSupportData;
+    }
 }
diff --git a/src/com/android/settings/datausage/CellDataPreference.java b/src/com/android/settings/datausage/CellDataPreference.java
index 0194178..77460ef 100644
--- a/src/com/android/settings/datausage/CellDataPreference.java
+++ b/src/com/android/settings/datausage/CellDataPreference.java
@@ -25,6 +25,7 @@
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.provider.Settings.Global;
+import android.support.v4.content.res.TypedArrayUtils;
 import android.support.v7.preference.PreferenceViewHolder;
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
@@ -53,7 +54,9 @@
     private SubscriptionManager mSubscriptionManager;
 
     public CellDataPreference(Context context, AttributeSet attrs) {
-        super(context, attrs, android.R.attr.switchPreferenceStyle);
+        super(context, attrs, TypedArrayUtils.getAttr(context,
+                android.support.v7.preference.R.attr.switchPreferenceStyle,
+                android.R.attr.switchPreferenceStyle));
     }
 
     @Override
diff --git a/src/com/android/settings/deviceinfo/Status.java b/src/com/android/settings/deviceinfo/Status.java
index fb6627a..baddc6c 100644
--- a/src/com/android/settings/deviceinfo/Status.java
+++ b/src/com/android/settings/deviceinfo/Status.java
@@ -46,14 +46,6 @@
 import static android.content.Context.CONNECTIVITY_SERVICE;
 import static android.content.Context.WIFI_SERVICE;
 
-/**
- * Display the following information
- * # Battery Strength  : TODO
- * # Uptime
- * # Awake Time
- * # XMPP/buzz/tickle status : TODO
- *
- */
 public class Status extends SettingsPreferenceFragment {
 
     private static final String KEY_BATTERY_STATUS = "battery_status";
diff --git a/src/com/android/settings/fuelgauge/PowerUsageBase.java b/src/com/android/settings/fuelgauge/PowerUsageBase.java
index 269249a..1af9df1 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageBase.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageBase.java
@@ -25,6 +25,7 @@
 import android.os.Handler;
 import android.os.Message;
 import android.os.UserManager;
+import android.support.annotation.VisibleForTesting;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
@@ -39,7 +40,8 @@
 public abstract class PowerUsageBase extends SettingsPreferenceFragment {
 
     // +1 to allow ordering for PowerUsageSummary.
-    private static final int MENU_STATS_REFRESH = Menu.FIRST + 1;
+    @VisibleForTesting
+    static final int MENU_STATS_REFRESH = Menu.FIRST + 1;
 
     protected BatteryStatsHelper mStatsHelper;
     protected UserManager mUm;
diff --git a/src/com/android/settings/fuelgauge/PowerUsageDetail.java b/src/com/android/settings/fuelgauge/PowerUsageDetail.java
index 003c7f6..5f9a305 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageDetail.java
@@ -350,8 +350,10 @@
     @Override
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
-        mPm = getActivity().getPackageManager();
-        mDpm = (DevicePolicyManager)getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
+
+        Activity activity = getActivity();
+        mPm = activity.getPackageManager();
+        mDpm = (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
 
         addPreferencesFromResource(R.xml.power_usage_details);
         mDetailsParent = (PreferenceCategory) findPreference(KEY_DETAILS_PARENT);
@@ -360,7 +362,7 @@
         mPackagesParent = (PreferenceCategory) findPreference(KEY_PACKAGES_PARENT);
 
         mPowerUsageFeatureProvider =
-                FeatureFactory.getFactory(getActivity()).getPowerUsageFeatureProvider();
+                FeatureFactory.getFactory(activity).getPowerUsageFeatureProvider(activity);
 
         createDetails();
     }
diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
index f58f635..2219e33 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
@@ -24,4 +24,6 @@
    * Check whether location setting is enabled
    */
   boolean isLocationSettingEnabled(String[] packages);
+
+  boolean isAdditionalBatteryInfoEnabled();
 }
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index 3ed9bee..1100a2c 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -26,6 +26,7 @@
 import android.os.Message;
 import android.os.Process;
 import android.os.UserHandle;
+import android.support.annotation.VisibleForTesting;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceGroup;
 import android.text.TextUtils;
@@ -43,6 +44,7 @@
 import com.android.settings.SettingsActivity;
 import com.android.settings.applications.ManageApplications;
 import com.android.settings.dashboard.SummaryLoader;
+import com.android.settings.overlay.FeatureFactory;
 import com.android.settingslib.BatteryInfo;
 
 import java.util.ArrayList;
@@ -67,7 +69,9 @@
 
     private static final int MENU_STATS_TYPE = Menu.FIRST;
     private static final int MENU_HIGH_POWER_APPS = Menu.FIRST + 3;
-    private static final int MENU_HELP = Menu.FIRST + 4;
+    @VisibleForTesting
+    static final int MENU_ADDITIONAL_BATTERY_INFO = Menu.FIRST + 4;
+    private static final int MENU_HELP = Menu.FIRST + 5;
 
     private BatteryHistoryPreference mHistPref;
     private PreferenceGroup mAppListGroup;
@@ -130,12 +134,20 @@
     @Override
     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
         if (DEBUG) {
-            menu.add(0, MENU_STATS_TYPE, 0, R.string.menu_stats_total)
+            menu.add(Menu.NONE, MENU_STATS_TYPE, Menu.NONE, R.string.menu_stats_total)
                     .setIcon(com.android.internal.R.drawable.ic_menu_info_details)
                     .setAlphabeticShortcut('t');
         }
 
-        menu.add(0, MENU_HIGH_POWER_APPS, 0, R.string.high_power_apps);
+        menu.add(Menu.NONE, MENU_HIGH_POWER_APPS, Menu.NONE, R.string.high_power_apps);
+
+        PowerUsageFeatureProvider powerUsageFeatureProvider =
+                FeatureFactory.getFactory(getContext()).getPowerUsageFeatureProvider(getContext());
+        if (powerUsageFeatureProvider != null &&
+                powerUsageFeatureProvider.isAdditionalBatteryInfoEnabled()) {
+            menu.add(Menu.NONE, MENU_ADDITIONAL_BATTERY_INFO,
+                    Menu.NONE, R.string.additional_battery_info);
+        }
         super.onCreateOptionsMenu(menu, inflater);
     }
 
diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java
index 88df549..1d5f09e 100644
--- a/src/com/android/settings/notification/ZenModeSettings.java
+++ b/src/com/android/settings/notification/ZenModeSettings.java
@@ -18,16 +18,14 @@
 
 import android.app.NotificationManager;
 import android.app.NotificationManager.Policy;
+import android.content.Context;
 import android.os.Bundle;
+import android.support.annotation.VisibleForTesting;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceScreen;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
-import com.android.settings.SettingsActivity;
 
 public class ZenModeSettings extends ZenModeSettingsBase {
     private static final String KEY_PRIORITY_SETTINGS = "priority_settings";
@@ -80,25 +78,25 @@
 
     private void updatePrioritySettingsSummary() {
         String s = getResources().getString(R.string.zen_mode_alarms);
-        s = appendLowercase(s, isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_REMINDERS),
+        s = append(s, isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_REMINDERS),
                 R.string.zen_mode_reminders);
-        s = appendLowercase(s, isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_EVENTS),
+        s = append(s, isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_EVENTS),
                 R.string.zen_mode_events);
         if (isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_MESSAGES)) {
             if (mPolicy.priorityMessageSenders == Policy.PRIORITY_SENDERS_ANY) {
-                s = appendLowercase(s, true, R.string.zen_mode_all_messages);
+                s = append(s, true, R.string.zen_mode_all_messages);
             } else {
-                s = appendLowercase(s, true, R.string.zen_mode_selected_messages);
+                s = append(s, true, R.string.zen_mode_selected_messages);
             }
         }
         if (isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_CALLS)) {
             if (mPolicy.priorityCallSenders == Policy.PRIORITY_SENDERS_ANY) {
-                s = appendLowercase(s, true, R.string.zen_mode_all_callers);
+                s = append(s, true, R.string.zen_mode_all_callers);
             } else {
-                s = appendLowercase(s, true, R.string.zen_mode_selected_callers);
+                s = append(s, true, R.string.zen_mode_selected_callers);
             }
         } else if (isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_REPEAT_CALLERS)) {
-            s = appendLowercase(s, true, R.string.zen_mode_repeat_callers);
+            s = append(s, true, R.string.zen_mode_repeat_callers);
         }
         mPrioritySettings.setSummary(s);
     }
@@ -124,10 +122,11 @@
         return (policy.priorityCategories & categoryType) != 0;
     }
 
-    private String appendLowercase(String s, boolean condition, int resId) {
+    @VisibleForTesting
+    String append(String s, boolean condition, int resId) {
         if (condition) {
-            return getResources().getString(R.string.join_many_items_middle, s,
-                    getResources().getString(resId).toLowerCase());
+            final Context context = getContext();
+            return context.getString(R.string.join_many_items_middle, s, context.getString(resId));
         }
         return s;
     }
diff --git a/src/com/android/settings/overlay/FeatureFactory.java b/src/com/android/settings/overlay/FeatureFactory.java
index 3532274..0b8ee8e 100644
--- a/src/com/android/settings/overlay/FeatureFactory.java
+++ b/src/com/android/settings/overlay/FeatureFactory.java
@@ -70,7 +70,7 @@
 
     public abstract MetricsFeatureProvider getMetricsFeatureProvider();
 
-    public abstract PowerUsageFeatureProvider getPowerUsageFeatureProvider();
+    public abstract PowerUsageFeatureProvider getPowerUsageFeatureProvider(Context context);
 
     public abstract DashboardFeatureProvider getDashboardFeatureProvider(Context context);
 
@@ -81,7 +81,7 @@
     public abstract EnterprisePrivacyFeatureProvider getEnterprisePrivacyFeatureProvider(
             Context context);
 
-    public abstract SearchFeatureProvider getSearchFeatureProvider(Context context);
+    public abstract SearchFeatureProvider getSearchFeatureProvider();
 
     public abstract SurveyFeatureProvider getSurveyFeatureProvider(Context context);
 
diff --git a/src/com/android/settings/overlay/FeatureFactoryImpl.java b/src/com/android/settings/overlay/FeatureFactoryImpl.java
index 313c270..c2d5d79 100644
--- a/src/com/android/settings/overlay/FeatureFactoryImpl.java
+++ b/src/com/android/settings/overlay/FeatureFactoryImpl.java
@@ -63,7 +63,7 @@
     }
 
     @Override
-    public PowerUsageFeatureProvider getPowerUsageFeatureProvider() {
+    public PowerUsageFeatureProvider getPowerUsageFeatureProvider(Context context) {
         return null;
     }
 
@@ -104,9 +104,9 @@
     }
 
     @Override
-    public SearchFeatureProvider getSearchFeatureProvider(Context context) {
+    public SearchFeatureProvider getSearchFeatureProvider() {
         if (mSearchFeatureProvider == null) {
-            mSearchFeatureProvider = new SearchFeatureProviderImpl(context);
+            mSearchFeatureProvider = new SearchFeatureProviderImpl();
         }
         return mSearchFeatureProvider;
     }
diff --git a/src/com/android/settings/search2/SearchFeatureProvider.java b/src/com/android/settings/search2/SearchFeatureProvider.java
index ad26eae..8a616a7 100644
--- a/src/com/android/settings/search2/SearchFeatureProvider.java
+++ b/src/com/android/settings/search2/SearchFeatureProvider.java
@@ -27,7 +27,7 @@
     /**
      * @return true to use the new version of search
      */
-    boolean isEnabled();
+    boolean isEnabled(Context context);
 
     /**
      * Inserts the Menu items into Settings activity.
diff --git a/src/com/android/settings/search2/SearchFeatureProviderImpl.java b/src/com/android/settings/search2/SearchFeatureProviderImpl.java
index e2d25ad..acb90b7 100644
--- a/src/com/android/settings/search2/SearchFeatureProviderImpl.java
+++ b/src/com/android/settings/search2/SearchFeatureProviderImpl.java
@@ -31,16 +31,11 @@
  * FeatureProvider for the refactored search code.
  */
 public class SearchFeatureProviderImpl implements SearchFeatureProvider {
-    protected Context mContext;
 
     private DatabaseIndexingManager mDatabaseIndexingManager;
 
-    public SearchFeatureProviderImpl(Context context) {
-        mContext = context;
-    }
-
     @Override
-    public boolean isEnabled() {
+    public boolean isEnabled(Context context) {
         return false;
     }
 
@@ -49,7 +44,7 @@
         if (menu == null || activity == null) {
             return;
         }
-        String menuTitle = mContext.getString(R.string.search_menu);
+        String menuTitle = activity.getString(R.string.search_menu);
         MenuItem menuItem = menu.add(Menu.NONE, Menu.NONE, Menu.NONE, menuTitle)
                 .setIcon(R.drawable.abc_ic_search_api_material)
                 .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@@ -86,7 +81,7 @@
 
     @Override
     public void updateIndex(Context context) {
-        if (isEnabled()) {
+        if (isEnabled(context)) {
             getIndexingManager(context).update();
         } else {
             Index.getInstance(context).update();
diff --git a/src/com/android/settings/search2/SearchFragment.java b/src/com/android/settings/search2/SearchFragment.java
index fca52e9..1a4e6dc 100644
--- a/src/com/android/settings/search2/SearchFragment.java
+++ b/src/com/android/settings/search2/SearchFragment.java
@@ -66,7 +66,7 @@
     public void onAttach(Context context) {
         super.onAttach(context);
         mSearchFeatureProvider = FeatureFactory.getFactory(context)
-                .getSearchFeatureProvider(context);
+                .getSearchFeatureProvider();
     }
 
     @Override
diff --git a/src/com/android/settings/vpn2/AppManagementFragment.java b/src/com/android/settings/vpn2/AppManagementFragment.java
index 23901ce..f86e677 100644
--- a/src/com/android/settings/vpn2/AppManagementFragment.java
+++ b/src/com/android/settings/vpn2/AppManagementFragment.java
@@ -33,7 +33,6 @@
 import android.os.ServiceManager;
 import android.os.UserHandle;
 import android.os.UserManager;
-import android.provider.Settings;
 import android.support.v7.preference.Preference;
 import android.text.TextUtils;
 import android.util.Log;
@@ -63,6 +62,7 @@
 
     private static final String KEY_VERSION = "version";
     private static final String KEY_ALWAYS_ON_VPN = "always_on_vpn";
+    private static final String KEY_LOCKDOWN_VPN = "lockdown_vpn";
     private static final String KEY_FORGET_VPN = "forget_vpn";
 
     private PackageManager mPackageManager;
@@ -78,6 +78,7 @@
     // UI preference
     private Preference mPreferenceVersion;
     private RestrictedSwitchPreference mPreferenceAlwaysOn;
+    private RestrictedSwitchPreference mPreferenceLockdown;
     private RestrictedPreference mPreferenceForget;
 
     // Listener
@@ -87,7 +88,7 @@
         public void onForget() {
             // Unset always-on-vpn when forgetting the VPN
             if (isVpnAlwaysOn()) {
-                setAlwaysOnVpn(false);
+                setAlwaysOnVpn(false, false);
             }
             // Also dismiss and go back to VPN list
             finish();
@@ -118,9 +119,11 @@
 
         mPreferenceVersion = findPreference(KEY_VERSION);
         mPreferenceAlwaysOn = (RestrictedSwitchPreference) findPreference(KEY_ALWAYS_ON_VPN);
+        mPreferenceLockdown = (RestrictedSwitchPreference) findPreference(KEY_LOCKDOWN_VPN);
         mPreferenceForget = (RestrictedPreference) findPreference(KEY_FORGET_VPN);
 
         mPreferenceAlwaysOn.setOnPreferenceChangeListener(this);
+        mPreferenceLockdown.setOnPreferenceChangeListener(this);
         mPreferenceForget.setOnPreferenceClickListener(this);
     }
 
@@ -154,7 +157,9 @@
     public boolean onPreferenceChange(Preference preference, Object newValue) {
         switch (preference.getKey()) {
             case KEY_ALWAYS_ON_VPN:
-                return onAlwaysOnVpnClick((Boolean) newValue);
+                return onAlwaysOnVpnClick((Boolean) newValue, mPreferenceLockdown.isChecked());
+            case KEY_LOCKDOWN_VPN:
+                return onAlwaysOnVpnClick(mPreferenceAlwaysOn.isChecked(), (Boolean) newValue);
             default:
                 Log.w(TAG, "unknown key is clicked: " + preference.getKey());
                 return false;
@@ -176,27 +181,28 @@
         return true;
     }
 
-    private boolean onAlwaysOnVpnClick(final boolean alwaysOnSetting) {
+    private boolean onAlwaysOnVpnClick(final boolean alwaysOnSetting, final boolean lockdown) {
         final boolean replacing = isAnotherVpnActive();
-        final boolean wasAlwaysOn = VpnUtils.isAlwaysOnOrLegacyLockdownActive(getActivity());
-        if (ConfirmLockdownFragment.shouldShow(replacing, wasAlwaysOn, alwaysOnSetting)) {
+        final boolean wasLockdown = VpnUtils.isAnyLockdownActive(getActivity());
+        if (ConfirmLockdownFragment.shouldShow(replacing, wasLockdown, lockdown)) {
             // Place a dialog to confirm that traffic should be locked down.
             final Bundle options = null;
-            ConfirmLockdownFragment.show(this, replacing, wasAlwaysOn, alwaysOnSetting, options);
+            ConfirmLockdownFragment.show(
+                    this, replacing, alwaysOnSetting, wasLockdown, lockdown, options);
             return false;
         }
         // No need to show the dialog. Change the setting straight away.
-        return setAlwaysOnVpnByUI(alwaysOnSetting);
+        return setAlwaysOnVpnByUI(alwaysOnSetting, lockdown);
     }
 
     @Override
-    public void onConfirmLockdown(Bundle options, boolean isEnabled) {
-        if (setAlwaysOnVpnByUI(isEnabled)) {
+    public void onConfirmLockdown(Bundle options, boolean isEnabled, boolean isLockdown) {
+        if (setAlwaysOnVpnByUI(isEnabled, isLockdown)) {
             updateUI();
         }
     }
 
-    private boolean setAlwaysOnVpnByUI(boolean isEnabled) {
+    private boolean setAlwaysOnVpnByUI(boolean isEnabled, boolean isLockdown) {
         updateRestrictedViews();
         if (!mPreferenceAlwaysOn.isEnabled()) {
             return false;
@@ -205,16 +211,16 @@
         if (mUserId == UserHandle.USER_SYSTEM) {
             VpnUtils.clearLockdownVpn(getContext());
         }
-        final boolean success = setAlwaysOnVpn(isEnabled);
+        final boolean success = setAlwaysOnVpn(isEnabled, isLockdown);
         if (isEnabled && (!success || !isVpnAlwaysOn())) {
             CannotConnectFragment.show(this, mVpnLabel);
         }
         return success;
     }
 
-    private boolean setAlwaysOnVpn(boolean isEnabled) {
-         return mConnectivityManager.setAlwaysOnVpnPackageForUser(mUserId,
-                isEnabled ? mPackageName : null, /* lockdownEnabled */ true);
+    private boolean setAlwaysOnVpn(boolean isEnabled, boolean isLockdown) {
+        return mConnectivityManager.setAlwaysOnVpnPackageForUser(mUserId,
+                isEnabled ? mPackageName : null, isLockdown);
     }
 
     @VisibleForTesting
@@ -232,7 +238,12 @@
 
     private void updateUI() {
         if (isAdded()) {
-            mPreferenceAlwaysOn.setChecked(isVpnAlwaysOn());
+            final boolean alwaysOn = isVpnAlwaysOn();
+            final boolean lockdown = alwaysOn
+                    && VpnUtils.isAnyLockdownActive(getActivity());
+
+            mPreferenceAlwaysOn.setChecked(alwaysOn);
+            mPreferenceLockdown.setChecked(lockdown);
             updateRestrictedViews();
         }
     }
@@ -241,6 +252,8 @@
         if (isAdded()) {
             mPreferenceAlwaysOn.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_VPN,
                     mUserId);
+            mPreferenceLockdown.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_VPN,
+                    mUserId);
             mPreferenceForget.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_VPN,
                     mUserId);
 
@@ -251,6 +264,7 @@
                 // should have refreshed the enable state.
             } else {
                 mPreferenceAlwaysOn.setEnabled(false);
+                mPreferenceLockdown.setEnabled(false);
                 mPreferenceAlwaysOn.setSummary(R.string.vpn_not_supported_by_this_app);
             }
         }
diff --git a/src/com/android/settings/vpn2/ConfigDialogFragment.java b/src/com/android/settings/vpn2/ConfigDialogFragment.java
index d9f35af..cf748e4 100644
--- a/src/com/android/settings/vpn2/ConfigDialogFragment.java
+++ b/src/com/android/settings/vpn2/ConfigDialogFragment.java
@@ -134,9 +134,9 @@
     }
 
     @Override
-    public void onConfirmLockdown(Bundle options, boolean isEnabled) {
+    public void onConfirmLockdown(Bundle options, boolean isAlwaysOn, boolean isLockdown) {
         VpnProfile profile = (VpnProfile) options.getParcelable(ARG_PROFILE);
-        connect(profile, isEnabled);
+        connect(profile, isAlwaysOn);
         dismiss();
     }
 
@@ -149,14 +149,15 @@
             // Possibly throw up a dialog to explain lockdown VPN.
             final boolean shouldLockdown = dialog.isVpnAlwaysOn();
             final boolean shouldConnect = shouldLockdown || !dialog.isEditing();
-            final boolean wasAlwaysOn = VpnUtils.isAlwaysOnOrLegacyLockdownActive(mContext);
+            final boolean wasLockdown = VpnUtils.isAnyLockdownActive(mContext);
             try {
                 final boolean replace = VpnUtils.isVpnActive(mContext);
                 if (shouldConnect && !isConnected(profile) &&
-                        ConfirmLockdownFragment.shouldShow(replace, wasAlwaysOn, shouldLockdown)) {
+                        ConfirmLockdownFragment.shouldShow(replace, wasLockdown, shouldLockdown)) {
                     final Bundle opts = new Bundle();
                     opts.putParcelable(ARG_PROFILE, profile);
-                    ConfirmLockdownFragment.show(this, replace, wasAlwaysOn, shouldLockdown, opts);
+                    ConfirmLockdownFragment.show(this, replace, /* alwaysOn */ shouldLockdown,
+                           /* from */  wasLockdown, /* to */ shouldLockdown, opts);
                 } else if (shouldConnect) {
                     connect(profile, shouldLockdown);
                 } else {
diff --git a/src/com/android/settings/vpn2/ConfirmLockdownFragment.java b/src/com/android/settings/vpn2/ConfirmLockdownFragment.java
index 246c2f2..0d40e4c 100644
--- a/src/com/android/settings/vpn2/ConfirmLockdownFragment.java
+++ b/src/com/android/settings/vpn2/ConfirmLockdownFragment.java
@@ -29,7 +29,7 @@
 public class ConfirmLockdownFragment extends InstrumentedDialogFragment
         implements DialogInterface.OnClickListener {
     public interface ConfirmLockdownListener {
-        public void onConfirmLockdown(Bundle options, boolean isEnabled);
+        public void onConfirmLockdown(Bundle options, boolean isEnabled, boolean isLockdown);
     }
 
     private static final String TAG = "ConfirmLockdown";
@@ -40,6 +40,7 @@
     }
 
     private static final String ARG_REPLACING = "replacing";
+    private static final String ARG_ALWAYS_ON = "always_on";
     private static final String ARG_LOCKDOWN_SRC = "lockdown_old";
     private static final String ARG_LOCKDOWN_DST = "lockdown_new";
     private static final String ARG_OPTIONS = "options";
@@ -47,11 +48,11 @@
     public static boolean shouldShow(boolean replacing, boolean fromLockdown, boolean toLockdown) {
         // We only need to show this if we are:
         //  - replacing an existing connection
-        //  - switching on always-on mode where it was not enabled before.
+        //  - switching on always-on mode with lockdown enabled where it was not enabled before.
         return replacing || (toLockdown && !fromLockdown);
     }
 
-    public static void show(Fragment parent, boolean replacing,
+    public static void show(Fragment parent, boolean replacing, boolean alwaysOn,
             boolean fromLockdown, boolean toLockdown, Bundle options) {
         if (parent.getFragmentManager().findFragmentByTag(TAG) != null) {
             // Already exists. Don't show it twice.
@@ -59,6 +60,7 @@
         }
         final Bundle args = new Bundle();
         args.putBoolean(ARG_REPLACING, replacing);
+        args.putBoolean(ARG_ALWAYS_ON, alwaysOn);
         args.putBoolean(ARG_LOCKDOWN_SRC, fromLockdown);
         args.putBoolean(ARG_LOCKDOWN_DST, toLockdown);
         args.putParcelable(ARG_OPTIONS, options);
@@ -72,20 +74,21 @@
     @Override
     public Dialog onCreateDialog(Bundle savedInstanceState) {
         final boolean replacing = getArguments().getBoolean(ARG_REPLACING);
-        final boolean wasAlwaysOn = getArguments().getBoolean(ARG_LOCKDOWN_SRC);
-        final boolean nowAlwaysOn = getArguments().getBoolean(ARG_LOCKDOWN_DST);
+        final boolean alwaysOn = getArguments().getBoolean(ARG_ALWAYS_ON);
+        final boolean wasLockdown = getArguments().getBoolean(ARG_LOCKDOWN_SRC);
+        final boolean nowLockdown = getArguments().getBoolean(ARG_LOCKDOWN_DST);
 
         final int titleId = replacing ? R.string.vpn_replace_vpn_title : R.string.vpn_set_vpn_title;
         final int actionId =
                 (replacing ? R.string.vpn_replace :
-                (nowAlwaysOn ? R.string.vpn_turn_on : R.string.okay));
+                (nowLockdown ? R.string.vpn_turn_on : R.string.okay));
         final int messageId;
-        if (nowAlwaysOn) {
+        if (nowLockdown) {
             messageId = replacing
                     ? R.string.vpn_replace_always_on_vpn_enable_message
                     : R.string.vpn_first_always_on_vpn_message;
         } else {
-            messageId = wasAlwaysOn
+            messageId = wasLockdown
                     ? R.string.vpn_replace_always_on_vpn_disable_message
                     : R.string.vpn_replace_vpn_message;
         }
@@ -103,6 +106,7 @@
         if (getTargetFragment() instanceof ConfirmLockdownListener) {
             ((ConfirmLockdownListener) getTargetFragment()).onConfirmLockdown(
                     getArguments().getParcelable(ARG_OPTIONS),
+                    getArguments().getBoolean(ARG_ALWAYS_ON),
                     getArguments().getBoolean(ARG_LOCKDOWN_DST));
         }
     }
diff --git a/src/com/android/settings/vpn2/VpnUtils.java b/src/com/android/settings/vpn2/VpnUtils.java
index 5990381..07e6c52 100644
--- a/src/com/android/settings/vpn2/VpnUtils.java
+++ b/src/com/android/settings/vpn2/VpnUtils.java
@@ -20,6 +20,7 @@
 import android.net.IConnectivityManager;
 import android.os.RemoteException;
 import android.os.ServiceManager;
+import android.provider.Settings;
 import android.security.Credentials;
 import android.security.KeyStore;
 
@@ -53,10 +54,14 @@
         return key.equals(getLockdownVpn());
     }
 
-    public static boolean isAlwaysOnOrLegacyLockdownActive(Context context) {
+    public static boolean isAnyLockdownActive(Context context) {
         final int userId = context.getUserId();
-        return getLockdownVpn() != null
-                || getConnectivityManager(context).getAlwaysOnVpnPackageForUser(userId) != null;
+        if (getLockdownVpn() != null) {
+            return true;
+        }
+        return getConnectivityManager(context).getAlwaysOnVpnPackageForUser(userId) != null
+                && Settings.Secure.getIntForUser(context.getContentResolver(),
+                        Settings.Secure.ALWAYS_ON_VPN_LOCKDOWN, /* default */ 0, userId) != 0;
     }
 
     public static boolean isVpnActive(Context context) throws RemoteException {
diff --git a/tests/robotests/Android.mk b/tests/robotests/Android.mk
index edc810f..0a49be2 100644
--- a/tests/robotests/Android.mk
+++ b/tests/robotests/Android.mk
@@ -12,7 +12,7 @@
     truth-prebuilt
 
 LOCAL_JAVA_LIBRARIES := \
-    junit4-target \
+    junit \
     platform-robolectric-prebuilt \
     sdk_vcurrent
 
diff --git a/tests/robotests/src/com/android/settings/MasterClearTest.java b/tests/robotests/src/com/android/settings/MasterClearTest.java
new file mode 100644
index 0000000..721d0e0
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/MasterClearTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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 static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.when;
+
+import android.widget.LinearLayout;
+import android.widget.ScrollView;
+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 MasterClearTest {
+    private MasterClear mMasterClear;
+    @Mock
+    private ScrollView mScrollView;
+    @Mock
+    private LinearLayout mLinearLayout;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mMasterClear = new MasterClear();
+
+        // Make scrollView only have one child
+        when(mScrollView.getChildAt(0)).thenReturn(mLinearLayout);
+        when(mScrollView.getChildCount()).thenReturn(1);
+    }
+
+    @Test
+    public void testHasReachedBottom_NotScrollDown_returnFalse() {
+        initScrollView(100, 0, 200);
+
+        assertThat(mMasterClear.hasReachedBottom(mScrollView)).isFalse();
+    }
+
+    @Test
+    public void testHasReachedBottom_CanNotScroll_returnTrue() {
+        initScrollView(100, 0, 80);
+
+        assertThat(mMasterClear.hasReachedBottom(mScrollView)).isTrue();
+    }
+
+    @Test
+    public void testHasReachedBottom_ScrollToBottom_returnTrue() {
+        initScrollView(100, 100, 200);
+
+        assertThat(mMasterClear.hasReachedBottom(mScrollView)).isTrue();
+    }
+
+    private void initScrollView(int height, int scrollY, int childBottom) {
+        when(mScrollView.getHeight()).thenReturn(height);
+        when(mScrollView.getScrollY()).thenReturn(scrollY);
+        when(mLinearLayout.getBottom()).thenReturn(childBottom);
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
index 6aa22b2..e4a988f 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
@@ -124,7 +124,7 @@
         tile.intent = new Intent();
         tile.intent.setComponent(new ComponentName("pkg", "class"));
 
-        when(mActivity.getApplicationContext().getSystemService(Context.USER_SERVICE))
+        when(mActivity.getSystemService(Context.USER_SERVICE))
                 .thenReturn(mUserManager);
 
         mImpl.bindPreferenceToTile(mActivity, preference, tile, "123", Preference.DEFAULT_ORDER);
@@ -242,4 +242,9 @@
                 CategoryKey.CATEGORY_HOMEPAGE).isEmpty())
                 .isFalse();
     }
+
+    @Test
+    public void testGetExtraIntentAction_shouldReturnNull() {
+        assertThat(mImpl.getExtraIntentAction()).isNull();
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/dashboard/SupportItemAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/SupportItemAdapterTest.java
index e3d4c94..a877ed2 100644
--- a/tests/robotests/src/com/android/settings/dashboard/SupportItemAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/SupportItemAdapterTest.java
@@ -18,6 +18,7 @@
 
 import android.accounts.Account;
 import android.app.Activity;
+import android.content.Context;
 import android.content.Intent;
 import android.provider.Settings;
 import android.view.LayoutInflater;
@@ -26,7 +27,9 @@
 import android.widget.SpinnerAdapter;
 import com.android.settings.TestConfig;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.settings.dashboard.SupportItemAdapter.EscalationData;
 import com.android.settings.overlay.SupportFeatureProvider;
+import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -38,6 +41,8 @@
 import com.android.settings.R;
 import org.robolectric.shadows.ShadowActivity;
 
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
 import static org.mockito.Mockito.verify;
 import static org.robolectric.Shadows.shadowOf;
 import static org.mockito.Mockito.when;
@@ -111,6 +116,37 @@
         verify(mSupportFeatureProvider).getSupportEligibleAccounts(mActivity);
     }
 
+    @Test
+    public void testRefreshData_CardUpdatedOnEnteringOrLeavingSupportHours() {
+        // pretend we have support right now
+        when(mSupportFeatureProvider.isSupportTypeEnabled(any(), anyInt()))
+                .thenReturn(true);
+        when(mSupportFeatureProvider.isOperatingNow(anyInt())).thenReturn(true);
+        when(mSupportFeatureProvider.getSupportEligibleAccounts(any())).thenReturn(ONE_ACCOUNT);
+        mSupportItemAdapter = new SupportItemAdapter(mActivity, null, mSupportFeatureProvider,
+                mMetricsFeatureProvider, null);
+
+        // If this doesn't return escalation data something has gone wrong
+        EscalationData data = (EscalationData) mSupportItemAdapter.getSupportData().get(0);
+
+        // precondition, support is enabled
+        assertThat(data.enabled1).isTrue();
+
+        // pretend we support hours are over
+        when(mSupportFeatureProvider.isOperatingNow(anyInt())).thenReturn(false);
+        mSupportItemAdapter.refreshData();
+        data = (EscalationData) mSupportItemAdapter.getSupportData().get(0);
+
+        assertThat(data.enabled1).isFalse();
+
+        // pretend support hours have started again
+        when(mSupportFeatureProvider.isOperatingNow(anyInt())).thenReturn(true);
+        mSupportItemAdapter.refreshData();
+        data = (EscalationData) mSupportItemAdapter.getSupportData().get(0);
+
+        assertThat(data.enabled1).isTrue();
+    }
+
     /**
      * Check after {@link SupportItemAdapter#bindAccountPicker(SupportItemAdapter.ViewHolder)} is
      * invoked, whether the spinner in {@paramref viewHolder} has all the data from {@paramref
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
new file mode 100644
index 0000000..ba4a9e3
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
@@ -0,0 +1,94 @@
+package com.android.settings.fuelgauge;
+
+import android.content.Context;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
+
+import static com.android.settings.fuelgauge.PowerUsageBase.MENU_STATS_REFRESH;
+import static com.android.settings.fuelgauge.PowerUsageSummary.MENU_ADDITIONAL_BATTERY_INFO;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Unit tests for {@link PowerUsageSummary}.
+ */
+@RunWith(RobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class PowerUsageSummaryTest {
+
+    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    private Context mContext;
+    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    private Menu mMenu;
+    @Mock
+    private MenuItem mRefresh;
+    @Mock
+    private MenuInflater mMenuInflater;
+
+    private TestFragment mFragment;
+    private FakeFeatureFactory mFeatureFactory;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        FakeFeatureFactory.setupForTest(mContext);
+        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+
+        mFragment = new TestFragment(mContext);
+
+        when(mMenu.add(Menu.NONE, PowerUsageBase.MENU_STATS_REFRESH, Menu.NONE,
+                R.string.menu_stats_refresh)
+                .setIcon(com.android.internal.R.drawable.ic_menu_refresh)
+                .setAlphabeticShortcut('r'))
+                .thenReturn(mRefresh);
+    }
+
+    @Test
+    public void testOnCreateOptionsMenu_additionalBatteryInfoEnabled() {
+        when(mFeatureFactory.powerUsageFeatureProvider.isAdditionalBatteryInfoEnabled())
+                .thenReturn(true);
+
+        mFragment.onCreateOptionsMenu(mMenu, mMenuInflater);
+
+        verify(mMenu).add(Menu.NONE, MENU_ADDITIONAL_BATTERY_INFO,
+                Menu.NONE, R.string.additional_battery_info);
+    }
+
+    @Test
+    public void testOnCreateOptionsMenu_additionalBatteryInfoDisabled() {
+        when(mFeatureFactory.powerUsageFeatureProvider.isAdditionalBatteryInfoEnabled())
+                .thenReturn(false);
+
+        mFragment.onCreateOptionsMenu(mMenu, mMenuInflater);
+
+        verify(mMenu, never()).add(Menu.NONE, MENU_ADDITIONAL_BATTERY_INFO,
+                Menu.NONE, R.string.additional_battery_info);
+    }
+
+    public static class TestFragment extends PowerUsageSummary {
+
+        private Context mContext;
+
+        public TestFragment(Context context) {
+            mContext = context;
+        }
+
+        @Override
+        public Context getContext() {
+            return mContext;
+        }
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
new file mode 100644
index 0000000..40cfed5
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.notification;
+
+import android.content.Context;
+
+import com.android.settings.R;
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class ZenModeSettingsTest {
+
+    private ZenModeSettings mSettings;
+    private Context mContext;
+
+    @Before
+    public void setUp() {
+        mContext = RuntimeEnvironment.application.getApplicationContext();
+        mSettings = spy(ZenModeSettings.class);
+        doReturn(mContext).when(mSettings).getContext();
+    }
+
+    @Test
+    public void testAppend_conditionFalse_shouldNotAppend() {
+        String original = "test";
+
+        final String result = mSettings.append(original, false, R.string.zen_mode_alarms);
+
+        assertThat(result).isEqualTo(original);
+    }
+
+    @Test
+    public void testAppend_conditionTrue_shouldAppend() {
+        String original = "test";
+        String alarm = mContext.getString(R.string.zen_mode_alarms);
+
+        final String result = mSettings.append(original, true, R.string.zen_mode_alarms);
+
+        assertThat(result).contains(alarm);
+    }
+
+}
diff --git a/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java
index d9e2dd6..c0b1b3d 100644
--- a/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java
@@ -61,7 +61,7 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         mActivity = Robolectric.buildActivity(Activity.class).create().visible().get();
-        mProvider = new SearchFeatureProviderImpl(mActivity);
+        mProvider = new SearchFeatureProviderImpl();
     }
 
     @Test
@@ -78,8 +78,8 @@
 
     @Test
     public void testUpdateIndexNewSearch_UsesDatabaseIndexingManager() {
-        mProvider = spy(new SearchFeatureProviderImpl(mActivity));
-        when(mProvider.isEnabled()).thenReturn(true);
+        mProvider = spy(new SearchFeatureProviderImpl());
+        when(mProvider.isEnabled(mActivity)).thenReturn(true);
 
         mProvider.updateIndex(mActivity);
         verify(mProvider).getIndexingManager(any(Context.class));
@@ -87,8 +87,8 @@
 
     @Test
     public void testUpdateIndexNewSearch_UsesIndex() {
-        mProvider = spy(new SearchFeatureProviderImpl(mActivity));
-        when(mProvider.isEnabled()).thenReturn(false);
+        mProvider = spy(new SearchFeatureProviderImpl());
+        when(mProvider.isEnabled(mActivity)).thenReturn(false);
 
         mProvider.updateIndex(mActivity);
         verify(mProvider, never()).getIndexingManager(any(Context.class));
diff --git a/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java b/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
index dc63ca6..1625f35 100644
--- a/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
+++ b/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
@@ -91,7 +91,7 @@
     }
 
     @Override
-    public PowerUsageFeatureProvider getPowerUsageFeatureProvider() {
+    public PowerUsageFeatureProvider getPowerUsageFeatureProvider(Context context) {
         return powerUsageFeatureProvider;
     }
 
@@ -116,7 +116,7 @@
     }
 
     @Override
-    public SearchFeatureProvider getSearchFeatureProvider(Context context) {
+    public SearchFeatureProvider getSearchFeatureProvider() {
         return searchFeatureProvider;
     }