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 | |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT; |
| 20 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
Jorim Jaggi | d3ec507 | 2016-04-28 15:57:47 -0700 | [diff] [blame^] | 21 | import static android.app.ActivityManager.StackId.HOME_STACK_ID; |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 22 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
| 23 | import static android.content.res.Configuration.DENSITY_DPI_UNDEFINED; |
| 24 | import static android.content.res.Configuration.ORIENTATION_PORTRAIT; |
| 25 | import static android.view.WindowManager.DOCKED_BOTTOM; |
| 26 | import static android.view.WindowManager.DOCKED_INVALID; |
| 27 | import static android.view.WindowManager.DOCKED_LEFT; |
| 28 | import static android.view.WindowManager.DOCKED_RIGHT; |
| 29 | import static android.view.WindowManager.DOCKED_TOP; |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 30 | import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER; |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 31 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_MOVEMENT; |
| 32 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
| 33 | import static com.android.server.wm.WindowManagerService.H.RESIZE_STACK; |
| 34 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 35 | import android.app.ActivityManager.StackId; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 36 | import android.content.res.Configuration; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 37 | import android.graphics.Rect; |
Craig Mautner | f0ac5c8 | 2013-06-24 11:21:57 -0700 | [diff] [blame] | 38 | import android.os.Debug; |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 39 | import android.os.RemoteException; |
Craig Mautner | 2c2549c | 2013-11-12 08:31:15 -0800 | [diff] [blame] | 40 | import android.util.EventLog; |
Craig Mautner | f0ac5c8 | 2013-06-24 11:21:57 -0700 | [diff] [blame] | 41 | import android.util.Slog; |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 42 | import android.util.SparseArray; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 43 | import android.view.DisplayInfo; |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 44 | import android.view.Surface; |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 45 | import android.view.SurfaceControl; |
Filip Gruszczynski | 54977fe | 2015-10-19 17:26:45 -0700 | [diff] [blame] | 46 | |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 47 | import com.android.internal.policy.DividerSnapAlgorithm; |
| 48 | import com.android.internal.policy.DividerSnapAlgorithm.SnapTarget; |
| 49 | import com.android.internal.policy.DockedDividerUtils; |
Craig Mautner | 2c2549c | 2013-11-12 08:31:15 -0800 | [diff] [blame] | 50 | import com.android.server.EventLogTags; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 51 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 52 | import java.io.PrintWriter; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 53 | import java.util.ArrayList; |
| 54 | |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 55 | public class TaskStack implements DimLayer.DimLayerUser, |
| 56 | BoundsAnimationController.AnimateBoundsUser { |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 57 | /** Minimum size of an adjusted stack bounds relative to original stack bounds. Used to |
| 58 | * restrict IME adjustment so that a min portion of top stack remains visible.*/ |
| 59 | private static final float ADJUSTED_STACK_FRACTION_MIN = 0.3f; |
| 60 | |
| 61 | /** Dimming amount for non-focused stack when stacks are IME-adjusted. */ |
| 62 | private static final float IME_ADJUST_DIM_AMOUNT = 0.25f; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 63 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 64 | /** Unique identifier */ |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 65 | final int mStackId; |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 66 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 67 | /** The service */ |
| 68 | private final WindowManagerService mService; |
| 69 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 70 | /** The display this stack sits under. */ |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 71 | private DisplayContent mDisplayContent; |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 72 | |
| 73 | /** The Tasks that define this stack. Oldest Tasks are at the bottom. The ordering must match |
| 74 | * mTaskHistory in the ActivityStack with the same mStackId */ |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 75 | private final ArrayList<Task> mTasks = new ArrayList<>(); |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 76 | |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 77 | /** For comparison with DisplayContent bounds. */ |
| 78 | private Rect mTmpRect = new Rect(); |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 79 | private Rect mTmpRect2 = new Rect(); |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 80 | |
| 81 | /** Content limits relative to the DisplayContent this sits in. */ |
| 82 | private Rect mBounds = new Rect(); |
| 83 | |
Chong Zhang | b816b86 | 2016-01-25 12:01:12 -0800 | [diff] [blame] | 84 | /** Stack bounds adjusted to screen content area (taking into account IM windows, etc.) */ |
| 85 | private final Rect mAdjustedBounds = new Rect(); |
| 86 | |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 87 | /** |
| 88 | * Fully adjusted IME bounds. These are different from {@link #mAdjustedBounds} because they |
| 89 | * represent the state when the animation has ended. |
| 90 | */ |
| 91 | private final Rect mFullyAdjustedImeBounds = new Rect(); |
| 92 | |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 93 | /** Whether mBounds is fullscreen */ |
| 94 | private boolean mFullscreen = true; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 95 | |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 96 | // Device rotation as of the last time {@link #mBounds} was set. |
| 97 | int mRotation; |
| 98 | |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 99 | /** Density as of last time {@link #mBounds} was set. */ |
| 100 | int mDensity; |
| 101 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 102 | /** Support for non-zero {@link android.view.animation.Animation#getBackgroundColor()} */ |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 103 | DimLayer mAnimationBackgroundSurface; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 104 | |
| 105 | /** The particular window with an Animation with non-zero background color. */ |
| 106 | WindowStateAnimator mAnimationBackgroundAnimator; |
| 107 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 108 | /** Application tokens that are exiting, but still on screen for animations. */ |
| 109 | final AppTokenList mExitingAppTokens = new AppTokenList(); |
| 110 | |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 111 | /** Detach this stack from its display when animation completes. */ |
| 112 | boolean mDeferDetach; |
Wale Ogunwale | ecbcadd | 2016-02-21 14:18:51 -0800 | [diff] [blame] | 113 | |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 114 | // Whether the stack and all its tasks is currently being drag-resized |
| 115 | private boolean mDragResizing; |
| 116 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 117 | private final Rect mTmpAdjustedBounds = new Rect(); |
| 118 | private boolean mAdjustedForIme; |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 119 | private boolean mImeGoingAway; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 120 | private WindowState mImeWin; |
| 121 | private float mMinimizeAmount; |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 122 | private float mAdjustImeAmount; |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 123 | private float mAdjustDividerAmount; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 124 | private final int mDockedStackMinimizeThickness; |
| 125 | |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 126 | // If this is true, we are in the bounds animating mode. |
| 127 | // The task will be down or upscaled to perfectly fit the |
| 128 | // region it would have been cropped to. We may also avoid |
| 129 | // certain logic we would otherwise apply while resizing, |
| 130 | // while resizing in the bounds animating mode. |
| 131 | private boolean mBoundsAnimating = false; |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 132 | // By default, movement animations are applied to all |
| 133 | // window movement. If this is true, animations will not |
| 134 | // be applied within this stack. This is useful for example |
| 135 | // if the windows are moving as the result of a stack animation, |
| 136 | // in which case a second window animation would cause jitter. |
| 137 | private boolean mFreezeMovementAnimations = false; |
| 138 | |
Chong Zhang | 167bbfac | 2016-03-31 09:44:34 -0700 | [diff] [blame] | 139 | // Temporary storage for the new bounds that should be used after the configuration change. |
| 140 | // Will be cleared once the client retrieves the new bounds via getBoundsForNewConfiguration(). |
| 141 | private final Rect mBoundsAfterRotation = new Rect(); |
| 142 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 143 | TaskStack(WindowManagerService service, int stackId) { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 144 | mService = service; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 145 | mStackId = stackId; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 146 | mDockedStackMinimizeThickness = service.mContext.getResources().getDimensionPixelSize( |
| 147 | com.android.internal.R.dimen.docked_stack_minimize_thickness); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 148 | EventLog.writeEvent(EventLogTags.WM_STACK_CREATED, stackId); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | DisplayContent getDisplayContent() { |
| 152 | return mDisplayContent; |
| 153 | } |
| 154 | |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 155 | ArrayList<Task> getTasks() { |
| 156 | return mTasks; |
| 157 | } |
| 158 | |
Jorim Jaggi | d3ec507 | 2016-04-28 15:57:47 -0700 | [diff] [blame^] | 159 | Task findHomeTask() { |
| 160 | if (mStackId != HOME_STACK_ID) { |
| 161 | return null; |
| 162 | } |
| 163 | |
| 164 | for (int i = mTasks.size() - 1; i >= 0; i--) { |
| 165 | if (mTasks.get(i).isHomeTask()) { |
| 166 | return mTasks.get(i); |
| 167 | } |
| 168 | } |
| 169 | return null; |
| 170 | } |
| 171 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 172 | /** |
| 173 | * Set the bounds of the stack and its containing tasks. |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 174 | * @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] | 175 | * @param configs Configuration for individual tasks, keyed by task id. |
| 176 | * @param taskBounds Bounds for individual tasks, keyed by task id. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 177 | * @return True if the stack bounds was changed. |
| 178 | * */ |
Wale Ogunwale | a6e902e | 2015-09-21 18:37:15 -0700 | [diff] [blame] | 179 | boolean setBounds( |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 180 | Rect stackBounds, SparseArray<Configuration> configs, SparseArray<Rect> taskBounds, |
| 181 | SparseArray<Rect> taskTempInsetBounds) { |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 182 | setBounds(stackBounds); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 183 | |
| 184 | // Update bounds of containing tasks. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 185 | for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 186 | final Task task = mTasks.get(taskNdx); |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 187 | Configuration config = configs.get(task.mTaskId); |
| 188 | if (config != null) { |
| 189 | Rect bounds = taskBounds.get(task.mTaskId); |
Chong Zhang | 2a88fc3 | 2016-01-11 17:14:24 -0800 | [diff] [blame] | 190 | if (task.isTwoFingerScrollMode()) { |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 191 | // This is a non-resizeable task that's docked (or side-by-side to the docked |
| 192 | // stack). It might have been scrolled previously, and after the stack resizing, |
| 193 | // it might no longer fully cover the stack area. |
| 194 | // Save the old bounds and re-apply the scroll. This adjusts the bounds to |
| 195 | // fit the new stack bounds. |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 196 | task.resizeLocked(bounds, config, false /* forced */); |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 197 | task.getBounds(mTmpRect); |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 198 | task.scrollLocked(mTmpRect); |
| 199 | } else { |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 200 | task.resizeLocked(bounds, config, false /* forced */); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 201 | task.setTempInsetBounds( |
| 202 | taskTempInsetBounds != null ? taskTempInsetBounds.get(task.mTaskId) |
| 203 | : null); |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 204 | } |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 205 | } else { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 206 | 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] | 207 | } |
| 208 | } |
| 209 | return true; |
| 210 | } |
| 211 | |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 212 | void prepareFreezingTaskBounds() { |
| 213 | for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 214 | final Task task = mTasks.get(taskNdx); |
| 215 | task.prepareFreezingBounds(); |
| 216 | } |
| 217 | } |
| 218 | |
Wale Ogunwale | b4ec0a3 | 2015-12-14 10:31:43 -0800 | [diff] [blame] | 219 | boolean isFullscreenBounds(Rect bounds) { |
| 220 | if (mDisplayContent == null || bounds == null) { |
| 221 | return true; |
| 222 | } |
| 223 | mDisplayContent.getLogicalDisplayRect(mTmpRect); |
| 224 | return mTmpRect.equals(bounds); |
| 225 | } |
| 226 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 227 | /** |
| 228 | * Overrides the adjusted bounds, i.e. sets temporary layout bounds which are different from |
| 229 | * the normal task bounds. |
| 230 | * |
| 231 | * @param bounds The adjusted bounds. |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 232 | */ |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 233 | private void setAdjustedBounds(Rect bounds) { |
| 234 | if (mAdjustedBounds.equals(bounds) && !isAnimatingForIme()) { |
| 235 | return; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | mAdjustedBounds.set(bounds); |
| 239 | final boolean adjusted = !mAdjustedBounds.isEmpty(); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 240 | Rect insetBounds = null; |
| 241 | if (adjusted && isAdjustedForMinimizedDock()) { |
| 242 | insetBounds = mBounds; |
| 243 | } else if (adjusted && isAdjustedForIme()) { |
| 244 | if (mImeGoingAway) { |
| 245 | insetBounds = mBounds; |
| 246 | } else { |
| 247 | insetBounds = mFullyAdjustedImeBounds; |
| 248 | } |
| 249 | } |
| 250 | alignTasksToAdjustedBounds(adjusted ? mAdjustedBounds : mBounds, insetBounds); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 251 | mDisplayContent.layoutNeeded = true; |
| 252 | } |
| 253 | |
| 254 | private void alignTasksToAdjustedBounds(Rect adjustedBounds, Rect tempInsetBounds) { |
Chong Zhang | b816b86 | 2016-01-25 12:01:12 -0800 | [diff] [blame] | 255 | if (mFullscreen) { |
| 256 | return; |
| 257 | } |
| 258 | // Update bounds of containing tasks. |
| 259 | for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 260 | final Task task = mTasks.get(taskNdx); |
| 261 | if (task.isTwoFingerScrollMode()) { |
| 262 | // If we're scrolling we don't care about your bounds or configs, |
| 263 | // they should be null as if we were in fullscreen. |
| 264 | task.resizeLocked(null, null, false /* forced */); |
| 265 | task.getBounds(mTmpRect2); |
| 266 | task.scrollLocked(mTmpRect2); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 267 | } else if (task.isResizeable() && task.mOverrideConfig != Configuration.EMPTY) { |
Chong Zhang | b816b86 | 2016-01-25 12:01:12 -0800 | [diff] [blame] | 268 | task.getBounds(mTmpRect2); |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 269 | if (mAdjustedForIme && getDockSide() == DOCKED_TOP) { |
| 270 | int offsetY = adjustedBounds.bottom - mTmpRect2.bottom; |
| 271 | mTmpRect2.offset(0, offsetY); |
| 272 | } else { |
| 273 | mTmpRect2.offsetTo(adjustedBounds.left, adjustedBounds.top); |
| 274 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 275 | task.setTempInsetBounds(tempInsetBounds); |
Chong Zhang | b816b86 | 2016-01-25 12:01:12 -0800 | [diff] [blame] | 276 | task.resizeLocked(mTmpRect2, task.mOverrideConfig, false /* forced */); |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 281 | private boolean setBounds(Rect bounds) { |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 282 | boolean oldFullscreen = mFullscreen; |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 283 | int rotation = Surface.ROTATION_0; |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 284 | int density = DENSITY_DPI_UNDEFINED; |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 285 | if (mDisplayContent != null) { |
| 286 | mDisplayContent.getLogicalDisplayRect(mTmpRect); |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 287 | rotation = mDisplayContent.getDisplayInfo().rotation; |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 288 | density = mDisplayContent.getDisplayInfo().logicalDensityDpi; |
Jorim Jaggi | 067e817 | 2016-02-03 18:24:12 -0800 | [diff] [blame] | 289 | mFullscreen = bounds == null; |
| 290 | if (mFullscreen) { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 291 | bounds = mTmpRect; |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 292 | } |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 293 | } |
| 294 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 295 | if (bounds == null) { |
Wale Ogunwale | 4a02d81 | 2015-02-12 23:01:38 -0800 | [diff] [blame] | 296 | // 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] | 297 | return false; |
| 298 | } |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 299 | if (mBounds.equals(bounds) && oldFullscreen == mFullscreen && mRotation == rotation) { |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 300 | return false; |
| 301 | } |
| 302 | |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 303 | if (mDisplayContent != null) { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 304 | mDisplayContent.mDimLayerController.updateDimLayer(this); |
Filip Gruszczynski | 57b6cce | 2015-10-06 09:50:51 -0700 | [diff] [blame] | 305 | mAnimationBackgroundSurface.setBounds(bounds); |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 308 | mBounds.set(bounds); |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 309 | mRotation = rotation; |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 310 | mDensity = density; |
Chong Zhang | b816b86 | 2016-01-25 12:01:12 -0800 | [diff] [blame] | 311 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 312 | updateAdjustedBounds(); |
Chong Zhang | b816b86 | 2016-01-25 12:01:12 -0800 | [diff] [blame] | 313 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 314 | return true; |
| 315 | } |
| 316 | |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 317 | /** Bounds of the stack without adjusting for other factors in the system like visibility |
| 318 | * of docked stack. |
| 319 | * Most callers should be using {@link #getBounds} as it take into consideration other system |
| 320 | * factors. */ |
| 321 | void getRawBounds(Rect out) { |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 322 | out.set(mBounds); |
| 323 | } |
| 324 | |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 325 | /** Return true if the current bound can get outputted to the rest of the system as-is. */ |
| 326 | private boolean useCurrentBounds() { |
| 327 | if (mFullscreen |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 328 | || !StackId.isResizeableByDockedStack(mStackId) |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 329 | || mDisplayContent == null |
| 330 | || mDisplayContent.getDockedStackLocked() != null) { |
| 331 | return true; |
| 332 | } |
| 333 | return false; |
| 334 | } |
| 335 | |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 336 | public void getBounds(Rect out) { |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 337 | if (useCurrentBounds()) { |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 338 | // If we're currently adjusting for IME or minimized docked stack, we use the adjusted |
| 339 | // bounds; otherwise, no need to adjust the output bounds if fullscreen or the docked |
| 340 | // stack is visible since it is already what we want to represent to the rest of the |
| 341 | // system. |
| 342 | if (!mAdjustedBounds.isEmpty()) { |
Chong Zhang | b816b86 | 2016-01-25 12:01:12 -0800 | [diff] [blame] | 343 | out.set(mAdjustedBounds); |
| 344 | } else { |
| 345 | out.set(mBounds); |
| 346 | } |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 347 | return; |
| 348 | } |
| 349 | |
| 350 | // The bounds has been adjusted to accommodate for a docked stack, but the docked stack |
| 351 | // is not currently visible. Go ahead a represent it as fullscreen to the rest of the |
| 352 | // system. |
| 353 | mDisplayContent.getLogicalDisplayRect(out); |
| 354 | } |
| 355 | |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 356 | /** Bounds of the stack with other system factors taken into consideration. */ |
| 357 | @Override |
| 358 | public void getDimBounds(Rect out) { |
| 359 | getBounds(out); |
| 360 | } |
| 361 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 362 | void updateDisplayInfo(Rect bounds) { |
Wale Ogunwale | ecbcadd | 2016-02-21 14:18:51 -0800 | [diff] [blame] | 363 | if (mDisplayContent == null) { |
| 364 | return; |
| 365 | } |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 366 | |
Wale Ogunwale | ecbcadd | 2016-02-21 14:18:51 -0800 | [diff] [blame] | 367 | for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 368 | mTasks.get(taskNdx).updateDisplayInfo(mDisplayContent); |
| 369 | } |
| 370 | if (bounds != null) { |
| 371 | setBounds(bounds); |
| 372 | return; |
| 373 | } else if (mFullscreen) { |
| 374 | setBounds(null); |
| 375 | return; |
| 376 | } |
| 377 | |
| 378 | mTmpRect2.set(mBounds); |
| 379 | final int newRotation = mDisplayContent.getDisplayInfo().rotation; |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 380 | final int newDensity = mDisplayContent.getDisplayInfo().logicalDensityDpi; |
| 381 | if (mRotation == newRotation && mDensity == newDensity) { |
Wale Ogunwale | ecbcadd | 2016-02-21 14:18:51 -0800 | [diff] [blame] | 382 | setBounds(mTmpRect2); |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 383 | } |
Jorim Jaggi | eb1cb92 | 2016-04-27 20:37:45 -0700 | [diff] [blame] | 384 | |
| 385 | // If the rotation or density didn't match, we'll update it in onConfigurationChanged. |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 386 | } |
| 387 | |
Chong Zhang | 167bbfac | 2016-03-31 09:44:34 -0700 | [diff] [blame] | 388 | boolean onConfigurationChanged() { |
Jorim Jaggi | eb1cb92 | 2016-04-27 20:37:45 -0700 | [diff] [blame] | 389 | return updateBoundsAfterConfigChange(); |
Wale Ogunwale | ecbcadd | 2016-02-21 14:18:51 -0800 | [diff] [blame] | 390 | } |
| 391 | |
Jorim Jaggi | eb1cb92 | 2016-04-27 20:37:45 -0700 | [diff] [blame] | 392 | private boolean updateBoundsAfterConfigChange() { |
Wale Ogunwale | 5952f9a | 2016-04-25 13:40:30 -0700 | [diff] [blame] | 393 | if (mFullscreen) { |
| 394 | // Bounds will already be set correctly when display info is updated in the case of |
| 395 | // fullscreen. |
| 396 | return false; |
| 397 | } |
| 398 | |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 399 | final int newRotation = getDisplayInfo().rotation; |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 400 | final int newDensity = getDisplayInfo().logicalDensityDpi; |
Wale Ogunwale | ecbcadd | 2016-02-21 14:18:51 -0800 | [diff] [blame] | 401 | |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 402 | if (mRotation == newRotation && mDensity == newDensity) { |
Jorim Jaggi | eb1cb92 | 2016-04-27 20:37:45 -0700 | [diff] [blame] | 403 | // Nothing to do here as we already update the state in updateDisplayInfo. |
Chong Zhang | 167bbfac | 2016-03-31 09:44:34 -0700 | [diff] [blame] | 404 | return false; |
Wale Ogunwale | ecbcadd | 2016-02-21 14:18:51 -0800 | [diff] [blame] | 405 | } |
| 406 | |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 407 | final int oldDockSide = mStackId == DOCKED_STACK_ID ? getDockSide() : DOCKED_INVALID; |
Wale Ogunwale | 5952f9a | 2016-04-25 13:40:30 -0700 | [diff] [blame] | 408 | mTmpRect2.set(mBounds); |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 409 | mDisplayContent.rotateBounds(mRotation, newRotation, mTmpRect2); |
| 410 | if (mStackId == DOCKED_STACK_ID) { |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 411 | repositionDockedStackAfterRotation(mTmpRect2); |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 412 | snapDockedStackAfterRotation(mTmpRect2); |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 413 | final int newDockSide = getDockSide(mTmpRect2); |
| 414 | if (oldDockSide != newDockSide) { |
| 415 | mDisplayContent.getDockedDividerController().notifyDockSideChanged(newDockSide); |
| 416 | } |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 417 | } |
| 418 | |
Jorim Jaggi | eb1cb92 | 2016-04-27 20:37:45 -0700 | [diff] [blame] | 419 | mBoundsAfterRotation.set(mTmpRect2); |
Chong Zhang | 167bbfac | 2016-03-31 09:44:34 -0700 | [diff] [blame] | 420 | return true; |
| 421 | } |
| 422 | |
| 423 | void getBoundsForNewConfiguration(Rect outBounds) { |
| 424 | outBounds.set(mBoundsAfterRotation); |
| 425 | mBoundsAfterRotation.setEmpty(); |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | /** |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 429 | * Some dock sides are not allowed by the policy. This method queries the policy and moves |
| 430 | * the docked stack around if needed. |
| 431 | * |
| 432 | * @param inOutBounds the bounds of the docked stack to adjust |
| 433 | */ |
| 434 | private void repositionDockedStackAfterRotation(Rect inOutBounds) { |
| 435 | int dockSide = getDockSide(inOutBounds); |
| 436 | if (mService.mPolicy.isDockSideAllowed(dockSide)) { |
| 437 | return; |
| 438 | } |
| 439 | mDisplayContent.getLogicalDisplayRect(mTmpRect); |
| 440 | dockSide = DockedDividerUtils.invertDockSide(dockSide); |
| 441 | switch (dockSide) { |
| 442 | case DOCKED_LEFT: |
| 443 | int movement = inOutBounds.left; |
| 444 | inOutBounds.left -= movement; |
| 445 | inOutBounds.right -= movement; |
| 446 | break; |
| 447 | case DOCKED_RIGHT: |
| 448 | movement = mTmpRect.right - inOutBounds.right; |
| 449 | inOutBounds.left += movement; |
| 450 | inOutBounds.right += movement; |
| 451 | break; |
| 452 | case DOCKED_TOP: |
| 453 | movement = inOutBounds.top; |
| 454 | inOutBounds.top -= movement; |
| 455 | inOutBounds.bottom -= movement; |
| 456 | break; |
| 457 | case DOCKED_BOTTOM: |
| 458 | movement = mTmpRect.bottom - inOutBounds.bottom; |
| 459 | inOutBounds.top += movement; |
| 460 | inOutBounds.bottom += movement; |
| 461 | break; |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | /** |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 466 | * Snaps the bounds after rotation to the closest snap target for the docked stack. |
| 467 | */ |
| 468 | private void snapDockedStackAfterRotation(Rect outBounds) { |
| 469 | |
| 470 | // Calculate the current position. |
| 471 | final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo(); |
| 472 | final int dividerSize = mService.getDefaultDisplayContentLocked() |
| 473 | .getDockedDividerController().getContentWidth(); |
| 474 | final int dockSide = getDockSide(outBounds); |
| 475 | final int dividerPosition = DockedDividerUtils.calculatePositionForBounds(outBounds, |
| 476 | dockSide, dividerSize); |
| 477 | final int displayWidth = mDisplayContent.getDisplayInfo().logicalWidth; |
| 478 | final int displayHeight = mDisplayContent.getDisplayInfo().logicalHeight; |
| 479 | |
| 480 | // Snap the position to a target. |
| 481 | final int rotation = displayInfo.rotation; |
| 482 | final int orientation = mService.mCurConfiguration.orientation; |
| 483 | mService.mPolicy.getStableInsetsLw(rotation, displayWidth, displayHeight, outBounds); |
| 484 | final DividerSnapAlgorithm algorithm = new DividerSnapAlgorithm( |
Jorim Jaggi | df012d5 | 2016-01-15 22:40:13 -0800 | [diff] [blame] | 485 | mService.mContext.getResources(), displayWidth, displayHeight, |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 486 | dividerSize, orientation == Configuration.ORIENTATION_PORTRAIT, outBounds); |
| 487 | final SnapTarget target = algorithm.calculateNonDismissingSnapTarget(dividerPosition); |
| 488 | |
| 489 | // Recalculate the bounds based on the position of the target. |
| 490 | DockedDividerUtils.calculateBoundsForPosition(target.position, dockSide, |
| 491 | outBounds, displayInfo.logicalWidth, displayInfo.logicalHeight, |
| 492 | dividerSize); |
| 493 | } |
| 494 | |
Craig Mautner | 1bf2b87 | 2014-02-05 15:37:40 -0800 | [diff] [blame] | 495 | boolean isAnimating() { |
| 496 | for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 497 | final ArrayList<AppWindowToken> activities = mTasks.get(taskNdx).mAppTokens; |
| 498 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 499 | final ArrayList<WindowState> windows = activities.get(activityNdx).allAppWindows; |
| 500 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
Craig Mautner | bc2a6df | 2014-06-13 15:08:48 -0700 | [diff] [blame] | 501 | final WindowStateAnimator winAnimator = windows.get(winNdx).mWinAnimator; |
Jorim Jaggi | 5c80c41 | 2016-04-19 20:03:47 -0700 | [diff] [blame] | 502 | if (winAnimator.isAnimationSet() || winAnimator.mWin.mAnimatingExit) { |
Craig Mautner | 1bf2b87 | 2014-02-05 15:37:40 -0800 | [diff] [blame] | 503 | return true; |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | return false; |
| 509 | } |
| 510 | |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 511 | void addTask(Task task, boolean toTop) { |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 512 | addTask(task, toTop, task.showForAllUsers()); |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 515 | /** |
| 516 | * Put a Task in this stack. Used for adding and moving. |
| 517 | * @param task The task to add. |
| 518 | * @param toTop Whether to add it to the top or bottom. |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 519 | * @param showForAllUsers Whether to show the task regardless of the current user. |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 520 | */ |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 521 | void addTask(Task task, boolean toTop, boolean showForAllUsers) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 522 | positionTask(task, toTop ? mTasks.size() : 0, showForAllUsers); |
| 523 | } |
| 524 | |
| 525 | void positionTask(Task task, int position, boolean showForAllUsers) { |
| 526 | final boolean canShowTask = |
| 527 | showForAllUsers || mService.isCurrentProfileLocked(task.mUserId); |
| 528 | mTasks.remove(task); |
| 529 | int stackSize = mTasks.size(); |
| 530 | int minPosition = 0; |
| 531 | int maxPosition = stackSize; |
| 532 | |
| 533 | if (canShowTask) { |
| 534 | minPosition = computeMinPosition(minPosition, stackSize); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 535 | } else { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 536 | maxPosition = computeMaxPosition(maxPosition); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 537 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 538 | // Reset position based on minimum/maximum possible positions. |
| 539 | position = Math.min(Math.max(position, minPosition), maxPosition); |
| 540 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 541 | if (DEBUG_TASK_MOVEMENT) Slog.d(TAG_WM, |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 542 | "positionTask: task=" + task + " position=" + position); |
| 543 | mTasks.add(position, task); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 544 | |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 545 | // If we are moving the task across stacks, the scroll is no longer valid. |
| 546 | if (task.mStack != this) { |
| 547 | task.resetScrollLocked(); |
| 548 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 549 | task.mStack = this; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 550 | task.updateDisplayInfo(mDisplayContent); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 551 | boolean toTop = position == mTasks.size() - 1; |
raysb.kim | 00a2725 | 2014-11-11 08:38:21 +0900 | [diff] [blame] | 552 | if (toTop) { |
| 553 | mDisplayContent.moveStack(this, true); |
| 554 | } |
Robert Carr | 1b5ea72 | 2016-04-20 13:23:28 -0700 | [diff] [blame] | 555 | |
| 556 | if (StackId.windowsAreScaleable(mStackId)) { |
| 557 | // We force windows out of SCALING_MODE_FREEZE |
| 558 | // so that we can continue to animate them |
| 559 | // while a resize is pending. |
| 560 | forceWindowsScaleable(task, true); |
| 561 | } else { |
| 562 | forceWindowsScaleable(task, false); |
| 563 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 564 | EventLog.writeEvent(EventLogTags.WM_TASK_MOVED, task.mTaskId, toTop ? 1 : 0, position); |
| 565 | } |
| 566 | |
| 567 | /** Calculate the minimum possible position for a task that can be shown to the user. |
| 568 | * The minimum position will be above all other tasks that can't be shown. |
| 569 | * @param minPosition The minimum position the caller is suggesting. |
| 570 | * We will start adjusting up from here. |
| 571 | * @param size The size of the current task list. |
| 572 | */ |
| 573 | private int computeMinPosition(int minPosition, int size) { |
| 574 | while (minPosition < size) { |
| 575 | final Task tmpTask = mTasks.get(minPosition); |
| 576 | final boolean canShowTmpTask = |
| 577 | tmpTask.showForAllUsers() |
| 578 | || mService.isCurrentProfileLocked(tmpTask.mUserId); |
| 579 | if (canShowTmpTask) { |
| 580 | break; |
| 581 | } |
| 582 | minPosition++; |
| 583 | } |
| 584 | return minPosition; |
| 585 | } |
| 586 | |
| 587 | /** Calculate the maximum possible position for a task that can't be shown to the user. |
| 588 | * The maximum position will be below all other tasks that can be shown. |
| 589 | * @param maxPosition The maximum position the caller is suggesting. |
| 590 | * We will start adjusting down from here. |
| 591 | */ |
| 592 | private int computeMaxPosition(int maxPosition) { |
| 593 | while (maxPosition > 0) { |
| 594 | final Task tmpTask = mTasks.get(maxPosition - 1); |
| 595 | final boolean canShowTmpTask = |
| 596 | tmpTask.showForAllUsers() |
| 597 | || mService.isCurrentProfileLocked(tmpTask.mUserId); |
| 598 | if (!canShowTmpTask) { |
| 599 | break; |
| 600 | } |
| 601 | maxPosition--; |
| 602 | } |
| 603 | return maxPosition; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 604 | } |
| 605 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 606 | void moveTaskToTop(Task task) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 607 | if (DEBUG_TASK_MOVEMENT) Slog.d(TAG_WM, "moveTaskToTop: task=" + task + " Callers=" |
Craig Mautner | f0ac5c8 | 2013-06-24 11:21:57 -0700 | [diff] [blame] | 608 | + Debug.getCallers(6)); |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 609 | mTasks.remove(task); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 610 | addTask(task, true); |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 613 | void moveTaskToBottom(Task task) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 614 | if (DEBUG_TASK_MOVEMENT) Slog.d(TAG_WM, "moveTaskToBottom: task=" + task); |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 615 | mTasks.remove(task); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 616 | addTask(task, false); |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 617 | } |
| 618 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 619 | /** |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 620 | * Delete a Task from this stack. If it is the last Task in the stack, move this stack to the |
| 621 | * back. |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 622 | * @param task The Task to delete. |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 623 | */ |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 624 | void removeTask(Task task) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 625 | if (DEBUG_TASK_MOVEMENT) Slog.d(TAG_WM, "removeTask: task=" + task); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 626 | mTasks.remove(task); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 627 | if (mDisplayContent != null) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 628 | if (mTasks.isEmpty()) { |
| 629 | mDisplayContent.moveStack(this, false); |
| 630 | } |
| 631 | mDisplayContent.layoutNeeded = true; |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 632 | } |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 633 | for (int appNdx = mExitingAppTokens.size() - 1; appNdx >= 0; --appNdx) { |
| 634 | final AppWindowToken wtoken = mExitingAppTokens.get(appNdx); |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 635 | if (wtoken.mTask == task) { |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 636 | wtoken.mIsExiting = false; |
| 637 | mExitingAppTokens.remove(appNdx); |
| 638 | } |
| 639 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 640 | } |
| 641 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 642 | void attachDisplayContent(DisplayContent displayContent) { |
| 643 | if (mDisplayContent != null) { |
| 644 | throw new IllegalStateException("attachDisplayContent: Already attached"); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 645 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 646 | |
| 647 | mDisplayContent = displayContent; |
Jorim Jaggi | bc5425c | 2016-03-01 13:51:16 +0100 | [diff] [blame] | 648 | mAnimationBackgroundSurface = new DimLayer(mService, this, mDisplayContent.getDisplayId(), |
| 649 | "animation background stackId=" + mStackId); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 650 | |
| 651 | Rect bounds = null; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 652 | final TaskStack dockedStack = mService.mStackIdToStack.get(DOCKED_STACK_ID); |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 653 | if (mStackId == DOCKED_STACK_ID |
Jorim Jaggi | 65002e1 | 2016-04-21 18:25:49 -0700 | [diff] [blame] | 654 | || (dockedStack != null && StackId.isResizeableByDockedStack(mStackId) |
| 655 | && !dockedStack.isFullscreen())) { |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 656 | // The existence of a docked stack affects the size of other static stack created since |
Jorim Jaggi | 65002e1 | 2016-04-21 18:25:49 -0700 | [diff] [blame] | 657 | // the docked stack occupies a dedicated region on screen, but only if the dock stack is |
| 658 | // not fullscreen. If it's fullscreen, it means that we are in the transition of |
| 659 | // dismissing it, so we must not resize this stack. |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 660 | bounds = new Rect(); |
| 661 | displayContent.getLogicalDisplayRect(mTmpRect); |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 662 | mTmpRect2.setEmpty(); |
| 663 | if (dockedStack != null) { |
| 664 | dockedStack.getRawBounds(mTmpRect2); |
| 665 | } |
Jorim Jaggi | 9ea2f7b | 2015-11-23 18:08:28 -0800 | [diff] [blame] | 666 | final boolean dockedOnTopOrLeft = mService.mDockedStackCreateMode |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 667 | == DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT; |
| 668 | getStackDockedModeBounds(mTmpRect, bounds, mStackId, mTmpRect2, |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 669 | mDisplayContent.mDividerControllerLocked.getContentWidth(), |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 670 | dockedOnTopOrLeft); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | updateDisplayInfo(bounds); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Wale Ogunwale | 961f485 | 2016-02-01 20:25:54 -0800 | [diff] [blame] | 676 | void getStackDockedModeBoundsLocked(Rect outBounds, boolean ignoreVisibility) { |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 677 | if ((mStackId != DOCKED_STACK_ID && !StackId.isResizeableByDockedStack(mStackId)) |
| 678 | || mDisplayContent == null) { |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 679 | outBounds.set(mBounds); |
| 680 | return; |
| 681 | } |
| 682 | |
Filip Gruszczynski | 54977fe | 2015-10-19 17:26:45 -0700 | [diff] [blame] | 683 | final TaskStack dockedStack = mService.mStackIdToStack.get(DOCKED_STACK_ID); |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 684 | if (dockedStack == null) { |
| 685 | // Not sure why you are calling this method when there is no docked stack... |
| 686 | throw new IllegalStateException( |
| 687 | "Calling getStackDockedModeBoundsLocked() when there is no docked stack."); |
| 688 | } |
Wale Ogunwale | 961f485 | 2016-02-01 20:25:54 -0800 | [diff] [blame] | 689 | if (!ignoreVisibility && !dockedStack.isVisibleLocked()) { |
Filip Gruszczynski | 54977fe | 2015-10-19 17:26:45 -0700 | [diff] [blame] | 690 | // The docked stack is being dismissed, but we caught before it finished being |
| 691 | // dismissed. In that case we want to treat it as if it is not occupying any space and |
| 692 | // let others occupy the whole display. |
Wale Ogunwale | ccb6ce2 | 2016-01-14 15:36:35 -0800 | [diff] [blame] | 693 | mDisplayContent.getLogicalDisplayRect(outBounds); |
Filip Gruszczynski | 54977fe | 2015-10-19 17:26:45 -0700 | [diff] [blame] | 694 | return; |
| 695 | } |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 696 | |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 697 | final int dockedSide = dockedStack.getDockSide(); |
| 698 | if (dockedSide == DOCKED_INVALID) { |
| 699 | // 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] | 700 | 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] | 701 | outBounds.set(mBounds); |
| 702 | return; |
| 703 | } |
| 704 | |
| 705 | mDisplayContent.getLogicalDisplayRect(mTmpRect); |
| 706 | dockedStack.getRawBounds(mTmpRect2); |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 707 | final boolean dockedOnTopOrLeft = dockedSide == DOCKED_TOP || dockedSide == DOCKED_LEFT; |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 708 | getStackDockedModeBounds(mTmpRect, outBounds, mStackId, mTmpRect2, |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 709 | mDisplayContent.mDividerControllerLocked.getContentWidth(), dockedOnTopOrLeft); |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 710 | |
| 711 | } |
| 712 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 713 | /** |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 714 | * 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] | 715 | * @param displayRect The bounds of the display the docked stack is on. |
| 716 | * @param outBounds Output bounds that should be used for the stack. |
| 717 | * @param stackId Id of stack we are calculating the bounds for. |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 718 | * @param dockedBounds Bounds of the docked stack. |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 719 | * @param dockDividerWidth We need to know the width of the divider make to the output bounds |
| 720 | * close to the side of the dock. |
| 721 | * @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] | 722 | */ |
Jorim Jaggi | 9ea2f7b | 2015-11-23 18:08:28 -0800 | [diff] [blame] | 723 | private void getStackDockedModeBounds( |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 724 | Rect displayRect, Rect outBounds, int stackId, Rect dockedBounds, int dockDividerWidth, |
| 725 | boolean dockOnTopOrLeft) { |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 726 | final boolean dockedStack = stackId == DOCKED_STACK_ID; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 727 | final boolean splitHorizontally = displayRect.width() > displayRect.height(); |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 728 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 729 | outBounds.set(displayRect); |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 730 | if (dockedStack) { |
Jorim Jaggi | 9ea2f7b | 2015-11-23 18:08:28 -0800 | [diff] [blame] | 731 | if (mService.mDockedStackCreateBounds != null) { |
| 732 | outBounds.set(mService.mDockedStackCreateBounds); |
| 733 | return; |
| 734 | } |
Jorim Jaggi | d434dcb | 2016-01-06 17:18:44 +0100 | [diff] [blame] | 735 | |
| 736 | // The initial bounds of the docked stack when it is created about half the screen space |
| 737 | // and its bounds can be adjusted after that. The bounds of all other stacks are |
| 738 | // adjusted to occupy whatever screen space the docked stack isn't occupying. |
| 739 | final DisplayInfo di = mDisplayContent.getDisplayInfo(); |
| 740 | mService.mPolicy.getStableInsetsLw(di.rotation, di.logicalWidth, di.logicalHeight, |
| 741 | mTmpRect2); |
| 742 | final int position = new DividerSnapAlgorithm(mService.mContext.getResources(), |
Jorim Jaggi | d434dcb | 2016-01-06 17:18:44 +0100 | [diff] [blame] | 743 | di.logicalWidth, |
| 744 | di.logicalHeight, |
| 745 | dockDividerWidth, |
| 746 | mService.mCurConfiguration.orientation == ORIENTATION_PORTRAIT, |
| 747 | mTmpRect2).getMiddleTarget().position; |
| 748 | |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 749 | if (dockOnTopOrLeft) { |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 750 | if (splitHorizontally) { |
Jorim Jaggi | d434dcb | 2016-01-06 17:18:44 +0100 | [diff] [blame] | 751 | outBounds.right = position; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 752 | } else { |
Jorim Jaggi | d434dcb | 2016-01-06 17:18:44 +0100 | [diff] [blame] | 753 | outBounds.bottom = position; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 754 | } |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 755 | } else { |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 756 | if (splitHorizontally) { |
Andrii Kulian | ef3b272 | 2016-04-08 12:45:27 -0700 | [diff] [blame] | 757 | outBounds.left = position + dockDividerWidth; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 758 | } else { |
Andrii Kulian | ef3b272 | 2016-04-08 12:45:27 -0700 | [diff] [blame] | 759 | outBounds.top = position + dockDividerWidth; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 760 | } |
| 761 | } |
| 762 | return; |
| 763 | } |
| 764 | |
| 765 | // Other stacks occupy whatever space is left by the docked stack. |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 766 | if (!dockOnTopOrLeft) { |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 767 | if (splitHorizontally) { |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 768 | outBounds.right = dockedBounds.left - dockDividerWidth; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 769 | } else { |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 770 | outBounds.bottom = dockedBounds.top - dockDividerWidth; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 771 | } |
| 772 | } else { |
| 773 | if (splitHorizontally) { |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 774 | outBounds.left = dockedBounds.right + dockDividerWidth; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 775 | } else { |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 776 | outBounds.top = dockedBounds.bottom + dockDividerWidth; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 777 | } |
| 778 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 779 | DockedDividerUtils.sanitizeStackBounds(outBounds, !dockOnTopOrLeft); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 782 | void resetDockedStackToMiddle() { |
| 783 | if (mStackId != DOCKED_STACK_ID) { |
| 784 | throw new IllegalStateException("Not a docked stack=" + this); |
| 785 | } |
| 786 | |
| 787 | mService.mDockedStackCreateBounds = null; |
| 788 | |
| 789 | final Rect bounds = new Rect(); |
| 790 | getStackDockedModeBoundsLocked(bounds, true /*ignoreVisibility*/); |
| 791 | mService.mH.obtainMessage(RESIZE_STACK, DOCKED_STACK_ID, |
| 792 | 1 /*allowResizeInDockedMode*/, bounds).sendToTarget(); |
| 793 | } |
| 794 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 795 | void detachDisplay() { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 796 | EventLog.writeEvent(EventLogTags.WM_STACK_REMOVED, mStackId); |
Craig Mautner | bc2a6df | 2014-06-13 15:08:48 -0700 | [diff] [blame] | 797 | |
| 798 | boolean doAnotherLayoutPass = false; |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 799 | for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | bc2a6df | 2014-06-13 15:08:48 -0700 | [diff] [blame] | 800 | final AppTokenList appWindowTokens = mTasks.get(taskNdx).mAppTokens; |
| 801 | for (int appNdx = appWindowTokens.size() - 1; appNdx >= 0; --appNdx) { |
| 802 | final WindowList appWindows = appWindowTokens.get(appNdx).allAppWindows; |
| 803 | for (int winNdx = appWindows.size() - 1; winNdx >= 0; --winNdx) { |
Filip Gruszczynski | d66af6a | 2015-08-31 08:57:24 -0700 | [diff] [blame] | 804 | // We are in the middle of changing the state of displays/stacks/tasks. We need |
| 805 | // to finish that, before we let layout interfere with it. |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 806 | mService.removeWindowLocked(appWindows.get(winNdx)); |
Craig Mautner | bc2a6df | 2014-06-13 15:08:48 -0700 | [diff] [blame] | 807 | doAnotherLayoutPass = true; |
| 808 | } |
| 809 | } |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 810 | } |
Craig Mautner | bc2a6df | 2014-06-13 15:08:48 -0700 | [diff] [blame] | 811 | if (doAnotherLayoutPass) { |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 812 | mService.mWindowPlacerLocked.requestTraversal(); |
Craig Mautner | bc2a6df | 2014-06-13 15:08:48 -0700 | [diff] [blame] | 813 | } |
| 814 | |
Craig Mautner | 00a6675 | 2015-03-23 14:00:47 -0700 | [diff] [blame] | 815 | close(); |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 816 | } |
| 817 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 818 | void resetAnimationBackgroundAnimator() { |
| 819 | mAnimationBackgroundAnimator = null; |
| 820 | mAnimationBackgroundSurface.hide(); |
| 821 | } |
| 822 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 823 | void setAnimationBackground(WindowStateAnimator winAnimator, int color) { |
| 824 | int animLayer = winAnimator.mAnimLayer; |
| 825 | if (mAnimationBackgroundAnimator == null |
| 826 | || animLayer < mAnimationBackgroundAnimator.mAnimLayer) { |
| 827 | mAnimationBackgroundAnimator = winAnimator; |
| 828 | animLayer = mService.adjustAnimationBackground(winAnimator); |
| 829 | mAnimationBackgroundSurface.show(animLayer - WindowManagerService.LAYER_OFFSET_DIM, |
| 830 | ((color >> 24) & 0xff) / 255f, 0); |
| 831 | } |
| 832 | } |
| 833 | |
Wale Ogunwale | 498e8c9 | 2015-02-13 09:42:46 -0800 | [diff] [blame] | 834 | void switchUser() { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 835 | int top = mTasks.size(); |
| 836 | for (int taskNdx = 0; taskNdx < top; ++taskNdx) { |
| 837 | Task task = mTasks.get(taskNdx); |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 838 | if (mService.isCurrentProfileLocked(task.mUserId) || task.showForAllUsers()) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 839 | mTasks.remove(taskNdx); |
| 840 | mTasks.add(task); |
| 841 | --top; |
| 842 | } |
| 843 | } |
| 844 | } |
| 845 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 846 | void close() { |
Craig Mautner | 00a6675 | 2015-03-23 14:00:47 -0700 | [diff] [blame] | 847 | if (mAnimationBackgroundSurface != null) { |
| 848 | mAnimationBackgroundSurface.destroySurface(); |
| 849 | mAnimationBackgroundSurface = null; |
| 850 | } |
Filip Gruszczynski | 26ed265 | 2015-08-10 11:02:53 -0700 | [diff] [blame] | 851 | mDisplayContent = null; |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 852 | } |
| 853 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 854 | /** |
| 855 | * Adjusts the stack bounds if the IME is visible. |
| 856 | * |
| 857 | * @param imeWin The IME window. |
| 858 | */ |
| 859 | void setAdjustedForIme(WindowState imeWin) { |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 860 | mImeWin = imeWin; |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 861 | mImeGoingAway = false; |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 862 | if (!mAdjustedForIme) { |
| 863 | mAdjustedForIme = true; |
| 864 | mAdjustImeAmount = 0f; |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 865 | mAdjustDividerAmount = 0f; |
| 866 | updateAdjustForIme(0f, 0f, true /* force */); |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 867 | } |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | boolean isAdjustedForIme() { |
| 871 | return mAdjustedForIme || mImeGoingAway; |
| 872 | } |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 873 | |
| 874 | boolean isAnimatingForIme() { |
| 875 | return mImeWin != null && mImeWin.isAnimatingLw(); |
| 876 | } |
| 877 | |
| 878 | /** |
| 879 | * Update the stack's bounds (crop or position) according to the IME window's |
| 880 | * current position. When IME window is animated, the bottom stack is animated |
| 881 | * together to track the IME window's current position, and the top stack is |
| 882 | * cropped as necessary. |
| 883 | * |
| 884 | * @return true if a traversal should be performed after the adjustment. |
| 885 | */ |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 886 | boolean updateAdjustForIme(float adjustAmount, float adjustDividerAmount, boolean force) { |
| 887 | if (adjustAmount != mAdjustImeAmount |
| 888 | || adjustDividerAmount != mAdjustDividerAmount || force) { |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 889 | mAdjustImeAmount = adjustAmount; |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 890 | mAdjustDividerAmount = adjustDividerAmount; |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 891 | updateAdjustedBounds(); |
| 892 | return isVisibleForUserLocked(); |
| 893 | } else { |
| 894 | return false; |
Chong Zhang | b58bbcc | 2016-03-23 11:57:36 -0700 | [diff] [blame] | 895 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | /** |
| 899 | * Resets the adjustment after it got adjusted for the IME. |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 900 | * @param adjustBoundsNow if true, reset and update the bounds immediately and forget about |
| 901 | * animations; otherwise, set flag and animates the window away together |
| 902 | * with IME window. |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 903 | */ |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 904 | void resetAdjustedForIme(boolean adjustBoundsNow) { |
| 905 | if (adjustBoundsNow) { |
| 906 | mImeWin = null; |
| 907 | mAdjustedForIme = false; |
| 908 | mImeGoingAway = false; |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 909 | mAdjustImeAmount = 0f; |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 910 | mAdjustDividerAmount = 0f; |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 911 | updateAdjustedBounds(); |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 912 | mService.setResizeDimLayer(false, mStackId, 1.0f); |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 913 | } else { |
| 914 | mImeGoingAway |= mAdjustedForIme; |
Chong Zhang | b58bbcc | 2016-03-23 11:57:36 -0700 | [diff] [blame] | 915 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | /** |
| 919 | * Sets the amount how much we currently minimize our stack. |
| 920 | * |
| 921 | * @param minimizeAmount The amount, between 0 and 1. |
| 922 | * @return Whether the amount has changed and a layout is needed. |
| 923 | */ |
| 924 | boolean setAdjustedForMinimizedDock(float minimizeAmount) { |
| 925 | if (minimizeAmount != mMinimizeAmount) { |
| 926 | mMinimizeAmount = minimizeAmount; |
| 927 | updateAdjustedBounds(); |
| 928 | return isVisibleForUserLocked(); |
| 929 | } else { |
| 930 | return false; |
| 931 | } |
| 932 | } |
| 933 | |
Jorim Jaggi | 409635b | 2016-04-01 15:32:28 -0700 | [diff] [blame] | 934 | boolean isAdjustedForMinimizedDock() { |
| 935 | return mMinimizeAmount != 0f; |
| 936 | } |
| 937 | |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 938 | /** |
| 939 | * Puts all visible tasks that are adjusted for IME into resizing mode and adds the windows |
| 940 | * to the list of to be drawn windows the service is waiting for. |
| 941 | */ |
| 942 | void beginImeAdjustAnimation() { |
| 943 | for (int j = mTasks.size() - 1; j >= 0; j--) { |
| 944 | final Task task = mTasks.get(j); |
| 945 | if (task.isVisibleForUser()) { |
| 946 | task.setDragResizing(true, DRAG_RESIZE_MODE_DOCKED_DIVIDER); |
| 947 | task.addWindowsWaitingForDrawnIfResizingChanged(); |
| 948 | } |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | /** |
| 953 | * Resets the resizing state of all windows. |
| 954 | */ |
| 955 | void endImeAdjustAnimation() { |
| 956 | for (int j = mTasks.size() - 1; j >= 0; j--) { |
| 957 | mTasks.get(j).setDragResizing(false, DRAG_RESIZE_MODE_DOCKED_DIVIDER); |
| 958 | } |
| 959 | } |
| 960 | |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 961 | int getMinTopStackBottom(final Rect displayContentRect, int originalStackBottom) { |
| 962 | return displayContentRect.top + (int) |
| 963 | ((originalStackBottom - displayContentRect.top) * ADJUSTED_STACK_FRACTION_MIN); |
| 964 | } |
| 965 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 966 | private boolean adjustForIME(final WindowState imeWin) { |
| 967 | final int dockedSide = getDockSide(); |
| 968 | final boolean dockedTopOrBottom = dockedSide == DOCKED_TOP || dockedSide == DOCKED_BOTTOM; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 969 | if (imeWin == null || !dockedTopOrBottom) { |
| 970 | return false; |
| 971 | } |
| 972 | |
| 973 | final Rect displayContentRect = mTmpRect; |
| 974 | final Rect contentBounds = mTmpRect2; |
| 975 | |
| 976 | // Calculate the content bounds excluding the area occupied by IME |
| 977 | getDisplayContent().getContentRect(displayContentRect); |
| 978 | contentBounds.set(displayContentRect); |
Jorim Jaggi | 5ac2ba2 | 2016-04-11 21:14:12 -0700 | [diff] [blame] | 979 | int imeTop = Math.max(imeWin.getFrameLw().top, contentBounds.top); |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 980 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 981 | imeTop += imeWin.getGivenContentInsetsLw().top; |
| 982 | if (contentBounds.bottom > imeTop) { |
| 983 | contentBounds.bottom = imeTop; |
| 984 | } |
| 985 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 986 | final int yOffset = displayContentRect.bottom - contentBounds.bottom; |
| 987 | |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 988 | final int dividerWidth = |
| 989 | getDisplayContent().mDividerControllerLocked.getContentWidth(); |
| 990 | final int dividerWidthInactive = |
| 991 | getDisplayContent().mDividerControllerLocked.getContentWidthInactive(); |
| 992 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 993 | if (dockedSide == DOCKED_TOP) { |
| 994 | // If this stack is docked on top, we make it smaller so the bottom stack is not |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 995 | // occluded by IME. We shift its bottom up by the height of the IME, but |
| 996 | // leaves at least 30% of the top stack visible. |
| 997 | final int minTopStackBottom = |
| 998 | getMinTopStackBottom(displayContentRect, mBounds.bottom); |
| 999 | final int bottom = Math.max( |
| 1000 | mBounds.bottom - yOffset + dividerWidth - dividerWidthInactive, |
| 1001 | minTopStackBottom); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1002 | mTmpAdjustedBounds.set(mBounds); |
| 1003 | mTmpAdjustedBounds.bottom = |
| 1004 | (int) (mAdjustImeAmount * bottom + (1 - mAdjustImeAmount) * mBounds.bottom); |
| 1005 | mFullyAdjustedImeBounds.set(mBounds); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1006 | } else { |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 1007 | // When the stack is on bottom and has no focus, it's only adjusted for divider width. |
| 1008 | final int dividerWidthDelta = dividerWidthInactive - dividerWidth; |
| 1009 | |
| 1010 | // When the stack is on bottom and has focus, it needs to be moved up so as to |
| 1011 | // not occluded by IME, and at the same time adjusted for divider width. |
| 1012 | // We try to move it up by the height of the IME window, but only to the extent |
| 1013 | // that leaves at least 30% of the top stack visible. |
| 1014 | // 'top' is where the top of bottom stack will move to in this case. |
| 1015 | final int topBeforeImeAdjust = mBounds.top - dividerWidth + dividerWidthInactive; |
| 1016 | final int minTopStackBottom = |
| 1017 | getMinTopStackBottom(displayContentRect, mBounds.top - dividerWidth); |
| 1018 | final int top = Math.max( |
| 1019 | mBounds.top - yOffset, minTopStackBottom + dividerWidthInactive); |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 1020 | |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1021 | mTmpAdjustedBounds.set(mBounds); |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 1022 | // Account for the adjustment for IME and divider width separately. |
| 1023 | // (top - topBeforeImeAdjust) is the amount of movement due to IME only, |
| 1024 | // and dividerWidthDelta is due to divider width change only. |
| 1025 | mTmpAdjustedBounds.top = mBounds.top + |
| 1026 | (int) (mAdjustImeAmount * (top - topBeforeImeAdjust) + |
| 1027 | mAdjustDividerAmount * dividerWidthDelta); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1028 | mFullyAdjustedImeBounds.set(mBounds); |
| 1029 | mFullyAdjustedImeBounds.top = top; |
| 1030 | mFullyAdjustedImeBounds.bottom = top + mBounds.height(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1031 | } |
| 1032 | return true; |
| 1033 | } |
| 1034 | |
| 1035 | private boolean adjustForMinimizedDockedStack(float minimizeAmount) { |
| 1036 | final int dockSide = getDockSide(); |
| 1037 | if (dockSide == DOCKED_INVALID && !mTmpAdjustedBounds.isEmpty()) { |
| 1038 | return false; |
| 1039 | } |
| 1040 | |
| 1041 | if (dockSide == DOCKED_TOP) { |
| 1042 | mService.getStableInsetsLocked(mTmpRect); |
| 1043 | int topInset = mTmpRect.top; |
| 1044 | mTmpAdjustedBounds.set(mBounds); |
| 1045 | mTmpAdjustedBounds.bottom = |
| 1046 | (int) (minimizeAmount * topInset + (1 - minimizeAmount) * mBounds.bottom); |
| 1047 | } else if (dockSide == DOCKED_LEFT) { |
| 1048 | mTmpAdjustedBounds.set(mBounds); |
Jorim Jaggi | bcff143 | 2016-04-01 15:49:45 -0700 | [diff] [blame] | 1049 | final int width = mBounds.width(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1050 | mTmpAdjustedBounds.right = |
| 1051 | (int) (minimizeAmount * mDockedStackMinimizeThickness |
| 1052 | + (1 - minimizeAmount) * mBounds.right); |
Jorim Jaggi | bcff143 | 2016-04-01 15:49:45 -0700 | [diff] [blame] | 1053 | mTmpAdjustedBounds.left = mTmpAdjustedBounds.right - width; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1054 | } else if (dockSide == DOCKED_RIGHT) { |
| 1055 | mTmpAdjustedBounds.set(mBounds); |
| 1056 | mTmpAdjustedBounds.left = |
| 1057 | (int) (minimizeAmount * (mBounds.right - mDockedStackMinimizeThickness) |
| 1058 | + (1 - minimizeAmount) * mBounds.left); |
| 1059 | } |
| 1060 | return true; |
| 1061 | } |
| 1062 | |
| 1063 | /** |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 1064 | * @return the distance in pixels how much the stack gets minimized from it's original size |
| 1065 | */ |
| 1066 | int getMinimizeDistance() { |
| 1067 | final int dockSide = getDockSide(); |
| 1068 | if (dockSide == DOCKED_INVALID) { |
| 1069 | return 0; |
| 1070 | } |
| 1071 | |
| 1072 | if (dockSide == DOCKED_TOP) { |
| 1073 | mService.getStableInsetsLocked(mTmpRect); |
| 1074 | int topInset = mTmpRect.top; |
| 1075 | return mBounds.bottom - topInset; |
| 1076 | } else if (dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT) { |
| 1077 | return mBounds.width() - mDockedStackMinimizeThickness; |
| 1078 | } else { |
| 1079 | return 0; |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | /** |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1084 | * Updates the adjustment depending on it's current state. |
| 1085 | */ |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1086 | void updateAdjustedBounds() { |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1087 | boolean adjust = false; |
| 1088 | if (mMinimizeAmount != 0f) { |
| 1089 | adjust = adjustForMinimizedDockedStack(mMinimizeAmount); |
| 1090 | } else if (mAdjustedForIme) { |
| 1091 | adjust = adjustForIME(mImeWin); |
| 1092 | } |
| 1093 | if (!adjust) { |
| 1094 | mTmpAdjustedBounds.setEmpty(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1095 | } |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1096 | setAdjustedBounds(mTmpAdjustedBounds); |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 1097 | |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 1098 | final boolean isImeTarget = (mService.getImeTargetStackLocked() == this); |
| 1099 | if (mAdjustedForIme && adjust && !isImeTarget) { |
| 1100 | final float alpha = Math.max(mAdjustImeAmount, mAdjustDividerAmount) |
| 1101 | * IME_ADJUST_DIM_AMOUNT; |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 1102 | mService.setResizeDimLayer(true, mStackId, alpha); |
| 1103 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | boolean isAdjustedForMinimizedDockedStack() { |
| 1107 | return mMinimizeAmount != 0f; |
| 1108 | } |
| 1109 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 1110 | public void dump(String prefix, PrintWriter pw) { |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 1111 | pw.println(prefix + "mStackId=" + mStackId); |
| 1112 | pw.println(prefix + "mDeferDetach=" + mDeferDetach); |
| 1113 | pw.println(prefix + "mFullscreen=" + mFullscreen); |
| 1114 | pw.println(prefix + "mBounds=" + mBounds.toShortString()); |
Jorim Jaggi | af558e1 | 2016-04-27 22:56:56 -0700 | [diff] [blame] | 1115 | if (mMinimizeAmount != 0f) { |
| 1116 | pw.println(prefix + "mMinimizeAmout=" + mMinimizeAmount); |
| 1117 | } |
| 1118 | if (mAdjustedForIme) { |
| 1119 | pw.println(prefix + "mAdjustedForIme=true"); |
| 1120 | pw.println(prefix + "mAdjustImeAmount=" + mAdjustImeAmount); |
| 1121 | pw.println(prefix + "mAdjustDividerAmount=" + mAdjustDividerAmount); |
| 1122 | } |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1123 | if (!mAdjustedBounds.isEmpty()) { |
| 1124 | pw.println(prefix + "mAdjustedBounds=" + mAdjustedBounds.toShortString()); |
| 1125 | } |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 1126 | for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; taskNdx--) { |
| 1127 | mTasks.get(taskNdx).dump(prefix + " ", pw); |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 1128 | } |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1129 | if (mAnimationBackgroundSurface.isDimming()) { |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 1130 | pw.println(prefix + "mWindowAnimationBackgroundSurface:"); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1131 | mAnimationBackgroundSurface.printTo(prefix + " ", pw); |
| 1132 | } |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 1133 | if (!mExitingAppTokens.isEmpty()) { |
| 1134 | pw.println(); |
| 1135 | pw.println(" Exiting application tokens:"); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1136 | for (int i = mExitingAppTokens.size() - 1; i >= 0; i--) { |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 1137 | WindowToken token = mExitingAppTokens.get(i); |
| 1138 | pw.print(" Exiting App #"); pw.print(i); |
| 1139 | pw.print(' '); pw.print(token); |
| 1140 | pw.println(':'); |
| 1141 | token.dump(pw, " "); |
| 1142 | } |
| 1143 | } |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 1144 | } |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 1145 | |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 1146 | /** Fullscreen status of the stack without adjusting for other factors in the system like |
| 1147 | * visibility of docked stack. |
| 1148 | * Most callers should be using {@link #isFullscreen} as it take into consideration other |
| 1149 | * system factors. */ |
| 1150 | boolean getRawFullscreen() { |
| 1151 | return mFullscreen; |
| 1152 | } |
| 1153 | |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 1154 | @Override |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1155 | public boolean isFullscreen() { |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 1156 | if (useCurrentBounds()) { |
| 1157 | return mFullscreen; |
| 1158 | } |
| 1159 | // The bounds has been adjusted to accommodate for a docked stack, but the docked stack |
| 1160 | // is not currently visible. Go ahead a represent it as fullscreen to the rest of the |
| 1161 | // system. |
| 1162 | return true; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | @Override |
| 1166 | public DisplayInfo getDisplayInfo() { |
| 1167 | return mDisplayContent.getDisplayInfo(); |
| 1168 | } |
| 1169 | |
| 1170 | @Override |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 1171 | public String toString() { |
| 1172 | return "{stackId=" + mStackId + " tasks=" + mTasks + "}"; |
| 1173 | } |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 1174 | |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 1175 | @Override |
| 1176 | public String toShortString() { |
| 1177 | return "Stack=" + mStackId; |
| 1178 | } |
| 1179 | |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 1180 | /** |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 1181 | * For docked workspace (or workspace that's side-by-side to the docked), provides |
| 1182 | * information which side of the screen was the dock anchored. |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 1183 | */ |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 1184 | int getDockSide() { |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 1185 | return getDockSide(mBounds); |
| 1186 | } |
| 1187 | |
| 1188 | int getDockSide(Rect bounds) { |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 1189 | if (mStackId != DOCKED_STACK_ID && !StackId.isResizeableByDockedStack(mStackId)) { |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 1190 | return DOCKED_INVALID; |
| 1191 | } |
| 1192 | if (mDisplayContent == null) { |
| 1193 | return DOCKED_INVALID; |
| 1194 | } |
| 1195 | mDisplayContent.getLogicalDisplayRect(mTmpRect); |
| 1196 | final int orientation = mService.mCurConfiguration.orientation; |
| 1197 | if (orientation == Configuration.ORIENTATION_PORTRAIT) { |
| 1198 | // Portrait mode, docked either at the top or the bottom. |
Jorim Jaggi | 067e817 | 2016-02-03 18:24:12 -0800 | [diff] [blame] | 1199 | if (bounds.top - mTmpRect.top <= mTmpRect.bottom - bounds.bottom) { |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 1200 | return DOCKED_TOP; |
| 1201 | } else { |
| 1202 | return DOCKED_BOTTOM; |
| 1203 | } |
| 1204 | } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { |
| 1205 | // Landscape mode, docked either on the left or on the right. |
Jorim Jaggi | 067e817 | 2016-02-03 18:24:12 -0800 | [diff] [blame] | 1206 | if (bounds.left - mTmpRect.left <= mTmpRect.right - bounds.right) { |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 1207 | return DOCKED_LEFT; |
| 1208 | } else { |
| 1209 | return DOCKED_RIGHT; |
| 1210 | } |
| 1211 | } else { |
| 1212 | return DOCKED_INVALID; |
| 1213 | } |
| 1214 | } |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 1215 | |
| 1216 | boolean isVisibleLocked() { |
Jorim Jaggi | 7998e48 | 2016-02-12 18:47:06 -0800 | [diff] [blame] | 1217 | final boolean keyguardOn = mService.mPolicy.isKeyguardShowingOrOccluded() |
| 1218 | && !mService.mAnimator.mKeyguardGoingAway; |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 1219 | if (keyguardOn && !StackId.isAllowedOverLockscreen(mStackId)) { |
Wale Ogunwale | ccb6ce2 | 2016-01-14 15:36:35 -0800 | [diff] [blame] | 1220 | // 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] | 1221 | return false; |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 1222 | } |
Wale Ogunwale | ccb6ce2 | 2016-01-14 15:36:35 -0800 | [diff] [blame] | 1223 | |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 1224 | for (int i = mTasks.size() - 1; i >= 0; i--) { |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1225 | final Task task = mTasks.get(i); |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 1226 | for (int j = task.mAppTokens.size() - 1; j >= 0; j--) { |
| 1227 | if (!task.mAppTokens.get(j).hidden) { |
| 1228 | return true; |
| 1229 | } |
| 1230 | } |
| 1231 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1232 | |
| 1233 | return false; |
| 1234 | } |
| 1235 | |
| 1236 | /** |
| 1237 | * @return true if a the stack is visible for the current in user, ignoring any other visibility |
| 1238 | * aspects, and false otherwise |
| 1239 | */ |
| 1240 | boolean isVisibleForUserLocked() { |
| 1241 | for (int i = mTasks.size() - 1; i >= 0; i--) { |
| 1242 | final Task task = mTasks.get(i); |
| 1243 | if (task.isVisibleForUser()) { |
| 1244 | return true; |
| 1245 | } |
| 1246 | } |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 1247 | return false; |
| 1248 | } |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 1249 | |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 1250 | boolean isDragResizing() { |
| 1251 | return mDragResizing; |
| 1252 | } |
| 1253 | |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 1254 | void setDragResizingLocked(boolean resizing) { |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 1255 | if (mDragResizing == resizing) { |
| 1256 | return; |
| 1257 | } |
| 1258 | mDragResizing = resizing; |
| 1259 | for (int i = mTasks.size() - 1; i >= 0 ; i--) { |
| 1260 | mTasks.get(i).resetDragResizingChangeReported(); |
| 1261 | } |
| 1262 | } |
| 1263 | |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 1264 | @Override // AnimatesBounds |
| 1265 | public boolean setSize(Rect bounds) { |
| 1266 | synchronized (mService.mWindowMap) { |
| 1267 | if (mDisplayContent == null) { |
| 1268 | return false; |
| 1269 | } |
| 1270 | } |
| 1271 | try { |
Wale Ogunwale | e75a9ad | 2016-03-18 20:43:49 -0700 | [diff] [blame] | 1272 | mService.mActivityManager.resizeStack(mStackId, bounds, false, true, false, -1); |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 1273 | } catch (RemoteException e) { |
| 1274 | } |
| 1275 | return true; |
| 1276 | } |
| 1277 | |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1278 | public boolean setPinnedStackSize(Rect bounds, Rect tempTaskBounds) { |
| 1279 | synchronized (mService.mWindowMap) { |
| 1280 | if (mDisplayContent == null) { |
| 1281 | return false; |
| 1282 | } |
| 1283 | if (mStackId != PINNED_STACK_ID) { |
| 1284 | Slog.w(TAG_WM, "Attempt to use pinned stack resize animation helper on" |
| 1285 | + "non pinned stack"); |
| 1286 | return false; |
| 1287 | } |
| 1288 | } |
| 1289 | try { |
| 1290 | mService.mActivityManager.resizePinnedStack(bounds, tempTaskBounds); |
| 1291 | } catch (RemoteException e) { |
| 1292 | // I don't believe you. |
| 1293 | } |
| 1294 | return true; |
| 1295 | } |
| 1296 | |
Robert Carr | 1b5ea72 | 2016-04-20 13:23:28 -0700 | [diff] [blame] | 1297 | void forceWindowsScaleable(Task task, boolean force) { |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 1298 | SurfaceControl.openTransaction(); |
| 1299 | try { |
Robert Carr | 1b5ea72 | 2016-04-20 13:23:28 -0700 | [diff] [blame] | 1300 | final ArrayList<AppWindowToken> activities = task.mAppTokens; |
| 1301 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1302 | final ArrayList<WindowState> windows = activities.get(activityNdx).allAppWindows; |
| 1303 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
| 1304 | final WindowStateAnimator winAnimator = windows.get(winNdx).mWinAnimator; |
| 1305 | if (winAnimator == null || !winAnimator.hasSurface()) { |
| 1306 | continue; |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 1307 | } |
Robert Carr | 1b5ea72 | 2016-04-20 13:23:28 -0700 | [diff] [blame] | 1308 | winAnimator.mSurfaceController.forceScaleableInTransaction(force); |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 1309 | } |
| 1310 | } |
| 1311 | } finally { |
| 1312 | SurfaceControl.closeTransaction(); |
| 1313 | } |
| 1314 | } |
| 1315 | |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 1316 | @Override // AnimatesBounds |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 1317 | public void onAnimationStart() { |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 1318 | synchronized (mService.mWindowMap) { |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1319 | mFreezeMovementAnimations = true; |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 1320 | mBoundsAnimating = true; |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 1321 | } |
| 1322 | } |
| 1323 | |
| 1324 | @Override // AnimatesBounds |
| 1325 | public void onAnimationEnd() { |
| 1326 | synchronized (mService.mWindowMap) { |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1327 | mFreezeMovementAnimations = false; |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 1328 | mBoundsAnimating = false; |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 1329 | mService.requestTraversal(); |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 1330 | } |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 1331 | if (mStackId == PINNED_STACK_ID) { |
| 1332 | try { |
| 1333 | mService.mActivityManager.notifyPinnedStackAnimationEnded(); |
| 1334 | } catch (RemoteException e) { |
| 1335 | // I don't believe you... |
| 1336 | } |
| 1337 | } |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 1338 | } |
Filip Gruszczynski | c17d8b7 | 2016-02-03 16:52:59 -0800 | [diff] [blame] | 1339 | |
| 1340 | @Override |
| 1341 | public void moveToFullscreen() { |
| 1342 | try { |
| 1343 | mService.mActivityManager.moveTasksToFullscreenStack(mStackId, true); |
| 1344 | } catch (RemoteException e) { |
| 1345 | e.printStackTrace(); |
| 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | @Override |
| 1350 | public void getFullScreenBounds(Rect bounds) { |
| 1351 | getDisplayContent().getContentRect(bounds); |
| 1352 | } |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1353 | |
| 1354 | public boolean getFreezeMovementAnimations() { |
| 1355 | return mFreezeMovementAnimations; |
| 1356 | } |
| 1357 | |
| 1358 | public boolean getForceScaleToCrop() { |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 1359 | return mBoundsAnimating; |
| 1360 | } |
| 1361 | |
| 1362 | public boolean getBoundsAnimating() { |
| 1363 | return mBoundsAnimating; |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1364 | } |
Wale Ogunwale | ecbcadd | 2016-02-21 14:18:51 -0800 | [diff] [blame] | 1365 | } |