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