blob: d707026fbbb2ba23535a927364df37d125479acc [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;
37
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070038import android.view.SurfaceControl;
Craig Mautnere3119b72015-01-20 15:02:36 -080039import com.android.server.EventLogTags;
Craig Mautner2c2549c2013-11-12 08:31:15 -080040
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070041import java.io.PrintWriter;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070042
Wale Ogunwalef6192862016-09-10 13:42:30 -070043class Task extends WindowContainer<AppWindowToken> implements DimLayer.DimLayerUser {
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -080044 static final String TAG = TAG_WITH_CLASS_NAME ? "Task" : TAG_WM;
Wale Ogunwale2cc92f52015-09-09 13:12:10 -070045 // Return value from {@link setBounds} indicating no change was made to the Task bounds.
46 static final int BOUNDS_CHANGE_NONE = 0;
47 // Return value from {@link setBounds} indicating the position of the Task bounds changed.
48 static final int BOUNDS_CHANGE_POSITION = 1;
49 // Return value from {@link setBounds} indicating the size of the Task bounds changed.
50 static final int BOUNDS_CHANGE_SIZE = 1 << 1;
51
Wale Ogunwalef6192862016-09-10 13:42:30 -070052 // TODO: Track parent marks like this in WindowContainer.
Craig Mautnerc00204b2013-03-05 15:02:14 -080053 TaskStack mStack;
Craig Mautner83162a92015-01-26 14:43:30 -080054 final int mTaskId;
Craig Mautnerac6f8432013-07-17 13:24:59 -070055 final int mUserId;
Craig Mautner9ef471f2014-02-07 13:11:47 -080056 boolean mDeferRemoval = false;
Craig Mautnere3119b72015-01-20 15:02:36 -080057 final WindowManagerService mService;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080058
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070059 // Content limits relative to the DisplayContent this sits in.
60 private Rect mBounds = new Rect();
Jorim Jaggi0429f352015-12-22 16:29:16 +010061 final Rect mPreparedFrozenBounds = new Rect();
Jorim Jaggi26c8c422016-05-09 19:57:25 -070062 final Configuration mPreparedFrozenMergedConfig = new Configuration();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070063
Jorim Jaggidc249c42015-12-15 14:57:31 -080064 // Bounds used to calculate the insets.
65 private final Rect mTempInsetBounds = new Rect();
66
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070067 // Device rotation as of the last time {@link #mBounds} was set.
68 int mRotation;
69
70 // Whether mBounds is fullscreen
71 private boolean mFullscreen = true;
72
Andrii Kulian8072d112016-09-16 11:11:01 -070073 /**
74 * Contains configurations settings that are different from the parent configuration due to
75 * stack specific operations. E.g. {@link #setBounds}.
76 */
Jorim Jaggi26c8c422016-05-09 19:57:25 -070077 Configuration mOverrideConfig = Configuration.EMPTY;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070078
79 // For comparison with DisplayContent bounds.
80 private Rect mTmpRect = new Rect();
81 // For handling display rotations.
82 private Rect mTmpRect2 = new Rect();
83
Wale Ogunwaleb1faf602016-01-27 09:12:31 -080084 // Resize mode of the task. See {@link ActivityInfo#resizeMode}
85 private int mResizeMode;
Chong Zhangb15758a2015-11-17 12:12:03 -080086
Chong Zhang3005e752015-09-18 18:46:28 -070087 // Whether the task is currently being drag-resized
88 private boolean mDragResizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +010089 private int mDragResizeMode;
Chong Zhang3005e752015-09-18 18:46:28 -070090
Wale Ogunwaleb1faf602016-01-27 09:12:31 -080091 private boolean mHomeTask;
92
Jiaquan Hedd1e66f2016-06-15 15:15:12 -070093 // Whether this task is an on-top launcher task, which is determined by the root activity.
94 private boolean mIsOnTopLauncher;
95
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070096 Task(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds,
Andrii Kulian8072d112016-09-16 11:11:01 -070097 Configuration overrideConfig, boolean isOnTopLauncher) {
Craig Mautner83162a92015-01-26 14:43:30 -080098 mTaskId = taskId;
Craig Mautnerc00204b2013-03-05 15:02:14 -080099 mStack = stack;
Craig Mautnerac6f8432013-07-17 13:24:59 -0700100 mUserId = userId;
Craig Mautnere3119b72015-01-20 15:02:36 -0800101 mService = service;
Jiaquan Hedd1e66f2016-06-15 15:15:12 -0700102 mIsOnTopLauncher = isOnTopLauncher;
Andrii Kulian8072d112016-09-16 11:11:01 -0700103 setBounds(bounds, overrideConfig);
Craig Mautnerc00204b2013-03-05 15:02:14 -0800104 }
105
106 DisplayContent getDisplayContent() {
107 return mStack.getDisplayContent();
108 }
109
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800110 void addAppToken(int addPos, AppWindowToken wtoken, int resizeMode, boolean homeTask) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700111 final int lastPos = mChildren.size();
Craig Mautner83162a92015-01-26 14:43:30 -0800112 if (addPos >= lastPos) {
113 addPos = lastPos;
114 } else {
115 for (int pos = 0; pos < lastPos && pos < addPos; ++pos) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700116 if (mChildren.get(pos).removed) {
Craig Mautner83162a92015-01-26 14:43:30 -0800117 // addPos assumes removed tokens are actually gone.
118 ++addPos;
119 }
Craig Mautner01f79cf2014-08-27 09:56:02 -0700120 }
Craig Mautner42bf39e2014-02-21 16:46:22 -0800121 }
Wale Ogunwalef6192862016-09-10 13:42:30 -0700122
123 if (wtoken.mParent != null) {
124 wtoken.mParent.removeChild(wtoken);
125 }
126 addChild(wtoken, addPos);
Craig Mautner83162a92015-01-26 14:43:30 -0800127 wtoken.mTask = this;
Craig Mautner42bf39e2014-02-21 16:46:22 -0800128 mDeferRemoval = false;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800129 mResizeMode = resizeMode;
130 mHomeTask = homeTask;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800131 }
132
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700133 private boolean hasWindowsAlive() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700134 for (int i = mChildren.size() - 1; i >= 0; i--) {
135 if (mChildren.get(i).hasWindowsAlive()) {
Chong Zhang7e8eeb72016-01-06 19:14:47 -0800136 return true;
137 }
138 }
139 return false;
140 }
141
Wale Ogunwalef6192862016-09-10 13:42:30 -0700142 @Override
143 void removeIfPossible() {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700144 if (hasWindowsAlive() && mStack.isAnimating()) {
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800145 if (DEBUG_STACK) Slog.i(TAG, "removeTask: deferring removing taskId=" + mTaskId);
Craig Mautnere3119b72015-01-20 15:02:36 -0800146 mDeferRemoval = true;
147 return;
148 }
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800149 if (DEBUG_STACK) Slog.i(TAG, "removeTask: removing taskId=" + mTaskId);
Craig Mautner83162a92015-01-26 14:43:30 -0800150 EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "removeTask");
Craig Mautnere3119b72015-01-20 15:02:36 -0800151 mDeferRemoval = false;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700152 DisplayContent content = getDisplayContent();
153 if (content != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800154 content.mDimLayerController.removeDimLayerUser(this);
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700155 }
Wale Ogunwale14a3fb92016-09-11 15:19:05 -0700156 mParent.removeChild(this);
Craig Mautner83162a92015-01-26 14:43:30 -0800157 mService.mTaskIdToTask.delete(mTaskId);
Craig Mautnere3119b72015-01-20 15:02:36 -0800158 }
159
Wale Ogunwalef6192862016-09-10 13:42:30 -0700160 // Change to use reparenting in WC when TaskStack is switched to use WC.
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800161 void moveTaskToStack(TaskStack stack, boolean toTop) {
162 if (stack == mStack) {
163 return;
164 }
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800165 if (DEBUG_STACK) Slog.i(TAG, "moveTaskToStack: removing taskId=" + mTaskId
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800166 + " from stack=" + mStack);
Wale Ogunwale000957c2015-04-03 08:19:12 -0700167 EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask");
Wale Ogunwale14a3fb92016-09-11 15:19:05 -0700168 mParent.removeChild(this);
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800169 stack.addTask(this, toTop);
170 }
171
Wale Ogunwale935e5022015-11-10 12:36:10 -0800172 void positionTaskInStack(TaskStack stack, int position, Rect bounds, Configuration config) {
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700173 if (mStack != null && stack != mStack) {
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800174 if (DEBUG_STACK) Slog.i(TAG, "positionTaskInStack: removing taskId=" + mTaskId
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700175 + " from stack=" + mStack);
176 EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask");
Wale Ogunwale14a3fb92016-09-11 15:19:05 -0700177 mStack.removeChild(this);
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700178 }
179 stack.positionTask(this, position, showForAllUsers());
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800180 resizeLocked(bounds, config, false /* force */);
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800181
Wale Ogunwalef6192862016-09-10 13:42:30 -0700182 for (int activityNdx = mChildren.size() - 1; activityNdx >= 0; --activityNdx) {
183 mChildren.get(activityNdx).notifyMovedInStack();
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800184 }
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700185 }
186
Wale Ogunwale14a3fb92016-09-11 15:19:05 -0700187 @Override
Wale Ogunwalef6192862016-09-10 13:42:30 -0700188 void removeChild(AppWindowToken token) {
189 if (!mChildren.contains(token)) {
190 Slog.e(TAG, "removeChild: token=" + this + " not found.");
191 return;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700192 }
193
Wale Ogunwalef6192862016-09-10 13:42:30 -0700194 super.removeChild(token);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700195
Wale Ogunwalef6192862016-09-10 13:42:30 -0700196 if (mChildren.isEmpty()) {
Jorim Jaggi0429f352015-12-22 16:29:16 +0100197 EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "removeAppToken: last token");
Craig Mautnere3119b72015-01-20 15:02:36 -0800198 if (mDeferRemoval) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700199 removeIfPossible();
Craig Mautnere3119b72015-01-20 15:02:36 -0800200 }
Craig Mautnerc00204b2013-03-05 15:02:14 -0800201 }
Wale Ogunwalef6192862016-09-10 13:42:30 -0700202 token.mTask = null;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800203 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800204
Craig Mautnercbd84af2014-10-22 13:21:22 -0700205 void setSendingToBottom(boolean toBottom) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700206 for (int appTokenNdx = 0; appTokenNdx < mChildren.size(); appTokenNdx++) {
207 mChildren.get(appTokenNdx).sendingToBottom = toBottom;
Craig Mautnercbd84af2014-10-22 13:21:22 -0700208 }
209 }
210
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700211 /** Set the task bounds. Passing in null sets the bounds to fullscreen. */
Andrii Kulian8072d112016-09-16 11:11:01 -0700212 private int setBounds(Rect bounds, Configuration overrideConfig) {
213 if (overrideConfig == null) {
214 overrideConfig = Configuration.EMPTY;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700215 }
Andrii Kulian8072d112016-09-16 11:11:01 -0700216 if (bounds == null && !Configuration.EMPTY.equals(overrideConfig)) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700217 throw new IllegalArgumentException("null bounds but non empty configuration: "
Andrii Kulian8072d112016-09-16 11:11:01 -0700218 + overrideConfig);
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700219 }
Andrii Kulian8072d112016-09-16 11:11:01 -0700220 if (bounds != null && Configuration.EMPTY.equals(overrideConfig)) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700221 throw new IllegalArgumentException("non null bounds, but empty configuration");
222 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700223 boolean oldFullscreen = mFullscreen;
224 int rotation = Surface.ROTATION_0;
225 final DisplayContent displayContent = mStack.getDisplayContent();
226 if (displayContent != null) {
227 displayContent.getLogicalDisplayRect(mTmpRect);
228 rotation = displayContent.getDisplayInfo().rotation;
Jorim Jaggi067e8172016-02-03 18:24:12 -0800229 mFullscreen = bounds == null;
230 if (mFullscreen) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700231 bounds = mTmpRect;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700232 }
233 }
234
235 if (bounds == null) {
236 // Can't set to fullscreen if we don't have a display to get bounds from...
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700237 return BOUNDS_CHANGE_NONE;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700238 }
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700239 if (mBounds.equals(bounds) && oldFullscreen == mFullscreen && mRotation == rotation) {
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700240 return BOUNDS_CHANGE_NONE;
241 }
242
243 int boundsChange = BOUNDS_CHANGE_NONE;
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700244 if (mBounds.left != bounds.left || mBounds.top != bounds.top) {
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700245 boundsChange |= BOUNDS_CHANGE_POSITION;
246 }
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700247 if (mBounds.width() != bounds.width() || mBounds.height() != bounds.height()) {
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700248 boundsChange |= BOUNDS_CHANGE_SIZE;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700249 }
250
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700251 mBounds.set(bounds);
Chong Zhangf66db432016-01-13 10:39:51 -0800252
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700253 mRotation = rotation;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700254 if (displayContent != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800255 displayContent.mDimLayerController.updateDimLayer(this);
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700256 }
Andrii Kulian8072d112016-09-16 11:11:01 -0700257 mOverrideConfig = mFullscreen ? Configuration.EMPTY : overrideConfig;
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700258 return boundsChange;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700259 }
260
Jorim Jaggidc249c42015-12-15 14:57:31 -0800261 /**
262 * Sets the bounds used to calculate the insets. See
263 * {@link android.app.IActivityManager#resizeDockedStack} why this is needed.
264 */
265 void setTempInsetBounds(Rect tempInsetBounds) {
266 if (tempInsetBounds != null) {
267 mTempInsetBounds.set(tempInsetBounds);
268 } else {
269 mTempInsetBounds.setEmpty();
270 }
271 }
272
273 /**
274 * Gets the bounds used to calculate the insets. See
275 * {@link android.app.IActivityManager#resizeDockedStack} why this is needed.
276 */
277 void getTempInsetBounds(Rect out) {
278 out.set(mTempInsetBounds);
279 }
280
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800281 void setResizeable(int resizeMode) {
282 mResizeMode = resizeMode;
Chong Zhangb15758a2015-11-17 12:12:03 -0800283 }
284
285 boolean isResizeable() {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800286 return !mHomeTask
287 && (ActivityInfo.isResizeableMode(mResizeMode) || mService.mForceResizableTasks);
288 }
289
Jiaquan Hedd1e66f2016-06-15 15:15:12 -0700290 boolean isOnTopLauncher() {
291 return mIsOnTopLauncher;
292 }
293
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800294 boolean cropWindowsToStackBounds() {
295 return !mHomeTask && (isResizeable() || mResizeMode == RESIZE_MODE_CROP_WINDOWS);
296 }
297
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800298 boolean isHomeTask() {
299 return mHomeTask;
300 }
301
Andrii Kulian8072d112016-09-16 11:11:01 -0700302 boolean resizeLocked(Rect bounds, Configuration overrideConfig, boolean forced) {
303 int boundsChanged = setBounds(bounds, overrideConfig);
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) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700311 onResize();
Chong Zhangbd0d9372015-12-28 15:18:29 -0800312 } else {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700313 onMovedByResize();
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);
Andrii Kulian8072d112016-09-16 11:11:01 -0700324 mPreparedFrozenMergedConfig.setTo(mService.mGlobalConfiguration);
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700325 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();
Wale Ogunwalef6192862016-09-10 13:42:30 -0700357 return mFullscreen
Wale Ogunwale3797c222015-10-27 14:21:58 -0700358 || !StackId.isTaskResizeableByDockedStack(mStack.mStackId)
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700359 || displayContent == null
Wale Ogunwalef6192862016-09-10 13:42:30 -0700360 || displayContent.getDockedStackVisibleForUserLocked() != null;
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700361 }
362
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800363 /** Original bounds of the task if applicable, otherwise fullscreen rect. */
Wale Ogunwaleccb6ce22016-01-14 15:36:35 -0800364 void getBounds(Rect out) {
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700365 if (useCurrentBounds()) {
366 // No need to adjust the output bounds if fullscreen or the docked stack is visible
367 // since it is already what we want to represent to the rest of the system.
368 out.set(mBounds);
369 return;
370 }
371
Wale Ogunwaleccb6ce22016-01-14 15:36:35 -0800372 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack is
373 // not currently visible. Go ahead a represent it as fullscreen to the rest of the system.
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700374 mStack.getDisplayContent().getLogicalDisplayRect(out);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700375 }
376
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800377 /**
378 * Calculate the maximum visible area of this task. If the task has only one app,
379 * the result will be visible frame of that app. If the task has more than one apps,
380 * we search from top down if the next app got different visible area.
381 *
382 * This effort is to handle the case where some task (eg. GMail composer) might pop up
383 * a dialog that's different in size from the activity below, in which case we should
384 * be dimming the entire task area behind the dialog.
385 *
386 * @param out Rect containing the max visible bounds.
387 * @return true if the task has some visible app windows; false otherwise.
388 */
389 boolean getMaxVisibleBounds(Rect out) {
390 boolean foundTop = false;
Wale Ogunwalef6192862016-09-10 13:42:30 -0700391 for (int i = mChildren.size() - 1; i >= 0; i--) {
392 final AppWindowToken token = mChildren.get(i);
Chong Zhangd8ceb852015-11-11 14:53:41 -0800393 // skip hidden (or about to hide) apps
394 if (token.mIsExiting || token.clientHidden || token.hiddenRequested) {
395 continue;
396 }
397 final WindowState win = token.findMainWindow();
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800398 if (win == null) {
399 continue;
400 }
401 if (!foundTop) {
402 out.set(win.mVisibleFrame);
403 foundTop = true;
404 continue;
405 }
406 if (win.mVisibleFrame.left < out.left) {
407 out.left = win.mVisibleFrame.left;
408 }
409 if (win.mVisibleFrame.top < out.top) {
410 out.top = win.mVisibleFrame.top;
411 }
412 if (win.mVisibleFrame.right > out.right) {
413 out.right = win.mVisibleFrame.right;
414 }
415 if (win.mVisibleFrame.bottom > out.bottom) {
416 out.bottom = win.mVisibleFrame.bottom;
417 }
418 }
419 return foundTop;
420 }
421
422 /** Bounds of the task to be used for dimming, as well as touch related tests. */
423 @Override
424 public void getDimBounds(Rect out) {
Robert Carra86a6bf2016-04-08 17:34:16 -0700425 final DisplayContent displayContent = mStack.getDisplayContent();
426 // It doesn't matter if we in particular are part of the resize, since we couldn't have
427 // a DimLayer anyway if we weren't visible.
Wale Ogunwalef6192862016-09-10 13:42:30 -0700428 final boolean dockedResizing = displayContent != null
429 && displayContent.mDividerControllerLocked.isResizing();
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800430 if (useCurrentBounds()) {
431 if (inFreeformWorkspace() && getMaxVisibleBounds(out)) {
432 return;
433 }
434
Jorim Jaggi22a869f2016-03-25 23:33:21 -0700435 if (!mFullscreen) {
436 // When minimizing the docked stack when going home, we don't adjust the task bounds
437 // so we need to intersect the task bounds with the stack bounds here.
Robert Carra86a6bf2016-04-08 17:34:16 -0700438 //
439 // If we are Docked Resizing with snap points, the task bounds could be smaller than the stack
440 // bounds and so we don't even want to use them. Even if the app should not be resized the Dim
441 // should keep up with the divider.
442 if (dockedResizing) {
443 mStack.getBounds(out);
444 } else {
445 mStack.getBounds(mTmpRect);
446 mTmpRect.intersect(mBounds);
447 }
Jorim Jaggi22a869f2016-03-25 23:33:21 -0700448 out.set(mTmpRect);
449 } else {
450 out.set(mBounds);
451 }
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800452 return;
453 }
454
Wale Ogunwalef6192862016-09-10 13:42:30 -0700455 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack is
456 // not currently visible. Go ahead a represent it as fullscreen to the rest of the system.
457 if (displayContent != null) {
458 displayContent.getLogicalDisplayRect(out);
459 }
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800460 }
461
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100462 void setDragResizing(boolean dragResizing, int dragResizeMode) {
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800463 if (mDragResizing != dragResizing) {
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100464 if (!DragResizeMode.isModeAllowedForStack(mStack.mStackId, dragResizeMode)) {
465 throw new IllegalArgumentException("Drag resize mode not allow for stack stackId="
466 + mStack.mStackId + " dragResizeMode=" + dragResizeMode);
467 }
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800468 mDragResizing = dragResizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100469 mDragResizeMode = dragResizeMode;
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800470 resetDragResizingChangeReported();
471 }
472 }
473
Chong Zhang3005e752015-09-18 18:46:28 -0700474 boolean isDragResizing() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700475 return mDragResizing;
Chong Zhang3005e752015-09-18 18:46:28 -0700476 }
477
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100478 int getDragResizeMode() {
479 return mDragResizeMode;
480 }
481
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700482 void updateDisplayInfo(final DisplayContent displayContent) {
483 if (displayContent == null) {
484 return;
485 }
486 if (mFullscreen) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700487 setBounds(null, Configuration.EMPTY);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700488 return;
489 }
490 final int newRotation = displayContent.getDisplayInfo().rotation;
491 if (mRotation == newRotation) {
492 return;
493 }
494
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800495 // Device rotation changed.
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700496 // - We don't want the task to move around on the screen when this happens, so update the
497 // task bounds so it stays in the same place.
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800498 // - Rotate the bounds and notify activity manager if the task can be resized independently
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700499 // from its stack. The stack will take care of task rotation for the other case.
500 mTmpRect2.set(mBounds);
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800501
502 if (!StackId.isTaskResizeAllowed(mStack.mStackId)) {
503 setBounds(mTmpRect2, mOverrideConfig);
504 return;
505 }
506
Wale Ogunwale94744212015-09-21 19:01:47 -0700507 displayContent.rotateBounds(mRotation, newRotation, mTmpRect2);
Wale Ogunwale1ed0d892015-09-28 13:27:44 -0700508 if (setBounds(mTmpRect2, mOverrideConfig) != BOUNDS_CHANGE_NONE) {
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800509 // Post message to inform activity manager of the bounds change simulating a one-way
510 // call. We do this to prevent a deadlock between window manager lock and activity
511 // manager lock been held.
512 mService.mH.obtainMessage(RESIZE_TASK, mTaskId,
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700513 RESIZE_MODE_SYSTEM_SCREEN_ROTATION, mBounds).sendToTarget();
Wale Ogunwale1ed0d892015-09-28 13:27:44 -0700514 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700515 }
516
Wale Ogunwalef6192862016-09-10 13:42:30 -0700517 /** Cancels any running app transitions associated with the task. */
Winsonc28098f2015-10-30 14:50:19 -0700518 void cancelTaskWindowTransition() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700519 for (int i = mChildren.size() - 1; i >= 0; --i) {
520 mChildren.get(i).mAppAnimator.clearAnimation();
Winsonc28098f2015-10-30 14:50:19 -0700521 }
522 }
523
Wale Ogunwalef6192862016-09-10 13:42:30 -0700524 /** Cancels any running thumbnail transitions associated with the task. */
Winson13d30662015-11-06 15:30:29 -0800525 void cancelTaskThumbnailTransition() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700526 for (int i = mChildren.size() - 1; i >= 0; --i) {
527 mChildren.get(i).mAppAnimator.clearThumbnail();
Winson13d30662015-11-06 15:30:29 -0800528 }
529 }
530
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700531 boolean showForAllUsers() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700532 final int tokensCount = mChildren.size();
533 return (tokensCount != 0) && mChildren.get(tokensCount - 1).showForAllUsers;
Jorim Jaggiff71d202016-04-14 13:12:36 -0700534 }
535
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700536 boolean inHomeStack() {
537 return mStack != null && mStack.mStackId == HOME_STACK_ID;
538 }
539
Chong Zhang09b21ef2015-09-14 10:20:21 -0700540 boolean inFreeformWorkspace() {
541 return mStack != null && mStack.mStackId == FREEFORM_WORKSPACE_STACK_ID;
542 }
543
Robert Carr03138452016-05-18 14:53:16 -0700544 boolean inPinnedWorkspace() {
545 return mStack != null && mStack.mStackId == PINNED_STACK_ID;
546 }
547
Robert Carre6275582016-02-29 15:45:45 -0800548 boolean isFloating() {
549 return StackId.tasksAreFloating(mStack.mStackId);
550 }
551
Chong Zhangd8ceb852015-11-11 14:53:41 -0800552 WindowState getTopVisibleAppMainWindow() {
553 final AppWindowToken token = getTopVisibleAppToken();
554 return token != null ? token.findMainWindow() : null;
Chong Zhang9184ec62015-09-24 12:32:21 -0700555 }
556
Chong Zhangd8ceb852015-11-11 14:53:41 -0800557 AppWindowToken getTopVisibleAppToken() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700558 for (int i = mChildren.size() - 1; i >= 0; i--) {
559 final AppWindowToken token = mChildren.get(i);
Chong Zhangd8ceb852015-11-11 14:53:41 -0800560 // skip hidden (or about to hide) apps
561 if (!token.mIsExiting && !token.clientHidden && !token.hiddenRequested) {
562 return token;
563 }
564 }
565 return null;
Chong Zhangbef461f2015-10-27 11:38:24 -0700566 }
567
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800568 @Override
Wale Ogunwale29bfbb82016-05-12 15:13:52 -0700569 public boolean dimFullscreen() {
570 return isHomeTask() || isFullscreen();
571 }
572
573 boolean isFullscreen() {
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700574 if (useCurrentBounds()) {
575 return mFullscreen;
576 }
577 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack
578 // is not currently visible. Go ahead a represent it as fullscreen to the rest of the
579 // system.
580 return true;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700581 }
582
583 @Override
584 public DisplayInfo getDisplayInfo() {
585 return mStack.getDisplayContent().getDisplayInfo();
586 }
587
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700588 void forceWindowsScaleable(boolean force) {
589 SurfaceControl.openTransaction();
590 try {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700591 for (int i = mChildren.size() - 1; i >= 0; i--) {
592 mChildren.get(i).forceWindowsScaleableInTransaction(force);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700593 }
594 } finally {
595 SurfaceControl.closeTransaction();
596 }
597 }
598
Wale Ogunwaleec731152016-09-08 20:18:57 -0700599 void getWindowOnDisplayBeforeToken(DisplayContent dc, WindowToken token,
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700600 DisplayContent.GetWindowOnDisplaySearchResult result) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700601 for (int i = mChildren.size() - 1; i >= 0; --i) {
602 final AppWindowToken current = mChildren.get(i);
Wale Ogunwaleec731152016-09-08 20:18:57 -0700603 if (current == token) {
604 // We have reach the token we are interested in. End search.
605 result.reachedToken = true;
606 return;
607 }
608
609 // We haven't reached the token yet; if this token is not going to the bottom and
610 // has windows on this display, then it is a candidate for what we are looking for.
611 final WindowList tokenWindowList = dc.getTokenWindowsOnDisplay(current);
612 if (!current.sendingToBottom && tokenWindowList.size() > 0) {
613 result.foundWindow = tokenWindowList.get(0);
614 }
615 }
616 }
617
618 void getWindowOnDisplayAfterToken(DisplayContent dc, WindowToken token,
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700619 DisplayContent.GetWindowOnDisplaySearchResult result) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700620 for (int i = mChildren.size() - 1; i >= 0; --i) {
621 final AppWindowToken current = mChildren.get(i);
Wale Ogunwaleec731152016-09-08 20:18:57 -0700622 if (!result.reachedToken) {
623 if (current == token) {
624 // We have reached the token we are interested in. Get whichever window occurs
625 // after it that is on the same display.
626 result.reachedToken = true;
627 }
628 continue;
629 }
630
631 final WindowList tokenWindowList = dc.getTokenWindowsOnDisplay(current);
632 if (tokenWindowList.size() > 0) {
633 result.foundWindow = tokenWindowList.get(tokenWindowList.size() - 1);
634 return;
635 }
636 }
637 }
638
Wale Ogunwalef6192862016-09-10 13:42:30 -0700639 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -0700640 boolean fillsParent() {
641 return mFullscreen || !StackId.isTaskResizeAllowed(mStack.mStackId);
642 }
643
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700644 @Override
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800645 public String toString() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700646 return "{taskId=" + mTaskId + " appTokens=" + mChildren + " mdr=" + mDeferRemoval + "}";
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800647 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700648
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700649 String getName() {
650 return toShortString();
651 }
652
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700653 @Override
654 public String toShortString() {
655 return "Task=" + mTaskId;
656 }
657
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800658 public void dump(String prefix, PrintWriter pw) {
659 final String doublePrefix = prefix + " ";
660
661 pw.println(prefix + "taskId=" + mTaskId);
662 pw.println(doublePrefix + "mFullscreen=" + mFullscreen);
663 pw.println(doublePrefix + "mBounds=" + mBounds.toShortString());
664 pw.println(doublePrefix + "mdr=" + mDeferRemoval);
Wale Ogunwalef6192862016-09-10 13:42:30 -0700665 pw.println(doublePrefix + "appTokens=" + mChildren);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800666 pw.println(doublePrefix + "mTempInsetBounds=" + mTempInsetBounds.toShortString());
667
668 final String triplePrefix = doublePrefix + " ";
669
Wale Ogunwalef6192862016-09-10 13:42:30 -0700670 for (int i = mChildren.size() - 1; i >= 0; i--) {
671 final AppWindowToken wtoken = mChildren.get(i);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800672 pw.println(triplePrefix + "Activity #" + i + " " + wtoken);
673 wtoken.dump(pw, triplePrefix);
674 }
675
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700676 }
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800677}