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; |
Robert Carr | 0313845 | 2016-05-18 14:53:16 -0700 | [diff] [blame] | 21 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 22 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
| 23 | import static android.app.ActivityManager.StackId.HOME_STACK_ID; |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 24 | import static android.content.pm.ActivityInfo.RESIZE_MODE_CROP_WINDOWS; |
Jorim Jaggi | d53f092 | 2016-04-06 22:16:23 -0700 | [diff] [blame] | 25 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 26 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE; |
| 27 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK; |
Jorim Jaggi | d53f092 | 2016-04-06 22:16:23 -0700 | [diff] [blame] | 28 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 29 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Wale Ogunwale | 1ed0d89 | 2015-09-28 13:27:44 -0700 | [diff] [blame] | 30 | import static com.android.server.wm.WindowManagerService.H.RESIZE_TASK; |
Robert Carr | 2c17cd2 | 2016-04-08 17:52:28 -0700 | [diff] [blame] | 31 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 32 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 33 | import android.app.ActivityManager.StackId; |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 34 | import android.content.pm.ActivityInfo; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 35 | import android.content.res.Configuration; |
| 36 | import android.graphics.Rect; |
Craig Mautner | 2c2549c | 2013-11-12 08:31:15 -0800 | [diff] [blame] | 37 | import android.util.EventLog; |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 38 | import android.util.Slog; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 39 | import android.view.DisplayInfo; |
| 40 | import android.view.Surface; |
| 41 | |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame^] | 42 | import android.view.SurfaceControl; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 43 | import com.android.server.EventLogTags; |
Craig Mautner | 2c2549c | 2013-11-12 08:31:15 -0800 | [diff] [blame] | 44 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 45 | import java.io.PrintWriter; |
| 46 | import java.util.ArrayList; |
| 47 | |
| 48 | class Task implements DimLayer.DimLayerUser { |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 49 | static final String TAG = TAG_WITH_CLASS_NAME ? "Task" : TAG_WM; |
Wale Ogunwale | 2cc92f5 | 2015-09-09 13:12:10 -0700 | [diff] [blame] | 50 | // Return value from {@link setBounds} indicating no change was made to the Task bounds. |
| 51 | static final int BOUNDS_CHANGE_NONE = 0; |
| 52 | // Return value from {@link setBounds} indicating the position of the Task bounds changed. |
| 53 | static final int BOUNDS_CHANGE_POSITION = 1; |
| 54 | // Return value from {@link setBounds} indicating the size of the Task bounds changed. |
| 55 | static final int BOUNDS_CHANGE_SIZE = 1 << 1; |
| 56 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 57 | TaskStack mStack; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 58 | final AppTokenList mAppTokens = new AppTokenList(); |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 59 | final int mTaskId; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 60 | final int mUserId; |
Craig Mautner | 9ef471f | 2014-02-07 13:11:47 -0800 | [diff] [blame] | 61 | boolean mDeferRemoval = false; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 62 | final WindowManagerService mService; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 63 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 64 | // Content limits relative to the DisplayContent this sits in. |
| 65 | private Rect mBounds = new Rect(); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 66 | final Rect mPreparedFrozenBounds = new Rect(); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 67 | final Configuration mPreparedFrozenMergedConfig = new Configuration(); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 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}. |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 80 | Configuration mOverrideConfig = Configuration.EMPTY; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 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 | |
Jiaquan He | dd1e66f | 2016-06-15 15:15:12 -0700 | [diff] [blame] | 96 | // Whether this task is an on-top launcher task, which is determined by the root activity. |
| 97 | private boolean mIsOnTopLauncher; |
| 98 | |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 99 | Task(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds, |
Jiaquan He | dd1e66f | 2016-06-15 15:15:12 -0700 | [diff] [blame] | 100 | Configuration config, boolean isOnTopLauncher) { |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 101 | mTaskId = taskId; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 102 | mStack = stack; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 103 | mUserId = userId; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 104 | mService = service; |
Jiaquan He | dd1e66f | 2016-06-15 15:15:12 -0700 | [diff] [blame] | 105 | mIsOnTopLauncher = isOnTopLauncher; |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 106 | setBounds(bounds, config); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | DisplayContent getDisplayContent() { |
| 110 | return mStack.getDisplayContent(); |
| 111 | } |
| 112 | |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 113 | void addAppToken(int addPos, AppWindowToken wtoken, int resizeMode, boolean homeTask) { |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 114 | final int lastPos = mAppTokens.size(); |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 115 | if (addPos >= lastPos) { |
| 116 | addPos = lastPos; |
| 117 | } else { |
| 118 | for (int pos = 0; pos < lastPos && pos < addPos; ++pos) { |
| 119 | if (mAppTokens.get(pos).removed) { |
| 120 | // addPos assumes removed tokens are actually gone. |
| 121 | ++addPos; |
| 122 | } |
Craig Mautner | 01f79cf | 2014-08-27 09:56:02 -0700 | [diff] [blame] | 123 | } |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 124 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 125 | mAppTokens.add(addPos, wtoken); |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 126 | wtoken.mTask = this; |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 127 | mDeferRemoval = false; |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 128 | mResizeMode = resizeMode; |
| 129 | mHomeTask = homeTask; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 130 | } |
| 131 | |
Wale Ogunwale | e42d0e1 | 2016-05-02 16:40:59 -0700 | [diff] [blame] | 132 | private boolean hasWindowsAlive() { |
Chong Zhang | 7e8eeb7 | 2016-01-06 19:14:47 -0800 | [diff] [blame] | 133 | for (int i = mAppTokens.size() - 1; i >= 0; i--) { |
Wale Ogunwale | e42d0e1 | 2016-05-02 16:40:59 -0700 | [diff] [blame] | 134 | if (mAppTokens.get(i).hasWindowsAlive()) { |
Chong Zhang | 7e8eeb7 | 2016-01-06 19:14:47 -0800 | [diff] [blame] | 135 | return true; |
| 136 | } |
| 137 | } |
| 138 | return false; |
| 139 | } |
| 140 | |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 141 | void removeLocked() { |
Wale Ogunwale | e42d0e1 | 2016-05-02 16:40:59 -0700 | [diff] [blame] | 142 | if (hasWindowsAlive() && mStack.isAnimating()) { |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 143 | if (DEBUG_STACK) Slog.i(TAG, "removeTask: deferring removing taskId=" + mTaskId); |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 144 | mDeferRemoval = true; |
| 145 | return; |
| 146 | } |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 147 | if (DEBUG_STACK) Slog.i(TAG, "removeTask: removing taskId=" + mTaskId); |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 148 | EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "removeTask"); |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 149 | mDeferRemoval = false; |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 150 | DisplayContent content = getDisplayContent(); |
| 151 | if (content != null) { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 152 | content.mDimLayerController.removeDimLayerUser(this); |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 153 | } |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 154 | mStack.removeTask(this); |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 155 | mService.mTaskIdToTask.delete(mTaskId); |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 156 | } |
| 157 | |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 158 | void moveTaskToStack(TaskStack stack, boolean toTop) { |
| 159 | if (stack == mStack) { |
| 160 | return; |
| 161 | } |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 162 | if (DEBUG_STACK) Slog.i(TAG, "moveTaskToStack: removing taskId=" + mTaskId |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 163 | + " from stack=" + mStack); |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 164 | EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask"); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 165 | if (mStack != null) { |
| 166 | mStack.removeTask(this); |
| 167 | } |
| 168 | stack.addTask(this, toTop); |
| 169 | } |
| 170 | |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 171 | void positionTaskInStack(TaskStack stack, int position, Rect bounds, Configuration config) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 172 | if (mStack != null && stack != mStack) { |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 173 | if (DEBUG_STACK) Slog.i(TAG, "positionTaskInStack: removing taskId=" + mTaskId |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 174 | + " from stack=" + mStack); |
| 175 | EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask"); |
| 176 | mStack.removeTask(this); |
| 177 | } |
| 178 | stack.positionTask(this, position, showForAllUsers()); |
Jorim Jaggi | 8fa4522 | 2016-02-19 19:54:39 -0800 | [diff] [blame] | 179 | resizeLocked(bounds, config, false /* force */); |
Jorim Jaggi | 5e6968d | 2016-02-19 18:02:13 -0800 | [diff] [blame] | 180 | |
| 181 | for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame^] | 182 | mAppTokens.get(activityNdx).notifyMovedInStack(); |
Jorim Jaggi | 5e6968d | 2016-02-19 18:02:13 -0800 | [diff] [blame] | 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 | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 235 | if (mBounds.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 | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 240 | if (mBounds.left != bounds.left || mBounds.top != bounds.top) { |
Wale Ogunwale | 2cc92f5 | 2015-09-09 13:12:10 -0700 | [diff] [blame] | 241 | boundsChange |= BOUNDS_CHANGE_POSITION; |
| 242 | } |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 243 | if (mBounds.width() != bounds.width() || mBounds.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 | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 247 | mBounds.set(bounds); |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 248 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 249 | mRotation = rotation; |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 250 | if (displayContent != null) { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 251 | displayContent.mDimLayerController.updateDimLayer(this); |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 252 | } |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 253 | mOverrideConfig = mFullscreen ? Configuration.EMPTY : config; |
Wale Ogunwale | 2cc92f5 | 2015-09-09 13:12:10 -0700 | [diff] [blame] | 254 | return boundsChange; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 257 | /** |
| 258 | * Sets the bounds used to calculate the insets. See |
| 259 | * {@link android.app.IActivityManager#resizeDockedStack} why this is needed. |
| 260 | */ |
| 261 | void setTempInsetBounds(Rect tempInsetBounds) { |
| 262 | if (tempInsetBounds != null) { |
| 263 | mTempInsetBounds.set(tempInsetBounds); |
| 264 | } else { |
| 265 | mTempInsetBounds.setEmpty(); |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * Gets the bounds used to calculate the insets. See |
| 271 | * {@link android.app.IActivityManager#resizeDockedStack} why this is needed. |
| 272 | */ |
| 273 | void getTempInsetBounds(Rect out) { |
| 274 | out.set(mTempInsetBounds); |
| 275 | } |
| 276 | |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 277 | void setResizeable(int resizeMode) { |
| 278 | mResizeMode = resizeMode; |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | boolean isResizeable() { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 282 | return !mHomeTask |
| 283 | && (ActivityInfo.isResizeableMode(mResizeMode) || mService.mForceResizableTasks); |
| 284 | } |
| 285 | |
Jiaquan He | dd1e66f | 2016-06-15 15:15:12 -0700 | [diff] [blame] | 286 | boolean isOnTopLauncher() { |
| 287 | return mIsOnTopLauncher; |
| 288 | } |
| 289 | |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 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 | |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 354 | /** Return true if the current bound can get outputted to the rest of the system as-is. */ |
| 355 | private boolean useCurrentBounds() { |
| 356 | final DisplayContent displayContent = mStack.getDisplayContent(); |
| 357 | if (mFullscreen |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 358 | || !StackId.isTaskResizeableByDockedStack(mStack.mStackId) |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 359 | || displayContent == null |
Jorim Jaggi | f4fa8cb | 2016-04-01 16:05:10 -0700 | [diff] [blame] | 360 | || displayContent.getDockedStackVisibleForUserLocked() != null) { |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 361 | return true; |
| 362 | } |
| 363 | return false; |
| 364 | } |
| 365 | |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 366 | /** Original bounds of the task if applicable, otherwise fullscreen rect. */ |
Wale Ogunwale | ccb6ce2 | 2016-01-14 15:36:35 -0800 | [diff] [blame] | 367 | void getBounds(Rect out) { |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 368 | if (useCurrentBounds()) { |
| 369 | // No need to adjust the output bounds if fullscreen or the docked stack is visible |
| 370 | // since it is already what we want to represent to the rest of the system. |
| 371 | out.set(mBounds); |
| 372 | return; |
| 373 | } |
| 374 | |
Wale Ogunwale | ccb6ce2 | 2016-01-14 15:36:35 -0800 | [diff] [blame] | 375 | // The bounds has been adjusted to accommodate for a docked stack, but the docked stack is |
| 376 | // 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] | 377 | mStack.getDisplayContent().getLogicalDisplayRect(out); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 380 | /** |
| 381 | * Calculate the maximum visible area of this task. If the task has only one app, |
| 382 | * the result will be visible frame of that app. If the task has more than one apps, |
| 383 | * we search from top down if the next app got different visible area. |
| 384 | * |
| 385 | * This effort is to handle the case where some task (eg. GMail composer) might pop up |
| 386 | * a dialog that's different in size from the activity below, in which case we should |
| 387 | * be dimming the entire task area behind the dialog. |
| 388 | * |
| 389 | * @param out Rect containing the max visible bounds. |
| 390 | * @return true if the task has some visible app windows; false otherwise. |
| 391 | */ |
| 392 | boolean getMaxVisibleBounds(Rect out) { |
| 393 | boolean foundTop = false; |
| 394 | for (int i = mAppTokens.size() - 1; i >= 0; i--) { |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 395 | final AppWindowToken token = mAppTokens.get(i); |
| 396 | // skip hidden (or about to hide) apps |
| 397 | if (token.mIsExiting || token.clientHidden || token.hiddenRequested) { |
| 398 | continue; |
| 399 | } |
| 400 | final WindowState win = token.findMainWindow(); |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 401 | if (win == null) { |
| 402 | continue; |
| 403 | } |
| 404 | if (!foundTop) { |
| 405 | out.set(win.mVisibleFrame); |
| 406 | foundTop = true; |
| 407 | continue; |
| 408 | } |
| 409 | if (win.mVisibleFrame.left < out.left) { |
| 410 | out.left = win.mVisibleFrame.left; |
| 411 | } |
| 412 | if (win.mVisibleFrame.top < out.top) { |
| 413 | out.top = win.mVisibleFrame.top; |
| 414 | } |
| 415 | if (win.mVisibleFrame.right > out.right) { |
| 416 | out.right = win.mVisibleFrame.right; |
| 417 | } |
| 418 | if (win.mVisibleFrame.bottom > out.bottom) { |
| 419 | out.bottom = win.mVisibleFrame.bottom; |
| 420 | } |
| 421 | } |
| 422 | return foundTop; |
| 423 | } |
| 424 | |
| 425 | /** Bounds of the task to be used for dimming, as well as touch related tests. */ |
| 426 | @Override |
| 427 | public void getDimBounds(Rect out) { |
Robert Carr | a86a6bf | 2016-04-08 17:34:16 -0700 | [diff] [blame] | 428 | final DisplayContent displayContent = mStack.getDisplayContent(); |
| 429 | // It doesn't matter if we in particular are part of the resize, since we couldn't have |
| 430 | // a DimLayer anyway if we weren't visible. |
| 431 | final boolean dockedResizing = displayContent != null ? |
| 432 | displayContent.mDividerControllerLocked.isResizing() : false; |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 433 | if (useCurrentBounds()) { |
| 434 | if (inFreeformWorkspace() && getMaxVisibleBounds(out)) { |
| 435 | return; |
| 436 | } |
| 437 | |
Jorim Jaggi | 22a869f | 2016-03-25 23:33:21 -0700 | [diff] [blame] | 438 | if (!mFullscreen) { |
| 439 | // When minimizing the docked stack when going home, we don't adjust the task bounds |
| 440 | // 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] | 441 | // |
| 442 | // If we are Docked Resizing with snap points, the task bounds could be smaller than the stack |
| 443 | // bounds and so we don't even want to use them. Even if the app should not be resized the Dim |
| 444 | // should keep up with the divider. |
| 445 | if (dockedResizing) { |
| 446 | mStack.getBounds(out); |
| 447 | } else { |
| 448 | mStack.getBounds(mTmpRect); |
| 449 | mTmpRect.intersect(mBounds); |
| 450 | } |
Jorim Jaggi | 22a869f | 2016-03-25 23:33:21 -0700 | [diff] [blame] | 451 | out.set(mTmpRect); |
| 452 | } else { |
| 453 | out.set(mBounds); |
| 454 | } |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 455 | return; |
| 456 | } |
| 457 | |
| 458 | // The bounds has been adjusted to accommodate for a docked stack, but the docked stack |
| 459 | // is not currently visible. Go ahead a represent it as fullscreen to the rest of the |
| 460 | // system. |
Robert Carr | a86a6bf | 2016-04-08 17:34:16 -0700 | [diff] [blame] | 461 | displayContent.getLogicalDisplayRect(out); |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 462 | } |
| 463 | |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 464 | void setDragResizing(boolean dragResizing, int dragResizeMode) { |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 465 | if (mDragResizing != dragResizing) { |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 466 | if (!DragResizeMode.isModeAllowedForStack(mStack.mStackId, dragResizeMode)) { |
| 467 | throw new IllegalArgumentException("Drag resize mode not allow for stack stackId=" |
| 468 | + mStack.mStackId + " dragResizeMode=" + dragResizeMode); |
| 469 | } |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 470 | mDragResizing = dragResizing; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 471 | mDragResizeMode = dragResizeMode; |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 472 | resetDragResizingChangeReported(); |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | void resetDragResizingChangeReported() { |
| 477 | for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame^] | 478 | mAppTokens.get(activityNdx).resetDragResizingChangeReported(); |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 479 | } |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | boolean isDragResizing() { |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 483 | return mDragResizing || (mStack != null && mStack.isDragResizing()); |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 486 | int getDragResizeMode() { |
| 487 | return mDragResizeMode; |
| 488 | } |
| 489 | |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 490 | /** |
| 491 | * Adds all of the tasks windows to {@link WindowManagerService#mWaitingForDrawn} if drag |
| 492 | * resizing state of the window has been changed. |
| 493 | */ |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame^] | 494 | void setWaitingForDrawnIfResizingChanged() { |
| 495 | for (int i = mAppTokens.size() - 1; i >= 0; --i) { |
| 496 | mAppTokens.get(i).setWaitingForDrawnIfResizingChanged(); |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | void detachDisplay() { |
| 501 | for (int i = mAppTokens.size() - 1; i >= 0; --i) { |
| 502 | mAppTokens.get(i).detachDisplay(); |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 503 | } |
| 504 | } |
| 505 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 506 | void updateDisplayInfo(final DisplayContent displayContent) { |
| 507 | if (displayContent == null) { |
| 508 | return; |
| 509 | } |
| 510 | if (mFullscreen) { |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 511 | setBounds(null, Configuration.EMPTY); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 512 | return; |
| 513 | } |
| 514 | final int newRotation = displayContent.getDisplayInfo().rotation; |
| 515 | if (mRotation == newRotation) { |
| 516 | return; |
| 517 | } |
| 518 | |
Wale Ogunwale | e1fe4d1 | 2016-01-14 08:52:30 -0800 | [diff] [blame] | 519 | // Device rotation changed. |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 520 | // - We don't want the task to move around on the screen when this happens, so update the |
| 521 | // task bounds so it stays in the same place. |
Wale Ogunwale | e1fe4d1 | 2016-01-14 08:52:30 -0800 | [diff] [blame] | 522 | // - Rotate the bounds and notify activity manager if the task can be resized independently |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 523 | // from its stack. The stack will take care of task rotation for the other case. |
| 524 | mTmpRect2.set(mBounds); |
Wale Ogunwale | e1fe4d1 | 2016-01-14 08:52:30 -0800 | [diff] [blame] | 525 | |
| 526 | if (!StackId.isTaskResizeAllowed(mStack.mStackId)) { |
| 527 | setBounds(mTmpRect2, mOverrideConfig); |
| 528 | return; |
| 529 | } |
| 530 | |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 531 | displayContent.rotateBounds(mRotation, newRotation, mTmpRect2); |
Wale Ogunwale | 1ed0d89 | 2015-09-28 13:27:44 -0700 | [diff] [blame] | 532 | if (setBounds(mTmpRect2, mOverrideConfig) != BOUNDS_CHANGE_NONE) { |
Wale Ogunwale | e1fe4d1 | 2016-01-14 08:52:30 -0800 | [diff] [blame] | 533 | // Post message to inform activity manager of the bounds change simulating a one-way |
| 534 | // call. We do this to prevent a deadlock between window manager lock and activity |
| 535 | // manager lock been held. |
| 536 | mService.mH.obtainMessage(RESIZE_TASK, mTaskId, |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 537 | RESIZE_MODE_SYSTEM_SCREEN_ROTATION, mBounds).sendToTarget(); |
Wale Ogunwale | 1ed0d89 | 2015-09-28 13:27:44 -0700 | [diff] [blame] | 538 | } |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 539 | } |
| 540 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 541 | void resizeWindows() { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 542 | for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame^] | 543 | mAppTokens.get(activityNdx).resizeWindows(); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 544 | } |
| 545 | } |
| 546 | |
Chong Zhang | bd0d937 | 2015-12-28 15:18:29 -0800 | [diff] [blame] | 547 | void moveWindows() { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame^] | 548 | for (int i = mAppTokens.size() - 1; i >= 0; --i) { |
| 549 | mAppTokens.get(i).moveWindows(); |
Chong Zhang | bd0d937 | 2015-12-28 15:18:29 -0800 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | |
Winson | c28098f | 2015-10-30 14:50:19 -0700 | [diff] [blame] | 553 | /** |
| 554 | * Cancels any running app transitions associated with the task. |
| 555 | */ |
| 556 | void cancelTaskWindowTransition() { |
| 557 | for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) { |
| 558 | mAppTokens.get(activityNdx).mAppAnimator.clearAnimation(); |
| 559 | } |
| 560 | } |
| 561 | |
Winson | 13d3066 | 2015-11-06 15:30:29 -0800 | [diff] [blame] | 562 | /** |
| 563 | * Cancels any running thumbnail transitions associated with the task. |
| 564 | */ |
| 565 | void cancelTaskThumbnailTransition() { |
| 566 | for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) { |
| 567 | mAppTokens.get(activityNdx).mAppAnimator.clearThumbnail(); |
| 568 | } |
| 569 | } |
| 570 | |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 571 | boolean showForAllUsers() { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 572 | final int tokensCount = mAppTokens.size(); |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 573 | return (tokensCount != 0) && mAppTokens.get(tokensCount - 1).showForAllUsers; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 574 | } |
| 575 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 576 | boolean isVisibleForUser() { |
| 577 | for (int i = mAppTokens.size() - 1; i >= 0; i--) { |
| 578 | final AppWindowToken appToken = mAppTokens.get(i); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame^] | 579 | if (appToken.isVisibleForUser()) { |
| 580 | return true; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 581 | } |
| 582 | } |
| 583 | return false; |
| 584 | } |
| 585 | |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 586 | boolean isVisible() { |
| 587 | for (int i = mAppTokens.size() - 1; i >= 0; i--) { |
| 588 | final AppWindowToken appToken = mAppTokens.get(i); |
| 589 | if (appToken.isVisible()) { |
| 590 | return true; |
| 591 | } |
| 592 | } |
| 593 | return false; |
| 594 | } |
| 595 | |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 596 | boolean inHomeStack() { |
| 597 | return mStack != null && mStack.mStackId == HOME_STACK_ID; |
| 598 | } |
| 599 | |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 600 | boolean inFreeformWorkspace() { |
| 601 | return mStack != null && mStack.mStackId == FREEFORM_WORKSPACE_STACK_ID; |
| 602 | } |
| 603 | |
Robert Carr | 0313845 | 2016-05-18 14:53:16 -0700 | [diff] [blame] | 604 | boolean inPinnedWorkspace() { |
| 605 | return mStack != null && mStack.mStackId == PINNED_STACK_ID; |
| 606 | } |
| 607 | |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 608 | boolean isFloating() { |
| 609 | return StackId.tasksAreFloating(mStack.mStackId); |
| 610 | } |
| 611 | |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 612 | WindowState getTopVisibleAppMainWindow() { |
| 613 | final AppWindowToken token = getTopVisibleAppToken(); |
| 614 | return token != null ? token.findMainWindow() : null; |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 615 | } |
| 616 | |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 617 | AppWindowToken getTopVisibleAppToken() { |
| 618 | for (int i = mAppTokens.size() - 1; i >= 0; i--) { |
| 619 | final AppWindowToken token = mAppTokens.get(i); |
| 620 | // skip hidden (or about to hide) apps |
| 621 | if (!token.mIsExiting && !token.clientHidden && !token.hiddenRequested) { |
| 622 | return token; |
| 623 | } |
| 624 | } |
| 625 | return null; |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Jorim Jaggi | af558e1 | 2016-04-27 22:56:56 -0700 | [diff] [blame] | 628 | AppWindowToken getTopAppToken() { |
| 629 | return mAppTokens.size() > 0 ? mAppTokens.get(mAppTokens.size() - 1) : null; |
| 630 | } |
| 631 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 632 | @Override |
Wale Ogunwale | 29bfbb8 | 2016-05-12 15:13:52 -0700 | [diff] [blame] | 633 | public boolean dimFullscreen() { |
| 634 | return isHomeTask() || isFullscreen(); |
| 635 | } |
| 636 | |
| 637 | boolean isFullscreen() { |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 638 | if (useCurrentBounds()) { |
| 639 | return mFullscreen; |
| 640 | } |
| 641 | // The bounds has been adjusted to accommodate for a docked stack, but the docked stack |
| 642 | // is not currently visible. Go ahead a represent it as fullscreen to the rest of the |
| 643 | // system. |
| 644 | return true; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | @Override |
| 648 | public DisplayInfo getDisplayInfo() { |
| 649 | return mStack.getDisplayContent().getDisplayInfo(); |
| 650 | } |
| 651 | |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame^] | 652 | void forceWindowsScaleable(boolean force) { |
| 653 | SurfaceControl.openTransaction(); |
| 654 | try { |
| 655 | for (int i = mAppTokens.size() - 1; i >= 0; i--) { |
| 656 | mAppTokens.get(i).forceWindowsScaleableInTransaction(force); |
| 657 | } |
| 658 | } finally { |
| 659 | SurfaceControl.closeTransaction(); |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | boolean isAnimating() { |
| 664 | for (int i = mAppTokens.size() - 1; i >= 0; i--) { |
| 665 | final AppWindowToken aToken = mAppTokens.get(i); |
| 666 | if (aToken.isAnimating()) { |
| 667 | return true; |
| 668 | } |
| 669 | } |
| 670 | return false; |
| 671 | } |
| 672 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 673 | @Override |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 674 | public String toString() { |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 675 | return "{taskId=" + mTaskId + " appTokens=" + mAppTokens + " mdr=" + mDeferRemoval + "}"; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 676 | } |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 677 | |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 678 | @Override |
| 679 | public String toShortString() { |
| 680 | return "Task=" + mTaskId; |
| 681 | } |
| 682 | |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 683 | public void dump(String prefix, PrintWriter pw) { |
| 684 | final String doublePrefix = prefix + " "; |
| 685 | |
| 686 | pw.println(prefix + "taskId=" + mTaskId); |
| 687 | pw.println(doublePrefix + "mFullscreen=" + mFullscreen); |
| 688 | pw.println(doublePrefix + "mBounds=" + mBounds.toShortString()); |
| 689 | pw.println(doublePrefix + "mdr=" + mDeferRemoval); |
| 690 | pw.println(doublePrefix + "appTokens=" + mAppTokens); |
| 691 | pw.println(doublePrefix + "mTempInsetBounds=" + mTempInsetBounds.toShortString()); |
| 692 | |
| 693 | final String triplePrefix = doublePrefix + " "; |
| 694 | |
| 695 | for (int i = mAppTokens.size() - 1; i >= 0; i--) { |
| 696 | final AppWindowToken wtoken = mAppTokens.get(i); |
| 697 | pw.println(triplePrefix + "Activity #" + i + " " + wtoken); |
| 698 | wtoken.dump(pw, triplePrefix); |
| 699 | } |
| 700 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 701 | } |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 702 | } |