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