summaryrefslogtreecommitdiff
path: root/core/java/android/view/SurfaceView.java
diff options
context:
space:
mode:
authorVadim Caen <caen@google.com>2021-04-15 14:28:55 +0200
committerVadim Caen <caen@google.com>2021-05-21 13:13:16 +0200
commitdd3687333472d862432210da08d980b331721d0c (patch)
tree9966da8b9f51a1a49e0533fc9c9b81801ba274be /core/java/android/view/SurfaceView.java
parentcb81f1716da2b37f25b38d3bb76ef1a6a3967c1e (diff)
Do not reparent the SC when package is already realeased
If we pass a copy of the surface package, we can release the original, but we need to check that in this case the surface control doesn't get reparented to null since the SurfaceView using the copy might already use the surface. Test: atest CtsWindowManagerDeviceTestCases:SurfaceControlViewHostTests#testTransferSurfacePackage Bug: 181757194 Change-Id: Ibf084aa70f3821e7dc82fe45b194c07f307ebe1e
Diffstat (limited to 'core/java/android/view/SurfaceView.java')
-rw-r--r--core/java/android/view/SurfaceView.java12
1 files changed, 9 insertions, 3 deletions
diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java
index 2fce4348cbb0..6b0bb9df5468 100644
--- a/core/java/android/view/SurfaceView.java
+++ b/core/java/android/view/SurfaceView.java
@@ -571,7 +571,10 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
// recreate this Surface, so only release it when we are fully
// detached.
if (mSurfacePackage != null) {
- mTmpTransaction.reparent(mSurfacePackage.getSurfaceControl(), null).apply();
+ final SurfaceControl sc = mSurfacePackage.getSurfaceControl();
+ if (sc != null && sc.isValid()) {
+ mTmpTransaction.reparent(sc, null).apply();
+ }
mSurfacePackage.release();
mSurfacePackage = null;
}
@@ -1826,7 +1829,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
*/
public void setChildSurfacePackage(@NonNull SurfaceControlViewHost.SurfacePackage p) {
final SurfaceControl lastSc = mSurfacePackage != null ?
- mSurfacePackage.getSurfaceControl() : null;
+ mSurfacePackage.getSurfaceControl() : null;
if (mSurfaceControl != null && lastSc != null) {
mTmpTransaction.reparent(lastSc, null).apply();
mSurfacePackage.release();
@@ -1839,8 +1842,11 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
private void reparentSurfacePackage(SurfaceControl.Transaction t,
SurfaceControlViewHost.SurfacePackage p) {
- initEmbeddedHierarchyForAccessibility(p);
final SurfaceControl sc = p.getSurfaceControl();
+ if (sc == null || !sc.isValid()) {
+ return;
+ }
+ initEmbeddedHierarchyForAccessibility(p);
final SurfaceControl parent;
if (mUseBlastAdapter) {
parent = mBlastSurfaceControl;