Add IME action to Enter editor action

At the moment apps need to support pressing "Enter" to search
differently if they want to support physical keyboard, as
currently no editor action is sent from it. This is a proposal
that will resolve that issue by sending that information.

Bug: 269672396
Test: built, flashed on device, confirmed pressing enter starts
the search

Change-Id: I1694303540295603097db2fd4e4206f1ca71cec0
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 5de8079..fd8f549 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -1117,7 +1117,9 @@
          * @param actionId Identifier of the action.  This will be either the
          * identifier you supplied, or {@link EditorInfo#IME_NULL
          * EditorInfo.IME_NULL} if being called due to the enter key
-         * being pressed.
+         * being pressed. Starting from Android 14, the action identifier will
+         * also be included when triggered by an enter key if the input is
+         * constrained to a single line.
          * @param event If triggered by an enter key, this is the event;
          * otherwise, this is null.
          * @return Return true if you have consumed the action, else false.
@@ -9272,7 +9274,9 @@
                         // chance to consume the event.
                         if (mEditor.mInputContentType.onEditorActionListener != null
                                 && mEditor.mInputContentType.onEditorActionListener.onEditorAction(
-                                        this, EditorInfo.IME_NULL, event)) {
+                                        this,
+                                        getActionIdForEnterEvent(),
+                                        event)) {
                             mEditor.mInputContentType.enterDown = true;
                             // We are consuming the enter key for them.
                             return KEY_EVENT_HANDLED;
@@ -9495,7 +9499,7 @@
                             && mEditor.mInputContentType.enterDown) {
                         mEditor.mInputContentType.enterDown = false;
                         if (mEditor.mInputContentType.onEditorActionListener.onEditorAction(
-                                this, EditorInfo.IME_NULL, event)) {
+                                this, getActionIdForEnterEvent(), event)) {
                             return true;
                         }
                     }
@@ -9559,6 +9563,15 @@
         return super.onKeyUp(keyCode, event);
     }
 
+    private int getActionIdForEnterEvent() {
+        // If it's not single line, no action
+        if (!isSingleLine()) {
+            return EditorInfo.IME_NULL;
+        }
+        // Return the action that was specified for Enter
+        return getImeOptions() & EditorInfo.IME_MASK_ACTION;
+    }
+
     @Override
     public boolean onCheckIsTextEditor() {
         return mEditor != null && mEditor.mInputType != EditorInfo.TYPE_NULL;