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 Original line Diff line number Diff line
@@ -352,6 +352,7 @@ public class InputMethodService extends AbstractInputMethodService {
    private ImeOnBackInvokedDispatcher mImeDispatcher;
    private ImeOnBackInvokedDispatcher mImeDispatcher;
    private Boolean mBackCallbackRegistered = false;
    private Boolean mBackCallbackRegistered = false;
    private final OnBackInvokedCallback mCompatBackCallback = this::compatHandleBack;
    private final OnBackInvokedCallback mCompatBackCallback = this::compatHandleBack;
    private Runnable mImeSurfaceRemoverRunnable;


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


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


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


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


    private void setImeWindowStatus(int visibilityFlags, int backDisposition) {
    private void setImeWindowStatus(int visibilityFlags, int backDisposition) {