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

Commit 2bcf7edb authored by Taran Singh's avatar Taran Singh
Browse files

Refactor InkWindow lifetime

Refactor InkWindow instance to live longer with a timer.
This should help with faster handwritiing intiiaiton if handwriting is
intiiated again shortly after the new window gets bound to IME.

Also refactored to finish handwriting on idle timeout rather than just
removing the window.

Bug: 291946496
Test: atest StylusHandwritingTest
Change-Id: I29a1eec9502b9558f8a7992308ec894f160dd4b7
parent 7b41e4d7
Loading
Loading
Loading
Loading
+11 −14
Original line number Diff line number Diff line
@@ -806,9 +806,11 @@ public class InputMethodService extends AbstractInputMethodService {
            onUnbindInput();
            mInputBinding = null;
            mInputConnection = null;
            // free-up cached InkWindow surface on detaching from current client.

            if (mInkWindow != null) {
                removeHandwritingInkWindow();
                finishStylusHandwriting();
                // free-up InkWindow surface after timeout.
                scheduleStylusWindowIdleTimeout();
            }
        }

@@ -1018,6 +1020,7 @@ public class InputMethodService extends AbstractInputMethodService {
                mOnPreparedStylusHwCalled = true;
            }
            if (onStartStylusHandwriting()) {
                cancelStylusWindowIdleTimeout();
                mPrivOps.onStylusHandwritingReady(requestId, Process.myPid());
            } else {
                Log.i(TAG, "IME is not ready. Can't start Stylus Handwriting");
@@ -1107,7 +1110,7 @@ public class InputMethodService extends AbstractInputMethodService {
         */
        @Override
        public void removeStylusHandwritingWindow() {
            InputMethodService.this.removeStylusHandwritingWindow();
            InputMethodService.this.finishAndRemoveStylusHandwritingWindow();
        }

        /**
@@ -2664,21 +2667,15 @@ public class InputMethodService extends AbstractInputMethodService {
     * Typically, this is called when {@link InkWindow} should no longer be holding a surface in
     * memory.
     */
    private void removeStylusHandwritingWindow() {
    private void finishAndRemoveStylusHandwritingWindow() {
        cancelStylusWindowIdleTimeout();
        mOnPreparedStylusHwCalled = false;
        mStylusWindowIdleTimeoutRunnable = null;
        if (mInkWindow != null) {
            if (mHandwritingRequestId.isPresent()) {
                // if handwriting session is still ongoing. This shouldn't happen.
                finishStylusHandwriting();
            }
            removeHandwritingInkWindow();
        }
    }

    private void removeHandwritingInkWindow() {
        cancelStylusWindowIdleTimeout();
        mOnPreparedStylusHwCalled = false;
        mStylusWindowIdleTimeoutRunnable = null;
        if (mInkWindow != null) {
            mInkWindow.hide(true /* remove */);
            mInkWindow.destroy();
            mInkWindow = null;
@@ -2704,7 +2701,7 @@ public class InputMethodService extends AbstractInputMethodService {
    private Runnable getStylusWindowIdleTimeoutRunnable() {
        if (mStylusWindowIdleTimeoutRunnable == null) {
            mStylusWindowIdleTimeoutRunnable = () -> {
                removeHandwritingInkWindow();
                finishAndRemoveStylusHandwritingWindow();
                mStylusWindowIdleTimeoutRunnable = null;
            };
        }