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

Commit b524965f authored by Hiroki Sato's avatar Hiroki Sato
Browse files

Make sure InputMethodService's StylusWindowIdleTimeout always work

This changes InputMethodService#mHandler a non-null final.
This makes sure that #scheduleStylusWindowIdleTimeout() always works as
expected, independently to the service's state.

Without this change, stylus window idle timeout works only when
scheduleHandwritingSessionTimeout() or scheduleImeSurfaceRemoval() is
called before. Other than that, no behavior changes are expected.

Bug: 434580675
Test: StylusHandwritingTest#testHandwritingWindowRemoval_immediate
Flag: EXEMPT bug fix
Change-Id: I9ac1200aeab53b250a2791e93a092466bb67c765
parent e60d1401
Loading
Loading
Loading
Loading
+5 −16
Original line number Diff line number Diff line
@@ -634,7 +634,7 @@ public class InputMethodService extends AbstractInputMethodService {

    private @NonNull OptionalInt mHandwritingRequestId = OptionalInt.empty();
    private InputEventReceiver mHandwritingEventReceiver;
    private Handler mHandler;
    private final Handler mHandler = new Handler(Looper.getMainLooper());
    private ImsConfigurationTracker mConfigTracker = new ImsConfigurationTracker();
    private boolean mDestroyed;
    private boolean mOnPreparedStylusHwCalled;
@@ -1245,9 +1245,6 @@ public class InputMethodService extends AbstractInputMethodService {
                || mImeSurfaceRemoverRunnable != null) {
            return;
        }
        if (mHandler == null) {
            mHandler = new Handler(getMainLooper());
        }

        if (mLastWasInFullscreenMode) {
            // Caching surface / delaying surface removal can cause mServedView to detach in certain
@@ -1272,7 +1269,7 @@ public class InputMethodService extends AbstractInputMethodService {
    }

    private void cancelImeSurfaceRemoval() {
        if (mHandler != null && mImeSurfaceRemoverRunnable != null) {
        if (mImeSurfaceRemoverRunnable != null) {
            mHandler.removeCallbacks(mImeSurfaceRemoverRunnable);
        }
        mImeSurfaceRemoverRunnable = null;
@@ -2770,7 +2767,7 @@ public class InputMethodService extends AbstractInputMethodService {
        if (!mHandwritingRequestId.isPresent()) {
            return;
        }
        if (mHandler != null && mFinishHwRunnable != null) {
        if (mFinishHwRunnable != null) {
            mHandler.removeCallbacks(mFinishHwRunnable);
        }
        mFinishHwRunnable = null;
@@ -2868,15 +2865,12 @@ public class InputMethodService extends AbstractInputMethodService {
    }

    private void cancelStylusWindowIdleTimeout() {
        if (mStylusWindowIdleTimeoutRunnable != null && mHandler != null) {
        if (mStylusWindowIdleTimeoutRunnable != null) {
            mHandler.removeCallbacks(mStylusWindowIdleTimeoutRunnable);
        }
    }

    private void scheduleStylusWindowIdleTimeout() {
        if (mHandler == null) {
            return;
        }
        cancelStylusWindowIdleTimeout();
        long timeout = (mStylusWindowIdleTimeoutForTest > 0)
                ? mStylusWindowIdleTimeoutForTest : STYLUS_WINDOW_IDLE_TIMEOUT_MILLIS;
@@ -2952,9 +2946,7 @@ public class InputMethodService extends AbstractInputMethodService {
            return mFinishHwRunnable;
        }
        return mFinishHwRunnable = () -> {
            if (mHandler != null) {
            mHandler.removeCallbacks(mFinishHwRunnable);
            }
            Log.d(TAG, "Stylus handwriting idle timed-out. calling finishStylusHandwriting()");
            mFinishHwRunnable = null;
            finishStylusHandwriting();
@@ -2962,9 +2954,6 @@ public class InputMethodService extends AbstractInputMethodService {
    }

    private void scheduleHandwritingSessionTimeout() {
        if (mHandler == null) {
            mHandler = new Handler(getMainLooper());
        }
        if (mFinishHwRunnable != null) {
            mHandler.removeCallbacks(mFinishHwRunnable);
        }