blob: da5fcf301c983e523ba7c088091346ca30316b5d [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;
skuhne@google.com322347b2016-12-02 12:54:03 -080022import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY;
23import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION;
24import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080025import static com.android.server.EventLogTags.WM_TASK_REMOVED;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080026import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
Andrii Kuliand2765632016-12-12 22:26:34 -080027import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_MOVEMENT;
Jorim Jaggid53f0922016-04-06 22:16:23 -070028import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
29import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwale99db1862015-10-23 20:08:22 -070030
Wale Ogunwale3797c222015-10-27 14:21:58 -070031import android.app.ActivityManager.StackId;
Jorim Jaggi829b9cd2017-01-23 16:20:53 +010032import android.app.ActivityManager.TaskDescription;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -080033import android.content.pm.ActivityInfo;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070034import android.content.res.Configuration;
35import android.graphics.Rect;
Craig Mautner2c2549c2013-11-12 08:31:15 -080036import android.util.EventLog;
Craig Mautner42bf39e2014-02-21 16:46:22 -080037import android.util.Slog;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070038import android.view.DisplayInfo;
39import android.view.Surface;
40
Wale Ogunwalec5cc3012017-01-13 13:26:16 -080041import com.android.internal.annotations.VisibleForTesting;
Craig Mautnere3119b72015-01-20 15:02:36 -080042import com.android.server.EventLogTags;
Craig Mautner2c2549c2013-11-12 08:31:15 -080043
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070044import java.io.PrintWriter;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070045
Wale Ogunwalef6192862016-09-10 13:42:30 -070046class Task extends WindowContainer<AppWindowToken> implements DimLayer.DimLayerUser {
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -080047 static final String TAG = TAG_WITH_CLASS_NAME ? "Task" : TAG_WM;
Wale Ogunwale2cc92f52015-09-09 13:12:10 -070048 // Return value from {@link setBounds} indicating no change was made to the Task bounds.
Wale Ogunwale3eadad72016-10-13 09:16:59 -070049 private static final int BOUNDS_CHANGE_NONE = 0;
Wale Ogunwale2cc92f52015-09-09 13:12:10 -070050 // Return value from {@link setBounds} indicating the position of the Task bounds changed.
Wale Ogunwale3eadad72016-10-13 09:16:59 -070051 private static final int BOUNDS_CHANGE_POSITION = 1;
Wale Ogunwale2cc92f52015-09-09 13:12:10 -070052 // Return value from {@link setBounds} indicating the size of the Task bounds changed.
Wale Ogunwale3eadad72016-10-13 09:16:59 -070053 private static final int BOUNDS_CHANGE_SIZE = 1 << 1;
Wale Ogunwale2cc92f52015-09-09 13:12:10 -070054
Wale Ogunwalef6192862016-09-10 13:42:30 -070055 // TODO: Track parent marks like this in WindowContainer.
Craig Mautnerc00204b2013-03-05 15:02:14 -080056 TaskStack mStack;
Craig Mautner83162a92015-01-26 14:43:30 -080057 final int mTaskId;
Craig Mautnerac6f8432013-07-17 13:24:59 -070058 final int mUserId;
Wale Ogunwale3eadad72016-10-13 09:16:59 -070059 private boolean mDeferRemoval = false;
Craig Mautnere3119b72015-01-20 15:02:36 -080060 final WindowManagerService mService;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080061
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070062 // Content limits relative to the DisplayContent this sits in.
63 private Rect mBounds = new Rect();
Jorim Jaggi0429f352015-12-22 16:29:16 +010064 final Rect mPreparedFrozenBounds = new Rect();
Jorim Jaggi26c8c422016-05-09 19:57:25 -070065 final Configuration mPreparedFrozenMergedConfig = new Configuration();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070066
Jorim Jaggidc249c42015-12-15 14:57:31 -080067 // Bounds used to calculate the insets.
68 private final Rect mTempInsetBounds = new Rect();
69
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070070 // Device rotation as of the last time {@link #mBounds} was set.
Wale Ogunwale3eadad72016-10-13 09:16:59 -070071 private int mRotation;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070072
73 // Whether mBounds is fullscreen
Wale Ogunwale5a2183d2016-09-19 12:26:13 -070074 private boolean mFillsParent = true;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070075
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070076 // For comparison with DisplayContent bounds.
77 private Rect mTmpRect = new Rect();
78 // For handling display rotations.
79 private Rect mTmpRect2 = new Rect();
80
Wale Ogunwaleb1faf602016-01-27 09:12:31 -080081 // Resize mode of the task. See {@link ActivityInfo#resizeMode}
82 private int mResizeMode;
Chong Zhangb15758a2015-11-17 12:12:03 -080083
Winson Chungd3395382016-12-13 11:49:09 -080084 // Whether the task supports picture-in-picture.
85 // See {@link ActivityInfo#FLAG_SUPPORTS_PICTURE_IN_PICTURE}
86 private boolean mSupportsPictureInPicture;
87
Chong Zhang3005e752015-09-18 18:46:28 -070088 // Whether the task is currently being drag-resized
89 private boolean mDragResizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +010090 private int mDragResizeMode;
Chong Zhang3005e752015-09-18 18:46:28 -070091
Wale Ogunwaleb1faf602016-01-27 09:12:31 -080092 private boolean mHomeTask;
93
Jorim Jaggi829b9cd2017-01-23 16:20:53 +010094 private TaskDescription mTaskDescription;
95
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -070096 Task(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds,
Wale Ogunwale069bbd32017-02-03 07:58:14 -080097 Configuration overrideConfig, int resizeMode, boolean supportsPictureInPicture,
98 boolean homeTask, TaskDescription taskDescription,
Winson Chungd3395382016-12-13 11:49:09 -080099 TaskWindowContainerController controller) {
Craig Mautner83162a92015-01-26 14:43:30 -0800100 mTaskId = taskId;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800101 mStack = stack;
Craig Mautnerac6f8432013-07-17 13:24:59 -0700102 mUserId = userId;
Craig Mautnere3119b72015-01-20 15:02:36 -0800103 mService = service;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800104 mResizeMode = resizeMode;
Winson Chungd3395382016-12-13 11:49:09 -0800105 mSupportsPictureInPicture = supportsPictureInPicture;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800106 mHomeTask = homeTask;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800107 setController(controller);
Andrii Kulian8072d112016-09-16 11:11:01 -0700108 setBounds(bounds, overrideConfig);
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100109 mTaskDescription = taskDescription;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800110 }
111
112 DisplayContent getDisplayContent() {
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800113 return mStack != null ? mStack.getDisplayContent() : null;
114 }
115
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800116 private int getAdjustedAddPosition(int suggestedPosition) {
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800117 final int size = mChildren.size();
118 if (suggestedPosition >= size) {
119 return Math.min(size, suggestedPosition);
120 }
121
122 for (int pos = 0; pos < size && pos < suggestedPosition; ++pos) {
123 // TODO: Confirm that this is the behavior we want long term.
124 if (mChildren.get(pos).removed) {
125 // suggestedPosition assumes removed tokens are actually gone.
126 ++suggestedPosition;
127 }
128 }
129 return Math.min(size, suggestedPosition);
Craig Mautnerc00204b2013-03-05 15:02:14 -0800130 }
131
Wale Ogunwale72919d22016-12-08 18:58:50 -0800132 @Override
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800133 void addChild(AppWindowToken wtoken, int position) {
134 position = getAdjustedAddPosition(position);
135 super.addChild(wtoken, position);
Craig Mautner83162a92015-01-26 14:43:30 -0800136 wtoken.mTask = this;
Craig Mautner42bf39e2014-02-21 16:46:22 -0800137 mDeferRemoval = false;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800138 }
139
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800140 @Override
141 void positionChildAt(int position, AppWindowToken child, boolean includingParents) {
142 position = getAdjustedAddPosition(position);
143 super.positionChildAt(position, child, includingParents);
144 mDeferRemoval = false;
145 }
146
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700147 private boolean hasWindowsAlive() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700148 for (int i = mChildren.size() - 1; i >= 0; i--) {
149 if (mChildren.get(i).hasWindowsAlive()) {
Chong Zhang7e8eeb72016-01-06 19:14:47 -0800150 return true;
151 }
152 }
153 return false;
154 }
155
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800156 @VisibleForTesting
157 boolean shouldDeferRemoval() {
158 return hasWindowsAlive() && mStack.isAnimating();
159 }
160
Wale Ogunwalef6192862016-09-10 13:42:30 -0700161 @Override
162 void removeIfPossible() {
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800163 if (shouldDeferRemoval()) {
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800164 if (DEBUG_STACK) Slog.i(TAG, "removeTask: deferring removing taskId=" + mTaskId);
Craig Mautnere3119b72015-01-20 15:02:36 -0800165 mDeferRemoval = true;
166 return;
167 }
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800168 removeImmediately();
169 }
170
171 @Override
172 void removeImmediately() {
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800173 if (DEBUG_STACK) Slog.i(TAG, "removeTask: removing taskId=" + mTaskId);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800174 EventLog.writeEvent(WM_TASK_REMOVED, mTaskId, "removeTask");
Craig Mautnere3119b72015-01-20 15:02:36 -0800175 mDeferRemoval = false;
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800176
177 // Make sure to remove dim layer user first before removing task its from parent.
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700178 DisplayContent content = getDisplayContent();
179 if (content != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800180 content.mDimLayerController.removeDimLayerUser(this);
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700181 }
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800182
183 super.removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800184 }
185
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800186 void reparent(TaskStack stack, int position) {
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800187 if (stack == mStack) {
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800188 throw new IllegalArgumentException(
189 "task=" + this + " already child of stack=" + mStack);
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800190 }
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800191 if (DEBUG_STACK) Slog.i(TAG, "reParentTask: removing taskId=" + mTaskId
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800192 + " from stack=" + mStack);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800193 EventLog.writeEvent(WM_TASK_REMOVED, mTaskId, "reParentTask");
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -0800194 final DisplayContent prevDisplayContent = getDisplayContent();
195
Andrii Kulian441e4492016-09-29 15:25:00 -0700196 getParent().removeChild(this);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800197 stack.addTask(this, position, showForAllUsers(), false /* moveParents */);
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -0800198
199 // Relayout display(s).
200 final DisplayContent displayContent = stack.getDisplayContent();
201 displayContent.setLayoutNeeded();
202 if (prevDisplayContent != displayContent) {
203 onDisplayChanged(displayContent);
204 prevDisplayContent.setLayoutNeeded();
205 }
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800206 }
207
Andrii Kuliand2765632016-12-12 22:26:34 -0800208 /** @see com.android.server.am.ActivityManagerService#positionTaskInStack(int, int, int). */
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800209 void positionAt(int position, Rect bounds, Configuration overrideConfig) {
210 mStack.positionChildAt(position, this, false /* includingParents */);
Andrii Kulian1779e612016-10-12 21:58:25 -0700211 resizeLocked(bounds, overrideConfig, false /* force */);
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800212
Wale Ogunwalef6192862016-09-10 13:42:30 -0700213 for (int activityNdx = mChildren.size() - 1; activityNdx >= 0; --activityNdx) {
214 mChildren.get(activityNdx).notifyMovedInStack();
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800215 }
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700216 }
217
Wale Ogunwale14a3fb92016-09-11 15:19:05 -0700218 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -0800219 void onParentSet() {
220 // Update task bounds if needed.
221 updateDisplayInfo(getDisplayContent());
222
223 if (StackId.windowsAreScaleable(mStack.mStackId)) {
224 // We force windows out of SCALING_MODE_FREEZE so that we can continue to animate them
225 // while a resize is pending.
226 forceWindowsScaleable(true /* force */);
227 } else {
228 forceWindowsScaleable(false /* force */);
229 }
230 }
231
232 @Override
Wale Ogunwalef6192862016-09-10 13:42:30 -0700233 void removeChild(AppWindowToken token) {
234 if (!mChildren.contains(token)) {
235 Slog.e(TAG, "removeChild: token=" + this + " not found.");
236 return;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700237 }
238
Wale Ogunwalef6192862016-09-10 13:42:30 -0700239 super.removeChild(token);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700240
Wale Ogunwalef6192862016-09-10 13:42:30 -0700241 if (mChildren.isEmpty()) {
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800242 EventLog.writeEvent(WM_TASK_REMOVED, mTaskId, "removeAppToken: last token");
Craig Mautnere3119b72015-01-20 15:02:36 -0800243 if (mDeferRemoval) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700244 removeIfPossible();
Craig Mautnere3119b72015-01-20 15:02:36 -0800245 }
Craig Mautnerc00204b2013-03-05 15:02:14 -0800246 }
Wale Ogunwalef6192862016-09-10 13:42:30 -0700247 token.mTask = null;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800248 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800249
Craig Mautnercbd84af2014-10-22 13:21:22 -0700250 void setSendingToBottom(boolean toBottom) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700251 for (int appTokenNdx = 0; appTokenNdx < mChildren.size(); appTokenNdx++) {
252 mChildren.get(appTokenNdx).sendingToBottom = toBottom;
Craig Mautnercbd84af2014-10-22 13:21:22 -0700253 }
254 }
255
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700256 /** Set the task bounds. Passing in null sets the bounds to fullscreen. */
Andrii Kulian8072d112016-09-16 11:11:01 -0700257 private int setBounds(Rect bounds, Configuration overrideConfig) {
258 if (overrideConfig == null) {
259 overrideConfig = Configuration.EMPTY;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700260 }
Andrii Kulian8072d112016-09-16 11:11:01 -0700261 if (bounds == null && !Configuration.EMPTY.equals(overrideConfig)) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700262 throw new IllegalArgumentException("null bounds but non empty configuration: "
Andrii Kulian8072d112016-09-16 11:11:01 -0700263 + overrideConfig);
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700264 }
Andrii Kulian8072d112016-09-16 11:11:01 -0700265 if (bounds != null && Configuration.EMPTY.equals(overrideConfig)) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700266 throw new IllegalArgumentException("non null bounds, but empty configuration");
267 }
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700268 boolean oldFullscreen = mFillsParent;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700269 int rotation = Surface.ROTATION_0;
270 final DisplayContent displayContent = mStack.getDisplayContent();
271 if (displayContent != null) {
272 displayContent.getLogicalDisplayRect(mTmpRect);
273 rotation = displayContent.getDisplayInfo().rotation;
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700274 mFillsParent = bounds == null;
275 if (mFillsParent) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700276 bounds = mTmpRect;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700277 }
278 }
279
280 if (bounds == null) {
281 // Can't set to fullscreen if we don't have a display to get bounds from...
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700282 return BOUNDS_CHANGE_NONE;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700283 }
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700284 if (mBounds.equals(bounds) && oldFullscreen == mFillsParent && mRotation == rotation) {
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700285 return BOUNDS_CHANGE_NONE;
286 }
287
288 int boundsChange = BOUNDS_CHANGE_NONE;
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700289 if (mBounds.left != bounds.left || mBounds.top != bounds.top) {
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700290 boundsChange |= BOUNDS_CHANGE_POSITION;
291 }
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700292 if (mBounds.width() != bounds.width() || mBounds.height() != bounds.height()) {
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700293 boundsChange |= BOUNDS_CHANGE_SIZE;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700294 }
295
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700296 mBounds.set(bounds);
Chong Zhangf66db432016-01-13 10:39:51 -0800297
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700298 mRotation = rotation;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700299 if (displayContent != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800300 displayContent.mDimLayerController.updateDimLayer(this);
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700301 }
Andrii Kulian441e4492016-09-29 15:25:00 -0700302 onOverrideConfigurationChanged(mFillsParent ? Configuration.EMPTY : overrideConfig);
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700303 return boundsChange;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700304 }
305
Jorim Jaggidc249c42015-12-15 14:57:31 -0800306 /**
307 * Sets the bounds used to calculate the insets. See
308 * {@link android.app.IActivityManager#resizeDockedStack} why this is needed.
309 */
310 void setTempInsetBounds(Rect tempInsetBounds) {
311 if (tempInsetBounds != null) {
312 mTempInsetBounds.set(tempInsetBounds);
313 } else {
314 mTempInsetBounds.setEmpty();
315 }
316 }
317
318 /**
319 * Gets the bounds used to calculate the insets. See
320 * {@link android.app.IActivityManager#resizeDockedStack} why this is needed.
321 */
322 void getTempInsetBounds(Rect out) {
323 out.set(mTempInsetBounds);
324 }
325
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800326 void setResizeable(int resizeMode) {
327 mResizeMode = resizeMode;
Chong Zhangb15758a2015-11-17 12:12:03 -0800328 }
329
330 boolean isResizeable() {
Winson Chungd3395382016-12-13 11:49:09 -0800331 return ActivityInfo.isResizeableMode(mResizeMode) || mSupportsPictureInPicture
332 || mService.mForceResizableTasks;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800333 }
334
skuhne@google.com322347b2016-12-02 12:54:03 -0800335 /**
336 * Tests if the orientation should be preserved upon user interactive resizig operations.
337
338 * @return true if orientation should not get changed upon resizing operation.
339 */
340 boolean preserveOrientationOnResize() {
341 return mResizeMode == RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY
342 || mResizeMode == RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY
343 || mResizeMode == RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION;
344 }
345
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800346 boolean cropWindowsToStackBounds() {
Wale Ogunwaledf241e92016-10-13 15:14:21 -0700347 return isResizeable();
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800348 }
349
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800350 boolean isHomeTask() {
351 return mHomeTask;
352 }
353
Andrii Kulian8072d112016-09-16 11:11:01 -0700354 boolean resizeLocked(Rect bounds, Configuration overrideConfig, boolean forced) {
355 int boundsChanged = setBounds(bounds, overrideConfig);
Chong Zhang87b21722015-09-21 15:39:51 -0700356 if (forced) {
Chong Zhang3005e752015-09-18 18:46:28 -0700357 boundsChanged |= BOUNDS_CHANGE_SIZE;
Chong Zhang3005e752015-09-18 18:46:28 -0700358 }
359 if (boundsChanged == BOUNDS_CHANGE_NONE) {
360 return false;
361 }
362 if ((boundsChanged & BOUNDS_CHANGE_SIZE) == BOUNDS_CHANGE_SIZE) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700363 onResize();
Chong Zhangbd0d9372015-12-28 15:18:29 -0800364 } else {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700365 onMovedByResize();
Chong Zhang3005e752015-09-18 18:46:28 -0700366 }
367 return true;
368 }
369
Jorim Jaggi0429f352015-12-22 16:29:16 +0100370 /**
371 * Prepares the task bounds to be frozen with the current size. See
372 * {@link AppWindowToken#freezeBounds}.
373 */
374 void prepareFreezingBounds() {
375 mPreparedFrozenBounds.set(mBounds);
Andrii Kulian441e4492016-09-29 15:25:00 -0700376 mPreparedFrozenMergedConfig.setTo(getConfiguration());
Jorim Jaggi0429f352015-12-22 16:29:16 +0100377 }
378
Chong Zhang5117e272016-05-03 12:47:34 -0700379 /**
380 * Align the task to the adjusted bounds.
381 *
382 * @param adjustedBounds Adjusted bounds to which the task should be aligned.
383 * @param tempInsetBounds Insets bounds for the task.
384 * @param alignBottom True if the task's bottom should be aligned to the adjusted
385 * bounds's bottom; false if the task's top should be aligned
386 * the adjusted bounds's top.
387 */
Andrii Kulian441e4492016-09-29 15:25:00 -0700388 void alignToAdjustedBounds(Rect adjustedBounds, Rect tempInsetBounds, boolean alignBottom) {
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700389 // Task override config might be empty, while display or stack override config isn't, so
390 // we have to check merged override config here.
391 if (!isResizeable() || Configuration.EMPTY.equals(getMergedOverrideConfiguration())) {
Chong Zhang5117e272016-05-03 12:47:34 -0700392 return;
393 }
394
395 getBounds(mTmpRect2);
396 if (alignBottom) {
397 int offsetY = adjustedBounds.bottom - mTmpRect2.bottom;
398 mTmpRect2.offset(0, offsetY);
399 } else {
400 mTmpRect2.offsetTo(adjustedBounds.left, adjustedBounds.top);
401 }
402 setTempInsetBounds(tempInsetBounds);
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700403 resizeLocked(mTmpRect2, getOverrideConfiguration(), false /* forced */);
Chong Zhang5117e272016-05-03 12:47:34 -0700404 }
405
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700406 /** Return true if the current bound can get outputted to the rest of the system as-is. */
407 private boolean useCurrentBounds() {
408 final DisplayContent displayContent = mStack.getDisplayContent();
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700409 return mFillsParent
Wale Ogunwale3797c222015-10-27 14:21:58 -0700410 || !StackId.isTaskResizeableByDockedStack(mStack.mStackId)
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700411 || displayContent == null
Jorim Jaggife762342016-10-13 14:33:27 +0200412 || displayContent.getDockedStackIgnoringVisibility() != null;
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700413 }
414
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800415 /** Original bounds of the task if applicable, otherwise fullscreen rect. */
Wale Ogunwaleccb6ce22016-01-14 15:36:35 -0800416 void getBounds(Rect out) {
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700417 if (useCurrentBounds()) {
418 // No need to adjust the output bounds if fullscreen or the docked stack is visible
419 // since it is already what we want to represent to the rest of the system.
420 out.set(mBounds);
421 return;
422 }
423
Wale Ogunwaleccb6ce22016-01-14 15:36:35 -0800424 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack is
425 // not currently visible. Go ahead a represent it as fullscreen to the rest of the system.
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700426 mStack.getDisplayContent().getLogicalDisplayRect(out);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700427 }
428
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800429 /**
430 * Calculate the maximum visible area of this task. If the task has only one app,
431 * the result will be visible frame of that app. If the task has more than one apps,
432 * we search from top down if the next app got different visible area.
433 *
434 * This effort is to handle the case where some task (eg. GMail composer) might pop up
435 * a dialog that's different in size from the activity below, in which case we should
436 * be dimming the entire task area behind the dialog.
437 *
438 * @param out Rect containing the max visible bounds.
439 * @return true if the task has some visible app windows; false otherwise.
440 */
441 boolean getMaxVisibleBounds(Rect out) {
442 boolean foundTop = false;
Wale Ogunwalef6192862016-09-10 13:42:30 -0700443 for (int i = mChildren.size() - 1; i >= 0; i--) {
444 final AppWindowToken token = mChildren.get(i);
Chong Zhangd8ceb852015-11-11 14:53:41 -0800445 // skip hidden (or about to hide) apps
446 if (token.mIsExiting || token.clientHidden || token.hiddenRequested) {
447 continue;
448 }
449 final WindowState win = token.findMainWindow();
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800450 if (win == null) {
451 continue;
452 }
453 if (!foundTop) {
454 out.set(win.mVisibleFrame);
455 foundTop = true;
456 continue;
457 }
458 if (win.mVisibleFrame.left < out.left) {
459 out.left = win.mVisibleFrame.left;
460 }
461 if (win.mVisibleFrame.top < out.top) {
462 out.top = win.mVisibleFrame.top;
463 }
464 if (win.mVisibleFrame.right > out.right) {
465 out.right = win.mVisibleFrame.right;
466 }
467 if (win.mVisibleFrame.bottom > out.bottom) {
468 out.bottom = win.mVisibleFrame.bottom;
469 }
470 }
471 return foundTop;
472 }
473
474 /** Bounds of the task to be used for dimming, as well as touch related tests. */
475 @Override
476 public void getDimBounds(Rect out) {
Robert Carra86a6bf2016-04-08 17:34:16 -0700477 final DisplayContent displayContent = mStack.getDisplayContent();
478 // It doesn't matter if we in particular are part of the resize, since we couldn't have
479 // a DimLayer anyway if we weren't visible.
Wale Ogunwalef6192862016-09-10 13:42:30 -0700480 final boolean dockedResizing = displayContent != null
481 && displayContent.mDividerControllerLocked.isResizing();
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800482 if (useCurrentBounds()) {
483 if (inFreeformWorkspace() && getMaxVisibleBounds(out)) {
484 return;
485 }
486
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700487 if (!mFillsParent) {
Jorim Jaggi22a869f2016-03-25 23:33:21 -0700488 // When minimizing the docked stack when going home, we don't adjust the task bounds
489 // so we need to intersect the task bounds with the stack bounds here.
Robert Carra86a6bf2016-04-08 17:34:16 -0700490 //
491 // If we are Docked Resizing with snap points, the task bounds could be smaller than the stack
492 // bounds and so we don't even want to use them. Even if the app should not be resized the Dim
493 // should keep up with the divider.
494 if (dockedResizing) {
495 mStack.getBounds(out);
496 } else {
497 mStack.getBounds(mTmpRect);
498 mTmpRect.intersect(mBounds);
499 }
Jorim Jaggi22a869f2016-03-25 23:33:21 -0700500 out.set(mTmpRect);
501 } else {
502 out.set(mBounds);
503 }
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800504 return;
505 }
506
Wale Ogunwalef6192862016-09-10 13:42:30 -0700507 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack is
508 // not currently visible. Go ahead a represent it as fullscreen to the rest of the system.
509 if (displayContent != null) {
510 displayContent.getLogicalDisplayRect(out);
511 }
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800512 }
513
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100514 void setDragResizing(boolean dragResizing, int dragResizeMode) {
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800515 if (mDragResizing != dragResizing) {
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100516 if (!DragResizeMode.isModeAllowedForStack(mStack.mStackId, dragResizeMode)) {
517 throw new IllegalArgumentException("Drag resize mode not allow for stack stackId="
518 + mStack.mStackId + " dragResizeMode=" + dragResizeMode);
519 }
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800520 mDragResizing = dragResizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100521 mDragResizeMode = dragResizeMode;
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800522 resetDragResizingChangeReported();
523 }
524 }
525
Chong Zhang3005e752015-09-18 18:46:28 -0700526 boolean isDragResizing() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700527 return mDragResizing;
Chong Zhang3005e752015-09-18 18:46:28 -0700528 }
529
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100530 int getDragResizeMode() {
531 return mDragResizeMode;
532 }
533
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700534 void updateDisplayInfo(final DisplayContent displayContent) {
535 if (displayContent == null) {
536 return;
537 }
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700538 if (mFillsParent) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700539 setBounds(null, Configuration.EMPTY);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700540 return;
541 }
542 final int newRotation = displayContent.getDisplayInfo().rotation;
543 if (mRotation == newRotation) {
544 return;
545 }
546
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800547 // Device rotation changed.
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700548 // - We don't want the task to move around on the screen when this happens, so update the
549 // task bounds so it stays in the same place.
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800550 // - Rotate the bounds and notify activity manager if the task can be resized independently
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700551 // from its stack. The stack will take care of task rotation for the other case.
552 mTmpRect2.set(mBounds);
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800553
554 if (!StackId.isTaskResizeAllowed(mStack.mStackId)) {
Andrii Kulian441e4492016-09-29 15:25:00 -0700555 setBounds(mTmpRect2, getOverrideConfiguration());
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800556 return;
557 }
558
Wale Ogunwale94744212015-09-21 19:01:47 -0700559 displayContent.rotateBounds(mRotation, newRotation, mTmpRect2);
Andrii Kulian441e4492016-09-29 15:25:00 -0700560 if (setBounds(mTmpRect2, getOverrideConfiguration()) != BOUNDS_CHANGE_NONE) {
Wale Ogunwale1666e312016-12-16 11:27:18 -0800561 final TaskWindowContainerController controller = getController();
562 if (controller != null) {
563 controller.requestResize(mBounds, RESIZE_MODE_SYSTEM_SCREEN_ROTATION);
564 }
Wale Ogunwale1ed0d892015-09-28 13:27:44 -0700565 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700566 }
567
Wale Ogunwalef6192862016-09-10 13:42:30 -0700568 /** Cancels any running app transitions associated with the task. */
Winsonc28098f2015-10-30 14:50:19 -0700569 void cancelTaskWindowTransition() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700570 for (int i = mChildren.size() - 1; i >= 0; --i) {
571 mChildren.get(i).mAppAnimator.clearAnimation();
Winsonc28098f2015-10-30 14:50:19 -0700572 }
573 }
574
Wale Ogunwalef6192862016-09-10 13:42:30 -0700575 /** Cancels any running thumbnail transitions associated with the task. */
Winson13d30662015-11-06 15:30:29 -0800576 void cancelTaskThumbnailTransition() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700577 for (int i = mChildren.size() - 1; i >= 0; --i) {
578 mChildren.get(i).mAppAnimator.clearThumbnail();
Winson13d30662015-11-06 15:30:29 -0800579 }
580 }
581
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700582 boolean showForAllUsers() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700583 final int tokensCount = mChildren.size();
Wale Ogunwale72919d22016-12-08 18:58:50 -0800584 return (tokensCount != 0) && mChildren.get(tokensCount - 1).mShowForAllUsers;
Jorim Jaggiff71d202016-04-14 13:12:36 -0700585 }
586
Chong Zhang09b21ef2015-09-14 10:20:21 -0700587 boolean inFreeformWorkspace() {
588 return mStack != null && mStack.mStackId == FREEFORM_WORKSPACE_STACK_ID;
589 }
590
Robert Carr03138452016-05-18 14:53:16 -0700591 boolean inPinnedWorkspace() {
592 return mStack != null && mStack.mStackId == PINNED_STACK_ID;
593 }
594
Robert Carr7e4c90e2017-02-15 19:52:38 -0800595 /**
596 * When we are in a floating stack (Freeform, Pinned, ...) we calculate
597 * insets differently. However if we are animating to the fullscreen stack
598 * we need to begin calculating insets as if we were fullscreen, otherwise
599 * we will have a jump at the end.
600 */
Robert Carre6275582016-02-29 15:45:45 -0800601 boolean isFloating() {
Robert Carr7e4c90e2017-02-15 19:52:38 -0800602 return StackId.tasksAreFloating(mStack.mStackId)
603 && !mStack.isBoundsAnimatingToFullscreen();
Robert Carre6275582016-02-29 15:45:45 -0800604 }
605
Chong Zhangd8ceb852015-11-11 14:53:41 -0800606 WindowState getTopVisibleAppMainWindow() {
607 final AppWindowToken token = getTopVisibleAppToken();
608 return token != null ? token.findMainWindow() : null;
Chong Zhang9184ec62015-09-24 12:32:21 -0700609 }
610
Chong Zhangd8ceb852015-11-11 14:53:41 -0800611 AppWindowToken getTopVisibleAppToken() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700612 for (int i = mChildren.size() - 1; i >= 0; i--) {
613 final AppWindowToken token = mChildren.get(i);
Chong Zhangd8ceb852015-11-11 14:53:41 -0800614 // skip hidden (or about to hide) apps
615 if (!token.mIsExiting && !token.clientHidden && !token.hiddenRequested) {
616 return token;
617 }
618 }
619 return null;
Chong Zhangbef461f2015-10-27 11:38:24 -0700620 }
621
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800622 @Override
Wale Ogunwale29bfbb82016-05-12 15:13:52 -0700623 public boolean dimFullscreen() {
Wale Ogunwaledf241e92016-10-13 15:14:21 -0700624 return isFullscreen();
Wale Ogunwale29bfbb82016-05-12 15:13:52 -0700625 }
626
627 boolean isFullscreen() {
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700628 if (useCurrentBounds()) {
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700629 return mFillsParent;
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700630 }
631 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack
632 // is not currently visible. Go ahead a represent it as fullscreen to the rest of the
633 // system.
634 return true;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700635 }
636
637 @Override
638 public DisplayInfo getDisplayInfo() {
Wale Ogunwalef0a60a92017-01-19 09:44:40 -0800639 return getDisplayContent().getDisplayInfo();
640 }
641
642 @Override
643 public boolean isAttachedToDisplay() {
644 return getDisplayContent() != null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700645 }
646
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700647 void forceWindowsScaleable(boolean force) {
Robert Carr68e5c9e2016-09-14 10:50:09 -0700648 mService.openSurfaceTransaction();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700649 try {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700650 for (int i = mChildren.size() - 1; i >= 0; i--) {
651 mChildren.get(i).forceWindowsScaleableInTransaction(force);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700652 }
653 } finally {
Robert Carr68e5c9e2016-09-14 10:50:09 -0700654 mService.closeSurfaceTransaction();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700655 }
656 }
657
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100658 void setTaskDescription(TaskDescription taskDescription) {
659 mTaskDescription = taskDescription;
660 }
661
662 TaskDescription getTaskDescription() {
663 return mTaskDescription;
664 }
665
Wale Ogunwalef6192862016-09-10 13:42:30 -0700666 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -0700667 boolean fillsParent() {
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700668 return mFillsParent || !StackId.isTaskResizeAllowed(mStack.mStackId);
Wale Ogunwale51362492016-09-08 17:49:17 -0700669 }
670
Jorim Jaggi329a5832017-01-05 18:57:12 +0100671 @Override
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100672 TaskWindowContainerController getController() {
673 return (TaskWindowContainerController) super.getController();
674 }
675
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700676 @Override
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800677 public String toString() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700678 return "{taskId=" + mTaskId + " appTokens=" + mChildren + " mdr=" + mDeferRemoval + "}";
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800679 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700680
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700681 String getName() {
682 return toShortString();
683 }
684
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700685 @Override
686 public String toShortString() {
687 return "Task=" + mTaskId;
688 }
689
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800690 public void dump(String prefix, PrintWriter pw) {
691 final String doublePrefix = prefix + " ";
692
693 pw.println(prefix + "taskId=" + mTaskId);
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700694 pw.println(doublePrefix + "mFillsParent=" + mFillsParent);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800695 pw.println(doublePrefix + "mBounds=" + mBounds.toShortString());
696 pw.println(doublePrefix + "mdr=" + mDeferRemoval);
Wale Ogunwalef6192862016-09-10 13:42:30 -0700697 pw.println(doublePrefix + "appTokens=" + mChildren);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800698 pw.println(doublePrefix + "mTempInsetBounds=" + mTempInsetBounds.toShortString());
699
700 final String triplePrefix = doublePrefix + " ";
701
Wale Ogunwalef6192862016-09-10 13:42:30 -0700702 for (int i = mChildren.size() - 1; i >= 0; i--) {
703 final AppWindowToken wtoken = mChildren.get(i);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800704 pw.println(triplePrefix + "Activity #" + i + " " + wtoken);
705 wtoken.dump(pw, triplePrefix);
706 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700707 }
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800708}