Introduce a flag to let app get global insets state

A new hidden flag is introduced to layout params to let system UI
components get the global insets state regardless of the z-order. That
is necessary to let components like power menu and system UI dialog.

Test: atest InsetsStateControllerTest
Bug: 178420426
Bug: 178115003
Change-Id: Ib103639ff00bf15919796788c0ba323aba0b4b4a
This commit is contained in:
Yunfan Chen
2021-02-19 17:58:45 +09:00
parent 09f52aa440
commit 3dc12ebadc
3 changed files with 37 additions and 7 deletions

View File

@@ -2721,6 +2721,15 @@ public interface WindowManager extends ViewManager {
*/
public boolean hasManualSurfaceInsets;
/**
* Whether we should use global insets state when report insets to the window. When set to
* {@code true}, all the insets will be reported to the window regardless of the z-order.
* Otherwise, only the insets above the given window will be reported.
*
* @hide
*/
public boolean receiveInsetsIgnoringZOrder;
/**
* Whether the previous surface insets should be used vs. what is currently set. When set
* to {@code true}, the view root will ignore surfaces insets in this object and use what
@@ -3610,15 +3619,16 @@ public interface WindowManager extends ViewManager {
out.writeInt(preferredDisplayModeId);
out.writeInt(systemUiVisibility);
out.writeInt(subtreeSystemUiVisibility);
out.writeInt(hasSystemUiListeners ? 1 : 0);
out.writeBoolean(hasSystemUiListeners);
out.writeInt(inputFeatures);
out.writeLong(userActivityTimeout);
out.writeInt(surfaceInsets.left);
out.writeInt(surfaceInsets.top);
out.writeInt(surfaceInsets.right);
out.writeInt(surfaceInsets.bottom);
out.writeInt(hasManualSurfaceInsets ? 1 : 0);
out.writeInt(preservePreviousSurfaceInsets ? 1 : 0);
out.writeBoolean(hasManualSurfaceInsets);
out.writeBoolean(receiveInsetsIgnoringZOrder);
out.writeBoolean(preservePreviousSurfaceInsets);
out.writeLong(accessibilityIdOfAnchor);
TextUtils.writeToParcel(accessibilityTitle, out, parcelableFlags);
out.writeInt(mColorMode);
@@ -3679,15 +3689,16 @@ public interface WindowManager extends ViewManager {
preferredDisplayModeId = in.readInt();
systemUiVisibility = in.readInt();
subtreeSystemUiVisibility = in.readInt();
hasSystemUiListeners = in.readInt() != 0;
hasSystemUiListeners = in.readBoolean();
inputFeatures = in.readInt();
userActivityTimeout = in.readLong();
surfaceInsets.left = in.readInt();
surfaceInsets.top = in.readInt();
surfaceInsets.right = in.readInt();
surfaceInsets.bottom = in.readInt();
hasManualSurfaceInsets = in.readInt() != 0;
preservePreviousSurfaceInsets = in.readInt() != 0;
hasManualSurfaceInsets = in.readBoolean();
receiveInsetsIgnoringZOrder = in.readBoolean();
preservePreviousSurfaceInsets = in.readBoolean();
accessibilityIdOfAnchor = in.readLong();
accessibilityTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
mColorMode = in.readInt();
@@ -3916,6 +3927,11 @@ public interface WindowManager extends ViewManager {
changes |= SURFACE_INSETS_CHANGED;
}
if (receiveInsetsIgnoringZOrder != o.receiveInsetsIgnoringZOrder) {
receiveInsetsIgnoringZOrder = o.receiveInsetsIgnoringZOrder;
changes |= SURFACE_INSETS_CHANGED;
}
if (preservePreviousSurfaceInsets != o.preservePreviousSurfaceInsets) {
preservePreviousSurfaceInsets = o.preservePreviousSurfaceInsets;
changes |= SURFACE_INSETS_CHANGED;
@@ -4104,6 +4120,9 @@ public interface WindowManager extends ViewManager {
sb.append(" (!preservePreviousSurfaceInsets)");
}
}
if (receiveInsetsIgnoringZOrder) {
sb.append(" receive insets ignoring z-order");
}
if (mColorMode != COLOR_MODE_DEFAULT) {
sb.append(" colorMode=").append(ActivityInfo.colorModeToString(mColorMode));
}

View File

@@ -124,7 +124,8 @@ class InsetsStateController {
? provider.getSource().getType() : ITYPE_INVALID;
return getInsetsForTarget(type, target.getWindowingMode(), target.isAlwaysOnTop(),
target.getFrozenInsetsState() != null ? target.getFrozenInsetsState() :
target.mAboveInsetsState);
(target.mAttrs.receiveInsetsIgnoringZOrder ? mState :
target.mAboveInsetsState));
}
InsetsState getInsetsForWindowMetrics(@NonNull WindowManager.LayoutParams attrs) {

View File

@@ -416,6 +416,16 @@ public class InsetsStateControllerTest extends WindowTestsBase {
verify(navBar, atLeastOnce()).notifyInsetsChanged();
}
@Test
public void testDispatchGlobalInsets() {
final WindowState navBar = createWindow(null, TYPE_APPLICATION, "navBar");
getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null);
final WindowState app = createWindow(null, TYPE_APPLICATION, "app");
assertNull(getController().getInsetsForWindow(app).peekSource(ITYPE_NAVIGATION_BAR));
app.mAttrs.receiveInsetsIgnoringZOrder = true;
assertNotNull(getController().getInsetsForWindow(app).peekSource(ITYPE_NAVIGATION_BAR));
}
private WindowState createTestWindow(String name) {
final WindowState win = createWindow(null, TYPE_APPLICATION, name);
win.setHasSurface(true);