From 871cd8fca444d20ba408c16b600242956f05e458 Mon Sep 17 00:00:00 2001 From: Bryce Lee Date: Wed, 29 Mar 2023 19:37:33 -0700 Subject: [PATCH] Do not process root surface control of detached views. This changelist ensures that TouchInsetManager does not attempt to process the root surface control of detached views, which will be null. Test: TouchInsetManagerTest#testViewOnDetachedHandling Fixes: 276012096 Change-Id: I8d2953263925a6068100305272f9ea7be7c5c49d --- .../android/systemui/touch/TouchInsetManager.java | 12 +++++++++--- .../systemui/touch/TouchInsetManagerTest.java | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/touch/TouchInsetManager.java b/packages/SystemUI/src/com/android/systemui/touch/TouchInsetManager.java index f09b2f76e38c4..757b4e50c3f8f 100644 --- a/packages/SystemUI/src/com/android/systemui/touch/TouchInsetManager.java +++ b/packages/SystemUI/src/com/android/systemui/touch/TouchInsetManager.java @@ -108,13 +108,18 @@ public class TouchInsetManager { private void updateTouchRegions() { mExecutor.execute(() -> { final HashMap affectedSurfaces = new HashMap<>(); + if (mTrackedViews.isEmpty()) { + return; + } + mTrackedViews.stream().forEach(view -> { - if (!view.isAttachedToWindow()) { + final AttachedSurfaceControl surface = view.getRootSurfaceControl(); + + // Detached views will not have a surface control. + if (surface == null) { return; } - final AttachedSurfaceControl surface = view.getRootSurfaceControl(); - if (!affectedSurfaces.containsKey(surface)) { affectedSurfaces.put(surface, Region.obtain()); } @@ -179,6 +184,7 @@ public class TouchInsetManager { mSessionRegions.values().stream().forEach(regionMapping -> { regionMapping.entrySet().stream().forEach(entry -> { final AttachedSurfaceControl surface = entry.getKey(); + if (!affectedSurfaces.containsKey(surface)) { affectedSurfaces.put(surface, Region.obtain()); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/touch/TouchInsetManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/touch/TouchInsetManagerTest.java index 667099718788f..eb932d29bf5bc 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/touch/TouchInsetManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/touch/TouchInsetManagerTest.java @@ -110,13 +110,14 @@ public class TouchInsetManagerTest extends SysuiTestCase { clearInvocations(mAttachedSurfaceControl); when(view.isAttachedToWindow()).thenReturn(false); + when(view.getRootSurfaceControl()).thenReturn(null); // Trigger detachment and verify touchable region is set. listener.getValue().onViewDetachedFromWindow(view); mFakeExecutor.runAllReady(); - verify(mAttachedSurfaceControl).setTouchableRegion(any()); + verify(mAttachedSurfaceControl).setTouchableRegion(eq(null)); } @Test