Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b4fa7151 authored by Taran Singh's avatar Taran Singh
Browse files

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

This is a retry for I1593ff10a5520aadb5ed86a4a09f2405ee65c321

Change-Id: Ibf54599f41ac13121215c5344eb92ecca3259db1
parent 9aaeeb36
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -163,6 +163,9 @@ final class InkWindow extends PhoneWindow {
        mGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                if (mInkView == null) {
                    return;
                }
                if (mInkView.isVisibleToUser()) {
                    if (mInkViewVisibilityListener != null) {
                        mInkViewVisibilityListener.onInkViewVisible();
+18 −13
Original line number Diff line number Diff line
@@ -962,7 +962,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();
@@ -1022,21 +1022,21 @@ public class InputMethodService extends AbstractInputMethodService {
         */
        @Override
        public void initInkWindow() {
            maybeCreateInkWindow();
            mInkWindow.initOnly();
            maybeCreateAndInitInkWindow();
            onPrepareStylusHandwriting();
            mOnPreparedStylusHwCalled = true;
        }

        /**
         * Create and attach token to Ink window if it wasn't already created.
         * Create, attach token and layout 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);
            }
            // TODO(b/243571274): set an idle-timeout after which InkWindow is removed.
            mInkWindow.initOnly();
        }

        /**
@@ -2464,16 +2464,20 @@ 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);
            if (mInkWindow != null) {
                mInkWindow.setInkViewVisibilityListener(() -> {
                    if (mPendingEvents != null && !mPendingEvents.isEmpty()) {
                        for (MotionEvent event : mPendingEvents.toArray()) {
                            if (mInkWindow == null) {
                                break;
                            }
                            mInkWindow.getDecorView().dispatchTouchEvent(event);
                        }
                        mPendingEvents.clear();
@@ -2481,6 +2485,7 @@ public class InputMethodService extends AbstractInputMethodService {
                });
            }
        }
    }

    /**
     * Called when the current stylus handwriting session was finished (either by the system or