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