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

Commit 85439f49 authored by Taran Singh's avatar Taran Singh
Browse files

Use explicit Handler callback removal for IME surface

Use explicit Handler callback removal from handler so we dont remove all
posted methods from Handler.
There should be no behavior change.

Bug: 167948419
Bug: 167948123
Bug: 233811329

Test: atest CtsInputMethodTestCases
Change-Id: I9564f5aa2430e5438b6a3d0a25967ff10661822a
parent 140e2bb5
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -352,6 +352,7 @@ public class InputMethodService extends AbstractInputMethodService {
    private ImeOnBackInvokedDispatcher mImeDispatcher;
    private Boolean mBackCallbackRegistered = false;
    private final OnBackInvokedCallback mCompatBackCallback = this::compatHandleBack;
    private Runnable mImeSurfaceRemoverRunnable;

    /**
     * Returns whether {@link InputMethodService} is responsible for rendering the back button and
@@ -598,7 +599,6 @@ public class InputMethodService extends AbstractInputMethodService {
    private @NonNull OptionalInt mHandwritingRequestId = OptionalInt.empty();
    private InputEventReceiver mHandwritingEventReceiver;
    private Handler mHandler;
    private boolean mImeSurfaceScheduledForRemoval;
    private ImsConfigurationTracker mConfigTracker = new ImsConfigurationTracker();
    private boolean mDestroyed;
    private boolean mOnPreparedStylusHwCalled;
@@ -1075,7 +1075,7 @@ public class InputMethodService extends AbstractInputMethodService {

    private void scheduleImeSurfaceRemoval() {
        if (mShowInputRequested || mWindowVisible || mWindow == null
                || mImeSurfaceScheduledForRemoval) {
                || mImeSurfaceRemoverRunnable != null) {
            return;
        }
        if (mHandler == null) {
@@ -1089,24 +1089,26 @@ public class InputMethodService extends AbstractInputMethodService {
            //  view issues is resolved in RecyclerView.
            removeImeSurface();
        } else {
            mImeSurfaceScheduledForRemoval = true;
            mHandler.postDelayed(() -> removeImeSurface(), TIMEOUT_SURFACE_REMOVAL_MILLIS);
            mImeSurfaceRemoverRunnable = () -> {
                removeImeSurface();
            };
            mHandler.postDelayed(mImeSurfaceRemoverRunnable, TIMEOUT_SURFACE_REMOVAL_MILLIS);
        }
    }

    private void removeImeSurface() {
        cancelImeSurfaceRemoval();
        // hiding a window removes its surface.
        if (mWindow != null) {
            mWindow.hide();
        }
        mImeSurfaceScheduledForRemoval = false;
    }

    private void cancelImeSurfaceRemoval() {
        if (mHandler != null && mImeSurfaceScheduledForRemoval) {
            mHandler.removeCallbacksAndMessages(null /* token */);
            mImeSurfaceScheduledForRemoval = false;
        if (mHandler != null && mImeSurfaceRemoverRunnable != null) {
            mHandler.removeCallbacks(mImeSurfaceRemoverRunnable);
        }
        mImeSurfaceRemoverRunnable = null;
    }

    private void setImeWindowStatus(int visibilityFlags, int backDisposition) {