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

Commit 6a11f904 authored by Alex Stetson's avatar Alex Stetson
Browse files

Always report real top focused window to remote inset controller

When the focused window is not controlling the system bars but rather
it's the responsibility of a remote insets controller, the actually top
focused window should be passed rather than limiting to a fullscreen
window only.

Bug: 440148796
Test: atest InsetsPolicyTest
Flag: NONE bugfix
Change-Id: I9ff3483f2d9c6a7f17798567a1a3c88dfadfb29b
parent ef37b7a9
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -2602,12 +2602,14 @@ public class DisplayPolicy {
    }

    void updateSystemBarAttributes() {
        // The focused window always needs to be sent to System UI regardless of filling
        // display when the remote insets controller is controlling system bars.
        final boolean isRemoteControlling = isRemoteInsetsControllerControllingSystemBars();
        // If there is no window focused, there will be nobody to handle the events
        // anyway, so just hang on in whatever state we're in until things settle down.
        WindowState winCandidate =
                mFocusedWindow != null && fillsDisplayWindowingMode(mFocusedWindow)
                        ? mFocusedWindow
                        : mTopFullscreenOpaqueWindowState;
                mFocusedWindow != null && (isRemoteControlling || fillsDisplayWindowingMode(
                        mFocusedWindow)) ? mFocusedWindow : mTopFullscreenOpaqueWindowState;

        // Immersive mode confirmation should never affect the system bar visibility, otherwise
        // it will unhide the navigation bar and hide itself.
@@ -2617,7 +2619,7 @@ public class DisplayPolicy {
                // Let notification shade control the system bar visibility.
                winCandidate = mNotificationShade;
            } else if (mLastFocusedWindow != null && mLastFocusedWindow.canReceiveKeys()
                    && fillsDisplayWindowingMode(mLastFocusedWindow)) {
                    && (isRemoteControlling || fillsDisplayWindowingMode(mLastFocusedWindow))) {
                // Immersive mode confirmation took the focus from mLastFocusedWindow which was
                // controlling the system bar visibility. Let it keep controlling the visibility.
                winCandidate = mLastFocusedWindow;
@@ -2627,7 +2629,8 @@ public class DisplayPolicy {
        }
        if (winCandidate == null) {
            final ActivityRecord focusedApp = mDisplayContent.mFocusedApp;
            if (focusedApp == null || fillsDisplayWindowingMode(focusedApp)) {
            if (focusedApp == null
                    || (isRemoteControlling || fillsDisplayWindowingMode(focusedApp))) {
                // Don't change the system UI controlling window when the new one is not ready.
                return;
            }
+29 −0
Original line number Diff line number Diff line
@@ -38,16 +38,22 @@ import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

import android.app.StatusBarManager;
import android.content.ComponentName;
import android.graphics.Insets;
import android.graphics.Rect;
import android.os.Binder;
import android.os.RemoteException;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.annotations.Presubmit;
import android.view.IDisplayWindowInsetsController;
import android.view.InsetsFrameProvider;
import android.view.InsetsSource;
import android.view.InsetsSourceControl;
@@ -170,6 +176,29 @@ public class InsetsPolicyTest extends WindowTestsBase {
        assertNull(controls);
    }

    @Test
    public void testControlsForDispatch_nonFullscreenMultiWindowTaskVisible_remoteInsetControl()
            throws RemoteException {
        addStatusBar();
        addNavigationBar();
        final IDisplayWindowInsetsController insetsController = spy(
                createDisplayWindowInsetsController());
        mDisplayContent.setRemoteInsetsController(insetsController);
        mDisplayContent.getDisplayPolicy().setRemoteInsetsControllerControlsSystemBars(true);

        final WindowState win = newWindowBuilder("app", TYPE_APPLICATION).setActivityType(
                ACTIVITY_TYPE_STANDARD).setWindowingMode(WINDOWING_MODE_MULTI_WINDOW).setDisplay(
                mDisplayContent).build();
        final ComponentName component = win.mActivityRecord.mActivityComponent;
        assertNotNull(component);
        win.getTask().setBounds(new Rect(1, 1, 10, 10));
        final InsetsSourceControl[] controls = addWindowAndGetControlsForDispatch(win);

        // The remote insets controller should control the system bars.
        assertNull(controls);
        verify(insetsController).topFocusedWindowChanged(eq(component), anyInt());
    }

    @Test
    public void testControlsForDispatch_forceStatusBarVisible() {
        addStatusBar().mAttrs.forciblyShownTypes |= statusBars();