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

Commit 47044ac7 authored by ryanlwlin's avatar ryanlwlin
Browse files

Fix incorrect IME visibility when the IME window is hidden

When onSurfaceShownChanged is invoked, we determine if the IME
window is visible, which is not correct because IME window might
not be visible on the screen but its surface is visible.

To determine the visiblity of the IME, we use ime inset visibility,
and check it when the window insets is changed.

Bug: 194668976
Test: manual test
      atest MagnificationControllerTest
Change-Id: I202ddb41ddde94f1afa96541795dc8ed1d727a0f
parent 8d2d9ded
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
@@ -137,7 +137,7 @@ final class AccessibilityController {
            new SparseArray<>();
    private SparseArray<IBinder> mFocusedWindow = new SparseArray<>();
    private int mFocusedDisplay = -1;

    private boolean mIsImeVisible = false;
    // Set to true if initializing window population complete.
    private boolean mAllObserversInitialized = true;

@@ -490,15 +490,19 @@ final class AccessibilityController {
        }
    }

    void onImeSurfaceShownChanged(WindowState windowState, boolean shown) {
    void updateImeVisibilityIfNeeded(int displayId, boolean shown) {
        if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK)) {
            mAccessibilityTracing.logTrace(TAG + ".onImeSurfaceShownChanged",
                    FLAGS_MAGNIFICATION_CALLBACK, "windowState=" + windowState + ";shown=" + shown);
            mAccessibilityTracing.logTrace(TAG + ".updateImeVisibilityIfNeeded",
                    FLAGS_MAGNIFICATION_CALLBACK, "displayId=" + displayId + ";shown=" + shown);
        }
        final int displayId = windowState.getDisplayId();
        if (mIsImeVisible == shown) {
            return;
        }

        mIsImeVisible = shown;
        final DisplayMagnifier displayMagnifier = mDisplayMagnifiers.get(displayId);
        if (displayMagnifier != null) {
            displayMagnifier.onImeSurfaceShownChanged(shown);
            displayMagnifier.notifyImeWindowVisibilityChanged(shown);
        }
    }

@@ -767,9 +771,9 @@ final class AccessibilityController {
            }
        }

        void onImeSurfaceShownChanged(boolean shown) {
        void notifyImeWindowVisibilityChanged(boolean shown) {
            if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK)) {
                mAccessibilityTracing.logTrace(LOG_TAG + ".onImeSurfaceShownChanged",
                mAccessibilityTracing.logTrace(LOG_TAG + ".notifyImeWindowVisibilityChanged",
                        FLAGS_MAGNIFICATION_CALLBACK, "shown=" + shown);
            }
            mHandler.obtainMessage(MyHandler.MESSAGE_NOTIFY_IME_WINDOW_VISIBILITY_CHANGED,
+7 −0
Original line number Diff line number Diff line
@@ -1910,6 +1910,13 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        if (mRemoteInsetsControlTarget != null) {
            mRemoteInsetsControlTarget.notifyInsetsChanged();
        }
        // In Accessibility side, we need to know what magnification mode is activated while IME
        // is opened for logging metrics.
        if (mWmService.mAccessibilityController.hasCallbacks()) {
            final boolean isImeShow = mImeControlTarget != null
                    && mImeControlTarget.getRequestedVisibility(ITYPE_IME);
            mWmService.mAccessibilityController.updateImeVisibilityIfNeeded(mDisplayId, isImeShow);
        }
    }

    /**
+0 −3
Original line number Diff line number Diff line
@@ -3573,9 +3573,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        if (mAttrs.type >= FIRST_SYSTEM_WINDOW && mAttrs.type != TYPE_TOAST) {
            mWmService.mAtmService.mActiveUids.onNonAppSurfaceVisibilityChanged(mOwnerUid, shown);
        }
        if (mIsImWindow && mWmService.mAccessibilityController.hasCallbacks()) {
            mWmService.mAccessibilityController.onImeSurfaceShownChanged(this, shown);
        }
    }

    private void logExclusionRestrictions(int side) {