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