blob: 4241b326622c410e81c20ecee4805d2508fd5dcd [file] [log] [blame]
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08001/*
2 * Copyright (C) 2013 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 Jaggid53f0922016-04-06 22:16:23 -070019import static android.app.ActivityManager.RESIZE_MODE_SYSTEM_SCREEN_ROTATION;
Robert Carr03138452016-05-18 14:53:16 -070020import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Wale Ogunwale3797c222015-10-27 14:21:58 -070021import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
22import static android.app.ActivityManager.StackId.HOME_STACK_ID;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -080023import static android.content.pm.ActivityInfo.RESIZE_MODE_CROP_WINDOWS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080024import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
Jorim Jaggid53f0922016-04-06 22:16:23 -070025import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
26import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwale1ed0d892015-09-28 13:27:44 -070027import static com.android.server.wm.WindowManagerService.H.RESIZE_TASK;
Wale Ogunwale99db1862015-10-23 20:08:22 -070028
Wale Ogunwale3797c222015-10-27 14:21:58 -070029import android.app.ActivityManager.StackId;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -080030import android.content.pm.ActivityInfo;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070031import android.content.res.Configuration;
32import android.graphics.Rect;
Craig Mautner2c2549c2013-11-12 08:31:15 -080033import android.util.EventLog;
Craig Mautner42bf39e2014-02-21 16:46:22 -080034import android.util.Slog;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070035import android.view.DisplayInfo;
36import android.view.Surface;
Jorim Jaggi6626f542016-08-22 13:08:44 -070037import android.view.animation.Animation;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070038
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070039import android.view.SurfaceControl;
Craig Mautnere3119b72015-01-20 15:02:36 -080040import com.android.server.EventLogTags;
Craig Mautner2c2549c2013-11-12 08:31:15 -080041
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070042import java.io.PrintWriter;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070043
44class Task implements DimLayer.DimLayerUser {
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -080045 static final String TAG = TAG_WITH_CLASS_NAME ? "Task" : TAG_WM;
Wale Ogunwale2cc92f52015-09-09 13:12:10 -070046 // Return value from {@link setBounds} indicating no change was made to the Task bounds.
47 static final int BOUNDS_CHANGE_NONE = 0;
48 // Return value from {@link setBounds} indicating the position of the Task bounds changed.
49 static final int BOUNDS_CHANGE_POSITION = 1;
50 // Return value from {@link setBounds} indicating the size of the Task bounds changed.
51 static final int BOUNDS_CHANGE_SIZE = 1 << 1;
52
Craig Mautnerc00204b2013-03-05 15:02:14 -080053 TaskStack mStack;
Craig Mautner05d6272ba2013-02-11 09:39:27 -080054 final AppTokenList mAppTokens = new AppTokenList();
Craig Mautner83162a92015-01-26 14:43:30 -080055 final int mTaskId;
Craig Mautnerac6f8432013-07-17 13:24:59 -070056 final int mUserId;
Craig Mautner9ef471f2014-02-07 13:11:47 -080057 boolean mDeferRemoval = false;
Craig Mautnere3119b72015-01-20 15:02:36 -080058 final WindowManagerService mService;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080059
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070060 // Content limits relative to the DisplayContent this sits in.
61 private Rect mBounds = new Rect();
Jorim Jaggi0429f352015-12-22 16:29:16 +010062 final Rect mPreparedFrozenBounds = new Rect();
Jorim Jaggi26c8c422016-05-09 19:57:25 -070063 final Configuration mPreparedFrozenMergedConfig = new Configuration();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070064
Jorim Jaggidc249c42015-12-15 14:57:31 -080065 // Bounds used to calculate the insets.
66 private final Rect mTempInsetBounds = new Rect();
67
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070068 // Device rotation as of the last time {@link #mBounds} was set.
69 int mRotation;
70
71 // Whether mBounds is fullscreen
72 private boolean mFullscreen = true;
73
74 // Contains configurations settings that are different from the global configuration due to
75 // stack specific operations. E.g. {@link #setBounds}.
Jorim Jaggi26c8c422016-05-09 19:57:25 -070076 Configuration mOverrideConfig = Configuration.EMPTY;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070077
78 // For comparison with DisplayContent bounds.
79 private Rect mTmpRect = new Rect();
80 // For handling display rotations.
81 private Rect mTmpRect2 = new Rect();
82
Wale Ogunwaleb1faf602016-01-27 09:12:31 -080083 // Resize mode of the task. See {@link ActivityInfo#resizeMode}
84 private int mResizeMode;
Chong Zhangb15758a2015-11-17 12:12:03 -080085
Chong Zhang3005e752015-09-18 18:46:28 -070086 // Whether the task is currently being drag-resized
87 private boolean mDragResizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +010088 private int mDragResizeMode;
Chong Zhang3005e752015-09-18 18:46:28 -070089
Wale Ogunwaleb1faf602016-01-27 09:12:31 -080090 private boolean mHomeTask;
91
Jiaquan Hedd1e66f2016-06-15 15:15:12 -070092 // Whether this task is an on-top launcher task, which is determined by the root activity.
93 private boolean mIsOnTopLauncher;
94
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070095 Task(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds,
Jiaquan Hedd1e66f2016-06-15 15:15:12 -070096 Configuration config, boolean isOnTopLauncher) {
Craig Mautner83162a92015-01-26 14:43:30 -080097 mTaskId = taskId;
Craig Mautnerc00204b2013-03-05 15:02:14 -080098 mStack = stack;
Craig Mautnerac6f8432013-07-17 13:24:59 -070099 mUserId = userId;
Craig Mautnere3119b72015-01-20 15:02:36 -0800100 mService = service;
Jiaquan Hedd1e66f2016-06-15 15:15:12 -0700101 mIsOnTopLauncher = isOnTopLauncher;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700102 setBounds(bounds, config);
Craig Mautnerc00204b2013-03-05 15:02:14 -0800103 }
104
105 DisplayContent getDisplayContent() {
106 return mStack.getDisplayContent();
107 }
108
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800109 void addAppToken(int addPos, AppWindowToken wtoken, int resizeMode, boolean homeTask) {
Craig Mautner42bf39e2014-02-21 16:46:22 -0800110 final int lastPos = mAppTokens.size();
Craig Mautner83162a92015-01-26 14:43:30 -0800111 if (addPos >= lastPos) {
112 addPos = lastPos;
113 } else {
114 for (int pos = 0; pos < lastPos && pos < addPos; ++pos) {
115 if (mAppTokens.get(pos).removed) {
116 // addPos assumes removed tokens are actually gone.
117 ++addPos;
118 }
Craig Mautner01f79cf2014-08-27 09:56:02 -0700119 }
Craig Mautner42bf39e2014-02-21 16:46:22 -0800120 }
Craig Mautnerc00204b2013-03-05 15:02:14 -0800121 mAppTokens.add(addPos, wtoken);
Craig Mautner83162a92015-01-26 14:43:30 -0800122 wtoken.mTask = this;
Craig Mautner42bf39e2014-02-21 16:46:22 -0800123 mDeferRemoval = false;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800124 mResizeMode = resizeMode;
125 mHomeTask = homeTask;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800126 }
127
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700128 private boolean hasWindowsAlive() {
Chong Zhang7e8eeb72016-01-06 19:14:47 -0800129 for (int i = mAppTokens.size() - 1; i >= 0; i--) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700130 if (mAppTokens.get(i).hasWindowsAlive()) {
Chong Zhang7e8eeb72016-01-06 19:14:47 -0800131 return true;
132 }
133 }
134 return false;
135 }
136
Craig Mautnere3119b72015-01-20 15:02:36 -0800137 void removeLocked() {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700138 if (hasWindowsAlive() && mStack.isAnimating()) {
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800139 if (DEBUG_STACK) Slog.i(TAG, "removeTask: deferring removing taskId=" + mTaskId);
Craig Mautnere3119b72015-01-20 15:02:36 -0800140 mDeferRemoval = true;
141 return;
142 }
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800143 if (DEBUG_STACK) Slog.i(TAG, "removeTask: removing taskId=" + mTaskId);
Craig Mautner83162a92015-01-26 14:43:30 -0800144 EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "removeTask");
Craig Mautnere3119b72015-01-20 15:02:36 -0800145 mDeferRemoval = false;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700146 DisplayContent content = getDisplayContent();
147 if (content != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800148 content.mDimLayerController.removeDimLayerUser(this);
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700149 }
Craig Mautnere3119b72015-01-20 15:02:36 -0800150 mStack.removeTask(this);
Craig Mautner83162a92015-01-26 14:43:30 -0800151 mService.mTaskIdToTask.delete(mTaskId);
Craig Mautnere3119b72015-01-20 15:02:36 -0800152 }
153
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800154 void moveTaskToStack(TaskStack stack, boolean toTop) {
155 if (stack == mStack) {
156 return;
157 }
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800158 if (DEBUG_STACK) Slog.i(TAG, "moveTaskToStack: removing taskId=" + mTaskId
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800159 + " from stack=" + mStack);
Wale Ogunwale000957c2015-04-03 08:19:12 -0700160 EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask");
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800161 if (mStack != null) {
162 mStack.removeTask(this);
163 }
164 stack.addTask(this, toTop);
165 }
166
Wale Ogunwale935e5022015-11-10 12:36:10 -0800167 void positionTaskInStack(TaskStack stack, int position, Rect bounds, Configuration config) {
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700168 if (mStack != null && stack != mStack) {
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800169 if (DEBUG_STACK) Slog.i(TAG, "positionTaskInStack: removing taskId=" + mTaskId
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700170 + " from stack=" + mStack);
171 EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask");
172 mStack.removeTask(this);
173 }
174 stack.positionTask(this, position, showForAllUsers());
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800175 resizeLocked(bounds, config, false /* force */);
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800176
177 for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700178 mAppTokens.get(activityNdx).notifyMovedInStack();
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800179 }
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700180 }
181
Craig Mautnerc00204b2013-03-05 15:02:14 -0800182 boolean removeAppToken(AppWindowToken wtoken) {
Craig Mautner42bf39e2014-02-21 16:46:22 -0800183 boolean removed = mAppTokens.remove(wtoken);
Craig Mautnerc00204b2013-03-05 15:02:14 -0800184 if (mAppTokens.size() == 0) {
Jorim Jaggi0429f352015-12-22 16:29:16 +0100185 EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "removeAppToken: last token");
Craig Mautnere3119b72015-01-20 15:02:36 -0800186 if (mDeferRemoval) {
187 removeLocked();
188 }
Craig Mautnerc00204b2013-03-05 15:02:14 -0800189 }
Craig Mautner83162a92015-01-26 14:43:30 -0800190 wtoken.mTask = null;
191 /* Leave mTaskId for now, it might be useful for debug
192 wtoken.mTaskId = -1;
193 */
Craig Mautner42bf39e2014-02-21 16:46:22 -0800194 return removed;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800195 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800196
Craig Mautnercbd84af2014-10-22 13:21:22 -0700197 void setSendingToBottom(boolean toBottom) {
198 for (int appTokenNdx = 0; appTokenNdx < mAppTokens.size(); appTokenNdx++) {
199 mAppTokens.get(appTokenNdx).sendingToBottom = toBottom;
200 }
201 }
202
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700203 /** Set the task bounds. Passing in null sets the bounds to fullscreen. */
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800204 private int setBounds(Rect bounds, Configuration config) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700205 if (config == null) {
206 config = Configuration.EMPTY;
207 }
208 if (bounds == null && !Configuration.EMPTY.equals(config)) {
209 throw new IllegalArgumentException("null bounds but non empty configuration: "
210 + config);
211 }
212 if (bounds != null && Configuration.EMPTY.equals(config)) {
213 throw new IllegalArgumentException("non null bounds, but empty configuration");
214 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700215 boolean oldFullscreen = mFullscreen;
216 int rotation = Surface.ROTATION_0;
217 final DisplayContent displayContent = mStack.getDisplayContent();
218 if (displayContent != null) {
219 displayContent.getLogicalDisplayRect(mTmpRect);
220 rotation = displayContent.getDisplayInfo().rotation;
Jorim Jaggi067e8172016-02-03 18:24:12 -0800221 mFullscreen = bounds == null;
222 if (mFullscreen) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700223 bounds = mTmpRect;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700224 }
225 }
226
227 if (bounds == null) {
228 // Can't set to fullscreen if we don't have a display to get bounds from...
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700229 return BOUNDS_CHANGE_NONE;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700230 }
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700231 if (mBounds.equals(bounds) && oldFullscreen == mFullscreen && mRotation == rotation) {
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700232 return BOUNDS_CHANGE_NONE;
233 }
234
235 int boundsChange = BOUNDS_CHANGE_NONE;
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700236 if (mBounds.left != bounds.left || mBounds.top != bounds.top) {
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700237 boundsChange |= BOUNDS_CHANGE_POSITION;
238 }
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700239 if (mBounds.width() != bounds.width() || mBounds.height() != bounds.height()) {
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700240 boundsChange |= BOUNDS_CHANGE_SIZE;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700241 }
242
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700243 mBounds.set(bounds);
Chong Zhangf66db432016-01-13 10:39:51 -0800244
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700245 mRotation = rotation;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700246 if (displayContent != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800247 displayContent.mDimLayerController.updateDimLayer(this);
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700248 }
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700249 mOverrideConfig = mFullscreen ? Configuration.EMPTY : config;
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700250 return boundsChange;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700251 }
252
Jorim Jaggidc249c42015-12-15 14:57:31 -0800253 /**
254 * Sets the bounds used to calculate the insets. See
255 * {@link android.app.IActivityManager#resizeDockedStack} why this is needed.
256 */
257 void setTempInsetBounds(Rect tempInsetBounds) {
258 if (tempInsetBounds != null) {
259 mTempInsetBounds.set(tempInsetBounds);
260 } else {
261 mTempInsetBounds.setEmpty();
262 }
263 }
264
265 /**
266 * Gets the bounds used to calculate the insets. See
267 * {@link android.app.IActivityManager#resizeDockedStack} why this is needed.
268 */
269 void getTempInsetBounds(Rect out) {
270 out.set(mTempInsetBounds);
271 }
272
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800273 void setResizeable(int resizeMode) {
274 mResizeMode = resizeMode;
Chong Zhangb15758a2015-11-17 12:12:03 -0800275 }
276
277 boolean isResizeable() {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800278 return !mHomeTask
279 && (ActivityInfo.isResizeableMode(mResizeMode) || mService.mForceResizableTasks);
280 }
281
Jiaquan Hedd1e66f2016-06-15 15:15:12 -0700282 boolean isOnTopLauncher() {
283 return mIsOnTopLauncher;
284 }
285
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800286 boolean cropWindowsToStackBounds() {
287 return !mHomeTask && (isResizeable() || mResizeMode == RESIZE_MODE_CROP_WINDOWS);
288 }
289
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800290 boolean isHomeTask() {
291 return mHomeTask;
292 }
293
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800294 private boolean inCropWindowsResizeMode() {
295 return !mHomeTask && !isResizeable() && mResizeMode == RESIZE_MODE_CROP_WINDOWS;
Chong Zhangb15758a2015-11-17 12:12:03 -0800296 }
297
Chong Zhang87b21722015-09-21 15:39:51 -0700298 boolean resizeLocked(Rect bounds, Configuration configuration, boolean forced) {
Chong Zhang3005e752015-09-18 18:46:28 -0700299 int boundsChanged = setBounds(bounds, configuration);
Chong Zhang87b21722015-09-21 15:39:51 -0700300 if (forced) {
Chong Zhang3005e752015-09-18 18:46:28 -0700301 boundsChanged |= BOUNDS_CHANGE_SIZE;
Chong Zhang3005e752015-09-18 18:46:28 -0700302 }
303 if (boundsChanged == BOUNDS_CHANGE_NONE) {
304 return false;
305 }
306 if ((boundsChanged & BOUNDS_CHANGE_SIZE) == BOUNDS_CHANGE_SIZE) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700307 onResize();
Chong Zhangbd0d9372015-12-28 15:18:29 -0800308 } else {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700309 onMovedByResize();
Chong Zhang3005e752015-09-18 18:46:28 -0700310 }
311 return true;
312 }
313
Jorim Jaggi0429f352015-12-22 16:29:16 +0100314 /**
315 * Prepares the task bounds to be frozen with the current size. See
316 * {@link AppWindowToken#freezeBounds}.
317 */
318 void prepareFreezingBounds() {
319 mPreparedFrozenBounds.set(mBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700320 mPreparedFrozenMergedConfig.setTo(mService.mCurConfiguration);
321 mPreparedFrozenMergedConfig.updateFrom(mOverrideConfig);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100322 }
323
Chong Zhang5117e272016-05-03 12:47:34 -0700324 /**
325 * Align the task to the adjusted bounds.
326 *
327 * @param adjustedBounds Adjusted bounds to which the task should be aligned.
328 * @param tempInsetBounds Insets bounds for the task.
329 * @param alignBottom True if the task's bottom should be aligned to the adjusted
330 * bounds's bottom; false if the task's top should be aligned
331 * the adjusted bounds's top.
332 */
333 void alignToAdjustedBounds(
334 Rect adjustedBounds, Rect tempInsetBounds, boolean alignBottom) {
335 if (!isResizeable() || mOverrideConfig == Configuration.EMPTY) {
336 return;
337 }
338
339 getBounds(mTmpRect2);
340 if (alignBottom) {
341 int offsetY = adjustedBounds.bottom - mTmpRect2.bottom;
342 mTmpRect2.offset(0, offsetY);
343 } else {
344 mTmpRect2.offsetTo(adjustedBounds.left, adjustedBounds.top);
345 }
346 setTempInsetBounds(tempInsetBounds);
347 resizeLocked(mTmpRect2, mOverrideConfig, false /* forced */);
348 }
349
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700350 /** Return true if the current bound can get outputted to the rest of the system as-is. */
351 private boolean useCurrentBounds() {
352 final DisplayContent displayContent = mStack.getDisplayContent();
353 if (mFullscreen
Wale Ogunwale3797c222015-10-27 14:21:58 -0700354 || !StackId.isTaskResizeableByDockedStack(mStack.mStackId)
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700355 || displayContent == null
Jorim Jaggif4fa8cb2016-04-01 16:05:10 -0700356 || displayContent.getDockedStackVisibleForUserLocked() != null) {
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700357 return true;
358 }
359 return false;
360 }
361
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800362 /** Original bounds of the task if applicable, otherwise fullscreen rect. */
Wale Ogunwaleccb6ce22016-01-14 15:36:35 -0800363 void getBounds(Rect out) {
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700364 if (useCurrentBounds()) {
365 // No need to adjust the output bounds if fullscreen or the docked stack is visible
366 // since it is already what we want to represent to the rest of the system.
367 out.set(mBounds);
368 return;
369 }
370
Wale Ogunwaleccb6ce22016-01-14 15:36:35 -0800371 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack is
372 // not currently visible. Go ahead a represent it as fullscreen to the rest of the system.
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700373 mStack.getDisplayContent().getLogicalDisplayRect(out);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700374 }
375
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800376 /**
377 * Calculate the maximum visible area of this task. If the task has only one app,
378 * the result will be visible frame of that app. If the task has more than one apps,
379 * we search from top down if the next app got different visible area.
380 *
381 * This effort is to handle the case where some task (eg. GMail composer) might pop up
382 * a dialog that's different in size from the activity below, in which case we should
383 * be dimming the entire task area behind the dialog.
384 *
385 * @param out Rect containing the max visible bounds.
386 * @return true if the task has some visible app windows; false otherwise.
387 */
388 boolean getMaxVisibleBounds(Rect out) {
389 boolean foundTop = false;
390 for (int i = mAppTokens.size() - 1; i >= 0; i--) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800391 final AppWindowToken token = mAppTokens.get(i);
392 // skip hidden (or about to hide) apps
393 if (token.mIsExiting || token.clientHidden || token.hiddenRequested) {
394 continue;
395 }
396 final WindowState win = token.findMainWindow();
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800397 if (win == null) {
398 continue;
399 }
400 if (!foundTop) {
401 out.set(win.mVisibleFrame);
402 foundTop = true;
403 continue;
404 }
405 if (win.mVisibleFrame.left < out.left) {
406 out.left = win.mVisibleFrame.left;
407 }
408 if (win.mVisibleFrame.top < out.top) {
409 out.top = win.mVisibleFrame.top;
410 }
411 if (win.mVisibleFrame.right > out.right) {
412 out.right = win.mVisibleFrame.right;
413 }
414 if (win.mVisibleFrame.bottom > out.bottom) {
415 out.bottom = win.mVisibleFrame.bottom;
416 }
417 }
418 return foundTop;
419 }
420
421 /** Bounds of the task to be used for dimming, as well as touch related tests. */
422 @Override
423 public void getDimBounds(Rect out) {
Robert Carra86a6bf2016-04-08 17:34:16 -0700424 final DisplayContent displayContent = mStack.getDisplayContent();
425 // It doesn't matter if we in particular are part of the resize, since we couldn't have
426 // a DimLayer anyway if we weren't visible.
427 final boolean dockedResizing = displayContent != null ?
428 displayContent.mDividerControllerLocked.isResizing() : false;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800429 if (useCurrentBounds()) {
430 if (inFreeformWorkspace() && getMaxVisibleBounds(out)) {
431 return;
432 }
433
Jorim Jaggi22a869f2016-03-25 23:33:21 -0700434 if (!mFullscreen) {
435 // When minimizing the docked stack when going home, we don't adjust the task bounds
436 // so we need to intersect the task bounds with the stack bounds here.
Robert Carra86a6bf2016-04-08 17:34:16 -0700437 //
438 // If we are Docked Resizing with snap points, the task bounds could be smaller than the stack
439 // bounds and so we don't even want to use them. Even if the app should not be resized the Dim
440 // should keep up with the divider.
441 if (dockedResizing) {
442 mStack.getBounds(out);
443 } else {
444 mStack.getBounds(mTmpRect);
445 mTmpRect.intersect(mBounds);
446 }
Jorim Jaggi22a869f2016-03-25 23:33:21 -0700447 out.set(mTmpRect);
448 } else {
449 out.set(mBounds);
450 }
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800451 return;
452 }
453
454 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack
455 // is not currently visible. Go ahead a represent it as fullscreen to the rest of the
456 // system.
Robert Carra86a6bf2016-04-08 17:34:16 -0700457 displayContent.getLogicalDisplayRect(out);
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800458 }
459
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100460 void setDragResizing(boolean dragResizing, int dragResizeMode) {
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800461 if (mDragResizing != dragResizing) {
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100462 if (!DragResizeMode.isModeAllowedForStack(mStack.mStackId, dragResizeMode)) {
463 throw new IllegalArgumentException("Drag resize mode not allow for stack stackId="
464 + mStack.mStackId + " dragResizeMode=" + dragResizeMode);
465 }
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800466 mDragResizing = dragResizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100467 mDragResizeMode = dragResizeMode;
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800468 resetDragResizingChangeReported();
469 }
470 }
471
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700472 private void resetDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800473 for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700474 mAppTokens.get(activityNdx).resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800475 }
Chong Zhang3005e752015-09-18 18:46:28 -0700476 }
477
478 boolean isDragResizing() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700479 return mDragResizing;
Chong Zhang3005e752015-09-18 18:46:28 -0700480 }
481
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100482 int getDragResizeMode() {
483 return mDragResizeMode;
484 }
485
Jorim Jaggiff71d202016-04-14 13:12:36 -0700486 /**
487 * Adds all of the tasks windows to {@link WindowManagerService#mWaitingForDrawn} if drag
488 * resizing state of the window has been changed.
489 */
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700490 void setWaitingForDrawnIfResizingChanged() {
491 for (int i = mAppTokens.size() - 1; i >= 0; --i) {
492 mAppTokens.get(i).setWaitingForDrawnIfResizingChanged();
493 }
494 }
495
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700496 boolean detachFromDisplay() {
497 boolean didSomething = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700498 for (int i = mAppTokens.size() - 1; i >= 0; --i) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700499 didSomething |= mAppTokens.get(i).detachFromDisplay();
Jorim Jaggiff71d202016-04-14 13:12:36 -0700500 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700501 return didSomething;
Jorim Jaggiff71d202016-04-14 13:12:36 -0700502 }
503
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700504 void updateDisplayInfo(final DisplayContent displayContent) {
505 if (displayContent == null) {
506 return;
507 }
508 if (mFullscreen) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700509 setBounds(null, Configuration.EMPTY);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700510 return;
511 }
512 final int newRotation = displayContent.getDisplayInfo().rotation;
513 if (mRotation == newRotation) {
514 return;
515 }
516
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800517 // Device rotation changed.
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700518 // - We don't want the task to move around on the screen when this happens, so update the
519 // task bounds so it stays in the same place.
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800520 // - Rotate the bounds and notify activity manager if the task can be resized independently
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700521 // from its stack. The stack will take care of task rotation for the other case.
522 mTmpRect2.set(mBounds);
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800523
524 if (!StackId.isTaskResizeAllowed(mStack.mStackId)) {
525 setBounds(mTmpRect2, mOverrideConfig);
526 return;
527 }
528
Wale Ogunwale94744212015-09-21 19:01:47 -0700529 displayContent.rotateBounds(mRotation, newRotation, mTmpRect2);
Wale Ogunwale1ed0d892015-09-28 13:27:44 -0700530 if (setBounds(mTmpRect2, mOverrideConfig) != BOUNDS_CHANGE_NONE) {
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800531 // Post message to inform activity manager of the bounds change simulating a one-way
532 // call. We do this to prevent a deadlock between window manager lock and activity
533 // manager lock been held.
534 mService.mH.obtainMessage(RESIZE_TASK, mTaskId,
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700535 RESIZE_MODE_SYSTEM_SCREEN_ROTATION, mBounds).sendToTarget();
Wale Ogunwale1ed0d892015-09-28 13:27:44 -0700536 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700537 }
538
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700539 private void onResize() {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700540 for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700541 mAppTokens.get(activityNdx).onResize();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700542 }
543 }
544
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700545 private void onMovedByResize() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700546 for (int i = mAppTokens.size() - 1; i >= 0; --i) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700547 mAppTokens.get(i).onMovedByResize();
Chong Zhangbd0d9372015-12-28 15:18:29 -0800548 }
549 }
550
Winsonc28098f2015-10-30 14:50:19 -0700551 /**
552 * Cancels any running app transitions associated with the task.
553 */
554 void cancelTaskWindowTransition() {
555 for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) {
556 mAppTokens.get(activityNdx).mAppAnimator.clearAnimation();
557 }
558 }
559
Winson13d30662015-11-06 15:30:29 -0800560 /**
561 * Cancels any running thumbnail transitions associated with the task.
562 */
563 void cancelTaskThumbnailTransition() {
564 for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) {
565 mAppTokens.get(activityNdx).mAppAnimator.clearThumbnail();
566 }
567 }
568
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700569 boolean showForAllUsers() {
Wale Ogunwale3fcb4a82015-04-06 14:00:13 -0700570 final int tokensCount = mAppTokens.size();
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700571 return (tokensCount != 0) && mAppTokens.get(tokensCount - 1).showForAllUsers;
Wale Ogunwale3fcb4a82015-04-06 14:00:13 -0700572 }
573
Jorim Jaggiff71d202016-04-14 13:12:36 -0700574 boolean isVisible() {
575 for (int i = mAppTokens.size() - 1; i >= 0; i--) {
576 final AppWindowToken appToken = mAppTokens.get(i);
577 if (appToken.isVisible()) {
578 return true;
579 }
580 }
581 return false;
582 }
583
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700584 boolean inHomeStack() {
585 return mStack != null && mStack.mStackId == HOME_STACK_ID;
586 }
587
Chong Zhang09b21ef2015-09-14 10:20:21 -0700588 boolean inFreeformWorkspace() {
589 return mStack != null && mStack.mStackId == FREEFORM_WORKSPACE_STACK_ID;
590 }
591
Robert Carr03138452016-05-18 14:53:16 -0700592 boolean inPinnedWorkspace() {
593 return mStack != null && mStack.mStackId == PINNED_STACK_ID;
594 }
595
Robert Carre6275582016-02-29 15:45:45 -0800596 boolean isFloating() {
597 return StackId.tasksAreFloating(mStack.mStackId);
598 }
599
Chong Zhangd8ceb852015-11-11 14:53:41 -0800600 WindowState getTopVisibleAppMainWindow() {
601 final AppWindowToken token = getTopVisibleAppToken();
602 return token != null ? token.findMainWindow() : null;
Chong Zhang9184ec62015-09-24 12:32:21 -0700603 }
604
Chong Zhangd8ceb852015-11-11 14:53:41 -0800605 AppWindowToken getTopVisibleAppToken() {
606 for (int i = mAppTokens.size() - 1; i >= 0; i--) {
607 final AppWindowToken token = mAppTokens.get(i);
608 // skip hidden (or about to hide) apps
609 if (!token.mIsExiting && !token.clientHidden && !token.hiddenRequested) {
610 return token;
611 }
612 }
613 return null;
Chong Zhangbef461f2015-10-27 11:38:24 -0700614 }
615
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800616 @Override
Wale Ogunwale29bfbb82016-05-12 15:13:52 -0700617 public boolean dimFullscreen() {
618 return isHomeTask() || isFullscreen();
619 }
620
621 boolean isFullscreen() {
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700622 if (useCurrentBounds()) {
623 return mFullscreen;
624 }
625 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack
626 // is not currently visible. Go ahead a represent it as fullscreen to the rest of the
627 // system.
628 return true;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700629 }
630
631 @Override
632 public DisplayInfo getDisplayInfo() {
633 return mStack.getDisplayContent().getDisplayInfo();
634 }
635
Jorim Jaggi6626f542016-08-22 13:08:44 -0700636 /**
637 * See {@link WindowManagerService#overridePlayingAppAnimationsLw}
638 */
639 void overridePlayingAppAnimations(Animation a) {
640 for (int i = mAppTokens.size() - 1; i >= 0; i--) {
641 mAppTokens.get(i).overridePlayingAppAnimations(a);
642 }
643 }
644
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700645 void forceWindowsScaleable(boolean force) {
646 SurfaceControl.openTransaction();
647 try {
648 for (int i = mAppTokens.size() - 1; i >= 0; i--) {
649 mAppTokens.get(i).forceWindowsScaleableInTransaction(force);
650 }
651 } finally {
652 SurfaceControl.closeTransaction();
653 }
654 }
655
656 boolean isAnimating() {
657 for (int i = mAppTokens.size() - 1; i >= 0; i--) {
658 final AppWindowToken aToken = mAppTokens.get(i);
659 if (aToken.isAnimating()) {
660 return true;
661 }
662 }
663 return false;
664 }
665
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700666 @Override
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800667 public String toString() {
Craig Mautner83162a92015-01-26 14:43:30 -0800668 return "{taskId=" + mTaskId + " appTokens=" + mAppTokens + " mdr=" + mDeferRemoval + "}";
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800669 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700670
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700671 @Override
672 public String toShortString() {
673 return "Task=" + mTaskId;
674 }
675
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800676 public void dump(String prefix, PrintWriter pw) {
677 final String doublePrefix = prefix + " ";
678
679 pw.println(prefix + "taskId=" + mTaskId);
680 pw.println(doublePrefix + "mFullscreen=" + mFullscreen);
681 pw.println(doublePrefix + "mBounds=" + mBounds.toShortString());
682 pw.println(doublePrefix + "mdr=" + mDeferRemoval);
683 pw.println(doublePrefix + "appTokens=" + mAppTokens);
684 pw.println(doublePrefix + "mTempInsetBounds=" + mTempInsetBounds.toShortString());
685
686 final String triplePrefix = doublePrefix + " ";
687
688 for (int i = mAppTokens.size() - 1; i >= 0; i--) {
689 final AppWindowToken wtoken = mAppTokens.get(i);
690 pw.println(triplePrefix + "Activity #" + i + " " + wtoken);
691 wtoken.dump(pw, triplePrefix);
692 }
693
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700694 }
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800695}