Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 19 | import android.app.ActivityManager.StackId; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 20 | import android.content.res.Configuration; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 21 | import android.graphics.Rect; |
Craig Mautner | f0ac5c8 | 2013-06-24 11:21:57 -0700 | [diff] [blame] | 22 | import android.os.Debug; |
Craig Mautner | 2c2549c | 2013-11-12 08:31:15 -0800 | [diff] [blame] | 23 | import android.util.EventLog; |
Craig Mautner | f0ac5c8 | 2013-06-24 11:21:57 -0700 | [diff] [blame] | 24 | import android.util.Slog; |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 25 | import android.util.SparseArray; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 26 | import android.view.DisplayInfo; |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 27 | import android.view.Surface; |
Filip Gruszczynski | 54977fe | 2015-10-19 17:26:45 -0700 | [diff] [blame] | 28 | |
Craig Mautner | 2c2549c | 2013-11-12 08:31:15 -0800 | [diff] [blame] | 29 | import com.android.server.EventLogTags; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 30 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 31 | import java.io.PrintWriter; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 32 | import java.util.ArrayList; |
| 33 | |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 34 | import static android.app.ActivityManager.DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT; |
| 35 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
| 36 | import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID; |
| 37 | import static android.view.WindowManager.DOCKED_BOTTOM; |
| 38 | import static android.view.WindowManager.DOCKED_INVALID; |
| 39 | import static android.view.WindowManager.DOCKED_LEFT; |
| 40 | import static android.view.WindowManager.DOCKED_RIGHT; |
| 41 | import static android.view.WindowManager.DOCKED_TOP; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 42 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_MOVEMENT; |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 43 | import static com.android.server.wm.WindowManagerService.H.RESIZE_STACK; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 44 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 45 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 46 | public class TaskStack implements DimLayer.DimLayerUser { |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 47 | |
| 48 | // If the stack should be resized to fullscreen. |
| 49 | private static final boolean FULLSCREEN = true; |
| 50 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 51 | /** Unique identifier */ |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 52 | final int mStackId; |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 53 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 54 | /** The service */ |
| 55 | private final WindowManagerService mService; |
| 56 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 57 | /** The display this stack sits under. */ |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 58 | private DisplayContent mDisplayContent; |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 59 | |
| 60 | /** The Tasks that define this stack. Oldest Tasks are at the bottom. The ordering must match |
| 61 | * mTaskHistory in the ActivityStack with the same mStackId */ |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 62 | private final ArrayList<Task> mTasks = new ArrayList<>(); |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 63 | |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 64 | /** For comparison with DisplayContent bounds. */ |
| 65 | private Rect mTmpRect = new Rect(); |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 66 | private Rect mTmpRect2 = new Rect(); |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 67 | |
| 68 | /** Content limits relative to the DisplayContent this sits in. */ |
| 69 | private Rect mBounds = new Rect(); |
| 70 | |
| 71 | /** Whether mBounds is fullscreen */ |
| 72 | private boolean mFullscreen = true; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 73 | |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 74 | // Device rotation as of the last time {@link #mBounds} was set. |
| 75 | int mRotation; |
| 76 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 77 | /** Support for non-zero {@link android.view.animation.Animation#getBackgroundColor()} */ |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 78 | DimLayer mAnimationBackgroundSurface; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 79 | |
| 80 | /** The particular window with an Animation with non-zero background color. */ |
| 81 | WindowStateAnimator mAnimationBackgroundAnimator; |
| 82 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 83 | /** Application tokens that are exiting, but still on screen for animations. */ |
| 84 | final AppTokenList mExitingAppTokens = new AppTokenList(); |
| 85 | |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 86 | /** Detach this stack from its display when animation completes. */ |
| 87 | boolean mDeferDetach; |
| 88 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 89 | TaskStack(WindowManagerService service, int stackId) { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 90 | mService = service; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 91 | mStackId = stackId; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 92 | EventLog.writeEvent(EventLogTags.WM_STACK_CREATED, stackId); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | DisplayContent getDisplayContent() { |
| 96 | return mDisplayContent; |
| 97 | } |
| 98 | |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 99 | ArrayList<Task> getTasks() { |
| 100 | return mTasks; |
| 101 | } |
| 102 | |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 103 | void resizeWindows() { |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 104 | for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 105 | mTasks.get(taskNdx).resizeWindows(); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 106 | } |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 109 | /** |
| 110 | * Set the bounds of the stack and its containing tasks. |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 111 | * @param stackBounds New stack bounds. Passing in null sets the bounds to fullscreen. |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 112 | * @param configs Configuration for individual tasks, keyed by task id. |
| 113 | * @param taskBounds Bounds for individual tasks, keyed by task id. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 114 | * @return True if the stack bounds was changed. |
| 115 | * */ |
Wale Ogunwale | a6e902e | 2015-09-21 18:37:15 -0700 | [diff] [blame] | 116 | boolean setBounds( |
| 117 | Rect stackBounds, SparseArray<Configuration> configs, SparseArray<Rect> taskBounds) { |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 118 | if (!setBounds(stackBounds)) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 119 | return false; |
| 120 | } |
| 121 | |
| 122 | // Update bounds of containing tasks. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 123 | for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 124 | final Task task = mTasks.get(taskNdx); |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 125 | Configuration config = configs.get(task.mTaskId); |
| 126 | if (config != null) { |
| 127 | Rect bounds = taskBounds.get(task.mTaskId); |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 128 | if (!task.isResizeable() && task.isDockedInEffect()) { |
| 129 | // This is a non-resizeable task that's docked (or side-by-side to the docked |
| 130 | // stack). It might have been scrolled previously, and after the stack resizing, |
| 131 | // it might no longer fully cover the stack area. |
| 132 | // Save the old bounds and re-apply the scroll. This adjusts the bounds to |
| 133 | // fit the new stack bounds. |
| 134 | task.getBounds(mTmpRect); |
| 135 | task.setBounds(bounds, config); |
| 136 | task.scrollLocked(mTmpRect); |
| 137 | } else { |
| 138 | task.setBounds(bounds, config); |
| 139 | } |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 140 | } else { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 141 | Slog.wtf(TAG_WM, "No config for task: " + task + ", is there a mismatch with AM?"); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | return true; |
| 145 | } |
| 146 | |
Wale Ogunwale | b4ec0a3 | 2015-12-14 10:31:43 -0800 | [diff] [blame^] | 147 | boolean isFullscreenBounds(Rect bounds) { |
| 148 | if (mDisplayContent == null || bounds == null) { |
| 149 | return true; |
| 150 | } |
| 151 | mDisplayContent.getLogicalDisplayRect(mTmpRect); |
| 152 | return mTmpRect.equals(bounds); |
| 153 | } |
| 154 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 155 | private boolean setBounds(Rect bounds) { |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 156 | boolean oldFullscreen = mFullscreen; |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 157 | int rotation = Surface.ROTATION_0; |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 158 | if (mDisplayContent != null) { |
| 159 | mDisplayContent.getLogicalDisplayRect(mTmpRect); |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 160 | rotation = mDisplayContent.getDisplayInfo().rotation; |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 161 | if (bounds == null) { |
| 162 | bounds = mTmpRect; |
| 163 | mFullscreen = true; |
| 164 | } else { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 165 | mFullscreen = mTmpRect.equals(bounds); |
| 166 | } |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 167 | } |
| 168 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 169 | if (bounds == null) { |
Wale Ogunwale | 4a02d81 | 2015-02-12 23:01:38 -0800 | [diff] [blame] | 170 | // Can't set to fullscreen if we don't have a display to get bounds from... |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 171 | return false; |
| 172 | } |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 173 | if (mBounds.equals(bounds) && oldFullscreen == mFullscreen && mRotation == rotation) { |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 174 | return false; |
| 175 | } |
| 176 | |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 177 | if (mDisplayContent != null) { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 178 | mDisplayContent.mDimLayerController.updateDimLayer(this); |
Filip Gruszczynski | 57b6cce | 2015-10-06 09:50:51 -0700 | [diff] [blame] | 179 | mAnimationBackgroundSurface.setBounds(bounds); |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 182 | mBounds.set(bounds); |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 183 | mRotation = rotation; |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 184 | return true; |
| 185 | } |
| 186 | |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 187 | /** Bounds of the stack without adjusting for other factors in the system like visibility |
| 188 | * of docked stack. |
| 189 | * Most callers should be using {@link #getBounds} as it take into consideration other system |
| 190 | * factors. */ |
| 191 | void getRawBounds(Rect out) { |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 192 | out.set(mBounds); |
| 193 | } |
| 194 | |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 195 | /** Return true if the current bound can get outputted to the rest of the system as-is. */ |
| 196 | private boolean useCurrentBounds() { |
| 197 | if (mFullscreen |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 198 | || !StackId.isResizeableByDockedStack(mStackId) |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 199 | || mDisplayContent == null |
| 200 | || mDisplayContent.getDockedStackLocked() != null) { |
| 201 | return true; |
| 202 | } |
| 203 | return false; |
| 204 | } |
| 205 | |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 206 | public void getBounds(Rect out) { |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 207 | if (useCurrentBounds()) { |
| 208 | // No need to adjust the output bounds if fullscreen or the docked stack is visible |
| 209 | // since it is already what we want to represent to the rest of the system. |
| 210 | out.set(mBounds); |
| 211 | return; |
| 212 | } |
| 213 | |
| 214 | // The bounds has been adjusted to accommodate for a docked stack, but the docked stack |
| 215 | // is not currently visible. Go ahead a represent it as fullscreen to the rest of the |
| 216 | // system. |
| 217 | mDisplayContent.getLogicalDisplayRect(out); |
| 218 | } |
| 219 | |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 220 | /** Bounds of the stack with other system factors taken into consideration. */ |
| 221 | @Override |
| 222 | public void getDimBounds(Rect out) { |
| 223 | getBounds(out); |
| 224 | } |
| 225 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 226 | void updateDisplayInfo(Rect bounds) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 227 | if (mDisplayContent != null) { |
Wale Ogunwale | 1ed0d89 | 2015-09-28 13:27:44 -0700 | [diff] [blame] | 228 | for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 229 | mTasks.get(taskNdx).updateDisplayInfo(mDisplayContent); |
| 230 | } |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 231 | if (bounds != null) { |
| 232 | setBounds(bounds); |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 233 | } else if (mFullscreen) { |
| 234 | setBounds(null); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 235 | } else { |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 236 | mTmpRect2.set(mBounds); |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 237 | mDisplayContent.rotateBounds( |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 238 | mRotation, mDisplayContent.getDisplayInfo().rotation, mTmpRect2); |
| 239 | if (setBounds(mTmpRect2)) { |
Wale Ogunwale | 1ed0d89 | 2015-09-28 13:27:44 -0700 | [diff] [blame] | 240 | // Post message to inform activity manager of the bounds change simulating |
| 241 | // a one-way call. We do this to prevent a deadlock between window manager |
| 242 | // lock and activity manager lock been held. |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 243 | mService.mH.sendMessage(mService.mH.obtainMessage( |
| 244 | RESIZE_STACK, mStackId, 0 /*allowResizeInDockedMode*/, mBounds)); |
Wale Ogunwale | 1ed0d89 | 2015-09-28 13:27:44 -0700 | [diff] [blame] | 245 | } |
Wale Ogunwale | 4a02d81 | 2015-02-12 23:01:38 -0800 | [diff] [blame] | 246 | } |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | |
Craig Mautner | 1bf2b87 | 2014-02-05 15:37:40 -0800 | [diff] [blame] | 250 | boolean isAnimating() { |
| 251 | for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 252 | final ArrayList<AppWindowToken> activities = mTasks.get(taskNdx).mAppTokens; |
| 253 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 254 | final ArrayList<WindowState> windows = activities.get(activityNdx).allAppWindows; |
| 255 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
Craig Mautner | bc2a6df | 2014-06-13 15:08:48 -0700 | [diff] [blame] | 256 | final WindowStateAnimator winAnimator = windows.get(winNdx).mWinAnimator; |
Craig Mautner | 7c9ee19 | 2014-08-14 16:08:26 -0700 | [diff] [blame] | 257 | if (winAnimator.isAnimating() || winAnimator.mWin.mExiting) { |
Craig Mautner | 1bf2b87 | 2014-02-05 15:37:40 -0800 | [diff] [blame] | 258 | return true; |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | return false; |
| 264 | } |
| 265 | |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 266 | void addTask(Task task, boolean toTop) { |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 267 | addTask(task, toTop, task.showForAllUsers()); |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 270 | /** |
| 271 | * Put a Task in this stack. Used for adding and moving. |
| 272 | * @param task The task to add. |
| 273 | * @param toTop Whether to add it to the top or bottom. |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 274 | * @param showForAllUsers Whether to show the task regardless of the current user. |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 275 | */ |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 276 | void addTask(Task task, boolean toTop, boolean showForAllUsers) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 277 | positionTask(task, toTop ? mTasks.size() : 0, showForAllUsers); |
| 278 | } |
| 279 | |
| 280 | void positionTask(Task task, int position, boolean showForAllUsers) { |
| 281 | final boolean canShowTask = |
| 282 | showForAllUsers || mService.isCurrentProfileLocked(task.mUserId); |
| 283 | mTasks.remove(task); |
| 284 | int stackSize = mTasks.size(); |
| 285 | int minPosition = 0; |
| 286 | int maxPosition = stackSize; |
| 287 | |
| 288 | if (canShowTask) { |
| 289 | minPosition = computeMinPosition(minPosition, stackSize); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 290 | } else { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 291 | maxPosition = computeMaxPosition(maxPosition); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 292 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 293 | // Reset position based on minimum/maximum possible positions. |
| 294 | position = Math.min(Math.max(position, minPosition), maxPosition); |
| 295 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 296 | if (DEBUG_TASK_MOVEMENT) Slog.d(TAG_WM, |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 297 | "positionTask: task=" + task + " position=" + position); |
| 298 | mTasks.add(position, task); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 299 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 300 | task.mStack = this; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 301 | task.updateDisplayInfo(mDisplayContent); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 302 | boolean toTop = position == mTasks.size() - 1; |
raysb.kim | 00a2725 | 2014-11-11 08:38:21 +0900 | [diff] [blame] | 303 | if (toTop) { |
| 304 | mDisplayContent.moveStack(this, true); |
| 305 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 306 | EventLog.writeEvent(EventLogTags.WM_TASK_MOVED, task.mTaskId, toTop ? 1 : 0, position); |
| 307 | } |
| 308 | |
| 309 | /** Calculate the minimum possible position for a task that can be shown to the user. |
| 310 | * The minimum position will be above all other tasks that can't be shown. |
| 311 | * @param minPosition The minimum position the caller is suggesting. |
| 312 | * We will start adjusting up from here. |
| 313 | * @param size The size of the current task list. |
| 314 | */ |
| 315 | private int computeMinPosition(int minPosition, int size) { |
| 316 | while (minPosition < size) { |
| 317 | final Task tmpTask = mTasks.get(minPosition); |
| 318 | final boolean canShowTmpTask = |
| 319 | tmpTask.showForAllUsers() |
| 320 | || mService.isCurrentProfileLocked(tmpTask.mUserId); |
| 321 | if (canShowTmpTask) { |
| 322 | break; |
| 323 | } |
| 324 | minPosition++; |
| 325 | } |
| 326 | return minPosition; |
| 327 | } |
| 328 | |
| 329 | /** Calculate the maximum possible position for a task that can't be shown to the user. |
| 330 | * The maximum position will be below all other tasks that can be shown. |
| 331 | * @param maxPosition The maximum position the caller is suggesting. |
| 332 | * We will start adjusting down from here. |
| 333 | */ |
| 334 | private int computeMaxPosition(int maxPosition) { |
| 335 | while (maxPosition > 0) { |
| 336 | final Task tmpTask = mTasks.get(maxPosition - 1); |
| 337 | final boolean canShowTmpTask = |
| 338 | tmpTask.showForAllUsers() |
| 339 | || mService.isCurrentProfileLocked(tmpTask.mUserId); |
| 340 | if (!canShowTmpTask) { |
| 341 | break; |
| 342 | } |
| 343 | maxPosition--; |
| 344 | } |
| 345 | return maxPosition; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 346 | } |
| 347 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 348 | void moveTaskToTop(Task task) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 349 | if (DEBUG_TASK_MOVEMENT) Slog.d(TAG_WM, "moveTaskToTop: task=" + task + " Callers=" |
Craig Mautner | f0ac5c8 | 2013-06-24 11:21:57 -0700 | [diff] [blame] | 350 | + Debug.getCallers(6)); |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 351 | mTasks.remove(task); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 352 | addTask(task, true); |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 355 | void moveTaskToBottom(Task task) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 356 | if (DEBUG_TASK_MOVEMENT) Slog.d(TAG_WM, "moveTaskToBottom: task=" + task); |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 357 | mTasks.remove(task); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 358 | addTask(task, false); |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 361 | /** |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 362 | * Delete a Task from this stack. If it is the last Task in the stack, move this stack to the |
| 363 | * back. |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 364 | * @param task The Task to delete. |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 365 | */ |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 366 | void removeTask(Task task) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 367 | if (DEBUG_TASK_MOVEMENT) Slog.d(TAG_WM, "removeTask: task=" + task); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 368 | mTasks.remove(task); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 369 | if (mDisplayContent != null) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 370 | if (mTasks.isEmpty()) { |
| 371 | mDisplayContent.moveStack(this, false); |
| 372 | } |
| 373 | mDisplayContent.layoutNeeded = true; |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 374 | } |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 375 | for (int appNdx = mExitingAppTokens.size() - 1; appNdx >= 0; --appNdx) { |
| 376 | final AppWindowToken wtoken = mExitingAppTokens.get(appNdx); |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 377 | if (wtoken.mTask == task) { |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 378 | wtoken.mIsExiting = false; |
| 379 | mExitingAppTokens.remove(appNdx); |
| 380 | } |
| 381 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 382 | } |
| 383 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 384 | void attachDisplayContent(DisplayContent displayContent) { |
| 385 | if (mDisplayContent != null) { |
| 386 | throw new IllegalStateException("attachDisplayContent: Already attached"); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 387 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 388 | |
| 389 | mDisplayContent = displayContent; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 390 | mAnimationBackgroundSurface = new DimLayer(mService, this, mDisplayContent.getDisplayId()); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 391 | |
| 392 | Rect bounds = null; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 393 | final TaskStack dockedStack = mService.mStackIdToStack.get(DOCKED_STACK_ID); |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 394 | if (mStackId == DOCKED_STACK_ID |
| 395 | || (dockedStack != null && StackId.isResizeableByDockedStack(mStackId))) { |
| 396 | // The existence of a docked stack affects the size of other static stack created since |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 397 | // the docked stack occupies a dedicated region on screen. |
| 398 | bounds = new Rect(); |
| 399 | displayContent.getLogicalDisplayRect(mTmpRect); |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 400 | mTmpRect2.setEmpty(); |
| 401 | if (dockedStack != null) { |
| 402 | dockedStack.getRawBounds(mTmpRect2); |
| 403 | } |
Jorim Jaggi | 9ea2f7b | 2015-11-23 18:08:28 -0800 | [diff] [blame] | 404 | final boolean dockedOnTopOrLeft = mService.mDockedStackCreateMode |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 405 | == DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT; |
| 406 | getStackDockedModeBounds(mTmpRect, bounds, mStackId, mTmpRect2, |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 407 | mDisplayContent.mDividerControllerLocked.getContentWidth(), |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 408 | dockedOnTopOrLeft); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | updateDisplayInfo(bounds); |
| 412 | |
| 413 | if (mStackId == DOCKED_STACK_ID) { |
| 414 | // Attaching a docked stack to the display affects the size of all other static |
| 415 | // stacks since the docked stack occupies a dedicated region on screen. |
| 416 | // Resize existing static stacks so they are pushed to the side of the docked stack. |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 417 | resizeNonDockedStacks(!FULLSCREEN, mBounds); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 421 | void getStackDockedModeBoundsLocked(Rect outBounds) { |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 422 | if (!StackId.isResizeableByDockedStack(mStackId) || mDisplayContent == null) { |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 423 | outBounds.set(mBounds); |
| 424 | return; |
| 425 | } |
| 426 | |
Filip Gruszczynski | 54977fe | 2015-10-19 17:26:45 -0700 | [diff] [blame] | 427 | final TaskStack dockedStack = mService.mStackIdToStack.get(DOCKED_STACK_ID); |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 428 | if (dockedStack == null) { |
| 429 | // Not sure why you are calling this method when there is no docked stack... |
| 430 | throw new IllegalStateException( |
| 431 | "Calling getStackDockedModeBoundsLocked() when there is no docked stack."); |
| 432 | } |
Filip Gruszczynski | 54977fe | 2015-10-19 17:26:45 -0700 | [diff] [blame] | 433 | if (!dockedStack.isVisibleLocked()) { |
| 434 | // The docked stack is being dismissed, but we caught before it finished being |
| 435 | // dismissed. In that case we want to treat it as if it is not occupying any space and |
| 436 | // let others occupy the whole display. |
| 437 | mDisplayContent.getLogicalDisplayRect(mTmpRect); |
| 438 | return; |
| 439 | } |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 440 | |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 441 | final int dockedSide = dockedStack.getDockSide(); |
| 442 | if (dockedSide == DOCKED_INVALID) { |
| 443 | // Not sure how you got here...Only thing we can do is return current bounds. |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 444 | Slog.e(TAG_WM, "Failed to get valid docked side for docked stack=" + dockedStack); |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 445 | outBounds.set(mBounds); |
| 446 | return; |
| 447 | } |
| 448 | |
| 449 | mDisplayContent.getLogicalDisplayRect(mTmpRect); |
| 450 | dockedStack.getRawBounds(mTmpRect2); |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 451 | final boolean dockedOnTopOrLeft = dockedSide == DOCKED_TOP |
| 452 | || dockedSide == DOCKED_LEFT; |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 453 | getStackDockedModeBounds(mTmpRect, outBounds, mStackId, mTmpRect2, |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 454 | mDisplayContent.mDividerControllerLocked.getContentWidth(), dockedOnTopOrLeft); |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 455 | |
| 456 | } |
| 457 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 458 | /** |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 459 | * Outputs the bounds a stack should be given the presence of a docked stack on the display. |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 460 | * @param displayRect The bounds of the display the docked stack is on. |
| 461 | * @param outBounds Output bounds that should be used for the stack. |
| 462 | * @param stackId Id of stack we are calculating the bounds for. |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 463 | * @param dockedBounds Bounds of the docked stack. |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 464 | * @param dockDividerWidth We need to know the width of the divider make to the output bounds |
| 465 | * close to the side of the dock. |
| 466 | * @param dockOnTopOrLeft If the docked stack is on the top or left side of the screen. |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 467 | */ |
Jorim Jaggi | 9ea2f7b | 2015-11-23 18:08:28 -0800 | [diff] [blame] | 468 | private void getStackDockedModeBounds( |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 469 | Rect displayRect, Rect outBounds, int stackId, Rect dockedBounds, int dockDividerWidth, |
| 470 | boolean dockOnTopOrLeft) { |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 471 | final boolean dockedStack = stackId == DOCKED_STACK_ID; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 472 | final boolean splitHorizontally = displayRect.width() > displayRect.height(); |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 473 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 474 | outBounds.set(displayRect); |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 475 | if (dockedStack) { |
Jorim Jaggi | 9ea2f7b | 2015-11-23 18:08:28 -0800 | [diff] [blame] | 476 | if (mService.mDockedStackCreateBounds != null) { |
| 477 | outBounds.set(mService.mDockedStackCreateBounds); |
| 478 | return; |
| 479 | } |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 480 | // The initial bounds of the docked stack when it is created half the screen space and |
| 481 | // its bounds can be adjusted after that. The bounds of all other stacks are adjusted |
| 482 | // to occupy whatever screen space the docked stack isn't occupying. |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 483 | if (dockOnTopOrLeft) { |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 484 | if (splitHorizontally) { |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 485 | outBounds.right = displayRect.centerX() - dockDividerWidth / 2; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 486 | } else { |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 487 | outBounds.bottom = displayRect.centerY() - dockDividerWidth / 2; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 488 | } |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 489 | } else { |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 490 | if (splitHorizontally) { |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 491 | outBounds.left = displayRect.centerX() + dockDividerWidth / 2; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 492 | } else { |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 493 | outBounds.top = displayRect.centerY() + dockDividerWidth / 2; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 494 | } |
| 495 | } |
| 496 | return; |
| 497 | } |
| 498 | |
| 499 | // Other stacks occupy whatever space is left by the docked stack. |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 500 | if (!dockOnTopOrLeft) { |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 501 | if (splitHorizontally) { |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 502 | outBounds.right = dockedBounds.left - dockDividerWidth; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 503 | } else { |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 504 | outBounds.bottom = dockedBounds.top - dockDividerWidth; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 505 | } |
| 506 | } else { |
| 507 | if (splitHorizontally) { |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 508 | outBounds.left = dockedBounds.right + dockDividerWidth; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 509 | } else { |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 510 | outBounds.top = dockedBounds.bottom + dockDividerWidth; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 511 | } |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | /** Resizes all non-docked stacks in the system to either fullscreen or the appropriate size |
| 516 | * based on the presence of a docked stack. |
| 517 | * @param fullscreen If true the stacks will be resized to fullscreen, else they will be |
| 518 | * resized to the appropriate size based on the presence of a docked stack. |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 519 | * @param dockedBounds Bounds of the docked stack. |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 520 | */ |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 521 | private void resizeNonDockedStacks(boolean fullscreen, Rect dockedBounds) { |
| 522 | // Not using mTmpRect because we are posting the object in a message. |
| 523 | final Rect bounds = new Rect(); |
| 524 | mDisplayContent.getLogicalDisplayRect(bounds); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 525 | if (!fullscreen) { |
Jorim Jaggi | 9ea2f7b | 2015-11-23 18:08:28 -0800 | [diff] [blame] | 526 | final boolean dockedOnTopOrLeft = mService.mDockedStackCreateMode |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 527 | == DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT; |
| 528 | getStackDockedModeBounds(bounds, bounds, FULLSCREEN_WORKSPACE_STACK_ID, dockedBounds, |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 529 | mDisplayContent.mDividerControllerLocked.getContentWidth(), dockedOnTopOrLeft); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | final int count = mService.mStackIdToStack.size(); |
| 533 | for (int i = 0; i < count; i++) { |
| 534 | final TaskStack otherStack = mService.mStackIdToStack.valueAt(i); |
| 535 | final int otherStackId = otherStack.mStackId; |
Wale Ogunwale | 3856bf7 | 2015-11-20 09:36:46 -0800 | [diff] [blame] | 536 | if (StackId.isResizeableByDockedStack(otherStackId) |
| 537 | && !otherStack.mBounds.equals(bounds)) { |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 538 | mService.mH.sendMessage( |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 539 | mService.mH.obtainMessage(RESIZE_STACK, otherStackId, |
Wale Ogunwale | 3856bf7 | 2015-11-20 09:36:46 -0800 | [diff] [blame] | 540 | 1 /*allowResizeInDockedMode*/, fullscreen ? null : bounds)); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 541 | } |
| 542 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 543 | } |
| 544 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 545 | void detachDisplay() { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 546 | EventLog.writeEvent(EventLogTags.WM_STACK_REMOVED, mStackId); |
Craig Mautner | bc2a6df | 2014-06-13 15:08:48 -0700 | [diff] [blame] | 547 | |
| 548 | boolean doAnotherLayoutPass = false; |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 549 | for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | bc2a6df | 2014-06-13 15:08:48 -0700 | [diff] [blame] | 550 | final AppTokenList appWindowTokens = mTasks.get(taskNdx).mAppTokens; |
| 551 | for (int appNdx = appWindowTokens.size() - 1; appNdx >= 0; --appNdx) { |
| 552 | final WindowList appWindows = appWindowTokens.get(appNdx).allAppWindows; |
| 553 | for (int winNdx = appWindows.size() - 1; winNdx >= 0; --winNdx) { |
Filip Gruszczynski | d66af6a | 2015-08-31 08:57:24 -0700 | [diff] [blame] | 554 | // We are in the middle of changing the state of displays/stacks/tasks. We need |
| 555 | // to finish that, before we let layout interfere with it. |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 556 | mService.removeWindowLocked(appWindows.get(winNdx)); |
Craig Mautner | bc2a6df | 2014-06-13 15:08:48 -0700 | [diff] [blame] | 557 | doAnotherLayoutPass = true; |
| 558 | } |
| 559 | } |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 560 | } |
Craig Mautner | bc2a6df | 2014-06-13 15:08:48 -0700 | [diff] [blame] | 561 | if (doAnotherLayoutPass) { |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 562 | mService.mWindowPlacerLocked.requestTraversal(); |
Craig Mautner | bc2a6df | 2014-06-13 15:08:48 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 565 | if (mStackId == DOCKED_STACK_ID) { |
| 566 | // Docked stack was detached from the display, so we no longer need to restrict the |
| 567 | // region of the screen other static stacks occupy. Go ahead and make them fullscreen. |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 568 | resizeNonDockedStacks(FULLSCREEN, null); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 569 | } |
| 570 | |
Craig Mautner | 00a6675 | 2015-03-23 14:00:47 -0700 | [diff] [blame] | 571 | close(); |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 574 | void resetAnimationBackgroundAnimator() { |
| 575 | mAnimationBackgroundAnimator = null; |
| 576 | mAnimationBackgroundSurface.hide(); |
| 577 | } |
| 578 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 579 | void setAnimationBackground(WindowStateAnimator winAnimator, int color) { |
| 580 | int animLayer = winAnimator.mAnimLayer; |
| 581 | if (mAnimationBackgroundAnimator == null |
| 582 | || animLayer < mAnimationBackgroundAnimator.mAnimLayer) { |
| 583 | mAnimationBackgroundAnimator = winAnimator; |
| 584 | animLayer = mService.adjustAnimationBackground(winAnimator); |
| 585 | mAnimationBackgroundSurface.show(animLayer - WindowManagerService.LAYER_OFFSET_DIM, |
| 586 | ((color >> 24) & 0xff) / 255f, 0); |
| 587 | } |
| 588 | } |
| 589 | |
Wale Ogunwale | 498e8c9 | 2015-02-13 09:42:46 -0800 | [diff] [blame] | 590 | void switchUser() { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 591 | int top = mTasks.size(); |
| 592 | for (int taskNdx = 0; taskNdx < top; ++taskNdx) { |
| 593 | Task task = mTasks.get(taskNdx); |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 594 | if (mService.isCurrentProfileLocked(task.mUserId) || task.showForAllUsers()) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 595 | mTasks.remove(taskNdx); |
| 596 | mTasks.add(task); |
| 597 | --top; |
| 598 | } |
| 599 | } |
| 600 | } |
| 601 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 602 | void close() { |
Craig Mautner | 00a6675 | 2015-03-23 14:00:47 -0700 | [diff] [blame] | 603 | if (mAnimationBackgroundSurface != null) { |
| 604 | mAnimationBackgroundSurface.destroySurface(); |
| 605 | mAnimationBackgroundSurface = null; |
| 606 | } |
Filip Gruszczynski | 26ed265 | 2015-08-10 11:02:53 -0700 | [diff] [blame] | 607 | mDisplayContent = null; |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 608 | } |
| 609 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 610 | public void dump(String prefix, PrintWriter pw) { |
| 611 | pw.print(prefix); pw.print("mStackId="); pw.println(mStackId); |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 612 | pw.print(prefix); pw.print("mDeferDetach="); pw.println(mDeferDetach); |
Wale Ogunwale | 56b88af | 2015-12-01 07:21:59 -0800 | [diff] [blame] | 613 | pw.print(prefix); pw.print("mFullscreen="); pw.println(mFullscreen); |
| 614 | pw.print(prefix); pw.print("mBounds="); pw.println(mBounds.toShortString()); |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 615 | for (int taskNdx = 0; taskNdx < mTasks.size(); ++taskNdx) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 616 | pw.print(prefix); |
| 617 | mTasks.get(taskNdx).printTo(prefix + " ", pw); |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 618 | } |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 619 | if (mAnimationBackgroundSurface.isDimming()) { |
| 620 | pw.print(prefix); pw.println("mWindowAnimationBackgroundSurface:"); |
| 621 | mAnimationBackgroundSurface.printTo(prefix + " ", pw); |
| 622 | } |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 623 | if (!mExitingAppTokens.isEmpty()) { |
| 624 | pw.println(); |
| 625 | pw.println(" Exiting application tokens:"); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 626 | for (int i = mExitingAppTokens.size() - 1; i >= 0; i--) { |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 627 | WindowToken token = mExitingAppTokens.get(i); |
| 628 | pw.print(" Exiting App #"); pw.print(i); |
| 629 | pw.print(' '); pw.print(token); |
| 630 | pw.println(':'); |
| 631 | token.dump(pw, " "); |
| 632 | } |
| 633 | } |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 634 | } |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 635 | |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 636 | /** Fullscreen status of the stack without adjusting for other factors in the system like |
| 637 | * visibility of docked stack. |
| 638 | * Most callers should be using {@link #isFullscreen} as it take into consideration other |
| 639 | * system factors. */ |
| 640 | boolean getRawFullscreen() { |
| 641 | return mFullscreen; |
| 642 | } |
| 643 | |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 644 | @Override |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 645 | public boolean isFullscreen() { |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 646 | if (useCurrentBounds()) { |
| 647 | return mFullscreen; |
| 648 | } |
| 649 | // The bounds has been adjusted to accommodate for a docked stack, but the docked stack |
| 650 | // is not currently visible. Go ahead a represent it as fullscreen to the rest of the |
| 651 | // system. |
| 652 | return true; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | @Override |
| 656 | public DisplayInfo getDisplayInfo() { |
| 657 | return mDisplayContent.getDisplayInfo(); |
| 658 | } |
| 659 | |
| 660 | @Override |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 661 | public String toString() { |
| 662 | return "{stackId=" + mStackId + " tasks=" + mTasks + "}"; |
| 663 | } |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 664 | |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 665 | @Override |
| 666 | public String toShortString() { |
| 667 | return "Stack=" + mStackId; |
| 668 | } |
| 669 | |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 670 | /** |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 671 | * For docked workspace (or workspace that's side-by-side to the docked), provides |
| 672 | * information which side of the screen was the dock anchored. |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 673 | */ |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 674 | int getDockSide() { |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 675 | if (mStackId != DOCKED_STACK_ID && !StackId.isResizeableByDockedStack(mStackId)) { |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 676 | return DOCKED_INVALID; |
| 677 | } |
| 678 | if (mDisplayContent == null) { |
| 679 | return DOCKED_INVALID; |
| 680 | } |
| 681 | mDisplayContent.getLogicalDisplayRect(mTmpRect); |
| 682 | final int orientation = mService.mCurConfiguration.orientation; |
| 683 | if (orientation == Configuration.ORIENTATION_PORTRAIT) { |
| 684 | // Portrait mode, docked either at the top or the bottom. |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 685 | if (mBounds.top - mTmpRect.top < mTmpRect.bottom - mBounds.bottom) { |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 686 | return DOCKED_TOP; |
| 687 | } else { |
| 688 | return DOCKED_BOTTOM; |
| 689 | } |
| 690 | } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { |
| 691 | // Landscape mode, docked either on the left or on the right. |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 692 | if (mBounds.left - mTmpRect.left < mTmpRect.right - mBounds.right) { |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 693 | return DOCKED_LEFT; |
| 694 | } else { |
| 695 | return DOCKED_RIGHT; |
| 696 | } |
| 697 | } else { |
| 698 | return DOCKED_INVALID; |
| 699 | } |
| 700 | } |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 701 | |
| 702 | boolean isVisibleLocked() { |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 703 | final boolean keyguardOn = mService.mPolicy.isKeyguardShowingOrOccluded(); |
| 704 | if (keyguardOn && !StackId.isAllowedOverLockscreen(mStackId)) { |
| 705 | return false; |
| 706 | } |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 707 | for (int i = mTasks.size() - 1; i >= 0; i--) { |
| 708 | Task task = mTasks.get(i); |
| 709 | for (int j = task.mAppTokens.size() - 1; j >= 0; j--) { |
| 710 | if (!task.mAppTokens.get(j).hidden) { |
| 711 | return true; |
| 712 | } |
| 713 | } |
| 714 | } |
| 715 | return false; |
| 716 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 717 | } |