From 1d5e29abd5ac0399c5b7f2e3ebb4f3d81582037e Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Tue, 20 Dec 2022 20:22:27 -0500 Subject: [PATCH] Catch error thrown by WindowManager if window has already been detached If the window is already detached, calling `removeView` will throw an error. Bug: 230499241 Test: flashed device and verified systemui no longer crashes Change-Id: I5028744fbb4e701e298b2c9e7d0cf403fead5df9 --- .../com/android/systemui/dreams/DreamOverlayService.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java index 1be9cd1986046..53b003b9893bc 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java @@ -229,6 +229,7 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ * Inserts {@link Window} to host the dream overlay into the dream's parent window. Must be * called from the main executing thread. The window attributes closely mirror those that are * set by the {@link android.service.dreams.DreamService} on the dream Window. + * * @param layoutParams The {@link android.view.WindowManager.LayoutParams} which allow inserting * into the dream window. */ @@ -275,7 +276,11 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ private void resetCurrentDreamOverlayLocked() { if (mStarted && mWindow != null) { - mWindowManager.removeView(mWindow.getDecorView()); + try { + mWindowManager.removeView(mWindow.getDecorView()); + } catch (IllegalArgumentException e) { + Log.e(TAG, "Error removing decor view when resetting overlay", e); + } } mStateController.setOverlayActive(false);