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

Commit 36ea6785 authored by Riddle Hsu's avatar Riddle Hsu Committed by Automerger Merge Worker
Browse files

Merge "Update decor insets when the amount of insets source is changed" into udc-dev am: 8aede728

parents 0f4519b1 8aede728
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -1856,6 +1856,9 @@ public class DisplayPolicy {
             */
            final Rect mConfigFrame = new Rect();

            /** The count of insets sources when calculating this info. */
            int mLastInsetsSourceCount;

            private boolean mNeedUpdate = true;

            void update(DisplayContent dc, int rotation, int w, int h) {
@@ -1877,6 +1880,7 @@ public class DisplayPolicy {
                mNonDecorFrame.inset(mNonDecorInsets);
                mConfigFrame.set(displayFrame);
                mConfigFrame.inset(mConfigInsets);
                mLastInsetsSourceCount = dc.getDisplayPolicy().mInsetsSourceWindowsExceptIme.size();
                mNeedUpdate = false;
            }

@@ -1885,6 +1889,7 @@ public class DisplayPolicy {
                mConfigInsets.set(other.mConfigInsets);
                mNonDecorFrame.set(other.mNonDecorFrame);
                mConfigFrame.set(other.mConfigFrame);
                mLastInsetsSourceCount = other.mLastInsetsSourceCount;
                mNeedUpdate = false;
            }

@@ -1983,6 +1988,19 @@ public class DisplayPolicy {
        newInfo.update(mDisplayContent, rotation, dw, dh);
        final DecorInsets.Info currentInfo = getDecorInsetsInfo(rotation, dw, dh);
        if (newInfo.mConfigFrame.equals(currentInfo.mConfigFrame)) {
            // Even if the config frame is not changed in current rotation, it may change the
            // insets in other rotations if the source count is changed.
            if (newInfo.mLastInsetsSourceCount != currentInfo.mLastInsetsSourceCount) {
                for (int i = mDecorInsets.mInfoForRotation.length - 1; i >= 0; i--) {
                    if (i != rotation) {
                        final boolean flipSize = (i + rotation) % 2 == 1;
                        final int w = flipSize ? dh : dw;
                        final int h = flipSize ? dw : dh;
                        mDecorInsets.mInfoForRotation[i].update(mDisplayContent, i, w, h);
                    }
                }
                mDecorInsets.mInfoForRotation[rotation].set(newInfo);
            }
            return false;
        }
        if (mCachedDecorInsets != null && !mCachedDecorInsets.canPreserve()
+32 −0
Original line number Diff line number Diff line
@@ -51,14 +51,18 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

import android.graphics.Insets;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.platform.test.annotations.Presubmit;
import android.view.DisplayInfo;
import android.view.DisplayShape;
import android.view.InsetsFrameProvider;
import android.view.InsetsSource;
import android.view.InsetsState;
import android.view.PrivacyIndicatorBounds;
import android.view.Surface;
import android.view.WindowInsets;
import android.view.WindowInsets.Side;
import android.view.WindowManager;

@@ -350,6 +354,34 @@ public class DisplayPolicyTests extends WindowTestsBase {
                && displayPolicy.updateDecorInsetsInfo());
        assertEquals(STATUS_BAR_HEIGHT, displayPolicy.getDecorInsetsInfo(di.rotation,
                di.logicalWidth, di.logicalHeight).mConfigInsets.top);

        // Add a window that provides the same insets in current rotation. But it specifies
        // different insets in other rotations.
        final WindowState bar2 = createWindow(null, statusBar.mAttrs.type, "bar2");
        bar2.mAttrs.providedInsets = new InsetsFrameProvider[] {
                new InsetsFrameProvider(bar2, 0, WindowInsets.Type.statusBars())
                        .setInsetsSize(Insets.of(0, STATUS_BAR_HEIGHT, 0, 0))
        };
        bar2.mAttrs.paramsForRotation = new WindowManager.LayoutParams[4];
        final int doubleHeightFor90 = STATUS_BAR_HEIGHT * 2;
        for (int i = ROTATION_0; i <= Surface.ROTATION_270; i++) {
            final WindowManager.LayoutParams params = new WindowManager.LayoutParams();
            if (i == Surface.ROTATION_90) {
                params.providedInsets = new InsetsFrameProvider[] {
                        new InsetsFrameProvider(bar2, 0, WindowInsets.Type.statusBars())
                                .setInsetsSize(Insets.of(0, doubleHeightFor90, 0, 0))
                };
            } else {
                params.providedInsets = bar2.mAttrs.providedInsets;
            }
            bar2.mAttrs.paramsForRotation[i] = params;
        }
        displayPolicy.addWindowLw(bar2, bar2.mAttrs);
        // Current rotation is 0 and the top insets is still STATUS_BAR_HEIGHT, so no change.
        assertFalse(displayPolicy.updateDecorInsetsInfo());
        // The insets in other rotations should be still updated.
        assertEquals(doubleHeightFor90, displayPolicy.getDecorInsetsInfo(Surface.ROTATION_90,
                di.logicalHeight, di.logicalWidth).mConfigInsets.top);
    }

    @SetupWindows(addWindows = { W_NAVIGATION_BAR, W_INPUT_METHOD })