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