Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Jorim Jaggi | 612bb88 | 2017-05-16 17:11:18 +0200 | [diff] [blame] | 19 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND; |
| 20 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; |
| 21 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 22 | import static android.content.pm.ActivityInfo.isFixedOrientationLandscape; |
| 23 | import static android.content.pm.ActivityInfo.isFixedOrientationPortrait; |
| 24 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
| 25 | import static android.content.res.Configuration.ORIENTATION_PORTRAIT; |
| 26 | import static android.content.res.Configuration.ORIENTATION_UNDEFINED; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 27 | import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; |
Vishnu Nair | 04ab439 | 2018-01-10 11:00:06 -0800 | [diff] [blame] | 28 | import static android.view.SurfaceControl.Transaction; |
Louis Chang | 7501e33 | 2018-08-20 13:08:39 +0800 | [diff] [blame] | 29 | |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 30 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
| 31 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_APP_TRANSITIONS; |
| 32 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_APP_TRANSITIONS_ANIM; |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 33 | import static com.android.server.wm.WindowContainer.AnimationFlags.CHILDREN; |
| 34 | import static com.android.server.wm.WindowContainer.AnimationFlags.PARENTS; |
| 35 | import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 36 | import static com.android.server.wm.WindowContainerProto.CONFIGURATION_CONTAINER; |
| 37 | import static com.android.server.wm.WindowContainerProto.ORIENTATION; |
| 38 | import static com.android.server.wm.WindowContainerProto.SURFACE_ANIMATOR; |
| 39 | import static com.android.server.wm.WindowContainerProto.VISIBLE; |
Louis Chang | 7501e33 | 2018-08-20 13:08:39 +0800 | [diff] [blame] | 40 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
| 41 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 42 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 43 | import static com.android.server.wm.WindowManagerService.logWithStack; |
Yunfan Chen | 87b5a24 | 2019-10-01 17:53:59 +0900 | [diff] [blame] | 44 | import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 45 | import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM; |
Jorim Jaggi | 612bb88 | 2017-05-16 17:11:18 +0200 | [diff] [blame] | 46 | |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 47 | import android.annotation.CallSuper; |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 48 | import android.annotation.IntDef; |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 49 | import android.annotation.Nullable; |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 50 | import android.app.WindowConfiguration; |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 51 | import android.content.pm.ActivityInfo; |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 52 | import android.content.res.Configuration; |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 53 | import android.graphics.Point; |
| 54 | import android.graphics.Rect; |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 55 | import android.os.Debug; |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 56 | import android.os.IBinder; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 57 | import android.os.Trace; |
| 58 | import android.util.Pair; |
Vishnu Nair | 04ab439 | 2018-01-10 11:00:06 -0800 | [diff] [blame] | 59 | import android.util.Pools; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 60 | import android.util.Slog; |
Vishnu Nair | 04ab439 | 2018-01-10 11:00:06 -0800 | [diff] [blame] | 61 | import android.util.proto.ProtoOutputStream; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 62 | import android.view.DisplayInfo; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 63 | import android.view.MagnificationSpec; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 64 | import android.view.RemoteAnimationTarget; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 65 | import android.view.SurfaceControl; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 66 | import android.view.SurfaceControl.Builder; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 67 | import android.view.SurfaceSession; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 68 | import android.view.WindowManager; |
| 69 | import android.view.animation.Animation; |
Garfield Tan | 2f145f2 | 2018-11-01 15:27:03 -0700 | [diff] [blame] | 70 | |
Evan Rosky | 65dffa6 | 2019-02-04 14:09:53 -0800 | [diff] [blame] | 71 | import com.android.internal.annotations.VisibleForTesting; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 72 | import com.android.internal.util.ToBooleanFunction; |
Yunfan Chen | 87b5a24 | 2019-10-01 17:53:59 +0900 | [diff] [blame] | 73 | import com.android.server.policy.WindowManagerPolicy; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 74 | import com.android.server.protolog.common.ProtoLog; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 75 | import com.android.server.wm.SurfaceAnimator.Animatable; |
Garfield Tan | 2f145f2 | 2018-11-01 15:27:03 -0700 | [diff] [blame] | 76 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 77 | import java.io.PrintWriter; |
Yunfan Chen | 87b5a24 | 2019-10-01 17:53:59 +0900 | [diff] [blame] | 78 | import java.util.ArrayList; |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 79 | import java.util.Comparator; |
| 80 | import java.util.LinkedList; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 81 | import java.util.function.Consumer; |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 82 | import java.util.function.Predicate; |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
| 85 | * Defines common functionality for classes that can hold windows directly or through their |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 86 | * children in a hierarchy form. |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 87 | * The test class is {@link WindowContainerTests} which must be kept up-to-date and ran anytime |
| 88 | * changes are made to this class. |
| 89 | */ |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 90 | class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<E> |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 91 | implements Comparable<WindowContainer>, Animatable { |
| 92 | |
| 93 | private static final String TAG = TAG_WITH_CLASS_NAME ? "WindowContainer" : TAG_WM; |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 94 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 95 | /** Animation layer that happens above all animating {@link ActivityStack}s. */ |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 96 | static final int ANIMATION_LAYER_STANDARD = 0; |
| 97 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 98 | /** Animation layer that happens above all {@link ActivityStack}s. */ |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 99 | static final int ANIMATION_LAYER_BOOSTED = 1; |
| 100 | |
| 101 | /** |
| 102 | * Animation layer that is reserved for {@link WindowConfiguration#ACTIVITY_TYPE_HOME} |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 103 | * activities and all activities that are being controlled by the recents animation. This |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 104 | * layer is generally below all {@link ActivityStack}s. |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 105 | */ |
| 106 | static final int ANIMATION_LAYER_HOME = 2; |
| 107 | |
| 108 | @IntDef(prefix = { "ANIMATION_LAYER_" }, value = { |
| 109 | ANIMATION_LAYER_STANDARD, |
| 110 | ANIMATION_LAYER_BOOSTED, |
| 111 | ANIMATION_LAYER_HOME, |
| 112 | }) |
| 113 | @interface AnimationLayer {} |
| 114 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 115 | static final int POSITION_TOP = Integer.MAX_VALUE; |
| 116 | static final int POSITION_BOTTOM = Integer.MIN_VALUE; |
| 117 | |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 118 | /** |
| 119 | * The parent of this window container. |
| 120 | * For removing or setting new parent {@link #setParent} should be used, because it also |
| 121 | * performs configuration updates based on new parent's settings. |
| 122 | */ |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 123 | private WindowContainer<WindowContainer> mParent = null; |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 124 | |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 125 | // Set to true when we are performing a reparenting operation so we only send one |
| 126 | // onParentChanged() notification. |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 127 | boolean mReparenting; |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 128 | |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 129 | // List of children for this window container. List is in z-order as the children appear on |
| 130 | // screen with the top-most window container at the tail of the list. |
Jorim Jaggi | 612bb88 | 2017-05-16 17:11:18 +0200 | [diff] [blame] | 131 | protected final WindowList<E> mChildren = new WindowList<E>(); |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 132 | |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 133 | // The specified orientation for this window container. |
| 134 | protected int mOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
| 135 | |
Wale Ogunwale | ee41d4a | 2016-11-21 08:41:10 -0800 | [diff] [blame] | 136 | private final Pools.SynchronizedPool<ForAllWindowsConsumerWrapper> mConsumerWrapperPool = |
| 137 | new Pools.SynchronizedPool<>(3); |
| 138 | |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 139 | // The display this window container is on. |
| 140 | protected DisplayContent mDisplayContent; |
| 141 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 142 | protected SurfaceControl mSurfaceControl; |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 143 | private int mLastLayer = 0; |
| 144 | private SurfaceControl mLastRelativeToLayer = null; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 145 | |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 146 | // TODO(b/132320879): Remove this from WindowContainers except DisplayContent. |
| 147 | private final Transaction mPendingTransaction; |
| 148 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 149 | /** |
Yunfan Chen | 87b5a24 | 2019-10-01 17:53:59 +0900 | [diff] [blame] | 150 | * Windows that clients are waiting to have drawn. |
| 151 | */ |
| 152 | final ArrayList<WindowState> mWaitingForDrawn = new ArrayList<>(); |
| 153 | |
| 154 | /** |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 155 | * Applied as part of the animation pass in "prepareSurfaces". |
| 156 | */ |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 157 | protected final SurfaceAnimator mSurfaceAnimator; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 158 | protected final WindowManagerService mWmService; |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 159 | |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 160 | private final Point mTmpPos = new Point(); |
chaviw | 3e751af | 2018-01-11 11:22:39 -0800 | [diff] [blame] | 161 | protected final Point mLastSurfacePosition = new Point(); |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 162 | |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 163 | /** Total number of elements in this subtree, including our own hierarchy element. */ |
| 164 | private int mTreeWeight = 1; |
| 165 | |
chaviw | 7f1fa99 | 2018-01-10 13:52:12 -0800 | [diff] [blame] | 166 | /** |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 167 | * Indicates whether we are animating and have committed the transaction to reparent our |
chaviw | 7f1fa99 | 2018-01-10 13:52:12 -0800 | [diff] [blame] | 168 | * surface to the animation leash |
| 169 | */ |
| 170 | private boolean mCommittedReparentToAnimationLeash; |
| 171 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 172 | private final Configuration mTmpConfig = new Configuration(); |
| 173 | |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 174 | /** Interface for {@link #isAnimating} to check which cases for the container is animating. */ |
| 175 | public interface AnimationFlags { |
| 176 | /** |
| 177 | * A bit flag indicates that {@link #isAnimating} should also return {@code true} |
| 178 | * even though the container is not yet animating, but the window container or its |
| 179 | * relatives as specified by PARENTS or CHILDREN are part of an {@link AppTransition} |
| 180 | * that is pending so an animation starts soon. |
| 181 | */ |
| 182 | int TRANSITION = 1; |
| 183 | |
| 184 | /** |
| 185 | * A bit flag indicates that {@link #isAnimating} should also check if one of the |
| 186 | * ancestors of the container are animating in addition to the container itself. |
| 187 | */ |
| 188 | int PARENTS = 2; |
| 189 | |
| 190 | /** |
| 191 | * A bit flag indicates that {@link #isAnimating} should also check if one of the |
| 192 | * descendants of the container are animating in addition to the container itself. |
| 193 | */ |
| 194 | int CHILDREN = 4; |
| 195 | } |
| 196 | |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 197 | /** |
| 198 | * Callback which is triggered while changing the parent, after setting up the surface but |
| 199 | * before asking the parent to assign child layers. |
| 200 | */ |
| 201 | interface PreAssignChildLayersCallback { |
| 202 | void onPreAssignChildLayers(); |
| 203 | } |
| 204 | |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 205 | /** |
| 206 | * True if this an AppWindowToken and the activity which created this was launched with |
| 207 | * ActivityOptions.setLaunchTaskBehind. |
| 208 | * |
| 209 | * TODO(b/142617871): We run a special animation when the activity was launched with that |
| 210 | * flag, but it's not necessary anymore. Keep the window invisible until the task is explicitly |
| 211 | * selected to suppress an animation, and remove this flag. |
| 212 | */ |
| 213 | boolean mLaunchTaskBehind; |
| 214 | |
| 215 | /** |
| 216 | * If we are running an animation, this determines the transition type. Must be one of |
| 217 | * {@link AppTransition#TransitionFlags}. |
| 218 | */ |
| 219 | int mTransit; |
| 220 | |
| 221 | /** |
| 222 | * If we are running an animation, this determines the flags during this animation. Must be a |
| 223 | * bitwise combination of AppTransition.TRANSIT_FLAG_* constants. |
| 224 | */ |
| 225 | int mTransitFlags; |
| 226 | |
| 227 | /** Whether this container should be boosted at the top of all its siblings. */ |
| 228 | @VisibleForTesting boolean mNeedsZBoost; |
| 229 | |
| 230 | /** Layer used to constrain the animation to a container's stack bounds. */ |
| 231 | SurfaceControl mAnimationBoundsLayer; |
| 232 | |
| 233 | /** Whether this container needs to create mAnimationBoundsLayer for cropping animations. */ |
| 234 | boolean mNeedsAnimationBoundsLayer; |
| 235 | |
| 236 | /** |
| 237 | * This gets used during some open/close transitions as well as during a change transition |
| 238 | * where it represents the starting-state snapshot. |
| 239 | */ |
lumark | bc0032a | 2019-11-01 21:38:13 +0800 | [diff] [blame] | 240 | WindowContainerThumbnail mThumbnail; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 241 | final Rect mTransitStartRect = new Rect(); |
| 242 | final Point mTmpPoint = new Point(); |
| 243 | protected final Rect mTmpRect = new Rect(); |
| 244 | final Rect mTmpPrevBounds = new Rect(); |
| 245 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 246 | WindowContainer(WindowManagerService wms) { |
| 247 | mWmService = wms; |
Vishnu Nair | 3319739 | 2019-08-30 10:29:37 -0700 | [diff] [blame] | 248 | mPendingTransaction = wms.mTransactionFactory.get(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 249 | mSurfaceAnimator = new SurfaceAnimator(this, this::onAnimationFinished, wms); |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 250 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 251 | |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 252 | @Override |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 253 | final protected WindowContainer getParent() { |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 254 | return mParent; |
| 255 | } |
| 256 | |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 257 | @Override |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 258 | protected int getChildCount() { |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 259 | return mChildren.size(); |
| 260 | } |
| 261 | |
| 262 | @Override |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 263 | protected E getChildAt(int index) { |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 264 | return mChildren.get(index); |
| 265 | } |
| 266 | |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 267 | @Override |
| 268 | public void onConfigurationChanged(Configuration newParentConfig) { |
| 269 | super.onConfigurationChanged(newParentConfig); |
chaviw | 2f0567b | 2018-01-29 16:22:02 -0800 | [diff] [blame] | 270 | updateSurfacePosition(); |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 271 | scheduleAnimation(); |
| 272 | } |
| 273 | |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 274 | void reparent(WindowContainer newParent, int position) { |
| 275 | if (newParent == null) { |
| 276 | throw new IllegalArgumentException("reparent: can't reparent to null " + this); |
| 277 | } |
| 278 | |
| 279 | final WindowContainer oldParent = mParent; |
| 280 | if (mParent == newParent) { |
| 281 | throw new IllegalArgumentException("WC=" + this + " already child of " + mParent); |
| 282 | } |
| 283 | |
| 284 | // The display object before reparenting as that might lead to old parent getting removed |
| 285 | // from the display if it no longer has any child. |
| 286 | final DisplayContent prevDc = oldParent.getDisplayContent(); |
| 287 | final DisplayContent dc = newParent.getDisplayContent(); |
| 288 | |
| 289 | mReparenting = true; |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 290 | // Oddly enough we add to the new parent before removing from the old parent to avoid |
| 291 | // issues... |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 292 | newParent.addChild(this, position); |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 293 | oldParent.removeChild(this); |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 294 | mReparenting = false; |
| 295 | |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 296 | // Relayout display(s) |
| 297 | dc.setLayoutNeeded(); |
| 298 | if (prevDc != dc) { |
| 299 | onDisplayChanged(dc); |
| 300 | prevDc.setLayoutNeeded(); |
| 301 | } |
| 302 | getDisplayContent().layoutAndAssignWindowLayersIfNeeded(); |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 303 | |
| 304 | // Send onParentChanged notification here is we disabled sending it in setParent for |
| 305 | // reparenting case. |
| 306 | onParentChanged(newParent, oldParent); |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 307 | } |
| 308 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 309 | final protected void setParent(WindowContainer<WindowContainer> parent) { |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 310 | final WindowContainer oldParent = mParent; |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 311 | mParent = parent; |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 312 | if (!mReparenting) { |
| 313 | onParentChanged(mParent, oldParent); |
| 314 | } |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | /** |
| 318 | * Callback that is triggered when @link WindowContainer#setParent(WindowContainer)} was called. |
| 319 | * Supposed to be overridden and contain actions that should be executed after parent was set. |
| 320 | */ |
Riddle Hsu | 3a4bb61 | 2019-01-31 00:02:22 +0800 | [diff] [blame] | 321 | @Override |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 322 | void onParentChanged(ConfigurationContainer newParent, ConfigurationContainer oldParent) { |
| 323 | onParentChanged(newParent, oldParent, null); |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 324 | } |
| 325 | |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 326 | void onParentChanged(ConfigurationContainer newParent, ConfigurationContainer oldParent, |
| 327 | PreAssignChildLayersCallback callback) { |
| 328 | super.onParentChanged(newParent, oldParent); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 329 | if (mParent == null) { |
| 330 | return; |
| 331 | } |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 332 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 333 | if (mSurfaceControl == null) { |
| 334 | // If we don't yet have a surface, but we now have a parent, we should |
| 335 | // build a surface. |
| 336 | mSurfaceControl = makeSurface().build(); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 337 | getPendingTransaction().show(mSurfaceControl); |
Evan Rosky | b1ea7ca | 2018-04-05 17:17:35 -0700 | [diff] [blame] | 338 | updateSurfacePosition(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 339 | } else { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 340 | // If we have a surface but a new parent, we just need to perform a reparent. Go through |
| 341 | // surface animator such that hierarchy is preserved when animating, i.e. |
| 342 | // mSurfaceControl stays attached to the leash and we just reparent the leash to the |
| 343 | // new parent. |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 344 | reparentSurfaceControl(getPendingTransaction(), mParent.mSurfaceControl); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 347 | if (callback != null) { |
| 348 | callback.onPreAssignChildLayers(); |
| 349 | } |
| 350 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 351 | // Either way we need to ask the parent to assign us a Z-order. |
| 352 | mParent.assignChildLayers(); |
| 353 | scheduleAnimation(); |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 356 | // Temp. holders for a chain of containers we are currently processing. |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 357 | private final LinkedList<WindowContainer> mTmpChain1 = new LinkedList<>(); |
| 358 | private final LinkedList<WindowContainer> mTmpChain2 = new LinkedList<>(); |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 359 | |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 360 | /** |
| 361 | * Adds the input window container has a child of this container in order based on the input |
| 362 | * comparator. |
| 363 | * @param child The window container to add as a child of this window container. |
| 364 | * @param comparator Comparator to use in determining the position the child should be added to. |
| 365 | * If null, the child will be added to the top. |
| 366 | */ |
| 367 | @CallSuper |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 368 | protected void addChild(E child, Comparator<E> comparator) { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 369 | if (!child.mReparenting && child.getParent() != null) { |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 370 | throw new IllegalArgumentException("addChild: container=" + child.getName() |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 371 | + " is already a child of container=" + child.getParent().getName() |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 372 | + " can't add to container=" + getName()); |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 373 | } |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 374 | |
Andrii Kulian | b94292e | 2016-10-19 13:30:58 -0700 | [diff] [blame] | 375 | int positionToAdd = -1; |
| 376 | if (comparator != null) { |
| 377 | final int count = mChildren.size(); |
| 378 | for (int i = 0; i < count; i++) { |
| 379 | if (comparator.compare(child, mChildren.get(i)) < 0) { |
| 380 | positionToAdd = i; |
| 381 | break; |
| 382 | } |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
Andrii Kulian | b94292e | 2016-10-19 13:30:58 -0700 | [diff] [blame] | 386 | if (positionToAdd == -1) { |
| 387 | mChildren.add(child); |
| 388 | } else { |
| 389 | mChildren.add(positionToAdd, child); |
| 390 | } |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 391 | onChildAdded(child); |
| 392 | |
Andrii Kulian | b94292e | 2016-10-19 13:30:58 -0700 | [diff] [blame] | 393 | // Set the parent after we've actually added a child in case a subclass depends on this. |
| 394 | child.setParent(this); |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 397 | /** Adds the input window container has a child of this container at the input index. */ |
| 398 | @CallSuper |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 399 | void addChild(E child, int index) { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 400 | if (!child.mReparenting && child.getParent() != null) { |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 401 | throw new IllegalArgumentException("addChild: container=" + child.getName() |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 402 | + " is already a child of container=" + child.getParent().getName() |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 403 | + " can't add to container=" + getName() |
| 404 | + "\n callers=" + Debug.getCallers(15, "\n")); |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 405 | } |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 406 | |
| 407 | if ((index < 0 && index != POSITION_BOTTOM) |
| 408 | || (index > mChildren.size() && index != POSITION_TOP)) { |
| 409 | throw new IllegalArgumentException("addChild: invalid position=" + index |
| 410 | + ", children number=" + mChildren.size()); |
| 411 | } |
| 412 | |
| 413 | if (index == POSITION_TOP) { |
| 414 | index = mChildren.size(); |
| 415 | } else if (index == POSITION_BOTTOM) { |
| 416 | index = 0; |
| 417 | } |
| 418 | |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 419 | mChildren.add(index, child); |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 420 | onChildAdded(child); |
| 421 | |
Andrii Kulian | b94292e | 2016-10-19 13:30:58 -0700 | [diff] [blame] | 422 | // Set the parent after we've actually added a child in case a subclass depends on this. |
| 423 | child.setParent(this); |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 426 | private void onChildAdded(WindowContainer child) { |
| 427 | mTreeWeight += child.mTreeWeight; |
| 428 | WindowContainer parent = getParent(); |
| 429 | while (parent != null) { |
| 430 | parent.mTreeWeight += child.mTreeWeight; |
| 431 | parent = parent.getParent(); |
| 432 | } |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 433 | onChildPositionChanged(child); |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 434 | } |
| 435 | |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 436 | /** |
| 437 | * Removes the input child container from this container which is its parent. |
| 438 | * |
| 439 | * @return True if the container did contain the input child and it was detached. |
| 440 | */ |
| 441 | @CallSuper |
| 442 | void removeChild(E child) { |
| 443 | if (mChildren.remove(child)) { |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 444 | onChildRemoved(child); |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 445 | if (!child.mReparenting) { |
| 446 | child.setParent(null); |
| 447 | } |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 448 | } else { |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 449 | throw new IllegalArgumentException("removeChild: container=" + child.getName() |
| 450 | + " is not a child of container=" + getName()); |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 451 | } |
| 452 | } |
| 453 | |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 454 | private void onChildRemoved(WindowContainer child) { |
| 455 | mTreeWeight -= child.mTreeWeight; |
| 456 | WindowContainer parent = getParent(); |
| 457 | while (parent != null) { |
| 458 | parent.mTreeWeight -= child.mTreeWeight; |
| 459 | parent = parent.getParent(); |
| 460 | } |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 461 | onChildPositionChanged(child); |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 462 | } |
| 463 | |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 464 | /** |
| 465 | * Removes this window container and its children with no regard for what else might be going on |
| 466 | * in the system. For example, the container will be removed during animation if this method is |
| 467 | * called which isn't desirable. For most cases you want to call {@link #removeIfPossible()} |
| 468 | * which allows the system to defer removal until a suitable time. |
| 469 | */ |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 470 | @CallSuper |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 471 | void removeImmediately() { |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 472 | while (!mChildren.isEmpty()) { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 473 | final E child = mChildren.peekLast(); |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 474 | child.removeImmediately(); |
| 475 | // Need to do this after calling remove on the child because the child might try to |
| 476 | // remove/detach itself from its parent which will cause an exception if we remove |
| 477 | // it before calling remove on the child. |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 478 | if (mChildren.remove(child)) { |
| 479 | onChildRemoved(child); |
| 480 | } |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 483 | if (mSurfaceControl != null) { |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 484 | getPendingTransaction().remove(mSurfaceControl); |
chaviw | 6728e2f | 2018-03-19 15:58:04 -0700 | [diff] [blame] | 485 | |
| 486 | // Merge to parent transaction to ensure the transactions on this WindowContainer are |
| 487 | // applied in native even if WindowContainer is removed. |
| 488 | if (mParent != null) { |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 489 | mParent.getPendingTransaction().merge(getPendingTransaction()); |
chaviw | 6728e2f | 2018-03-19 15:58:04 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 492 | mSurfaceControl = null; |
Garfield Tan | 265ab91a | 2019-11-12 16:30:49 -0800 | [diff] [blame] | 493 | mLastSurfacePosition.set(0, 0); |
Chavi Weingarten | b736e32 | 2018-02-23 00:27:54 +0000 | [diff] [blame] | 494 | scheduleAnimation(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 497 | if (mParent != null) { |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 498 | mParent.removeChild(this); |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 499 | } |
| 500 | } |
| 501 | |
| 502 | /** |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 503 | * @return The index of this element in the hierarchy tree in prefix order. |
| 504 | */ |
| 505 | int getPrefixOrderIndex() { |
| 506 | if (mParent == null) { |
| 507 | return 0; |
| 508 | } |
| 509 | return mParent.getPrefixOrderIndex(this); |
| 510 | } |
| 511 | |
| 512 | private int getPrefixOrderIndex(WindowContainer child) { |
| 513 | int order = 0; |
| 514 | for (int i = 0; i < mChildren.size(); i++) { |
| 515 | final WindowContainer childI = mChildren.get(i); |
| 516 | if (child == childI) { |
| 517 | break; |
| 518 | } |
| 519 | order += childI.mTreeWeight; |
| 520 | } |
| 521 | if (mParent != null) { |
| 522 | order += mParent.getPrefixOrderIndex(this); |
| 523 | } |
| 524 | |
| 525 | // We also need to count ourselves. |
| 526 | order++; |
| 527 | return order; |
| 528 | } |
| 529 | |
| 530 | /** |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 531 | * Removes this window container and its children taking care not to remove them during a |
| 532 | * critical stage in the system. For example, some containers will not be removed during |
| 533 | * animation if this method is called. |
| 534 | */ |
| 535 | // TODO: figure-out implementation that works best for this. |
| 536 | // E.g. when do we remove from parent list? maybe not... |
| 537 | void removeIfPossible() { |
| 538 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 539 | final WindowContainer wc = mChildren.get(i); |
| 540 | wc.removeIfPossible(); |
| 541 | } |
| 542 | } |
| 543 | |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 544 | /** Returns true if this window container has the input child. */ |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 545 | boolean hasChild(E child) { |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 546 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 547 | final E current = mChildren.get(i); |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 548 | if (current == child || current.hasChild(child)) { |
| 549 | return true; |
| 550 | } |
| 551 | } |
| 552 | return false; |
| 553 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 554 | |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 555 | /** |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 556 | * Move a child from it's current place in siblings list to the specified position, |
| 557 | * with an option to move all its parents to top. |
| 558 | * @param position Target position to move the child to. |
| 559 | * @param child Child to move to selected position. |
| 560 | * @param includingParents Flag indicating whether we need to move the entire branch of the |
| 561 | * hierarchy when we're moving a child to {@link #POSITION_TOP} or |
| 562 | * {@link #POSITION_BOTTOM}. When moving to other intermediate positions |
| 563 | * this flag will do nothing. |
| 564 | */ |
| 565 | @CallSuper |
| 566 | void positionChildAt(int position, E child, boolean includingParents) { |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 567 | |
| 568 | if (child.getParent() != this) { |
| 569 | throw new IllegalArgumentException("removeChild: container=" + child.getName() |
| 570 | + " is not a child of container=" + getName() |
| 571 | + " current parent=" + child.getParent()); |
| 572 | } |
| 573 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 574 | if (position >= mChildren.size() - 1) { |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 575 | position = POSITION_TOP; |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 576 | } else if (position <= 0) { |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 577 | position = POSITION_BOTTOM; |
| 578 | } |
| 579 | |
| 580 | switch (position) { |
| 581 | case POSITION_TOP: |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 582 | if (mChildren.peekLast() != child) { |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 583 | mChildren.remove(child); |
Jorim Jaggi | 612bb88 | 2017-05-16 17:11:18 +0200 | [diff] [blame] | 584 | mChildren.add(child); |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 585 | onChildPositionChanged(child); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 586 | } |
| 587 | if (includingParents && getParent() != null) { |
| 588 | getParent().positionChildAt(POSITION_TOP, this /* child */, |
| 589 | true /* includingParents */); |
| 590 | } |
| 591 | break; |
| 592 | case POSITION_BOTTOM: |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 593 | if (mChildren.peekFirst() != child) { |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 594 | mChildren.remove(child); |
| 595 | mChildren.addFirst(child); |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 596 | onChildPositionChanged(child); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 597 | } |
| 598 | if (includingParents && getParent() != null) { |
| 599 | getParent().positionChildAt(POSITION_BOTTOM, this /* child */, |
| 600 | true /* includingParents */); |
| 601 | } |
| 602 | break; |
| 603 | default: |
Winson Chung | 123e07a | 2018-02-27 11:47:16 -0800 | [diff] [blame] | 604 | // TODO: Removing the child before reinserting requires the caller to provide a |
| 605 | // position that takes into account the removed child (if the index of the |
| 606 | // child < position, then the position should be adjusted). We should consider |
| 607 | // doing this adjustment here and remove any adjustments in the callers. |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 608 | mChildren.remove(child); |
| 609 | mChildren.add(position, child); |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 610 | onChildPositionChanged(child); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 611 | } |
| 612 | } |
| 613 | |
| 614 | /** |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 615 | * Notify that a child's position has changed. Possible changes are adding or removing a child. |
| 616 | */ |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 617 | void onChildPositionChanged(WindowContainer child) { } |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 618 | |
| 619 | /** |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 620 | * Update override configuration and recalculate full config. |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 621 | * @see #mRequestedOverrideConfiguration |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 622 | * @see #mFullConfiguration |
| 623 | */ |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 624 | @Override |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 625 | public void onRequestedOverrideConfigurationChanged(Configuration overrideConfiguration) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 626 | // We must diff before the configuration is applied so that we can capture the change |
| 627 | // against the existing bounds. |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 628 | final int diff = diffRequestedOverrideBounds( |
| 629 | overrideConfiguration.windowConfiguration.getBounds()); |
| 630 | super.onRequestedOverrideConfigurationChanged(overrideConfiguration); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 631 | if (mParent != null) { |
| 632 | mParent.onDescendantOverrideConfigurationChanged(); |
| 633 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 634 | |
| 635 | if (diff == BOUNDS_CHANGE_NONE) { |
| 636 | return; |
| 637 | } |
| 638 | |
| 639 | if ((diff & BOUNDS_CHANGE_SIZE) == BOUNDS_CHANGE_SIZE) { |
| 640 | onResize(); |
| 641 | } else { |
| 642 | onMovedByResize(); |
| 643 | } |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | /** |
| 647 | * Notify that a descendant's overrideConfiguration has changed. |
| 648 | */ |
| 649 | void onDescendantOverrideConfigurationChanged() { |
| 650 | if (mParent != null) { |
| 651 | mParent.onDescendantOverrideConfigurationChanged(); |
| 652 | } |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | /** |
Garfield Tan | 2f145f2 | 2018-11-01 15:27:03 -0700 | [diff] [blame] | 656 | * Notify that the display this container is on has changed. This could be either this container |
| 657 | * is moved to a new display, or some configurations on the display it is on changes. |
| 658 | * |
| 659 | * @param dc The display this container is on after changes. |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 660 | */ |
| 661 | void onDisplayChanged(DisplayContent dc) { |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 662 | mDisplayContent = dc; |
| 663 | if (dc != null && dc != this) { |
| 664 | dc.getPendingTransaction().merge(mPendingTransaction); |
| 665 | } |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 666 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 667 | final WindowContainer child = mChildren.get(i); |
| 668 | child.onDisplayChanged(dc); |
| 669 | } |
| 670 | } |
| 671 | |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 672 | DisplayContent getDisplayContent() { |
| 673 | return mDisplayContent; |
| 674 | } |
| 675 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 676 | void setWaitingForDrawnIfResizingChanged() { |
| 677 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 678 | final WindowContainer wc = mChildren.get(i); |
| 679 | wc.setWaitingForDrawnIfResizingChanged(); |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | void onResize() { |
| 684 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 685 | final WindowContainer wc = mChildren.get(i); |
Bryce Lee | d92ae48 | 2018-01-22 13:56:23 -0800 | [diff] [blame] | 686 | wc.onParentResize(); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 687 | } |
| 688 | } |
| 689 | |
Bryce Lee | d92ae48 | 2018-01-22 13:56:23 -0800 | [diff] [blame] | 690 | void onParentResize() { |
| 691 | // In the case this container has specified its own bounds, a parent resize will not |
| 692 | // affect its bounds. Any relevant changes will be propagated through changes to the |
| 693 | // Configuration override. |
| 694 | if (hasOverrideBounds()) { |
| 695 | return; |
| 696 | } |
| 697 | |
| 698 | // Default implementation is to treat as resize on self. |
| 699 | onResize(); |
| 700 | } |
| 701 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 702 | void onMovedByResize() { |
| 703 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 704 | final WindowContainer wc = mChildren.get(i); |
| 705 | wc.onMovedByResize(); |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | void resetDragResizingChangeReported() { |
| 710 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 711 | final WindowContainer wc = mChildren.get(i); |
| 712 | wc.resetDragResizingChangeReported(); |
| 713 | } |
| 714 | } |
| 715 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 716 | void forceWindowsScaleableInTransaction(boolean force) { |
| 717 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 718 | final WindowContainer wc = mChildren.get(i); |
| 719 | wc.forceWindowsScaleableInTransaction(force); |
| 720 | } |
| 721 | } |
| 722 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 723 | /** |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 724 | * @return {@code true} when this container or its related containers are running an |
| 725 | * animation, {@code false} otherwise. |
| 726 | * |
| 727 | * By default this predicate only checks if this container itself is actually running an |
| 728 | * animation, but you can extend the check target over its relatives, or relax the condition |
| 729 | * so that this can return {@code true} if an animation starts soon by giving a combination |
| 730 | * of {@link #AnimationFlags}. |
| 731 | * |
| 732 | * Note that you can give a combination of bitmask flags to specify targets and condition for |
| 733 | * checking animating status. |
| 734 | * e.g. {@code isAnimating(TRANSITION | PARENT)} returns {@code true} if either this |
| 735 | * container itself or one of its parents is running an animation or waiting for an app |
| 736 | * transition. |
| 737 | * |
| 738 | * Note that TRANSITION propagates to parents and children as well. |
| 739 | * |
| 740 | * {@see AnimationFlags#TRANSITION} |
| 741 | * {@see AnimationFlags#PARENTS} |
| 742 | * {@see AnimationFlags#CHILDREN} |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 743 | */ |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 744 | final boolean isAnimating(int flags) { |
| 745 | if (mSurfaceAnimator.isAnimating()) { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 746 | return true; |
| 747 | } |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 748 | if ((flags & TRANSITION) != 0 && isWaitingForTransitionStart()) { |
| 749 | return true; |
| 750 | } |
| 751 | if ((flags & PARENTS) != 0) { |
| 752 | final WindowContainer parent = getParent(); |
| 753 | if (parent != null && parent.isAnimating(flags & ~CHILDREN)) { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 754 | return true; |
| 755 | } |
| 756 | } |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 757 | if ((flags & CHILDREN) != 0) { |
| 758 | for (int i = 0; i < mChildren.size(); ++i) { |
| 759 | final WindowContainer wc = mChildren.get(i); |
| 760 | if (wc.isAnimating(flags & ~PARENTS)) { |
| 761 | return true; |
| 762 | } |
| 763 | } |
| 764 | } |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 765 | return false; |
| 766 | } |
| 767 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 768 | /** |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 769 | * @return {@code true} when the container is waiting the app transition start, {@code false} |
| 770 | * otherwise. |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 771 | */ |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 772 | boolean isWaitingForTransitionStart() { |
| 773 | return false; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | /** |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 777 | * @return {@code true} if in this subtree of the hierarchy we have an |
| 778 | * {@ode ActivityRecord#isAnimating(TRANSITION)}, {@code false} otherwise. |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 779 | */ |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 780 | boolean isAppTransitioning() { |
| 781 | return forAllActivities(app -> app.isAnimating(TRANSITION)); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | /** |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 785 | * @return Whether our own container running an animation at the moment. |
| 786 | */ |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 787 | final boolean isAnimating() { |
| 788 | return isAnimating(0 /* self only */); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 789 | } |
| 790 | |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 791 | /** |
| 792 | * @return {@code true} if the container is in changing app transition. |
| 793 | */ |
| 794 | boolean isChangingAppTransition() { |
| 795 | return false; |
| 796 | } |
| 797 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 798 | void sendAppVisibilityToClients() { |
| 799 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 800 | final WindowContainer wc = mChildren.get(i); |
| 801 | wc.sendAppVisibilityToClients(); |
| 802 | } |
| 803 | } |
| 804 | |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 805 | /** |
| 806 | * Returns true if the container or one of its children as some content it can display or wants |
| 807 | * to display (e.g. app views or saved surface). |
| 808 | * |
| 809 | * NOTE: While this method will return true if the there is some content to display, it doesn't |
| 810 | * mean the container is visible. Use {@link #isVisible()} to determine if the container is |
| 811 | * visible. |
| 812 | */ |
| 813 | boolean hasContentToDisplay() { |
| 814 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 815 | final WindowContainer wc = mChildren.get(i); |
| 816 | if (wc.hasContentToDisplay()) { |
| 817 | return true; |
| 818 | } |
| 819 | } |
| 820 | return false; |
| 821 | } |
| 822 | |
| 823 | /** |
| 824 | * Returns true if the container or one of its children is considered visible from the |
| 825 | * WindowManager perspective which usually means valid surface and some other internal state |
| 826 | * are true. |
| 827 | * |
| 828 | * NOTE: While this method will return true if the surface is visible, it doesn't mean the |
| 829 | * client has actually displayed any content. Use {@link #hasContentToDisplay()} to determine if |
| 830 | * the container has any content to display. |
| 831 | */ |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 832 | boolean isVisible() { |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 833 | // TODO: Will this be more correct if it checks the visibility of its parents? |
| 834 | // It depends...For example, Tasks and Stacks are only visible if there children are visible |
| 835 | // but, WindowState are not visible if there parent are not visible. Maybe have the |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 836 | // container specify which direction to traverse for visibility? |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 837 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 838 | final WindowContainer wc = mChildren.get(i); |
| 839 | if (wc.isVisible()) { |
| 840 | return true; |
| 841 | } |
| 842 | } |
| 843 | return false; |
| 844 | } |
| 845 | |
Bryce Lee | 00d586d | 2017-07-28 20:48:43 -0700 | [diff] [blame] | 846 | /** |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 847 | * @return Whether this child is on top of the window hierarchy. |
Bryce Lee | 00d586d | 2017-07-28 20:48:43 -0700 | [diff] [blame] | 848 | */ |
| 849 | boolean isOnTop() { |
| 850 | return getParent().getTopChild() == this && getParent().isOnTop(); |
| 851 | } |
| 852 | |
Jorim Jaggi | 10abe2f | 2017-01-03 16:44:46 +0100 | [diff] [blame] | 853 | /** Returns the top child container. */ |
| 854 | E getTopChild() { |
| 855 | return mChildren.peekLast(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 856 | } |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 857 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 858 | /** Returns true if there is still a removal being deferred */ |
| 859 | boolean checkCompleteDeferredRemoval() { |
| 860 | boolean stillDeferringRemoval = false; |
| 861 | |
| 862 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 863 | final WindowContainer wc = mChildren.get(i); |
| 864 | stillDeferringRemoval |= wc.checkCompleteDeferredRemoval(); |
| 865 | } |
| 866 | |
| 867 | return stillDeferringRemoval; |
| 868 | } |
| 869 | |
| 870 | /** Checks if all windows in an app are all drawn and shows them if needed. */ |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 871 | void checkAppWindowsReadyToShow() { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 872 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 873 | final WindowContainer wc = mChildren.get(i); |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 874 | wc.checkAppWindowsReadyToShow(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 875 | } |
| 876 | } |
| 877 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 878 | void onAppTransitionDone() { |
| 879 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 880 | final WindowContainer wc = mChildren.get(i); |
| 881 | wc.onAppTransitionDone(); |
| 882 | } |
| 883 | } |
| 884 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 885 | /** |
| 886 | * Called when this container or one of its descendants changed its requested orientation, and |
| 887 | * wants this container to handle it or pass it to its parent. |
| 888 | * |
| 889 | * @param freezeDisplayToken freeze this app window token if display needs to freeze |
| 890 | * @param requestingContainer the container which orientation request has changed |
| 891 | * @return {@code true} if handled; {@code false} otherwise. |
| 892 | */ |
| 893 | boolean onDescendantOrientationChanged(@Nullable IBinder freezeDisplayToken, |
| 894 | @Nullable ConfigurationContainer requestingContainer) { |
| 895 | final WindowContainer parent = getParent(); |
| 896 | if (parent == null) { |
| 897 | return false; |
| 898 | } |
| 899 | return parent.onDescendantOrientationChanged(freezeDisplayToken, |
| 900 | requestingContainer); |
| 901 | } |
| 902 | |
| 903 | /** |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 904 | * Check if this container or its parent will handle orientation changes from descendants. It's |
| 905 | * different from the return value of {@link #onDescendantOrientationChanged(IBinder, |
| 906 | * ConfigurationContainer)} in the sense that the return value of this method tells if this |
| 907 | * container or its parent will handle the request eventually, while the return value of the |
| 908 | * other method is if it handled the request synchronously. |
| 909 | * |
| 910 | * @return {@code true} if it handles or will handle orientation change in the future; {@code |
| 911 | * false} if it won't handle the change at anytime. |
| 912 | */ |
| 913 | boolean handlesOrientationChangeFromDescendant() { |
| 914 | final WindowContainer parent = getParent(); |
| 915 | return parent != null && parent.handlesOrientationChangeFromDescendant(); |
| 916 | } |
| 917 | |
| 918 | /** |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 919 | * Get the configuration orientation by the requested screen orientation |
| 920 | * ({@link ActivityInfo.ScreenOrientation}) of this activity. |
| 921 | * |
| 922 | * @return orientation in ({@link Configuration#ORIENTATION_LANDSCAPE}, |
| 923 | * {@link Configuration#ORIENTATION_PORTRAIT}, |
| 924 | * {@link Configuration#ORIENTATION_UNDEFINED}). |
| 925 | */ |
| 926 | int getRequestedConfigurationOrientation() { |
| 927 | if (mOrientation == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 928 | // NOSENSOR means the display's "natural" orientation, so return that. |
| 929 | if (mDisplayContent != null) { |
| 930 | return mDisplayContent.getNaturalOrientation(); |
| 931 | } |
| 932 | } else if (mOrientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 933 | // LOCKED means the activity's orientation remains unchanged, so return existing value. |
| 934 | return getConfiguration().orientation; |
| 935 | } else if (isFixedOrientationLandscape(mOrientation)) { |
| 936 | return ORIENTATION_LANDSCAPE; |
| 937 | } else if (isFixedOrientationPortrait(mOrientation)) { |
| 938 | return ORIENTATION_PORTRAIT; |
| 939 | } |
| 940 | return ORIENTATION_UNDEFINED; |
| 941 | } |
| 942 | |
| 943 | /** |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 944 | * Calls {@link #setOrientation(int, IBinder, ActivityRecord)} with {@code null} to the last 2 |
| 945 | * parameters. |
| 946 | * |
| 947 | * @param orientation the specified orientation. |
| 948 | */ |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 949 | void setOrientation(int orientation) { |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 950 | setOrientation(orientation, null /* freezeDisplayToken */, |
| 951 | null /* ActivityRecord */); |
| 952 | } |
| 953 | |
| 954 | /** |
| 955 | * Sets the specified orientation of this container. It percolates this change upward along the |
| 956 | * hierarchy to let each level of the hierarchy a chance to respond to it. |
| 957 | * |
| 958 | * @param orientation the specified orientation. Needs to be one of {@link |
| 959 | * android.content.pm.ActivityInfo.ScreenOrientation}. |
| 960 | * @param freezeDisplayToken uses this token to freeze display if orientation change is not |
| 961 | * done. Display will not be frozen if this is {@code null}, which |
| 962 | * should only happen in tests. |
| 963 | * @param requestingContainer the container which orientation request has changed. Mostly used |
| 964 | * to ensure it gets correct configuration. |
| 965 | */ |
| 966 | void setOrientation(int orientation, @Nullable IBinder freezeDisplayToken, |
| 967 | @Nullable ConfigurationContainer requestingContainer) { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 968 | if (mOrientation == orientation) { |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 969 | return; |
| 970 | } |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 971 | |
| 972 | mOrientation = orientation; |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 973 | final int configOrientation = getRequestedConfigurationOrientation(); |
| 974 | if (getRequestedOverrideConfiguration().orientation != configOrientation) { |
| 975 | mTmpConfig.setTo(getRequestedOverrideConfiguration()); |
| 976 | mTmpConfig.orientation = configOrientation; |
| 977 | onRequestedOverrideConfigurationChanged(mTmpConfig); |
| 978 | } |
| 979 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 980 | final WindowContainer parent = getParent(); |
| 981 | if (parent != null) { |
| 982 | onDescendantOrientationChanged(freezeDisplayToken, requestingContainer); |
| 983 | } |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 984 | } |
| 985 | |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 986 | int getOrientation() { |
| 987 | return getOrientation(mOrientation); |
| 988 | } |
| 989 | |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 990 | /** |
| 991 | * Returns the specified orientation for this window container or one of its children is there |
| 992 | * is one set, or {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSET} if no |
| 993 | * specification is set. |
| 994 | * NOTE: {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED} is a |
| 995 | * specification... |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 996 | * |
| 997 | * @param candidate The current orientation candidate that will be returned if we don't find a |
| 998 | * better match. |
| 999 | * @return The orientation as specified by this branch or the window hierarchy. |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1000 | */ |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 1001 | int getOrientation(int candidate) { |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1002 | if (!fillsParent()) { |
| 1003 | // Ignore containers that don't completely fill their parents. |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1004 | return SCREEN_ORIENTATION_UNSET; |
| 1005 | } |
| 1006 | |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1007 | // The container fills its parent so we can use it orientation if it has one |
| 1008 | // specified; otherwise we prefer to use the orientation of its topmost child that has one |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1009 | // specified and fall back on this container's unset or unspecified value as a candidate |
| 1010 | // if none of the children have a better candidate for the orientation. |
| 1011 | if (mOrientation != SCREEN_ORIENTATION_UNSET |
| 1012 | && mOrientation != SCREEN_ORIENTATION_UNSPECIFIED) { |
| 1013 | return mOrientation; |
| 1014 | } |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1015 | |
| 1016 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1017 | final WindowContainer wc = mChildren.get(i); |
| 1018 | |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 1019 | // TODO: Maybe mOrientation should default to SCREEN_ORIENTATION_UNSET vs. |
| 1020 | // SCREEN_ORIENTATION_UNSPECIFIED? |
| 1021 | final int orientation = wc.getOrientation(candidate == SCREEN_ORIENTATION_BEHIND |
| 1022 | ? SCREEN_ORIENTATION_BEHIND : SCREEN_ORIENTATION_UNSET); |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1023 | if (orientation == SCREEN_ORIENTATION_BEHIND) { |
| 1024 | // container wants us to use the orientation of the container behind it. See if we |
| 1025 | // can find one. Else return SCREEN_ORIENTATION_BEHIND so the caller can choose to |
| 1026 | // look behind this container. |
| 1027 | candidate = orientation; |
| 1028 | continue; |
| 1029 | } |
| 1030 | |
| 1031 | if (orientation == SCREEN_ORIENTATION_UNSET) { |
| 1032 | continue; |
| 1033 | } |
| 1034 | |
| 1035 | if (wc.fillsParent() || orientation != SCREEN_ORIENTATION_UNSPECIFIED) { |
| 1036 | // Use the orientation if the container fills its parent or requested an explicit |
| 1037 | // orientation that isn't SCREEN_ORIENTATION_UNSPECIFIED. |
| 1038 | return orientation; |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | return candidate; |
| 1043 | } |
| 1044 | |
| 1045 | /** |
| 1046 | * Returns true if this container is opaque and fills all the space made available by its parent |
| 1047 | * container. |
| 1048 | * |
| 1049 | * NOTE: It is possible for this container to occupy more space than the parent has (or less), |
| 1050 | * this is just a signal from the client to window manager stating its intent, but not what it |
| 1051 | * actually does. |
| 1052 | */ |
| 1053 | boolean fillsParent() { |
| 1054 | return false; |
| 1055 | } |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1056 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 1057 | // TODO: Users would have their own window containers under the display container? |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 1058 | void switchUser(int userId) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 1059 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 1060 | mChildren.get(i).switchUser(userId); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1061 | } |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 1064 | /** |
| 1065 | * For all windows at or below this container call the callback. |
| 1066 | * @param callback Calls the {@link ToBooleanFunction#apply} method for each window found and |
| 1067 | * stops the search if {@link ToBooleanFunction#apply} returns true. |
| 1068 | * @param traverseTopToBottom If true traverses the hierarchy from top-to-bottom in terms of |
| 1069 | * z-order, else from bottom-to-top. |
| 1070 | * @return True if the search ended before we reached the end of the hierarchy due to |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 1071 | * {@link ToBooleanFunction#apply} returning true. |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 1072 | */ |
| 1073 | boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 1074 | if (traverseTopToBottom) { |
| 1075 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 1076 | if (mChildren.get(i).forAllWindows(callback, traverseTopToBottom)) { |
| 1077 | return true; |
| 1078 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 1079 | } |
| 1080 | } else { |
| 1081 | final int count = mChildren.size(); |
| 1082 | for (int i = 0; i < count; i++) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 1083 | if (mChildren.get(i).forAllWindows(callback, traverseTopToBottom)) { |
| 1084 | return true; |
| 1085 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 1086 | } |
| 1087 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 1088 | return false; |
| 1089 | } |
| 1090 | |
| 1091 | void forAllWindows(Consumer<WindowState> callback, boolean traverseTopToBottom) { |
Wale Ogunwale | ee41d4a | 2016-11-21 08:41:10 -0800 | [diff] [blame] | 1092 | ForAllWindowsConsumerWrapper wrapper = obtainConsumerWrapper(callback); |
| 1093 | forAllWindows(wrapper, traverseTopToBottom); |
| 1094 | wrapper.release(); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 1095 | } |
| 1096 | |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 1097 | boolean forAllActivities(ToBooleanFunction<ActivityRecord> callback) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1098 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 1099 | if (mChildren.get(i).forAllActivities(callback)) { |
| 1100 | return true; |
| 1101 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1102 | } |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 1103 | return false; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1104 | } |
| 1105 | |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 1106 | void forAllWallpaperWindows(Consumer<WallpaperWindowToken> callback) { |
| 1107 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1108 | mChildren.get(i).forAllWallpaperWindows(callback); |
| 1109 | } |
| 1110 | } |
| 1111 | |
Jorim Jaggi | 51304d7 | 2017-05-17 17:25:32 +0200 | [diff] [blame] | 1112 | /** |
| 1113 | * For all tasks at or below this container call the callback. |
| 1114 | * |
| 1115 | * @param callback Callback to be called for every task. |
| 1116 | */ |
| 1117 | void forAllTasks(Consumer<Task> callback) { |
| 1118 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1119 | mChildren.get(i).forAllTasks(callback); |
| 1120 | } |
| 1121 | } |
| 1122 | |
lumark | bc0032a | 2019-11-01 21:38:13 +0800 | [diff] [blame] | 1123 | /** |
| 1124 | * For all tasks at or below this container call the callback. |
| 1125 | * |
| 1126 | * @param callback Calls the {@link ToBooleanFunction#apply} method for each task found and |
| 1127 | * stops the search if {@link ToBooleanFunction#apply} returns {@code true}. |
| 1128 | */ |
| 1129 | boolean forAllTasks(ToBooleanFunction<Task> callback) { |
| 1130 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1131 | if (mChildren.get(i).forAllTasks(callback)) { |
| 1132 | return true; |
| 1133 | } |
| 1134 | } |
| 1135 | return false; |
| 1136 | } |
| 1137 | |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 1138 | WindowState getWindow(Predicate<WindowState> callback) { |
| 1139 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1140 | final WindowState w = mChildren.get(i).getWindow(callback); |
| 1141 | if (w != null) { |
| 1142 | return w; |
| 1143 | } |
| 1144 | } |
| 1145 | |
| 1146 | return null; |
| 1147 | } |
| 1148 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1149 | /** |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 1150 | * Returns 1, 0, or -1 depending on if this container is greater than, equal to, or lesser than |
| 1151 | * the input container in terms of z-order. |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1152 | */ |
| 1153 | @Override |
| 1154 | public int compareTo(WindowContainer other) { |
| 1155 | if (this == other) { |
| 1156 | return 0; |
| 1157 | } |
| 1158 | |
| 1159 | if (mParent != null && mParent == other.mParent) { |
Jorim Jaggi | 612bb88 | 2017-05-16 17:11:18 +0200 | [diff] [blame] | 1160 | final WindowList<WindowContainer> list = mParent.mChildren; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1161 | return list.indexOf(this) > list.indexOf(other) ? 1 : -1; |
| 1162 | } |
| 1163 | |
| 1164 | final LinkedList<WindowContainer> thisParentChain = mTmpChain1; |
| 1165 | final LinkedList<WindowContainer> otherParentChain = mTmpChain2; |
Jorim Jaggi | 4448e1e | 2017-05-16 22:26:02 +0200 | [diff] [blame] | 1166 | try { |
| 1167 | getParents(thisParentChain); |
| 1168 | other.getParents(otherParentChain); |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1169 | |
Jorim Jaggi | 4448e1e | 2017-05-16 22:26:02 +0200 | [diff] [blame] | 1170 | // Find the common ancestor of both containers. |
| 1171 | WindowContainer commonAncestor = null; |
| 1172 | WindowContainer thisTop = thisParentChain.peekLast(); |
| 1173 | WindowContainer otherTop = otherParentChain.peekLast(); |
| 1174 | while (thisTop != null && otherTop != null && thisTop == otherTop) { |
| 1175 | commonAncestor = thisParentChain.removeLast(); |
| 1176 | otherParentChain.removeLast(); |
| 1177 | thisTop = thisParentChain.peekLast(); |
| 1178 | otherTop = otherParentChain.peekLast(); |
| 1179 | } |
| 1180 | |
| 1181 | // Containers don't belong to the same hierarchy??? |
| 1182 | if (commonAncestor == null) { |
| 1183 | throw new IllegalArgumentException("No in the same hierarchy this=" |
| 1184 | + thisParentChain + " other=" + otherParentChain); |
| 1185 | } |
| 1186 | |
| 1187 | // Children are always considered greater than their parents, so if one of the containers |
| 1188 | // we are comparing it the parent of the other then whichever is the child is greater. |
| 1189 | if (commonAncestor == this) { |
| 1190 | return -1; |
| 1191 | } else if (commonAncestor == other) { |
| 1192 | return 1; |
| 1193 | } |
| 1194 | |
| 1195 | // The position of the first non-common ancestor in the common ancestor list determines |
| 1196 | // which is greater the which. |
| 1197 | final WindowList<WindowContainer> list = commonAncestor.mChildren; |
| 1198 | return list.indexOf(thisParentChain.peekLast()) > list.indexOf(otherParentChain.peekLast()) |
| 1199 | ? 1 : -1; |
| 1200 | } finally { |
| 1201 | mTmpChain1.clear(); |
| 1202 | mTmpChain2.clear(); |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1203 | } |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | private void getParents(LinkedList<WindowContainer> parents) { |
| 1207 | parents.clear(); |
| 1208 | WindowContainer current = this; |
| 1209 | do { |
| 1210 | parents.addLast(current); |
| 1211 | current = current.mParent; |
| 1212 | } while (current != null); |
| 1213 | } |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1214 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1215 | SurfaceControl.Builder makeSurface() { |
| 1216 | final WindowContainer p = getParent(); |
| 1217 | return p.makeChildSurface(this); |
| 1218 | } |
| 1219 | |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 1220 | /** |
| 1221 | * @param child The WindowContainer this child surface is for, or null if the Surface |
| 1222 | * is not assosciated with a WindowContainer (e.g. a surface used for Dimming). |
| 1223 | */ |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1224 | SurfaceControl.Builder makeChildSurface(WindowContainer child) { |
| 1225 | final WindowContainer p = getParent(); |
| 1226 | // Give the parent a chance to set properties. In hierarchy v1 we rely |
| 1227 | // on this to set full-screen dimensions on all our Surface-less Layers. |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 1228 | return p.makeChildSurface(child) |
| 1229 | .setParent(mSurfaceControl); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1230 | } |
Robert Carr | dea7bf4 | 2019-04-04 12:02:51 -0700 | [diff] [blame] | 1231 | /* |
| 1232 | * @return The SurfaceControl parent for this containers SurfaceControl. |
| 1233 | * The SurfaceControl must be valid if non-null. |
| 1234 | */ |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1235 | @Override |
| 1236 | public SurfaceControl getParentSurfaceControl() { |
| 1237 | final WindowContainer parent = getParent(); |
| 1238 | if (parent == null) { |
| 1239 | return null; |
| 1240 | } |
| 1241 | return parent.getSurfaceControl(); |
| 1242 | } |
| 1243 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1244 | /** |
| 1245 | * @return Whether this WindowContainer should be magnified by the accessibility magnifier. |
| 1246 | */ |
| 1247 | boolean shouldMagnify() { |
Yuki Awano | 4c36b55 | 2018-04-24 17:27:50 +0900 | [diff] [blame] | 1248 | if (mSurfaceControl == null) { |
| 1249 | return false; |
| 1250 | } |
| 1251 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1252 | for (int i = 0; i < mChildren.size(); i++) { |
| 1253 | if (!mChildren.get(i).shouldMagnify()) { |
| 1254 | return false; |
| 1255 | } |
| 1256 | } |
| 1257 | return true; |
| 1258 | } |
| 1259 | |
| 1260 | SurfaceSession getSession() { |
| 1261 | if (getParent() != null) { |
| 1262 | return getParent().getSession(); |
| 1263 | } |
| 1264 | return null; |
| 1265 | } |
| 1266 | |
| 1267 | void assignLayer(Transaction t, int layer) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1268 | final boolean changed = layer != mLastLayer || mLastRelativeToLayer != null; |
| 1269 | if (mSurfaceControl != null && changed) { |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 1270 | setLayer(t, layer); |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1271 | mLastLayer = layer; |
| 1272 | mLastRelativeToLayer = null; |
| 1273 | } |
| 1274 | } |
| 1275 | |
| 1276 | void assignRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) { |
| 1277 | final boolean changed = layer != mLastLayer || mLastRelativeToLayer != relativeTo; |
| 1278 | if (mSurfaceControl != null && changed) { |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 1279 | setRelativeLayer(t, relativeTo, layer); |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1280 | mLastLayer = layer; |
| 1281 | mLastRelativeToLayer = relativeTo; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1282 | } |
| 1283 | } |
| 1284 | |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 1285 | protected void setLayer(Transaction t, int layer) { |
| 1286 | |
| 1287 | // Route through surface animator to accommodate that our surface control might be |
| 1288 | // attached to the leash, and leash is attached to parent container. |
| 1289 | mSurfaceAnimator.setLayer(t, layer); |
| 1290 | } |
| 1291 | |
| 1292 | protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) { |
| 1293 | |
| 1294 | // Route through surface animator to accommodate that our surface control might be |
| 1295 | // attached to the leash, and leash is attached to parent container. |
| 1296 | mSurfaceAnimator.setRelativeLayer(t, relativeTo, layer); |
| 1297 | } |
| 1298 | |
| 1299 | protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) { |
| 1300 | mSurfaceAnimator.reparent(t, newParent); |
| 1301 | } |
| 1302 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1303 | void assignChildLayers(Transaction t) { |
| 1304 | int layer = 0; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1305 | |
| 1306 | // We use two passes as a way to promote children which |
| 1307 | // need Z-boosting to the end of the list. |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1308 | for (int j = 0; j < mChildren.size(); ++j) { |
| 1309 | final WindowContainer wc = mChildren.get(j); |
| 1310 | wc.assignChildLayers(t); |
| 1311 | if (!wc.needsZBoost()) { |
| 1312 | wc.assignLayer(t, layer++); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1313 | } |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1314 | } |
| 1315 | for (int j = 0; j < mChildren.size(); ++j) { |
| 1316 | final WindowContainer wc = mChildren.get(j); |
| 1317 | if (wc.needsZBoost()) { |
| 1318 | wc.assignLayer(t, layer++); |
| 1319 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | void assignChildLayers() { |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 1324 | assignChildLayers(getPendingTransaction()); |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1325 | scheduleAnimation(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | boolean needsZBoost() { |
| 1329 | for (int i = 0; i < mChildren.size(); i++) { |
| 1330 | if (mChildren.get(i).needsZBoost()) { |
| 1331 | return true; |
| 1332 | } |
| 1333 | } |
| 1334 | return false; |
| 1335 | } |
| 1336 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1337 | /** |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 1338 | * Write to a protocol buffer output stream. Protocol buffer message definition is at |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 1339 | * {@link com.android.server.wm.WindowContainerProto}. |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 1340 | * |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 1341 | * @param proto Stream to write the WindowContainer object to. |
| 1342 | * @param fieldId Field Id of the WindowContainer as defined in the parent message. |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 1343 | * @param logLevel Determines the amount of data to be written to the Protobuf. |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 1344 | * @hide |
| 1345 | */ |
| 1346 | @CallSuper |
| 1347 | @Override |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 1348 | public void writeToProto(ProtoOutputStream proto, long fieldId, |
| 1349 | @WindowTraceLogLevel int logLevel) { |
| 1350 | boolean isVisible = isVisible(); |
| 1351 | if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible) { |
| 1352 | return; |
| 1353 | } |
| 1354 | |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 1355 | final long token = proto.start(fieldId); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 1356 | super.writeToProto(proto, CONFIGURATION_CONTAINER, logLevel); |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 1357 | proto.write(ORIENTATION, mOrientation); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 1358 | proto.write(VISIBLE, isVisible); |
| 1359 | if (mSurfaceAnimator.isAnimating()) { |
| 1360 | mSurfaceAnimator.writeToProto(proto, SURFACE_ANIMATOR); |
| 1361 | } |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 1362 | proto.end(token); |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 1363 | } |
| 1364 | |
Wale Ogunwale | ee41d4a | 2016-11-21 08:41:10 -0800 | [diff] [blame] | 1365 | private ForAllWindowsConsumerWrapper obtainConsumerWrapper(Consumer<WindowState> consumer) { |
| 1366 | ForAllWindowsConsumerWrapper wrapper = mConsumerWrapperPool.acquire(); |
| 1367 | if (wrapper == null) { |
| 1368 | wrapper = new ForAllWindowsConsumerWrapper(); |
| 1369 | } |
| 1370 | wrapper.setConsumer(consumer); |
| 1371 | return wrapper; |
| 1372 | } |
| 1373 | |
| 1374 | private final class ForAllWindowsConsumerWrapper implements ToBooleanFunction<WindowState> { |
| 1375 | |
| 1376 | private Consumer<WindowState> mConsumer; |
| 1377 | |
| 1378 | void setConsumer(Consumer<WindowState> consumer) { |
| 1379 | mConsumer = consumer; |
| 1380 | } |
| 1381 | |
| 1382 | @Override |
| 1383 | public boolean apply(WindowState w) { |
| 1384 | mConsumer.accept(w); |
| 1385 | return false; |
| 1386 | } |
| 1387 | |
| 1388 | void release() { |
| 1389 | mConsumer = null; |
| 1390 | mConsumerWrapperPool.release(this); |
| 1391 | } |
| 1392 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1393 | |
| 1394 | // TODO(b/68336570): Should this really be on WindowContainer since it |
| 1395 | // can only be used on the top-level nodes that aren't animated? |
| 1396 | // (otherwise we would be fighting other callers of setMatrix). |
| 1397 | void applyMagnificationSpec(Transaction t, MagnificationSpec spec) { |
| 1398 | if (shouldMagnify()) { |
| 1399 | t.setMatrix(mSurfaceControl, spec.scale, 0, 0, spec.scale) |
| 1400 | .setPosition(mSurfaceControl, spec.offsetX, spec.offsetY); |
| 1401 | } else { |
| 1402 | for (int i = 0; i < mChildren.size(); i++) { |
| 1403 | mChildren.get(i).applyMagnificationSpec(t, spec); |
| 1404 | } |
| 1405 | } |
| 1406 | } |
| 1407 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1408 | void prepareSurfaces() { |
chaviw | 7f1fa99 | 2018-01-10 13:52:12 -0800 | [diff] [blame] | 1409 | // If a leash has been set when the transaction was committed, then the leash reparent has |
| 1410 | // been committed. |
| 1411 | mCommittedReparentToAnimationLeash = mSurfaceAnimator.hasLeash(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1412 | for (int i = 0; i < mChildren.size(); i++) { |
| 1413 | mChildren.get(i).prepareSurfaces(); |
| 1414 | } |
| 1415 | } |
| 1416 | |
| 1417 | /** |
chaviw | 7f1fa99 | 2018-01-10 13:52:12 -0800 | [diff] [blame] | 1418 | * @return true if the reparent to animation leash transaction has been committed, false |
| 1419 | * otherwise. |
| 1420 | */ |
| 1421 | boolean hasCommittedReparentToAnimationLeash() { |
| 1422 | return mCommittedReparentToAnimationLeash; |
| 1423 | } |
| 1424 | |
| 1425 | /** |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 1426 | * Trigger a call to prepareSurfaces from the animation thread, such that pending transactions |
| 1427 | * will be applied. |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1428 | */ |
| 1429 | void scheduleAnimation() { |
| 1430 | if (mParent != null) { |
| 1431 | mParent.scheduleAnimation(); |
| 1432 | } |
| 1433 | } |
| 1434 | |
Robert Carr | dea7bf4 | 2019-04-04 12:02:51 -0700 | [diff] [blame] | 1435 | /** |
| 1436 | * @return The SurfaceControl for this container. |
| 1437 | * The SurfaceControl must be valid if non-null. |
| 1438 | */ |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1439 | @Override |
| 1440 | public SurfaceControl getSurfaceControl() { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1441 | return mSurfaceControl; |
| 1442 | } |
| 1443 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1444 | @Override |
| 1445 | public Transaction getPendingTransaction() { |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 1446 | final DisplayContent displayContent = getDisplayContent(); |
| 1447 | if (displayContent != null && displayContent != this) { |
| 1448 | return displayContent.getPendingTransaction(); |
| 1449 | } |
| 1450 | // This WindowContainer has not attached to a display yet or this is a DisplayContent, so we |
| 1451 | // let the caller to save the surface operations within the local mPendingTransaction. |
| 1452 | // If this is not a DisplayContent, we will merge it to the pending transaction of its |
| 1453 | // display once it attaches to it. |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 1454 | return mPendingTransaction; |
| 1455 | } |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1456 | |
| 1457 | /** |
| 1458 | * Starts an animation on the container. |
| 1459 | * |
| 1460 | * @param anim The animation to run. |
| 1461 | * @param hidden Whether our container is currently hidden. TODO This should use isVisible at |
| 1462 | * some point but the meaning is too weird to work for all containers. |
| 1463 | */ |
| 1464 | void startAnimation(Transaction t, AnimationAdapter anim, boolean hidden) { |
| 1465 | if (DEBUG_ANIM) Slog.v(TAG, "Starting animation on " + this + ": " + anim); |
| 1466 | |
| 1467 | // TODO: This should use isVisible() but because isVisible has a really weird meaning at |
| 1468 | // the moment this doesn't work for all animatable window containers. |
| 1469 | mSurfaceAnimator.startAnimation(t, anim, hidden); |
| 1470 | } |
| 1471 | |
Jorim Jaggi | 980c9de | 2017-11-17 01:41:37 +0100 | [diff] [blame] | 1472 | void transferAnimation(WindowContainer from) { |
| 1473 | mSurfaceAnimator.transferAnimation(from.mSurfaceAnimator); |
| 1474 | } |
| 1475 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1476 | void cancelAnimation() { |
| 1477 | mSurfaceAnimator.cancelAnimation(); |
| 1478 | } |
| 1479 | |
| 1480 | @Override |
| 1481 | public Builder makeAnimationLeash() { |
| 1482 | return makeSurface(); |
| 1483 | } |
| 1484 | |
Jorim Jaggi | 596a199 | 2017-12-29 14:48:02 +0100 | [diff] [blame] | 1485 | @Override |
| 1486 | public SurfaceControl getAnimationLeashParent() { |
| 1487 | return getParentSurfaceControl(); |
| 1488 | } |
| 1489 | |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 1490 | /** |
| 1491 | * @return The layer on which all app animations are happening. |
| 1492 | */ |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 1493 | SurfaceControl getAppAnimationLayer(@AnimationLayer int animationLayer) { |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 1494 | final WindowContainer parent = getParent(); |
| 1495 | if (parent != null) { |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 1496 | return parent.getAppAnimationLayer(animationLayer); |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 1497 | } |
| 1498 | return null; |
| 1499 | } |
| 1500 | |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 1501 | // TODO: Remove this and use #getBounds() instead once we set an app transition animation |
| 1502 | // on TaskStack. |
| 1503 | Rect getAnimationBounds(int appStackClipMode) { |
| 1504 | return getBounds(); |
| 1505 | } |
| 1506 | |
| 1507 | /** |
| 1508 | * Applies the app transition animation according the given the layout properties in the |
| 1509 | * window hierarchy. |
| 1510 | * |
| 1511 | * @param lp The layout parameters of the window. |
| 1512 | * @param transit The app transition type indicates what kind of transition to be applied. |
| 1513 | * @param enter Whether the app transition is entering transition or not. |
| 1514 | * @param isVoiceInteraction Whether the container is participating in voice interaction or not. |
| 1515 | * |
| 1516 | * @return {@code true} when the container applied the app transition, {@code false} if the |
| 1517 | * app transition is disabled or skipped. |
| 1518 | * |
| 1519 | * @see #getAnimationAdapter |
| 1520 | */ |
| 1521 | boolean applyAnimation(WindowManager.LayoutParams lp, int transit, boolean enter, |
| 1522 | boolean isVoiceInteraction) { |
| 1523 | if (mWmService.mDisableTransitionAnimation) { |
| 1524 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS_ANIM, |
| 1525 | "applyAnimation: transition animation is disabled or skipped. " |
| 1526 | + "container=%s", this); |
| 1527 | cancelAnimation(); |
| 1528 | return false; |
| 1529 | } |
| 1530 | |
| 1531 | // Only apply an animation if the display isn't frozen. If it is frozen, there is no reason |
| 1532 | // to animate and it can cause strange artifacts when we unfreeze the display if some |
| 1533 | // different animation is running. |
| 1534 | try { |
| 1535 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "WC#applyAnimation"); |
| 1536 | if (okToAnimate()) { |
lumark | bc0032a | 2019-11-01 21:38:13 +0800 | [diff] [blame] | 1537 | final Pair<AnimationAdapter, AnimationAdapter> adapters = getAnimationAdapter(lp, |
| 1538 | transit, enter, isVoiceInteraction); |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 1539 | AnimationAdapter adapter = adapters.first; |
| 1540 | AnimationAdapter thumbnailAdapter = adapters.second; |
| 1541 | if (adapter != null) { |
| 1542 | startAnimation(getPendingTransaction(), adapter, !isVisible()); |
| 1543 | if (adapter.getShowWallpaper()) { |
| 1544 | mDisplayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 1545 | } |
| 1546 | if (thumbnailAdapter != null) { |
| 1547 | mThumbnail.startAnimation( |
| 1548 | getPendingTransaction(), thumbnailAdapter, !isVisible()); |
| 1549 | } |
| 1550 | } |
| 1551 | } else { |
| 1552 | cancelAnimation(); |
| 1553 | } |
| 1554 | } finally { |
| 1555 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 1556 | } |
| 1557 | |
| 1558 | return isAnimating(); |
| 1559 | } |
| 1560 | |
| 1561 | /** |
| 1562 | * Gets the {@link AnimationAdapter} according the given window layout properties in the window |
| 1563 | * hierarchy. |
| 1564 | * |
| 1565 | * @return The return value will always contain two elements, one for normal animations and the |
| 1566 | * other for thumbnail animation, both can be {@code null}. |
| 1567 | * |
| 1568 | * @See com.android.server.wm.RemoteAnimationController.RemoteAnimationRecord |
| 1569 | * @See LocalAnimationAdapter |
| 1570 | */ |
| 1571 | Pair<AnimationAdapter, AnimationAdapter> getAnimationAdapter(WindowManager.LayoutParams lp, |
| 1572 | int transit, boolean enter, boolean isVoiceInteraction) { |
| 1573 | final Pair<AnimationAdapter, AnimationAdapter> resultAdapters; |
| 1574 | final int appStackClipMode = getDisplayContent().mAppTransition.getAppStackClipMode(); |
| 1575 | |
| 1576 | // Separate position and size for use in animators. |
| 1577 | mTmpRect.set(getAnimationBounds(appStackClipMode)); |
| 1578 | mTmpPoint.set(mTmpRect.left, mTmpRect.top); |
| 1579 | mTmpRect.offsetTo(0, 0); |
| 1580 | |
| 1581 | final RemoteAnimationController controller = |
| 1582 | getDisplayContent().mAppTransition.getRemoteAnimationController(); |
| 1583 | final boolean isChanging = AppTransition.isChangeTransit(transit) && enter |
| 1584 | && isChangingAppTransition(); |
| 1585 | |
| 1586 | // Delaying animation start isn't compatible with remote animations at all. |
| 1587 | if (controller != null && !mSurfaceAnimator.isAnimationStartDelayed()) { |
| 1588 | final RemoteAnimationController.RemoteAnimationRecord adapters = |
| 1589 | controller.createRemoteAnimationRecord(this, mTmpPoint, mTmpRect, |
| 1590 | (isChanging ? mTransitStartRect : null)); |
| 1591 | resultAdapters = new Pair<>(adapters.mAdapter, adapters.mThumbnailAdapter); |
| 1592 | } else if (isChanging) { |
| 1593 | final float durationScale = mWmService.getTransitionAnimationScaleLocked(); |
| 1594 | final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo(); |
| 1595 | mTmpRect.offsetTo(mTmpPoint.x, mTmpPoint.y); |
| 1596 | |
lumark | bc0032a | 2019-11-01 21:38:13 +0800 | [diff] [blame] | 1597 | final AnimationAdapter adapter = new LocalAnimationAdapter( |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 1598 | new WindowChangeAnimationSpec(mTransitStartRect, mTmpRect, displayInfo, |
| 1599 | durationScale, true /* isAppAnimation */, false /* isThumbnail */), |
| 1600 | getSurfaceAnimationRunner()); |
| 1601 | |
lumark | bc0032a | 2019-11-01 21:38:13 +0800 | [diff] [blame] | 1602 | final AnimationAdapter thumbnailAdapter = mThumbnail != null |
| 1603 | ? new LocalAnimationAdapter(new WindowChangeAnimationSpec(mTransitStartRect, |
| 1604 | mTmpRect, displayInfo, durationScale, true /* isAppAnimation */, |
| 1605 | true /* isThumbnail */), getSurfaceAnimationRunner()) |
| 1606 | : null; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 1607 | resultAdapters = new Pair<>(adapter, thumbnailAdapter); |
| 1608 | mTransit = transit; |
| 1609 | mTransitFlags = getDisplayContent().mAppTransition.getTransitFlags(); |
| 1610 | } else { |
| 1611 | mNeedsAnimationBoundsLayer = (appStackClipMode == STACK_CLIP_AFTER_ANIM); |
| 1612 | final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction); |
| 1613 | |
| 1614 | if (a != null) { |
| 1615 | // Only apply corner radius to animation if we're not in multi window mode. |
| 1616 | // We don't want rounded corners when in pip or split screen. |
| 1617 | final float windowCornerRadius = !inMultiWindowMode() |
| 1618 | ? getDisplayContent().getWindowCornerRadius() |
| 1619 | : 0; |
| 1620 | AnimationAdapter adapter = new LocalAnimationAdapter( |
| 1621 | new WindowAnimationSpec(a, mTmpPoint, mTmpRect, |
| 1622 | getDisplayContent().mAppTransition.canSkipFirstFrame(), |
| 1623 | appStackClipMode, true /* isAppAnimation */, windowCornerRadius), |
| 1624 | getSurfaceAnimationRunner()); |
| 1625 | |
| 1626 | resultAdapters = new Pair<>(adapter, null); |
| 1627 | mNeedsZBoost = a.getZAdjustment() == Animation.ZORDER_TOP; |
| 1628 | mTransit = transit; |
| 1629 | mTransitFlags = getDisplayContent().mAppTransition.getTransitFlags(); |
| 1630 | } else { |
| 1631 | resultAdapters = new Pair<>(null, null); |
| 1632 | } |
| 1633 | } |
| 1634 | return resultAdapters; |
| 1635 | } |
| 1636 | |
| 1637 | final SurfaceAnimationRunner getSurfaceAnimationRunner() { |
| 1638 | return mWmService.mSurfaceAnimationRunner; |
| 1639 | } |
| 1640 | |
| 1641 | private Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter, |
| 1642 | boolean isVoiceInteraction) { |
| 1643 | final DisplayContent displayContent = getDisplayContent(); |
| 1644 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 1645 | final int width = displayInfo.appWidth; |
| 1646 | final int height = displayInfo.appHeight; |
| 1647 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS_ANIM, "applyAnimation: container=%s", this); |
| 1648 | |
| 1649 | // Determine the visible rect to calculate the thumbnail clip with |
| 1650 | // getAnimationFrames. |
| 1651 | final Rect frame = new Rect(0, 0, width, height); |
| 1652 | final Rect displayFrame = new Rect(0, 0, |
| 1653 | displayInfo.logicalWidth, displayInfo.logicalHeight); |
| 1654 | final Rect insets = new Rect(); |
| 1655 | final Rect stableInsets = new Rect(); |
| 1656 | final Rect surfaceInsets = new Rect(); |
| 1657 | getAnimationFrames(frame, insets, stableInsets, surfaceInsets); |
| 1658 | |
| 1659 | if (mLaunchTaskBehind) { |
| 1660 | // Differentiate the two animations. This one which is briefly on the screen |
| 1661 | // gets the !enter animation, and the other one which remains on the |
| 1662 | // screen gets the enter animation. Both appear in the mOpeningApps set. |
| 1663 | enter = false; |
| 1664 | } |
| 1665 | ProtoLog.d(WM_DEBUG_APP_TRANSITIONS, |
| 1666 | "Loading animation for app transition. transit=%s enter=%b frame=%s insets=%s " |
| 1667 | + "surfaceInsets=%s", |
| 1668 | AppTransition.appTransitionToString(transit), enter, frame, insets, surfaceInsets); |
| 1669 | final Configuration displayConfig = displayContent.getConfiguration(); |
| 1670 | final Animation a = getDisplayContent().mAppTransition.loadAnimation(lp, transit, enter, |
| 1671 | displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets, |
| 1672 | surfaceInsets, stableInsets, isVoiceInteraction, inFreeformWindowingMode(), this); |
| 1673 | if (a != null) { |
| 1674 | if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this); |
| 1675 | final int containingWidth = frame.width(); |
| 1676 | final int containingHeight = frame.height(); |
| 1677 | a.initialize(containingWidth, containingHeight, width, height); |
| 1678 | a.scaleCurrentDuration(mWmService.getTransitionAnimationScaleLocked()); |
| 1679 | } |
| 1680 | return a; |
| 1681 | } |
| 1682 | |
| 1683 | RemoteAnimationTarget createRemoteAnimationTarget( |
| 1684 | RemoteAnimationController.RemoteAnimationRecord record) { |
| 1685 | return null; |
| 1686 | } |
| 1687 | |
| 1688 | boolean okToDisplay() { |
| 1689 | return mDisplayContent != null && mDisplayContent.okToDisplay(); |
| 1690 | } |
| 1691 | |
| 1692 | boolean okToAnimate() { |
| 1693 | return mDisplayContent != null && mDisplayContent.okToAnimate(); |
| 1694 | } |
| 1695 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1696 | @Override |
| 1697 | public void commitPendingTransaction() { |
| 1698 | scheduleAnimation(); |
| 1699 | } |
| 1700 | |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 1701 | void reassignLayer(Transaction t) { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1702 | final WindowContainer parent = getParent(); |
| 1703 | if (parent != null) { |
| 1704 | parent.assignChildLayers(t); |
| 1705 | } |
| 1706 | } |
| 1707 | |
| 1708 | @Override |
| 1709 | public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) { |
Robert Carr | f12f9d3 | 2018-03-01 15:24:36 -0800 | [diff] [blame] | 1710 | mLastLayer = -1; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1711 | reassignLayer(t); |
| 1712 | } |
| 1713 | |
| 1714 | @Override |
lumark | f6f3494 | 2019-04-29 16:56:50 +0800 | [diff] [blame] | 1715 | public void onAnimationLeashLost(Transaction t) { |
Robert Carr | f12f9d3 | 2018-03-01 15:24:36 -0800 | [diff] [blame] | 1716 | mLastLayer = -1; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1717 | reassignLayer(t); |
| 1718 | } |
| 1719 | |
| 1720 | /** |
| 1721 | * Called when an animation has finished running. |
| 1722 | */ |
| 1723 | protected void onAnimationFinished() { |
chaviw | ccd5d50 | 2019-02-22 13:30:31 -0800 | [diff] [blame] | 1724 | mWmService.onAnimationFinished(); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | /** |
| 1728 | * @return The currently running animation, if any, or {@code null} otherwise. |
| 1729 | */ |
| 1730 | AnimationAdapter getAnimation() { |
| 1731 | return mSurfaceAnimator.getAnimation(); |
| 1732 | } |
| 1733 | |
| 1734 | /** |
| 1735 | * @see SurfaceAnimator#startDelayingAnimationStart |
| 1736 | */ |
| 1737 | void startDelayingAnimationStart() { |
| 1738 | mSurfaceAnimator.startDelayingAnimationStart(); |
| 1739 | } |
| 1740 | |
| 1741 | /** |
| 1742 | * @see SurfaceAnimator#endDelayingAnimationStart |
| 1743 | */ |
| 1744 | void endDelayingAnimationStart() { |
| 1745 | mSurfaceAnimator.endDelayingAnimationStart(); |
| 1746 | } |
| 1747 | |
| 1748 | @Override |
| 1749 | public int getSurfaceWidth() { |
| 1750 | return mSurfaceControl.getWidth(); |
| 1751 | } |
| 1752 | |
| 1753 | @Override |
| 1754 | public int getSurfaceHeight() { |
| 1755 | return mSurfaceControl.getHeight(); |
| 1756 | } |
| 1757 | |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 1758 | @CallSuper |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1759 | void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
| 1760 | if (mSurfaceAnimator.isAnimating()) { |
| 1761 | pw.print(prefix); pw.println("ContainerAnimator:"); |
| 1762 | mSurfaceAnimator.dump(pw, prefix + " "); |
| 1763 | } |
| 1764 | } |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 1765 | |
chaviw | 2f0567b | 2018-01-29 16:22:02 -0800 | [diff] [blame] | 1766 | void updateSurfacePosition() { |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 1767 | if (mSurfaceControl == null) { |
| 1768 | return; |
| 1769 | } |
| 1770 | |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 1771 | getRelativeDisplayedPosition(mTmpPos); |
chaviw | 3e751af | 2018-01-11 11:22:39 -0800 | [diff] [blame] | 1772 | if (mTmpPos.equals(mLastSurfacePosition)) { |
| 1773 | return; |
| 1774 | } |
| 1775 | |
chaviw | 2f0567b | 2018-01-29 16:22:02 -0800 | [diff] [blame] | 1776 | getPendingTransaction().setPosition(mSurfaceControl, mTmpPos.x, mTmpPos.y); |
chaviw | 3e751af | 2018-01-11 11:22:39 -0800 | [diff] [blame] | 1777 | mLastSurfacePosition.set(mTmpPos.x, mTmpPos.y); |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 1778 | } |
| 1779 | |
Evan Rosky | 65dffa6 | 2019-02-04 14:09:53 -0800 | [diff] [blame] | 1780 | @VisibleForTesting |
Evan Rosky | 89f5c1d | 2019-01-29 10:04:05 -0800 | [diff] [blame] | 1781 | Point getLastSurfacePosition() { |
| 1782 | return mLastSurfacePosition; |
| 1783 | } |
| 1784 | |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 1785 | /** |
| 1786 | * Displayed bounds specify where to display this container at. It differs from bounds during |
| 1787 | * certain operations (like animation or interactive dragging). |
| 1788 | * |
| 1789 | * @return the bounds to display this container at. |
| 1790 | */ |
| 1791 | Rect getDisplayedBounds() { |
| 1792 | return getBounds(); |
| 1793 | } |
| 1794 | |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 1795 | /** |
| 1796 | * The {@code outFrame} retrieved by this method specifies where the animation will finish |
| 1797 | * the entrance animation, as the next frame will display the window at these coordinates. In |
| 1798 | * case of exit animation, this is where the animation will start, as the frame before the |
| 1799 | * animation is displaying the window at these bounds. |
| 1800 | * |
| 1801 | * @param outFrame The bounds where entrance animation finishes or exit animation starts. |
| 1802 | * @param outInsets Insets that are covered by system windows. |
| 1803 | * @param outStableInsets Insets that determine the area covered by the stable system windows. |
| 1804 | * @param outSurfaceInsets Positive insets between the drawing surface and window content. |
| 1805 | */ |
| 1806 | void getAnimationFrames(Rect outFrame, Rect outInsets, Rect outStableInsets, |
| 1807 | Rect outSurfaceInsets) { |
| 1808 | final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo(); |
| 1809 | outFrame.set(0, 0, displayInfo.appWidth, displayInfo.appHeight); |
| 1810 | outInsets.setEmpty(); |
| 1811 | outStableInsets.setEmpty(); |
| 1812 | outSurfaceInsets.setEmpty(); |
| 1813 | } |
| 1814 | |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 1815 | void getRelativeDisplayedPosition(Point outPos) { |
| 1816 | final Rect dispBounds = getDisplayedBounds(); |
| 1817 | outPos.set(dispBounds.left, dispBounds.top); |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 1818 | final WindowContainer parent = getParent(); |
| 1819 | if (parent != null) { |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 1820 | final Rect parentBounds = parent.getDisplayedBounds(); |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 1821 | outPos.offset(-parentBounds.left, -parentBounds.top); |
| 1822 | } |
| 1823 | } |
chaviw | 2fb06bc | 2018-01-19 17:09:15 -0800 | [diff] [blame] | 1824 | |
Yunfan Chen | 87b5a24 | 2019-10-01 17:53:59 +0900 | [diff] [blame] | 1825 | void waitForAllWindowsDrawn() { |
| 1826 | final WindowManagerPolicy policy = mWmService.mPolicy; |
| 1827 | forAllWindows(w -> { |
| 1828 | final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1829 | if (w.isVisibleLw() && (w.mActivityRecord != null || keyguard)) { |
Yunfan Chen | 87b5a24 | 2019-10-01 17:53:59 +0900 | [diff] [blame] | 1830 | w.mWinAnimator.mDrawState = DRAW_PENDING; |
| 1831 | // Force add to mResizingWindows. |
| 1832 | w.resetLastContentInsets(); |
| 1833 | mWaitingForDrawn.add(w); |
| 1834 | } |
| 1835 | }, true /* traverseTopToBottom */); |
| 1836 | } |
| 1837 | |
chaviw | 2fb06bc | 2018-01-19 17:09:15 -0800 | [diff] [blame] | 1838 | Dimmer getDimmer() { |
| 1839 | if (mParent == null) { |
| 1840 | return null; |
| 1841 | } |
| 1842 | return mParent.getDimmer(); |
| 1843 | } |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 1844 | } |