Merge "Fix issue #16013164: Externally Reported Moderate:"
diff --git a/core/res/res/anim/button_state_list_anim_material.xml b/core/res/res/anim/button_state_list_anim_material.xml
index 01989a4..9a61548 100644
--- a/core/res/res/anim/button_state_list_anim_material.xml
+++ b/core/res/res/anim/button_state_list_anim_material.xml
@@ -18,16 +18,37 @@
         <set>
             <objectAnimator android:propertyName="translationZ"
                             android:duration="@integer/button_pressed_animation_duration"
-                            android:valueTo="@dimen/button_pressed_z"
+                            android:valueTo="@dimen/button_pressed_z_material"
+                            android:valueType="floatType"/>
+            <objectAnimator android:propertyName="elevation"
+                            android:duration="0"
+                            android:valueTo="@dimen/button_elevation_material"
                             android:valueType="floatType"/>
         </set>
     </item>
     <!-- base state -->
-    <item>
+    <item android:state_enabled="true">
         <set>
             <objectAnimator android:propertyName="translationZ"
                             android:duration="@integer/button_pressed_animation_duration"
                             android:valueTo="0"
+                            android:startDelay="@integer/button_pressed_animation_delay"
+                            android:valueType="floatType"/>
+            <objectAnimator android:propertyName="elevation"
+                            android:duration="0"
+                            android:valueTo="@dimen/button_elevation_material"
+                            android:valueType="floatType" />
+        </set>
+    </item>
+    <item>
+        <set>
+            <objectAnimator android:propertyName="translationZ"
+                            android:duration="0"
+                            android:valueTo="0"
+                            android:valueType="floatType"/>
+            <objectAnimator android:propertyName="elevation"
+                            android:duration="0"
+                            android:valueTo="0"
                             android:valueType="floatType"/>
         </set>
     </item>
diff --git a/core/res/res/drawable-hdpi/btn_mtrl_alpha.9.png b/core/res/res/drawable-hdpi/btn_mtrl_alpha.9.png
deleted file mode 100644
index 171688f..0000000
--- a/core/res/res/drawable-hdpi/btn_mtrl_alpha.9.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable-hdpi/btn_toggle_mtrl_alpha.9.png b/core/res/res/drawable-hdpi/btn_toggle_mtrl_alpha.9.png
deleted file mode 100644
index 879d9c2..0000000
--- a/core/res/res/drawable-hdpi/btn_toggle_mtrl_alpha.9.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable-ldpi/btn_mtrl_alpha.9.png b/core/res/res/drawable-ldpi/btn_mtrl_alpha.9.png
deleted file mode 100644
index 1b648db..0000000
--- a/core/res/res/drawable-ldpi/btn_mtrl_alpha.9.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable-mdpi/btn_mtrl_alpha.9.png b/core/res/res/drawable-mdpi/btn_mtrl_alpha.9.png
deleted file mode 100644
index fc51595..0000000
--- a/core/res/res/drawable-mdpi/btn_mtrl_alpha.9.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable-mdpi/btn_toggle_mtrl_alpha.9.png b/core/res/res/drawable-mdpi/btn_toggle_mtrl_alpha.9.png
deleted file mode 100644
index dca86ea..0000000
--- a/core/res/res/drawable-mdpi/btn_toggle_mtrl_alpha.9.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/btn_mtrl_alpha.9.png b/core/res/res/drawable-xhdpi/btn_mtrl_alpha.9.png
deleted file mode 100644
index 30d732a..0000000
--- a/core/res/res/drawable-xhdpi/btn_mtrl_alpha.9.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/btn_toggle_mtrl_alpha.9.png b/core/res/res/drawable-xhdpi/btn_toggle_mtrl_alpha.9.png
deleted file mode 100644
index b135338..0000000
--- a/core/res/res/drawable-xhdpi/btn_toggle_mtrl_alpha.9.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable-xxhdpi/btn_mtrl_alpha.9.png b/core/res/res/drawable-xxhdpi/btn_mtrl_alpha.9.png
deleted file mode 100644
index 7d29d18..0000000
--- a/core/res/res/drawable-xxhdpi/btn_mtrl_alpha.9.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable-xxhdpi/btn_toggle_mtrl_alpha.9.png b/core/res/res/drawable-xxhdpi/btn_toggle_mtrl_alpha.9.png
deleted file mode 100644
index f235aed..0000000
--- a/core/res/res/drawable-xxhdpi/btn_toggle_mtrl_alpha.9.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable-xxxhdpi/btn_mtrl_alpha.9.png b/core/res/res/drawable-xxxhdpi/btn_mtrl_alpha.9.png
deleted file mode 100644
index 01eeefe..0000000
--- a/core/res/res/drawable-xxxhdpi/btn_mtrl_alpha.9.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable-xxxhdpi/btn_toggle_mtrl_alpha.9.png b/core/res/res/drawable-xxxhdpi/btn_toggle_mtrl_alpha.9.png
deleted file mode 100755
index 7556167..0000000
--- a/core/res/res/drawable-xxxhdpi/btn_toggle_mtrl_alpha.9.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable/btn_borderless_material.xml b/core/res/res/drawable/btn_borderless_material.xml
index a459089..47cc455 100644
--- a/core/res/res/drawable/btn_borderless_material.xml
+++ b/core/res/res/drawable/btn_borderless_material.xml
@@ -14,8 +14,13 @@
      limitations under the License.
 -->
 
-<ripple xmlns:android="http://schemas.android.com/apk/res/android"
-    android:color="?attr/colorControlHighlight">
-    <item android:id="@id/mask"
-        android:drawable="@drawable/btn_mtrl_alpha" />
-</ripple>
+<inset xmlns:android="http://schemas.android.com/apk/res/android"
+       android:insetLeft="@dimen/control_inset_material"
+       android:insetTop="@dimen/control_inset_material"
+       android:insetBottom="@dimen/control_inset_material"
+       android:insetRight="@dimen/control_inset_material">
+    <ripple android:color="?attr/colorControlHighlight">
+        <item android:id="@id/mask"
+              android:drawable="@drawable/btn_default_mtrl_shape" />
+    </ripple>
+</inset>
diff --git a/core/res/res/drawable/btn_default_material.xml b/core/res/res/drawable/btn_default_material.xml
index 9cee3ab..b04d4fb 100644
--- a/core/res/res/drawable/btn_default_material.xml
+++ b/core/res/res/drawable/btn_default_material.xml
@@ -14,10 +14,12 @@
      limitations under the License.
 -->
 
-<ripple xmlns:android="http://schemas.android.com/apk/res/android"
-    android:color="?attr/colorControlHighlight">
-    <item>
-        <nine-patch android:src="@drawable/btn_mtrl_alpha"
-            android:tint="?attr/colorButtonNormal" />
-    </item>
-</ripple>
+<inset xmlns:android="http://schemas.android.com/apk/res/android"
+       android:insetLeft="@dimen/control_inset_material"
+       android:insetTop="@dimen/control_inset_material"
+       android:insetBottom="@dimen/control_inset_material"
+       android:insetRight="@dimen/control_inset_material">
+    <ripple android:color="?attr/colorControlHighlight">
+        <item android:drawable="@drawable/btn_default_mtrl_shape" />
+    </ripple>
+</inset>
diff --git a/core/res/res/drawable/btn_default_mtrl_shape.xml b/core/res/res/drawable/btn_default_mtrl_shape.xml
new file mode 100644
index 0000000..9235c76
--- /dev/null
+++ b/core/res/res/drawable/btn_default_mtrl_shape.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<!-- Used as the canonical button shape. -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+       android:shape="rectangle">
+    <corners android:radius="@dimen/control_corner_material" />
+    <solid android:color="?attr/colorButtonNormal" />
+    <padding android:top="@dimen/control_padding_material"
+             android:bottom="@dimen/control_padding_material"
+             android:left="@dimen/control_padding_material"
+             android:right="@dimen/control_padding_material" />
+</shape>
diff --git a/core/res/res/drawable/btn_toggle_material.xml b/core/res/res/drawable/btn_toggle_material.xml
index 73fe4d3..a9951e7 100644
--- a/core/res/res/drawable/btn_toggle_material.xml
+++ b/core/res/res/drawable/btn_toggle_material.xml
@@ -15,16 +15,24 @@
 -->
 
 <inset xmlns:android="http://schemas.android.com/apk/res/android"
-    android:insetLeft="4dp"
-    android:insetTop="4dp"
-    android:insetBottom="4dp"
-    android:insetRight="4dp">
+       android:insetLeft="@dimen/control_inset_material"
+       android:insetTop="@dimen/control_inset_material"
+       android:insetBottom="@dimen/control_inset_material"
+       android:insetRight="@dimen/control_inset_material">
     <layer-list android:paddingMode="stack">
         <item>
             <ripple android:color="?attr/colorControlHighlight">
                 <item>
-                    <nine-patch android:src="@drawable/btn_toggle_mtrl_alpha"
-                        android:tint="?attr/colorButtonNormal" />
+                    <shape xmlns:android="http://schemas.android.com/apk/res/android"
+                           android:shape="rectangle">
+                        <corners android:topLeftRadius="@dimen/control_corner_material"
+                                 android:topRightRadius="@dimen/control_corner_material"/>
+                        <solid android:color="?attr/colorButtonNormal" />
+                        <padding android:top="@dimen/control_padding_material"
+                                 android:bottom="@dimen/control_padding_material"
+                                 android:left="@dimen/control_padding_material"
+                                 android:right="@dimen/control_padding_material" />
+                    </shape>
                 </item>
             </ripple>
         </item>
diff --git a/core/res/res/values/arrays.xml b/core/res/res/values/arrays.xml
index b135d4e..11d6dca 100644
--- a/core/res/res/values/arrays.xml
+++ b/core/res/res/values/arrays.xml
@@ -335,7 +335,6 @@
        <item>@drawable/btn_check_to_on_mtrl_013</item>
        <item>@drawable/btn_check_to_on_mtrl_014</item>
        <item>@drawable/btn_check_to_on_mtrl_015</item>
-       <item>@drawable/btn_mtrl_alpha</item>
        <item>@drawable/btn_radio_to_off_mtrl_000</item>
        <item>@drawable/btn_radio_to_off_mtrl_001</item>
        <item>@drawable/btn_radio_to_off_mtrl_002</item>
@@ -402,7 +401,6 @@
        <item>@drawable/btn_switch_to_on_mtrl_013</item>
        <item>@drawable/btn_switch_to_on_mtrl_014</item>
        <item>@drawable/btn_toggle_indicator_mtrl_alpha</item>
-       <item>@drawable/btn_toggle_mtrl_alpha</item>
        <item>@drawable/expander_close_mtrl_alpha</item>
        <item>@drawable/expander_open_mtrl_alpha</item>
        <item>@drawable/fastscroll_thumb_mtrl_alpha</item>
diff --git a/core/res/res/values/dimens_material.xml b/core/res/res/values/dimens_material.xml
index 18e4574..bae8e8d 100644
--- a/core/res/res/values/dimens_material.xml
+++ b/core/res/res/values/dimens_material.xml
@@ -58,6 +58,14 @@
     <dimen name="floating_window_margin_right">16dp</dimen>
     <dimen name="floating_window_margin_bottom">32dp</dimen>
 
-    <!-- Amount of elevation for pressed button state -->
-    <dimen name="button_pressed_z">2dp</dimen>
+    <!-- Elevation when button is pressed -->
+    <dimen name="button_elevation_material">1dp</dimen>
+    <!-- Z translation to apply when button is pressed -->
+    <dimen name="button_pressed_z_material">2dp</dimen>
+    <!-- Default insets (outer padding) around controls -->
+    <dimen name="control_inset_material">4dp</dimen>
+    <!-- Default inner padding within controls -->
+    <dimen name="control_padding_material">4dp</dimen>
+    <!-- Default rounded corner for controls -->
+    <dimen name="control_corner_material">2dp</dimen>
 </resources>
diff --git a/core/res/res/values/integers.xml b/core/res/res/values/integers.xml
index e6748c4..fd61f73 100644
--- a/core/res/res/values/integers.xml
+++ b/core/res/res/values/integers.xml
@@ -20,4 +20,5 @@
     <integer name="kg_carousel_angle">75</integer>
     <integer name="kg_glowpad_rotation_offset">0</integer>
     <integer name="button_pressed_animation_duration">100</integer>
+    <integer name="button_pressed_animation_delay">100</integer>
 </resources>
diff --git a/core/res/res/values/styles_material.xml b/core/res/res/values/styles_material.xml
index 75f905c..b496ead 100644
--- a/core/res/res/values/styles_material.xml
+++ b/core/res/res/values/styles_material.xml
@@ -355,35 +355,35 @@
     <style name="TextAppearance.StatusBar.Material" />
 
     <style name="TextAppearance.StatusBar.Material.EventContent">
-        <item name="android:textColor">#90000000</item>
-        <item name="android:textSize">@dimen/notification_text_size</item>
+        <item name="textColor">#90000000</item>
+        <item name="textSize">@dimen/notification_text_size</item>
     </style>
 
     <style name="TextAppearance.StatusBar.Material.EventContent.Title">
-        <item name="android:textColor">#DD000000</item>
-        <item name="android:textSize">@dimen/notification_title_text_size</item>
+        <item name="textColor">#DD000000</item>
+        <item name="textSize">@dimen/notification_title_text_size</item>
     </style>
 
     <style name="TextAppearance.StatusBar.Material.EventContent.Line2">
-        <item name="android:textSize">@dimen/notification_subtext_size</item>
+        <item name="textSize">@dimen/notification_subtext_size</item>
     </style>
 
     <style name="TextAppearance.StatusBar.Material.EventContent.Info">
-        <item name="android:textSize">@dimen/notification_subtext_size</item>
+        <item name="textSize">@dimen/notification_subtext_size</item>
     </style>
 
     <style name="TextAppearance.StatusBar.Material.EventContent.Time">
-        <item name="android:textSize">@dimen/notification_subtext_size</item>
+        <item name="textSize">@dimen/notification_subtext_size</item>
     </style>
 
     <style name="TextAppearance.StatusBar.Material.EventContent.Emphasis">
-        <item name="android:textColor">#66000000</item>
+        <item name="textColor">#66000000</item>
     </style>
 
     <style name="Widget.StatusBar.Material.ProgressBar" parent="Widget.Material.Light.ProgressBar.Horizontal" />
 
     <style name="Widget.StatusBar.Material.ProgressBar.Media">
-        <item name="android:progressDrawable">@drawable/notification_material_media_progress</item>
+        <item name="progressDrawable">@drawable/notification_material_media_progress</item>
     </style>
 
     <!-- Widget Styles -->
@@ -399,9 +399,7 @@
         <item name="textColor">?attr/textColorPrimary</item>
         <item name="minHeight">48dip</item>
         <item name="minWidth">88dip</item>
-
-        <!-- TODO: Turn this back on when we support inset drawable outlines. -->
-        <!-- <item name="stateListAnimator">@anim/button_state_list_anim_material</item> -->
+        <item name="stateListAnimator">@anim/button_state_list_anim_material</item>
     </style>
 
     <!-- Small bordered ink button -->
@@ -430,7 +428,6 @@
         <item name="background">@drawable/btn_toggle_material</item>
         <item name="textOn">@string/capital_on</item>
         <item name="textOff">@string/capital_off</item>
-        <item name="minHeight">48dip</item>
     </style>
 
     <style name="Widget.Material.ButtonBar">
@@ -515,7 +512,7 @@
     <style name="Widget.Material.GestureOverlayView" parent="Widget.GestureOverlayView"/>
 
     <style name="Widget.Material.GridView" parent="Widget.GridView">
-        <item name="android:listSelector">?attr/selectableItemBackground</item>
+        <item name="listSelector">?attr/selectableItemBackground</item>
     </style>
 
     <style name="Widget.Material.CalendarView" parent="Widget.CalendarView">
@@ -687,11 +684,11 @@
     </style>
 
     <style name="Widget.Material.Toolbar" parent="Widget.Toolbar">
-        <item name="android:navigationButtonStyle">@android:style/Widget.Material.Toolbar.Button.Navigation</item>
+        <item name="navigationButtonStyle">@android:style/Widget.Material.Toolbar.Button.Navigation</item>
     </style>
 
     <style name="Widget.Material.Toolbar.Button.Navigation" parent="Widget.Toolbar.Button.Navigation">
-        <item name="android:background">?attr/selectableItemBackgroundBorderless</item>
+        <item name="background">?attr/selectableItemBackgroundBorderless</item>
     </style>
 
     <style name="Widget.Material.WebTextView" parent="Widget.WebTextView"/>
diff --git a/services/print/java/com/android/server/print/PrintManagerService.java b/services/print/java/com/android/server/print/PrintManagerService.java
index 39f228f..0575a5e9 100644
--- a/services/print/java/com/android/server/print/PrintManagerService.java
+++ b/services/print/java/com/android/server/print/PrintManagerService.java
@@ -119,7 +119,6 @@
                     final UserState userState;
                     synchronized (mLock) {
                         userState = getCurrentUserStateLocked();
-                        userState.updateIfNeededLocked();
                     }
                     // This is the first time we switch to this user after boot, so
                     // now is the time to remove obsolete print jobs since they
diff --git a/services/print/java/com/android/server/print/UserState.java b/services/print/java/com/android/server/print/UserState.java
index f647814..33edb11 100644
--- a/services/print/java/com/android/server/print/UserState.java
+++ b/services/print/java/com/android/server/print/UserState.java
@@ -126,7 +126,8 @@
         mSpooler = new RemotePrintSpooler(context, userId, this);
         mHandler = new UserStateHandler(context.getMainLooper());
         synchronized (mLock) {
-            enableSystemPrintServicesOnFirstBootLocked();
+            enableSystemPrintServicesLocked();
+            onConfigurationChangedLocked();
         }
     }
 
@@ -727,7 +728,7 @@
         }
     }
 
-    private void enableSystemPrintServicesOnFirstBootLocked() {
+    private void enableSystemPrintServicesLocked() {
         // Load enabled and installed services.
         readEnabledPrintServicesLocked();
         readInstalledPrintServicesLocked();
@@ -1159,6 +1160,7 @@
                 Log.w(LOG_TAG, "Not destroying - session destroyed");
                 return;
             }
+            mIsDestroyed = true;
             // Make sure printer tracking is stopped.
             final int printerCount = mStateTrackedPrinters.size();
             for (int i = 0; i < printerCount; i++) {