Fix "Select All" in extracted mode

Stop calling onExtractTextContextMenuItem if "Select All"
is selected (the action does not modify text thus does
not need batch editing). Editor#finishBatchEdit reports
that text changed which in turn can stop the action mode
and the selection after it was started by onPreDraw.

Bug: 22059417
Change-Id: I5354cbe4bae374e0d5f3de39616336170ee33b92
diff --git a/core/java/android/inputmethodservice/ExtractEditText.java b/core/java/android/inputmethodservice/ExtractEditText.java
index 24596c3..b039fc7 100644
--- a/core/java/android/inputmethodservice/ExtractEditText.java
+++ b/core/java/android/inputmethodservice/ExtractEditText.java
@@ -29,7 +29,7 @@
 public class ExtractEditText extends EditText {
     private InputMethodService mIME;
     private int mSettingExtractedText;
-    
+
     public ExtractEditText(Context context) {
         super(context, null);
     }
@@ -45,11 +45,11 @@
     public ExtractEditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
         super(context, attrs, defStyleAttr, defStyleRes);
     }
-    
+
     void setIME(InputMethodService ime) {
         mIME = ime;
     }
-    
+
     /**
      * Start making changes that will not be reported to the client.  That
      * is, {@link #onSelectionChanged(int, int)} will not result in sending
@@ -58,7 +58,7 @@
     public void startInternalChanges() {
         mSettingExtractedText += 1;
     }
-    
+
     /**
      * Finish making changes that will not be reported to the client.  That
      * is, {@link #onSelectionChanged(int, int)} will not result in sending
@@ -67,7 +67,7 @@
     public void finishInternalChanges() {
         mSettingExtractedText -= 1;
     }
-    
+
     /**
      * Implement just to keep track of when we are setting text from the
      * client (vs. seeing changes in ourself from the user).
@@ -80,7 +80,7 @@
             mSettingExtractedText--;
         }
     }
-    
+
     /**
      * Report to the underlying text editor about selection changes.
      */
@@ -89,7 +89,7 @@
             mIME.onExtractedSelectionChanged(selStart, selEnd);
         }
     }
-    
+
     /**
      * Redirect clicks to the IME for handling there.  First allows any
      * on click handler to run, though.
@@ -101,9 +101,10 @@
         }
         return false;
     }
-    
+
     @Override public boolean onTextContextMenuItem(int id) {
-        if (mIME != null && mIME.onExtractTextContextMenuItem(id)) {
+        // Select all shouldn't be handled by the original edit text, but by the extracted one.
+        if (id != android.R.id.selectAll && mIME != null && mIME.onExtractTextContextMenuItem(id)) {
             // Mode was started on Extracted, needs to be stopped here.
             // Cut will change the text, which stops selection mode.
             if (id == android.R.id.copy || id == android.R.id.paste) stopTextActionMode();
@@ -111,7 +112,7 @@
         }
         return super.onTextContextMenuItem(id);
     }
-    
+
     /**
      * We are always considered to be an input method target.
      */
@@ -119,14 +120,14 @@
     public boolean isInputMethodTarget() {
         return true;
     }
-    
+
     /**
      * Return true if the edit text is currently showing a scroll bar.
      */
     public boolean hasVerticalScrollBar() {
         return computeVerticalScrollRange() > computeVerticalScrollExtent();
     }
-    
+
     /**
      * Pretend like the window this view is in always has focus, so its
      * highlight and cursor will be displayed.