From 8379b15dc569f851c807146a19dda7186d8065df Mon Sep 17 00:00:00 2001 From: Bryce Lee Date: Mon, 23 Aug 2021 16:24:01 -0700 Subject: [PATCH] Always reparent SurfacePackage in setChildSurfacePackage. Currently, SurfaceView#setChildSurfacePackage only reparents a provided SurfacePackage when there is no SurfaceControl already present. This can lead to the SurfacePackage potentially never being reparented. This changelist addresses the issue by always reparenting the SurfacePackage, following cleanup of the existing SurfaceControl. Bug: 197568243 Test: atest SurfaceControlViewHostTests#testCanReplaceSurfacePackage Change-Id: Ib0bcfee5cb9801e1b1c4f1f300af9862141b12f3 --- core/java/android/view/SurfaceView.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java index a4e7a43cc9347..643c1bc68d2cf 100644 --- a/core/java/android/view/SurfaceView.java +++ b/core/java/android/view/SurfaceView.java @@ -1889,10 +1889,12 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall public void setChildSurfacePackage(@NonNull SurfaceControlViewHost.SurfacePackage p) { final SurfaceControl lastSc = mSurfacePackage != null ? mSurfacePackage.getSurfaceControl() : null; - if (mSurfaceControl != null && lastSc != null) { - mTmpTransaction.reparent(lastSc, null).apply(); - mSurfacePackage.release(); - } else if (mSurfaceControl != null) { + if (mSurfaceControl != null) { + if (lastSc != null) { + mTmpTransaction.reparent(lastSc, null); + mSurfacePackage.release(); + } + reparentSurfacePackage(mTmpTransaction, p); mTmpTransaction.apply(); }