Merge "Update decor insets when the amount of insets source is changed" into udc-dev
This commit is contained in:
@@ -1856,6 +1856,9 @@ public class DisplayPolicy {
|
|||||||
*/
|
*/
|
||||||
final Rect mConfigFrame = new Rect();
|
final Rect mConfigFrame = new Rect();
|
||||||
|
|
||||||
|
/** The count of insets sources when calculating this info. */
|
||||||
|
int mLastInsetsSourceCount;
|
||||||
|
|
||||||
private boolean mNeedUpdate = true;
|
private boolean mNeedUpdate = true;
|
||||||
|
|
||||||
void update(DisplayContent dc, int rotation, int w, int h) {
|
void update(DisplayContent dc, int rotation, int w, int h) {
|
||||||
@@ -1877,6 +1880,7 @@ public class DisplayPolicy {
|
|||||||
mNonDecorFrame.inset(mNonDecorInsets);
|
mNonDecorFrame.inset(mNonDecorInsets);
|
||||||
mConfigFrame.set(displayFrame);
|
mConfigFrame.set(displayFrame);
|
||||||
mConfigFrame.inset(mConfigInsets);
|
mConfigFrame.inset(mConfigInsets);
|
||||||
|
mLastInsetsSourceCount = dc.getDisplayPolicy().mInsetsSourceWindowsExceptIme.size();
|
||||||
mNeedUpdate = false;
|
mNeedUpdate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1885,6 +1889,7 @@ public class DisplayPolicy {
|
|||||||
mConfigInsets.set(other.mConfigInsets);
|
mConfigInsets.set(other.mConfigInsets);
|
||||||
mNonDecorFrame.set(other.mNonDecorFrame);
|
mNonDecorFrame.set(other.mNonDecorFrame);
|
||||||
mConfigFrame.set(other.mConfigFrame);
|
mConfigFrame.set(other.mConfigFrame);
|
||||||
|
mLastInsetsSourceCount = other.mLastInsetsSourceCount;
|
||||||
mNeedUpdate = false;
|
mNeedUpdate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1983,6 +1988,19 @@ public class DisplayPolicy {
|
|||||||
newInfo.update(mDisplayContent, rotation, dw, dh);
|
newInfo.update(mDisplayContent, rotation, dw, dh);
|
||||||
final DecorInsets.Info currentInfo = getDecorInsetsInfo(rotation, dw, dh);
|
final DecorInsets.Info currentInfo = getDecorInsetsInfo(rotation, dw, dh);
|
||||||
if (newInfo.mConfigFrame.equals(currentInfo.mConfigFrame)) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
if (mCachedDecorInsets != null && !mCachedDecorInsets.canPreserve()
|
if (mCachedDecorInsets != null && !mCachedDecorInsets.canPreserve()
|
||||||
|
|||||||
@@ -51,14 +51,18 @@ import static org.mockito.Mockito.doReturn;
|
|||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.graphics.Insets;
|
||||||
import android.graphics.PixelFormat;
|
import android.graphics.PixelFormat;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.platform.test.annotations.Presubmit;
|
import android.platform.test.annotations.Presubmit;
|
||||||
import android.view.DisplayInfo;
|
import android.view.DisplayInfo;
|
||||||
import android.view.DisplayShape;
|
import android.view.DisplayShape;
|
||||||
|
import android.view.InsetsFrameProvider;
|
||||||
import android.view.InsetsSource;
|
import android.view.InsetsSource;
|
||||||
import android.view.InsetsState;
|
import android.view.InsetsState;
|
||||||
import android.view.PrivacyIndicatorBounds;
|
import android.view.PrivacyIndicatorBounds;
|
||||||
|
import android.view.Surface;
|
||||||
|
import android.view.WindowInsets;
|
||||||
import android.view.WindowInsets.Side;
|
import android.view.WindowInsets.Side;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
@@ -350,6 +354,34 @@ public class DisplayPolicyTests extends WindowTestsBase {
|
|||||||
&& displayPolicy.updateDecorInsetsInfo());
|
&& displayPolicy.updateDecorInsetsInfo());
|
||||||
assertEquals(STATUS_BAR_HEIGHT, displayPolicy.getDecorInsetsInfo(di.rotation,
|
assertEquals(STATUS_BAR_HEIGHT, displayPolicy.getDecorInsetsInfo(di.rotation,
|
||||||
di.logicalWidth, di.logicalHeight).mConfigInsets.top);
|
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 })
|
@SetupWindows(addWindows = { W_NAVIGATION_BAR, W_INPUT_METHOD })
|
||||||
|
|||||||
Reference in New Issue
Block a user