Merge "Remove redundant RectInsetsSourceProvider" into udc-dev
This commit is contained in:
@@ -5153,12 +5153,12 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
|
||||
|
||||
@Override
|
||||
void updateAboveInsetsState(InsetsState aboveInsetsState,
|
||||
SparseArray<InsetsSourceProvider> localInsetsSourceProvidersFromParent,
|
||||
SparseArray<InsetsSource> localInsetsSourcesFromParent,
|
||||
ArraySet<WindowState> insetsChangedWindows) {
|
||||
if (skipImeWindowsDuringTraversal(mDisplayContent)) {
|
||||
return;
|
||||
}
|
||||
super.updateAboveInsetsState(aboveInsetsState, localInsetsSourceProvidersFromParent,
|
||||
super.updateAboveInsetsState(aboveInsetsState, localInsetsSourcesFromParent,
|
||||
insetsChangedWindows);
|
||||
}
|
||||
|
||||
|
||||
@@ -161,14 +161,15 @@ class InsetsStateController {
|
||||
final InsetsState aboveInsetsState = new InsetsState();
|
||||
aboveInsetsState.set(mState,
|
||||
displayCutout() | systemGestures() | mandatorySystemGestures());
|
||||
final SparseArray<InsetsSource> localInsetsSourcesFromParent = new SparseArray<>();
|
||||
final ArraySet<WindowState> insetsChangedWindows = new ArraySet<>();
|
||||
final SparseArray<InsetsSourceProvider>
|
||||
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));
|
||||
|
||||
@@ -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().");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,15 +157,14 @@ class WindowContainer<E extends 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<InsetsSourceProvider> mLocalInsetsSourceProviders = null;
|
||||
SparseArray<InsetsSource> mLocalInsetsSources = null;
|
||||
|
||||
@Nullable
|
||||
protected InsetsSourceProvider mControllableInsetProvider;
|
||||
@@ -374,49 +373,46 @@ class WindowContainer<E extends 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<InsetsSourceProvider> localInsetsSourceProvidersFromParent,
|
||||
SparseArray<InsetsSource> localInsetsSourcesFromParent,
|
||||
ArraySet<WindowState> insetsChangedWindows) {
|
||||
SparseArray<InsetsSourceProvider> 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<InsetsSource> 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 <T> SparseArray<T> createShallowCopy(SparseArray<T> inputArray) {
|
||||
SparseArray<T> copyOfInput = new SparseArray<>(inputArray.size());
|
||||
for (int i = 0; i < inputArray.size(); i++) {
|
||||
copyOfInput.append(inputArray.keyAt(i), inputArray.valueAt(i));
|
||||
static <T> SparseArray<T> createMergedSparseArray(SparseArray<T> sa1, SparseArray<T> sa2) {
|
||||
final int size1 = sa1 != null ? sa1.size() : 0;
|
||||
final int size2 = sa2 != null ? sa2.size() : 0;
|
||||
final SparseArray<T> 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<E extends 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<E extends 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<E extends 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<E extends 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4495,20 +4495,10 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
|
||||
|
||||
@Override
|
||||
void updateAboveInsetsState(InsetsState aboveInsetsState,
|
||||
SparseArray<InsetsSourceProvider> localInsetsSourceProvidersFromParent,
|
||||
SparseArray<InsetsSource> localInsetsSourcesFromParent,
|
||||
ArraySet<WindowState> insetsChangedWindows) {
|
||||
SparseArray<InsetsSourceProvider> 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<InsetsSource> mergedLocalInsetsSourcesFromParent =
|
||||
toInsetsSources(mergedLocalInsetsSourceProviders);
|
||||
final SparseArray<InsetsSource> 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<WindowState> 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<WindowState> implements WindowManagerP
|
||||
}, true /* traverseTopToBottom */);
|
||||
}
|
||||
|
||||
private static SparseArray<InsetsSource> toInsetsSources(
|
||||
SparseArray<InsetsSourceProvider> insetsSourceProviders) {
|
||||
final SparseArray<InsetsSource> 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<WindowState> 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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user