From 8013720af9d780510995022f1fc29344e09495bb Mon Sep 17 00:00:00 2001 From: Chris Li Date: Tue, 4 Jan 2022 16:25:04 +0800 Subject: [PATCH] Catch exception when add immersive confirmation Before, when the display is removed before the immersive window is added, there can be an InvalidDisplayException. Bug: 188107066 Test: pass existing Change-Id: Ic4988b56c0ff739d9866b142bc26160e9499d2b6 --- .../com/android/server/wm/DisplayPolicy.java | 1 + .../server/wm/ImmersiveModeConfirmation.java | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java index 49a51d528422e..4b29c2ffc9e5f 100644 --- a/services/core/java/com/android/server/wm/DisplayPolicy.java +++ b/services/core/java/com/android/server/wm/DisplayPolicy.java @@ -2821,6 +2821,7 @@ public class DisplayPolicy { void release() { mHandler.post(mGestureNavigationSettingsObserver::unregister); + mImmersiveModeConfirmation.release(); } @VisibleForTesting diff --git a/services/core/java/com/android/server/wm/ImmersiveModeConfirmation.java b/services/core/java/com/android/server/wm/ImmersiveModeConfirmation.java index f3b9cdfd39e07..93bdf16a99eae 100644 --- a/services/core/java/com/android/server/wm/ImmersiveModeConfirmation.java +++ b/services/core/java/com/android/server/wm/ImmersiveModeConfirmation.java @@ -149,6 +149,11 @@ public class ImmersiveModeConfirmation { } } + void release() { + mHandler.removeMessages(H.SHOW); + mHandler.removeMessages(H.HIDE); + } + boolean onSettingChanged(int currentUserId) { final boolean changed = loadSetting(currentUserId, mContext); // Remove the window if the setting changes to be confirmed. @@ -204,7 +209,12 @@ public class ImmersiveModeConfirmation { if (mClingWindow != null) { if (DEBUG) Slog.d(TAG, "Hiding immersive mode confirmation"); // We don't care which root display area the window manager is specifying for removal. - getWindowManager(FEATURE_UNDEFINED).removeView(mClingWindow); + try { + getWindowManager(FEATURE_UNDEFINED).removeView(mClingWindow); + } catch (WindowManager.InvalidDisplayException e) { + Slog.w(TAG, "Fail to hide the immersive confirmation window because of " + e); + return; + } mClingWindow = null; } } @@ -432,7 +442,11 @@ public class ImmersiveModeConfirmation { // show the confirmation WindowManager.LayoutParams lp = getClingWindowLayoutParams(); - getWindowManager(rootDisplayAreaId).addView(mClingWindow, lp); + try { + getWindowManager(rootDisplayAreaId).addView(mClingWindow, lp); + } catch (WindowManager.InvalidDisplayException e) { + Slog.w(TAG, "Fail to show the immersive confirmation window because of " + e); + } } private final Runnable mConfirm = new Runnable() {