diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 1604c2a0343be..a74a40a393ca3 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -5154,12 +5154,12 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp @Override void updateAboveInsetsState(InsetsState aboveInsetsState, - SparseArray localInsetsSourceProvidersFromParent, + SparseArray localInsetsSourcesFromParent, ArraySet insetsChangedWindows) { if (skipImeWindowsDuringTraversal(mDisplayContent)) { return; } - super.updateAboveInsetsState(aboveInsetsState, localInsetsSourceProvidersFromParent, + super.updateAboveInsetsState(aboveInsetsState, localInsetsSourcesFromParent, insetsChangedWindows); } diff --git a/services/core/java/com/android/server/wm/InsetsStateController.java b/services/core/java/com/android/server/wm/InsetsStateController.java index e4ffb8de46e04..fca333d337314 100644 --- a/services/core/java/com/android/server/wm/InsetsStateController.java +++ b/services/core/java/com/android/server/wm/InsetsStateController.java @@ -161,14 +161,15 @@ class InsetsStateController { final InsetsState aboveInsetsState = new InsetsState(); aboveInsetsState.set(mState, displayCutout() | systemGestures() | mandatorySystemGestures()); + final SparseArray localInsetsSourcesFromParent = new SparseArray<>(); final ArraySet insetsChangedWindows = new ArraySet<>(); - final SparseArray - localInsetsSourceProvidersFromParent = new SparseArray<>(); + // This method will iterate on the entire hierarchy in top to bottom z-order manner. The // aboveInsetsState will be modified as per the insets provided by the WindowState being // visited. - mDisplayContent.updateAboveInsetsState(aboveInsetsState, - localInsetsSourceProvidersFromParent, insetsChangedWindows); + mDisplayContent.updateAboveInsetsState(aboveInsetsState, localInsetsSourcesFromParent, + insetsChangedWindows); + if (notifyInsetsChange) { for (int i = insetsChangedWindows.size() - 1; i >= 0; i--) { mDispatchInsetsChanged.accept(insetsChangedWindows.valueAt(i)); diff --git a/services/core/java/com/android/server/wm/RectInsetsSourceProvider.java b/services/core/java/com/android/server/wm/RectInsetsSourceProvider.java deleted file mode 100644 index 6e8beee86576d..0000000000000 --- a/services/core/java/com/android/server/wm/RectInsetsSourceProvider.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.server.wm; - -import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; -import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; - -import android.graphics.Rect; -import android.util.Slog; -import android.view.InsetsSource; - -/** - * An {@link InsetsSourceProvider} which doesn't have a backing window or a window container. - */ -public class RectInsetsSourceProvider extends InsetsSourceProvider { - private static final String TAG = TAG_WITH_CLASS_NAME - ? RectInsetsSourceProvider.class.getSimpleName() - : TAG_WM; - - RectInsetsSourceProvider(InsetsSource source, - InsetsStateController stateController, DisplayContent displayContent) { - super(source, stateController, displayContent); - } - - /** - * Sets the given {@code rect} as the frame of the underlying {@link InsetsSource}. - */ - void setRect(Rect rect) { - mSource.setFrame(rect); - mSource.setVisible(true); - } - - @Override - void onPostLayout() { - if (WindowManagerDebugConfig.DEBUG) { - Slog.d(TAG, "onPostLayout(), not calling super.onPostLayout()."); - } - } -} diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java index bd0344faa0785..2e217820c264c 100644 --- a/services/core/java/com/android/server/wm/WindowContainer.java +++ b/services/core/java/com/android/server/wm/WindowContainer.java @@ -157,15 +157,14 @@ class WindowContainer extends ConfigurationContainer< boolean mReparenting; /** - * Map of {@link InsetsState.InternalInsetsType} to the {@link InsetsSourceProvider} that - * provides local insets for all children of the current {@link WindowContainer}. - * - * Note that these InsetsSourceProviders are not part of the {@link InsetsStateController} and - * live here. These are supposed to provide insets only to the subtree of the current + * Map of the source ID to the {@link InsetsSource} for all children of the current * {@link WindowContainer}. + * + * Note that these sources are not part of the {@link InsetsStateController} and live here. + * These are supposed to provide insets only to the subtree of this {@link WindowContainer}. */ @Nullable - SparseArray mLocalInsetsSourceProviders = null; + SparseArray mLocalInsetsSources = null; @Nullable protected InsetsSourceProvider mControllableInsetProvider; @@ -374,49 +373,46 @@ class WindowContainer extends ConfigurationContainer< * {@link WindowState}s below it. * * {@link WindowState#mMergedLocalInsetsSources} is updated by considering - * {@link WindowContainer#mLocalInsetsSourceProviders} provided by all the parents of the - * window. - * A given insetsType can be provided as a LocalInsetsSourceProvider only once in a - * Parent-to-leaf path. + * {@link WindowContainer#mLocalInsetsSources} provided by all the parents of the window. * * Examples: Please take a look at * {@link WindowContainerTests#testAddLocalInsetsSourceProvider()} - * {@link - * WindowContainerTests#testAddLocalInsetsSourceProvider_windowSkippedIfProvidingOnParent()} * {@link WindowContainerTests#testRemoveLocalInsetsSourceProvider()}. * - * @param aboveInsetsState The InsetsState of all the Windows above the current container. - * @param localInsetsSourceProvidersFromParent The local InsetsSourceProviders provided by all - * the parents in the hierarchy of the current - * container. - * @param insetsChangedWindows The windows which the insets changed have changed for. + * @param aboveInsetsState The InsetsState of all the Windows above the current + * container. + * @param localInsetsSourcesFromParent The local InsetsSourceProviders provided by all + * the parents in the hierarchy of the current + * container. + * @param insetsChangedWindows The windows which the insets changed have changed for. */ void updateAboveInsetsState(InsetsState aboveInsetsState, - SparseArray localInsetsSourceProvidersFromParent, + SparseArray localInsetsSourcesFromParent, ArraySet insetsChangedWindows) { - SparseArray mergedLocalInsetsSourceProviders = - localInsetsSourceProvidersFromParent; - if (mLocalInsetsSourceProviders != null && mLocalInsetsSourceProviders.size() != 0) { - mergedLocalInsetsSourceProviders = createShallowCopy(mergedLocalInsetsSourceProviders); - for (int i = 0; i < mLocalInsetsSourceProviders.size(); i++) { - mergedLocalInsetsSourceProviders.put( - mLocalInsetsSourceProviders.keyAt(i), - mLocalInsetsSourceProviders.valueAt(i)); - } - } + final SparseArray mergedLocalInsetsSources = + createMergedSparseArray(localInsetsSourcesFromParent, mLocalInsetsSources); for (int i = mChildren.size() - 1; i >= 0; --i) { - mChildren.get(i).updateAboveInsetsState(aboveInsetsState, - mergedLocalInsetsSourceProviders, insetsChangedWindows); + mChildren.get(i).updateAboveInsetsState(aboveInsetsState, mergedLocalInsetsSources, + insetsChangedWindows); } } - static SparseArray createShallowCopy(SparseArray inputArray) { - SparseArray copyOfInput = new SparseArray<>(inputArray.size()); - for (int i = 0; i < inputArray.size(); i++) { - copyOfInput.append(inputArray.keyAt(i), inputArray.valueAt(i)); + static SparseArray createMergedSparseArray(SparseArray sa1, SparseArray sa2) { + final int size1 = sa1 != null ? sa1.size() : 0; + final int size2 = sa2 != null ? sa2.size() : 0; + final SparseArray mergedArray = new SparseArray<>(size1 + size2); + if (size1 > 0) { + for (int i = 0; i < size1; i++) { + mergedArray.append(sa1.keyAt(i), sa1.valueAt(i)); + } } - return copyOfInput; + if (size2 > 0) { + for (int i = 0; i < size2; i++) { + mergedArray.put(sa2.keyAt(i), sa2.valueAt(i)); + } + } + return mergedArray; } /** @@ -433,25 +429,23 @@ class WindowContainer extends ConfigurationContainer< // 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); + Slog.w(TAG, "Can't add insets frame provider when detached. " + this); return; } - if (mLocalInsetsSourceProviders == null) { - mLocalInsetsSourceProviders = new SparseArray<>(); + if (mLocalInsetsSources == null) { + mLocalInsetsSources = new SparseArray<>(); } final int id = InsetsSource.createId( provider.getOwner(), provider.getIndex(), provider.getType()); - if (mLocalInsetsSourceProviders.get(id) != null) { + if (mLocalInsetsSources.get(id) != null) { if (DEBUG) { - Slog.d(TAG, "The local insets provider for this " + provider - + " already exists. Overwriting"); + Slog.d(TAG, "The local insets source for this " + provider + + " already exists. Overwriting."); } } - final RectInsetsSourceProvider insetsSourceProvider = new RectInsetsSourceProvider( - new InsetsSource(id, provider.getType()), - mDisplayContent.getInsetsStateController(), mDisplayContent); - mLocalInsetsSourceProviders.put(id, insetsSourceProvider); - insetsSourceProvider.setRect(provider.getArbitraryRectangle()); + final InsetsSource source = new InsetsSource(id, provider.getType()); + source.setFrame(provider.getArbitraryRectangle()); + mLocalInsetsSources.put(id, source); mDisplayContent.getInsetsStateController().updateAboveInsetsState(true); } @@ -459,20 +453,19 @@ class WindowContainer extends ConfigurationContainer< if (provider == null) { throw new IllegalArgumentException("Insets type not specified."); } - if (mLocalInsetsSourceProviders == null) { + if (mLocalInsetsSources == null) { return; } final int id = InsetsSource.createId( provider.getOwner(), provider.getIndex(), provider.getType()); - if (mLocalInsetsSourceProviders.get(id) == null) { + if (mLocalInsetsSources.get(id) == null) { if (DEBUG) { - Slog.d(TAG, "Given " + provider - + " doesn't have a local insetsSourceProvider."); + Slog.d(TAG, "Given " + provider + " doesn't have a local insets source."); } return; } - mLocalInsetsSourceProviders.remove(id); + mLocalInsetsSources.remove(id); // Update insets if this window is attached. if (mDisplayContent != null) { @@ -1014,8 +1007,8 @@ class WindowContainer extends ConfigurationContainer< if (dc != null && dc != this) { dc.getPendingTransaction().merge(mPendingTransaction); } - if (dc != this && mLocalInsetsSourceProviders != null) { - mLocalInsetsSourceProviders.clear(); + if (dc != this && mLocalInsetsSources != null) { + mLocalInsetsSources.clear(); } for (int i = mChildren.size() - 1; i >= 0; --i) { final WindowContainer child = mChildren.get(i); @@ -3555,11 +3548,11 @@ class WindowContainer extends ConfigurationContainer< pw.println(prefix + "mLastOrientationSource=" + mLastOrientationSource); pw.println(prefix + "deepestLastOrientationSource=" + getLastOrientationSource()); } - if (mLocalInsetsSourceProviders != null && mLocalInsetsSourceProviders.size() != 0) { - pw.println(prefix + mLocalInsetsSourceProviders.size() + " LocalInsetsSourceProviders"); + if (mLocalInsetsSources != null && mLocalInsetsSources.size() != 0) { + pw.println(prefix + mLocalInsetsSources.size() + " LocalInsetsSources"); final String childPrefix = prefix + " "; - for (int i = 0; i < mLocalInsetsSourceProviders.size(); ++i) { - mLocalInsetsSourceProviders.valueAt(i).dump(pw, childPrefix); + for (int i = 0; i < mLocalInsetsSources.size(); ++i) { + mLocalInsetsSources.valueAt(i).dump(childPrefix, pw); } } } diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 232b817b83140..680f6052f36ab 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -4495,20 +4495,10 @@ class WindowState extends WindowContainer implements WindowManagerP @Override void updateAboveInsetsState(InsetsState aboveInsetsState, - SparseArray localInsetsSourceProvidersFromParent, + SparseArray localInsetsSourcesFromParent, ArraySet insetsChangedWindows) { - SparseArray mergedLocalInsetsSourceProviders = - localInsetsSourceProvidersFromParent; - if (mLocalInsetsSourceProviders != null && mLocalInsetsSourceProviders.size() != 0) { - mergedLocalInsetsSourceProviders = createShallowCopy(mergedLocalInsetsSourceProviders); - for (int i = 0; i < mLocalInsetsSourceProviders.size(); i++) { - mergedLocalInsetsSourceProviders.put( - mLocalInsetsSourceProviders.keyAt(i), - mLocalInsetsSourceProviders.valueAt(i)); - } - } - final SparseArray mergedLocalInsetsSourcesFromParent = - toInsetsSources(mergedLocalInsetsSourceProviders); + final SparseArray mergedLocalInsetsSources = + createMergedSparseArray(localInsetsSourcesFromParent, mLocalInsetsSources); // Insets provided by the IME window can effect all the windows below it and hence it needs // to be visited in the correct order. Because of which updateAboveInsetsState() can't be @@ -4519,9 +4509,8 @@ class WindowState extends WindowContainer implements WindowManagerP insetsChangedWindows.add(w); } - if (!mergedLocalInsetsSourcesFromParent.contentEquals(w.mMergedLocalInsetsSources)) { - w.mMergedLocalInsetsSources = createShallowCopy( - mergedLocalInsetsSourcesFromParent); + if (!mergedLocalInsetsSources.contentEquals(w.mMergedLocalInsetsSources)) { + w.mMergedLocalInsetsSources = mergedLocalInsetsSources; insetsChangedWindows.add(w); } @@ -4534,17 +4523,6 @@ class WindowState extends WindowContainer implements WindowManagerP }, true /* traverseTopToBottom */); } - private static SparseArray toInsetsSources( - SparseArray insetsSourceProviders) { - final SparseArray insetsSources = new SparseArray<>( - insetsSourceProviders.size()); - for (int i = 0; i < insetsSourceProviders.size(); i++) { - insetsSources.append(insetsSourceProviders.keyAt(i), - insetsSourceProviders.valueAt(i).getSource()); - } - return insetsSources; - } - private boolean forAllWindowTopToBottom(ToBooleanFunction callback) { // We want to consume the positive sublayer children first because they need to appear // above the parent, then this window (the parent), and then the negative sublayer children diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowOrganizerTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowOrganizerTests.java index 373f994f83a48..d19c996ce939d 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowOrganizerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowOrganizerTests.java @@ -801,8 +801,8 @@ public class WindowOrganizerTests extends WindowTestsBase { new Rect(0, 0, 1080, 200)); mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct); - assertThat(navigationBarInsetsReceiverTask.mLocalInsetsSourceProviders - .valueAt(0).getSource().getType()).isEqualTo( + assertThat(navigationBarInsetsReceiverTask.mLocalInsetsSources + .valueAt(0).getType()).isEqualTo( WindowInsets.Type.systemOverlays()); } @@ -831,7 +831,7 @@ public class WindowOrganizerTests extends WindowTestsBase { WindowInsets.Type.systemOverlays()); mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct2); - assertThat(navigationBarInsetsReceiverTask.mLocalInsetsSourceProviders.size()).isEqualTo(0); + assertThat(navigationBarInsetsReceiverTask.mLocalInsetsSources.size()).isEqualTo(0); } @Test