Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1 | package com.android.server.wm; |
| 2 | |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 3 | import static android.app.ActivityManagerInternal.APP_TRANSITION_SAVED_SURFACE; |
| 4 | import static android.app.ActivityManagerInternal.APP_TRANSITION_STARTING_WINDOW; |
| 5 | import static android.app.ActivityManagerInternal.APP_TRANSITION_TIMEOUT; |
| 6 | import static android.app.ActivityManagerInternal.APP_TRANSITION_WINDOWS_DRAWN; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 7 | import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
| 8 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 9 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 10 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION; |
Ruchi Kandoi | 43e38de | 2016-04-14 19:34:53 -0700 | [diff] [blame] | 11 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 12 | import static android.view.WindowManager.LayoutParams.TYPE_DREAM; |
| 13 | import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 14 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; |
| 15 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; |
| 16 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
| 17 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; |
| 18 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; |
| 19 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; |
| 20 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 21 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG; |
| 22 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE; |
| 23 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS; |
| 24 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT; |
| 25 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS; |
| 26 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
| 27 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER; |
| 28 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW; |
| 29 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT; |
| 30 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
| 31 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT; |
| 32 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE; |
Chong Zhang | 4ffc318 | 2016-05-04 15:06:02 -0700 | [diff] [blame] | 33 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_KEEP_SCREEN_ON; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 34 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS; |
| 35 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS; |
Chong Zhang | 4ffc318 | 2016-05-04 15:06:02 -0700 | [diff] [blame] | 36 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_KEEP_SCREEN_ON; |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 37 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 38 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 39 | import static com.android.server.wm.WindowManagerService.H.DO_TRAVERSAL; |
| 40 | import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN; |
| 41 | import static com.android.server.wm.WindowManagerService.H.NOTIFY_APP_TRANSITION_STARTING; |
| 42 | import static com.android.server.wm.WindowManagerService.H.NOTIFY_STARTING_WINDOW_DRAWN; |
| 43 | import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS; |
| 44 | import static com.android.server.wm.WindowManagerService.H.REPORT_WINDOWS_CHANGE; |
| 45 | import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION; |
| 46 | import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER; |
| 47 | import static com.android.server.wm.WindowManagerService.H.WINDOW_FREEZE_TIMEOUT; |
| 48 | import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD; |
| 49 | import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 50 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES; |
| 51 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES; |
| 52 | import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_NONE; |
| 53 | |
| 54 | import android.graphics.Bitmap; |
| 55 | import android.graphics.Canvas; |
| 56 | import android.graphics.PixelFormat; |
| 57 | import android.graphics.Rect; |
| 58 | import android.os.Debug; |
| 59 | import android.os.PowerManager; |
| 60 | import android.os.RemoteException; |
| 61 | import android.os.SystemClock; |
| 62 | import android.os.Trace; |
| 63 | import android.provider.Settings; |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 64 | import android.util.ArraySet; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 65 | import android.util.Slog; |
| 66 | import android.view.Display; |
| 67 | import android.view.DisplayInfo; |
| 68 | import android.view.Surface; |
| 69 | import android.view.SurfaceControl; |
| 70 | import android.view.View; |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 71 | import android.view.WindowManager.LayoutParams; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 72 | import android.view.animation.Animation; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 73 | |
Jorim Jaggi | d75962e | 2016-05-03 15:10:03 -0700 | [diff] [blame] | 74 | import com.android.server.wm.WindowManagerService.H; |
| 75 | |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 76 | import java.io.PrintWriter; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 77 | import 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 | */ |
| 85 | class WindowSurfacePlacer { |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 86 | private static final String TAG = TAG_WITH_CLASS_NAME ? "WindowSurfacePlacer" : TAG_WM; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 87 | 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 Ogunwale | b4ec0a3 | 2015-12-14 10:31:43 -0800 | [diff] [blame] | 116 | private final Rect mTmpContentRect = new Rect(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 117 | |
| 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 Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 130 | private boolean mTraversalScheduled; |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 131 | private int mDeferDepth = 0; |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 132 | |
Ruchi Kandoi | 43e38de | 2016-04-14 19:34:53 -0700 | [diff] [blame] | 133 | private boolean mSustainedPerformanceModeEnabled = false; |
| 134 | private boolean mSustainedPerformanceModeCurrent = false; |
| 135 | |
Chong Zhang | 4ffc318 | 2016-05-04 15:06:02 -0700 | [diff] [blame] | 136 | // 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 Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 142 | private static final class LayerAndToken { |
| 143 | public int layer; |
| 144 | public AppWindowToken token; |
| 145 | } |
| 146 | private final LayerAndToken mTmpLayerAndToken = new LayerAndToken(); |
| 147 | |
Jorim Jaggi | 3dac63a | 2016-03-01 12:37:07 +0100 | [diff] [blame] | 148 | private final ArrayList<SurfaceControl> mPendingDestroyingSurfaces = new ArrayList<>(); |
| 149 | |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 150 | public WindowSurfacePlacer(WindowManagerService service) { |
| 151 | mService = service; |
| 152 | mWallpaperControllerLocked = mService.mWallpaperControllerLocked; |
| 153 | } |
| 154 | |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 155 | /** |
| 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 Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 172 | final void performSurfacePlacement() { |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 173 | if (mDeferDepth > 0) { |
| 174 | return; |
| 175 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 176 | int loopCount = 6; |
| 177 | do { |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 178 | mTraversalScheduled = false; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 179 | performSurfacePlacementLoop(); |
| 180 | mService.mH.removeMessages(DO_TRAVERSAL); |
| 181 | loopCount--; |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 182 | } while (mTraversalScheduled && loopCount > 0); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 183 | mWallpaperActionPending = false; |
| 184 | } |
| 185 | |
| 186 | private void performSurfacePlacementLoop() { |
| 187 | if (mInLayout) { |
| 188 | if (DEBUG) { |
| 189 | throw new RuntimeException("Recursive call!"); |
| 190 | } |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 191 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout. Callers=" |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 192 | + 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 Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 216 | final WindowState ws = mService.mForceRemoves.remove(0); |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 217 | Slog.i(TAG, "Force removing: " + ws); |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 218 | ws.removeImmediately(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 219 | } |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 220 | Slog.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 221 | 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 Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 237 | requestTraversal(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 238 | } else { |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 239 | Slog.e(TAG, "Performed 6 layouts in a row. Skipping"); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 240 | 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 Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 252 | Slog.wtf(TAG, "Unhandled exception while laying out windows", e); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 253 | } |
| 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 Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 260 | Slog.v(TAG, "Layouts looping: " + msg + |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 261 | ", 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 Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 267 | if (DEBUG_WINDOW_TRACE) Slog.v(TAG, "performSurfacePlacementInner: entry. Called by " |
| 268 | + Debug.getCallers(3)); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 269 | |
| 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 Zhang | 4ffc318 | 2016-05-04 15:06:02 -0700 | [diff] [blame] | 298 | mHoldScreenWindow = null; |
| 299 | mObsuringWindow = null; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 300 | mScreenBrightness = -1; |
| 301 | mButtonBrightness = -1; |
| 302 | mUserActivityTimeout = -1; |
| 303 | mObscureApplicationContentOnSecondaryDisplays = false; |
Ruchi Kandoi | 43e38de | 2016-04-14 19:34:53 -0700 | [diff] [blame] | 304 | mSustainedPerformanceModeCurrent = false; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 305 | 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 Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 312 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 313 | ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces"); |
| 314 | SurfaceControl.openTransaction(); |
| 315 | try { |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 316 | applySurfaceChangesTransaction(recoveringMemory, numDisplays, defaultDw, defaultDh); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 317 | } catch (RuntimeException e) { |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 318 | Slog.wtf(TAG, "Unhandled exception in Window Manager", e); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 319 | } finally { |
| 320 | SurfaceControl.closeTransaction(); |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 321 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 322 | "<<< 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 Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 368 | Slog.v(TAG, "Wallpaper may change! Adjusting"); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 369 | 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 Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 395 | // Discard the saved surface if window size is changed, it can't be reused. |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 396 | if (win.mAppToken != null) { |
| 397 | win.mAppToken.destroySavedSurfaces(); |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 398 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 399 | win.reportResized(); |
| 400 | mService.mResizingWindows.remove(i); |
| 401 | } |
| 402 | |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 403 | if (DEBUG_ORIENTATION && mService.mDisplayFrozen) Slog.v(TAG, |
| 404 | "With display frozen, orientationChangeComplete=" + mOrientationChangeComplete); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 405 | 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 Gruszczynski | 19723a4 | 2015-11-25 15:01:48 -0800 | [diff] [blame] | 415 | 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 Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 428 | win.destroyOrSaveSurface(); |
Filip Gruszczynski | 19723a4 | 2015-11-25 15:01:48 -0800 | [diff] [blame] | 429 | } while (i > 0); |
| 430 | mService.mDestroySurface.clear(); |
| 431 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 432 | |
| 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 Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 456 | (!token.mIsExiting || token.isEmpty())) { |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 457 | // 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 Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 462 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 463 | "performLayout: App token exiting now removed" + token); |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 464 | token.removeIfPossible(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 465 | } |
| 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 Kandoi | 43e38de | 2016-04-14 19:34:53 -0700 | [diff] [blame] | 503 | 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 Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 510 | 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 Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 515 | Slog.v(TAG, "Turning screen on after layout!"); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 516 | } |
| 517 | mService.mPowerManager.wakeUp(SystemClock.uptimeMillis(), |
| 518 | "android.server.wm:TURN_ON"); |
| 519 | } |
| 520 | mService.mTurnOnScreen = false; |
| 521 | } |
| 522 | |
| 523 | if (mUpdateRotation) { |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 524 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 525 | 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 Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 547 | final WindowState w = mService.mPendingRemoveTmp[i]; |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 548 | w.removeImmediately(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 549 | 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 Gruszczynski | 92e432c | 2015-12-15 19:17:09 -0800 | [diff] [blame] | 556 | mService.mLayersController.assignLayersLocked(displayContent.getWindowList()); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 557 | 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 Ogunwale | 15ead90 | 2016-09-02 14:30:11 -0700 | [diff] [blame^] | 563 | mService.mDisplayContents.valueAt(displayNdx).onCompleteDeferredRemoval(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | if (updateInputWindowsNeeded) { |
| 567 | mService.mInputMonitor.updateInputWindowsLw(false /*force*/); |
| 568 | } |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 569 | mService.setFocusTaskRegionLocked(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 570 | |
| 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 Jaggi | 3dac63a | 2016-03-01 12:37:07 +0100 | [diff] [blame] | 576 | mService.mWindowPlacerLocked.destroyPendingSurfaces(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 577 | |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 578 | if (DEBUG_WINDOW_TRACE) Slog.e(TAG, |
Wale Ogunwale | 69cf50f | 2015-11-13 11:08:36 -0800 | [diff] [blame] | 579 | "performSurfacePlacementInner exit: animating=" + mService.mAnimator.isAnimating()); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 582 | 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 Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 609 | 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 Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 620 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 621 | 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 Gruszczynski | 92e432c | 2015-12-15 19:17:09 -0800 | [diff] [blame] | 630 | mService.mLayersController.assignLayersLocked(windows); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 631 | displayContent.layoutNeeded = true; |
| 632 | } |
| 633 | |
| 634 | if (isDefaultDisplay |
| 635 | && (displayContent.pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) { |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 636 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 637 | 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 Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 652 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 653 | } |
| 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 Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 664 | mService.mPolicy.applyPostLayoutPolicyLw( |
| 665 | w, w.mAttrs, w.getParentWindow()); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 666 | } |
| 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 Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 684 | final Task task = w.getTask(); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 685 | final boolean obscuredChanged = w.mObscured != mObscured; |
| 686 | |
| 687 | // Update effect. |
| 688 | w.mObscured = mObscured; |
| 689 | if (!mObscured) { |
Chong Zhang | 0abb20f | 2015-11-19 14:17:31 -0800 | [diff] [blame] | 690 | handleNotObscuredLocked(w, displayInfo); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 691 | } |
| 692 | |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 693 | w.applyDimLayerIfNeeded(); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 694 | |
| 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 Gruszczynski | f52dd20 | 2015-11-15 20:36:38 -0800 | [diff] [blame] | 706 | // 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 Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 709 | 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 Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 714 | final boolean adjustedForMinimizedDockOrIme = task != null |
| 715 | && (task.mStack.isAdjustedForMinimizedDockedStack() |
| 716 | || task.mStack.isAdjustedForIme()); |
Filip Gruszczynski | f52dd20 | 2015-11-15 20:36:38 -0800 | [diff] [blame] | 717 | if ((w.mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0 |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 718 | && !w.isDragResizing() && !adjustedForMinimizedDockOrIme |
Robert Carr | c729460 | 2016-05-13 11:32:05 -0700 | [diff] [blame] | 719 | && (task == null || w.getTask().mStack.hasMovementAnimations()) |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 720 | && !w.mWinAnimator.mLastHidden) { |
Filip Gruszczynski | f52dd20 | 2015-11-15 20:36:38 -0800 | [diff] [blame] | 721 | winAnimator.setMoveAnimation(left, top); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 722 | } |
| 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 Ogunwale | 7774bd5 | 2016-06-17 09:44:22 -0700 | [diff] [blame] | 731 | w.mClient.moved(left, top); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 732 | } catch (RemoteException e) { |
| 733 | } |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 734 | w.mMovedByResize = false; |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 735 | } |
| 736 | |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 737 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing"); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 738 | w.mContentChanged = false; |
| 739 | |
| 740 | // Moved from updateWindowsAndWallpaperLocked(). |
| 741 | if (w.mHasSurface) { |
Robert Carr | 679c807 | 2016-04-07 15:51:48 -0700 | [diff] [blame] | 742 | // 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 Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 746 | // 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 Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 763 | Slog.v(TAG, "First draw done in potential wallpaper target " + w); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 764 | 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 Zhang | e22006d | 2016-05-09 10:59:59 -0700 | [diff] [blame] | 772 | if (!winAnimator.isAnimationStarting() && !winAnimator.isWaitingForOpening()) { |
Filip Gruszczynski | c46f41c | 2016-01-05 11:29:21 -0800 | [diff] [blame] | 773 | // 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 Jaggi | 5c80c41 | 2016-04-19 20:03:47 -0700 | [diff] [blame] | 776 | // 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 Gruszczynski | c46f41c | 2016-01-05 11:29:21 -0800 | [diff] [blame] | 781 | winAnimator.computeShownFrameLocked(); |
| 782 | } |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 783 | winAnimator.setSurfaceBoundariesLocked(recoveringMemory); |
| 784 | } |
| 785 | |
| 786 | final AppWindowToken atoken = w.mAppToken; |
| 787 | if (DEBUG_STARTING_WINDOW && atoken != null && w == atoken.startingWindow) { |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 788 | Slog.d(TAG, "updateWindows: starting " + w |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 789 | + " isOnScreen=" + w.isOnScreen() + " allDrawn=" + atoken.allDrawn |
| 790 | + " freezingScreen=" + atoken.mAppAnimator.freezingScreen); |
| 791 | } |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 792 | if (atoken != null && (!atoken.allDrawn || !atoken.allDrawnExcludingSaved |
| 793 | || atoken.mAppAnimator.freezingScreen)) { |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 794 | if (atoken.lastTransactionSequence != mService.mTransactionSequence) { |
| 795 | atoken.lastTransactionSequence = mService.mTransactionSequence; |
| 796 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 797 | atoken.numInterestingWindowsExcludingSaved = 0; |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 798 | atoken.numDrawnWindowsExcludingSaved = 0; |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 799 | atoken.startingDisplayed = false; |
| 800 | } |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 801 | if (!atoken.allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) { |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 802 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 803 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 804 | + w.isDrawnLw() |
Jorim Jaggi | 5c80c41 | 2016-04-19 20:03:47 -0700 | [diff] [blame] | 805 | + ", isAnimationSet=" + winAnimator.isAnimationSet()); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 806 | if (!w.isDrawnLw()) { |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 807 | Slog.v(TAG, "Not displayed: s=" |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 808 | + winAnimator.mSurfaceController |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 809 | + " pv=" + w.mPolicyVisibility |
| 810 | + " mDrawState=" + winAnimator.drawStateToString() |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 811 | + " ph=" + w.isParentWindowHidden() |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 812 | + " th=" + atoken.hiddenRequested |
| 813 | + " a=" + winAnimator.mAnimating); |
| 814 | } |
| 815 | } |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 816 | if (w != atoken.startingWindow) { |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 817 | if (w.isInteresting()) { |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 818 | atoken.numInterestingWindows++; |
| 819 | if (w.isDrawnLw()) { |
| 820 | atoken.numDrawnWindows++; |
| 821 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 822 | Slog.v(TAG, "tokenMayBeDrawn: " + atoken |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 823 | + " w=" + w + " numInteresting=" |
| 824 | + atoken.numInterestingWindows |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 825 | + " freezingScreen=" |
| 826 | + atoken.mAppAnimator.freezingScreen |
| 827 | + " mAppFreezing=" + w.mAppFreezing); |
| 828 | updateAllDrawn = true; |
| 829 | } |
| 830 | } |
| 831 | } else if (w.isDrawnLw()) { |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 832 | mService.mH.sendEmptyMessage(NOTIFY_STARTING_WINDOW_DRAWN); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 833 | atoken.startingDisplayed = true; |
| 834 | } |
| 835 | } |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 836 | 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 Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 841 | atoken.numDrawnWindowsExcludingSaved++; |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 842 | 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 Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 853 | } |
| 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 Ogunwale | 15ead90 | 2016-09-02 14:30:11 -0700 | [diff] [blame^] | 869 | displayContent.stopDimmingIfNeeded(); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 870 | |
| 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 Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 885 | 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 Kaznacheev | 0d50d86 | 2016-03-29 15:43:28 -0700 | [diff] [blame] | 906 | if (mService.mWallpaperInputConsumer != null) { |
| 907 | mService.mWallpaperInputConsumer.layout(dw, dh); |
| 908 | } |
| 909 | |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 910 | final int N = windows.size(); |
| 911 | int i; |
| 912 | |
| 913 | if (DEBUG_LAYOUT) { |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 914 | Slog.v(TAG, "-------------------------------------"); |
| 915 | Slog.v(TAG, "performLayout: needed=" |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 916 | + displayContent.layoutNeeded + " dw=" + dw + " dh=" + dh); |
| 917 | } |
| 918 | |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 919 | mService.mPolicy.beginLayoutLw(isDefaultDisplay, dw, dh, mService.mRotation, |
| 920 | mService.mCurConfiguration.uiMode); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 921 | 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 Ogunwale | b4ec0a3 | 2015-12-14 10:31:43 -0800 | [diff] [blame] | 927 | mService.mPolicy.getContentRectLw(mTmpContentRect); |
| 928 | displayContent.resize(mTmpContentRect); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 929 | |
| 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 Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 949 | Slog.v(TAG, "1ST PASS " + win |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 950 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 951 | + " mLayoutAttached=" + win.mLayoutAttached |
| 952 | + " screen changed=" + win.isConfigChanged()); |
| 953 | final AppWindowToken atoken = win.mAppToken; |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 954 | if (gone) Slog.v(TAG, " GONE: mViewVisibility=" |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 955 | + win.mViewVisibility + " mRelayoutCalled=" |
| 956 | + win.mRelayoutCalled + " hidden=" |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 957 | + win.mToken.hidden + " hiddenRequested=" |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 958 | + (atoken != null && atoken.hiddenRequested) |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 959 | + " parentHidden=" + win.isParentWindowHidden()); |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 960 | else Slog.v(TAG, " VIS: mViewVisibility=" |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 961 | + win.mViewVisibility + " mRelayoutCalled=" |
| 962 | + win.mRelayoutCalled + " hidden=" |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 963 | + win.mToken.hidden + " hiddenRequested=" |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 964 | + (atoken != null && atoken.hiddenRequested) |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 965 | + " parentHidden=" + win.isParentWindowHidden()); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 966 | } |
| 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 Carr | 31aa98b | 2016-07-20 15:29:03 -0700 | [diff] [blame] | 974 | || ((win.isConfigChanged() || win.setReportResizeHints()) |
Jorim Jaggi | 5c80c41 | 2016-04-19 20:03:47 -0700 | [diff] [blame] | 975 | && !win.isGoneForLayoutLw() && |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 976 | ((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 Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 981 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 982 | 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 Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 994 | |
| 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 Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1001 | if (DEBUG_LAYOUT) Slog.v(TAG, |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1002 | " 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 Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1022 | if (DEBUG_LAYOUT) Slog.v(TAG, |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1023 | "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 Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1036 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1037 | win.mContentChanged = false; |
| 1038 | } |
| 1039 | win.mLayoutNeeded = false; |
| 1040 | win.prelayout(); |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 1041 | mService.mPolicy.layoutWindowLw(win, win.getParentWindow()); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1042 | win.mLayoutSeq = seq; |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1043 | if (DEBUG_LAYOUT) Slog.v(TAG, |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1044 | " 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 Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 1055 | // Window frames may have changed. Tell the input dispatcher about it. |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1056 | mService.mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 1057 | if (updateInputWindows) { |
| 1058 | mService.mInputMonitor.updateInputWindowsLw(false /*force*/); |
| 1059 | } |
| 1060 | |
| 1061 | mService.mPolicy.finishLayoutLw(); |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 1062 | mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1063 | } |
| 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 Zhang | 8784be6 | 2016-06-28 15:25:07 -0700 | [diff] [blame] | 1074 | Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "AppTransitionReady"); |
| 1075 | |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1076 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO"); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1077 | 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 Jaggi | d75962e | 2016-05-03 15:10:03 -0700 | [diff] [blame] | 1084 | mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1085 | |
| 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 Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 1092 | LayoutParams animLp = null; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1093 | int bestAnimLayer = -1; |
| 1094 | boolean fullscreenAnim = false; |
| 1095 | boolean voiceInteraction = false; |
| 1096 | |
Chong Zhang | ec8299c | 2016-07-29 13:09:40 -0700 | [diff] [blame] | 1097 | 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 Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1117 | 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 Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1133 | // 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 Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1187 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1188 | "Animations disallowed by keyguard or dream."); |
| 1189 | animLp = null; |
| 1190 | } |
| 1191 | |
| 1192 | processApplicationsAnimatingInPlace(transit); |
| 1193 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1194 | mTmpLayerAndToken.token = null; |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 1195 | handleClosingApps(transit, animLp, voiceInteraction, mTmpLayerAndToken); |
| 1196 | final AppWindowToken topClosingApp = mTmpLayerAndToken.token; |
| 1197 | final int topClosingLayer = mTmpLayerAndToken.layer; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1198 | |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 1199 | final AppWindowToken topOpeningApp = handleOpeningApps(transit, |
| 1200 | animLp, voiceInteraction, topClosingLayer); |
| 1201 | |
Chong Zhang | 1c93f6d | 2016-07-27 17:52:45 -0700 | [diff] [blame] | 1202 | mService.mAppTransition.setLastAppTransition(transit, topOpeningApp, topClosingApp); |
| 1203 | |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 1204 | final AppWindowAnimator openingAppAnimator = (topOpeningApp == null) ? null : |
| 1205 | topOpeningApp.mAppAnimator; |
| 1206 | final AppWindowAnimator closingAppAnimator = (topClosingApp == null) ? null : |
| 1207 | topClosingApp.mAppAnimator; |
| 1208 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1209 | mService.mAppTransition.goodToGo(openingAppAnimator, closingAppAnimator, |
| 1210 | mService.mOpeningApps, mService.mClosingApps); |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 1211 | 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 Zhang | ec8299c | 2016-07-29 13:09:40 -0700 | [diff] [blame] | 1219 | displayContent.layoutNeeded = true; |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 1220 | |
| 1221 | // TODO(multidisplay): IMEs are only supported on the default display. |
| 1222 | if (windows == mService.getDefaultWindowListLocked() |
| 1223 | && !mService.moveInputMethodWindowsIfNeededLocked(true)) { |
Filip Gruszczynski | 92e432c | 2015-12-15 19:17:09 -0800 | [diff] [blame] | 1224 | mService.mLayersController.assignLayersLocked(windows); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1225 | } |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 1226 | mService.updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 1227 | true /*updateInputWindows*/); |
| 1228 | mService.mFocusMayChange = false; |
| 1229 | mService.notifyActivityDrawnForKeyguard(); |
Chong Zhang | 8784be6 | 2016-06-28 15:25:07 -0700 | [diff] [blame] | 1230 | |
| 1231 | Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); |
| 1232 | |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 1233 | return FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_CONFIG; |
| 1234 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1235 | |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 1236 | private AppWindowToken handleOpeningApps(int transit, LayoutParams animLp, |
| 1237 | boolean voiceInteraction, int topClosingLayer) { |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1238 | AppWindowToken topOpeningApp = null; |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 1239 | final int appsCount = mService.mOpeningApps.size(); |
| 1240 | for (int i = 0; i < appsCount; i++) { |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1241 | AppWindowToken wtoken = mService.mOpeningApps.valueAt(i); |
| 1242 | final AppWindowAnimator appAnimator = wtoken.mAppAnimator; |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1243 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Now opening app" + wtoken); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1244 | |
| 1245 | if (!appAnimator.usingTransferredAnimation) { |
| 1246 | appAnimator.clearThumbnail(); |
Chong Zhang | 65d15d0 | 2016-03-14 13:59:32 -0700 | [diff] [blame] | 1247 | appAnimator.setNullAnimation(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1248 | } |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 1249 | |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1250 | if (!wtoken.setVisibility(animLp, true, transit, false, voiceInteraction)){ |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1251 | // 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 Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1258 | wtoken.setAllAppWinAnimators(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1259 | |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1260 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
Filip Gruszczynski | 974eb3d | 2015-10-23 17:33:11 -0700 | [diff] [blame] | 1261 | ">>> OPEN TRANSACTION handleAppTransitionReadyLocked()"); |
| 1262 | SurfaceControl.openTransaction(); |
| 1263 | try { |
Wale Ogunwale | 69cf50f | 2015-11-13 11:08:36 -0800 | [diff] [blame] | 1264 | mService.mAnimator.orAnimating(appAnimator.showAllWindowsLocked()); |
Filip Gruszczynski | 974eb3d | 2015-10-23 17:33:11 -0700 | [diff] [blame] | 1265 | } finally { |
| 1266 | SurfaceControl.closeTransaction(); |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1267 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
Filip Gruszczynski | 974eb3d | 2015-10-23 17:33:11 -0700 | [diff] [blame] | 1268 | "<<< CLOSE TRANSACTION handleAppTransitionReadyLocked()"); |
| 1269 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1270 | mService.mAnimator.mAppWindowAnimating |= appAnimator.isAnimating(); |
| 1271 | |
| 1272 | int topOpeningLayer = 0; |
| 1273 | if (animLp != null) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1274 | final int layer = wtoken.getHighestAnimLayer(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1275 | if (topOpeningApp == null || layer > topOpeningLayer) { |
| 1276 | topOpeningApp = wtoken; |
| 1277 | topOpeningLayer = layer; |
| 1278 | } |
| 1279 | } |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 1280 | if (mService.mAppTransition.isNextAppTransitionThumbnailUp()) { |
| 1281 | createThumbnailAppAnimator(transit, wtoken, topOpeningLayer, topClosingLayer); |
| 1282 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1283 | } |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 1284 | return topOpeningApp; |
| 1285 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1286 | |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 1287 | 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 Zhang | f58631a | 2016-05-24 16:02:10 -0700 | [diff] [blame] | 1293 | |
| 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 Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 1301 | final AppWindowAnimator appAnimator = wtoken.mAppAnimator; |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1302 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Now closing app " + wtoken); |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 1303 | appAnimator.clearThumbnail(); |
Chong Zhang | 65d15d0 | 2016-03-14 13:59:32 -0700 | [diff] [blame] | 1304 | appAnimator.setNullAnimation(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1305 | wtoken.setVisibility(animLp, false, transit, false, voiceInteraction); |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 1306 | 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 Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 1314 | if (wtoken.startingWindow != null && !wtoken.startingWindow.mAnimatingExit) { |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 1315 | mService.scheduleRemoveStartingWindowLocked(wtoken); |
| 1316 | } |
| 1317 | mService.mAnimator.mAppWindowAnimating |= appAnimator.isAnimating(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1318 | |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 1319 | if (animLp != null) { |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 1320 | int layer = wtoken.getHighestAnimLayer(); |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 1321 | 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 Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1329 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | private boolean transitionGoodToGo(int appsCount) { |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1333 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1334 | "Checking " + appsCount + " opening apps (frozen=" |
| 1335 | + mService.mDisplayFrozen + " timeout=" |
| 1336 | + mService.mAppTransition.isTimeout() + ")..."); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 1337 | int reason = APP_TRANSITION_TIMEOUT; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1338 | if (!mService.mAppTransition.isTimeout()) { |
| 1339 | for (int i = 0; i < appsCount; i++) { |
| 1340 | AppWindowToken wtoken = mService.mOpeningApps.valueAt(i); |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1341 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1342 | "Check opening app=" + wtoken + ": allDrawn=" |
| 1343 | + wtoken.allDrawn + " startingDisplayed=" |
| 1344 | + wtoken.startingDisplayed + " startingMoved=" |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 1345 | + wtoken.startingMoved + " isRelaunching()=" |
| 1346 | + wtoken.isRelaunching()); |
| 1347 | |
| 1348 | if (wtoken.isRelaunching()) { |
| 1349 | return false; |
| 1350 | } |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 1351 | |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 1352 | final boolean drawnBeforeRestoring = wtoken.allDrawn; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1353 | wtoken.restoreSavedSurfaceForInterestingWindows(); |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 1354 | |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1355 | if (!wtoken.allDrawn && !wtoken.startingDisplayed && !wtoken.startingMoved) { |
| 1356 | return false; |
| 1357 | } |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 1358 | 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 Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1364 | } |
| 1365 | |
Jorim Jaggi | 2f7d292 | 2015-10-29 13:08:29 +0100 | [diff] [blame] | 1366 | // We also need to wait for the specs to be fetched, if needed. |
| 1367 | if (mService.mAppTransition.isFetchingAppTransitionsSpecs()) { |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1368 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "isFetchingAppTransitionSpecs=true"); |
Jorim Jaggi | 2f7d292 | 2015-10-29 13:08:29 +0100 | [diff] [blame] | 1369 | return false; |
| 1370 | } |
| 1371 | |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1372 | // If the wallpaper is visible, we need to check it's ready too. |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 1373 | boolean wallpaperReady = !mWallpaperControllerLocked.isWallpaperVisible() || |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1374 | mWallpaperControllerLocked.wallpaperTransitionReady(); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 1375 | if (wallpaperReady) { |
| 1376 | mService.mH.obtainMessage(NOTIFY_APP_TRANSITION_STARTING, reason, 0).sendToTarget(); |
| 1377 | return true; |
| 1378 | } |
| 1379 | return false; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1380 | } |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 1381 | mService.mH.obtainMessage(NOTIFY_APP_TRANSITION_STARTING, reason, 0).sendToTarget(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1382 | 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 Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 1393 | final ArraySet<AppWindowToken> openingApps = mService.mOpeningApps; |
| 1394 | final ArraySet<AppWindowToken> closingApps = mService.mClosingApps; |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1395 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1396 | "New wallpaper target=" + wallpaperTarget |
| 1397 | + ", oldWallpaper=" + oldWallpaper |
| 1398 | + ", lower target=" + lowerWallpaperTarget |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 1399 | + ", upper target=" + upperWallpaperTarget |
| 1400 | + ", openingApps=" + openingApps |
| 1401 | + ", closingApps=" + closingApps); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1402 | mService.mAnimateWallpaperWithTarget = false; |
| 1403 | if (closingAppHasWallpaper && openingAppHasWallpaper) { |
| 1404 | if (DEBUG_APP_TRANSITIONS) |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1405 | Slog.v(TAG, "Wallpaper animation!"); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1406 | 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 Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1418 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1419 | "New transit: " + AppTransition.appTransitionToString(transit)); |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 1420 | } 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 Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1424 | transit = AppTransition.TRANSIT_WALLPAPER_CLOSE; |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1425 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1426 | "New transit away from wallpaper: " |
| 1427 | + AppTransition.appTransitionToString(transit)); |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 1428 | } else if (wallpaperTarget != null && wallpaperTarget.isVisibleLw() && |
| 1429 | openingApps.contains(wallpaperTarget.mAppToken)) { |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1430 | // We are transitioning from an activity without |
| 1431 | // a wallpaper to now showing the wallpaper |
| 1432 | transit = AppTransition.TRANSIT_WALLPAPER_OPEN; |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1433 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1434 | "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 Zhang | 0abb20f | 2015-11-19 14:17:31 -0800 | [diff] [blame] | 1444 | * @param dispInfo info of the display that the window's obscuring state is checked against. |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1445 | */ |
Chong Zhang | 0abb20f | 2015-11-19 14:17:31 -0800 | [diff] [blame] | 1446 | private void handleNotObscuredLocked(final WindowState w, final DisplayInfo dispInfo) { |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 1447 | final LayoutParams attrs = w.mAttrs; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1448 | final int attrFlags = attrs.flags; |
| 1449 | final boolean canBeSeen = w.isDisplayedLw(); |
Ruchi Kandoi | 43e38de | 2016-04-14 19:34:53 -0700 | [diff] [blame] | 1450 | final int privateflags = attrs.privateFlags; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1451 | |
Chong Zhang | 0abb20f | 2015-11-19 14:17:31 -0800 | [diff] [blame] | 1452 | if (canBeSeen && w.isObscuringFullscreen(dispInfo)) { |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1453 | // This window completely covers everything behind it, |
| 1454 | // so we want to leave all of them as undimmed (for |
| 1455 | // performance reasons). |
Chong Zhang | 4ffc318 | 2016-05-04 15:06:02 -0700 | [diff] [blame] | 1456 | if (!mObscured) { |
| 1457 | mObsuringWindow = w; |
| 1458 | } |
| 1459 | |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1460 | mObscured = true; |
| 1461 | } |
| 1462 | |
Andrii Kulian | b20addbd | 2016-08-09 18:52:01 -0700 | [diff] [blame] | 1463 | if (w.mHasSurface && canBeSeen) { |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1464 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 1465 | mHoldScreen = w.mSession; |
Chong Zhang | 4ffc318 | 2016-05-04 15:06:02 -0700 | [diff] [blame] | 1466 | 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 Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1471 | } |
| 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 Kulian | b20addbd | 2016-08-09 18:52:01 -0700 | [diff] [blame] | 1486 | if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR |
| 1487 | || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1488 | mSyswin = true; |
| 1489 | } |
| 1490 | |
Andrii Kulian | b20addbd | 2016-08-09 18:52:01 -0700 | [diff] [blame] | 1491 | // 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 Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1501 | } |
Andrii Kulian | b20addbd | 2016-08-09 18:52:01 -0700 | [diff] [blame] | 1502 | 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 Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1519 | } |
| 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 Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1537 | Slog.v(TAG, "allDrawn: " + wtoken |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1538 | + " 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 Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 1548 | if (!wtoken.allDrawnExcludingSaved) { |
| 1549 | int numInteresting = wtoken.numInterestingWindowsExcludingSaved; |
| 1550 | if (numInteresting > 0 |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1551 | && wtoken.numDrawnWindowsExcludingSaved >= numInteresting) { |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 1552 | if (DEBUG_VISIBILITY) |
| 1553 | Slog.v(TAG, "allDrawnExcludingSaved: " + wtoken |
| 1554 | + " interesting=" + numInteresting |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1555 | + " drawn=" + wtoken.numDrawnWindowsExcludingSaved); |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 1556 | 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 Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1564 | } |
| 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 Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1582 | Slog.v(TAG, "Now animating app in place " + wtoken); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1583 | appAnimator.clearThumbnail(); |
Chong Zhang | 65d15d0 | 2016-03-14 13:59:32 -0700 | [diff] [blame] | 1584 | appAnimator.setNullAnimation(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1585 | mService.updateTokenInPlaceLocked(wtoken, transit); |
| 1586 | wtoken.updateReportedVisibilityLocked(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1587 | wtoken.setAllAppWinAnimators(); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1588 | mService.mAnimator.mAppWindowAnimating |= appAnimator.isAnimating(); |
Wale Ogunwale | 69cf50f | 2015-11-13 11:08:36 -0800 | [diff] [blame] | 1589 | mService.mAnimator.orAnimating(appAnimator.showAllWindowsLocked()); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1590 | } |
| 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 Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1603 | if (DEBUG_APP_TRANSITIONS) Slog.d(TAG, "No thumbnail header bitmap for: " + taskId); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1604 | 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 Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1621 | Slog.i(TAG, " THUMBNAIL " + surfaceControl + ": CREATE"); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1622 | } |
| 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 Jaggi | de63d44 | 2016-03-14 14:56:56 +0100 | [diff] [blame] | 1641 | Rect insets = win != null ? win.mContentInsets : null; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1642 | // 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, |
Winson | b202476 | 2016-04-05 17:32:30 -0700 | [diff] [blame] | 1647 | insets, thumbnailHeader, taskId, mService.mCurConfiguration.uiMode, |
| 1648 | mService.mCurConfiguration.orientation); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1649 | 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 Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1663 | } catch (Surface.OutOfResourcesException e) { |
Filip Gruszczynski | ce4ec40 | 2016-01-22 11:22:47 -0800 | [diff] [blame] | 1664 | Slog.e(TAG, "Can't allocate thumbnail/Canvas surface w=" |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1665 | + 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 Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 1704 | |
| 1705 | void requestTraversal() { |
| 1706 | if (!mTraversalScheduled) { |
| 1707 | mTraversalScheduled = true; |
| 1708 | mService.mH.sendEmptyMessage(DO_TRAVERSAL); |
| 1709 | } |
| 1710 | } |
| 1711 | |
Jorim Jaggi | 3dac63a | 2016-03-01 12:37:07 +0100 | [diff] [blame] | 1712 | /** |
| 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 Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 1731 | public void dump(PrintWriter pw, String prefix) { |
| 1732 | pw.print(prefix); pw.print("mTraversalScheduled="); pw.println(mTraversalScheduled); |
Chong Zhang | 4ffc318 | 2016-05-04 15:06:02 -0700 | [diff] [blame] | 1733 | pw.print(prefix); pw.print("mHoldScreenWindow="); pw.println(mHoldScreenWindow); |
| 1734 | pw.print(prefix); pw.print("mObsuringWindow="); pw.println(mObsuringWindow); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 1735 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1736 | } |