Merge "Make AwesomePlayer's reset process more verbose to track down ANRs."
diff --git a/api/current.xml b/api/current.xml
index 3357d1e..af6d2cd 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -9084,6 +9084,17 @@
  visibility="public"
 >
 </field>
+<field name="state_multiline"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16843611"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="state_pressed"
  type="int"
  transient="false"
@@ -252110,7 +252121,7 @@
  deprecated="not deprecated"
  visibility="public"
 >
-<parameter name="arg0" type="T">
+<parameter name="t" type="T">
 </parameter>
 </method>
 </interface>
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index a3bfe8b..ae4b193 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -310,8 +310,6 @@
     int mTextSelectHandleRes;
     int mTextEditPasteWindowLayout;
     int mTextEditNoPasteWindowLayout;
-    Drawable mEditTextMultilineBackground;
-    Drawable mEditTextSingleLineBackground;
 
     Drawable mSelectHandleLeft;
     Drawable mSelectHandleRight;
@@ -321,6 +319,8 @@
     private Callback mCustomSelectionActionModeCallback;
 
     private final int mSquaredTouchSlopDistance;
+    // Set when this TextView gained focus with some text selected. Will start selection mode.
+    private boolean mCreatedWithASelection = false;
 
     /*
      * Kick-start the font cache for the zygote process (to pay the cost of
@@ -763,10 +763,6 @@
                 mTextEditNoPasteWindowLayout = a.getResourceId(attr, 0);
                 break;
 
-            case com.android.internal.R.styleable.TextView_multilineBackground:
-                mEditTextMultilineBackground = a.getDrawable(attr);
-                break;
-
             case com.android.internal.R.styleable.TextView_textIsSelectable:
                 mTextIsSelectable = a.getBoolean(attr, false);
                 break;
@@ -774,7 +770,6 @@
         }
         a.recycle();
 
-        mEditTextSingleLineBackground = getBackground();
         BufferType bufferType = BufferType.EDITABLE;
 
         final int variation =
@@ -3887,10 +3882,15 @@
         // This has to be checked here since:
         // - onFocusChanged cannot start it when focus is given to a view with selected text (after
         //   a screen rotation) since layout is not yet initialized at that point.
-        // - ExtractEditText does not call onFocus when it is displayed. Fixing this issue would
-        //   allow to test for hasSelection in onFocusChanged, which would trigger a
-        //   startTextSelectionMode here. TODO
-        if (this instanceof ExtractEditText && hasSelection() && canSelectText()) {
+        if (mCreatedWithASelection) {
+            startSelectionActionMode();
+            mCreatedWithASelection = false;
+        }
+
+        // Phone specific code (there is no ExtractEditText on tablets).
+        // ExtractEditText does not call onFocus when it is displayed, and mHasSelectionOnFocus can
+        // not be set. Do the test here instead.
+        if (this instanceof ExtractEditText && hasSelection()) {
             startSelectionActionMode();
         }
 
@@ -4132,7 +4132,12 @@
 
     @Override
     protected int[] onCreateDrawableState(int extraSpace) {
-        final int[] drawableState = super.onCreateDrawableState(extraSpace);
+        final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
+
+        if (!mSingleLine) {
+            mergeDrawableStates(drawableState, MULTILINE_STATE_SET);
+        }
+
         if (mTextIsSelectable) {
             // Disable pressed state, which was introduced when TextView was made clickable.
             // Prevents text color change.
@@ -4148,6 +4153,7 @@
                 }
             }
         }
+
         return drawableState;
     }
 
@@ -6378,7 +6384,7 @@
             if (applyTransformation) {
                 setTransformationMethod(SingleLineTransformationMethod.getInstance());
             }
-            setBackgroundDrawable(mEditTextSingleLineBackground);
+            // TODO setState
         } else {
             if (changeMaxLines) {
                 setMaxLines(Integer.MAX_VALUE);
@@ -6387,13 +6393,10 @@
             if (applyTransformation) {
                 setTransformationMethod(null);
             }
-            // mEditTextMultilineBackground is defined and used only in EditText
-            if (mEditTextMultilineBackground != null) {
-                setBackgroundDrawable(mEditTextMultilineBackground);
-            }
+            // TODO setState
         }
     }
-    
+
     /**
      * Causes words in the text that are longer than the view is wide
      * to be ellipsized instead of broken in the middle.  You may also
@@ -7008,6 +7011,12 @@
             int selStart = getSelectionStart();
             int selEnd = getSelectionEnd();
 
+            // SelectAllOnFocus fields are highlighted and not selected. Do not start text selection
+            // mode for these, unless there was a specific selection already started.
+            final boolean isFocusHighlighted = mSelectAllOnFocus && selStart == 0 &&
+                    selEnd == mText.length();
+            mCreatedWithASelection = mFrozenWithFocus && hasSelection() && !isFocusHighlighted;
+
             if (!mFrozenWithFocus || (selStart < 0 || selEnd < 0)) {
                 // If a tap was used to give focus to that view, move cursor at tap position.
                 // Has to be done before onTakeFocus, which can be overloaded.
@@ -8179,10 +8188,15 @@
             return false;
         }
 
-        selectCurrentWord();
+        if (!hasSelection()) {
+            // If selection mode is started after a device rotation, there is already a selection.
+            selectCurrentWord();
+        }
+
         final InputMethodManager imm = (InputMethodManager)
                 getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
         imm.showSoftInput(this, 0, null);
+
         ActionMode.Callback actionModeCallback = new SelectionActionModeCallback();
         mSelectionActionMode = startActionMode(actionModeCallback);
         return mSelectionActionMode != null;
@@ -9480,4 +9494,6 @@
     private static long sLastCutOrCopyTime;
     // Used to highlight a word when it is corrected by the IME
     private CorrectionHighlighter mCorrectionHighlighter;
+    // New state used to change background based on whether this TextView is multiline.
+    private static final int[] MULTILINE_STATE_SET = { R.attr.state_multiline };
 }
diff --git a/core/res/res/drawable/edit_text_holo_dark.xml b/core/res/res/drawable/edit_text_holo_dark.xml
index 29a5150c..d00747f 100644
--- a/core/res/res/drawable/edit_text_holo_dark.xml
+++ b/core/res/res/drawable/edit_text_holo_dark.xml
@@ -15,10 +15,19 @@
 -->
 
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item android:state_multiline="true" android:state_window_focused="false" android:state_enabled="true"  android:drawable="@drawable/textfield_multiline_default_holo_dark" />
+    <item android:state_multiline="true" android:state_window_focused="false" android:state_enabled="false" android:drawable="@drawable/textfield_multiline_disabled_holo_dark" />
+    <item android:state_multiline="true" android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/textfield_multiline_activated_holo_dark" />
+    <item android:state_multiline="true" android:state_enabled="true" android:state_activated="true" android:drawable="@drawable/textfield_multiline_focused_holo_dark" />
+    <item android:state_multiline="true" android:state_enabled="true" android:drawable="@drawable/textfield_multiline_default_holo_dark" />
+    <item android:state_multiline="true" android:state_focused="true" android:drawable="@drawable/textfield_multiline_disabled_focused_holo_dark" />
+    <item android:state_multiline="true" android:drawable="@drawable/textfield_multiline_disabled_holo_dark" />
+
     <item android:state_window_focused="false" android:state_enabled="true" android:drawable="@drawable/textfield_default_holo_dark" />
     <item android:state_window_focused="false" android:state_enabled="false" android:drawable="@drawable/textfield_disabled_holo_dark" />
     <item android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/textfield_activated_holo_dark" />
-    <item android:state_enabled="true" android:state_activated="true" android:drawable="@drawable/textfield_focused_holo_dark" />
+    <iten android:state_enabled="true" android:state_activated="true" android:drawable="@drawable/textfield_focused_holo_dark" />
     <item android:state_enabled="true" android:drawable="@drawable/textfield_default_holo_dark" />
     <item android:state_focused="true" android:drawable="@drawable/textfield_disabled_focused_holo_dark" />
     <item android:drawable="@drawable/textfield_disabled_holo_dark" />
diff --git a/core/res/res/drawable/edit_text_holo_light.xml b/core/res/res/drawable/edit_text_holo_light.xml
index 5426916..5bdcbd9 100644
--- a/core/res/res/drawable/edit_text_holo_light.xml
+++ b/core/res/res/drawable/edit_text_holo_light.xml
@@ -15,6 +15,15 @@
 -->
 
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item android:state_multiline="true" android:state_window_focused="false" android:state_enabled="true"  android:drawable="@drawable/textfield_multiline_default_holo_light" />
+    <item android:state_multiline="true" android:state_window_focused="false" android:state_enabled="false" android:drawable="@drawable/textfield_multiline_disabled_holo_light" />
+    <item android:state_multiline="true" android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/textfield_multiline_activated_holo_light" />
+    <item android:state_multiline="true" android:state_enabled="true" android:state_activated="true" android:drawable="@drawable/textfield_multiline_focused_holo_light" />
+    <item android:state_multiline="true" android:state_enabled="true" android:drawable="@drawable/textfield_multiline_default_holo_light" />
+    <item android:state_multiline="true" android:state_focused="true" android:drawable="@drawable/textfield_multiline_disabled_focused_holo_light" />
+    <item android:state_multiline="true" android:drawable="@drawable/textfield_multiline_disabled_holo_light" />
+
     <item android:state_window_focused="false" android:state_enabled="true" android:drawable="@drawable/textfield_default_holo_light" />
     <item android:state_window_focused="false" android:state_enabled="false" android:drawable="@drawable/textfield_disabled_holo_light" />
     <item android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/textfield_activated_holo_light" />
diff --git a/core/res/res/drawable/edit_text_multiline_holo_dark.xml b/core/res/res/drawable/edit_text_multiline_holo_dark.xml
deleted file mode 100644
index d20ea19..0000000
--- a/core/res/res/drawable/edit_text_multiline_holo_dark.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2010 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-  
-          http://www.apache.org/licenses/LICENSE-2.0
-  
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:state_window_focused="false" android:state_enabled="true"  android:drawable="@drawable/textfield_multiline_default_holo_dark" />
-    <item android:state_window_focused="false" android:state_enabled="false" android:drawable="@drawable/textfield_multiline_disabled_holo_dark" />
-    <item android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/textfield_multiline_activated_holo_dark" />
-    <item android:state_enabled="true" android:state_activated="true" android:drawable="@drawable/textfield_multiline_focused_holo_dark" />
-    <item android:state_enabled="true" android:drawable="@drawable/textfield_multiline_default_holo_dark" />
-    <item android:state_focused="true" android:drawable="@drawable/textfield_multiline_disabled_focused_holo_dark" />
-    <item android:drawable="@drawable/textfield_multiline_disabled_holo_dark" />
-</selector>
diff --git a/core/res/res/drawable/edit_text_multiline_holo_light.xml b/core/res/res/drawable/edit_text_multiline_holo_light.xml
deleted file mode 100644
index 41a4eab..0000000
--- a/core/res/res/drawable/edit_text_multiline_holo_light.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2010 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-  
-          http://www.apache.org/licenses/LICENSE-2.0
-  
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:state_window_focused="false" android:state_enabled="true"  android:drawable="@drawable/textfield_multiline_default_holo_light" />
-    <item android:state_window_focused="false" android:state_enabled="false" android:drawable="@drawable/textfield_multiline_disabled_holo_light" />
-    <item android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/textfield_multiline_activated_holo_light" />
-    <item android:state_enabled="true" android:state_activated="true" android:drawable="@drawable/textfield_multiline_focused_holo_light" />
-    <item android:state_enabled="true" android:drawable="@drawable/textfield_multiline_default_holo_light" />
-    <item android:state_focused="true" android:drawable="@drawable/textfield_multiline_disabled_focused_holo_light" />
-    <item android:drawable="@drawable/textfield_multiline_disabled_holo_light" />
-</selector>
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index f6899ad..588b33b 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -141,8 +141,6 @@
         <attr name="editTextColor" format="reference|color" />
         <!-- EditText background drawable. -->
         <attr name="editTextBackground" format="reference" />
-        <!-- EditText background drawable for multiline EditText. -->
-        <attr name="editTextMultilineBackground" format="reference" />
 
         <!-- A styled string, specifying the style to be used for showing
              inline candidate text when composing with an input method.  The
@@ -2685,8 +2683,6 @@
         <attr name="textEditNoPasteWindowLayout" />
         <!-- Indicates that the content of a non-editable text can be selected. -->
         <attr name="textIsSelectable" />
-        <!--  A specific background drawable used by multi-line EditText only. -->
-        <attr name="multilineBackground" format="reference"/>
     </declare-styleable>
     <!-- An <code>input-extras</code> is a container for extra data to supply to
          an input method.  Contains
@@ -3696,6 +3692,10 @@
         <!-- State identifier indicating the popup will be above the anchor. -->
         <attr name="state_above_anchor" format="boolean" />
     </declare-styleable>
+    <declare-styleable name="TextViewMultiLineBackgroundState">
+        <!-- State identifier indicating a TextView has a multi-line layout. -->
+        <attr name="state_multiline" format="boolean" />
+    </declare-styleable>
 
     <!-- ***************************************************************** -->
     <!-- Support for Searchable activities. -->
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 9f1b9a1..76a9d3b 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1425,6 +1425,7 @@
   <public type="attr" name="solidColor" />
   <public type="attr" name="spinnersShown" />
   <public type="attr" name="calendarViewShown" />
+  <public type="attr" name="state_multiline" />
 
   <public type="anim" name="animator_fade_in" />
   <public type="anim" name="animator_fade_out" />
diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml
index f6c88e7..8a86676 100644
--- a/core/res/res/values/styles.xml
+++ b/core/res/res/values/styles.xml
@@ -444,7 +444,6 @@
         <item name="android:focusableInTouchMode">true</item>
         <item name="android:clickable">true</item>
         <item name="android:background">?android:attr/editTextBackground</item>
-        <item name="android:multilineBackground">?android:attr/editTextMultilineBackground</item>
         <item name="android:textAppearance">?android:attr/textAppearanceMediumInverse</item>
         <item name="android:textColor">?android:attr/editTextColor</item>
         <item name="android:gravity">center_vertical</item>
diff --git a/core/res/res/values/themes.xml b/core/res/res/values/themes.xml
index 43686bc..439d551 100644
--- a/core/res/res/values/themes.xml
+++ b/core/res/res/values/themes.xml
@@ -72,7 +72,6 @@
         
         <item name="editTextColor">?android:attr/textColorPrimaryInverse</item>
         <item name="editTextBackground">@android:drawable/edit_text</item>
-        <item name="editTextMultilineBackground">@android:drawable/edit_text</item>
         
         <item name="candidatesTextStyleSpans">@android:string/candidates_style</item>
         
@@ -736,7 +735,6 @@
         
         <item name="editTextColor">?android:attr/textColorPrimary</item>
         <item name="editTextBackground">@android:drawable/edit_text_holo_dark</item>
-        <item name="editTextMultilineBackground">@android:drawable/edit_text_multiline_holo_dark</item>
         
         <item name="candidatesTextStyleSpans">@android:string/candidates_style</item>
         
@@ -995,7 +993,6 @@
 
         <item name="editTextColor">?android:attr/textColorPrimary</item>
         <item name="editTextBackground">@android:drawable/edit_text_holo_light</item>
-        <item name="editTextMultilineBackground">@android:drawable/edit_text_multiline_holo_light</item>
 
         <item name="candidatesTextStyleSpans">@android:string/candidates_style</item>