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; |
Jorim Jaggi | 5160527 | 2016-02-24 18:06:49 -0500 | [diff] [blame] | 22 | import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE; |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 23 | import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 24 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
Wale Ogunwale | 1ed0d89 | 2015-09-28 13:27:44 -0700 | [diff] [blame] | 25 | import static android.app.ActivityManager.RESIZE_MODE_SYSTEM_SCREEN_ROTATION; |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 26 | import static android.content.pm.ActivityInfo.RESIZE_MODE_CROP_WINDOWS; |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 27 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 28 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
| 29 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE; |
| 30 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK; |
Wale Ogunwale | 1ed0d89 | 2015-09-28 13:27:44 -0700 | [diff] [blame] | 31 | import static com.android.server.wm.WindowManagerService.H.RESIZE_TASK; |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 32 | import static com.android.server.wm.WindowManagerService.H.SHOW_NON_RESIZEABLE_DOCK_TOAST; |
| 33 | import static android.view.WindowManager.DOCKED_INVALID; |
| 34 | import static android.view.WindowManager.DOCKED_LEFT; |
| 35 | import static android.view.WindowManager.DOCKED_RIGHT; |
| 36 | import static android.view.WindowManager.DOCKED_TOP; |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 37 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 38 | import android.app.ActivityManager.StackId; |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 39 | import android.content.pm.ActivityInfo; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 40 | import android.content.res.Configuration; |
| 41 | import android.graphics.Rect; |
Craig Mautner | 2c2549c | 2013-11-12 08:31:15 -0800 | [diff] [blame] | 42 | import android.util.EventLog; |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 43 | import android.util.Slog; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 44 | import android.view.DisplayInfo; |
| 45 | import android.view.Surface; |
| 46 | |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 47 | import com.android.internal.R; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 48 | import com.android.server.EventLogTags; |
Craig Mautner | 2c2549c | 2013-11-12 08:31:15 -0800 | [diff] [blame] | 49 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 50 | import java.io.PrintWriter; |
| 51 | import java.util.ArrayList; |
| 52 | |
| 53 | class Task implements DimLayer.DimLayerUser { |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 54 | static final String TAG = TAG_WITH_CLASS_NAME ? "Task" : TAG_WM; |
Wale Ogunwale | 2cc92f5 | 2015-09-09 13:12:10 -0700 | [diff] [blame] | 55 | // Return value from {@link setBounds} indicating no change was made to the Task bounds. |
| 56 | static final int BOUNDS_CHANGE_NONE = 0; |
| 57 | // Return value from {@link setBounds} indicating the position of the Task bounds changed. |
| 58 | static final int BOUNDS_CHANGE_POSITION = 1; |
| 59 | // Return value from {@link setBounds} indicating the size of the Task bounds changed. |
| 60 | static final int BOUNDS_CHANGE_SIZE = 1 << 1; |
| 61 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 62 | TaskStack mStack; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 63 | final AppTokenList mAppTokens = new AppTokenList(); |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 64 | final int mTaskId; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 65 | final int mUserId; |
Craig Mautner | 9ef471f | 2014-02-07 13:11:47 -0800 | [diff] [blame] | 66 | boolean mDeferRemoval = false; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 67 | final WindowManagerService mService; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 68 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 69 | // Content limits relative to the DisplayContent this sits in. |
| 70 | private Rect mBounds = new Rect(); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 71 | final Rect mPreparedFrozenBounds = new Rect(); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 72 | |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 73 | private Rect mPreScrollBounds = new Rect(); |
| 74 | private boolean mScrollValid; |
| 75 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 76 | // Bounds used to calculate the insets. |
| 77 | private final Rect mTempInsetBounds = new Rect(); |
| 78 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 79 | // Device rotation as of the last time {@link #mBounds} was set. |
| 80 | int mRotation; |
| 81 | |
| 82 | // Whether mBounds is fullscreen |
| 83 | private boolean mFullscreen = true; |
| 84 | |
| 85 | // Contains configurations settings that are different from the global configuration due to |
| 86 | // stack specific operations. E.g. {@link #setBounds}. |
| 87 | Configuration mOverrideConfig; |
| 88 | |
| 89 | // For comparison with DisplayContent bounds. |
| 90 | private Rect mTmpRect = new Rect(); |
| 91 | // For handling display rotations. |
| 92 | private Rect mTmpRect2 = new Rect(); |
| 93 | |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 94 | // Resize mode of the task. See {@link ActivityInfo#resizeMode} |
| 95 | private int mResizeMode; |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 96 | |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 97 | // Whether we need to show toast about the app being non-resizeable when it becomes visible. |
| 98 | // This flag is set when a non-resizeable task is docked (or side-by-side). It's cleared |
| 99 | // after we show the toast. |
| 100 | private boolean mShowNonResizeableDockToast; |
| 101 | |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 102 | // Whether the task is currently being drag-resized |
| 103 | private boolean mDragResizing; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 104 | private int mDragResizeMode; |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 105 | |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 106 | private boolean mHomeTask; |
| 107 | |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 108 | Task(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds, |
| 109 | Configuration config) { |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 110 | mTaskId = taskId; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 111 | mStack = stack; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 112 | mUserId = userId; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 113 | mService = service; |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 114 | setBounds(bounds, config); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | DisplayContent getDisplayContent() { |
| 118 | return mStack.getDisplayContent(); |
| 119 | } |
| 120 | |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 121 | void setShowNonResizeableDockToast() { |
| 122 | mShowNonResizeableDockToast = true; |
| 123 | } |
| 124 | |
| 125 | void scheduleShowNonResizeableDockToastIfNeeded() { |
| 126 | if (!mShowNonResizeableDockToast) { |
| 127 | return; |
| 128 | } |
| 129 | final DisplayContent displayContent = mStack.getDisplayContent(); |
| 130 | // If docked stack is not yet visible, we don't want to show the toast yet, |
| 131 | // since we need the visible rect of the docked task to position the toast. |
| 132 | if (displayContent == null || displayContent.getDockedStackLocked() == null) { |
| 133 | return; |
| 134 | } |
| 135 | |
| 136 | mShowNonResizeableDockToast = false; |
| 137 | |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 138 | if (mResizeMode == RESIZE_MODE_UNRESIZEABLE) { |
| 139 | final String text = |
| 140 | mService.mContext.getString(R.string.dock_non_resizeble_failed_to_dock_text); |
| 141 | mService.mH.obtainMessage(SHOW_NON_RESIZEABLE_DOCK_TOAST, 0, 0, text).sendToTarget(); |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 142 | } |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 143 | } |
| 144 | |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 145 | void addAppToken(int addPos, AppWindowToken wtoken, int resizeMode, boolean homeTask) { |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 146 | final int lastPos = mAppTokens.size(); |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 147 | if (addPos >= lastPos) { |
| 148 | addPos = lastPos; |
| 149 | } else { |
| 150 | for (int pos = 0; pos < lastPos && pos < addPos; ++pos) { |
| 151 | if (mAppTokens.get(pos).removed) { |
| 152 | // addPos assumes removed tokens are actually gone. |
| 153 | ++addPos; |
| 154 | } |
Craig Mautner | 01f79cf | 2014-08-27 09:56:02 -0700 | [diff] [blame] | 155 | } |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 156 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 157 | mAppTokens.add(addPos, wtoken); |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 158 | wtoken.mTask = this; |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 159 | mDeferRemoval = false; |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 160 | mResizeMode = resizeMode; |
| 161 | mHomeTask = homeTask; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 162 | } |
| 163 | |
Chong Zhang | 7e8eeb7 | 2016-01-06 19:14:47 -0800 | [diff] [blame] | 164 | private boolean hasAppTokensAlive() { |
| 165 | for (int i = mAppTokens.size() - 1; i >= 0; i--) { |
| 166 | if (!mAppTokens.get(i).appDied) { |
| 167 | return true; |
| 168 | } |
| 169 | } |
| 170 | return false; |
| 171 | } |
| 172 | |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 173 | void removeLocked() { |
Chong Zhang | 7e8eeb7 | 2016-01-06 19:14:47 -0800 | [diff] [blame] | 174 | if (hasAppTokensAlive() && mStack.isAnimating()) { |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 175 | if (DEBUG_STACK) Slog.i(TAG, "removeTask: deferring removing taskId=" + mTaskId); |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 176 | mDeferRemoval = true; |
| 177 | return; |
| 178 | } |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 179 | if (DEBUG_STACK) Slog.i(TAG, "removeTask: removing taskId=" + mTaskId); |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 180 | EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "removeTask"); |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 181 | mDeferRemoval = false; |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 182 | DisplayContent content = getDisplayContent(); |
| 183 | if (content != null) { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 184 | content.mDimLayerController.removeDimLayerUser(this); |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 185 | } |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 186 | mStack.removeTask(this); |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 187 | mService.mTaskIdToTask.delete(mTaskId); |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 188 | } |
| 189 | |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 190 | void moveTaskToStack(TaskStack stack, boolean toTop) { |
| 191 | if (stack == mStack) { |
| 192 | return; |
| 193 | } |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 194 | if (DEBUG_STACK) Slog.i(TAG, "moveTaskToStack: removing taskId=" + mTaskId |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 195 | + " from stack=" + mStack); |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 196 | EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask"); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 197 | if (mStack != null) { |
| 198 | mStack.removeTask(this); |
| 199 | } |
| 200 | stack.addTask(this, toTop); |
| 201 | } |
| 202 | |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 203 | void positionTaskInStack(TaskStack stack, int position, Rect bounds, Configuration config) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 204 | if (mStack != null && stack != mStack) { |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 205 | if (DEBUG_STACK) Slog.i(TAG, "positionTaskInStack: removing taskId=" + mTaskId |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 206 | + " from stack=" + mStack); |
| 207 | EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask"); |
| 208 | mStack.removeTask(this); |
| 209 | } |
| 210 | stack.positionTask(this, position, showForAllUsers()); |
Jorim Jaggi | 8fa4522 | 2016-02-19 19:54:39 -0800 | [diff] [blame] | 211 | resizeLocked(bounds, config, false /* force */); |
Jorim Jaggi | 5e6968d | 2016-02-19 18:02:13 -0800 | [diff] [blame] | 212 | |
| 213 | for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) { |
| 214 | final ArrayList<WindowState> windows = mAppTokens.get(activityNdx).allAppWindows; |
| 215 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
| 216 | final WindowState win = windows.get(winNdx); |
| 217 | win.notifyMovedInStack(); |
| 218 | } |
| 219 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 222 | boolean removeAppToken(AppWindowToken wtoken) { |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 223 | boolean removed = mAppTokens.remove(wtoken); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 224 | if (mAppTokens.size() == 0) { |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 225 | EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "removeAppToken: last token"); |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 226 | if (mDeferRemoval) { |
| 227 | removeLocked(); |
| 228 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 229 | } |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 230 | wtoken.mTask = null; |
| 231 | /* Leave mTaskId for now, it might be useful for debug |
| 232 | wtoken.mTaskId = -1; |
| 233 | */ |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 234 | return removed; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 235 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 236 | |
Craig Mautner | cbd84af | 2014-10-22 13:21:22 -0700 | [diff] [blame] | 237 | void setSendingToBottom(boolean toBottom) { |
| 238 | for (int appTokenNdx = 0; appTokenNdx < mAppTokens.size(); appTokenNdx++) { |
| 239 | mAppTokens.get(appTokenNdx).sendingToBottom = toBottom; |
| 240 | } |
| 241 | } |
| 242 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 243 | /** Set the task bounds. Passing in null sets the bounds to fullscreen. */ |
Jorim Jaggi | 8fa4522 | 2016-02-19 19:54:39 -0800 | [diff] [blame] | 244 | private int setBounds(Rect bounds, Configuration config) { |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 245 | if (config == null) { |
| 246 | config = Configuration.EMPTY; |
| 247 | } |
| 248 | if (bounds == null && !Configuration.EMPTY.equals(config)) { |
| 249 | throw new IllegalArgumentException("null bounds but non empty configuration: " |
| 250 | + config); |
| 251 | } |
| 252 | if (bounds != null && Configuration.EMPTY.equals(config)) { |
| 253 | throw new IllegalArgumentException("non null bounds, but empty configuration"); |
| 254 | } |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 255 | boolean oldFullscreen = mFullscreen; |
| 256 | int rotation = Surface.ROTATION_0; |
| 257 | final DisplayContent displayContent = mStack.getDisplayContent(); |
| 258 | if (displayContent != null) { |
| 259 | displayContent.getLogicalDisplayRect(mTmpRect); |
| 260 | rotation = displayContent.getDisplayInfo().rotation; |
Jorim Jaggi | 067e817 | 2016-02-03 18:24:12 -0800 | [diff] [blame] | 261 | mFullscreen = bounds == null; |
| 262 | if (mFullscreen) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 263 | bounds = mTmpRect; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
| 267 | if (bounds == null) { |
| 268 | // 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] | 269 | return BOUNDS_CHANGE_NONE; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 270 | } |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 271 | if (mPreScrollBounds.equals(bounds) && oldFullscreen == mFullscreen && mRotation == rotation) { |
Wale Ogunwale | 2cc92f5 | 2015-09-09 13:12:10 -0700 | [diff] [blame] | 272 | return BOUNDS_CHANGE_NONE; |
| 273 | } |
| 274 | |
| 275 | int boundsChange = BOUNDS_CHANGE_NONE; |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 276 | if (mPreScrollBounds.left != bounds.left || mPreScrollBounds.top != bounds.top) { |
Wale Ogunwale | 2cc92f5 | 2015-09-09 13:12:10 -0700 | [diff] [blame] | 277 | boundsChange |= BOUNDS_CHANGE_POSITION; |
| 278 | } |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 279 | if (mPreScrollBounds.width() != bounds.width() || mPreScrollBounds.height() != bounds.height()) { |
Wale Ogunwale | 2cc92f5 | 2015-09-09 13:12:10 -0700 | [diff] [blame] | 280 | boundsChange |= BOUNDS_CHANGE_SIZE; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 283 | |
| 284 | mPreScrollBounds.set(bounds); |
| 285 | |
| 286 | resetScrollLocked(); |
| 287 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 288 | mRotation = rotation; |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 289 | if (displayContent != null) { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 290 | displayContent.mDimLayerController.updateDimLayer(this); |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 291 | } |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 292 | mOverrideConfig = mFullscreen ? Configuration.EMPTY : config; |
Wale Ogunwale | 2cc92f5 | 2015-09-09 13:12:10 -0700 | [diff] [blame] | 293 | return boundsChange; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 296 | /** |
| 297 | * Sets the bounds used to calculate the insets. See |
| 298 | * {@link android.app.IActivityManager#resizeDockedStack} why this is needed. |
| 299 | */ |
| 300 | void setTempInsetBounds(Rect tempInsetBounds) { |
| 301 | if (tempInsetBounds != null) { |
| 302 | mTempInsetBounds.set(tempInsetBounds); |
| 303 | } else { |
| 304 | mTempInsetBounds.setEmpty(); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * Gets the bounds used to calculate the insets. See |
| 310 | * {@link android.app.IActivityManager#resizeDockedStack} why this is needed. |
| 311 | */ |
| 312 | void getTempInsetBounds(Rect out) { |
| 313 | out.set(mTempInsetBounds); |
| 314 | } |
| 315 | |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 316 | void setResizeable(int resizeMode) { |
| 317 | mResizeMode = resizeMode; |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | boolean isResizeable() { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 321 | return !mHomeTask |
| 322 | && (ActivityInfo.isResizeableMode(mResizeMode) || mService.mForceResizableTasks); |
| 323 | } |
| 324 | |
| 325 | boolean cropWindowsToStackBounds() { |
| 326 | return !mHomeTask && (isResizeable() || mResizeMode == RESIZE_MODE_CROP_WINDOWS); |
| 327 | } |
| 328 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 329 | boolean isHomeTask() { |
| 330 | return mHomeTask; |
| 331 | } |
| 332 | |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 333 | private boolean inCropWindowsResizeMode() { |
| 334 | return !mHomeTask && !isResizeable() && mResizeMode == RESIZE_MODE_CROP_WINDOWS; |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 335 | } |
| 336 | |
Chong Zhang | 87b2172 | 2015-09-21 15:39:51 -0700 | [diff] [blame] | 337 | boolean resizeLocked(Rect bounds, Configuration configuration, boolean forced) { |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 338 | int boundsChanged = setBounds(bounds, configuration); |
Chong Zhang | 87b2172 | 2015-09-21 15:39:51 -0700 | [diff] [blame] | 339 | if (forced) { |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 340 | boundsChanged |= BOUNDS_CHANGE_SIZE; |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 341 | } |
| 342 | if (boundsChanged == BOUNDS_CHANGE_NONE) { |
| 343 | return false; |
| 344 | } |
| 345 | if ((boundsChanged & BOUNDS_CHANGE_SIZE) == BOUNDS_CHANGE_SIZE) { |
| 346 | resizeWindows(); |
Chong Zhang | bd0d937 | 2015-12-28 15:18:29 -0800 | [diff] [blame] | 347 | } else { |
| 348 | moveWindows(); |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 349 | } |
| 350 | return true; |
| 351 | } |
| 352 | |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 353 | /** |
| 354 | * Prepares the task bounds to be frozen with the current size. See |
| 355 | * {@link AppWindowToken#freezeBounds}. |
| 356 | */ |
| 357 | void prepareFreezingBounds() { |
| 358 | mPreparedFrozenBounds.set(mBounds); |
| 359 | } |
| 360 | |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 361 | void resetScrollLocked() { |
| 362 | if (mScrollValid) { |
| 363 | mScrollValid = false; |
| 364 | applyScrollToAllWindows(0, 0); |
| 365 | } |
| 366 | mBounds.set(mPreScrollBounds); |
| 367 | } |
| 368 | |
| 369 | void applyScrollToAllWindows(final int xOffset, final int yOffset) { |
| 370 | for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) { |
| 371 | final ArrayList<WindowState> windows = mAppTokens.get(activityNdx).allAppWindows; |
| 372 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
| 373 | final WindowState win = windows.get(winNdx); |
| 374 | win.mXOffset = xOffset; |
| 375 | win.mYOffset = yOffset; |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | void applyScrollToWindowIfNeeded(final WindowState win) { |
| 381 | if (mScrollValid) { |
| 382 | win.mXOffset = mBounds.left; |
| 383 | win.mYOffset = mBounds.top; |
| 384 | } |
| 385 | } |
| 386 | |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 387 | boolean scrollLocked(Rect bounds) { |
| 388 | // shift the task bound if it doesn't fully cover the stack area |
| 389 | mStack.getDimBounds(mTmpRect); |
| 390 | if (mService.mCurConfiguration.orientation == ORIENTATION_LANDSCAPE) { |
| 391 | if (bounds.left > mTmpRect.left) { |
| 392 | bounds.left = mTmpRect.left; |
| 393 | bounds.right = mTmpRect.left + mBounds.width(); |
| 394 | } else if (bounds.right < mTmpRect.right) { |
| 395 | bounds.left = mTmpRect.right - mBounds.width(); |
| 396 | bounds.right = mTmpRect.right; |
| 397 | } |
| 398 | } else { |
| 399 | if (bounds.top > mTmpRect.top) { |
| 400 | bounds.top = mTmpRect.top; |
| 401 | bounds.bottom = mTmpRect.top + mBounds.height(); |
| 402 | } else if (bounds.bottom < mTmpRect.bottom) { |
| 403 | bounds.top = mTmpRect.bottom - mBounds.height(); |
| 404 | bounds.bottom = mTmpRect.bottom; |
| 405 | } |
| 406 | } |
| 407 | |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 408 | // We can stop here if we're already scrolling and the scrolled bounds not changed. |
| 409 | if (mScrollValid && bounds.equals(mBounds)) { |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 410 | return false; |
| 411 | } |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 412 | |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 413 | // Normal setBounds() does not allow non-null bounds for fullscreen apps. |
| 414 | // We only change bounds for the scrolling case without change it size, |
| 415 | // on resizing path we should still want the validation. |
| 416 | mBounds.set(bounds); |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 417 | mScrollValid = true; |
| 418 | applyScrollToAllWindows(bounds.left, bounds.top); |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 419 | return true; |
| 420 | } |
| 421 | |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 422 | /** Return true if the current bound can get outputted to the rest of the system as-is. */ |
| 423 | private boolean useCurrentBounds() { |
| 424 | final DisplayContent displayContent = mStack.getDisplayContent(); |
| 425 | if (mFullscreen |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 426 | || !StackId.isTaskResizeableByDockedStack(mStack.mStackId) |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 427 | || displayContent == null |
| 428 | || displayContent.getDockedStackLocked() != null) { |
| 429 | return true; |
| 430 | } |
| 431 | return false; |
| 432 | } |
| 433 | |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 434 | /** Original bounds of the task if applicable, otherwise fullscreen rect. */ |
Wale Ogunwale | ccb6ce2 | 2016-01-14 15:36:35 -0800 | [diff] [blame] | 435 | void getBounds(Rect out) { |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 436 | if (useCurrentBounds()) { |
| 437 | // No need to adjust the output bounds if fullscreen or the docked stack is visible |
| 438 | // since it is already what we want to represent to the rest of the system. |
| 439 | out.set(mBounds); |
| 440 | return; |
| 441 | } |
| 442 | |
Wale Ogunwale | ccb6ce2 | 2016-01-14 15:36:35 -0800 | [diff] [blame] | 443 | // The bounds has been adjusted to accommodate for a docked stack, but the docked stack is |
| 444 | // not currently visible. Go ahead a represent it as fullscreen to the rest of the system. |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 445 | mStack.getDisplayContent().getLogicalDisplayRect(out); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 448 | /** |
| 449 | * Calculate the maximum visible area of this task. If the task has only one app, |
| 450 | * the result will be visible frame of that app. If the task has more than one apps, |
| 451 | * we search from top down if the next app got different visible area. |
| 452 | * |
| 453 | * This effort is to handle the case where some task (eg. GMail composer) might pop up |
| 454 | * a dialog that's different in size from the activity below, in which case we should |
| 455 | * be dimming the entire task area behind the dialog. |
| 456 | * |
| 457 | * @param out Rect containing the max visible bounds. |
| 458 | * @return true if the task has some visible app windows; false otherwise. |
| 459 | */ |
| 460 | boolean getMaxVisibleBounds(Rect out) { |
| 461 | boolean foundTop = false; |
| 462 | for (int i = mAppTokens.size() - 1; i >= 0; i--) { |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 463 | final AppWindowToken token = mAppTokens.get(i); |
| 464 | // skip hidden (or about to hide) apps |
| 465 | if (token.mIsExiting || token.clientHidden || token.hiddenRequested) { |
| 466 | continue; |
| 467 | } |
| 468 | final WindowState win = token.findMainWindow(); |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 469 | if (win == null) { |
| 470 | continue; |
| 471 | } |
| 472 | if (!foundTop) { |
| 473 | out.set(win.mVisibleFrame); |
| 474 | foundTop = true; |
| 475 | continue; |
| 476 | } |
| 477 | if (win.mVisibleFrame.left < out.left) { |
| 478 | out.left = win.mVisibleFrame.left; |
| 479 | } |
| 480 | if (win.mVisibleFrame.top < out.top) { |
| 481 | out.top = win.mVisibleFrame.top; |
| 482 | } |
| 483 | if (win.mVisibleFrame.right > out.right) { |
| 484 | out.right = win.mVisibleFrame.right; |
| 485 | } |
| 486 | if (win.mVisibleFrame.bottom > out.bottom) { |
| 487 | out.bottom = win.mVisibleFrame.bottom; |
| 488 | } |
| 489 | } |
| 490 | return foundTop; |
| 491 | } |
| 492 | |
| 493 | /** Bounds of the task to be used for dimming, as well as touch related tests. */ |
| 494 | @Override |
| 495 | public void getDimBounds(Rect out) { |
| 496 | if (useCurrentBounds()) { |
| 497 | if (inFreeformWorkspace() && getMaxVisibleBounds(out)) { |
| 498 | return; |
| 499 | } |
| 500 | |
Jorim Jaggi | 22a869f | 2016-03-25 23:33:21 -0700 | [diff] [blame] | 501 | if (!mFullscreen) { |
| 502 | // When minimizing the docked stack when going home, we don't adjust the task bounds |
| 503 | // so we need to intersect the task bounds with the stack bounds here. |
| 504 | mStack.getBounds(mTmpRect); |
| 505 | mTmpRect.intersect(mBounds); |
| 506 | out.set(mTmpRect); |
| 507 | } else { |
| 508 | out.set(mBounds); |
| 509 | } |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 510 | return; |
| 511 | } |
| 512 | |
| 513 | // The bounds has been adjusted to accommodate for a docked stack, but the docked stack |
| 514 | // is not currently visible. Go ahead a represent it as fullscreen to the rest of the |
| 515 | // system. |
| 516 | mStack.getDisplayContent().getLogicalDisplayRect(out); |
| 517 | } |
| 518 | |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 519 | void setDragResizing(boolean dragResizing, int dragResizeMode) { |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 520 | if (mDragResizing != dragResizing) { |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 521 | if (!DragResizeMode.isModeAllowedForStack(mStack.mStackId, dragResizeMode)) { |
| 522 | throw new IllegalArgumentException("Drag resize mode not allow for stack stackId=" |
| 523 | + mStack.mStackId + " dragResizeMode=" + dragResizeMode); |
| 524 | } |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 525 | mDragResizing = dragResizing; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 526 | mDragResizeMode = dragResizeMode; |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 527 | resetDragResizingChangeReported(); |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | void resetDragResizingChangeReported() { |
| 532 | for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) { |
| 533 | final ArrayList<WindowState> windows = mAppTokens.get(activityNdx).allAppWindows; |
| 534 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
| 535 | final WindowState win = windows.get(winNdx); |
| 536 | win.resetDragResizingChangeReported(); |
| 537 | } |
| 538 | } |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | boolean isDragResizing() { |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 542 | return mDragResizing || (mStack != null && mStack.isDragResizing()); |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 545 | int getDragResizeMode() { |
| 546 | return mDragResizeMode; |
| 547 | } |
| 548 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 549 | void updateDisplayInfo(final DisplayContent displayContent) { |
| 550 | if (displayContent == null) { |
| 551 | return; |
| 552 | } |
| 553 | if (mFullscreen) { |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 554 | setBounds(null, Configuration.EMPTY); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 555 | return; |
| 556 | } |
| 557 | final int newRotation = displayContent.getDisplayInfo().rotation; |
| 558 | if (mRotation == newRotation) { |
| 559 | return; |
| 560 | } |
| 561 | |
Wale Ogunwale | e1fe4d1 | 2016-01-14 08:52:30 -0800 | [diff] [blame] | 562 | // Device rotation changed. |
| 563 | // - Reset the bounds to the pre-scroll bounds as whatever scrolling was done is no longer |
| 564 | // valid. |
| 565 | // - Rotate the bounds and notify activity manager if the task can be resized independently |
| 566 | // from its stack. The stack will take care of task rotation for the other case. |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 567 | mTmpRect2.set(mPreScrollBounds); |
Wale Ogunwale | e1fe4d1 | 2016-01-14 08:52:30 -0800 | [diff] [blame] | 568 | |
| 569 | if (!StackId.isTaskResizeAllowed(mStack.mStackId)) { |
| 570 | setBounds(mTmpRect2, mOverrideConfig); |
| 571 | return; |
| 572 | } |
| 573 | |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 574 | displayContent.rotateBounds(mRotation, newRotation, mTmpRect2); |
Wale Ogunwale | 1ed0d89 | 2015-09-28 13:27:44 -0700 | [diff] [blame] | 575 | if (setBounds(mTmpRect2, mOverrideConfig) != BOUNDS_CHANGE_NONE) { |
Wale Ogunwale | e1fe4d1 | 2016-01-14 08:52:30 -0800 | [diff] [blame] | 576 | // Post message to inform activity manager of the bounds change simulating a one-way |
| 577 | // call. We do this to prevent a deadlock between window manager lock and activity |
| 578 | // manager lock been held. |
| 579 | mService.mH.obtainMessage(RESIZE_TASK, mTaskId, |
| 580 | RESIZE_MODE_SYSTEM_SCREEN_ROTATION, mPreScrollBounds).sendToTarget(); |
Wale Ogunwale | 1ed0d89 | 2015-09-28 13:27:44 -0700 | [diff] [blame] | 581 | } |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 584 | void resizeWindows() { |
| 585 | final ArrayList<WindowState> resizingWindows = mService.mResizingWindows; |
| 586 | for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) { |
Jorim Jaggi | 8fa4522 | 2016-02-19 19:54:39 -0800 | [diff] [blame] | 587 | final AppWindowToken atoken = mAppTokens.get(activityNdx); |
| 588 | |
| 589 | // Some windows won't go through the resizing process, if they don't have a surface, so |
| 590 | // destroy all saved surfaces here. |
| 591 | atoken.destroySavedSurfaces(); |
| 592 | final ArrayList<WindowState> windows = atoken.allAppWindows; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 593 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
| 594 | final WindowState win = windows.get(winNdx); |
Jorim Jaggi | 69abc19 | 2016-02-04 19:34:00 -0800 | [diff] [blame] | 595 | if (win.mHasSurface && !resizingWindows.contains(win)) { |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 596 | if (DEBUG_RESIZE) Slog.d(TAG, "resizeWindows: Resizing " + win); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 597 | resizingWindows.add(win); |
| 598 | } |
Jorim Jaggi | 8fa4522 | 2016-02-19 19:54:39 -0800 | [diff] [blame] | 599 | if (win.isGoneForLayoutLw()) { |
| 600 | win.mResizedWhileGone = true; |
| 601 | } |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 602 | } |
| 603 | } |
| 604 | } |
| 605 | |
Chong Zhang | bd0d937 | 2015-12-28 15:18:29 -0800 | [diff] [blame] | 606 | void moveWindows() { |
| 607 | for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) { |
| 608 | final ArrayList<WindowState> windows = mAppTokens.get(activityNdx).allAppWindows; |
| 609 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
| 610 | final WindowState win = windows.get(winNdx); |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 611 | if (DEBUG_RESIZE) Slog.d(TAG, "moveWindows: Moving " + win); |
Chong Zhang | bd0d937 | 2015-12-28 15:18:29 -0800 | [diff] [blame] | 612 | win.mMovedByResize = true; |
| 613 | } |
| 614 | } |
| 615 | } |
| 616 | |
Winson | c28098f | 2015-10-30 14:50:19 -0700 | [diff] [blame] | 617 | /** |
| 618 | * Cancels any running app transitions associated with the task. |
| 619 | */ |
| 620 | void cancelTaskWindowTransition() { |
| 621 | for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) { |
| 622 | mAppTokens.get(activityNdx).mAppAnimator.clearAnimation(); |
| 623 | } |
| 624 | } |
| 625 | |
Winson | 13d3066 | 2015-11-06 15:30:29 -0800 | [diff] [blame] | 626 | /** |
| 627 | * Cancels any running thumbnail transitions associated with the task. |
| 628 | */ |
| 629 | void cancelTaskThumbnailTransition() { |
| 630 | for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) { |
| 631 | mAppTokens.get(activityNdx).mAppAnimator.clearThumbnail(); |
| 632 | } |
| 633 | } |
| 634 | |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 635 | boolean showForAllUsers() { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 636 | final int tokensCount = mAppTokens.size(); |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 637 | return (tokensCount != 0) && mAppTokens.get(tokensCount - 1).showForAllUsers; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 638 | } |
| 639 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 640 | boolean isVisibleForUser() { |
| 641 | for (int i = mAppTokens.size() - 1; i >= 0; i--) { |
| 642 | final AppWindowToken appToken = mAppTokens.get(i); |
| 643 | for (int j = appToken.allAppWindows.size() - 1; j >= 0; j--) { |
| 644 | WindowState window = appToken.allAppWindows.get(j); |
| 645 | if (!window.isHiddenFromUserLocked()) { |
| 646 | return true; |
| 647 | } |
| 648 | } |
| 649 | } |
| 650 | return false; |
| 651 | } |
| 652 | |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 653 | boolean inHomeStack() { |
| 654 | return mStack != null && mStack.mStackId == HOME_STACK_ID; |
| 655 | } |
| 656 | |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 657 | boolean inFreeformWorkspace() { |
| 658 | return mStack != null && mStack.mStackId == FREEFORM_WORKSPACE_STACK_ID; |
| 659 | } |
| 660 | |
Filip Gruszczynski | 955b2fc | 2015-10-15 14:46:07 -0700 | [diff] [blame] | 661 | boolean inDockedWorkspace() { |
| 662 | return mStack != null && mStack.mStackId == DOCKED_STACK_ID; |
| 663 | } |
| 664 | |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 665 | boolean isResizeableByDockedStack() { |
Wale Ogunwale | 5e7409c | 2016-01-11 12:24:19 -0800 | [diff] [blame] | 666 | final DisplayContent displayContent = getDisplayContent(); |
| 667 | return displayContent != null && displayContent.getDockedStackLocked() != null |
| 668 | && mStack != null && StackId.isTaskResizeableByDockedStack(mStack.mStackId); |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 669 | } |
| 670 | |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 671 | boolean isFloating() { |
| 672 | return StackId.tasksAreFloating(mStack.mStackId); |
| 673 | } |
| 674 | |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 675 | /** |
| 676 | * Whether the task should be treated as if it's docked. Returns true if the task |
| 677 | * is currently in docked workspace, or it's side-by-side to a docked task. |
| 678 | */ |
| 679 | boolean isDockedInEffect() { |
| 680 | return inDockedWorkspace() || isResizeableByDockedStack(); |
| 681 | } |
| 682 | |
Chong Zhang | 2a88fc3 | 2016-01-11 17:14:24 -0800 | [diff] [blame] | 683 | boolean isTwoFingerScrollMode() { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 684 | return inCropWindowsResizeMode() && isDockedInEffect(); |
Chong Zhang | 2a88fc3 | 2016-01-11 17:14:24 -0800 | [diff] [blame] | 685 | } |
| 686 | |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 687 | WindowState getTopVisibleAppMainWindow() { |
| 688 | final AppWindowToken token = getTopVisibleAppToken(); |
| 689 | return token != null ? token.findMainWindow() : null; |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 690 | } |
| 691 | |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 692 | AppWindowToken getTopVisibleAppToken() { |
| 693 | for (int i = mAppTokens.size() - 1; i >= 0; i--) { |
| 694 | final AppWindowToken token = mAppTokens.get(i); |
| 695 | // skip hidden (or about to hide) apps |
| 696 | if (!token.mIsExiting && !token.clientHidden && !token.hiddenRequested) { |
| 697 | return token; |
| 698 | } |
| 699 | } |
| 700 | return null; |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 701 | } |
| 702 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 703 | @Override |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 704 | public boolean isFullscreen() { |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 705 | if (useCurrentBounds()) { |
| 706 | return mFullscreen; |
| 707 | } |
| 708 | // The bounds has been adjusted to accommodate for a docked stack, but the docked stack |
| 709 | // is not currently visible. Go ahead a represent it as fullscreen to the rest of the |
| 710 | // system. |
| 711 | return true; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | @Override |
| 715 | public DisplayInfo getDisplayInfo() { |
| 716 | return mStack.getDisplayContent().getDisplayInfo(); |
| 717 | } |
| 718 | |
| 719 | @Override |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 720 | public String toString() { |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 721 | return "{taskId=" + mTaskId + " appTokens=" + mAppTokens + " mdr=" + mDeferRemoval + "}"; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 722 | } |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 723 | |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 724 | @Override |
| 725 | public String toShortString() { |
| 726 | return "Task=" + mTaskId; |
| 727 | } |
| 728 | |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 729 | public void dump(String prefix, PrintWriter pw) { |
| 730 | final String doublePrefix = prefix + " "; |
| 731 | |
| 732 | pw.println(prefix + "taskId=" + mTaskId); |
| 733 | pw.println(doublePrefix + "mFullscreen=" + mFullscreen); |
| 734 | pw.println(doublePrefix + "mBounds=" + mBounds.toShortString()); |
| 735 | pw.println(doublePrefix + "mdr=" + mDeferRemoval); |
| 736 | pw.println(doublePrefix + "appTokens=" + mAppTokens); |
| 737 | pw.println(doublePrefix + "mTempInsetBounds=" + mTempInsetBounds.toShortString()); |
| 738 | |
| 739 | final String triplePrefix = doublePrefix + " "; |
| 740 | |
| 741 | for (int i = mAppTokens.size() - 1; i >= 0; i--) { |
| 742 | final AppWindowToken wtoken = mAppTokens.get(i); |
| 743 | pw.println(triplePrefix + "Activity #" + i + " " + wtoken); |
| 744 | wtoken.dump(pw, triplePrefix); |
| 745 | } |
| 746 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 747 | } |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 748 | } |