Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 19 | import static android.view.InsetsState.ITYPE_IME; |
| 20 | import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; |
| 21 | import static android.view.InsetsState.ITYPE_STATUS_BAR; |
Jorim Jaggi | a12ea56 | 2019-01-07 17:47:47 +0100 | [diff] [blame] | 22 | import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL; |
| 23 | import static android.view.ViewRootImpl.sNewInsetsMode; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 24 | |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 25 | import android.annotation.NonNull; |
| 26 | import android.annotation.Nullable; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 27 | import android.util.ArrayMap; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 28 | import android.util.ArraySet; |
| 29 | import android.util.SparseArray; |
Jorim Jaggi | e35c059 | 2018-11-06 16:21:08 +0100 | [diff] [blame] | 30 | import android.view.InsetsSource; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 31 | import android.view.InsetsSourceControl; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 32 | import android.view.InsetsState; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 33 | import android.view.InsetsState.InternalInsetsType; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 34 | |
| 35 | import java.io.PrintWriter; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 36 | import java.util.ArrayList; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 37 | import java.util.function.Consumer; |
| 38 | |
| 39 | /** |
| 40 | * Manages global window inset state in the system represented by {@link InsetsState}. |
| 41 | */ |
| 42 | class InsetsStateController { |
| 43 | |
| 44 | private final InsetsState mLastState = new InsetsState(); |
| 45 | private final InsetsState mState = new InsetsState(); |
| 46 | private final DisplayContent mDisplayContent; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 47 | |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 48 | private final ArrayMap<Integer, InsetsSourceProvider> mProviders = new ArrayMap<>(); |
| 49 | private final ArrayMap<InsetsControlTarget, ArrayList<Integer>> mControlTargetTypeMap = |
| 50 | new ArrayMap<>(); |
| 51 | private final SparseArray<InsetsControlTarget> mTypeControlTargetMap = new SparseArray<>(); |
Jorim Jaggi | a12ea56 | 2019-01-07 17:47:47 +0100 | [diff] [blame] | 52 | |
| 53 | /** @see #onControlFakeTargetChanged */ |
| 54 | private final SparseArray<InsetsControlTarget> mTypeFakeControlTargetMap = new SparseArray<>(); |
| 55 | |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 56 | private final ArraySet<InsetsControlTarget> mPendingControlChanged = new ArraySet<>(); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 57 | |
| 58 | private final Consumer<WindowState> mDispatchInsetsChanged = w -> { |
| 59 | if (w.isVisible()) { |
| 60 | w.notifyInsetsChanged(); |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | InsetsStateController(DisplayContent displayContent) { |
| 65 | mDisplayContent = displayContent; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * When dispatching window state to the client, we'll need to exclude the source that represents |
| 70 | * the window that is being dispatched. |
| 71 | * |
| 72 | * @param target The client we dispatch the state to. |
| 73 | * @return The state stripped of the necessary information. |
| 74 | */ |
| 75 | InsetsState getInsetsForDispatch(WindowState target) { |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 76 | final InsetsSourceProvider provider = target.getControllableInsetProvider(); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 77 | if (provider == null) { |
| 78 | return mState; |
| 79 | } |
| 80 | |
| 81 | final InsetsState state = new InsetsState(); |
| 82 | state.set(mState); |
| 83 | final int type = provider.getSource().getType(); |
| 84 | state.removeSource(type); |
| 85 | |
| 86 | // Navigation bar doesn't get influenced by anything else |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 87 | if (type == ITYPE_NAVIGATION_BAR) { |
| 88 | state.removeSource(ITYPE_IME); |
| 89 | state.removeSource(ITYPE_STATUS_BAR); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 90 | } |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 91 | |
| 92 | // IME needs different frames for certain cases (e.g. navigation bar in gesture nav). |
| 93 | if (type == ITYPE_IME) { |
| 94 | for (int i = mProviders.size() - 1; i >= 0; i--) { |
| 95 | InsetsSourceProvider otherProvider = mProviders.valueAt(i); |
| 96 | if (otherProvider.overridesImeFrame()) { |
| 97 | InsetsSource override = |
| 98 | new InsetsSource(state.getSource(otherProvider.getSource().getType())); |
| 99 | override.setFrame(otherProvider.getImeOverrideFrame()); |
| 100 | state.addSource(override); |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 105 | return state; |
| 106 | } |
| 107 | |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 108 | InsetsState getRawInsetsState() { |
| 109 | return mState; |
| 110 | } |
| 111 | |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 112 | @Nullable InsetsSourceControl[] getControlsForDispatch(InsetsControlTarget target) { |
| 113 | ArrayList<Integer> controlled = mControlTargetTypeMap.get(target); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 114 | if (controlled == null) { |
| 115 | return null; |
| 116 | } |
| 117 | final int size = controlled.size(); |
| 118 | final InsetsSourceControl[] result = new InsetsSourceControl[size]; |
| 119 | for (int i = 0; i < size; i++) { |
Jorim Jaggi | a12ea56 | 2019-01-07 17:47:47 +0100 | [diff] [blame] | 120 | result[i] = mProviders.get(controlled.get(i)).getControl(target); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 121 | } |
| 122 | return result; |
| 123 | } |
| 124 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 125 | /** |
| 126 | * @return The provider of a specific type. |
| 127 | */ |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 128 | InsetsSourceProvider getSourceProvider(@InternalInsetsType int type) { |
| 129 | if (type == ITYPE_IME) { |
Tarandeep Singh | 500a38f | 2019-09-26 13:36:40 -0700 | [diff] [blame] | 130 | return mProviders.computeIfAbsent(type, |
| 131 | key -> new ImeInsetsSourceProvider( |
| 132 | mState.getSource(key), this, mDisplayContent)); |
| 133 | } else { |
| 134 | return mProviders.computeIfAbsent(type, |
| 135 | key -> new InsetsSourceProvider(mState.getSource(key), this, mDisplayContent)); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | ImeInsetsSourceProvider getImeSourceProvider() { |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 140 | return (ImeInsetsSourceProvider) getSourceProvider(ITYPE_IME); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /** |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 144 | * @return The provider of a specific type or null if we don't have it. |
| 145 | */ |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 146 | @Nullable InsetsSourceProvider peekSourceProvider(@InternalInsetsType int type) { |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 147 | return mProviders.get(type); |
| 148 | } |
| 149 | |
| 150 | /** |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 151 | * Called when a layout pass has occurred. |
| 152 | */ |
| 153 | void onPostLayout() { |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 154 | mState.setDisplayFrame(mDisplayContent.getBounds()); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 155 | for (int i = mProviders.size() - 1; i >= 0; i--) { |
| 156 | mProviders.valueAt(i).onPostLayout(); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 157 | } |
| 158 | if (!mLastState.equals(mState)) { |
| 159 | mLastState.set(mState, true /* copySources */); |
| 160 | notifyInsetsChanged(); |
| 161 | } |
Tarandeep Singh | 500a38f | 2019-09-26 13:36:40 -0700 | [diff] [blame] | 162 | getImeSourceProvider().onPostInsetsDispatched(); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 163 | } |
| 164 | |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 165 | void onInsetsModified(InsetsControlTarget windowState, InsetsState state) { |
Jorim Jaggi | e35c059 | 2018-11-06 16:21:08 +0100 | [diff] [blame] | 166 | boolean changed = false; |
| 167 | for (int i = state.getSourcesCount() - 1; i >= 0; i--) { |
| 168 | final InsetsSource source = state.sourceAt(i); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 169 | final InsetsSourceProvider provider = mProviders.get(source.getType()); |
Jorim Jaggi | e35c059 | 2018-11-06 16:21:08 +0100 | [diff] [blame] | 170 | if (provider == null) { |
| 171 | continue; |
| 172 | } |
| 173 | changed |= provider.onInsetsModified(windowState, source); |
| 174 | } |
| 175 | if (changed) { |
| 176 | notifyInsetsChanged(); |
| 177 | } |
| 178 | } |
| 179 | |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 180 | boolean isFakeTarget(@InternalInsetsType int type, InsetsControlTarget target) { |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 181 | return mTypeFakeControlTargetMap.get(type) == target; |
| 182 | } |
| 183 | |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 184 | void onImeTargetChanged(@Nullable InsetsControlTarget imeTarget) { |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 185 | onControlChanged(ITYPE_IME, imeTarget); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 186 | notifyPendingInsetsControlChanged(); |
| 187 | } |
| 188 | |
| 189 | /** |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 190 | * Called when the focused window that is able to control the system bars changes. |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 191 | * |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 192 | * @param topControlling The target that is now able to control the top bar appearance |
| 193 | * and visibility. |
| 194 | * @param navControlling The target that is now able to control the nav bar appearance |
| 195 | * and visibility. |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 196 | */ |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 197 | void onBarControlTargetChanged(@Nullable InsetsControlTarget topControlling, |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 198 | @Nullable InsetsControlTarget fakeTopControlling, |
| 199 | @Nullable InsetsControlTarget navControlling, |
| 200 | @Nullable InsetsControlTarget fakeNavControlling) { |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 201 | onControlChanged(ITYPE_STATUS_BAR, topControlling); |
| 202 | onControlChanged(ITYPE_NAVIGATION_BAR, navControlling); |
| 203 | onControlFakeTargetChanged(ITYPE_STATUS_BAR, fakeTopControlling); |
| 204 | onControlFakeTargetChanged(ITYPE_NAVIGATION_BAR, fakeNavControlling); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 205 | notifyPendingInsetsControlChanged(); |
| 206 | } |
| 207 | |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 208 | void notifyControlRevoked(@NonNull InsetsControlTarget previousControlTarget, |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 209 | InsetsSourceProvider provider) { |
Jorim Jaggi | a12ea56 | 2019-01-07 17:47:47 +0100 | [diff] [blame] | 210 | removeFromControlMaps(previousControlTarget, provider.getSource().getType(), |
| 211 | false /* fake */); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 212 | } |
| 213 | |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 214 | private void onControlChanged(@InternalInsetsType int type, |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 215 | @Nullable InsetsControlTarget target) { |
| 216 | final InsetsControlTarget previous = mTypeControlTargetMap.get(type); |
| 217 | if (target == previous) { |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 218 | return; |
| 219 | } |
Tiger Huang | 969c608 | 2019-12-24 20:08:57 +0800 | [diff] [blame] | 220 | final InsetsSourceProvider provider = mProviders.get(type); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 221 | if (provider == null) { |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 222 | return; |
| 223 | } |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 224 | if (!provider.isControllable()) { |
Jorim Jaggi | a2759b2 | 2019-01-24 13:21:40 +0100 | [diff] [blame] | 225 | return; |
| 226 | } |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 227 | provider.updateControlForTarget(target, false /* force */); |
Tiger Huang | 969c608 | 2019-12-24 20:08:57 +0800 | [diff] [blame] | 228 | target = provider.getControlTarget(); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 229 | if (previous != null) { |
Jorim Jaggi | a12ea56 | 2019-01-07 17:47:47 +0100 | [diff] [blame] | 230 | removeFromControlMaps(previous, type, false /* fake */); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 231 | mPendingControlChanged.add(previous); |
| 232 | } |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 233 | if (target != null) { |
Jorim Jaggi | a12ea56 | 2019-01-07 17:47:47 +0100 | [diff] [blame] | 234 | addToControlMaps(target, type, false /* fake */); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 235 | mPendingControlChanged.add(target); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | |
Jorim Jaggi | a12ea56 | 2019-01-07 17:47:47 +0100 | [diff] [blame] | 239 | /** |
| 240 | * The fake target saved here will be used to pretend to the app that it's still under control |
| 241 | * of the bars while it's not really, but we still need to find out the apps intentions around |
| 242 | * showing/hiding. For example, when the transient bars are showing, and the fake target |
| 243 | * requests to show system bars, the transient state will be aborted. |
| 244 | */ |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 245 | void onControlFakeTargetChanged(@InternalInsetsType int type, |
Jorim Jaggi | a12ea56 | 2019-01-07 17:47:47 +0100 | [diff] [blame] | 246 | @Nullable InsetsControlTarget fakeTarget) { |
| 247 | if (sNewInsetsMode != NEW_INSETS_MODE_FULL) { |
| 248 | return; |
| 249 | } |
| 250 | final InsetsControlTarget previous = mTypeFakeControlTargetMap.get(type); |
| 251 | if (fakeTarget == previous) { |
| 252 | return; |
| 253 | } |
| 254 | final InsetsSourceProvider provider = mProviders.get(type); |
| 255 | if (provider == null) { |
| 256 | return; |
| 257 | } |
| 258 | provider.updateControlForFakeTarget(fakeTarget); |
| 259 | if (previous != null) { |
| 260 | removeFromControlMaps(previous, type, true /* fake */); |
| 261 | mPendingControlChanged.add(previous); |
| 262 | } |
| 263 | if (fakeTarget != null) { |
| 264 | addToControlMaps(fakeTarget, type, true /* fake */); |
| 265 | mPendingControlChanged.add(fakeTarget); |
| 266 | } |
| 267 | } |
| 268 | |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 269 | private void removeFromControlMaps(@NonNull InsetsControlTarget target, |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 270 | @InternalInsetsType int type, boolean fake) { |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 271 | final ArrayList<Integer> array = mControlTargetTypeMap.get(target); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 272 | if (array == null) { |
| 273 | return; |
| 274 | } |
| 275 | array.remove((Integer) type); |
| 276 | if (array.isEmpty()) { |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 277 | mControlTargetTypeMap.remove(target); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 278 | } |
Jorim Jaggi | a12ea56 | 2019-01-07 17:47:47 +0100 | [diff] [blame] | 279 | if (fake) { |
| 280 | mTypeFakeControlTargetMap.remove(type); |
| 281 | } else { |
| 282 | mTypeControlTargetMap.remove(type); |
| 283 | } |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 284 | } |
| 285 | |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 286 | private void addToControlMaps(@NonNull InsetsControlTarget target, |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 287 | @InternalInsetsType int type, boolean fake) { |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 288 | final ArrayList<Integer> array = mControlTargetTypeMap.computeIfAbsent(target, |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 289 | key -> new ArrayList<>()); |
| 290 | array.add(type); |
Jorim Jaggi | a12ea56 | 2019-01-07 17:47:47 +0100 | [diff] [blame] | 291 | if (fake) { |
| 292 | mTypeFakeControlTargetMap.put(type, target); |
| 293 | } else { |
| 294 | mTypeControlTargetMap.put(type, target); |
| 295 | } |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 296 | } |
| 297 | |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 298 | void notifyControlChanged(InsetsControlTarget target) { |
Tarandeep Singh | 215929b | 2019-01-11 18:24:37 -0800 | [diff] [blame] | 299 | mPendingControlChanged.add(target); |
| 300 | notifyPendingInsetsControlChanged(); |
| 301 | } |
| 302 | |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 303 | private void notifyPendingInsetsControlChanged() { |
Jorim Jaggi | f86eb49 | 2019-01-09 17:37:08 +0100 | [diff] [blame] | 304 | if (mPendingControlChanged.isEmpty()) { |
| 305 | return; |
| 306 | } |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 307 | mDisplayContent.mWmService.mAnimator.addAfterPrepareSurfacesRunnable(() -> { |
| 308 | for (int i = mPendingControlChanged.size() - 1; i >= 0; i--) { |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 309 | final InsetsControlTarget controlTarget = mPendingControlChanged.valueAt(i); |
| 310 | controlTarget.notifyInsetsControlChanged(); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 311 | } |
| 312 | mPendingControlChanged.clear(); |
| 313 | }); |
| 314 | } |
| 315 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 316 | void notifyInsetsChanged() { |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 317 | mDisplayContent.forAllWindows(mDispatchInsetsChanged, true /* traverseTopToBottom */); |
Evan Rosky | 8d782e0 | 2019-10-14 15:43:53 -0700 | [diff] [blame] | 318 | if (mDisplayContent.mRemoteInsetsControlTarget != null) { |
| 319 | mDisplayContent.mRemoteInsetsControlTarget.notifyInsetsChanged(); |
| 320 | } |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | void dump(String prefix, PrintWriter pw) { |
| 324 | pw.println(prefix + "WindowInsetsStateController"); |
| 325 | mState.dump(prefix + " ", pw); |
Jorim Jaggi | cfd6f3b | 2018-11-07 15:30:18 +0100 | [diff] [blame] | 326 | pw.println(prefix + " " + "Control map:"); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 327 | for (int i = mTypeControlTargetMap.size() - 1; i >= 0; i--) { |
Jorim Jaggi | cfd6f3b | 2018-11-07 15:30:18 +0100 | [diff] [blame] | 328 | pw.print(prefix + " "); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 329 | pw.println(InsetsState.typeToString(mTypeControlTargetMap.keyAt(i)) + " -> " |
| 330 | + mTypeControlTargetMap.valueAt(i)); |
Jorim Jaggi | cfd6f3b | 2018-11-07 15:30:18 +0100 | [diff] [blame] | 331 | } |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 332 | } |
| 333 | } |