From d98f037ab26551e1a3aa1d4fa4e12394f7182f27 Mon Sep 17 00:00:00 2001 From: Taran Singh Date: Wed, 9 Mar 2022 20:22:20 +0000 Subject: [PATCH] Finish handwriting session for recents gesture Finish stylus handwriting session when user swipes to recent. Bug: 223748964 Test: Manually: 1. Open an app with editor 2. swipe on editor with stylus [or emulated stylus] 3. Observe ink trail drawn on screen 4. quickly sipe to recents, ink should go away. 5. repeat steps 1-3 for swipe to home Change-Id: Id750ff55cb447247c3eca75daf37cb5aeb1d0cfa --- .../IInputMethodWrapper.java | 11 ++++++++++ .../InputMethodService.java | 11 +++++++++- .../android/view/inputmethod/InputMethod.java | 8 +++++++ .../IInputMethodPrivilegedOperations.aidl | 2 +- .../InputMethodPrivilegedOperations.java | 4 ++-- .../android/internal/view/IInputMethod.aidl | 2 ++ .../inputmethod/IInputMethodInvoker.java | 9 ++++++++ .../InputMethodManagerInternal.java | 11 ++++++++++ .../InputMethodManagerService.java | 21 ++++++++++++++++--- .../server/wm/RecentsAnimationController.java | 1 + 10 files changed, 73 insertions(+), 7 deletions(-) diff --git a/core/java/android/inputmethodservice/IInputMethodWrapper.java b/core/java/android/inputmethodservice/IInputMethodWrapper.java index 02302a20fe38c..f9ed0e3db4994 100644 --- a/core/java/android/inputmethodservice/IInputMethodWrapper.java +++ b/core/java/android/inputmethodservice/IInputMethodWrapper.java @@ -81,6 +81,7 @@ class IInputMethodWrapper extends IInputMethod.Stub private static final int DO_CAN_START_STYLUS_HANDWRITING = 100; private static final int DO_START_STYLUS_HANDWRITING = 110; private static final int DO_INIT_INK_WINDOW = 120; + private static final int DO_FINISH_STYLUS_HANDWRITING = 130; final WeakReference mTarget; final Context mContext; @@ -263,6 +264,10 @@ class IInputMethodWrapper extends IInputMethod.Stub inputMethod.initInkWindow(); return; } + case DO_FINISH_STYLUS_HANDWRITING: { + inputMethod.finishStylusHandwriting(); + return; + } } Log.w(TAG, "Unhandled message code: " + msg.what); @@ -427,4 +432,10 @@ class IInputMethodWrapper extends IInputMethod.Stub public void initInkWindow() { mCaller.executeOrSendMessage(mCaller.obtainMessage(DO_INIT_INK_WINDOW)); } + + @BinderThread + @Override + public void finishStylusHandwriting() { + mCaller.executeOrSendMessage(mCaller.obtainMessage(DO_FINISH_STYLUS_HANDWRITING)); + } } diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index b46bb3257c860..4fdd534253283 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -992,6 +992,15 @@ public class InputMethodService extends AbstractInputMethodService { mOnPreparedStylusHwCalled = true; } + /** + * {@inheritDoc} + * @hide + */ + @Override + public void finishStylusHandwriting() { + InputMethodService.this.finishStylusHandwriting(); + } + /** * {@inheritDoc} */ @@ -2461,7 +2470,7 @@ public class InputMethodService extends AbstractInputMethodService { mHandwritingEventReceiver = null; mInkWindow.hide(false /* remove */); - mPrivOps.finishStylusHandwriting(requestId); + mPrivOps.resetStylusHandwriting(requestId); mOnPreparedStylusHwCalled = false; onFinishStylusHandwriting(); } diff --git a/core/java/android/view/inputmethod/InputMethod.java b/core/java/android/view/inputmethod/InputMethod.java index fd336a27bb675..6209b46997e86 100644 --- a/core/java/android/view/inputmethod/InputMethod.java +++ b/core/java/android/view/inputmethod/InputMethod.java @@ -414,4 +414,12 @@ public interface InputMethod { // intentionally empty } + /** + * Finish stylus handwriting session. + * @hide + */ + default void finishStylusHandwriting() { + // intentionally empty + } + } diff --git a/core/java/com/android/internal/inputmethod/IInputMethodPrivilegedOperations.aidl b/core/java/com/android/internal/inputmethod/IInputMethodPrivilegedOperations.aidl index b18c98b58516d..2ee47b64b1a58 100644 --- a/core/java/com/android/internal/inputmethod/IInputMethodPrivilegedOperations.aidl +++ b/core/java/com/android/internal/inputmethod/IInputMethodPrivilegedOperations.aidl @@ -43,5 +43,5 @@ oneway interface IInputMethodPrivilegedOperations { void notifyUserActionAsync(); void applyImeVisibilityAsync(IBinder showOrHideInputToken, boolean setVisible); void onStylusHandwritingReady(int requestId, int pid); - void finishStylusHandwriting(int requestId); + void resetStylusHandwriting(int requestId); } diff --git a/core/java/com/android/internal/inputmethod/InputMethodPrivilegedOperations.java b/core/java/com/android/internal/inputmethod/InputMethodPrivilegedOperations.java index e8a2d810d563d..15d7acfb6e0ac 100644 --- a/core/java/com/android/internal/inputmethod/InputMethodPrivilegedOperations.java +++ b/core/java/com/android/internal/inputmethod/InputMethodPrivilegedOperations.java @@ -416,13 +416,13 @@ public final class InputMethodPrivilegedOperations { * @param requestId */ @AnyThread - public void finishStylusHandwriting(int requestId) { + public void resetStylusHandwriting(int requestId) { final IInputMethodPrivilegedOperations ops = mOps.getAndWarnIfNull(); if (ops == null) { return; } try { - ops.finishStylusHandwriting(requestId); + ops.resetStylusHandwriting(requestId); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } diff --git a/core/java/com/android/internal/view/IInputMethod.aidl b/core/java/com/android/internal/view/IInputMethod.aidl index 273c5f1708123..40d89db6165ce 100644 --- a/core/java/com/android/internal/view/IInputMethod.aidl +++ b/core/java/com/android/internal/view/IInputMethod.aidl @@ -67,4 +67,6 @@ oneway interface IInputMethod { in List events); void initInkWindow(); + + void finishStylusHandwriting(); } diff --git a/services/core/java/com/android/server/inputmethod/IInputMethodInvoker.java b/services/core/java/com/android/server/inputmethod/IInputMethodInvoker.java index e6fd409023864..e62c5c13f04d3 100644 --- a/services/core/java/com/android/server/inputmethod/IInputMethodInvoker.java +++ b/services/core/java/com/android/server/inputmethod/IInputMethodInvoker.java @@ -245,4 +245,13 @@ final class IInputMethodInvoker { logRemoteException(e); } } + + @AnyThread + void finishStylusHandwriting() { + try { + mTarget.finishStylusHandwriting(); + } catch (RemoteException e) { + logRemoteException(e); + } + } } diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerInternal.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerInternal.java index 29dcdfaa1bba4..a2d3588f0e68c 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerInternal.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerInternal.java @@ -19,6 +19,7 @@ package com.android.server.inputmethod; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; +import android.inputmethodservice.InputMethodService; import android.os.IBinder; import android.view.inputmethod.InlineSuggestionsRequest; import android.view.inputmethod.InputMethodInfo; @@ -149,6 +150,12 @@ public abstract class InputMethodManagerInternal { */ public abstract void updateImeWindowStatus(boolean disableImeIcon); + /** + * Finish stylus handwriting by calling {@link InputMethodService#finishStylusHandwriting()} if + * there is an ongoing handwriting session. + */ + public abstract void maybeFinishStylusHandwriting(); + /** * Callback when the IInputMethodSession from the accessibility service with the specified * accessibilityConnectionId is created. @@ -239,6 +246,10 @@ public abstract class InputMethodManagerInternal { @Override public void unbindAccessibilityFromCurrentClient(int accessibilityConnectionId) { } + + @Override + public void maybeFinishStylusHandwriting() { + } }; /** diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 77dcbd3e92773..831c8093d6210 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -230,6 +230,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub private static final int MSG_RESET_HANDWRITING = 1090; private static final int MSG_START_HANDWRITING = 1100; + private static final int MSG_FINISH_HANDWRITING = 1110; private static final int MSG_UNBIND_CLIENT = 3000; private static final int MSG_UNBIND_ACCESSIBILITY_SERVICE = 3001; @@ -4430,7 +4431,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub } @BinderThread - private void finishStylusHandwriting(int requestId) { + private void resetStylusHandwriting(int requestId) { synchronized (ImfLock.class) { final OptionalInt curRequest = mHwController.getCurrentRequestId(); if (!curRequest.isPresent() || curRequest.getAsInt() != requestId) { @@ -4797,6 +4798,14 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub } } return true; + case MSG_FINISH_HANDWRITING: + synchronized (ImfLock.class) { + IInputMethodInvoker curMethod = getCurMethodLocked(); + if (curMethod != null && mHwController.getCurrentRequestId().isPresent()) { + curMethod.finishStylusHandwriting(); + } + } + return true; } return false; } @@ -5435,6 +5444,12 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub } } } + + @Override + public void maybeFinishStylusHandwriting() { + mHandler.removeMessages(MSG_FINISH_HANDWRITING); + mHandler.obtainMessage(MSG_FINISH_HANDWRITING).sendToTarget(); + } } @BinderThread @@ -6388,8 +6403,8 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub @BinderThread @Override - public void finishStylusHandwriting(int requestId) { - mImms.finishStylusHandwriting(requestId); + public void resetStylusHandwriting(int requestId) { + mImms.resetStylusHandwriting(requestId); } } } diff --git a/services/core/java/com/android/server/wm/RecentsAnimationController.java b/services/core/java/com/android/server/wm/RecentsAnimationController.java index a4d338c06708b..e21ae05c08276 100644 --- a/services/core/java/com/android/server/wm/RecentsAnimationController.java +++ b/services/core/java/com/android/server/wm/RecentsAnimationController.java @@ -281,6 +281,7 @@ public class RecentsAnimationController implements DeathRecipient { task.setCanAffectSystemUiFlags(behindSystemBars); } } + InputMethodManagerInternal.get().maybeFinishStylusHandwriting(); if (!behindSystemBars) { // Hiding IME if IME window is not attached to app. // Since some windowing mode is not proper to snapshot Task with IME window