diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java index b810d9440b1dd..bce131b6700b7 100644 --- a/services/core/java/com/android/server/wm/WindowContainer.java +++ b/services/core/java/com/android/server/wm/WindowContainer.java @@ -429,6 +429,13 @@ class WindowContainer extends ConfigurationContainer< if (insetsTypes == null || insetsTypes.length == 0) { throw new IllegalArgumentException("Insets type not specified."); } + if (mDisplayContent == null) { + // This is possible this container is detached when WM shell is responding to a previous + // request. WM shell will be updated when this container is attached again and the + // insets need to be updated. + Slog.w(TAG, "Can't add local rect insets source provider when detached. " + this); + return; + } if (mLocalInsetsSourceProviders == null) { mLocalInsetsSourceProviders = new SparseArray<>(); } @@ -1014,6 +1021,9 @@ class WindowContainer extends ConfigurationContainer< if (dc != null && dc != this) { dc.getPendingTransaction().merge(mPendingTransaction); } + if (dc != this && mLocalInsetsSourceProviders != null) { + mLocalInsetsSourceProviders.clear(); + } for (int i = mChildren.size() - 1; i >= 0; --i) { final WindowContainer child = mChildren.get(i); child.onDisplayChanged(dc);