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 | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 19 | import static android.app.ActivityTaskManager.SPLIT_SCREEN_CREATE_MODE_BOTTOM_OR_RIGHT; |
| 20 | import static android.app.ActivityTaskManager.SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 21 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT; |
| 22 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
| 23 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 24 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
Robert Carr | 32bcb10 | 2018-01-29 15:03:23 -0800 | [diff] [blame] | 25 | import static android.app.WindowConfiguration.PINNED_WINDOWING_MODE_ELEVATION_IN_DIP; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 26 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 27 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 28 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 29 | import static android.content.res.Configuration.ORIENTATION_PORTRAIT; |
Winson Chung | 303c6b7 | 2016-10-24 17:12:49 -0700 | [diff] [blame] | 30 | import static android.view.Display.DEFAULT_DISPLAY; |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 31 | import static android.view.WindowManager.DOCKED_BOTTOM; |
| 32 | import static android.view.WindowManager.DOCKED_INVALID; |
| 33 | import static android.view.WindowManager.DOCKED_LEFT; |
| 34 | import static android.view.WindowManager.DOCKED_RIGHT; |
| 35 | import static android.view.WindowManager.DOCKED_TOP; |
Garfield Tan | dec96db | 2018-10-30 11:28:49 -0700 | [diff] [blame] | 36 | |
Tracy Zhou | 9c675d4 | 2019-04-08 00:32:40 -0700 | [diff] [blame] | 37 | import static com.android.server.wm.BoundsAnimationController.FADE_IN; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 38 | import static com.android.server.wm.BoundsAnimationController.NO_PIP_MODE_CHANGED_CALLBACKS; |
| 39 | import static com.android.server.wm.BoundsAnimationController.SCHEDULE_PIP_MODE_CHANGED_ON_END; |
| 40 | import static com.android.server.wm.BoundsAnimationController.SCHEDULE_PIP_MODE_CHANGED_ON_START; |
| 41 | import static com.android.server.wm.BoundsAnimationController.SchedulePipModeChangedState; |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 42 | import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 43 | import static com.android.server.wm.StackProto.ADJUSTED_BOUNDS; |
| 44 | import static com.android.server.wm.StackProto.ADJUSTED_FOR_IME; |
| 45 | import static com.android.server.wm.StackProto.ADJUST_DIVIDER_AMOUNT; |
| 46 | import static com.android.server.wm.StackProto.ADJUST_IME_AMOUNT; |
Winson Chung | 82267ce | 2018-04-06 16:38:26 -0700 | [diff] [blame] | 47 | import static com.android.server.wm.StackProto.ANIMATING_BOUNDS; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 48 | import static com.android.server.wm.StackProto.ANIMATION_BACKGROUND_SURFACE_IS_DIMMING; |
| 49 | import static com.android.server.wm.StackProto.BOUNDS; |
| 50 | import static com.android.server.wm.StackProto.DEFER_REMOVAL; |
| 51 | import static com.android.server.wm.StackProto.FILLS_PARENT; |
| 52 | import static com.android.server.wm.StackProto.ID; |
| 53 | import static com.android.server.wm.StackProto.MINIMIZE_AMOUNT; |
| 54 | import static com.android.server.wm.StackProto.TASKS; |
| 55 | import static com.android.server.wm.StackProto.WINDOW_CONTAINER; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 56 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK; |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame] | 57 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_MOVEMENT; |
| 58 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 59 | |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 60 | import android.annotation.CallSuper; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 61 | import android.app.RemoteAction; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 62 | import android.content.res.Configuration; |
chaviw | 3e751af | 2018-01-11 11:22:39 -0800 | [diff] [blame] | 63 | import android.graphics.Point; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 64 | import android.graphics.Rect; |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 65 | import android.graphics.Region; |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 66 | import android.os.RemoteException; |
Robert Carr | 32bcb10 | 2018-01-29 15:03:23 -0800 | [diff] [blame] | 67 | import android.util.DisplayMetrics; |
Craig Mautner | 2c2549c | 2013-11-12 08:31:15 -0800 | [diff] [blame] | 68 | import android.util.EventLog; |
Craig Mautner | f0ac5c8 | 2013-06-24 11:21:57 -0700 | [diff] [blame] | 69 | import android.util.Slog; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 70 | import android.util.proto.ProtoOutputStream; |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 71 | import android.view.DisplayCutout; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 72 | import android.view.DisplayInfo; |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 73 | import android.view.SurfaceControl; |
Garfield Tan | dec96db | 2018-10-30 11:28:49 -0700 | [diff] [blame] | 74 | |
Riddle Hsu | 6619acb | 2019-02-20 19:12:57 +0800 | [diff] [blame] | 75 | import com.android.internal.annotations.VisibleForTesting; |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 76 | import com.android.internal.policy.DividerSnapAlgorithm; |
| 77 | import com.android.internal.policy.DividerSnapAlgorithm.SnapTarget; |
| 78 | import com.android.internal.policy.DockedDividerUtils; |
Craig Mautner | 2c2549c | 2013-11-12 08:31:15 -0800 | [diff] [blame] | 79 | import com.android.server.EventLogTags; |
Garfield Tan | dec96db | 2018-10-30 11:28:49 -0700 | [diff] [blame] | 80 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 81 | import java.io.PrintWriter; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 82 | import java.util.List; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 83 | |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 84 | public class TaskStack extends WindowContainer<Task> implements |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 85 | BoundsAnimationTarget, ConfigurationContainerListener { |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 86 | /** Minimum size of an adjusted stack bounds relative to original stack bounds. Used to |
| 87 | * restrict IME adjustment so that a min portion of top stack remains visible.*/ |
| 88 | private static final float ADJUSTED_STACK_FRACTION_MIN = 0.3f; |
| 89 | |
| 90 | /** Dimming amount for non-focused stack when stacks are IME-adjusted. */ |
| 91 | private static final float IME_ADJUST_DIM_AMOUNT = 0.25f; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 92 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 93 | /** Unique identifier */ |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 94 | final int mStackId; |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 95 | |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 96 | /** For comparison with DisplayContent bounds. */ |
| 97 | private Rect mTmpRect = new Rect(); |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 98 | private Rect mTmpRect2 = new Rect(); |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 99 | private Rect mTmpRect3 = new Rect(); |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 100 | |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 101 | /** For Pinned stack controlling. */ |
| 102 | private Rect mTmpFromBounds = new Rect(); |
| 103 | private Rect mTmpToBounds = new Rect(); |
| 104 | |
Chong Zhang | b816b86 | 2016-01-25 12:01:12 -0800 | [diff] [blame] | 105 | /** Stack bounds adjusted to screen content area (taking into account IM windows, etc.) */ |
| 106 | private final Rect mAdjustedBounds = new Rect(); |
| 107 | |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 108 | /** |
| 109 | * Fully adjusted IME bounds. These are different from {@link #mAdjustedBounds} because they |
| 110 | * represent the state when the animation has ended. |
| 111 | */ |
| 112 | private final Rect mFullyAdjustedImeBounds = new Rect(); |
| 113 | |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 114 | private SurfaceControl mAnimationBackgroundSurface; |
| 115 | private boolean mAnimationBackgroundSurfaceIsShown = false; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 116 | |
| 117 | /** The particular window with an Animation with non-zero background color. */ |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 118 | private WindowStateAnimator mAnimationBackgroundAnimator; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 119 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 120 | /** Application tokens that are exiting, but still on screen for animations. */ |
| 121 | final AppTokenList mExitingAppTokens = new AppTokenList(); |
Wale Ogunwale | 48458e1 | 2017-06-06 10:07:58 -0700 | [diff] [blame] | 122 | final AppTokenList mTmpAppTokens = new AppTokenList(); |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 123 | |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 124 | /** Detach this stack from its display when animation completes. */ |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 125 | // TODO: maybe tie this to WindowContainer#removeChild some how... |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 126 | boolean mDeferRemoval; |
Wale Ogunwale | ecbcadd | 2016-02-21 14:18:51 -0800 | [diff] [blame] | 127 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 128 | private final Rect mTmpAdjustedBounds = new Rect(); |
| 129 | private boolean mAdjustedForIme; |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 130 | private boolean mImeGoingAway; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 131 | private WindowState mImeWin; |
| 132 | private float mMinimizeAmount; |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 133 | private float mAdjustImeAmount; |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 134 | private float mAdjustDividerAmount; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 135 | private final int mDockedStackMinimizeThickness; |
| 136 | |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 137 | // If this is true, we are in the bounds animating mode. The task will be down or upscaled to |
| 138 | // perfectly fit the region it would have been cropped to. We may also avoid certain logic we |
| 139 | // would otherwise apply while resizing, while resizing in the bounds animating mode. |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 140 | private boolean mBoundsAnimating = false; |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 141 | // Set when an animation has been requested but has not yet started from the UI thread. This is |
| 142 | // cleared when the animation actually starts. |
| 143 | private boolean mBoundsAnimatingRequested = false; |
Robert Carr | 7e4c90e | 2017-02-15 19:52:38 -0800 | [diff] [blame] | 144 | private boolean mBoundsAnimatingToFullscreen = false; |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 145 | private boolean mCancelCurrentBoundsAnimation = false; |
Winson Chung | 84a3834 | 2016-11-08 16:15:10 -0800 | [diff] [blame] | 146 | private Rect mBoundsAnimationTarget = new Rect(); |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 147 | private Rect mBoundsAnimationSourceHintBounds = new Rect(); |
Tracy Zhou | 9c675d4 | 2019-04-08 00:32:40 -0700 | [diff] [blame] | 148 | private @BoundsAnimationController.AnimationType int mAnimationType; |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 149 | |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 150 | Rect mPreAnimationBounds = new Rect(); |
| 151 | |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 152 | private Dimmer mDimmer = new Dimmer(this); |
| 153 | |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 154 | // TODO: remove after unification. |
| 155 | ActivityStack mActivityStack; |
| 156 | |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 157 | /** |
| 158 | * For {@link #prepareSurfaces}. |
| 159 | */ |
| 160 | final Rect mTmpDimBoundsRect = new Rect(); |
chaviw | 3e751af | 2018-01-11 11:22:39 -0800 | [diff] [blame] | 161 | private final Point mLastSurfaceSize = new Point(); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 162 | |
Jorim Jaggi | 6de6101 | 2018-03-19 14:53:23 +0100 | [diff] [blame] | 163 | private final AnimatingAppWindowTokenRegistry mAnimatingAppWindowTokenRegistry = |
| 164 | new AnimatingAppWindowTokenRegistry(); |
| 165 | |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 166 | TaskStack(WindowManagerService service, int stackId, ActivityStack activityStack) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 167 | super(service); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 168 | mStackId = stackId; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 169 | mActivityStack = activityStack; |
| 170 | activityStack.registerConfigurationChangeListener(this); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 171 | mDockedStackMinimizeThickness = service.mContext.getResources().getDimensionPixelSize( |
| 172 | com.android.internal.R.dimen.docked_stack_minimize_thickness); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 173 | EventLog.writeEvent(EventLogTags.WM_STACK_CREATED, stackId); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 174 | } |
| 175 | |
Jorim Jaggi | d3ec507 | 2016-04-28 15:57:47 -0700 | [diff] [blame] | 176 | Task findHomeTask() { |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 177 | if (!isActivityTypeHome() || mChildren.isEmpty()) { |
Jorim Jaggi | d3ec507 | 2016-04-28 15:57:47 -0700 | [diff] [blame] | 178 | return null; |
| 179 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 180 | return mChildren.get(mChildren.size() - 1); |
Wale Ogunwale | 15ead90 | 2016-09-02 14:30:11 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 183 | void prepareFreezingTaskBounds() { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 184 | for (int taskNdx = mChildren.size() - 1; taskNdx >= 0; --taskNdx) { |
| 185 | final Task task = mChildren.get(taskNdx); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 186 | task.prepareFreezingBounds(); |
| 187 | } |
| 188 | } |
| 189 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 190 | /** |
| 191 | * Overrides the adjusted bounds, i.e. sets temporary layout bounds which are different from |
| 192 | * the normal task bounds. |
| 193 | * |
| 194 | * @param bounds The adjusted bounds. |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 195 | */ |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 196 | private void setAdjustedBounds(Rect bounds) { |
| 197 | if (mAdjustedBounds.equals(bounds) && !isAnimatingForIme()) { |
| 198 | return; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | mAdjustedBounds.set(bounds); |
| 202 | final boolean adjusted = !mAdjustedBounds.isEmpty(); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 203 | Rect insetBounds = null; |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 204 | if (adjusted && isAdjustedForMinimizedDockedStack()) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 205 | insetBounds = getRawBounds(); |
Chong Zhang | 5117e27 | 2016-05-03 12:47:34 -0700 | [diff] [blame] | 206 | } else if (adjusted && mAdjustedForIme) { |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 207 | if (mImeGoingAway) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 208 | insetBounds = getRawBounds(); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 209 | } else { |
| 210 | insetBounds = mFullyAdjustedImeBounds; |
| 211 | } |
| 212 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 213 | alignTasksToAdjustedBounds(adjusted ? mAdjustedBounds : getRawBounds(), insetBounds); |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 214 | mDisplayContent.setLayoutNeeded(); |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 215 | |
| 216 | updateSurfaceBounds(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | private void alignTasksToAdjustedBounds(Rect adjustedBounds, Rect tempInsetBounds) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 220 | if (matchParentBounds()) { |
Chong Zhang | b816b86 | 2016-01-25 12:01:12 -0800 | [diff] [blame] | 221 | return; |
| 222 | } |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 223 | |
| 224 | final boolean alignBottom = mAdjustedForIme && getDockSide() == DOCKED_TOP; |
| 225 | |
Chong Zhang | b816b86 | 2016-01-25 12:01:12 -0800 | [diff] [blame] | 226 | // Update bounds of containing tasks. |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 227 | for (int taskNdx = mChildren.size() - 1; taskNdx >= 0; --taskNdx) { |
| 228 | final Task task = mChildren.get(taskNdx); |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 229 | task.alignToAdjustedBounds(adjustedBounds, tempInsetBounds, alignBottom); |
Chong Zhang | b816b86 | 2016-01-25 12:01:12 -0800 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 233 | private void updateAnimationBackgroundBounds() { |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 234 | if (mAnimationBackgroundSurface == null) { |
| 235 | return; |
| 236 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 237 | getRawBounds(mTmpRect); |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 238 | final Rect stackBounds = getBounds(); |
| 239 | getPendingTransaction() |
Vishnu Nair | d454442d | 2018-11-13 13:51:01 -0800 | [diff] [blame] | 240 | .setWindowCrop(mAnimationBackgroundSurface, mTmpRect.width(), mTmpRect.height()) |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 241 | .setPosition(mAnimationBackgroundSurface, mTmpRect.left - stackBounds.left, |
| 242 | mTmpRect.top - stackBounds.top); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 243 | scheduleAnimation(); |
| 244 | } |
| 245 | |
| 246 | private void hideAnimationSurface() { |
| 247 | if (mAnimationBackgroundSurface == null) { |
| 248 | return; |
| 249 | } |
| 250 | getPendingTransaction().hide(mAnimationBackgroundSurface); |
| 251 | mAnimationBackgroundSurfaceIsShown = false; |
| 252 | scheduleAnimation(); |
| 253 | } |
| 254 | |
| 255 | private void showAnimationSurface(float alpha) { |
| 256 | if (mAnimationBackgroundSurface == null) { |
| 257 | return; |
| 258 | } |
| 259 | getPendingTransaction().setLayer(mAnimationBackgroundSurface, Integer.MIN_VALUE) |
| 260 | .setAlpha(mAnimationBackgroundSurface, alpha) |
| 261 | .show(mAnimationBackgroundSurface); |
| 262 | mAnimationBackgroundSurfaceIsShown = true; |
| 263 | scheduleAnimation(); |
| 264 | } |
| 265 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 266 | @Override |
| 267 | public int setBounds(Rect bounds) { |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 268 | return setBounds(getRequestedOverrideBounds(), bounds); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | private int setBounds(Rect existing, Rect bounds) { |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 272 | if (equivalentBounds(existing, bounds)) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 273 | return BOUNDS_CHANGE_NONE; |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 274 | } |
| 275 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 276 | final int result = super.setBounds(bounds); |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 277 | |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 278 | if (getParent() != null) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 279 | updateAnimationBackgroundBounds(); |
| 280 | } |
| 281 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 282 | updateAdjustedBounds(); |
Chong Zhang | b816b86 | 2016-01-25 12:01:12 -0800 | [diff] [blame] | 283 | |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 284 | updateSurfaceBounds(); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 285 | return result; |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 286 | } |
| 287 | |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 288 | /** Bounds of the stack without adjusting for other factors in the system like visibility |
| 289 | * of docked stack. |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 290 | * Most callers should be using {@link ConfigurationContainer#getRequestedOverrideBounds} a |
| 291 | * it takes into consideration other system factors. */ |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 292 | void getRawBounds(Rect out) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 293 | out.set(getRawBounds()); |
| 294 | } |
| 295 | |
| 296 | Rect getRawBounds() { |
| 297 | return super.getBounds(); |
Craig Mautner | b660b9d | 2014-02-13 10:59:16 -0800 | [diff] [blame] | 298 | } |
| 299 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 300 | @Override |
| 301 | public void getBounds(Rect bounds) { |
| 302 | bounds.set(getBounds()); |
| 303 | } |
| 304 | |
| 305 | @Override |
| 306 | public Rect getBounds() { |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 307 | // If we're currently adjusting for IME or minimized docked stack, we use the adjusted |
| 308 | // bounds; otherwise, no need to adjust the output bounds if fullscreen or the docked |
| 309 | // stack is visible since it is already what we want to represent to the rest of the |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 310 | // system. |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 311 | if (!mAdjustedBounds.isEmpty()) { |
| 312 | return mAdjustedBounds; |
| 313 | } else { |
| 314 | return super.getBounds(); |
| 315 | } |
Wale Ogunwale | f175e8a | 2015-09-29 11:07:06 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Winson Chung | 84a3834 | 2016-11-08 16:15:10 -0800 | [diff] [blame] | 318 | /** |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 319 | * Sets the bounds animation target bounds ahead of an animation. This can't currently be done |
| 320 | * in onAnimationStart() since that is started on the UiThread. |
Winson Chung | 84a3834 | 2016-11-08 16:15:10 -0800 | [diff] [blame] | 321 | */ |
chaviw | 01f1aa4 | 2019-05-14 10:08:12 -0700 | [diff] [blame] | 322 | private void setAnimationFinalBounds(Rect sourceHintBounds, Rect destBounds, |
| 323 | boolean toFullscreen) { |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 324 | mBoundsAnimatingRequested = true; |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 325 | mBoundsAnimatingToFullscreen = toFullscreen; |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 326 | if (destBounds != null) { |
| 327 | mBoundsAnimationTarget.set(destBounds); |
Winson Chung | 84a3834 | 2016-11-08 16:15:10 -0800 | [diff] [blame] | 328 | } else { |
| 329 | mBoundsAnimationTarget.setEmpty(); |
| 330 | } |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 331 | if (sourceHintBounds != null) { |
| 332 | mBoundsAnimationSourceHintBounds.set(sourceHintBounds); |
chaviw | 01f1aa4 | 2019-05-14 10:08:12 -0700 | [diff] [blame] | 333 | } else if (!mBoundsAnimating) { |
| 334 | // If the bounds are already animating, we don't want to reset the source hint. This is |
| 335 | // because the source hint is sent when starting the animation from the client that |
| 336 | // requested to enter pip. Other requests can adjust the pip bounds during an animation, |
| 337 | // but could accidentally reset the source hint bounds. |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 338 | mBoundsAnimationSourceHintBounds.setEmpty(); |
| 339 | } |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 340 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 341 | mPreAnimationBounds.set(getRawBounds()); |
Winson Chung | 84a3834 | 2016-11-08 16:15:10 -0800 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | /** |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 345 | * @return the final bounds for the bounds animation. |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 346 | */ |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 347 | void getFinalAnimationBounds(Rect outBounds) { |
| 348 | outBounds.set(mBoundsAnimationTarget); |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /** |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 352 | * @return the final source bounds for the bounds animation. |
Winson Chung | 84a3834 | 2016-11-08 16:15:10 -0800 | [diff] [blame] | 353 | */ |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 354 | void getFinalAnimationSourceHintBounds(Rect outBounds) { |
| 355 | outBounds.set(mBoundsAnimationSourceHintBounds); |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | /** |
| 359 | * @return the final animation bounds if the task stack is currently being animated, or the |
| 360 | * current stack bounds otherwise. |
| 361 | */ |
| 362 | void getAnimationOrCurrentBounds(Rect outBounds) { |
| 363 | if ((mBoundsAnimatingRequested || mBoundsAnimating) && !mBoundsAnimationTarget.isEmpty()) { |
| 364 | getFinalAnimationBounds(outBounds); |
Winson Chung | 84a3834 | 2016-11-08 16:15:10 -0800 | [diff] [blame] | 365 | return; |
| 366 | } |
| 367 | getBounds(outBounds); |
| 368 | } |
| 369 | |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 370 | /** Bounds of the stack with other system factors taken into consideration. */ |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 371 | public void getDimBounds(Rect out) { |
| 372 | getBounds(out); |
| 373 | } |
| 374 | |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 375 | /** |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 376 | * Updates the passed-in {@code inOutBounds} based on the current state of the |
| 377 | * pinned controller. This gets run *after* the override configuration is updated, so it's |
| 378 | * safe to rely on the controller's state in here (though eventually this dependence should |
| 379 | * be removed). |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 380 | * |
| 381 | * This does NOT modify this TaskStack's configuration. However, it does, for the time-being, |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 382 | * update pinned controller state. |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 383 | * |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 384 | * @param inOutBounds the bounds to update (both input and output). |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 385 | * @return true if bounds were updated to some non-empty value. |
| 386 | */ |
| 387 | boolean calculatePinnedBoundsForConfigChange(Rect inOutBounds) { |
wilsonshih | 4dd0712 | 2019-04-03 15:55:02 +0800 | [diff] [blame] | 388 | boolean animating = false; |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 389 | if ((mBoundsAnimatingRequested || mBoundsAnimating) && !mBoundsAnimationTarget.isEmpty()) { |
wilsonshih | 4dd0712 | 2019-04-03 15:55:02 +0800 | [diff] [blame] | 390 | animating = true; |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 391 | getFinalAnimationBounds(mTmpRect2); |
| 392 | } else { |
| 393 | mTmpRect2.set(inOutBounds); |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 394 | } |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 395 | boolean updated = mDisplayContent.mPinnedStackControllerLocked.onTaskStackBoundsChanged( |
| 396 | mTmpRect2, mTmpRect3); |
| 397 | if (updated) { |
| 398 | inOutBounds.set(mTmpRect3); |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 399 | |
wilsonshih | 4dd0712 | 2019-04-03 15:55:02 +0800 | [diff] [blame] | 400 | // The final boundary is updated while there is an existing boundary animation. Let's |
| 401 | // cancel this animation to prevent the obsolete animation overwritten updated bounds. |
| 402 | if (animating && !inOutBounds.equals(mBoundsAnimationTarget)) { |
| 403 | final DisplayContent displayContent = getDisplayContent(); |
| 404 | displayContent.mBoundsAnimationController.getHandler().post(() -> |
| 405 | displayContent.mBoundsAnimationController.cancel(this)); |
| 406 | } |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 407 | // Once we've set the bounds based on the rotation of the old bounds in the new |
| 408 | // orientation, clear the animation target bounds since they are obsolete, and |
| 409 | // cancel any currently running animations |
| 410 | mBoundsAnimationTarget.setEmpty(); |
| 411 | mBoundsAnimationSourceHintBounds.setEmpty(); |
| 412 | mCancelCurrentBoundsAnimation = true; |
Wale Ogunwale | ecbcadd | 2016-02-21 14:18:51 -0800 | [diff] [blame] | 413 | } |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 414 | return updated; |
| 415 | } |
Wale Ogunwale | ecbcadd | 2016-02-21 14:18:51 -0800 | [diff] [blame] | 416 | |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 417 | /** |
| 418 | * Updates the passed-in {@code inOutBounds} based on the current state of the |
| 419 | * docked controller. This gets run *after* the override configuration is updated, so it's |
| 420 | * safe to rely on the controller's state in here (though eventually this dependence should |
| 421 | * be removed). |
| 422 | * |
| 423 | * This does NOT modify this TaskStack's configuration. However, it does, for the time-being, |
| 424 | * update docked controller state. |
| 425 | * |
| 426 | * @param parentConfig the parent configuration for reference. |
| 427 | * @param inOutBounds the bounds to update (both input and output). |
| 428 | */ |
| 429 | void calculateDockedBoundsForConfigChange(Configuration parentConfig, Rect inOutBounds) { |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 430 | final boolean primary = |
| 431 | getRequestedOverrideWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 432 | repositionSplitScreenStackAfterRotation(parentConfig, primary, inOutBounds); |
| 433 | final DisplayCutout cutout = mDisplayContent.getDisplayInfo().displayCutout; |
| 434 | snapDockedStackAfterRotation(parentConfig, cutout, inOutBounds); |
| 435 | if (primary) { |
| 436 | final int newDockSide = getDockSide(parentConfig, inOutBounds); |
| 437 | // Update the dock create mode and clear the dock create bounds, these |
| 438 | // might change after a rotation and the original values will be invalid. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 439 | mWmService.setDockedStackCreateStateLocked( |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 440 | (newDockSide == DOCKED_LEFT || newDockSide == DOCKED_TOP) |
| 441 | ? SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT |
| 442 | : SPLIT_SCREEN_CREATE_MODE_BOTTOM_OR_RIGHT, |
| 443 | null); |
| 444 | mDisplayContent.getDockedDividerController().notifyDockSideChanged(newDockSide); |
Chong Zhang | ccc335c | 2016-05-13 11:04:38 -0700 | [diff] [blame] | 445 | } |
Chong Zhang | 167bbfac | 2016-03-31 09:44:34 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 448 | /** |
Matthew Ng | cb1b8e4 | 2017-10-20 16:29:23 -0700 | [diff] [blame] | 449 | * Some primary split screen sides are not allowed by the policy. This method queries the policy |
| 450 | * and moves the primary stack around if needed. |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 451 | * |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 452 | * @param parentConfig the configuration of the stack's parent. |
| 453 | * @param primary true if adjusting the primary docked stack, false for secondary. |
| 454 | * @param inOutBounds the bounds of the stack to adjust. |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 455 | */ |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 456 | void repositionSplitScreenStackAfterRotation(Configuration parentConfig, boolean primary, |
| 457 | Rect inOutBounds) { |
| 458 | final int dockSide = getDockSide(mDisplayContent, parentConfig, inOutBounds); |
| 459 | final int otherDockSide = DockedDividerUtils.invertDockSide(dockSide); |
| 460 | final int primaryDockSide = primary ? dockSide : otherDockSide; |
| 461 | if (mDisplayContent.getDockedDividerController() |
| 462 | .canPrimaryStackDockTo(primaryDockSide, |
| 463 | parentConfig.windowConfiguration.getBounds(), |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 464 | parentConfig.windowConfiguration.getRotation())) { |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 465 | return; |
| 466 | } |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 467 | final Rect parentBounds = parentConfig.windowConfiguration.getBounds(); |
| 468 | switch (otherDockSide) { |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 469 | case DOCKED_LEFT: |
| 470 | int movement = inOutBounds.left; |
| 471 | inOutBounds.left -= movement; |
| 472 | inOutBounds.right -= movement; |
| 473 | break; |
| 474 | case DOCKED_RIGHT: |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 475 | movement = parentBounds.right - inOutBounds.right; |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 476 | inOutBounds.left += movement; |
| 477 | inOutBounds.right += movement; |
| 478 | break; |
| 479 | case DOCKED_TOP: |
| 480 | movement = inOutBounds.top; |
| 481 | inOutBounds.top -= movement; |
| 482 | inOutBounds.bottom -= movement; |
| 483 | break; |
| 484 | case DOCKED_BOTTOM: |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 485 | movement = parentBounds.bottom - inOutBounds.bottom; |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 486 | inOutBounds.top += movement; |
| 487 | inOutBounds.bottom += movement; |
| 488 | break; |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | /** |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 493 | * Snaps the bounds after rotation to the closest snap target for the docked stack. |
| 494 | */ |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 495 | void snapDockedStackAfterRotation(Configuration parentConfig, DisplayCutout displayCutout, |
| 496 | Rect outBounds) { |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 497 | |
| 498 | // Calculate the current position. |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 499 | final int dividerSize = mDisplayContent.getDockedDividerController().getContentWidth(); |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 500 | final int dockSide = getDockSide(parentConfig, outBounds); |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 501 | final int dividerPosition = DockedDividerUtils.calculatePositionForBounds(outBounds, |
| 502 | dockSide, dividerSize); |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 503 | final int displayWidth = parentConfig.windowConfiguration.getBounds().width(); |
| 504 | final int displayHeight = parentConfig.windowConfiguration.getBounds().height(); |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 505 | |
| 506 | // Snap the position to a target. |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 507 | final int rotation = parentConfig.windowConfiguration.getRotation(); |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 508 | final int orientation = parentConfig.orientation; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 509 | mDisplayContent.getDisplayPolicy().getStableInsetsLw(rotation, displayWidth, displayHeight, |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 510 | displayCutout, outBounds); |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 511 | final DividerSnapAlgorithm algorithm = new DividerSnapAlgorithm( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 512 | mWmService.mContext.getResources(), displayWidth, displayHeight, |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 513 | dividerSize, orientation == Configuration.ORIENTATION_PORTRAIT, outBounds, |
Matthew Ng | f59a413 | 2017-10-25 12:03:22 -0700 | [diff] [blame] | 514 | getDockSide(), isMinimizedDockAndHomeStackResizable()); |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 515 | final SnapTarget target = algorithm.calculateNonDismissingSnapTarget(dividerPosition); |
| 516 | |
| 517 | // Recalculate the bounds based on the position of the target. |
| 518 | DockedDividerUtils.calculateBoundsForPosition(target.position, dockSide, |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 519 | outBounds, displayWidth, displayHeight, |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 520 | dividerSize); |
| 521 | } |
| 522 | |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 523 | // TODO: Checkout the call points of this method and the ones below to see how they can fit in WC. |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 524 | void addTask(Task task, int position) { |
| 525 | addTask(task, position, task.showForAllUsers(), true /* moveParents */); |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 526 | } |
| 527 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 528 | /** |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 529 | * Put a Task in this stack. Used for adding only. |
| 530 | * When task is added to top of the stack, the entire branch of the hierarchy (including stack |
| 531 | * and display) will be brought to top. |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 532 | * @param task The task to add. |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 533 | * @param position Target position to add the task to. |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 534 | * @param showForAllUsers Whether to show the task regardless of the current user. |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 535 | */ |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 536 | void addTask(Task task, int position, boolean showForAllUsers, boolean moveParents) { |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 537 | final TaskStack currentStack = task.mStack; |
| 538 | // TODO: We pass stack to task's constructor, but we still need to call this method. |
| 539 | // This doesn't make sense, mStack will already be set equal to "this" at this point. |
| 540 | if (currentStack != null && currentStack.mStackId != mStackId) { |
| 541 | throw new IllegalStateException("Trying to add taskId=" + task.mTaskId |
| 542 | + " to stackId=" + mStackId |
| 543 | + ", but it is already attached to stackId=" + task.mStack.mStackId); |
| 544 | } |
| 545 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 546 | // Add child task. |
| 547 | task.mStack = this; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 548 | addChild(task, null); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 549 | |
| 550 | // Move child to a proper position, as some restriction for position might apply. |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 551 | positionChildAt(position, task, moveParents /* includingParents */, showForAllUsers); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 552 | } |
| 553 | |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 554 | void positionChildAt(Task child, int position) { |
| 555 | if (DEBUG_STACK) { |
| 556 | Slog.i(TAG_WM, "positionChildAt: positioning task=" + child + " at " + position); |
| 557 | } |
| 558 | if (child == null) { |
| 559 | if (DEBUG_STACK) { |
| 560 | Slog.i(TAG_WM, "positionChildAt: could not find task=" + this); |
| 561 | } |
| 562 | return; |
| 563 | } |
| 564 | child.positionAt(position); |
| 565 | getDisplayContent().layoutAndAssignWindowLayersIfNeeded(); |
| 566 | } |
| 567 | |
| 568 | void positionChildAtTop(Task child, boolean includingParents) { |
| 569 | if (child == null) { |
| 570 | // TODO: Fix the call-points that cause this to happen. |
| 571 | return; |
| 572 | } |
| 573 | |
| 574 | positionChildAt(POSITION_TOP, child, includingParents); |
| 575 | |
| 576 | final DisplayContent displayContent = getDisplayContent(); |
| 577 | if (displayContent.mAppTransition.isTransitionSet()) { |
| 578 | child.setSendingToBottom(false); |
| 579 | } |
| 580 | displayContent.layoutAndAssignWindowLayersIfNeeded(); |
| 581 | } |
| 582 | |
| 583 | void positionChildAtBottom(Task child, boolean includingParents) { |
| 584 | if (child == null) { |
| 585 | // TODO: Fix the call-points that cause this to happen. |
| 586 | return; |
| 587 | } |
| 588 | |
| 589 | positionChildAt(POSITION_BOTTOM, child, includingParents); |
| 590 | |
| 591 | if (getDisplayContent().mAppTransition.isTransitionSet()) { |
| 592 | child.setSendingToBottom(true); |
| 593 | } |
| 594 | getDisplayContent().layoutAndAssignWindowLayersIfNeeded(); |
| 595 | } |
| 596 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 597 | @Override |
| 598 | void positionChildAt(int position, Task child, boolean includingParents) { |
| 599 | positionChildAt(position, child, includingParents, child.showForAllUsers()); |
| 600 | } |
| 601 | |
| 602 | /** |
| 603 | * Overridden version of {@link TaskStack#positionChildAt(int, Task, boolean)}. Used in |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 604 | * {@link TaskStack#addTask(Task, int, boolean showForAllUsers, boolean)}, as it can receive |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 605 | * showForAllUsers param from {@link AppWindowToken} instead of {@link Task#showForAllUsers()}. |
| 606 | */ |
| 607 | private void positionChildAt(int position, Task child, boolean includingParents, |
| 608 | boolean showForAllUsers) { |
| 609 | final int targetPosition = findPositionForTask(child, position, showForAllUsers, |
| 610 | false /* addingNew */); |
| 611 | super.positionChildAt(targetPosition, child, includingParents); |
| 612 | |
| 613 | // Log positioning. |
| 614 | if (DEBUG_TASK_MOVEMENT) |
| 615 | Slog.d(TAG_WM, "positionTask: task=" + this + " position=" + position); |
| 616 | |
| 617 | final int toTop = targetPosition == mChildren.size() - 1 ? 1 : 0; |
| 618 | EventLog.writeEvent(EventLogTags.WM_TASK_MOVED, child.mTaskId, toTop, targetPosition); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 621 | void reparent(int displayId, Rect outStackBounds, boolean onTop) { |
| 622 | final DisplayContent targetDc = mWmService.mRoot.getDisplayContent(displayId); |
| 623 | if (targetDc == null) { |
| 624 | throw new IllegalArgumentException("Trying to move stackId=" + mStackId |
| 625 | + " to unknown displayId=" + displayId); |
| 626 | } |
| 627 | |
| 628 | targetDc.moveStackToDisplay(this, onTop); |
| 629 | if (matchParentBounds()) { |
| 630 | outStackBounds.setEmpty(); |
| 631 | } else { |
| 632 | getRawBounds(outStackBounds); |
| 633 | } |
| 634 | } |
| 635 | |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 636 | // TODO: We should really have users as a window container in the hierarchy so that we don't |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 637 | // have to do complicated things like we are doing in this method. |
| 638 | private int findPositionForTask(Task task, int targetPosition, boolean showForAllUsers, |
| 639 | boolean addingNew) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 640 | final boolean canShowTask = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 641 | showForAllUsers || mWmService.isCurrentProfileLocked(task.mUserId); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 642 | |
| 643 | final int stackSize = mChildren.size(); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 644 | int minPosition = 0; |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 645 | int maxPosition = addingNew ? stackSize : stackSize - 1; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 646 | |
| 647 | if (canShowTask) { |
| 648 | minPosition = computeMinPosition(minPosition, stackSize); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 649 | } else { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 650 | maxPosition = computeMaxPosition(maxPosition); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 651 | } |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 652 | |
| 653 | // preserve POSITION_BOTTOM/POSITION_TOP positions if they are still valid. |
| 654 | if (targetPosition == POSITION_BOTTOM && minPosition == 0) { |
| 655 | return POSITION_BOTTOM; |
| 656 | } else if (targetPosition == POSITION_TOP |
| 657 | && maxPosition == (addingNew ? stackSize : stackSize - 1)) { |
| 658 | return POSITION_TOP; |
| 659 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 660 | // Reset position based on minimum/maximum possible positions. |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 661 | return Math.min(Math.max(targetPosition, minPosition), maxPosition); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | /** Calculate the minimum possible position for a task that can be shown to the user. |
| 665 | * The minimum position will be above all other tasks that can't be shown. |
| 666 | * @param minPosition The minimum position the caller is suggesting. |
| 667 | * We will start adjusting up from here. |
| 668 | * @param size The size of the current task list. |
| 669 | */ |
| 670 | private int computeMinPosition(int minPosition, int size) { |
| 671 | while (minPosition < size) { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 672 | final Task tmpTask = mChildren.get(minPosition); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 673 | final boolean canShowTmpTask = |
| 674 | tmpTask.showForAllUsers() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 675 | || mWmService.isCurrentProfileLocked(tmpTask.mUserId); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 676 | if (canShowTmpTask) { |
| 677 | break; |
| 678 | } |
| 679 | minPosition++; |
| 680 | } |
| 681 | return minPosition; |
| 682 | } |
| 683 | |
| 684 | /** Calculate the maximum possible position for a task that can't be shown to the user. |
| 685 | * The maximum position will be below all other tasks that can be shown. |
| 686 | * @param maxPosition The maximum position the caller is suggesting. |
| 687 | * We will start adjusting down from here. |
| 688 | */ |
| 689 | private int computeMaxPosition(int maxPosition) { |
| 690 | while (maxPosition > 0) { |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 691 | final Task tmpTask = mChildren.get(maxPosition); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 692 | final boolean canShowTmpTask = |
| 693 | tmpTask.showForAllUsers() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 694 | || mWmService.isCurrentProfileLocked(tmpTask.mUserId); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 695 | if (!canShowTmpTask) { |
| 696 | break; |
| 697 | } |
| 698 | maxPosition--; |
| 699 | } |
| 700 | return maxPosition; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 701 | } |
| 702 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 703 | /** |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 704 | * Delete a Task from this stack. If it is the last Task in the stack, move this stack to the |
| 705 | * back. |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 706 | * @param task The Task to delete. |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 707 | */ |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 708 | @Override |
| 709 | void removeChild(Task task) { |
| 710 | if (DEBUG_TASK_MOVEMENT) Slog.d(TAG_WM, "removeChild: task=" + task); |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 711 | |
| 712 | super.removeChild(task); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 713 | task.mStack = null; |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 714 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 715 | if (mDisplayContent != null) { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 716 | if (mChildren.isEmpty()) { |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 717 | getParent().positionChildAt(POSITION_BOTTOM, this, false /* includingParents */); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 718 | } |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 719 | mDisplayContent.setLayoutNeeded(); |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 720 | } |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 721 | for (int appNdx = mExitingAppTokens.size() - 1; appNdx >= 0; --appNdx) { |
| 722 | final AppWindowToken wtoken = mExitingAppTokens.get(appNdx); |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 723 | if (wtoken.getTask() == task) { |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 724 | wtoken.mIsExiting = false; |
| 725 | mExitingAppTokens.remove(appNdx); |
| 726 | } |
| 727 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 728 | } |
| 729 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 730 | @Override |
| 731 | public void onConfigurationChanged(Configuration newParentConfig) { |
| 732 | final int prevWindowingMode = getWindowingMode(); |
Jorim Jaggi | 1a6d98b | 2018-01-08 16:23:00 +0100 | [diff] [blame] | 733 | super.onConfigurationChanged(newParentConfig); |
| 734 | |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 735 | // Only need to update surface size here since the super method will handle updating |
| 736 | // surface position. |
| 737 | updateSurfaceSize(getPendingTransaction()); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 738 | final int windowingMode = getWindowingMode(); |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 739 | final boolean isAlwaysOnTop = isAlwaysOnTop(); |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 740 | |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 741 | if (mDisplayContent == null) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 742 | return; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 743 | } |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 744 | |
| 745 | if (prevWindowingMode != windowingMode) { |
| 746 | mDisplayContent.onStackWindowingModeChanged(this); |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 747 | |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 748 | if (inSplitScreenSecondaryWindowingMode()) { |
| 749 | // When the stack is resized due to entering split screen secondary, offset the |
| 750 | // windows to compensate for the new stack position. |
| 751 | forAllWindows(w -> { |
| 752 | w.mWinAnimator.setOffsetPositionForStackResize(true); |
| 753 | }, true); |
| 754 | } |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 755 | } |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 756 | } |
| 757 | |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 758 | private void updateSurfaceBounds() { |
chaviw | 2f0567b | 2018-01-29 16:22:02 -0800 | [diff] [blame] | 759 | updateSurfaceSize(getPendingTransaction()); |
| 760 | updateSurfacePosition(); |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 761 | scheduleAnimation(); |
| 762 | } |
| 763 | |
Robert Carr | 32bcb10 | 2018-01-29 15:03:23 -0800 | [diff] [blame] | 764 | /** |
| 765 | * Calculate an amount by which to expand the stack bounds in each direction. |
| 766 | * Used to make room for shadows in the pinned windowing mode. |
| 767 | */ |
| 768 | int getStackOutset() { |
Evan Rosky | b1ea7ca | 2018-04-05 17:17:35 -0700 | [diff] [blame] | 769 | DisplayContent displayContent = getDisplayContent(); |
| 770 | if (inPinnedWindowingMode() && displayContent != null) { |
| 771 | final DisplayMetrics displayMetrics = displayContent.getDisplayMetrics(); |
Robert Carr | 74a66a2 | 2018-02-23 12:17:51 -0800 | [diff] [blame] | 772 | |
| 773 | // We multiply by two to match the client logic for converting view elevation |
| 774 | // to insets, as in {@link WindowManager.LayoutParams#setSurfaceInsets} |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 775 | return (int)Math.ceil(mWmService.dipToPixel(PINNED_WINDOWING_MODE_ELEVATION_IN_DIP, |
Robert Carr | 74a66a2 | 2018-02-23 12:17:51 -0800 | [diff] [blame] | 776 | displayMetrics) * 2); |
Robert Carr | 32bcb10 | 2018-01-29 15:03:23 -0800 | [diff] [blame] | 777 | } |
| 778 | return 0; |
| 779 | } |
| 780 | |
Riddle Hsu | 6619acb | 2019-02-20 19:12:57 +0800 | [diff] [blame] | 781 | @Override |
| 782 | void getRelativeDisplayedPosition(Point outPos) { |
| 783 | super.getRelativeDisplayedPosition(outPos); |
| 784 | final int outset = getStackOutset(); |
| 785 | outPos.x -= outset; |
| 786 | outPos.y -= outset; |
| 787 | } |
| 788 | |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 789 | private void updateSurfaceSize(SurfaceControl.Transaction transaction) { |
| 790 | if (mSurfaceControl == null) { |
| 791 | return; |
| 792 | } |
| 793 | |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 794 | final Rect stackBounds = getDisplayedBounds(); |
Robert Carr | 32bcb10 | 2018-01-29 15:03:23 -0800 | [diff] [blame] | 795 | int width = stackBounds.width(); |
| 796 | int height = stackBounds.height(); |
| 797 | |
| 798 | final int outset = getStackOutset(); |
| 799 | width += 2*outset; |
| 800 | height += 2*outset; |
| 801 | |
chaviw | 3e751af | 2018-01-11 11:22:39 -0800 | [diff] [blame] | 802 | if (width == mLastSurfaceSize.x && height == mLastSurfaceSize.y) { |
| 803 | return; |
| 804 | } |
Evan Rosky | 1c66f44 | 2019-04-30 16:02:58 -0700 | [diff] [blame] | 805 | if (getWindowConfiguration().tasksAreFloating()) { |
| 806 | // Don't crop freeform windows to the stack. |
| 807 | transaction.setWindowCrop(mSurfaceControl, -1, -1); |
| 808 | } else { |
| 809 | transaction.setWindowCrop(mSurfaceControl, width, height); |
| 810 | } |
chaviw | 3e751af | 2018-01-11 11:22:39 -0800 | [diff] [blame] | 811 | mLastSurfaceSize.set(width, height); |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 812 | } |
| 813 | |
Riddle Hsu | 6619acb | 2019-02-20 19:12:57 +0800 | [diff] [blame] | 814 | @VisibleForTesting |
| 815 | Point getLastSurfaceSize() { |
| 816 | return mLastSurfaceSize; |
| 817 | } |
| 818 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 819 | @Override |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 820 | void onDisplayChanged(DisplayContent dc) { |
Garfield Tan | 2f145f2 | 2018-11-01 15:27:03 -0700 | [diff] [blame] | 821 | if (mDisplayContent != null && mDisplayContent != dc) { |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 822 | throw new IllegalStateException("onDisplayChanged: Already attached"); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 823 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 824 | |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 825 | super.onDisplayChanged(dc); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 826 | |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 827 | updateSurfaceBounds(); |
Garfield Tan | f80d420 | 2018-11-15 11:17:06 -0800 | [diff] [blame] | 828 | if (mAnimationBackgroundSurface == null) { |
Chavi Weingarten | 6ef9cc6 | 2019-02-07 16:28:45 +0000 | [diff] [blame] | 829 | mAnimationBackgroundSurface = makeChildSurface(null).setColorLayer() |
Garfield Tan | 2f145f2 | 2018-11-01 15:27:03 -0700 | [diff] [blame] | 830 | .setName("animation background stackId=" + mStackId) |
| 831 | .build(); |
| 832 | } |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 833 | } |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 834 | |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 835 | /** |
| 836 | * Determines the stack and task bounds of the other stack when in docked mode. The current task |
| 837 | * bounds is passed in but depending on the stack, the task and stack must match. Only in |
| 838 | * minimized mode with resizable launcher, the other stack ignores calculating the stack bounds |
| 839 | * and uses the task bounds passed in as the stack and task bounds, otherwise the stack bounds |
| 840 | * is calculated and is also used for its task bounds. |
| 841 | * If any of the out bounds are empty, it represents default bounds |
| 842 | * |
| 843 | * @param currentTempTaskBounds the current task bounds of the other stack |
| 844 | * @param outStackBounds the calculated stack bounds of the other stack |
| 845 | * @param outTempTaskBounds the calculated task bounds of the other stack |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 846 | */ |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 847 | void getStackDockedModeBoundsLocked(Configuration parentConfig, Rect dockedBounds, |
| 848 | Rect currentTempTaskBounds, Rect outStackBounds, Rect outTempTaskBounds) { |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 849 | outTempTaskBounds.setEmpty(); |
| 850 | |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 851 | if (dockedBounds == null || dockedBounds.isEmpty()) { |
| 852 | // Calculate the primary docked bounds. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 853 | final boolean dockedOnTopOrLeft = mWmService.mDockedStackCreateMode |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 854 | == SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT; |
| 855 | getStackDockedModeBounds(parentConfig, |
| 856 | true /* primary */, outStackBounds, dockedBounds, |
| 857 | mDisplayContent.mDividerControllerLocked.getContentWidth(), dockedOnTopOrLeft); |
| 858 | return; |
| 859 | } |
| 860 | final int dockedSide = getDockSide(parentConfig, dockedBounds); |
| 861 | |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 862 | // When the home stack is resizable, should always have the same stack and task bounds |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 863 | if (isActivityTypeHome()) { |
Winson Chung | f7fb5e3 | 2017-05-23 17:47:05 -0700 | [diff] [blame] | 864 | final Task homeTask = findHomeTask(); |
| 865 | if (homeTask != null && homeTask.isResizeable()) { |
Wale Ogunwale | 649c160 | 2017-04-24 10:15:31 -0700 | [diff] [blame] | 866 | // Calculate the home stack bounds when in docked mode and the home stack is |
| 867 | // resizeable. |
| 868 | getDisplayContent().mDividerControllerLocked |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 869 | .getHomeStackBoundsInDockedMode(parentConfig, |
| 870 | dockedSide, outStackBounds); |
Wale Ogunwale | 649c160 | 2017-04-24 10:15:31 -0700 | [diff] [blame] | 871 | } else { |
| 872 | // Home stack isn't resizeable, so don't specify stack bounds. |
| 873 | outStackBounds.setEmpty(); |
| 874 | } |
| 875 | |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 876 | outTempTaskBounds.set(outStackBounds); |
| 877 | return; |
| 878 | } |
| 879 | |
| 880 | // When minimized state, the stack bounds for all non-home and docked stack bounds should |
| 881 | // match the passed task bounds |
| 882 | if (isMinimizedDockAndHomeStackResizable() && currentTempTaskBounds != null) { |
| 883 | outStackBounds.set(currentTempTaskBounds); |
| 884 | return; |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 885 | } |
| 886 | |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 887 | if (dockedSide == DOCKED_INVALID) { |
| 888 | // Not sure how you got here...Only thing we can do is return current bounds. |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 889 | Slog.e(TAG_WM, "Failed to get valid docked side for docked stack"); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 890 | outStackBounds.set(getRawBounds()); |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 891 | return; |
| 892 | } |
| 893 | |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 894 | final boolean dockedOnTopOrLeft = dockedSide == DOCKED_TOP || dockedSide == DOCKED_LEFT; |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 895 | getStackDockedModeBounds(parentConfig, |
| 896 | false /* primary */, outStackBounds, dockedBounds, |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 897 | mDisplayContent.mDividerControllerLocked.getContentWidth(), dockedOnTopOrLeft); |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 898 | } |
| 899 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 900 | /** |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 901 | * Outputs the bounds a stack should be given the presence of a docked stack on the display. |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 902 | * @param parentConfig The parent configuration. |
| 903 | * @param primary {@code true} if getting the primary stack bounds. |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 904 | * @param outBounds Output bounds that should be used for the stack. |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 905 | * @param dockedBounds Bounds of the docked stack. |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 906 | * @param dockDividerWidth We need to know the width of the divider make to the output bounds |
| 907 | * close to the side of the dock. |
| 908 | * @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] | 909 | */ |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 910 | private void getStackDockedModeBounds(Configuration parentConfig, boolean primary, |
| 911 | Rect outBounds, Rect dockedBounds, int dockDividerWidth, |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 912 | boolean dockOnTopOrLeft) { |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 913 | final Rect displayRect = parentConfig.windowConfiguration.getBounds(); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 914 | final boolean splitHorizontally = displayRect.width() > displayRect.height(); |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 915 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 916 | outBounds.set(displayRect); |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 917 | if (primary) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 918 | if (mWmService.mDockedStackCreateBounds != null) { |
| 919 | outBounds.set(mWmService.mDockedStackCreateBounds); |
Jorim Jaggi | 9ea2f7b | 2015-11-23 18:08:28 -0800 | [diff] [blame] | 920 | return; |
| 921 | } |
Jorim Jaggi | d434dcb | 2016-01-06 17:18:44 +0100 | [diff] [blame] | 922 | |
| 923 | // The initial bounds of the docked stack when it is created about half the screen space |
| 924 | // and its bounds can be adjusted after that. The bounds of all other stacks are |
| 925 | // adjusted to occupy whatever screen space the docked stack isn't occupying. |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 926 | final DisplayCutout displayCutout = mDisplayContent.getDisplayInfo().displayCutout; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 927 | mDisplayContent.getDisplayPolicy().getStableInsetsLw( |
| 928 | parentConfig.windowConfiguration.getRotation(), |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 929 | displayRect.width(), displayRect.height(), displayCutout, mTmpRect2); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 930 | final int position = new DividerSnapAlgorithm(mWmService.mContext.getResources(), |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 931 | displayRect.width(), |
| 932 | displayRect.height(), |
Jorim Jaggi | d434dcb | 2016-01-06 17:18:44 +0100 | [diff] [blame] | 933 | dockDividerWidth, |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 934 | parentConfig.orientation == ORIENTATION_PORTRAIT, |
Jorim Jaggi | d434dcb | 2016-01-06 17:18:44 +0100 | [diff] [blame] | 935 | mTmpRect2).getMiddleTarget().position; |
| 936 | |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 937 | if (dockOnTopOrLeft) { |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 938 | if (splitHorizontally) { |
Jorim Jaggi | d434dcb | 2016-01-06 17:18:44 +0100 | [diff] [blame] | 939 | outBounds.right = position; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 940 | } else { |
Jorim Jaggi | d434dcb | 2016-01-06 17:18:44 +0100 | [diff] [blame] | 941 | outBounds.bottom = position; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 942 | } |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 943 | } else { |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 944 | if (splitHorizontally) { |
Andrii Kulian | ef3b272 | 2016-04-08 12:45:27 -0700 | [diff] [blame] | 945 | outBounds.left = position + dockDividerWidth; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 946 | } else { |
Andrii Kulian | ef3b272 | 2016-04-08 12:45:27 -0700 | [diff] [blame] | 947 | outBounds.top = position + dockDividerWidth; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 948 | } |
| 949 | } |
| 950 | return; |
| 951 | } |
| 952 | |
| 953 | // Other stacks occupy whatever space is left by the docked stack. |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 954 | if (!dockOnTopOrLeft) { |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 955 | if (splitHorizontally) { |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 956 | outBounds.right = dockedBounds.left - dockDividerWidth; |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 957 | } else { |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 958 | outBounds.bottom = dockedBounds.top - dockDividerWidth; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 959 | } |
| 960 | } else { |
| 961 | if (splitHorizontally) { |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 962 | outBounds.left = dockedBounds.right + dockDividerWidth; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 963 | } else { |
Filip Gruszczynski | ba47f81 | 2015-10-28 16:11:55 -0700 | [diff] [blame] | 964 | outBounds.top = dockedBounds.bottom + dockDividerWidth; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 965 | } |
| 966 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 967 | DockedDividerUtils.sanitizeStackBounds(outBounds, !dockOnTopOrLeft); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 968 | } |
| 969 | |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 970 | void resetDockedStackToMiddle() { |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 971 | if (inSplitScreenPrimaryWindowingMode()) { |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 972 | throw new IllegalStateException("Not a docked stack=" + this); |
| 973 | } |
| 974 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 975 | mWmService.mDockedStackCreateBounds = null; |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 976 | |
| 977 | final Rect bounds = new Rect(); |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 978 | final Rect tempBounds = new Rect(); |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 979 | TaskStack dockedStack = mDisplayContent.getSplitScreenPrimaryStackIgnoringVisibility(); |
| 980 | Rect dockedBounds = |
| 981 | (dockedStack == null || dockedStack == this) ? null : dockedStack.getRawBounds(); |
| 982 | getStackDockedModeBoundsLocked(mDisplayContent.getConfiguration(), dockedBounds, |
| 983 | null /* currentTempTaskBounds */, bounds, tempBounds); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 984 | mActivityStack.requestResize(bounds); |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 985 | } |
| 986 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 987 | @Override |
| 988 | void removeIfPossible() { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 989 | if (isSelfOrChildAnimating()) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 990 | mDeferRemoval = true; |
| 991 | return; |
| 992 | } |
| 993 | removeImmediately(); |
| 994 | } |
| 995 | |
| 996 | @Override |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 997 | void removeImmediately() { |
| 998 | if (mActivityStack != null) { |
| 999 | mActivityStack.unregisterConfigurationChangeListener(this); |
| 1000 | } |
| 1001 | super.removeImmediately(); |
| 1002 | } |
| 1003 | |
| 1004 | @Override |
Riddle Hsu | 3a4bb61 | 2019-01-31 00:02:22 +0800 | [diff] [blame] | 1005 | void onParentChanged() { |
| 1006 | super.onParentChanged(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1007 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 1008 | if (getParent() != null || mDisplayContent == null) { |
| 1009 | return; |
| 1010 | } |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1011 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1012 | EventLog.writeEvent(EventLogTags.WM_STACK_REMOVED, mStackId); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1013 | |
| 1014 | if (mAnimationBackgroundSurface != null) { |
Robert Carr | 5ea304d | 2019-02-04 16:04:55 -0800 | [diff] [blame] | 1015 | mAnimationBackgroundSurface.remove(); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1016 | mAnimationBackgroundSurface = null; |
| 1017 | } |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1018 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 1019 | mDisplayContent = null; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1020 | mWmService.mWindowPlacerLocked.requestTraversal(); |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1023 | void resetAnimationBackgroundAnimator() { |
| 1024 | mAnimationBackgroundAnimator = null; |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 1025 | hideAnimationSurface(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1026 | } |
| 1027 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1028 | void setAnimationBackground(WindowStateAnimator winAnimator, int color) { |
Jorim Jaggi | 35d328a | 2018-08-14 17:00:20 +0200 | [diff] [blame] | 1029 | if (mAnimationBackgroundAnimator == null) { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1030 | mAnimationBackgroundAnimator = winAnimator; |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 1031 | showAnimationSurface(((color >> 24) & 0xff) / 255f); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1032 | } |
| 1033 | } |
| 1034 | |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1035 | // TODO: Should each user have there own stacks? |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 1036 | @Override |
Wale Ogunwale | 498e8c9 | 2015-02-13 09:42:46 -0800 | [diff] [blame] | 1037 | void switchUser() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 1038 | super.switchUser(); |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1039 | int top = mChildren.size(); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1040 | for (int taskNdx = 0; taskNdx < top; ++taskNdx) { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1041 | Task task = mChildren.get(taskNdx); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1042 | if (mWmService.isCurrentProfileLocked(task.mUserId) || task.showForAllUsers()) { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1043 | mChildren.remove(taskNdx); |
| 1044 | mChildren.add(task); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1045 | --top; |
| 1046 | } |
| 1047 | } |
| 1048 | } |
| 1049 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1050 | /** |
| 1051 | * Adjusts the stack bounds if the IME is visible. |
| 1052 | * |
| 1053 | * @param imeWin The IME window. |
lumark | 72aeda0 | 2018-12-18 21:34:04 +0800 | [diff] [blame] | 1054 | * @param keepLastAmount Use {@code true} to keep the last adjusted amount from |
| 1055 | * {@link DockedStackDividerController} for adjusting the stack bounds, |
| 1056 | * Use {@code false} to reset adjusted amount as 0. |
| 1057 | * @see #updateAdjustForIme(float, float, boolean) |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1058 | */ |
lumark | 72aeda0 | 2018-12-18 21:34:04 +0800 | [diff] [blame] | 1059 | void setAdjustedForIme(WindowState imeWin, boolean keepLastAmount) { |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1060 | mImeWin = imeWin; |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 1061 | mImeGoingAway = false; |
lumark | 72aeda0 | 2018-12-18 21:34:04 +0800 | [diff] [blame] | 1062 | if (!mAdjustedForIme || keepLastAmount) { |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 1063 | mAdjustedForIme = true; |
lumark | 72aeda0 | 2018-12-18 21:34:04 +0800 | [diff] [blame] | 1064 | DockedStackDividerController controller = getDisplayContent().mDividerControllerLocked; |
| 1065 | final float adjustImeAmount = keepLastAmount ? controller.mLastAnimationProgress : 0f; |
| 1066 | final float adjustDividerAmount = keepLastAmount ? controller.mLastDividerProgress : 0f; |
| 1067 | updateAdjustForIme(adjustImeAmount, adjustDividerAmount, true /* force */); |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 1068 | } |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | boolean isAdjustedForIme() { |
Chong Zhang | 5117e27 | 2016-05-03 12:47:34 -0700 | [diff] [blame] | 1072 | return mAdjustedForIme; |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 1073 | } |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 1074 | |
| 1075 | boolean isAnimatingForIme() { |
| 1076 | return mImeWin != null && mImeWin.isAnimatingLw(); |
| 1077 | } |
| 1078 | |
| 1079 | /** |
| 1080 | * Update the stack's bounds (crop or position) according to the IME window's |
| 1081 | * current position. When IME window is animated, the bottom stack is animated |
| 1082 | * together to track the IME window's current position, and the top stack is |
| 1083 | * cropped as necessary. |
| 1084 | * |
| 1085 | * @return true if a traversal should be performed after the adjustment. |
| 1086 | */ |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 1087 | boolean updateAdjustForIme(float adjustAmount, float adjustDividerAmount, boolean force) { |
| 1088 | if (adjustAmount != mAdjustImeAmount |
| 1089 | || adjustDividerAmount != mAdjustDividerAmount || force) { |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1090 | mAdjustImeAmount = adjustAmount; |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 1091 | mAdjustDividerAmount = adjustDividerAmount; |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1092 | updateAdjustedBounds(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1093 | return isVisible(); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1094 | } else { |
| 1095 | return false; |
Chong Zhang | b58bbcc | 2016-03-23 11:57:36 -0700 | [diff] [blame] | 1096 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | /** |
| 1100 | * Resets the adjustment after it got adjusted for the IME. |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 1101 | * @param adjustBoundsNow if true, reset and update the bounds immediately and forget about |
| 1102 | * animations; otherwise, set flag and animates the window away together |
| 1103 | * with IME window. |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1104 | */ |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 1105 | void resetAdjustedForIme(boolean adjustBoundsNow) { |
| 1106 | if (adjustBoundsNow) { |
| 1107 | mImeWin = null; |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 1108 | mImeGoingAway = false; |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1109 | mAdjustImeAmount = 0f; |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 1110 | mAdjustDividerAmount = 0f; |
Jorim Jaggi | f93ac2b | 2017-10-25 15:20:24 +0200 | [diff] [blame] | 1111 | if (!mAdjustedForIme) { |
| 1112 | return; |
| 1113 | } |
| 1114 | mAdjustedForIme = false; |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 1115 | updateAdjustedBounds(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1116 | mWmService.setResizeDimLayer(false, getWindowingMode(), 1.0f); |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 1117 | } else { |
| 1118 | mImeGoingAway |= mAdjustedForIme; |
Chong Zhang | b58bbcc | 2016-03-23 11:57:36 -0700 | [diff] [blame] | 1119 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | /** |
| 1123 | * Sets the amount how much we currently minimize our stack. |
| 1124 | * |
| 1125 | * @param minimizeAmount The amount, between 0 and 1. |
| 1126 | * @return Whether the amount has changed and a layout is needed. |
| 1127 | */ |
| 1128 | boolean setAdjustedForMinimizedDock(float minimizeAmount) { |
| 1129 | if (minimizeAmount != mMinimizeAmount) { |
| 1130 | mMinimizeAmount = minimizeAmount; |
| 1131 | updateAdjustedBounds(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1132 | return isVisible(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1133 | } else { |
| 1134 | return false; |
| 1135 | } |
| 1136 | } |
| 1137 | |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 1138 | boolean shouldIgnoreInput() { |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 1139 | return isAdjustedForMinimizedDockedStack() || |
| 1140 | (inSplitScreenPrimaryWindowingMode() && isMinimizedDockAndHomeStackResizable()); |
Jorim Jaggi | 409635b | 2016-04-01 15:32:28 -0700 | [diff] [blame] | 1141 | } |
| 1142 | |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 1143 | /** |
| 1144 | * Puts all visible tasks that are adjusted for IME into resizing mode and adds the windows |
| 1145 | * to the list of to be drawn windows the service is waiting for. |
| 1146 | */ |
| 1147 | void beginImeAdjustAnimation() { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1148 | for (int j = mChildren.size() - 1; j >= 0; j--) { |
| 1149 | final Task task = mChildren.get(j); |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 1150 | if (task.hasContentToDisplay()) { |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 1151 | task.setDragResizing(true, DRAG_RESIZE_MODE_DOCKED_DIVIDER); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1152 | task.setWaitingForDrawnIfResizingChanged(); |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 1153 | } |
| 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | /** |
| 1158 | * Resets the resizing state of all windows. |
| 1159 | */ |
| 1160 | void endImeAdjustAnimation() { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1161 | for (int j = mChildren.size() - 1; j >= 0; j--) { |
| 1162 | mChildren.get(j).setDragResizing(false, DRAG_RESIZE_MODE_DOCKED_DIVIDER); |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 1163 | } |
| 1164 | } |
| 1165 | |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 1166 | int getMinTopStackBottom(final Rect displayContentRect, int originalStackBottom) { |
| 1167 | return displayContentRect.top + (int) |
| 1168 | ((originalStackBottom - displayContentRect.top) * ADJUSTED_STACK_FRACTION_MIN); |
| 1169 | } |
| 1170 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1171 | private boolean adjustForIME(final WindowState imeWin) { |
lumark | bcc316e | 2018-12-25 21:37:05 +0800 | [diff] [blame] | 1172 | // To prevent task stack resize animation may flicking when playing app transition |
| 1173 | // animation & IME window enter animation in parallel, we need to make sure app |
| 1174 | // transition is done and then adjust task size for IME, skip the new adjusted frame when |
| 1175 | // app transition is still running. |
| 1176 | if (getDisplayContent().mAppTransition.isRunning()) { |
| 1177 | return false; |
| 1178 | } |
| 1179 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1180 | final int dockedSide = getDockSide(); |
| 1181 | final boolean dockedTopOrBottom = dockedSide == DOCKED_TOP || dockedSide == DOCKED_BOTTOM; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1182 | if (imeWin == null || !dockedTopOrBottom) { |
| 1183 | return false; |
| 1184 | } |
| 1185 | |
Wale Ogunwale | db50619 | 2017-12-08 10:57:32 -0800 | [diff] [blame] | 1186 | final Rect displayStableRect = mTmpRect; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1187 | final Rect contentBounds = mTmpRect2; |
| 1188 | |
| 1189 | // Calculate the content bounds excluding the area occupied by IME |
Wale Ogunwale | db50619 | 2017-12-08 10:57:32 -0800 | [diff] [blame] | 1190 | getDisplayContent().getStableRect(displayStableRect); |
| 1191 | contentBounds.set(displayStableRect); |
Jorim Jaggi | 5ac2ba2 | 2016-04-11 21:14:12 -0700 | [diff] [blame] | 1192 | int imeTop = Math.max(imeWin.getFrameLw().top, contentBounds.top); |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 1193 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1194 | imeTop += imeWin.getGivenContentInsetsLw().top; |
| 1195 | if (contentBounds.bottom > imeTop) { |
| 1196 | contentBounds.bottom = imeTop; |
| 1197 | } |
| 1198 | |
Wale Ogunwale | db50619 | 2017-12-08 10:57:32 -0800 | [diff] [blame] | 1199 | final int yOffset = displayStableRect.bottom - contentBounds.bottom; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1200 | |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 1201 | final int dividerWidth = |
| 1202 | getDisplayContent().mDividerControllerLocked.getContentWidth(); |
| 1203 | final int dividerWidthInactive = |
| 1204 | getDisplayContent().mDividerControllerLocked.getContentWidthInactive(); |
| 1205 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1206 | if (dockedSide == DOCKED_TOP) { |
| 1207 | // 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] | 1208 | // occluded by IME. We shift its bottom up by the height of the IME, but |
| 1209 | // leaves at least 30% of the top stack visible. |
| 1210 | final int minTopStackBottom = |
Wale Ogunwale | db50619 | 2017-12-08 10:57:32 -0800 | [diff] [blame] | 1211 | getMinTopStackBottom(displayStableRect, getRawBounds().bottom); |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 1212 | final int bottom = Math.max( |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1213 | getRawBounds().bottom - yOffset + dividerWidth - dividerWidthInactive, |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 1214 | minTopStackBottom); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1215 | mTmpAdjustedBounds.set(getRawBounds()); |
| 1216 | mTmpAdjustedBounds.bottom = (int) (mAdjustImeAmount * bottom + (1 - mAdjustImeAmount) |
| 1217 | * getRawBounds().bottom); |
| 1218 | mFullyAdjustedImeBounds.set(getRawBounds()); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1219 | } else { |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 1220 | // When the stack is on bottom and has no focus, it's only adjusted for divider width. |
| 1221 | final int dividerWidthDelta = dividerWidthInactive - dividerWidth; |
| 1222 | |
| 1223 | // When the stack is on bottom and has focus, it needs to be moved up so as to |
| 1224 | // not occluded by IME, and at the same time adjusted for divider width. |
| 1225 | // We try to move it up by the height of the IME window, but only to the extent |
| 1226 | // that leaves at least 30% of the top stack visible. |
| 1227 | // 'top' is where the top of bottom stack will move to in this case. |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1228 | final int topBeforeImeAdjust = |
| 1229 | getRawBounds().top - dividerWidth + dividerWidthInactive; |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 1230 | final int minTopStackBottom = |
Wale Ogunwale | db50619 | 2017-12-08 10:57:32 -0800 | [diff] [blame] | 1231 | getMinTopStackBottom(displayStableRect, |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1232 | getRawBounds().top - dividerWidth); |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 1233 | final int top = Math.max( |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1234 | getRawBounds().top - yOffset, minTopStackBottom + dividerWidthInactive); |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 1235 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1236 | mTmpAdjustedBounds.set(getRawBounds()); |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 1237 | // Account for the adjustment for IME and divider width separately. |
| 1238 | // (top - topBeforeImeAdjust) is the amount of movement due to IME only, |
| 1239 | // and dividerWidthDelta is due to divider width change only. |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1240 | mTmpAdjustedBounds.top = getRawBounds().top + |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 1241 | (int) (mAdjustImeAmount * (top - topBeforeImeAdjust) + |
| 1242 | mAdjustDividerAmount * dividerWidthDelta); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1243 | mFullyAdjustedImeBounds.set(getRawBounds()); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1244 | mFullyAdjustedImeBounds.top = top; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1245 | mFullyAdjustedImeBounds.bottom = top + getRawBounds().height(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1246 | } |
| 1247 | return true; |
| 1248 | } |
| 1249 | |
| 1250 | private boolean adjustForMinimizedDockedStack(float minimizeAmount) { |
| 1251 | final int dockSide = getDockSide(); |
| 1252 | if (dockSide == DOCKED_INVALID && !mTmpAdjustedBounds.isEmpty()) { |
| 1253 | return false; |
| 1254 | } |
| 1255 | |
| 1256 | if (dockSide == DOCKED_TOP) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1257 | mWmService.getStableInsetsLocked(DEFAULT_DISPLAY, mTmpRect); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1258 | int topInset = mTmpRect.top; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1259 | mTmpAdjustedBounds.set(getRawBounds()); |
| 1260 | mTmpAdjustedBounds.bottom = (int) (minimizeAmount * topInset + (1 - minimizeAmount) |
| 1261 | * getRawBounds().bottom); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1262 | } else if (dockSide == DOCKED_LEFT) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1263 | mTmpAdjustedBounds.set(getRawBounds()); |
| 1264 | final int width = getRawBounds().width(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1265 | mTmpAdjustedBounds.right = |
| 1266 | (int) (minimizeAmount * mDockedStackMinimizeThickness |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1267 | + (1 - minimizeAmount) * getRawBounds().right); |
Jorim Jaggi | bcff143 | 2016-04-01 15:49:45 -0700 | [diff] [blame] | 1268 | mTmpAdjustedBounds.left = mTmpAdjustedBounds.right - width; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1269 | } else if (dockSide == DOCKED_RIGHT) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1270 | mTmpAdjustedBounds.set(getRawBounds()); |
| 1271 | mTmpAdjustedBounds.left = (int) (minimizeAmount * |
| 1272 | (getRawBounds().right - mDockedStackMinimizeThickness) |
| 1273 | + (1 - minimizeAmount) * getRawBounds().left); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1274 | } |
| 1275 | return true; |
| 1276 | } |
| 1277 | |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 1278 | private boolean isMinimizedDockAndHomeStackResizable() { |
| 1279 | return mDisplayContent.mDividerControllerLocked.isMinimizedDock() |
| 1280 | && mDisplayContent.mDividerControllerLocked.isHomeStackResizable(); |
| 1281 | } |
| 1282 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1283 | /** |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 1284 | * @return the distance in pixels how much the stack gets minimized from it's original size |
| 1285 | */ |
| 1286 | int getMinimizeDistance() { |
| 1287 | final int dockSide = getDockSide(); |
| 1288 | if (dockSide == DOCKED_INVALID) { |
| 1289 | return 0; |
| 1290 | } |
| 1291 | |
| 1292 | if (dockSide == DOCKED_TOP) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1293 | mWmService.getStableInsetsLocked(DEFAULT_DISPLAY, mTmpRect); |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 1294 | int topInset = mTmpRect.top; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1295 | return getRawBounds().bottom - topInset; |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 1296 | } else if (dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1297 | return getRawBounds().width() - mDockedStackMinimizeThickness; |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 1298 | } else { |
| 1299 | return 0; |
| 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | /** |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1304 | * Updates the adjustment depending on it's current state. |
| 1305 | */ |
Chong Zhang | 5117e27 | 2016-05-03 12:47:34 -0700 | [diff] [blame] | 1306 | private void updateAdjustedBounds() { |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1307 | boolean adjust = false; |
| 1308 | if (mMinimizeAmount != 0f) { |
| 1309 | adjust = adjustForMinimizedDockedStack(mMinimizeAmount); |
| 1310 | } else if (mAdjustedForIme) { |
| 1311 | adjust = adjustForIME(mImeWin); |
| 1312 | } |
| 1313 | if (!adjust) { |
| 1314 | mTmpAdjustedBounds.setEmpty(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1315 | } |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1316 | setAdjustedBounds(mTmpAdjustedBounds); |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 1317 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1318 | final boolean isImeTarget = (mWmService.getImeFocusStackLocked() == this); |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 1319 | if (mAdjustedForIme && adjust && !isImeTarget) { |
| 1320 | final float alpha = Math.max(mAdjustImeAmount, mAdjustDividerAmount) |
| 1321 | * IME_ADJUST_DIM_AMOUNT; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1322 | mWmService.setResizeDimLayer(true, getWindowingMode(), alpha); |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 1323 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1324 | } |
| 1325 | |
Chong Zhang | 5117e27 | 2016-05-03 12:47:34 -0700 | [diff] [blame] | 1326 | void applyAdjustForImeIfNeeded(Task task) { |
| 1327 | if (mMinimizeAmount != 0f || !mAdjustedForIme || mAdjustedBounds.isEmpty()) { |
| 1328 | return; |
| 1329 | } |
| 1330 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1331 | final Rect insetBounds = mImeGoingAway ? getRawBounds() : mFullyAdjustedImeBounds; |
Chong Zhang | 5117e27 | 2016-05-03 12:47:34 -0700 | [diff] [blame] | 1332 | task.alignToAdjustedBounds(mAdjustedBounds, insetBounds, getDockSide() == DOCKED_TOP); |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1333 | mDisplayContent.setLayoutNeeded(); |
Chong Zhang | 5117e27 | 2016-05-03 12:47:34 -0700 | [diff] [blame] | 1334 | } |
| 1335 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1336 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1337 | boolean isAdjustedForMinimizedDockedStack() { |
| 1338 | return mMinimizeAmount != 0f; |
| 1339 | } |
| 1340 | |
Winson Chung | d41f71d | 2018-03-16 15:26:07 -0700 | [diff] [blame] | 1341 | /** |
| 1342 | * @return {@code true} if we have a {@link Task} that is animating (currently only used for the |
| 1343 | * recents animation); {@code false} otherwise. |
| 1344 | */ |
| 1345 | boolean isTaskAnimating() { |
| 1346 | for (int j = mChildren.size() - 1; j >= 0; j--) { |
| 1347 | final Task task = mChildren.get(j); |
| 1348 | if (task.isTaskAnimating()) { |
| 1349 | return true; |
| 1350 | } |
| 1351 | } |
| 1352 | return false; |
| 1353 | } |
| 1354 | |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 1355 | @CallSuper |
| 1356 | @Override |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 1357 | public void writeToProto(ProtoOutputStream proto, long fieldId, |
| 1358 | @WindowTraceLogLevel int logLevel) { |
| 1359 | if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible()) { |
| 1360 | return; |
| 1361 | } |
| 1362 | |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 1363 | final long token = proto.start(fieldId); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 1364 | super.writeToProto(proto, WINDOW_CONTAINER, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 1365 | proto.write(ID, mStackId); |
| 1366 | for (int taskNdx = mChildren.size() - 1; taskNdx >= 0; taskNdx--) { |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 1367 | mChildren.get(taskNdx).writeToProto(proto, TASKS, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 1368 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1369 | proto.write(FILLS_PARENT, matchParentBounds()); |
| 1370 | getRawBounds().writeToProto(proto, BOUNDS); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 1371 | proto.write(ANIMATION_BACKGROUND_SURFACE_IS_DIMMING, mAnimationBackgroundSurfaceIsShown); |
Vishnu Nair | 04ab439 | 2018-01-10 11:00:06 -0800 | [diff] [blame] | 1372 | proto.write(DEFER_REMOVAL, mDeferRemoval); |
| 1373 | proto.write(MINIMIZE_AMOUNT, mMinimizeAmount); |
| 1374 | proto.write(ADJUSTED_FOR_IME, mAdjustedForIme); |
| 1375 | proto.write(ADJUST_IME_AMOUNT, mAdjustImeAmount); |
| 1376 | proto.write(ADJUST_DIVIDER_AMOUNT, mAdjustDividerAmount); |
| 1377 | mAdjustedBounds.writeToProto(proto, ADJUSTED_BOUNDS); |
Winson Chung | 82267ce | 2018-04-06 16:38:26 -0700 | [diff] [blame] | 1378 | proto.write(ANIMATING_BOUNDS, mBoundsAnimating); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 1379 | proto.end(token); |
| 1380 | } |
| 1381 | |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 1382 | @Override |
| 1383 | void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 1384 | pw.println(prefix + "mStackId=" + mStackId); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1385 | pw.println(prefix + "mDeferRemoval=" + mDeferRemoval); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1386 | pw.println(prefix + "mBounds=" + getRawBounds().toShortString()); |
Jorim Jaggi | af558e1 | 2016-04-27 22:56:56 -0700 | [diff] [blame] | 1387 | if (mMinimizeAmount != 0f) { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1388 | pw.println(prefix + "mMinimizeAmount=" + mMinimizeAmount); |
Jorim Jaggi | af558e1 | 2016-04-27 22:56:56 -0700 | [diff] [blame] | 1389 | } |
| 1390 | if (mAdjustedForIme) { |
| 1391 | pw.println(prefix + "mAdjustedForIme=true"); |
| 1392 | pw.println(prefix + "mAdjustImeAmount=" + mAdjustImeAmount); |
| 1393 | pw.println(prefix + "mAdjustDividerAmount=" + mAdjustDividerAmount); |
| 1394 | } |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1395 | if (!mAdjustedBounds.isEmpty()) { |
| 1396 | pw.println(prefix + "mAdjustedBounds=" + mAdjustedBounds.toShortString()); |
| 1397 | } |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1398 | for (int taskNdx = mChildren.size() - 1; taskNdx >= 0; taskNdx--) { |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 1399 | mChildren.get(taskNdx).dump(pw, prefix + " ", dumpAll); |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 1400 | } |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 1401 | if (mAnimationBackgroundSurfaceIsShown) { |
| 1402 | pw.println(prefix + "mWindowAnimationBackgroundSurface is shown"); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1403 | } |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 1404 | if (!mExitingAppTokens.isEmpty()) { |
| 1405 | pw.println(); |
| 1406 | pw.println(" Exiting application tokens:"); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1407 | for (int i = mExitingAppTokens.size() - 1; i >= 0; i--) { |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 1408 | WindowToken token = mExitingAppTokens.get(i); |
| 1409 | pw.print(" Exiting App #"); pw.print(i); |
| 1410 | pw.print(' '); pw.print(token); |
| 1411 | pw.println(':'); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 1412 | token.dump(pw, " ", dumpAll); |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 1413 | } |
| 1414 | } |
Jorim Jaggi | b8a9cbe | 2018-03-27 18:02:18 +0200 | [diff] [blame] | 1415 | mAnimatingAppWindowTokenRegistry.dump(pw, "AnimatingApps:", prefix); |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 1416 | } |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 1417 | |
| 1418 | @Override |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1419 | boolean fillsParent() { |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 1420 | return matchParentBounds(); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | @Override |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 1424 | public String toString() { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1425 | return "{stackId=" + mStackId + " tasks=" + mChildren + "}"; |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 1426 | } |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 1427 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1428 | String getName() { |
| 1429 | return toShortString(); |
| 1430 | } |
| 1431 | |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 1432 | public String toShortString() { |
| 1433 | return "Stack=" + mStackId; |
| 1434 | } |
| 1435 | |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 1436 | /** |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 1437 | * For docked workspace (or workspace that's side-by-side to the docked), provides |
| 1438 | * information which side of the screen was the dock anchored. |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 1439 | */ |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 1440 | int getDockSide() { |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 1441 | return getDockSide(mDisplayContent.getConfiguration(), getRawBounds()); |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 1442 | } |
| 1443 | |
Matthew Ng | e8b052a | 2018-01-16 14:33:47 -0800 | [diff] [blame] | 1444 | int getDockSideForDisplay(DisplayContent dc) { |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 1445 | return getDockSide(dc, dc.getConfiguration(), getRawBounds()); |
Matthew Ng | e8b052a | 2018-01-16 14:33:47 -0800 | [diff] [blame] | 1446 | } |
| 1447 | |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 1448 | int getDockSide(Configuration parentConfig, Rect bounds) { |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 1449 | if (mDisplayContent == null) { |
| 1450 | return DOCKED_INVALID; |
| 1451 | } |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 1452 | return getDockSide(mDisplayContent, parentConfig, bounds); |
Matthew Ng | e8b052a | 2018-01-16 14:33:47 -0800 | [diff] [blame] | 1453 | } |
| 1454 | |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 1455 | private int getDockSide(DisplayContent dc, Configuration parentConfig, Rect bounds) { |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 1456 | return dc.getDockedDividerController().getDockSide(bounds, |
| 1457 | parentConfig.windowConfiguration.getBounds(), |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 1458 | parentConfig.orientation, parentConfig.windowConfiguration.getRotation()); |
Filip Gruszczynski | 923f826 | 2015-09-17 17:41:13 -0700 | [diff] [blame] | 1459 | } |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 1460 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1461 | boolean hasTaskForUser(int userId) { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1462 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 1463 | final Task task = mChildren.get(i); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1464 | if (task.mUserId == userId) { |
| 1465 | return true; |
| 1466 | } |
| 1467 | } |
| 1468 | return false; |
| 1469 | } |
| 1470 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1471 | void findTaskForResizePoint(int x, int y, int delta, |
| 1472 | DisplayContent.TaskForResizePointSearchResult results) { |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 1473 | if (!getWindowConfiguration().canResizeTask()) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1474 | results.searchDone = true; |
| 1475 | return; |
| 1476 | } |
| 1477 | |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1478 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1479 | final Task task = mChildren.get(i); |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 1480 | if (task.getWindowingMode() == WINDOWING_MODE_FULLSCREEN) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1481 | results.searchDone = true; |
| 1482 | return; |
| 1483 | } |
| 1484 | |
| 1485 | // We need to use the task's dim bounds (which is derived from the visible bounds of |
| 1486 | // its apps windows) for any touch-related tests. Can't use the task's original |
| 1487 | // bounds because it might be adjusted to fit the content frame. One example is when |
| 1488 | // the task is put to top-left quadrant, the actual visible area would not start at |
| 1489 | // (0,0) after it's adjusted for the status bar. |
| 1490 | task.getDimBounds(mTmpRect); |
| 1491 | mTmpRect.inset(-delta, -delta); |
| 1492 | if (mTmpRect.contains(x, y)) { |
| 1493 | mTmpRect.inset(delta, delta); |
| 1494 | |
| 1495 | results.searchDone = true; |
| 1496 | |
| 1497 | if (!mTmpRect.contains(x, y)) { |
| 1498 | results.taskForResize = task; |
| 1499 | return; |
| 1500 | } |
| 1501 | // User touched inside the task. No need to look further, |
| 1502 | // focus transfer will be handled in ACTION_UP. |
| 1503 | return; |
| 1504 | } |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | void setTouchExcludeRegion(Task focusedTask, int delta, Region touchExcludeRegion, |
| 1509 | Rect contentRect, Rect postExclude) { |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1510 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1511 | final Task task = mChildren.get(i); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1512 | AppWindowToken token = task.getTopVisibleAppToken(); |
| 1513 | if (token == null || !token.hasContentToDisplay()) { |
| 1514 | continue; |
| 1515 | } |
| 1516 | |
| 1517 | /** |
| 1518 | * Exclusion region is the region that TapDetector doesn't care about. |
| 1519 | * Here we want to remove all non-focused tasks from the exclusion region. |
| 1520 | * We also remove the outside touch area for resizing for all freeform |
| 1521 | * tasks (including the focused). |
| 1522 | * |
| 1523 | * We save the focused task region once we find it, and add it back at the end. |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 1524 | * |
| 1525 | * If the task is home stack and it is resizable in the minimized state, we want to |
| 1526 | * exclude the docked stack from touch so we need the entire screen area and not just a |
| 1527 | * small portion which the home stack currently is resized to. |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1528 | */ |
| 1529 | |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1530 | if (task.isActivityTypeHome() && isMinimizedDockAndHomeStackResizable()) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1531 | mDisplayContent.getBounds(mTmpRect); |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 1532 | } else { |
| 1533 | task.getDimBounds(mTmpRect); |
| 1534 | } |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1535 | |
| 1536 | if (task == focusedTask) { |
| 1537 | // Add the focused task rect back into the exclude region once we are done |
| 1538 | // processing stacks. |
| 1539 | postExclude.set(mTmpRect); |
| 1540 | } |
| 1541 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 1542 | final boolean isFreeformed = task.inFreeformWindowingMode(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1543 | if (task != focusedTask || isFreeformed) { |
| 1544 | if (isFreeformed) { |
| 1545 | // If the task is freeformed, enlarge the area to account for outside |
| 1546 | // touch area for resize. |
| 1547 | mTmpRect.inset(-delta, -delta); |
| 1548 | // Intersect with display content rect. If we have system decor (status bar/ |
| 1549 | // navigation bar), we want to exclude that from the tap detection. |
| 1550 | // Otherwise, if the app is partially placed under some system button (eg. |
| 1551 | // Recents, Home), pressing that button would cause a full series of |
| 1552 | // unwanted transfer focus/resume/pause, before we could go home. |
| 1553 | mTmpRect.intersect(contentRect); |
| 1554 | } |
| 1555 | touchExcludeRegion.op(mTmpRect, Region.Op.DIFFERENCE); |
| 1556 | } |
| 1557 | } |
| 1558 | } |
| 1559 | |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1560 | public boolean setPinnedStackSize(Rect stackBounds, Rect tempTaskBounds) { |
| 1561 | // Hold the lock since this is called from the BoundsAnimator running on the UiThread |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1562 | synchronized (mWmService.mGlobalLock) { |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1563 | if (mCancelCurrentBoundsAnimation) { |
| 1564 | return false; |
| 1565 | } |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 1566 | } |
| 1567 | |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1568 | try { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1569 | mWmService.mActivityTaskManager.resizePinnedStack(stackBounds, tempTaskBounds); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1570 | } catch (RemoteException e) { |
| 1571 | // I don't believe you. |
| 1572 | } |
| 1573 | return true; |
| 1574 | } |
| 1575 | |
Robert Carr | ecc06b3 | 2017-04-18 14:25:10 -0700 | [diff] [blame] | 1576 | void onAllWindowsDrawn() { |
Winson Chung | e7ba686 | 2017-05-24 12:13:33 -0700 | [diff] [blame] | 1577 | if (!mBoundsAnimating && !mBoundsAnimatingRequested) { |
Robert Carr | ecc06b3 | 2017-04-18 14:25:10 -0700 | [diff] [blame] | 1578 | return; |
| 1579 | } |
| 1580 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1581 | getDisplayContent().mBoundsAnimationController.onAllWindowsDrawn(); |
Robert Carr | ecc06b3 | 2017-04-18 14:25:10 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 1584 | @Override // AnimatesBounds |
Tracy Zhou | 9c675d4 | 2019-04-08 00:32:40 -0700 | [diff] [blame] | 1585 | public boolean onAnimationStart(boolean schedulePipModeChangedCallback, boolean forceUpdate, |
| 1586 | @BoundsAnimationController.AnimationType int animationType) { |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1587 | // Hold the lock since this is called from the BoundsAnimator running on the UiThread |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1588 | synchronized (mWmService.mGlobalLock) { |
Winson Chung | a06403d | 2018-06-28 12:56:53 -0700 | [diff] [blame] | 1589 | if (!isAttached()) { |
| 1590 | // Don't run the animation if the stack is already detached |
| 1591 | return false; |
| 1592 | } |
| 1593 | |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 1594 | mBoundsAnimatingRequested = false; |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 1595 | mBoundsAnimating = true; |
Tracy Zhou | 9c675d4 | 2019-04-08 00:32:40 -0700 | [diff] [blame] | 1596 | mAnimationType = animationType; |
Robert Carr | ecc06b3 | 2017-04-18 14:25:10 -0700 | [diff] [blame] | 1597 | |
| 1598 | // If we are changing UI mode, as in the PiP to fullscreen |
| 1599 | // transition, then we need to wait for the window to draw. |
| 1600 | if (schedulePipModeChangedCallback) { |
| 1601 | forAllWindows((w) -> { w.mWinAnimator.resetDrawState(); }, |
| 1602 | false /* traverseTopToBottom */); |
| 1603 | } |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 1604 | } |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 1605 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 1606 | if (inPinnedWindowingMode()) { |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 1607 | try { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1608 | mWmService.mActivityTaskManager.notifyPinnedStackAnimationStarted(); |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 1609 | } catch (RemoteException e) { |
| 1610 | // I don't believe you... |
| 1611 | } |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1612 | |
Tracy Zhou | 9c675d4 | 2019-04-08 00:32:40 -0700 | [diff] [blame] | 1613 | if ((schedulePipModeChangedCallback || animationType == FADE_IN) |
| 1614 | && mActivityStack != null) { |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 1615 | // We need to schedule the PiP mode change before the animation up. It is possible |
| 1616 | // in this case for the animation down to not have been completed, so always |
| 1617 | // force-schedule and update to the client to ensure that it is notified that it |
| 1618 | // is no longer in picture-in-picture mode |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 1619 | mActivityStack.updatePictureInPictureModeForPinnedStackAnimation(null, |
| 1620 | forceUpdate); |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1621 | } |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 1622 | } |
Winson Chung | a06403d | 2018-06-28 12:56:53 -0700 | [diff] [blame] | 1623 | return true; |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 1624 | } |
| 1625 | |
| 1626 | @Override // AnimatesBounds |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1627 | public void onAnimationEnd(boolean schedulePipModeChangedCallback, Rect finalStackSize, |
| 1628 | boolean moveToFullscreen) { |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 1629 | if (inPinnedWindowingMode()) { |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 1630 | // Update to the final bounds if requested. This is done here instead of in the bounds |
| 1631 | // animator to allow us to coordinate this after we notify the PiP mode changed |
| 1632 | |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 1633 | if (schedulePipModeChangedCallback) { |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1634 | // We need to schedule the PiP mode change after the animation down, so use the |
| 1635 | // final bounds |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 1636 | mActivityStack.updatePictureInPictureModeForPinnedStackAnimation( |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 1637 | mBoundsAnimationTarget, false /* forceUpdate */); |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1638 | } |
| 1639 | |
Tracy Zhou | c1f792d | 2019-05-07 16:32:02 -0700 | [diff] [blame] | 1640 | if (mAnimationType == BoundsAnimationController.FADE_IN) { |
| 1641 | setPinnedStackAlpha(1f); |
| 1642 | mActivityStack.mService.notifyPinnedStackAnimationEnded(); |
Tracy Zhou | 316b1f5 | 2019-06-04 16:05:19 -0700 | [diff] [blame] | 1643 | return; |
Tracy Zhou | c1f792d | 2019-05-07 16:32:02 -0700 | [diff] [blame] | 1644 | } |
| 1645 | |
wilsonshih | 4dd0712 | 2019-04-03 15:55:02 +0800 | [diff] [blame] | 1646 | if (finalStackSize != null && !mCancelCurrentBoundsAnimation) { |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1647 | setPinnedStackSize(finalStackSize, null); |
Winson Chung | e40082ea | 2018-06-05 16:03:12 -0700 | [diff] [blame] | 1648 | } else { |
| 1649 | // We have been canceled, so the final stack size is null, still run the |
| 1650 | // animation-end logic |
| 1651 | onPipAnimationEndResize(); |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1652 | } |
| 1653 | |
Tracy Zhou | c1f792d | 2019-05-07 16:32:02 -0700 | [diff] [blame] | 1654 | mActivityStack.mService.notifyPinnedStackAnimationEnded(); |
| 1655 | if (moveToFullscreen) { |
| 1656 | mActivityStack.mService.moveTasksToFullscreenStack(mStackId, true /* onTop */); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 1657 | } |
Winson Chung | e40082ea | 2018-06-05 16:03:12 -0700 | [diff] [blame] | 1658 | } else { |
| 1659 | // No PiP animation, just run the normal animation-end logic |
| 1660 | onPipAnimationEndResize(); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 1661 | } |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 1662 | } |
Filip Gruszczynski | c17d8b7 | 2016-02-03 16:52:59 -0800 | [diff] [blame] | 1663 | |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 1664 | /** |
| 1665 | * @return the current stack bounds transformed to the given {@param aspectRatio}. If |
| 1666 | * the default bounds is {@code null}, then the {@param aspectRatio} is applied to the |
| 1667 | * default bounds. |
| 1668 | */ |
| 1669 | Rect getPictureInPictureBounds(float aspectRatio, Rect stackBounds) { |
| 1670 | if (!mWmService.mSupportsPictureInPicture) { |
| 1671 | return null; |
| 1672 | } |
| 1673 | |
| 1674 | final DisplayContent displayContent = getDisplayContent(); |
| 1675 | if (displayContent == null) { |
| 1676 | return null; |
| 1677 | } |
| 1678 | |
| 1679 | if (!inPinnedWindowingMode()) { |
| 1680 | return null; |
| 1681 | } |
| 1682 | |
| 1683 | final PinnedStackController pinnedStackController = |
| 1684 | displayContent.getPinnedStackController(); |
| 1685 | if (stackBounds == null) { |
| 1686 | // Calculate the aspect ratio bounds from the default bounds |
| 1687 | stackBounds = pinnedStackController.getDefaultOrLastSavedBounds(); |
| 1688 | } |
| 1689 | |
| 1690 | if (pinnedStackController.isValidPictureInPictureAspectRatio(aspectRatio)) { |
| 1691 | return pinnedStackController.transformBoundsToAspectRatio(stackBounds, aspectRatio, |
| 1692 | true /* useCurrentMinEdgeSize */); |
| 1693 | } else { |
| 1694 | return stackBounds; |
| 1695 | } |
| 1696 | } |
| 1697 | |
| 1698 | /** |
| 1699 | * Animates the pinned stack. |
| 1700 | */ |
| 1701 | void animateResizePinnedStack(Rect toBounds, Rect sourceHintBounds, |
| 1702 | int animationDuration, boolean fromFullscreen) { |
| 1703 | if (!inPinnedWindowingMode()) { |
| 1704 | return; |
| 1705 | } |
| 1706 | // Get the from-bounds |
| 1707 | final Rect fromBounds = new Rect(); |
| 1708 | getBounds(fromBounds); |
| 1709 | |
| 1710 | // Get non-null fullscreen to-bounds for animating if the bounds are null |
| 1711 | @SchedulePipModeChangedState int schedulePipModeChangedState = |
| 1712 | NO_PIP_MODE_CHANGED_CALLBACKS; |
| 1713 | final boolean toFullscreen = toBounds == null; |
| 1714 | if (toFullscreen) { |
| 1715 | if (fromFullscreen) { |
| 1716 | throw new IllegalArgumentException("Should not defer scheduling PiP mode" |
| 1717 | + " change on animation to fullscreen."); |
| 1718 | } |
| 1719 | schedulePipModeChangedState = SCHEDULE_PIP_MODE_CHANGED_ON_START; |
| 1720 | |
| 1721 | mWmService.getStackBounds( |
| 1722 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, mTmpToBounds); |
| 1723 | if (!mTmpToBounds.isEmpty()) { |
| 1724 | // If there is a fullscreen bounds, use that |
| 1725 | toBounds = new Rect(mTmpToBounds); |
| 1726 | } else { |
| 1727 | // Otherwise, use the display bounds |
| 1728 | toBounds = new Rect(); |
| 1729 | getDisplayContent().getBounds(toBounds); |
| 1730 | } |
| 1731 | } else if (fromFullscreen) { |
| 1732 | schedulePipModeChangedState = SCHEDULE_PIP_MODE_CHANGED_ON_END; |
| 1733 | } |
| 1734 | |
| 1735 | setAnimationFinalBounds(sourceHintBounds, toBounds, toFullscreen); |
| 1736 | |
| 1737 | final Rect finalToBounds = toBounds; |
| 1738 | final @SchedulePipModeChangedState int finalSchedulePipModeChangedState = |
| 1739 | schedulePipModeChangedState; |
| 1740 | final DisplayContent displayContent = getDisplayContent(); |
Tracy Zhou | 9c675d4 | 2019-04-08 00:32:40 -0700 | [diff] [blame] | 1741 | @BoundsAnimationController.AnimationType int intendedAnimationType = |
| 1742 | displayContent.mBoundsAnimationController.getAnimationType(); |
| 1743 | if (intendedAnimationType == FADE_IN) { |
| 1744 | if (fromFullscreen) { |
| 1745 | setPinnedStackAlpha(0f); |
| 1746 | } |
| 1747 | if (toBounds.width() == fromBounds.width() |
| 1748 | && toBounds.height() == fromBounds.height()) { |
| 1749 | intendedAnimationType = BoundsAnimationController.BOUNDS; |
| 1750 | } |
| 1751 | } |
| 1752 | |
| 1753 | final @BoundsAnimationController.AnimationType int animationType = intendedAnimationType; |
wilsonshih | 4dd0712 | 2019-04-03 15:55:02 +0800 | [diff] [blame] | 1754 | mCancelCurrentBoundsAnimation = false; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 1755 | displayContent.mBoundsAnimationController.getHandler().post(() -> { |
| 1756 | displayContent.mBoundsAnimationController.animateBounds(this, fromBounds, |
| 1757 | finalToBounds, animationDuration, finalSchedulePipModeChangedState, |
Tracy Zhou | 9c675d4 | 2019-04-08 00:32:40 -0700 | [diff] [blame] | 1758 | fromFullscreen, toFullscreen, animationType); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 1759 | }); |
| 1760 | } |
| 1761 | |
| 1762 | /** |
| 1763 | * Sets the current picture-in-picture aspect ratio. |
| 1764 | */ |
| 1765 | void setPictureInPictureAspectRatio(float aspectRatio) { |
| 1766 | if (!mWmService.mSupportsPictureInPicture) { |
| 1767 | return; |
| 1768 | } |
| 1769 | |
| 1770 | if (!inPinnedWindowingMode()) { |
| 1771 | return; |
| 1772 | } |
| 1773 | |
| 1774 | final PinnedStackController pinnedStackController = |
| 1775 | getDisplayContent().getPinnedStackController(); |
| 1776 | |
| 1777 | if (Float.compare(aspectRatio, pinnedStackController.getAspectRatio()) == 0) { |
| 1778 | return; |
| 1779 | } |
| 1780 | getAnimationOrCurrentBounds(mTmpFromBounds); |
| 1781 | mTmpToBounds.set(mTmpFromBounds); |
| 1782 | getPictureInPictureBounds(aspectRatio, mTmpToBounds); |
| 1783 | if (!mTmpToBounds.equals(mTmpFromBounds)) { |
| 1784 | animateResizePinnedStack(mTmpToBounds, null /* sourceHintBounds */, |
| 1785 | -1 /* duration */, false /* fromFullscreen */); |
| 1786 | } |
| 1787 | pinnedStackController.setAspectRatio( |
| 1788 | pinnedStackController.isValidPictureInPictureAspectRatio(aspectRatio) |
| 1789 | ? aspectRatio : -1f); |
| 1790 | } |
| 1791 | |
| 1792 | /** |
| 1793 | * Sets the current picture-in-picture actions. |
| 1794 | */ |
| 1795 | void setPictureInPictureActions(List<RemoteAction> actions) { |
| 1796 | if (!mWmService.mSupportsPictureInPicture) { |
| 1797 | return; |
| 1798 | } |
| 1799 | |
| 1800 | if (!inPinnedWindowingMode()) { |
| 1801 | return; |
| 1802 | } |
| 1803 | |
| 1804 | getDisplayContent().getPinnedStackController().setActions(actions); |
| 1805 | } |
| 1806 | |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 1807 | @Override |
| 1808 | public boolean isAttached() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1809 | synchronized (mWmService.mGlobalLock) { |
Winson Chung | a06403d | 2018-06-28 12:56:53 -0700 | [diff] [blame] | 1810 | return mDisplayContent != null; |
| 1811 | } |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
Winson Chung | 15036ca | 2018-05-31 15:51:47 -0700 | [diff] [blame] | 1814 | /** |
| 1815 | * Called immediately prior to resizing the tasks at the end of the pinned stack animation. |
| 1816 | */ |
| 1817 | public void onPipAnimationEndResize() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1818 | synchronized (mWmService.mGlobalLock) { |
Winson Chung | a06403d | 2018-06-28 12:56:53 -0700 | [diff] [blame] | 1819 | mBoundsAnimating = false; |
| 1820 | for (int i = 0; i < mChildren.size(); i++) { |
| 1821 | final Task t = mChildren.get(i); |
| 1822 | t.clearPreserveNonFloatingState(); |
| 1823 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1824 | mWmService.requestTraversal(); |
Winson Chung | 15036ca | 2018-05-31 15:51:47 -0700 | [diff] [blame] | 1825 | } |
Winson Chung | 15036ca | 2018-05-31 15:51:47 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame] | 1828 | @Override |
| 1829 | public boolean shouldDeferStartOnMoveToFullscreen() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1830 | synchronized (mWmService.mGlobalLock) { |
Riddle Hsu | e8b10e3 | 2018-11-09 19:35:26 +0800 | [diff] [blame] | 1831 | if (!isAttached()) { |
| 1832 | // Unnecessary to pause the animation because the stack is detached. |
| 1833 | return false; |
| 1834 | } |
| 1835 | |
Winson Chung | a06403d | 2018-06-28 12:56:53 -0700 | [diff] [blame] | 1836 | // Workaround for the recents animation -- normally we need to wait for the new activity |
| 1837 | // to show before starting the PiP animation, but because we start and show the home |
| 1838 | // activity early for the recents animation prior to the PiP animation starting, there |
| 1839 | // is no subsequent all-drawn signal. In this case, we can skip the pause when the home |
| 1840 | // stack is already visible and drawn. |
| 1841 | final TaskStack homeStack = mDisplayContent.getHomeStack(); |
| 1842 | if (homeStack == null) { |
| 1843 | return true; |
| 1844 | } |
| 1845 | final Task homeTask = homeStack.getTopChild(); |
| 1846 | if (homeTask == null) { |
| 1847 | return true; |
| 1848 | } |
| 1849 | final AppWindowToken homeApp = homeTask.getTopVisibleAppToken(); |
| 1850 | if (!homeTask.isVisible() || homeApp == null) { |
| 1851 | return true; |
| 1852 | } |
| 1853 | return !homeApp.allDrawn; |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame] | 1854 | } |
Winson Chung | 6a38fca | 2018-03-28 17:57:09 -0700 | [diff] [blame] | 1855 | } |
| 1856 | |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1857 | /** |
| 1858 | * @return True if we are currently animating the pinned stack from fullscreen to non-fullscreen |
| 1859 | * bounds and we have a deferred PiP mode changed callback set with the animation. |
| 1860 | */ |
| 1861 | public boolean deferScheduleMultiWindowModeChanged() { |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 1862 | if (inPinnedWindowingMode()) { |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1863 | return (mBoundsAnimatingRequested || mBoundsAnimating); |
Filip Gruszczynski | c17d8b7 | 2016-02-03 16:52:59 -0800 | [diff] [blame] | 1864 | } |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1865 | return false; |
Filip Gruszczynski | c17d8b7 | 2016-02-03 16:52:59 -0800 | [diff] [blame] | 1866 | } |
| 1867 | |
Robert Carr | 8f0a3ad | 2017-02-15 19:30:28 -0800 | [diff] [blame] | 1868 | public boolean isForceScaled() { |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 1869 | return mBoundsAnimating; |
| 1870 | } |
| 1871 | |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 1872 | public boolean isAnimatingBounds() { |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 1873 | return mBoundsAnimating; |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1874 | } |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 1875 | |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 1876 | public boolean lastAnimatingBoundsWasToFullscreen() { |
| 1877 | return mBoundsAnimatingToFullscreen; |
| 1878 | } |
| 1879 | |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 1880 | public boolean isAnimatingBoundsToFullscreen() { |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 1881 | return isAnimatingBounds() && lastAnimatingBoundsWasToFullscreen(); |
Robert Carr | 7e4c90e | 2017-02-15 19:52:38 -0800 | [diff] [blame] | 1882 | } |
| 1883 | |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1884 | public boolean pinnedStackResizeDisallowed() { |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 1885 | if (mBoundsAnimating && mCancelCurrentBoundsAnimation) { |
| 1886 | return true; |
| 1887 | } |
| 1888 | return false; |
| 1889 | } |
| 1890 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1891 | /** Returns true if a removal action is still being deferred. */ |
| 1892 | boolean checkCompleteDeferredRemoval() { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1893 | if (isSelfOrChildAnimating()) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1894 | return true; |
| 1895 | } |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1896 | if (mDeferRemoval) { |
| 1897 | removeImmediately(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1898 | } |
| 1899 | |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1900 | return super.checkCompleteDeferredRemoval(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1901 | } |
| 1902 | |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1903 | @Override |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1904 | int getOrientation() { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 1905 | return (canSpecifyOrientation()) ? super.getOrientation() : SCREEN_ORIENTATION_UNSET; |
| 1906 | } |
| 1907 | |
| 1908 | private boolean canSpecifyOrientation() { |
| 1909 | final int windowingMode = getWindowingMode(); |
| 1910 | final int activityType = getActivityType(); |
| 1911 | return windowingMode == WINDOWING_MODE_FULLSCREEN |
| 1912 | || activityType == ACTIVITY_TYPE_HOME |
| 1913 | || activityType == ACTIVITY_TYPE_RECENTS |
| 1914 | || activityType == ACTIVITY_TYPE_ASSISTANT; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1915 | } |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 1916 | |
chaviw | 2fb06bc | 2018-01-19 17:09:15 -0800 | [diff] [blame] | 1917 | @Override |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 1918 | Dimmer getDimmer() { |
| 1919 | return mDimmer; |
| 1920 | } |
| 1921 | |
| 1922 | @Override |
| 1923 | void prepareSurfaces() { |
| 1924 | mDimmer.resetDimStates(); |
| 1925 | super.prepareSurfaces(); |
| 1926 | getDimBounds(mTmpDimBoundsRect); |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 1927 | |
| 1928 | // Bounds need to be relative, as the dim layer is a child. |
| 1929 | mTmpDimBoundsRect.offsetTo(0, 0); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 1930 | if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) { |
| 1931 | scheduleAnimation(); |
| 1932 | } |
| 1933 | } |
| 1934 | |
Tracy Zhou | 9c675d4 | 2019-04-08 00:32:40 -0700 | [diff] [blame] | 1935 | @Override |
| 1936 | public boolean setPinnedStackAlpha(float alpha) { |
| 1937 | // Hold the lock since this is called from the BoundsAnimator running on the UiThread |
| 1938 | synchronized (mWmService.mGlobalLock) { |
Winson Chung | 8312b1d | 2019-06-24 11:57:22 -0700 | [diff] [blame] | 1939 | final SurfaceControl sc = getSurfaceControl(); |
| 1940 | if (sc == null || !sc.isValid()) { |
| 1941 | // If the stack is already removed, don't bother updating any stack animation |
| 1942 | return false; |
| 1943 | } |
| 1944 | getPendingTransaction().setAlpha(sc, mCancelCurrentBoundsAnimation ? 1 : alpha); |
Tracy Zhou | 9c675d4 | 2019-04-08 00:32:40 -0700 | [diff] [blame] | 1945 | scheduleAnimation(); |
Tracy Zhou | 316b1f5 | 2019-06-04 16:05:19 -0700 | [diff] [blame] | 1946 | return !mCancelCurrentBoundsAnimation; |
Tracy Zhou | 9c675d4 | 2019-04-08 00:32:40 -0700 | [diff] [blame] | 1947 | } |
Tracy Zhou | 9c675d4 | 2019-04-08 00:32:40 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 1950 | public DisplayInfo getDisplayInfo() { |
| 1951 | return mDisplayContent.getDisplayInfo(); |
| 1952 | } |
| 1953 | |
| 1954 | void dim(float alpha) { |
| 1955 | mDimmer.dimAbove(getPendingTransaction(), alpha); |
| 1956 | scheduleAnimation(); |
| 1957 | } |
| 1958 | |
| 1959 | void stopDimming() { |
| 1960 | mDimmer.stopDim(getPendingTransaction()); |
| 1961 | scheduleAnimation(); |
| 1962 | } |
Robert Carr | 32bcb10 | 2018-01-29 15:03:23 -0800 | [diff] [blame] | 1963 | |
Jorim Jaggi | 6de6101 | 2018-03-19 14:53:23 +0100 | [diff] [blame] | 1964 | AnimatingAppWindowTokenRegistry getAnimatingAppWindowTokenRegistry() { |
| 1965 | return mAnimatingAppWindowTokenRegistry; |
| 1966 | } |
Wale Ogunwale | ecbcadd | 2016-02-21 14:18:51 -0800 | [diff] [blame] | 1967 | } |