diff options
| -rw-r--r-- | services/core/java/com/android/server/wm/DisplayPolicy.java | 18 | ||||
| -rw-r--r-- | services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java | 32 |
2 files changed, 50 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java index 812d2a5d3217..8dcb042b3733 100644 --- a/services/core/java/com/android/server/wm/DisplayPolicy.java +++ b/services/core/java/com/android/server/wm/DisplayPolicy.java @@ -1859,6 +1859,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) { @@ -1880,6 +1883,7 @@ public class DisplayPolicy { mNonDecorFrame.inset(mNonDecorInsets); mConfigFrame.set(displayFrame); mConfigFrame.inset(mConfigInsets); + mLastInsetsSourceCount = dc.getDisplayPolicy().mInsetsSourceWindowsExceptIme.size(); mNeedUpdate = false; } @@ -1888,6 +1892,7 @@ public class DisplayPolicy { mConfigInsets.set(other.mConfigInsets); mNonDecorFrame.set(other.mNonDecorFrame); mConfigFrame.set(other.mConfigFrame); + mLastInsetsSourceCount = other.mLastInsetsSourceCount; mNeedUpdate = false; } @@ -1986,6 +1991,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() diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java index a422c6893de5..2cdb4970073a 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java @@ -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; @@ -388,6 +392,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 }) |