summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorTiger Huang <tigerhuang@google.com>2021-01-06 19:10:02 +0800
committerTiger Huang <tigerhuang@google.com>2021-01-06 19:10:02 +0800
commit7dbb0540c0ffed0dde7fab11d477188ffc25c32b (patch)
tree851d3b6722d0870ab7c7aa28493f38dfdc4d16b9 /core/java/android
parentf74907691092b73de5dadc607300d83f0258950f (diff)
Preserve the controlling state of appearance and behavior
Make sure the appearance or the behavior controlled by the new APIs won't be affected by setting new LayoutParams. This CL also makes ViewRootImpl#setLayoutParams won't modify the caller's LayoutParams. Fix: 175169461 Test: atest ViewRootImplTest Change-Id: I4cdd846e8638f9813146e6461134e4dd1606bd50
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/view/ViewRootImpl.java28
1 files changed, 18 insertions, 10 deletions
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 24989b60cf46..7d309eb36483 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -1389,7 +1389,8 @@ public final class ViewRootImpl implements ViewParent,
return mLocation;
}
- void setLayoutParams(WindowManager.LayoutParams attrs, boolean newView) {
+ @VisibleForTesting
+ public void setLayoutParams(WindowManager.LayoutParams attrs, boolean newView) {
synchronized (this) {
final int oldInsetLeft = mWindowAttributes.surfaceInsets.left;
final int oldInsetTop = mWindowAttributes.surfaceInsets.top;
@@ -1411,13 +1412,15 @@ public final class ViewRootImpl implements ViewParent,
final int compatibleWindowFlag = mWindowAttributes.privateFlags
& WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
- // Transfer over system UI visibility values as they carry current state.
- attrs.systemUiVisibility = mWindowAttributes.systemUiVisibility;
- attrs.subtreeSystemUiVisibility = mWindowAttributes.subtreeSystemUiVisibility;
+ // Preserve system UI visibility.
+ final int systemUiVisibility = mWindowAttributes.systemUiVisibility;
+ final int subtreeSystemUiVisibility = mWindowAttributes.subtreeSystemUiVisibility;
- // Transfer over appearance and behavior values as they carry current state.
- attrs.insetsFlags.appearance = mWindowAttributes.insetsFlags.appearance;
- attrs.insetsFlags.behavior = mWindowAttributes.insetsFlags.behavior;
+ // Preserve appearance and behavior.
+ final int appearance = mWindowAttributes.insetsFlags.appearance;
+ final int behavior = mWindowAttributes.insetsFlags.behavior;
+ final int appearanceAndBehaviorPrivateFlags = mWindowAttributes.privateFlags
+ & (PRIVATE_FLAG_APPEARANCE_CONTROLLED | PRIVATE_FLAG_BEHAVIOR_CONTROLLED);
final int changes = mWindowAttributes.copyFrom(attrs);
if ((changes & WindowManager.LayoutParams.TRANSLUCENT_FLAGS_CHANGED) != 0) {
@@ -1431,10 +1434,15 @@ public final class ViewRootImpl implements ViewParent,
if (mWindowAttributes.packageName == null) {
mWindowAttributes.packageName = mBasePackageName;
}
- mWindowAttributes.privateFlags |= compatibleWindowFlag;
- mWindowAttributes.privateFlags |=
- WindowManager.LayoutParams.PRIVATE_FLAG_USE_BLAST;
+ // Restore preserved flags.
+ mWindowAttributes.systemUiVisibility = systemUiVisibility;
+ mWindowAttributes.subtreeSystemUiVisibility = subtreeSystemUiVisibility;
+ mWindowAttributes.insetsFlags.appearance = appearance;
+ mWindowAttributes.insetsFlags.behavior = behavior;
+ mWindowAttributes.privateFlags |= compatibleWindowFlag
+ | appearanceAndBehaviorPrivateFlags
+ | WindowManager.LayoutParams.PRIVATE_FLAG_USE_BLAST;
if (mWindowAttributes.preservePreviousSurfaceInsets) {
// Restore old surface insets.