Change to use ConfigurationContainer.onParentChanged
Reduce duplicated code and also fix crash of WindowContainerTests
(testAddChildSetsSurfacePosition replaces the transaction factory)
by restoring the original surface transaction factory because the
WMS instance is shared.
Fixes: 123624626
Test: atest WindowContainerTests
Change-Id: Icf39aa074c2d91eda2ad07bd22e5ff751e48ba46
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index a52f1af..ebb61f2 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -978,8 +978,8 @@
}
@Override
- void onParentSet() {
- super.onParentSet();
+ void onParentChanged() {
+ super.onParentChanged();
final Task task = getTask();
diff --git a/services/core/java/com/android/server/wm/ConfigurationContainer.java b/services/core/java/com/android/server/wm/ConfigurationContainer.java
index ce3fb51..d86cf0f 100644
--- a/services/core/java/com/android/server/wm/ConfigurationContainer.java
+++ b/services/core/java/com/android/server/wm/ConfigurationContainer.java
@@ -532,7 +532,7 @@
/**
* Must be called when new parent for the container was set.
*/
- protected void onParentChanged() {
+ void onParentChanged() {
final ConfigurationContainer parent = getParent();
// Removing parent usually means that we've detached this entity to destroy it or to attach
// to another parent. In both cases we don't need to update the configuration now.
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index 3426ba6..a1bb303 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -4356,8 +4356,8 @@
}
@Override
- void onParentSet() {
- super.onParentSet();
+ void onParentChanged() {
+ super.onParentChanged();
if (getParent() != null) {
mAppAnimationLayer = makeChildSurface(null)
.setName("animationLayer")
@@ -4612,10 +4612,10 @@
}
@Override
- void onParentSet() {
+ void onParentChanged() {
// Since we are the top of the SurfaceControl hierarchy here
// we create the root surfaces explicitly rather than chaining
- // up as the default implementation in onParentSet does. So we
+ // up as the default implementation in onParentChanged does. So we
// explicitly do NOT call super here.
}
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index 476bd6e..7a86c96 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -252,8 +252,8 @@
}
@Override
- void onParentSet() {
- super.onParentSet();
+ void onParentChanged() {
+ super.onParentChanged();
// Update task bounds if needed.
adjustBoundsForDisplayChangeIfNeeded(getDisplayContent());
diff --git a/services/core/java/com/android/server/wm/TaskStack.java b/services/core/java/com/android/server/wm/TaskStack.java
index 59549e0..2f0adea 100644
--- a/services/core/java/com/android/server/wm/TaskStack.java
+++ b/services/core/java/com/android/server/wm/TaskStack.java
@@ -996,8 +996,8 @@
}
@Override
- void onParentSet() {
- super.onParentSet();
+ void onParentChanged() {
+ super.onParentChanged();
if (getParent() != null || mDisplayContent == null) {
return;
diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java
index 1905877..f330569 100644
--- a/services/core/java/com/android/server/wm/WindowContainer.java
+++ b/services/core/java/com/android/server/wm/WindowContainer.java
@@ -161,23 +161,16 @@
final protected void setParent(WindowContainer<WindowContainer> parent) {
mParent = parent;
- // Removing parent usually means that we've detached this entity to destroy it or to attach
- // to another parent. In both cases we don't need to update the configuration now.
- if (mParent != null) {
- // Update full configuration of this container and all its children.
- onConfigurationChanged(mParent.getConfiguration());
- // Update merged override configuration of this container and all its children.
- onMergedOverrideConfigurationChanged();
- }
-
- onParentSet();
+ onParentChanged();
}
/**
* Callback that is triggered when @link WindowContainer#setParent(WindowContainer)} was called.
* Supposed to be overridden and contain actions that should be executed after parent was set.
*/
- void onParentSet() {
+ @Override
+ void onParentChanged() {
+ super.onParentChanged();
if (mParent == null) {
return;
}
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java
index 4f12010..2613140 100644
--- a/services/core/java/com/android/server/wm/WindowState.java
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -747,8 +747,8 @@
}
@Override
- void onParentSet() {
- super.onParentSet();
+ void onParentChanged() {
+ super.onParentChanged();
setDrawnStateEvaluated(false /*evaluated*/);
getDisplayContent().reapplyMagnificationSpec();
diff --git a/services/tests/wmtests/src/com/android/server/wm/AppChangeTransitionTests.java b/services/tests/wmtests/src/com/android/server/wm/AppChangeTransitionTests.java
index 19ace3c..3bf884f 100644
--- a/services/tests/wmtests/src/com/android/server/wm/AppChangeTransitionTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/AppChangeTransitionTests.java
@@ -55,7 +55,7 @@
mStack = createTaskStackOnDisplay(mDisplayContent);
mTask = createTaskInStack(mStack, 0 /* userId */);
mToken = WindowTestUtils.createTestAppWindowToken(mDisplayContent);
- mToken.mSkipOnParentSet = false;
+ mToken.mSkipOnParentChanged = false;
mTask.addChild(mToken, 0);
}
diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java
index e156143..8628575 100644
--- a/services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java
@@ -103,13 +103,13 @@
assertEquals(secondLayer1, root.getChildAt(5));
assertEquals(layer2, root.getChildAt(6));
- assertTrue(layer1.mOnParentSetCalled);
- assertTrue(secondLayer1.mOnParentSetCalled);
- assertTrue(layer2.mOnParentSetCalled);
- assertTrue(layerNeg1.mOnParentSetCalled);
- assertTrue(layerNeg2.mOnParentSetCalled);
- assertTrue(secondLayerNeg1.mOnParentSetCalled);
- assertTrue(layer0.mOnParentSetCalled);
+ assertTrue(layer1.mOnParentChangedCalled);
+ assertTrue(secondLayer1.mOnParentChangedCalled);
+ assertTrue(layer2.mOnParentChangedCalled);
+ assertTrue(layerNeg1.mOnParentChangedCalled);
+ assertTrue(layerNeg2.mOnParentChangedCalled);
+ assertTrue(secondLayerNeg1.mOnParentChangedCalled);
+ assertTrue(layer0.mOnParentChangedCalled);
}
@Test
@@ -747,7 +747,7 @@
private boolean mFillsParent;
private Integer mOrientation;
- private boolean mOnParentSetCalled;
+ private boolean mOnParentChangedCalled;
private boolean mOnDescendantOverrideCalled;
/**
@@ -801,8 +801,8 @@
}
@Override
- void onParentSet() {
- mOnParentSetCalled = true;
+ void onParentChanged() {
+ mOnParentChangedCalled = true;
}
@Override
diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowTestUtils.java b/services/tests/wmtests/src/com/android/server/wm/WindowTestUtils.java
index 2263cf3..a494889 100644
--- a/services/tests/wmtests/src/com/android/server/wm/WindowTestUtils.java
+++ b/services/tests/wmtests/src/com/android/server/wm/WindowTestUtils.java
@@ -152,7 +152,7 @@
public static class TestAppWindowToken extends AppWindowToken {
boolean mOnTop = false;
private Transaction mPendingTransactionOverride;
- boolean mSkipOnParentSet = true;
+ boolean mSkipOnParentChanged = true;
private TestAppWindowToken(DisplayContent dc) {
super(dc.mWmService, new IApplicationToken.Stub() {
@@ -200,9 +200,11 @@
}
@Override
- void onParentSet() {
- if (!mSkipOnParentSet) {
- super.onParentSet();
+ void onParentChanged() {
+ if (!mSkipOnParentChanged) {
+ super.onParentChanged();
+ } else {
+ updateConfigurationFromParent(this);
}
}
@@ -223,6 +225,21 @@
}
}
+ /**
+ * Used when we don't want to perform surface related operation in
+ * {@link WindowContainer#onParentChanged} or the overridden method, but the configuration
+ * still needs to propagate from parent.
+ *
+ * @see ConfigurationContainer#onParentChanged
+ */
+ static void updateConfigurationFromParent(WindowContainer container) {
+ final WindowContainer parent = container.getParent();
+ if (parent != null) {
+ container.onConfigurationChanged(parent.getConfiguration());
+ container.onMergedOverrideConfigurationChanged();
+ }
+ }
+
static TestWindowToken createTestWindowToken(int type, DisplayContent dc) {
return createTestWindowToken(type, dc, false /* persistOnEmpty */);
}
@@ -341,8 +358,8 @@
}
@Override
- void onParentSet() {
- // Do nothing;
+ void onParentChanged() {
+ updateConfigurationFromParent(this);
}
}
}
diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java b/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java
index e38118e..3cb2814 100644
--- a/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java
+++ b/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java
@@ -91,6 +91,12 @@
WindowState mChildAppWindowBelow;
HashSet<WindowState> mCommonWindows;
+ /**
+ * To restore the original SurfaceControl.Transaction factory if any tests changed
+ * {@link WindowManagerService#mTransactionFactory}.
+ */
+ private TransactionFactory mOriginalTransactionFactory;
+
@Rule
public final DexmakerShareClassLoaderRule mDexmakerShareClassLoaderRule =
new DexmakerShareClassLoaderRule();
@@ -121,6 +127,7 @@
final Context context = getInstrumentation().getTargetContext();
mWm = TestSystemServices.getWindowManagerService();
+ mOriginalTransactionFactory = mWm.mTransactionFactory;
beforeCreateDisplay();
context.getDisplay().getDisplayInfo(mDisplayInfo);
@@ -170,6 +177,7 @@
// stable state to clean up for consistency.
waitUntilHandlersIdle();
+ mWm.mTransactionFactory = mOriginalTransactionFactory;
final LinkedList<WindowState> nonCommonWindows = new LinkedList<>();
synchronized (mWm.mGlobalLock) {