blob: 51e48a338ff28e5df1c8986c96ff27c82b727de0 [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
Wale Ogunwale3797c222015-10-27 14:21:58 -070019import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
20import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
21import static android.app.ActivityManager.StackId.HOME_STACK_ID;
22import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Chong Zhangb15758a2015-11-17 12:12:03 -080023import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
Wale Ogunwale1ed0d892015-09-28 13:27:44 -070024import static android.app.ActivityManager.RESIZE_MODE_SYSTEM_SCREEN_ROTATION;
Craig Mautner42bf39e2014-02-21 16:46:22 -080025import static com.android.server.wm.WindowManagerService.TAG;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070026import static com.android.server.wm.WindowManagerService.DEBUG_RESIZE;
Craig Mautnere3119b72015-01-20 15:02:36 -080027import static com.android.server.wm.WindowManagerService.DEBUG_STACK;
Wale Ogunwale1ed0d892015-09-28 13:27:44 -070028import static com.android.server.wm.WindowManagerService.H.RESIZE_TASK;
Wale Ogunwale99db1862015-10-23 20:08:22 -070029
Wale Ogunwale3797c222015-10-27 14:21:58 -070030import android.app.ActivityManager.StackId;
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;
37
Craig Mautnere3119b72015-01-20 15:02:36 -080038import com.android.server.EventLogTags;
Craig Mautner2c2549c2013-11-12 08:31:15 -080039
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070040import java.io.PrintWriter;
41import java.util.ArrayList;
42
43class Task implements DimLayer.DimLayerUser {
Wale Ogunwale2cc92f52015-09-09 13:12:10 -070044 // Return value from {@link setBounds} indicating no change was made to the Task bounds.
45 static final int BOUNDS_CHANGE_NONE = 0;
46 // Return value from {@link setBounds} indicating the position of the Task bounds changed.
47 static final int BOUNDS_CHANGE_POSITION = 1;
48 // Return value from {@link setBounds} indicating the size of the Task bounds changed.
49 static final int BOUNDS_CHANGE_SIZE = 1 << 1;
50
Craig Mautnerc00204b2013-03-05 15:02:14 -080051 TaskStack mStack;
Craig Mautner05d6272ba2013-02-11 09:39:27 -080052 final AppTokenList mAppTokens = new AppTokenList();
Craig Mautner83162a92015-01-26 14:43:30 -080053 final int mTaskId;
Craig Mautnerac6f8432013-07-17 13:24:59 -070054 final int mUserId;
Craig Mautner9ef471f2014-02-07 13:11:47 -080055 boolean mDeferRemoval = false;
Craig Mautnere3119b72015-01-20 15:02:36 -080056 final WindowManagerService mService;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080057
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070058 // Content limits relative to the DisplayContent this sits in.
59 private Rect mBounds = new Rect();
60
61 // Device rotation as of the last time {@link #mBounds} was set.
62 int mRotation;
63
64 // Whether mBounds is fullscreen
65 private boolean mFullscreen = true;
66
67 // Contains configurations settings that are different from the global configuration due to
68 // stack specific operations. E.g. {@link #setBounds}.
69 Configuration mOverrideConfig;
70
71 // For comparison with DisplayContent bounds.
72 private Rect mTmpRect = new Rect();
73 // For handling display rotations.
74 private Rect mTmpRect2 = new Rect();
75
Chong Zhangb15758a2015-11-17 12:12:03 -080076 // Whether the task is resizeable
77 private boolean mResizeable;
78
Chong Zhang3005e752015-09-18 18:46:28 -070079 // Whether the task is currently being drag-resized
80 private boolean mDragResizing;
81
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070082 Task(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds,
83 Configuration config) {
Craig Mautner83162a92015-01-26 14:43:30 -080084 mTaskId = taskId;
Craig Mautnerc00204b2013-03-05 15:02:14 -080085 mStack = stack;
Craig Mautnerac6f8432013-07-17 13:24:59 -070086 mUserId = userId;
Craig Mautnere3119b72015-01-20 15:02:36 -080087 mService = service;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070088 setBounds(bounds, config);
Craig Mautnerc00204b2013-03-05 15:02:14 -080089 }
90
91 DisplayContent getDisplayContent() {
92 return mStack.getDisplayContent();
93 }
94
95 void addAppToken(int addPos, AppWindowToken wtoken) {
Craig Mautner42bf39e2014-02-21 16:46:22 -080096 final int lastPos = mAppTokens.size();
Craig Mautner83162a92015-01-26 14:43:30 -080097 if (addPos >= lastPos) {
98 addPos = lastPos;
99 } else {
100 for (int pos = 0; pos < lastPos && pos < addPos; ++pos) {
101 if (mAppTokens.get(pos).removed) {
102 // addPos assumes removed tokens are actually gone.
103 ++addPos;
104 }
Craig Mautner01f79cf2014-08-27 09:56:02 -0700105 }
Craig Mautner42bf39e2014-02-21 16:46:22 -0800106 }
Craig Mautnerc00204b2013-03-05 15:02:14 -0800107 mAppTokens.add(addPos, wtoken);
Craig Mautner83162a92015-01-26 14:43:30 -0800108 wtoken.mTask = this;
Craig Mautner42bf39e2014-02-21 16:46:22 -0800109 mDeferRemoval = false;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800110 }
111
Craig Mautnere3119b72015-01-20 15:02:36 -0800112 void removeLocked() {
113 if (!mAppTokens.isEmpty() && mStack.isAnimating()) {
Craig Mautner83162a92015-01-26 14:43:30 -0800114 if (DEBUG_STACK) Slog.i(TAG, "removeTask: deferring removing taskId=" + mTaskId);
Craig Mautnere3119b72015-01-20 15:02:36 -0800115 mDeferRemoval = true;
116 return;
117 }
Craig Mautner83162a92015-01-26 14:43:30 -0800118 if (DEBUG_STACK) Slog.i(TAG, "removeTask: removing taskId=" + mTaskId);
119 EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "removeTask");
Craig Mautnere3119b72015-01-20 15:02:36 -0800120 mDeferRemoval = false;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700121 DisplayContent content = getDisplayContent();
122 if (content != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800123 content.mDimLayerController.removeDimLayerUser(this);
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700124 }
Craig Mautnere3119b72015-01-20 15:02:36 -0800125 mStack.removeTask(this);
Craig Mautner83162a92015-01-26 14:43:30 -0800126 mService.mTaskIdToTask.delete(mTaskId);
Craig Mautnere3119b72015-01-20 15:02:36 -0800127 }
128
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800129 void moveTaskToStack(TaskStack stack, boolean toTop) {
130 if (stack == mStack) {
131 return;
132 }
133 if (DEBUG_STACK) Slog.i(TAG, "moveTaskToStack: removing taskId=" + mTaskId
134 + " from stack=" + mStack);
Wale Ogunwale000957c2015-04-03 08:19:12 -0700135 EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask");
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800136 if (mStack != null) {
137 mStack.removeTask(this);
138 }
139 stack.addTask(this, toTop);
140 }
141
Wale Ogunwale935e5022015-11-10 12:36:10 -0800142 void positionTaskInStack(TaskStack stack, int position, Rect bounds, Configuration config) {
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700143 if (mStack != null && stack != mStack) {
144 if (DEBUG_STACK) Slog.i(TAG, "positionTaskInStack: removing taskId=" + mTaskId
145 + " from stack=" + mStack);
146 EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask");
147 mStack.removeTask(this);
148 }
149 stack.positionTask(this, position, showForAllUsers());
Wale Ogunwale935e5022015-11-10 12:36:10 -0800150 setBounds(bounds, config);
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700151 }
152
Craig Mautnerc00204b2013-03-05 15:02:14 -0800153 boolean removeAppToken(AppWindowToken wtoken) {
Craig Mautner42bf39e2014-02-21 16:46:22 -0800154 boolean removed = mAppTokens.remove(wtoken);
Craig Mautnerc00204b2013-03-05 15:02:14 -0800155 if (mAppTokens.size() == 0) {
Wale Ogunwale000957c2015-04-03 08:19:12 -0700156 EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId,
Craig Mautner2c2549c2013-11-12 08:31:15 -0800157 "removeAppToken: last token");
Craig Mautnere3119b72015-01-20 15:02:36 -0800158 if (mDeferRemoval) {
159 removeLocked();
160 }
Craig Mautnerc00204b2013-03-05 15:02:14 -0800161 }
Craig Mautner83162a92015-01-26 14:43:30 -0800162 wtoken.mTask = null;
163 /* Leave mTaskId for now, it might be useful for debug
164 wtoken.mTaskId = -1;
165 */
Craig Mautner42bf39e2014-02-21 16:46:22 -0800166 return removed;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800167 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800168
Craig Mautnercbd84af2014-10-22 13:21:22 -0700169 void setSendingToBottom(boolean toBottom) {
170 for (int appTokenNdx = 0; appTokenNdx < mAppTokens.size(); appTokenNdx++) {
171 mAppTokens.get(appTokenNdx).sendingToBottom = toBottom;
172 }
173 }
174
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700175 /** Set the task bounds. Passing in null sets the bounds to fullscreen. */
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700176 int setBounds(Rect bounds, Configuration config) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700177 if (config == null) {
178 config = Configuration.EMPTY;
179 }
180 if (bounds == null && !Configuration.EMPTY.equals(config)) {
181 throw new IllegalArgumentException("null bounds but non empty configuration: "
182 + config);
183 }
184 if (bounds != null && Configuration.EMPTY.equals(config)) {
185 throw new IllegalArgumentException("non null bounds, but empty configuration");
186 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700187 boolean oldFullscreen = mFullscreen;
188 int rotation = Surface.ROTATION_0;
189 final DisplayContent displayContent = mStack.getDisplayContent();
190 if (displayContent != null) {
191 displayContent.getLogicalDisplayRect(mTmpRect);
192 rotation = displayContent.getDisplayInfo().rotation;
193 if (bounds == null) {
194 bounds = mTmpRect;
195 mFullscreen = true;
196 } else {
Wale Ogunwale99db1862015-10-23 20:08:22 -0700197 if ((mStack.mStackId != FREEFORM_WORKSPACE_STACK_ID
198 && mStack.mStackId != PINNED_STACK_ID) || bounds.isEmpty()) {
Stefan Kuhne234dbf82015-08-13 09:44:28 -0700199 // ensure bounds are entirely within the display rect
200 if (!bounds.intersect(mTmpRect)) {
201 // Can't set bounds outside the containing display...Sorry!
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700202 return BOUNDS_CHANGE_NONE;
Stefan Kuhne234dbf82015-08-13 09:44:28 -0700203 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700204 }
205 mFullscreen = mTmpRect.equals(bounds);
206 }
207 }
208
209 if (bounds == null) {
210 // Can't set to fullscreen if we don't have a display to get bounds from...
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700211 return BOUNDS_CHANGE_NONE;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700212 }
213 if (mBounds.equals(bounds) && oldFullscreen == mFullscreen && mRotation == rotation) {
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700214 return BOUNDS_CHANGE_NONE;
215 }
216
217 int boundsChange = BOUNDS_CHANGE_NONE;
218 if (mBounds.left != bounds.left || mBounds.right != bounds.right) {
219 boundsChange |= BOUNDS_CHANGE_POSITION;
220 }
221 if (mBounds.width() != bounds.width() || mBounds.height() != bounds.height()) {
222 boundsChange |= BOUNDS_CHANGE_SIZE;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700223 }
224
225 mBounds.set(bounds);
226 mRotation = rotation;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700227 if (displayContent != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800228 displayContent.mDimLayerController.updateDimLayer(this);
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700229 }
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700230 mOverrideConfig = mFullscreen ? Configuration.EMPTY : config;
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700231 return boundsChange;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700232 }
233
Chong Zhangb15758a2015-11-17 12:12:03 -0800234 void setResizeable(boolean resizeable) {
235 mResizeable = resizeable;
236 }
237
238 boolean isResizeable() {
239 return mResizeable;
240 }
241
Chong Zhang87b21722015-09-21 15:39:51 -0700242 boolean resizeLocked(Rect bounds, Configuration configuration, boolean forced) {
Chong Zhang3005e752015-09-18 18:46:28 -0700243 int boundsChanged = setBounds(bounds, configuration);
Chong Zhang87b21722015-09-21 15:39:51 -0700244 if (forced) {
Chong Zhang3005e752015-09-18 18:46:28 -0700245 boundsChanged |= BOUNDS_CHANGE_SIZE;
Chong Zhang3005e752015-09-18 18:46:28 -0700246 }
247 if (boundsChanged == BOUNDS_CHANGE_NONE) {
248 return false;
249 }
250 if ((boundsChanged & BOUNDS_CHANGE_SIZE) == BOUNDS_CHANGE_SIZE) {
251 resizeWindows();
252 }
253 return true;
254 }
255
Chong Zhangb15758a2015-11-17 12:12:03 -0800256 boolean scrollLocked(Rect bounds) {
257 // shift the task bound if it doesn't fully cover the stack area
258 mStack.getDimBounds(mTmpRect);
259 if (mService.mCurConfiguration.orientation == ORIENTATION_LANDSCAPE) {
260 if (bounds.left > mTmpRect.left) {
261 bounds.left = mTmpRect.left;
262 bounds.right = mTmpRect.left + mBounds.width();
263 } else if (bounds.right < mTmpRect.right) {
264 bounds.left = mTmpRect.right - mBounds.width();
265 bounds.right = mTmpRect.right;
266 }
267 } else {
268 if (bounds.top > mTmpRect.top) {
269 bounds.top = mTmpRect.top;
270 bounds.bottom = mTmpRect.top + mBounds.height();
271 } else if (bounds.bottom < mTmpRect.bottom) {
272 bounds.top = mTmpRect.bottom - mBounds.height();
273 bounds.bottom = mTmpRect.bottom;
274 }
275 }
276
277 if (bounds.equals(mBounds)) {
278 return false;
279 }
280 // Normal setBounds() does not allow non-null bounds for fullscreen apps.
281 // We only change bounds for the scrolling case without change it size,
282 // on resizing path we should still want the validation.
283 mBounds.set(bounds);
284 for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) {
285 final ArrayList<WindowState> windows = mAppTokens.get(activityNdx).allAppWindows;
286 for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
287 final WindowState win = windows.get(winNdx);
288 win.mXOffset = bounds.left;
289 win.mYOffset = bounds.top;
290 }
291 }
292 return true;
293 }
294
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700295 /** Return true if the current bound can get outputted to the rest of the system as-is. */
296 private boolean useCurrentBounds() {
297 final DisplayContent displayContent = mStack.getDisplayContent();
298 if (mFullscreen
Wale Ogunwale3797c222015-10-27 14:21:58 -0700299 || !StackId.isTaskResizeableByDockedStack(mStack.mStackId)
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700300 || displayContent == null
301 || displayContent.getDockedStackLocked() != null) {
302 return true;
303 }
304 return false;
305 }
306
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800307 /** Original bounds of the task if applicable, otherwise fullscreen rect. */
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700308 public void getBounds(Rect out) {
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700309 if (useCurrentBounds()) {
310 // No need to adjust the output bounds if fullscreen or the docked stack is visible
311 // since it is already what we want to represent to the rest of the system.
312 out.set(mBounds);
313 return;
314 }
315
316 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack
317 // is not currently visible. Go ahead a represent it as fullscreen to the rest of the
318 // system.
319 mStack.getDisplayContent().getLogicalDisplayRect(out);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700320 }
321
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800322
323 /**
324 * Calculate the maximum visible area of this task. If the task has only one app,
325 * the result will be visible frame of that app. If the task has more than one apps,
326 * we search from top down if the next app got different visible area.
327 *
328 * This effort is to handle the case where some task (eg. GMail composer) might pop up
329 * a dialog that's different in size from the activity below, in which case we should
330 * be dimming the entire task area behind the dialog.
331 *
332 * @param out Rect containing the max visible bounds.
333 * @return true if the task has some visible app windows; false otherwise.
334 */
335 boolean getMaxVisibleBounds(Rect out) {
336 boolean foundTop = false;
337 for (int i = mAppTokens.size() - 1; i >= 0; i--) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800338 final AppWindowToken token = mAppTokens.get(i);
339 // skip hidden (or about to hide) apps
340 if (token.mIsExiting || token.clientHidden || token.hiddenRequested) {
341 continue;
342 }
343 final WindowState win = token.findMainWindow();
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800344 if (win == null) {
345 continue;
346 }
347 if (!foundTop) {
348 out.set(win.mVisibleFrame);
349 foundTop = true;
350 continue;
351 }
352 if (win.mVisibleFrame.left < out.left) {
353 out.left = win.mVisibleFrame.left;
354 }
355 if (win.mVisibleFrame.top < out.top) {
356 out.top = win.mVisibleFrame.top;
357 }
358 if (win.mVisibleFrame.right > out.right) {
359 out.right = win.mVisibleFrame.right;
360 }
361 if (win.mVisibleFrame.bottom > out.bottom) {
362 out.bottom = win.mVisibleFrame.bottom;
363 }
364 }
365 return foundTop;
366 }
367
368 /** Bounds of the task to be used for dimming, as well as touch related tests. */
369 @Override
370 public void getDimBounds(Rect out) {
371 if (useCurrentBounds()) {
372 if (inFreeformWorkspace() && getMaxVisibleBounds(out)) {
373 return;
374 }
375
376 out.set(mBounds);
377 return;
378 }
379
380 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack
381 // is not currently visible. Go ahead a represent it as fullscreen to the rest of the
382 // system.
383 mStack.getDisplayContent().getLogicalDisplayRect(out);
384 }
385
Chong Zhang3005e752015-09-18 18:46:28 -0700386 void setDragResizing(boolean dragResizing) {
Chong Zhang3005e752015-09-18 18:46:28 -0700387 mDragResizing = dragResizing;
388 }
389
390 boolean isDragResizing() {
391 return mDragResizing;
392 }
393
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700394 void updateDisplayInfo(final DisplayContent displayContent) {
395 if (displayContent == null) {
396 return;
397 }
398 if (mFullscreen) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700399 setBounds(null, Configuration.EMPTY);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700400 return;
401 }
402 final int newRotation = displayContent.getDisplayInfo().rotation;
403 if (mRotation == newRotation) {
404 return;
405 }
406
407 // Device rotation changed. We don't want the task to move around on the screen when
408 // this happens, so update the task bounds so it stays in the same place.
Wale Ogunwale94744212015-09-21 19:01:47 -0700409 mTmpRect2.set(mBounds);
410 displayContent.rotateBounds(mRotation, newRotation, mTmpRect2);
Wale Ogunwale1ed0d892015-09-28 13:27:44 -0700411 if (setBounds(mTmpRect2, mOverrideConfig) != BOUNDS_CHANGE_NONE) {
412 // Post message to inform activity manager of the bounds change simulating
413 // a one-way call. We do this to prevent a deadlock between window manager
Filip Gruszczynski44bc4da2015-10-03 13:59:49 -0700414 // lock and activity manager lock been held. Only tasks within the freeform stack
415 // are resizeable independently of their stack resizing.
416 if (mStack.mStackId == FREEFORM_WORKSPACE_STACK_ID) {
417 mService.mH.sendMessage(mService.mH.obtainMessage(
418 RESIZE_TASK, mTaskId, RESIZE_MODE_SYSTEM_SCREEN_ROTATION, mBounds));
419 }
Wale Ogunwale1ed0d892015-09-28 13:27:44 -0700420 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700421 }
422
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700423 void resizeWindows() {
424 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
425 for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) {
426 final ArrayList<WindowState> windows = mAppTokens.get(activityNdx).allAppWindows;
427 for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
428 final WindowState win = windows.get(winNdx);
429 if (!resizingWindows.contains(win)) {
430 if (DEBUG_RESIZE) Slog.d(TAG, "setBounds: Resizing " + win);
431 resizingWindows.add(win);
432 }
433 }
434 }
435 }
436
Winsonc28098f2015-10-30 14:50:19 -0700437 /**
438 * Cancels any running app transitions associated with the task.
439 */
440 void cancelTaskWindowTransition() {
441 for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) {
442 mAppTokens.get(activityNdx).mAppAnimator.clearAnimation();
443 }
444 }
445
Winson13d30662015-11-06 15:30:29 -0800446 /**
447 * Cancels any running thumbnail transitions associated with the task.
448 */
449 void cancelTaskThumbnailTransition() {
450 for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) {
451 mAppTokens.get(activityNdx).mAppAnimator.clearThumbnail();
452 }
453 }
454
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700455 boolean showForAllUsers() {
Wale Ogunwale3fcb4a82015-04-06 14:00:13 -0700456 final int tokensCount = mAppTokens.size();
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700457 return (tokensCount != 0) && mAppTokens.get(tokensCount - 1).showForAllUsers;
Wale Ogunwale3fcb4a82015-04-06 14:00:13 -0700458 }
459
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700460 boolean inHomeStack() {
461 return mStack != null && mStack.mStackId == HOME_STACK_ID;
462 }
463
Chong Zhang09b21ef2015-09-14 10:20:21 -0700464 boolean inFreeformWorkspace() {
465 return mStack != null && mStack.mStackId == FREEFORM_WORKSPACE_STACK_ID;
466 }
467
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -0700468 boolean inDockedWorkspace() {
469 return mStack != null && mStack.mStackId == DOCKED_STACK_ID;
470 }
471
Chong Zhangb15758a2015-11-17 12:12:03 -0800472 boolean isResizeableByDockedStack() {
473 return mStack != null && getDisplayContent().getDockedStackLocked() != null &&
474 StackId.isTaskResizeableByDockedStack(mStack.mStackId);
475 }
476
477 /**
478 * Whether the task should be treated as if it's docked. Returns true if the task
479 * is currently in docked workspace, or it's side-by-side to a docked task.
480 */
481 boolean isDockedInEffect() {
482 return inDockedWorkspace() || isResizeableByDockedStack();
483 }
484
Chong Zhangd8ceb852015-11-11 14:53:41 -0800485 WindowState getTopVisibleAppMainWindow() {
486 final AppWindowToken token = getTopVisibleAppToken();
487 return token != null ? token.findMainWindow() : null;
Chong Zhang9184ec62015-09-24 12:32:21 -0700488 }
489
Chong Zhangd8ceb852015-11-11 14:53:41 -0800490 AppWindowToken getTopVisibleAppToken() {
491 for (int i = mAppTokens.size() - 1; i >= 0; i--) {
492 final AppWindowToken token = mAppTokens.get(i);
493 // skip hidden (or about to hide) apps
494 if (!token.mIsExiting && !token.clientHidden && !token.hiddenRequested) {
495 return token;
496 }
497 }
498 return null;
Chong Zhangbef461f2015-10-27 11:38:24 -0700499 }
500
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800501 @Override
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700502 public boolean isFullscreen() {
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700503 if (useCurrentBounds()) {
504 return mFullscreen;
505 }
506 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack
507 // is not currently visible. Go ahead a represent it as fullscreen to the rest of the
508 // system.
509 return true;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700510 }
511
512 @Override
513 public DisplayInfo getDisplayInfo() {
514 return mStack.getDisplayContent().getDisplayInfo();
515 }
516
517 @Override
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800518 public String toString() {
Craig Mautner83162a92015-01-26 14:43:30 -0800519 return "{taskId=" + mTaskId + " appTokens=" + mAppTokens + " mdr=" + mDeferRemoval + "}";
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800520 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700521
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700522 @Override
523 public String toShortString() {
524 return "Task=" + mTaskId;
525 }
526
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700527 public void printTo(String prefix, PrintWriter pw) {
528 pw.print(prefix); pw.print("taskId="); pw.print(mTaskId);
529 pw.print(prefix); pw.print("appTokens="); pw.print(mAppTokens);
530 pw.print(prefix); pw.print("mdr="); pw.println(mDeferRemoval);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700531 }
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800532}