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

Commit 7b80be55 authored by Liran Binyamin's avatar Liran Binyamin
Browse files

Fix IME visibility issue when device is locked

When the device is locked, if a bubble is expanded and the IME is
visible we now hide the IME before collapsing.

Previously we updated Bubbles internal state, then hid the IME and
once the IME visibility state changed we collapsed the bubble.
But the IME state gets frozen when the device is locked, so that
resulted in corrupt IME and Bubbles state and when the device is
unlocked, the IME remains visible and the bubble remains expanded.

To work around the frozen IME state, this change hides the IME
directly through DisplayImeController to make sure the state
updates correctly.

Flag: EXEMPT bug fix
Fix: 391062949
Test: manual
       - have a floating bubble
       - expand and show IME
       - lock device
       - unlock and observe bubble is collapsed
Test: BubbleControllerTest is being created in a separate change
       - will add unit tests once it's submitted
       - tracked in b/392605916
Change-Id: I955996c8b794832ac5429f06ddb13450f1371dc4
parent bc8b9324
Loading
Loading
Loading
Loading
+26 −2
Original line number Diff line number Diff line
@@ -629,6 +629,14 @@ public class BubbleController implements ConfigurationChangeListener,
        mOnImeHidden = onImeHidden;
        mBubblePositioner.setImeVisible(false /* visible */, 0 /* height */);
        int displayId = mWindowManager.getDefaultDisplay().getDisplayId();
        // if the device is locked we can't use the status bar service to hide the IME because
        // the IME state is frozen and it will lead to internal IME state going out of sync. This
        // will make the IME visible when the device is unlocked. Instead we use
        // DisplayImeController directly to make sure the state is correct when the device unlocks.
        if (isDeviceLocked()) {
            mDisplayImeController.hideImeForBubblesWhenLocked(displayId);
            return;
        }
        try {
            mBarService.hideCurrentInputMethodForBubbles(displayId);
        } catch (RemoteException e) {
@@ -668,9 +676,21 @@ public class BubbleController implements ConfigurationChangeListener,
                        ? mNotifEntryToExpandOnShadeUnlock.getKey() : "null"));
        mIsStatusBarShade = isShade;
        if (!mIsStatusBarShade && didChange) {
            // Only collapse stack on change
            if (mBubbleData.isExpanded()) {
                // If the IME is visible, hide it first and then collapse.
                if (mBubblePositioner.isImeVisible()) {
                    hideCurrentInputMethod(this::collapseStack);
                } else {
                    collapseStack();
                }
            } else if (mOnImeHidden != null) {
                // a request to collapse started before we're notified that the device is locking.
                // we're currently waiting for the IME to collapse, before mOnImeHidden can be
                // executed, which may not happen since the screen may already be off. hide the IME
                // immediately now that we're locked and pass the same runnable so it can complete.
                hideCurrentInputMethod(mOnImeHidden);
            }
        }

        if (mNotifEntryToExpandOnShadeUnlock != null) {
            expandStackAndSelectBubble(mNotifEntryToExpandOnShadeUnlock);
@@ -2448,6 +2468,10 @@ public class BubbleController implements ConfigurationChangeListener,
        mBubbleData.setSelectedBubbleAndExpandStack(bubbleToSelect);
    }

    private boolean isDeviceLocked() {
        return !mIsStatusBarShade;
    }

    /**
     * Description of current bubble state.
     */
+6 −0
Original line number Diff line number Diff line
@@ -224,6 +224,12 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
        }
    }

    /** Hides the IME for Bubbles when the device is locked. */
    public void hideImeForBubblesWhenLocked(int displayId) {
        PerDisplay pd = mImePerDisplay.get(displayId);
        pd.setImeInputTargetRequestedVisibility(false, pd.getImeSourceControl().getImeStatsToken());
    }

    /** An implementation of {@link IDisplayWindowInsetsController} for a given display id. */
    public class PerDisplay implements DisplayInsetsController.OnInsetsChangedListener {
        final int mDisplayId;