Merge "Check getShowSoftInputOnFocus() for stylus input" into main
diff --git a/core/java/android/text/flags/flags.aconfig b/core/java/android/text/flags/flags.aconfig
index 3599332..ec5b488 100644
--- a/core/java/android/text/flags/flags.aconfig
+++ b/core/java/android/text/flags/flags.aconfig
@@ -178,3 +178,13 @@
     purpose: PURPOSE_BUGFIX
   }
 }
+
+flag {
+  name: "handwriting_unsupported_show_soft_input_fix"
+  namespace: "text"
+  description: "Don't show soft keyboard on stylus input if text field doesn't support handwriting and getShowSoftInputOnFocus() returns false."
+  bug: "363180475"
+  metadata {
+    purpose: PURPOSE_BUGFIX
+  }
+}
diff --git a/core/java/android/view/HandwritingInitiator.java b/core/java/android/view/HandwritingInitiator.java
index f132963..c217999 100644
--- a/core/java/android/view/HandwritingInitiator.java
+++ b/core/java/android/view/HandwritingInitiator.java
@@ -19,6 +19,7 @@
 import static com.android.text.flags.Flags.handwritingCursorPosition;
 import static com.android.text.flags.Flags.handwritingTrackDisabled;
 import static com.android.text.flags.Flags.handwritingUnsupportedMessage;
+import static com.android.text.flags.Flags.handwritingUnsupportedShowSoftInputFix;
 
 import android.annotation.FlaggedApi;
 import android.annotation.NonNull;
@@ -241,7 +242,11 @@
                             if (!candidateView.hasFocus()) {
                                 requestFocusWithoutReveal(candidateView);
                             }
-                            mImm.showSoftInput(candidateView, 0);
+                            if (!handwritingUnsupportedShowSoftInputFix()
+                                    || (candidateView instanceof TextView tv
+                                            && tv.getShowSoftInputOnFocus())) {
+                                mImm.showSoftInput(candidateView, 0);
+                            }
                             mState.mHandled = true;
                             mState.mShouldInitHandwriting = false;
                             motionEvent.setAction((motionEvent.getAction()