Loading packages/SystemUI/src/com/android/systemui/ambient/touch/TouchMonitor.java +9 −6 Original line number Diff line number Diff line Loading @@ -323,12 +323,15 @@ public class TouchMonitor { // When we stop monitoring touches, we must ensure that all active touch sessions and // descendants informed of the removal so any cleanup for active tracking can proceed. mMainExecutor.execute(() -> mActiveTouchSessions.forEach(touchSession -> { mMainExecutor.execute(() -> { mActiveTouchSessions.forEach(touchSession -> { while (touchSession != null) { touchSession.onRemoved(); touchSession = touchSession.getPredecessor(); } })); }); mActiveTouchSessions.clear(); }); mCurrentInputSession.dispose(); mCurrentInputSession = null; Loading packages/SystemUI/tests/src/com/android/systemui/ambient/touch/TouchMonitorTest.java +34 −1 Original line number Diff line number Diff line Loading @@ -211,6 +211,40 @@ public class TouchMonitorTest extends SysuiTestCase { } } @Test public void testSessionResetOnLifecycle() { final TouchHandler touchHandler = createTouchHandler(); final Rect touchArea = new Rect(4, 4, 8 , 8); doAnswer(invocation -> { final Region region = (Region) invocation.getArguments()[1]; region.set(touchArea); return null; }).when(touchHandler).getTouchInitiationRegion(any(), any(), any()); final Environment environment = new Environment(Stream.of(touchHandler) .collect(Collectors.toCollection(HashSet::new)), mKosmos); // Ensure touch outside specified region is not delivered. final MotionEvent initialEvent = Mockito.mock(MotionEvent.class); // Make sure touch inside region causes session start. when(initialEvent.getX()).thenReturn(5.0f); when(initialEvent.getY()).thenReturn(5.0f); environment.publishInputEvent(initialEvent); verify(touchHandler).onSessionStart(any()); Mockito.clearInvocations(touchHandler); // Reset lifecycle, forcing monitoring to be reset environment.updateLifecycle(Lifecycle.State.STARTED); environment.updateLifecycle(Lifecycle.State.RESUMED); environment.executeAll(); environment.publishInputEvent(initialEvent); verify(touchHandler).onSessionStart(any()); } @Test @EnableFlags(Flags.FLAG_AMBIENT_TOUCH_MONITOR_LISTEN_TO_DISPLAY_CHANGES) public void testConfigurationListenerUpdatesBounds() { Loading Loading @@ -332,7 +366,6 @@ public class TouchMonitorTest extends SysuiTestCase { } } @Test public void testNoActiveSessionWhenHandlerDisabled() { final TouchHandler touchHandler = Mockito.mock(TouchHandler.class); Loading Loading
packages/SystemUI/src/com/android/systemui/ambient/touch/TouchMonitor.java +9 −6 Original line number Diff line number Diff line Loading @@ -323,12 +323,15 @@ public class TouchMonitor { // When we stop monitoring touches, we must ensure that all active touch sessions and // descendants informed of the removal so any cleanup for active tracking can proceed. mMainExecutor.execute(() -> mActiveTouchSessions.forEach(touchSession -> { mMainExecutor.execute(() -> { mActiveTouchSessions.forEach(touchSession -> { while (touchSession != null) { touchSession.onRemoved(); touchSession = touchSession.getPredecessor(); } })); }); mActiveTouchSessions.clear(); }); mCurrentInputSession.dispose(); mCurrentInputSession = null; Loading
packages/SystemUI/tests/src/com/android/systemui/ambient/touch/TouchMonitorTest.java +34 −1 Original line number Diff line number Diff line Loading @@ -211,6 +211,40 @@ public class TouchMonitorTest extends SysuiTestCase { } } @Test public void testSessionResetOnLifecycle() { final TouchHandler touchHandler = createTouchHandler(); final Rect touchArea = new Rect(4, 4, 8 , 8); doAnswer(invocation -> { final Region region = (Region) invocation.getArguments()[1]; region.set(touchArea); return null; }).when(touchHandler).getTouchInitiationRegion(any(), any(), any()); final Environment environment = new Environment(Stream.of(touchHandler) .collect(Collectors.toCollection(HashSet::new)), mKosmos); // Ensure touch outside specified region is not delivered. final MotionEvent initialEvent = Mockito.mock(MotionEvent.class); // Make sure touch inside region causes session start. when(initialEvent.getX()).thenReturn(5.0f); when(initialEvent.getY()).thenReturn(5.0f); environment.publishInputEvent(initialEvent); verify(touchHandler).onSessionStart(any()); Mockito.clearInvocations(touchHandler); // Reset lifecycle, forcing monitoring to be reset environment.updateLifecycle(Lifecycle.State.STARTED); environment.updateLifecycle(Lifecycle.State.RESUMED); environment.executeAll(); environment.publishInputEvent(initialEvent); verify(touchHandler).onSessionStart(any()); } @Test @EnableFlags(Flags.FLAG_AMBIENT_TOUCH_MONITOR_LISTEN_TO_DISPLAY_CHANGES) public void testConfigurationListenerUpdatesBounds() { Loading Loading @@ -332,7 +366,6 @@ public class TouchMonitorTest extends SysuiTestCase { } } @Test public void testNoActiveSessionWhenHandlerDisabled() { final TouchHandler touchHandler = Mockito.mock(TouchHandler.class); Loading