blob: 22f39fb66b312ef376819753c16b4021752f8487 [file] [log] [blame]
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001package com.android.server.wm;
2
Jorim Jaggi275561a2016-02-23 10:11:02 -05003import static android.app.ActivityManagerInternal.APP_TRANSITION_SAVED_SURFACE;
4import static android.app.ActivityManagerInternal.APP_TRANSITION_STARTING_WINDOW;
5import static android.app.ActivityManagerInternal.APP_TRANSITION_TIMEOUT;
6import static android.app.ActivityManagerInternal.APP_TRANSITION_WINDOWS_DRAWN;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07007import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
8import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
9import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
10import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
Ruchi Kandoi43e38de2016-04-14 19:34:53 -070011import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070012import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
13import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070014import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
15import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
16import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
17import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
18import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
19import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
20import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080021import static com.android.server.wm.WindowManagerDebugConfig.DEBUG;
22import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
23import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
24import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
25import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
26import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
27import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
28import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
29import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
30import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
31import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
32import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE;
Chong Zhang4ffc3182016-05-04 15:06:02 -070033import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_KEEP_SCREEN_ON;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080034import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
35import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
Chong Zhang4ffc3182016-05-04 15:06:02 -070036import static com.android.server.wm.WindowManagerDebugConfig.TAG_KEEP_SCREEN_ON;
Jorim Jaggi192086e2016-03-11 17:17:03 +010037import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080038import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Jorim Jaggi192086e2016-03-11 17:17:03 +010039import static com.android.server.wm.WindowManagerService.H.DO_TRAVERSAL;
40import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
41import static com.android.server.wm.WindowManagerService.H.NOTIFY_APP_TRANSITION_STARTING;
42import static com.android.server.wm.WindowManagerService.H.NOTIFY_STARTING_WINDOW_DRAWN;
43import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS;
44import static com.android.server.wm.WindowManagerService.H.REPORT_WINDOWS_CHANGE;
45import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
46import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER;
47import static com.android.server.wm.WindowManagerService.H.WINDOW_FREEZE_TIMEOUT;
48import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
49import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070050import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES;
51import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
52import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_NONE;
53
54import android.graphics.Bitmap;
55import android.graphics.Canvas;
56import android.graphics.PixelFormat;
57import android.graphics.Rect;
58import android.os.Debug;
59import android.os.PowerManager;
60import android.os.RemoteException;
61import android.os.SystemClock;
62import android.os.Trace;
63import android.provider.Settings;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -070064import android.util.ArraySet;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070065import android.util.Slog;
66import android.view.Display;
67import android.view.DisplayInfo;
68import android.view.Surface;
69import android.view.SurfaceControl;
70import android.view.View;
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -080071import android.view.WindowManager.LayoutParams;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070072import android.view.animation.Animation;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070073
Jorim Jaggid75962e2016-05-03 15:10:03 -070074import com.android.server.wm.WindowManagerService.H;
75
Filip Gruszczynski24966d42015-09-05 15:00:00 -070076import java.io.PrintWriter;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070077import java.util.ArrayList;
78
79/**
80 * Positions windows and their surfaces.
81 *
82 * It sets positions of windows by calculating their frames and then applies this by positioning
83 * surfaces according to these frames. Z layer is still assigned withing WindowManagerService.
84 */
85class WindowSurfacePlacer {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -080086 private static final String TAG = TAG_WITH_CLASS_NAME ? "WindowSurfacePlacer" : TAG_WM;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070087 private final WindowManagerService mService;
88 private final WallpaperController mWallpaperControllerLocked;
89
90 private boolean mInLayout = false;
91
92 /** Only do a maximum of 6 repeated layouts. After that quit */
93 private int mLayoutRepeatCount;
94
95 static final int SET_UPDATE_ROTATION = 1 << 0;
96 static final int SET_WALLPAPER_MAY_CHANGE = 1 << 1;
97 static final int SET_FORCE_HIDING_CHANGED = 1 << 2;
98 static final int SET_ORIENTATION_CHANGE_COMPLETE = 1 << 3;
99 static final int SET_TURN_ON_SCREEN = 1 << 4;
100 static final int SET_WALLPAPER_ACTION_PENDING = 1 << 5;
101
102 boolean mWallpaperMayChange = false;
103 boolean mOrientationChangeComplete = true;
104 boolean mWallpaperActionPending = false;
105
106 private boolean mWallpaperForceHidingChanged = false;
107 private Object mLastWindowFreezeSource = null;
108 private Session mHoldScreen = null;
109 private boolean mObscured = false;
110 private boolean mSyswin = false;
111 private float mScreenBrightness = -1;
112 private float mButtonBrightness = -1;
113 private long mUserActivityTimeout = -1;
114 private boolean mUpdateRotation = false;
115 private final Rect mTmpStartRect = new Rect();
Wale Ogunwaleb4ec0a32015-12-14 10:31:43 -0800116 private final Rect mTmpContentRect = new Rect();
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700117
118 // Set to true when the display contains content to show the user.
119 // When false, the display manager may choose to mirror or blank the display.
120 private boolean mDisplayHasContent = false;
121
122 // Only set while traversing the default display based on its content.
123 // Affects the behavior of mirroring on secondary displays.
124 private boolean mObscureApplicationContentOnSecondaryDisplays = false;
125
126 private float mPreferredRefreshRate = 0;
127
128 private int mPreferredModeId = 0;
129
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700130 private boolean mTraversalScheduled;
Jorim Jaggic4025202015-10-22 16:43:34 +0200131 private int mDeferDepth = 0;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700132
Ruchi Kandoi43e38de2016-04-14 19:34:53 -0700133 private boolean mSustainedPerformanceModeEnabled = false;
134 private boolean mSustainedPerformanceModeCurrent = false;
135
Chong Zhang4ffc3182016-05-04 15:06:02 -0700136 // Following variables are for debugging screen wakelock only.
137 // Last window that requires screen wakelock
138 WindowState mHoldScreenWindow = null;
139 // Last window that obscures all windows below
140 WindowState mObsuringWindow = null;
141
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800142 private static final class LayerAndToken {
143 public int layer;
144 public AppWindowToken token;
145 }
146 private final LayerAndToken mTmpLayerAndToken = new LayerAndToken();
147
Jorim Jaggi3dac63a2016-03-01 12:37:07 +0100148 private final ArrayList<SurfaceControl> mPendingDestroyingSurfaces = new ArrayList<>();
149
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700150 public WindowSurfacePlacer(WindowManagerService service) {
151 mService = service;
152 mWallpaperControllerLocked = mService.mWallpaperControllerLocked;
153 }
154
Jorim Jaggic4025202015-10-22 16:43:34 +0200155 /**
156 * See {@link WindowManagerService#deferSurfaceLayout()}
157 */
158 void deferLayout() {
159 mDeferDepth++;
160 }
161
162 /**
163 * See {@link WindowManagerService#continueSurfaceLayout()}
164 */
165 void continueLayout() {
166 mDeferDepth--;
167 if (mDeferDepth <= 0) {
168 performSurfacePlacement();
169 }
170 }
171
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700172 final void performSurfacePlacement() {
Jorim Jaggic4025202015-10-22 16:43:34 +0200173 if (mDeferDepth > 0) {
174 return;
175 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700176 int loopCount = 6;
177 do {
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700178 mTraversalScheduled = false;
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700179 performSurfacePlacementLoop();
180 mService.mH.removeMessages(DO_TRAVERSAL);
181 loopCount--;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700182 } while (mTraversalScheduled && loopCount > 0);
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700183 mWallpaperActionPending = false;
184 }
185
186 private void performSurfacePlacementLoop() {
187 if (mInLayout) {
188 if (DEBUG) {
189 throw new RuntimeException("Recursive call!");
190 }
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800191 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout. Callers="
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700192 + Debug.getCallers(3));
193 return;
194 }
195
196 if (mService.mWaitingForConfig) {
197 // Our configuration has changed (most likely rotation), but we
198 // don't yet have the complete configuration to report to
199 // applications. Don't do any window layout until we have it.
200 return;
201 }
202
203 if (!mService.mDisplayReady) {
204 // Not yet initialized, nothing to do.
205 return;
206 }
207
208 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "wmLayout");
209 mInLayout = true;
210
211 boolean recoveringMemory = false;
212 if (!mService.mForceRemoves.isEmpty()) {
213 recoveringMemory = true;
214 // Wait a little bit for things to settle down, and off we go.
215 while (!mService.mForceRemoves.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700216 final WindowState ws = mService.mForceRemoves.remove(0);
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800217 Slog.i(TAG, "Force removing: " + ws);
Wale Ogunwale571771c2016-08-26 13:18:50 -0700218 ws.removeImmediately();
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700219 }
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800220 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700221 Object tmp = new Object();
222 synchronized (tmp) {
223 try {
224 tmp.wait(250);
225 } catch (InterruptedException e) {
226 }
227 }
228 }
229
230 try {
231 performSurfacePlacementInner(recoveringMemory);
232
233 mInLayout = false;
234
235 if (mService.needsLayout()) {
236 if (++mLayoutRepeatCount < 6) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700237 requestTraversal();
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700238 } else {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800239 Slog.e(TAG, "Performed 6 layouts in a row. Skipping");
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700240 mLayoutRepeatCount = 0;
241 }
242 } else {
243 mLayoutRepeatCount = 0;
244 }
245
246 if (mService.mWindowsChanged && !mService.mWindowChangeListeners.isEmpty()) {
247 mService.mH.removeMessages(REPORT_WINDOWS_CHANGE);
248 mService.mH.sendEmptyMessage(REPORT_WINDOWS_CHANGE);
249 }
250 } catch (RuntimeException e) {
251 mInLayout = false;
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800252 Slog.wtf(TAG, "Unhandled exception while laying out windows", e);
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700253 }
254
255 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
256 }
257
258 void debugLayoutRepeats(final String msg, int pendingLayoutChanges) {
259 if (mLayoutRepeatCount >= LAYOUT_REPEAT_THRESHOLD) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800260 Slog.v(TAG, "Layouts looping: " + msg +
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700261 ", mPendingLayoutChanges = 0x" + Integer.toHexString(pendingLayoutChanges));
262 }
263 }
264
265 // "Something has changed! Let's make it correct now."
266 private void performSurfacePlacementInner(boolean recoveringMemory) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800267 if (DEBUG_WINDOW_TRACE) Slog.v(TAG, "performSurfacePlacementInner: entry. Called by "
268 + Debug.getCallers(3));
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700269
270 int i;
271 boolean updateInputWindowsNeeded = false;
272
273 if (mService.mFocusMayChange) {
274 mService.mFocusMayChange = false;
275 updateInputWindowsNeeded = mService.updateFocusedWindowLocked(
276 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
277 }
278
279 // Initialize state of exiting tokens.
280 final int numDisplays = mService.mDisplayContents.size();
281 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
282 final DisplayContent displayContent = mService.mDisplayContents.valueAt(displayNdx);
283 for (i=displayContent.mExitingTokens.size()-1; i>=0; i--) {
284 displayContent.mExitingTokens.get(i).hasVisible = false;
285 }
286 }
287
288 for (int stackNdx = mService.mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) {
289 // Initialize state of exiting applications.
290 final AppTokenList exitingAppTokens =
291 mService.mStackIdToStack.valueAt(stackNdx).mExitingAppTokens;
292 for (int tokenNdx = exitingAppTokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
293 exitingAppTokens.get(tokenNdx).hasVisible = false;
294 }
295 }
296
297 mHoldScreen = null;
Chong Zhang4ffc3182016-05-04 15:06:02 -0700298 mHoldScreenWindow = null;
299 mObsuringWindow = null;
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700300 mScreenBrightness = -1;
301 mButtonBrightness = -1;
302 mUserActivityTimeout = -1;
303 mObscureApplicationContentOnSecondaryDisplays = false;
Ruchi Kandoi43e38de2016-04-14 19:34:53 -0700304 mSustainedPerformanceModeCurrent = false;
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700305 mService.mTransactionSequence++;
306
307 final DisplayContent defaultDisplay = mService.getDefaultDisplayContentLocked();
308 final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo();
309 final int defaultDw = defaultInfo.logicalWidth;
310 final int defaultDh = defaultInfo.logicalHeight;
311
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800312 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700313 ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
314 SurfaceControl.openTransaction();
315 try {
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700316 applySurfaceChangesTransaction(recoveringMemory, numDisplays, defaultDw, defaultDh);
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700317 } catch (RuntimeException e) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800318 Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700319 } finally {
320 SurfaceControl.closeTransaction();
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800321 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700322 "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
323 }
324
325 final WindowList defaultWindows = defaultDisplay.getWindowList();
326
327 // If we are ready to perform an app transition, check through
328 // all of the app tokens to be shown and see if they are ready
329 // to go.
330 if (mService.mAppTransition.isReady()) {
331 defaultDisplay.pendingLayoutChanges |= handleAppTransitionReadyLocked(defaultWindows);
332 if (DEBUG_LAYOUT_REPEATS)
333 debugLayoutRepeats("after handleAppTransitionReadyLocked",
334 defaultDisplay.pendingLayoutChanges);
335 }
336
337 if (!mService.mAnimator.mAppWindowAnimating && mService.mAppTransition.isRunning()) {
338 // We have finished the animation of an app transition. To do
339 // this, we have delayed a lot of operations like showing and
340 // hiding apps, moving apps in Z-order, etc. The app token list
341 // reflects the correct Z-order, but the window list may now
342 // be out of sync with it. So here we will just rebuild the
343 // entire app window list. Fun!
344 defaultDisplay.pendingLayoutChanges |=
345 mService.handleAnimatingStoppedAndTransitionLocked();
346 if (DEBUG_LAYOUT_REPEATS)
347 debugLayoutRepeats("after handleAnimStopAndXitionLock",
348 defaultDisplay.pendingLayoutChanges);
349 }
350
351 if (mWallpaperForceHidingChanged && defaultDisplay.pendingLayoutChanges == 0
352 && !mService.mAppTransition.isReady()) {
353 // At this point, there was a window with a wallpaper that
354 // was force hiding other windows behind it, but now it
355 // is going away. This may be simple -- just animate
356 // away the wallpaper and its window -- or it may be
357 // hard -- the wallpaper now needs to be shown behind
358 // something that was hidden.
359 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
360 if (DEBUG_LAYOUT_REPEATS)
361 debugLayoutRepeats("after animateAwayWallpaperLocked",
362 defaultDisplay.pendingLayoutChanges);
363 }
364 mWallpaperForceHidingChanged = false;
365
366 if (mWallpaperMayChange) {
367 if (DEBUG_WALLPAPER_LIGHT)
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800368 Slog.v(TAG, "Wallpaper may change! Adjusting");
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700369 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
370 if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("WallpaperMayChange",
371 defaultDisplay.pendingLayoutChanges);
372 }
373
374 if (mService.mFocusMayChange) {
375 mService.mFocusMayChange = false;
376 if (mService.updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
377 false /*updateInputWindows*/)) {
378 updateInputWindowsNeeded = true;
379 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
380 }
381 }
382
383 if (mService.needsLayout()) {
384 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
385 if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("mLayoutNeeded",
386 defaultDisplay.pendingLayoutChanges);
387 }
388
389 for (i = mService.mResizingWindows.size() - 1; i >= 0; i--) {
390 WindowState win = mService.mResizingWindows.get(i);
391 if (win.mAppFreezing) {
392 // Don't remove this window until rotation has completed.
393 continue;
394 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700395 // Discard the saved surface if window size is changed, it can't be reused.
Chong Zhangbef461f2015-10-27 11:38:24 -0700396 if (win.mAppToken != null) {
397 win.mAppToken.destroySavedSurfaces();
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700398 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700399 win.reportResized();
400 mService.mResizingWindows.remove(i);
401 }
402
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800403 if (DEBUG_ORIENTATION && mService.mDisplayFrozen) Slog.v(TAG,
404 "With display frozen, orientationChangeComplete=" + mOrientationChangeComplete);
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700405 if (mOrientationChangeComplete) {
406 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
407 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_NONE;
408 mService.mLastFinishedFreezeSource = mLastWindowFreezeSource;
409 mService.mH.removeMessages(WINDOW_FREEZE_TIMEOUT);
410 }
411 mService.stopFreezingDisplayLocked();
412 }
413
414 // Destroy the surface of any windows that are no longer visible.
Filip Gruszczynski19723a42015-11-25 15:01:48 -0800415 boolean wallpaperDestroyed = false;
416 i = mService.mDestroySurface.size();
417 if (i > 0) {
418 do {
419 i--;
420 WindowState win = mService.mDestroySurface.get(i);
421 win.mDestroying = false;
422 if (mService.mInputMethodWindow == win) {
423 mService.mInputMethodWindow = null;
424 }
425 if (mWallpaperControllerLocked.isWallpaperTarget(win)) {
426 wallpaperDestroyed = true;
427 }
Robert Carr13f7be9e2015-12-02 18:39:45 -0800428 win.destroyOrSaveSurface();
Filip Gruszczynski19723a42015-11-25 15:01:48 -0800429 } while (i > 0);
430 mService.mDestroySurface.clear();
431 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700432
433 // Time to remove any exiting tokens?
434 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
435 final DisplayContent displayContent = mService.mDisplayContents.valueAt(displayNdx);
436 ArrayList<WindowToken> exitingTokens = displayContent.mExitingTokens;
437 for (i = exitingTokens.size() - 1; i >= 0; i--) {
438 WindowToken token = exitingTokens.get(i);
439 if (!token.hasVisible) {
440 exitingTokens.remove(i);
441 if (token.windowType == TYPE_WALLPAPER) {
442 mWallpaperControllerLocked.removeWallpaperToken(token);
443 }
444 }
445 }
446 }
447
448 // Time to remove any exiting applications?
449 for (int stackNdx = mService.mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) {
450 // Initialize state of exiting applications.
451 final AppTokenList exitingAppTokens =
452 mService.mStackIdToStack.valueAt(stackNdx).mExitingAppTokens;
453 for (i = exitingAppTokens.size() - 1; i >= 0; i--) {
454 AppWindowToken token = exitingAppTokens.get(i);
455 if (!token.hasVisible && !mService.mClosingApps.contains(token) &&
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700456 (!token.mIsExiting || token.isEmpty())) {
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700457 // Make sure there is no animation running on this token,
458 // so any windows associated with it will be removed as
459 // soon as their animations are complete
460 token.mAppAnimator.clearAnimation();
461 token.mAppAnimator.animating = false;
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800462 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
463 "performLayout: App token exiting now removed" + token);
Wale Ogunwale571771c2016-08-26 13:18:50 -0700464 token.removeIfPossible();
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700465 }
466 }
467 }
468
469 if (wallpaperDestroyed) {
470 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
471 defaultDisplay.layoutNeeded = true;
472 }
473
474 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
475 final DisplayContent displayContent = mService.mDisplayContents.valueAt(displayNdx);
476 if (displayContent.pendingLayoutChanges != 0) {
477 displayContent.layoutNeeded = true;
478 }
479 }
480
481 // Finally update all input windows now that the window changes have stabilized.
482 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
483
484 mService.setHoldScreenLocked(mHoldScreen);
485 if (!mService.mDisplayFrozen) {
486 if (mScreenBrightness < 0 || mScreenBrightness > 1.0f) {
487 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(-1);
488 } else {
489 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(
490 toBrightnessOverride(mScreenBrightness));
491 }
492 if (mButtonBrightness < 0
493 || mButtonBrightness > 1.0f) {
494 mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(-1);
495 } else {
496 mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(
497 toBrightnessOverride(mButtonBrightness));
498 }
499 mService.mPowerManagerInternal.setUserActivityTimeoutOverrideFromWindowManager(
500 mUserActivityTimeout);
501 }
502
Ruchi Kandoi43e38de2016-04-14 19:34:53 -0700503 if (mSustainedPerformanceModeCurrent != mSustainedPerformanceModeEnabled) {
504 mSustainedPerformanceModeEnabled = mSustainedPerformanceModeCurrent;
505 mService.mPowerManagerInternal.powerHint(
506 mService.mPowerManagerInternal.POWER_HINT_SUSTAINED_PERFORMANCE_MODE,
507 (mSustainedPerformanceModeEnabled ? 1 : 0));
508 }
509
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700510 if (mService.mTurnOnScreen) {
511 if (mService.mAllowTheaterModeWakeFromLayout
512 || Settings.Global.getInt(mService.mContext.getContentResolver(),
513 Settings.Global.THEATER_MODE_ON, 0) == 0) {
514 if (DEBUG_VISIBILITY || DEBUG_POWER) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800515 Slog.v(TAG, "Turning screen on after layout!");
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700516 }
517 mService.mPowerManager.wakeUp(SystemClock.uptimeMillis(),
518 "android.server.wm:TURN_ON");
519 }
520 mService.mTurnOnScreen = false;
521 }
522
523 if (mUpdateRotation) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800524 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700525 if (mService.updateRotationUncheckedLocked(false)) {
526 mService.mH.sendEmptyMessage(SEND_NEW_CONFIGURATION);
527 } else {
528 mUpdateRotation = false;
529 }
530 }
531
532 if (mService.mWaitingForDrawnCallback != null ||
533 (mOrientationChangeComplete && !defaultDisplay.layoutNeeded &&
534 !mUpdateRotation)) {
535 mService.checkDrawnWindowsLocked();
536 }
537
538 final int N = mService.mPendingRemove.size();
539 if (N > 0) {
540 if (mService.mPendingRemoveTmp.length < N) {
541 mService.mPendingRemoveTmp = new WindowState[N+10];
542 }
543 mService.mPendingRemove.toArray(mService.mPendingRemoveTmp);
544 mService.mPendingRemove.clear();
545 DisplayContentList displayList = new DisplayContentList();
546 for (i = 0; i < N; i++) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700547 final WindowState w = mService.mPendingRemoveTmp[i];
Wale Ogunwale571771c2016-08-26 13:18:50 -0700548 w.removeImmediately();
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700549 final DisplayContent displayContent = w.getDisplayContent();
550 if (displayContent != null && !displayList.contains(displayContent)) {
551 displayList.add(displayContent);
552 }
553 }
554
555 for (DisplayContent displayContent : displayList) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -0800556 mService.mLayersController.assignLayersLocked(displayContent.getWindowList());
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700557 displayContent.layoutNeeded = true;
558 }
559 }
560
561 // Remove all deferred displays stacks, tasks, and activities.
562 for (int displayNdx = mService.mDisplayContents.size() - 1; displayNdx >= 0; --displayNdx) {
Wale Ogunwale15ead902016-09-02 14:30:11 -0700563 mService.mDisplayContents.valueAt(displayNdx).onCompleteDeferredRemoval();
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700564 }
565
566 if (updateInputWindowsNeeded) {
567 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
568 }
Chong Zhangb15758a2015-11-17 12:12:03 -0800569 mService.setFocusTaskRegionLocked();
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700570
571 // Check to see if we are now in a state where the screen should
572 // be enabled, because the window obscured flags have changed.
573 mService.enableScreenIfNeededLocked();
574
575 mService.scheduleAnimationLocked();
Jorim Jaggi3dac63a2016-03-01 12:37:07 +0100576 mService.mWindowPlacerLocked.destroyPendingSurfaces();
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700577
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800578 if (DEBUG_WINDOW_TRACE) Slog.e(TAG,
Wale Ogunwale69cf50f2015-11-13 11:08:36 -0800579 "performSurfacePlacementInner exit: animating=" + mService.mAnimator.isAnimating());
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700580 }
581
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700582 private void applySurfaceChangesTransaction(boolean recoveringMemory, int numDisplays,
583 int defaultDw, int defaultDh) {
584 if (mService.mWatermark != null) {
585 mService.mWatermark.positionSurface(defaultDw, defaultDh);
586 }
587 if (mService.mStrictModeFlash != null) {
588 mService.mStrictModeFlash.positionSurface(defaultDw, defaultDh);
589 }
590 if (mService.mCircularDisplayMask != null) {
591 mService.mCircularDisplayMask.positionSurface(defaultDw, defaultDh,
592 mService.mRotation);
593 }
594 if (mService.mEmulatorDisplayOverlay != null) {
595 mService.mEmulatorDisplayOverlay.positionSurface(defaultDw, defaultDh,
596 mService.mRotation);
597 }
598
599 boolean focusDisplayed = false;
600
601 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
602 final DisplayContent displayContent = mService.mDisplayContents.valueAt(displayNdx);
603 boolean updateAllDrawn = false;
604 WindowList windows = displayContent.getWindowList();
605 DisplayInfo displayInfo = displayContent.getDisplayInfo();
606 final int displayId = displayContent.getDisplayId();
607 final int dw = displayInfo.logicalWidth;
608 final int dh = displayInfo.logicalHeight;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700609 final boolean isDefaultDisplay = (displayId == Display.DEFAULT_DISPLAY);
610
611 // Reset for each display.
612 mDisplayHasContent = false;
613 mPreferredRefreshRate = 0;
614 mPreferredModeId = 0;
615
616 int repeats = 0;
617 do {
618 repeats++;
619 if (repeats > 6) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800620 Slog.w(TAG, "Animation repeat aborted after too many iterations");
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700621 displayContent.layoutNeeded = false;
622 break;
623 }
624
625 if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats(
626 "On entry to LockedInner", displayContent.pendingLayoutChanges);
627
628 if ((displayContent.pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0 &&
629 mWallpaperControllerLocked.adjustWallpaperWindows()) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -0800630 mService.mLayersController.assignLayersLocked(windows);
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700631 displayContent.layoutNeeded = true;
632 }
633
634 if (isDefaultDisplay
635 && (displayContent.pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800636 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700637 if (mService.updateOrientationFromAppTokensLocked(true)) {
638 displayContent.layoutNeeded = true;
639 mService.mH.sendEmptyMessage(SEND_NEW_CONFIGURATION);
640 }
641 }
642
643 if ((displayContent.pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
644 displayContent.layoutNeeded = true;
645 }
646
647 // FIRST LOOP: Perform a layout, if needed.
648 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
649 performLayoutLockedInner(displayContent, repeats == 1,
650 false /* updateInputWindows */);
651 } else {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800652 Slog.w(TAG, "Layout repeat skipped after too many iterations");
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700653 }
654
655 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think
656 // it is animating.
657 displayContent.pendingLayoutChanges = 0;
658
659 if (isDefaultDisplay) {
660 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
661 for (int i = windows.size() - 1; i >= 0; i--) {
662 WindowState w = windows.get(i);
663 if (w.mHasSurface) {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -0700664 mService.mPolicy.applyPostLayoutPolicyLw(
665 w, w.mAttrs, w.getParentWindow());
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700666 }
667 }
668 displayContent.pendingLayoutChanges |=
669 mService.mPolicy.finishPostLayoutPolicyLw();
670 if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("after finishPostLayoutPolicyLw",
671 displayContent.pendingLayoutChanges);
672 }
673 } while (displayContent.pendingLayoutChanges != 0);
674
675 mObscured = false;
676 mSyswin = false;
677 displayContent.resetDimming();
678
679 // Only used if default window
680 final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty();
681
682 for (int i = windows.size() - 1; i >= 0; i--) {
683 WindowState w = windows.get(i);
Robert Carr0d00c2e2016-02-29 17:45:02 -0800684 final Task task = w.getTask();
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700685 final boolean obscuredChanged = w.mObscured != mObscured;
686
687 // Update effect.
688 w.mObscured = mObscured;
689 if (!mObscured) {
Chong Zhang0abb20f2015-11-19 14:17:31 -0800690 handleNotObscuredLocked(w, displayInfo);
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700691 }
692
Chong Zhang112eb8c2015-11-02 11:17:00 -0800693 w.applyDimLayerIfNeeded();
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700694
695 if (isDefaultDisplay && obscuredChanged
696 && mWallpaperControllerLocked.isWallpaperTarget(w) && w.isVisibleLw()) {
697 // This is the wallpaper target and its obscured state
698 // changed... make sure the current wallaper's visibility
699 // has been updated accordingly.
700 mWallpaperControllerLocked.updateWallpaperVisibility();
701 }
702
703 final WindowStateAnimator winAnimator = w.mWinAnimator;
704
705 // If the window has moved due to its containing content frame changing, then
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800706 // notify the listeners and optionally animate it. Simply checking a change of
707 // position is not enough, because being move due to dock divider is not a trigger
708 // for animation.
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700709 if (w.hasMoved()) {
710 // Frame has moved, containing content frame has also moved, and we're not
711 // currently animating... let's do something.
712 final int left = w.mFrame.left;
713 final int top = w.mFrame.top;
Chong Zhangbaba7832016-03-24 10:21:26 -0700714 final boolean adjustedForMinimizedDockOrIme = task != null
715 && (task.mStack.isAdjustedForMinimizedDockedStack()
716 || task.mStack.isAdjustedForIme());
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800717 if ((w.mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
Chong Zhangbaba7832016-03-24 10:21:26 -0700718 && !w.isDragResizing() && !adjustedForMinimizedDockOrIme
Robert Carrc7294602016-05-13 11:32:05 -0700719 && (task == null || w.getTask().mStack.hasMovementAnimations())
Jorim Jaggi192086e2016-03-11 17:17:03 +0100720 && !w.mWinAnimator.mLastHidden) {
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800721 winAnimator.setMoveAnimation(left, top);
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700722 }
723
724 //TODO (multidisplay): Accessibility supported only for the default display.
725 if (mService.mAccessibilityController != null
726 && displayId == Display.DEFAULT_DISPLAY) {
727 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
728 }
729
730 try {
Wale Ogunwale7774bd52016-06-17 09:44:22 -0700731 w.mClient.moved(left, top);
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700732 } catch (RemoteException e) {
733 }
Jorim Jaggi192086e2016-03-11 17:17:03 +0100734 w.mMovedByResize = false;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700735 }
736
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800737 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700738 w.mContentChanged = false;
739
740 // Moved from updateWindowsAndWallpaperLocked().
741 if (w.mHasSurface) {
Robert Carr679c8072016-04-07 15:51:48 -0700742 // If we have recently synchronized a previous transaction for this
743 // window ensure we don't push through an unsynchronized one now.
744 winAnimator.deferToPendingTransaction();
745
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700746 // Take care of the window being ready to display.
747 final boolean committed = winAnimator.commitFinishDrawingLocked();
748 if (isDefaultDisplay && committed) {
749 if (w.mAttrs.type == TYPE_DREAM) {
750 // HACK: When a dream is shown, it may at that
751 // point hide the lock screen. So we need to
752 // redo the layout to let the phone window manager
753 // make this happen.
754 displayContent.pendingLayoutChanges |=
755 FINISH_LAYOUT_REDO_LAYOUT;
756 if (DEBUG_LAYOUT_REPEATS) {
757 debugLayoutRepeats("dream and commitFinishDrawingLocked true",
758 displayContent.pendingLayoutChanges);
759 }
760 }
761 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
762 if (DEBUG_WALLPAPER_LIGHT)
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800763 Slog.v(TAG, "First draw done in potential wallpaper target " + w);
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700764 mWallpaperMayChange = true;
765 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
766 if (DEBUG_LAYOUT_REPEATS) {
767 debugLayoutRepeats("wallpaper and commitFinishDrawingLocked true",
768 displayContent.pendingLayoutChanges);
769 }
770 }
771 }
Chong Zhange22006d2016-05-09 10:59:59 -0700772 if (!winAnimator.isAnimationStarting() && !winAnimator.isWaitingForOpening()) {
Filip Gruszczynskic46f41c2016-01-05 11:29:21 -0800773 // Updates the shown frame before we set up the surface. This is needed
774 // because the resizing could change the top-left position (in addition to
775 // size) of the window. setSurfaceBoundariesLocked uses mShownPosition to
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700776 // position the surface.
777 //
778 // If an animation is being started, we can't call this method because the
779 // animation hasn't processed its initial transformation yet, but in general
780 // we do want to update the position if the window is animating.
Filip Gruszczynskic46f41c2016-01-05 11:29:21 -0800781 winAnimator.computeShownFrameLocked();
782 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700783 winAnimator.setSurfaceBoundariesLocked(recoveringMemory);
784 }
785
786 final AppWindowToken atoken = w.mAppToken;
787 if (DEBUG_STARTING_WINDOW && atoken != null && w == atoken.startingWindow) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800788 Slog.d(TAG, "updateWindows: starting " + w
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700789 + " isOnScreen=" + w.isOnScreen() + " allDrawn=" + atoken.allDrawn
790 + " freezingScreen=" + atoken.mAppAnimator.freezingScreen);
791 }
Chong Zhang8e4bda92016-05-04 15:08:18 -0700792 if (atoken != null && (!atoken.allDrawn || !atoken.allDrawnExcludingSaved
793 || atoken.mAppAnimator.freezingScreen)) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700794 if (atoken.lastTransactionSequence != mService.mTransactionSequence) {
795 atoken.lastTransactionSequence = mService.mTransactionSequence;
796 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700797 atoken.numInterestingWindowsExcludingSaved = 0;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700798 atoken.numDrawnWindowsExcludingSaved = 0;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700799 atoken.startingDisplayed = false;
800 }
Chong Zhang8e4bda92016-05-04 15:08:18 -0700801 if (!atoken.allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700802 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800803 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700804 + w.isDrawnLw()
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700805 + ", isAnimationSet=" + winAnimator.isAnimationSet());
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700806 if (!w.isDrawnLw()) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800807 Slog.v(TAG, "Not displayed: s="
Robert Carre6a83512015-11-03 16:09:21 -0800808 + winAnimator.mSurfaceController
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700809 + " pv=" + w.mPolicyVisibility
810 + " mDrawState=" + winAnimator.drawStateToString()
Wale Ogunwale9d147902016-07-16 11:58:55 -0700811 + " ph=" + w.isParentWindowHidden()
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700812 + " th=" + atoken.hiddenRequested
813 + " a=" + winAnimator.mAnimating);
814 }
815 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800816 if (w != atoken.startingWindow) {
Chong Zhang8e4bda92016-05-04 15:08:18 -0700817 if (w.isInteresting()) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700818 atoken.numInterestingWindows++;
819 if (w.isDrawnLw()) {
820 atoken.numDrawnWindows++;
821 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION)
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800822 Slog.v(TAG, "tokenMayBeDrawn: " + atoken
Chong Zhang8e4bda92016-05-04 15:08:18 -0700823 + " w=" + w + " numInteresting="
824 + atoken.numInterestingWindows
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700825 + " freezingScreen="
826 + atoken.mAppAnimator.freezingScreen
827 + " mAppFreezing=" + w.mAppFreezing);
828 updateAllDrawn = true;
829 }
830 }
831 } else if (w.isDrawnLw()) {
Jorim Jaggi275561a2016-02-23 10:11:02 -0500832 mService.mH.sendEmptyMessage(NOTIFY_STARTING_WINDOW_DRAWN);
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700833 atoken.startingDisplayed = true;
834 }
835 }
Chong Zhang8e4bda92016-05-04 15:08:18 -0700836 if (!atoken.allDrawnExcludingSaved
837 && w.mightAffectAllDrawn(true /* visibleOnly */)) {
838 if (w != atoken.startingWindow && w.isInteresting()) {
839 atoken.numInterestingWindowsExcludingSaved++;
840 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
Wale Ogunwale571771c2016-08-26 13:18:50 -0700841 atoken.numDrawnWindowsExcludingSaved++;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700842 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION)
843 Slog.v(TAG, "tokenMayBeDrawnExcludingSaved: " + atoken
844 + " w=" + w + " numInteresting="
845 + atoken.numInterestingWindowsExcludingSaved
846 + " freezingScreen="
847 + atoken.mAppAnimator.freezingScreen
848 + " mAppFreezing=" + w.mAppFreezing);
849 updateAllDrawn = true;
850 }
851 }
852 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700853 }
854
855 if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus
856 && w.isDisplayedLw()) {
857 focusDisplayed = true;
858 }
859
860 mService.updateResizingWindows(w);
861 }
862
863 mService.mDisplayManagerInternal.setDisplayProperties(displayId,
864 mDisplayHasContent,
865 mPreferredRefreshRate,
866 mPreferredModeId,
867 true /* inTraversal, must call performTraversalInTrans... below */);
868
Wale Ogunwale15ead902016-09-02 14:30:11 -0700869 displayContent.stopDimmingIfNeeded();
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700870
871 if (updateAllDrawn) {
872 updateAllDrawnLocked(displayContent);
873 }
874 }
875
876 if (focusDisplayed) {
877 mService.mH.sendEmptyMessage(REPORT_LOSING_FOCUS);
878 }
879
880 // Give the display manager a chance to adjust properties
881 // like display rotation if it needs to.
882 mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
883 }
884
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700885 boolean isInLayout() {
886 return mInLayout;
887 }
888
889 final void performLayoutLockedInner(final DisplayContent displayContent,
890 boolean initial, boolean updateInputWindows) {
891 if (!displayContent.layoutNeeded) {
892 return;
893 }
894 displayContent.layoutNeeded = false;
895 WindowList windows = displayContent.getWindowList();
896 boolean isDefaultDisplay = displayContent.isDefaultDisplay;
897
898 DisplayInfo displayInfo = displayContent.getDisplayInfo();
899 final int dw = displayInfo.logicalWidth;
900 final int dh = displayInfo.logicalHeight;
901
902 if (mService.mInputConsumer != null) {
903 mService.mInputConsumer.layout(dw, dh);
904 }
905
Vladislav Kaznacheev0d50d862016-03-29 15:43:28 -0700906 if (mService.mWallpaperInputConsumer != null) {
907 mService.mWallpaperInputConsumer.layout(dw, dh);
908 }
909
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700910 final int N = windows.size();
911 int i;
912
913 if (DEBUG_LAYOUT) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800914 Slog.v(TAG, "-------------------------------------");
915 Slog.v(TAG, "performLayout: needed="
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700916 + displayContent.layoutNeeded + " dw=" + dw + " dh=" + dh);
917 }
918
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -0800919 mService.mPolicy.beginLayoutLw(isDefaultDisplay, dw, dh, mService.mRotation,
920 mService.mCurConfiguration.uiMode);
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700921 if (isDefaultDisplay) {
922 // Not needed on non-default displays.
923 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
924 mService.mScreenRect.set(0, 0, dw, dh);
925 }
926
Wale Ogunwaleb4ec0a32015-12-14 10:31:43 -0800927 mService.mPolicy.getContentRectLw(mTmpContentRect);
928 displayContent.resize(mTmpContentRect);
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700929
930 int seq = mService.mLayoutSeq+1;
931 if (seq < 0) seq = 0;
932 mService.mLayoutSeq = seq;
933
934 boolean behindDream = false;
935
936 // First perform layout of any root windows (not attached
937 // to another window).
938 int topAttached = -1;
939 for (i = N-1; i >= 0; i--) {
940 final WindowState win = windows.get(i);
941
942 // Don't do layout of a window if it is not visible, or
943 // soon won't be visible, to avoid wasting time and funky
944 // changes while a window is animating away.
945 final boolean gone = (behindDream && mService.mPolicy.canBeForceHidden(win, win.mAttrs))
946 || win.isGoneForLayoutLw();
947
948 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800949 Slog.v(TAG, "1ST PASS " + win
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700950 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
951 + " mLayoutAttached=" + win.mLayoutAttached
952 + " screen changed=" + win.isConfigChanged());
953 final AppWindowToken atoken = win.mAppToken;
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800954 if (gone) Slog.v(TAG, " GONE: mViewVisibility="
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700955 + win.mViewVisibility + " mRelayoutCalled="
956 + win.mRelayoutCalled + " hidden="
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700957 + win.mToken.hidden + " hiddenRequested="
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700958 + (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -0700959 + " parentHidden=" + win.isParentWindowHidden());
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800960 else Slog.v(TAG, " VIS: mViewVisibility="
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700961 + win.mViewVisibility + " mRelayoutCalled="
962 + win.mRelayoutCalled + " hidden="
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700963 + win.mToken.hidden + " hiddenRequested="
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700964 + (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -0700965 + " parentHidden=" + win.isParentWindowHidden());
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700966 }
967
968 // If this view is GONE, then skip it -- keep the current
969 // frame, and let the caller know so they can ignore it
970 // if they want. (We do the normal layout for INVISIBLE
971 // windows, since that means "perform layout as normal,
972 // just don't display").
973 if (!gone || !win.mHaveFrame || win.mLayoutNeeded
Robert Carr31aa98b2016-07-20 15:29:03 -0700974 || ((win.isConfigChanged() || win.setReportResizeHints())
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700975 && !win.isGoneForLayoutLw() &&
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700976 ((win.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
977 (win.mHasSurface && win.mAppToken != null &&
978 win.mAppToken.layoutConfigChanges)))) {
979 if (!win.mLayoutAttached) {
980 if (initial) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800981 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700982 win.mContentChanged = false;
983 }
984 if (win.mAttrs.type == TYPE_DREAM) {
985 // Don't layout windows behind a dream, so that if it
986 // does stuff like hide the status bar we won't get a
987 // bad transition when it goes away.
988 behindDream = true;
989 }
990 win.mLayoutNeeded = false;
991 win.prelayout();
992 mService.mPolicy.layoutWindowLw(win, null);
993 win.mLayoutSeq = seq;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800994
995 // Window frames may have changed. Update dim layer with the new bounds.
996 final Task task = win.getTask();
997 if (task != null) {
998 displayContent.mDimLayerController.updateDimLayer(task);
999 }
1000
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001001 if (DEBUG_LAYOUT) Slog.v(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001002 " LAYOUT: mFrame="
1003 + win.mFrame + " mContainingFrame="
1004 + win.mContainingFrame + " mDisplayFrame="
1005 + win.mDisplayFrame);
1006 } else {
1007 if (topAttached < 0) topAttached = i;
1008 }
1009 }
1010 }
1011
1012 boolean attachedBehindDream = false;
1013
1014 // Now perform layout of attached windows, which usually
1015 // depend on the position of the window they are attached to.
1016 // XXX does not deal with windows that are attached to windows
1017 // that are themselves attached.
1018 for (i = topAttached; i >= 0; i--) {
1019 final WindowState win = windows.get(i);
1020
1021 if (win.mLayoutAttached) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001022 if (DEBUG_LAYOUT) Slog.v(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001023 "2ND PASS " + win + " mHaveFrame=" + win.mHaveFrame + " mViewVisibility="
1024 + win.mViewVisibility + " mRelayoutCalled=" + win.mRelayoutCalled);
1025 // If this view is GONE, then skip it -- keep the current
1026 // frame, and let the caller know so they can ignore it
1027 // if they want. (We do the normal layout for INVISIBLE
1028 // windows, since that means "perform layout as normal,
1029 // just don't display").
1030 if (attachedBehindDream && mService.mPolicy.canBeForceHidden(win, win.mAttrs)) {
1031 continue;
1032 }
1033 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
1034 || !win.mHaveFrame || win.mLayoutNeeded) {
1035 if (initial) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001036 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001037 win.mContentChanged = false;
1038 }
1039 win.mLayoutNeeded = false;
1040 win.prelayout();
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001041 mService.mPolicy.layoutWindowLw(win, win.getParentWindow());
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001042 win.mLayoutSeq = seq;
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001043 if (DEBUG_LAYOUT) Slog.v(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001044 " LAYOUT: mFrame=" + win.mFrame + " mContainingFrame="
1045 + win.mContainingFrame + " mDisplayFrame=" + win.mDisplayFrame);
1046 }
1047 } else if (win.mAttrs.type == TYPE_DREAM) {
1048 // Don't layout windows behind a dream, so that if it
1049 // does stuff like hide the status bar we won't get a
1050 // bad transition when it goes away.
1051 attachedBehindDream = behindDream;
1052 }
1053 }
1054
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001055 // Window frames may have changed. Tell the input dispatcher about it.
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001056 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
1057 if (updateInputWindows) {
1058 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1059 }
1060
1061 mService.mPolicy.finishLayoutLw();
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001062 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001063 }
1064
1065 /**
1066 * @param windows List of windows on default display.
1067 * @return bitmap indicating if another pass through layout must be made.
1068 */
1069 private int handleAppTransitionReadyLocked(WindowList windows) {
1070 int appsCount = mService.mOpeningApps.size();
1071 if (!transitionGoodToGo(appsCount)) {
1072 return 0;
1073 }
Chong Zhang8784be62016-06-28 15:25:07 -07001074 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "AppTransitionReady");
1075
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001076 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001077 int transit = mService.mAppTransition.getAppTransition();
1078 if (mService.mSkipAppTransitionAnimation) {
1079 transit = AppTransition.TRANSIT_UNSET;
1080 }
1081 mService.mSkipAppTransitionAnimation = false;
1082 mService.mNoAnimationNotifyOnTransitionFinished.clear();
1083
Jorim Jaggid75962e2016-05-03 15:10:03 -07001084 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001085
1086 mService.rebuildAppWindowListLocked();
1087
1088 mWallpaperMayChange = false;
1089
1090 // The top-most window will supply the layout params,
1091 // and we will determine it below.
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001092 LayoutParams animLp = null;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001093 int bestAnimLayer = -1;
1094 boolean fullscreenAnim = false;
1095 boolean voiceInteraction = false;
1096
Chong Zhangec8299c2016-07-29 13:09:40 -07001097 int i;
1098 for (i = 0; i < appsCount; i++) {
1099 final AppWindowToken wtoken = mService.mOpeningApps.valueAt(i);
1100 // Clearing the mAnimatingExit flag before entering animation. It's set to
1101 // true if app window is removed, or window relayout to invisible.
1102 // This also affects window visibility. We need to clear it *before*
1103 // maybeUpdateTransitToWallpaper() as the transition selection depends on
1104 // wallpaper target visibility.
1105 wtoken.clearAnimatingFlags();
1106
1107 }
1108 // Adjust wallpaper before we pull the lower/upper target, since pending changes
1109 // (like the clearAnimatingFlags() above) might affect wallpaper target result.
1110 final DisplayContent displayContent = mService.getDefaultDisplayContentLocked();
1111 if ((displayContent.pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0 &&
1112 mWallpaperControllerLocked.adjustWallpaperWindows()) {
1113 mService.mLayersController.assignLayersLocked(windows);
1114 displayContent.layoutNeeded = true;
1115 }
1116
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001117 final WindowState lowerWallpaperTarget =
1118 mWallpaperControllerLocked.getLowerWallpaperTarget();
1119 final WindowState upperWallpaperTarget =
1120 mWallpaperControllerLocked.getUpperWallpaperTarget();
1121
1122 boolean openingAppHasWallpaper = false;
1123 boolean closingAppHasWallpaper = false;
1124 final AppWindowToken lowerWallpaperAppToken;
1125 final AppWindowToken upperWallpaperAppToken;
1126 if (lowerWallpaperTarget == null) {
1127 lowerWallpaperAppToken = upperWallpaperAppToken = null;
1128 } else {
1129 lowerWallpaperAppToken = lowerWallpaperTarget.mAppToken;
1130 upperWallpaperAppToken = upperWallpaperTarget.mAppToken;
1131 }
1132
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001133 // Do a first pass through the tokens for two
1134 // things:
1135 // (1) Determine if both the closing and opening
1136 // app token sets are wallpaper targets, in which
1137 // case special animations are needed
1138 // (since the wallpaper needs to stay static
1139 // behind them).
1140 // (2) Find the layout params of the top-most
1141 // application window in the tokens, which is
1142 // what will control the animation theme.
1143 final int closingAppsCount = mService.mClosingApps.size();
1144 appsCount = closingAppsCount + mService.mOpeningApps.size();
1145 for (i = 0; i < appsCount; i++) {
1146 final AppWindowToken wtoken;
1147 if (i < closingAppsCount) {
1148 wtoken = mService.mClosingApps.valueAt(i);
1149 if (wtoken == lowerWallpaperAppToken || wtoken == upperWallpaperAppToken) {
1150 closingAppHasWallpaper = true;
1151 }
1152 } else {
1153 wtoken = mService.mOpeningApps.valueAt(i - closingAppsCount);
1154 if (wtoken == lowerWallpaperAppToken || wtoken == upperWallpaperAppToken) {
1155 openingAppHasWallpaper = true;
1156 }
1157 }
1158
1159 voiceInteraction |= wtoken.voiceInteraction;
1160
1161 if (wtoken.appFullscreen) {
1162 WindowState ws = wtoken.findMainWindow();
1163 if (ws != null) {
1164 animLp = ws.mAttrs;
1165 bestAnimLayer = ws.mLayer;
1166 fullscreenAnim = true;
1167 }
1168 } else if (!fullscreenAnim) {
1169 WindowState ws = wtoken.findMainWindow();
1170 if (ws != null) {
1171 if (ws.mLayer > bestAnimLayer) {
1172 animLp = ws.mAttrs;
1173 bestAnimLayer = ws.mLayer;
1174 }
1175 }
1176 }
1177 }
1178
1179 transit = maybeUpdateTransitToWallpaper(transit, openingAppHasWallpaper,
1180 closingAppHasWallpaper, lowerWallpaperTarget, upperWallpaperTarget);
1181
1182 // If all closing windows are obscured, then there is
1183 // no need to do an animation. This is the case, for
1184 // example, when this transition is being done behind
1185 // the lock screen.
1186 if (!mService.mPolicy.allowAppAnimationsLw()) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001187 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001188 "Animations disallowed by keyguard or dream.");
1189 animLp = null;
1190 }
1191
1192 processApplicationsAnimatingInPlace(transit);
1193
Jorim Jaggi42625d1b2016-02-11 20:11:07 -08001194 mTmpLayerAndToken.token = null;
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001195 handleClosingApps(transit, animLp, voiceInteraction, mTmpLayerAndToken);
1196 final AppWindowToken topClosingApp = mTmpLayerAndToken.token;
1197 final int topClosingLayer = mTmpLayerAndToken.layer;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001198
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001199 final AppWindowToken topOpeningApp = handleOpeningApps(transit,
1200 animLp, voiceInteraction, topClosingLayer);
1201
Chong Zhang1c93f6d2016-07-27 17:52:45 -07001202 mService.mAppTransition.setLastAppTransition(transit, topOpeningApp, topClosingApp);
1203
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001204 final AppWindowAnimator openingAppAnimator = (topOpeningApp == null) ? null :
1205 topOpeningApp.mAppAnimator;
1206 final AppWindowAnimator closingAppAnimator = (topClosingApp == null) ? null :
1207 topClosingApp.mAppAnimator;
1208
Jorim Jaggi42625d1b2016-02-11 20:11:07 -08001209 mService.mAppTransition.goodToGo(openingAppAnimator, closingAppAnimator,
1210 mService.mOpeningApps, mService.mClosingApps);
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001211 mService.mAppTransition.postAnimationCallback();
1212 mService.mAppTransition.clear();
1213
1214 mService.mOpeningApps.clear();
1215 mService.mClosingApps.clear();
1216
1217 // This has changed the visibility of windows, so perform
1218 // a new layout to get them all up-to-date.
Chong Zhangec8299c2016-07-29 13:09:40 -07001219 displayContent.layoutNeeded = true;
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001220
1221 // TODO(multidisplay): IMEs are only supported on the default display.
1222 if (windows == mService.getDefaultWindowListLocked()
1223 && !mService.moveInputMethodWindowsIfNeededLocked(true)) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001224 mService.mLayersController.assignLayersLocked(windows);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001225 }
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001226 mService.updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
1227 true /*updateInputWindows*/);
1228 mService.mFocusMayChange = false;
1229 mService.notifyActivityDrawnForKeyguard();
Chong Zhang8784be62016-06-28 15:25:07 -07001230
1231 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
1232
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001233 return FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_CONFIG;
1234 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001235
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001236 private AppWindowToken handleOpeningApps(int transit, LayoutParams animLp,
1237 boolean voiceInteraction, int topClosingLayer) {
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001238 AppWindowToken topOpeningApp = null;
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001239 final int appsCount = mService.mOpeningApps.size();
1240 for (int i = 0; i < appsCount; i++) {
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001241 AppWindowToken wtoken = mService.mOpeningApps.valueAt(i);
1242 final AppWindowAnimator appAnimator = wtoken.mAppAnimator;
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001243 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Now opening app" + wtoken);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001244
1245 if (!appAnimator.usingTransferredAnimation) {
1246 appAnimator.clearThumbnail();
Chong Zhang65d15d02016-03-14 13:59:32 -07001247 appAnimator.setNullAnimation();
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001248 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001249
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001250 if (!wtoken.setVisibility(animLp, true, transit, false, voiceInteraction)){
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001251 // This token isn't going to be animating. Add it to the list of tokens to
1252 // be notified of app transition complete since the notification will not be
1253 // sent be the app window animator.
1254 mService.mNoAnimationNotifyOnTransitionFinished.add(wtoken.token);
1255 }
1256 wtoken.updateReportedVisibilityLocked();
1257 wtoken.waitingToShow = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001258 wtoken.setAllAppWinAnimators();
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001259
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001260 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
Filip Gruszczynski974eb3d2015-10-23 17:33:11 -07001261 ">>> OPEN TRANSACTION handleAppTransitionReadyLocked()");
1262 SurfaceControl.openTransaction();
1263 try {
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001264 mService.mAnimator.orAnimating(appAnimator.showAllWindowsLocked());
Filip Gruszczynski974eb3d2015-10-23 17:33:11 -07001265 } finally {
1266 SurfaceControl.closeTransaction();
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001267 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
Filip Gruszczynski974eb3d2015-10-23 17:33:11 -07001268 "<<< CLOSE TRANSACTION handleAppTransitionReadyLocked()");
1269 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001270 mService.mAnimator.mAppWindowAnimating |= appAnimator.isAnimating();
1271
1272 int topOpeningLayer = 0;
1273 if (animLp != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001274 final int layer = wtoken.getHighestAnimLayer();
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001275 if (topOpeningApp == null || layer > topOpeningLayer) {
1276 topOpeningApp = wtoken;
1277 topOpeningLayer = layer;
1278 }
1279 }
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001280 if (mService.mAppTransition.isNextAppTransitionThumbnailUp()) {
1281 createThumbnailAppAnimator(transit, wtoken, topOpeningLayer, topClosingLayer);
1282 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001283 }
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001284 return topOpeningApp;
1285 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001286
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001287 private void handleClosingApps(int transit, LayoutParams animLp, boolean voiceInteraction,
1288 LayerAndToken layerAndToken) {
1289 final int appsCount;
1290 appsCount = mService.mClosingApps.size();
1291 for (int i = 0; i < appsCount; i++) {
1292 AppWindowToken wtoken = mService.mClosingApps.valueAt(i);
Chong Zhangf58631a2016-05-24 16:02:10 -07001293
1294 // If we still have some windows animating with saved surfaces that's
1295 // either invisible or already removed, mark them exiting so that they
1296 // are disposed of after the exit animation. These are not supposed to
1297 // be shown, or are delayed removal until app is actually drawn (in which
1298 // case the window will be removed after the animation).
1299 wtoken.markSavedSurfaceExiting();
1300
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001301 final AppWindowAnimator appAnimator = wtoken.mAppAnimator;
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001302 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Now closing app " + wtoken);
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001303 appAnimator.clearThumbnail();
Chong Zhang65d15d02016-03-14 13:59:32 -07001304 appAnimator.setNullAnimation();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001305 wtoken.setVisibility(animLp, false, transit, false, voiceInteraction);
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001306 wtoken.updateReportedVisibilityLocked();
1307 // Force the allDrawn flag, because we want to start
1308 // this guy's animations regardless of whether it's
1309 // gotten drawn.
1310 wtoken.allDrawn = true;
1311 wtoken.deferClearAllDrawn = false;
1312 // Ensure that apps that are mid-starting are also scheduled to have their
1313 // starting windows removed after the animation is complete
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001314 if (wtoken.startingWindow != null && !wtoken.startingWindow.mAnimatingExit) {
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001315 mService.scheduleRemoveStartingWindowLocked(wtoken);
1316 }
1317 mService.mAnimator.mAppWindowAnimating |= appAnimator.isAnimating();
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001318
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001319 if (animLp != null) {
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07001320 int layer = wtoken.getHighestAnimLayer();
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001321 if (layerAndToken.token == null || layer > layerAndToken.layer) {
1322 layerAndToken.token = wtoken;
1323 layerAndToken.layer = layer;
1324 }
1325 }
1326 if (mService.mAppTransition.isNextAppTransitionThumbnailDown()) {
1327 createThumbnailAppAnimator(transit, wtoken, 0, layerAndToken.layer);
1328 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001329 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001330 }
1331
1332 private boolean transitionGoodToGo(int appsCount) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001333 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001334 "Checking " + appsCount + " opening apps (frozen="
1335 + mService.mDisplayFrozen + " timeout="
1336 + mService.mAppTransition.isTimeout() + ")...");
Jorim Jaggi275561a2016-02-23 10:11:02 -05001337 int reason = APP_TRANSITION_TIMEOUT;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001338 if (!mService.mAppTransition.isTimeout()) {
1339 for (int i = 0; i < appsCount; i++) {
1340 AppWindowToken wtoken = mService.mOpeningApps.valueAt(i);
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001341 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001342 "Check opening app=" + wtoken + ": allDrawn="
1343 + wtoken.allDrawn + " startingDisplayed="
1344 + wtoken.startingDisplayed + " startingMoved="
Chong Zhangd78ddb42016-03-02 17:01:14 -08001345 + wtoken.startingMoved + " isRelaunching()="
1346 + wtoken.isRelaunching());
1347
1348 if (wtoken.isRelaunching()) {
1349 return false;
1350 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001351
Jorim Jaggi275561a2016-02-23 10:11:02 -05001352 final boolean drawnBeforeRestoring = wtoken.allDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001353 wtoken.restoreSavedSurfaceForInterestingWindows();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08001354
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001355 if (!wtoken.allDrawn && !wtoken.startingDisplayed && !wtoken.startingMoved) {
1356 return false;
1357 }
Jorim Jaggi275561a2016-02-23 10:11:02 -05001358 if (wtoken.allDrawn) {
1359 reason = drawnBeforeRestoring ? APP_TRANSITION_WINDOWS_DRAWN
1360 : APP_TRANSITION_SAVED_SURFACE;
1361 } else {
1362 reason = APP_TRANSITION_STARTING_WINDOW;
1363 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001364 }
1365
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001366 // We also need to wait for the specs to be fetched, if needed.
1367 if (mService.mAppTransition.isFetchingAppTransitionsSpecs()) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001368 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "isFetchingAppTransitionSpecs=true");
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001369 return false;
1370 }
1371
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001372 // If the wallpaper is visible, we need to check it's ready too.
Jorim Jaggi275561a2016-02-23 10:11:02 -05001373 boolean wallpaperReady = !mWallpaperControllerLocked.isWallpaperVisible() ||
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001374 mWallpaperControllerLocked.wallpaperTransitionReady();
Jorim Jaggi275561a2016-02-23 10:11:02 -05001375 if (wallpaperReady) {
1376 mService.mH.obtainMessage(NOTIFY_APP_TRANSITION_STARTING, reason, 0).sendToTarget();
1377 return true;
1378 }
1379 return false;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001380 }
Jorim Jaggi275561a2016-02-23 10:11:02 -05001381 mService.mH.obtainMessage(NOTIFY_APP_TRANSITION_STARTING, reason, 0).sendToTarget();
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001382 return true;
1383 }
1384
1385 private int maybeUpdateTransitToWallpaper(int transit, boolean openingAppHasWallpaper,
1386 boolean closingAppHasWallpaper, WindowState lowerWallpaperTarget,
1387 WindowState upperWallpaperTarget) {
1388 // if wallpaper is animating in or out set oldWallpaper to null else to wallpaper
1389 final WindowState wallpaperTarget = mWallpaperControllerLocked.getWallpaperTarget();
1390 final WindowState oldWallpaper =
1391 mWallpaperControllerLocked.isWallpaperTargetAnimating()
1392 ? null : wallpaperTarget;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001393 final ArraySet<AppWindowToken> openingApps = mService.mOpeningApps;
1394 final ArraySet<AppWindowToken> closingApps = mService.mClosingApps;
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001395 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001396 "New wallpaper target=" + wallpaperTarget
1397 + ", oldWallpaper=" + oldWallpaper
1398 + ", lower target=" + lowerWallpaperTarget
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001399 + ", upper target=" + upperWallpaperTarget
1400 + ", openingApps=" + openingApps
1401 + ", closingApps=" + closingApps);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001402 mService.mAnimateWallpaperWithTarget = false;
1403 if (closingAppHasWallpaper && openingAppHasWallpaper) {
1404 if (DEBUG_APP_TRANSITIONS)
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001405 Slog.v(TAG, "Wallpaper animation!");
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001406 switch (transit) {
1407 case AppTransition.TRANSIT_ACTIVITY_OPEN:
1408 case AppTransition.TRANSIT_TASK_OPEN:
1409 case AppTransition.TRANSIT_TASK_TO_FRONT:
1410 transit = AppTransition.TRANSIT_WALLPAPER_INTRA_OPEN;
1411 break;
1412 case AppTransition.TRANSIT_ACTIVITY_CLOSE:
1413 case AppTransition.TRANSIT_TASK_CLOSE:
1414 case AppTransition.TRANSIT_TASK_TO_BACK:
1415 transit = AppTransition.TRANSIT_WALLPAPER_INTRA_CLOSE;
1416 break;
1417 }
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001418 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001419 "New transit: " + AppTransition.appTransitionToString(transit));
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001420 } else if (oldWallpaper != null && !mService.mOpeningApps.isEmpty()
1421 && !openingApps.contains(oldWallpaper.mAppToken)
1422 && closingApps.contains(oldWallpaper.mAppToken)) {
1423 // We are transitioning from an activity with a wallpaper to one without.
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001424 transit = AppTransition.TRANSIT_WALLPAPER_CLOSE;
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001425 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001426 "New transit away from wallpaper: "
1427 + AppTransition.appTransitionToString(transit));
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001428 } else if (wallpaperTarget != null && wallpaperTarget.isVisibleLw() &&
1429 openingApps.contains(wallpaperTarget.mAppToken)) {
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001430 // We are transitioning from an activity without
1431 // a wallpaper to now showing the wallpaper
1432 transit = AppTransition.TRANSIT_WALLPAPER_OPEN;
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001433 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001434 "New transit into wallpaper: "
1435 + AppTransition.appTransitionToString(transit));
1436 } else {
1437 mService.mAnimateWallpaperWithTarget = true;
1438 }
1439 return transit;
1440 }
1441
1442 /**
1443 * @param w WindowState this method is applied to.
Chong Zhang0abb20f2015-11-19 14:17:31 -08001444 * @param dispInfo info of the display that the window's obscuring state is checked against.
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001445 */
Chong Zhang0abb20f2015-11-19 14:17:31 -08001446 private void handleNotObscuredLocked(final WindowState w, final DisplayInfo dispInfo) {
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001447 final LayoutParams attrs = w.mAttrs;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001448 final int attrFlags = attrs.flags;
1449 final boolean canBeSeen = w.isDisplayedLw();
Ruchi Kandoi43e38de2016-04-14 19:34:53 -07001450 final int privateflags = attrs.privateFlags;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001451
Chong Zhang0abb20f2015-11-19 14:17:31 -08001452 if (canBeSeen && w.isObscuringFullscreen(dispInfo)) {
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001453 // This window completely covers everything behind it,
1454 // so we want to leave all of them as undimmed (for
1455 // performance reasons).
Chong Zhang4ffc3182016-05-04 15:06:02 -07001456 if (!mObscured) {
1457 mObsuringWindow = w;
1458 }
1459
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001460 mObscured = true;
1461 }
1462
Andrii Kulianb20addbd2016-08-09 18:52:01 -07001463 if (w.mHasSurface && canBeSeen) {
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001464 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
1465 mHoldScreen = w.mSession;
Chong Zhang4ffc3182016-05-04 15:06:02 -07001466 mHoldScreenWindow = w;
1467 } else if (DEBUG_KEEP_SCREEN_ON && w == mService.mLastWakeLockHoldingWindow) {
1468 Slog.d(TAG_KEEP_SCREEN_ON, "handleNotObscuredLocked: " + w + " was holding "
1469 + "screen wakelock but no longer has FLAG_KEEP_SCREEN_ON!!! called by"
1470 + Debug.getCallers(10));
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001471 }
1472 if (!mSyswin && w.mAttrs.screenBrightness >= 0
1473 && mScreenBrightness < 0) {
1474 mScreenBrightness = w.mAttrs.screenBrightness;
1475 }
1476 if (!mSyswin && w.mAttrs.buttonBrightness >= 0
1477 && mButtonBrightness < 0) {
1478 mButtonBrightness = w.mAttrs.buttonBrightness;
1479 }
1480 if (!mSyswin && w.mAttrs.userActivityTimeout >= 0
1481 && mUserActivityTimeout < 0) {
1482 mUserActivityTimeout = w.mAttrs.userActivityTimeout;
1483 }
1484
1485 final int type = attrs.type;
Andrii Kulianb20addbd2016-08-09 18:52:01 -07001486 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
1487 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001488 mSyswin = true;
1489 }
1490
Andrii Kulianb20addbd2016-08-09 18:52:01 -07001491 // This function assumes that the contents of the default display are
1492 // processed first before secondary displays.
1493 final DisplayContent displayContent = w.getDisplayContent();
1494 if (displayContent != null && displayContent.isDefaultDisplay) {
1495 // While a dream or keyguard is showing, obscure ordinary application
1496 // content on secondary displays (by forcibly enabling mirroring unless
1497 // there is other content we want to show) but still allow opaque
1498 // keyguard dialogs to be shown.
1499 if (type == TYPE_DREAM || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
1500 mObscureApplicationContentOnSecondaryDisplays = true;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001501 }
Andrii Kulianb20addbd2016-08-09 18:52:01 -07001502 mDisplayHasContent = true;
1503 } else if (displayContent != null &&
1504 (!mObscureApplicationContentOnSecondaryDisplays
1505 || (mObscured && type == TYPE_KEYGUARD_DIALOG))) {
1506 // Allow full screen keyguard presentation dialogs to be seen.
1507 mDisplayHasContent = true;
1508 }
1509 if (mPreferredRefreshRate == 0
1510 && w.mAttrs.preferredRefreshRate != 0) {
1511 mPreferredRefreshRate = w.mAttrs.preferredRefreshRate;
1512 }
1513 if (mPreferredModeId == 0
1514 && w.mAttrs.preferredDisplayModeId != 0) {
1515 mPreferredModeId = w.mAttrs.preferredDisplayModeId;
1516 }
1517 if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) {
1518 mSustainedPerformanceModeCurrent = true;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001519 }
1520 }
1521 }
1522
1523 private void updateAllDrawnLocked(DisplayContent displayContent) {
1524 // See if any windows have been drawn, so they (and others
1525 // associated with them) can now be shown.
1526 ArrayList<TaskStack> stacks = displayContent.getStacks();
1527 for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
1528 final ArrayList<Task> tasks = stacks.get(stackNdx).getTasks();
1529 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
1530 final AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
1531 for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
1532 final AppWindowToken wtoken = tokens.get(tokenNdx);
1533 if (!wtoken.allDrawn) {
1534 int numInteresting = wtoken.numInterestingWindows;
1535 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
1536 if (DEBUG_VISIBILITY)
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001537 Slog.v(TAG, "allDrawn: " + wtoken
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001538 + " interesting=" + numInteresting
1539 + " drawn=" + wtoken.numDrawnWindows);
1540 wtoken.allDrawn = true;
1541 // Force an additional layout pass where WindowStateAnimator#
1542 // commitFinishDrawingLocked() will call performShowLocked().
1543 displayContent.layoutNeeded = true;
1544 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN,
1545 wtoken.token).sendToTarget();
1546 }
1547 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07001548 if (!wtoken.allDrawnExcludingSaved) {
1549 int numInteresting = wtoken.numInterestingWindowsExcludingSaved;
1550 if (numInteresting > 0
Wale Ogunwale571771c2016-08-26 13:18:50 -07001551 && wtoken.numDrawnWindowsExcludingSaved >= numInteresting) {
Chong Zhang8e4bda92016-05-04 15:08:18 -07001552 if (DEBUG_VISIBILITY)
1553 Slog.v(TAG, "allDrawnExcludingSaved: " + wtoken
1554 + " interesting=" + numInteresting
Wale Ogunwale571771c2016-08-26 13:18:50 -07001555 + " drawn=" + wtoken.numDrawnWindowsExcludingSaved);
Chong Zhang8e4bda92016-05-04 15:08:18 -07001556 wtoken.allDrawnExcludingSaved = true;
1557 displayContent.layoutNeeded = true;
1558 if (wtoken.isAnimatingInvisibleWithSavedSurface()
1559 && !mService.mFinishedEarlyAnim.contains(wtoken)) {
1560 mService.mFinishedEarlyAnim.add(wtoken);
1561 }
1562 }
1563 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001564 }
1565 }
1566 }
1567 }
1568
1569 private static int toBrightnessOverride(float value) {
1570 return (int)(value * PowerManager.BRIGHTNESS_ON);
1571 }
1572
1573 private void processApplicationsAnimatingInPlace(int transit) {
1574 if (transit == AppTransition.TRANSIT_TASK_IN_PLACE) {
1575 // Find the focused window
1576 final WindowState win = mService.findFocusedWindowLocked(
1577 mService.getDefaultDisplayContentLocked());
1578 if (win != null) {
1579 final AppWindowToken wtoken = win.mAppToken;
1580 final AppWindowAnimator appAnimator = wtoken.mAppAnimator;
1581 if (DEBUG_APP_TRANSITIONS)
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001582 Slog.v(TAG, "Now animating app in place " + wtoken);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001583 appAnimator.clearThumbnail();
Chong Zhang65d15d02016-03-14 13:59:32 -07001584 appAnimator.setNullAnimation();
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001585 mService.updateTokenInPlaceLocked(wtoken, transit);
1586 wtoken.updateReportedVisibilityLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001587 wtoken.setAllAppWinAnimators();
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001588 mService.mAnimator.mAppWindowAnimating |= appAnimator.isAnimating();
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001589 mService.mAnimator.orAnimating(appAnimator.showAllWindowsLocked());
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001590 }
1591 }
1592 }
1593
1594 private void createThumbnailAppAnimator(int transit, AppWindowToken appToken,
1595 int openingLayer, int closingLayer) {
1596 AppWindowAnimator openingAppAnimator = (appToken == null) ? null : appToken.mAppAnimator;
1597 if (openingAppAnimator == null || openingAppAnimator.animation == null) {
1598 return;
1599 }
1600 final int taskId = appToken.mTask.mTaskId;
1601 Bitmap thumbnailHeader = mService.mAppTransition.getAppTransitionThumbnailHeader(taskId);
1602 if (thumbnailHeader == null || thumbnailHeader.getConfig() == Bitmap.Config.ALPHA_8) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001603 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG, "No thumbnail header bitmap for: " + taskId);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001604 return;
1605 }
1606 // This thumbnail animation is very special, we need to have
1607 // an extra surface with the thumbnail included with the animation.
1608 Rect dirty = new Rect(0, 0, thumbnailHeader.getWidth(), thumbnailHeader.getHeight());
1609 try {
1610 // TODO(multi-display): support other displays
1611 final DisplayContent displayContent = mService.getDefaultDisplayContentLocked();
1612 final Display display = displayContent.getDisplay();
1613 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
1614
1615 // Create a new surface for the thumbnail
1616 SurfaceControl surfaceControl = new SurfaceControl(mService.mFxSession,
1617 "thumbnail anim", dirty.width(), dirty.height(),
1618 PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN);
1619 surfaceControl.setLayerStack(display.getLayerStack());
1620 if (SHOW_TRANSACTIONS) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001621 Slog.i(TAG, " THUMBNAIL " + surfaceControl + ": CREATE");
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001622 }
1623
1624 // Draw the thumbnail onto the surface
1625 Surface drawSurface = new Surface();
1626 drawSurface.copyFrom(surfaceControl);
1627 Canvas c = drawSurface.lockCanvas(dirty);
1628 c.drawBitmap(thumbnailHeader, 0, 0, null);
1629 drawSurface.unlockCanvasAndPost(c);
1630 drawSurface.release();
1631
1632 // Get the thumbnail animation
1633 Animation anim;
1634 if (mService.mAppTransition.isNextThumbnailTransitionAspectScaled()) {
1635 // If this is a multi-window scenario, we use the windows frame as
1636 // destination of the thumbnail header animation. If this is a full screen
1637 // window scenario, we use the whole display as the target.
1638 WindowState win = appToken.findMainWindow();
1639 Rect appRect = win != null ? win.getContentFrameLw() :
1640 new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight);
Jorim Jaggide63d442016-03-14 14:56:56 +01001641 Rect insets = win != null ? win.mContentInsets : null;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001642 // For the new aspect-scaled transition, we want it to always show
1643 // above the animating opening/closing window, and we want to
1644 // synchronize its thumbnail surface with the surface for the
1645 // open/close animation (only on the way down)
1646 anim = mService.mAppTransition.createThumbnailAspectScaleAnimationLocked(appRect,
Winsonb2024762016-04-05 17:32:30 -07001647 insets, thumbnailHeader, taskId, mService.mCurConfiguration.uiMode,
1648 mService.mCurConfiguration.orientation);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001649 openingAppAnimator.thumbnailForceAboveLayer = Math.max(openingLayer, closingLayer);
1650 openingAppAnimator.deferThumbnailDestruction =
1651 !mService.mAppTransition.isNextThumbnailTransitionScaleUp();
1652 } else {
1653 anim = mService.mAppTransition.createThumbnailScaleAnimationLocked(
1654 displayInfo.appWidth, displayInfo.appHeight, transit, thumbnailHeader);
1655 }
1656 anim.restrictDuration(MAX_ANIMATION_DURATION);
1657 anim.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked());
1658
1659 openingAppAnimator.thumbnail = surfaceControl;
1660 openingAppAnimator.thumbnailLayer = openingLayer;
1661 openingAppAnimator.thumbnailAnimation = anim;
1662 mService.mAppTransition.getNextAppTransitionStartRect(taskId, mTmpStartRect);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001663 } catch (Surface.OutOfResourcesException e) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001664 Slog.e(TAG, "Can't allocate thumbnail/Canvas surface w="
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001665 + dirty.width() + " h=" + dirty.height(), e);
1666 openingAppAnimator.clearThumbnail();
1667 }
1668 }
1669
1670 boolean copyAnimToLayoutParamsLocked() {
1671 boolean doRequest = false;
1672
1673 final int bulkUpdateParams = mService.mAnimator.mBulkUpdateParams;
1674 if ((bulkUpdateParams & SET_UPDATE_ROTATION) != 0) {
1675 mUpdateRotation = true;
1676 doRequest = true;
1677 }
1678 if ((bulkUpdateParams & SET_WALLPAPER_MAY_CHANGE) != 0) {
1679 mWallpaperMayChange = true;
1680 doRequest = true;
1681 }
1682 if ((bulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0) {
1683 mWallpaperForceHidingChanged = true;
1684 doRequest = true;
1685 }
1686 if ((bulkUpdateParams & SET_ORIENTATION_CHANGE_COMPLETE) == 0) {
1687 mOrientationChangeComplete = false;
1688 } else {
1689 mOrientationChangeComplete = true;
1690 mLastWindowFreezeSource = mService.mAnimator.mLastWindowFreezeSource;
1691 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
1692 doRequest = true;
1693 }
1694 }
1695 if ((bulkUpdateParams & SET_TURN_ON_SCREEN) != 0) {
1696 mService.mTurnOnScreen = true;
1697 }
1698 if ((bulkUpdateParams & SET_WALLPAPER_ACTION_PENDING) != 0) {
1699 mWallpaperActionPending = true;
1700 }
1701
1702 return doRequest;
1703 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001704
1705 void requestTraversal() {
1706 if (!mTraversalScheduled) {
1707 mTraversalScheduled = true;
1708 mService.mH.sendEmptyMessage(DO_TRAVERSAL);
1709 }
1710 }
1711
Jorim Jaggi3dac63a2016-03-01 12:37:07 +01001712 /**
1713 * Puts the {@param surface} into a pending list to be destroyed after the current transaction
1714 * has been committed.
1715 */
1716 void destroyAfterTransaction(SurfaceControl surface) {
1717 mPendingDestroyingSurfaces.add(surface);
1718 }
1719
1720 /**
1721 * Destroys any surfaces that have been put into the pending list with
1722 * {@link #destroyAfterTransaction}.
1723 */
1724 void destroyPendingSurfaces() {
1725 for (int i = mPendingDestroyingSurfaces.size() - 1; i >= 0; i--) {
1726 mPendingDestroyingSurfaces.get(i).destroy();
1727 }
1728 mPendingDestroyingSurfaces.clear();
1729 }
1730
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001731 public void dump(PrintWriter pw, String prefix) {
1732 pw.print(prefix); pw.print("mTraversalScheduled="); pw.println(mTraversalScheduled);
Chong Zhang4ffc3182016-05-04 15:06:02 -07001733 pw.print(prefix); pw.print("mHoldScreenWindow="); pw.println(mHoldScreenWindow);
1734 pw.print(prefix); pw.print("mObsuringWindow="); pw.println(mObsuringWindow);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001735 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001736}