From a6e5b8c8b173dad23ca7589d82809725ae190308 Mon Sep 17 00:00:00 2001 From: Yunfan Chen Date: Wed, 26 Oct 2022 16:26:12 +0900 Subject: [PATCH] Do not do anything special to system bars when dispatching insets The new insets system will not report insets above the window, and the insets of the window itself. Besides, the system UI have the flexibility to deal with other types of insets if they want to. The logic of excluding the system bars for system bar windows is no longer needed. Test: InsetsPolicyTest Bug: 243758934 Change-Id: Iebf510b6863c642859d3eb91f3255c67993a3e7d --- .../com/android/server/wm/InsetsPolicy.java | 48 +++++++------------ .../com/android/server/wm/WindowState.java | 8 +--- 2 files changed, 18 insertions(+), 38 deletions(-) diff --git a/services/core/java/com/android/server/wm/InsetsPolicy.java b/services/core/java/com/android/server/wm/InsetsPolicy.java index b9fa80cf2c0f2..7e56dbf5602b7 100644 --- a/services/core/java/com/android/server/wm/InsetsPolicy.java +++ b/services/core/java/com/android/server/wm/InsetsPolicy.java @@ -26,7 +26,6 @@ import static android.view.InsetsController.ANIMATION_TYPE_HIDE; import static android.view.InsetsController.ANIMATION_TYPE_SHOW; import static android.view.InsetsController.LAYOUT_INSETS_DURING_ANIMATION_HIDDEN; import static android.view.InsetsController.LAYOUT_INSETS_DURING_ANIMATION_SHOWN; -import static android.view.InsetsState.ITYPE_CAPTION_BAR; import static android.view.InsetsState.ITYPE_CLIMATE_BAR; import static android.view.InsetsState.ITYPE_EXTRA_NAVIGATION_BAR; import static android.view.InsetsState.ITYPE_IME; @@ -289,9 +288,8 @@ class InsetsPolicy { final boolean alwaysOnTop = token != null && token.isAlwaysOnTop(); // Always use windowing mode fullscreen when get insets for window metrics to make sure it // contains all insets types. - final InsetsState originalState = mDisplayContent.getInsetsPolicy() - .enforceInsetsPolicyForTarget(type, WINDOWING_MODE_FULLSCREEN, alwaysOnTop, - attrs.type, mStateController.getRawInsetsState()); + final InsetsState originalState = enforceInsetsPolicyForTarget(WINDOWING_MODE_FULLSCREEN, + alwaysOnTop, attrs, mStateController.getRawInsetsState()); InsetsState state = adjustVisibilityForTransientTypes(originalState); return adjustInsetsForRoundedCorners(token, state, state == originalState); } @@ -343,56 +341,42 @@ class InsetsPolicy { /** - * Modifies the given {@code state} according to the {@code type} (Inset type) provided by - * the target. - * When performing layout of the target or dispatching insets to the target, we need to exclude - * sources which should not be visible to the target. e.g., the source which represents the - * target window itself, and the IME source when the target is above IME. We also need to - * exclude certain types of insets source for client within specific windowing modes. + * Modifies the given {@code state} according to the target's window state. + * When performing layout of the target or dispatching insets to the target, we need to adjust + * sources based on the target. e.g., the floating window will not receive system bars other + * than caption, and some insets provider may request to override sizes for given window types. + * Since the window type and the insets types provided by the window shall not change at + * runtime, rotation doesn't matter in the layout params. * - * @param type the inset type provided by the target * @param windowingMode the windowing mode of the target * @param isAlwaysOnTop is the target always on top - * @param windowType the type of the target + * @param attrs the layout params of the target * @param state the input inset state containing all the sources * @return The state stripped of the necessary information. */ - InsetsState enforceInsetsPolicyForTarget(@InternalInsetsType int type, - @WindowConfiguration.WindowingMode int windowingMode, boolean isAlwaysOnTop, - int windowType, InsetsState state) { + InsetsState enforceInsetsPolicyForTarget(@WindowConfiguration.WindowingMode int windowingMode, + boolean isAlwaysOnTop, WindowManager.LayoutParams attrs, InsetsState state) { boolean stateCopied = false; - if (type != ITYPE_INVALID) { + if (attrs.providedInsets != null && attrs.providedInsets.length > 0) { state = new InsetsState(state); stateCopied = true; - state.removeSource(type); - - // Navigation bar doesn't get influenced by anything else - if (type == ITYPE_NAVIGATION_BAR || type == ITYPE_EXTRA_NAVIGATION_BAR) { - state.removeSource(ITYPE_STATUS_BAR); - state.removeSource(ITYPE_CLIMATE_BAR); - state.removeSource(ITYPE_CAPTION_BAR); - state.removeSource(ITYPE_NAVIGATION_BAR); - state.removeSource(ITYPE_EXTRA_NAVIGATION_BAR); - } - - // Status bar doesn't get influenced by caption bar - if (type == ITYPE_STATUS_BAR || type == ITYPE_CLIMATE_BAR) { - state.removeSource(ITYPE_CAPTION_BAR); + for (int i = attrs.providedInsets.length - 1; i >= 0; i--) { + state.removeSource(attrs.providedInsets[i].type); } } ArrayMap providers = mStateController .getSourceProviders(); for (int i = providers.size() - 1; i >= 0; i--) { WindowContainerInsetsSourceProvider otherProvider = providers.valueAt(i); - if (otherProvider.overridesFrame(windowType)) { + if (otherProvider.overridesFrame(attrs.type)) { if (!stateCopied) { state = new InsetsState(state); stateCopied = true; } InsetsSource override = new InsetsSource(state.getSource(otherProvider.getSource().getType())); - override.setFrame(otherProvider.getOverriddenFrame(windowType)); + override.setFrame(otherProvider.getOverriddenFrame(attrs.type)); state.addSource(override); } } diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 6d750a469f8c7..ccfb9299b565e 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -29,7 +29,6 @@ import static android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS; import static android.os.PowerManager.DRAW_WAKE_LOCK; import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; import static android.view.InsetsState.ITYPE_IME; -import static android.view.InsetsState.ITYPE_INVALID; import static android.view.SurfaceControl.Transaction; import static android.view.SurfaceControl.getGlobalTransaction; import static android.view.ViewRootImpl.LOCAL_LAYOUT; @@ -1673,14 +1672,11 @@ class WindowState extends WindowContainer implements WindowManagerP if (rotatedState != null) { return insetsPolicy.adjustInsetsForWindow(this, rotatedState); } - final InsetsSourceProvider provider = getControllableInsetProvider(); - final @InternalInsetsType int insetTypeProvidedByWindow = provider != null - ? provider.getSource().getType() : ITYPE_INVALID; final InsetsState rawInsetsState = mFrozenInsetsState != null ? mFrozenInsetsState : getMergedInsetsState(); final InsetsState insetsStateForWindow = insetsPolicy - .enforceInsetsPolicyForTarget(insetTypeProvidedByWindow, - getWindowingMode(), isAlwaysOnTop(), mAttrs.type, rawInsetsState); + .enforceInsetsPolicyForTarget( + getWindowingMode(), isAlwaysOnTop(), mAttrs, rawInsetsState); return insetsPolicy.adjustInsetsForWindow(this, insetsStateForWindow, includeTransient); }