Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.wm; |
| 18 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
| 20 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
| 21 | import static android.app.ActivityManager.StackId.HOME_STACK_ID; |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 22 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
Wale Ogunwale | 1ed0d89 | 2015-09-28 13:27:44 -0700 | [diff] [blame] | 23 | import static android.app.ActivityManager.RESIZE_MODE_SYSTEM_SCREEN_ROTATION; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 24 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
| 25 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE; |
| 26 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK; |
Wale Ogunwale | 1ed0d89 | 2015-09-28 13:27:44 -0700 | [diff] [blame] | 27 | import static com.android.server.wm.WindowManagerService.H.RESIZE_TASK; |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 28 | import static com.android.server.wm.WindowManagerService.H.SHOW_NON_RESIZEABLE_DOCK_TOAST; |
| 29 | import static android.view.WindowManager.DOCKED_INVALID; |
| 30 | import static android.view.WindowManager.DOCKED_LEFT; |
| 31 | import static android.view.WindowManager.DOCKED_RIGHT; |
| 32 | import static android.view.WindowManager.DOCKED_TOP; |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 33 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 34 | import android.app.ActivityManager.StackId; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 35 | import android.content.res.Configuration; |
| 36 | import android.graphics.Rect; |
Craig Mautner | 2c2549c | 2013-11-12 08:31:15 -0800 | [diff] [blame] | 37 | import android.util.EventLog; |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 38 | import android.util.Slog; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 39 | import android.view.DisplayInfo; |
| 40 | import android.view.Surface; |
| 41 | |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 42 | import com.android.server.EventLogTags; |
Craig Mautner | 2c2549c | 2013-11-12 08:31:15 -0800 | [diff] [blame] | 43 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 44 | import java.io.PrintWriter; |
| 45 | import java.util.ArrayList; |
| 46 | |
| 47 | class Task implements DimLayer.DimLayerUser { |
Wale Ogunwale | 2cc92f5 | 2015-09-09 13:12:10 -0700 | [diff] [blame] | 48 | // Return value from {@link setBounds} indicating no change was made to the Task bounds. |
| 49 | static final int BOUNDS_CHANGE_NONE = 0; |
| 50 | // Return value from {@link setBounds} indicating the position of the Task bounds changed. |
| 51 | static final int BOUNDS_CHANGE_POSITION = 1; |
| 52 | // Return value from {@link setBounds} indicating the size of the Task bounds changed. |
| 53 | static final int BOUNDS_CHANGE_SIZE = 1 << 1; |
| 54 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 55 | TaskStack mStack; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 56 | final AppTokenList mAppTokens = new AppTokenList(); |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 57 | final int mTaskId; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 58 | final int mUserId; |
Craig Mautner | 9ef471f | 2014-02-07 13:11:47 -0800 | [diff] [blame] | 59 | boolean mDeferRemoval = false; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 60 | final WindowManagerService mService; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 61 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 62 | // Content limits relative to the DisplayContent this sits in. |
| 63 | private Rect mBounds = new Rect(); |
| 64 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 65 | // Bounds used to calculate the insets. |
| 66 | private final Rect mTempInsetBounds = new Rect(); |
| 67 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 68 | // Device rotation as of the last time {@link #mBounds} was set. |
| 69 | int mRotation; |
| 70 | |
| 71 | // Whether mBounds is fullscreen |
| 72 | private boolean mFullscreen = true; |
| 73 | |
| 74 | // Contains configurations settings that are different from the global configuration due to |
| 75 | // stack specific operations. E.g. {@link #setBounds}. |
| 76 | Configuration mOverrideConfig; |
| 77 | |
| 78 | // For comparison with DisplayContent bounds. |
| 79 | private Rect mTmpRect = new Rect(); |
| 80 | // For handling display rotations. |
| 81 | private Rect mTmpRect2 = new Rect(); |
| 82 | |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 83 | // Whether the task is resizeable |
| 84 | private boolean mResizeable; |
| 85 | |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 86 | // Whether we need to show toast about the app being non-resizeable when it becomes visible. |
| 87 | // This flag is set when a non-resizeable task is docked (or side-by-side). It's cleared |
| 88 | // after we show the toast. |
| 89 | private boolean mShowNonResizeableDockToast; |
| 90 | |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 91 | // Whether the task is currently being drag-resized |
| 92 | private boolean mDragResizing; |
| 93 | |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 94 | Task(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds, |
| 95 | Configuration config) { |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 96 | mTaskId = taskId; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 97 | mStack = stack; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 98 | mUserId = userId; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 99 | mService = service; |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 100 | setBounds(bounds, config); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | DisplayContent getDisplayContent() { |
| 104 | return mStack.getDisplayContent(); |
| 105 | } |
| 106 | |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 107 | void setShowNonResizeableDockToast() { |
| 108 | mShowNonResizeableDockToast = true; |
| 109 | } |
| 110 | |
| 111 | void scheduleShowNonResizeableDockToastIfNeeded() { |
| 112 | if (!mShowNonResizeableDockToast) { |
| 113 | return; |
| 114 | } |
| 115 | final DisplayContent displayContent = mStack.getDisplayContent(); |
| 116 | // If docked stack is not yet visible, we don't want to show the toast yet, |
| 117 | // since we need the visible rect of the docked task to position the toast. |
| 118 | if (displayContent == null || displayContent.getDockedStackLocked() == null) { |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | mShowNonResizeableDockToast = false; |
| 123 | |
| 124 | final int dockSide = mStack.getDockSide(); |
| 125 | int xOffset = 0; |
| 126 | int yOffset = 0; |
| 127 | if (dockSide != DOCKED_INVALID) { |
| 128 | mStack.getBounds(mTmpRect); |
| 129 | displayContent.getLogicalDisplayRect(mTmpRect2); |
| 130 | |
| 131 | if (dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT) { |
| 132 | xOffset = mTmpRect.centerX() - mTmpRect2.centerX(); |
| 133 | } else if (dockSide == DOCKED_TOP) { |
| 134 | // We don't adjust for DOCKED_BOTTOM case since it's already at the bottom. |
| 135 | yOffset = mTmpRect2.bottom - mTmpRect.bottom; |
| 136 | } |
| 137 | mService.mH.obtainMessage( |
| 138 | SHOW_NON_RESIZEABLE_DOCK_TOAST, xOffset, yOffset).sendToTarget(); |
| 139 | } |
| 140 | } |
| 141 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 142 | void addAppToken(int addPos, AppWindowToken wtoken) { |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 143 | final int lastPos = mAppTokens.size(); |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 144 | if (addPos >= lastPos) { |
| 145 | addPos = lastPos; |
| 146 | } else { |
| 147 | for (int pos = 0; pos < lastPos && pos < addPos; ++pos) { |
| 148 | if (mAppTokens.get(pos).removed) { |
| 149 | // addPos assumes removed tokens are actually gone. |
| 150 | ++addPos; |
| 151 | } |
Craig Mautner | 01f79cf | 2014-08-27 09:56:02 -0700 | [diff] [blame] | 152 | } |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 153 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 154 | mAppTokens.add(addPos, wtoken); |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 155 | wtoken.mTask = this; |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 156 | mDeferRemoval = false; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 157 | } |
| 158 | |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 159 | void removeLocked() { |
| 160 | if (!mAppTokens.isEmpty() && mStack.isAnimating()) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 161 | if (DEBUG_STACK) Slog.i(TAG_WM, "removeTask: deferring removing taskId=" + mTaskId); |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 162 | mDeferRemoval = true; |
| 163 | return; |
| 164 | } |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 165 | if (DEBUG_STACK) Slog.i(TAG_WM, "removeTask: removing taskId=" + mTaskId); |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 166 | EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "removeTask"); |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 167 | mDeferRemoval = false; |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 168 | DisplayContent content = getDisplayContent(); |
| 169 | if (content != null) { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 170 | content.mDimLayerController.removeDimLayerUser(this); |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 171 | } |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 172 | mStack.removeTask(this); |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 173 | mService.mTaskIdToTask.delete(mTaskId); |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 174 | } |
| 175 | |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 176 | void moveTaskToStack(TaskStack stack, boolean toTop) { |
| 177 | if (stack == mStack) { |
| 178 | return; |
| 179 | } |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 180 | if (DEBUG_STACK) Slog.i(TAG_WM, "moveTaskToStack: removing taskId=" + mTaskId |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 181 | + " from stack=" + mStack); |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 182 | EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask"); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 183 | if (mStack != null) { |
| 184 | mStack.removeTask(this); |
| 185 | } |
| 186 | stack.addTask(this, toTop); |
| 187 | } |
| 188 | |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 189 | void positionTaskInStack(TaskStack stack, int position, Rect bounds, Configuration config) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 190 | if (mStack != null && stack != mStack) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 191 | if (DEBUG_STACK) Slog.i(TAG_WM, "positionTaskInStack: removing taskId=" + mTaskId |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 192 | + " from stack=" + mStack); |
| 193 | EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask"); |
| 194 | mStack.removeTask(this); |
| 195 | } |
| 196 | stack.positionTask(this, position, showForAllUsers()); |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 197 | setBounds(bounds, config); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 200 | boolean removeAppToken(AppWindowToken wtoken) { |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 201 | boolean removed = mAppTokens.remove(wtoken); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 202 | if (mAppTokens.size() == 0) { |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 203 | EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, |
Craig Mautner | 2c2549c | 2013-11-12 08:31:15 -0800 | [diff] [blame] | 204 | "removeAppToken: last token"); |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 205 | if (mDeferRemoval) { |
| 206 | removeLocked(); |
| 207 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 208 | } |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 209 | wtoken.mTask = null; |
| 210 | /* Leave mTaskId for now, it might be useful for debug |
| 211 | wtoken.mTaskId = -1; |
| 212 | */ |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 213 | return removed; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 214 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 215 | |
Craig Mautner | cbd84af | 2014-10-22 13:21:22 -0700 | [diff] [blame] | 216 | void setSendingToBottom(boolean toBottom) { |
| 217 | for (int appTokenNdx = 0; appTokenNdx < mAppTokens.size(); appTokenNdx++) { |
| 218 | mAppTokens.get(appTokenNdx).sendingToBottom = toBottom; |
| 219 | } |
| 220 | } |
| 221 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 222 | /** Set the task bounds. Passing in null sets the bounds to fullscreen. */ |
Wale Ogunwale | 2cc92f5 | 2015-09-09 13:12:10 -0700 | [diff] [blame] | 223 | int setBounds(Rect bounds, Configuration config) { |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 224 | if (config == null) { |
| 225 | config = Configuration.EMPTY; |
| 226 | } |
| 227 | if (bounds == null && !Configuration.EMPTY.equals(config)) { |
| 228 | throw new IllegalArgumentException("null bounds but non empty configuration: " |
| 229 | + config); |
| 230 | } |
| 231 | if (bounds != null && Configuration.EMPTY.equals(config)) { |
| 232 | throw new IllegalArgumentException("non null bounds, but empty configuration"); |
| 233 | } |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 234 | boolean oldFullscreen = mFullscreen; |
| 235 | int rotation = Surface.ROTATION_0; |
| 236 | final DisplayContent displayContent = mStack.getDisplayContent(); |
| 237 | if (displayContent != null) { |
| 238 | displayContent.getLogicalDisplayRect(mTmpRect); |
| 239 | rotation = displayContent.getDisplayInfo().rotation; |
| 240 | if (bounds == null) { |
| 241 | bounds = mTmpRect; |
| 242 | mFullscreen = true; |
| 243 | } else { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 244 | mFullscreen = mTmpRect.equals(bounds); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | if (bounds == null) { |
| 249 | // Can't set to fullscreen if we don't have a display to get bounds from... |
Wale Ogunwale | 2cc92f5 | 2015-09-09 13:12:10 -0700 | [diff] [blame] | 250 | return BOUNDS_CHANGE_NONE; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 251 | } |
| 252 | if (mBounds.equals(bounds) && oldFullscreen == mFullscreen && mRotation == rotation) { |
Wale Ogunwale | 2cc92f5 | 2015-09-09 13:12:10 -0700 | [diff] [blame] | 253 | return BOUNDS_CHANGE_NONE; |
| 254 | } |
| 255 | |
| 256 | int boundsChange = BOUNDS_CHANGE_NONE; |
Chong Zhang | 48a87a5 | 2015-12-03 15:36:21 -0800 | [diff] [blame] | 257 | if (mBounds.left != bounds.left || mBounds.top != bounds.top) { |
Wale Ogunwale | 2cc92f5 | 2015-09-09 13:12:10 -0700 | [diff] [blame] | 258 | boundsChange |= BOUNDS_CHANGE_POSITION; |
| 259 | } |
| 260 | if (mBounds.width() != bounds.width() || mBounds.height() != bounds.height()) { |
| 261 | boundsChange |= BOUNDS_CHANGE_SIZE; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | mBounds.set(bounds); |
| 265 | mRotation = rotation; |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 266 | if (displayContent != null) { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 267 | displayContent.mDimLayerController.updateDimLayer(this); |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 268 | } |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 269 | mOverrideConfig = mFullscreen ? Configuration.EMPTY : config; |
Wale Ogunwale | 2cc92f5 | 2015-09-09 13:12:10 -0700 | [diff] [blame] | 270 | return boundsChange; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 273 | /** |
| 274 | * Sets the bounds used to calculate the insets. See |
| 275 | * {@link android.app.IActivityManager#resizeDockedStack} why this is needed. |
| 276 | */ |
| 277 | void setTempInsetBounds(Rect tempInsetBounds) { |
| 278 | if (tempInsetBounds != null) { |
| 279 | mTempInsetBounds.set(tempInsetBounds); |
| 280 | } else { |
| 281 | mTempInsetBounds.setEmpty(); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * Gets the bounds used to calculate the insets. See |
| 287 | * {@link android.app.IActivityManager#resizeDockedStack} why this is needed. |
| 288 | */ |
| 289 | void getTempInsetBounds(Rect out) { |
| 290 | out.set(mTempInsetBounds); |
| 291 | } |
| 292 | |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 293 | void setResizeable(boolean resizeable) { |
| 294 | mResizeable = resizeable; |
| 295 | } |
| 296 | |
| 297 | boolean isResizeable() { |
| 298 | return mResizeable; |
| 299 | } |
| 300 | |
Chong Zhang | 87b2172 | 2015-09-21 15:39:51 -0700 | [diff] [blame] | 301 | boolean resizeLocked(Rect bounds, Configuration configuration, boolean forced) { |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 302 | int boundsChanged = setBounds(bounds, configuration); |
Chong Zhang | 87b2172 | 2015-09-21 15:39:51 -0700 | [diff] [blame] | 303 | if (forced) { |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 304 | boundsChanged |= BOUNDS_CHANGE_SIZE; |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 305 | } |
| 306 | if (boundsChanged == BOUNDS_CHANGE_NONE) { |
| 307 | return false; |
| 308 | } |
| 309 | if ((boundsChanged & BOUNDS_CHANGE_SIZE) == BOUNDS_CHANGE_SIZE) { |
| 310 | resizeWindows(); |
Chong Zhang | bd0d937 | 2015-12-28 15:18:29 -0800 | [diff] [blame] | 311 | } else { |
| 312 | moveWindows(); |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 313 | } |
| 314 | return true; |
| 315 | } |
| 316 | |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 317 | boolean scrollLocked(Rect bounds) { |
| 318 | // shift the task bound if it doesn't fully cover the stack area |
| 319 | mStack.getDimBounds(mTmpRect); |
| 320 | if (mService.mCurConfiguration.orientation == ORIENTATION_LANDSCAPE) { |
| 321 | if (bounds.left > mTmpRect.left) { |
| 322 | bounds.left = mTmpRect.left; |
| 323 | bounds.right = mTmpRect.left + mBounds.width(); |
| 324 | } else if (bounds.right < mTmpRect.right) { |
| 325 | bounds.left = mTmpRect.right - mBounds.width(); |
| 326 | bounds.right = mTmpRect.right; |
| 327 | } |
| 328 | } else { |
| 329 | if (bounds.top > mTmpRect.top) { |
| 330 | bounds.top = mTmpRect.top; |
| 331 | bounds.bottom = mTmpRect.top + mBounds.height(); |
| 332 | } else if (bounds.bottom < mTmpRect.bottom) { |
| 333 | bounds.top = mTmpRect.bottom - mBounds.height(); |
| 334 | bounds.bottom = mTmpRect.bottom; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | if (bounds.equals(mBounds)) { |
| 339 | return false; |
| 340 | } |
| 341 | // Normal setBounds() does not allow non-null bounds for fullscreen apps. |
| 342 | // We only change bounds for the scrolling case without change it size, |
| 343 | // on resizing path we should still want the validation. |
| 344 | mBounds.set(bounds); |
| 345 | for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) { |
| 346 | final ArrayList<WindowState> windows = mAppTokens.get(activityNdx).allAppWindows; |
| 347 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
| 348 | final WindowState win = windows.get(winNdx); |
| 349 | win.mXOffset = bounds.left; |
| 350 | win.mYOffset = bounds.top; |
| 351 | } |
| 352 | } |
| 353 | return true; |
| 354 | } |
| 355 | |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 356 | /** Return true if the current bound can get outputted to the rest of the system as-is. */ |
| 357 | private boolean useCurrentBounds() { |
| 358 | final DisplayContent displayContent = mStack.getDisplayContent(); |
| 359 | if (mFullscreen |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 360 | || !StackId.isTaskResizeableByDockedStack(mStack.mStackId) |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 361 | || displayContent == null |
| 362 | || displayContent.getDockedStackLocked() != null) { |
| 363 | return true; |
| 364 | } |
| 365 | return false; |
| 366 | } |
| 367 | |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 368 | /** Original bounds of the task if applicable, otherwise fullscreen rect. */ |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 369 | public void getBounds(Rect out) { |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 370 | if (useCurrentBounds()) { |
| 371 | // No need to adjust the output bounds if fullscreen or the docked stack is visible |
| 372 | // since it is already what we want to represent to the rest of the system. |
| 373 | out.set(mBounds); |
| 374 | return; |
| 375 | } |
| 376 | |
| 377 | // The bounds has been adjusted to accommodate for a docked stack, but the docked stack |
| 378 | // is not currently visible. Go ahead a represent it as fullscreen to the rest of the |
| 379 | // system. |
| 380 | mStack.getDisplayContent().getLogicalDisplayRect(out); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 383 | /** |
| 384 | * Calculate the maximum visible area of this task. If the task has only one app, |
| 385 | * the result will be visible frame of that app. If the task has more than one apps, |
| 386 | * we search from top down if the next app got different visible area. |
| 387 | * |
| 388 | * This effort is to handle the case where some task (eg. GMail composer) might pop up |
| 389 | * a dialog that's different in size from the activity below, in which case we should |
| 390 | * be dimming the entire task area behind the dialog. |
| 391 | * |
| 392 | * @param out Rect containing the max visible bounds. |
| 393 | * @return true if the task has some visible app windows; false otherwise. |
| 394 | */ |
| 395 | boolean getMaxVisibleBounds(Rect out) { |
| 396 | boolean foundTop = false; |
| 397 | for (int i = mAppTokens.size() - 1; i >= 0; i--) { |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 398 | final AppWindowToken token = mAppTokens.get(i); |
| 399 | // skip hidden (or about to hide) apps |
| 400 | if (token.mIsExiting || token.clientHidden || token.hiddenRequested) { |
| 401 | continue; |
| 402 | } |
| 403 | final WindowState win = token.findMainWindow(); |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 404 | if (win == null) { |
| 405 | continue; |
| 406 | } |
| 407 | if (!foundTop) { |
| 408 | out.set(win.mVisibleFrame); |
| 409 | foundTop = true; |
| 410 | continue; |
| 411 | } |
| 412 | if (win.mVisibleFrame.left < out.left) { |
| 413 | out.left = win.mVisibleFrame.left; |
| 414 | } |
| 415 | if (win.mVisibleFrame.top < out.top) { |
| 416 | out.top = win.mVisibleFrame.top; |
| 417 | } |
| 418 | if (win.mVisibleFrame.right > out.right) { |
| 419 | out.right = win.mVisibleFrame.right; |
| 420 | } |
| 421 | if (win.mVisibleFrame.bottom > out.bottom) { |
| 422 | out.bottom = win.mVisibleFrame.bottom; |
| 423 | } |
| 424 | } |
| 425 | return foundTop; |
| 426 | } |
| 427 | |
| 428 | /** Bounds of the task to be used for dimming, as well as touch related tests. */ |
| 429 | @Override |
| 430 | public void getDimBounds(Rect out) { |
| 431 | if (useCurrentBounds()) { |
| 432 | if (inFreeformWorkspace() && getMaxVisibleBounds(out)) { |
| 433 | return; |
| 434 | } |
| 435 | |
| 436 | out.set(mBounds); |
| 437 | return; |
| 438 | } |
| 439 | |
| 440 | // The bounds has been adjusted to accommodate for a docked stack, but the docked stack |
| 441 | // is not currently visible. Go ahead a represent it as fullscreen to the rest of the |
| 442 | // system. |
| 443 | mStack.getDisplayContent().getLogicalDisplayRect(out); |
| 444 | } |
| 445 | |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 446 | void setDragResizing(boolean dragResizing) { |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 447 | mDragResizing = dragResizing; |
| 448 | } |
| 449 | |
| 450 | boolean isDragResizing() { |
| 451 | return mDragResizing; |
| 452 | } |
| 453 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 454 | void updateDisplayInfo(final DisplayContent displayContent) { |
| 455 | if (displayContent == null) { |
| 456 | return; |
| 457 | } |
| 458 | if (mFullscreen) { |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 459 | setBounds(null, Configuration.EMPTY); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 460 | return; |
| 461 | } |
| 462 | final int newRotation = displayContent.getDisplayInfo().rotation; |
| 463 | if (mRotation == newRotation) { |
| 464 | return; |
| 465 | } |
| 466 | |
| 467 | // Device rotation changed. We don't want the task to move around on the screen when |
| 468 | // this happens, so update the task bounds so it stays in the same place. |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 469 | mTmpRect2.set(mBounds); |
| 470 | displayContent.rotateBounds(mRotation, newRotation, mTmpRect2); |
Wale Ogunwale | 1ed0d89 | 2015-09-28 13:27:44 -0700 | [diff] [blame] | 471 | if (setBounds(mTmpRect2, mOverrideConfig) != BOUNDS_CHANGE_NONE) { |
| 472 | // Post message to inform activity manager of the bounds change simulating |
| 473 | // a one-way call. We do this to prevent a deadlock between window manager |
Filip Gruszczynski | 44bc4da | 2015-10-03 13:59:49 -0700 | [diff] [blame] | 474 | // lock and activity manager lock been held. Only tasks within the freeform stack |
| 475 | // are resizeable independently of their stack resizing. |
| 476 | if (mStack.mStackId == FREEFORM_WORKSPACE_STACK_ID) { |
| 477 | mService.mH.sendMessage(mService.mH.obtainMessage( |
| 478 | RESIZE_TASK, mTaskId, RESIZE_MODE_SYSTEM_SCREEN_ROTATION, mBounds)); |
| 479 | } |
Wale Ogunwale | 1ed0d89 | 2015-09-28 13:27:44 -0700 | [diff] [blame] | 480 | } |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 483 | void resizeWindows() { |
| 484 | final ArrayList<WindowState> resizingWindows = mService.mResizingWindows; |
| 485 | for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) { |
| 486 | final ArrayList<WindowState> windows = mAppTokens.get(activityNdx).allAppWindows; |
| 487 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
| 488 | final WindowState win = windows.get(winNdx); |
| 489 | if (!resizingWindows.contains(win)) { |
Chong Zhang | bd0d937 | 2015-12-28 15:18:29 -0800 | [diff] [blame] | 490 | if (DEBUG_RESIZE) Slog.d(TAG_WM, "resizeWindows: Resizing " + win); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 491 | resizingWindows.add(win); |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | } |
| 496 | |
Chong Zhang | bd0d937 | 2015-12-28 15:18:29 -0800 | [diff] [blame] | 497 | void moveWindows() { |
| 498 | for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) { |
| 499 | final ArrayList<WindowState> windows = mAppTokens.get(activityNdx).allAppWindows; |
| 500 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
| 501 | final WindowState win = windows.get(winNdx); |
| 502 | if (DEBUG_RESIZE) Slog.d(TAG_WM, "moveWindows: Moving " + win); |
| 503 | win.mMovedByResize = true; |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | |
Winson | c28098f | 2015-10-30 14:50:19 -0700 | [diff] [blame] | 508 | /** |
| 509 | * Cancels any running app transitions associated with the task. |
| 510 | */ |
| 511 | void cancelTaskWindowTransition() { |
| 512 | for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) { |
| 513 | mAppTokens.get(activityNdx).mAppAnimator.clearAnimation(); |
| 514 | } |
| 515 | } |
| 516 | |
Winson | 13d3066 | 2015-11-06 15:30:29 -0800 | [diff] [blame] | 517 | /** |
| 518 | * Cancels any running thumbnail transitions associated with the task. |
| 519 | */ |
| 520 | void cancelTaskThumbnailTransition() { |
| 521 | for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) { |
| 522 | mAppTokens.get(activityNdx).mAppAnimator.clearThumbnail(); |
| 523 | } |
| 524 | } |
| 525 | |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 526 | boolean showForAllUsers() { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 527 | final int tokensCount = mAppTokens.size(); |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 528 | return (tokensCount != 0) && mAppTokens.get(tokensCount - 1).showForAllUsers; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 529 | } |
| 530 | |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 531 | boolean inHomeStack() { |
| 532 | return mStack != null && mStack.mStackId == HOME_STACK_ID; |
| 533 | } |
| 534 | |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 535 | boolean inFreeformWorkspace() { |
| 536 | return mStack != null && mStack.mStackId == FREEFORM_WORKSPACE_STACK_ID; |
| 537 | } |
| 538 | |
Filip Gruszczynski | 955b2fc | 2015-10-15 14:46:07 -0700 | [diff] [blame] | 539 | boolean inDockedWorkspace() { |
| 540 | return mStack != null && mStack.mStackId == DOCKED_STACK_ID; |
| 541 | } |
| 542 | |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 543 | boolean isResizeableByDockedStack() { |
| 544 | return mStack != null && getDisplayContent().getDockedStackLocked() != null && |
| 545 | StackId.isTaskResizeableByDockedStack(mStack.mStackId); |
| 546 | } |
| 547 | |
| 548 | /** |
| 549 | * Whether the task should be treated as if it's docked. Returns true if the task |
| 550 | * is currently in docked workspace, or it's side-by-side to a docked task. |
| 551 | */ |
| 552 | boolean isDockedInEffect() { |
| 553 | return inDockedWorkspace() || isResizeableByDockedStack(); |
| 554 | } |
| 555 | |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 556 | WindowState getTopVisibleAppMainWindow() { |
| 557 | final AppWindowToken token = getTopVisibleAppToken(); |
| 558 | return token != null ? token.findMainWindow() : null; |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 559 | } |
| 560 | |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 561 | AppWindowToken getTopVisibleAppToken() { |
| 562 | for (int i = mAppTokens.size() - 1; i >= 0; i--) { |
| 563 | final AppWindowToken token = mAppTokens.get(i); |
| 564 | // skip hidden (or about to hide) apps |
| 565 | if (!token.mIsExiting && !token.clientHidden && !token.hiddenRequested) { |
| 566 | return token; |
| 567 | } |
| 568 | } |
| 569 | return null; |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 572 | @Override |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 573 | public boolean isFullscreen() { |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 574 | if (useCurrentBounds()) { |
| 575 | return mFullscreen; |
| 576 | } |
| 577 | // The bounds has been adjusted to accommodate for a docked stack, but the docked stack |
| 578 | // is not currently visible. Go ahead a represent it as fullscreen to the rest of the |
| 579 | // system. |
| 580 | return true; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | @Override |
| 584 | public DisplayInfo getDisplayInfo() { |
| 585 | return mStack.getDisplayContent().getDisplayInfo(); |
| 586 | } |
| 587 | |
| 588 | @Override |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 589 | public String toString() { |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 590 | return "{taskId=" + mTaskId + " appTokens=" + mAppTokens + " mdr=" + mDeferRemoval + "}"; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 591 | } |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 592 | |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 593 | @Override |
| 594 | public String toShortString() { |
| 595 | return "Task=" + mTaskId; |
| 596 | } |
| 597 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 598 | public void printTo(String prefix, PrintWriter pw) { |
Wale Ogunwale | 56b88af | 2015-12-01 07:21:59 -0800 | [diff] [blame] | 599 | pw.print(prefix); pw.print("taskId="); pw.println(mTaskId); |
| 600 | pw.print(prefix + prefix); pw.print("mFullscreen="); pw.println(mFullscreen); |
| 601 | pw.print(prefix + prefix); pw.print("mBounds="); pw.println(mBounds.toShortString()); |
| 602 | pw.print(prefix + prefix); pw.print("mdr="); pw.println(mDeferRemoval); |
| 603 | pw.print(prefix + prefix); pw.print("appTokens="); pw.println(mAppTokens); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 604 | } |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 605 | } |