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

Commit 82dc96aa authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Ensure insets state for dispatch is processed by policy

Otherwise the visibility of transient state doesn't take effect if
there is a fixed rotation insets state. Then the client side may not
aware visibility change to update alpha of insets leash.

Fixes: 160458371
Test: atest DisplayPolicyLayoutTests#testFixedRotationInsetsSourceFrame
  InsetsStateControllerTest#testTransientVisibilityOfFixedRotationState

Change-Id: Icecb25f64e983b163f169c191a9f0b15ac1b3086
parent b511a73d
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -105,6 +105,10 @@ class InsetsStateController {
     * @return The state stripped of the necessary information.
     * @return The state stripped of the necessary information.
     */
     */
    InsetsState getInsetsForDispatch(@NonNull WindowState target) {
    InsetsState getInsetsForDispatch(@NonNull WindowState target) {
        final InsetsState rotatedState = target.mToken.getFixedRotationTransformInsetsState();
        if (rotatedState != null) {
            return rotatedState;
        }
        final InsetsSourceProvider provider = target.getControllableInsetProvider();
        final InsetsSourceProvider provider = target.getControllableInsetProvider();
        final @InternalInsetsType int type = provider != null
        final @InternalInsetsType int type = provider != null
                ? provider.getSource().getType() : ITYPE_INVALID;
                ? provider.getSource().getType() : ITYPE_INVALID;
+0 −4
Original line number Original line Diff line number Diff line
@@ -1535,10 +1535,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
    }
    }


    InsetsState getInsetsState() {
    InsetsState getInsetsState() {
        final InsetsState insetsState = mToken.getFixedRotationTransformInsetsState();
        if (insetsState != null) {
            return insetsState;
        }
        return getDisplayContent().getInsetsPolicy().getInsetsForDispatch(this);
        return getDisplayContent().getInsetsPolicy().getInsetsForDispatch(this);
    }
    }


+15 −0
Original line number Original line Diff line number Diff line
@@ -48,12 +48,14 @@ import static android.view.WindowManagerPolicyConstants.ALT_BAR_LEFT;
import static android.view.WindowManagerPolicyConstants.ALT_BAR_RIGHT;
import static android.view.WindowManagerPolicyConstants.ALT_BAR_RIGHT;
import static android.view.WindowManagerPolicyConstants.ALT_BAR_TOP;
import static android.view.WindowManagerPolicyConstants.ALT_BAR_TOP;


import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;


import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.spy;
@@ -873,6 +875,19 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
                new ToStringComparatorWrapper<>(simulatedInsetsState));
                new ToStringComparatorWrapper<>(simulatedInsetsState));
    }
    }


    @Test
    public void testFixedRotationInsetsSourceFrame() {
        mDisplayPolicy.beginLayoutLw(mFrames, mDisplayContent.getConfiguration().uiMode);
        doReturn((mDisplayContent.getRotation() + 1) % 4).when(mDisplayContent)
                .rotationForActivityInDifferentOrientation(eq(mWindow.mActivityRecord));
        final Rect frame = mWindow.getInsetsState().getSource(ITYPE_STATUS_BAR).getFrame();
        mDisplayContent.rotateInDifferentOrientationIfNeeded(mWindow.mActivityRecord);
        final Rect rotatedFrame = mWindow.getInsetsState().getSource(ITYPE_STATUS_BAR).getFrame();

        assertEquals(DISPLAY_WIDTH, frame.width());
        assertEquals(DISPLAY_HEIGHT, rotatedFrame.width());
    }

    @Test
    @Test
    public void testScreenDecorWindows() {
    public void testScreenDecorWindows() {
        final WindowState decorWindow = spy(
        final WindowState decorWindow = spy(
+25 −0
Original line number Original line Diff line number Diff line
@@ -28,6 +28,9 @@ import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;


import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotNull;
@@ -40,6 +43,7 @@ import static org.mockito.Mockito.verify;


import android.graphics.Rect;
import android.graphics.Rect;
import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.Presubmit;
import android.util.IntArray;
import android.view.InsetsSourceControl;
import android.view.InsetsSourceControl;
import android.view.InsetsState;
import android.view.InsetsState;
import android.view.test.InsetsModeSession;
import android.view.test.InsetsModeSession;
@@ -328,6 +332,27 @@ public class InsetsStateControllerTest extends WindowTestsBase {
        assertNull(getController().getControlsForDispatch(app));
        assertNull(getController().getControlsForDispatch(app));
    }
    }


    @Test
    public void testTransientVisibilityOfFixedRotationState() {
        final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar");
        final WindowState app = createWindow(null, TYPE_APPLICATION, "app");
        final InsetsSourceProvider provider = getController().getSourceProvider(ITYPE_STATUS_BAR);
        provider.setWindow(statusBar, null, null);

        final InsetsState rotatedState = new InsetsState(app.getInsetsState(),
                true /* copySources */);
        spyOn(app.mToken);
        doReturn(rotatedState).when(app.mToken).getFixedRotationTransformInsetsState();
        assertTrue(rotatedState.getSource(ITYPE_STATUS_BAR).isVisible());

        provider.getSource().setVisible(false);
        mDisplayContent.getInsetsPolicy().showTransient(
                IntArray.wrap(new int[] { ITYPE_STATUS_BAR }));

        assertTrue(mDisplayContent.getInsetsPolicy().isTransient(ITYPE_STATUS_BAR));
        assertFalse(app.getInsetsState().getSource(ITYPE_STATUS_BAR).isVisible());
    }

    private InsetsStateController getController() {
    private InsetsStateController getController() {
        return mDisplayContent.getInsetsStateController();
        return mDisplayContent.getInsetsStateController();
    }
    }
+2 −0
Original line number Original line Diff line number Diff line
@@ -568,6 +568,8 @@ public class SizeCompatTests extends WindowTestsBase {
    private static WindowState addWindowToActivity(ActivityRecord activity) {
    private static WindowState addWindowToActivity(ActivityRecord activity) {
        final WindowManager.LayoutParams params = new WindowManager.LayoutParams();
        final WindowManager.LayoutParams params = new WindowManager.LayoutParams();
        params.type = WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
        params.type = WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
        params.setFitInsetsSides(0);
        params.setFitInsetsTypes(0);
        final TestWindowState w = new TestWindowState(
        final TestWindowState w = new TestWindowState(
                activity.mWmService, mock(Session.class), new TestIWindow(), params, activity);
                activity.mWmService, mock(Session.class), new TestIWindow(), params, activity);
        WindowTestsBase.makeWindowVisible(w);
        WindowTestsBase.makeWindowVisible(w);