blob: 317bb43adb98d9cfdb551c07ce5cb43c67497284 [file] [log] [blame]
Jorim Jaggi28620472019-01-02 23:21:49 +01001/*
2 * Copyright (C) 2019 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
17package com.android.server.wm;
18
Jorim Jaggi956ca412019-01-07 14:49:14 +010019import static android.app.StatusBarManager.WINDOW_STATE_HIDDEN;
20import static android.app.StatusBarManager.WINDOW_STATE_SHOWING;
Jorim Jaggi28620472019-01-02 23:21:49 +010021import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
22import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
Tarandeep Singhb9538cd2020-02-20 17:51:18 -080023import static android.view.InsetsController.ANIMATION_TYPE_HIDE;
24import static android.view.InsetsController.ANIMATION_TYPE_SHOW;
Tiger Huang332793b2019-10-29 23:21:27 +080025import static android.view.InsetsState.ITYPE_NAVIGATION_BAR;
26import static android.view.InsetsState.ITYPE_STATUS_BAR;
Yunfan Chenb5d2db72019-12-06 15:43:43 +090027import static android.view.SyncRtSurfaceTransactionApplier.applyParams;
wilsonshihe8321942019-10-18 18:39:46 +080028import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_SHOW_STATUS_BAR;
Jorim Jaggi28620472019-01-02 23:21:49 +010029import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION;
30
31import android.annotation.Nullable;
Jorim Jaggi956ca412019-01-07 14:49:14 +010032import android.app.StatusBarManager;
33import android.util.IntArray;
Yunfan Chenb5d2db72019-12-06 15:43:43 +090034import android.util.SparseArray;
35import android.view.InsetsAnimationControlCallbacks;
36import android.view.InsetsAnimationControlImpl;
Jorim Jaggi6d5c8012020-02-28 01:40:27 +010037import android.view.InsetsAnimationControlRunner;
Yunfan Chenb5d2db72019-12-06 15:43:43 +090038import android.view.InsetsController;
39import android.view.InsetsSourceControl;
Jorim Jaggi956ca412019-01-07 14:49:14 +010040import android.view.InsetsState;
Tiger Huang332793b2019-10-29 23:21:27 +080041import android.view.InsetsState.InternalInsetsType;
Yunfan Chenb5d2db72019-12-06 15:43:43 +090042import android.view.SurfaceControl;
43import android.view.SyncRtSurfaceTransactionApplier;
Jorim Jaggi956ca412019-01-07 14:49:14 +010044import android.view.ViewRootImpl;
Adrian Roosdb5b0c22020-02-12 15:05:27 -080045import android.view.WindowInsetsAnimation;
Jorim Jaggi6d5c8012020-02-28 01:40:27 +010046import android.view.WindowInsetsAnimation.Bounds;
Yunfan Chenb5d2db72019-12-06 15:43:43 +090047import android.view.WindowInsetsAnimationControlListener;
48
Tiger Huanga16634032020-02-05 17:10:03 +080049import com.android.internal.annotations.VisibleForTesting;
Yunfan Chenb5d2db72019-12-06 15:43:43 +090050import com.android.server.DisplayThread;
Jorim Jaggi28620472019-01-02 23:21:49 +010051
52/**
53 * Policy that implements who gets control over the windows generating insets.
54 */
55class InsetsPolicy {
56
57 private final InsetsStateController mStateController;
58 private final DisplayContent mDisplayContent;
59 private final DisplayPolicy mPolicy;
Jorim Jaggi956ca412019-01-07 14:49:14 +010060 private final IntArray mShowingTransientTypes = new IntArray();
61
Tiger Huangb9510ef2020-03-03 23:03:39 +080062 /** For resetting visibilities of insets sources. */
63 private final InsetsControlTarget mDummyControlTarget = new InsetsControlTarget() { };
64
Jorim Jaggi956ca412019-01-07 14:49:14 +010065 private WindowState mFocusedWin;
Tiger Huang4a7835f2019-11-06 00:07:56 +080066 private BarWindow mStatusBar = new BarWindow(StatusBarManager.WINDOW_STATUS_BAR);
Jorim Jaggi956ca412019-01-07 14:49:14 +010067 private BarWindow mNavBar = new BarWindow(StatusBarManager.WINDOW_NAVIGATION_BAR);
Yunfan Chenb5d2db72019-12-06 15:43:43 +090068 private boolean mAnimatingShown;
69 private final float[] mTmpFloat9 = new float[9];
Jorim Jaggi28620472019-01-02 23:21:49 +010070
71 InsetsPolicy(InsetsStateController stateController, DisplayContent displayContent) {
72 mStateController = stateController;
73 mDisplayContent = displayContent;
74 mPolicy = displayContent.getDisplayPolicy();
75 }
76
77 /** Updates the target which can control system bars. */
78 void updateBarControlTarget(@Nullable WindowState focusedWin) {
Jorim Jaggi49b9f6c2020-03-24 22:28:38 +010079 if (mFocusedWin != focusedWin){
80 abortTransient();
81 }
Jorim Jaggi956ca412019-01-07 14:49:14 +010082 mFocusedWin = focusedWin;
Tiger Huang4a7835f2019-11-06 00:07:56 +080083 mStateController.onBarControlTargetChanged(getStatusControlTarget(focusedWin),
84 getFakeStatusControlTarget(focusedWin),
Jorim Jaggi956ca412019-01-07 14:49:14 +010085 getNavControlTarget(focusedWin),
86 getFakeNavControlTarget(focusedWin));
87 if (ViewRootImpl.sNewInsetsMode != ViewRootImpl.NEW_INSETS_MODE_FULL) {
88 return;
89 }
Tiger Huang4a7835f2019-11-06 00:07:56 +080090 mStatusBar.setVisible(focusedWin == null
91 || focusedWin != getStatusControlTarget(focusedWin)
Jorim Jaggi0dd0cf92019-12-27 15:17:44 +010092 || focusedWin.getRequestedInsetsState().getSource(ITYPE_STATUS_BAR).isVisible());
Jorim Jaggi956ca412019-01-07 14:49:14 +010093 mNavBar.setVisible(focusedWin == null
94 || focusedWin != getNavControlTarget(focusedWin)
Jorim Jaggi0dd0cf92019-12-27 15:17:44 +010095 || focusedWin.getRequestedInsetsState().getSource(ITYPE_NAVIGATION_BAR)
96 .isVisible());
Tiger Huang9ff42bd2020-05-01 03:27:33 +080097 mPolicy.updateHideNavInputEventReceiver();
Jorim Jaggi956ca412019-01-07 14:49:14 +010098 }
99
Tiger Huang332793b2019-10-29 23:21:27 +0800100 boolean isHidden(@InternalInsetsType int type) {
Jorim Jaggi956ca412019-01-07 14:49:14 +0100101 final InsetsSourceProvider provider = mStateController.peekSourceProvider(type);
102 return provider != null && provider.hasWindow() && !provider.getSource().isVisible();
103 }
104
105 void showTransient(IntArray types) {
106 boolean changed = false;
107 for (int i = types.size() - 1; i >= 0; i--) {
108 final int type = types.get(i);
109 if (mShowingTransientTypes.indexOf(type) != -1) {
110 continue;
111 }
112 if (!isHidden(type)) {
113 continue;
114 }
115 mShowingTransientTypes.add(type);
116 changed = true;
117 }
118 if (changed) {
Tiger Huanga16634032020-02-05 17:10:03 +0800119 mPolicy.getStatusBarManagerInternal().showTransient(mDisplayContent.getDisplayId(),
120 mShowingTransientTypes.toArray());
121 updateBarControlTarget(mFocusedWin);
Tiger Huange480e5f2020-04-16 23:26:49 +0800122
123 // The leashes can be created while updating bar control target. The surface transaction
124 // of the new leashes might not be applied yet. The callback posted here ensures we can
125 // get the valid leashes because the surface transaction will be applied in the next
126 // animation frame which will be triggered if a new leash is created.
127 mDisplayContent.mWmService.mAnimator.getChoreographer().postFrameCallback(time -> {
Yunfan Chenb5d2db72019-12-06 15:43:43 +0900128 synchronized (mDisplayContent.mWmService.mGlobalLock) {
Tiger Huange480e5f2020-04-16 23:26:49 +0800129 final InsetsState state = new InsetsState(mStateController.getRawInsetsState());
130 startAnimation(true /* show */, () -> {
131 synchronized (mDisplayContent.mWmService.mGlobalLock) {
132 mStateController.notifyInsetsChanged();
133 }
134 }, state);
135 mStateController.onInsetsModified(mDummyControlTarget, state);
Yunfan Chenb5d2db72019-12-06 15:43:43 +0900136 }
Tiger Huange480e5f2020-04-16 23:26:49 +0800137 });
Jorim Jaggi956ca412019-01-07 14:49:14 +0100138 }
139 }
140
141 void hideTransient() {
142 if (mShowingTransientTypes.size() == 0) {
143 return;
144 }
Jorim Jaggi49b9f6c2020-03-24 22:28:38 +0100145 InsetsState state = new InsetsState(mStateController.getRawInsetsState());
Tiger Huanga16634032020-02-05 17:10:03 +0800146 startAnimation(false /* show */, () -> {
Yunfan Chenb5d2db72019-12-06 15:43:43 +0900147 synchronized (mDisplayContent.mWmService.mGlobalLock) {
148 mShowingTransientTypes.clear();
149 mStateController.notifyInsetsChanged();
150 updateBarControlTarget(mFocusedWin);
151 }
Jorim Jaggi49b9f6c2020-03-24 22:28:38 +0100152 }, state);
153 mStateController.onInsetsModified(mDummyControlTarget, state);
Jorim Jaggi956ca412019-01-07 14:49:14 +0100154 }
155
Tiger Huang4a7835f2019-11-06 00:07:56 +0800156 boolean isTransient(@InternalInsetsType int type) {
157 return mShowingTransientTypes.indexOf(type) != -1;
158 }
159
Jorim Jaggi956ca412019-01-07 14:49:14 +0100160 /**
161 * @see InsetsStateController#getInsetsForDispatch
162 */
163 InsetsState getInsetsForDispatch(WindowState target) {
Jorim Jaggi49b9f6c2020-03-24 22:28:38 +0100164 InsetsState originalState = mStateController.getInsetsForDispatch(target);
165 InsetsState state = originalState;
Jorim Jaggi956ca412019-01-07 14:49:14 +0100166 for (int i = mShowingTransientTypes.size() - 1; i >= 0; i--) {
Jorim Jaggi49b9f6c2020-03-24 22:28:38 +0100167 state = new InsetsState(state);
Jorim Jaggi956ca412019-01-07 14:49:14 +0100168 state.setSourceVisible(mShowingTransientTypes.get(i), false);
169 }
Tiger Huangb9510ef2020-03-03 23:03:39 +0800170 if (mFocusedWin != null && getStatusControlTarget(mFocusedWin) == mDummyControlTarget) {
Jorim Jaggi49b9f6c2020-03-24 22:28:38 +0100171 if (state == originalState) {
172 state = new InsetsState(state);
173 }
Tiger Huangb9510ef2020-03-03 23:03:39 +0800174 state.setSourceVisible(ITYPE_STATUS_BAR, mFocusedWin.getRequestedInsetsState());
175 }
176 if (mFocusedWin != null && getNavControlTarget(mFocusedWin) == mDummyControlTarget) {
Jorim Jaggi49b9f6c2020-03-24 22:28:38 +0100177 if (state == originalState) {
178 state = new InsetsState(state);
179 }
Tiger Huangb9510ef2020-03-03 23:03:39 +0800180 state.setSourceVisible(ITYPE_NAVIGATION_BAR, mFocusedWin.getRequestedInsetsState());
181 }
Jorim Jaggi956ca412019-01-07 14:49:14 +0100182 return state;
183 }
184
185 void onInsetsModified(WindowState windowState, InsetsState state) {
186 mStateController.onInsetsModified(windowState, state);
187 checkAbortTransient(windowState, state);
188 if (ViewRootImpl.sNewInsetsMode != ViewRootImpl.NEW_INSETS_MODE_FULL) {
189 return;
190 }
Tiger Huang4a7835f2019-11-06 00:07:56 +0800191 if (windowState == getStatusControlTarget(mFocusedWin)) {
192 mStatusBar.setVisible(state.getSource(ITYPE_STATUS_BAR).isVisible());
Jorim Jaggi956ca412019-01-07 14:49:14 +0100193 }
194 if (windowState == getNavControlTarget(mFocusedWin)) {
Tiger Huang332793b2019-10-29 23:21:27 +0800195 mNavBar.setVisible(state.getSource(ITYPE_NAVIGATION_BAR).isVisible());
Jorim Jaggi956ca412019-01-07 14:49:14 +0100196 }
Tiger Huang9ff42bd2020-05-01 03:27:33 +0800197 mPolicy.updateHideNavInputEventReceiver();
Jorim Jaggi956ca412019-01-07 14:49:14 +0100198 }
199
200 /**
201 * Called when a window modified the insets state. If the window set a insets source to visible
202 * while it is shown transiently, we need to abort the transient state.
203 *
204 * @param windowState who changed the insets state.
205 * @param state the modified insets state.
206 */
207 private void checkAbortTransient(WindowState windowState, InsetsState state) {
208 if (mShowingTransientTypes.size() != 0) {
209 IntArray abortTypes = new IntArray();
210 for (int i = mShowingTransientTypes.size() - 1; i >= 0; i--) {
211 final int type = mShowingTransientTypes.get(i);
212 if (mStateController.isFakeTarget(type, windowState)
213 && state.getSource(type).isVisible()) {
214 mShowingTransientTypes.remove(i);
215 abortTypes.add(type);
216 }
217 }
218 if (abortTypes.size() > 0) {
219 mPolicy.getStatusBarManagerInternal().abortTransient(mDisplayContent.getDisplayId(),
220 abortTypes.toArray());
221 updateBarControlTarget(mFocusedWin);
222 }
223 }
224 }
225
Jorim Jaggi49b9f6c2020-03-24 22:28:38 +0100226 private void abortTransient() {
227 mPolicy.getStatusBarManagerInternal().abortTransient(mDisplayContent.getDisplayId(),
228 mShowingTransientTypes.toArray());
229 mShowingTransientTypes.clear();
230 updateBarControlTarget(mFocusedWin);
231 }
232
Tiger Huang4a7835f2019-11-06 00:07:56 +0800233 private @Nullable InsetsControlTarget getFakeStatusControlTarget(
234 @Nullable WindowState focused) {
Tiger Huangb9510ef2020-03-03 23:03:39 +0800235 return getStatusControlTarget(focused) == mDummyControlTarget ? focused : null;
Jorim Jaggi956ca412019-01-07 14:49:14 +0100236 }
237
238 private @Nullable InsetsControlTarget getFakeNavControlTarget(@Nullable WindowState focused) {
Tiger Huangb9510ef2020-03-03 23:03:39 +0800239 return getNavControlTarget(focused) == mDummyControlTarget ? focused : null;
Jorim Jaggi28620472019-01-02 23:21:49 +0100240 }
241
Tiger Huang4a7835f2019-11-06 00:07:56 +0800242 private @Nullable InsetsControlTarget getStatusControlTarget(@Nullable WindowState focusedWin) {
Tiger Huang332793b2019-10-29 23:21:27 +0800243 if (mShowingTransientTypes.indexOf(ITYPE_STATUS_BAR) != -1) {
Tiger Huangb9510ef2020-03-03 23:03:39 +0800244 return mDummyControlTarget;
Jorim Jaggi956ca412019-01-07 14:49:14 +0100245 }
Jorim Jaggi026ed752020-01-29 00:30:24 +0100246 if (focusedWin == mPolicy.getNotificationShade()) {
247 // Notification shade has control anyways, no reason to force anything.
248 return focusedWin;
249 }
Tiger Huangb9510ef2020-03-03 23:03:39 +0800250 if (forceShowsSystemBarsForWindowingMode()) {
251 // Status bar is forcibly shown for the windowing mode which is a steady state.
252 // We don't want the client to control the status bar, and we will dispatch the real
253 // visibility of status bar to the client.
Jorim Jaggi28620472019-01-02 23:21:49 +0100254 return null;
255 }
Tiger Huangb9510ef2020-03-03 23:03:39 +0800256 if (forceShowsStatusBarTransiently()) {
257 // Status bar is forcibly shown transiently, and its new visibility won't be
258 // dispatched to the client so that we can keep the layout stable. We will dispatch the
259 // fake control to the client, so that it can re-show the bar during this scenario.
260 return mDummyControlTarget;
261 }
Jorim Jaggi28620472019-01-02 23:21:49 +0100262 return focusedWin;
263 }
264
265 private @Nullable InsetsControlTarget getNavControlTarget(@Nullable WindowState focusedWin) {
Tiger Huang332793b2019-10-29 23:21:27 +0800266 if (mShowingTransientTypes.indexOf(ITYPE_NAVIGATION_BAR) != -1) {
Tiger Huangb9510ef2020-03-03 23:03:39 +0800267 return mDummyControlTarget;
Jorim Jaggi956ca412019-01-07 14:49:14 +0100268 }
Jorim Jaggi026ed752020-01-29 00:30:24 +0100269 if (focusedWin == mPolicy.getNotificationShade()) {
270 // Notification shade has control anyways, no reason to force anything.
271 return focusedWin;
272 }
Tiger Huangb9510ef2020-03-03 23:03:39 +0800273 if (forceShowsSystemBarsForWindowingMode()) {
274 // Navigation bar is forcibly shown for the windowing mode which is a steady state.
275 // We don't want the client to control the navigation bar, and we will dispatch the real
276 // visibility of navigation bar to the client.
Jorim Jaggi28620472019-01-02 23:21:49 +0100277 return null;
278 }
Tiger Huangb9510ef2020-03-03 23:03:39 +0800279 if (forceShowsNavigationBarTransiently()) {
280 // Navigation bar is forcibly shown transiently, and its new visibility won't be
281 // dispatched to the client so that we can keep the layout stable. We will dispatch the
282 // fake control to the client, so that it can re-show the bar during this scenario.
283 return mDummyControlTarget;
284 }
Jorim Jaggi28620472019-01-02 23:21:49 +0100285 return focusedWin;
286 }
287
Tiger Huangb9510ef2020-03-03 23:03:39 +0800288 private boolean forceShowsStatusBarTransiently() {
289 final WindowState win = mPolicy.getStatusBar();
290 return win != null && (win.mAttrs.privateFlags & PRIVATE_FLAG_FORCE_SHOW_STATUS_BAR) != 0;
Jorim Jaggi28620472019-01-02 23:21:49 +0100291 }
292
Tiger Huangb9510ef2020-03-03 23:03:39 +0800293 private boolean forceShowsNavigationBarTransiently() {
294 final WindowState win = mPolicy.getNotificationShade();
295 return win != null
296 && (win.mAttrs.privateFlags & PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION) != 0;
Jorim Jaggi28620472019-01-02 23:21:49 +0100297 }
298
Tiger Huangb9510ef2020-03-03 23:03:39 +0800299 private boolean forceShowsSystemBarsForWindowingMode() {
Andrii Kulian4c0fd0d2020-03-29 13:32:14 -0700300 final boolean isDockedStackVisible = mDisplayContent.getDefaultTaskDisplayArea()
301 .isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
302 final boolean isFreeformStackVisible = mDisplayContent.getDefaultTaskDisplayArea()
303 .isStackVisible(WINDOWING_MODE_FREEFORM);
Jorim Jaggi28620472019-01-02 23:21:49 +0100304 final boolean isResizing = mDisplayContent.getDockedDividerController().isResizing();
305
306 // We need to force system bars when the docked stack is visible, when the freeform stack
307 // is visible but also when we are resizing for the transitions when docked stack
308 // visibility changes.
JianYang Liuae86b3f2020-04-03 20:20:35 -0700309 return isDockedStackVisible
310 || isFreeformStackVisible
311 || isResizing
312 || mPolicy.getForceShowSystemBars();
Jorim Jaggi28620472019-01-02 23:21:49 +0100313 }
314
Tiger Huanga16634032020-02-05 17:10:03 +0800315 @VisibleForTesting
Jorim Jaggi49b9f6c2020-03-24 22:28:38 +0100316 void startAnimation(boolean show, Runnable callback, InsetsState state) {
Yunfan Chenb5d2db72019-12-06 15:43:43 +0900317 int typesReady = 0;
318 final SparseArray<InsetsSourceControl> controls = new SparseArray<>();
Tiger Huanga16634032020-02-05 17:10:03 +0800319 final IntArray showingTransientTypes = mShowingTransientTypes;
320 for (int i = showingTransientTypes.size() - 1; i >= 0; i--) {
Jorim Jaggi49b9f6c2020-03-24 22:28:38 +0100321 int type = showingTransientTypes.get(i);
322 InsetsSourceProvider provider = mStateController.getSourceProvider(type);
Tiger Huangb9510ef2020-03-03 23:03:39 +0800323 InsetsSourceControl control = provider.getControl(mDummyControlTarget);
Tiger Huanga16634032020-02-05 17:10:03 +0800324 if (control == null || control.getLeash() == null) {
325 continue;
326 }
Jorim Jaggi49b9f6c2020-03-24 22:28:38 +0100327 typesReady |= InsetsState.toPublicType(type);
Tiger Huanga16634032020-02-05 17:10:03 +0800328 controls.put(control.getType(), new InsetsSourceControl(control));
Jorim Jaggi49b9f6c2020-03-24 22:28:38 +0100329 state.setSourceVisible(type, show);
Yunfan Chenb5d2db72019-12-06 15:43:43 +0900330 }
331 controlAnimationUnchecked(typesReady, controls, show, callback);
332 }
333
334 private void controlAnimationUnchecked(int typesReady,
335 SparseArray<InsetsSourceControl> controls, boolean show, Runnable callback) {
336 InsetsPolicyAnimationControlListener listener =
Jorim Jaggi5875cca2020-03-17 13:44:57 +0100337 new InsetsPolicyAnimationControlListener(show, callback, typesReady);
Yunfan Chenb5d2db72019-12-06 15:43:43 +0900338 listener.mControlCallbacks.controlAnimationUnchecked(typesReady, controls, show);
339 }
340
Jorim Jaggi956ca412019-01-07 14:49:14 +0100341 private class BarWindow {
342
343 private final int mId;
344 private @StatusBarManager.WindowVisibleState int mState =
345 StatusBarManager.WINDOW_STATE_SHOWING;
346
347 BarWindow(int id) {
348 mId = id;
349 }
350
351 private void setVisible(boolean visible) {
352 final int state = visible ? WINDOW_STATE_SHOWING : WINDOW_STATE_HIDDEN;
353 if (mState != state) {
354 mState = state;
355 mPolicy.getStatusBarManagerInternal().setWindowState(
356 mDisplayContent.getDisplayId(), mId, state);
357 }
358 }
359 }
360
Yunfan Chenb5d2db72019-12-06 15:43:43 +0900361 private class InsetsPolicyAnimationControlListener extends
362 InsetsController.InternalAnimationControlListener {
363 Runnable mFinishCallback;
364 InsetsPolicyAnimationControlCallbacks mControlCallbacks;
365
Jorim Jaggi5875cca2020-03-17 13:44:57 +0100366 InsetsPolicyAnimationControlListener(boolean show, Runnable finishCallback, int types) {
367 super(show, false /* hasCallbacks */, types);
Yunfan Chenb5d2db72019-12-06 15:43:43 +0900368 mFinishCallback = finishCallback;
369 mControlCallbacks = new InsetsPolicyAnimationControlCallbacks(this);
370 }
371
372 @Override
373 protected void onAnimationFinish() {
374 super.onAnimationFinish();
Yunfan Chenb5d2db72019-12-06 15:43:43 +0900375 DisplayThread.getHandler().post(mFinishCallback);
376 }
377
378 private class InsetsPolicyAnimationControlCallbacks implements
379 InsetsAnimationControlCallbacks {
380 private InsetsAnimationControlImpl mAnimationControl = null;
381 private InsetsPolicyAnimationControlListener mListener;
382
383 InsetsPolicyAnimationControlCallbacks(InsetsPolicyAnimationControlListener listener) {
Yunfan Chenb5d2db72019-12-06 15:43:43 +0900384 mListener = listener;
385 }
386
387 private void controlAnimationUnchecked(int typesReady,
388 SparseArray<InsetsSourceControl> controls, boolean show) {
389 if (typesReady == 0) {
390 // nothing to animate.
391 return;
392 }
393 mAnimatingShown = show;
394
395 mAnimationControl = new InsetsAnimationControlImpl(controls,
396 mFocusedWin.getDisplayContent().getBounds(), getState(),
397 mListener, typesReady, this, mListener.getDurationMs(),
Jorim Jaggi5875cca2020-03-17 13:44:57 +0100398 InsetsController.SYSTEM_BARS_INTERPOLATOR,
Tarandeep Singhb9538cd2020-02-20 17:51:18 -0800399 show ? ANIMATION_TYPE_SHOW : ANIMATION_TYPE_HIDE);
Tiger Huanga16634032020-02-05 17:10:03 +0800400 SurfaceAnimationThread.getHandler().post(
401 () -> mListener.onReady(mAnimationControl, typesReady));
Yunfan Chenb5d2db72019-12-06 15:43:43 +0900402 }
403
Tiger Huanga16634032020-02-05 17:10:03 +0800404 /** Called on SurfaceAnimationThread without global WM lock held. */
Yunfan Chenb5d2db72019-12-06 15:43:43 +0900405 @Override
Adrian Roos6a4448f2020-04-01 15:01:08 +0200406 public void scheduleApplyChangeInsets(InsetsAnimationControlRunner runner) {
Yunfan Chenb5d2db72019-12-06 15:43:43 +0900407 InsetsState state = getState();
408 if (mAnimationControl.applyChangeInsets(state)) {
409 mAnimationControl.finish(mAnimatingShown);
410 }
411 }
412
413 @Override
Jorim Jaggi6d5c8012020-02-28 01:40:27 +0100414 public void notifyFinished(InsetsAnimationControlRunner runner, boolean shown) {
Yunfan Chenb5d2db72019-12-06 15:43:43 +0900415 // Nothing's needed here. Finish steps is handled in the listener
416 // onAnimationFinished callback.
417 }
418
419 /**
420 * This method will return a state with fullscreen frame override. No need to make copy
421 * after getting state from this method.
422 * @return The client insets state with full display frame override.
423 */
424 private InsetsState getState() {
425 // To animate the transient animation correctly, we need to let the state hold
426 // the full display frame.
427 InsetsState overrideState = new InsetsState(mFocusedWin.getRequestedInsetsState(),
428 true);
429 overrideState.setDisplayFrame(mFocusedWin.getDisplayContent().getBounds());
430 return overrideState;
431 }
432
Tiger Huanga16634032020-02-05 17:10:03 +0800433 /** Called on SurfaceAnimationThread without global WM lock held. */
Yunfan Chenb5d2db72019-12-06 15:43:43 +0900434 @Override
435 public void applySurfaceParams(
436 final SyncRtSurfaceTransactionApplier.SurfaceParams... params) {
437 SurfaceControl.Transaction t = new SurfaceControl.Transaction();
438 for (int i = params.length - 1; i >= 0; i--) {
439 SyncRtSurfaceTransactionApplier.SurfaceParams surfaceParams = params[i];
440 applyParams(t, surfaceParams, mTmpFloat9);
441 }
442 t.apply();
Jorim Jaggi6d5c8012020-02-28 01:40:27 +0100443 t.close();
Yunfan Chenb5d2db72019-12-06 15:43:43 +0900444 }
445
Rob Carr3a367c42020-03-10 15:51:35 -0700446 // Since we don't push applySurfaceParams to a Handler-queue we don't need
447 // to push release in this case.
448 @Override
449 public void releaseSurfaceControlFromRt(SurfaceControl sc) {
450 sc.release();
451 }
452
Yunfan Chenb5d2db72019-12-06 15:43:43 +0900453 @Override
454 public void startAnimation(InsetsAnimationControlImpl controller,
455 WindowInsetsAnimationControlListener listener, int types,
Adrian Roosdb5b0c22020-02-12 15:05:27 -0800456 WindowInsetsAnimation animation,
Jorim Jaggi6d5c8012020-02-28 01:40:27 +0100457 Bounds bounds) {
Yunfan Chenb5d2db72019-12-06 15:43:43 +0900458 }
459 }
460 }
Jorim Jaggi28620472019-01-02 23:21:49 +0100461}