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