blob: 69d9810dd2070cc1818876a161135fdee04e3a10 [file] [log] [blame]
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Wale Ogunwale65ebd952018-04-25 15:41:44 -070019import static android.app.ActivityTaskManager.RESIZE_MODE_SYSTEM_SCREEN_ROTATION;
skuhne@google.com322347b2016-12-02 12:54:03 -080020import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY;
Jason Monkba53d8a2017-04-06 18:28:19 +000021import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY;
Jorim Jaggi30d64f32017-04-07 16:33:17 +020022import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION;
Bryce Lee61fbcbc2017-03-10 14:14:03 -080023import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Wale Ogunwale68278562017-09-23 17:13:55 -070024import static android.content.res.Configuration.EMPTY;
chaviw8c9d1f52018-07-25 14:56:07 -070025
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -080026import static com.android.server.EventLogTags.WM_TASK_REMOVED;
Yunfan Chen0e7aff92018-12-05 16:35:32 -080027import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
Yi Jin6c6e9ca2018-03-20 16:53:35 -070028import static com.android.server.wm.TaskProto.APP_WINDOW_TOKENS;
29import static com.android.server.wm.TaskProto.BOUNDS;
30import static com.android.server.wm.TaskProto.DEFER_REMOVAL;
Evan Roskyed6767f2018-10-26 17:21:06 -070031import static com.android.server.wm.TaskProto.DISPLAYED_BOUNDS;
Yi Jin6c6e9ca2018-03-20 16:53:35 -070032import static com.android.server.wm.TaskProto.FILLS_PARENT;
33import static com.android.server.wm.TaskProto.ID;
Louis Chang7501e332018-08-20 13:08:39 +080034import static com.android.server.wm.TaskProto.SURFACE_HEIGHT;
35import static com.android.server.wm.TaskProto.SURFACE_WIDTH;
Yi Jin6c6e9ca2018-03-20 16:53:35 -070036import static com.android.server.wm.TaskProto.WINDOW_CONTAINER;
chaviw8c9d1f52018-07-25 14:56:07 -070037import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
38import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
39import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwale99db1862015-10-23 20:08:22 -070040
Wale Ogunwale0d5609b2017-09-13 05:55:07 -070041import android.annotation.CallSuper;
Yunfan Chen0e7aff92018-12-05 16:35:32 -080042import android.app.ActivityManager;
Jorim Jaggi829b9cd2017-01-23 16:20:53 +010043import android.app.ActivityManager.TaskDescription;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -080044import android.content.pm.ActivityInfo;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070045import android.content.res.Configuration;
46import android.graphics.Rect;
Craig Mautner2c2549c2013-11-12 08:31:15 -080047import android.util.EventLog;
Craig Mautner42bf39e2014-02-21 16:46:22 -080048import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -070049import android.util.proto.ProtoOutputStream;
Garfield Tandec96db2018-10-30 11:28:49 -070050import android.view.Display;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070051import android.view.Surface;
Winson Chungd41f71d2018-03-16 15:26:07 -070052import android.view.SurfaceControl;
chaviw8c9d1f52018-07-25 14:56:07 -070053
Wale Ogunwalec5cc3012017-01-13 13:26:16 -080054import com.android.internal.annotations.VisibleForTesting;
Craig Mautner2c2549c2013-11-12 08:31:15 -080055
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070056import java.io.PrintWriter;
Jorim Jaggi51304d72017-05-17 17:25:32 +020057import java.util.function.Consumer;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070058
Yunfan Chen0e7aff92018-12-05 16:35:32 -080059class Task extends WindowContainer<AppWindowToken> implements ConfigurationContainerListener{
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -080060 static final String TAG = TAG_WITH_CLASS_NAME ? "Task" : TAG_WM;
Wale Ogunwale2cc92f52015-09-09 13:12:10 -070061
Wale Ogunwalef6192862016-09-10 13:42:30 -070062 // TODO: Track parent marks like this in WindowContainer.
Craig Mautnerc00204b2013-03-05 15:02:14 -080063 TaskStack mStack;
Craig Mautner83162a92015-01-26 14:43:30 -080064 final int mTaskId;
Craig Mautnerac6f8432013-07-17 13:24:59 -070065 final int mUserId;
Wale Ogunwale3eadad72016-10-13 09:16:59 -070066 private boolean mDeferRemoval = false;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080067
Jorim Jaggi0429f352015-12-22 16:29:16 +010068 final Rect mPreparedFrozenBounds = new Rect();
Jorim Jaggi26c8c422016-05-09 19:57:25 -070069 final Configuration mPreparedFrozenMergedConfig = new Configuration();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070070
Evan Roskyed6767f2018-10-26 17:21:06 -070071 // If non-empty, bounds used to display the task during animations/interactions.
72 private final Rect mOverrideDisplayedBounds = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -080073
Garfield Tandec96db2018-10-30 11:28:49 -070074 /** ID of the display which rotation {@link #mRotation} has. */
75 private int mLastRotationDisplayId = Display.INVALID_DISPLAY;
76 /**
77 * Display rotation as of the last time {@link #setBounds(Rect)} was called or this task was
78 * moved to a new display.
79 */
Wale Ogunwale3eadad72016-10-13 09:16:59 -070080 private int mRotation;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070081
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070082 // For comparison with DisplayContent bounds.
83 private Rect mTmpRect = new Rect();
84 // For handling display rotations.
85 private Rect mTmpRect2 = new Rect();
Bryce Leef3c6a472017-11-14 14:53:06 -080086 // For retrieving dim bounds
87 private Rect mTmpRect3 = new Rect();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070088
Wale Ogunwaleb1faf602016-01-27 09:12:31 -080089 // Resize mode of the task. See {@link ActivityInfo#resizeMode}
90 private int mResizeMode;
Chong Zhangb15758a2015-11-17 12:12:03 -080091
Winson Chungd3395382016-12-13 11:49:09 -080092 // Whether the task supports picture-in-picture.
93 // See {@link ActivityInfo#FLAG_SUPPORTS_PICTURE_IN_PICTURE}
94 private boolean mSupportsPictureInPicture;
95
Chong Zhang3005e752015-09-18 18:46:28 -070096 // Whether the task is currently being drag-resized
97 private boolean mDragResizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +010098 private int mDragResizeMode;
Chong Zhang3005e752015-09-18 18:46:28 -070099
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100100 private TaskDescription mTaskDescription;
101
Robert Carr18f622f2017-05-08 11:20:43 -0700102 // If set to true, the task will report that it is not in the floating
Wale Ogunwale6fbde9f2017-08-24 07:24:12 -0700103 // state regardless of it's stack affiliation. As the floating state drives
Robert Carr18f622f2017-05-08 11:20:43 -0700104 // production of content insets this can be used to preserve them across
105 // stack moves and we in fact do so when moving from full screen to pinned.
106 private boolean mPreserveNonFloatingState = false;
107
Robert Carrf59b8dd2017-10-02 18:58:36 -0700108 private Dimmer mDimmer = new Dimmer(this);
109 private final Rect mTmpDimBoundsRect = new Rect();
110
Jorim Jaggi50bf59c2018-03-09 17:29:48 +0100111 /** @see #setCanAffectSystemUiFlags */
112 private boolean mCanAffectSystemUiFlags = true;
113
Yunfan Chen0e7aff92018-12-05 16:35:32 -0800114 // TODO: remove after unification
115 TaskRecord mTaskRecord;
116
Bryce Leef3c6a472017-11-14 14:53:06 -0800117 Task(int taskId, TaskStack stack, int userId, WindowManagerService service, int resizeMode,
118 boolean supportsPictureInPicture, TaskDescription taskDescription,
Yunfan Chen0e7aff92018-12-05 16:35:32 -0800119 TaskRecord taskRecord) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100120 super(service);
Craig Mautner83162a92015-01-26 14:43:30 -0800121 mTaskId = taskId;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800122 mStack = stack;
Craig Mautnerac6f8432013-07-17 13:24:59 -0700123 mUserId = userId;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800124 mResizeMode = resizeMode;
Winson Chungd3395382016-12-13 11:49:09 -0800125 mSupportsPictureInPicture = supportsPictureInPicture;
Yunfan Chen0e7aff92018-12-05 16:35:32 -0800126 mTaskRecord = taskRecord;
127 if (mTaskRecord != null) {
128 // This can be null when we call createTaskInStack in WindowTestUtils. Remove this after
129 // unification.
130 mTaskRecord.registerConfigurationChangeListener(this);
131 }
Evan Roskydfe3da72018-10-26 17:21:06 -0700132 setBounds(getRequestedOverrideBounds());
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100133 mTaskDescription = taskDescription;
Bryce Lee61fbcbc2017-03-10 14:14:03 -0800134
135 // Tasks have no set orientation value (including SCREEN_ORIENTATION_UNSPECIFIED).
136 setOrientation(SCREEN_ORIENTATION_UNSET);
Craig Mautnerc00204b2013-03-05 15:02:14 -0800137 }
138
139 DisplayContent getDisplayContent() {
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800140 return mStack != null ? mStack.getDisplayContent() : null;
141 }
142
Wale Ogunwale069bbd32017-02-03 07:58:14 -0800143 private int getAdjustedAddPosition(int suggestedPosition) {
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800144 final int size = mChildren.size();
145 if (suggestedPosition >= size) {
146 return Math.min(size, suggestedPosition);
147 }
148
149 for (int pos = 0; pos < size && pos < suggestedPosition; ++pos) {
150 // TODO: Confirm that this is the behavior we want long term.
151 if (mChildren.get(pos).removed) {
152 // suggestedPosition assumes removed tokens are actually gone.
153 ++suggestedPosition;
154 }
155 }
156 return Math.min(size, suggestedPosition);
Craig Mautnerc00204b2013-03-05 15:02:14 -0800157 }
158
Wale Ogunwale72919d22016-12-08 18:58:50 -0800159 @Override
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800160 void addChild(AppWindowToken wtoken, int position) {
161 position = getAdjustedAddPosition(position);
162 super.addChild(wtoken, position);
Craig Mautner42bf39e2014-02-21 16:46:22 -0800163 mDeferRemoval = false;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800164 }
165
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800166 @Override
167 void positionChildAt(int position, AppWindowToken child, boolean includingParents) {
168 position = getAdjustedAddPosition(position);
169 super.positionChildAt(position, child, includingParents);
170 mDeferRemoval = false;
171 }
172
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700173 private boolean hasWindowsAlive() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700174 for (int i = mChildren.size() - 1; i >= 0; i--) {
175 if (mChildren.get(i).hasWindowsAlive()) {
Chong Zhang7e8eeb72016-01-06 19:14:47 -0800176 return true;
177 }
178 }
179 return false;
180 }
181
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800182 @VisibleForTesting
183 boolean shouldDeferRemoval() {
Wale Ogunwale2c9f2032017-06-02 06:50:50 -0700184 // TODO: This should probably return false if mChildren.isEmpty() regardless if the stack
185 // is animating...
Jorim Jaggia5e10572017-11-15 14:36:26 +0100186 return hasWindowsAlive() && mStack.isSelfOrChildAnimating();
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800187 }
188
Wale Ogunwalef6192862016-09-10 13:42:30 -0700189 @Override
190 void removeIfPossible() {
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800191 if (shouldDeferRemoval()) {
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800192 if (DEBUG_STACK) Slog.i(TAG, "removeTask: deferring removing taskId=" + mTaskId);
Craig Mautnere3119b72015-01-20 15:02:36 -0800193 mDeferRemoval = true;
194 return;
195 }
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800196 removeImmediately();
197 }
198
199 @Override
200 void removeImmediately() {
Wale Ogunwaleb9b16a72016-01-27 12:24:44 -0800201 if (DEBUG_STACK) Slog.i(TAG, "removeTask: removing taskId=" + mTaskId);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800202 EventLog.writeEvent(WM_TASK_REMOVED, mTaskId, "removeTask");
Craig Mautnere3119b72015-01-20 15:02:36 -0800203 mDeferRemoval = false;
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800204
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800205 super.removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800206 }
207
Yunfan Chen0e7aff92018-12-05 16:35:32 -0800208 void reparent(StackWindowController stackController, int position, boolean moveParents) {
209 if (DEBUG_STACK) {
210 Slog.i(TAG_WM, "reparent: moving taskId=" + mTaskId
211 + " to stack=" + stackController + " at " + position);
212 }
213 final TaskStack stack = stackController.mContainer;
214 if (stack == null) {
215 throw new IllegalArgumentException("reparent: could not find stack="
216 + stackController);
217 }
218 reparent(stack, position, moveParents);
219 getDisplayContent().layoutAndAssignWindowLayersIfNeeded();
220 }
221
222
Wale Ogunwale2719cc12017-04-14 09:45:27 -0700223 void reparent(TaskStack stack, int position, boolean moveParents) {
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800224 if (stack == mStack) {
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800225 throw new IllegalArgumentException(
226 "task=" + this + " already child of stack=" + mStack);
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800227 }
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800228 if (DEBUG_STACK) Slog.i(TAG, "reParentTask: removing taskId=" + mTaskId
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800229 + " from stack=" + mStack);
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800230 EventLog.writeEvent(WM_TASK_REMOVED, mTaskId, "reParentTask");
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -0800231 final DisplayContent prevDisplayContent = getDisplayContent();
232
Robert Carr18f622f2017-05-08 11:20:43 -0700233 // If we are moving from the fullscreen stack to the pinned stack
234 // then we want to preserve our insets so that there will not
235 // be a jump in the area covered by system decorations. We rely
236 // on the pinned animation to later unset this value.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700237 if (stack.inPinnedWindowingMode()) {
Robert Carr18f622f2017-05-08 11:20:43 -0700238 mPreserveNonFloatingState = true;
239 } else {
240 mPreserveNonFloatingState = false;
241 }
242
Andrii Kulian441e4492016-09-29 15:25:00 -0700243 getParent().removeChild(this);
Wale Ogunwale2719cc12017-04-14 09:45:27 -0700244 stack.addTask(this, position, showForAllUsers(), moveParents);
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -0800245
246 // Relayout display(s).
247 final DisplayContent displayContent = stack.getDisplayContent();
248 displayContent.setLayoutNeeded();
249 if (prevDisplayContent != displayContent) {
250 onDisplayChanged(displayContent);
251 prevDisplayContent.setLayoutNeeded();
252 }
Wale Ogunwale53a29a92015-02-23 15:42:52 -0800253 }
254
Wale Ogunwale59507092018-10-29 09:00:30 -0700255 /** @see ActivityTaskManagerService#positionTaskInStack(int, int, int). */
Bryce Leef3c6a472017-11-14 14:53:06 -0800256 void positionAt(int position) {
Wale Ogunwalec5cc3012017-01-13 13:26:16 -0800257 mStack.positionChildAt(position, this, false /* includingParents */);
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700258 }
259
Wale Ogunwale14a3fb92016-09-11 15:19:05 -0700260 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -0800261 void onParentSet() {
Robert Carrb1579c82017-09-05 14:54:47 -0700262 super.onParentSet();
263
Andrii Kuliand2765632016-12-12 22:26:34 -0800264 // Update task bounds if needed.
Garfield Tan2f145f22018-11-01 15:27:03 -0700265 adjustBoundsForDisplayChangeIfNeeded(getDisplayContent());
Andrii Kuliand2765632016-12-12 22:26:34 -0800266
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700267 if (getWindowConfiguration().windowsAreScaleable()) {
Andrii Kuliand2765632016-12-12 22:26:34 -0800268 // We force windows out of SCALING_MODE_FREEZE so that we can continue to animate them
269 // while a resize is pending.
270 forceWindowsScaleable(true /* force */);
271 } else {
272 forceWindowsScaleable(false /* force */);
273 }
274 }
275
276 @Override
Wale Ogunwalef6192862016-09-10 13:42:30 -0700277 void removeChild(AppWindowToken token) {
278 if (!mChildren.contains(token)) {
279 Slog.e(TAG, "removeChild: token=" + this + " not found.");
280 return;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700281 }
282
Wale Ogunwalef6192862016-09-10 13:42:30 -0700283 super.removeChild(token);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700284
Wale Ogunwalef6192862016-09-10 13:42:30 -0700285 if (mChildren.isEmpty()) {
Wale Ogunwalee1fe7fa22016-12-15 18:27:00 -0800286 EventLog.writeEvent(WM_TASK_REMOVED, mTaskId, "removeAppToken: last token");
Craig Mautnere3119b72015-01-20 15:02:36 -0800287 if (mDeferRemoval) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700288 removeIfPossible();
Craig Mautnere3119b72015-01-20 15:02:36 -0800289 }
Craig Mautnerc00204b2013-03-05 15:02:14 -0800290 }
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800291 }
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800292
Craig Mautnercbd84af2014-10-22 13:21:22 -0700293 void setSendingToBottom(boolean toBottom) {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700294 for (int appTokenNdx = 0; appTokenNdx < mChildren.size(); appTokenNdx++) {
295 mChildren.get(appTokenNdx).sendingToBottom = toBottom;
Craig Mautnercbd84af2014-10-22 13:21:22 -0700296 }
297 }
298
Bryce Leef3c6a472017-11-14 14:53:06 -0800299 public int setBounds(Rect bounds, boolean forceResize) {
300 final int boundsChanged = setBounds(bounds);
301
302 if (forceResize && (boundsChanged & BOUNDS_CHANGE_SIZE) != BOUNDS_CHANGE_SIZE) {
303 onResize();
304 return BOUNDS_CHANGE_SIZE | boundsChanged;
Filip Gruszczynskiebcc8752015-08-25 16:51:05 -0700305 }
Wale Ogunwale68278562017-09-23 17:13:55 -0700306
Bryce Leef3c6a472017-11-14 14:53:06 -0800307 return boundsChanged;
308 }
309
310 /** Set the task bounds. Passing in null sets the bounds to fullscreen. */
311 @Override
312 public int setBounds(Rect bounds) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700313 int rotation = Surface.ROTATION_0;
314 final DisplayContent displayContent = mStack.getDisplayContent();
315 if (displayContent != null) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700316 rotation = displayContent.getDisplayInfo().rotation;
Bryce Leef3c6a472017-11-14 14:53:06 -0800317 } else if (bounds == null) {
Evan Roskye747c3e2018-10-30 20:06:41 -0700318 return super.setBounds(bounds);
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700319 }
320
Bryce Leef3c6a472017-11-14 14:53:06 -0800321 final int boundsChange = super.setBounds(bounds);
Chong Zhangf66db432016-01-13 10:39:51 -0800322
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700323 mRotation = rotation;
Robert Carrf59b8dd2017-10-02 18:58:36 -0700324
Wale Ogunwale2cc92f52015-09-09 13:12:10 -0700325 return boundsChange;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700326 }
327
Yunfan Chen0e7aff92018-12-05 16:35:32 -0800328 void resize(boolean relayout, boolean forced) {
329 if (setBounds(getRequestedOverrideBounds(), forced) != BOUNDS_CHANGE_NONE && relayout) {
330 getDisplayContent().layoutAndAssignWindowLayersIfNeeded();
331 }
332 }
333
Louis Chang7501e332018-08-20 13:08:39 +0800334 @Override
335 void onDisplayChanged(DisplayContent dc) {
Garfield Tan2f145f22018-11-01 15:27:03 -0700336 adjustBoundsForDisplayChangeIfNeeded(dc);
Louis Chang7501e332018-08-20 13:08:39 +0800337 super.onDisplayChanged(dc);
338 }
339
Jorim Jaggidc249c42015-12-15 14:57:31 -0800340 /**
Evan Roskyed6767f2018-10-26 17:21:06 -0700341 * Sets bounds that override where the task is displayed. Used during transient operations
342 * like animation / interaction.
Jorim Jaggidc249c42015-12-15 14:57:31 -0800343 */
Evan Roskyed6767f2018-10-26 17:21:06 -0700344 void setOverrideDisplayedBounds(Rect overrideDisplayedBounds) {
345 if (overrideDisplayedBounds != null) {
346 mOverrideDisplayedBounds.set(overrideDisplayedBounds);
Jorim Jaggidc249c42015-12-15 14:57:31 -0800347 } else {
Evan Roskyed6767f2018-10-26 17:21:06 -0700348 mOverrideDisplayedBounds.setEmpty();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800349 }
350 }
351
352 /**
Evan Roskyed6767f2018-10-26 17:21:06 -0700353 * Gets the bounds that override where the task is displayed. See
Wale Ogunwale04d9cb52018-04-30 13:55:07 -0700354 * {@link android.app.IActivityTaskManager#resizeDockedStack} why this is needed.
Jorim Jaggidc249c42015-12-15 14:57:31 -0800355 */
Evan Roskyed6767f2018-10-26 17:21:06 -0700356 Rect getOverrideDisplayedBounds() {
357 return mOverrideDisplayedBounds;
Jorim Jaggidc249c42015-12-15 14:57:31 -0800358 }
359
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800360 void setResizeable(int resizeMode) {
361 mResizeMode = resizeMode;
Chong Zhangb15758a2015-11-17 12:12:03 -0800362 }
363
364 boolean isResizeable() {
Winson Chungd3395382016-12-13 11:49:09 -0800365 return ActivityInfo.isResizeableMode(mResizeMode) || mSupportsPictureInPicture
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800366 || mWmService.mForceResizableTasks;
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800367 }
368
skuhne@google.com322347b2016-12-02 12:54:03 -0800369 /**
370 * Tests if the orientation should be preserved upon user interactive resizig operations.
371
372 * @return true if orientation should not get changed upon resizing operation.
373 */
374 boolean preserveOrientationOnResize() {
375 return mResizeMode == RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY
376 || mResizeMode == RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY
377 || mResizeMode == RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION;
378 }
379
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800380 boolean cropWindowsToStackBounds() {
Wale Ogunwaledf241e92016-10-13 15:14:21 -0700381 return isResizeable();
Wale Ogunwaleb1faf602016-01-27 09:12:31 -0800382 }
383
Jorim Jaggi0429f352015-12-22 16:29:16 +0100384 /**
385 * Prepares the task bounds to be frozen with the current size. See
386 * {@link AppWindowToken#freezeBounds}.
387 */
388 void prepareFreezingBounds() {
Bryce Leef3c6a472017-11-14 14:53:06 -0800389 mPreparedFrozenBounds.set(getBounds());
Andrii Kulian441e4492016-09-29 15:25:00 -0700390 mPreparedFrozenMergedConfig.setTo(getConfiguration());
Jorim Jaggi0429f352015-12-22 16:29:16 +0100391 }
392
Chong Zhang5117e272016-05-03 12:47:34 -0700393 /**
394 * Align the task to the adjusted bounds.
395 *
396 * @param adjustedBounds Adjusted bounds to which the task should be aligned.
397 * @param tempInsetBounds Insets bounds for the task.
398 * @param alignBottom True if the task's bottom should be aligned to the adjusted
399 * bounds's bottom; false if the task's top should be aligned
400 * the adjusted bounds's top.
401 */
Andrii Kulian441e4492016-09-29 15:25:00 -0700402 void alignToAdjustedBounds(Rect adjustedBounds, Rect tempInsetBounds, boolean alignBottom) {
Evan Roskydfe3da72018-10-26 17:21:06 -0700403 if (!isResizeable() || EMPTY.equals(getRequestedOverrideConfiguration())) {
Chong Zhang5117e272016-05-03 12:47:34 -0700404 return;
405 }
406
407 getBounds(mTmpRect2);
408 if (alignBottom) {
409 int offsetY = adjustedBounds.bottom - mTmpRect2.bottom;
410 mTmpRect2.offset(0, offsetY);
411 } else {
412 mTmpRect2.offsetTo(adjustedBounds.left, adjustedBounds.top);
413 }
Evan Roskyed6767f2018-10-26 17:21:06 -0700414 if (tempInsetBounds == null || tempInsetBounds.isEmpty()) {
415 setOverrideDisplayedBounds(null);
416 setBounds(mTmpRect2);
417 } else {
418 setOverrideDisplayedBounds(mTmpRect2);
419 setBounds(tempInsetBounds);
420 }
Chong Zhang5117e272016-05-03 12:47:34 -0700421 }
422
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700423 /** Return true if the current bound can get outputted to the rest of the system as-is. */
424 private boolean useCurrentBounds() {
Wale Ogunwale926aade2017-08-29 11:24:37 -0700425 final DisplayContent displayContent = getDisplayContent();
Bryce Leef3c6a472017-11-14 14:53:06 -0800426 return matchParentBounds()
Wale Ogunwale926aade2017-08-29 11:24:37 -0700427 || !inSplitScreenSecondaryWindowingMode()
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700428 || displayContent == null
Matthew Ng64e77cf2017-10-31 14:01:31 -0700429 || displayContent.getSplitScreenPrimaryStackIgnoringVisibility() != null;
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700430 }
431
Bryce Leef3c6a472017-11-14 14:53:06 -0800432 @Override
433 public void getBounds(Rect out) {
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700434 if (useCurrentBounds()) {
435 // No need to adjust the output bounds if fullscreen or the docked stack is visible
436 // since it is already what we want to represent to the rest of the system.
Bryce Leef3c6a472017-11-14 14:53:06 -0800437 super.getBounds(out);
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700438 return;
439 }
440
Wale Ogunwaleccb6ce22016-01-14 15:36:35 -0800441 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack is
442 // not currently visible. Go ahead a represent it as fullscreen to the rest of the system.
Bryce Leef3c6a472017-11-14 14:53:06 -0800443 mStack.getDisplayContent().getBounds(out);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700444 }
445
Evan Roskyed6767f2018-10-26 17:21:06 -0700446 @Override
447 public Rect getDisplayedBounds() {
448 if (mOverrideDisplayedBounds.isEmpty()) {
449 return super.getDisplayedBounds();
450 } else {
451 return mOverrideDisplayedBounds;
452 }
453 }
454
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800455 /**
456 * Calculate the maximum visible area of this task. If the task has only one app,
457 * the result will be visible frame of that app. If the task has more than one apps,
458 * we search from top down if the next app got different visible area.
459 *
460 * This effort is to handle the case where some task (eg. GMail composer) might pop up
461 * a dialog that's different in size from the activity below, in which case we should
462 * be dimming the entire task area behind the dialog.
463 *
464 * @param out Rect containing the max visible bounds.
465 * @return true if the task has some visible app windows; false otherwise.
466 */
chaviw553b0212018-07-12 13:37:01 -0700467 private boolean getMaxVisibleBounds(Rect out) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800468 boolean foundTop = false;
Wale Ogunwalef6192862016-09-10 13:42:30 -0700469 for (int i = mChildren.size() - 1; i >= 0; i--) {
470 final AppWindowToken token = mChildren.get(i);
Chong Zhangd8ceb852015-11-11 14:53:41 -0800471 // skip hidden (or about to hide) apps
Wale Ogunwale89973222017-04-23 18:39:45 -0700472 if (token.mIsExiting || token.isClientHidden() || token.hiddenRequested) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800473 continue;
474 }
475 final WindowState win = token.findMainWindow();
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800476 if (win == null) {
477 continue;
478 }
479 if (!foundTop) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800480 foundTop = true;
chaviw553b0212018-07-12 13:37:01 -0700481 out.setEmpty();
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800482 }
chaviw553b0212018-07-12 13:37:01 -0700483
484 win.getMaxVisibleBounds(out);
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800485 }
486 return foundTop;
487 }
488
489 /** Bounds of the task to be used for dimming, as well as touch related tests. */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800490 public void getDimBounds(Rect out) {
Robert Carra86a6bf2016-04-08 17:34:16 -0700491 final DisplayContent displayContent = mStack.getDisplayContent();
492 // It doesn't matter if we in particular are part of the resize, since we couldn't have
493 // a DimLayer anyway if we weren't visible.
Wale Ogunwalef6192862016-09-10 13:42:30 -0700494 final boolean dockedResizing = displayContent != null
495 && displayContent.mDividerControllerLocked.isResizing();
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800496 if (useCurrentBounds()) {
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700497 if (inFreeformWindowingMode() && getMaxVisibleBounds(out)) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800498 return;
499 }
500
Bryce Leef3c6a472017-11-14 14:53:06 -0800501 if (!matchParentBounds()) {
Jorim Jaggi22a869f2016-03-25 23:33:21 -0700502 // When minimizing the docked stack when going home, we don't adjust the task bounds
503 // so we need to intersect the task bounds with the stack bounds here.
Robert Carra86a6bf2016-04-08 17:34:16 -0700504 //
505 // If we are Docked Resizing with snap points, the task bounds could be smaller than the stack
506 // bounds and so we don't even want to use them. Even if the app should not be resized the Dim
507 // should keep up with the divider.
508 if (dockedResizing) {
509 mStack.getBounds(out);
510 } else {
511 mStack.getBounds(mTmpRect);
Bryce Leef3c6a472017-11-14 14:53:06 -0800512 mTmpRect.intersect(getBounds());
chaviw2fb06bc2018-01-19 17:09:15 -0800513 out.set(mTmpRect);
Robert Carra86a6bf2016-04-08 17:34:16 -0700514 }
Jorim Jaggi22a869f2016-03-25 23:33:21 -0700515 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -0800516 out.set(getBounds());
Jorim Jaggi22a869f2016-03-25 23:33:21 -0700517 }
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800518 return;
519 }
520
Wale Ogunwalef6192862016-09-10 13:42:30 -0700521 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack is
522 // not currently visible. Go ahead a represent it as fullscreen to the rest of the system.
523 if (displayContent != null) {
Bryce Leef3c6a472017-11-14 14:53:06 -0800524 displayContent.getBounds(out);
Wale Ogunwalef6192862016-09-10 13:42:30 -0700525 }
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800526 }
527
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100528 void setDragResizing(boolean dragResizing, int dragResizeMode) {
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800529 if (mDragResizing != dragResizing) {
chaviw8c9d1f52018-07-25 14:56:07 -0700530 // No need to check if the mode is allowed if it's leaving dragResize
531 if (dragResizing && !DragResizeMode.isModeAllowedForStack(mStack, dragResizeMode)) {
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100532 throw new IllegalArgumentException("Drag resize mode not allow for stack stackId="
533 + mStack.mStackId + " dragResizeMode=" + dragResizeMode);
534 }
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800535 mDragResizing = dragResizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100536 mDragResizeMode = dragResizeMode;
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800537 resetDragResizingChangeReported();
538 }
539 }
540
Chong Zhang3005e752015-09-18 18:46:28 -0700541 boolean isDragResizing() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700542 return mDragResizing;
Chong Zhang3005e752015-09-18 18:46:28 -0700543 }
544
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100545 int getDragResizeMode() {
546 return mDragResizeMode;
547 }
548
Yunfan Chen0e7aff92018-12-05 16:35:32 -0800549 /**
550 * Puts this task into docked drag resizing mode. See {@link DragResizeMode}.
551 *
552 * @param resizing Whether to put the task into drag resize mode.
553 */
554 public void setTaskDockedResizing(boolean resizing) {
555 setDragResizing(resizing, DRAG_RESIZE_MODE_DOCKED_DIVIDER);
556 }
557
Garfield Tan2f145f22018-11-01 15:27:03 -0700558 private void adjustBoundsForDisplayChangeIfNeeded(final DisplayContent displayContent) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700559 if (displayContent == null) {
560 return;
561 }
Bryce Leef3c6a472017-11-14 14:53:06 -0800562 if (matchParentBounds()) {
Wale Ogunwale68278562017-09-23 17:13:55 -0700563 // TODO: Yeah...not sure if this works with WindowConfiguration, but shouldn't be a
564 // problem once we move mBounds into WindowConfiguration.
Bryce Leef3c6a472017-11-14 14:53:06 -0800565 setBounds(null);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700566 return;
567 }
Garfield Tandec96db2018-10-30 11:28:49 -0700568 final int displayId = displayContent.getDisplayId();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700569 final int newRotation = displayContent.getDisplayInfo().rotation;
Garfield Tandec96db2018-10-30 11:28:49 -0700570 if (displayId != mLastRotationDisplayId) {
571 // This task is on a display that it wasn't on. There is no point to keep the relative
572 // position if display rotations for old and new displays are different. Just keep these
573 // values.
574 mLastRotationDisplayId = displayId;
575 mRotation = newRotation;
576 return;
577 }
578
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700579 if (mRotation == newRotation) {
Garfield Tandec96db2018-10-30 11:28:49 -0700580 // Rotation didn't change. We don't need to adjust the bounds to keep the relative
581 // position.
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700582 return;
583 }
584
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800585 // Device rotation changed.
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700586 // - We don't want the task to move around on the screen when this happens, so update the
587 // task bounds so it stays in the same place.
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800588 // - Rotate the bounds and notify activity manager if the task can be resized independently
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700589 // from its stack. The stack will take care of task rotation for the other case.
Bryce Leef3c6a472017-11-14 14:53:06 -0800590 mTmpRect2.set(getBounds());
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800591
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700592 if (!getWindowConfiguration().canResizeTask()) {
Bryce Leef3c6a472017-11-14 14:53:06 -0800593 setBounds(mTmpRect2);
Wale Ogunwalee1fe4d12016-01-14 08:52:30 -0800594 return;
595 }
596
Wale Ogunwale94744212015-09-21 19:01:47 -0700597 displayContent.rotateBounds(mRotation, newRotation, mTmpRect2);
Bryce Leef3c6a472017-11-14 14:53:06 -0800598 if (setBounds(mTmpRect2) != BOUNDS_CHANGE_NONE) {
Yunfan Chen0e7aff92018-12-05 16:35:32 -0800599 if (mTaskRecord != null) {
600 mTaskRecord.requestResize(getBounds(), RESIZE_MODE_SYSTEM_SCREEN_ROTATION);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800601 }
Wale Ogunwale1ed0d892015-09-28 13:27:44 -0700602 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700603 }
604
Wale Ogunwalef6192862016-09-10 13:42:30 -0700605 /** Cancels any running app transitions associated with the task. */
Winsonc28098f2015-10-30 14:50:19 -0700606 void cancelTaskWindowTransition() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700607 for (int i = mChildren.size() - 1; i >= 0; --i) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200608 mChildren.get(i).cancelAnimation();
Winsonc28098f2015-10-30 14:50:19 -0700609 }
610 }
611
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700612 boolean showForAllUsers() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700613 final int tokensCount = mChildren.size();
Wale Ogunwale72919d22016-12-08 18:58:50 -0800614 return (tokensCount != 0) && mChildren.get(tokensCount - 1).mShowForAllUsers;
Jorim Jaggiff71d202016-04-14 13:12:36 -0700615 }
616
Robert Carr7e4c90e2017-02-15 19:52:38 -0800617 /**
618 * When we are in a floating stack (Freeform, Pinned, ...) we calculate
619 * insets differently. However if we are animating to the fullscreen stack
620 * we need to begin calculating insets as if we were fullscreen, otherwise
621 * we will have a jump at the end.
622 */
Robert Carre6275582016-02-29 15:45:45 -0800623 boolean isFloating() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700624 return getWindowConfiguration().tasksAreFloating()
Robert Carr18f622f2017-05-08 11:20:43 -0700625 && !mStack.isAnimatingBoundsToFullscreen() && !mPreserveNonFloatingState;
Robert Carre6275582016-02-29 15:45:45 -0800626 }
627
Winson Chungd41f71d2018-03-16 15:26:07 -0700628 @Override
629 public SurfaceControl getAnimationLeashParent() {
Winson Chung732446a2018-09-19 13:15:17 -0700630 // Currently, only the recents animation will create animation leashes for tasks. In this
631 // case, reparent the task to the home animation layer while it is being animated to allow
632 // the home activity to reorder the app windows relative to its own.
633 return getAppAnimationLayer(ANIMATION_LAYER_HOME);
Winson Chungd41f71d2018-03-16 15:26:07 -0700634 }
635
636 boolean isTaskAnimating() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800637 final RecentsAnimationController recentsAnim = mWmService.getRecentsAnimationController();
Winson Chungd41f71d2018-03-16 15:26:07 -0700638 if (recentsAnim != null) {
639 if (recentsAnim.isAnimatingTask(this)) {
640 return true;
641 }
642 }
643 return false;
644 }
645
Chong Zhangd8ceb852015-11-11 14:53:41 -0800646 WindowState getTopVisibleAppMainWindow() {
647 final AppWindowToken token = getTopVisibleAppToken();
648 return token != null ? token.findMainWindow() : null;
Chong Zhang9184ec62015-09-24 12:32:21 -0700649 }
650
Jorim Jaggie6c6ecb2017-07-20 18:09:20 +0200651 AppWindowToken getTopFullscreenAppToken() {
652 for (int i = mChildren.size() - 1; i >= 0; i--) {
653 final AppWindowToken token = mChildren.get(i);
654 final WindowState win = token.findMainWindow();
655 if (win != null && win.mAttrs.isFullscreen()) {
656 return token;
657 }
658 }
659 return null;
660 }
661
Chong Zhangd8ceb852015-11-11 14:53:41 -0800662 AppWindowToken getTopVisibleAppToken() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700663 for (int i = mChildren.size() - 1; i >= 0; i--) {
664 final AppWindowToken token = mChildren.get(i);
Chong Zhangd8ceb852015-11-11 14:53:41 -0800665 // skip hidden (or about to hide) apps
Wale Ogunwale89973222017-04-23 18:39:45 -0700666 if (!token.mIsExiting && !token.isClientHidden() && !token.hiddenRequested) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800667 return token;
668 }
669 }
670 return null;
Chong Zhangbef461f2015-10-27 11:38:24 -0700671 }
672
Yunfan Chen0e7aff92018-12-05 16:35:32 -0800673 void positionChildAtTop(AppWindowToken aToken) {
674 positionChildAt(aToken, POSITION_TOP);
675 }
676
677 void positionChildAt(AppWindowToken aToken, int position) {
678 if (aToken == null) {
679 Slog.w(TAG_WM,
680 "Attempted to position of non-existing app");
681 return;
682 }
683
684 positionChildAt(position, aToken, false /* includeParents */);
685 }
686
Wale Ogunwale29bfbb82016-05-12 15:13:52 -0700687 boolean isFullscreen() {
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700688 if (useCurrentBounds()) {
Bryce Leef3c6a472017-11-14 14:53:06 -0800689 return matchParentBounds();
Wale Ogunwalef175e8a2015-09-29 11:07:06 -0700690 }
691 // The bounds has been adjusted to accommodate for a docked stack, but the docked stack
692 // is not currently visible. Go ahead a represent it as fullscreen to the rest of the
693 // system.
694 return true;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700695 }
696
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700697 void forceWindowsScaleable(boolean force) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800698 mWmService.openSurfaceTransaction();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700699 try {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700700 for (int i = mChildren.size() - 1; i >= 0; i--) {
701 mChildren.get(i).forceWindowsScaleableInTransaction(force);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700702 }
703 } finally {
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800704 mWmService.closeSurfaceTransaction("forceWindowsScaleable");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700705 }
706 }
707
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100708 void setTaskDescription(TaskDescription taskDescription) {
709 mTaskDescription = taskDescription;
710 }
711
Yunfan Chen0e7aff92018-12-05 16:35:32 -0800712 void onSnapshotChanged(ActivityManager.TaskSnapshot snapshot) {
713 mTaskRecord.onSnapshotChanged(snapshot);
714 }
715
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100716 TaskDescription getTaskDescription() {
717 return mTaskDescription;
718 }
719
Wale Ogunwalef6192862016-09-10 13:42:30 -0700720 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -0700721 boolean fillsParent() {
Bryce Leef3c6a472017-11-14 14:53:06 -0800722 return matchParentBounds() || !getWindowConfiguration().canResizeTask();
Wale Ogunwale51362492016-09-08 17:49:17 -0700723 }
724
Jorim Jaggi329a5832017-01-05 18:57:12 +0100725 @Override
Jorim Jaggi51304d72017-05-17 17:25:32 +0200726 void forAllTasks(Consumer<Task> callback) {
727 callback.accept(this);
728 }
729
Jorim Jaggi50bf59c2018-03-09 17:29:48 +0100730 /**
731 * @param canAffectSystemUiFlags If false, all windows in this task can not affect SystemUI
732 * flags. See {@link WindowState#canAffectSystemUiFlags()}.
733 */
734 void setCanAffectSystemUiFlags(boolean canAffectSystemUiFlags) {
735 mCanAffectSystemUiFlags = canAffectSystemUiFlags;
736 }
737
738 /**
739 * @see #setCanAffectSystemUiFlags
740 */
741 boolean canAffectSystemUiFlags() {
742 return mCanAffectSystemUiFlags;
743 }
744
chaviw87ca63a2018-03-26 14:06:17 -0700745 void dontAnimateDimExit() {
746 mDimmer.dontAnimateExit();
747 }
748
Jorim Jaggi51304d72017-05-17 17:25:32 +0200749 @Override
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800750 public String toString() {
Wale Ogunwalef6192862016-09-10 13:42:30 -0700751 return "{taskId=" + mTaskId + " appTokens=" + mChildren + " mdr=" + mDeferRemoval + "}";
Craig Mautner5d9c7be2013-02-15 14:02:56 -0800752 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700753
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700754 String getName() {
755 return toShortString();
756 }
757
Robert Carr18f622f2017-05-08 11:20:43 -0700758 void clearPreserveNonFloatingState() {
759 mPreserveNonFloatingState = false;
760 }
761
chaviw2fb06bc2018-01-19 17:09:15 -0800762 @Override
Robert Carrf59b8dd2017-10-02 18:58:36 -0700763 Dimmer getDimmer() {
764 return mDimmer;
765 }
766
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700767 @Override
Robert Carrf59b8dd2017-10-02 18:58:36 -0700768 void prepareSurfaces() {
769 mDimmer.resetDimStates();
770 super.prepareSurfaces();
771 getDimBounds(mTmpDimBoundsRect);
chaviwe07246a2017-12-12 16:18:29 -0800772
773 // Bounds need to be relative, as the dim layer is a child.
774 mTmpDimBoundsRect.offsetTo(0, 0);
Robert Carrf59b8dd2017-10-02 18:58:36 -0700775 if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
776 scheduleAnimation();
777 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700778 }
779
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700780 @CallSuper
781 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +0200782 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -0700783 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +0200784 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -0700785 proto.write(ID, mTaskId);
786 for (int i = mChildren.size() - 1; i >= 0; i--) {
787 final AppWindowToken appWindowToken = mChildren.get(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +0200788 appWindowToken.writeToProto(proto, APP_WINDOW_TOKENS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -0700789 }
Bryce Leef3c6a472017-11-14 14:53:06 -0800790 proto.write(FILLS_PARENT, matchParentBounds());
791 getBounds().writeToProto(proto, BOUNDS);
Evan Roskyed6767f2018-10-26 17:21:06 -0700792 mOverrideDisplayedBounds.writeToProto(proto, DISPLAYED_BOUNDS);
Vishnu Nair04ab4392018-01-10 11:00:06 -0800793 proto.write(DEFER_REMOVAL, mDeferRemoval);
Louis Chang7501e332018-08-20 13:08:39 +0800794 proto.write(SURFACE_WIDTH, mSurfaceControl.getWidth());
795 proto.write(SURFACE_HEIGHT, mSurfaceControl.getHeight());
Steven Timotiusaf03df62017-07-18 16:56:43 -0700796 proto.end(token);
797 }
798
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200799 @Override
800 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
801 super.dump(pw, prefix, dumpAll);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800802 final String doublePrefix = prefix + " ";
803
804 pw.println(prefix + "taskId=" + mTaskId);
Bryce Leef3c6a472017-11-14 14:53:06 -0800805 pw.println(doublePrefix + "mBounds=" + getBounds().toShortString());
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800806 pw.println(doublePrefix + "mdr=" + mDeferRemoval);
Wale Ogunwalef6192862016-09-10 13:42:30 -0700807 pw.println(doublePrefix + "appTokens=" + mChildren);
Evan Roskyed6767f2018-10-26 17:21:06 -0700808 pw.println(doublePrefix + "mDisplayedBounds=" + mOverrideDisplayedBounds.toShortString());
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800809
810 final String triplePrefix = doublePrefix + " ";
Jorim Jaggi153dc9d2018-02-23 13:28:15 +0100811 final String quadruplePrefix = triplePrefix + " ";
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800812
Wale Ogunwalef6192862016-09-10 13:42:30 -0700813 for (int i = mChildren.size() - 1; i >= 0; i--) {
814 final AppWindowToken wtoken = mChildren.get(i);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800815 pw.println(triplePrefix + "Activity #" + i + " " + wtoken);
Jorim Jaggi153dc9d2018-02-23 13:28:15 +0100816 wtoken.dump(pw, quadruplePrefix, dumpAll);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800817 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700818 }
Robert Carrf59b8dd2017-10-02 18:58:36 -0700819
820 String toShortString() {
821 return "Task=" + mTaskId;
822 }
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800823}