blob: 2b45d67120d9d928b4674bb7865cff2f3ae0d87e [file] [log] [blame]
Filip Gruszczynski466f3212015-09-21 17:57:57 -07001/*
2 * Copyright (C) 2012 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 Jaggibc5425c2016-03-01 13:51:16 +010019import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
Jorim Jaggid3ec5072016-04-28 15:57:47 -070020import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
Jorim Jaggibc5425c2016-03-01 13:51:16 +010021import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Jorim Jaggi85639432016-05-06 17:27:55 -070022import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
23import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
24import static android.view.Surface.ROTATION_270;
25import static android.view.Surface.ROTATION_90;
Jorim Jaggibc5425c2016-03-01 13:51:16 +010026import static android.view.WindowManager.DOCKED_BOTTOM;
27import static android.view.WindowManager.DOCKED_LEFT;
28import static android.view.WindowManager.DOCKED_RIGHT;
29import static android.view.WindowManager.DOCKED_TOP;
30import static com.android.server.wm.AppTransition.DEFAULT_APP_TRANSITION_DURATION;
31import static com.android.server.wm.AppTransition.TOUCH_RESPONSE_INTERPOLATOR;
Jorim Jaggi84afb1a2016-09-28 14:54:04 +020032import static com.android.server.wm.AppTransition.TRANSIT_NONE;
Jorim Jaggibc5425c2016-03-01 13:51:16 +010033import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
34import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Tony Mak853304c2016-04-18 15:17:41 +010035import static com.android.server.wm.WindowManagerService.H.NOTIFY_DOCKED_STACK_MINIMIZED_CHANGED;
Wale Ogunwalec69694a2016-10-18 13:51:15 -070036import static com.android.server.wm.WindowManagerService.LAYER_OFFSET_DIM;
Steven Timotiusaf03df62017-07-18 16:56:43 -070037import static com.android.server.wm.proto.DockedStackDividerControllerProto.MINIMIZED_DOCK;
Jorim Jaggibc5425c2016-03-01 13:51:16 +010038
Filip Gruszczynski466f3212015-09-21 17:57:57 -070039import android.content.Context;
Jorim Jaggi85639432016-05-06 17:27:55 -070040import android.content.res.Configuration;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070041import android.graphics.Rect;
Jorim Jaggia6c934e2015-12-21 13:22:31 +010042import android.os.RemoteCallbackList;
Filip Gruszczynski64cdc142015-11-29 21:10:07 -080043import android.os.RemoteException;
Jorim Jaggi936aaeb2016-08-26 19:02:11 -070044import android.util.ArraySet;
Filip Gruszczynski77049052015-11-09 14:01:21 -080045import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -070046import android.util.proto.ProtoOutputStream;
Jorim Jaggi50981592015-12-29 17:54:12 +010047import android.view.DisplayInfo;
Jorim Jaggia6c934e2015-12-21 13:22:31 +010048import android.view.IDockedStackListener;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080049import android.view.animation.AnimationUtils;
50import android.view.animation.Interpolator;
Jorim Jaggieb88d832016-04-13 20:17:43 -070051import android.view.animation.PathInterpolator;
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -070052import android.view.inputmethod.InputMethodManagerInternal;
Jorim Jaggi50981592015-12-29 17:54:12 +010053
Jorim Jaggi85639432016-05-06 17:27:55 -070054import com.android.internal.policy.DividerSnapAlgorithm;
55import com.android.internal.policy.DockedDividerUtils;
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -070056import com.android.server.LocalServices;
Jorim Jaggi50981592015-12-29 17:54:12 +010057import com.android.server.wm.DimLayer.DimLayerUser;
Jorim Jaggiff71d202016-04-14 13:12:36 -070058import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi61f39a72015-10-29 16:54:18 +010059
Jorim Jaggi31f71702016-05-04 16:43:04 -070060import java.io.PrintWriter;
Chong Zhangbaba7832016-03-24 10:21:26 -070061
Filip Gruszczynski466f3212015-09-21 17:57:57 -070062/**
Jorim Jaggi61f39a72015-10-29 16:54:18 +010063 * Keeps information about the docked stack divider.
Filip Gruszczynski466f3212015-09-21 17:57:57 -070064 */
Jorim Jaggi50981592015-12-29 17:54:12 +010065public class DockedStackDividerController implements DimLayerUser {
Jorim Jaggi61f39a72015-10-29 16:54:18 +010066
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080067 private static final String TAG = TAG_WITH_CLASS_NAME ? "DockedStackDividerController" : TAG_WM;
Jorim Jaggi61f39a72015-10-29 16:54:18 +010068
Jorim Jaggif97ed922016-02-18 18:57:07 -080069 /**
70 * The fraction during the maximize/clip reveal animation the divider meets the edge of the clip
71 * revealing surface at the earliest.
72 */
73 private static final float CLIP_REVEAL_MEET_EARLIEST = 0.6f;
74
75 /**
76 * The fraction during the maximize/clip reveal animation the divider meets the edge of the clip
77 * revealing surface at the latest.
78 */
79 private static final float CLIP_REVEAL_MEET_LAST = 1f;
80
81 /**
82 * If the app translates at least CLIP_REVEAL_MEET_FRACTION_MIN * minimize distance, we start
83 * meet somewhere between {@link #CLIP_REVEAL_MEET_LAST} and {@link #CLIP_REVEAL_MEET_EARLIEST}.
84 */
85 private static final float CLIP_REVEAL_MEET_FRACTION_MIN = 0.4f;
86
87 /**
88 * If the app translates equals or more than CLIP_REVEAL_MEET_FRACTION_MIN * minimize distance,
89 * we meet at {@link #CLIP_REVEAL_MEET_EARLIEST}.
90 */
91 private static final float CLIP_REVEAL_MEET_FRACTION_MAX = 0.8f;
92
Jorim Jaggieb88d832016-04-13 20:17:43 -070093 private static final Interpolator IME_ADJUST_ENTRY_INTERPOLATOR =
Jorim Jaggiff71d202016-04-14 13:12:36 -070094 new PathInterpolator(0.2f, 0f, 0.1f, 1f);
Jorim Jaggieb88d832016-04-13 20:17:43 -070095
Jorim Jaggi698e7632016-04-13 21:02:22 -070096 private static final long IME_ADJUST_ANIM_DURATION = 280;
Jorim Jaggieb88d832016-04-13 20:17:43 -070097
Jorim Jaggiff71d202016-04-14 13:12:36 -070098 private static final long IME_ADJUST_DRAWN_TIMEOUT = 200;
99
Chong Zhang198afac2016-04-15 12:03:11 -0700100 private static final int DIVIDER_WIDTH_INACTIVE_DP = 4;
101
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800102 private final WindowManagerService mService;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700103 private final DisplayContent mDisplayContent;
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700104 private int mDividerWindowWidth;
Chong Zhang198afac2016-04-15 12:03:11 -0700105 private int mDividerWindowWidthInactive;
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700106 private int mDividerInsets;
Matthew Nge15352e2016-12-20 15:36:29 -0800107 private int mTaskHeightInMinimizedMode;
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100108 private boolean mResizing;
109 private WindowState mWindow;
110 private final Rect mTmpRect = new Rect();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800111 private final Rect mTmpRect2 = new Rect();
Jorim Jaggi85639432016-05-06 17:27:55 -0700112 private final Rect mTmpRect3 = new Rect();
Filip Gruszczynski77049052015-11-09 14:01:21 -0800113 private final Rect mLastRect = new Rect();
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800114 private boolean mLastVisibility = false;
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100115 private final RemoteCallbackList<IDockedStackListener> mDockedStackListeners
116 = new RemoteCallbackList<>();
Jorim Jaggi50981592015-12-29 17:54:12 +0100117 private final DimLayer mDimLayer;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700118
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800119 private boolean mMinimizedDock;
Chong Zhangbaba7832016-03-24 10:21:26 -0700120 private boolean mAnimatingForMinimizedDockedStack;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800121 private boolean mAnimationStarted;
122 private long mAnimationStartTime;
123 private float mAnimationStart;
124 private float mAnimationTarget;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800125 private long mAnimationDuration;
Jorim Jaggiff71d202016-04-14 13:12:36 -0700126 private boolean mAnimationStartDelayed;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800127 private final Interpolator mMinimizedDockInterpolator;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800128 private float mMaximizeMeetFraction;
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100129 private final Rect mTouchRegion = new Rect();
Chong Zhangbaba7832016-03-24 10:21:26 -0700130 private boolean mAnimatingForIme;
131 private boolean mAdjustedForIme;
Keisuke Kuroyanagi19d9a8f2016-05-12 16:49:02 -0700132 private int mImeHeight;
Jorim Jaggiff71d202016-04-14 13:12:36 -0700133 private WindowState mDelayedImeWin;
Chong Zhangf347ab52016-04-18 21:02:01 -0700134 private boolean mAdjustedForDivider;
135 private float mDividerAnimationStart;
136 private float mDividerAnimationTarget;
Wale Ogunwale10124582016-09-15 20:25:50 -0700137 float mLastAnimationProgress;
138 float mLastDividerProgress;
Jorim Jaggi85639432016-05-06 17:27:55 -0700139 private final DividerSnapAlgorithm[] mSnapAlgorithmForRotation = new DividerSnapAlgorithm[4];
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -0700140 private boolean mImeHideRequested;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800141
142 DockedStackDividerController(WindowManagerService service, DisplayContent displayContent) {
143 mService = service;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700144 mDisplayContent = displayContent;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800145 final Context context = service.mContext;
Jorim Jaggibc5425c2016-03-01 13:51:16 +0100146 mDimLayer = new DimLayer(displayContent.mService, this, displayContent.getDisplayId(),
147 "DockedStackDim");
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800148 mMinimizedDockInterpolator = AnimationUtils.loadInterpolator(
149 context, android.R.interpolator.fast_out_slow_in);
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700150 loadDimens();
151 }
152
Jorim Jaggi85639432016-05-06 17:27:55 -0700153 int getSmallestWidthDpForBounds(Rect bounds) {
154 final DisplayInfo di = mDisplayContent.getDisplayInfo();
155
Jorim Jaggi85639432016-05-06 17:27:55 -0700156 final int baseDisplayWidth = mDisplayContent.mBaseDisplayWidth;
157 final int baseDisplayHeight = mDisplayContent.mBaseDisplayHeight;
158 int minWidth = Integer.MAX_VALUE;
159
160 // Go through all screen orientations and find the orientation in which the task has the
161 // smallest width.
162 for (int rotation = 0; rotation < 4; rotation++) {
163 mTmpRect.set(bounds);
164 mDisplayContent.rotateBounds(di.rotation, rotation, mTmpRect);
165 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
166 mTmpRect2.set(0, 0,
167 rotated ? baseDisplayHeight : baseDisplayWidth,
168 rotated ? baseDisplayWidth : baseDisplayHeight);
169 final int orientation = mTmpRect2.width() <= mTmpRect2.height()
170 ? ORIENTATION_PORTRAIT
171 : ORIENTATION_LANDSCAPE;
172 final int dockSide = TaskStack.getDockSideUnchecked(mTmpRect, mTmpRect2, orientation);
173 final int position = DockedDividerUtils.calculatePositionForBounds(mTmpRect, dockSide,
174 getContentWidth());
175
176 // Since we only care about feasible states, snap to the closest snap target, like it
177 // would happen when actually rotating the screen.
178 final int snappedPosition = mSnapAlgorithmForRotation[rotation]
179 .calculateNonDismissingSnapTarget(position).position;
180 DockedDividerUtils.calculateBoundsForPosition(snappedPosition, dockSide, mTmpRect,
181 mTmpRect2.width(), mTmpRect2.height(), getContentWidth());
182 mService.mPolicy.getStableInsetsLw(rotation, mTmpRect2.width(), mTmpRect2.height(),
183 mTmpRect3);
Winson Chungbdc646f2017-02-13 12:12:22 -0800184 mService.intersectDisplayInsetBounds(mTmpRect2, mTmpRect3, mTmpRect);
Jorim Jaggi85639432016-05-06 17:27:55 -0700185 minWidth = Math.min(mTmpRect.width(), minWidth);
186 }
187 return (int) (minWidth / mDisplayContent.getDisplayMetrics().density);
188 }
189
Matthew Nge15352e2016-12-20 15:36:29 -0800190 void getHomeStackBoundsInDockedMode(Rect outBounds) {
191 final DisplayInfo di = mDisplayContent.getDisplayInfo();
192 mService.mPolicy.getStableInsetsLw(di.rotation, di.logicalWidth, di.logicalHeight,
193 mTmpRect);
194 int dividerSize = mDividerWindowWidth - 2 * mDividerInsets;
195 Configuration configuration = mDisplayContent.getConfiguration();
Matthew Nga9e173d2017-05-17 15:03:18 -0700196 // The offset in the left (landscape)/top (portrait) is calculated with the minimized
197 // offset value with the divider size and any system insets in that direction.
Matthew Nge15352e2016-12-20 15:36:29 -0800198 if (configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
199 outBounds.set(0, mTaskHeightInMinimizedMode + dividerSize + mTmpRect.top,
200 di.logicalWidth, di.logicalHeight);
201 } else {
Matthew Nga9e173d2017-05-17 15:03:18 -0700202 // In landscape append the left position with the statusbar height to match the
203 // minimized size height in portrait mode.
204 outBounds.set(mTaskHeightInMinimizedMode + dividerSize + mTmpRect.left + mTmpRect.top,
205 0, di.logicalWidth, di.logicalHeight);
Matthew Nge15352e2016-12-20 15:36:29 -0800206 }
207 }
208
209 boolean isHomeStackResizable() {
210 final TaskStack homeStack = mDisplayContent.getHomeStack();
211 if (homeStack == null) {
212 return false;
213 }
214 final Task homeTask = homeStack.findHomeTask();
215 return homeTask != null && homeTask.isResizeable();
216 }
217
Jorim Jaggi85639432016-05-06 17:27:55 -0700218 private void initSnapAlgorithmForRotations() {
Andrii Kulian441e4492016-09-29 15:25:00 -0700219 final Configuration baseConfig = mDisplayContent.getConfiguration();
Jorim Jaggi85639432016-05-06 17:27:55 -0700220
221 // Initialize the snap algorithms for all 4 screen orientations.
222 final Configuration config = new Configuration();
223 for (int rotation = 0; rotation < 4; rotation++) {
224 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
225 final int dw = rotated
226 ? mDisplayContent.mBaseDisplayHeight
227 : mDisplayContent.mBaseDisplayWidth;
228 final int dh = rotated
229 ? mDisplayContent.mBaseDisplayWidth
230 : mDisplayContent.mBaseDisplayHeight;
231 mService.mPolicy.getStableInsetsLw(rotation, dw, dh, mTmpRect);
Andrii Kulianb10330d2016-09-16 13:51:46 -0700232 config.unset();
Jorim Jaggi85639432016-05-06 17:27:55 -0700233 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
Bryce Lee7566d762017-03-30 09:34:15 -0700234
235 final int displayId = mDisplayContent.getDisplayId();
236 final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation,
237 baseConfig.uiMode, displayId);
238 final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation,
239 baseConfig.uiMode, displayId);
240 mService.mPolicy.getNonDecorInsetsLw(rotation, dw, dh, mTmpRect);
241 final int leftInset = mTmpRect.left;
242 final int topInset = mTmpRect.top;
243
244 config.setAppBounds(leftInset /*left*/, topInset /*top*/, leftInset + appWidth /*right*/,
245 topInset + appHeight /*bottom*/);
246
Jorim Jaggi85639432016-05-06 17:27:55 -0700247 config.screenWidthDp = (int)
Andrii Kuliandb8e1062016-11-15 18:30:27 -0800248 (mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, baseConfig.uiMode,
Bryce Lee7566d762017-03-30 09:34:15 -0700249 displayId) / mDisplayContent.getDisplayMetrics().density);
Jorim Jaggi85639432016-05-06 17:27:55 -0700250 config.screenHeightDp = (int)
Andrii Kuliandb8e1062016-11-15 18:30:27 -0800251 (mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, baseConfig.uiMode,
Bryce Lee7566d762017-03-30 09:34:15 -0700252 displayId) / mDisplayContent.getDisplayMetrics().density);
Jorim Jaggi85639432016-05-06 17:27:55 -0700253 final Context rotationContext = mService.mContext.createConfigurationContext(config);
254 mSnapAlgorithmForRotation[rotation] = new DividerSnapAlgorithm(
255 rotationContext.getResources(), dw, dh, getContentWidth(),
256 config.orientation == ORIENTATION_PORTRAIT, mTmpRect);
257 }
258 }
259
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700260 private void loadDimens() {
261 final Context context = mService.mContext;
262 mDividerWindowWidth = context.getResources().getDimensionPixelSize(
263 com.android.internal.R.dimen.docked_stack_divider_thickness);
264 mDividerInsets = context.getResources().getDimensionPixelSize(
265 com.android.internal.R.dimen.docked_stack_divider_insets);
Chong Zhang198afac2016-04-15 12:03:11 -0700266 mDividerWindowWidthInactive = WindowManagerService.dipToPixel(
267 DIVIDER_WIDTH_INACTIVE_DP, mDisplayContent.getDisplayMetrics());
Matthew Nge15352e2016-12-20 15:36:29 -0800268 mTaskHeightInMinimizedMode = context.getResources().getDimensionPixelSize(
269 com.android.internal.R.dimen.task_height_of_minimized_mode);
Jorim Jaggi85639432016-05-06 17:27:55 -0700270 initSnapAlgorithmForRotations();
Jorim Jaggi11c62e12016-04-05 20:41:21 -0700271 }
272
273 void onConfigurationChanged() {
274 loadDimens();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700275 }
276
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100277 boolean isResizing() {
278 return mResizing;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700279 }
280
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100281 int getContentWidth() {
282 return mDividerWindowWidth - 2 * mDividerInsets;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700283 }
284
Jorim Jaggi81ba11e2016-02-03 22:04:22 -0800285 int getContentInsets() {
286 return mDividerInsets;
287 }
288
Chong Zhang198afac2016-04-15 12:03:11 -0700289 int getContentWidthInactive() {
290 return mDividerWindowWidthInactive;
291 }
292
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100293 void setResizing(boolean resizing) {
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800294 if (mResizing != resizing) {
295 mResizing = resizing;
296 resetDragResizingChangeReported();
297 }
298 }
299
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100300 void setTouchRegion(Rect touchRegion) {
301 mTouchRegion.set(touchRegion);
302 }
303
304 void getTouchRegion(Rect outRegion) {
305 outRegion.set(mTouchRegion);
306 outRegion.offset(mWindow.getFrameLw().left, mWindow.getFrameLw().top);
307 }
308
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800309 private void resetDragResizingChangeReported() {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800310 mDisplayContent.forAllWindows(WindowState::resetDragResizingChangeReported,
311 true /* traverseTopToBottom */ );
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100312 }
313
314 void setWindow(WindowState window) {
315 mWindow = window;
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -0800316 reevaluateVisibility(false);
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100317 }
318
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -0800319 void reevaluateVisibility(boolean force) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800320 if (mWindow == null) {
321 return;
322 }
Jorim Jaggife762342016-10-13 14:33:27 +0200323 TaskStack stack = mDisplayContent.getDockedStackIgnoringVisibility();
Jorim Jaggi7998e482016-02-12 18:47:06 -0800324
325 // If the stack is invisible, we policy force hide it in WindowAnimator.shouldForceHide
326 final boolean visible = stack != null;
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -0800327 if (mLastVisibility == visible && !force) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800328 return;
329 }
330 mLastVisibility = visible;
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100331 notifyDockedDividerVisibilityChanged(visible);
Jorim Jaggi50981592015-12-29 17:54:12 +0100332 if (!visible) {
333 setResizeDimLayer(false, INVALID_STACK_ID, 0f);
334 }
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100335 }
336
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700337 private boolean wasVisible() {
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100338 return mLastVisibility;
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100339 }
340
Chong Zhangf347ab52016-04-18 21:02:01 -0700341 void setAdjustedForIme(
342 boolean adjustedForIme, boolean adjustedForDivider,
Keisuke Kuroyanagi19d9a8f2016-05-12 16:49:02 -0700343 boolean animate, WindowState imeWin, int imeHeight) {
344 if (mAdjustedForIme != adjustedForIme || (adjustedForIme && mImeHeight != imeHeight)
345 || mAdjustedForDivider != adjustedForDivider) {
Jorim Jaggi3070e772016-05-17 16:41:32 -0700346 if (animate && !mAnimatingForMinimizedDockedStack) {
Chong Zhangf347ab52016-04-18 21:02:01 -0700347 startImeAdjustAnimation(adjustedForIme, adjustedForDivider, imeWin);
Jorim Jaggiff71d202016-04-14 13:12:36 -0700348 } else {
Jorim Jaggiff71d202016-04-14 13:12:36 -0700349 // Animation might be delayed, so only notify if we don't run an animation.
Chong Zhangf347ab52016-04-18 21:02:01 -0700350 notifyAdjustedForImeChanged(adjustedForIme || adjustedForDivider, 0 /* duration */);
Jorim Jaggieb88d832016-04-13 20:17:43 -0700351 }
Chong Zhangf347ab52016-04-18 21:02:01 -0700352 mAdjustedForIme = adjustedForIme;
Keisuke Kuroyanagi19d9a8f2016-05-12 16:49:02 -0700353 mImeHeight = imeHeight;
Chong Zhangf347ab52016-04-18 21:02:01 -0700354 mAdjustedForDivider = adjustedForDivider;
Chong Zhangbaba7832016-03-24 10:21:26 -0700355 }
Chong Zhangb58bbcc2016-03-23 11:57:36 -0700356 }
357
Keisuke Kuroyanagi19d9a8f2016-05-12 16:49:02 -0700358 int getImeHeightAdjustedFor() {
359 return mImeHeight;
360 }
361
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700362 void positionDockedStackedDivider(Rect frame) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700363 TaskStack stack = mDisplayContent.getDockedStackLocked();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700364 if (stack == null) {
365 // Unfortunately we might end up with still having a divider, even though the underlying
366 // stack was already removed. This is because we are on AM thread and the removal of the
Filip Gruszczynski77049052015-11-09 14:01:21 -0800367 // divider was deferred to WM thread and hasn't happened yet. In that case let's just
368 // keep putting it in the same place it was before the stack was removed to have
369 // continuity and prevent it from jumping to the center. It will get hidden soon.
370 frame.set(mLastRect);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700371 return;
Filip Gruszczynski77049052015-11-09 14:01:21 -0800372 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800373 stack.getDimBounds(mTmpRect);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700374 }
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100375 int side = stack.getDockSide();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700376 switch (side) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700377 case DOCKED_LEFT:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100378 frame.set(mTmpRect.right - mDividerInsets, frame.top,
379 mTmpRect.right + frame.width() - mDividerInsets, frame.bottom);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700380 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700381 case DOCKED_TOP:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100382 frame.set(frame.left, mTmpRect.bottom - mDividerInsets,
383 mTmpRect.right, mTmpRect.bottom + frame.height() - mDividerInsets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700384 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700385 case DOCKED_RIGHT:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100386 frame.set(mTmpRect.left - frame.width() + mDividerInsets, frame.top,
387 mTmpRect.left + mDividerInsets, frame.bottom);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700388 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700389 case DOCKED_BOTTOM:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100390 frame.set(frame.left, mTmpRect.top - frame.height() + mDividerInsets,
391 frame.right, mTmpRect.top + mDividerInsets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700392 break;
393 }
Filip Gruszczynski77049052015-11-09 14:01:21 -0800394 mLastRect.set(frame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700395 }
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800396
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700397 private void notifyDockedDividerVisibilityChanged(boolean visible) {
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100398 final int size = mDockedStackListeners.beginBroadcast();
399 for (int i = 0; i < size; ++i) {
400 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
401 try {
402 listener.onDividerVisibilityChanged(visible);
403 } catch (RemoteException e) {
404 Slog.e(TAG_WM, "Error delivering divider visibility changed event.", e);
405 }
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800406 }
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100407 mDockedStackListeners.finishBroadcast();
408 }
409
410 void notifyDockedStackExistsChanged(boolean exists) {
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700411 // TODO(multi-display): Perform all actions only for current display.
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100412 final int size = mDockedStackListeners.beginBroadcast();
413 for (int i = 0; i < size; ++i) {
414 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
415 try {
416 listener.onDockedStackExistsChanged(exists);
417 } catch (RemoteException e) {
418 Slog.e(TAG_WM, "Error delivering docked stack exists changed event.", e);
419 }
420 }
421 mDockedStackListeners.finishBroadcast();
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -0700422 if (exists) {
423 InputMethodManagerInternal inputMethodManagerInternal =
424 LocalServices.getService(InputMethodManagerInternal.class);
425 if (inputMethodManagerInternal != null) {
426
427 // Hide the current IME to avoid problems with animations from IME adjustment when
428 // attaching the docked stack.
429 inputMethodManagerInternal.hideCurrentInputMethod();
430 mImeHideRequested = true;
431 }
Matthew Ngbc527a32017-06-19 16:42:31 -0700432 return;
Jorim Jaggief92d6f2016-03-25 22:07:16 -0700433 }
Matthew Ngbc527a32017-06-19 16:42:31 -0700434 setMinimizedDockedStack(false /* minimizedDock */, false /* animate */);
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100435 }
436
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -0700437 /**
438 * Resets the state that IME hide has been requested. See {@link #isImeHideRequested}.
439 */
440 void resetImeHideRequested() {
441 mImeHideRequested = false;
442 }
443
444 /**
445 * The docked stack divider controller makes sure the IME gets hidden when attaching the docked
446 * stack, to avoid animation problems. This flag indicates whether the request to hide the IME
447 * has been sent in an asynchronous manner, and the IME should be treated as hidden already.
448 *
449 * @return whether IME hide request has been sent
450 */
451 boolean isImeHideRequested() {
452 return mImeHideRequested;
453 }
454
Matthew Nge15352e2016-12-20 15:36:29 -0800455 private void notifyDockedStackMinimizedChanged(boolean minimizedDock, boolean animate,
456 boolean isHomeStackResizable) {
457 long animDuration = 0;
458 if (animate) {
459 final TaskStack stack = mDisplayContent.getStackById(DOCKED_STACK_ID);
460 final long transitionDuration = isAnimationMaximizing()
461 ? mService.mAppTransition.getLastClipRevealTransitionDuration()
462 : DEFAULT_APP_TRANSITION_DURATION;
463 mAnimationDuration = (long)
464 (transitionDuration * mService.getTransitionAnimationScaleLocked());
465 mMaximizeMeetFraction = getClipRevealMeetFraction(stack);
466 animDuration = (long) (mAnimationDuration * mMaximizeMeetFraction);
467 }
Tony Mak853304c2016-04-18 15:17:41 +0100468 mService.mH.removeMessages(NOTIFY_DOCKED_STACK_MINIMIZED_CHANGED);
469 mService.mH.obtainMessage(NOTIFY_DOCKED_STACK_MINIMIZED_CHANGED,
470 minimizedDock ? 1 : 0, 0).sendToTarget();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800471 final int size = mDockedStackListeners.beginBroadcast();
472 for (int i = 0; i < size; ++i) {
473 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
474 try {
Matthew Nge15352e2016-12-20 15:36:29 -0800475 listener.onDockedStackMinimizedChanged(minimizedDock, animDuration,
476 isHomeStackResizable);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800477 } catch (RemoteException e) {
478 Slog.e(TAG_WM, "Error delivering minimized dock changed event.", e);
479 }
480 }
481 mDockedStackListeners.finishBroadcast();
482 }
483
Jorim Jaggi2917dc42016-04-11 11:39:13 -0700484 void notifyDockSideChanged(int newDockSide) {
485 final int size = mDockedStackListeners.beginBroadcast();
486 for (int i = 0; i < size; ++i) {
487 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
488 try {
489 listener.onDockSideChanged(newDockSide);
490 } catch (RemoteException e) {
491 Slog.e(TAG_WM, "Error delivering dock side changed event.", e);
492 }
493 }
494 mDockedStackListeners.finishBroadcast();
495 }
496
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700497 private void notifyAdjustedForImeChanged(boolean adjustedForIme, long animDuration) {
Jorim Jaggi698e7632016-04-13 21:02:22 -0700498 final int size = mDockedStackListeners.beginBroadcast();
499 for (int i = 0; i < size; ++i) {
500 final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
501 try {
502 listener.onAdjustedForImeChanged(adjustedForIme, animDuration);
503 } catch (RemoteException e) {
504 Slog.e(TAG_WM, "Error delivering adjusted for ime changed event.", e);
505 }
506 }
507 mDockedStackListeners.finishBroadcast();
508 }
509
Jorim Jaggia6c934e2015-12-21 13:22:31 +0100510 void registerDockedStackListener(IDockedStackListener listener) {
511 mDockedStackListeners.register(listener);
512 notifyDockedDividerVisibilityChanged(wasVisible());
Wale Ogunwale1666e312016-12-16 11:27:18 -0800513 notifyDockedStackExistsChanged(mDisplayContent.getDockedStackIgnoringVisibility() != null);
Matthew Nge15352e2016-12-20 15:36:29 -0800514 notifyDockedStackMinimizedChanged(mMinimizedDock, false /* animate */,
515 isHomeStackResizable());
Jorim Jaggi698e7632016-04-13 21:02:22 -0700516 notifyAdjustedForImeChanged(mAdjustedForIme, 0 /* animDuration */);
517
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800518 }
Jorim Jaggi50981592015-12-29 17:54:12 +0100519
520 void setResizeDimLayer(boolean visible, int targetStackId, float alpha) {
Robert Carr68e5c9e2016-09-14 10:50:09 -0700521 mService.openSurfaceTransaction();
Wale Ogunwale1666e312016-12-16 11:27:18 -0800522 final TaskStack stack = mDisplayContent.getStackById(targetStackId);
Jorim Jaggibc5425c2016-03-01 13:51:16 +0100523 final TaskStack dockedStack = mDisplayContent.getDockedStackLocked();
524 boolean visibleAndValid = visible && stack != null && dockedStack != null;
Jorim Jaggi7b371dd2016-01-05 15:32:34 +0100525 if (visibleAndValid) {
Jorim Jaggi50981592015-12-29 17:54:12 +0100526 stack.getDimBounds(mTmpRect);
Jorim Jaggi10b89dc2016-01-05 15:40:17 +0100527 if (mTmpRect.height() > 0 && mTmpRect.width() > 0) {
Jorim Jaggi7b371dd2016-01-05 15:32:34 +0100528 mDimLayer.setBounds(mTmpRect);
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700529 mDimLayer.show(getResizeDimLayer(), alpha, 0 /* duration */);
Jorim Jaggi7b371dd2016-01-05 15:32:34 +0100530 } else {
531 visibleAndValid = false;
532 }
533 }
534 if (!visibleAndValid) {
Jorim Jaggi50981592015-12-29 17:54:12 +0100535 mDimLayer.hide();
536 }
Robert Carr68e5c9e2016-09-14 10:50:09 -0700537 mService.closeSurfaceTransaction();
Jorim Jaggi50981592015-12-29 17:54:12 +0100538 }
539
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800540 /**
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700541 * @return The layer used for dimming the apps when dismissing docked/fullscreen stack. Just
542 * above all application surfaces.
543 */
544 private int getResizeDimLayer() {
545 return (mWindow != null) ? mWindow.mLayer - 1 : LAYER_OFFSET_DIM;
546 }
547
548 /**
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800549 * Notifies the docked stack divider controller of a visibility change that happens without
550 * an animation.
551 */
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700552 void notifyAppVisibilityChanged() {
553 checkMinimizeChanged(false /* animate */);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800554 }
555
Jorim Jaggi84afb1a2016-09-28 14:54:04 +0200556 void notifyAppTransitionStarting(ArraySet<AppWindowToken> openingApps, int appTransition) {
Jorim Jaggi936aaeb2016-08-26 19:02:11 -0700557 final boolean wasMinimized = mMinimizedDock;
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700558 checkMinimizeChanged(true /* animate */);
Jorim Jaggi936aaeb2016-08-26 19:02:11 -0700559
560 // We were minimized, and now we are still minimized, but somebody is trying to launch an
Matthew Ng8e265522017-02-13 11:09:37 -0800561 // app in docked stack, better show recent apps so we actually get unminimized! However do
562 // not do this if keyguard is dismissed such as when the device is unlocking. This catches
Jorim Jaggi936aaeb2016-08-26 19:02:11 -0700563 // any case that was missed in ActivityStarter.postStartActivityUncheckedProcessing because
564 // we couldn't retrace the launch of the app in the docked stack to the launch from
565 // homescreen.
Jorim Jaggi84afb1a2016-09-28 14:54:04 +0200566 if (wasMinimized && mMinimizedDock && containsAppInDockedStack(openingApps)
Matthew Ng8e265522017-02-13 11:09:37 -0800567 && appTransition != TRANSIT_NONE &&
568 !AppTransition.isKeyguardGoingAwayTransit(appTransition)) {
Jorim Jaggi936aaeb2016-08-26 19:02:11 -0700569 mService.showRecentApps(true /* fromHome */);
570 }
571 }
572
573 /**
574 * @return true if {@param apps} contains an activity in the docked stack, false otherwise.
575 */
576 private boolean containsAppInDockedStack(ArraySet<AppWindowToken> apps) {
577 for (int i = apps.size() - 1; i >= 0; i--) {
578 final AppWindowToken token = apps.valueAt(i);
Bryce Lee6d410262017-02-28 15:30:17 -0800579 if (token.getTask() != null && token.getTask().mStack.mStackId == DOCKED_STACK_ID) {
Jorim Jaggi936aaeb2016-08-26 19:02:11 -0700580 return true;
581 }
582 }
583 return false;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800584 }
585
Jorim Jaggi1ae68bf2016-05-09 18:44:34 -0700586 boolean isMinimizedDock() {
587 return mMinimizedDock;
588 }
589
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700590 private void checkMinimizeChanged(boolean animate) {
Jorim Jaggife762342016-10-13 14:33:27 +0200591 if (mDisplayContent.getDockedStackIgnoringVisibility() == null) {
Jorim Jaggi817a5242016-05-06 15:45:00 -0700592 return;
593 }
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700594 final TaskStack homeStack = mDisplayContent.getHomeStack();
595 if (homeStack == null) {
596 return;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800597 }
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700598 final Task homeTask = homeStack.findHomeTask();
599 if (homeTask == null || !isWithinDisplay(homeTask)) {
600 return;
601 }
Matthew Ng8e265522017-02-13 11:09:37 -0800602
603 // Do not minimize when dock is already minimized while keyguard is showing and not
604 // occluded such as unlocking the screen
605 if (mMinimizedDock && mService.mPolicy.isKeyguardShowingAndNotOccluded()) {
606 return;
607 }
Wale Ogunwale1666e312016-12-16 11:27:18 -0800608 final TaskStack fullscreenStack =
609 mDisplayContent.getStackById(FULLSCREEN_WORKSPACE_STACK_ID);
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700610 final boolean homeVisible = homeTask.getTopVisibleAppToken() != null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700611 final boolean homeBehind = (fullscreenStack != null && fullscreenStack.isVisible())
Wale Ogunwale15ead902016-09-02 14:30:11 -0700612 || (homeStack.hasMultipleTaskWithHomeTaskNotTop());
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800613 setMinimizedDockedStack(homeVisible && !homeBehind, animate);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800614 }
615
616 private boolean isWithinDisplay(Task task) {
617 task.mStack.getBounds(mTmpRect);
618 mDisplayContent.getLogicalDisplayRect(mTmpRect2);
619 return mTmpRect.intersect(mTmpRect2);
620 }
621
622 /**
623 * Sets whether the docked stack is currently in a minimized state, i.e. all the tasks in the
624 * docked stack are heavily clipped so you can only see a minimal peek state.
625 *
626 * @param minimizedDock Whether the docked stack is currently minimized.
627 * @param animate Whether to animate the change.
628 */
629 private void setMinimizedDockedStack(boolean minimizedDock, boolean animate) {
Jorim Jaggief92d6f2016-03-25 22:07:16 -0700630 final boolean wasMinimized = mMinimizedDock;
631 mMinimizedDock = minimizedDock;
Jorim Jaggi817a5242016-05-06 15:45:00 -0700632 if (minimizedDock == wasMinimized) {
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800633 return;
634 }
635
Chong Zhang22eff0a2016-07-01 14:48:11 -0700636 final boolean imeChanged = clearImeAdjustAnimation();
637 boolean minimizedChange = false;
Matthew Nge15352e2016-12-20 15:36:29 -0800638 if (isHomeStackResizable()) {
639 notifyDockedStackMinimizedChanged(minimizedDock, true /* animate */,
640 true /* isHomeStackResizable */);
641 minimizedChange = true;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800642 } else {
Matthew Nge15352e2016-12-20 15:36:29 -0800643 if (minimizedDock) {
644 if (animate) {
645 startAdjustAnimation(0f, 1f);
646 } else {
647 minimizedChange |= setMinimizedDockedStack(true);
648 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800649 } else {
Matthew Nge15352e2016-12-20 15:36:29 -0800650 if (animate) {
651 startAdjustAnimation(1f, 0f);
652 } else {
653 minimizedChange |= setMinimizedDockedStack(false);
654 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800655 }
656 }
Chong Zhang22eff0a2016-07-01 14:48:11 -0700657 if (imeChanged || minimizedChange) {
658 if (imeChanged && !minimizedChange) {
659 Slog.d(TAG, "setMinimizedDockedStack: IME adjust changed due to minimizing,"
660 + " minimizedDock=" + minimizedDock
661 + " minimizedChange=" + minimizedChange);
662 }
663 mService.mWindowPlacerLocked.performSurfacePlacement();
664 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800665 }
666
Chong Zhang22eff0a2016-07-01 14:48:11 -0700667 private boolean clearImeAdjustAnimation() {
Wale Ogunwale10124582016-09-15 20:25:50 -0700668 final boolean changed = mDisplayContent.clearImeAdjustAnimation();
Jorim Jaggieb88d832016-04-13 20:17:43 -0700669 mAnimatingForIme = false;
Chong Zhang22eff0a2016-07-01 14:48:11 -0700670 return changed;
Jorim Jaggieb88d832016-04-13 20:17:43 -0700671 }
672
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800673 private void startAdjustAnimation(float from, float to) {
Chong Zhangbaba7832016-03-24 10:21:26 -0700674 mAnimatingForMinimizedDockedStack = true;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800675 mAnimationStarted = false;
676 mAnimationStart = from;
677 mAnimationTarget = to;
678 }
679
Chong Zhangf347ab52016-04-18 21:02:01 -0700680 private void startImeAdjustAnimation(
681 boolean adjustedForIme, boolean adjustedForDivider, WindowState imeWin) {
Chong Zhangf347ab52016-04-18 21:02:01 -0700682
683 // If we're not in an animation, the starting point depends on whether we're adjusted
684 // or not. If we're already in an animation, we start from where the current animation
685 // left off, so that the motion doesn't look discontinuous.
686 if (!mAnimatingForIme) {
687 mAnimationStart = mAdjustedForIme ? 1 : 0;
688 mDividerAnimationStart = mAdjustedForDivider ? 1 : 0;
689 mLastAnimationProgress = mAnimationStart;
690 mLastDividerProgress = mDividerAnimationStart;
691 } else {
692 mAnimationStart = mLastAnimationProgress;
693 mDividerAnimationStart = mLastDividerProgress;
694 }
Jorim Jaggi3070e772016-05-17 16:41:32 -0700695 mAnimatingForIme = true;
696 mAnimationStarted = false;
Chong Zhangf347ab52016-04-18 21:02:01 -0700697 mAnimationTarget = adjustedForIme ? 1 : 0;
698 mDividerAnimationTarget = adjustedForDivider ? 1 : 0;
Jorim Jaggiff71d202016-04-14 13:12:36 -0700699
Wale Ogunwale10124582016-09-15 20:25:50 -0700700 mDisplayContent.beginImeAdjustAnimation();
Jorim Jaggiff71d202016-04-14 13:12:36 -0700701
702 // We put all tasks into drag resizing mode - wait until all of them have completed the
703 // drag resizing switch.
704 if (!mService.mWaitingForDrawn.isEmpty()) {
705 mService.mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT);
706 mService.mH.sendEmptyMessageDelayed(H.WAITING_FOR_DRAWN_TIMEOUT,
707 IME_ADJUST_DRAWN_TIMEOUT);
708 mAnimationStartDelayed = true;
709 if (imeWin != null) {
710
711 // There might be an old window delaying the animation start - clear it.
712 if (mDelayedImeWin != null) {
713 mDelayedImeWin.mWinAnimator.endDelayingAnimationStart();
714 }
715 mDelayedImeWin = imeWin;
716 imeWin.mWinAnimator.startDelayingAnimationStart();
717 }
Jorim Jaggi31883862016-11-04 15:45:30 -0700718
719 // If we are already waiting for something to be drawn, clear out the old one so it
720 // still gets executed.
721 // TODO: Have a real system where we can wait on different windows to be drawn with
722 // different callbacks.
723 if (mService.mWaitingForDrawnCallback != null) {
724 mService.mWaitingForDrawnCallback.run();
725 }
Jorim Jaggiff71d202016-04-14 13:12:36 -0700726 mService.mWaitingForDrawnCallback = () -> {
727 mAnimationStartDelayed = false;
728 if (mDelayedImeWin != null) {
729 mDelayedImeWin.mWinAnimator.endDelayingAnimationStart();
730 }
Chong Zhang22eff0a2016-07-01 14:48:11 -0700731 // If the adjust status changed since this was posted, only notify
732 // the new states and don't animate.
733 long duration = 0;
734 if (mAdjustedForIme == adjustedForIme
735 && mAdjustedForDivider == adjustedForDivider) {
736 duration = IME_ADJUST_ANIM_DURATION;
737 } else {
738 Slog.w(TAG, "IME adjust changed while waiting for drawn:"
739 + " adjustedForIme=" + adjustedForIme
740 + " adjustedForDivider=" + adjustedForDivider
741 + " mAdjustedForIme=" + mAdjustedForIme
742 + " mAdjustedForDivider=" + mAdjustedForDivider);
743 }
Chong Zhangf347ab52016-04-18 21:02:01 -0700744 notifyAdjustedForImeChanged(
Chong Zhang22eff0a2016-07-01 14:48:11 -0700745 mAdjustedForIme || mAdjustedForDivider, duration);
Jorim Jaggiff71d202016-04-14 13:12:36 -0700746 };
747 } else {
Chong Zhangf347ab52016-04-18 21:02:01 -0700748 notifyAdjustedForImeChanged(
749 adjustedForIme || adjustedForDivider, IME_ADJUST_ANIM_DURATION);
Jorim Jaggiff71d202016-04-14 13:12:36 -0700750 }
Jorim Jaggieb88d832016-04-13 20:17:43 -0700751 }
752
Chong Zhang22eff0a2016-07-01 14:48:11 -0700753 private boolean setMinimizedDockedStack(boolean minimized) {
Jorim Jaggife762342016-10-13 14:33:27 +0200754 final TaskStack stack = mDisplayContent.getDockedStackIgnoringVisibility();
Matthew Nge15352e2016-12-20 15:36:29 -0800755 notifyDockedStackMinimizedChanged(minimized, false /* animate */, isHomeStackResizable());
Chong Zhang22eff0a2016-07-01 14:48:11 -0700756 return stack != null && stack.setAdjustedForMinimizedDock(minimized ? 1f : 0f);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800757 }
758
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800759 private boolean isAnimationMaximizing() {
760 return mAnimationTarget == 0f;
761 }
762
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800763 public boolean animate(long now) {
Wale Ogunwale20ec11b2016-04-22 12:11:51 -0700764 if (mWindow == null) {
765 return false;
766 }
Chong Zhangbaba7832016-03-24 10:21:26 -0700767 if (mAnimatingForMinimizedDockedStack) {
768 return animateForMinimizedDockedStack(now);
769 } else if (mAnimatingForIme) {
Jorim Jaggieb88d832016-04-13 20:17:43 -0700770 return animateForIme(now);
Chong Zhangbaba7832016-03-24 10:21:26 -0700771 } else {
Wale Ogunwale20ec11b2016-04-22 12:11:51 -0700772 if (mDimLayer != null && mDimLayer.isDimming()) {
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700773 mDimLayer.setLayer(getResizeDimLayer());
Chong Zhang1402c2e2016-04-21 15:17:47 -0700774 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800775 return false;
776 }
Chong Zhangbaba7832016-03-24 10:21:26 -0700777 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800778
Jorim Jaggieb88d832016-04-13 20:17:43 -0700779 private boolean animateForIme(long now) {
Jorim Jaggiff71d202016-04-14 13:12:36 -0700780 if (!mAnimationStarted || mAnimationStartDelayed) {
Jorim Jaggieb88d832016-04-13 20:17:43 -0700781 mAnimationStarted = true;
782 mAnimationStartTime = now;
783 mAnimationDuration = (long)
Jorim Jaggi698e7632016-04-13 21:02:22 -0700784 (IME_ADJUST_ANIM_DURATION * mService.getWindowAnimationScaleLocked());
Jorim Jaggieb88d832016-04-13 20:17:43 -0700785 }
786 float t = Math.min(1f, (float) (now - mAnimationStartTime) / mAnimationDuration);
787 t = (mAnimationTarget == 1f ? IME_ADJUST_ENTRY_INTERPOLATOR : TOUCH_RESPONSE_INTERPOLATOR)
788 .getInterpolation(t);
Wale Ogunwale10124582016-09-15 20:25:50 -0700789 final boolean updated =
790 mDisplayContent.animateForIme(t, mAnimationTarget, mDividerAnimationTarget);
Jorim Jaggieb88d832016-04-13 20:17:43 -0700791 if (updated) {
792 mService.mWindowPlacerLocked.performSurfacePlacement();
793 }
794 if (t >= 1.0f) {
Chong Zhangf347ab52016-04-18 21:02:01 -0700795 mLastAnimationProgress = mAnimationTarget;
796 mLastDividerProgress = mDividerAnimationTarget;
Jorim Jaggieb88d832016-04-13 20:17:43 -0700797 mAnimatingForIme = false;
798 return false;
799 } else {
800 return true;
801 }
Chong Zhangbaba7832016-03-24 10:21:26 -0700802 }
803
804 private boolean animateForMinimizedDockedStack(long now) {
Wale Ogunwale1666e312016-12-16 11:27:18 -0800805 final TaskStack stack = mDisplayContent.getStackById(DOCKED_STACK_ID);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800806 if (!mAnimationStarted) {
807 mAnimationStarted = true;
808 mAnimationStartTime = now;
Matthew Nge15352e2016-12-20 15:36:29 -0800809 notifyDockedStackMinimizedChanged(mMinimizedDock, true /* animate */,
810 isHomeStackResizable() /* isHomeStackResizable */);
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800811 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800812 float t = Math.min(1f, (float) (now - mAnimationStartTime) / mAnimationDuration);
813 t = (isAnimationMaximizing() ? TOUCH_RESPONSE_INTERPOLATOR : mMinimizedDockInterpolator)
814 .getInterpolation(t);
Chong Zhang741c0ba2016-05-27 12:52:11 -0700815 if (stack != null) {
816 if (stack.setAdjustedForMinimizedDock(getMinimizeAmount(stack, t))) {
817 mService.mWindowPlacerLocked.performSurfacePlacement();
818 }
819 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800820 if (t >= 1.0f) {
Chong Zhangbaba7832016-03-24 10:21:26 -0700821 mAnimatingForMinimizedDockedStack = false;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800822 return false;
823 } else {
824 return true;
825 }
826 }
827
Wale Ogunwale10124582016-09-15 20:25:50 -0700828 float getInterpolatedAnimationValue(float t) {
Jorim Jaggieb88d832016-04-13 20:17:43 -0700829 return t * mAnimationTarget + (1 - t) * mAnimationStart;
830 }
831
Wale Ogunwale10124582016-09-15 20:25:50 -0700832 float getInterpolatedDividerValue(float t) {
Chong Zhangf347ab52016-04-18 21:02:01 -0700833 return t * mDividerAnimationTarget + (1 - t) * mDividerAnimationStart;
834 }
835
Jorim Jaggif97ed922016-02-18 18:57:07 -0800836 /**
837 * Gets the amount how much to minimize a stack depending on the interpolated fraction t.
838 */
839 private float getMinimizeAmount(TaskStack stack, float t) {
Jorim Jaggieb88d832016-04-13 20:17:43 -0700840 final float naturalAmount = getInterpolatedAnimationValue(t);
Jorim Jaggif97ed922016-02-18 18:57:07 -0800841 if (isAnimationMaximizing()) {
842 return adjustMaximizeAmount(stack, t, naturalAmount);
843 } else {
844 return naturalAmount;
845 }
846 }
847
848 /**
849 * When maximizing the stack during a clip reveal transition, this adjusts the minimize amount
850 * during the transition such that the edge of the clip reveal rect is met earlier in the
851 * transition so we don't create a visible "hole", but only if both the clip reveal and the
852 * docked stack divider start from about the same portion on the screen.
853 */
854 private float adjustMaximizeAmount(TaskStack stack, float t, float naturalAmount) {
855 if (mMaximizeMeetFraction == 1f) {
856 return naturalAmount;
857 }
858 final int minimizeDistance = stack.getMinimizeDistance();
859 float startPrime = mService.mAppTransition.getLastClipRevealMaxTranslation()
860 / (float) minimizeDistance;
861 final float amountPrime = t * mAnimationTarget + (1 - t) * startPrime;
862 final float t2 = Math.min(t / mMaximizeMeetFraction, 1);
863 return amountPrime * t2 + naturalAmount * (1 - t2);
864 }
865
866 /**
867 * Retrieves the animation fraction at which the docked stack has to meet the clip reveal
868 * edge. See {@link #adjustMaximizeAmount}.
869 */
870 private float getClipRevealMeetFraction(TaskStack stack) {
871 if (!isAnimationMaximizing() || stack == null ||
872 !mService.mAppTransition.hadClipRevealAnimation()) {
873 return 1f;
874 }
875 final int minimizeDistance = stack.getMinimizeDistance();
876 final float fraction = Math.abs(mService.mAppTransition.getLastClipRevealMaxTranslation())
877 / (float) minimizeDistance;
878 final float t = Math.max(0, Math.min(1, (fraction - CLIP_REVEAL_MEET_FRACTION_MIN)
879 / (CLIP_REVEAL_MEET_FRACTION_MAX - CLIP_REVEAL_MEET_FRACTION_MIN)));
880 return CLIP_REVEAL_MEET_EARLIEST
881 + (1 - t) * (CLIP_REVEAL_MEET_LAST - CLIP_REVEAL_MEET_EARLIEST);
882 }
883
Jorim Jaggi50981592015-12-29 17:54:12 +0100884 @Override
Wale Ogunwale29bfbb82016-05-12 15:13:52 -0700885 public boolean dimFullscreen() {
Jorim Jaggi50981592015-12-29 17:54:12 +0100886 return false;
887 }
888
889 @Override
890 public DisplayInfo getDisplayInfo() {
891 return mDisplayContent.getDisplayInfo();
892 }
893
894 @Override
Wale Ogunwalef0a60a92017-01-19 09:44:40 -0800895 public boolean isAttachedToDisplay() {
896 return mDisplayContent != null;
897 }
898
899 @Override
Jorim Jaggi50981592015-12-29 17:54:12 +0100900 public void getDimBounds(Rect outBounds) {
901 // This dim layer user doesn't need this.
902 }
903
904 @Override
905 public String toShortString() {
906 return TAG;
907 }
Robert Carre63e01a2016-04-18 20:27:34 -0700908
909 WindowState getWindow() {
910 return mWindow;
911 }
Jorim Jaggi31f71702016-05-04 16:43:04 -0700912
913 void dump(String prefix, PrintWriter pw) {
914 pw.println(prefix + "DockedStackDividerController");
915 pw.println(prefix + " mLastVisibility=" + mLastVisibility);
916 pw.println(prefix + " mMinimizedDock=" + mMinimizedDock);
917 pw.println(prefix + " mAdjustedForIme=" + mAdjustedForIme);
918 pw.println(prefix + " mAdjustedForDivider=" + mAdjustedForDivider);
919 if (mDimLayer.isDimming()) {
920 pw.println(prefix + " Dim layer is dimming: ");
921 mDimLayer.printTo(prefix + " ", pw);
922 }
923 }
Steven Timotiusaf03df62017-07-18 16:56:43 -0700924
925 void writeToProto(ProtoOutputStream proto, long fieldId) {
926 final long token = proto.start(fieldId);
927 proto.write(MINIMIZED_DOCK, mMinimizedDock);
928 proto.end(token);
929 }
Robert Carre63e01a2016-04-18 20:27:34 -0700930}