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
This commit is contained in:
Lucas Silva
2022-12-20 20:22:27 -05:00
parent e04adb101e
commit 1d5e29abd5

View File

@@ -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);