blob: 048d980bd9da0edaeb1a66032e061aa301477fb3 [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;
Wale Ogunwale3797c222015-10-27 14:21:58 -070020import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
Robert Carr03138452016-05-18 14:53:16 -070021import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Wale Ogunwale3797c222015-10-27 14:21:58 -070022import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
23import static android.app.ActivityManager.StackId.HOME_STACK_ID;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -080024import static android.content.pm.ActivityInfo.RESIZE_MODE_CROP_WINDOWS;
Jorim Jaggid53f0922016-04-06 22:16:23 -070025import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080026import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
27import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
Jorim Jaggid53f0922016-04-06 22:16:23 -070028import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
29import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwale1ed0d892015-09-28 13:27:44 -070030import static com.android.server.wm.WindowManagerService.H.RESIZE_TASK;
Robert Carr2c17cd22016-04-08 17:52:28 -070031import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale99db1862015-10-23 20:08:22 -070032
Wale Ogunwale3797c222015-10-27 14:21:58 -070033import android.app.ActivityManager.StackId;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -080034import android.content.pm.ActivityInfo;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070035import android.content.res.Configuration;
36import android.graphics.Rect;
Craig Mautner2c2549c2013-11-12 08:31:15 -080037import android.util.EventLog;
Craig Mautner42bf39e2014-02-21 16:46:22 -080038import android.util.Slog;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070039import android.view.DisplayInfo;
40import android.view.Surface;
41
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070042import android.view.SurfaceControl;
Craig Mautnere3119b72015-01-20 15:02:36 -080043import com.android.server.EventLogTags;
Craig Mautner2c2549c2013-11-12 08:31:15 -080044
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070045import java.io.PrintWriter;
46import java.util.ArrayList;
47
48class Task implements DimLayer.DimLayerUser {
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -080049 static final String TAG = TAG_WITH_CLASS_NAME ? "Task" : TAG_WM;
Wale Ogunwale2cc92f52015-09-09 13:12:10 -070050 // Return value from {@link setBounds} indicating no change was made to the Task bounds.
51 static final int BOUNDS_CHANGE_NONE = 0;
52 // Return value from {@link setBounds} indicating the position of the Task bounds changed.
53 static final int BOUNDS_CHANGE_POSITION = 1;
54 // Return value from {@link setBounds} indicating the size of the Task bounds changed.
55 static final int BOUNDS_CHANGE_SIZE = 1 << 1;
56
Craig Mautnerc00204b2013-03-05 15:02:14 -080057 TaskStack mStack;
Craig Mautner05d6272ba2013-02-11 09:39:27 -080058 final AppTokenList mAppTokens = new AppTokenList();
Craig Mautner83162a92015-01-26 14:43:30 -080059 final int mTaskId;
Craig Mautnerac6f8432013-07-17 13:24:59 -070060 final int mUserId;
Craig Mautner9ef471f2014-02-07 13:11:47 -080061 boolean mDeferRemoval = false;
Craig Mautnere3119b72015-01-20 15:02:36 -080062 final WindowManagerService mService;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080063
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070064 // Content limits relative to the DisplayContent this sits in.
65 private Rect mBounds = new Rect();
Jorim Jaggi0429f352015-12-22 16:29:16 +010066 final Rect mPreparedFrozenBounds = new Rect();
Jorim Jaggi26c8c422016-05-09 19:57:25 -070067 final Configuration mPreparedFrozenMergedConfig = new Configuration();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070068
Jorim Jaggidc249c42015-12-15 14:57:31 -080069 // Bounds used to calculate the insets.
70 private final Rect mTempInsetBounds = new Rect();
71
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070072 // Device rotation as of the last time {@link #mBounds} was set.
73 int mRotation;
74
75 // Whether mBounds is fullscreen
76 private boolean mFullscreen = true;
77
78 // Contains configurations settings that are different from the global configuration due to
79 // stack specific operations. E.g. {@link #setBounds}.
Jorim Jaggi26c8c422016-05-09 19:57:25 -070080 Configuration mOverrideConfig = Configuration.EMPTY;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070081
82 // For comparison with DisplayContent bounds.
83 private Rect mTmpRect = new Rect();
84 // For handling display rotations.
85 private Rect mTmpRect2 = new Rect();
86
Wale Ogunwaleb1faf602016-01-27 09:12:31 -080087 // Resize mode of the task. See {@link ActivityInfo#resizeMode}
88 private int mResizeMode;
Chong Zhangb15758a2015-11-17 12:12:03 -080089
Chong Zhang3005e752015-09-18 18:46:28 -070090 // Whether the task is currently being drag-resized
91 private boolean mDragResizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +010092 private int mDragResizeMode;
Chong Zhang3005e752015-09-18 18:46:28 -070093
Wale Ogunwaleb1faf602016-01-27 09:12:31 -080094 private boolean mHomeTask;
95
Jiaquan Hedd1e66f2016-06-15 15:15:12 -070096 // Whether this task is an on-top launcher task, which is determined by the root activity.
97 private boolean mIsOnTopLauncher;
98
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070099 Task(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds,
Jiaquan Hedd1e66f2016-06-15 15:15:12 -0700100 Configuration config, boolean isOnTopLauncher) {
Craig Mautner83162a92015-01-26 14:43:30 -0800101 mTaskId = taskId;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800102 mStack = stack;
Craig Mautnerac6f8432013-07-17 13:24:59 -0700103 mUserId = userId;
Craig Mautnere3119b72015-01-20 15:02:36 -0800104 mService = service;
Jiaquan Hedd1e66f2016-06-15 15:15:12 -0700105 mIsOnTopLauncher = isOnTopLauncher;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700106 setBounds(bounds, config);
Craig Mautnerc00204b2013-03-05 15:02:14 -0800107 }
108
109 DisplayContent getDisplayContent() {
110 return mStack.getDisplayContent();
111 }
112
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800113 void addAppToken(int addPos, AppWindowToken wtoken, int resizeMode, boolean homeTask) {
Craig Mautner42bf39e2014-02-21 16:46:22 -0800114 final int lastPos = mAppTokens.size();
Craig Mautner83162a92015-01-26 14:43:30 -0800115 if (addPos >= lastPos) {
116 addPos = lastPos;
117 } else {
118 for (int pos = 0; pos < lastPos && pos < addPos; ++pos) {
119 if (mAppTokens.get(pos).removed) {
120 // addPos assumes removed tokens are actually gone.
121 ++addPos;
122 }
Craig Mautner01f79cf2014-08-27 09:56:02 -0700123 }
Craig Mautner42bf39e2014-02-21 16:46:22 -0800124 }
Craig Mautnerc00204b2013-03-05 15:02:14 -0800125 mAppTokens.add(addPos, wtoken);
Craig Mautner83162a92015-01-26 14:43:30 -0800126 wtoken.mTask = this;
Craig Mautner42bf39e2014-02-21 16:46:22 -0800127 mDeferRemoval = false;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800128 mResizeMode = resizeMode;
129 mHomeTask = homeTask;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800130 }
131
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700132 private boolean hasWindowsAlive() {
Chong Zhang7e8eeb72016-01-06 19:14:47 -0800133 for (int i = mAppTokens.size() - 1; i >= 0; i--) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700134 if (mAppTokens.get(i).hasWindowsAlive()) {
Chong Zhang7e8eeb72016-01-06 19:14:47 -0800135 return true;
136 }
137 }
138 return false;
139 }
140
Craig Mautnere3119b72015-01-20 15:02:36 -0800141 void removeLocked() {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700142 if (hasWindowsAlive() && mStack.isAnimating()) {
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800143 if (DEBUG_STACK) Slog.i(TAG, "removeTask: deferring removing taskId=" + mTaskId);
Craig Mautnere3119b72015-01-20 15:02:36 -0800144 mDeferRemoval = true;
145 return;
146 }
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800147 if (DEBUG_STACK) Slog.i(TAG, "removeTask: removing taskId=" + mTaskId);
Craig Mautner83162a92015-01-26 14:43:30 -0800148 EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "removeTask");
Craig Mautnere3119b72015-01-20 15:02:36 -0800149 mDeferRemoval = false;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700150 DisplayContent content = getDisplayContent();
151 if (content != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800152 content.mDimLayerController.removeDimLayerUser(this);
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700153 }
Craig Mautnere3119b72015-01-20 15:02:36 -0800154 mStack.removeTask(this);
Craig Mautner83162a92015-01-26 14:43:30 -0800155 mService.mTaskIdToTask.delete(mTaskId);
Craig Mautnere3119b72015-01-20 15:02:36 -0800156 }
157
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800158 void moveTaskToStack(TaskStack stack, boolean toTop) {
159 if (stack == mStack) {
160 return;
161 }
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800162 if (DEBUG_STACK) Slog.i(TAG, "moveTaskToStack: removing taskId=" + mTaskId
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800163 + " from stack=" + mStack);
Wale Ogunwale000957c2015-04-03 08:19:12 -0700164 EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask");
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800165 if (mStack != null) {
166 mStack.removeTask(this);
167 }
168 stack.addTask(this, toTop);
169 }
170
Wale Ogunwale935e5022015-11-10 12:36:10 -0800171 void positionTaskInStack(TaskStack stack, int position, Rect bounds, Configuration config) {
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700172 if (mStack != null && stack != mStack) {
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800173 if (DEBUG_STACK) Slog.i(TAG, "positionTaskInStack: removing taskId=" + mTaskId
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700174 + " from stack=" + mStack);
175 EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask");
176 mStack.removeTask(this);
177 }
178 stack.positionTask(this, position, showForAllUsers());
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800179 resizeLocked(bounds, config, false /* force */);
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800180
181 for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700182 mAppTokens.get(activityNdx).notifyMovedInStack();
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800183 }
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700184 }
185
Craig Mautnerc00204b2013-03-05 15:02:14 -0800186 boolean removeAppToken(AppWindowToken wtoken) {
Craig Mautner42bf39e2014-02-21 16:46:22 -0800187 boolean removed = mAppTokens.remove(wtoken);
Craig Mautnerc00204b2013-03-05 15:02:14 -0800188 if (mAppTokens.size() == 0) {
Jorim Jaggi0429f352015-12-22 16:29:16 +0100189 EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "removeAppToken: last token");
Craig Mautnere3119b72015-01-20 15:02:36 -0800190 if (mDeferRemoval) {
191 removeLocked();
192 }
Craig Mautnerc00204b2013-03-05 15:02:14 -0800193 }
Craig Mautner83162a92015-01-26 14:43:30 -0800194 wtoken.mTask = null;
195 /* Leave mTaskId for now, it might be useful for debug
196 wtoken.mTaskId = -1;
197 */
Craig Mautner42bf39e2014-02-21 16:46:22 -0800198 return removed;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800199 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800200
Craig Mautnercbd84af2014-10-22 13:21:22 -0700201 void setSendingToBottom(boolean toBottom) {
202 for (int appTokenNdx = 0; appTokenNdx < mAppTokens.size(); appTokenNdx++) {
203 mAppTokens.get(appTokenNdx).sendingToBottom = toBottom;
204 }
205 }
206
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700207 /** Set the task bounds. Passing in null sets the bounds to fullscreen. */
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800208 private int setBounds(Rect bounds, Configuration config) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700209 if (config == null) {
210 config = Configuration.EMPTY;
211 }
212 if (bounds == null && !Configuration.EMPTY.equals(config)) {
213 throw new IllegalArgumentException("null bounds but non empty configuration: "
214 + config);
215 }
216 if (bounds != null && Configuration.EMPTY.equals(config)) {
217 throw new IllegalArgumentException("non null bounds, but empty configuration");
218 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700219 boolean oldFullscreen = mFullscreen;
220 int rotation = Surface.ROTATION_0;
221 final DisplayContent displayContent = mStack.getDisplayContent();
222 if (displayContent != null) {
223 displayContent.getLogicalDisplayRect(mTmpRect);
224 rotation = displayContent.getDisplayInfo().rotation;
Jorim Jaggi067e8172016-02-03 18:24:12 -0800225 mFullscreen = bounds == null;
226 if (mFullscreen) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700227 bounds = mTmpRect;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700228 }
229 }
230
231 if (bounds == null) {
232 // Can't set to fullscreen if we don't have a display to get bounds from...
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700233 return BOUNDS_CHANGE_NONE;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700234 }
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700235 if (mBounds.equals(bounds) && oldFullscreen == mFullscreen && mRotation == rotation) {
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700236 return BOUNDS_CHANGE_NONE;
237 }
238
239 int boundsChange = BOUNDS_CHANGE_NONE;
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700240 if (mBounds.left != bounds.left || mBounds.top != bounds.top) {
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700241 boundsChange |= BOUNDS_CHANGE_POSITION;
242 }
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700243 if (mBounds.width() != bounds.width() || mBounds.height() != bounds.height()) {
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700244 boundsChange |= BOUNDS_CHANGE_SIZE;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700245 }
246
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700247 mBounds.set(bounds);
Chong Zhangf66db432016-01-13 10:39:51 -0800248
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700249 mRotation = rotation;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700250 if (displayContent != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800251 displayContent.mDimLayerController.updateDimLayer(this);
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700252 }
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700253 mOverrideConfig = mFullscreen ? Configuration.EMPTY : config;
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700254 return boundsChange;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700255 }
256
Jorim Jaggidc249c42015-12-15 14:57:31 -0800257 /**
258 * Sets the bounds used to calculate the insets. See
259 * {@link android.app.IActivityManager#resizeDockedStack} why this is needed.
260 */
261 void setTempInsetBounds(Rect tempInsetBounds) {
262 if (tempInsetBounds != null) {
263 mTempInsetBounds.set(tempInsetBounds);
264 } else {
265 mTempInsetBounds.setEmpty();
266 }
267 }
268
269 /**
270 * Gets the bounds used to calculate the insets. See
271 * {@link android.app.IActivityManager#resizeDockedStack} why this is needed.
272 */
273 void getTempInsetBounds(Rect out) {
274 out.set(mTempInsetBounds);
275 }
276
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800277 void setResizeable(int resizeMode) {
278 mResizeMode = resizeMode;
Chong Zhangb15758a2015-11-17 12:12:03 -0800279 }
280
281 boolean isResizeable() {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800282 return !mHomeTask
283 && (ActivityInfo.isResizeableMode(mResizeMode) || mService.mForceResizableTasks);
284 }
285
Jiaquan Hedd1e66f2016-06-15 15:15:12 -0700286 boolean isOnTopLauncher() {
287 return mIsOnTopLauncher;
288 }
289
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800290 boolean cropWindowsToStackBounds() {
291 return !mHomeTask && (isResizeable() || mResizeMode == RESIZE_MODE_CROP_WINDOWS);
292 }
293
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800294 boolean isHomeTask() {
295 return mHomeTask;
296 }
297
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800298 private boolean inCropWindowsResizeMode() {
299 return !mHomeTask && !isResizeable() && mResizeMode == RESIZE_MODE_CROP_WINDOWS;
Chong Zhangb15758a2015-11-17 12:12:03 -0800300 }
301
Chong Zhang87b21722015-09-21 15:39:51 -0700302 boolean resizeLocked(Rect bounds, Configuration configuration, boolean forced) {
Chong Zhang3005e752015-09-18 18:46:28 -0700303 int boundsChanged = setBounds(bounds, configuration);
Chong Zhang87b21722015-09-21 15:39:51 -0700304 if (forced) {
Chong Zhang3005e752015-09-18 18:46:28 -0700305 boundsChanged |= BOUNDS_CHANGE_SIZE;
Chong Zhang3005e752015-09-18 18:46:28 -0700306 }
307 if (boundsChanged == BOUNDS_CHANGE_NONE) {
308 return false;
309 }
310 if ((boundsChanged & BOUNDS_CHANGE_SIZE) == BOUNDS_CHANGE_SIZE) {
311 resizeWindows();
Chong Zhangbd0d9372015-12-28 15:18:29 -0800312 } else {
313 moveWindows();
Chong Zhang3005e752015-09-18 18:46:28 -0700314 }
315 return true;
316 }
317
Jorim Jaggi0429f352015-12-22 16:29:16 +0100318 /**
319 * Prepares the task bounds to be frozen with the current size. See
320 * {@link AppWindowToken#freezeBounds}.
321 */
322 void prepareFreezingBounds() {
323 mPreparedFrozenBounds.set(mBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700324 mPreparedFrozenMergedConfig.setTo(mService.mCurConfiguration);
325 mPreparedFrozenMergedConfig.updateFrom(mOverrideConfig);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100326 }
327
Chong Zhang5117e272016-05-03 12:47:34 -0700328 /**
329 * Align the task to the adjusted bounds.
330 *
331 * @param adjustedBounds Adjusted bounds to which the task should be aligned.
332 * @param tempInsetBounds Insets bounds for the task.
333 * @param alignBottom True if the task's bottom should be aligned to the adjusted
334 * bounds's bottom; false if the task's top should be aligned
335 * the adjusted bounds's top.
336 */
337 void alignToAdjustedBounds(
338 Rect adjustedBounds, Rect tempInsetBounds, boolean alignBottom) {
339 if (!isResizeable() || mOverrideConfig == Configuration.EMPTY) {
340 return;
341 }
342
343 getBounds(mTmpRect2);
344 if (alignBottom) {
345 int offsetY = adjustedBounds.bottom - mTmpRect2.bottom;
346 mTmpRect2.offset(0, offsetY);
347 } else {
348 mTmpRect2.offsetTo(adjustedBounds.left, adjustedBounds.top);
349 }
350 setTempInsetBounds(tempInsetBounds);
351 resizeLocked(mTmpRect2, mOverrideConfig, false /* forced */);
352 }
353
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700354 /** Return true if the current bound can get outputted to the rest of the system as-is. */
355 private boolean useCurrentBounds() {
356 final DisplayContent displayContent = mStack.getDisplayContent();
357 if (mFullscreen
Wale Ogunwale3797c222015-10-27 14:21:58 -0700358 || !StackId.isTaskResizeableByDockedStack(mStack.mStackId)
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700359 || displayContent == null
Jorim Jaggif4fa8cb2016-04-01 16:05:10 -0700360 || displayContent.getDockedStackVisibleForUserLocked() != null) {
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700361 return true;
362 }
363 return false;
364 }
365
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800366 /** Original bounds of the task if applicable, otherwise fullscreen rect. */
Wale Ogunwaleccb6ce22016-01-14 15:36:35 -0800367 void getBounds(Rect out) {
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700368 if (useCurrentBounds()) {
369 // No need to adjust the output bounds if fullscreen or the docked stack is visible
370 // since it is already what we want to represent to the rest of the system.
371 out.set(mBounds);
372 return;
373 }
374
Wale Ogunwaleccb6ce22016-01-14 15:36:35 -0800375 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack is
376 // not currently visible. Go ahead a represent it as fullscreen to the rest of the system.
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700377 mStack.getDisplayContent().getLogicalDisplayRect(out);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700378 }
379
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800380 /**
381 * Calculate the maximum visible area of this task. If the task has only one app,
382 * the result will be visible frame of that app. If the task has more than one apps,
383 * we search from top down if the next app got different visible area.
384 *
385 * This effort is to handle the case where some task (eg. GMail composer) might pop up
386 * a dialog that's different in size from the activity below, in which case we should
387 * be dimming the entire task area behind the dialog.
388 *
389 * @param out Rect containing the max visible bounds.
390 * @return true if the task has some visible app windows; false otherwise.
391 */
392 boolean getMaxVisibleBounds(Rect out) {
393 boolean foundTop = false;
394 for (int i = mAppTokens.size() - 1; i >= 0; i--) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800395 final AppWindowToken token = mAppTokens.get(i);
396 // skip hidden (or about to hide) apps
397 if (token.mIsExiting || token.clientHidden || token.hiddenRequested) {
398 continue;
399 }
400 final WindowState win = token.findMainWindow();
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800401 if (win == null) {
402 continue;
403 }
404 if (!foundTop) {
405 out.set(win.mVisibleFrame);
406 foundTop = true;
407 continue;
408 }
409 if (win.mVisibleFrame.left < out.left) {
410 out.left = win.mVisibleFrame.left;
411 }
412 if (win.mVisibleFrame.top < out.top) {
413 out.top = win.mVisibleFrame.top;
414 }
415 if (win.mVisibleFrame.right > out.right) {
416 out.right = win.mVisibleFrame.right;
417 }
418 if (win.mVisibleFrame.bottom > out.bottom) {
419 out.bottom = win.mVisibleFrame.bottom;
420 }
421 }
422 return foundTop;
423 }
424
425 /** Bounds of the task to be used for dimming, as well as touch related tests. */
426 @Override
427 public void getDimBounds(Rect out) {
Robert Carra86a6bf2016-04-08 17:34:16 -0700428 final DisplayContent displayContent = mStack.getDisplayContent();
429 // It doesn't matter if we in particular are part of the resize, since we couldn't have
430 // a DimLayer anyway if we weren't visible.
431 final boolean dockedResizing = displayContent != null ?
432 displayContent.mDividerControllerLocked.isResizing() : false;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800433 if (useCurrentBounds()) {
434 if (inFreeformWorkspace() && getMaxVisibleBounds(out)) {
435 return;
436 }
437
Jorim Jaggi22a869f2016-03-25 23:33:21 -0700438 if (!mFullscreen) {
439 // When minimizing the docked stack when going home, we don't adjust the task bounds
440 // so we need to intersect the task bounds with the stack bounds here.
Robert Carra86a6bf2016-04-08 17:34:16 -0700441 //
442 // If we are Docked Resizing with snap points, the task bounds could be smaller than the stack
443 // bounds and so we don't even want to use them. Even if the app should not be resized the Dim
444 // should keep up with the divider.
445 if (dockedResizing) {
446 mStack.getBounds(out);
447 } else {
448 mStack.getBounds(mTmpRect);
449 mTmpRect.intersect(mBounds);
450 }
Jorim Jaggi22a869f2016-03-25 23:33:21 -0700451 out.set(mTmpRect);
452 } else {
453 out.set(mBounds);
454 }
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800455 return;
456 }
457
458 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack
459 // is not currently visible. Go ahead a represent it as fullscreen to the rest of the
460 // system.
Robert Carra86a6bf2016-04-08 17:34:16 -0700461 displayContent.getLogicalDisplayRect(out);
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800462 }
463
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100464 void setDragResizing(boolean dragResizing, int dragResizeMode) {
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800465 if (mDragResizing != dragResizing) {
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100466 if (!DragResizeMode.isModeAllowedForStack(mStack.mStackId, dragResizeMode)) {
467 throw new IllegalArgumentException("Drag resize mode not allow for stack stackId="
468 + mStack.mStackId + " dragResizeMode=" + dragResizeMode);
469 }
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800470 mDragResizing = dragResizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100471 mDragResizeMode = dragResizeMode;
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800472 resetDragResizingChangeReported();
473 }
474 }
475
476 void resetDragResizingChangeReported() {
477 for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700478 mAppTokens.get(activityNdx).resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800479 }
Chong Zhang3005e752015-09-18 18:46:28 -0700480 }
481
482 boolean isDragResizing() {
Wale Ogunwalece144522016-02-05 22:51:01 -0800483 return mDragResizing || (mStack != null && mStack.isDragResizing());
Chong Zhang3005e752015-09-18 18:46:28 -0700484 }
485
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100486 int getDragResizeMode() {
487 return mDragResizeMode;
488 }
489
Jorim Jaggiff71d202016-04-14 13:12:36 -0700490 /**
491 * Adds all of the tasks windows to {@link WindowManagerService#mWaitingForDrawn} if drag
492 * resizing state of the window has been changed.
493 */
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700494 void setWaitingForDrawnIfResizingChanged() {
495 for (int i = mAppTokens.size() - 1; i >= 0; --i) {
496 mAppTokens.get(i).setWaitingForDrawnIfResizingChanged();
497 }
498 }
499
500 void detachDisplay() {
501 for (int i = mAppTokens.size() - 1; i >= 0; --i) {
502 mAppTokens.get(i).detachDisplay();
Jorim Jaggiff71d202016-04-14 13:12:36 -0700503 }
504 }
505
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700506 void updateDisplayInfo(final DisplayContent displayContent) {
507 if (displayContent == null) {
508 return;
509 }
510 if (mFullscreen) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700511 setBounds(null, Configuration.EMPTY);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700512 return;
513 }
514 final int newRotation = displayContent.getDisplayInfo().rotation;
515 if (mRotation == newRotation) {
516 return;
517 }
518
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800519 // Device rotation changed.
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700520 // - We don't want the task to move around on the screen when this happens, so update the
521 // task bounds so it stays in the same place.
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800522 // - Rotate the bounds and notify activity manager if the task can be resized independently
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700523 // from its stack. The stack will take care of task rotation for the other case.
524 mTmpRect2.set(mBounds);
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800525
526 if (!StackId.isTaskResizeAllowed(mStack.mStackId)) {
527 setBounds(mTmpRect2, mOverrideConfig);
528 return;
529 }
530
Wale Ogunwale94744212015-09-21 19:01:47 -0700531 displayContent.rotateBounds(mRotation, newRotation, mTmpRect2);
Wale Ogunwale1ed0d892015-09-28 13:27:44 -0700532 if (setBounds(mTmpRect2, mOverrideConfig) != BOUNDS_CHANGE_NONE) {
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800533 // Post message to inform activity manager of the bounds change simulating a one-way
534 // call. We do this to prevent a deadlock between window manager lock and activity
535 // manager lock been held.
536 mService.mH.obtainMessage(RESIZE_TASK, mTaskId,
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700537 RESIZE_MODE_SYSTEM_SCREEN_ROTATION, mBounds).sendToTarget();
Wale Ogunwale1ed0d892015-09-28 13:27:44 -0700538 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700539 }
540
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700541 void resizeWindows() {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700542 for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700543 mAppTokens.get(activityNdx).resizeWindows();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700544 }
545 }
546
Chong Zhangbd0d9372015-12-28 15:18:29 -0800547 void moveWindows() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700548 for (int i = mAppTokens.size() - 1; i >= 0; --i) {
549 mAppTokens.get(i).moveWindows();
Chong Zhangbd0d9372015-12-28 15:18:29 -0800550 }
551 }
552
Winsonc28098f2015-10-30 14:50:19 -0700553 /**
554 * Cancels any running app transitions associated with the task.
555 */
556 void cancelTaskWindowTransition() {
557 for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) {
558 mAppTokens.get(activityNdx).mAppAnimator.clearAnimation();
559 }
560 }
561
Winson13d30662015-11-06 15:30:29 -0800562 /**
563 * Cancels any running thumbnail transitions associated with the task.
564 */
565 void cancelTaskThumbnailTransition() {
566 for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) {
567 mAppTokens.get(activityNdx).mAppAnimator.clearThumbnail();
568 }
569 }
570
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700571 boolean showForAllUsers() {
Wale Ogunwale3fcb4a82015-04-06 14:00:13 -0700572 final int tokensCount = mAppTokens.size();
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700573 return (tokensCount != 0) && mAppTokens.get(tokensCount - 1).showForAllUsers;
Wale Ogunwale3fcb4a82015-04-06 14:00:13 -0700574 }
575
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800576 boolean isVisibleForUser() {
577 for (int i = mAppTokens.size() - 1; i >= 0; i--) {
578 final AppWindowToken appToken = mAppTokens.get(i);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700579 if (appToken.isVisibleForUser()) {
580 return true;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800581 }
582 }
583 return false;
584 }
585
Jorim Jaggiff71d202016-04-14 13:12:36 -0700586 boolean isVisible() {
587 for (int i = mAppTokens.size() - 1; i >= 0; i--) {
588 final AppWindowToken appToken = mAppTokens.get(i);
589 if (appToken.isVisible()) {
590 return true;
591 }
592 }
593 return false;
594 }
595
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700596 boolean inHomeStack() {
597 return mStack != null && mStack.mStackId == HOME_STACK_ID;
598 }
599
Chong Zhang09b21ef2015-09-14 10:20:21 -0700600 boolean inFreeformWorkspace() {
601 return mStack != null && mStack.mStackId == FREEFORM_WORKSPACE_STACK_ID;
602 }
603
Robert Carr03138452016-05-18 14:53:16 -0700604 boolean inPinnedWorkspace() {
605 return mStack != null && mStack.mStackId == PINNED_STACK_ID;
606 }
607
Robert Carre6275582016-02-29 15:45:45 -0800608 boolean isFloating() {
609 return StackId.tasksAreFloating(mStack.mStackId);
610 }
611
Chong Zhangd8ceb852015-11-11 14:53:41 -0800612 WindowState getTopVisibleAppMainWindow() {
613 final AppWindowToken token = getTopVisibleAppToken();
614 return token != null ? token.findMainWindow() : null;
Chong Zhang9184ec62015-09-24 12:32:21 -0700615 }
616
Chong Zhangd8ceb852015-11-11 14:53:41 -0800617 AppWindowToken getTopVisibleAppToken() {
618 for (int i = mAppTokens.size() - 1; i >= 0; i--) {
619 final AppWindowToken token = mAppTokens.get(i);
620 // skip hidden (or about to hide) apps
621 if (!token.mIsExiting && !token.clientHidden && !token.hiddenRequested) {
622 return token;
623 }
624 }
625 return null;
Chong Zhangbef461f2015-10-27 11:38:24 -0700626 }
627
Jorim Jaggiaf558e12016-04-27 22:56:56 -0700628 AppWindowToken getTopAppToken() {
629 return mAppTokens.size() > 0 ? mAppTokens.get(mAppTokens.size() - 1) : null;
630 }
631
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800632 @Override
Wale Ogunwale29bfbb82016-05-12 15:13:52 -0700633 public boolean dimFullscreen() {
634 return isHomeTask() || isFullscreen();
635 }
636
637 boolean isFullscreen() {
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700638 if (useCurrentBounds()) {
639 return mFullscreen;
640 }
641 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack
642 // is not currently visible. Go ahead a represent it as fullscreen to the rest of the
643 // system.
644 return true;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700645 }
646
647 @Override
648 public DisplayInfo getDisplayInfo() {
649 return mStack.getDisplayContent().getDisplayInfo();
650 }
651
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700652 void forceWindowsScaleable(boolean force) {
653 SurfaceControl.openTransaction();
654 try {
655 for (int i = mAppTokens.size() - 1; i >= 0; i--) {
656 mAppTokens.get(i).forceWindowsScaleableInTransaction(force);
657 }
658 } finally {
659 SurfaceControl.closeTransaction();
660 }
661 }
662
663 boolean isAnimating() {
664 for (int i = mAppTokens.size() - 1; i >= 0; i--) {
665 final AppWindowToken aToken = mAppTokens.get(i);
666 if (aToken.isAnimating()) {
667 return true;
668 }
669 }
670 return false;
671 }
672
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700673 @Override
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800674 public String toString() {
Craig Mautner83162a92015-01-26 14:43:30 -0800675 return "{taskId=" + mTaskId + " appTokens=" + mAppTokens + " mdr=" + mDeferRemoval + "}";
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800676 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700677
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700678 @Override
679 public String toShortString() {
680 return "Task=" + mTaskId;
681 }
682
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800683 public void dump(String prefix, PrintWriter pw) {
684 final String doublePrefix = prefix + " ";
685
686 pw.println(prefix + "taskId=" + mTaskId);
687 pw.println(doublePrefix + "mFullscreen=" + mFullscreen);
688 pw.println(doublePrefix + "mBounds=" + mBounds.toShortString());
689 pw.println(doublePrefix + "mdr=" + mDeferRemoval);
690 pw.println(doublePrefix + "appTokens=" + mAppTokens);
691 pw.println(doublePrefix + "mTempInsetBounds=" + mTempInsetBounds.toShortString());
692
693 final String triplePrefix = doublePrefix + " ";
694
695 for (int i = mAppTokens.size() - 1; i >= 0; i--) {
696 final AppWindowToken wtoken = mAppTokens.get(i);
697 pw.println(triplePrefix + "Activity #" + i + " " + wtoken);
698 wtoken.dump(pw, triplePrefix);
699 }
700
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700701 }
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800702}