Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 20 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 21 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 22 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 23 | import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM; |
| 24 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 25 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE; |
| 26 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS; |
| 27 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS; |
| 28 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT; |
| 29 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
| 30 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER; |
| 31 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT; |
| 32 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 33 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 34 | import static com.android.server.wm.WindowManagerService.H.WALLPAPER_DRAW_PENDING_TIMEOUT; |
| 35 | import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER; |
| 36 | import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET; |
| 37 | |
| 38 | import android.os.Bundle; |
| 39 | import android.os.Debug; |
| 40 | import android.os.IBinder; |
| 41 | import android.os.RemoteException; |
| 42 | import android.os.SystemClock; |
| 43 | import android.util.Slog; |
| 44 | import android.view.DisplayInfo; |
| 45 | import android.view.WindowManager; |
| 46 | import android.view.WindowManagerPolicy; |
| 47 | |
| 48 | import java.io.PrintWriter; |
| 49 | import java.util.ArrayList; |
| 50 | |
| 51 | /** |
| 52 | * Controls wallpaper windows visibility, ordering, and so on. |
| 53 | * NOTE: All methods in this class must be called with the window manager service lock held. |
| 54 | */ |
| 55 | class WallpaperController { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 56 | private static final String TAG = TAG_WITH_CLASS_NAME ? "WallpaperController" : TAG_WM; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 57 | final private WindowManagerService mService; |
| 58 | |
| 59 | private final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<>(); |
| 60 | |
| 61 | // If non-null, this is the currently visible window that is associated |
| 62 | // with the wallpaper. |
| 63 | private WindowState mWallpaperTarget = null; |
| 64 | // If non-null, we are in the middle of animating from one wallpaper target |
| 65 | // to another, and this is the lower one in Z-order. |
| 66 | private WindowState mLowerWallpaperTarget = null; |
| 67 | // If non-null, we are in the middle of animating from one wallpaper target |
| 68 | // to another, and this is the higher one in Z-order. |
| 69 | private WindowState mUpperWallpaperTarget = null; |
| 70 | |
| 71 | private int mWallpaperAnimLayerAdjustment; |
| 72 | |
| 73 | private float mLastWallpaperX = -1; |
| 74 | private float mLastWallpaperY = -1; |
| 75 | private float mLastWallpaperXStep = -1; |
| 76 | private float mLastWallpaperYStep = -1; |
| 77 | private int mLastWallpaperDisplayOffsetX = Integer.MIN_VALUE; |
| 78 | private int mLastWallpaperDisplayOffsetY = Integer.MIN_VALUE; |
| 79 | |
| 80 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 81 | // changing its scroll position. |
| 82 | WindowState mWaitingOnWallpaper; |
| 83 | |
| 84 | // The last time we had a timeout when waiting for a wallpaper. |
| 85 | private long mLastWallpaperTimeoutTime; |
| 86 | // We give a wallpaper up to 150ms to finish scrolling. |
| 87 | private static final long WALLPAPER_TIMEOUT = 150; |
| 88 | // Time we wait after a timeout before trying to wait again. |
| 89 | private static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
| 90 | |
| 91 | // Set to the wallpaper window we would like to hide once the transition animations are done. |
| 92 | // This is useful in cases where we don't want the wallpaper to be hidden when the close app |
| 93 | // is a wallpaper target and is done animating out, but the opening app isn't a wallpaper |
| 94 | // target and isn't done animating in. |
| 95 | private WindowState mDeferredHideWallpaper = null; |
| 96 | |
| 97 | // We give a wallpaper up to 500ms to finish drawing before playing app transitions. |
| 98 | private static final long WALLPAPER_DRAW_PENDING_TIMEOUT_DURATION = 500; |
| 99 | private static final int WALLPAPER_DRAW_NORMAL = 0; |
| 100 | private static final int WALLPAPER_DRAW_PENDING = 1; |
| 101 | private static final int WALLPAPER_DRAW_TIMEOUT = 2; |
| 102 | private int mWallpaperDrawState = WALLPAPER_DRAW_NORMAL; |
| 103 | |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 104 | private final FindWallpaperTargetResult mFindResults = new FindWallpaperTargetResult(); |
| 105 | |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 106 | public WallpaperController(WindowManagerService service) { |
| 107 | mService = service; |
| 108 | } |
| 109 | |
| 110 | WindowState getWallpaperTarget() { |
| 111 | return mWallpaperTarget; |
| 112 | } |
| 113 | |
| 114 | WindowState getLowerWallpaperTarget() { |
| 115 | return mLowerWallpaperTarget; |
| 116 | } |
| 117 | |
| 118 | WindowState getUpperWallpaperTarget() { |
| 119 | return mUpperWallpaperTarget; |
| 120 | } |
| 121 | |
| 122 | boolean isWallpaperTarget(WindowState win) { |
| 123 | return win == mWallpaperTarget; |
| 124 | } |
| 125 | |
| 126 | boolean isBelowWallpaperTarget(WindowState win) { |
| 127 | return mWallpaperTarget != null && mWallpaperTarget.mLayer >= win.mBaseLayer; |
| 128 | } |
| 129 | |
| 130 | boolean isWallpaperVisible() { |
| 131 | return isWallpaperVisible(mWallpaperTarget); |
| 132 | } |
| 133 | |
| 134 | private boolean isWallpaperVisible(WindowState wallpaperTarget) { |
| 135 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target " + wallpaperTarget + ", obscured=" |
| 136 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 137 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 138 | ? wallpaperTarget.mAppToken.mAppAnimator.animation : null) |
| 139 | + " upper=" + mUpperWallpaperTarget |
| 140 | + " lower=" + mLowerWallpaperTarget); |
| 141 | return (wallpaperTarget != null |
| 142 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 143 | && wallpaperTarget.mAppToken.mAppAnimator.animation != null))) |
| 144 | || mUpperWallpaperTarget != null |
| 145 | || mLowerWallpaperTarget != null; |
| 146 | } |
| 147 | |
| 148 | boolean isWallpaperTargetAnimating() { |
Jorim Jaggi | 5c80c41 | 2016-04-19 20:03:47 -0700 | [diff] [blame] | 149 | return mWallpaperTarget != null && mWallpaperTarget.mWinAnimator.isAnimationSet() |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 150 | && !mWallpaperTarget.mWinAnimator.isDummyAnimation(); |
| 151 | } |
| 152 | |
| 153 | void updateWallpaperVisibility() { |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 154 | final DisplayContent displayContent = mWallpaperTarget.getDisplayContent(); |
| 155 | if (displayContent == null) { |
| 156 | return; |
| 157 | } |
Filip Gruszczynski | 63a35e2 | 2015-11-05 15:38:59 -0800 | [diff] [blame] | 158 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 159 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 160 | final int dw = displayInfo.logicalWidth; |
| 161 | final int dh = displayInfo.logicalHeight; |
| 162 | |
| 163 | for (int curTokenNdx = mWallpaperTokens.size() - 1; curTokenNdx >= 0; curTokenNdx--) { |
| 164 | WindowToken token = mWallpaperTokens.get(curTokenNdx); |
| 165 | if (token.hidden == visible) { |
| 166 | token.hidden = !visible; |
| 167 | // Need to do a layout to ensure the wallpaper now has the |
| 168 | // correct size. |
| 169 | displayContent.layoutNeeded = true; |
| 170 | } |
| 171 | |
| 172 | final WindowList windows = token.windows; |
| 173 | for (int wallpaperNdx = windows.size() - 1; wallpaperNdx >= 0; wallpaperNdx--) { |
| 174 | WindowState wallpaper = windows.get(wallpaperNdx); |
| 175 | if (visible) { |
| 176 | updateWallpaperOffset(wallpaper, dw, dh, false); |
| 177 | } |
| 178 | |
| 179 | dispatchWallpaperVisibility(wallpaper, visible); |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | void hideDeferredWallpapersIfNeeded() { |
| 185 | if (mDeferredHideWallpaper != null) { |
| 186 | hideWallpapers(mDeferredHideWallpaper); |
| 187 | mDeferredHideWallpaper = null; |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | void hideWallpapers(final WindowState winGoingAway) { |
| 192 | if (mWallpaperTarget != null |
| 193 | && (mWallpaperTarget != winGoingAway || mLowerWallpaperTarget != null)) { |
| 194 | return; |
| 195 | } |
| 196 | if (mService.mAppTransition.isRunning()) { |
| 197 | // Defer hiding the wallpaper when app transition is running until the animations |
| 198 | // are done. |
| 199 | mDeferredHideWallpaper = winGoingAway; |
| 200 | return; |
| 201 | } |
| 202 | |
| 203 | final boolean wasDeferred = (mDeferredHideWallpaper == winGoingAway); |
| 204 | for (int i = mWallpaperTokens.size() - 1; i >= 0; i--) { |
| 205 | final WindowToken token = mWallpaperTokens.get(i); |
| 206 | for (int j = token.windows.size() - 1; j >= 0; j--) { |
| 207 | final WindowState wallpaper = token.windows.get(j); |
| 208 | final WindowStateAnimator winAnimator = wallpaper.mWinAnimator; |
| 209 | if (!winAnimator.mLastHidden || wasDeferred) { |
Filip Gruszczynski | 63a35e2 | 2015-11-05 15:38:59 -0800 | [diff] [blame] | 210 | winAnimator.hide("hideWallpapers"); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 211 | dispatchWallpaperVisibility(wallpaper, false); |
| 212 | final DisplayContent displayContent = wallpaper.getDisplayContent(); |
| 213 | if (displayContent != null) { |
| 214 | displayContent.pendingLayoutChanges |= |
| 215 | WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | if (DEBUG_WALLPAPER_LIGHT && !token.hidden) Slog.d(TAG, "Hiding wallpaper " + token |
| 220 | + " from " + winGoingAway + " target=" + mWallpaperTarget + " lower=" |
| 221 | + mLowerWallpaperTarget + "\n" + Debug.getCallers(5, " ")); |
| 222 | token.hidden = true; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Check wallpaper for visibility change and notify window if so. |
| 228 | * @param wallpaper The wallpaper to test and notify. |
| 229 | * @param visible Current visibility. |
| 230 | */ |
| 231 | void dispatchWallpaperVisibility(final WindowState wallpaper, final boolean visible) { |
| 232 | // Only send notification if the visibility actually changed and we are not trying to hide |
| 233 | // the wallpaper when we are deferring hiding of the wallpaper. |
| 234 | if (wallpaper.mWallpaperVisible != visible |
| 235 | && (mDeferredHideWallpaper == null || visible)) { |
| 236 | wallpaper.mWallpaperVisible = visible; |
| 237 | try { |
| 238 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 239 | "Updating vis of wallpaper " + wallpaper |
| 240 | + ": " + visible + " from:\n" + Debug.getCallers(4, " ")); |
| 241 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 242 | } catch (RemoteException e) { |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | boolean updateWallpaperOffset(WindowState wallpaperWin, int dw, int dh, boolean sync) { |
| 248 | boolean rawChanged = false; |
| 249 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
| 250 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
| 251 | int availw = wallpaperWin.mFrame.right - wallpaperWin.mFrame.left - dw; |
| 252 | int offset = availw > 0 ? -(int)(availw * wpx + .5f) : 0; |
| 253 | if (mLastWallpaperDisplayOffsetX != Integer.MIN_VALUE) { |
| 254 | offset += mLastWallpaperDisplayOffsetX; |
| 255 | } |
| 256 | boolean changed = wallpaperWin.mXOffset != offset; |
| 257 | if (changed) { |
| 258 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " + wallpaperWin + " x: " + offset); |
| 259 | wallpaperWin.mXOffset = offset; |
| 260 | } |
| 261 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
| 262 | wallpaperWin.mWallpaperX = wpx; |
| 263 | wallpaperWin.mWallpaperXStep = wpxs; |
| 264 | rawChanged = true; |
| 265 | } |
| 266 | |
| 267 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
| 268 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
| 269 | int availh = wallpaperWin.mFrame.bottom - wallpaperWin.mFrame.top - dh; |
| 270 | offset = availh > 0 ? -(int)(availh * wpy + .5f) : 0; |
| 271 | if (mLastWallpaperDisplayOffsetY != Integer.MIN_VALUE) { |
| 272 | offset += mLastWallpaperDisplayOffsetY; |
| 273 | } |
| 274 | if (wallpaperWin.mYOffset != offset) { |
| 275 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " + wallpaperWin + " y: " + offset); |
| 276 | changed = true; |
| 277 | wallpaperWin.mYOffset = offset; |
| 278 | } |
| 279 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
| 280 | wallpaperWin.mWallpaperY = wpy; |
| 281 | wallpaperWin.mWallpaperYStep = wpys; |
| 282 | rawChanged = true; |
| 283 | } |
| 284 | |
| 285 | if (rawChanged && (wallpaperWin.mAttrs.privateFlags & |
| 286 | WindowManager.LayoutParams.PRIVATE_FLAG_WANTS_OFFSET_NOTIFICATIONS) != 0) { |
| 287 | try { |
| 288 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
| 289 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 290 | + " y=" + wallpaperWin.mWallpaperY); |
| 291 | if (sync) { |
| 292 | mWaitingOnWallpaper = wallpaperWin; |
| 293 | } |
| 294 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
| 295 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 296 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
| 297 | if (sync) { |
| 298 | if (mWaitingOnWallpaper != null) { |
| 299 | long start = SystemClock.uptimeMillis(); |
| 300 | if ((mLastWallpaperTimeoutTime + WALLPAPER_TIMEOUT_RECOVERY) |
| 301 | < start) { |
| 302 | try { |
| 303 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 304 | "Waiting for offset complete..."); |
| 305 | mService.mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 306 | } catch (InterruptedException e) { |
| 307 | } |
| 308 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
| 309 | if ((start + WALLPAPER_TIMEOUT) < SystemClock.uptimeMillis()) { |
| 310 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
| 311 | + wallpaperWin); |
| 312 | mLastWallpaperTimeoutTime = start; |
| 313 | } |
| 314 | } |
| 315 | mWaitingOnWallpaper = null; |
| 316 | } |
| 317 | } |
| 318 | } catch (RemoteException e) { |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | return changed; |
| 323 | } |
| 324 | |
| 325 | void setWindowWallpaperPosition( |
| 326 | WindowState window, float x, float y, float xStep, float yStep) { |
| 327 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 328 | window.mWallpaperX = x; |
| 329 | window.mWallpaperY = y; |
| 330 | window.mWallpaperXStep = xStep; |
| 331 | window.mWallpaperYStep = yStep; |
| 332 | updateWallpaperOffsetLocked(window, true); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | void setWindowWallpaperDisplayOffset(WindowState window, int x, int y) { |
| 337 | if (window.mWallpaperDisplayOffsetX != x || window.mWallpaperDisplayOffsetY != y) { |
| 338 | window.mWallpaperDisplayOffsetX = x; |
| 339 | window.mWallpaperDisplayOffsetY = y; |
| 340 | updateWallpaperOffsetLocked(window, true); |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | Bundle sendWindowWallpaperCommand( |
| 345 | WindowState window, String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 346 | if (window == mWallpaperTarget |
| 347 | || window == mLowerWallpaperTarget |
| 348 | || window == mUpperWallpaperTarget) { |
| 349 | boolean doWait = sync; |
| 350 | for (int curTokenNdx = mWallpaperTokens.size() - 1; curTokenNdx >= 0; curTokenNdx--) { |
| 351 | final WindowList windows = mWallpaperTokens.get(curTokenNdx).windows; |
| 352 | for (int wallpaperNdx = windows.size() - 1; wallpaperNdx >= 0; wallpaperNdx--) { |
| 353 | WindowState wallpaper = windows.get(wallpaperNdx); |
| 354 | try { |
| 355 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 356 | x, y, z, extras, sync); |
| 357 | // We only want to be synchronous with one wallpaper. |
| 358 | sync = false; |
| 359 | } catch (RemoteException e) { |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | if (doWait) { |
| 365 | // TODO: Need to wait for result. |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | return null; |
| 370 | } |
| 371 | |
| 372 | void updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
| 373 | final DisplayContent displayContent = changingTarget.getDisplayContent(); |
| 374 | if (displayContent == null) { |
| 375 | return; |
| 376 | } |
| 377 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 378 | final int dw = displayInfo.logicalWidth; |
| 379 | final int dh = displayInfo.logicalHeight; |
| 380 | |
| 381 | WindowState target = mWallpaperTarget; |
| 382 | if (target != null) { |
| 383 | if (target.mWallpaperX >= 0) { |
| 384 | mLastWallpaperX = target.mWallpaperX; |
| 385 | } else if (changingTarget.mWallpaperX >= 0) { |
| 386 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 387 | } |
| 388 | if (target.mWallpaperY >= 0) { |
| 389 | mLastWallpaperY = target.mWallpaperY; |
| 390 | } else if (changingTarget.mWallpaperY >= 0) { |
| 391 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 392 | } |
| 393 | if (target.mWallpaperDisplayOffsetX != Integer.MIN_VALUE) { |
| 394 | mLastWallpaperDisplayOffsetX = target.mWallpaperDisplayOffsetX; |
| 395 | } else if (changingTarget.mWallpaperDisplayOffsetX != Integer.MIN_VALUE) { |
| 396 | mLastWallpaperDisplayOffsetX = changingTarget.mWallpaperDisplayOffsetX; |
| 397 | } |
| 398 | if (target.mWallpaperDisplayOffsetY != Integer.MIN_VALUE) { |
| 399 | mLastWallpaperDisplayOffsetY = target.mWallpaperDisplayOffsetY; |
| 400 | } else if (changingTarget.mWallpaperDisplayOffsetY != Integer.MIN_VALUE) { |
| 401 | mLastWallpaperDisplayOffsetY = changingTarget.mWallpaperDisplayOffsetY; |
| 402 | } |
| 403 | if (target.mWallpaperXStep >= 0) { |
| 404 | mLastWallpaperXStep = target.mWallpaperXStep; |
| 405 | } else if (changingTarget.mWallpaperXStep >= 0) { |
| 406 | mLastWallpaperXStep = changingTarget.mWallpaperXStep; |
| 407 | } |
| 408 | if (target.mWallpaperYStep >= 0) { |
| 409 | mLastWallpaperYStep = target.mWallpaperYStep; |
| 410 | } else if (changingTarget.mWallpaperYStep >= 0) { |
| 411 | mLastWallpaperYStep = changingTarget.mWallpaperYStep; |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | for (int curTokenNdx = mWallpaperTokens.size() - 1; curTokenNdx >= 0; curTokenNdx--) { |
| 416 | WindowList windows = mWallpaperTokens.get(curTokenNdx).windows; |
| 417 | for (int wallpaperNdx = windows.size() - 1; wallpaperNdx >= 0; wallpaperNdx--) { |
| 418 | WindowState wallpaper = windows.get(wallpaperNdx); |
| 419 | if (updateWallpaperOffset(wallpaper, dw, dh, sync)) { |
| 420 | WindowStateAnimator winAnimator = wallpaper.mWinAnimator; |
| 421 | winAnimator.computeShownFrameLocked(); |
| 422 | // No need to lay out the windows - we can just set the wallpaper position |
| 423 | // directly. |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 424 | winAnimator.setWallpaperOffset(wallpaper.mShownPosition); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 425 | // We only want to be synchronous with one wallpaper. |
| 426 | sync = false; |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | void clearLastWallpaperTimeoutTime() { |
| 433 | mLastWallpaperTimeoutTime = 0; |
| 434 | } |
| 435 | |
| 436 | void wallpaperCommandComplete(IBinder window) { |
| 437 | if (mWaitingOnWallpaper != null && |
| 438 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 439 | mWaitingOnWallpaper = null; |
| 440 | mService.mWindowMap.notifyAll(); |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | void wallpaperOffsetsComplete(IBinder window) { |
| 445 | if (mWaitingOnWallpaper != null && |
| 446 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 447 | mWaitingOnWallpaper = null; |
| 448 | mService.mWindowMap.notifyAll(); |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | int getAnimLayerAdjustment() { |
| 453 | return mWallpaperAnimLayerAdjustment; |
| 454 | } |
| 455 | |
| 456 | void setAnimLayerAdjustment(WindowState win, int adj) { |
| 457 | if (win != mWallpaperTarget || mLowerWallpaperTarget != null) { |
| 458 | return; |
| 459 | } |
| 460 | |
| 461 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Setting wallpaper layer adj to " + adj); |
| 462 | mWallpaperAnimLayerAdjustment = adj; |
| 463 | for (int i = mWallpaperTokens.size() - 1; i >= 0; i--) { |
| 464 | WindowList windows = mWallpaperTokens.get(i).windows; |
| 465 | for (int j = windows.size() - 1; j >= 0; j--) { |
| 466 | WindowState wallpaper = windows.get(j); |
| 467 | wallpaper.mWinAnimator.mAnimLayer = wallpaper.mLayer + adj; |
| 468 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "setWallpaper win " |
| 469 | + wallpaper + " anim layer: " + wallpaper.mWinAnimator.mAnimLayer); |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 474 | private void findWallpaperTarget(WindowList windows, FindWallpaperTargetResult result) { |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 475 | final WindowAnimator winAnimator = mService.mAnimator; |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 476 | result.reset(); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 477 | WindowState w = null; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 478 | int windowDetachedI = -1; |
Wale Ogunwale | 21fdd91 | 2015-08-20 12:34:57 -0700 | [diff] [blame] | 479 | boolean resetTopWallpaper = false; |
| 480 | boolean inFreeformSpace = false; |
Filip Gruszczynski | 51cb83e | 2015-11-05 09:32:19 -0800 | [diff] [blame] | 481 | boolean replacing = false; |
Wale Ogunwale | 6cbba70 | 2016-06-28 16:27:31 -0700 | [diff] [blame^] | 482 | boolean keyguardGoingAwayWithWallpaper = false; |
| 483 | |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 484 | for (int i = windows.size() - 1; i >= 0; i--) { |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 485 | w = windows.get(i); |
| 486 | if ((w.mAttrs.type == TYPE_WALLPAPER)) { |
Wale Ogunwale | 21fdd91 | 2015-08-20 12:34:57 -0700 | [diff] [blame] | 487 | if (result.topWallpaper == null || resetTopWallpaper) { |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 488 | result.setTopWallpaper(w, i); |
Wale Ogunwale | 21fdd91 | 2015-08-20 12:34:57 -0700 | [diff] [blame] | 489 | resetTopWallpaper = false; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 490 | } |
| 491 | continue; |
| 492 | } |
Wale Ogunwale | 21fdd91 | 2015-08-20 12:34:57 -0700 | [diff] [blame] | 493 | resetTopWallpaper = true; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 494 | if (w != winAnimator.mWindowDetachedWallpaper && w.mAppToken != null) { |
| 495 | // If this window's app token is hidden and not animating, |
| 496 | // it is of no interest to us. |
| 497 | if (w.mAppToken.hidden && w.mAppToken.mAppAnimator.animation == null) { |
| 498 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 499 | "Skipping hidden and not animating token: " + w); |
| 500 | continue; |
| 501 | } |
| 502 | } |
| 503 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win #" + i + " " + w + ": isOnScreen=" |
| 504 | + w.isOnScreen() + " mDrawState=" + w.mWinAnimator.mDrawState); |
| 505 | |
Wale Ogunwale | 21fdd91 | 2015-08-20 12:34:57 -0700 | [diff] [blame] | 506 | if (!inFreeformSpace) { |
| 507 | TaskStack stack = w.getStack(); |
| 508 | inFreeformSpace = stack != null && stack.mStackId == FREEFORM_WORKSPACE_STACK_ID; |
| 509 | } |
| 510 | |
Wale Ogunwale | 6cbba70 | 2016-06-28 16:27:31 -0700 | [diff] [blame^] | 511 | replacing |= w.mWillReplaceWindow; |
| 512 | keyguardGoingAwayWithWallpaper |= (w.mAppToken != null |
| 513 | && w.mWinAnimator.mKeyguardGoingAwayWithWallpaper); |
Filip Gruszczynski | 51cb83e | 2015-11-05 09:32:19 -0800 | [diff] [blame] | 514 | |
Wale Ogunwale | 6cbba70 | 2016-06-28 16:27:31 -0700 | [diff] [blame^] | 515 | final boolean hasWallpaper = (w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
Filip Gruszczynski | 51cb83e | 2015-11-05 09:32:19 -0800 | [diff] [blame] | 516 | if (hasWallpaper && w.isOnScreen() && (mWallpaperTarget == w || w.isDrawFinishedLw())) { |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 517 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Found wallpaper target: #" + i + "=" + w); |
| 518 | result.setWallpaperTarget(w, i); |
Jorim Jaggi | 5c80c41 | 2016-04-19 20:03:47 -0700 | [diff] [blame] | 519 | if (w == mWallpaperTarget && w.mWinAnimator.isAnimationSet()) { |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 520 | // The current wallpaper target is animating, so we'll look behind it for |
| 521 | // another possible target and figure out what is going on later. |
| 522 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 523 | "Win " + w + ": token animating, looking behind."); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 524 | continue; |
| 525 | } |
| 526 | break; |
| 527 | } else if (w == winAnimator.mWindowDetachedWallpaper) { |
| 528 | windowDetachedI = i; |
| 529 | } |
| 530 | } |
| 531 | |
Wale Ogunwale | 6cbba70 | 2016-06-28 16:27:31 -0700 | [diff] [blame^] | 532 | if (result.wallpaperTarget != null) { |
| 533 | return; |
| 534 | } |
| 535 | |
| 536 | if (windowDetachedI >= 0) { |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 537 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 538 | "Found animating detached wallpaper activity: #" + windowDetachedI + "=" + w); |
| 539 | result.setWallpaperTarget(w, windowDetachedI); |
Wale Ogunwale | 6cbba70 | 2016-06-28 16:27:31 -0700 | [diff] [blame^] | 540 | } else if (inFreeformSpace || (replacing && mWallpaperTarget != null)) { |
Wale Ogunwale | 21fdd91 | 2015-08-20 12:34:57 -0700 | [diff] [blame] | 541 | // In freeform mode we set the wallpaper as its own target, so we don't need an |
Filip Gruszczynski | 51cb83e | 2015-11-05 09:32:19 -0800 | [diff] [blame] | 542 | // additional window to make it visible. When we are replacing a window and there was |
| 543 | // wallpaper before replacement, we want to keep the window until the new windows fully |
| 544 | // appear and can determine the visibility, to avoid flickering. |
Wale Ogunwale | 21fdd91 | 2015-08-20 12:34:57 -0700 | [diff] [blame] | 545 | result.setWallpaperTarget(result.topWallpaper, result.topWallpaperIndex); |
Wale Ogunwale | 6cbba70 | 2016-06-28 16:27:31 -0700 | [diff] [blame^] | 546 | |
| 547 | } else if (keyguardGoingAwayWithWallpaper) { |
| 548 | // If the app is executing an animation because the keyguard is going away (and the |
| 549 | // keyguard was showing the wallpaper) keep the wallpaper during the animation so it |
| 550 | // doesn't flicker out by having it be its own target. |
| 551 | result.setWallpaperTarget(result.topWallpaper, result.topWallpaperIndex); |
Wale Ogunwale | 21fdd91 | 2015-08-20 12:34:57 -0700 | [diff] [blame] | 552 | } |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 553 | } |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 554 | |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 555 | private boolean updateWallpaperWindowsTarget( |
| 556 | WindowList windows, FindWallpaperTargetResult result) { |
| 557 | |
| 558 | boolean targetChanged = false; |
| 559 | WindowState wallpaperTarget = result.wallpaperTarget; |
| 560 | int wallpaperTargetIndex = result.wallpaperTargetIndex; |
| 561 | |
| 562 | if (mWallpaperTarget != wallpaperTarget |
| 563 | && (mLowerWallpaperTarget == null || mLowerWallpaperTarget != wallpaperTarget)) { |
| 564 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 565 | "New wallpaper target: " + wallpaperTarget + " oldTarget: " + mWallpaperTarget); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 566 | |
| 567 | mLowerWallpaperTarget = null; |
| 568 | mUpperWallpaperTarget = null; |
| 569 | |
| 570 | WindowState oldW = mWallpaperTarget; |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 571 | mWallpaperTarget = wallpaperTarget; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 572 | targetChanged = true; |
| 573 | |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 574 | // Now what is happening... if the current and new targets are animating, |
| 575 | // then we are in our super special mode! |
| 576 | if (wallpaperTarget != null && oldW != null) { |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 577 | boolean oldAnim = oldW.isAnimatingLw(); |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 578 | boolean foundAnim = wallpaperTarget.isAnimatingLw(); |
| 579 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 580 | "New animation: " + foundAnim + " old animation: " + oldAnim); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 581 | if (foundAnim && oldAnim) { |
| 582 | int oldI = windows.indexOf(oldW); |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 583 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 584 | "New i: " + wallpaperTargetIndex + " old i: " + oldI); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 585 | if (oldI >= 0) { |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 586 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 587 | "Animating wallpapers: old#" + oldI + "=" + oldW + "; new#" |
| 588 | + wallpaperTargetIndex + "=" + wallpaperTarget); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 589 | |
| 590 | // Set the new target correctly. |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 591 | if (wallpaperTarget.mAppToken != null |
| 592 | && wallpaperTarget.mAppToken.hiddenRequested) { |
| 593 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 594 | "Old wallpaper still the target."); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 595 | mWallpaperTarget = oldW; |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 596 | wallpaperTarget = oldW; |
| 597 | wallpaperTargetIndex = oldI; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 598 | } |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 599 | // Now set the upper and lower wallpaper targets correctly, |
| 600 | // and make sure that we are positioning the wallpaper below the lower. |
| 601 | else if (wallpaperTargetIndex > oldI) { |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 602 | // The new target is on top of the old one. |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 603 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 604 | "Found target above old target."); |
| 605 | mUpperWallpaperTarget = wallpaperTarget; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 606 | mLowerWallpaperTarget = oldW; |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 607 | wallpaperTarget = oldW; |
| 608 | wallpaperTargetIndex = oldI; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 609 | } else { |
| 610 | // The new target is below the old one. |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 611 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 612 | "Found target below old target."); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 613 | mUpperWallpaperTarget = oldW; |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 614 | mLowerWallpaperTarget = wallpaperTarget; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 615 | } |
| 616 | } |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | } else if (mLowerWallpaperTarget != null) { |
| 621 | // Is it time to stop animating? |
| 622 | if (!mLowerWallpaperTarget.isAnimatingLw() || !mUpperWallpaperTarget.isAnimatingLw()) { |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 623 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "No longer animating wallpaper targets!"); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 624 | mLowerWallpaperTarget = null; |
| 625 | mUpperWallpaperTarget = null; |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 626 | mWallpaperTarget = wallpaperTarget; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 627 | targetChanged = true; |
| 628 | } |
| 629 | } |
| 630 | |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 631 | result.setWallpaperTarget(wallpaperTarget, wallpaperTargetIndex); |
| 632 | return targetChanged; |
| 633 | } |
| 634 | |
| 635 | boolean updateWallpaperWindowsTargetByLayer( |
| 636 | WindowList windows, FindWallpaperTargetResult result) { |
| 637 | |
| 638 | WindowState wallpaperTarget = result.wallpaperTarget; |
| 639 | int wallpaperTargetIndex = result.wallpaperTargetIndex; |
| 640 | boolean visible = wallpaperTarget != null; |
| 641 | |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 642 | if (visible) { |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 643 | // The window is visible to the compositor...but is it visible to the user? |
| 644 | // That is what the wallpaper cares about. |
| 645 | visible = isWallpaperVisible(wallpaperTarget); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 646 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
| 647 | |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 648 | // If the wallpaper target is animating, we may need to copy its layer adjustment. |
| 649 | // Only do this if we are not transferring between two wallpaper targets. |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 650 | mWallpaperAnimLayerAdjustment = |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 651 | (mLowerWallpaperTarget == null && wallpaperTarget.mAppToken != null) |
| 652 | ? wallpaperTarget.mAppToken.mAppAnimator.animLayerAdjustment : 0; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 653 | |
| 654 | final int maxLayer = (mService.mPolicy.getMaxWallpaperLayer() * TYPE_LAYER_MULTIPLIER) |
| 655 | + TYPE_LAYER_OFFSET; |
| 656 | |
| 657 | // Now w is the window we are supposed to be behind... but we |
| 658 | // need to be sure to also be behind any of its attached windows, |
| 659 | // AND any starting window associated with it, AND below the |
| 660 | // maximum layer the policy allows for wallpapers. |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 661 | while (wallpaperTargetIndex > 0) { |
| 662 | WindowState wb = windows.get(wallpaperTargetIndex - 1); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 663 | if (wb.mBaseLayer < maxLayer && |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 664 | wb.mAttachedWindow != wallpaperTarget && |
| 665 | (wallpaperTarget.mAttachedWindow == null || |
| 666 | wb.mAttachedWindow != wallpaperTarget.mAttachedWindow) && |
| 667 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING |
| 668 | || wallpaperTarget.mToken == null |
| 669 | || wb.mToken != wallpaperTarget.mToken)) { |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 670 | // This window is not related to the previous one in any |
| 671 | // interesting way, so stop here. |
| 672 | break; |
| 673 | } |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 674 | wallpaperTarget = wb; |
| 675 | wallpaperTargetIndex--; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 676 | } |
| 677 | } else { |
| 678 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
| 679 | } |
| 680 | |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 681 | result.setWallpaperTarget(wallpaperTarget, wallpaperTargetIndex); |
| 682 | return visible; |
| 683 | } |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 684 | |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 685 | boolean updateWallpaperWindowsPlacement(WindowList windows, |
| 686 | WindowState wallpaperTarget, int wallpaperTargetIndex, boolean visible) { |
| 687 | |
| 688 | // TODO(multidisplay): Wallpapers on main screen only. |
| 689 | final DisplayInfo displayInfo = mService.getDefaultDisplayContentLocked().getDisplayInfo(); |
| 690 | final int dw = displayInfo.logicalWidth; |
| 691 | final int dh = displayInfo.logicalHeight; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 692 | |
| 693 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 694 | // are correctly placed. |
| 695 | boolean changed = false; |
| 696 | for (int curTokenNdx = mWallpaperTokens.size() - 1; curTokenNdx >= 0; curTokenNdx--) { |
| 697 | WindowToken token = mWallpaperTokens.get(curTokenNdx); |
| 698 | if (token.hidden == visible) { |
| 699 | if (DEBUG_WALLPAPER_LIGHT) Slog.d(TAG, |
| 700 | "Wallpaper token " + token + " hidden=" + !visible); |
| 701 | token.hidden = !visible; |
| 702 | // Need to do a layout to ensure the wallpaper now has the correct size. |
| 703 | mService.getDefaultDisplayContentLocked().layoutNeeded = true; |
| 704 | } |
| 705 | |
| 706 | final WindowList tokenWindows = token.windows; |
| 707 | for (int wallpaperNdx = tokenWindows.size() - 1; wallpaperNdx >= 0; wallpaperNdx--) { |
| 708 | WindowState wallpaper = tokenWindows.get(wallpaperNdx); |
| 709 | |
| 710 | if (visible) { |
| 711 | updateWallpaperOffset(wallpaper, dw, dh, false); |
| 712 | } |
| 713 | |
| 714 | // First, make sure the client has the current visibility state. |
| 715 | dispatchWallpaperVisibility(wallpaper, visible); |
| 716 | |
| 717 | wallpaper.mWinAnimator.mAnimLayer = |
| 718 | wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
| 719 | if (DEBUG_LAYERS || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "adjustWallpaper win " |
| 720 | + wallpaper + " anim layer: " + wallpaper.mWinAnimator.mAnimLayer); |
| 721 | |
| 722 | // First, if this window is at the current index, then all is well. |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 723 | if (wallpaper == wallpaperTarget) { |
| 724 | wallpaperTargetIndex--; |
| 725 | wallpaperTarget = wallpaperTargetIndex > 0 |
| 726 | ? windows.get(wallpaperTargetIndex - 1) : null; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 727 | continue; |
| 728 | } |
| 729 | |
| 730 | // The window didn't match... the current wallpaper window, |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 731 | // wherever it is, is in the wrong place, so make sure it is not in the list. |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 732 | int oldIndex = windows.indexOf(wallpaper); |
| 733 | if (oldIndex >= 0) { |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 734 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| 735 | "Wallpaper removing at " + oldIndex + ": " + wallpaper); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 736 | windows.remove(oldIndex); |
| 737 | mService.mWindowsChanged = true; |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 738 | if (oldIndex < wallpaperTargetIndex) { |
| 739 | wallpaperTargetIndex--; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 740 | } |
| 741 | } |
| 742 | |
| 743 | // Now stick it in. For apps over wallpaper keep the wallpaper at the bottommost |
| 744 | // layer. For keyguard over wallpaper put the wallpaper under the keyguard. |
| 745 | int insertionIndex = 0; |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 746 | if (visible && wallpaperTarget != null) { |
| 747 | final int type = wallpaperTarget.mAttrs.type; |
| 748 | final int privateFlags = wallpaperTarget.mAttrs.privateFlags; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 749 | if ((privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 |
| 750 | || type == TYPE_KEYGUARD_SCRIM) { |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 751 | insertionIndex = windows.indexOf(wallpaperTarget); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 752 | } |
| 753 | } |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 754 | if (DEBUG_WALLPAPER_LIGHT || DEBUG_WINDOW_MOVEMENT |
| 755 | || (DEBUG_ADD_REMOVE && oldIndex != insertionIndex)) Slog.v(TAG, |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 756 | "Moving wallpaper " + wallpaper |
| 757 | + " from " + oldIndex + " to " + insertionIndex); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 758 | |
| 759 | windows.add(insertionIndex, wallpaper); |
| 760 | mService.mWindowsChanged = true; |
| 761 | changed = true; |
| 762 | } |
| 763 | } |
| 764 | |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 765 | return changed; |
| 766 | } |
| 767 | |
| 768 | boolean adjustWallpaperWindows() { |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 769 | mService.mWindowPlacerLocked.mWallpaperMayChange = false; |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 770 | |
| 771 | final WindowList windows = mService.getDefaultWindowListLocked(); |
| 772 | // First find top-most window that has asked to be on top of the wallpaper; |
| 773 | // all wallpapers go behind it. |
| 774 | findWallpaperTarget(windows, mFindResults); |
| 775 | final boolean targetChanged = updateWallpaperWindowsTarget(windows, mFindResults); |
| 776 | final boolean visible = updateWallpaperWindowsTargetByLayer(windows, mFindResults); |
| 777 | WindowState wallpaperTarget = mFindResults.wallpaperTarget; |
| 778 | int wallpaperTargetIndex = mFindResults.wallpaperTargetIndex; |
| 779 | |
| 780 | if (wallpaperTarget == null && mFindResults.topWallpaper != null) { |
| 781 | // There is no wallpaper target, so it goes at the bottom. |
| 782 | // We will assume it is the same place as last time, if known. |
| 783 | wallpaperTarget = mFindResults.topWallpaper; |
| 784 | wallpaperTargetIndex = mFindResults.topWallpaperIndex + 1; |
| 785 | } else { |
| 786 | // Okay i is the position immediately above the wallpaper. |
| 787 | // Look at what is below it for later. |
| 788 | wallpaperTarget = wallpaperTargetIndex > 0 |
| 789 | ? windows.get(wallpaperTargetIndex - 1) : null; |
| 790 | } |
| 791 | |
| 792 | if (visible) { |
| 793 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 794 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
| 795 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
| 796 | } |
| 797 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 798 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
| 799 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
| 800 | } |
| 801 | if (mWallpaperTarget.mWallpaperDisplayOffsetX != Integer.MIN_VALUE) { |
| 802 | mLastWallpaperDisplayOffsetX = mWallpaperTarget.mWallpaperDisplayOffsetX; |
| 803 | } |
| 804 | if (mWallpaperTarget.mWallpaperDisplayOffsetY != Integer.MIN_VALUE) { |
| 805 | mLastWallpaperDisplayOffsetY = mWallpaperTarget.mWallpaperDisplayOffsetY; |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | final boolean changed = updateWallpaperWindowsPlacement( |
| 810 | windows, wallpaperTarget, wallpaperTargetIndex, visible); |
| 811 | |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 812 | if (targetChanged && DEBUG_WALLPAPER_LIGHT) Slog.d(TAG, "New wallpaper: target=" |
| 813 | + mWallpaperTarget + " lower=" + mLowerWallpaperTarget + " upper=" |
| 814 | + mUpperWallpaperTarget); |
| 815 | |
| 816 | return changed; |
| 817 | } |
| 818 | |
| 819 | boolean processWallpaperDrawPendingTimeout() { |
| 820 | if (mWallpaperDrawState == WALLPAPER_DRAW_PENDING) { |
| 821 | mWallpaperDrawState = WALLPAPER_DRAW_TIMEOUT; |
| 822 | if (DEBUG_APP_TRANSITIONS || DEBUG_WALLPAPER) Slog.v(TAG, |
| 823 | "*** WALLPAPER DRAW TIMEOUT"); |
| 824 | return true; |
| 825 | } |
| 826 | return false; |
| 827 | } |
| 828 | |
| 829 | boolean wallpaperTransitionReady() { |
| 830 | boolean transitionReady = true; |
| 831 | boolean wallpaperReady = true; |
| 832 | for (int curTokenIndex = mWallpaperTokens.size() - 1; |
| 833 | curTokenIndex >= 0 && wallpaperReady; curTokenIndex--) { |
| 834 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 835 | for (int curWallpaperIndex = token.windows.size() - 1; curWallpaperIndex >= 0; |
| 836 | curWallpaperIndex--) { |
| 837 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 838 | if (wallpaper.mWallpaperVisible && !wallpaper.isDrawnLw()) { |
| 839 | // We've told this wallpaper to be visible, but it is not drawn yet |
| 840 | wallpaperReady = false; |
| 841 | if (mWallpaperDrawState != WALLPAPER_DRAW_TIMEOUT) { |
| 842 | // wait for this wallpaper until it is drawn or timeout |
| 843 | transitionReady = false; |
| 844 | } |
| 845 | if (mWallpaperDrawState == WALLPAPER_DRAW_NORMAL) { |
| 846 | mWallpaperDrawState = WALLPAPER_DRAW_PENDING; |
| 847 | mService.mH.removeMessages(WALLPAPER_DRAW_PENDING_TIMEOUT); |
| 848 | mService.mH.sendEmptyMessageDelayed(WALLPAPER_DRAW_PENDING_TIMEOUT, |
| 849 | WALLPAPER_DRAW_PENDING_TIMEOUT_DURATION); |
| 850 | } |
| 851 | if (DEBUG_APP_TRANSITIONS || DEBUG_WALLPAPER) Slog.v(TAG, |
| 852 | "Wallpaper should be visible but has not been drawn yet. " + |
| 853 | "mWallpaperDrawState=" + mWallpaperDrawState); |
| 854 | break; |
| 855 | } |
| 856 | } |
| 857 | } |
| 858 | if (wallpaperReady) { |
| 859 | mWallpaperDrawState = WALLPAPER_DRAW_NORMAL; |
| 860 | mService.mH.removeMessages(WALLPAPER_DRAW_PENDING_TIMEOUT); |
| 861 | } |
| 862 | |
| 863 | return transitionReady; |
| 864 | } |
| 865 | |
| 866 | void addWallpaperToken(WindowToken token) { |
| 867 | mWallpaperTokens.add(token); |
| 868 | } |
| 869 | |
| 870 | void removeWallpaperToken(WindowToken token) { |
| 871 | mWallpaperTokens.remove(token); |
| 872 | } |
| 873 | |
| 874 | void dump(PrintWriter pw, String prefix) { |
| 875 | pw.print(prefix); pw.print("mWallpaperTarget="); pw.println(mWallpaperTarget); |
| 876 | if (mLowerWallpaperTarget != null || mUpperWallpaperTarget != null) { |
| 877 | pw.print(prefix); pw.print("mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 878 | pw.print(prefix); pw.print("mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 879 | } |
| 880 | pw.print(prefix); pw.print("mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 881 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
| 882 | if (mLastWallpaperDisplayOffsetX != Integer.MIN_VALUE |
| 883 | || mLastWallpaperDisplayOffsetY != Integer.MIN_VALUE) { |
| 884 | pw.print(prefix); |
| 885 | pw.print("mLastWallpaperDisplayOffsetX="); pw.print(mLastWallpaperDisplayOffsetX); |
| 886 | pw.print(" mLastWallpaperDisplayOffsetY="); pw.println(mLastWallpaperDisplayOffsetY); |
| 887 | } |
| 888 | } |
| 889 | |
| 890 | void dumpTokens(PrintWriter pw, String prefix, boolean dumpAll) { |
| 891 | if (!mWallpaperTokens.isEmpty()) { |
| 892 | pw.println(); |
| 893 | pw.print(prefix); pw.println("Wallpaper tokens:"); |
| 894 | for (int i = mWallpaperTokens.size() - 1; i >= 0; i--) { |
| 895 | WindowToken token = mWallpaperTokens.get(i); |
| 896 | pw.print(prefix); pw.print("Wallpaper #"); pw.print(i); |
| 897 | pw.print(' '); pw.print(token); |
| 898 | if (dumpAll) { |
| 899 | pw.println(':'); |
| 900 | token.dump(pw, " "); |
| 901 | } else { |
| 902 | pw.println(); |
| 903 | } |
| 904 | } |
| 905 | } |
| 906 | } |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 907 | |
| 908 | /** Helper class for storing the results of a wallpaper target find operation. */ |
| 909 | final private static class FindWallpaperTargetResult { |
| 910 | int topWallpaperIndex = 0; |
| 911 | WindowState topWallpaper = null; |
| 912 | int wallpaperTargetIndex = 0; |
| 913 | WindowState wallpaperTarget = null; |
| 914 | |
| 915 | void setTopWallpaper(WindowState win, int index) { |
| 916 | topWallpaper = win; |
| 917 | topWallpaperIndex = index; |
| 918 | } |
| 919 | |
| 920 | void setWallpaperTarget(WindowState win, int index) { |
| 921 | wallpaperTarget = win; |
| 922 | wallpaperTargetIndex = index; |
| 923 | } |
| 924 | |
| 925 | void reset() { |
| 926 | topWallpaperIndex = 0; |
| 927 | topWallpaper = null; |
| 928 | wallpaperTargetIndex = 0; |
| 929 | wallpaperTarget = null; |
| 930 | } |
| 931 | } |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 932 | } |