diff options
| author | 2022-09-22 18:03:02 +0000 | |
|---|---|---|
| committer | 2022-09-22 18:03:02 +0000 | |
| commit | c87e17af06ece46a395a852849d139ade9b830c4 (patch) | |
| tree | 2c74e8cbadd3dc6240e288b50e6bc7550b2ea78a | |
| parent | e775b14da7300539ff08d1cd20a39a1b73b2257a (diff) | |
Handle non-initalized InkWindow
With [1] we changed the lifecycle of InkWindow to be short lived and
missed certain cases.
This also fixes CTS testStylusSession_fingerTriggersNavbarGestures
Bug: 243571274
Test: atest StylusHandwritingTest
[1]: Icd3eea91fe144cff7100d3ecf19191c064c0d196
Change-Id: I1593ff10a5520aadb5ed86a4a09f2405ee65c321
| -rw-r--r-- | core/java/android/inputmethodservice/InputMethodService.java | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index 7436601f5352..9ed55ffef11f 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -967,7 +967,7 @@ public class InputMethodService extends AbstractInputMethodService { Log.d(TAG, "Input should have started before starting Stylus handwriting."); return; } - maybeCreateInkWindow(); + maybeCreateAndInitInkWindow(); if (!mOnPreparedStylusHwCalled) { // prepare hasn't been called by Stylus HOVER. onPrepareStylusHandwriting(); @@ -1027,8 +1027,7 @@ public class InputMethodService extends AbstractInputMethodService { */ @Override public void initInkWindow() { - maybeCreateInkWindow(); - mInkWindow.initOnly(); + maybeCreateAndInitInkWindow(); onPrepareStylusHandwriting(); mOnPreparedStylusHwCalled = true; } @@ -1036,11 +1035,13 @@ public class InputMethodService extends AbstractInputMethodService { /** * Create and attach token to Ink window if it wasn't already created. */ - private void maybeCreateInkWindow() { + private void maybeCreateAndInitInkWindow() { if (mInkWindow == null) { mInkWindow = new InkWindow(mWindow.getContext()); mInkWindow.setToken(mToken); } + mInkWindow.initOnly(); + setInkViewVisibilityListener(); // TODO(b/243571274): set an idle-timeout after which InkWindow is removed. } @@ -2469,13 +2470,19 @@ public class InputMethodService extends AbstractInputMethodService { * @param motionEvent {@link MotionEvent} from stylus. */ public void onStylusHandwritingMotionEvent(@NonNull MotionEvent motionEvent) { - if (mInkWindow.isInkViewVisible()) { + if (mInkWindow != null && mInkWindow.isInkViewVisible()) { mInkWindow.getDecorView().dispatchTouchEvent(motionEvent); } else { if (mPendingEvents == null) { mPendingEvents = new RingBuffer(MotionEvent.class, MAX_EVENTS_BUFFER); } mPendingEvents.append(motionEvent); + setInkViewVisibilityListener(); + } + } + + private void setInkViewVisibilityListener() { + if (mInkWindow != null) { mInkWindow.setInkViewVisibilityListener(() -> { if (mPendingEvents != null && !mPendingEvents.isEmpty()) { for (MotionEvent event : mPendingEvents.toArray()) { @@ -2539,6 +2546,7 @@ public class InputMethodService extends AbstractInputMethodService { mHandler.removeCallbacks(mFinishHwRunnable); } mFinishHwRunnable = null; + mPendingEvents.clear(); final int requestId = mHandwritingRequestId.getAsInt(); mHandwritingRequestId = OptionalInt.empty(); |