blob: 27661e2ef045005f7f19a05792f70d8a48e9d2bb [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;
Jason Monkba53d8a2017-04-06 18:28:19 +000020import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
Jorim Jaggi30d64f32017-04-07 16:33:17 +020021import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
skuhne@google.com322347b2016-12-02 12:54:03 -080022import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY;
Jason Monkba53d8a2017-04-06 18:28:19 +000023import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY;
Jorim Jaggi30d64f32017-04-07 16:33:17 +020024import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION;
Bryce Lee61fbcbc2017-03-10 14:14:03 -080025import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080026import static com.android.server.EventLogTags.WM_TASK_REMOVED;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080027import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
Jorim Jaggid53f0922016-04-06 22:16:23 -070028import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
29import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale 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 Mautner2c2549c2013-11-12 08:31:15 -080042
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070043import java.io.PrintWriter;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070044
Wale Ogunwalef6192862016-09-10 13:42:30 -070045class Task extends WindowContainer<AppWindowToken> implements DimLayer.DimLayerUser {
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -080046 static final String TAG = TAG_WITH_CLASS_NAME ? "Task" : TAG_WM;
Wale Ogunwale2cc92f52015-09-09 13:12:10 -070047 // Return value from {@link setBounds} indicating no change was made to the Task bounds.
Wale Ogunwale3eadad72016-10-13 09:16:59 -070048 private static final int BOUNDS_CHANGE_NONE = 0;
Wale Ogunwale2cc92f52015-09-09 13:12:10 -070049 // Return value from {@link setBounds} indicating the position of the Task bounds changed.
Wale Ogunwale3eadad72016-10-13 09:16:59 -070050 private static final int BOUNDS_CHANGE_POSITION = 1;
Wale Ogunwale2cc92f52015-09-09 13:12:10 -070051 // Return value from {@link setBounds} indicating the size of the Task bounds changed.
Wale Ogunwale3eadad72016-10-13 09:16:59 -070052 private static final int BOUNDS_CHANGE_SIZE = 1 << 1;
Wale Ogunwale2cc92f52015-09-09 13:12:10 -070053
Wale Ogunwalef6192862016-09-10 13:42:30 -070054 // TODO: Track parent marks like this in WindowContainer.
Craig Mautnerc00204b2013-03-05 15:02:14 -080055 TaskStack mStack;
Craig Mautner83162a92015-01-26 14:43:30 -080056 final int mTaskId;
Craig Mautnerac6f8432013-07-17 13:24:59 -070057 final int mUserId;
Wale Ogunwale3eadad72016-10-13 09:16:59 -070058 private boolean mDeferRemoval = false;
Craig Mautnere3119b72015-01-20 15:02:36 -080059 final WindowManagerService mService;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080060
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070061 // Content limits relative to the DisplayContent this sits in.
62 private Rect mBounds = new Rect();
Jorim Jaggi0429f352015-12-22 16:29:16 +010063 final Rect mPreparedFrozenBounds = new Rect();
Jorim Jaggi26c8c422016-05-09 19:57:25 -070064 final Configuration mPreparedFrozenMergedConfig = new Configuration();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070065
Jorim Jaggidc249c42015-12-15 14:57:31 -080066 // Bounds used to calculate the insets.
67 private final Rect mTempInsetBounds = new Rect();
68
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070069 // Device rotation as of the last time {@link #mBounds} was set.
Wale Ogunwale3eadad72016-10-13 09:16:59 -070070 private int mRotation;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070071
72 // Whether mBounds is fullscreen
Wale Ogunwale5a2183d2016-09-19 12:26:13 -070073 private boolean mFillsParent = true;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070074
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070075 // For comparison with DisplayContent bounds.
76 private Rect mTmpRect = new Rect();
77 // For handling display rotations.
78 private Rect mTmpRect2 = new Rect();
79
Wale Ogunwaleb1faf602016-01-27 09:12:31 -080080 // Resize mode of the task. See {@link ActivityInfo#resizeMode}
81 private int mResizeMode;
Chong Zhangb15758a2015-11-17 12:12:03 -080082
Winson Chungd3395382016-12-13 11:49:09 -080083 // Whether the task supports picture-in-picture.
84 // See {@link ActivityInfo#FLAG_SUPPORTS_PICTURE_IN_PICTURE}
85 private boolean mSupportsPictureInPicture;
86
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
Jorim Jaggi829b9cd2017-01-23 16:20:53 +010093 private TaskDescription mTaskDescription;
94
Robert Carr18f622f2017-05-08 11:20:43 -070095 // If set to true, the task will report that it is not in the floating
96 // state regardless of it's stack affilation. As the floating state drives
97 // production of content insets this can be used to preserve them across
98 // stack moves and we in fact do so when moving from full screen to pinned.
99 private boolean mPreserveNonFloatingState = false;
100
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700101 Task(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds,
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800102 Configuration overrideConfig, int resizeMode, boolean supportsPictureInPicture,
103 boolean homeTask, TaskDescription taskDescription,
Winson Chungd3395382016-12-13 11:49:09 -0800104 TaskWindowContainerController controller) {
Craig Mautner83162a92015-01-26 14:43:30 -0800105 mTaskId = taskId;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800106 mStack = stack;
Craig Mautnerac6f8432013-07-17 13:24:59 -0700107 mUserId = userId;
Craig Mautnere3119b72015-01-20 15:02:36 -0800108 mService = service;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800109 mResizeMode = resizeMode;
Winson Chungd3395382016-12-13 11:49:09 -0800110 mSupportsPictureInPicture = supportsPictureInPicture;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800111 mHomeTask = homeTask;
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800112 setController(controller);
Andrii Kulian8072d112016-09-16 11:11:01 -0700113 setBounds(bounds, overrideConfig);
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100114 mTaskDescription = taskDescription;
Bryce Lee61fbcbc2017-03-10 14:14:03 -0800115
116 // Tasks have no set orientation value (including SCREEN_ORIENTATION_UNSPECIFIED).
117 setOrientation(SCREEN_ORIENTATION_UNSET);
Craig Mautnerc00204b2013-03-05 15:02:14 -0800118 }
119
120 DisplayContent getDisplayContent() {
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800121 return mStack != null ? mStack.getDisplayContent() : null;
122 }
123
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800124 private int getAdjustedAddPosition(int suggestedPosition) {
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800125 final int size = mChildren.size();
126 if (suggestedPosition >= size) {
127 return Math.min(size, suggestedPosition);
128 }
129
130 for (int pos = 0; pos < size && pos < suggestedPosition; ++pos) {
131 // TODO: Confirm that this is the behavior we want long term.
132 if (mChildren.get(pos).removed) {
133 // suggestedPosition assumes removed tokens are actually gone.
134 ++suggestedPosition;
135 }
136 }
137 return Math.min(size, suggestedPosition);
Craig Mautnerc00204b2013-03-05 15:02:14 -0800138 }
139
Wale Ogunwale72919d22016-12-08 18:58:50 -0800140 @Override
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800141 void addChild(AppWindowToken wtoken, int position) {
142 position = getAdjustedAddPosition(position);
143 super.addChild(wtoken, position);
Craig Mautner42bf39e2014-02-21 16:46:22 -0800144 mDeferRemoval = false;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800145 }
146
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800147 @Override
148 void positionChildAt(int position, AppWindowToken child, boolean includingParents) {
149 position = getAdjustedAddPosition(position);
150 super.positionChildAt(position, child, includingParents);
151 mDeferRemoval = false;
152 }
153
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700154 private boolean hasWindowsAlive() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700155 for (int i = mChildren.size() - 1; i >= 0; i--) {
156 if (mChildren.get(i).hasWindowsAlive()) {
Chong Zhang7e8eeb72016-01-06 19:14:47 -0800157 return true;
158 }
159 }
160 return false;
161 }
162
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800163 @VisibleForTesting
164 boolean shouldDeferRemoval() {
165 return hasWindowsAlive() && mStack.isAnimating();
166 }
167
Wale Ogunwalef6192862016-09-10 13:42:30 -0700168 @Override
169 void removeIfPossible() {
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800170 if (shouldDeferRemoval()) {
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800171 if (DEBUG_STACK) Slog.i(TAG, "removeTask: deferring removing taskId=" + mTaskId);
Craig Mautnere3119b72015-01-20 15:02:36 -0800172 mDeferRemoval = true;
173 return;
174 }
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800175 removeImmediately();
176 }
177
178 @Override
179 void removeImmediately() {
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800180 if (DEBUG_STACK) Slog.i(TAG, "removeTask: removing taskId=" + mTaskId);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800181 EventLog.writeEvent(WM_TASK_REMOVED, mTaskId, "removeTask");
Craig Mautnere3119b72015-01-20 15:02:36 -0800182 mDeferRemoval = false;
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800183
184 // Make sure to remove dim layer user first before removing task its from parent.
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700185 DisplayContent content = getDisplayContent();
186 if (content != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800187 content.mDimLayerController.removeDimLayerUser(this);
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700188 }
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800189
190 super.removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800191 }
192
Wale Ogunwale2719cc12017-04-14 09:45:27 -0700193 void reparent(TaskStack stack, int position, boolean moveParents) {
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800194 if (stack == mStack) {
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800195 throw new IllegalArgumentException(
196 "task=" + this + " already child of stack=" + mStack);
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800197 }
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800198 if (DEBUG_STACK) Slog.i(TAG, "reParentTask: removing taskId=" + mTaskId
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800199 + " from stack=" + mStack);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800200 EventLog.writeEvent(WM_TASK_REMOVED, mTaskId, "reParentTask");
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -0800201 final DisplayContent prevDisplayContent = getDisplayContent();
202
Robert Carr18f622f2017-05-08 11:20:43 -0700203 // If we are moving from the fullscreen stack to the pinned stack
204 // then we want to preserve our insets so that there will not
205 // be a jump in the area covered by system decorations. We rely
206 // on the pinned animation to later unset this value.
207 if (stack.mStackId == PINNED_STACK_ID) {
208 mPreserveNonFloatingState = true;
209 } else {
210 mPreserveNonFloatingState = false;
211 }
212
Andrii Kulian441e4492016-09-29 15:25:00 -0700213 getParent().removeChild(this);
Wale Ogunwale2719cc12017-04-14 09:45:27 -0700214 stack.addTask(this, position, showForAllUsers(), moveParents);
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -0800215
216 // Relayout display(s).
217 final DisplayContent displayContent = stack.getDisplayContent();
218 displayContent.setLayoutNeeded();
219 if (prevDisplayContent != displayContent) {
220 onDisplayChanged(displayContent);
221 prevDisplayContent.setLayoutNeeded();
222 }
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800223 }
224
Andrii Kuliand2765632016-12-12 22:26:34 -0800225 /** @see com.android.server.am.ActivityManagerService#positionTaskInStack(int, int, int). */
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800226 void positionAt(int position, Rect bounds, Configuration overrideConfig) {
227 mStack.positionChildAt(position, this, false /* includingParents */);
Andrii Kulian1779e612016-10-12 21:58:25 -0700228 resizeLocked(bounds, overrideConfig, false /* force */);
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700229 }
230
Wale Ogunwale14a3fb92016-09-11 15:19:05 -0700231 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -0800232 void onParentSet() {
233 // Update task bounds if needed.
234 updateDisplayInfo(getDisplayContent());
235
236 if (StackId.windowsAreScaleable(mStack.mStackId)) {
237 // We force windows out of SCALING_MODE_FREEZE so that we can continue to animate them
238 // while a resize is pending.
239 forceWindowsScaleable(true /* force */);
240 } else {
241 forceWindowsScaleable(false /* force */);
242 }
243 }
244
245 @Override
Wale Ogunwalef6192862016-09-10 13:42:30 -0700246 void removeChild(AppWindowToken token) {
247 if (!mChildren.contains(token)) {
248 Slog.e(TAG, "removeChild: token=" + this + " not found.");
249 return;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700250 }
251
Wale Ogunwalef6192862016-09-10 13:42:30 -0700252 super.removeChild(token);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700253
Wale Ogunwalef6192862016-09-10 13:42:30 -0700254 if (mChildren.isEmpty()) {
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800255 EventLog.writeEvent(WM_TASK_REMOVED, mTaskId, "removeAppToken: last token");
Craig Mautnere3119b72015-01-20 15:02:36 -0800256 if (mDeferRemoval) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700257 removeIfPossible();
Craig Mautnere3119b72015-01-20 15:02:36 -0800258 }
Craig Mautnerc00204b2013-03-05 15:02:14 -0800259 }
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800260 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800261
Craig Mautnercbd84af2014-10-22 13:21:22 -0700262 void setSendingToBottom(boolean toBottom) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700263 for (int appTokenNdx = 0; appTokenNdx < mChildren.size(); appTokenNdx++) {
264 mChildren.get(appTokenNdx).sendingToBottom = toBottom;
Craig Mautnercbd84af2014-10-22 13:21:22 -0700265 }
266 }
267
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700268 /** Set the task bounds. Passing in null sets the bounds to fullscreen. */
Andrii Kulian8072d112016-09-16 11:11:01 -0700269 private int setBounds(Rect bounds, Configuration overrideConfig) {
270 if (overrideConfig == null) {
271 overrideConfig = Configuration.EMPTY;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700272 }
Andrii Kulian8072d112016-09-16 11:11:01 -0700273 if (bounds == null && !Configuration.EMPTY.equals(overrideConfig)) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700274 throw new IllegalArgumentException("null bounds but non empty configuration: "
Andrii Kulian8072d112016-09-16 11:11:01 -0700275 + overrideConfig);
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700276 }
Andrii Kulian8072d112016-09-16 11:11:01 -0700277 if (bounds != null && Configuration.EMPTY.equals(overrideConfig)) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700278 throw new IllegalArgumentException("non null bounds, but empty configuration");
279 }
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700280 boolean oldFullscreen = mFillsParent;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700281 int rotation = Surface.ROTATION_0;
282 final DisplayContent displayContent = mStack.getDisplayContent();
283 if (displayContent != null) {
284 displayContent.getLogicalDisplayRect(mTmpRect);
285 rotation = displayContent.getDisplayInfo().rotation;
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700286 mFillsParent = bounds == null;
287 if (mFillsParent) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700288 bounds = mTmpRect;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700289 }
290 }
291
292 if (bounds == null) {
293 // Can't set to fullscreen if we don't have a display to get bounds from...
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700294 return BOUNDS_CHANGE_NONE;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700295 }
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700296 if (mBounds.equals(bounds) && oldFullscreen == mFillsParent && mRotation == rotation) {
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700297 return BOUNDS_CHANGE_NONE;
298 }
299
300 int boundsChange = BOUNDS_CHANGE_NONE;
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700301 if (mBounds.left != bounds.left || mBounds.top != bounds.top) {
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700302 boundsChange |= BOUNDS_CHANGE_POSITION;
303 }
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700304 if (mBounds.width() != bounds.width() || mBounds.height() != bounds.height()) {
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700305 boundsChange |= BOUNDS_CHANGE_SIZE;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700306 }
307
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700308 mBounds.set(bounds);
Chong Zhangf66db432016-01-13 10:39:51 -0800309
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700310 mRotation = rotation;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700311 if (displayContent != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800312 displayContent.mDimLayerController.updateDimLayer(this);
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700313 }
Andrii Kulian441e4492016-09-29 15:25:00 -0700314 onOverrideConfigurationChanged(mFillsParent ? Configuration.EMPTY : overrideConfig);
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700315 return boundsChange;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700316 }
317
Jorim Jaggidc249c42015-12-15 14:57:31 -0800318 /**
319 * Sets the bounds used to calculate the insets. See
320 * {@link android.app.IActivityManager#resizeDockedStack} why this is needed.
321 */
322 void setTempInsetBounds(Rect tempInsetBounds) {
323 if (tempInsetBounds != null) {
324 mTempInsetBounds.set(tempInsetBounds);
325 } else {
326 mTempInsetBounds.setEmpty();
327 }
328 }
329
330 /**
331 * Gets the bounds used to calculate the insets. See
332 * {@link android.app.IActivityManager#resizeDockedStack} why this is needed.
333 */
334 void getTempInsetBounds(Rect out) {
335 out.set(mTempInsetBounds);
336 }
337
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800338 void setResizeable(int resizeMode) {
339 mResizeMode = resizeMode;
Chong Zhangb15758a2015-11-17 12:12:03 -0800340 }
341
342 boolean isResizeable() {
Winson Chungd3395382016-12-13 11:49:09 -0800343 return ActivityInfo.isResizeableMode(mResizeMode) || mSupportsPictureInPicture
344 || mService.mForceResizableTasks;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800345 }
346
skuhne@google.com322347b2016-12-02 12:54:03 -0800347 /**
348 * Tests if the orientation should be preserved upon user interactive resizig operations.
349
350 * @return true if orientation should not get changed upon resizing operation.
351 */
352 boolean preserveOrientationOnResize() {
353 return mResizeMode == RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY
354 || mResizeMode == RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY
355 || mResizeMode == RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION;
356 }
357
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800358 boolean cropWindowsToStackBounds() {
Wale Ogunwaledf241e92016-10-13 15:14:21 -0700359 return isResizeable();
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800360 }
361
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800362 boolean isHomeTask() {
363 return mHomeTask;
364 }
365
Andrii Kulian8072d112016-09-16 11:11:01 -0700366 boolean resizeLocked(Rect bounds, Configuration overrideConfig, boolean forced) {
367 int boundsChanged = setBounds(bounds, overrideConfig);
Chong Zhang87b21722015-09-21 15:39:51 -0700368 if (forced) {
Chong Zhang3005e752015-09-18 18:46:28 -0700369 boundsChanged |= BOUNDS_CHANGE_SIZE;
Chong Zhang3005e752015-09-18 18:46:28 -0700370 }
371 if (boundsChanged == BOUNDS_CHANGE_NONE) {
372 return false;
373 }
374 if ((boundsChanged & BOUNDS_CHANGE_SIZE) == BOUNDS_CHANGE_SIZE) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700375 onResize();
Chong Zhangbd0d9372015-12-28 15:18:29 -0800376 } else {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700377 onMovedByResize();
Chong Zhang3005e752015-09-18 18:46:28 -0700378 }
379 return true;
380 }
381
Jorim Jaggi0429f352015-12-22 16:29:16 +0100382 /**
383 * Prepares the task bounds to be frozen with the current size. See
384 * {@link AppWindowToken#freezeBounds}.
385 */
386 void prepareFreezingBounds() {
387 mPreparedFrozenBounds.set(mBounds);
Andrii Kulian441e4492016-09-29 15:25:00 -0700388 mPreparedFrozenMergedConfig.setTo(getConfiguration());
Jorim Jaggi0429f352015-12-22 16:29:16 +0100389 }
390
Chong Zhang5117e272016-05-03 12:47:34 -0700391 /**
392 * Align the task to the adjusted bounds.
393 *
394 * @param adjustedBounds Adjusted bounds to which the task should be aligned.
395 * @param tempInsetBounds Insets bounds for the task.
396 * @param alignBottom True if the task's bottom should be aligned to the adjusted
397 * bounds's bottom; false if the task's top should be aligned
398 * the adjusted bounds's top.
399 */
Andrii Kulian441e4492016-09-29 15:25:00 -0700400 void alignToAdjustedBounds(Rect adjustedBounds, Rect tempInsetBounds, boolean alignBottom) {
Andrii Kulian94251162017-04-26 11:07:52 -0700401 if (!isResizeable() || Configuration.EMPTY.equals(getOverrideConfiguration())) {
Chong Zhang5117e272016-05-03 12:47:34 -0700402 return;
403 }
404
405 getBounds(mTmpRect2);
406 if (alignBottom) {
407 int offsetY = adjustedBounds.bottom - mTmpRect2.bottom;
408 mTmpRect2.offset(0, offsetY);
409 } else {
410 mTmpRect2.offsetTo(adjustedBounds.left, adjustedBounds.top);
411 }
412 setTempInsetBounds(tempInsetBounds);
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700413 resizeLocked(mTmpRect2, getOverrideConfiguration(), false /* forced */);
Chong Zhang5117e272016-05-03 12:47:34 -0700414 }
415
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700416 /** Return true if the current bound can get outputted to the rest of the system as-is. */
417 private boolean useCurrentBounds() {
418 final DisplayContent displayContent = mStack.getDisplayContent();
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700419 return mFillsParent
Wale Ogunwale3797c222015-10-27 14:21:58 -0700420 || !StackId.isTaskResizeableByDockedStack(mStack.mStackId)
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700421 || displayContent == null
Jorim Jaggife762342016-10-13 14:33:27 +0200422 || displayContent.getDockedStackIgnoringVisibility() != null;
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700423 }
424
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800425 /** Original bounds of the task if applicable, otherwise fullscreen rect. */
Wale Ogunwaleccb6ce22016-01-14 15:36:35 -0800426 void getBounds(Rect out) {
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700427 if (useCurrentBounds()) {
428 // No need to adjust the output bounds if fullscreen or the docked stack is visible
429 // since it is already what we want to represent to the rest of the system.
430 out.set(mBounds);
431 return;
432 }
433
Wale Ogunwaleccb6ce22016-01-14 15:36:35 -0800434 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack is
435 // not currently visible. Go ahead a represent it as fullscreen to the rest of the system.
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700436 mStack.getDisplayContent().getLogicalDisplayRect(out);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700437 }
438
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800439 /**
440 * Calculate the maximum visible area of this task. If the task has only one app,
441 * the result will be visible frame of that app. If the task has more than one apps,
442 * we search from top down if the next app got different visible area.
443 *
444 * This effort is to handle the case where some task (eg. GMail composer) might pop up
445 * a dialog that's different in size from the activity below, in which case we should
446 * be dimming the entire task area behind the dialog.
447 *
448 * @param out Rect containing the max visible bounds.
449 * @return true if the task has some visible app windows; false otherwise.
450 */
451 boolean getMaxVisibleBounds(Rect out) {
452 boolean foundTop = false;
Wale Ogunwalef6192862016-09-10 13:42:30 -0700453 for (int i = mChildren.size() - 1; i >= 0; i--) {
454 final AppWindowToken token = mChildren.get(i);
Chong Zhangd8ceb852015-11-11 14:53:41 -0800455 // skip hidden (or about to hide) apps
Wale Ogunwale89973222017-04-23 18:39:45 -0700456 if (token.mIsExiting || token.isClientHidden() || token.hiddenRequested) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800457 continue;
458 }
459 final WindowState win = token.findMainWindow();
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800460 if (win == null) {
461 continue;
462 }
463 if (!foundTop) {
464 out.set(win.mVisibleFrame);
465 foundTop = true;
466 continue;
467 }
468 if (win.mVisibleFrame.left < out.left) {
469 out.left = win.mVisibleFrame.left;
470 }
471 if (win.mVisibleFrame.top < out.top) {
472 out.top = win.mVisibleFrame.top;
473 }
474 if (win.mVisibleFrame.right > out.right) {
475 out.right = win.mVisibleFrame.right;
476 }
477 if (win.mVisibleFrame.bottom > out.bottom) {
478 out.bottom = win.mVisibleFrame.bottom;
479 }
480 }
481 return foundTop;
482 }
483
484 /** Bounds of the task to be used for dimming, as well as touch related tests. */
485 @Override
486 public void getDimBounds(Rect out) {
Robert Carra86a6bf2016-04-08 17:34:16 -0700487 final DisplayContent displayContent = mStack.getDisplayContent();
488 // It doesn't matter if we in particular are part of the resize, since we couldn't have
489 // a DimLayer anyway if we weren't visible.
Wale Ogunwalef6192862016-09-10 13:42:30 -0700490 final boolean dockedResizing = displayContent != null
491 && displayContent.mDividerControllerLocked.isResizing();
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800492 if (useCurrentBounds()) {
493 if (inFreeformWorkspace() && getMaxVisibleBounds(out)) {
494 return;
495 }
496
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700497 if (!mFillsParent) {
Jorim Jaggi22a869f2016-03-25 23:33:21 -0700498 // When minimizing the docked stack when going home, we don't adjust the task bounds
499 // so we need to intersect the task bounds with the stack bounds here.
Robert Carra86a6bf2016-04-08 17:34:16 -0700500 //
501 // If we are Docked Resizing with snap points, the task bounds could be smaller than the stack
502 // bounds and so we don't even want to use them. Even if the app should not be resized the Dim
503 // should keep up with the divider.
504 if (dockedResizing) {
505 mStack.getBounds(out);
506 } else {
507 mStack.getBounds(mTmpRect);
508 mTmpRect.intersect(mBounds);
509 }
Jorim Jaggi22a869f2016-03-25 23:33:21 -0700510 out.set(mTmpRect);
511 } else {
512 out.set(mBounds);
513 }
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800514 return;
515 }
516
Wale Ogunwalef6192862016-09-10 13:42:30 -0700517 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack is
518 // not currently visible. Go ahead a represent it as fullscreen to the rest of the system.
519 if (displayContent != null) {
520 displayContent.getLogicalDisplayRect(out);
521 }
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800522 }
523
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100524 void setDragResizing(boolean dragResizing, int dragResizeMode) {
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800525 if (mDragResizing != dragResizing) {
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100526 if (!DragResizeMode.isModeAllowedForStack(mStack.mStackId, dragResizeMode)) {
527 throw new IllegalArgumentException("Drag resize mode not allow for stack stackId="
528 + mStack.mStackId + " dragResizeMode=" + dragResizeMode);
529 }
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800530 mDragResizing = dragResizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100531 mDragResizeMode = dragResizeMode;
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800532 resetDragResizingChangeReported();
533 }
534 }
535
Chong Zhang3005e752015-09-18 18:46:28 -0700536 boolean isDragResizing() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700537 return mDragResizing;
Chong Zhang3005e752015-09-18 18:46:28 -0700538 }
539
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100540 int getDragResizeMode() {
541 return mDragResizeMode;
542 }
543
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700544 void updateDisplayInfo(final DisplayContent displayContent) {
545 if (displayContent == null) {
546 return;
547 }
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700548 if (mFillsParent) {
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700549 setBounds(null, Configuration.EMPTY);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700550 return;
551 }
552 final int newRotation = displayContent.getDisplayInfo().rotation;
553 if (mRotation == newRotation) {
554 return;
555 }
556
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800557 // Device rotation changed.
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700558 // - We don't want the task to move around on the screen when this happens, so update the
559 // task bounds so it stays in the same place.
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800560 // - Rotate the bounds and notify activity manager if the task can be resized independently
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700561 // from its stack. The stack will take care of task rotation for the other case.
562 mTmpRect2.set(mBounds);
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800563
564 if (!StackId.isTaskResizeAllowed(mStack.mStackId)) {
Andrii Kulian441e4492016-09-29 15:25:00 -0700565 setBounds(mTmpRect2, getOverrideConfiguration());
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800566 return;
567 }
568
Wale Ogunwale94744212015-09-21 19:01:47 -0700569 displayContent.rotateBounds(mRotation, newRotation, mTmpRect2);
Andrii Kulian441e4492016-09-29 15:25:00 -0700570 if (setBounds(mTmpRect2, getOverrideConfiguration()) != BOUNDS_CHANGE_NONE) {
Wale Ogunwale1666e312016-12-16 11:27:18 -0800571 final TaskWindowContainerController controller = getController();
572 if (controller != null) {
573 controller.requestResize(mBounds, RESIZE_MODE_SYSTEM_SCREEN_ROTATION);
574 }
Wale Ogunwale1ed0d892015-09-28 13:27:44 -0700575 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700576 }
577
Wale Ogunwalef6192862016-09-10 13:42:30 -0700578 /** Cancels any running app transitions associated with the task. */
Winsonc28098f2015-10-30 14:50:19 -0700579 void cancelTaskWindowTransition() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700580 for (int i = mChildren.size() - 1; i >= 0; --i) {
581 mChildren.get(i).mAppAnimator.clearAnimation();
Winsonc28098f2015-10-30 14:50:19 -0700582 }
583 }
584
Wale Ogunwalef6192862016-09-10 13:42:30 -0700585 /** Cancels any running thumbnail transitions associated with the task. */
Winson13d30662015-11-06 15:30:29 -0800586 void cancelTaskThumbnailTransition() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700587 for (int i = mChildren.size() - 1; i >= 0; --i) {
588 mChildren.get(i).mAppAnimator.clearThumbnail();
Winson13d30662015-11-06 15:30:29 -0800589 }
590 }
591
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700592 boolean showForAllUsers() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700593 final int tokensCount = mChildren.size();
Wale Ogunwale72919d22016-12-08 18:58:50 -0800594 return (tokensCount != 0) && mChildren.get(tokensCount - 1).mShowForAllUsers;
Jorim Jaggiff71d202016-04-14 13:12:36 -0700595 }
596
Chong Zhang09b21ef2015-09-14 10:20:21 -0700597 boolean inFreeformWorkspace() {
598 return mStack != null && mStack.mStackId == FREEFORM_WORKSPACE_STACK_ID;
599 }
600
Robert Carr03138452016-05-18 14:53:16 -0700601 boolean inPinnedWorkspace() {
602 return mStack != null && mStack.mStackId == PINNED_STACK_ID;
603 }
604
Robert Carr7e4c90e2017-02-15 19:52:38 -0800605 /**
606 * When we are in a floating stack (Freeform, Pinned, ...) we calculate
607 * insets differently. However if we are animating to the fullscreen stack
608 * we need to begin calculating insets as if we were fullscreen, otherwise
609 * we will have a jump at the end.
610 */
Robert Carre6275582016-02-29 15:45:45 -0800611 boolean isFloating() {
Robert Carr18f622f2017-05-08 11:20:43 -0700612 return StackId.tasksAreFloating(mStack.mStackId)
613 && !mStack.isAnimatingBoundsToFullscreen() && !mPreserveNonFloatingState;
Robert Carre6275582016-02-29 15:45:45 -0800614 }
615
Chong Zhangd8ceb852015-11-11 14:53:41 -0800616 WindowState getTopVisibleAppMainWindow() {
617 final AppWindowToken token = getTopVisibleAppToken();
618 return token != null ? token.findMainWindow() : null;
Chong Zhang9184ec62015-09-24 12:32:21 -0700619 }
620
Chong Zhangd8ceb852015-11-11 14:53:41 -0800621 AppWindowToken getTopVisibleAppToken() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700622 for (int i = mChildren.size() - 1; i >= 0; i--) {
623 final AppWindowToken token = mChildren.get(i);
Chong Zhangd8ceb852015-11-11 14:53:41 -0800624 // skip hidden (or about to hide) apps
Wale Ogunwale89973222017-04-23 18:39:45 -0700625 if (!token.mIsExiting && !token.isClientHidden() && !token.hiddenRequested) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800626 return token;
627 }
628 }
629 return null;
Chong Zhangbef461f2015-10-27 11:38:24 -0700630 }
631
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800632 @Override
Wale Ogunwale29bfbb82016-05-12 15:13:52 -0700633 public boolean dimFullscreen() {
Wale Ogunwaledf241e92016-10-13 15:14:21 -0700634 return isFullscreen();
Wale Ogunwale29bfbb82016-05-12 15:13:52 -0700635 }
636
637 boolean isFullscreen() {
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700638 if (useCurrentBounds()) {
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700639 return mFillsParent;
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700640 }
641 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack
642 // is not currently visible. Go ahead a represent it as fullscreen to the rest of the
643 // system.
644 return true;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700645 }
646
647 @Override
648 public DisplayInfo getDisplayInfo() {
Wale Ogunwalef0a60a92017-01-19 09:44:40 -0800649 return getDisplayContent().getDisplayInfo();
650 }
651
652 @Override
653 public boolean isAttachedToDisplay() {
654 return getDisplayContent() != null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700655 }
656
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700657 void forceWindowsScaleable(boolean force) {
Robert Carr68e5c9e2016-09-14 10:50:09 -0700658 mService.openSurfaceTransaction();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700659 try {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700660 for (int i = mChildren.size() - 1; i >= 0; i--) {
661 mChildren.get(i).forceWindowsScaleableInTransaction(force);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700662 }
663 } finally {
Robert Carr68e5c9e2016-09-14 10:50:09 -0700664 mService.closeSurfaceTransaction();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700665 }
666 }
667
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100668 void setTaskDescription(TaskDescription taskDescription) {
669 mTaskDescription = taskDescription;
670 }
671
672 TaskDescription getTaskDescription() {
673 return mTaskDescription;
674 }
675
Wale Ogunwalef6192862016-09-10 13:42:30 -0700676 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -0700677 boolean fillsParent() {
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700678 return mFillsParent || !StackId.isTaskResizeAllowed(mStack.mStackId);
Wale Ogunwale51362492016-09-08 17:49:17 -0700679 }
680
Jorim Jaggi329a5832017-01-05 18:57:12 +0100681 @Override
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100682 TaskWindowContainerController getController() {
683 return (TaskWindowContainerController) super.getController();
684 }
685
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700686 @Override
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800687 public String toString() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700688 return "{taskId=" + mTaskId + " appTokens=" + mChildren + " mdr=" + mDeferRemoval + "}";
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800689 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700690
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700691 String getName() {
692 return toShortString();
693 }
694
Robert Carr18f622f2017-05-08 11:20:43 -0700695 void clearPreserveNonFloatingState() {
696 mPreserveNonFloatingState = false;
697 }
698
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700699 @Override
700 public String toShortString() {
701 return "Task=" + mTaskId;
702 }
703
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800704 public void dump(String prefix, PrintWriter pw) {
705 final String doublePrefix = prefix + " ";
706
707 pw.println(prefix + "taskId=" + mTaskId);
Wale Ogunwale5a2183d2016-09-19 12:26:13 -0700708 pw.println(doublePrefix + "mFillsParent=" + mFillsParent);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800709 pw.println(doublePrefix + "mBounds=" + mBounds.toShortString());
710 pw.println(doublePrefix + "mdr=" + mDeferRemoval);
Wale Ogunwalef6192862016-09-10 13:42:30 -0700711 pw.println(doublePrefix + "appTokens=" + mChildren);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800712 pw.println(doublePrefix + "mTempInsetBounds=" + mTempInsetBounds.toShortString());
713
714 final String triplePrefix = doublePrefix + " ";
715
Wale Ogunwalef6192862016-09-10 13:42:30 -0700716 for (int i = mChildren.size() - 1; i >= 0; i--) {
717 final AppWindowToken wtoken = mChildren.get(i);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800718 pw.println(triplePrefix + "Activity #" + i + " " + wtoken);
719 wtoken.dump(pw, triplePrefix);
720 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700721 }
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800722}