From 02de5054c5691e9425305a73f6210ca2b1cef499 Mon Sep 17 00:00:00 2001 From: Miranda Kephart Date: Thu, 4 Nov 2021 13:49:04 -0400 Subject: [PATCH] Ensure screenshot input monitor is always removed We currently remove and dispose of the input monitor in View.onDetach. However, it's possible for the screenshot process to get frozen before that call actually occurs, which causes an ANR when the screenshot process doesn't actually respond to input events. This change adds a synchronous call to removeWindow to ensure that the input monitor is never left around once the window is removed. Bug: 199592789 Test: manual -- forced a delay in detaching the view and stopping the input listener, verified that the expected crash occurred, and checked that adding the synchronous call fixes the problem Change-Id: I0aff68ce4876082a5e20e3fe5f83cffcda4f6390 --- .../com/android/systemui/screenshot/ScreenshotController.java | 4 ++++ .../src/com/android/systemui/screenshot/ScreenshotView.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java index a0118ab8a312b..6e3d6a8cf7820 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java @@ -776,6 +776,10 @@ public class ScreenshotController { } mWindowManager.removeViewImmediate(decorView); } + // Ensure that we remove the input monitor + if (mScreenshotView != null) { + mScreenshotView.stopInputListening(); + } } /** diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java index 3314c75b5a867..6e9f728cb9271 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java @@ -314,7 +314,7 @@ public class ScreenshotView extends FrameLayout implements }); } - private void stopInputListening() { + void stopInputListening() { if (mInputMonitor != null) { mInputMonitor.dispose(); mInputMonitor = null;