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