Merge "Add settings for altering VR display behavior." into nyc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 2eb2760..f6c7957 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1293,7 +1293,7 @@
         </activity>
 
         <activity android:name="MonitoringCertInfoActivity"
-                android:label="@string/ssl_ca_cert_dialog_title"
+                android:label=""
                 android:theme="@style/Transparent"
                 android:excludeFromRecents="true"
                 android:taskAffinity="">
@@ -1478,8 +1478,7 @@
         <activity android:name=".accessibility.AccessibilitySettingsForSetupWizardActivity"
                 android:label="@string/vision_settings_title"
                 android:theme="@style/SetupWizardAccessibilityTheme"
-                android:taskAffinity="com.android.wizard"
-                android:configChanges="orientation|keyboardHidden|screenSize" >
+                android:taskAffinity="com.android.wizard" >
             <intent-filter android:priority="1">
                 <action android:name="android.settings.ACCESSIBILITY_SETTINGS_FOR_SUW" />
                 <category android:name="android.intent.category.DEFAULT" />
@@ -1558,6 +1557,7 @@
         <activity android:name="ConfirmDeviceCredentialActivity$InternalActivity"
             android:exported="false"
             android:permission="android.permission.MANAGE_USERS"
+            android:resizeableActivity="false"
             android:theme="@android:style/Theme.NoDisplay">
             <intent-filter android:priority="1">
                 <action android:name="android.app.action.CONFIRM_DEVICE_CREDENTIAL_WITH_USER" />
@@ -1885,7 +1885,8 @@
                 android:label="@string/development_settings_title"
                 android:icon="@drawable/ic_settings_development"
                 android:taskAffinity="com.android.settings"
-                android:parentActivityName="Settings">
+                android:parentActivityName="Settings"
+                android:enabled="false">
             <intent-filter android:priority="1">
                 <action android:name="android.settings.APPLICATION_DEVELOPMENT_SETTINGS" />
                 <action android:name="com.android.settings.APPLICATION_DEVELOPMENT_SETTINGS" />
diff --git a/res/layout-h360dp/font_size_activity.xml b/res/layout-land/font_size_activity.xml
similarity index 73%
rename from res/layout-h360dp/font_size_activity.xml
rename to res/layout-land/font_size_activity.xml
index aa3930c..69abac1 100644
--- a/res/layout-h360dp/font_size_activity.xml
+++ b/res/layout-land/font_size_activity.xml
@@ -14,18 +14,34 @@
      limitations under the License.
 -->
 
-<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:fillViewport="true">
+            android:orientation="horizontal">
 
     <LinearLayout
         android:orientation="vertical"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content" >
+        android:layout_width="0dp"
+        android:layout_weight="1"
+        android:layout_height="match_parent">
 
         <include layout="@layout/preview_seek_bar_view_pager" />
 
+        <com.android.settings.widget.DotsPageIndicator
+            android:id="@+id/page_indicator"
+            style="@style/PreviewPagerPageIndicator"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal"
+            android:padding="6dp" />
+    </LinearLayout>
+
+    <ScrollView
+            android:layout_width="0dp"
+            android:layout_weight="1"
+            android:layout_height="match_parent"
+            android:fillViewport="true">
+
         <LinearLayout
             android:orientation="vertical"
             android:layout_width="match_parent"
@@ -34,14 +50,6 @@
             android:paddingStart="?android:attr/listPreferredItemPaddingStart"
             android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
 
-            <com.android.settings.widget.DotsPageIndicator
-                android:id="@+id/page_indicator"
-                style="@style/PreviewPagerPageIndicator"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_gravity="center_horizontal"
-                android:padding="6dp" />
-
             <TextView
                 android:id="@+id/current_label"
                 android:layout_width="wrap_content"
@@ -51,16 +59,22 @@
                 android:textAppearance="@android:style/TextAppearance.Material.Widget.TextView"
                 android:elevation="2dp" />
 
-            <LinearLayout
+            <com.android.settings.widget.LabeledSeekBar
+                android:id="@+id/seek_bar"
+                android:layout_width="match_parent"
+                android:layout_height="48dp"
+                style="@android:style/Widget.Material.SeekBar.Discrete" />
+
+            <RelativeLayout
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                android:gravity="center_vertical"
-                android:paddingTop="8dp">
+                android:gravity="center_vertical">
 
                 <ImageView
                     android:id="@+id/smaller"
                     android:layout_width="48dp"
                     android:layout_height="48dp"
+                    android:layout_alignParentStart="true"
                     android:background="?android:attr/selectableItemBackgroundBorderless"
                     android:src="@drawable/ic_font_size_16dp"
                     android:tint="?android:attr/textColorPrimary"
@@ -69,17 +83,11 @@
                     android:focusable="true"
                     android:contentDescription="@string/font_size_make_smaller_desc" />
 
-                <com.android.settings.widget.LabeledSeekBar
-                    android:id="@+id/seek_bar"
-                    android:layout_width="0dp"
-                    android:layout_height="48dp"
-                    android:layout_weight="1"
-                    style="@android:style/Widget.Material.SeekBar.Discrete"/>
-
                 <ImageView
                     android:id="@+id/larger"
                     android:layout_width="48dp"
                     android:layout_height="48dp"
+                    android:layout_alignParentEnd="true"
                     android:background="?android:attr/selectableItemBackgroundBorderless"
                     android:src="@drawable/ic_font_size_24dp"
                     android:tint="?android:attr/textColorPrimary"
@@ -87,7 +95,7 @@
                     android:scaleType="center"
                     android:focusable="true"
                     android:contentDescription="@string/font_size_make_larger_desc" />
-            </LinearLayout>
+            </RelativeLayout>
 
             <TextView
                 android:layout_width="wrap_content"
@@ -96,5 +104,5 @@
                 android:layout_marginBottom="16dp"
                 android:textAppearance="@android:style/TextAppearance.Material.Subhead" />
         </LinearLayout>
-    </LinearLayout>
-</ScrollView>
+    </ScrollView>
+</LinearLayout>
diff --git a/res/layout-h360dp/screen_zoom_activity.xml b/res/layout-land/screen_zoom_activity.xml
similarity index 74%
rename from res/layout-h360dp/screen_zoom_activity.xml
rename to res/layout-land/screen_zoom_activity.xml
index 0141019..8d6e735 100644
--- a/res/layout-h360dp/screen_zoom_activity.xml
+++ b/res/layout-land/screen_zoom_activity.xml
@@ -14,18 +14,34 @@
      limitations under the License.
 -->
 
-<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:fillViewport="true">
+            android:orientation="horizontal">
 
     <LinearLayout
         android:orientation="vertical"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content" >
+        android:layout_width="0dp"
+        android:layout_weight="1"
+        android:layout_height="match_parent" >
 
         <include layout="@layout/preview_seek_bar_view_pager" />
 
+        <com.android.settings.widget.DotsPageIndicator
+            android:id="@+id/page_indicator"
+            style="@style/PreviewPagerPageIndicator"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal"
+            android:padding="6dp" />
+    </LinearLayout>
+
+    <ScrollView
+            android:layout_width="0dp"
+            android:layout_weight="1"
+            android:layout_height="match_parent"
+            android:fillViewport="true">
+
         <LinearLayout
             android:orientation="vertical"
             android:layout_width="match_parent"
@@ -34,14 +50,6 @@
             android:paddingStart="?android:attr/listPreferredItemPaddingStart"
             android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
 
-            <com.android.settings.widget.DotsPageIndicator
-                android:id="@+id/page_indicator"
-                style="@style/PreviewPagerPageIndicator"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_gravity="center_horizontal"
-                android:padding="6dp" />
-
             <TextView
                 android:id="@+id/current_label"
                 android:layout_width="wrap_content"
@@ -51,7 +59,13 @@
                 android:textAppearance="@android:style/TextAppearance.Material.Widget.TextView"
                 android:elevation="2dp" />
 
-            <LinearLayout
+            <com.android.settings.widget.LabeledSeekBar
+                android:id="@+id/seek_bar"
+                android:layout_width="match_parent"
+                android:layout_height="48dp"
+                style="@android:style/Widget.Material.SeekBar.Discrete"/>
+
+            <RelativeLayout
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:gravity="center_vertical">
@@ -60,6 +74,7 @@
                     android:id="@+id/smaller"
                     android:layout_width="48dp"
                     android:layout_height="48dp"
+                    android:layout_alignParentStart="true"
                     android:background="?android:attr/selectableItemBackgroundBorderless"
                     android:src="@drawable/ic_remove_24dp"
                     android:tint="?android:attr/textColorPrimary"
@@ -68,17 +83,11 @@
                     android:focusable="true"
                     android:contentDescription="@string/screen_zoom_make_smaller_desc" />
 
-                <com.android.settings.widget.LabeledSeekBar
-                    android:id="@+id/seek_bar"
-                    android:layout_width="0dp"
-                    android:layout_height="48dp"
-                    android:layout_weight="1"
-                    style="@android:style/Widget.Material.SeekBar.Discrete"/>
-
                 <ImageView
                     android:id="@+id/larger"
                     android:layout_width="48dp"
                     android:layout_height="48dp"
+                    android:layout_alignParentEnd="true"
                     android:background="?android:attr/selectableItemBackgroundBorderless"
                     android:src="@drawable/ic_add_24dp"
                     android:tint="?android:attr/textColorPrimary"
@@ -86,7 +95,7 @@
                     android:scaleType="center"
                     android:focusable="true"
                     android:contentDescription="@string/screen_zoom_make_larger_desc" />
-            </LinearLayout>
+            </RelativeLayout>
 
             <TextView
                 android:layout_width="wrap_content"
@@ -95,5 +104,5 @@
                 android:layout_marginBottom="16dp"
                 android:textAppearance="@android:style/TextAppearance.Material.Subhead" />
         </LinearLayout>
-    </LinearLayout>
-</ScrollView>
+    </ScrollView>
+</LinearLayout>
diff --git a/res/layout/condition_card.xml b/res/layout/condition_card.xml
index 0e480a5..c1224b5 100644
--- a/res/layout/condition_card.xml
+++ b/res/layout/condition_card.xml
@@ -85,11 +85,13 @@
 
             <!-- TODO: Better background -->
             <View
+                android:id="@+id/divider"
                 android:layout_width="match_parent"
                 android:layout_height=".25dp"
                 android:background="@android:color/white" />
 
             <com.android.internal.widget.ButtonBarLayout
+                android:id="@+id/buttonBar"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:paddingTop="8dp"
diff --git a/res/layout/conversation_message_content.xml b/res/layout/conversation_message_content.xml
index 7bc53e5..bdb0ea7 100644
--- a/res/layout/conversation_message_content.xml
+++ b/res/layout/conversation_message_content.xml
@@ -25,7 +25,6 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:orientation="vertical"
-        android:minHeight="@dimen/conversation_message_contact_icon_size"
         android:layout_marginTop="0dp" >
 
         <TextView
diff --git a/res/layout/conversation_message_icon.xml b/res/layout/conversation_message_icon.xml
index 4ffd285..9f9f0ac 100644
--- a/res/layout/conversation_message_icon.xml
+++ b/res/layout/conversation_message_icon.xml
@@ -16,8 +16,8 @@
 
 <TextView xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/conversation_icon"
-    android:layout_width="@dimen/conversation_message_contact_icon_size"
-    android:layout_height="@dimen/conversation_message_contact_icon_size"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
     android:fontFamily="sans-serif"
     android:textStyle="bold"
     android:textSize="@dimen/conversation_message_contact_icon_text_size"
diff --git a/res/layout/font_size_activity.xml b/res/layout/font_size_activity.xml
index 4825f24..aa3930c 100644
--- a/res/layout/font_size_activity.xml
+++ b/res/layout/font_size_activity.xml
@@ -22,63 +22,79 @@
     <LinearLayout
         android:orientation="vertical"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:paddingTop="16dp"
-        android:paddingStart="?android:attr/listPreferredItemPaddingStart"
-        android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
+        android:layout_height="wrap_content" >
 
-        <TextView
-            android:id="@+id/current_label"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_gravity="center_horizontal"
-            android:padding="6dp"
-            android:textAppearance="@android:style/TextAppearance.Material.Widget.TextView"
-            android:elevation="2dp" />
+        <include layout="@layout/preview_seek_bar_view_pager" />
 
         <LinearLayout
+            android:orientation="vertical"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:gravity="center_vertical"
-            android:paddingTop="8dp">
+            android:paddingTop="16dp"
+            android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+            android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
 
-            <ImageView
-                android:id="@+id/smaller"
-                android:layout_width="48dp"
-                android:layout_height="48dp"
-                android:background="?android:attr/selectableItemBackgroundBorderless"
-                android:src="@drawable/ic_font_size_16dp"
-                android:tint="?android:attr/textColorPrimary"
-                android:tintMode="src_in"
-                android:scaleType="center"
-                android:focusable="true"
-                android:contentDescription="@string/font_size_make_smaller_desc" />
+            <com.android.settings.widget.DotsPageIndicator
+                android:id="@+id/page_indicator"
+                style="@style/PreviewPagerPageIndicator"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_gravity="center_horizontal"
+                android:padding="6dp" />
 
-            <com.android.settings.widget.LabeledSeekBar
-                android:id="@+id/seek_bar"
-                android:layout_width="0dp"
-                android:layout_height="48dp"
-                android:layout_weight="1"
-                style="@android:style/Widget.Material.SeekBar.Discrete"/>
+            <TextView
+                android:id="@+id/current_label"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_gravity="center_horizontal"
+                android:padding="6dp"
+                android:textAppearance="@android:style/TextAppearance.Material.Widget.TextView"
+                android:elevation="2dp" />
 
-            <ImageView
-                android:id="@+id/larger"
-                android:layout_width="48dp"
-                android:layout_height="48dp"
-                android:background="?android:attr/selectableItemBackgroundBorderless"
-                android:src="@drawable/ic_font_size_24dp"
-                android:tint="?android:attr/textColorPrimary"
-                android:tintMode="src_in"
-                android:scaleType="center"
-                android:focusable="true"
-                android:contentDescription="@string/font_size_make_larger_desc" />
+            <LinearLayout
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:gravity="center_vertical"
+                android:paddingTop="8dp">
+
+                <ImageView
+                    android:id="@+id/smaller"
+                    android:layout_width="48dp"
+                    android:layout_height="48dp"
+                    android:background="?android:attr/selectableItemBackgroundBorderless"
+                    android:src="@drawable/ic_font_size_16dp"
+                    android:tint="?android:attr/textColorPrimary"
+                    android:tintMode="src_in"
+                    android:scaleType="center"
+                    android:focusable="true"
+                    android:contentDescription="@string/font_size_make_smaller_desc" />
+
+                <com.android.settings.widget.LabeledSeekBar
+                    android:id="@+id/seek_bar"
+                    android:layout_width="0dp"
+                    android:layout_height="48dp"
+                    android:layout_weight="1"
+                    style="@android:style/Widget.Material.SeekBar.Discrete"/>
+
+                <ImageView
+                    android:id="@+id/larger"
+                    android:layout_width="48dp"
+                    android:layout_height="48dp"
+                    android:background="?android:attr/selectableItemBackgroundBorderless"
+                    android:src="@drawable/ic_font_size_24dp"
+                    android:tint="?android:attr/textColorPrimary"
+                    android:tintMode="src_in"
+                    android:scaleType="center"
+                    android:focusable="true"
+                    android:contentDescription="@string/font_size_make_larger_desc" />
+            </LinearLayout>
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="@string/font_size_summary"
+                android:layout_marginBottom="16dp"
+                android:textAppearance="@android:style/TextAppearance.Material.Subhead" />
         </LinearLayout>
-
-        <TextView
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:text="@string/font_size_summary"
-            android:layout_marginBottom="16dp"
-            android:textAppearance="@android:style/TextAppearance.Material.Subhead" />
     </LinearLayout>
 </ScrollView>
diff --git a/res/layout/preview_seek_bar_view_pager.xml b/res/layout/preview_seek_bar_view_pager.xml
index e24b674..5524d8a 100644
--- a/res/layout/preview_seek_bar_view_pager.xml
+++ b/res/layout/preview_seek_bar_view_pager.xml
@@ -19,7 +19,6 @@
     android:layout_height="0dp"
     android:layout_weight="1"
     android:orientation="vertical"
-    android:minHeight="@dimen/preview_pager_min_height"
     android:padding="@dimen/preview_pager_padding"
     android:background="@drawable/preview_seek_bar_outline" >
 
diff --git a/res/layout/screen_zoom_activity.xml b/res/layout/screen_zoom_activity.xml
index 36dd9fa..0141019 100644
--- a/res/layout/screen_zoom_activity.xml
+++ b/res/layout/screen_zoom_activity.xml
@@ -22,62 +22,78 @@
     <LinearLayout
         android:orientation="vertical"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:paddingTop="16dp"
-        android:paddingStart="?android:attr/listPreferredItemPaddingStart"
-        android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
+        android:layout_height="wrap_content" >
 
-        <TextView
-            android:id="@+id/current_label"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_gravity="center_horizontal"
-            android:padding="6dp"
-            android:textAppearance="@android:style/TextAppearance.Material.Widget.TextView"
-            android:elevation="2dp" />
+        <include layout="@layout/preview_seek_bar_view_pager" />
 
         <LinearLayout
+            android:orientation="vertical"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:gravity="center_vertical">
+            android:paddingTop="16dp"
+            android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+            android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
 
-            <ImageView
-                android:id="@+id/smaller"
-                android:layout_width="48dp"
-                android:layout_height="48dp"
-                android:background="?android:attr/selectableItemBackgroundBorderless"
-                android:src="@drawable/ic_remove_24dp"
-                android:tint="?android:attr/textColorPrimary"
-                android:tintMode="src_in"
-                android:scaleType="center"
-                android:focusable="true"
-                android:contentDescription="@string/screen_zoom_make_smaller_desc" />
+            <com.android.settings.widget.DotsPageIndicator
+                android:id="@+id/page_indicator"
+                style="@style/PreviewPagerPageIndicator"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_gravity="center_horizontal"
+                android:padding="6dp" />
 
-            <com.android.settings.widget.LabeledSeekBar
-                android:id="@+id/seek_bar"
-                android:layout_width="0dp"
-                android:layout_height="48dp"
-                android:layout_weight="1"
-                style="@android:style/Widget.Material.SeekBar.Discrete"/>
+            <TextView
+                android:id="@+id/current_label"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_gravity="center_horizontal"
+                android:padding="6dp"
+                android:textAppearance="@android:style/TextAppearance.Material.Widget.TextView"
+                android:elevation="2dp" />
 
-            <ImageView
-                android:id="@+id/larger"
-                android:layout_width="48dp"
-                android:layout_height="48dp"
-                android:background="?android:attr/selectableItemBackgroundBorderless"
-                android:src="@drawable/ic_add_24dp"
-                android:tint="?android:attr/textColorPrimary"
-                android:tintMode="src_in"
-                android:scaleType="center"
-                android:focusable="true"
-                android:contentDescription="@string/screen_zoom_make_larger_desc" />
+            <LinearLayout
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:gravity="center_vertical">
+
+                <ImageView
+                    android:id="@+id/smaller"
+                    android:layout_width="48dp"
+                    android:layout_height="48dp"
+                    android:background="?android:attr/selectableItemBackgroundBorderless"
+                    android:src="@drawable/ic_remove_24dp"
+                    android:tint="?android:attr/textColorPrimary"
+                    android:tintMode="src_in"
+                    android:scaleType="center"
+                    android:focusable="true"
+                    android:contentDescription="@string/screen_zoom_make_smaller_desc" />
+
+                <com.android.settings.widget.LabeledSeekBar
+                    android:id="@+id/seek_bar"
+                    android:layout_width="0dp"
+                    android:layout_height="48dp"
+                    android:layout_weight="1"
+                    style="@android:style/Widget.Material.SeekBar.Discrete"/>
+
+                <ImageView
+                    android:id="@+id/larger"
+                    android:layout_width="48dp"
+                    android:layout_height="48dp"
+                    android:background="?android:attr/selectableItemBackgroundBorderless"
+                    android:src="@drawable/ic_add_24dp"
+                    android:tint="?android:attr/textColorPrimary"
+                    android:tintMode="src_in"
+                    android:scaleType="center"
+                    android:focusable="true"
+                    android:contentDescription="@string/screen_zoom_make_larger_desc" />
+            </LinearLayout>
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="@string/screen_zoom_summary"
+                android:layout_marginBottom="16dp"
+                android:textAppearance="@android:style/TextAppearance.Material.Subhead" />
         </LinearLayout>
-
-        <TextView
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:text="@string/screen_zoom_summary"
-            android:layout_marginBottom="16dp"
-            android:textAppearance="@android:style/TextAppearance.Material.Subhead" />
     </LinearLayout>
 </ScrollView>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index eb06105..ef7efa2 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -263,10 +263,8 @@
     <dimen name="unmount_button_padding">8dp</dimen>
 
     <!-- Display, Screen zoom -->
-    <dimen name="screen_zoom_preview_height">240dp</dimen>
     <dimen name="screen_zoom_preview_app_icon_width">88dp</dimen>
     <dimen name="conversation_message_list_padding">10dp</dimen>
-    <dimen name="conversation_message_contact_icon_size">42dp</dimen>
     <dimen name="conversation_message_contact_icon_text_size">32sp</dimen>
     <dimen name="conversation_message_text_size">16sp</dimen>
     <dimen name="conversation_status_text_size">12sp</dimen>
@@ -282,9 +280,6 @@
     <dimen name="accessibility_layout_margin_start_end">24dp</dimen>
     <dimen name="accessibility_button_preference_padding_top_bottom">18dp</dimen>
 
-    <!-- Accessibility, Font size -->
-    <dimen name="font_size_preview_height">240dp</dimen>
-
     <!-- Accessibility, Screen magnification. These values are meant to be relative values and the actual layout value will be set programmatically. -->
     <dimen name="screen_magnification_video_background_width">750dp</dimen>
     <dimen name="screen_magnification_video_background_height">383dp</dimen>
@@ -297,7 +292,6 @@
 
     <!-- Display Size and Font Size preview screen -->
     <dimen name="preview_pager_padding">8dp</dimen>
-    <dimen name="preview_pager_min_height">240dp</dimen>
 
     <!-- Padding between the radio buttons/checkbox and text on the redaction interstitial -->
     <dimen name="redaction_padding_start">16dp</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 555588f..e061f6e 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2120,7 +2120,7 @@
     <!-- Wallpaper settings fragment title [CHAR LIMIT=30] -->
     <string name="wallpaper_settings_fragment_title">Choose wallpaper from</string>
     <!-- Display settings screen, trigger for screen saver options -->
-    <string name="screensaver_settings_title">Daydream</string>
+    <string name="screensaver_settings_title">Screen saver</string>
     <!-- Display settings screen, summary fragment for screen saver options, activated when docked or asleep and charging -->
     <string name="screensaver_settings_summary_either_long">When docked or asleep and charging</string>
     <!-- Dream settings screen, dialog option, activated when docked or asleep and charging -->
@@ -2132,9 +2132,9 @@
     <!-- Display settings screen, summary for screen saver options, screen saver is turned off -->
     <string name="screensaver_settings_summary_off">Off</string>
     <!-- Dream settings screen, caption for when dreams are disabled -->
-    <string name="screensaver_settings_disabled_prompt">To control what happens when the phone is docked and/or sleeping, turn Daydream on.</string>
+    <string name="screensaver_settings_disabled_prompt">To control what happens when the phone is docked and/or sleeping, turn screen saver on.</string>
     <!-- Dream settings screen, action label, when to dream -->
-    <string name="screensaver_settings_when_to_dream">When to daydream</string>
+    <string name="screensaver_settings_when_to_dream">When to turn screen saver on</string>
     <!-- Dream settings screen, button label to start dreaming -->
     <string name="screensaver_settings_dream_start">Start now</string>
     <!-- Dream settings screen, button label for settings for a specific screensaver -->
@@ -7252,6 +7252,9 @@
     <!-- Button that leads to list of apps with unrestricted data access [CHAR LIMIT=60] -->
     <string name="unrestricted_data_saver">Unrestricted data access</string>
 
+    <!-- Description of message shown when app is blacklisted for background data access [CHAR LIMIT=NONE] -->
+    <string name="restrict_background_blacklisted">Background data is turned off</string>
+
     <!-- Summary for the Data Saver feature being on [CHAR LIMIT=NONE] -->
     <string name="data_saver_on">On</string>
 
diff --git a/res/xml/app_notification_settings.xml b/res/xml/app_notification_settings.xml
index fd2f33e..40a8569 100644
--- a/res/xml/app_notification_settings.xml
+++ b/res/xml/app_notification_settings.xml
@@ -15,8 +15,10 @@
 -->
 
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+        xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
         android:title="@string/app_notifications_title"
-        android:key="app_notification_settings">
+        android:key="app_notification_settings"
+        settings:keywords="@string/keywords_date_and_time">
 
     <!-- Importance -->
     <!-- Block -->
@@ -24,13 +26,16 @@
             android:key="block"
             android:title="@string/app_notification_block_title"
             android:summary="@string/app_notification_block_summary"
-            android:order="2" />
+            android:order="2"
+            settings:useAdditionalSummary="true"
+            settings:restrictedSwitchSummary="@string/enabled_by_admin" />
     <!-- Silent -->
     <com.android.settingslib.RestrictedSwitchPreference
             android:key="silent"
             android:title="@string/show_silently"
             android:summary="@string/show_silently_summary"
-            android:order="3" />
+            android:order="3"
+            settings:useAdditionalSummary="true" />
     <!-- Slider -->
     <com.android.settings.notification.ImportanceSeekBarPreference
             android:key="importance"
@@ -48,6 +53,7 @@
             android:key="bypass_dnd"
             android:title="@string/app_notification_override_dnd_title"
             android:summary="@string/app_notification_override_dnd_summary"
-            android:order="6" />
+            android:order="6"
+            settings:useAdditionalSummary="true" />
 
 </PreferenceScreen>
diff --git a/res/xml/date_time_prefs.xml b/res/xml/date_time_prefs.xml
index 0aec43f..e573bbd 100644
--- a/res/xml/date_time_prefs.xml
+++ b/res/xml/date_time_prefs.xml
@@ -15,7 +15,7 @@
 -->
 
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
-                  xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
+        xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
         android:title="@string/date_and_time"
         settings:keywords="@string/keywords_date_and_time">
 
@@ -23,6 +23,8 @@
         android:title="@string/date_time_auto"
         android:summaryOn="@string/date_time_auto_summaryOn"
         android:summaryOff="@string/date_time_auto_summaryOff"
+        settings:useAdditionalSummary="true"
+        settings:restrictedSwitchSummary="@string/enabled_by_admin"
         />
 
     <SwitchPreference android:key="auto_zone"
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index e737ba8..6d1a9fc 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -15,6 +15,7 @@
 -->
 
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+        xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
         android:title="@string/development_settings_title">
     <com.android.settings.BugreportPreference
             android:key="bugreport"
@@ -32,10 +33,11 @@
                 android:targetClass="com.android.settings.SetFullBackupPassword" />
     </PreferenceScreen>
 
-    <SwitchPreference
+    <com.android.settingslib.RestrictedSwitchPreference
         android:key="keep_screen_on"
         android:title="@string/keep_screen_on"
-        android:summary="@string/keep_screen_on_summary"/>
+        android:summary="@string/keep_screen_on_summary"
+        settings:useAdditionalSummary="true" />
 
     <ListPreference
         android:key="hdcp_checking"
diff --git a/res/xml/tts_settings.xml b/res/xml/tts_settings.xml
index 05ed6e7..ab57649 100644
--- a/res/xml/tts_settings.xml
+++ b/res/xml/tts_settings.xml
@@ -47,6 +47,11 @@
             android:title="@string/tts_reset_speech_rate_title"
             android:summary="@string/tts_reset_speech_rate_summary" />
 
+        <Preference android:key="reset_speech_pitch"
+            android:persistent="false"
+            android:title="@string/tts_reset_speech_pitch_title"
+            android:summary="@string/tts_reset_speech_pitch_summary" />
+
         <Preference android:key="tts_play_example"
             android:persistent="false"
             android:title="@string/tts_play_example_title"
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index 1551bcf..5036b9f 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -84,6 +84,9 @@
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.search.Indexable;
 import com.android.settings.widget.SwitchBar;
+import com.android.settingslib.RestrictedLockUtils;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+import com.android.settingslib.RestrictedSwitchPreference;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -232,7 +235,7 @@
     private SwitchPreference mEnableTerminal;
     private Preference mBugreport;
     private SwitchPreference mBugreportInPower;
-    private SwitchPreference mKeepScreenOn;
+    private RestrictedSwitchPreference mKeepScreenOn;
     private SwitchPreference mBtHciSnoopLog;
     private SwitchPreference mEnableOemUnlock;
     private SwitchPreference mDebugViewAttributes;
@@ -364,7 +367,7 @@
 
         mBugreport = findPreference(BUGREPORT);
         mBugreportInPower = findAndInitSwitchPref(BUGREPORT_IN_POWER_KEY);
-        mKeepScreenOn = findAndInitSwitchPref(KEEP_SCREEN_ON);
+        mKeepScreenOn = (RestrictedSwitchPreference) findAndInitSwitchPref(KEEP_SCREEN_ON);
         mBtHciSnoopLog = findAndInitSwitchPref(BT_HCI_SNOOP_LOG);
         mEnableOemUnlock = findAndInitSwitchPref(ENABLE_OEM_UNLOCK);
         if (!showEnableOemUnlockPreference()) {
@@ -562,14 +565,17 @@
             return;
         }
 
-        if (mDpm.getMaximumTimeToLockForUserAndProfiles(UserHandle.myUserId()) > 0) {
-            // A DeviceAdmin has specified a maximum time until the device
-            // will lock...  in this case we can't allow the user to turn
-            // on "stay awake when plugged in" because that would defeat the
-            // restriction.
-            mDisabledPrefs.add(mKeepScreenOn);
-        } else {
+        // A DeviceAdmin has specified a maximum time until the device
+        // will lock...  in this case we can't allow the user to turn
+        // on "stay awake when plugged in" because that would defeat the
+        // restriction.
+        final EnforcedAdmin admin = RestrictedLockUtils.checkIfMaximumTimeToLockIsSet(
+                getActivity());
+        mKeepScreenOn.setDisabledByAdmin(admin);
+        if (admin == null) {
             mDisabledPrefs.remove(mKeepScreenOn);
+        } else {
+            mDisabledPrefs.add(mKeepScreenOn);
         }
 
         final ContentResolver cr = getActivity().getContentResolver();
diff --git a/src/com/android/settings/MonitoringCertInfoActivity.java b/src/com/android/settings/MonitoringCertInfoActivity.java
index cfa8e6f..7bf5768 100644
--- a/src/com/android/settings/MonitoringCertInfoActivity.java
+++ b/src/com/android/settings/MonitoringCertInfoActivity.java
@@ -41,10 +41,12 @@
         DevicePolicyManager dpm = getSystemService(DevicePolicyManager.class);
         final int numberOfCertificates = getIntent().getIntExtra(
                 Settings.EXTRA_NUMBER_OF_CERTIFICATES, 1);
+        final CharSequence title = getResources().getQuantityText(
+                R.plurals.ssl_ca_cert_dialog_title, numberOfCertificates);
+        setTitle(title);
 
         final AlertDialog.Builder builder = new AlertDialog.Builder(this);
-        builder.setTitle(getResources().getQuantityText(R.plurals.ssl_ca_cert_dialog_title,
-                numberOfCertificates));
+        builder.setTitle(title);
         builder.setCancelable(true);
         builder.setPositiveButton(getResources().getQuantityText(
                 R.plurals.ssl_ca_cert_settings_button, numberOfCertificates) , this);
diff --git a/src/com/android/settings/PreviewSeekBarPreferenceFragment.java b/src/com/android/settings/PreviewSeekBarPreferenceFragment.java
index ff9e035..9d4a09e 100644
--- a/src/com/android/settings/PreviewSeekBarPreferenceFragment.java
+++ b/src/com/android/settings/PreviewSeekBarPreferenceFragment.java
@@ -156,21 +156,19 @@
         }
 
         mPreviewPager = (ViewPager) content.findViewById(R.id.preview_pager);
-        if (mPreviewPager != null) {
-            mPreviewPagerAdapter = new PreviewPagerAdapter(context, isLayoutRtl,
-                    mPreviewSampleResIds, configurations);
-            mPreviewPager.setAdapter(mPreviewPagerAdapter);
-            mPreviewPager.setCurrentItem(isLayoutRtl ? mPreviewSampleResIds.length - 1 : 0);
-            mPreviewPager.addOnPageChangeListener(mPreviewPageChangeListener);
+        mPreviewPagerAdapter = new PreviewPagerAdapter(context, isLayoutRtl,
+                mPreviewSampleResIds, configurations);
+        mPreviewPager.setAdapter(mPreviewPagerAdapter);
+        mPreviewPager.setCurrentItem(isLayoutRtl ? mPreviewSampleResIds.length - 1 : 0);
+        mPreviewPager.addOnPageChangeListener(mPreviewPageChangeListener);
 
-            mPageIndicator = (DotsPageIndicator) content.findViewById(R.id.page_indicator);
-            if (mPreviewSampleResIds.length > 1) {
-                mPageIndicator.setViewPager(mPreviewPager);
-                mPageIndicator.setVisibility(View.VISIBLE);
-                mPageIndicator.setOnPageChangeListener(mPageIndicatorPageChangeListener);
-            } else {
-                mPageIndicator.setVisibility(View.GONE);
-            }
+        mPageIndicator = (DotsPageIndicator) content.findViewById(R.id.page_indicator);
+        if (mPreviewSampleResIds.length > 1) {
+            mPageIndicator.setViewPager(mPreviewPager);
+            mPageIndicator.setVisibility(View.VISIBLE);
+            mPageIndicator.setOnPageChangeListener(mPageIndicatorPageChangeListener);
+        } else {
+            mPageIndicator.setVisibility(View.GONE);
         }
 
         setPreviewLayer(mInitialIndex, false);
@@ -191,11 +189,9 @@
         mLabel.setText(mEntries[index]);
         mSmaller.setEnabled(index > 0);
         mLarger.setEnabled(index < mEntries.length - 1);
-        if (mPreviewPager != null) {
-            setPagerIndicatorContentDescription(mPreviewPager.getCurrentItem());
-            mPreviewPagerAdapter.setPreviewLayer(index, mCurrentIndex,
-                    mPreviewPager.getCurrentItem(), animate);
-        }
+        setPagerIndicatorContentDescription(mPreviewPager.getCurrentItem());
+        mPreviewPagerAdapter.setPreviewLayer(index, mCurrentIndex,
+                mPreviewPager.getCurrentItem(), animate);
 
         mCurrentIndex = index;
     }
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 53c97b5..616fe39 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -1096,8 +1096,7 @@
             enabled = false;
         }
         int state = pm.getComponentEnabledSetting(component);
-        boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
-                || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
+        boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
         if (isEnabled != enabled) {
             pm.setComponentEnabledSetting(component, enabled
                     ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
index e0a2844..1a3c850 100644
--- a/src/com/android/settings/SettingsPreferenceFragment.java
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -187,9 +187,7 @@
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
-        if (!TextUtils.isEmpty(mHelpUri)) {
-            setHasOptionsMenu(true);
-        }
+        setHasOptionsMenu(true);
     }
 
     @Override
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 46a3d9b..e439bed 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -347,11 +347,12 @@
         // If there's no profile photo, assign a default avatar
         if (avatarDataStream == null) {
             assignDefaultPhoto(context, userId);
-        } else {
-            UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
-            Bitmap icon = BitmapFactory.decodeStream(avatarDataStream);
-            um.setUserIcon(userId, icon);
+            return;
         }
+
+        UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
+        Bitmap icon = BitmapFactory.decodeStream(avatarDataStream);
+        um.setUserIcon(userId, icon);
         try {
             avatarDataStream.close();
         } catch (IOException ioe) { }
diff --git a/src/com/android/settings/accounts/AccountSettings.java b/src/com/android/settings/accounts/AccountSettings.java
index 852d33a..3b4c722 100644
--- a/src/com/android/settings/accounts/AccountSettings.java
+++ b/src/com/android/settings/accounts/AccountSettings.java
@@ -191,6 +191,7 @@
     @Override
     public void onResume() {
         super.onResume();
+        cleanUpPreferences();
         updateUi();
         mManagedProfileBroadcastReceiver.register(getActivity());
         listenToAccountUpdates();
@@ -201,7 +202,6 @@
         super.onPause();
         stopListeningToAccountUpdates();
         mManagedProfileBroadcastReceiver.unregister(getActivity());
-        cleanUpPreferences();
     }
 
     @Override
diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java
index 7813745..14277c9 100755
--- a/src/com/android/settings/applications/InstalledAppDetails.java
+++ b/src/com/android/settings/applications/InstalledAppDetails.java
@@ -52,7 +52,6 @@
 import android.os.UserHandle;
 import android.os.UserManager;
 import android.provider.Settings;
-import android.service.notification.NotificationListenerService;
 import android.service.notification.NotificationListenerService.Ranking;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.Preference.OnPreferenceClickListener;
@@ -73,6 +72,7 @@
 import android.widget.Button;
 import android.widget.ImageView;
 import android.widget.TextView;
+
 import com.android.internal.logging.MetricsProto.MetricsEvent;
 import com.android.internal.os.BatterySipper;
 import com.android.internal.os.BatteryStatsHelper;
@@ -81,6 +81,7 @@
 import com.android.settings.DeviceAdminAdd;
 import com.android.settings.R;
 import com.android.settings.SettingsActivity;
+import com.android.settings.SettingsPreferenceFragment;
 import com.android.settings.Utils;
 import com.android.settings.applications.PermissionsSummaryHelper.PermissionsResultCallback;
 import com.android.settings.datausage.AppDataUsage;
@@ -741,14 +742,19 @@
     }
 
     private void startAppInfoFragment(Class<?> fragment, CharSequence title) {
+        startAppInfoFragment(fragment, title, this, mAppEntry);
+    }
+
+    public static void startAppInfoFragment(Class<?> fragment, CharSequence title,
+            SettingsPreferenceFragment caller, AppEntry appEntry) {
         // start new fragment to display extended information
         Bundle args = new Bundle();
-        args.putString(ARG_PACKAGE_NAME, mAppEntry.info.packageName);
-        args.putInt(ARG_PACKAGE_UID, mAppEntry.info.uid);
+        args.putString(ARG_PACKAGE_NAME, appEntry.info.packageName);
+        args.putInt(ARG_PACKAGE_UID, appEntry.info.uid);
         args.putBoolean(AppHeader.EXTRA_HIDE_INFO_BUTTON, true);
 
-        SettingsActivity sa = (SettingsActivity) getActivity();
-        sa.startPreferencePanel(fragment.getName(), args, -1, title, this, SUB_INFO_FRAGMENT);
+        SettingsActivity sa = (SettingsActivity) caller.getActivity();
+        sa.startPreferencePanel(fragment.getName(), args, -1, title, caller, SUB_INFO_FRAGMENT);
     }
 
     /*
@@ -929,7 +935,7 @@
     }
 
     private boolean hasPermission(String permission) {
-        if (mPackageInfo.requestedPermissions == null) {
+        if (mPackageInfo == null || mPackageInfo.requestedPermissions == null) {
             return false;
         }
         for (int i = 0; i < mPackageInfo.requestedPermissions.length; i++) {
diff --git a/src/com/android/settings/dashboard/SummaryLoader.java b/src/com/android/settings/dashboard/SummaryLoader.java
index 55d97df..780d68e 100644
--- a/src/com/android/settings/dashboard/SummaryLoader.java
+++ b/src/com/android/settings/dashboard/SummaryLoader.java
@@ -16,8 +16,14 @@
 package com.android.settings.dashboard;
 
 import android.app.Activity;
+import android.content.BroadcastReceiver;
 import android.content.ComponentName;
-import android.os.*;
+import android.content.IntentFilter;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.Looper;
+import android.os.Message;
 import android.os.Process;
 import android.util.ArrayMap;
 import android.util.Log;
@@ -45,6 +51,7 @@
 
     private DashboardAdapter mAdapter;
     private boolean mListening;
+    private ArrayList<BroadcastReceiver> mReceivers = new ArrayList<>();
 
     public SummaryLoader(Activity activity, List<DashboardCategory> categories) {
         mHandler = new Handler();
@@ -88,6 +95,14 @@
     }
 
     public void setListening(boolean listening) {
+        synchronized (mReceivers) {
+            // Unregister listeners immediately.
+            mListening = false;
+            for (int i = 0; i < mReceivers.size(); i++) {
+                mActivity.unregisterReceiver(mReceivers.get(i));
+            }
+            mReceivers.clear();
+        }
         mWorker.obtainMessage(Worker.MSG_SET_LISTENING, listening ? 1 : 0, 0).sendToTarget();
     }
 
@@ -128,13 +143,28 @@
         return tile.metaData;
     }
 
+    /**
+     * Registers a receiver and automatically unregisters it when the activity is stopping.
+     * This ensures that the receivers are unregistered immediately, since most summary loader
+     * operations are asynchronous.
+     */
+    public void registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
+        synchronized (mReceivers) {
+            if (!mListening) {
+                return;
+            }
+            mReceivers.add(receiver);
+            mActivity.registerReceiver(receiver, filter);
+        }
+    }
+
     private synchronized void setListeningW(boolean listening) {
         if (mListening == listening) return;
         if (DEBUG) Log.d(TAG, "Listening " + listening);
+        mListening = listening;
         for (SummaryProvider p : mSummaryMap.keySet()) {
             p.setListening(listening);
         }
-        mListening = listening;
     }
 
     private synchronized void makeProviderW(Tile tile) {
diff --git a/src/com/android/settings/dashboard/conditional/ConditionAdapterUtils.java b/src/com/android/settings/dashboard/conditional/ConditionAdapterUtils.java
index a5d0701..9a45a5a 100644
--- a/src/com/android/settings/dashboard/conditional/ConditionAdapterUtils.java
+++ b/src/com/android/settings/dashboard/conditional/ConditionAdapterUtils.java
@@ -74,13 +74,13 @@
         expand.setOnClickListener(onExpandListener);
 
         View detailGroup = view.itemView.findViewById(R.id.detail_group);
+        CharSequence[] actions = condition.getActions();
         if (isExpanded != (detailGroup.getVisibility() == View.VISIBLE)) {
             animateChange(view.itemView, view.itemView.findViewById(R.id.content),
-                    detailGroup, isExpanded);
+                    detailGroup, isExpanded, actions.length > 0);
         }
         if (isExpanded) {
             view.summary.setText(condition.getSummary());
-            CharSequence[] actions = condition.getActions();
             for (int i = 0; i < 2; i++) {
                 Button button = (Button) detailGroup.findViewById(i == 0
                         ? R.id.first_action : R.id.second_action);
@@ -105,7 +105,9 @@
     }
 
     private static void animateChange(final View view, final View content,
-            final View detailGroup, final boolean visible) {
+            final View detailGroup, final boolean visible, final boolean hasButtons) {
+        setViewVisibility(detailGroup, R.id.divider, hasButtons);
+        setViewVisibility(detailGroup, R.id.buttonBar, hasButtons);
         final int beforeBottom = content.getBottom();
         setHeight(detailGroup, visible ? LayoutParams.WRAP_CONTENT : 0);
         detailGroup.setVisibility(View.VISIBLE);
@@ -138,4 +140,11 @@
         params.height = height;
         detailGroup.setLayoutParams(params);
     }
+
+    private static void setViewVisibility(View containerView, int viewId, boolean visible) {
+        View view = containerView.findViewById(viewId);
+        if (view != null) {
+            view.setVisibility(visible ? View.VISIBLE : View.GONE);
+        }
+    }
 }
diff --git a/src/com/android/settings/dashboard/conditional/HotspotCondition.java b/src/com/android/settings/dashboard/conditional/HotspotCondition.java
index be74c9e..17be591 100644
--- a/src/com/android/settings/dashboard/conditional/HotspotCondition.java
+++ b/src/com/android/settings/dashboard/conditional/HotspotCondition.java
@@ -21,10 +21,15 @@
 import android.graphics.drawable.Icon;
 import android.net.wifi.WifiConfiguration;
 import android.net.wifi.WifiManager;
+import android.os.UserHandle;
+import android.os.UserManager;
+
 import com.android.internal.logging.MetricsProto.MetricsEvent;
 import com.android.settings.R;
 import com.android.settings.TetherSettings;
 import com.android.settings.Utils;
+import com.android.settingslib.RestrictedLockUtils;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
 import com.android.settingslib.TetherUtil;
 
 public class HotspotCondition extends Condition {
@@ -74,7 +79,12 @@
 
     @Override
     public CharSequence[] getActions() {
-        return new CharSequence[] { mManager.getContext().getString(R.string.condition_turn_off) };
+        final Context context = mManager.getContext();
+        if (RestrictedLockUtils.hasBaseUserRestriction(context,
+                UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId())) {
+            return new CharSequence[0];
+        }
+        return new CharSequence[] { context.getString(R.string.condition_turn_off) };
     }
 
     @Override
@@ -86,8 +96,15 @@
     @Override
     public void onActionClick(int index) {
         if (index == 0) {
-            TetherUtil.setWifiTethering(false, mManager.getContext());
-            setActive(false);
+            final Context context = mManager.getContext();
+            final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(context,
+                    UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId());
+            if (admin != null) {
+                RestrictedLockUtils.sendShowAdminSupportDetailsIntent(context, admin);
+            } else {
+                TetherUtil.setWifiTethering(false, context);
+                setActive(false);
+            }
         } else {
             throw new IllegalArgumentException("Unexpected index " + index);
         }
diff --git a/src/com/android/settings/datausage/AppDataUsage.java b/src/com/android/settings/datausage/AppDataUsage.java
index 3da3bac..0bd0615 100644
--- a/src/com/android/settings/datausage/AppDataUsage.java
+++ b/src/com/android/settings/datausage/AppDataUsage.java
@@ -54,7 +54,8 @@
 import static android.net.NetworkPolicyManager.POLICY_NONE;
 import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
 
-public class AppDataUsage extends DataUsageBase implements Preference.OnPreferenceChangeListener {
+public class AppDataUsage extends DataUsageBase implements Preference.OnPreferenceChangeListener,
+        DataSaverBackend.Listener {
 
     public static final String ARG_APP_ITEM = "app_item";
     public static final String ARG_NETWORK_TEMPLATE = "network_template";
@@ -207,6 +208,7 @@
     @Override
     public void onResume() {
         super.onResume();
+        mDataSaverBackend.addListener(this);
         mPolicy = services.mPolicyEditor.getPolicy(mTemplate);
         getLoaderManager().restartLoader(LOADER_CHART_DATA,
                 ChartDataLoader.buildArgs(mTemplate, mAppItem), mChartDataCallbacks);
@@ -214,9 +216,15 @@
     }
 
     @Override
+    public void onPause() {
+        super.onPause();
+        mDataSaverBackend.remListener(this);
+    }
+
+    @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
         if (preference == mRestrictBackground) {
-            setAppRestrictBackground(!(Boolean) newValue);
+            mDataSaverBackend.setIsBlacklisted(mAppItem.key, mPackageName, !(Boolean) newValue);
             return true;
         } else if (preference == mUnrestrictedData) {
             mDataSaverBackend.setIsWhitelisted(mAppItem.key, mPackageName, (Boolean) newValue);
@@ -237,15 +245,19 @@
     }
 
     private void updatePrefs() {
+        updatePrefs(getAppRestrictBackground(), getUnrestrictData());
+    }
+
+    private void updatePrefs(boolean restrictBackground, boolean unrestrictData) {
         if (mRestrictBackground != null) {
-            mRestrictBackground.setChecked(!getAppRestrictBackground());
+            mRestrictBackground.setChecked(!restrictBackground);
         }
         if (mUnrestrictedData != null) {
-            if (getAppRestrictBackground()) {
+            if (restrictBackground) {
                 mUnrestrictedData.setVisible(false);
             } else {
                 mUnrestrictedData.setVisible(true);
-                mUnrestrictedData.setChecked(mDataSaverBackend.isWhitelisted(mAppItem.key));
+                mUnrestrictedData.setChecked(unrestrictData);
             }
         }
     }
@@ -287,15 +299,8 @@
         return (uidPolicy & POLICY_REJECT_METERED_BACKGROUND) != 0;
     }
 
-    private void setAppRestrictBackground(boolean restrictBackground) {
-        final int uid = mAppItem.key;
-        services.mPolicyManager.setUidPolicy(
-                uid, restrictBackground ? POLICY_REJECT_METERED_BACKGROUND : POLICY_NONE);
-        updatePrefs();        // TODO: should have been notified by NPMS instead
-        if (restrictBackground) {
-            MetricsLogger.action(getContext(),
-                    MetricsEvent.ACTION_DATA_SAVER_BLACKLIST, mPackageName);
-        }
+    private boolean getUnrestrictData() {
+        return mDataSaverBackend.isWhitelisted(mAppItem.key);
     }
 
     @Override
@@ -378,4 +383,23 @@
             }
         }
     }
+
+    @Override
+    public void onDataSaverChanged(boolean isDataSaving) {
+
+    }
+
+    @Override
+    public void onWhitelistStatusChanged(int uid, boolean isWhitelisted) {
+        if (mAppItem.uids.get(uid, false)) {
+            updatePrefs(getAppRestrictBackground(), isWhitelisted);
+        }
+    }
+
+    @Override
+    public void onBlacklistStatusChanged(int uid, boolean isBlacklisted) {
+        if (mAppItem.uids.get(uid, false)) {
+            updatePrefs(isBlacklisted, getUnrestrictData());
+        }
+    }
 }
diff --git a/src/com/android/settings/datausage/AppStateDataUsageBridge.java b/src/com/android/settings/datausage/AppStateDataUsageBridge.java
index 1aff496..0b535d0 100644
--- a/src/com/android/settings/datausage/AppStateDataUsageBridge.java
+++ b/src/com/android/settings/datausage/AppStateDataUsageBridge.java
@@ -37,20 +37,24 @@
         final int N = apps.size();
         for (int i = 0; i < N; i++) {
             AppEntry app = apps.get(i);
-            app.extraInfo = new DataUsageState(mDataSaverBackend.isWhitelisted(app.info.uid));
+            app.extraInfo = new DataUsageState(mDataSaverBackend.isWhitelisted(app.info.uid),
+                    mDataSaverBackend.isBlacklisted(app.info.uid));
         }
     }
 
     @Override
     protected void updateExtraInfo(AppEntry app, String pkg, int uid) {
-        app.extraInfo = new DataUsageState(mDataSaverBackend.isWhitelisted(uid));
+        app.extraInfo = new DataUsageState(mDataSaverBackend.isWhitelisted(uid),
+                mDataSaverBackend.isBlacklisted(uid));
     }
 
     public static class DataUsageState {
         public boolean isDataSaverWhitelisted;
+        public boolean isDataSaverBlacklisted;
 
-        public DataUsageState(boolean isDataSaverWhitelisted) {
+        public DataUsageState(boolean isDataSaverWhitelisted, boolean isDataSaverBlacklisted) {
             this.isDataSaverWhitelisted = isDataSaverWhitelisted;
+            this.isDataSaverBlacklisted = isDataSaverBlacklisted;
         }
     }
 }
diff --git a/src/com/android/settings/datausage/DataSaverBackend.java b/src/com/android/settings/datausage/DataSaverBackend.java
index d72fe3d..eb62ad7 100644
--- a/src/com/android/settings/datausage/DataSaverBackend.java
+++ b/src/com/android/settings/datausage/DataSaverBackend.java
@@ -29,6 +29,9 @@
 
 import java.util.ArrayList;
 
+import static android.net.NetworkPolicyManager.POLICY_NONE;
+import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
+
 public class DataSaverBackend {
 
     private static final String TAG = "DataSaverBackend";
@@ -40,6 +43,7 @@
     private final INetworkPolicyManager mIPolicyManager;
     private final ArrayList<Listener> mListeners = new ArrayList<>();
     private SparseBooleanArray mWhitelist;
+    private SparseBooleanArray mBlacklist;
 
     // TODO: Staticize into only one.
     public DataSaverBackend(Context context) {
@@ -121,15 +125,81 @@
         }
     }
 
+    public void refreshBlacklist() {
+        loadBlacklist();
+    }
+
+    public void setIsBlacklisted(int uid, String packageName, boolean blacklisted) {
+        mPolicyManager.setUidPolicy(
+                uid, blacklisted ? POLICY_REJECT_METERED_BACKGROUND : POLICY_NONE);
+        if (blacklisted) {
+            MetricsLogger.action(mContext, MetricsEvent.ACTION_DATA_SAVER_BLACKLIST, packageName);
+        }
+    }
+
+    public boolean isBlacklisted(int uid) {
+        if (mBlacklist == null) {
+            loadBlacklist();
+        }
+        return mBlacklist.get(uid);
+    }
+
+    private void loadBlacklist() {
+        mBlacklist = new SparseBooleanArray();
+        try {
+            for (int uid : mIPolicyManager.getUidsWithPolicy(POLICY_REJECT_METERED_BACKGROUND)) {
+                mBlacklist.put(uid, true);
+            }
+        } catch (RemoteException e) {
+        }
+    }
+
     private void handleRestrictBackgroundChanged(boolean isDataSaving) {
         for (int i = 0; i < mListeners.size(); i++) {
             mListeners.get(i).onDataSaverChanged(isDataSaving);
         }
     }
 
+    private void handleWhitelistChanged(int uid, boolean isWhitelisted) {
+        for (int i = 0; i < mListeners.size(); i++) {
+            mListeners.get(i).onWhitelistStatusChanged(uid, isWhitelisted);
+        }
+    }
+
+    private void handleBlacklistChanged(int uid, boolean isBlacklisted) {
+        for (int i = 0; i < mListeners.size(); i++) {
+            mListeners.get(i).onBlacklistStatusChanged(uid, isBlacklisted);
+        }
+    }
+
     private final INetworkPolicyListener mPolicyListener = new INetworkPolicyListener.Stub() {
         @Override
-        public void onUidRulesChanged(int i, int i1) throws RemoteException {
+        public void onUidRulesChanged(final int uid, int uidRules) throws RemoteException {
+            if (mBlacklist == null) {
+                loadBlacklist();
+            }
+            final boolean isBlacklisted = uidRules == POLICY_REJECT_METERED_BACKGROUND;
+            mBlacklist.put(uid, isBlacklisted);
+            mHandler.post(new Runnable() {
+                @Override
+                public void run() {
+                    handleBlacklistChanged(uid, isBlacklisted);
+                }
+            });
+        }
+
+        @Override
+        public void onRestrictBackgroundWhitelistChanged(final int uid, final boolean whitelisted) {
+            if (mWhitelist == null) {
+                loadWhitelist();
+            }
+            mWhitelist.put(uid, whitelisted);
+            mHandler.post(new Runnable() {
+                @Override
+                public void run() {
+                    handleWhitelistChanged(uid, whitelisted);
+                }
+            });
         }
 
         @Override
@@ -149,5 +219,7 @@
 
     public interface Listener {
         void onDataSaverChanged(boolean isDataSaving);
+        void onWhitelistStatusChanged(int uid, boolean isWhitelisted);
+        void onBlacklistStatusChanged(int uid, boolean isBlacklisted);
     }
 }
diff --git a/src/com/android/settings/datausage/DataSaverPreference.java b/src/com/android/settings/datausage/DataSaverPreference.java
index c286d95..13ef9d7 100644
--- a/src/com/android/settings/datausage/DataSaverPreference.java
+++ b/src/com/android/settings/datausage/DataSaverPreference.java
@@ -44,4 +44,12 @@
     public void onDataSaverChanged(boolean isDataSaving) {
         setSummary(isDataSaving ? R.string.data_saver_on : R.string.data_saver_off);
     }
+
+    @Override
+    public void onWhitelistStatusChanged(int uid, boolean isWhitelisted) {
+    }
+
+    @Override
+    public void onBlacklistStatusChanged(int uid, boolean isBlacklisted) {
+    }
 }
diff --git a/src/com/android/settings/datausage/DataSaverSummary.java b/src/com/android/settings/datausage/DataSaverSummary.java
index e8c8cdd..8dfbad5 100644
--- a/src/com/android/settings/datausage/DataSaverSummary.java
+++ b/src/com/android/settings/datausage/DataSaverSummary.java
@@ -70,6 +70,7 @@
     public void onResume() {
         super.onResume();
         mDataSaverBackend.refreshWhitelist();
+        mDataSaverBackend.refreshBlacklist();
         mDataSaverBackend.addListener(this);
         mSession.resume();
         mDataUsageBridge.resume();
@@ -99,6 +100,14 @@
     }
 
     @Override
+    public void onWhitelistStatusChanged(int uid, boolean isWhitelisted) {
+    }
+
+    @Override
+    public void onBlacklistStatusChanged(int uid, boolean isBlacklisted) {
+    }
+
+    @Override
     public void onExtraInfoUpdated() {
         if (!isAdded()) {
             return;
diff --git a/src/com/android/settings/datausage/UnrestrictedDataAccess.java b/src/com/android/settings/datausage/UnrestrictedDataAccess.java
index 36ec050..740fe06 100644
--- a/src/com/android/settings/datausage/UnrestrictedDataAccess.java
+++ b/src/com/android/settings/datausage/UnrestrictedDataAccess.java
@@ -24,10 +24,15 @@
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
+
 import com.android.internal.logging.MetricsProto.MetricsEvent;
+import com.android.settings.AppHeader;
 import com.android.settings.R;
+import com.android.settings.SettingsActivity;
 import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.applications.AppInfoBase;
 import com.android.settings.applications.AppStateBaseBridge;
+import com.android.settings.applications.InstalledAppDetails;
 import com.android.settings.datausage.AppStateDataUsageBridge.DataUsageState;
 import com.android.settingslib.applications.ApplicationsState;
 import com.android.settingslib.applications.ApplicationsState.AppEntry;
@@ -36,10 +41,12 @@
 import java.util.ArrayList;
 
 public class UnrestrictedDataAccess extends SettingsPreferenceFragment
-        implements ApplicationsState.Callbacks, AppStateBaseBridge.Callback, Preference.OnPreferenceChangeListener {
+        implements ApplicationsState.Callbacks, AppStateBaseBridge.Callback,
+        Preference.OnPreferenceChangeListener {
 
     private static final int MENU_SHOW_SYSTEM = Menu.FIRST + 42;
     private static final String EXTRA_SHOW_SYSTEM = "show_system";
+
     private ApplicationsState mApplicationsState;
     private AppStateDataUsageBridge mDataUsageBridge;
     private ApplicationsState.Session mSession;
@@ -144,11 +151,11 @@
     }
 
     @Override
-    public void onRebuildComplete(ArrayList<ApplicationsState.AppEntry> apps) {
+    public void onRebuildComplete(ArrayList<AppEntry> apps) {
         cacheRemoveAllPrefs(getPreferenceScreen());
         final int N = apps.size();
         for (int i = 0; i < N; i++) {
-            ApplicationsState.AppEntry entry = apps.get(i);
+            AppEntry entry = apps.get(i);
             String key = entry.info.packageName + "|" + entry.info.uid;
             AccessPreference preference = (AccessPreference) getCachedPreference(key);
             if (preference == null) {
@@ -202,32 +209,69 @@
             boolean whitelisted = newValue == Boolean.TRUE;
             mDataSaverBackend.setIsWhitelisted(accessPreference.mEntry.info.uid,
                     accessPreference.mEntry.info.packageName, whitelisted);
-            ((AppStateDataUsageBridge.DataUsageState) accessPreference.mEntry.extraInfo)
-                    .isDataSaverWhitelisted = whitelisted;
+            accessPreference.mState.isDataSaverWhitelisted = whitelisted;
             return true;
         }
         return false;
     }
 
-    private class AccessPreference extends SwitchPreference {
-        private final ApplicationsState.AppEntry mEntry;
+    private class AccessPreference extends SwitchPreference implements DataSaverBackend.Listener {
+        private final AppEntry mEntry;
+        private final DataUsageState mState;
 
-        public AccessPreference(Context context, ApplicationsState.AppEntry entry) {
+        public AccessPreference(final Context context, AppEntry entry) {
             super(context);
             mEntry = entry;
+            mState = (DataUsageState) mEntry.extraInfo;
             mEntry.ensureLabel(getContext());
-            setTitle(entry.label);
-            final DataUsageState state = (DataUsageState) entry.extraInfo;
-            setChecked(state != null && state.isDataSaverWhitelisted);
+            setState();
             if (mEntry.icon != null) {
                 setIcon(mEntry.icon);
             }
         }
 
-        public void reuse() {
+        @Override
+        public void onAttached() {
+            super.onAttached();
+            mDataSaverBackend.addListener(this);
+        }
+
+        @Override
+        public void onDetached() {
+            mDataSaverBackend.remListener(this);
+            super.onDetached();
+        }
+
+        @Override
+        protected void onClick() {
+            if (mState.isDataSaverBlacklisted) {
+                // app is blacklisted, launch App Data Usage screen
+                InstalledAppDetails.startAppInfoFragment(AppDataUsage.class,
+                        getContext().getString(R.string.app_data_usage),
+                        UnrestrictedDataAccess.this,
+                        mEntry);
+            } else {
+                // app is not blacklisted, let superclass handle toggle switch
+                super.onClick();
+            }
+        }
+
+        // Sets UI state based on whitelist/blacklist status.
+        private void setState() {
             setTitle(mEntry.label);
-            final DataUsageState state = (DataUsageState) mEntry.extraInfo;
-            setChecked(state != null && state.isDataSaverWhitelisted);
+            if (mState != null) {
+                setChecked(mState.isDataSaverWhitelisted);
+                if (mState.isDataSaverBlacklisted) {
+                    setSummary(R.string.restrict_background_blacklisted);
+                } else {
+                    setSummary("");
+                }
+            }
+        }
+
+        public void reuse() {
+            setState();
+            notifyChanged();
         }
 
         @Override
@@ -244,7 +288,31 @@
                     }
                 });
             }
+            holder.findViewById(android.R.id.widget_frame)
+                    .setVisibility(mState != null && mState.isDataSaverBlacklisted
+                            ? View.INVISIBLE : View.VISIBLE);
             super.onBindViewHolder(holder);
         }
+
+        @Override
+        public void onDataSaverChanged(boolean isDataSaving) {
+        }
+
+        @Override
+        public void onWhitelistStatusChanged(int uid, boolean isWhitelisted) {
+            if (mState != null && mEntry.info.uid == uid) {
+                mState.isDataSaverWhitelisted = isWhitelisted;
+                reuse();
+            }
+        }
+
+        @Override
+        public void onBlacklistStatusChanged(int uid, boolean isBlacklisted) {
+            if (mState != null && mEntry.info.uid == uid) {
+                mState.isDataSaverBlacklisted = isBlacklisted;
+                reuse();
+            }
+        }
     }
+
 }
diff --git a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
index 5f5975d..66026eb 100644
--- a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
+++ b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
@@ -326,6 +326,12 @@
     }
 
     @Override
+    public void onAttach(Context context) {
+        super.onAttach(context);
+        mDetached = false;
+    }
+
+    @Override
     public void onDetach() {
         super.onDetach();
         mDetached = true;
diff --git a/src/com/android/settings/deviceinfo/SimStatus.java b/src/com/android/settings/deviceinfo/SimStatus.java
index 80dfc58..0acad37 100644
--- a/src/com/android/settings/deviceinfo/SimStatus.java
+++ b/src/com/android/settings/deviceinfo/SimStatus.java
@@ -151,7 +151,7 @@
             mSir = mSelectableSubInfos.size() > 0 ? mSelectableSubInfos.get(0) : null;
 
             if (mSelectableSubInfos.size() > 1) {
-                setContentView(com.android.internal.R.layout.common_tab_settings);
+                setContentView(R.layout.icc_lock_tabs);
 
                 mTabHost = (TabHost) findViewById(android.R.id.tabhost);
                 mTabWidget = (TabWidget) findViewById(android.R.id.tabs);
diff --git a/src/com/android/settings/deviceinfo/StorageSettings.java b/src/com/android/settings/deviceinfo/StorageSettings.java
index 9774db9..902ca07 100644
--- a/src/com/android/settings/deviceinfo/StorageSettings.java
+++ b/src/com/android/settings/deviceinfo/StorageSettings.java
@@ -248,6 +248,10 @@
             // Picked a normal volume
             final VolumeInfo vol = mStorageManager.findVolumeById(key);
 
+            if (vol == null) {
+                return false;
+            }
+
             if (vol.getState() == VolumeInfo.STATE_UNMOUNTED) {
                 VolumeUnmountedFragment.show(this, vol.getId());
                 return true;
diff --git a/src/com/android/settings/display/ConversationMessageView.java b/src/com/android/settings/display/ConversationMessageView.java
index a0889c4..06e7b9b 100644
--- a/src/com/android/settings/display/ConversationMessageView.java
+++ b/src/com/android/settings/display/ConversationMessageView.java
@@ -96,13 +96,15 @@
         updateViewAppearance();
 
         final int horizontalSpace = MeasureSpec.getSize(widthMeasureSpec);
-        final int iconSize = getResources()
-                .getDimensionPixelSize(R.dimen.conversation_message_contact_icon_size);
 
         final int unspecifiedMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
-        final int iconMeasureSpec = MeasureSpec.makeMeasureSpec(iconSize, MeasureSpec.EXACTLY);
+        int iconMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
 
         mContactIconView.measure(iconMeasureSpec, iconMeasureSpec);
+        iconMeasureSpec = MeasureSpec.makeMeasureSpec(
+                Math.max(mContactIconView.getMeasuredWidth(), mContactIconView.getMeasuredHeight()),
+                MeasureSpec.EXACTLY);
+        mContactIconView.measure(iconMeasureSpec, iconMeasureSpec);
 
         final int arrowWidth =
                 getResources().getDimensionPixelSize(R.dimen.message_bubble_arrow_width);
diff --git a/src/com/android/settings/inputmethod/AvailableVirtualKeyboardFragment.java b/src/com/android/settings/inputmethod/AvailableVirtualKeyboardFragment.java
index 1de3fcc..d35f895 100644
--- a/src/com/android/settings/inputmethod/AvailableVirtualKeyboardFragment.java
+++ b/src/com/android/settings/inputmethod/AvailableVirtualKeyboardFragment.java
@@ -16,9 +16,15 @@
 
 package com.android.settings.inputmethod;
 
+import android.annotation.DrawableRes;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.app.Activity;
 import android.app.admin.DevicePolicyManager;
 import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ServiceInfo;
 import android.content.res.Configuration;
 import android.graphics.Color;
 import android.graphics.drawable.ColorDrawable;
@@ -40,8 +46,6 @@
 public final class AvailableVirtualKeyboardFragment extends SettingsPreferenceFragment
         implements InputMethodPreference.OnSavePreferenceListener {
 
-    private static final Drawable NO_ICON = new ColorDrawable(Color.TRANSPARENT);
-
     private final ArrayList<InputMethodPreference> mInputMethodPreferenceList = new ArrayList<>();
     private InputMethodSettingValuesWrapper mInputMethodSettingValues;
     private InputMethodManager mImm;
@@ -85,27 +89,68 @@
         return MetricsEvent.ENABLE_VIRTUAL_KEYBOARDS;
     }
 
+    @Nullable
+    private static Drawable loadDrawable(@NonNull final PackageManager packageManager,
+            @NonNull final String packageName, @DrawableRes final int resId,
+            @NonNull final ApplicationInfo applicationInfo) {
+        if (resId == 0) {
+            return null;
+        }
+        try {
+            return packageManager.getDrawable(packageName, resId, applicationInfo);
+        } catch (Exception e){
+            return null;
+        }
+    }
+
+    @NonNull
+    private static Drawable getInputMethodIcon(@NonNull final PackageManager packageManager,
+            @NonNull final InputMethodInfo imi) {
+        final ServiceInfo si = imi.getServiceInfo();
+        final ApplicationInfo ai = si.applicationInfo;
+        final String packageName = imi.getPackageName();
+        if (si == null || ai == null || packageName == null) {
+            return new ColorDrawable(Color.TRANSPARENT);
+        }
+        // We do not use ServiceInfo#loadLogo() and ServiceInfo#loadIcon here since those methods
+        // internally have some fallback rules, which we want to do manually.
+        Drawable drawable = loadDrawable(packageManager, packageName, si.logo, ai);
+        if (drawable != null) {
+            return drawable;
+        }
+        drawable = loadDrawable(packageManager, packageName, si.icon, ai);
+        if (drawable != null) {
+            return drawable;
+        }
+        // We do not use ApplicationInfo#loadLogo() and ApplicationInfo#loadIcon here since those
+        // methods internally have some fallback rules, which we want to do manually.
+        drawable = loadDrawable(packageManager, packageName, ai.logo, ai);
+        if (drawable != null) {
+            return drawable;
+        }
+        drawable = loadDrawable(packageManager, packageName, ai.icon, ai);
+        if (drawable != null) {
+            return drawable;
+        }
+        return new ColorDrawable(Color.TRANSPARENT);
+    }
+
     private void updateInputMethodPreferenceViews() {
         mInputMethodSettingValues.refreshAllInputMethodAndSubtypes();
         // Clear existing "InputMethodPreference"s
         mInputMethodPreferenceList.clear();
         List<String> permittedList = mDpm.getPermittedInputMethodsForCurrentUser();
         final Context context = getPrefContext();
+        final PackageManager packageManager = getActivity().getPackageManager();
         final List<InputMethodInfo> imis = mInputMethodSettingValues.getInputMethodList();
         final int N = (imis == null ? 0 : imis.size());
         for (int i = 0; i < N; ++i) {
             final InputMethodInfo imi = imis.get(i);
             final boolean isAllowedByOrganization = permittedList == null
                     || permittedList.contains(imi.getPackageName());
-            Drawable icon;
-            try {
-                icon = getActivity().getPackageManager().getApplicationIcon(imi.getPackageName());
-            } catch (Exception e) {
-                icon = NO_ICON;
-            }
             final InputMethodPreference pref = new InputMethodPreference(
                     context, imi, true, isAllowedByOrganization, this);
-            pref.setIcon(icon);
+            pref.setIcon(getInputMethodIcon(packageManager, imi));
             mInputMethodPreferenceList.add(pref);
         }
         final Collator collator = Collator.getInstance();
diff --git a/src/com/android/settings/inputmethod/SpellCheckersSettings.java b/src/com/android/settings/inputmethod/SpellCheckersSettings.java
index bc2a5c0..3309af2 100644
--- a/src/com/android/settings/inputmethod/SpellCheckersSettings.java
+++ b/src/com/android/settings/inputmethod/SpellCheckersSettings.java
@@ -113,7 +113,7 @@
         mSwitchBar.setChecked(isSpellCheckerEnabled);
 
         final SpellCheckerSubtype currentScs;
-        if (mCurrentSci == null) {
+        if (mCurrentSci != null) {
             currentScs = mTsm.getCurrentSpellCheckerSubtype(
                     false /* allowImplicitlySelectedSubtype */);
         } else {
diff --git a/src/com/android/settings/inputmethod/VirtualKeyboardFragment.java b/src/com/android/settings/inputmethod/VirtualKeyboardFragment.java
index fe81a81..3b36de6 100644
--- a/src/com/android/settings/inputmethod/VirtualKeyboardFragment.java
+++ b/src/com/android/settings/inputmethod/VirtualKeyboardFragment.java
@@ -113,7 +113,7 @@
             InputMethodAndSubtypeUtil.removeUnnecessaryNonPersistentPreference(pref);
             pref.updatePreferenceViews();
         }
-        mAddVirtualKeyboardScreen.setIcon(R.drawable.ic_add);
+        mAddVirtualKeyboardScreen.setIcon(R.drawable.ic_add_24dp);
         mAddVirtualKeyboardScreen.setOrder(N);
         getPreferenceScreen().addPreference(mAddVirtualKeyboardScreen);
     }
diff --git a/src/com/android/settings/tts/TextToSpeechSettings.java b/src/com/android/settings/tts/TextToSpeechSettings.java
index 0a48874..8c34518 100644
--- a/src/com/android/settings/tts/TextToSpeechSettings.java
+++ b/src/com/android/settings/tts/TextToSpeechSettings.java
@@ -71,6 +71,9 @@
     /** Preference key for the TTS reset speech rate preference. */
     private static final String KEY_RESET_SPEECH_RATE = "reset_speech_rate";
 
+    /** Preference key for the TTS reset speech pitch preference. */
+    private static final String KEY_RESET_SPEECH_PITCH = "reset_speech_pitch";
+
     /** Preference key for the TTS status field. */
     private static final String KEY_STATUS = "tts_status";
 
@@ -87,10 +90,11 @@
     private static final int VOICE_DATA_INTEGRITY_CHECK = 1977;
 
     /**
-     * Maximum speech rate value.
+     * Speech rate value.
      * This value should be kept in sync with the max value set in tts_settings xml.
      */
     private static final int MAX_SPEECH_RATE = 600;
+    private static final int MIN_SPEECH_RATE = 10;
 
     /**
      * Speech pitch value.
@@ -107,6 +111,7 @@
     private SeekBarPreference mDefaultPitchPref;
     private SeekBarPreference mDefaultRatePref;
     private Preference mResetSpeechRate;
+    private Preference mResetSpeechPitch;
     private Preference mPlayExample;
     private Preference mEngineStatus;
 
@@ -189,6 +194,8 @@
 
         mResetSpeechRate = findPreference(KEY_RESET_SPEECH_RATE);
         mResetSpeechRate.setOnPreferenceClickListener(this);
+        mResetSpeechPitch = findPreference(KEY_RESET_SPEECH_PITCH);
+        mResetSpeechPitch.setOnPreferenceClickListener(this);
 
         mEnginePreferenceCategory = (PreferenceCategory) findPreference(
                 KEY_ENGINE_PREFERENCE_SECTION);
@@ -252,24 +259,27 @@
     private void initSettings() {
         final ContentResolver resolver = getContentResolver();
 
-         // Set up the default rate and pitch.
-        try {
-            mDefaultPitch = android.provider.Settings.Secure.getInt(resolver, TTS_DEFAULT_PITCH);
-            mDefaultRate = android.provider.Settings.Secure.getInt(resolver, TTS_DEFAULT_RATE);
-        } catch (SettingNotFoundException e) {
-            // Default rate and pitch setting not found, initialize it.
-            mDefaultPitch = TextToSpeech.Engine.DEFAULT_PITCH;
-            mDefaultRate = TextToSpeech.Engine.DEFAULT_RATE;
-        }
-        mDefaultRatePref.setProgress(mDefaultRate);
+        // Set up the default rate and pitch.
+        mDefaultRate = android.provider.Settings.Secure.getInt(
+            resolver, TTS_DEFAULT_RATE, TextToSpeech.Engine.DEFAULT_RATE);
+        mDefaultPitch = android.provider.Settings.Secure.getInt(
+            resolver, TTS_DEFAULT_PITCH, TextToSpeech.Engine.DEFAULT_PITCH);
+
+        mDefaultRatePref.setProgress(getSeekBarProgressFromValue(KEY_DEFAULT_RATE, mDefaultRate));
         mDefaultRatePref.setOnPreferenceChangeListener(this);
-        mDefaultRatePref.setMax(MAX_SPEECH_RATE);
+        mDefaultRatePref.setMax(getSeekBarProgressFromValue(KEY_DEFAULT_RATE, MAX_SPEECH_RATE));
 
-        mDefaultPitchPref.setProgress(getPitchSeekBarProgressFromSpeechPitchValue(mDefaultPitch));
+        mDefaultPitchPref.setProgress(getSeekBarProgressFromValue(KEY_DEFAULT_PITCH,
+              mDefaultPitch));
         mDefaultPitchPref.setOnPreferenceChangeListener(this);
-        mDefaultPitchPref.setMax(getPitchSeekBarProgressFromSpeechPitchValue(MAX_SPEECH_PITCH));
+        mDefaultPitchPref.setMax(getSeekBarProgressFromValue(KEY_DEFAULT_PITCH,
+              MAX_SPEECH_PITCH));
 
-        mCurrentEngine = mTts.getCurrentEngine();
+        if (mTts != null) {
+            mCurrentEngine = mTts.getCurrentEngine();
+            mTts.setSpeechRate(mDefaultRate/100.0f);
+            mTts.setPitch(mDefaultPitch/100.0f);
+        }
 
         SettingsActivity activity = null;
         if (getActivity() instanceof SettingsActivity) {
@@ -292,21 +302,31 @@
     }
 
     /**
-     * The minimum pitch value should be > 0 but the minimum value of a seekbar in android
-     * is fixed at 0. Therefore, we increment the seekbar progress with MIN_SPEECH_PITCH value
-     * so that the minimum seekbar progress value is MIN_SPEECH_PITCH.
-     *     PITCH_VALUE = MIN_SPEECH_PITCH + PITCH_SEEKBAR_PROGRESS
+     * The minimum speech pitch/rate value should be > 0 but the minimum value of a seekbar in
+     * android is fixed at 0. Therefore, we increment the seekbar progress with MIN_SPEECH_VALUE
+     * so that the minimum seekbar progress value is MIN_SPEECH_PITCH/RATE.
+     *     SPEECH_VALUE = MIN_SPEECH_VALUE + SEEKBAR_PROGRESS
      */
-    private int getSpeechPitchValueFromSeekBarProgress(int progress) {
-        return MIN_SPEECH_PITCH + progress;
+    private int getValueFromSeekBarProgress(String preferenceKey, int progress) {
+        if (preferenceKey.equals(KEY_DEFAULT_RATE)) {
+            return MIN_SPEECH_RATE + progress;
+        } else if (preferenceKey.equals(KEY_DEFAULT_PITCH)) {
+            return MIN_SPEECH_PITCH + progress;
+        }
+        return progress;
     }
 
     /**
-     * Since we are appending the MIN_SPEECH_PITCH to the pitch seekbar progress, the pitch
-     * seekbar progress should be set to (pitchValue - MIN_SPEECH_PITCH).
+     * Since we are appending the MIN_SPEECH value to the speech seekbar progress, the
+     * speech seekbar progress should be set to (speechValue - MIN_SPEECH value).
      */
-    private int getPitchSeekBarProgressFromSpeechPitchValue(int pitchValue) {
-        return pitchValue - MIN_SPEECH_PITCH;
+    private int getSeekBarProgressFromValue(String preferenceKey, int value) {
+        if (preferenceKey.equals(KEY_DEFAULT_RATE)) {
+            return value - MIN_SPEECH_RATE;
+        } else if (preferenceKey.equals(KEY_DEFAULT_PITCH)) {
+            return value - MIN_SPEECH_PITCH;
+        }
+        return value;
     }
 
     /**
@@ -505,24 +525,14 @@
         if (KEY_DEFAULT_RATE.equals(preference.getKey())) {
             updateSpeechRate((Integer) objValue);
         } else if (KEY_DEFAULT_PITCH.equals(preference.getKey())) {
-            int progress = (Integer) objValue;
-            mDefaultPitch = getSpeechPitchValueFromSeekBarProgress(progress);
-            try {
-                android.provider.Settings.Secure.putInt(getContentResolver(),
-                        TTS_DEFAULT_PITCH, mDefaultPitch);
-               if (mTts != null) {
-                   mTts.setPitch(mDefaultPitch / 100.0f);
-               }
-               if (DBG) Log.d(TAG, "TTS default pitch changed, now" + mDefaultPitch);
-           } catch (NumberFormatException e) {
-               Log.e(TAG, "could not persist default TTS pitch setting", e);
-           }
+            updateSpeechPitchValue((Integer) objValue);
         }
         return true;
     }
 
     /**
-     * Called when mPlayExample or mResetSpeechRate is clicked.
+     * Called when mPlayExample, mResetSpeechRate or mResetSpeechPitch is
+     * clicked.
      */
     @Override
     public boolean onPreferenceClick(Preference preference) {
@@ -532,15 +542,24 @@
             speakSampleText();
             return true;
         } else if (preference == mResetSpeechRate) {
-          mDefaultRatePref.setProgress(TextToSpeech.Engine.DEFAULT_RATE);
-          updateSpeechRate(TextToSpeech.Engine.DEFAULT_RATE);
+          int speechRateSeekbarProgress = getSeekBarProgressFromValue(
+              KEY_DEFAULT_RATE, TextToSpeech.Engine.DEFAULT_RATE);
+          mDefaultRatePref.setProgress(speechRateSeekbarProgress);
+          updateSpeechRate(speechRateSeekbarProgress);
+          return true;
+        } else if (preference == mResetSpeechPitch) {
+          int pitchSeekbarProgress = getSeekBarProgressFromValue(
+              KEY_DEFAULT_PITCH, TextToSpeech.Engine.DEFAULT_PITCH);
+          mDefaultPitchPref.setProgress(pitchSeekbarProgress);
+          updateSpeechPitchValue(pitchSeekbarProgress);
           return true;
         }
         return false;
     }
 
-    private void updateSpeechRate(int speechRate) {
-        mDefaultRate = speechRate;
+    private void updateSpeechRate(int speechRateSeekBarProgress) {
+        mDefaultRate = getValueFromSeekBarProgress(KEY_DEFAULT_RATE,
+            speechRateSeekBarProgress);
         try {
             android.provider.Settings.Secure.putInt(getContentResolver(),
                     TTS_DEFAULT_RATE, mDefaultRate);
@@ -554,6 +573,22 @@
         return;
     }
 
+    private void updateSpeechPitchValue(int speechPitchSeekBarProgress) {
+        mDefaultPitch = getValueFromSeekBarProgress(KEY_DEFAULT_PITCH,
+            speechPitchSeekBarProgress);
+        try {
+            android.provider.Settings.Secure.putInt(getContentResolver(),
+                    TTS_DEFAULT_PITCH, mDefaultPitch);
+            if (mTts != null) {
+                mTts.setPitch(mDefaultPitch / 100.0f);
+            }
+            if (DBG) Log.d(TAG, "TTS default pitch changed, now" + mDefaultPitch);
+        } catch (NumberFormatException e) {
+            Log.e(TAG, "could not persist default TTS pitch setting", e);
+        }
+        return;
+    }
+
     private void updateWidgetState(boolean enable) {
         mPlayExample.setEnabled(enable);
         mDefaultRatePref.setEnabled(enable);
diff --git a/src/com/android/settings/widget/LabeledSeekBar.java b/src/com/android/settings/widget/LabeledSeekBar.java
index bf6983e..f1a6788 100644
--- a/src/com/android/settings/widget/LabeledSeekBar.java
+++ b/src/com/android/settings/widget/LabeledSeekBar.java
@@ -17,6 +17,7 @@
 package com.android.settings.widget;
 
 import android.content.Context;
+import android.content.res.Configuration;
 import android.graphics.Rect;
 import android.os.Bundle;
 import android.support.v4.view.ViewCompat;
@@ -24,6 +25,7 @@
 import android.support.v4.widget.ExploreByTouchHelper;
 import android.util.AttributeSet;
 import android.view.MotionEvent;
+import android.view.View;
 import android.view.accessibility.AccessibilityEvent;
 import android.widget.RadioButton;
 import android.widget.RadioGroup;
@@ -121,8 +123,12 @@
 
     private class LabeledSeekBarExploreByTouchHelper extends ExploreByTouchHelper {
 
+        private boolean mIsLayoutRtl;
+
         public LabeledSeekBarExploreByTouchHelper(LabeledSeekBar forView) {
             super(forView);
+            mIsLayoutRtl = forView.getResources().getConfiguration()
+                    .getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
         }
 
         @Override
@@ -192,20 +198,23 @@
         }
 
         private int getVirtualViewIdIndexFromX(float x) {
-            final int posBase = Math.max(0,
+            int posBase = Math.max(0,
                     ((int) x - LabeledSeekBar.this.getPaddingStart()) / getHalfVirtualViewWidth());
-            return (posBase + 1) / 2;
+            posBase = (posBase + 1) / 2;
+            return mIsLayoutRtl ? LabeledSeekBar.this.getMax() - posBase : posBase;
         }
 
         private Rect getBoundsInParentFromVirtualViewId(int virtualViewId) {
-            int left = (virtualViewId * 2 - 1) * getHalfVirtualViewWidth()
+            final int updatedVirtualViewId = mIsLayoutRtl
+                    ? LabeledSeekBar.this.getMax() - virtualViewId : virtualViewId;
+            int left = (updatedVirtualViewId * 2 - 1) * getHalfVirtualViewWidth()
                     + LabeledSeekBar.this.getPaddingStart();
-            int right = (virtualViewId * 2 + 1) * getHalfVirtualViewWidth()
+            int right = (updatedVirtualViewId * 2 + 1) * getHalfVirtualViewWidth()
                     + LabeledSeekBar.this.getPaddingStart();
 
             // Edge case
-            left = virtualViewId == 0 ? 0 : left;
-            right = virtualViewId == LabeledSeekBar.this.getMax()
+            left = updatedVirtualViewId == 0 ? 0 : left;
+            right = updatedVirtualViewId == LabeledSeekBar.this.getMax()
                     ? LabeledSeekBar.this.getWidth() : right;
 
             final Rect r = new Rect();
diff --git a/src/com/android/settings/wifi/WifiEnabler.java b/src/com/android/settings/wifi/WifiEnabler.java
index 2ff404d..f064050 100644
--- a/src/com/android/settings/wifi/WifiEnabler.java
+++ b/src/com/android/settings/wifi/WifiEnabler.java
@@ -26,6 +26,8 @@
 import android.net.wifi.WifiManager;
 import android.os.Handler;
 import android.os.Message;
+import android.os.UserHandle;
+import android.os.UserManager;
 import android.provider.Settings;
 import android.widget.Switch;
 import android.widget.Toast;
@@ -35,6 +37,8 @@
 import com.android.settings.R;
 import com.android.settings.search.Index;
 import com.android.settings.widget.SwitchBar;
+import com.android.settingslib.RestrictedLockUtils;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
 import com.android.settingslib.WirelessUtils;
 
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -136,6 +140,9 @@
     }
 
     private void handleWifiStateChanged(int state) {
+        // Clear any previous state
+        mSwitchBar.setDisabledByAdmin(null);
+
         switch (state) {
             case WifiManager.WIFI_STATE_ENABLING:
                 mSwitchBar.setEnabled(false);
@@ -158,6 +165,16 @@
                 mSwitchBar.setEnabled(true);
                 updateSearchIndex(false);
         }
+        if (mayDisableTethering(!mSwitchBar.isChecked())) {
+            if (RestrictedLockUtils.hasBaseUserRestriction(mContext,
+                    UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId())) {
+                mSwitchBar.setEnabled(false);
+            } else {
+                final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(mContext,
+                    UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId());
+                mSwitchBar.setDisabledByAdmin(admin);
+            }
+        }
     }
 
     private void updateSearchIndex(boolean isWiFiOn) {
@@ -206,9 +223,7 @@
         }
 
         // Disable tethering if enabling Wifi
-        int wifiApState = mWifiManager.getWifiApState();
-        if (isChecked && ((wifiApState == WifiManager.WIFI_AP_STATE_ENABLING) ||
-                (wifiApState == WifiManager.WIFI_AP_STATE_ENABLED))) {
+        if (mayDisableTethering(isChecked)) {
             mWifiManager.setWifiApEnabled(null, false);
         }
         MetricsLogger.action(mContext,
@@ -219,4 +234,10 @@
             Toast.makeText(mContext, R.string.wifi_error, Toast.LENGTH_SHORT).show();
         }
     }
+
+    private boolean mayDisableTethering(boolean isChecked) {
+        final int wifiApState = mWifiManager.getWifiApState();
+        return isChecked && ((wifiApState == WifiManager.WIFI_AP_STATE_ENABLING) ||
+            (wifiApState == WifiManager.WIFI_AP_STATE_ENABLED));
+    }
 }
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 08e27ec..8eb1759 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -28,7 +28,6 @@
 import android.content.pm.PackageManager;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.res.Resources;
-import android.graphics.drawable.Drawable;
 import android.net.ConnectivityManager;
 import android.net.NetworkInfo;
 import android.net.NetworkInfo.State;
@@ -39,15 +38,12 @@
 import android.os.Bundle;
 import android.os.HandlerThread;
 import android.os.Process;
-import android.os.RemoteException;
-import android.os.UserHandle;
 import android.provider.Settings;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceViewHolder;
 import android.text.Spannable;
 import android.text.style.TextAppearanceSpan;
 import android.util.Log;
-import android.util.TypedValue;
 import android.view.ContextMenu;
 import android.view.ContextMenu.ContextMenuInfo;
 import android.view.Menu;
@@ -58,7 +54,6 @@
 import android.widget.TextView;
 import android.widget.TextView.BufferType;
 import android.widget.Toast;
-
 import com.android.internal.logging.MetricsLogger;
 import com.android.internal.logging.MetricsProto.MetricsEvent;
 import com.android.settings.LinkifyUtils;
@@ -999,9 +994,7 @@
                 filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
                 filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
                 filter.addAction(WifiManager.RSSI_CHANGED_ACTION);
-                mContext.registerReceiver(this, filter);
-            } else {
-                mContext.unregisterReceiver(this);
+                mSummaryLoader.registerReceiver(this, filter);
             }
         }