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