diff options
| author | 2024-01-29 22:05:33 +0000 | |
|---|---|---|
| committer | 2024-01-29 22:06:31 +0000 | |
| commit | 72b40d8fdf30bf16b0949871b7194d98cbd4cbee (patch) | |
| tree | e32a419368db94a7801f0e6eab404f342401977b | |
| parent | 684e0da6246202e2943af1f39ee6ab0fb8710f94 (diff) | |
Prevent adding duplicate overlays
- Hypothetical fix: check for duplicate overlay before adding it to the
overlay list, otherwise we may attempt to release the same overlay
twice when cleaning up the overlay later. We keep the rest of the
setup just to keep it consistent with adding a new overlay though.
- Hold the wm lock when checking the overlay surface package state
as in ag/25193528 to ensure it's also valid for the duration of the
WM code running
Bug: 314880864
Test: atest TrustedOverlayTests
Change-Id: Ib7cad1a2265ba82dd1d98b8358380874f9f8719d
Signed-off-by: Winson Chung <winsonc@google.com>
| -rw-r--r-- | services/core/java/com/android/server/wm/TrustedOverlayHost.java | 12 | ||||
| -rw-r--r-- | services/core/java/com/android/server/wm/WindowManagerService.java | 9 |
2 files changed, 16 insertions, 5 deletions
diff --git a/services/core/java/com/android/server/wm/TrustedOverlayHost.java b/services/core/java/com/android/server/wm/TrustedOverlayHost.java index f8edc2b871be..debe7946dc95 100644 --- a/services/core/java/com/android/server/wm/TrustedOverlayHost.java +++ b/services/core/java/com/android/server/wm/TrustedOverlayHost.java @@ -88,7 +88,17 @@ class TrustedOverlayHost { void addOverlay(SurfaceControlViewHost.SurfacePackage p, SurfaceControl currentParent) { requireOverlaySurfaceControl(); - mOverlays.add(p); + + boolean hasExistingOverlay = false; + for (int i = mOverlays.size() - 1; i >= 0; i--) { + SurfaceControlViewHost.SurfacePackage l = mOverlays.get(i); + if (l.getSurfaceControl().isSameSurface(p.getSurfaceControl())) { + hasExistingOverlay = true; + } + } + if (!hasExistingOverlay) { + mOverlays.add(p); + } SurfaceControl.Transaction t = mWmService.mTransactionFactory.get(); t.reparent(p.getSurfaceControl(), mSurfaceControl) diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 426694d178af..5db2a5304b3b 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -8468,12 +8468,13 @@ public class WindowManagerService extends IWindowManager.Stub SurfaceControlViewHost.SurfacePackage overlay) { if (overlay == null) { throw new IllegalArgumentException("Invalid overlay passed in for task=" + taskId); - } else if (overlay.getSurfaceControl() == null - || !overlay.getSurfaceControl().isValid()) { - throw new IllegalArgumentException( - "Invalid overlay surfacecontrol passed in for task=" + taskId); } synchronized (mGlobalLock) { + if (overlay.getSurfaceControl() == null + || !overlay.getSurfaceControl().isValid()) { + throw new IllegalArgumentException( + "Invalid overlay surfacecontrol passed in for task=" + taskId); + } final Task task = mRoot.getRootTask(taskId); if (task == null) { throw new IllegalArgumentException("no task with taskId" + taskId); |