From 0a947d95901688be1b864247dea942b5dff2697c Mon Sep 17 00:00:00 2001 From: chaviw Date: Wed, 27 May 2020 10:09:10 -0700 Subject: [PATCH] Check for null parent when migrating SurfaceControl When migrating the SurfaceControl, the WC parent can be null. In this case, we create a new SurfaceControl, but set it's parent to null so the layer is still available, but will be offscreen. This way if the parent becomes non null, the SC can get re-parented to the new parent. Test: Split screen with removing secondary app Bug: 153579514 Change-Id: Id0e2f2d5e5b7448c3cafd5b90120777f5175153c --- .../com/android/server/wm/WindowContainer.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java index a1fbb597533f0..3fe8229e2ec2c 100644 --- a/services/core/java/com/android/server/wm/WindowContainer.java +++ b/services/core/java/com/android/server/wm/WindowContainer.java @@ -399,7 +399,11 @@ class WindowContainer extends ConfigurationContainer< } void createSurfaceControl(boolean force) { - setSurfaceControl(makeSurface().build()); + setInitialSurfaceControlProperties(makeSurface().build()); + } + + private void setInitialSurfaceControlProperties(SurfaceControl surfaceControl) { + setSurfaceControl(surfaceControl); getPendingTransaction().show(mSurfaceControl); onSurfaceShown(getPendingTransaction()); updateSurfacePosition(); @@ -423,7 +427,16 @@ class WindowContainer extends ConfigurationContainer< // Clear the last position so the new SurfaceControl will get correct position mLastSurfacePosition.set(0, 0); - createSurfaceControl(false /* force */); + final SurfaceControl.Builder b = mWmService.makeSurfaceBuilder(null) + .setContainerLayer() + .setName(getName()); + + setInitialSurfaceControlProperties(b.build()); + + // If parent is null, the layer should be placed offscreen so reparent to null. Otherwise, + // set to the available parent. + t.reparent(mSurfaceControl, mParent == null ? null : mParent.getSurfaceControl()); + if (mLastRelativeToLayer != null) { t.setRelativeLayer(mSurfaceControl, mLastRelativeToLayer, mLastLayer); } else {