blob: 19c9b7d0fcf68ae7da770bf3692e09b036d4b40f [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;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080023import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
Jorim Jaggid53f0922016-04-06 22:16:23 -070024import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
25import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwale1ed0d892015-09-28 13:27:44 -070026import static com.android.server.wm.WindowManagerService.H.RESIZE_TASK;
Wale Ogunwale99db1862015-10-23 20:08:22 -070027
Wale Ogunwale3797c222015-10-27 14:21:58 -070028import android.app.ActivityManager.StackId;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -080029import android.content.pm.ActivityInfo;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070030import android.content.res.Configuration;
31import android.graphics.Rect;
Craig Mautner2c2549c2013-11-12 08:31:15 -080032import android.util.EventLog;
Craig Mautner42bf39e2014-02-21 16:46:22 -080033import android.util.Slog;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070034import android.view.DisplayInfo;
35import android.view.Surface;
36
Craig Mautnere3119b72015-01-20 15:02:36 -080037import com.android.server.EventLogTags;
Craig Mautner2c2549c2013-11-12 08:31:15 -080038
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070039import java.io.PrintWriter;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070040
Wale Ogunwalef6192862016-09-10 13:42:30 -070041class Task extends WindowContainer<AppWindowToken> implements DimLayer.DimLayerUser {
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -080042 static final String TAG = TAG_WITH_CLASS_NAME ? "Task" : TAG_WM;
Wale Ogunwale2cc92f52015-09-09 13:12:10 -070043 // Return value from {@link setBounds} indicating no change was made to the Task bounds.
Wale Ogunwale3eadad72016-10-13 09:16:59 -070044 private static final int BOUNDS_CHANGE_NONE = 0;
Wale Ogunwale2cc92f52015-09-09 13:12:10 -070045 // Return value from {@link setBounds} indicating the position of the Task bounds changed.
Wale Ogunwale3eadad72016-10-13 09:16:59 -070046 private static final int BOUNDS_CHANGE_POSITION = 1;
Wale Ogunwale2cc92f52015-09-09 13:12:10 -070047 // Return value from {@link setBounds} indicating the size of the Task bounds changed.
Wale Ogunwale3eadad72016-10-13 09:16:59 -070048 private static final int BOUNDS_CHANGE_SIZE = 1 << 1;
Wale Ogunwale2cc92f52015-09-09 13:12:10 -070049
Wale Ogunwalef6192862016-09-10 13:42:30 -070050 // TODO: Track parent marks like this in WindowContainer.
Craig Mautnerc00204b2013-03-05 15:02:14 -080051 TaskStack mStack;
Craig Mautner83162a92015-01-26 14:43:30 -080052 final int mTaskId;
Craig Mautnerac6f8432013-07-17 13:24:59 -070053 final int mUserId;
Wale Ogunwale3eadad72016-10-13 09:16:59 -070054 private boolean mDeferRemoval = false;
Craig Mautnere3119b72015-01-20 15:02:36 -080055 final WindowManagerService mService;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080056
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070057 // Content limits relative to the DisplayContent this sits in.
58 private Rect mBounds = new Rect();
Jorim Jaggi0429f352015-12-22 16:29:16 +010059 final Rect mPreparedFrozenBounds = new Rect();
Jorim Jaggi26c8c422016-05-09 19:57:25 -070060 final Configuration mPreparedFrozenMergedConfig = new Configuration();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070061
Jorim Jaggidc249c42015-12-15 14:57:31 -080062 // Bounds used to calculate the insets.
63 private final Rect mTempInsetBounds = new Rect();
64
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070065 // Device rotation as of the last time {@link #mBounds} was set.
Wale Ogunwale3eadad72016-10-13 09:16:59 -070066 private int mRotation;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070067
68 // Whether mBounds is fullscreen
Wale Ogunwale5a2183d2016-09-19 12:26:13 -070069 private boolean mFillsParent = true;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070070
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070071 // For comparison with DisplayContent bounds.
72 private Rect mTmpRect = new Rect();
73 // For handling display rotations.
74 private Rect mTmpRect2 = new Rect();
75
Wale Ogunwaleb1faf602016-01-27 09:12:31 -080076 // Resize mode of the task. See {@link ActivityInfo#resizeMode}
77 private int mResizeMode;
Chong Zhangb15758a2015-11-17 12:12:03 -080078
Chong Zhang3005e752015-09-18 18:46:28 -070079 // Whether the task is currently being drag-resized
80 private boolean mDragResizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +010081 private int mDragResizeMode;
Chong Zhang3005e752015-09-18 18:46:28 -070082
Wale Ogunwaleb1faf602016-01-27 09:12:31 -080083 private boolean mHomeTask;
84
Jiaquan Hedd1e66f2016-06-15 15:15:12 -070085 // Whether this task is an on-top launcher task, which is determined by the root activity.
86 private boolean mIsOnTopLauncher;
87
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070088 Task(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds,
Andrii Kulian8072d112016-09-16 11:11:01 -070089 Configuration overrideConfig, boolean isOnTopLauncher) {
Craig Mautner83162a92015-01-26 14:43:30 -080090 mTaskId = taskId;
Craig Mautnerc00204b2013-03-05 15:02:14 -080091 mStack = stack;
Craig Mautnerac6f8432013-07-17 13:24:59 -070092 mUserId = userId;
Craig Mautnere3119b72015-01-20 15:02:36 -080093 mService = service;
Jiaquan Hedd1e66f2016-06-15 15:15:12 -070094 mIsOnTopLauncher = isOnTopLauncher;
Andrii Kulian8072d112016-09-16 11:11:01 -070095 setBounds(bounds, overrideConfig);
Craig Mautnerc00204b2013-03-05 15:02:14 -080096 }
97
98 DisplayContent getDisplayContent() {
99 return mStack.getDisplayContent();
100 }
101
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800102 void addAppToken(int addPos, AppWindowToken wtoken, int resizeMode, boolean homeTask) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700103 final int lastPos = mChildren.size();
Craig Mautner83162a92015-01-26 14:43:30 -0800104 if (addPos >= lastPos) {
105 addPos = lastPos;
106 } else {
107 for (int pos = 0; pos < lastPos && pos < addPos; ++pos) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700108 if (mChildren.get(pos).removed) {
Craig Mautner83162a92015-01-26 14:43:30 -0800109 // addPos assumes removed tokens are actually gone.
110 ++addPos;
111 }
Craig Mautner01f79cf2014-08-27 09:56:02 -0700112 }
Craig Mautner42bf39e2014-02-21 16:46:22 -0800113 }
Wale Ogunwalef6192862016-09-10 13:42:30 -0700114
Andrii Kulian441e4492016-09-29 15:25:00 -0700115 final WindowContainer parent = wtoken.getParent();
116 if (parent != null) {
117 parent.removeChild(wtoken);
Wale Ogunwalef6192862016-09-10 13:42:30 -0700118 }
119 addChild(wtoken, addPos);
Craig Mautner83162a92015-01-26 14:43:30 -0800120 wtoken.mTask = this;
Craig Mautner42bf39e2014-02-21 16:46:22 -0800121 mDeferRemoval = false;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800122 mResizeMode = resizeMode;
123 mHomeTask = homeTask;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800124 }
125
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700126 private boolean hasWindowsAlive() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700127 for (int i = mChildren.size() - 1; i >= 0; i--) {
128 if (mChildren.get(i).hasWindowsAlive()) {
Chong Zhang7e8eeb72016-01-06 19:14:47 -0800129 return true;
130 }
131 }
132 return false;
133 }
134
Wale Ogunwalef6192862016-09-10 13:42:30 -0700135 @Override
136 void removeIfPossible() {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700137 if (hasWindowsAlive() && mStack.isAnimating()) {
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800138 if (DEBUG_STACK) Slog.i(TAG, "removeTask: deferring removing taskId=" + mTaskId);
Craig Mautnere3119b72015-01-20 15:02:36 -0800139 mDeferRemoval = true;
140 return;
141 }
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800142 if (DEBUG_STACK) Slog.i(TAG, "removeTask: removing taskId=" + mTaskId);
Craig Mautner83162a92015-01-26 14:43:30 -0800143 EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "removeTask");
Craig Mautnere3119b72015-01-20 15:02:36 -0800144 mDeferRemoval = false;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700145 DisplayContent content = getDisplayContent();
146 if (content != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800147 content.mDimLayerController.removeDimLayerUser(this);
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700148 }
Andrii Kulian441e4492016-09-29 15:25:00 -0700149 getParent().removeChild(this);
Craig Mautner83162a92015-01-26 14:43:30 -0800150 mService.mTaskIdToTask.delete(mTaskId);
Craig Mautnere3119b72015-01-20 15:02:36 -0800151 }
152
Wale Ogunwalef6192862016-09-10 13:42:30 -0700153 // Change to use reparenting in WC when TaskStack is switched to use WC.
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800154 void moveTaskToStack(TaskStack stack, boolean toTop) {
155 if (stack == mStack) {
156 return;
157 }
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800158 if (DEBUG_STACK) Slog.i(TAG, "moveTaskToStack: removing taskId=" + mTaskId
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800159 + " from stack=" + mStack);
Wale Ogunwale000957c2015-04-03 08:19:12 -0700160 EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask");
Andrii Kulian441e4492016-09-29 15:25:00 -0700161 getParent().removeChild(this);
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800162 stack.addTask(this, toTop);
163 }
164
Andrii Kulian1779e612016-10-12 21:58:25 -0700165 void positionTaskInStack(TaskStack stack, int position, Rect bounds,
166 Configuration overrideConfig) {
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700167 if (mStack != null && stack != mStack) {
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800168 if (DEBUG_STACK) Slog.i(TAG, "positionTaskInStack: removing taskId=" + mTaskId
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700169 + " from stack=" + mStack);
170 EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask");
Wale Ogunwale14a3fb92016-09-11 15:19:05 -0700171 mStack.removeChild(this);
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700172 }
173 stack.positionTask(this, position, showForAllUsers());
Andrii Kulian1779e612016-10-12 21:58:25 -0700174 resizeLocked(bounds, overrideConfig, false /* force */);
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800175
Wale Ogunwalef6192862016-09-10 13:42:30 -0700176 for (int activityNdx = mChildren.size() - 1; activityNdx >= 0; --activityNdx) {
177 mChildren.get(activityNdx).notifyMovedInStack();
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800178 }
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700179 }
180
Wale Ogunwale14a3fb92016-09-11 15:19:05 -0700181 @Override
Wale Ogunwalef6192862016-09-10 13:42:30 -0700182 void removeChild(AppWindowToken token) {
183 if (!mChildren.contains(token)) {
184 Slog.e(TAG, "removeChild: token=" + this + " not found.");
185 return;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700186 }
187
Wale Ogunwalef6192862016-09-10 13:42:30 -0700188 super.removeChild(token);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700189
Wale Ogunwalef6192862016-09-10 13:42:30 -0700190 if (mChildren.isEmpty()) {
Jorim Jaggi0429f352015-12-22 16:29:16 +0100191 EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "removeAppToken: last token");
Craig Mautnere3119b72015-01-20 15:02:36 -0800192 if (mDeferRemoval) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700193 removeIfPossible();
Craig Mautnere3119b72015-01-20 15:02:36 -0800194 }
Craig Mautnerc00204b2013-03-05 15:02:14 -0800195 }
Wale Ogunwalef6192862016-09-10 13:42:30 -0700196 token.mTask = null;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800197 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800198
Craig Mautnercbd84af2014-10-22 13:21:22 -0700199 void setSendingToBottom(boolean toBottom) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700200 for (int appTokenNdx = 0; appTokenNdx < mChildren.size(); appTokenNdx++) {
201 mChildren.get(appTokenNdx).sendingToBottom = toBottom;
Craig Mautnercbd84af2014-10-22 13:21:22 -0700202 }
203 }
204
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700205 /** Set the task bounds. Passing in null sets the bounds to fullscreen. */
Andrii Kulian8072d112016-09-16 11:11:01 -0700206 private int setBounds(Rect bounds, Configuration overrideConfig) {
207 if (overrideConfig == null) {
208 overrideConfig = Configuration.EMPTY;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700209 }
Andrii Kulian8072d112016-09-16 11:11:01 -0700210 if (bounds == null && !Configuration.EMPTY.equals(overrideConfig)) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700211 throw new IllegalArgumentException("null bounds but non empty configuration: "
Andrii Kulian8072d112016-09-16 11:11:01 -0700212 + overrideConfig);
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700213 }
Andrii Kulian8072d112016-09-16 11:11:01 -0700214 if (bounds != null && Configuration.EMPTY.equals(overrideConfig)) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700215 throw new IllegalArgumentException("non null bounds, but empty configuration");
216 }
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700217 boolean oldFullscreen = mFillsParent;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700218 int rotation = Surface.ROTATION_0;
219 final DisplayContent displayContent = mStack.getDisplayContent();
220 if (displayContent != null) {
221 displayContent.getLogicalDisplayRect(mTmpRect);
222 rotation = displayContent.getDisplayInfo().rotation;
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700223 mFillsParent = bounds == null;
224 if (mFillsParent) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700225 bounds = mTmpRect;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700226 }
227 }
228
229 if (bounds == null) {
230 // Can't set to fullscreen if we don't have a display to get bounds from...
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700231 return BOUNDS_CHANGE_NONE;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700232 }
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700233 if (mBounds.equals(bounds) && oldFullscreen == mFillsParent && mRotation == rotation) {
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700234 return BOUNDS_CHANGE_NONE;
235 }
236
237 int boundsChange = BOUNDS_CHANGE_NONE;
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700238 if (mBounds.left != bounds.left || mBounds.top != bounds.top) {
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700239 boundsChange |= BOUNDS_CHANGE_POSITION;
240 }
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700241 if (mBounds.width() != bounds.width() || mBounds.height() != bounds.height()) {
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700242 boundsChange |= BOUNDS_CHANGE_SIZE;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700243 }
244
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700245 mBounds.set(bounds);
Chong Zhangf66db432016-01-13 10:39:51 -0800246
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700247 mRotation = rotation;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700248 if (displayContent != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800249 displayContent.mDimLayerController.updateDimLayer(this);
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700250 }
Andrii Kulian441e4492016-09-29 15:25:00 -0700251 onOverrideConfigurationChanged(mFillsParent ? Configuration.EMPTY : overrideConfig);
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700252 return boundsChange;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700253 }
254
Jorim Jaggidc249c42015-12-15 14:57:31 -0800255 /**
256 * Sets the bounds used to calculate the insets. See
257 * {@link android.app.IActivityManager#resizeDockedStack} why this is needed.
258 */
259 void setTempInsetBounds(Rect tempInsetBounds) {
260 if (tempInsetBounds != null) {
261 mTempInsetBounds.set(tempInsetBounds);
262 } else {
263 mTempInsetBounds.setEmpty();
264 }
265 }
266
267 /**
268 * Gets the bounds used to calculate the insets. See
269 * {@link android.app.IActivityManager#resizeDockedStack} why this is needed.
270 */
271 void getTempInsetBounds(Rect out) {
272 out.set(mTempInsetBounds);
273 }
274
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800275 void setResizeable(int resizeMode) {
276 mResizeMode = resizeMode;
Chong Zhangb15758a2015-11-17 12:12:03 -0800277 }
278
279 boolean isResizeable() {
Wale Ogunwaledf241e92016-10-13 15:14:21 -0700280 return ActivityInfo.isResizeableMode(mResizeMode) || mService.mForceResizableTasks;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800281 }
282
Jiaquan Hedd1e66f2016-06-15 15:15:12 -0700283 boolean isOnTopLauncher() {
284 return mIsOnTopLauncher;
285 }
286
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800287 boolean cropWindowsToStackBounds() {
Wale Ogunwaledf241e92016-10-13 15:14:21 -0700288 return isResizeable();
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800289 }
290
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800291 boolean isHomeTask() {
292 return mHomeTask;
293 }
294
Andrii Kulian8072d112016-09-16 11:11:01 -0700295 boolean resizeLocked(Rect bounds, Configuration overrideConfig, boolean forced) {
296 int boundsChanged = setBounds(bounds, overrideConfig);
Chong Zhang87b21722015-09-21 15:39:51 -0700297 if (forced) {
Chong Zhang3005e752015-09-18 18:46:28 -0700298 boundsChanged |= BOUNDS_CHANGE_SIZE;
Chong Zhang3005e752015-09-18 18:46:28 -0700299 }
300 if (boundsChanged == BOUNDS_CHANGE_NONE) {
301 return false;
302 }
303 if ((boundsChanged & BOUNDS_CHANGE_SIZE) == BOUNDS_CHANGE_SIZE) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700304 onResize();
Chong Zhangbd0d9372015-12-28 15:18:29 -0800305 } else {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700306 onMovedByResize();
Chong Zhang3005e752015-09-18 18:46:28 -0700307 }
308 return true;
309 }
310
Jorim Jaggi0429f352015-12-22 16:29:16 +0100311 /**
312 * Prepares the task bounds to be frozen with the current size. See
313 * {@link AppWindowToken#freezeBounds}.
314 */
315 void prepareFreezingBounds() {
316 mPreparedFrozenBounds.set(mBounds);
Andrii Kulian441e4492016-09-29 15:25:00 -0700317 mPreparedFrozenMergedConfig.setTo(getConfiguration());
Jorim Jaggi0429f352015-12-22 16:29:16 +0100318 }
319
Chong Zhang5117e272016-05-03 12:47:34 -0700320 /**
321 * Align the task to the adjusted bounds.
322 *
323 * @param adjustedBounds Adjusted bounds to which the task should be aligned.
324 * @param tempInsetBounds Insets bounds for the task.
325 * @param alignBottom True if the task's bottom should be aligned to the adjusted
326 * bounds's bottom; false if the task's top should be aligned
327 * the adjusted bounds's top.
328 */
Andrii Kulian441e4492016-09-29 15:25:00 -0700329 void alignToAdjustedBounds(Rect adjustedBounds, Rect tempInsetBounds, boolean alignBottom) {
330 final Configuration overrideConfig = getOverrideConfiguration();
331 if (!isResizeable() || Configuration.EMPTY.equals(overrideConfig)) {
Chong Zhang5117e272016-05-03 12:47:34 -0700332 return;
333 }
334
335 getBounds(mTmpRect2);
336 if (alignBottom) {
337 int offsetY = adjustedBounds.bottom - mTmpRect2.bottom;
338 mTmpRect2.offset(0, offsetY);
339 } else {
340 mTmpRect2.offsetTo(adjustedBounds.left, adjustedBounds.top);
341 }
342 setTempInsetBounds(tempInsetBounds);
Andrii Kulian441e4492016-09-29 15:25:00 -0700343 resizeLocked(mTmpRect2, overrideConfig, false /* forced */);
Chong Zhang5117e272016-05-03 12:47:34 -0700344 }
345
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700346 /** Return true if the current bound can get outputted to the rest of the system as-is. */
347 private boolean useCurrentBounds() {
348 final DisplayContent displayContent = mStack.getDisplayContent();
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700349 return mFillsParent
Wale Ogunwale3797c222015-10-27 14:21:58 -0700350 || !StackId.isTaskResizeableByDockedStack(mStack.mStackId)
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700351 || displayContent == null
Wale Ogunwalef6192862016-09-10 13:42:30 -0700352 || displayContent.getDockedStackVisibleForUserLocked() != null;
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700353 }
354
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800355 /** Original bounds of the task if applicable, otherwise fullscreen rect. */
Wale Ogunwaleccb6ce22016-01-14 15:36:35 -0800356 void getBounds(Rect out) {
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700357 if (useCurrentBounds()) {
358 // No need to adjust the output bounds if fullscreen or the docked stack is visible
359 // since it is already what we want to represent to the rest of the system.
360 out.set(mBounds);
361 return;
362 }
363
Wale Ogunwaleccb6ce22016-01-14 15:36:35 -0800364 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack is
365 // not currently visible. Go ahead a represent it as fullscreen to the rest of the system.
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700366 mStack.getDisplayContent().getLogicalDisplayRect(out);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700367 }
368
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800369 /**
370 * Calculate the maximum visible area of this task. If the task has only one app,
371 * the result will be visible frame of that app. If the task has more than one apps,
372 * we search from top down if the next app got different visible area.
373 *
374 * This effort is to handle the case where some task (eg. GMail composer) might pop up
375 * a dialog that's different in size from the activity below, in which case we should
376 * be dimming the entire task area behind the dialog.
377 *
378 * @param out Rect containing the max visible bounds.
379 * @return true if the task has some visible app windows; false otherwise.
380 */
381 boolean getMaxVisibleBounds(Rect out) {
382 boolean foundTop = false;
Wale Ogunwalef6192862016-09-10 13:42:30 -0700383 for (int i = mChildren.size() - 1; i >= 0; i--) {
384 final AppWindowToken token = mChildren.get(i);
Chong Zhangd8ceb852015-11-11 14:53:41 -0800385 // skip hidden (or about to hide) apps
386 if (token.mIsExiting || token.clientHidden || token.hiddenRequested) {
387 continue;
388 }
389 final WindowState win = token.findMainWindow();
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800390 if (win == null) {
391 continue;
392 }
393 if (!foundTop) {
394 out.set(win.mVisibleFrame);
395 foundTop = true;
396 continue;
397 }
398 if (win.mVisibleFrame.left < out.left) {
399 out.left = win.mVisibleFrame.left;
400 }
401 if (win.mVisibleFrame.top < out.top) {
402 out.top = win.mVisibleFrame.top;
403 }
404 if (win.mVisibleFrame.right > out.right) {
405 out.right = win.mVisibleFrame.right;
406 }
407 if (win.mVisibleFrame.bottom > out.bottom) {
408 out.bottom = win.mVisibleFrame.bottom;
409 }
410 }
411 return foundTop;
412 }
413
414 /** Bounds of the task to be used for dimming, as well as touch related tests. */
415 @Override
416 public void getDimBounds(Rect out) {
Robert Carra86a6bf2016-04-08 17:34:16 -0700417 final DisplayContent displayContent = mStack.getDisplayContent();
418 // It doesn't matter if we in particular are part of the resize, since we couldn't have
419 // a DimLayer anyway if we weren't visible.
Wale Ogunwalef6192862016-09-10 13:42:30 -0700420 final boolean dockedResizing = displayContent != null
421 && displayContent.mDividerControllerLocked.isResizing();
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800422 if (useCurrentBounds()) {
423 if (inFreeformWorkspace() && getMaxVisibleBounds(out)) {
424 return;
425 }
426
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700427 if (!mFillsParent) {
Jorim Jaggi22a869f2016-03-25 23:33:21 -0700428 // When minimizing the docked stack when going home, we don't adjust the task bounds
429 // so we need to intersect the task bounds with the stack bounds here.
Robert Carra86a6bf2016-04-08 17:34:16 -0700430 //
431 // If we are Docked Resizing with snap points, the task bounds could be smaller than the stack
432 // bounds and so we don't even want to use them. Even if the app should not be resized the Dim
433 // should keep up with the divider.
434 if (dockedResizing) {
435 mStack.getBounds(out);
436 } else {
437 mStack.getBounds(mTmpRect);
438 mTmpRect.intersect(mBounds);
439 }
Jorim Jaggi22a869f2016-03-25 23:33:21 -0700440 out.set(mTmpRect);
441 } else {
442 out.set(mBounds);
443 }
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800444 return;
445 }
446
Wale Ogunwalef6192862016-09-10 13:42:30 -0700447 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack is
448 // not currently visible. Go ahead a represent it as fullscreen to the rest of the system.
449 if (displayContent != null) {
450 displayContent.getLogicalDisplayRect(out);
451 }
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800452 }
453
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100454 void setDragResizing(boolean dragResizing, int dragResizeMode) {
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800455 if (mDragResizing != dragResizing) {
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100456 if (!DragResizeMode.isModeAllowedForStack(mStack.mStackId, dragResizeMode)) {
457 throw new IllegalArgumentException("Drag resize mode not allow for stack stackId="
458 + mStack.mStackId + " dragResizeMode=" + dragResizeMode);
459 }
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800460 mDragResizing = dragResizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100461 mDragResizeMode = dragResizeMode;
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800462 resetDragResizingChangeReported();
463 }
464 }
465
Chong Zhang3005e752015-09-18 18:46:28 -0700466 boolean isDragResizing() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700467 return mDragResizing;
Chong Zhang3005e752015-09-18 18:46:28 -0700468 }
469
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100470 int getDragResizeMode() {
471 return mDragResizeMode;
472 }
473
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700474 void updateDisplayInfo(final DisplayContent displayContent) {
475 if (displayContent == null) {
476 return;
477 }
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700478 if (mFillsParent) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700479 setBounds(null, Configuration.EMPTY);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700480 return;
481 }
482 final int newRotation = displayContent.getDisplayInfo().rotation;
483 if (mRotation == newRotation) {
484 return;
485 }
486
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800487 // Device rotation changed.
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700488 // - We don't want the task to move around on the screen when this happens, so update the
489 // task bounds so it stays in the same place.
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800490 // - Rotate the bounds and notify activity manager if the task can be resized independently
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700491 // from its stack. The stack will take care of task rotation for the other case.
492 mTmpRect2.set(mBounds);
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800493
494 if (!StackId.isTaskResizeAllowed(mStack.mStackId)) {
Andrii Kulian441e4492016-09-29 15:25:00 -0700495 setBounds(mTmpRect2, getOverrideConfiguration());
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800496 return;
497 }
498
Wale Ogunwale94744212015-09-21 19:01:47 -0700499 displayContent.rotateBounds(mRotation, newRotation, mTmpRect2);
Andrii Kulian441e4492016-09-29 15:25:00 -0700500 if (setBounds(mTmpRect2, getOverrideConfiguration()) != BOUNDS_CHANGE_NONE) {
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800501 // Post message to inform activity manager of the bounds change simulating a one-way
502 // call. We do this to prevent a deadlock between window manager lock and activity
503 // manager lock been held.
504 mService.mH.obtainMessage(RESIZE_TASK, mTaskId,
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700505 RESIZE_MODE_SYSTEM_SCREEN_ROTATION, mBounds).sendToTarget();
Wale Ogunwale1ed0d892015-09-28 13:27:44 -0700506 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700507 }
508
Wale Ogunwalef6192862016-09-10 13:42:30 -0700509 /** Cancels any running app transitions associated with the task. */
Winsonc28098f2015-10-30 14:50:19 -0700510 void cancelTaskWindowTransition() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700511 for (int i = mChildren.size() - 1; i >= 0; --i) {
512 mChildren.get(i).mAppAnimator.clearAnimation();
Winsonc28098f2015-10-30 14:50:19 -0700513 }
514 }
515
Wale Ogunwalef6192862016-09-10 13:42:30 -0700516 /** Cancels any running thumbnail transitions associated with the task. */
Winson13d30662015-11-06 15:30:29 -0800517 void cancelTaskThumbnailTransition() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700518 for (int i = mChildren.size() - 1; i >= 0; --i) {
519 mChildren.get(i).mAppAnimator.clearThumbnail();
Winson13d30662015-11-06 15:30:29 -0800520 }
521 }
522
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700523 boolean showForAllUsers() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700524 final int tokensCount = mChildren.size();
525 return (tokensCount != 0) && mChildren.get(tokensCount - 1).showForAllUsers;
Jorim Jaggiff71d202016-04-14 13:12:36 -0700526 }
527
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700528 boolean inHomeStack() {
529 return mStack != null && mStack.mStackId == HOME_STACK_ID;
530 }
531
Chong Zhang09b21ef2015-09-14 10:20:21 -0700532 boolean inFreeformWorkspace() {
533 return mStack != null && mStack.mStackId == FREEFORM_WORKSPACE_STACK_ID;
534 }
535
Robert Carr03138452016-05-18 14:53:16 -0700536 boolean inPinnedWorkspace() {
537 return mStack != null && mStack.mStackId == PINNED_STACK_ID;
538 }
539
Robert Carre6275582016-02-29 15:45:45 -0800540 boolean isFloating() {
541 return StackId.tasksAreFloating(mStack.mStackId);
542 }
543
Chong Zhangd8ceb852015-11-11 14:53:41 -0800544 WindowState getTopVisibleAppMainWindow() {
545 final AppWindowToken token = getTopVisibleAppToken();
546 return token != null ? token.findMainWindow() : null;
Chong Zhang9184ec62015-09-24 12:32:21 -0700547 }
548
Chong Zhangd8ceb852015-11-11 14:53:41 -0800549 AppWindowToken getTopVisibleAppToken() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700550 for (int i = mChildren.size() - 1; i >= 0; i--) {
551 final AppWindowToken token = mChildren.get(i);
Chong Zhangd8ceb852015-11-11 14:53:41 -0800552 // skip hidden (or about to hide) apps
553 if (!token.mIsExiting && !token.clientHidden && !token.hiddenRequested) {
554 return token;
555 }
556 }
557 return null;
Chong Zhangbef461f2015-10-27 11:38:24 -0700558 }
559
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800560 @Override
Wale Ogunwale29bfbb82016-05-12 15:13:52 -0700561 public boolean dimFullscreen() {
Wale Ogunwaledf241e92016-10-13 15:14:21 -0700562 return isFullscreen();
Wale Ogunwale29bfbb82016-05-12 15:13:52 -0700563 }
564
565 boolean isFullscreen() {
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700566 if (useCurrentBounds()) {
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700567 return mFillsParent;
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700568 }
569 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack
570 // is not currently visible. Go ahead a represent it as fullscreen to the rest of the
571 // system.
572 return true;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700573 }
574
575 @Override
576 public DisplayInfo getDisplayInfo() {
577 return mStack.getDisplayContent().getDisplayInfo();
578 }
579
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700580 void forceWindowsScaleable(boolean force) {
Robert Carr68e5c9e2016-09-14 10:50:09 -0700581 mService.openSurfaceTransaction();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700582 try {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700583 for (int i = mChildren.size() - 1; i >= 0; i--) {
584 mChildren.get(i).forceWindowsScaleableInTransaction(force);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700585 }
586 } finally {
Robert Carr68e5c9e2016-09-14 10:50:09 -0700587 mService.closeSurfaceTransaction();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700588 }
589 }
590
Wale Ogunwaleec731152016-09-08 20:18:57 -0700591 void getWindowOnDisplayBeforeToken(DisplayContent dc, WindowToken token,
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700592 DisplayContent.GetWindowOnDisplaySearchResult result) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700593 for (int i = mChildren.size() - 1; i >= 0; --i) {
594 final AppWindowToken current = mChildren.get(i);
Wale Ogunwaleec731152016-09-08 20:18:57 -0700595 if (current == token) {
596 // We have reach the token we are interested in. End search.
597 result.reachedToken = true;
598 return;
599 }
600
601 // We haven't reached the token yet; if this token is not going to the bottom and
602 // has windows on this display, then it is a candidate for what we are looking for.
603 final WindowList tokenWindowList = dc.getTokenWindowsOnDisplay(current);
604 if (!current.sendingToBottom && tokenWindowList.size() > 0) {
605 result.foundWindow = tokenWindowList.get(0);
606 }
607 }
608 }
609
610 void getWindowOnDisplayAfterToken(DisplayContent dc, WindowToken token,
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700611 DisplayContent.GetWindowOnDisplaySearchResult result) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700612 for (int i = mChildren.size() - 1; i >= 0; --i) {
613 final AppWindowToken current = mChildren.get(i);
Wale Ogunwaleec731152016-09-08 20:18:57 -0700614 if (!result.reachedToken) {
615 if (current == token) {
616 // We have reached the token we are interested in. Get whichever window occurs
617 // after it that is on the same display.
618 result.reachedToken = true;
619 }
620 continue;
621 }
622
623 final WindowList tokenWindowList = dc.getTokenWindowsOnDisplay(current);
624 if (tokenWindowList.size() > 0) {
625 result.foundWindow = tokenWindowList.get(tokenWindowList.size() - 1);
626 return;
627 }
628 }
629 }
630
Wale Ogunwalef6192862016-09-10 13:42:30 -0700631 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -0700632 boolean fillsParent() {
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700633 return mFillsParent || !StackId.isTaskResizeAllowed(mStack.mStackId);
Wale Ogunwale51362492016-09-08 17:49:17 -0700634 }
635
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700636 @Override
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800637 public String toString() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700638 return "{taskId=" + mTaskId + " appTokens=" + mChildren + " mdr=" + mDeferRemoval + "}";
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800639 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700640
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700641 String getName() {
642 return toShortString();
643 }
644
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700645 @Override
646 public String toShortString() {
647 return "Task=" + mTaskId;
648 }
649
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800650 public void dump(String prefix, PrintWriter pw) {
651 final String doublePrefix = prefix + " ";
652
653 pw.println(prefix + "taskId=" + mTaskId);
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700654 pw.println(doublePrefix + "mFillsParent=" + mFillsParent);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800655 pw.println(doublePrefix + "mBounds=" + mBounds.toShortString());
656 pw.println(doublePrefix + "mdr=" + mDeferRemoval);
Wale Ogunwalef6192862016-09-10 13:42:30 -0700657 pw.println(doublePrefix + "appTokens=" + mChildren);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800658 pw.println(doublePrefix + "mTempInsetBounds=" + mTempInsetBounds.toShortString());
659
660 final String triplePrefix = doublePrefix + " ";
661
Wale Ogunwalef6192862016-09-10 13:42:30 -0700662 for (int i = mChildren.size() - 1; i >= 0; i--) {
663 final AppWindowToken wtoken = mChildren.get(i);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800664 pw.println(triplePrefix + "Activity #" + i + " " + wtoken);
665 wtoken.dump(pw, triplePrefix);
666 }
667
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700668 }
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800669}