Merge "[WifiSetup] Fix colors during setup" into lmp-dev
diff --git a/res/layout-sw600dp/crypt_keeper_pattern_entry.xml b/res/layout-sw600dp/crypt_keeper_pattern_entry.xml
index 4685ebf..3937008 100644
--- a/res/layout-sw600dp/crypt_keeper_pattern_entry.xml
+++ b/res/layout-sw600dp/crypt_keeper_pattern_entry.xml
@@ -18,26 +18,24 @@
 -->
 
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:orientation="vertical"
     android:layout_width="match_parent"
-    android:layout_height="match_parent">
+    android:layout_height="match_parent"
+    android:orientation="vertical"
+    android:layout_marginTop="@dimen/crypt_keeper_pattern_top_margin">
 
     <include layout="@layout/crypt_keeper_status" />
 
-    <RelativeLayout
-        android:layout_width="wrap_content"
-        android:layout_height="0dip"
-        android:layout_weight="1"
-        android:layout_gravity="center_horizontal">
+    <LinearLayout
+        android:layout_width="@dimen/crypt_keeper_pattern_size"
+        android:layout_height="@dimen/crypt_keeper_pattern_size"
+        android:orientation="horizontal"
+        android:layout_gravity="center_horizontal"
+        android:layout_marginTop="@dimen/crypt_keeper_pattern_separator">
 
-        <!-- Password entry field -->
-        <LinearLayout
-            android:layout_height="@dimen/crypt_keeper_pattern_size"
-            android:layout_width="@dimen/crypt_keeper_pattern_size"
-            android:layout_centerVertical="true"
-            android:orientation="horizontal">
-            <include layout="@layout/crypt_keeper_pattern_field" />
-        </LinearLayout>
+        <include layout="@layout/crypt_keeper_pattern_field" />
 
-    </RelativeLayout>
+    </LinearLayout>
+
+    <include layout="@layout/crypt_keeper_emergency_button" />
+
 </LinearLayout>
diff --git a/res/layout/crypt_keeper_emergency_button.xml b/res/layout/crypt_keeper_emergency_button.xml
new file mode 100644
index 0000000..d0004de
--- /dev/null
+++ b/res/layout/crypt_keeper_emergency_button.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+**
+** Copyright 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.
+*/
+-->
+
+<!-- Emergency call button.
+     Text is set by CryptKeeper.updateEmergencyCallButtonState() -->
+<Button
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/emergencyCallButton"
+    android:layout_width="wrap_content"
+    android:layout_height="0dp"
+    android:layout_gravity="center_horizontal"
+    android:textSize="14sp"
+    android:fontFamily="sans-serif"
+    android:textColor="#FFFFFF"
+    android:layout_weight="1"
+    android:gravity="bottom"
+    style="?android:attr/borderlessButtonStyle" />
diff --git a/res/layout/crypt_keeper_password_entry.xml b/res/layout/crypt_keeper_password_entry.xml
index 6e99527..a7fecba 100644
--- a/res/layout/crypt_keeper_password_entry.xml
+++ b/res/layout/crypt_keeper_password_entry.xml
@@ -20,36 +20,23 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:orientation="vertical">
+    android:orientation="vertical"
+    android:layout_marginTop="@dimen/crypt_keeper_password_top_margin">
 
     <include layout="@layout/crypt_keeper_status" />
 
     <LinearLayout
-        android:layout_height="0dp"
-        android:layout_width="match_parent"
-        android:layout_weight="1"
-        android:layout_marginStart="@dimen/crypt_keeper_edit_text_margin"
-        android:layout_marginEnd="@dimen/crypt_keeper_edit_text_margin"
-        android:orientation="vertical"
-        android:gravity="center_vertical">
+        android:layout_width="@dimen/crypt_keeper_password_width"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal"
+        android:layout_marginTop="16dip"
+        android:layout_gravity="center_horizontal"
+        android:background="@color/crypt_keeper_password_background">
 
-        <LinearLayout
-            android:background="@color/crypt_keeper_password_background"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:orientation="horizontal">
-            <include layout="@layout/crypt_keeper_password_field" />
-        </LinearLayout>
+        <include layout="@layout/crypt_keeper_password_field" />
 
     </LinearLayout>
 
-    <!-- Emergency call button.
-         Text is set by CryptKeeper.updateEmergencyCallButtonState() -->
-    <Button android:id="@+id/emergencyCallButton"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_gravity="center_horizontal"
-        android:layout_marginTop="@dimen/crypt_keeper_emergency_call_space_above"
-        style="?android:attr/borderlessButtonStyle" />
+    <include layout="@layout/crypt_keeper_emergency_button" />
 
 </LinearLayout>
diff --git a/res/layout/crypt_keeper_pattern_entry.xml b/res/layout/crypt_keeper_pattern_entry.xml
index 80e318f..00d3d6e 100644
--- a/res/layout/crypt_keeper_pattern_entry.xml
+++ b/res/layout/crypt_keeper_pattern_entry.xml
@@ -20,35 +20,22 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:orientation="vertical">
+    android:orientation="vertical"
+    android:layout_marginTop="@dimen/crypt_keeper_pattern_top_margin">
 
     <include layout="@layout/crypt_keeper_status" />
 
     <LinearLayout
-        android:layout_height="0dp"
         android:layout_width="match_parent"
-        android:layout_weight="1"
-        android:orientation="vertical"
-        android:gravity="center_vertical">
+        android:layout_height="wrap_content"
+        android:layout_marginStart="@dimen/crypt_keeper_pattern_margin"
+        android:layout_marginEnd="@dimen/crypt_keeper_pattern_margin"
+        android:orientation="horizontal">
 
-        <LinearLayout
-            android:layout_height="wrap_content"
-            android:layout_width="match_parent"
-            android:layout_marginStart="@dimen/crypt_keeper_edit_text_margin"
-            android:layout_marginEnd="@dimen/crypt_keeper_edit_text_margin"
-            android:orientation="horizontal" >
-            <include layout="@layout/crypt_keeper_pattern_field" />
-        </LinearLayout>
+        <include layout="@layout/crypt_keeper_pattern_field" />
 
     </LinearLayout>
 
-    <!-- Emergency call button.
-         Text and icon are set by CryptKeeper.updateEmergencyCallButtonState() -->
-    <Button android:id="@+id/emergencyCallButton"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_gravity="center"
-        android:layout_marginTop="@dimen/crypt_keeper_emergency_call_space_above"
-        style="?android:attr/borderlessButtonStyle" />
+    <include layout="@layout/crypt_keeper_emergency_button" />
 
 </LinearLayout>
diff --git a/res/layout/crypt_keeper_pin_entry.xml b/res/layout/crypt_keeper_pin_entry.xml
index 0bcbec5..3926ab0 100644
--- a/res/layout/crypt_keeper_pin_entry.xml
+++ b/res/layout/crypt_keeper_pin_entry.xml
@@ -20,36 +20,23 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:orientation="vertical">
+    android:orientation="vertical"
+    android:layout_marginTop="@dimen/crypt_keeper_password_top_margin">
 
     <include layout="@layout/crypt_keeper_status" />
 
     <LinearLayout
-        android:layout_height="0dp"
-        android:layout_width="match_parent"
-        android:layout_weight="1"
-        android:layout_marginStart="@dimen/crypt_keeper_edit_text_margin"
-        android:layout_marginEnd="@dimen/crypt_keeper_edit_text_margin"
-        android:orientation="vertical"
-        android:gravity="center_vertical">
+        android:layout_width="@dimen/crypt_keeper_password_width"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="16dip"
+        android:orientation="horizontal"
+        android:layout_gravity="center_horizontal"
+        android:background="@color/crypt_keeper_password_background">
 
-        <LinearLayout
-            android:background="@color/crypt_keeper_password_background"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:orientation="horizontal">
-            <include layout="@layout/crypt_keeper_pin_field" />
-        </LinearLayout>
+        <include layout="@layout/crypt_keeper_pin_field" />
 
     </LinearLayout>
 
-    <!-- Emergency call button.
-         Text is set by CryptKeeper.updateEmergencyCallButtonState() -->
-    <Button android:id="@+id/emergencyCallButton"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_gravity="center_horizontal"
-        android:layout_marginTop="@dimen/crypt_keeper_emergency_call_space_above"
-        style="?android:attr/borderlessButtonStyle" />
+    <include layout="@layout/crypt_keeper_emergency_button" />
 
 </LinearLayout>
diff --git a/res/layout/crypt_keeper_status.xml b/res/layout/crypt_keeper_status.xml
index c366b57..bddff1a 100644
--- a/res/layout/crypt_keeper_status.xml
+++ b/res/layout/crypt_keeper_status.xml
@@ -31,11 +31,11 @@
         android:id="@+id/status"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginTop="10dip"
         android:layout_marginStart="8dip"
         android:layout_marginEnd="8dip"
-        android:textSize="18sp"
-        android:textAppearance="?android:attr/textAppearanceLarge"
+        android:textSize="16sp"
+        android:fontFamily="sans-serif"
+        android:textColor="@android:color/white"
         android:text="@string/enter_password"
         android:layout_gravity="center_horizontal"
         android:gravity="center_horizontal" />
@@ -51,6 +51,8 @@
         android:ellipsize="marquee"
         android:marqueeRepeatLimit ="marquee_forever"
         android:textSize="16sp"
-        android:textAppearance="?android:attr/textAppearanceMedium" />
+        android:fontFamily="sans-serif"
+        android:textColor="#B3FFFFFF"
+        android:gravity="center_horizontal" />
 
 </LinearLayout>
diff --git a/res/layout/mac_preference.xml b/res/layout/mac_preference.xml
new file mode 100644
index 0000000..f096b07
--- /dev/null
+++ b/res/layout/mac_preference.xml
@@ -0,0 +1,79 @@
+<?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:orientation="vertical"
+    android:background="?android:attr/selectableItemBackground">
+
+    <View
+        android:layout_width="fill_parent"
+        android:layout_height="@dimen/wifi_divider_height"
+        android:background="@color/wifi_divider" />
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:minHeight="?android:attr/listPreferredItemHeightSmall"
+        android:gravity="center_vertical"
+        android:background="?android:attr/selectableItemBackground">
+
+        <RelativeLayout
+            android:layout_width="0dip"
+            android:layout_height="wrap_content"
+            android:layout_weight="1"
+            android:paddingTop="6dip"
+            android:paddingBottom="6dip">
+
+            <TextView
+                android:id="@+android:id/title"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:paddingStart="16dip"
+                android:paddingEnd="16dip"
+                android:singleLine="true"
+                android:textAppearance="?android:attr/textAppearanceSmall"
+                android:ellipsize="marquee"
+                android:fadingEdge="horizontal" />
+
+            <TextView
+                android:id="@android:id/summary"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:layout_below="@android:id/title"
+                android:layout_alignStart="@android:id/title"
+                android:paddingStart="16dip"
+                android:layout_marginEnd="16dip"
+                android:visibility="gone"
+                android:textAppearance="?android:attr/textAppearanceSmall"
+                android:textColor="?android:attr/textColorSecondary"
+                android:maxLines="4" />
+
+        </RelativeLayout>
+
+        <LinearLayout
+            android:id="@android:id/widget_frame"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:gravity="center_vertical"
+            android:orientation="vertical" />
+
+    </LinearLayout>
+
+</LinearLayout>
diff --git a/res/layout/radio_info.xml b/res/layout/radio_info.xml
index 760cf80..d81dad6 100644
--- a/res/layout/radio_info.xml
+++ b/res/layout/radio_info.xml
@@ -234,14 +234,6 @@
                 android:layout_height="wrap_content"
                 />
 
-        <!-- Dial over PS (i.e. MO VoLTE) -->
-        <Button android:id="@+id/mo_over_volte"
-            android:textSize="14sp"
-            android:layout_marginTop="8dip"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            />
-
         <!-- LTE ram dump -->
         <Button android:id="@+id/lte_ram_dump"
                 android:textSize="14sp"
diff --git a/res/values-sw600dp-land/dimens.xml b/res/values-sw600dp-land/dimens.xml
index c0a79ad..eb37d0f 100755
--- a/res/values-sw600dp-land/dimens.xml
+++ b/res/values-sw600dp-land/dimens.xml
@@ -20,4 +20,11 @@
     <dimen name="screen_margin_bottom">48dip</dimen>
     <dimen name="appwidget_preview_height">80dip</dimen>
     <dimen name="keyguard_appwidget_picker_width">720dip</dimen>
+
+    <!-- CryptKeeper top margin for password/pin screen -->
+    <dimen name="crypt_keeper_password_top_margin">116dip</dimen>
+
+    <!-- CryptKeeper top margin for pattern screen -->
+    <dimen name="crypt_keeper_pattern_top_margin">128dip</dimen>
+
 </resources>
diff --git a/res/values-sw600dp/dimens.xml b/res/values-sw600dp/dimens.xml
index e040167..e1bb33e 100755
--- a/res/values-sw600dp/dimens.xml
+++ b/res/values-sw600dp/dimens.xml
@@ -55,6 +55,18 @@
     <dimen name="dashboard_tile_image_margin_start">8dp</dimen>
     <dimen name="dashboard_tile_image_margin_end">32dp</dimen>
 
+    <!-- CryptKeeper top margin for password/pin screen -->
+    <dimen name="crypt_keeper_password_top_margin">256dip</dimen>
+
+    <!-- CryptKeeper top margin for pattern screen -->
+    <dimen name="crypt_keeper_pattern_top_margin">256dip</dimen>
+
+    <!-- CryptKeeper separation between status and pattern -->
+    <dimen name="crypt_keeper_pattern_separator">100dip</dimen>
+
+    <!-- CryptKeeper password/pin width -->
+    <dimen name="crypt_keeper_password_width">512dip</dimen>
+
     <!-- SwitchBar margin start / end -->
     <dimen name="switchbar_margin_start">24dp</dimen>
     <dimen name="switchbar_margin_end">24dp</dimen>
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 0b00902..cba8483 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -70,7 +70,7 @@
     <color name="theme_accent">#ff009688</color>
 
     <color name="dashboard_background_color">#ffe1e1e0</color>
-    <color name="switchbar_background_color">#ff384248</color>
+    <color name="switchbar_background_color">#ff37474f</color>
     <color name="switch_accent_color">#ff7fcac3</color>
 
     <color name="default_preference_background_color">@*android:color/background_material_light</color>
@@ -92,4 +92,6 @@
     <!-- Avatar color used for guest -->
     <color name="grey_500">@*android:color/material_grey_500</color>
 
+    <color name="wifi_divider">#ffe0e0e0</color>
+
 </resources>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index cb87bf0..865b029 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -168,8 +168,14 @@
     <dimen name="wifi_assistant_padding">25dp</dimen>
     <dimen name="wifi_assistant_text_padding">16dp</dimen>
 
-    <!-- CryptKeeper edit text margin -->
-    <dimen name="crypt_keeper_edit_text_margin">16dip</dimen>
+    <!-- CryptKeeper top margin for password/pin screen -->
+    <dimen name="crypt_keeper_password_top_margin">88dip</dimen>
+
+    <!-- CryptKeeper top margin for pattern screen -->
+    <dimen name="crypt_keeper_pattern_top_margin">88dip</dimen>
+
+    <!-- CryptKeeper password/pin width -->
+    <dimen name="crypt_keeper_password_width">280dip</dimen>
 
     <!-- CryptKeeper emergency call button dimensions -->
     <dimen name="crypt_keeper_emergency_call_space_above">16dip</dimen>
@@ -177,6 +183,9 @@
     <!-- CryptKeeper edit text ime icon padding -->
     <dimen name="crypt_keeper_edit_text_ime_padding">8dip</dimen>
 
+    <!-- CryptKeeper pattern margin on phone -->
+    <dimen name="crypt_keeper_pattern_margin">8dip</dimen>
+
     <!-- CryptKeeper pattern size for tablet -->
     <dimen name="crypt_keeper_pattern_size">354dip</dimen>
 
@@ -208,4 +217,6 @@
     <dimen name="bluetooth_dialog_padding">8dip</dimen>
     <integer name="bluetooth_name_length">32</integer>
 
+    <dimen name="wifi_divider_height">1px</dimen>
+
 </resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 864d83c..f8d5c2c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -67,11 +67,6 @@
     <!-- Phone SMS over IMS off. Only shown in diagnostic screen, so precise translation is not needed. -->
     <string name="sms_over_ims_off">Turn off SMS over IMS</string>
 
-    <!-- MO over PS/VoLTE. Only shown in diagnostic screen, so precise translation is not needed. -->
-    <string name="mo_over_volte_on">Enable MO over PS/VoLTE</string>
-    <!-- MO over PS/VoLTE. Only shown in diagnostic screen, so precise translation is not needed. -->
-    <string name="mo_over_volte_off">Disable MO over PS/VoLTE</string>
-
     <!-- Phone SMS over IMS IMS registration required on. Only shown in diagnostic screen, so precise translation is not needed. -->
     <string name="ims_reg_required_on">Turn on IMS registration required</string>
     <!-- Phone IMS registration required off. Only shown in diagnostic screen, so precise translation is not needed. -->
@@ -275,7 +270,7 @@
     <string name="bluetooth_empty_list_user_restricted">You don\'t have permission to change Bluetooth settings.</string>
 
     <!-- Bluetooth Visibility message.  This message informs the user that their device is now visible to other bluetooth devices.  [CHAR LIMIT=50] -->
-    <string name="bluetooth_is_visible_message"><xliff:g id="device_name">%1$s</xliff:g> is now visible to nearby devices.</string>
+    <string name="bluetooth_is_visible_message"><xliff:g id="device_name">%1$s</xliff:g> is visible to nearby devices while Bluetooth Settings is open.</string>
     <!-- Bluetooth Visibility discoonect question.  Asks the user if they wish to disconnect a paired bluetooth device.  [CHAR LIMIT=50] -->
     <string name="bluetooth_is_disconnect_question">Disconnect <xliff:g id="device_name">%1$s</xliff:g>?</string>
     <!-- Bluetooth broadcasting settings, option to enable/disable broadcasting -->
@@ -1491,7 +1486,7 @@
     <!-- Checkbox title for option to Automatically manage Wi\u2011Fi  [CHAR LIMIT=40] -->
     <string name="wifi_automatically_manage_title">Automatically manage Wi\u2011Fi</string>
     <!-- Checkbox summary for option to Automatically manage Wi\u2011Fi  [CHAR LIMIT=100] -->
-    <string name="wifi_automatically_manage_summary">Let a Wi\u2011Fi assistant manage your Wi\u2011Fi connection</string>
+    <string name="wifi_automatically_manage_summary">Let <xliff:g id="wifi_assistant">%1$s</xliff:g> manage your Wi\u2011Fi connection</string>
     <!-- Checkbox title for option for Wi\u2011Fi Assistant  [CHAR LIMIT=40] -->
     <string name="wifi_assistant_setting_title">Wi\u2011Fi assistant</string>
     <!-- Checkbox summary for option for Wi\u2011Fi Assistant  [CHAR LIMIT=40] -->
diff --git a/res/xml/security_settings_biometric_weak.xml b/res/xml/security_settings_biometric_weak.xml
index 750a270..4879fe6 100644
--- a/res/xml/security_settings_biometric_weak.xml
+++ b/res/xml/security_settings_biometric_weak.xml
@@ -31,12 +31,12 @@
             android:key="biometric_weak_improve_matching"
             android:title="@string/biometric_weak_improve_matching_title"/>
 
-        <CheckBoxPreference
+        <SwitchPreference
            android:key="biometric_weak_liveliness"
            android:title="@string/biometric_weak_liveliness_title"
            android:summary="@string/biometric_weak_liveliness_summary"/>
 
-        <CheckBoxPreference
+        <SwitchPreference
             android:key="visiblepattern"
             android:title="@string/lockpattern_settings_enable_visible_pattern_title"/>
 
@@ -48,7 +48,7 @@
             android:entryValues="@array/lock_after_timeout_values"
             android:persistent="false"/>
 
-        <CheckBoxPreference
+        <SwitchPreference
             android:key="power_button_instantly_locks"
             android:title="@string/lockpattern_settings_enable_power_button_instantly_locks"/>
 
diff --git a/res/xml/security_settings_misc.xml b/res/xml/security_settings_misc.xml
index 7219a6c..a0e81b2 100644
--- a/res/xml/security_settings_misc.xml
+++ b/res/xml/security_settings_misc.xml
@@ -36,7 +36,7 @@
     <PreferenceCategory android:title="@string/security_passwords_title"
             android:persistent="false">
 
-        <CheckBoxPreference android:key="show_password"
+        <SwitchPreference android:key="show_password"
                 android:title="@string/show_password"
                 android:persistent="false"/>
 
@@ -52,7 +52,7 @@
                 android:persistent="false"
                 android:fragment="com.android.settings.DeviceAdminSettings"/>
 
-        <CheckBoxPreference android:key="toggle_install_applications"
+        <SwitchPreference android:key="toggle_install_applications"
                 android:title="@string/install_applications"
                 android:summaryOff="@string/install_unknown_applications"
                 android:summaryOn="@string/install_unknown_applications"
diff --git a/res/xml/security_settings_password.xml b/res/xml/security_settings_password.xml
index bb9c360..b6ea76e 100644
--- a/res/xml/security_settings_password.xml
+++ b/res/xml/security_settings_password.xml
@@ -35,7 +35,7 @@
             android:entryValues="@array/lock_after_timeout_values"
             android:persistent="false"/>
 
-        <CheckBoxPreference
+        <SwitchPreference
             android:key="power_button_instantly_locks"
             android:title="@string/lockpattern_settings_enable_power_button_instantly_locks"/>
 
diff --git a/res/xml/security_settings_pattern.xml b/res/xml/security_settings_pattern.xml
index 168a685..cb848c6 100644
--- a/res/xml/security_settings_pattern.xml
+++ b/res/xml/security_settings_pattern.xml
@@ -27,7 +27,7 @@
             android:summary="@string/unlock_set_unlock_mode_pattern"
             android:persistent="false"/>
 
-        <CheckBoxPreference
+        <SwitchPreference
             android:key="visiblepattern"
             android:title="@string/lockpattern_settings_enable_visible_pattern_title"/>
 
@@ -39,7 +39,7 @@
             android:entryValues="@array/lock_after_timeout_values"
             android:persistent="false"/>
 
-        <CheckBoxPreference
+        <SwitchPreference
             android:key="power_button_instantly_locks"
             android:title="@string/lockpattern_settings_enable_power_button_instantly_locks"/>
 
diff --git a/res/xml/security_settings_pin.xml b/res/xml/security_settings_pin.xml
index 4ead03f..e45bdf5 100644
--- a/res/xml/security_settings_pin.xml
+++ b/res/xml/security_settings_pin.xml
@@ -35,7 +35,7 @@
             android:entryValues="@array/lock_after_timeout_values"
             android:persistent="false"/>
 
-        <CheckBoxPreference
+        <SwitchPreference
             android:key="power_button_instantly_locks"
             android:title="@string/lockpattern_settings_enable_power_button_instantly_locks"/>
 
diff --git a/res/xml/wifi_advanced_settings.xml b/res/xml/wifi_advanced_settings.xml
index 118f691..f83a106 100644
--- a/res/xml/wifi_advanced_settings.xml
+++ b/res/xml/wifi_advanced_settings.xml
@@ -18,31 +18,30 @@
         android:title="@string/wifi_advanced_titlebar">
 
     <!-- android:dependency="enable_wifi" -->
-    <CheckBoxPreference
+    <SwitchPreference
             android:key="notify_open_networks"
             android:title="@string/wifi_notify_open_networks"
             android:summary="@string/wifi_notify_open_networks_summary"
             android:persistent="false" />
 
+    <SwitchPreference
+            android:key="wifi_scan_always_available"
+            android:title="@string/wifi_scan_always_available"
+            android:summary="@string/wifi_scan_always_available_summary"
+            android:persistent="false" />
+
+    <SwitchPreference
+            android:key="wifi_assistant"
+            android:title="@string/wifi_automatically_manage_title"
+            android:summary="@string/wifi_assistant_setting_summary"
+            android:persistent="false" />
+
     <ListPreference
             android:key="sleep_policy"
             android:title="@string/wifi_setting_sleep_policy_title"
             android:persistent="false"
             android:entries="@array/wifi_sleep_policy_entries"
-            android:entryValues="@array/wifi_sleep_policy_values"
-            />
-    <CheckBoxPreference
-            android:key="wifi_scan_always_available"
-            android:title="@string/wifi_scan_always_available"
-            android:summary="@string/wifi_scan_always_available_summary"
-            android:persistent="false" />
-
-    <!-- android:dependency="enable_wifi" -->
-    <CheckBoxPreference
-            android:key="wifi_poor_network_detection"
-            android:title="@string/wifi_poor_network_detection"
-            android:summary="@string/wifi_poor_network_detection_summary"
-            android:persistent="false" />
+            android:entryValues="@array/wifi_sleep_policy_values" />
 
     <ListPreference
             android:key="frequency_band"
@@ -50,8 +49,7 @@
             android:summary="@string/wifi_setting_frequency_band_summary"
             android:persistent="false"
             android:entries="@array/wifi_frequency_band_entries"
-            android:entryValues="@array/wifi_frequency_band_values"
-            />
+            android:entryValues="@array/wifi_frequency_band_values" />
 
     <Preference
             android:key="install_credentials"
@@ -73,16 +71,10 @@
             android:title="@string/wifi_menu_wps_pin"
             android:persistent="false" />
 
-    <CheckBoxPreference
-            android:key="suspend_optimizations"
-            android:title="@string/wifi_suspend_optimizations"
-            android:summary="@string/wifi_suspend_optimizations_summary"
-            android:persistent="false" />
-
     <Preference
             android:key="mac_address"
             android:title="@string/wifi_advanced_mac_address_title"
-            android:layout="@layout/wifi_advance_layout" />
+            android:layout="@layout/mac_preference" />
 
     <Preference
             android:key="current_ip_address"
diff --git a/src/com/android/settings/RadioInfo.java b/src/com/android/settings/RadioInfo.java
index 75de222..b0a4a53 100644
--- a/src/com/android/settings/RadioInfo.java
+++ b/src/com/android/settings/RadioInfo.java
@@ -303,9 +303,6 @@
         imsRegRequiredButton = (Button) findViewById(R.id.ims_reg_required);
         imsRegRequiredButton.setOnClickListener(mImsRegRequiredHandler);
 
-        moOverVolteButton = (Button) findViewById(R.id.mo_over_volte);
-        moOverVolteButton.setOnClickListener(mMoOverVolteHandler);
-
         smsOverImsButton = (Button) findViewById(R.id.sms_over_ims);
         smsOverImsButton.setOnClickListener(mSmsOverImsHandler);
 
@@ -363,7 +360,6 @@
         updatePowerState();
         updateCellInfoListRate();
         updateImsRegRequiredState();
-        updateMoOverImsState();
         updateSmsOverImsState();
         updateLteRamDumpState();
         updateProperties();
@@ -989,35 +985,6 @@
         imsRegRequiredButton.setText(buttonText);
     }
 
-    private Button moOverVolteButton;
-    OnClickListener mMoOverVolteHandler = new OnClickListener() {
-        @Override
-        public void onClick(View v) {
-            boolean moOverVolteEnabled = isMoOverVolteEnabled();
-            log(String.format("toggle %s: currently %s",
-                    TelephonyProperties.PROPERTY_DBG_IMS_VOLTE_ENABLE,
-                    (moOverVolteEnabled ? "on" : "off")));
-            boolean newValue = !moOverVolteEnabled;
-            SystemProperties.set(TelephonyProperties.PROPERTY_DBG_IMS_VOLTE_ENABLE,
-                    newValue ? "1" : "0");
-            updateMoOverImsState();
-        }
-    };
-
-    private boolean isMoOverVolteEnabled() {
-        return SystemProperties.getInt(TelephonyProperties.PROPERTY_DBG_IMS_VOLTE_ENABLE,
-                TelephonyProperties.PROPERTY_DBG_IMS_VOLTE_ENABLE_DEAFULT) == 1;
-    }
-
-    private void updateMoOverImsState() {
-        boolean moOverVolteEnabled = isMoOverVolteEnabled();
-        log("updateMoOverImsState isMoOverVolteEnabled()=" + moOverVolteEnabled);
-        String buttonText = moOverVolteEnabled ?
-                getString(R.string.mo_over_volte_off) :
-                getString(R.string.mo_over_volte_on);
-        moOverVolteButton.setText(buttonText);
-    }
-
     private Button smsOverImsButton;
     static final String PROPERTY_SMS_OVER_IMS = "persist.radio.imsallowmtsms";
     OnClickListener mSmsOverImsHandler = new OnClickListener() {
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index 1fb5e13..7f51599 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -31,7 +31,7 @@
 import android.os.Bundle;
 import android.os.UserHandle;
 import android.os.UserManager;
-import android.preference.CheckBoxPreference;
+import android.preference.SwitchPreference;
 import android.preference.ListPreference;
 import android.preference.Preference;
 import android.preference.Preference.OnPreferenceChangeListener;
@@ -99,6 +99,11 @@
     private static final String KEY_TRUST_AGENT = "trust_agent";
     private static final String KEY_SCREEN_PINNING = "screen_pinning_settings";
 
+    // These switch preferences need special handling since they're not all stored in Settings.
+    private static final String SWITCH_PREFERENCE_KEYS[] = { KEY_LOCK_AFTER_TIMEOUT,
+            KEY_LOCK_ENABLED, KEY_VISIBLE_PATTERN, KEY_BIOMETRIC_WEAK_LIVELINESS,
+            KEY_POWER_INSTANTLY_LOCKS, KEY_SHOW_PASSWORD, KEY_TOGGLE_INSTALL_APPLICATIONS };
+
     // Only allow one trust agent on the platform.
     private static final boolean ONLY_ONE_TRUST_AGENT = true;
 
@@ -108,17 +113,17 @@
     private LockPatternUtils mLockPatternUtils;
     private ListPreference mLockAfter;
 
-    private CheckBoxPreference mBiometricWeakLiveliness;
-    private CheckBoxPreference mVisiblePattern;
+    private SwitchPreference mBiometricWeakLiveliness;
+    private SwitchPreference mVisiblePattern;
 
-    private CheckBoxPreference mShowPassword;
+    private SwitchPreference mShowPassword;
 
     private KeyStore mKeyStore;
     private Preference mResetCredentials;
 
-    private CheckBoxPreference mToggleAppInstallation;
+    private SwitchPreference mToggleAppInstallation;
     private DialogInterface mWarnInstallApps;
-    private CheckBoxPreference mPowerButtonInstantlyLocks;
+    private SwitchPreference mPowerButtonInstantlyLocks;
 
     private boolean mIsPrimary;
 
@@ -249,13 +254,13 @@
 
         // biometric weak liveliness
         mBiometricWeakLiveliness =
-                (CheckBoxPreference) root.findPreference(KEY_BIOMETRIC_WEAK_LIVELINESS);
+                (SwitchPreference) root.findPreference(KEY_BIOMETRIC_WEAK_LIVELINESS);
 
         // visible pattern
-        mVisiblePattern = (CheckBoxPreference) root.findPreference(KEY_VISIBLE_PATTERN);
+        mVisiblePattern = (SwitchPreference) root.findPreference(KEY_VISIBLE_PATTERN);
 
         // lock instantly on power key press
-        mPowerButtonInstantlyLocks = (CheckBoxPreference) root.findPreference(
+        mPowerButtonInstantlyLocks = (SwitchPreference) root.findPreference(
                 KEY_POWER_INSTANTLY_LOCKS);
         Preference trustAgentPreference = root.findPreference(KEY_TRUST_AGENT);
         if (mPowerButtonInstantlyLocks != null &&
@@ -302,7 +307,7 @@
         }
 
         // Show password
-        mShowPassword = (CheckBoxPreference) root.findPreference(KEY_SHOW_PASSWORD);
+        mShowPassword = (SwitchPreference) root.findPreference(KEY_SHOW_PASSWORD);
         mResetCredentials = root.findPreference(KEY_RESET_CREDENTIALS);
 
         // Credential storage
@@ -326,7 +331,7 @@
         // Application install
         PreferenceGroup deviceAdminCategory = (PreferenceGroup)
                 root.findPreference(KEY_DEVICE_ADMIN_CATEGORY);
-        mToggleAppInstallation = (CheckBoxPreference) findPreference(
+        mToggleAppInstallation = (SwitchPreference) findPreference(
                 KEY_TOGGLE_INSTALL_APPLICATIONS);
         mToggleAppInstallation.setChecked(isNonMarketAppsAllowed());
         // Side loading of apps.
@@ -341,7 +346,7 @@
                 (PreferenceGroup)root.findPreference(KEY_ADVANCED_SECURITY);
         if (advancedCategory != null && !mLockPatternUtils.isSecure()) {
             Preference manageAgents = advancedCategory.findPreference(KEY_MANAGE_TRUST_AGENTS);
-            if (advancedCategory != null) advancedCategory.removePreference(manageAgents);
+            if (manageAgents != null) advancedCategory.removePreference(manageAgents);
         }
 
         // The above preferences come and go based on security state, so we need to update
@@ -350,6 +355,10 @@
         Index.getInstance(getActivity())
                 .updateFromClassNameResource(SecuritySettings.class.getName(), true, true);
 
+        for (int i = 0; i < SWITCH_PREFERENCE_KEYS.length; i++) {
+            final Preference pref = findPreference(SWITCH_PREFERENCE_KEYS[i]);
+            if (pref != null) pref.setOnPreferenceChangeListener(this);
+        }
         return root;
     }
 
@@ -523,8 +532,6 @@
     @Override
     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
         final String key = preference.getKey();
-
-        final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
         if (KEY_UNLOCK_SET_OR_CHANGE.equals(key)) {
             startFragment(this, "com.android.settings.ChooseLockGeneric$ChooseLockGenericFragment",
                     R.string.lock_settings_picker_title, SET_OR_CHANGE_LOCK_METHOD_REQUEST, null);
@@ -539,42 +546,6 @@
                 // can't be reached, but is here in case things change in the future
                 startBiometricWeakImprove();
             }
-        } else if (KEY_BIOMETRIC_WEAK_LIVELINESS.equals(key)) {
-            if (isToggled(preference)) {
-                lockPatternUtils.setBiometricWeakLivelinessEnabled(true);
-            } else {
-                // In this case the user has just unchecked the checkbox, but this action requires
-                // them to confirm their password.  We need to re-check the checkbox until
-                // they've confirmed their password
-                mBiometricWeakLiveliness.setChecked(true);
-                ChooseLockSettingsHelper helper =
-                        new ChooseLockSettingsHelper(this.getActivity(), this);
-                if (!helper.launchConfirmationActivity(
-                                CONFIRM_EXISTING_FOR_BIOMETRIC_WEAK_LIVELINESS_OFF, null, null)) {
-                    // If this returns false, it means no password confirmation is required, so
-                    // go ahead and uncheck it here.
-                    // Note: currently a backup is required for biometric_weak so this code path
-                    // can't be reached, but is here in case things change in the future
-                    lockPatternUtils.setBiometricWeakLivelinessEnabled(false);
-                    mBiometricWeakLiveliness.setChecked(false);
-                }
-            }
-        } else if (KEY_LOCK_ENABLED.equals(key)) {
-            lockPatternUtils.setLockPatternEnabled(isToggled(preference));
-        } else if (KEY_VISIBLE_PATTERN.equals(key)) {
-            lockPatternUtils.setVisiblePatternEnabled(isToggled(preference));
-        } else if (KEY_POWER_INSTANTLY_LOCKS.equals(key)) {
-            lockPatternUtils.setPowerButtonInstantlyLocks(isToggled(preference));
-        } else if (preference == mShowPassword) {
-            Settings.System.putInt(getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD,
-                    mShowPassword.isChecked() ? 1 : 0);
-        } else if (preference == mToggleAppInstallation) {
-            if (mToggleAppInstallation.isChecked()) {
-                mToggleAppInstallation.setChecked(false);
-                warnAppInstallation();
-            } else {
-                setNonMarketAppsAllowed(false);
-            }
         } else if (KEY_TRUST_AGENT.equals(key)) {
             ChooseLockSettingsHelper helper =
                     new ChooseLockSettingsHelper(this.getActivity(), this);
@@ -589,14 +560,9 @@
             // If we didn't handle it, let preferences handle it.
             return super.onPreferenceTreeClick(preferenceScreen, preference);
         }
-
         return true;
     }
 
-    private boolean isToggled(Preference pref) {
-        return ((CheckBoxPreference) pref).isChecked();
-    }
-
     /**
      * see confirmPatternThenDisableAndClear
      */
@@ -629,7 +595,9 @@
 
     @Override
     public boolean onPreferenceChange(Preference preference, Object value) {
-        if (preference == mLockAfter) {
+        final String key = preference.getKey();
+        final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
+        if (KEY_LOCK_AFTER_TIMEOUT.equals(key)) {
             int timeout = Integer.parseInt((String) value);
             try {
                 Settings.Secure.putInt(getContentResolver(),
@@ -638,6 +606,42 @@
                 Log.e("SecuritySettings", "could not persist lockAfter timeout setting", e);
             }
             updateLockAfterPreferenceSummary();
+        } else if (KEY_LOCK_ENABLED.equals(key)) {
+            lockPatternUtils.setLockPatternEnabled((Boolean) value);
+        } else if (KEY_VISIBLE_PATTERN.equals(key)) {
+            lockPatternUtils.setVisiblePatternEnabled((Boolean) value);
+        } else  if (KEY_BIOMETRIC_WEAK_LIVELINESS.equals(key)) {
+            if ((Boolean) value) {
+                lockPatternUtils.setBiometricWeakLivelinessEnabled(true);
+            } else {
+                // In this case the user has just unchecked the checkbox, but this action requires
+                // them to confirm their password.  We need to re-check the checkbox until
+                // they've confirmed their password
+                mBiometricWeakLiveliness.setChecked(true);
+                ChooseLockSettingsHelper helper =
+                        new ChooseLockSettingsHelper(this.getActivity(), this);
+                if (!helper.launchConfirmationActivity(
+                                CONFIRM_EXISTING_FOR_BIOMETRIC_WEAK_LIVELINESS_OFF, null, null)) {
+                    // If this returns false, it means no password confirmation is required, so
+                    // go ahead and uncheck it here.
+                    // Note: currently a backup is required for biometric_weak so this code path
+                    // can't be reached, but is here in case things change in the future
+                    lockPatternUtils.setBiometricWeakLivelinessEnabled(false);
+                    mBiometricWeakLiveliness.setChecked(false);
+                }
+            }
+        } else if (KEY_POWER_INSTANTLY_LOCKS.equals(key)) {
+            mLockPatternUtils.setPowerButtonInstantlyLocks((Boolean) value);
+        } else if (KEY_SHOW_PASSWORD.equals(key)) {
+            Settings.System.putInt(getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD,
+                    ((Boolean) value) ? 1 : 0);
+        } else if (KEY_TOGGLE_INSTALL_APPLICATIONS.equals(key)) {
+            if ((Boolean) value) {
+                mToggleAppInstallation.setChecked(false);
+                warnAppInstallation();
+            } else {
+                setNonMarketAppsAllowed(false);
+            }
         }
         return true;
     }
diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java
index 4b278ac..bbd86a1 100755
--- a/src/com/android/settings/bluetooth/BluetoothSettings.java
+++ b/src/com/android/settings/bluetooth/BluetoothSettings.java
@@ -249,6 +249,8 @@
         if (!mAvailableDevicesCategoryIsPresent) {
             getPreferenceScreen().addPreference(mAvailableDevicesCategory);
         }
+        mLocalManager.getCachedDeviceManager().clearCachedDevices();
+        mAvailableDevicesCategory.removeAll();
         mLocalAdapter.startScanning(true);
     }
 
@@ -405,7 +407,7 @@
                 LayoutInflater inflater = getActivity().getLayoutInflater();
                 mSettingsDialogView = inflater.inflate(R.layout.bluetooth_device_picker, null);
                 profileFrag = (DeviceProfilesSettings)activity.getFragmentManager()
-                .findFragmentById(R.id.bluetooth_fragment_settings);
+                    .findFragmentById(R.id.bluetooth_fragment_settings);
             }
 
             final View dialogLayout = mSettingsDialogView;
diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java b/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java
index ff282cc..0b53b1a 100755
--- a/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java
+++ b/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java
@@ -86,7 +86,9 @@
             BluetoothDevice device) {
         CachedBluetoothDevice newDevice = new CachedBluetoothDevice(mContext, adapter,
             profileManager, device);
-        mCachedDevices.add(newDevice);
+        synchronized (mCachedDevices) {
+            mCachedDevices.add(newDevice);
+        }
         return newDevice;
     }
 
@@ -110,6 +112,10 @@
         return device.getAddress();
     }
 
+    public synchronized void clearCachedDevices() {
+        mCachedDevices.clear();
+    }
+
     public synchronized void onScanningStateChanged(boolean started) {
         if (!started) return;
 
diff --git a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
index f482ecd..e7208b5 100644
--- a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
+++ b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
@@ -167,6 +167,12 @@
      }
 
     void createDevicePreference(CachedBluetoothDevice cachedDevice) {
+        if (mDeviceListGroup == null) {
+            Log.w(TAG, "Trying to create a device preference before the list group/category "
+                    + "exists!");
+            return;
+        }
+
         BluetoothDevicePreference preference = new BluetoothDevicePreference(
                 getActivity(), cachedDevice);
 
diff --git a/src/com/android/settings/wifi/AdvancedWifiSettings.java b/src/com/android/settings/wifi/AdvancedWifiSettings.java
index b7316d0..236aecd 100644
--- a/src/com/android/settings/wifi/AdvancedWifiSettings.java
+++ b/src/com/android/settings/wifi/AdvancedWifiSettings.java
@@ -20,6 +20,9 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.net.NetworkScoreManager;
+import android.net.NetworkScorerAppManager;
+import android.net.NetworkScorerAppManager.NetworkScorerAppData;
 import android.net.wifi.WifiInfo;
 import android.net.wifi.WifiManager;
 import android.net.wifi.WpsInfo;
@@ -29,6 +32,7 @@
 import android.preference.Preference;
 import android.preference.Preference.OnPreferenceClickListener;
 import android.preference.PreferenceScreen;
+import android.preference.SwitchPreference;
 import android.provider.Settings;
 import android.provider.Settings.Global;
 import android.security.Credentials;
@@ -40,6 +44,8 @@
 import com.android.settings.SettingsPreferenceFragment;
 import com.android.settings.Utils;
 
+import java.util.Collection;
+
 public class AdvancedWifiSettings extends SettingsPreferenceFragment
         implements Preference.OnPreferenceChangeListener {
 
@@ -49,13 +55,12 @@
     private static final String KEY_FREQUENCY_BAND = "frequency_band";
     private static final String KEY_NOTIFY_OPEN_NETWORKS = "notify_open_networks";
     private static final String KEY_SLEEP_POLICY = "sleep_policy";
-    private static final String KEY_POOR_NETWORK_DETECTION = "wifi_poor_network_detection";
     private static final String KEY_SCAN_ALWAYS_AVAILABLE = "wifi_scan_always_available";
     private static final String KEY_INSTALL_CREDENTIALS = "install_credentials";
+    private static final String KEY_WIFI_ASSISTANT = "wifi_assistant";
     private static final String KEY_WIFI_DIRECT = "wifi_direct";
     private static final String KEY_WPS_PUSH = "wps_push_button";
     private static final String KEY_WPS_PIN = "wps_pin_entry";
-    private static final String KEY_SUSPEND_OPTIMIZATIONS = "suspend_optimizations";
 
     private WifiManager mWifiManager;
 
@@ -102,27 +107,14 @@
     }
 
     private void initPreferences() {
-        CheckBoxPreference notifyOpenNetworks =
-            (CheckBoxPreference) findPreference(KEY_NOTIFY_OPEN_NETWORKS);
+        SwitchPreference notifyOpenNetworks =
+            (SwitchPreference) findPreference(KEY_NOTIFY_OPEN_NETWORKS);
         notifyOpenNetworks.setChecked(Settings.Global.getInt(getContentResolver(),
                 Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 0) == 1);
         notifyOpenNetworks.setEnabled(mWifiManager.isWifiEnabled());
 
-        CheckBoxPreference poorNetworkDetection =
-            (CheckBoxPreference) findPreference(KEY_POOR_NETWORK_DETECTION);
-        if (poorNetworkDetection != null) {
-            if (Utils.isWifiOnly(getActivity())) {
-                getPreferenceScreen().removePreference(poorNetworkDetection);
-            } else {
-                poorNetworkDetection.setChecked(Global.getInt(getContentResolver(),
-                        Global.WIFI_WATCHDOG_POOR_NETWORK_TEST_ENABLED,
-                        WifiManager.DEFAULT_POOR_NETWORK_AVOIDANCE_ENABLED ?
-                        1 : 0) == 1);
-            }
-        }
-
-        CheckBoxPreference scanAlwaysAvailable =
-            (CheckBoxPreference) findPreference(KEY_SCAN_ALWAYS_AVAILABLE);
+        SwitchPreference scanAlwaysAvailable =
+            (SwitchPreference) findPreference(KEY_SCAN_ALWAYS_AVAILABLE);
         scanAlwaysAvailable.setChecked(Global.getInt(getContentResolver(),
                     Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1);
 
@@ -133,7 +125,20 @@
         Preference pref = findPreference(KEY_INSTALL_CREDENTIALS);
         pref.setIntent(intent);
 
-        Intent wifiDirectIntent = new Intent(getActivity(),
+        final Context context = getActivity();
+        NetworkScorerAppData scorer = WifiSettings.getWifiAssistantApp(context);
+        SwitchPreference wifiAssistant = (SwitchPreference)findPreference(KEY_WIFI_ASSISTANT);
+        if (scorer != null) {
+            final boolean checked = NetworkScorerAppManager.getActiveScorer(context) != null;
+            wifiAssistant.setSummary(getResources().getString(
+                    R.string.wifi_automatically_manage_summary, scorer.mScorerName));
+            wifiAssistant.setOnPreferenceChangeListener(this);
+            wifiAssistant.setChecked(checked);
+        } else {
+            getPreferenceScreen().removePreference(wifiAssistant);
+        }
+
+        Intent wifiDirectIntent = new Intent(context,
                 com.android.settings.Settings.WifiP2pSettingsActivity.class);
         Preference wifiDirectPref = findPreference(KEY_WIFI_DIRECT);
         wifiDirectPref.setIntent(wifiDirectIntent);
@@ -142,7 +147,7 @@
         Preference wpsPushPref = findPreference(KEY_WPS_PUSH);
         wpsPushPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                 public boolean onPreferenceClick(Preference arg0) {
-                    WpsDialog wpsDialog = new WpsDialog(getActivity(), WpsInfo.PBC);
+                    WpsDialog wpsDialog = new WpsDialog(context, WpsInfo.PBC);
                     wpsDialog.show();
                     return true;
                 }
@@ -152,17 +157,12 @@
         Preference wpsPinPref = findPreference(KEY_WPS_PIN);
         wpsPinPref.setOnPreferenceClickListener(new OnPreferenceClickListener(){
                 public boolean onPreferenceClick(Preference arg0) {
-                    WpsDialog wpsDialog = new WpsDialog(getActivity(), WpsInfo.DISPLAY);
+                    WpsDialog wpsDialog = new WpsDialog(context, WpsInfo.DISPLAY);
                     wpsDialog.show();
                     return true;
                 }
         });
 
-        CheckBoxPreference suspendOptimizations =
-            (CheckBoxPreference) findPreference(KEY_SUSPEND_OPTIMIZATIONS);
-        suspendOptimizations.setChecked(Global.getInt(getContentResolver(),
-                Global.WIFI_SUSPEND_OPTIMIZATIONS_ENABLED, 1) == 1);
-
         ListPreference frequencyPref = (ListPreference) findPreference(KEY_FREQUENCY_BAND);
 
         if (mWifiManager.isDualBandSupported()) {
@@ -183,7 +183,7 @@
 
         ListPreference sleepPolicyPref = (ListPreference) findPreference(KEY_SLEEP_POLICY);
         if (sleepPolicyPref != null) {
-            if (Utils.isWifiOnly(getActivity())) {
+            if (Utils.isWifiOnly(context)) {
                 sleepPolicyPref.setEntries(R.array.wifi_sleep_policy_entries_wifi_only);
             }
             sleepPolicyPref.setOnPreferenceChangeListener(this);
@@ -228,19 +228,11 @@
         if (KEY_NOTIFY_OPEN_NETWORKS.equals(key)) {
             Global.putInt(getContentResolver(),
                     Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
-                    ((CheckBoxPreference) preference).isChecked() ? 1 : 0);
-        } else if (KEY_POOR_NETWORK_DETECTION.equals(key)) {
-            Global.putInt(getContentResolver(),
-                    Global.WIFI_WATCHDOG_POOR_NETWORK_TEST_ENABLED,
-                    ((CheckBoxPreference) preference).isChecked() ? 1 : 0);
-        } else if (KEY_SUSPEND_OPTIMIZATIONS.equals(key)) {
-            Global.putInt(getContentResolver(),
-                    Global.WIFI_SUSPEND_OPTIMIZATIONS_ENABLED,
-                    ((CheckBoxPreference) preference).isChecked() ? 1 : 0);
+                    ((SwitchPreference) preference).isChecked() ? 1 : 0);
         } else if (KEY_SCAN_ALWAYS_AVAILABLE.equals(key)) {
             Global.putInt(getContentResolver(),
                     Global.WIFI_SCAN_ALWAYS_AVAILABLE,
-                    ((CheckBoxPreference) preference).isChecked() ? 1 : 0);
+                    ((SwitchPreference) preference).isChecked() ? 1 : 0);
         } else {
             return super.onPreferenceTreeClick(screen, preference);
         }
@@ -249,6 +241,7 @@
 
     @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
+        final Context context = getActivity();
         String key = preference.getKey();
 
         if (KEY_FREQUENCY_BAND.equals(key)) {
@@ -257,10 +250,32 @@
                 mWifiManager.setFrequencyBand(value, true);
                 updateFrequencyBandSummary(preference, value);
             } catch (NumberFormatException e) {
-                Toast.makeText(getActivity(), R.string.wifi_setting_frequency_band_error,
+                Toast.makeText(context, R.string.wifi_setting_frequency_band_error,
                         Toast.LENGTH_SHORT).show();
                 return false;
             }
+        } else if (KEY_WIFI_ASSISTANT.equals(key)) {
+            if (((Boolean)newValue).booleanValue() == false) {
+                NetworkScorerAppManager.setActiveScorer(context, null);
+                return true;
+            }
+
+            NetworkScorerAppData wifiAssistant = WifiSettings.getWifiAssistantApp(context);
+            Intent intent = new Intent();
+            if (wifiAssistant.mConfigurationActivityClassName != null) {
+                // App has a custom configuration activity; launch that.
+                // This custom activity will be responsible for launching the system
+                // dialog.
+                intent.setClassName(wifiAssistant.mPackageName,
+                        wifiAssistant.mConfigurationActivityClassName);
+            } else {
+                // Fall back on the system dialog.
+                intent.setAction(NetworkScoreManager.ACTION_CHANGE_ACTIVE);
+                intent.putExtra(NetworkScoreManager.EXTRA_PACKAGE_NAME,
+                        wifiAssistant.mPackageName);
+            }
+
+            startActivity(intent);
         }
 
         if (KEY_SLEEP_POLICY.equals(key)) {
@@ -270,7 +285,7 @@
                         Integer.parseInt(stringValue));
                 updateSleepPolicySummary(preference, stringValue);
             } catch (NumberFormatException e) {
-                Toast.makeText(getActivity(), R.string.wifi_setting_sleep_policy_error,
+                Toast.makeText(context, R.string.wifi_setting_sleep_policy_error,
                         Toast.LENGTH_SHORT).show();
                 return false;
             }
@@ -280,18 +295,19 @@
     }
 
     private void refreshWifiInfo() {
+        final Context context = getActivity();
         WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
 
         Preference wifiMacAddressPref = findPreference(KEY_MAC_ADDRESS);
         String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress();
         wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress
-                : getActivity().getString(R.string.status_unavailable));
+                : context.getString(R.string.status_unavailable));
         wifiMacAddressPref.setSelectable(false);
 
         Preference wifiIpAddressPref = findPreference(KEY_CURRENT_IP_ADDRESS);
-        String ipAddress = Utils.getWifiIpAddresses(getActivity());
+        String ipAddress = Utils.getWifiIpAddresses(context);
         wifiIpAddressPref.setSummary(ipAddress == null ?
-                getActivity().getString(R.string.status_unavailable) : ipAddress);
+                context.getString(R.string.status_unavailable) : ipAddress);
         wifiIpAddressPref.setSelectable(false);
     }
 
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index e83cb06..5366d66 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -27,7 +27,6 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.SharedPreferences;
-import android.content.pm.PackageManager;
 import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.location.LocationManager;
@@ -45,11 +44,13 @@
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
+import android.os.Parcelable;
 import android.preference.Preference;
 import android.preference.PreferenceScreen;
 import android.util.Log;
 import android.view.ContextMenu;
 import android.view.ContextMenu.ContextMenuInfo;
+import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
@@ -129,7 +130,6 @@
     private WifiManager.ActionListener mConnectListener;
     private WifiManager.ActionListener mSaveListener;
     private WifiManager.ActionListener mForgetListener;
-    private boolean mP2pSupported;
 
     private WifiEnabler mWifiEnabler;
     // An access point being editted is stored here.
@@ -156,7 +156,7 @@
     private boolean mDlgEdit;
     private AccessPoint mDlgAccessPoint;
     private Bundle mAccessPointSavedState;
-    private Preference mWifiAssistantPreference;
+    private View mWifiAssistantCard;
     private NetworkScorerAppData mWifiAssistantApp;
 
     /** verbose logging flag. this flag is set thru developer debugging options
@@ -165,52 +165,6 @@
 
     /* End of "used in Wifi Setup context" */
 
-    /** Holds the Wifi Assistant Card. */
-    private class WifiAssistantPreference extends Preference {
-        public WifiAssistantPreference() {
-            super(getActivity());
-            setLayoutResource(R.layout.wifi_assistant_card);
-        }
-
-        @Override
-        public void onBindView(View view) {
-            super.onBindView(view);
-            Button setup = (Button)view.findViewById(R.id.setup);
-            Button noThanks = (Button)view.findViewById(R.id.no_thanks_button);
-
-            if (setup != null && noThanks != null) {
-                setup.setOnClickListener(new OnClickListener() {
-                    @Override
-                    public void onClick(View v) {
-                        Intent intent = new Intent();
-                        if (mWifiAssistantApp.mConfigurationActivityClassName != null) {
-                            // App has a custom configuration activity; launch that.
-                            // This custom activity will be responsible for launching the system
-                            // dialog.
-                            intent.setClassName(mWifiAssistantApp.mPackageName,
-                                    mWifiAssistantApp.mConfigurationActivityClassName);
-                        } else {
-                            // Fall back on the system dialog.
-                            intent.setAction(NetworkScoreManager.ACTION_CHANGE_ACTIVE);
-                            intent.putExtra(NetworkScoreManager.EXTRA_PACKAGE_NAME,
-                                    mWifiAssistantApp.mPackageName);
-                        }
-                        startActivityForResult(intent, REQUEST_ENABLE_WIFI_ASSISTANT);
-                    }
-                });
-
-                noThanks.setOnClickListener(new OnClickListener() {
-                    @Override
-                    public void onClick(View v) {
-                        setWifiAssistantTimeout();
-                        getPreferenceScreen().removePreference(WifiAssistantPreference.this);
-                        mWifiAssistantApp = null;
-                    }
-                });
-            }
-        }
-    }
-
     /** A restricted multimap for use in constructAccessPoints */
     private static class Multimap<K,V> {
         private final HashMap<K,List<V>> store = new HashMap<K,List<V>>();
@@ -285,7 +239,7 @@
         mReceiver = new BroadcastReceiver() {
             @Override
             public void onReceive(Context context, Intent intent) {
-                handleEvent(context, intent);
+                handleEvent(intent);
             }
         };
 
@@ -296,7 +250,6 @@
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
 
-        mP2pSupported = getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT);
         mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
 
         mConnectListener = new WifiManager.ActionListener() {
@@ -347,7 +300,7 @@
         if (savedInstanceState != null) {
             mDlgEdit = savedInstanceState.getBoolean(SAVE_DIALOG_EDIT_MODE);
             if (savedInstanceState.containsKey(SAVE_DIALOG_ACCESS_POINT_STATE)) {
-                mAccessPointSavedState = 
+                mAccessPointSavedState =
                     savedInstanceState.getBundle(SAVE_DIALOG_ACCESS_POINT_STATE);
             }
         }
@@ -384,7 +337,7 @@
         if (requestCode == REQUEST_ENABLE_WIFI_ASSISTANT) {
             if (resultCode == Activity.RESULT_OK) {
                 setWifiAssistantTimeout();
-                getPreferenceScreen().removePreference(mWifiAssistantPreference);
+                getListView().removeHeaderView(mWifiAssistantCard);
                 mWifiAssistantApp = null;
             }
         } else {
@@ -706,8 +659,9 @@
                     addMessagePreference(R.string.wifi_empty_list_wifi_on);
                 }
 
+                getListView().removeHeaderView(mWifiAssistantCard);
                 if (mWifiAssistantApp != null) {
-                    getPreferenceScreen().addPreference(mWifiAssistantPreference);
+                    getListView().addHeaderView(mWifiAssistantCard);
                 }
 
                 for (AccessPoint accessPoint : accessPoints) {
@@ -732,38 +686,88 @@
         }
     }
 
-    private boolean prepareWifiAssistantCard() {
-        if (mWifiAssistantPreference == null) {
-            mWifiAssistantPreference = new WifiAssistantPreference();
+    /**
+     * Returns the Network Scorer for the Wifi Assistant App.
+     */
+    public static NetworkScorerAppData getWifiAssistantApp(Context context) {
+        Collection<NetworkScorerAppData> scorers =
+                NetworkScorerAppManager.getAllValidScorers(context);
+
+        if (scorers.isEmpty()) {
+            return null;
         }
 
+        // TODO: b/13780935 - Implement proper scorer selection. Rather than pick the first
+        // scorer on the system, we should allow the user to select one.
+        return scorers.iterator().next();
+    }
+
+    private void prepareWifiAssistantCard() {
         if (getActivity() instanceof WifiPickerActivity) {
-            return false;
+            return;
         }
 
         if (NetworkScorerAppManager.getActiveScorer(getActivity()) != null) {
             // A scorer is already enabled; don't show the card.
-            return false;
+            return;
         }
 
         Collection<NetworkScorerAppData> scorers =
                 NetworkScorerAppManager.getAllValidScorers(getActivity());
         if (scorers.isEmpty()) {
             // No scorers are available to enable; don't show the card.
-            return false;
+            return;
         }
 
         SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
         long lastTimeoutEndTime = sharedPreferences.getLong(KEY_ASSISTANT_START_TIME, 0);
         long dismissTime = sharedPreferences.getLong(KEY_ASSISTANT_DISMISS_TIME, 0);
 
-        boolean shouldShow = ((System.currentTimeMillis() - lastTimeoutEndTime) > dismissTime);
-        if (shouldShow) {
-            // TODO: b/13780935 - Implement proper scorer selection. Rather than pick the first
-            // scorer on the system, we should allow the user to select one.
-            mWifiAssistantApp = scorers.iterator().next();
+        if ((System.currentTimeMillis() - lastTimeoutEndTime) <= dismissTime) {
+            return;
         }
-        return shouldShow;
+
+        // TODO: b/13780935 - Implement proper scorer selection. Rather than pick the first
+        // scorer on the system, we should allow the user to select one.
+        mWifiAssistantApp = scorers.iterator().next();
+
+        if (mWifiAssistantCard == null) {
+            mWifiAssistantCard = LayoutInflater.from(getActivity())
+                    .inflate(R.layout.wifi_assistant_card, getListView(), false);
+            Button setup = (Button) mWifiAssistantCard.findViewById(R.id.setup);
+            Button noThanks = (Button) mWifiAssistantCard.findViewById(R.id.no_thanks_button);
+
+            if (setup != null && noThanks != null) {
+                setup.setOnClickListener(new OnClickListener() {
+                    @Override
+                    public void onClick(View v) {
+                        Intent intent = new Intent();
+                        if (mWifiAssistantApp.mConfigurationActivityClassName != null) {
+                            // App has a custom configuration activity; launch that.
+                            // This custom activity will be responsible for launching the system
+                            // dialog.
+                            intent.setClassName(mWifiAssistantApp.mPackageName,
+                                    mWifiAssistantApp.mConfigurationActivityClassName);
+                        } else {
+                            // Fall back on the system dialog.
+                            intent.setAction(NetworkScoreManager.ACTION_CHANGE_ACTIVE);
+                            intent.putExtra(NetworkScoreManager.EXTRA_PACKAGE_NAME,
+                                    mWifiAssistantApp.mPackageName);
+                        }
+                        startActivityForResult(intent, REQUEST_ENABLE_WIFI_ASSISTANT);
+                    }
+                });
+
+                noThanks.setOnClickListener(new OnClickListener() {
+                    @Override
+                    public void onClick(View v) {
+                        setWifiAssistantTimeout();
+                        getListView().removeHeaderView(mWifiAssistantCard);
+                        mWifiAssistantApp = null;
+                    }
+                });
+            }
+        }
     }
 
     private void setWifiAssistantTimeout() {
@@ -861,7 +865,7 @@
         return accessPoints;
     }
 
-    private void handleEvent(Context context, Intent intent) {
+    private void handleEvent(Intent intent) {
         String action = intent.getAction();
         if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
             updateWifiState(intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,