diff --git a/core/api/current.txt b/core/api/current.txt index b5b71463afbb4..785bf44258b5e 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -53178,6 +53178,7 @@ package android.view.inputmethod { method public boolean isActive(); method public boolean isFullscreenMode(); method public boolean isInputMethodSuppressingSpellChecker(); + method public boolean isStylusHandwritingAvailable(); method @Deprecated public boolean isWatchingCursor(android.view.View); method public void restartInput(android.view.View); method public void sendAppPrivateCommand(android.view.View, String, android.os.Bundle); diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index 2428709220a8a..c99466c6ee700 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -1402,6 +1402,20 @@ public final class InputMethodManager { } } + /** + * Returns {@code true} if currently selected IME supports Stylus handwriting. + * If the method returns {@code false}, {@link #startStylusHandwriting(View)} shouldn't be + * called and Stylus touch should continue as normal touch input. + * @see #startStylusHandwriting(View) + */ + public boolean isStylusHandwritingAvailable() { + try { + return mService.isStylusHandwritingAvailable(); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + /** * Returns the list of installed input methods for the specified user. * @@ -1992,10 +2006,13 @@ public final class InputMethodManager { * pointers will be {@code android.view.MotionEvent#FLAG_CANCELED} cancelled. * * If Stylus handwriting mode is not supported or cannot be fulfilled for any reason by IME, - * request will be ignored and Stylus touch will continue as normal touch input. + * request will be ignored and Stylus touch will continue as normal touch input. Ideally, + * {@link #isStylusHandwritingAvailable()} should be called first to determine if stylus + * handwriting is supported by IME. * * @param view the View for which stylus handwriting is requested. It and * {@link View#hasWindowFocus its window} must be {@link View#hasFocus focused}. + * @see #isStylusHandwritingAvailable() */ public void startStylusHandwriting(@NonNull View view) { // Re-dispatch if there is a context mismatch. diff --git a/core/java/com/android/internal/view/IInputMethodManager.aidl b/core/java/com/android/internal/view/IInputMethodManager.aidl index d7bb2cb10b8c4..05c7183f564f3 100644 --- a/core/java/com/android/internal/view/IInputMethodManager.aidl +++ b/core/java/com/android/internal/view/IInputMethodManager.aidl @@ -89,4 +89,6 @@ interface IInputMethodManager { /** Start Stylus handwriting session **/ void startStylusHandwriting(in IInputMethodClient client); + /** Returns {@code true} if currently selected IME supports Stylus handwriting. */ + boolean isStylusHandwritingAvailable(); } diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerInternal.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerInternal.java index 57d89dae588e5..08420a1822e04 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerInternal.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerInternal.java @@ -74,6 +74,11 @@ public abstract class InputMethodManagerInternal { */ public abstract List getEnabledInputMethodListAsUser(@UserIdInt int userId); + /** + * Returns {@code true} if currently selected IME supports Stylus handwriting. + */ + public abstract boolean isStylusHandwritingAvailable(); + /** * Called by the Autofill Frameworks to request an {@link InlineSuggestionsRequest} from * the input method. @@ -256,6 +261,11 @@ public abstract class InputMethodManagerInternal { @Override public void maybeFinishStylusHandwriting() { } + + @Override + public boolean isStylusHandwritingAvailable() { + return false; + } }; /** diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index dd9b6e9e5de7e..d1998a16d368b 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -2133,6 +2133,13 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub } } + @Override + public boolean isStylusHandwritingAvailable() { + synchronized (ImfLock.class) { + return mBindingController.supportsStylusHandwriting(); + } + } + @GuardedBy("ImfLock.class") private List getInputMethodListLocked(@UserIdInt int userId, @DirectBootAwareness int directBootAwareness) { @@ -5787,6 +5794,11 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub mHandler.removeMessages(MSG_FINISH_HANDWRITING); mHandler.obtainMessage(MSG_FINISH_HANDWRITING).sendToTarget(); } + + @Override + public boolean isStylusHandwritingAvailable() { + return InputMethodManagerService.this.isStylusHandwritingAvailable(); + } } @BinderThread