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