blob: cb7143952b9599cd56a5535abb1d81581c181648 [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;
Jorim Jaggi192086e2016-03-11 17:17:03 +010040import static com.android.server.wm.WindowManagerService.H.NOTIFY_APP_TRANSITION_STARTING;
41import static com.android.server.wm.WindowManagerService.H.NOTIFY_STARTING_WINDOW_DRAWN;
42import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS;
43import static com.android.server.wm.WindowManagerService.H.REPORT_WINDOWS_CHANGE;
44import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
45import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER;
46import static com.android.server.wm.WindowManagerService.H.WINDOW_FREEZE_TIMEOUT;
47import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
48import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070049import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES;
50import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
51import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_NONE;
52
53import android.graphics.Bitmap;
54import android.graphics.Canvas;
55import android.graphics.PixelFormat;
56import android.graphics.Rect;
57import android.os.Debug;
58import android.os.PowerManager;
59import android.os.RemoteException;
60import android.os.SystemClock;
61import android.os.Trace;
62import android.provider.Settings;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -070063import android.util.ArraySet;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070064import android.util.Slog;
65import android.view.Display;
66import android.view.DisplayInfo;
67import android.view.Surface;
68import android.view.SurfaceControl;
69import android.view.View;
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -080070import android.view.WindowManager.LayoutParams;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070071import android.view.animation.Animation;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070072
Jorim Jaggid75962e2016-05-03 15:10:03 -070073import com.android.server.wm.WindowManagerService.H;
74
Filip Gruszczynski24966d42015-09-05 15:00:00 -070075import java.io.PrintWriter;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070076import java.util.ArrayList;
77
78/**
79 * Positions windows and their surfaces.
80 *
81 * It sets positions of windows by calculating their frames and then applies this by positioning
82 * surfaces according to these frames. Z layer is still assigned withing WindowManagerService.
83 */
84class WindowSurfacePlacer {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -080085 private static final String TAG = TAG_WITH_CLASS_NAME ? "WindowSurfacePlacer" : TAG_WM;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070086 private final WindowManagerService mService;
87 private final WallpaperController mWallpaperControllerLocked;
88
89 private boolean mInLayout = false;
90
91 /** Only do a maximum of 6 repeated layouts. After that quit */
92 private int mLayoutRepeatCount;
93
94 static final int SET_UPDATE_ROTATION = 1 << 0;
95 static final int SET_WALLPAPER_MAY_CHANGE = 1 << 1;
96 static final int SET_FORCE_HIDING_CHANGED = 1 << 2;
97 static final int SET_ORIENTATION_CHANGE_COMPLETE = 1 << 3;
98 static final int SET_TURN_ON_SCREEN = 1 << 4;
99 static final int SET_WALLPAPER_ACTION_PENDING = 1 << 5;
100
101 boolean mWallpaperMayChange = false;
102 boolean mOrientationChangeComplete = true;
103 boolean mWallpaperActionPending = false;
104
105 private boolean mWallpaperForceHidingChanged = false;
106 private Object mLastWindowFreezeSource = null;
107 private Session mHoldScreen = null;
108 private boolean mObscured = false;
109 private boolean mSyswin = false;
110 private float mScreenBrightness = -1;
111 private float mButtonBrightness = -1;
112 private long mUserActivityTimeout = -1;
113 private boolean mUpdateRotation = false;
114 private final Rect mTmpStartRect = new Rect();
Wale Ogunwaleb4ec0a32015-12-14 10:31:43 -0800115 private final Rect mTmpContentRect = new Rect();
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700116
117 // Set to true when the display contains content to show the user.
118 // When false, the display manager may choose to mirror or blank the display.
119 private boolean mDisplayHasContent = false;
120
121 // Only set while traversing the default display based on its content.
122 // Affects the behavior of mirroring on secondary displays.
123 private boolean mObscureApplicationContentOnSecondaryDisplays = false;
124
125 private float mPreferredRefreshRate = 0;
126
127 private int mPreferredModeId = 0;
128
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700129 private boolean mTraversalScheduled;
Jorim Jaggic4025202015-10-22 16:43:34 +0200130 private int mDeferDepth = 0;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700131
Ruchi Kandoi43e38de2016-04-14 19:34:53 -0700132 private boolean mSustainedPerformanceModeEnabled = false;
133 private boolean mSustainedPerformanceModeCurrent = false;
134
Chong Zhang4ffc3182016-05-04 15:06:02 -0700135 // Following variables are for debugging screen wakelock only.
136 // Last window that requires screen wakelock
137 WindowState mHoldScreenWindow = null;
138 // Last window that obscures all windows below
139 WindowState mObsuringWindow = null;
140
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800141 private static final class LayerAndToken {
142 public int layer;
143 public AppWindowToken token;
144 }
145 private final LayerAndToken mTmpLayerAndToken = new LayerAndToken();
146
Jorim Jaggi3dac63a2016-03-01 12:37:07 +0100147 private final ArrayList<SurfaceControl> mPendingDestroyingSurfaces = new ArrayList<>();
148
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700149 public WindowSurfacePlacer(WindowManagerService service) {
150 mService = service;
151 mWallpaperControllerLocked = mService.mWallpaperControllerLocked;
152 }
153
Jorim Jaggic4025202015-10-22 16:43:34 +0200154 /**
155 * See {@link WindowManagerService#deferSurfaceLayout()}
156 */
157 void deferLayout() {
158 mDeferDepth++;
159 }
160
161 /**
162 * See {@link WindowManagerService#continueSurfaceLayout()}
163 */
164 void continueLayout() {
165 mDeferDepth--;
166 if (mDeferDepth <= 0) {
167 performSurfacePlacement();
168 }
169 }
170
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700171 final void performSurfacePlacement() {
Jorim Jaggic4025202015-10-22 16:43:34 +0200172 if (mDeferDepth > 0) {
173 return;
174 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700175 int loopCount = 6;
176 do {
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700177 mTraversalScheduled = false;
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700178 performSurfacePlacementLoop();
179 mService.mH.removeMessages(DO_TRAVERSAL);
180 loopCount--;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700181 } while (mTraversalScheduled && loopCount > 0);
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700182 mWallpaperActionPending = false;
183 }
184
185 private void performSurfacePlacementLoop() {
186 if (mInLayout) {
187 if (DEBUG) {
188 throw new RuntimeException("Recursive call!");
189 }
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800190 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout. Callers="
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700191 + Debug.getCallers(3));
192 return;
193 }
194
195 if (mService.mWaitingForConfig) {
196 // Our configuration has changed (most likely rotation), but we
197 // don't yet have the complete configuration to report to
198 // applications. Don't do any window layout until we have it.
199 return;
200 }
201
202 if (!mService.mDisplayReady) {
203 // Not yet initialized, nothing to do.
204 return;
205 }
206
207 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "wmLayout");
208 mInLayout = true;
209
210 boolean recoveringMemory = false;
211 if (!mService.mForceRemoves.isEmpty()) {
212 recoveringMemory = true;
213 // Wait a little bit for things to settle down, and off we go.
214 while (!mService.mForceRemoves.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700215 final WindowState ws = mService.mForceRemoves.remove(0);
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800216 Slog.i(TAG, "Force removing: " + ws);
Wale Ogunwale571771c2016-08-26 13:18:50 -0700217 ws.removeImmediately();
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700218 }
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800219 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700220 Object tmp = new Object();
221 synchronized (tmp) {
222 try {
223 tmp.wait(250);
224 } catch (InterruptedException e) {
225 }
226 }
227 }
228
229 try {
230 performSurfacePlacementInner(recoveringMemory);
231
232 mInLayout = false;
233
234 if (mService.needsLayout()) {
235 if (++mLayoutRepeatCount < 6) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700236 requestTraversal();
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700237 } else {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800238 Slog.e(TAG, "Performed 6 layouts in a row. Skipping");
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700239 mLayoutRepeatCount = 0;
240 }
241 } else {
242 mLayoutRepeatCount = 0;
243 }
244
245 if (mService.mWindowsChanged && !mService.mWindowChangeListeners.isEmpty()) {
246 mService.mH.removeMessages(REPORT_WINDOWS_CHANGE);
247 mService.mH.sendEmptyMessage(REPORT_WINDOWS_CHANGE);
248 }
249 } catch (RuntimeException e) {
250 mInLayout = false;
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800251 Slog.wtf(TAG, "Unhandled exception while laying out windows", e);
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700252 }
253
254 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
255 }
256
257 void debugLayoutRepeats(final String msg, int pendingLayoutChanges) {
258 if (mLayoutRepeatCount >= LAYOUT_REPEAT_THRESHOLD) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800259 Slog.v(TAG, "Layouts looping: " + msg +
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700260 ", mPendingLayoutChanges = 0x" + Integer.toHexString(pendingLayoutChanges));
261 }
262 }
263
264 // "Something has changed! Let's make it correct now."
265 private void performSurfacePlacementInner(boolean recoveringMemory) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800266 if (DEBUG_WINDOW_TRACE) Slog.v(TAG, "performSurfacePlacementInner: entry. Called by "
267 + Debug.getCallers(3));
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700268
269 int i;
270 boolean updateInputWindowsNeeded = false;
271
272 if (mService.mFocusMayChange) {
273 mService.mFocusMayChange = false;
274 updateInputWindowsNeeded = mService.updateFocusedWindowLocked(
275 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
276 }
277
278 // Initialize state of exiting tokens.
279 final int numDisplays = mService.mDisplayContents.size();
280 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
281 final DisplayContent displayContent = mService.mDisplayContents.valueAt(displayNdx);
282 for (i=displayContent.mExitingTokens.size()-1; i>=0; i--) {
283 displayContent.mExitingTokens.get(i).hasVisible = false;
284 }
285 }
286
287 for (int stackNdx = mService.mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) {
288 // Initialize state of exiting applications.
289 final AppTokenList exitingAppTokens =
290 mService.mStackIdToStack.valueAt(stackNdx).mExitingAppTokens;
291 for (int tokenNdx = exitingAppTokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
292 exitingAppTokens.get(tokenNdx).hasVisible = false;
293 }
294 }
295
296 mHoldScreen = null;
Chong Zhang4ffc3182016-05-04 15:06:02 -0700297 mHoldScreenWindow = null;
298 mObsuringWindow = null;
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700299 mScreenBrightness = -1;
300 mButtonBrightness = -1;
301 mUserActivityTimeout = -1;
302 mObscureApplicationContentOnSecondaryDisplays = false;
Ruchi Kandoi43e38de2016-04-14 19:34:53 -0700303 mSustainedPerformanceModeCurrent = false;
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700304 mService.mTransactionSequence++;
305
306 final DisplayContent defaultDisplay = mService.getDefaultDisplayContentLocked();
307 final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo();
308 final int defaultDw = defaultInfo.logicalWidth;
309 final int defaultDh = defaultInfo.logicalHeight;
310
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800311 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700312 ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700313 mService.openSurfaceTransaction();
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700314 try {
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700315 applySurfaceChangesTransaction(recoveringMemory, numDisplays, defaultDw, defaultDh);
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700316 } catch (RuntimeException e) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800317 Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700318 } finally {
Robert Carr68e5c9e2016-09-14 10:50:09 -0700319 mService.closeSurfaceTransaction();
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800320 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700321 "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
322 }
323
324 final WindowList defaultWindows = defaultDisplay.getWindowList();
325
326 // If we are ready to perform an app transition, check through
327 // all of the app tokens to be shown and see if they are ready
328 // to go.
329 if (mService.mAppTransition.isReady()) {
330 defaultDisplay.pendingLayoutChanges |= handleAppTransitionReadyLocked(defaultWindows);
331 if (DEBUG_LAYOUT_REPEATS)
332 debugLayoutRepeats("after handleAppTransitionReadyLocked",
333 defaultDisplay.pendingLayoutChanges);
334 }
335
336 if (!mService.mAnimator.mAppWindowAnimating && mService.mAppTransition.isRunning()) {
337 // We have finished the animation of an app transition. To do
338 // this, we have delayed a lot of operations like showing and
339 // hiding apps, moving apps in Z-order, etc. The app token list
340 // reflects the correct Z-order, but the window list may now
341 // be out of sync with it. So here we will just rebuild the
342 // entire app window list. Fun!
343 defaultDisplay.pendingLayoutChanges |=
344 mService.handleAnimatingStoppedAndTransitionLocked();
345 if (DEBUG_LAYOUT_REPEATS)
346 debugLayoutRepeats("after handleAnimStopAndXitionLock",
347 defaultDisplay.pendingLayoutChanges);
348 }
349
350 if (mWallpaperForceHidingChanged && defaultDisplay.pendingLayoutChanges == 0
351 && !mService.mAppTransition.isReady()) {
352 // At this point, there was a window with a wallpaper that
353 // was force hiding other windows behind it, but now it
354 // is going away. This may be simple -- just animate
355 // away the wallpaper and its window -- or it may be
356 // hard -- the wallpaper now needs to be shown behind
357 // something that was hidden.
358 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
359 if (DEBUG_LAYOUT_REPEATS)
360 debugLayoutRepeats("after animateAwayWallpaperLocked",
361 defaultDisplay.pendingLayoutChanges);
362 }
363 mWallpaperForceHidingChanged = false;
364
365 if (mWallpaperMayChange) {
366 if (DEBUG_WALLPAPER_LIGHT)
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800367 Slog.v(TAG, "Wallpaper may change! Adjusting");
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700368 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
369 if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("WallpaperMayChange",
370 defaultDisplay.pendingLayoutChanges);
371 }
372
373 if (mService.mFocusMayChange) {
374 mService.mFocusMayChange = false;
375 if (mService.updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
376 false /*updateInputWindows*/)) {
377 updateInputWindowsNeeded = true;
378 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
379 }
380 }
381
382 if (mService.needsLayout()) {
383 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
384 if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("mLayoutNeeded",
385 defaultDisplay.pendingLayoutChanges);
386 }
387
388 for (i = mService.mResizingWindows.size() - 1; i >= 0; i--) {
389 WindowState win = mService.mResizingWindows.get(i);
390 if (win.mAppFreezing) {
391 // Don't remove this window until rotation has completed.
392 continue;
393 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700394 // Discard the saved surface if window size is changed, it can't be reused.
Chong Zhangbef461f2015-10-27 11:38:24 -0700395 if (win.mAppToken != null) {
396 win.mAppToken.destroySavedSurfaces();
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700397 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700398 win.reportResized();
399 mService.mResizingWindows.remove(i);
400 }
401
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800402 if (DEBUG_ORIENTATION && mService.mDisplayFrozen) Slog.v(TAG,
403 "With display frozen, orientationChangeComplete=" + mOrientationChangeComplete);
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700404 if (mOrientationChangeComplete) {
405 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
406 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_NONE;
407 mService.mLastFinishedFreezeSource = mLastWindowFreezeSource;
408 mService.mH.removeMessages(WINDOW_FREEZE_TIMEOUT);
409 }
410 mService.stopFreezingDisplayLocked();
411 }
412
413 // Destroy the surface of any windows that are no longer visible.
Filip Gruszczynski19723a42015-11-25 15:01:48 -0800414 boolean wallpaperDestroyed = false;
415 i = mService.mDestroySurface.size();
416 if (i > 0) {
417 do {
418 i--;
419 WindowState win = mService.mDestroySurface.get(i);
420 win.mDestroying = false;
421 if (mService.mInputMethodWindow == win) {
422 mService.mInputMethodWindow = null;
423 }
424 if (mWallpaperControllerLocked.isWallpaperTarget(win)) {
425 wallpaperDestroyed = true;
426 }
Robert Carr13f7be9e2015-12-02 18:39:45 -0800427 win.destroyOrSaveSurface();
Filip Gruszczynski19723a42015-11-25 15:01:48 -0800428 } while (i > 0);
429 mService.mDestroySurface.clear();
430 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700431
432 // Time to remove any exiting tokens?
433 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
434 final DisplayContent displayContent = mService.mDisplayContents.valueAt(displayNdx);
435 ArrayList<WindowToken> exitingTokens = displayContent.mExitingTokens;
436 for (i = exitingTokens.size() - 1; i >= 0; i--) {
437 WindowToken token = exitingTokens.get(i);
438 if (!token.hasVisible) {
439 exitingTokens.remove(i);
440 if (token.windowType == TYPE_WALLPAPER) {
441 mWallpaperControllerLocked.removeWallpaperToken(token);
442 }
443 }
444 }
445 }
446
447 // Time to remove any exiting applications?
448 for (int stackNdx = mService.mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) {
449 // Initialize state of exiting applications.
450 final AppTokenList exitingAppTokens =
451 mService.mStackIdToStack.valueAt(stackNdx).mExitingAppTokens;
452 for (i = exitingAppTokens.size() - 1; i >= 0; i--) {
453 AppWindowToken token = exitingAppTokens.get(i);
454 if (!token.hasVisible && !mService.mClosingApps.contains(token) &&
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700455 (!token.mIsExiting || token.isEmpty())) {
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700456 // Make sure there is no animation running on this token,
457 // so any windows associated with it will be removed as
458 // soon as their animations are complete
459 token.mAppAnimator.clearAnimation();
460 token.mAppAnimator.animating = false;
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800461 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
462 "performLayout: App token exiting now removed" + token);
Wale Ogunwale571771c2016-08-26 13:18:50 -0700463 token.removeIfPossible();
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700464 }
465 }
466 }
467
468 if (wallpaperDestroyed) {
469 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
470 defaultDisplay.layoutNeeded = true;
471 }
472
473 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
474 final DisplayContent displayContent = mService.mDisplayContents.valueAt(displayNdx);
475 if (displayContent.pendingLayoutChanges != 0) {
476 displayContent.layoutNeeded = true;
477 }
478 }
479
480 // Finally update all input windows now that the window changes have stabilized.
481 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
482
483 mService.setHoldScreenLocked(mHoldScreen);
484 if (!mService.mDisplayFrozen) {
485 if (mScreenBrightness < 0 || mScreenBrightness > 1.0f) {
486 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(-1);
487 } else {
488 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(
489 toBrightnessOverride(mScreenBrightness));
490 }
491 if (mButtonBrightness < 0
492 || mButtonBrightness > 1.0f) {
493 mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(-1);
494 } else {
495 mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(
496 toBrightnessOverride(mButtonBrightness));
497 }
498 mService.mPowerManagerInternal.setUserActivityTimeoutOverrideFromWindowManager(
499 mUserActivityTimeout);
500 }
501
Ruchi Kandoi43e38de2016-04-14 19:34:53 -0700502 if (mSustainedPerformanceModeCurrent != mSustainedPerformanceModeEnabled) {
503 mSustainedPerformanceModeEnabled = mSustainedPerformanceModeCurrent;
504 mService.mPowerManagerInternal.powerHint(
505 mService.mPowerManagerInternal.POWER_HINT_SUSTAINED_PERFORMANCE_MODE,
506 (mSustainedPerformanceModeEnabled ? 1 : 0));
507 }
508
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700509 if (mService.mTurnOnScreen) {
510 if (mService.mAllowTheaterModeWakeFromLayout
511 || Settings.Global.getInt(mService.mContext.getContentResolver(),
512 Settings.Global.THEATER_MODE_ON, 0) == 0) {
513 if (DEBUG_VISIBILITY || DEBUG_POWER) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800514 Slog.v(TAG, "Turning screen on after layout!");
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700515 }
516 mService.mPowerManager.wakeUp(SystemClock.uptimeMillis(),
517 "android.server.wm:TURN_ON");
518 }
519 mService.mTurnOnScreen = false;
520 }
521
522 if (mUpdateRotation) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800523 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700524 if (mService.updateRotationUncheckedLocked(false)) {
525 mService.mH.sendEmptyMessage(SEND_NEW_CONFIGURATION);
526 } else {
527 mUpdateRotation = false;
528 }
529 }
530
531 if (mService.mWaitingForDrawnCallback != null ||
532 (mOrientationChangeComplete && !defaultDisplay.layoutNeeded &&
533 !mUpdateRotation)) {
534 mService.checkDrawnWindowsLocked();
535 }
536
537 final int N = mService.mPendingRemove.size();
538 if (N > 0) {
539 if (mService.mPendingRemoveTmp.length < N) {
540 mService.mPendingRemoveTmp = new WindowState[N+10];
541 }
542 mService.mPendingRemove.toArray(mService.mPendingRemoveTmp);
543 mService.mPendingRemove.clear();
544 DisplayContentList displayList = new DisplayContentList();
545 for (i = 0; i < N; i++) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700546 final WindowState w = mService.mPendingRemoveTmp[i];
Wale Ogunwale571771c2016-08-26 13:18:50 -0700547 w.removeImmediately();
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700548 final DisplayContent displayContent = w.getDisplayContent();
549 if (displayContent != null && !displayList.contains(displayContent)) {
550 displayList.add(displayContent);
551 }
552 }
553
554 for (DisplayContent displayContent : displayList) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -0800555 mService.mLayersController.assignLayersLocked(displayContent.getWindowList());
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700556 displayContent.layoutNeeded = true;
557 }
558 }
559
560 // Remove all deferred displays stacks, tasks, and activities.
561 for (int displayNdx = mService.mDisplayContents.size() - 1; displayNdx >= 0; --displayNdx) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700562 mService.mDisplayContents.valueAt(displayNdx).checkCompleteDeferredRemoval();
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700563 }
564
565 if (updateInputWindowsNeeded) {
566 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
567 }
Chong Zhangb15758a2015-11-17 12:12:03 -0800568 mService.setFocusTaskRegionLocked();
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700569
570 // Check to see if we are now in a state where the screen should
571 // be enabled, because the window obscured flags have changed.
572 mService.enableScreenIfNeededLocked();
573
574 mService.scheduleAnimationLocked();
Jorim Jaggi3dac63a2016-03-01 12:37:07 +0100575 mService.mWindowPlacerLocked.destroyPendingSurfaces();
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700576
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800577 if (DEBUG_WINDOW_TRACE) Slog.e(TAG,
Wale Ogunwale69cf50f2015-11-13 11:08:36 -0800578 "performSurfacePlacementInner exit: animating=" + mService.mAnimator.isAnimating());
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700579 }
580
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700581 private void applySurfaceChangesTransaction(boolean recoveringMemory, int numDisplays,
582 int defaultDw, int defaultDh) {
583 if (mService.mWatermark != null) {
584 mService.mWatermark.positionSurface(defaultDw, defaultDh);
585 }
586 if (mService.mStrictModeFlash != null) {
587 mService.mStrictModeFlash.positionSurface(defaultDw, defaultDh);
588 }
589 if (mService.mCircularDisplayMask != null) {
590 mService.mCircularDisplayMask.positionSurface(defaultDw, defaultDh,
591 mService.mRotation);
592 }
593 if (mService.mEmulatorDisplayOverlay != null) {
594 mService.mEmulatorDisplayOverlay.positionSurface(defaultDw, defaultDh,
595 mService.mRotation);
596 }
597
598 boolean focusDisplayed = false;
599
600 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
601 final DisplayContent displayContent = mService.mDisplayContents.valueAt(displayNdx);
602 boolean updateAllDrawn = false;
603 WindowList windows = displayContent.getWindowList();
604 DisplayInfo displayInfo = displayContent.getDisplayInfo();
605 final int displayId = displayContent.getDisplayId();
606 final int dw = displayInfo.logicalWidth;
607 final int dh = displayInfo.logicalHeight;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700608 final boolean isDefaultDisplay = (displayId == Display.DEFAULT_DISPLAY);
609
610 // Reset for each display.
611 mDisplayHasContent = false;
612 mPreferredRefreshRate = 0;
613 mPreferredModeId = 0;
614
615 int repeats = 0;
616 do {
617 repeats++;
618 if (repeats > 6) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800619 Slog.w(TAG, "Animation repeat aborted after too many iterations");
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700620 displayContent.layoutNeeded = false;
621 break;
622 }
623
624 if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats(
625 "On entry to LockedInner", displayContent.pendingLayoutChanges);
626
627 if ((displayContent.pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0 &&
628 mWallpaperControllerLocked.adjustWallpaperWindows()) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -0800629 mService.mLayersController.assignLayersLocked(windows);
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700630 displayContent.layoutNeeded = true;
631 }
632
633 if (isDefaultDisplay
634 && (displayContent.pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800635 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700636 if (mService.updateOrientationFromAppTokensLocked(true)) {
637 displayContent.layoutNeeded = true;
638 mService.mH.sendEmptyMessage(SEND_NEW_CONFIGURATION);
639 }
640 }
641
642 if ((displayContent.pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
643 displayContent.layoutNeeded = true;
644 }
645
646 // FIRST LOOP: Perform a layout, if needed.
647 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
648 performLayoutLockedInner(displayContent, repeats == 1,
649 false /* updateInputWindows */);
650 } else {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800651 Slog.w(TAG, "Layout repeat skipped after too many iterations");
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700652 }
653
654 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think
655 // it is animating.
656 displayContent.pendingLayoutChanges = 0;
657
658 if (isDefaultDisplay) {
659 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
660 for (int i = windows.size() - 1; i >= 0; i--) {
661 WindowState w = windows.get(i);
662 if (w.mHasSurface) {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -0700663 mService.mPolicy.applyPostLayoutPolicyLw(
664 w, w.mAttrs, w.getParentWindow());
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700665 }
666 }
667 displayContent.pendingLayoutChanges |=
668 mService.mPolicy.finishPostLayoutPolicyLw();
669 if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("after finishPostLayoutPolicyLw",
670 displayContent.pendingLayoutChanges);
671 }
672 } while (displayContent.pendingLayoutChanges != 0);
673
674 mObscured = false;
675 mSyswin = false;
676 displayContent.resetDimming();
677
678 // Only used if default window
679 final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty();
680
681 for (int i = windows.size() - 1; i >= 0; i--) {
682 WindowState w = windows.get(i);
Robert Carr0d00c2e2016-02-29 17:45:02 -0800683 final Task task = w.getTask();
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700684 final boolean obscuredChanged = w.mObscured != mObscured;
685
686 // Update effect.
687 w.mObscured = mObscured;
688 if (!mObscured) {
Chong Zhang0abb20f2015-11-19 14:17:31 -0800689 handleNotObscuredLocked(w, displayInfo);
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700690 }
691
Chong Zhang112eb8c2015-11-02 11:17:00 -0800692 w.applyDimLayerIfNeeded();
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700693
694 if (isDefaultDisplay && obscuredChanged
695 && mWallpaperControllerLocked.isWallpaperTarget(w) && w.isVisibleLw()) {
696 // This is the wallpaper target and its obscured state
697 // changed... make sure the current wallaper's visibility
698 // has been updated accordingly.
699 mWallpaperControllerLocked.updateWallpaperVisibility();
700 }
701
702 final WindowStateAnimator winAnimator = w.mWinAnimator;
703
704 // If the window has moved due to its containing content frame changing, then
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800705 // notify the listeners and optionally animate it. Simply checking a change of
706 // position is not enough, because being move due to dock divider is not a trigger
707 // for animation.
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700708 if (w.hasMoved()) {
709 // Frame has moved, containing content frame has also moved, and we're not
710 // currently animating... let's do something.
711 final int left = w.mFrame.left;
712 final int top = w.mFrame.top;
Chong Zhangbaba7832016-03-24 10:21:26 -0700713 final boolean adjustedForMinimizedDockOrIme = task != null
714 && (task.mStack.isAdjustedForMinimizedDockedStack()
715 || task.mStack.isAdjustedForIme());
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800716 if ((w.mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
Chong Zhangbaba7832016-03-24 10:21:26 -0700717 && !w.isDragResizing() && !adjustedForMinimizedDockOrIme
Robert Carrc7294602016-05-13 11:32:05 -0700718 && (task == null || w.getTask().mStack.hasMovementAnimations())
Jorim Jaggi192086e2016-03-11 17:17:03 +0100719 && !w.mWinAnimator.mLastHidden) {
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800720 winAnimator.setMoveAnimation(left, top);
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700721 }
722
723 //TODO (multidisplay): Accessibility supported only for the default display.
724 if (mService.mAccessibilityController != null
725 && displayId == Display.DEFAULT_DISPLAY) {
726 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
727 }
728
729 try {
Wale Ogunwale7774bd52016-06-17 09:44:22 -0700730 w.mClient.moved(left, top);
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700731 } catch (RemoteException e) {
732 }
Jorim Jaggi192086e2016-03-11 17:17:03 +0100733 w.mMovedByResize = false;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700734 }
735
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800736 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700737 w.mContentChanged = false;
738
739 // Moved from updateWindowsAndWallpaperLocked().
740 if (w.mHasSurface) {
741 // Take care of the window being ready to display.
742 final boolean committed = winAnimator.commitFinishDrawingLocked();
743 if (isDefaultDisplay && committed) {
744 if (w.mAttrs.type == TYPE_DREAM) {
745 // HACK: When a dream is shown, it may at that
746 // point hide the lock screen. So we need to
747 // redo the layout to let the phone window manager
748 // make this happen.
749 displayContent.pendingLayoutChanges |=
750 FINISH_LAYOUT_REDO_LAYOUT;
751 if (DEBUG_LAYOUT_REPEATS) {
752 debugLayoutRepeats("dream and commitFinishDrawingLocked true",
753 displayContent.pendingLayoutChanges);
754 }
755 }
756 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
757 if (DEBUG_WALLPAPER_LIGHT)
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800758 Slog.v(TAG, "First draw done in potential wallpaper target " + w);
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700759 mWallpaperMayChange = true;
760 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
761 if (DEBUG_LAYOUT_REPEATS) {
762 debugLayoutRepeats("wallpaper and commitFinishDrawingLocked true",
763 displayContent.pendingLayoutChanges);
764 }
765 }
766 }
Chong Zhange22006d2016-05-09 10:59:59 -0700767 if (!winAnimator.isAnimationStarting() && !winAnimator.isWaitingForOpening()) {
Filip Gruszczynskic46f41c2016-01-05 11:29:21 -0800768 // Updates the shown frame before we set up the surface. This is needed
769 // because the resizing could change the top-left position (in addition to
770 // size) of the window. setSurfaceBoundariesLocked uses mShownPosition to
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700771 // position the surface.
772 //
773 // If an animation is being started, we can't call this method because the
774 // animation hasn't processed its initial transformation yet, but in general
775 // we do want to update the position if the window is animating.
Filip Gruszczynskic46f41c2016-01-05 11:29:21 -0800776 winAnimator.computeShownFrameLocked();
777 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700778 winAnimator.setSurfaceBoundariesLocked(recoveringMemory);
779 }
780
781 final AppWindowToken atoken = w.mAppToken;
782 if (DEBUG_STARTING_WINDOW && atoken != null && w == atoken.startingWindow) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800783 Slog.d(TAG, "updateWindows: starting " + w
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700784 + " isOnScreen=" + w.isOnScreen() + " allDrawn=" + atoken.allDrawn
785 + " freezingScreen=" + atoken.mAppAnimator.freezingScreen);
786 }
Chong Zhang8e4bda92016-05-04 15:08:18 -0700787 if (atoken != null && (!atoken.allDrawn || !atoken.allDrawnExcludingSaved
788 || atoken.mAppAnimator.freezingScreen)) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700789 if (atoken.lastTransactionSequence != mService.mTransactionSequence) {
790 atoken.lastTransactionSequence = mService.mTransactionSequence;
791 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700792 atoken.numInterestingWindowsExcludingSaved = 0;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700793 atoken.numDrawnWindowsExcludingSaved = 0;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700794 atoken.startingDisplayed = false;
795 }
Chong Zhang8e4bda92016-05-04 15:08:18 -0700796 if (!atoken.allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700797 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800798 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700799 + w.isDrawnLw()
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700800 + ", isAnimationSet=" + winAnimator.isAnimationSet());
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700801 if (!w.isDrawnLw()) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800802 Slog.v(TAG, "Not displayed: s="
Robert Carre6a83512015-11-03 16:09:21 -0800803 + winAnimator.mSurfaceController
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700804 + " pv=" + w.mPolicyVisibility
805 + " mDrawState=" + winAnimator.drawStateToString()
Wale Ogunwale9d147902016-07-16 11:58:55 -0700806 + " ph=" + w.isParentWindowHidden()
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700807 + " th=" + atoken.hiddenRequested
808 + " a=" + winAnimator.mAnimating);
809 }
810 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800811 if (w != atoken.startingWindow) {
Chong Zhang8e4bda92016-05-04 15:08:18 -0700812 if (w.isInteresting()) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700813 atoken.numInterestingWindows++;
814 if (w.isDrawnLw()) {
815 atoken.numDrawnWindows++;
816 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION)
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800817 Slog.v(TAG, "tokenMayBeDrawn: " + atoken
Chong Zhang8e4bda92016-05-04 15:08:18 -0700818 + " w=" + w + " numInteresting="
819 + atoken.numInterestingWindows
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700820 + " freezingScreen="
821 + atoken.mAppAnimator.freezingScreen
822 + " mAppFreezing=" + w.mAppFreezing);
823 updateAllDrawn = true;
824 }
825 }
826 } else if (w.isDrawnLw()) {
Jorim Jaggi275561a2016-02-23 10:11:02 -0500827 mService.mH.sendEmptyMessage(NOTIFY_STARTING_WINDOW_DRAWN);
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700828 atoken.startingDisplayed = true;
829 }
830 }
Chong Zhang8e4bda92016-05-04 15:08:18 -0700831 if (!atoken.allDrawnExcludingSaved
832 && w.mightAffectAllDrawn(true /* visibleOnly */)) {
833 if (w != atoken.startingWindow && w.isInteresting()) {
834 atoken.numInterestingWindowsExcludingSaved++;
835 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
Wale Ogunwale571771c2016-08-26 13:18:50 -0700836 atoken.numDrawnWindowsExcludingSaved++;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700837 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION)
838 Slog.v(TAG, "tokenMayBeDrawnExcludingSaved: " + atoken
839 + " w=" + w + " numInteresting="
840 + atoken.numInterestingWindowsExcludingSaved
841 + " freezingScreen="
842 + atoken.mAppAnimator.freezingScreen
843 + " mAppFreezing=" + w.mAppFreezing);
844 updateAllDrawn = true;
845 }
846 }
847 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700848 }
849
850 if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus
851 && w.isDisplayedLw()) {
852 focusDisplayed = true;
853 }
854
855 mService.updateResizingWindows(w);
856 }
857
858 mService.mDisplayManagerInternal.setDisplayProperties(displayId,
859 mDisplayHasContent,
860 mPreferredRefreshRate,
861 mPreferredModeId,
862 true /* inTraversal, must call performTraversalInTrans... below */);
863
Wale Ogunwale15ead902016-09-02 14:30:11 -0700864 displayContent.stopDimmingIfNeeded();
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700865
866 if (updateAllDrawn) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700867 // See if any windows have been drawn, so they (and others associated with them)
868 // can now be shown.
869 displayContent.updateAllDrawn();
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700870 }
871 }
872
873 if (focusDisplayed) {
874 mService.mH.sendEmptyMessage(REPORT_LOSING_FOCUS);
875 }
876
877 // Give the display manager a chance to adjust properties
878 // like display rotation if it needs to.
879 mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
880 }
881
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700882 boolean isInLayout() {
883 return mInLayout;
884 }
885
886 final void performLayoutLockedInner(final DisplayContent displayContent,
887 boolean initial, boolean updateInputWindows) {
888 if (!displayContent.layoutNeeded) {
889 return;
890 }
891 displayContent.layoutNeeded = false;
892 WindowList windows = displayContent.getWindowList();
893 boolean isDefaultDisplay = displayContent.isDefaultDisplay;
894
895 DisplayInfo displayInfo = displayContent.getDisplayInfo();
896 final int dw = displayInfo.logicalWidth;
897 final int dh = displayInfo.logicalHeight;
898
899 if (mService.mInputConsumer != null) {
900 mService.mInputConsumer.layout(dw, dh);
901 }
902
Vladislav Kaznacheev0d50d862016-03-29 15:43:28 -0700903 if (mService.mWallpaperInputConsumer != null) {
904 mService.mWallpaperInputConsumer.layout(dw, dh);
905 }
906
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700907 final int N = windows.size();
908 int i;
909
910 if (DEBUG_LAYOUT) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800911 Slog.v(TAG, "-------------------------------------");
912 Slog.v(TAG, "performLayout: needed="
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700913 + displayContent.layoutNeeded + " dw=" + dw + " dh=" + dh);
914 }
915
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -0800916 mService.mPolicy.beginLayoutLw(isDefaultDisplay, dw, dh, mService.mRotation,
Andrii Kulian8072d112016-09-16 11:11:01 -0700917 mService.mGlobalConfiguration.uiMode);
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700918 if (isDefaultDisplay) {
919 // Not needed on non-default displays.
920 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
921 mService.mScreenRect.set(0, 0, dw, dh);
922 }
923
Wale Ogunwaleb4ec0a32015-12-14 10:31:43 -0800924 mService.mPolicy.getContentRectLw(mTmpContentRect);
925 displayContent.resize(mTmpContentRect);
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700926
927 int seq = mService.mLayoutSeq+1;
928 if (seq < 0) seq = 0;
929 mService.mLayoutSeq = seq;
930
931 boolean behindDream = false;
932
933 // First perform layout of any root windows (not attached
934 // to another window).
935 int topAttached = -1;
936 for (i = N-1; i >= 0; i--) {
937 final WindowState win = windows.get(i);
938
939 // Don't do layout of a window if it is not visible, or
940 // soon won't be visible, to avoid wasting time and funky
941 // changes while a window is animating away.
942 final boolean gone = (behindDream && mService.mPolicy.canBeForceHidden(win, win.mAttrs))
943 || win.isGoneForLayoutLw();
944
945 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800946 Slog.v(TAG, "1ST PASS " + win
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700947 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
948 + " mLayoutAttached=" + win.mLayoutAttached
949 + " screen changed=" + win.isConfigChanged());
950 final AppWindowToken atoken = win.mAppToken;
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800951 if (gone) Slog.v(TAG, " GONE: mViewVisibility="
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700952 + win.mViewVisibility + " mRelayoutCalled="
953 + win.mRelayoutCalled + " hidden="
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700954 + win.mToken.hidden + " hiddenRequested="
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700955 + (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -0700956 + " parentHidden=" + win.isParentWindowHidden());
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800957 else Slog.v(TAG, " VIS: mViewVisibility="
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700958 + win.mViewVisibility + " mRelayoutCalled="
959 + win.mRelayoutCalled + " hidden="
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700960 + win.mToken.hidden + " hiddenRequested="
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700961 + (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -0700962 + " parentHidden=" + win.isParentWindowHidden());
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700963 }
964
965 // If this view is GONE, then skip it -- keep the current
966 // frame, and let the caller know so they can ignore it
967 // if they want. (We do the normal layout for INVISIBLE
968 // windows, since that means "perform layout as normal,
969 // just don't display").
970 if (!gone || !win.mHaveFrame || win.mLayoutNeeded
Robert Carr31aa98b2016-07-20 15:29:03 -0700971 || ((win.isConfigChanged() || win.setReportResizeHints())
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700972 && !win.isGoneForLayoutLw() &&
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700973 ((win.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
974 (win.mHasSurface && win.mAppToken != null &&
975 win.mAppToken.layoutConfigChanges)))) {
976 if (!win.mLayoutAttached) {
977 if (initial) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800978 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700979 win.mContentChanged = false;
980 }
981 if (win.mAttrs.type == TYPE_DREAM) {
982 // Don't layout windows behind a dream, so that if it
983 // does stuff like hide the status bar we won't get a
984 // bad transition when it goes away.
985 behindDream = true;
986 }
987 win.mLayoutNeeded = false;
988 win.prelayout();
989 mService.mPolicy.layoutWindowLw(win, null);
990 win.mLayoutSeq = seq;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800991
992 // Window frames may have changed. Update dim layer with the new bounds.
993 final Task task = win.getTask();
994 if (task != null) {
995 displayContent.mDimLayerController.updateDimLayer(task);
996 }
997
Filip Gruszczynskice4ec402016-01-22 11:22:47 -0800998 if (DEBUG_LAYOUT) Slog.v(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700999 " LAYOUT: mFrame="
1000 + win.mFrame + " mContainingFrame="
1001 + win.mContainingFrame + " mDisplayFrame="
1002 + win.mDisplayFrame);
1003 } else {
1004 if (topAttached < 0) topAttached = i;
1005 }
1006 }
1007 }
1008
1009 boolean attachedBehindDream = false;
1010
1011 // Now perform layout of attached windows, which usually
1012 // depend on the position of the window they are attached to.
1013 // XXX does not deal with windows that are attached to windows
1014 // that are themselves attached.
1015 for (i = topAttached; i >= 0; i--) {
1016 final WindowState win = windows.get(i);
1017
1018 if (win.mLayoutAttached) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001019 if (DEBUG_LAYOUT) Slog.v(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001020 "2ND PASS " + win + " mHaveFrame=" + win.mHaveFrame + " mViewVisibility="
1021 + win.mViewVisibility + " mRelayoutCalled=" + win.mRelayoutCalled);
1022 // If this view is GONE, then skip it -- keep the current
1023 // frame, and let the caller know so they can ignore it
1024 // if they want. (We do the normal layout for INVISIBLE
1025 // windows, since that means "perform layout as normal,
1026 // just don't display").
1027 if (attachedBehindDream && mService.mPolicy.canBeForceHidden(win, win.mAttrs)) {
1028 continue;
1029 }
1030 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
1031 || !win.mHaveFrame || win.mLayoutNeeded) {
1032 if (initial) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001033 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001034 win.mContentChanged = false;
1035 }
1036 win.mLayoutNeeded = false;
1037 win.prelayout();
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001038 mService.mPolicy.layoutWindowLw(win, win.getParentWindow());
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001039 win.mLayoutSeq = seq;
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001040 if (DEBUG_LAYOUT) Slog.v(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001041 " LAYOUT: mFrame=" + win.mFrame + " mContainingFrame="
1042 + win.mContainingFrame + " mDisplayFrame=" + win.mDisplayFrame);
1043 }
1044 } else if (win.mAttrs.type == TYPE_DREAM) {
1045 // Don't layout windows behind a dream, so that if it
1046 // does stuff like hide the status bar we won't get a
1047 // bad transition when it goes away.
1048 attachedBehindDream = behindDream;
1049 }
1050 }
1051
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001052 // Window frames may have changed. Tell the input dispatcher about it.
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001053 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
1054 if (updateInputWindows) {
1055 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1056 }
1057
1058 mService.mPolicy.finishLayoutLw();
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001059 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001060 }
1061
1062 /**
1063 * @param windows List of windows on default display.
1064 * @return bitmap indicating if another pass through layout must be made.
1065 */
1066 private int handleAppTransitionReadyLocked(WindowList windows) {
1067 int appsCount = mService.mOpeningApps.size();
1068 if (!transitionGoodToGo(appsCount)) {
1069 return 0;
1070 }
Chong Zhang8784be62016-06-28 15:25:07 -07001071 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "AppTransitionReady");
1072
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001073 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001074 int transit = mService.mAppTransition.getAppTransition();
1075 if (mService.mSkipAppTransitionAnimation) {
1076 transit = AppTransition.TRANSIT_UNSET;
1077 }
1078 mService.mSkipAppTransitionAnimation = false;
1079 mService.mNoAnimationNotifyOnTransitionFinished.clear();
1080
Jorim Jaggid75962e2016-05-03 15:10:03 -07001081 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001082
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001083 final DisplayContent displayContent = mService.getDefaultDisplayContentLocked();
1084 displayContent.rebuildAppWindowList();
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001085
1086 mWallpaperMayChange = false;
1087
1088 // The top-most window will supply the layout params,
1089 // and we will determine it below.
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001090 LayoutParams animLp = null;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001091 int bestAnimLayer = -1;
1092 boolean fullscreenAnim = false;
1093 boolean voiceInteraction = false;
1094
Chong Zhangec8299c2016-07-29 13:09:40 -07001095 int i;
1096 for (i = 0; i < appsCount; i++) {
1097 final AppWindowToken wtoken = mService.mOpeningApps.valueAt(i);
1098 // Clearing the mAnimatingExit flag before entering animation. It's set to
1099 // true if app window is removed, or window relayout to invisible.
1100 // This also affects window visibility. We need to clear it *before*
1101 // maybeUpdateTransitToWallpaper() as the transition selection depends on
1102 // wallpaper target visibility.
1103 wtoken.clearAnimatingFlags();
1104
1105 }
1106 // Adjust wallpaper before we pull the lower/upper target, since pending changes
1107 // (like the clearAnimatingFlags() above) might affect wallpaper target result.
Chong Zhangec8299c2016-07-29 13:09:40 -07001108 if ((displayContent.pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0 &&
1109 mWallpaperControllerLocked.adjustWallpaperWindows()) {
1110 mService.mLayersController.assignLayersLocked(windows);
1111 displayContent.layoutNeeded = true;
1112 }
1113
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001114 final WindowState lowerWallpaperTarget =
1115 mWallpaperControllerLocked.getLowerWallpaperTarget();
1116 final WindowState upperWallpaperTarget =
1117 mWallpaperControllerLocked.getUpperWallpaperTarget();
1118
1119 boolean openingAppHasWallpaper = false;
1120 boolean closingAppHasWallpaper = false;
1121 final AppWindowToken lowerWallpaperAppToken;
1122 final AppWindowToken upperWallpaperAppToken;
1123 if (lowerWallpaperTarget == null) {
1124 lowerWallpaperAppToken = upperWallpaperAppToken = null;
1125 } else {
1126 lowerWallpaperAppToken = lowerWallpaperTarget.mAppToken;
1127 upperWallpaperAppToken = upperWallpaperTarget.mAppToken;
1128 }
1129
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001130 // Do a first pass through the tokens for two
1131 // things:
1132 // (1) Determine if both the closing and opening
1133 // app token sets are wallpaper targets, in which
1134 // case special animations are needed
1135 // (since the wallpaper needs to stay static
1136 // behind them).
1137 // (2) Find the layout params of the top-most
1138 // application window in the tokens, which is
1139 // what will control the animation theme.
1140 final int closingAppsCount = mService.mClosingApps.size();
1141 appsCount = closingAppsCount + mService.mOpeningApps.size();
1142 for (i = 0; i < appsCount; i++) {
1143 final AppWindowToken wtoken;
1144 if (i < closingAppsCount) {
1145 wtoken = mService.mClosingApps.valueAt(i);
1146 if (wtoken == lowerWallpaperAppToken || wtoken == upperWallpaperAppToken) {
1147 closingAppHasWallpaper = true;
1148 }
1149 } else {
1150 wtoken = mService.mOpeningApps.valueAt(i - closingAppsCount);
1151 if (wtoken == lowerWallpaperAppToken || wtoken == upperWallpaperAppToken) {
1152 openingAppHasWallpaper = true;
1153 }
1154 }
1155
1156 voiceInteraction |= wtoken.voiceInteraction;
1157
Wale Ogunwale51362492016-09-08 17:49:17 -07001158 if (wtoken.fillsParent()) {
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001159 WindowState ws = wtoken.findMainWindow();
1160 if (ws != null) {
1161 animLp = ws.mAttrs;
1162 bestAnimLayer = ws.mLayer;
1163 fullscreenAnim = true;
1164 }
1165 } else if (!fullscreenAnim) {
1166 WindowState ws = wtoken.findMainWindow();
1167 if (ws != null) {
1168 if (ws.mLayer > bestAnimLayer) {
1169 animLp = ws.mAttrs;
1170 bestAnimLayer = ws.mLayer;
1171 }
1172 }
1173 }
1174 }
1175
1176 transit = maybeUpdateTransitToWallpaper(transit, openingAppHasWallpaper,
1177 closingAppHasWallpaper, lowerWallpaperTarget, upperWallpaperTarget);
1178
1179 // If all closing windows are obscured, then there is
1180 // no need to do an animation. This is the case, for
1181 // example, when this transition is being done behind
1182 // the lock screen.
1183 if (!mService.mPolicy.allowAppAnimationsLw()) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001184 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001185 "Animations disallowed by keyguard or dream.");
1186 animLp = null;
1187 }
1188
1189 processApplicationsAnimatingInPlace(transit);
1190
Jorim Jaggi42625d1b2016-02-11 20:11:07 -08001191 mTmpLayerAndToken.token = null;
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001192 handleClosingApps(transit, animLp, voiceInteraction, mTmpLayerAndToken);
1193 final AppWindowToken topClosingApp = mTmpLayerAndToken.token;
1194 final int topClosingLayer = mTmpLayerAndToken.layer;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001195
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001196 final AppWindowToken topOpeningApp = handleOpeningApps(transit,
1197 animLp, voiceInteraction, topClosingLayer);
1198
Chong Zhang1c93f6d2016-07-27 17:52:45 -07001199 mService.mAppTransition.setLastAppTransition(transit, topOpeningApp, topClosingApp);
1200
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001201 final AppWindowAnimator openingAppAnimator = (topOpeningApp == null) ? null :
1202 topOpeningApp.mAppAnimator;
1203 final AppWindowAnimator closingAppAnimator = (topClosingApp == null) ? null :
1204 topClosingApp.mAppAnimator;
1205
Jorim Jaggi42625d1b2016-02-11 20:11:07 -08001206 mService.mAppTransition.goodToGo(openingAppAnimator, closingAppAnimator,
1207 mService.mOpeningApps, mService.mClosingApps);
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001208 mService.mAppTransition.postAnimationCallback();
1209 mService.mAppTransition.clear();
1210
1211 mService.mOpeningApps.clear();
1212 mService.mClosingApps.clear();
1213
1214 // This has changed the visibility of windows, so perform
1215 // a new layout to get them all up-to-date.
Chong Zhangec8299c2016-07-29 13:09:40 -07001216 displayContent.layoutNeeded = true;
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001217
1218 // TODO(multidisplay): IMEs are only supported on the default display.
1219 if (windows == mService.getDefaultWindowListLocked()
1220 && !mService.moveInputMethodWindowsIfNeededLocked(true)) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001221 mService.mLayersController.assignLayersLocked(windows);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001222 }
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001223 mService.updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
1224 true /*updateInputWindows*/);
1225 mService.mFocusMayChange = false;
1226 mService.notifyActivityDrawnForKeyguard();
Chong Zhang8784be62016-06-28 15:25:07 -07001227
1228 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
1229
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001230 return FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_CONFIG;
1231 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001232
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001233 private AppWindowToken handleOpeningApps(int transit, LayoutParams animLp,
1234 boolean voiceInteraction, int topClosingLayer) {
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001235 AppWindowToken topOpeningApp = null;
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001236 final int appsCount = mService.mOpeningApps.size();
1237 for (int i = 0; i < appsCount; i++) {
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001238 AppWindowToken wtoken = mService.mOpeningApps.valueAt(i);
1239 final AppWindowAnimator appAnimator = wtoken.mAppAnimator;
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001240 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Now opening app" + wtoken);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001241
1242 if (!appAnimator.usingTransferredAnimation) {
1243 appAnimator.clearThumbnail();
Chong Zhang65d15d02016-03-14 13:59:32 -07001244 appAnimator.setNullAnimation();
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001245 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001246
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001247 if (!wtoken.setVisibility(animLp, true, transit, false, voiceInteraction)){
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001248 // This token isn't going to be animating. Add it to the list of tokens to
1249 // be notified of app transition complete since the notification will not be
1250 // sent be the app window animator.
1251 mService.mNoAnimationNotifyOnTransitionFinished.add(wtoken.token);
1252 }
1253 wtoken.updateReportedVisibilityLocked();
1254 wtoken.waitingToShow = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001255 wtoken.setAllAppWinAnimators();
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001256
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001257 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
Filip Gruszczynski974eb3d2015-10-23 17:33:11 -07001258 ">>> OPEN TRANSACTION handleAppTransitionReadyLocked()");
Robert Carr68e5c9e2016-09-14 10:50:09 -07001259 mService.openSurfaceTransaction();
Filip Gruszczynski974eb3d2015-10-23 17:33:11 -07001260 try {
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001261 mService.mAnimator.orAnimating(appAnimator.showAllWindowsLocked());
Filip Gruszczynski974eb3d2015-10-23 17:33:11 -07001262 } finally {
Robert Carr68e5c9e2016-09-14 10:50:09 -07001263 mService.closeSurfaceTransaction();
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001264 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
Filip Gruszczynski974eb3d2015-10-23 17:33:11 -07001265 "<<< CLOSE TRANSACTION handleAppTransitionReadyLocked()");
1266 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001267 mService.mAnimator.mAppWindowAnimating |= appAnimator.isAnimating();
1268
1269 int topOpeningLayer = 0;
1270 if (animLp != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001271 final int layer = wtoken.getHighestAnimLayer();
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001272 if (topOpeningApp == null || layer > topOpeningLayer) {
1273 topOpeningApp = wtoken;
1274 topOpeningLayer = layer;
1275 }
1276 }
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001277 if (mService.mAppTransition.isNextAppTransitionThumbnailUp()) {
1278 createThumbnailAppAnimator(transit, wtoken, topOpeningLayer, topClosingLayer);
1279 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001280 }
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001281 return topOpeningApp;
1282 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001283
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001284 private void handleClosingApps(int transit, LayoutParams animLp, boolean voiceInteraction,
1285 LayerAndToken layerAndToken) {
1286 final int appsCount;
1287 appsCount = mService.mClosingApps.size();
1288 for (int i = 0; i < appsCount; i++) {
1289 AppWindowToken wtoken = mService.mClosingApps.valueAt(i);
Chong Zhangf58631a2016-05-24 16:02:10 -07001290
1291 // If we still have some windows animating with saved surfaces that's
1292 // either invisible or already removed, mark them exiting so that they
1293 // are disposed of after the exit animation. These are not supposed to
1294 // be shown, or are delayed removal until app is actually drawn (in which
1295 // case the window will be removed after the animation).
1296 wtoken.markSavedSurfaceExiting();
1297
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001298 final AppWindowAnimator appAnimator = wtoken.mAppAnimator;
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001299 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Now closing app " + wtoken);
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001300 appAnimator.clearThumbnail();
Chong Zhang65d15d02016-03-14 13:59:32 -07001301 appAnimator.setNullAnimation();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001302 wtoken.setVisibility(animLp, false, transit, false, voiceInteraction);
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001303 wtoken.updateReportedVisibilityLocked();
1304 // Force the allDrawn flag, because we want to start
1305 // this guy's animations regardless of whether it's
1306 // gotten drawn.
1307 wtoken.allDrawn = true;
1308 wtoken.deferClearAllDrawn = false;
1309 // Ensure that apps that are mid-starting are also scheduled to have their
1310 // starting windows removed after the animation is complete
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001311 if (wtoken.startingWindow != null && !wtoken.startingWindow.mAnimatingExit) {
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001312 mService.scheduleRemoveStartingWindowLocked(wtoken);
1313 }
1314 mService.mAnimator.mAppWindowAnimating |= appAnimator.isAnimating();
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001315
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001316 if (animLp != null) {
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07001317 int layer = wtoken.getHighestAnimLayer();
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001318 if (layerAndToken.token == null || layer > layerAndToken.layer) {
1319 layerAndToken.token = wtoken;
1320 layerAndToken.layer = layer;
1321 }
1322 }
1323 if (mService.mAppTransition.isNextAppTransitionThumbnailDown()) {
1324 createThumbnailAppAnimator(transit, wtoken, 0, layerAndToken.layer);
1325 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001326 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001327 }
1328
1329 private boolean transitionGoodToGo(int appsCount) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001330 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001331 "Checking " + appsCount + " opening apps (frozen="
1332 + mService.mDisplayFrozen + " timeout="
1333 + mService.mAppTransition.isTimeout() + ")...");
Jorim Jaggi275561a2016-02-23 10:11:02 -05001334 int reason = APP_TRANSITION_TIMEOUT;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001335 if (!mService.mAppTransition.isTimeout()) {
1336 for (int i = 0; i < appsCount; i++) {
1337 AppWindowToken wtoken = mService.mOpeningApps.valueAt(i);
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001338 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001339 "Check opening app=" + wtoken + ": allDrawn="
1340 + wtoken.allDrawn + " startingDisplayed="
1341 + wtoken.startingDisplayed + " startingMoved="
Chong Zhangd78ddb42016-03-02 17:01:14 -08001342 + wtoken.startingMoved + " isRelaunching()="
1343 + wtoken.isRelaunching());
1344
1345 if (wtoken.isRelaunching()) {
1346 return false;
1347 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001348
Jorim Jaggi275561a2016-02-23 10:11:02 -05001349 final boolean drawnBeforeRestoring = wtoken.allDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001350 wtoken.restoreSavedSurfaceForInterestingWindows();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08001351
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001352 if (!wtoken.allDrawn && !wtoken.startingDisplayed && !wtoken.startingMoved) {
1353 return false;
1354 }
Jorim Jaggi275561a2016-02-23 10:11:02 -05001355 if (wtoken.allDrawn) {
1356 reason = drawnBeforeRestoring ? APP_TRANSITION_WINDOWS_DRAWN
1357 : APP_TRANSITION_SAVED_SURFACE;
1358 } else {
1359 reason = APP_TRANSITION_STARTING_WINDOW;
1360 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001361 }
1362
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001363 // We also need to wait for the specs to be fetched, if needed.
1364 if (mService.mAppTransition.isFetchingAppTransitionsSpecs()) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001365 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "isFetchingAppTransitionSpecs=true");
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001366 return false;
1367 }
1368
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001369 // If the wallpaper is visible, we need to check it's ready too.
Jorim Jaggi275561a2016-02-23 10:11:02 -05001370 boolean wallpaperReady = !mWallpaperControllerLocked.isWallpaperVisible() ||
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001371 mWallpaperControllerLocked.wallpaperTransitionReady();
Jorim Jaggi275561a2016-02-23 10:11:02 -05001372 if (wallpaperReady) {
1373 mService.mH.obtainMessage(NOTIFY_APP_TRANSITION_STARTING, reason, 0).sendToTarget();
1374 return true;
1375 }
1376 return false;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001377 }
Jorim Jaggi275561a2016-02-23 10:11:02 -05001378 mService.mH.obtainMessage(NOTIFY_APP_TRANSITION_STARTING, reason, 0).sendToTarget();
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001379 return true;
1380 }
1381
1382 private int maybeUpdateTransitToWallpaper(int transit, boolean openingAppHasWallpaper,
1383 boolean closingAppHasWallpaper, WindowState lowerWallpaperTarget,
1384 WindowState upperWallpaperTarget) {
1385 // if wallpaper is animating in or out set oldWallpaper to null else to wallpaper
1386 final WindowState wallpaperTarget = mWallpaperControllerLocked.getWallpaperTarget();
1387 final WindowState oldWallpaper =
1388 mWallpaperControllerLocked.isWallpaperTargetAnimating()
1389 ? null : wallpaperTarget;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001390 final ArraySet<AppWindowToken> openingApps = mService.mOpeningApps;
1391 final ArraySet<AppWindowToken> closingApps = mService.mClosingApps;
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001392 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001393 "New wallpaper target=" + wallpaperTarget
1394 + ", oldWallpaper=" + oldWallpaper
1395 + ", lower target=" + lowerWallpaperTarget
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001396 + ", upper target=" + upperWallpaperTarget
1397 + ", openingApps=" + openingApps
1398 + ", closingApps=" + closingApps);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001399 mService.mAnimateWallpaperWithTarget = false;
1400 if (closingAppHasWallpaper && openingAppHasWallpaper) {
1401 if (DEBUG_APP_TRANSITIONS)
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001402 Slog.v(TAG, "Wallpaper animation!");
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001403 switch (transit) {
1404 case AppTransition.TRANSIT_ACTIVITY_OPEN:
1405 case AppTransition.TRANSIT_TASK_OPEN:
1406 case AppTransition.TRANSIT_TASK_TO_FRONT:
1407 transit = AppTransition.TRANSIT_WALLPAPER_INTRA_OPEN;
1408 break;
1409 case AppTransition.TRANSIT_ACTIVITY_CLOSE:
1410 case AppTransition.TRANSIT_TASK_CLOSE:
1411 case AppTransition.TRANSIT_TASK_TO_BACK:
1412 transit = AppTransition.TRANSIT_WALLPAPER_INTRA_CLOSE;
1413 break;
1414 }
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001415 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001416 "New transit: " + AppTransition.appTransitionToString(transit));
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001417 } else if (oldWallpaper != null && !mService.mOpeningApps.isEmpty()
1418 && !openingApps.contains(oldWallpaper.mAppToken)
1419 && closingApps.contains(oldWallpaper.mAppToken)) {
1420 // We are transitioning from an activity with a wallpaper to one without.
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001421 transit = AppTransition.TRANSIT_WALLPAPER_CLOSE;
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001422 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001423 "New transit away from wallpaper: "
1424 + AppTransition.appTransitionToString(transit));
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001425 } else if (wallpaperTarget != null && wallpaperTarget.isVisibleLw() &&
1426 openingApps.contains(wallpaperTarget.mAppToken)) {
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001427 // We are transitioning from an activity without
1428 // a wallpaper to now showing the wallpaper
1429 transit = AppTransition.TRANSIT_WALLPAPER_OPEN;
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001430 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001431 "New transit into wallpaper: "
1432 + AppTransition.appTransitionToString(transit));
1433 } else {
1434 mService.mAnimateWallpaperWithTarget = true;
1435 }
1436 return transit;
1437 }
1438
1439 /**
1440 * @param w WindowState this method is applied to.
Chong Zhang0abb20f2015-11-19 14:17:31 -08001441 * @param dispInfo info of the display that the window's obscuring state is checked against.
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001442 */
Chong Zhang0abb20f2015-11-19 14:17:31 -08001443 private void handleNotObscuredLocked(final WindowState w, final DisplayInfo dispInfo) {
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -08001444 final LayoutParams attrs = w.mAttrs;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001445 final int attrFlags = attrs.flags;
1446 final boolean canBeSeen = w.isDisplayedLw();
Ruchi Kandoi43e38de2016-04-14 19:34:53 -07001447 final int privateflags = attrs.privateFlags;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001448
Chong Zhang0abb20f2015-11-19 14:17:31 -08001449 if (canBeSeen && w.isObscuringFullscreen(dispInfo)) {
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001450 // This window completely covers everything behind it,
1451 // so we want to leave all of them as undimmed (for
1452 // performance reasons).
Chong Zhang4ffc3182016-05-04 15:06:02 -07001453 if (!mObscured) {
1454 mObsuringWindow = w;
1455 }
1456
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001457 mObscured = true;
1458 }
1459
Andrii Kulianb20addbd2016-08-09 18:52:01 -07001460 if (w.mHasSurface && canBeSeen) {
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001461 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
1462 mHoldScreen = w.mSession;
Chong Zhang4ffc3182016-05-04 15:06:02 -07001463 mHoldScreenWindow = w;
1464 } else if (DEBUG_KEEP_SCREEN_ON && w == mService.mLastWakeLockHoldingWindow) {
1465 Slog.d(TAG_KEEP_SCREEN_ON, "handleNotObscuredLocked: " + w + " was holding "
1466 + "screen wakelock but no longer has FLAG_KEEP_SCREEN_ON!!! called by"
1467 + Debug.getCallers(10));
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001468 }
1469 if (!mSyswin && w.mAttrs.screenBrightness >= 0
1470 && mScreenBrightness < 0) {
1471 mScreenBrightness = w.mAttrs.screenBrightness;
1472 }
1473 if (!mSyswin && w.mAttrs.buttonBrightness >= 0
1474 && mButtonBrightness < 0) {
1475 mButtonBrightness = w.mAttrs.buttonBrightness;
1476 }
1477 if (!mSyswin && w.mAttrs.userActivityTimeout >= 0
1478 && mUserActivityTimeout < 0) {
1479 mUserActivityTimeout = w.mAttrs.userActivityTimeout;
1480 }
1481
1482 final int type = attrs.type;
Andrii Kulianb20addbd2016-08-09 18:52:01 -07001483 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
1484 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001485 mSyswin = true;
1486 }
1487
Andrii Kulianb20addbd2016-08-09 18:52:01 -07001488 // This function assumes that the contents of the default display are
1489 // processed first before secondary displays.
1490 final DisplayContent displayContent = w.getDisplayContent();
1491 if (displayContent != null && displayContent.isDefaultDisplay) {
1492 // While a dream or keyguard is showing, obscure ordinary application
1493 // content on secondary displays (by forcibly enabling mirroring unless
1494 // there is other content we want to show) but still allow opaque
1495 // keyguard dialogs to be shown.
1496 if (type == TYPE_DREAM || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
1497 mObscureApplicationContentOnSecondaryDisplays = true;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001498 }
Andrii Kulianb20addbd2016-08-09 18:52:01 -07001499 mDisplayHasContent = true;
1500 } else if (displayContent != null &&
1501 (!mObscureApplicationContentOnSecondaryDisplays
1502 || (mObscured && type == TYPE_KEYGUARD_DIALOG))) {
1503 // Allow full screen keyguard presentation dialogs to be seen.
1504 mDisplayHasContent = true;
1505 }
1506 if (mPreferredRefreshRate == 0
1507 && w.mAttrs.preferredRefreshRate != 0) {
1508 mPreferredRefreshRate = w.mAttrs.preferredRefreshRate;
1509 }
1510 if (mPreferredModeId == 0
1511 && w.mAttrs.preferredDisplayModeId != 0) {
1512 mPreferredModeId = w.mAttrs.preferredDisplayModeId;
1513 }
1514 if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) {
1515 mSustainedPerformanceModeCurrent = true;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001516 }
1517 }
1518 }
1519
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001520 private static int toBrightnessOverride(float value) {
1521 return (int)(value * PowerManager.BRIGHTNESS_ON);
1522 }
1523
1524 private void processApplicationsAnimatingInPlace(int transit) {
1525 if (transit == AppTransition.TRANSIT_TASK_IN_PLACE) {
1526 // Find the focused window
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07001527 final WindowState win = mService.getDefaultDisplayContentLocked().findFocusedWindow();
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001528 if (win != null) {
1529 final AppWindowToken wtoken = win.mAppToken;
1530 final AppWindowAnimator appAnimator = wtoken.mAppAnimator;
1531 if (DEBUG_APP_TRANSITIONS)
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001532 Slog.v(TAG, "Now animating app in place " + wtoken);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001533 appAnimator.clearThumbnail();
Chong Zhang65d15d02016-03-14 13:59:32 -07001534 appAnimator.setNullAnimation();
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001535 mService.updateTokenInPlaceLocked(wtoken, transit);
1536 wtoken.updateReportedVisibilityLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001537 wtoken.setAllAppWinAnimators();
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001538 mService.mAnimator.mAppWindowAnimating |= appAnimator.isAnimating();
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001539 mService.mAnimator.orAnimating(appAnimator.showAllWindowsLocked());
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001540 }
1541 }
1542 }
1543
1544 private void createThumbnailAppAnimator(int transit, AppWindowToken appToken,
1545 int openingLayer, int closingLayer) {
1546 AppWindowAnimator openingAppAnimator = (appToken == null) ? null : appToken.mAppAnimator;
1547 if (openingAppAnimator == null || openingAppAnimator.animation == null) {
1548 return;
1549 }
1550 final int taskId = appToken.mTask.mTaskId;
1551 Bitmap thumbnailHeader = mService.mAppTransition.getAppTransitionThumbnailHeader(taskId);
1552 if (thumbnailHeader == null || thumbnailHeader.getConfig() == Bitmap.Config.ALPHA_8) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001553 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG, "No thumbnail header bitmap for: " + taskId);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001554 return;
1555 }
1556 // This thumbnail animation is very special, we need to have
1557 // an extra surface with the thumbnail included with the animation.
1558 Rect dirty = new Rect(0, 0, thumbnailHeader.getWidth(), thumbnailHeader.getHeight());
1559 try {
1560 // TODO(multi-display): support other displays
1561 final DisplayContent displayContent = mService.getDefaultDisplayContentLocked();
1562 final Display display = displayContent.getDisplay();
1563 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
1564
1565 // Create a new surface for the thumbnail
1566 SurfaceControl surfaceControl = new SurfaceControl(mService.mFxSession,
1567 "thumbnail anim", dirty.width(), dirty.height(),
1568 PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN);
1569 surfaceControl.setLayerStack(display.getLayerStack());
1570 if (SHOW_TRANSACTIONS) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001571 Slog.i(TAG, " THUMBNAIL " + surfaceControl + ": CREATE");
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001572 }
1573
1574 // Draw the thumbnail onto the surface
1575 Surface drawSurface = new Surface();
1576 drawSurface.copyFrom(surfaceControl);
1577 Canvas c = drawSurface.lockCanvas(dirty);
1578 c.drawBitmap(thumbnailHeader, 0, 0, null);
1579 drawSurface.unlockCanvasAndPost(c);
1580 drawSurface.release();
1581
1582 // Get the thumbnail animation
1583 Animation anim;
1584 if (mService.mAppTransition.isNextThumbnailTransitionAspectScaled()) {
1585 // If this is a multi-window scenario, we use the windows frame as
1586 // destination of the thumbnail header animation. If this is a full screen
1587 // window scenario, we use the whole display as the target.
1588 WindowState win = appToken.findMainWindow();
1589 Rect appRect = win != null ? win.getContentFrameLw() :
1590 new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight);
Jorim Jaggide63d442016-03-14 14:56:56 +01001591 Rect insets = win != null ? win.mContentInsets : null;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001592 // For the new aspect-scaled transition, we want it to always show
1593 // above the animating opening/closing window, and we want to
1594 // synchronize its thumbnail surface with the surface for the
1595 // open/close animation (only on the way down)
1596 anim = mService.mAppTransition.createThumbnailAspectScaleAnimationLocked(appRect,
Andrii Kulian8072d112016-09-16 11:11:01 -07001597 insets, thumbnailHeader, taskId, mService.mGlobalConfiguration.uiMode,
1598 mService.mGlobalConfiguration.orientation);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001599 openingAppAnimator.thumbnailForceAboveLayer = Math.max(openingLayer, closingLayer);
1600 openingAppAnimator.deferThumbnailDestruction =
1601 !mService.mAppTransition.isNextThumbnailTransitionScaleUp();
1602 } else {
1603 anim = mService.mAppTransition.createThumbnailScaleAnimationLocked(
1604 displayInfo.appWidth, displayInfo.appHeight, transit, thumbnailHeader);
1605 }
1606 anim.restrictDuration(MAX_ANIMATION_DURATION);
1607 anim.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked());
1608
1609 openingAppAnimator.thumbnail = surfaceControl;
1610 openingAppAnimator.thumbnailLayer = openingLayer;
1611 openingAppAnimator.thumbnailAnimation = anim;
1612 mService.mAppTransition.getNextAppTransitionStartRect(taskId, mTmpStartRect);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001613 } catch (Surface.OutOfResourcesException e) {
Filip Gruszczynskice4ec402016-01-22 11:22:47 -08001614 Slog.e(TAG, "Can't allocate thumbnail/Canvas surface w="
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001615 + dirty.width() + " h=" + dirty.height(), e);
1616 openingAppAnimator.clearThumbnail();
1617 }
1618 }
1619
1620 boolean copyAnimToLayoutParamsLocked() {
1621 boolean doRequest = false;
1622
1623 final int bulkUpdateParams = mService.mAnimator.mBulkUpdateParams;
1624 if ((bulkUpdateParams & SET_UPDATE_ROTATION) != 0) {
1625 mUpdateRotation = true;
1626 doRequest = true;
1627 }
1628 if ((bulkUpdateParams & SET_WALLPAPER_MAY_CHANGE) != 0) {
1629 mWallpaperMayChange = true;
1630 doRequest = true;
1631 }
1632 if ((bulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0) {
1633 mWallpaperForceHidingChanged = true;
1634 doRequest = true;
1635 }
1636 if ((bulkUpdateParams & SET_ORIENTATION_CHANGE_COMPLETE) == 0) {
1637 mOrientationChangeComplete = false;
1638 } else {
1639 mOrientationChangeComplete = true;
1640 mLastWindowFreezeSource = mService.mAnimator.mLastWindowFreezeSource;
1641 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
1642 doRequest = true;
1643 }
1644 }
1645 if ((bulkUpdateParams & SET_TURN_ON_SCREEN) != 0) {
1646 mService.mTurnOnScreen = true;
1647 }
1648 if ((bulkUpdateParams & SET_WALLPAPER_ACTION_PENDING) != 0) {
1649 mWallpaperActionPending = true;
1650 }
1651
1652 return doRequest;
1653 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001654
1655 void requestTraversal() {
1656 if (!mTraversalScheduled) {
1657 mTraversalScheduled = true;
1658 mService.mH.sendEmptyMessage(DO_TRAVERSAL);
1659 }
1660 }
1661
Jorim Jaggi3dac63a2016-03-01 12:37:07 +01001662 /**
1663 * Puts the {@param surface} into a pending list to be destroyed after the current transaction
1664 * has been committed.
1665 */
1666 void destroyAfterTransaction(SurfaceControl surface) {
1667 mPendingDestroyingSurfaces.add(surface);
1668 }
1669
1670 /**
1671 * Destroys any surfaces that have been put into the pending list with
1672 * {@link #destroyAfterTransaction}.
1673 */
1674 void destroyPendingSurfaces() {
1675 for (int i = mPendingDestroyingSurfaces.size() - 1; i >= 0; i--) {
1676 mPendingDestroyingSurfaces.get(i).destroy();
1677 }
1678 mPendingDestroyingSurfaces.clear();
1679 }
1680
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001681 public void dump(PrintWriter pw, String prefix) {
1682 pw.print(prefix); pw.print("mTraversalScheduled="); pw.println(mTraversalScheduled);
Chong Zhang4ffc3182016-05-04 15:06:02 -07001683 pw.print(prefix); pw.print("mHoldScreenWindow="); pw.println(mHoldScreenWindow);
1684 pw.print(prefix); pw.print("mObsuringWindow="); pw.println(mObsuringWindow);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001685 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001686}