lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
| 19 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 20 | import static android.view.WindowManager.TRANSIT_ACTIVITY_CLOSE; |
| 21 | import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN; |
Evan Rosky | 7735d35 | 2019-03-18 17:27:27 -0700 | [diff] [blame] | 22 | import static android.view.WindowManager.TRANSIT_ACTIVITY_RELAUNCH; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 23 | import static android.view.WindowManager.TRANSIT_CRASHING_ACTIVITY_CLOSE; |
| 24 | import static android.view.WindowManager.TRANSIT_DOCK_TASK_FROM_RECENTS; |
| 25 | import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION; |
Issei Suzuki | 5609ccb | 2019-06-13 15:04:08 +0200 | [diff] [blame] | 26 | import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_SUBTLE_ANIMATION; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 27 | import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE; |
| 28 | import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER; |
| 29 | import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY; |
| 30 | import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER; |
| 31 | import static android.view.WindowManager.TRANSIT_NONE; |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 32 | import static android.view.WindowManager.TRANSIT_SHOW_SINGLE_TASK_DISPLAY; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 33 | import static android.view.WindowManager.TRANSIT_TASK_CLOSE; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 34 | import static android.view.WindowManager.TRANSIT_TASK_OPEN; |
| 35 | import static android.view.WindowManager.TRANSIT_TASK_TO_BACK; |
| 36 | import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT; |
| 37 | import static android.view.WindowManager.TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE; |
| 38 | import static android.view.WindowManager.TRANSIT_TRANSLUCENT_ACTIVITY_OPEN; |
| 39 | import static android.view.WindowManager.TRANSIT_WALLPAPER_CLOSE; |
| 40 | import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 41 | import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 42 | import static android.view.WindowManager.TRANSIT_WALLPAPER_OPEN; |
| 43 | |
| 44 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; |
| 45 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; |
| 46 | import static com.android.server.wm.ActivityTaskManagerInternal.APP_TRANSITION_SNAPSHOT; |
| 47 | import static com.android.server.wm.ActivityTaskManagerInternal.APP_TRANSITION_SPLASH_SCREEN; |
| 48 | import static com.android.server.wm.ActivityTaskManagerInternal.APP_TRANSITION_WINDOWS_DRAWN; |
| 49 | import static com.android.server.wm.AppTransition.isKeyguardGoingAwayTransit; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 50 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_APP_TRANSITIONS; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 51 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS; |
| 52 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 53 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 54 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 55 | import android.os.Trace; |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 56 | import android.util.ArrayMap; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 57 | import android.util.ArraySet; |
| 58 | import android.util.Slog; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 59 | import android.view.Display; |
| 60 | import android.view.RemoteAnimationAdapter; |
| 61 | import android.view.RemoteAnimationDefinition; |
| 62 | import android.view.WindowManager; |
| 63 | import android.view.WindowManager.LayoutParams; |
| 64 | import android.view.animation.Animation; |
| 65 | |
| 66 | import com.android.internal.annotations.VisibleForTesting; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 67 | import com.android.server.protolog.common.ProtoLog; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 68 | |
| 69 | import java.util.function.Predicate; |
| 70 | |
| 71 | |
| 72 | /** |
| 73 | * Checks for app transition readiness, resolves animation attributes and performs visibility |
| 74 | * change for apps that animate as part of an app transition. |
| 75 | */ |
| 76 | public class AppTransitionController { |
| 77 | private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransitionController" : TAG_WM; |
| 78 | private final WindowManagerService mService; |
| 79 | private final DisplayContent mDisplayContent; |
| 80 | private final WallpaperController mWallpaperControllerLocked; |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 81 | private RemoteAnimationDefinition mRemoteAnimationDefinition = null; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 82 | |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 83 | private final ArrayMap<ActivityRecord, Integer> mTempTransitionReasons = new ArrayMap<>(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 84 | |
| 85 | AppTransitionController(WindowManagerService service, DisplayContent displayContent) { |
| 86 | mService = service; |
| 87 | mDisplayContent = displayContent; |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 88 | mWallpaperControllerLocked = mDisplayContent.mWallpaperController; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 89 | } |
| 90 | |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 91 | void registerRemoteAnimations(RemoteAnimationDefinition definition) { |
| 92 | mRemoteAnimationDefinition = definition; |
| 93 | } |
| 94 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 95 | /** |
| 96 | * Handle application transition for given display. |
| 97 | */ |
| 98 | void handleAppTransitionReady() { |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 99 | mTempTransitionReasons.clear(); |
| 100 | if (!transitionGoodToGo(mDisplayContent.mOpeningApps, mTempTransitionReasons) |
| 101 | || !transitionGoodToGo(mDisplayContent.mChangingApps, mTempTransitionReasons)) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 102 | return; |
| 103 | } |
| 104 | Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "AppTransitionReady"); |
| 105 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 106 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, "**** GOOD TO GO"); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 107 | final AppTransition appTransition = mDisplayContent.mAppTransition; |
| 108 | int transit = appTransition.getAppTransition(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 109 | if (mDisplayContent.mSkipAppTransitionAnimation && !isKeyguardGoingAwayTransit(transit)) { |
| 110 | transit = WindowManager.TRANSIT_UNSET; |
| 111 | } |
| 112 | mDisplayContent.mSkipAppTransitionAnimation = false; |
| 113 | mDisplayContent.mNoAnimationNotifyOnTransitionFinished.clear(); |
| 114 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 115 | appTransition.removeAppTransitionTimeoutCallbacks(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 116 | |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 117 | mDisplayContent.mWallpaperMayChange = false; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 118 | |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 119 | int appCount = mDisplayContent.mOpeningApps.size(); |
| 120 | for (int i = 0; i < appCount; ++i) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 121 | // Clearing the mAnimatingExit flag before entering animation. It's set to true if app |
| 122 | // window is removed, or window relayout to invisible. This also affects window |
| 123 | // visibility. We need to clear it *before* maybeUpdateTransitToWallpaper() as the |
| 124 | // transition selection depends on wallpaper target visibility. |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 125 | mDisplayContent.mOpeningApps.valueAtUnchecked(i).clearAnimatingFlags(); |
| 126 | } |
| 127 | appCount = mDisplayContent.mChangingApps.size(); |
| 128 | for (int i = 0; i < appCount; ++i) { |
| 129 | // Clearing for same reason as above. |
| 130 | mDisplayContent.mChangingApps.valueAtUnchecked(i).clearAnimatingFlags(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | // Adjust wallpaper before we pull the lower/upper target, since pending changes |
| 134 | // (like the clearAnimatingFlags() above) might affect wallpaper target result. |
| 135 | // Or, the opening app window should be a wallpaper target. |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 136 | mWallpaperControllerLocked.adjustWallpaperWindowsForAppTransitionIfNeeded( |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 137 | mDisplayContent.mOpeningApps, mDisplayContent.mChangingApps); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 138 | |
| 139 | // Determine if closing and opening app token sets are wallpaper targets, in which case |
| 140 | // special animations are needed. |
| 141 | final boolean hasWallpaperTarget = mWallpaperControllerLocked.getWallpaperTarget() != null; |
| 142 | final boolean openingAppHasWallpaper = canBeWallpaperTarget(mDisplayContent.mOpeningApps) |
| 143 | && hasWallpaperTarget; |
| 144 | final boolean closingAppHasWallpaper = canBeWallpaperTarget(mDisplayContent.mClosingApps) |
| 145 | && hasWallpaperTarget; |
| 146 | |
| 147 | transit = maybeUpdateTransitToTranslucentAnim(transit); |
| 148 | transit = maybeUpdateTransitToWallpaper(transit, openingAppHasWallpaper, |
| 149 | closingAppHasWallpaper); |
| 150 | |
| 151 | // Find the layout params of the top-most application window in the tokens, which is |
| 152 | // what will control the animation theme. If all closing windows are obscured, then there is |
| 153 | // no need to do an animation. This is the case, for example, when this transition is being |
| 154 | // done behind a dream window. |
| 155 | final ArraySet<Integer> activityTypes = collectActivityTypes(mDisplayContent.mOpeningApps, |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 156 | mDisplayContent.mClosingApps, mDisplayContent.mChangingApps); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 157 | final boolean allowAnimations = mDisplayContent.getDisplayPolicy().allowAppAnimationsLw(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 158 | final ActivityRecord animLpActivity = allowAnimations |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 159 | ? findAnimLayoutParamsToken(transit, activityTypes) |
| 160 | : null; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 161 | final ActivityRecord topOpeningApp = allowAnimations |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 162 | ? getTopApp(mDisplayContent.mOpeningApps, false /* ignoreHidden */) |
| 163 | : null; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 164 | final ActivityRecord topClosingApp = allowAnimations |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 165 | ? getTopApp(mDisplayContent.mClosingApps, false /* ignoreHidden */) |
| 166 | : null; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 167 | final ActivityRecord topChangingApp = allowAnimations |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 168 | ? getTopApp(mDisplayContent.mChangingApps, false /* ignoreHidden */) |
| 169 | : null; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 170 | final WindowManager.LayoutParams animLp = getAnimLp(animLpActivity); |
| 171 | overrideWithRemoteAnimationIfSet(animLpActivity, transit, activityTypes); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 172 | |
| 173 | final boolean voiceInteraction = containsVoiceInteraction(mDisplayContent.mOpeningApps) |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 174 | || containsVoiceInteraction(mDisplayContent.mOpeningApps) |
| 175 | || containsVoiceInteraction(mDisplayContent.mChangingApps); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 176 | |
| 177 | final int layoutRedo; |
| 178 | mService.mSurfaceAnimationRunner.deferStartingAnimations(); |
| 179 | try { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 180 | handleClosingApps(transit, animLp, voiceInteraction); |
| 181 | handleOpeningApps(transit, animLp, voiceInteraction); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 182 | handleChangingApps(transit, animLp, voiceInteraction); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 183 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 184 | appTransition.setLastAppTransition(transit, topOpeningApp, |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 185 | topClosingApp, topChangingApp); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 186 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 187 | final int flags = appTransition.getTransitFlags(); |
| 188 | layoutRedo = appTransition.goodToGo(transit, topOpeningApp, |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 189 | mDisplayContent.mOpeningApps); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 190 | handleNonAppWindowsInTransition(transit, flags); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 191 | appTransition.postAnimationCallback(); |
| 192 | appTransition.clear(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 193 | } finally { |
| 194 | mService.mSurfaceAnimationRunner.continueStartingAnimations(); |
| 195 | } |
| 196 | |
| 197 | mService.mTaskSnapshotController.onTransitionStarting(mDisplayContent); |
| 198 | |
| 199 | mDisplayContent.mOpeningApps.clear(); |
| 200 | mDisplayContent.mClosingApps.clear(); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 201 | mDisplayContent.mChangingApps.clear(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 202 | mDisplayContent.mUnknownAppVisibilityController.clear(); |
| 203 | |
| 204 | // This has changed the visibility of windows, so perform |
| 205 | // a new layout to get them all up-to-date. |
| 206 | mDisplayContent.setLayoutNeeded(); |
| 207 | |
| 208 | mDisplayContent.computeImeTarget(true /* updateImeTarget */); |
| 209 | |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 210 | mService.mAtmService.mStackSupervisor.getActivityMetricsLogger().notifyTransitionStarting( |
| 211 | mTempTransitionReasons); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 212 | |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 213 | if (transit == TRANSIT_SHOW_SINGLE_TASK_DISPLAY) { |
| 214 | mService.mAnimator.addAfterPrepareSurfacesRunnable(() -> { |
| 215 | mService.mAtmInternal.notifySingleTaskDisplayDrawn(mDisplayContent.getDisplayId()); |
| 216 | }); |
| 217 | } |
| 218 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 219 | Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); |
| 220 | |
| 221 | mDisplayContent.pendingLayoutChanges |= |
| 222 | layoutRedo | FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_CONFIG; |
| 223 | } |
| 224 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 225 | private static WindowManager.LayoutParams getAnimLp(ActivityRecord activity) { |
| 226 | final WindowState mainWindow = activity != null ? activity.findMainWindow() : null; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 227 | return mainWindow != null ? mainWindow.mAttrs : null; |
| 228 | } |
| 229 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 230 | RemoteAnimationAdapter getRemoteAnimationOverride(ActivityRecord animLpActivity, int transit, |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 231 | ArraySet<Integer> activityTypes) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 232 | final RemoteAnimationDefinition definition = animLpActivity.getRemoteAnimationDefinition(); |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 233 | if (definition != null) { |
| 234 | final RemoteAnimationAdapter adapter = definition.getAdapter(transit, activityTypes); |
| 235 | if (adapter != null) { |
| 236 | return adapter; |
| 237 | } |
| 238 | } |
| 239 | if (mRemoteAnimationDefinition == null) { |
| 240 | return null; |
| 241 | } |
| 242 | return mRemoteAnimationDefinition.getAdapter(transit, activityTypes); |
| 243 | } |
| 244 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 245 | /** |
| 246 | * Overrides the pending transition with the remote animation defined for the transition in the |
| 247 | * set of defined remote animations in the app window token. |
| 248 | */ |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 249 | private void overrideWithRemoteAnimationIfSet(ActivityRecord animLpActivity, int transit, |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 250 | ArraySet<Integer> activityTypes) { |
| 251 | if (transit == TRANSIT_CRASHING_ACTIVITY_CLOSE) { |
| 252 | // The crash transition has higher priority than any involved remote animations. |
| 253 | return; |
| 254 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 255 | if (animLpActivity == null) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 256 | return; |
| 257 | } |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 258 | final RemoteAnimationAdapter adapter = |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 259 | getRemoteAnimationOverride(animLpActivity, transit, activityTypes); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 260 | if (adapter != null) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 261 | animLpActivity.getDisplayContent().mAppTransition.overridePendingAppTransitionRemote( |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 262 | adapter); |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * @return The window token that determines the animation theme. |
| 268 | */ |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 269 | private ActivityRecord findAnimLayoutParamsToken(@WindowManager.TransitionType int transit, |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 270 | ArraySet<Integer> activityTypes) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 271 | ActivityRecord result; |
| 272 | final ArraySet<ActivityRecord> closingApps = mDisplayContent.mClosingApps; |
| 273 | final ArraySet<ActivityRecord> openingApps = mDisplayContent.mOpeningApps; |
| 274 | final ArraySet<ActivityRecord> changingApps = mDisplayContent.mChangingApps; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 275 | |
| 276 | // Remote animations always win, but fullscreen tokens override non-fullscreen tokens. |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 277 | result = lookForHighestTokenWithFilter(closingApps, openingApps, changingApps, |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 278 | w -> w.getRemoteAnimationDefinition() != null |
| 279 | && w.getRemoteAnimationDefinition().hasTransition(transit, activityTypes)); |
| 280 | if (result != null) { |
| 281 | return result; |
| 282 | } |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 283 | result = lookForHighestTokenWithFilter(closingApps, openingApps, changingApps, |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 284 | w -> w.fillsParent() && w.findMainWindow() != null); |
| 285 | if (result != null) { |
| 286 | return result; |
| 287 | } |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 288 | return lookForHighestTokenWithFilter(closingApps, openingApps, changingApps, |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 289 | w -> w.findMainWindow() != null); |
| 290 | } |
| 291 | |
| 292 | /** |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 293 | * @return The set of {@link android.app.WindowConfiguration.ActivityType}s contained in the set |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 294 | * of apps in {@code array1}, {@code array2}, and {@code array3}. |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 295 | */ |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 296 | private static ArraySet<Integer> collectActivityTypes(ArraySet<ActivityRecord> array1, |
| 297 | ArraySet<ActivityRecord> array2, ArraySet<ActivityRecord> array3) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 298 | final ArraySet<Integer> result = new ArraySet<>(); |
| 299 | for (int i = array1.size() - 1; i >= 0; i--) { |
| 300 | result.add(array1.valueAt(i).getActivityType()); |
| 301 | } |
| 302 | for (int i = array2.size() - 1; i >= 0; i--) { |
| 303 | result.add(array2.valueAt(i).getActivityType()); |
| 304 | } |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 305 | for (int i = array3.size() - 1; i >= 0; i--) { |
| 306 | result.add(array3.valueAt(i).getActivityType()); |
| 307 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 308 | return result; |
| 309 | } |
| 310 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 311 | private static ActivityRecord lookForHighestTokenWithFilter(ArraySet<ActivityRecord> array1, |
| 312 | ArraySet<ActivityRecord> array2, ArraySet<ActivityRecord> array3, |
| 313 | Predicate<ActivityRecord> filter) { |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 314 | final int array2base = array1.size(); |
| 315 | final int array3base = array2.size() + array2base; |
| 316 | final int count = array3base + array3.size(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 317 | int bestPrefixOrderIndex = Integer.MIN_VALUE; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 318 | ActivityRecord bestToken = null; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 319 | for (int i = 0; i < count; i++) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 320 | final ActivityRecord wtoken = i < array2base |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 321 | ? array1.valueAt(i) |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 322 | : (i < array3base |
| 323 | ? array2.valueAt(i - array2base) |
| 324 | : array3.valueAt(i - array3base)); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 325 | final int prefixOrderIndex = wtoken.getPrefixOrderIndex(); |
| 326 | if (filter.test(wtoken) && prefixOrderIndex > bestPrefixOrderIndex) { |
| 327 | bestPrefixOrderIndex = prefixOrderIndex; |
| 328 | bestToken = wtoken; |
| 329 | } |
| 330 | } |
| 331 | return bestToken; |
| 332 | } |
| 333 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 334 | private boolean containsVoiceInteraction(ArraySet<ActivityRecord> apps) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 335 | for (int i = apps.size() - 1; i >= 0; i--) { |
| 336 | if (apps.valueAt(i).mVoiceInteraction) { |
| 337 | return true; |
| 338 | } |
| 339 | } |
| 340 | return false; |
| 341 | } |
| 342 | |
| 343 | private void handleOpeningApps(int transit, LayoutParams animLp, boolean voiceInteraction) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 344 | final ArraySet<ActivityRecord> openingApps = mDisplayContent.mOpeningApps; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 345 | final int appsCount = openingApps.size(); |
| 346 | for (int i = 0; i < appsCount; i++) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 347 | ActivityRecord wtoken = openingApps.valueAt(i); |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 348 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, "Now opening app %s", wtoken); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 349 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 350 | if (!wtoken.commitVisibility(animLp, true, transit, false, voiceInteraction)) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 351 | // This token isn't going to be animating. Add it to the list of tokens to |
| 352 | // be notified of app transition complete since the notification will not be |
| 353 | // sent be the app window animator. |
| 354 | mDisplayContent.mNoAnimationNotifyOnTransitionFinished.add(wtoken.token); |
| 355 | } |
| 356 | wtoken.updateReportedVisibilityLocked(); |
| 357 | wtoken.waitingToShow = false; |
| 358 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 359 | ">>> OPEN TRANSACTION handleAppTransitionReady()"); |
| 360 | mService.openSurfaceTransaction(); |
| 361 | try { |
| 362 | wtoken.showAllWindowsLocked(); |
| 363 | } finally { |
| 364 | mService.closeSurfaceTransaction("handleAppTransitionReady"); |
| 365 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 366 | "<<< CLOSE TRANSACTION handleAppTransitionReady()"); |
| 367 | } |
| 368 | |
| 369 | if (mDisplayContent.mAppTransition.isNextAppTransitionThumbnailUp()) { |
| 370 | wtoken.attachThumbnailAnimation(); |
| 371 | } else if (mDisplayContent.mAppTransition.isNextAppTransitionOpenCrossProfileApps()) { |
| 372 | wtoken.attachCrossProfileAppsThumbnailAnimation(); |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | private void handleClosingApps(int transit, LayoutParams animLp, boolean voiceInteraction) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 378 | final ArraySet<ActivityRecord> closingApps = mDisplayContent.mClosingApps; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 379 | final int appsCount = closingApps.size(); |
| 380 | for (int i = 0; i < appsCount; i++) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 381 | ActivityRecord wtoken = closingApps.valueAt(i); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 382 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 383 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, "Now closing app %s", wtoken); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 384 | // TODO: Do we need to add to mNoAnimationNotifyOnTransitionFinished like above if not |
| 385 | // animating? |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 386 | wtoken.commitVisibility(animLp, false, transit, false, voiceInteraction); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 387 | wtoken.updateReportedVisibilityLocked(); |
| 388 | // Force the allDrawn flag, because we want to start |
| 389 | // this guy's animations regardless of whether it's |
| 390 | // gotten drawn. |
| 391 | wtoken.allDrawn = true; |
| 392 | wtoken.deferClearAllDrawn = false; |
| 393 | // Ensure that apps that are mid-starting are also scheduled to have their |
| 394 | // starting windows removed after the animation is complete |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 395 | if (wtoken.startingWindow != null && !wtoken.startingWindow.mAnimatingExit) { |
| 396 | wtoken.removeStartingWindow(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | if (mDisplayContent.mAppTransition.isNextAppTransitionThumbnailDown()) { |
| 400 | wtoken.attachThumbnailAnimation(); |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 405 | private void handleChangingApps(int transit, LayoutParams animLp, boolean voiceInteraction) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 406 | final ArraySet<ActivityRecord> apps = mDisplayContent.mChangingApps; |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 407 | final int appsCount = apps.size(); |
| 408 | for (int i = 0; i < appsCount; i++) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 409 | ActivityRecord activity = apps.valueAt(i); |
| 410 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, "Now changing app %s", activity); |
| 411 | activity.cancelAnimationOnly(); |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 412 | activity.applyAnimation(null, transit, true, false); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 413 | activity.updateReportedVisibilityLocked(); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 414 | mService.openSurfaceTransaction(); |
| 415 | try { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 416 | activity.showAllWindowsLocked(); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 417 | } finally { |
| 418 | mService.closeSurfaceTransaction("handleChangingApps"); |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 423 | private void handleNonAppWindowsInTransition(int transit, int flags) { |
| 424 | if (transit == TRANSIT_KEYGUARD_GOING_AWAY) { |
| 425 | if ((flags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER) != 0 |
Issei Suzuki | 5609ccb | 2019-06-13 15:04:08 +0200 | [diff] [blame] | 426 | && (flags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) == 0 |
| 427 | && (flags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_SUBTLE_ANIMATION) == 0) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 428 | Animation anim = mService.mPolicy.createKeyguardWallpaperExit( |
| 429 | (flags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0); |
| 430 | if (anim != null) { |
| 431 | mDisplayContent.mWallpaperController.startWallpaperAnimation(anim); |
| 432 | } |
| 433 | } |
| 434 | } |
| 435 | if (transit == TRANSIT_KEYGUARD_GOING_AWAY |
| 436 | || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) { |
| 437 | mDisplayContent.startKeyguardExitOnNonAppWindows( |
| 438 | transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, |
Issei Suzuki | 5609ccb | 2019-06-13 15:04:08 +0200 | [diff] [blame] | 439 | (flags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0, |
| 440 | (flags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_SUBTLE_ANIMATION) != 0); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 444 | private boolean transitionGoodToGo(ArraySet<ActivityRecord> apps, |
| 445 | ArrayMap<ActivityRecord, Integer> outReasons) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 446 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, |
| 447 | "Checking %d opening apps (frozen=%b timeout=%b)...", apps.size(), |
| 448 | mService.mDisplayFrozen, mDisplayContent.mAppTransition.isTimeout()); |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 449 | |
| 450 | final ScreenRotationAnimation screenRotationAnimation = mService.mRoot.getDisplayContent( |
| 451 | Display.DEFAULT_DISPLAY).getRotationAnimation(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 452 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 453 | if (!mDisplayContent.mAppTransition.isTimeout()) { |
| 454 | // Imagine the case where we are changing orientation due to an app transition, but a |
| 455 | // previous orientation change is still in progress. We won't process the orientation |
| 456 | // change for our transition because we need to wait for the rotation animation to |
| 457 | // finish. |
| 458 | // If we start the app transition at this point, we will interrupt it halfway with a |
| 459 | // new rotation animation after the old one finally finishes. It's better to defer the |
| 460 | // app transition. |
| 461 | if (screenRotationAnimation != null && screenRotationAnimation.isAnimating() && |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 462 | mDisplayContent.getDisplayRotation().needsUpdate()) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 463 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, |
| 464 | "Delaying app transition for screen rotation animation to finish"); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 465 | return false; |
| 466 | } |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 467 | for (int i = 0; i < apps.size(); i++) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 468 | ActivityRecord activity = apps.valueAt(i); |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 469 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, |
| 470 | "Check opening app=%s: allDrawn=%b startingDisplayed=%b " |
| 471 | + "startingMoved=%b isRelaunching()=%b startingWindow=%s", |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 472 | activity, activity.allDrawn, activity.startingDisplayed, |
| 473 | activity.startingMoved, activity.isRelaunching(), |
| 474 | activity.startingWindow); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 475 | |
| 476 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 477 | final boolean allDrawn = activity.allDrawn && !activity.isRelaunching(); |
| 478 | if (!allDrawn && !activity.startingDisplayed && !activity.startingMoved) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 479 | return false; |
| 480 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 481 | if (allDrawn) { |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 482 | outReasons.put(activity, APP_TRANSITION_WINDOWS_DRAWN); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 483 | } else { |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 484 | outReasons.put(activity, |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 485 | activity.mStartingData instanceof SplashScreenStartingData |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 486 | ? APP_TRANSITION_SPLASH_SCREEN |
| 487 | : APP_TRANSITION_SNAPSHOT); |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | // We also need to wait for the specs to be fetched, if needed. |
| 492 | if (mDisplayContent.mAppTransition.isFetchingAppTransitionsSpecs()) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 493 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, "isFetchingAppTransitionSpecs=true"); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 494 | return false; |
| 495 | } |
| 496 | |
| 497 | if (!mDisplayContent.mUnknownAppVisibilityController.allResolved()) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 498 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, "unknownApps is not empty: %s", |
| 499 | mDisplayContent.mUnknownAppVisibilityController.getDebugMessage()); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 500 | return false; |
| 501 | } |
| 502 | |
| 503 | // If the wallpaper is visible, we need to check it's ready too. |
| 504 | boolean wallpaperReady = !mWallpaperControllerLocked.isWallpaperVisible() || |
| 505 | mWallpaperControllerLocked.wallpaperTransitionReady(); |
| 506 | if (wallpaperReady) { |
| 507 | return true; |
| 508 | } |
| 509 | return false; |
| 510 | } |
| 511 | return true; |
| 512 | } |
| 513 | |
| 514 | private int maybeUpdateTransitToWallpaper(int transit, boolean openingAppHasWallpaper, |
| 515 | boolean closingAppHasWallpaper) { |
| 516 | // Given no app transition pass it through instead of a wallpaper transition. |
| 517 | // Never convert the crashing transition. |
| 518 | // Never update the transition for the wallpaper if we are just docking from recents |
Evan Rosky | ec9488c | 2019-03-01 19:32:12 -0800 | [diff] [blame] | 519 | // Never convert a change transition since the top activity isn't changing and will likely |
| 520 | // still be above an opening wallpaper. |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 521 | if (transit == TRANSIT_NONE || transit == TRANSIT_CRASHING_ACTIVITY_CLOSE |
Evan Rosky | ec9488c | 2019-03-01 19:32:12 -0800 | [diff] [blame] | 522 | || transit == TRANSIT_DOCK_TASK_FROM_RECENTS |
| 523 | || AppTransition.isChangeTransit(transit)) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 524 | return transit; |
| 525 | } |
| 526 | |
| 527 | final WindowState wallpaperTarget = mWallpaperControllerLocked.getWallpaperTarget(); |
| 528 | final boolean showWallpaper = wallpaperTarget != null |
| 529 | && (wallpaperTarget.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
| 530 | // If wallpaper is animating or wallpaperTarget doesn't have SHOW_WALLPAPER flag set, |
| 531 | // don't consider upgrading to wallpaper transition. |
| 532 | final WindowState oldWallpaper = |
| 533 | (mWallpaperControllerLocked.isWallpaperTargetAnimating() || !showWallpaper) |
| 534 | ? null |
| 535 | : wallpaperTarget; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 536 | final ArraySet<ActivityRecord> openingApps = mDisplayContent.mOpeningApps; |
| 537 | final ArraySet<ActivityRecord> closingApps = mDisplayContent.mClosingApps; |
| 538 | final ActivityRecord topOpeningApp = getTopApp(mDisplayContent.mOpeningApps, |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 539 | false /* ignoreHidden */); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 540 | final ActivityRecord topClosingApp = getTopApp(mDisplayContent.mClosingApps, |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 541 | true /* ignoreHidden */); |
| 542 | |
| 543 | boolean openingCanBeWallpaperTarget = canBeWallpaperTarget(openingApps); |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 544 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, |
| 545 | "New wallpaper target=%s, oldWallpaper=%s, openingApps=%s, closingApps=%s", |
| 546 | wallpaperTarget, oldWallpaper, openingApps, closingApps); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 547 | |
| 548 | if (openingCanBeWallpaperTarget && transit == TRANSIT_KEYGUARD_GOING_AWAY) { |
| 549 | transit = TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 550 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, |
| 551 | "New transit: %s", AppTransition.appTransitionToString(transit)); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 552 | } |
| 553 | // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic |
| 554 | // relies on the fact that we always execute a Keyguard transition after preparing one. |
| 555 | else if (!isKeyguardGoingAwayTransit(transit)) { |
| 556 | if (closingAppHasWallpaper && openingAppHasWallpaper) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 557 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, "Wallpaper animation!"); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 558 | switch (transit) { |
| 559 | case TRANSIT_ACTIVITY_OPEN: |
| 560 | case TRANSIT_TASK_OPEN: |
| 561 | case TRANSIT_TASK_TO_FRONT: |
| 562 | transit = TRANSIT_WALLPAPER_INTRA_OPEN; |
| 563 | break; |
| 564 | case TRANSIT_ACTIVITY_CLOSE: |
| 565 | case TRANSIT_TASK_CLOSE: |
| 566 | case TRANSIT_TASK_TO_BACK: |
| 567 | transit = TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 568 | break; |
| 569 | } |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 570 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, |
| 571 | "New transit: %s", AppTransition.appTransitionToString(transit)); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 572 | } else if (oldWallpaper != null && !mDisplayContent.mOpeningApps.isEmpty() |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 573 | && !openingApps.contains(oldWallpaper.mActivityRecord) |
| 574 | && closingApps.contains(oldWallpaper.mActivityRecord) |
| 575 | && topClosingApp == oldWallpaper.mActivityRecord) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 576 | // We are transitioning from an activity with a wallpaper to one without. |
| 577 | transit = TRANSIT_WALLPAPER_CLOSE; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 578 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, |
| 579 | "New transit away from wallpaper: %s", |
| 580 | AppTransition.appTransitionToString(transit)); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 581 | } else if (wallpaperTarget != null && wallpaperTarget.isVisibleLw() |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 582 | && openingApps.contains(wallpaperTarget.mActivityRecord) |
| 583 | && topOpeningApp == wallpaperTarget.mActivityRecord |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 584 | && transit != TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE) { |
| 585 | // We are transitioning from an activity without |
| 586 | // a wallpaper to now showing the wallpaper |
| 587 | transit = TRANSIT_WALLPAPER_OPEN; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 588 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, "New transit into wallpaper: %s", |
| 589 | AppTransition.appTransitionToString(transit)); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 590 | } |
| 591 | } |
| 592 | return transit; |
| 593 | } |
| 594 | |
| 595 | /** |
| 596 | * There are cases where we open/close a new task/activity, but in reality only a translucent |
| 597 | * activity on top of existing activities is opening/closing. For that one, we have a different |
| 598 | * animation because non of the task/activity animations actually work well with translucent |
| 599 | * apps. |
| 600 | * |
| 601 | * @param transit The current transition type. |
| 602 | * @return The current transition type or |
| 603 | * {@link WindowManager#TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE}/ |
| 604 | * {@link WindowManager#TRANSIT_TRANSLUCENT_ACTIVITY_OPEN} if appropriate for the |
| 605 | * situation. |
| 606 | */ |
| 607 | @VisibleForTesting |
| 608 | int maybeUpdateTransitToTranslucentAnim(int transit) { |
Evan Rosky | ec9488c | 2019-03-01 19:32:12 -0800 | [diff] [blame] | 609 | if (AppTransition.isChangeTransit(transit)) { |
| 610 | // There's no special animation to handle change animations with translucent apps |
| 611 | return transit; |
| 612 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 613 | final boolean taskOrActivity = AppTransition.isTaskTransit(transit) |
| 614 | || AppTransition.isActivityTransit(transit); |
| 615 | boolean allOpeningVisible = true; |
| 616 | boolean allTranslucentOpeningApps = !mDisplayContent.mOpeningApps.isEmpty(); |
| 617 | for (int i = mDisplayContent.mOpeningApps.size() - 1; i >= 0; i--) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 618 | final ActivityRecord activity = mDisplayContent.mOpeningApps.valueAt(i); |
| 619 | if (!activity.isVisible()) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 620 | allOpeningVisible = false; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 621 | if (activity.fillsParent()) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 622 | allTranslucentOpeningApps = false; |
| 623 | } |
| 624 | } |
| 625 | } |
| 626 | boolean allTranslucentClosingApps = !mDisplayContent.mClosingApps.isEmpty(); |
| 627 | for (int i = mDisplayContent.mClosingApps.size() - 1; i >= 0; i--) { |
| 628 | if (mDisplayContent.mClosingApps.valueAt(i).fillsParent()) { |
| 629 | allTranslucentClosingApps = false; |
| 630 | break; |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | if (taskOrActivity && allTranslucentClosingApps && allOpeningVisible) { |
| 635 | return TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE; |
| 636 | } |
| 637 | if (taskOrActivity && allTranslucentOpeningApps && mDisplayContent.mClosingApps.isEmpty()) { |
| 638 | return TRANSIT_TRANSLUCENT_ACTIVITY_OPEN; |
| 639 | } |
| 640 | return transit; |
| 641 | } |
| 642 | |
Evan Rosky | 7735d35 | 2019-03-18 17:27:27 -0700 | [diff] [blame] | 643 | /** |
| 644 | * Identifies whether the current transition occurs within a single task or not. This is used |
| 645 | * to determine whether animations should be clipped to the task bounds instead of stack bounds. |
| 646 | */ |
| 647 | @VisibleForTesting |
| 648 | boolean isTransitWithinTask(int transit, Task task) { |
| 649 | if (task == null |
| 650 | || !mDisplayContent.mChangingApps.isEmpty()) { |
| 651 | // if there is no task, then we can't constrain to the task. |
| 652 | // if anything is changing, it can animate outside its task. |
| 653 | return false; |
| 654 | } |
| 655 | if (!(transit == TRANSIT_ACTIVITY_OPEN |
| 656 | || transit == TRANSIT_ACTIVITY_CLOSE |
| 657 | || transit == TRANSIT_ACTIVITY_RELAUNCH)) { |
| 658 | // only activity-level transitions will be within-task. |
| 659 | return false; |
| 660 | } |
| 661 | // check that all components are in the task. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 662 | for (ActivityRecord activity : mDisplayContent.mOpeningApps) { |
Evan Rosky | 7735d35 | 2019-03-18 17:27:27 -0700 | [diff] [blame] | 663 | Task activityTask = activity.getTask(); |
| 664 | if (activityTask != task) { |
| 665 | return false; |
| 666 | } |
| 667 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 668 | for (ActivityRecord activity : mDisplayContent.mClosingApps) { |
Evan Rosky | 7735d35 | 2019-03-18 17:27:27 -0700 | [diff] [blame] | 669 | if (activity.getTask() != task) { |
| 670 | return false; |
| 671 | } |
| 672 | } |
| 673 | return true; |
| 674 | } |
| 675 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 676 | private boolean canBeWallpaperTarget(ArraySet<ActivityRecord> apps) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 677 | for (int i = apps.size() - 1; i >= 0; i--) { |
| 678 | if (apps.valueAt(i).windowsCanBeWallpaperTarget()) { |
| 679 | return true; |
| 680 | } |
| 681 | } |
| 682 | return false; |
| 683 | } |
| 684 | |
| 685 | /** |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 686 | * Finds the top app in a list of apps, using its {@link ActivityRecord#getPrefixOrderIndex} to |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 687 | * compare z-order. |
| 688 | * |
| 689 | * @param apps The list of apps to search. |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 690 | * @param ignoreInvisible If set to true, ignores apps that are not |
| 691 | * {@link ActivityRecord#isVisible}. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 692 | * @return The top {@link ActivityRecord}. |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 693 | */ |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 694 | private ActivityRecord getTopApp(ArraySet<ActivityRecord> apps, boolean ignoreInvisible) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 695 | int topPrefixOrderIndex = Integer.MIN_VALUE; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 696 | ActivityRecord topApp = null; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 697 | for (int i = apps.size() - 1; i >= 0; i--) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 698 | final ActivityRecord app = apps.valueAt(i); |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 699 | if (ignoreInvisible && !app.isVisible()) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 700 | continue; |
| 701 | } |
| 702 | final int prefixOrderIndex = app.getPrefixOrderIndex(); |
| 703 | if (prefixOrderIndex > topPrefixOrderIndex) { |
| 704 | topPrefixOrderIndex = prefixOrderIndex; |
| 705 | topApp = app; |
| 706 | } |
| 707 | } |
| 708 | return topApp; |
| 709 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 710 | } |