Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | */ |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 16 | |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
| 18 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 20 | import static android.app.ActivityManagerInternal.APP_TRANSITION_SNAPSHOT; |
| 21 | import static android.app.ActivityManagerInternal.APP_TRANSITION_SPLASH_SCREEN; |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 22 | import static android.app.ActivityManagerInternal.APP_TRANSITION_WINDOWS_DRAWN; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 23 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; |
| 24 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 25 | import static com.android.server.wm.AppTransition.TRANSIT_ACTIVITY_CLOSE; |
| 26 | import static com.android.server.wm.AppTransition.TRANSIT_ACTIVITY_OPEN; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 27 | import static com.android.server.wm.AppTransition.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION; |
| 28 | import static com.android.server.wm.AppTransition.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE; |
| 29 | import static com.android.server.wm.AppTransition.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER; |
| 30 | import static com.android.server.wm.AppTransition.TRANSIT_KEYGUARD_GOING_AWAY; |
| 31 | import static com.android.server.wm.AppTransition.TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER; |
Matthew Ng | 26a1cec | 2017-05-18 14:42:51 -0700 | [diff] [blame] | 32 | import static com.android.server.wm.AppTransition.TRANSIT_NONE; |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 33 | import static com.android.server.wm.AppTransition.TRANSIT_TASK_CLOSE; |
| 34 | import static com.android.server.wm.AppTransition.TRANSIT_TASK_IN_PLACE; |
| 35 | import static com.android.server.wm.AppTransition.TRANSIT_TASK_OPEN; |
| 36 | import static com.android.server.wm.AppTransition.TRANSIT_TASK_TO_BACK; |
| 37 | import static com.android.server.wm.AppTransition.TRANSIT_TASK_TO_FRONT; |
| 38 | import static com.android.server.wm.AppTransition.TRANSIT_WALLPAPER_CLOSE; |
| 39 | import static com.android.server.wm.AppTransition.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 40 | import static com.android.server.wm.AppTransition.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 41 | import static com.android.server.wm.AppTransition.TRANSIT_WALLPAPER_OPEN; |
Jorim Jaggi | a69243a | 2017-06-15 15:10:38 -0400 | [diff] [blame] | 42 | import static com.android.server.wm.AppTransition.isKeyguardGoingAwayTransit; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 43 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 44 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 45 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS; |
| 46 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS; |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 47 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 48 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 49 | import static com.android.server.wm.WindowManagerService.H.NOTIFY_APP_TRANSITION_STARTING; |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 50 | import static com.android.server.wm.WindowManagerService.H.REPORT_WINDOWS_CHANGE; |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 51 | import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD; |
| 52 | import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 53 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 54 | |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 55 | import android.content.res.Configuration; |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 56 | import android.graphics.GraphicBuffer; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 57 | import android.graphics.PixelFormat; |
| 58 | import android.graphics.Rect; |
Bryce Lee | e6c25d4 | 2017-05-31 10:27:42 -0700 | [diff] [blame] | 59 | import android.os.Binder; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 60 | import android.os.Debug; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 61 | import android.os.Trace; |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 62 | import android.util.ArraySet; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 63 | import android.util.Slog; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 64 | import android.util.SparseIntArray; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 65 | import android.view.Display; |
| 66 | import android.view.DisplayInfo; |
| 67 | import android.view.Surface; |
| 68 | import android.view.SurfaceControl; |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 69 | import android.view.WindowManager.LayoutParams; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 70 | import android.view.animation.Animation; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 71 | |
Jorim Jaggi | d75962e | 2016-05-03 15:10:03 -0700 | [diff] [blame] | 72 | import com.android.server.wm.WindowManagerService.H; |
| 73 | |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 74 | import java.io.PrintWriter; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 75 | import java.util.ArrayList; |
| 76 | |
| 77 | /** |
| 78 | * Positions windows and their surfaces. |
| 79 | * |
| 80 | * It sets positions of windows by calculating their frames and then applies this by positioning |
| 81 | * surfaces according to these frames. Z layer is still assigned withing WindowManagerService. |
| 82 | */ |
| 83 | class WindowSurfacePlacer { |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 84 | private static final String TAG = TAG_WITH_CLASS_NAME ? "WindowSurfacePlacer" : TAG_WM; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 85 | private final WindowManagerService mService; |
| 86 | private final WallpaperController mWallpaperControllerLocked; |
| 87 | |
| 88 | private boolean mInLayout = false; |
| 89 | |
| 90 | /** Only do a maximum of 6 repeated layouts. After that quit */ |
| 91 | private int mLayoutRepeatCount; |
| 92 | |
| 93 | static final int SET_UPDATE_ROTATION = 1 << 0; |
| 94 | static final int SET_WALLPAPER_MAY_CHANGE = 1 << 1; |
| 95 | static final int SET_FORCE_HIDING_CHANGED = 1 << 2; |
| 96 | static final int SET_ORIENTATION_CHANGE_COMPLETE = 1 << 3; |
| 97 | static final int SET_TURN_ON_SCREEN = 1 << 4; |
| 98 | static final int SET_WALLPAPER_ACTION_PENDING = 1 << 5; |
| 99 | |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 100 | private boolean mTraversalScheduled; |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 101 | private int mDeferDepth = 0; |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 102 | |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 103 | private static final class LayerAndToken { |
| 104 | public int layer; |
| 105 | public AppWindowToken token; |
| 106 | } |
| 107 | private final LayerAndToken mTmpLayerAndToken = new LayerAndToken(); |
| 108 | |
Jorim Jaggi | 3dac63a | 2016-03-01 12:37:07 +0100 | [diff] [blame] | 109 | private final ArrayList<SurfaceControl> mPendingDestroyingSurfaces = new ArrayList<>(); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 110 | private final SparseIntArray mTempTransitionReasons = new SparseIntArray(); |
Jorim Jaggi | 3dac63a | 2016-03-01 12:37:07 +0100 | [diff] [blame] | 111 | |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 112 | private final Runnable mPerformSurfacePlacement; |
| 113 | |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 114 | public WindowSurfacePlacer(WindowManagerService service) { |
| 115 | mService = service; |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 116 | mWallpaperControllerLocked = mService.mRoot.mWallpaperController; |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 117 | mPerformSurfacePlacement = () -> { |
| 118 | synchronized (mService.mWindowMap) { |
| 119 | performSurfacePlacement(); |
| 120 | } |
| 121 | }; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 124 | /** |
| 125 | * See {@link WindowManagerService#deferSurfaceLayout()} |
| 126 | */ |
| 127 | void deferLayout() { |
| 128 | mDeferDepth++; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * See {@link WindowManagerService#continueSurfaceLayout()} |
| 133 | */ |
| 134 | void continueLayout() { |
| 135 | mDeferDepth--; |
| 136 | if (mDeferDepth <= 0) { |
| 137 | performSurfacePlacement(); |
| 138 | } |
| 139 | } |
| 140 | |
Jorim Jaggi | 1f83308 | 2017-08-04 18:06:56 +0200 | [diff] [blame] | 141 | boolean isLayoutDeferred() { |
| 142 | return mDeferDepth > 0; |
| 143 | } |
| 144 | |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 145 | final void performSurfacePlacement() { |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 146 | performSurfacePlacement(false /* force */); |
| 147 | } |
| 148 | |
| 149 | final void performSurfacePlacement(boolean force) { |
| 150 | if (mDeferDepth > 0 && !force) { |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 151 | return; |
| 152 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 153 | int loopCount = 6; |
| 154 | do { |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 155 | mTraversalScheduled = false; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 156 | performSurfacePlacementLoop(); |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 157 | mService.mAnimationHandler.removeCallbacks(mPerformSurfacePlacement); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 158 | loopCount--; |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 159 | } while (mTraversalScheduled && loopCount > 0); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 160 | mService.mRoot.mWallpaperActionPending = false; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | private void performSurfacePlacementLoop() { |
| 164 | if (mInLayout) { |
| 165 | if (DEBUG) { |
| 166 | throw new RuntimeException("Recursive call!"); |
| 167 | } |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 168 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout. Callers=" |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 169 | + Debug.getCallers(3)); |
| 170 | return; |
| 171 | } |
| 172 | |
| 173 | if (mService.mWaitingForConfig) { |
| 174 | // Our configuration has changed (most likely rotation), but we |
| 175 | // don't yet have the complete configuration to report to |
| 176 | // applications. Don't do any window layout until we have it. |
| 177 | return; |
| 178 | } |
| 179 | |
| 180 | if (!mService.mDisplayReady) { |
| 181 | // Not yet initialized, nothing to do. |
| 182 | return; |
| 183 | } |
| 184 | |
| 185 | Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "wmLayout"); |
| 186 | mInLayout = true; |
| 187 | |
| 188 | boolean recoveringMemory = false; |
| 189 | if (!mService.mForceRemoves.isEmpty()) { |
| 190 | recoveringMemory = true; |
| 191 | // Wait a little bit for things to settle down, and off we go. |
| 192 | while (!mService.mForceRemoves.isEmpty()) { |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 193 | final WindowState ws = mService.mForceRemoves.remove(0); |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 194 | Slog.i(TAG, "Force removing: " + ws); |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 195 | ws.removeImmediately(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 196 | } |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 197 | Slog.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 198 | Object tmp = new Object(); |
| 199 | synchronized (tmp) { |
| 200 | try { |
| 201 | tmp.wait(250); |
| 202 | } catch (InterruptedException e) { |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | try { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 208 | mService.mRoot.performSurfacePlacement(recoveringMemory); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 209 | |
| 210 | mInLayout = false; |
| 211 | |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 212 | if (mService.mRoot.isLayoutNeeded()) { |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 213 | if (++mLayoutRepeatCount < 6) { |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 214 | requestTraversal(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 215 | } else { |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 216 | Slog.e(TAG, "Performed 6 layouts in a row. Skipping"); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 217 | mLayoutRepeatCount = 0; |
| 218 | } |
| 219 | } else { |
| 220 | mLayoutRepeatCount = 0; |
| 221 | } |
| 222 | |
| 223 | if (mService.mWindowsChanged && !mService.mWindowChangeListeners.isEmpty()) { |
| 224 | mService.mH.removeMessages(REPORT_WINDOWS_CHANGE); |
| 225 | mService.mH.sendEmptyMessage(REPORT_WINDOWS_CHANGE); |
| 226 | } |
| 227 | } catch (RuntimeException e) { |
| 228 | mInLayout = false; |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 229 | Slog.wtf(TAG, "Unhandled exception while laying out windows", e); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); |
| 233 | } |
| 234 | |
| 235 | void debugLayoutRepeats(final String msg, int pendingLayoutChanges) { |
| 236 | if (mLayoutRepeatCount >= LAYOUT_REPEAT_THRESHOLD) { |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 237 | Slog.v(TAG, "Layouts looping: " + msg + |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 238 | ", mPendingLayoutChanges = 0x" + Integer.toHexString(pendingLayoutChanges)); |
| 239 | } |
| 240 | } |
| 241 | |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 242 | boolean isInLayout() { |
| 243 | return mInLayout; |
| 244 | } |
| 245 | |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 246 | /** |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 247 | * @return bitmap indicating if another pass through layout must be made. |
| 248 | */ |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 249 | int handleAppTransitionReadyLocked() { |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 250 | int appsCount = mService.mOpeningApps.size(); |
Jorim Jaggi | dbaad38 | 2017-07-18 13:22:52 +0200 | [diff] [blame] | 251 | if (!transitionGoodToGo(appsCount, mTempTransitionReasons)) { |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 252 | return 0; |
| 253 | } |
Chong Zhang | 8784be6 | 2016-06-28 15:25:07 -0700 | [diff] [blame] | 254 | Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "AppTransitionReady"); |
| 255 | |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 256 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO"); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 257 | int transit = mService.mAppTransition.getAppTransition(); |
Jorim Jaggi | a69243a | 2017-06-15 15:10:38 -0400 | [diff] [blame] | 258 | if (mService.mSkipAppTransitionAnimation && !isKeyguardGoingAwayTransit(transit)) { |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 259 | transit = AppTransition.TRANSIT_UNSET; |
| 260 | } |
| 261 | mService.mSkipAppTransitionAnimation = false; |
| 262 | mService.mNoAnimationNotifyOnTransitionFinished.clear(); |
| 263 | |
Jorim Jaggi | d75962e | 2016-05-03 15:10:03 -0700 | [diff] [blame] | 264 | mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 265 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 266 | final DisplayContent displayContent = mService.getDefaultDisplayContentLocked(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 267 | // TODO: Don't believe this is really needed... |
| 268 | //mService.mWindowsChanged = true; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 269 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 270 | mService.mRoot.mWallpaperMayChange = false; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 271 | |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 272 | // The top-most window will supply the layout params, and we will determine it below. |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 273 | LayoutParams animLp = null; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 274 | int bestAnimLayer = -1; |
| 275 | boolean fullscreenAnim = false; |
| 276 | boolean voiceInteraction = false; |
| 277 | |
Chong Zhang | ec8299c | 2016-07-29 13:09:40 -0700 | [diff] [blame] | 278 | int i; |
| 279 | for (i = 0; i < appsCount; i++) { |
| 280 | final AppWindowToken wtoken = mService.mOpeningApps.valueAt(i); |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 281 | // Clearing the mAnimatingExit flag before entering animation. It's set to true if app |
| 282 | // window is removed, or window relayout to invisible. This also affects window |
| 283 | // visibility. We need to clear it *before* maybeUpdateTransitToWallpaper() as the |
| 284 | // transition selection depends on wallpaper target visibility. |
Chong Zhang | ec8299c | 2016-07-29 13:09:40 -0700 | [diff] [blame] | 285 | wtoken.clearAnimatingFlags(); |
| 286 | |
| 287 | } |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 288 | |
Chong Zhang | ec8299c | 2016-07-29 13:09:40 -0700 | [diff] [blame] | 289 | // Adjust wallpaper before we pull the lower/upper target, since pending changes |
| 290 | // (like the clearAnimatingFlags() above) might affect wallpaper target result. |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 291 | // Or, the opening app window should be a wallpaper target. |
| 292 | mWallpaperControllerLocked.adjustWallpaperWindowsForAppTransitionIfNeeded(displayContent, |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 293 | mService.mOpeningApps); |
Chong Zhang | ec8299c | 2016-07-29 13:09:40 -0700 | [diff] [blame] | 294 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 295 | final WindowState wallpaperTarget = mWallpaperControllerLocked.getWallpaperTarget(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 296 | boolean openingAppHasWallpaper = false; |
| 297 | boolean closingAppHasWallpaper = false; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 298 | |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 299 | // Do a first pass through the tokens for two things: |
| 300 | // (1) Determine if both the closing and opening app token sets are wallpaper targets, in |
| 301 | // which case special animations are needed (since the wallpaper needs to stay static behind |
| 302 | // them). |
| 303 | // (2) Find the layout params of the top-most application window in the tokens, which is |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 304 | // what will control the animation theme. |
| 305 | final int closingAppsCount = mService.mClosingApps.size(); |
| 306 | appsCount = closingAppsCount + mService.mOpeningApps.size(); |
| 307 | for (i = 0; i < appsCount; i++) { |
| 308 | final AppWindowToken wtoken; |
| 309 | if (i < closingAppsCount) { |
| 310 | wtoken = mService.mClosingApps.valueAt(i); |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 311 | if (wallpaperTarget != null && wtoken.windowsCanBeWallpaperTarget()) { |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 312 | closingAppHasWallpaper = true; |
| 313 | } |
| 314 | } else { |
| 315 | wtoken = mService.mOpeningApps.valueAt(i - closingAppsCount); |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 316 | if (wallpaperTarget != null && wtoken.windowsCanBeWallpaperTarget()) { |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 317 | openingAppHasWallpaper = true; |
| 318 | } |
| 319 | } |
| 320 | |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 321 | voiceInteraction |= wtoken.mVoiceInteraction; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 322 | |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 323 | if (wtoken.fillsParent()) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 324 | final WindowState ws = wtoken.findMainWindow(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 325 | if (ws != null) { |
| 326 | animLp = ws.mAttrs; |
| 327 | bestAnimLayer = ws.mLayer; |
| 328 | fullscreenAnim = true; |
| 329 | } |
| 330 | } else if (!fullscreenAnim) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 331 | final WindowState ws = wtoken.findMainWindow(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 332 | if (ws != null) { |
| 333 | if (ws.mLayer > bestAnimLayer) { |
| 334 | animLp = ws.mAttrs; |
| 335 | bestAnimLayer = ws.mLayer; |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | transit = maybeUpdateTransitToWallpaper(transit, openingAppHasWallpaper, |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 342 | closingAppHasWallpaper); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 343 | |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 344 | // If all closing windows are obscured, then there is no need to do an animation. This is |
| 345 | // the case, for example, when this transition is being done behind the lock screen. |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 346 | if (!mService.mPolicy.allowAppAnimationsLw()) { |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 347 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 348 | "Animations disallowed by keyguard or dream."); |
| 349 | animLp = null; |
| 350 | } |
| 351 | |
Jorim Jaggi | d6d9716 | 2018-01-05 18:28:36 +0100 | [diff] [blame] | 352 | final int layoutRedo; |
| 353 | mService.mSurfaceAnimationRunner.deferStartingAnimations(); |
| 354 | try { |
| 355 | processApplicationsAnimatingInPlace(transit); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 356 | |
Jorim Jaggi | d6d9716 | 2018-01-05 18:28:36 +0100 | [diff] [blame] | 357 | mTmpLayerAndToken.token = null; |
| 358 | handleClosingApps(transit, animLp, voiceInteraction, mTmpLayerAndToken); |
| 359 | final AppWindowToken topClosingApp = mTmpLayerAndToken.token; |
| 360 | final AppWindowToken topOpeningApp = handleOpeningApps(transit, animLp, |
| 361 | voiceInteraction); |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 362 | |
Jorim Jaggi | d6d9716 | 2018-01-05 18:28:36 +0100 | [diff] [blame] | 363 | mService.mAppTransition.setLastAppTransition(transit, topOpeningApp, topClosingApp); |
Chong Zhang | 1c93f6d | 2016-07-27 17:52:45 -0700 | [diff] [blame] | 364 | |
Jorim Jaggi | d6d9716 | 2018-01-05 18:28:36 +0100 | [diff] [blame] | 365 | final int flags = mService.mAppTransition.getTransitFlags(); |
| 366 | layoutRedo = mService.mAppTransition.goodToGo(transit, topOpeningApp, |
| 367 | topClosingApp, mService.mOpeningApps, mService.mClosingApps); |
| 368 | handleNonAppWindowsInTransition(transit, flags); |
| 369 | mService.mAppTransition.postAnimationCallback(); |
| 370 | mService.mAppTransition.clear(); |
| 371 | } finally { |
| 372 | mService.mSurfaceAnimationRunner.continueStartingAnimations(); |
| 373 | } |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 374 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 375 | mService.mTaskSnapshotController.onTransitionStarting(); |
| 376 | |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 377 | mService.mOpeningApps.clear(); |
| 378 | mService.mClosingApps.clear(); |
Jorim Jaggi | 5a108c2 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 379 | mService.mUnknownAppVisibilityController.clear(); |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 380 | |
| 381 | // This has changed the visibility of windows, so perform |
| 382 | // a new layout to get them all up-to-date. |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 383 | displayContent.setLayoutNeeded(); |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 384 | |
| 385 | // TODO(multidisplay): IMEs are only supported on the default display. |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 386 | final DisplayContent dc = mService.getDefaultDisplayContentLocked(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 387 | dc.computeImeTarget(true /* updateImeTarget */); |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 388 | mService.updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 389 | true /*updateInputWindows*/); |
| 390 | mService.mFocusMayChange = false; |
Chong Zhang | 8784be6 | 2016-06-28 15:25:07 -0700 | [diff] [blame] | 391 | |
Jorim Jaggi | dbaad38 | 2017-07-18 13:22:52 +0200 | [diff] [blame] | 392 | mService.mH.obtainMessage(NOTIFY_APP_TRANSITION_STARTING, |
| 393 | mTempTransitionReasons.clone()).sendToTarget(); |
| 394 | |
Chong Zhang | 8784be6 | 2016-06-28 15:25:07 -0700 | [diff] [blame] | 395 | Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); |
| 396 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 397 | return layoutRedo | FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_CONFIG; |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 398 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 399 | |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 400 | private AppWindowToken handleOpeningApps(int transit, LayoutParams animLp, |
Matthew Ng | b7e8a13 | 2017-09-29 10:27:24 -0700 | [diff] [blame] | 401 | boolean voiceInteraction) { |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 402 | AppWindowToken topOpeningApp = null; |
Matthew Ng | b7e8a13 | 2017-09-29 10:27:24 -0700 | [diff] [blame] | 403 | int topOpeningLayer = Integer.MIN_VALUE; |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 404 | final int appsCount = mService.mOpeningApps.size(); |
| 405 | for (int i = 0; i < appsCount; i++) { |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 406 | AppWindowToken wtoken = mService.mOpeningApps.valueAt(i); |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 407 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Now opening app" + wtoken); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 408 | |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 409 | if (!wtoken.setVisibility(animLp, true, transit, false, voiceInteraction)){ |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 410 | // This token isn't going to be animating. Add it to the list of tokens to |
| 411 | // be notified of app transition complete since the notification will not be |
| 412 | // sent be the app window animator. |
| 413 | mService.mNoAnimationNotifyOnTransitionFinished.add(wtoken.token); |
| 414 | } |
| 415 | wtoken.updateReportedVisibilityLocked(); |
| 416 | wtoken.waitingToShow = false; |
| 417 | |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 418 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
Filip Gruszczynski | 974eb3d | 2015-10-23 17:33:11 -0700 | [diff] [blame] | 419 | ">>> OPEN TRANSACTION handleAppTransitionReadyLocked()"); |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 420 | mService.openSurfaceTransaction(); |
Filip Gruszczynski | 974eb3d | 2015-10-23 17:33:11 -0700 | [diff] [blame] | 421 | try { |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 422 | wtoken.showAllWindowsLocked(); |
Filip Gruszczynski | 974eb3d | 2015-10-23 17:33:11 -0700 | [diff] [blame] | 423 | } finally { |
Adrian Roos | 111aff9 | 2017-09-27 18:11:46 +0200 | [diff] [blame] | 424 | mService.closeSurfaceTransaction("handleAppTransitionReadyLocked"); |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 425 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
Filip Gruszczynski | 974eb3d | 2015-10-23 17:33:11 -0700 | [diff] [blame] | 426 | "<<< CLOSE TRANSACTION handleAppTransitionReadyLocked()"); |
| 427 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 428 | |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 429 | if (animLp != null) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 430 | final int layer = wtoken.getHighestAnimLayer(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 431 | if (topOpeningApp == null || layer > topOpeningLayer) { |
| 432 | topOpeningApp = wtoken; |
| 433 | topOpeningLayer = layer; |
| 434 | } |
| 435 | } |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 436 | if (mService.mAppTransition.isNextAppTransitionThumbnailUp()) { |
Jorim Jaggi | 988f668 | 2017-11-17 17:46:43 +0100 | [diff] [blame] | 437 | wtoken.attachThumbnailAnimation(); |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 438 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 439 | } |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 440 | return topOpeningApp; |
| 441 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 442 | |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 443 | private void handleClosingApps(int transit, LayoutParams animLp, boolean voiceInteraction, |
| 444 | LayerAndToken layerAndToken) { |
| 445 | final int appsCount; |
| 446 | appsCount = mService.mClosingApps.size(); |
| 447 | for (int i = 0; i < appsCount; i++) { |
| 448 | AppWindowToken wtoken = mService.mClosingApps.valueAt(i); |
Chong Zhang | f58631a | 2016-05-24 16:02:10 -0700 | [diff] [blame] | 449 | |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 450 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Now closing app " + wtoken); |
Winson Chung | 87e5d55 | 2017-04-05 11:49:38 -0700 | [diff] [blame] | 451 | // TODO: Do we need to add to mNoAnimationNotifyOnTransitionFinished like above if not |
| 452 | // animating? |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 453 | wtoken.setVisibility(animLp, false, transit, false, voiceInteraction); |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 454 | wtoken.updateReportedVisibilityLocked(); |
| 455 | // Force the allDrawn flag, because we want to start |
| 456 | // this guy's animations regardless of whether it's |
| 457 | // gotten drawn. |
| 458 | wtoken.allDrawn = true; |
| 459 | wtoken.deferClearAllDrawn = false; |
| 460 | // Ensure that apps that are mid-starting are also scheduled to have their |
| 461 | // starting windows removed after the animation is complete |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 462 | if (wtoken.startingWindow != null && !wtoken.startingWindow.mAnimatingExit |
| 463 | && wtoken.getController() != null) { |
| 464 | wtoken.getController().removeStartingWindow(); |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 465 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 466 | |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 467 | if (animLp != null) { |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 468 | int layer = wtoken.getHighestAnimLayer(); |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 469 | if (layerAndToken.token == null || layer > layerAndToken.layer) { |
| 470 | layerAndToken.token = wtoken; |
| 471 | layerAndToken.layer = layer; |
| 472 | } |
| 473 | } |
| 474 | if (mService.mAppTransition.isNextAppTransitionThumbnailDown()) { |
Jorim Jaggi | 988f668 | 2017-11-17 17:46:43 +0100 | [diff] [blame] | 475 | wtoken.attachThumbnailAnimation(); |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 476 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 477 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 480 | private void handleNonAppWindowsInTransition(int transit, int flags) { |
| 481 | if (transit == TRANSIT_KEYGUARD_GOING_AWAY) { |
| 482 | if ((flags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER) != 0 |
| 483 | && (flags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) == 0) { |
| 484 | Animation anim = mService.mPolicy.createKeyguardWallpaperExit( |
| 485 | (flags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0); |
| 486 | if (anim != null) { |
| 487 | mService.getDefaultDisplayContentLocked().mWallpaperController |
| 488 | .startWallpaperAnimation(anim); |
| 489 | } |
| 490 | } |
| 491 | } |
| 492 | if (transit == TRANSIT_KEYGUARD_GOING_AWAY |
| 493 | || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) { |
| 494 | mService.getDefaultDisplayContentLocked().startKeyguardExitOnNonAppWindows( |
| 495 | transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, |
| 496 | (flags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0); |
| 497 | } |
| 498 | } |
| 499 | |
Jorim Jaggi | dbaad38 | 2017-07-18 13:22:52 +0200 | [diff] [blame] | 500 | private boolean transitionGoodToGo(int appsCount, SparseIntArray outReasons) { |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 501 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 502 | "Checking " + appsCount + " opening apps (frozen=" |
| 503 | + mService.mDisplayFrozen + " timeout=" |
| 504 | + mService.mAppTransition.isTimeout() + ")..."); |
Robert Carr | 42769ff | 2016-09-20 13:36:42 -0700 | [diff] [blame] | 505 | final ScreenRotationAnimation screenRotationAnimation = |
| 506 | mService.mAnimator.getScreenRotationAnimationLocked( |
| 507 | Display.DEFAULT_DISPLAY); |
| 508 | |
Jorim Jaggi | dbaad38 | 2017-07-18 13:22:52 +0200 | [diff] [blame] | 509 | outReasons.clear(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 510 | if (!mService.mAppTransition.isTimeout()) { |
Robert Carr | 42769ff | 2016-09-20 13:36:42 -0700 | [diff] [blame] | 511 | // Imagine the case where we are changing orientation due to an app transition, but a previous |
| 512 | // orientation change is still in progress. We won't process the orientation change |
| 513 | // for our transition because we need to wait for the rotation animation to finish. |
| 514 | // If we start the app transition at this point, we will interrupt it halfway with a new rotation |
| 515 | // animation after the old one finally finishes. It's better to defer the |
| 516 | // app transition. |
| 517 | if (screenRotationAnimation != null && screenRotationAnimation.isAnimating() && |
| 518 | mService.rotationNeedsUpdateLocked()) { |
| 519 | if (DEBUG_APP_TRANSITIONS) { |
| 520 | Slog.v(TAG, "Delaying app transition for screen rotation animation to finish"); |
| 521 | } |
| 522 | return false; |
| 523 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 524 | for (int i = 0; i < appsCount; i++) { |
| 525 | AppWindowToken wtoken = mService.mOpeningApps.valueAt(i); |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 526 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 527 | "Check opening app=" + wtoken + ": allDrawn=" |
| 528 | + wtoken.allDrawn + " startingDisplayed=" |
| 529 | + wtoken.startingDisplayed + " startingMoved=" |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 530 | + wtoken.startingMoved + " isRelaunching()=" |
| 531 | + wtoken.isRelaunching()); |
| 532 | |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 533 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 534 | final boolean allDrawn = wtoken.allDrawn && !wtoken.isRelaunching(); |
| 535 | if (!allDrawn && !wtoken.startingDisplayed && !wtoken.startingMoved) { |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 536 | return false; |
| 537 | } |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 538 | final TaskStack stack = wtoken.getStack(); |
| 539 | final int stackId = stack != null ? stack.mStackId : INVALID_STACK_ID; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 540 | if (allDrawn) { |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 541 | outReasons.put(stackId, APP_TRANSITION_WINDOWS_DRAWN); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 542 | } else { |
Jorim Jaggi | dbaad38 | 2017-07-18 13:22:52 +0200 | [diff] [blame] | 543 | outReasons.put(stackId, wtoken.startingData instanceof SplashScreenStartingData |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 544 | ? APP_TRANSITION_SPLASH_SCREEN |
| 545 | : APP_TRANSITION_SNAPSHOT); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 546 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Jorim Jaggi | 2f7d292 | 2015-10-29 13:08:29 +0100 | [diff] [blame] | 549 | // We also need to wait for the specs to be fetched, if needed. |
| 550 | if (mService.mAppTransition.isFetchingAppTransitionsSpecs()) { |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 551 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "isFetchingAppTransitionSpecs=true"); |
Jorim Jaggi | 2f7d292 | 2015-10-29 13:08:29 +0100 | [diff] [blame] | 552 | return false; |
| 553 | } |
| 554 | |
Jorim Jaggi | 5a108c2 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 555 | if (!mService.mUnknownAppVisibilityController.allResolved()) { |
| 556 | if (DEBUG_APP_TRANSITIONS) { |
| 557 | Slog.v(TAG, "unknownApps is not empty: " |
| 558 | + mService.mUnknownAppVisibilityController.getDebugMessage()); |
| 559 | } |
| 560 | return false; |
| 561 | } |
| 562 | |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 563 | // If the wallpaper is visible, we need to check it's ready too. |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 564 | boolean wallpaperReady = !mWallpaperControllerLocked.isWallpaperVisible() || |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 565 | mWallpaperControllerLocked.wallpaperTransitionReady(); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 566 | if (wallpaperReady) { |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 567 | return true; |
| 568 | } |
| 569 | return false; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 570 | } |
| 571 | return true; |
| 572 | } |
| 573 | |
| 574 | private int maybeUpdateTransitToWallpaper(int transit, boolean openingAppHasWallpaper, |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 575 | boolean closingAppHasWallpaper) { |
Matthew Ng | 26a1cec | 2017-05-18 14:42:51 -0700 | [diff] [blame] | 576 | // Given no app transition pass it through instead of a wallpaper transition |
| 577 | if (transit == TRANSIT_NONE) { |
| 578 | return TRANSIT_NONE; |
| 579 | } |
| 580 | |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 581 | // if wallpaper is animating in or out set oldWallpaper to null else to wallpaper |
| 582 | final WindowState wallpaperTarget = mWallpaperControllerLocked.getWallpaperTarget(); |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 583 | final WindowState oldWallpaper = mWallpaperControllerLocked.isWallpaperTargetAnimating() |
| 584 | ? null : wallpaperTarget; |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 585 | final ArraySet<AppWindowToken> openingApps = mService.mOpeningApps; |
| 586 | final ArraySet<AppWindowToken> closingApps = mService.mClosingApps; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 587 | boolean openingCanBeWallpaperTarget = canBeWallpaperTarget(openingApps); |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 588 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 589 | "New wallpaper target=" + wallpaperTarget |
| 590 | + ", oldWallpaper=" + oldWallpaper |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 591 | + ", openingApps=" + openingApps |
| 592 | + ", closingApps=" + closingApps); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 593 | |
Jorim Jaggi | a69243a | 2017-06-15 15:10:38 -0400 | [diff] [blame] | 594 | if (openingCanBeWallpaperTarget && transit == TRANSIT_KEYGUARD_GOING_AWAY) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 595 | transit = TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER; |
| 596 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| 597 | "New transit: " + AppTransition.appTransitionToString(transit)); |
Jorim Jaggi | a69243a | 2017-06-15 15:10:38 -0400 | [diff] [blame] | 598 | } |
| 599 | // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic |
| 600 | // relies on the fact that we always execute a Keyguard transition after preparing one. |
| 601 | else if (!isKeyguardGoingAwayTransit(transit)) { |
| 602 | if (closingAppHasWallpaper && openingAppHasWallpaper) { |
| 603 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Wallpaper animation!"); |
| 604 | switch (transit) { |
| 605 | case TRANSIT_ACTIVITY_OPEN: |
| 606 | case TRANSIT_TASK_OPEN: |
| 607 | case TRANSIT_TASK_TO_FRONT: |
| 608 | transit = TRANSIT_WALLPAPER_INTRA_OPEN; |
| 609 | break; |
| 610 | case TRANSIT_ACTIVITY_CLOSE: |
| 611 | case TRANSIT_TASK_CLOSE: |
| 612 | case TRANSIT_TASK_TO_BACK: |
| 613 | transit = TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 614 | break; |
| 615 | } |
| 616 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| 617 | "New transit: " + AppTransition.appTransitionToString(transit)); |
| 618 | } else if (oldWallpaper != null && !mService.mOpeningApps.isEmpty() |
| 619 | && !openingApps.contains(oldWallpaper.mAppToken) |
| 620 | && closingApps.contains(oldWallpaper.mAppToken)) { |
| 621 | // We are transitioning from an activity with a wallpaper to one without. |
| 622 | transit = TRANSIT_WALLPAPER_CLOSE; |
| 623 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "New transit away from wallpaper: " |
| 624 | + AppTransition.appTransitionToString(transit)); |
| 625 | } else if (wallpaperTarget != null && wallpaperTarget.isVisibleLw() && |
| 626 | openingApps.contains(wallpaperTarget.mAppToken)) { |
| 627 | // We are transitioning from an activity without |
| 628 | // a wallpaper to now showing the wallpaper |
| 629 | transit = TRANSIT_WALLPAPER_OPEN; |
| 630 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "New transit into wallpaper: " |
| 631 | + AppTransition.appTransitionToString(transit)); |
Jorim Jaggi | a69243a | 2017-06-15 15:10:38 -0400 | [diff] [blame] | 632 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 633 | } |
| 634 | return transit; |
| 635 | } |
| 636 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 637 | private boolean canBeWallpaperTarget(ArraySet<AppWindowToken> apps) { |
| 638 | for (int i = apps.size() - 1; i >= 0; i--) { |
| 639 | if (apps.valueAt(i).windowsCanBeWallpaperTarget()) { |
| 640 | return true; |
| 641 | } |
| 642 | } |
| 643 | return false; |
| 644 | } |
| 645 | |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 646 | private void processApplicationsAnimatingInPlace(int transit) { |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 647 | if (transit == TRANSIT_TASK_IN_PLACE) { |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 648 | // Find the focused window |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 649 | final WindowState win = mService.getDefaultDisplayContentLocked().findFocusedWindow(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 650 | if (win != null) { |
| 651 | final AppWindowToken wtoken = win.mAppToken; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 652 | if (DEBUG_APP_TRANSITIONS) |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 653 | Slog.v(TAG, "Now animating app in place " + wtoken); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 654 | wtoken.cancelAnimation(); |
| 655 | wtoken.applyAnimationLocked(null, transit, false, false); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 656 | wtoken.updateReportedVisibilityLocked(); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 657 | wtoken.showAllWindowsLocked(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | } |
| 661 | |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 662 | void requestTraversal() { |
| 663 | if (!mTraversalScheduled) { |
| 664 | mTraversalScheduled = true; |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 665 | mService.mAnimationHandler.post(mPerformSurfacePlacement); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 666 | } |
| 667 | } |
| 668 | |
Jorim Jaggi | 3dac63a | 2016-03-01 12:37:07 +0100 | [diff] [blame] | 669 | /** |
| 670 | * Puts the {@param surface} into a pending list to be destroyed after the current transaction |
| 671 | * has been committed. |
| 672 | */ |
| 673 | void destroyAfterTransaction(SurfaceControl surface) { |
| 674 | mPendingDestroyingSurfaces.add(surface); |
| 675 | } |
| 676 | |
| 677 | /** |
| 678 | * Destroys any surfaces that have been put into the pending list with |
| 679 | * {@link #destroyAfterTransaction}. |
| 680 | */ |
| 681 | void destroyPendingSurfaces() { |
| 682 | for (int i = mPendingDestroyingSurfaces.size() - 1; i >= 0; i--) { |
| 683 | mPendingDestroyingSurfaces.get(i).destroy(); |
| 684 | } |
| 685 | mPendingDestroyingSurfaces.clear(); |
| 686 | } |
| 687 | |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 688 | public void dump(PrintWriter pw, String prefix) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 689 | pw.println(prefix + "mTraversalScheduled=" + mTraversalScheduled); |
| 690 | pw.println(prefix + "mHoldScreenWindow=" + mService.mRoot.mHoldScreenWindow); |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 691 | pw.println(prefix + "mObscuringWindow=" + mService.mRoot.mObscuringWindow); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 692 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 693 | } |