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 | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 19 | import com.android.internal.util.ToBooleanFunction; |
| 20 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 21 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 22 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 23 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 24 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 25 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 26 | |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 27 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 28 | import static com.android.server.wm.AppTransition.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 29 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 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; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 35 | |
| 36 | import android.os.Bundle; |
| 37 | import android.os.Debug; |
| 38 | import android.os.IBinder; |
| 39 | import android.os.RemoteException; |
| 40 | import android.os.SystemClock; |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 41 | import android.util.ArraySet; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 42 | import android.util.Slog; |
| 43 | import android.view.DisplayInfo; |
| 44 | import android.view.WindowManager; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 45 | import android.view.animation.Animation; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 46 | |
| 47 | import java.io.PrintWriter; |
| 48 | import java.util.ArrayList; |
| 49 | |
| 50 | /** |
| 51 | * Controls wallpaper windows visibility, ordering, and so on. |
| 52 | * NOTE: All methods in this class must be called with the window manager service lock held. |
| 53 | */ |
| 54 | class WallpaperController { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 55 | private static final String TAG = TAG_WITH_CLASS_NAME ? "WallpaperController" : TAG_WM; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 56 | private WindowManagerService mService; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 57 | |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 58 | private final ArrayList<WallpaperWindowToken> mWallpaperTokens = new ArrayList<>(); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 59 | |
| 60 | // If non-null, this is the currently visible window that is associated |
| 61 | // with the wallpaper. |
| 62 | private WindowState mWallpaperTarget = null; |
| 63 | // If non-null, we are in the middle of animating from one wallpaper target |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 64 | // to another, and this is the previous wallpaper target. |
| 65 | private WindowState mPrevWallpaperTarget = null; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 66 | |
| 67 | private int mWallpaperAnimLayerAdjustment; |
| 68 | |
| 69 | private float mLastWallpaperX = -1; |
| 70 | private float mLastWallpaperY = -1; |
| 71 | private float mLastWallpaperXStep = -1; |
| 72 | private float mLastWallpaperYStep = -1; |
| 73 | private int mLastWallpaperDisplayOffsetX = Integer.MIN_VALUE; |
| 74 | private int mLastWallpaperDisplayOffsetY = Integer.MIN_VALUE; |
| 75 | |
| 76 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 77 | // changing its scroll position. |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 78 | private WindowState mWaitingOnWallpaper; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 79 | |
| 80 | // The last time we had a timeout when waiting for a wallpaper. |
| 81 | private long mLastWallpaperTimeoutTime; |
| 82 | // We give a wallpaper up to 150ms to finish scrolling. |
| 83 | private static final long WALLPAPER_TIMEOUT = 150; |
| 84 | // Time we wait after a timeout before trying to wait again. |
| 85 | private static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
| 86 | |
| 87 | // Set to the wallpaper window we would like to hide once the transition animations are done. |
| 88 | // This is useful in cases where we don't want the wallpaper to be hidden when the close app |
| 89 | // is a wallpaper target and is done animating out, but the opening app isn't a wallpaper |
| 90 | // target and isn't done animating in. |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 91 | WindowState mDeferredHideWallpaper = null; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 92 | |
| 93 | // We give a wallpaper up to 500ms to finish drawing before playing app transitions. |
| 94 | private static final long WALLPAPER_DRAW_PENDING_TIMEOUT_DURATION = 500; |
| 95 | private static final int WALLPAPER_DRAW_NORMAL = 0; |
| 96 | private static final int WALLPAPER_DRAW_PENDING = 1; |
| 97 | private static final int WALLPAPER_DRAW_TIMEOUT = 2; |
| 98 | private int mWallpaperDrawState = WALLPAPER_DRAW_NORMAL; |
| 99 | |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 100 | private final FindWallpaperTargetResult mFindResults = new FindWallpaperTargetResult(); |
| 101 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 102 | private final ToBooleanFunction<WindowState> mFindWallpaperTargetFunction = w -> { |
| 103 | final WindowAnimator winAnimator = mService.mAnimator; |
| 104 | if ((w.mAttrs.type == TYPE_WALLPAPER)) { |
| 105 | if (mFindResults.topWallpaper == null || mFindResults.resetTopWallpaper) { |
| 106 | mFindResults.setTopWallpaper(w); |
| 107 | mFindResults.resetTopWallpaper = false; |
| 108 | } |
| 109 | return false; |
| 110 | } |
| 111 | |
| 112 | mFindResults.resetTopWallpaper = true; |
| 113 | if (w != winAnimator.mWindowDetachedWallpaper && w.mAppToken != null) { |
| 114 | // If this window's app token is hidden and not animating, it is of no interest to us. |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame^] | 115 | if (w.mAppToken.isHidden() && !w.mAppToken.isSelfAnimating()) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 116 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 117 | "Skipping hidden and not animating token: " + w); |
| 118 | return false; |
| 119 | } |
| 120 | } |
| 121 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": isOnScreen=" + w.isOnScreen() |
| 122 | + " mDrawState=" + w.mWinAnimator.mDrawState); |
| 123 | |
| 124 | if (w.mWillReplaceWindow && mWallpaperTarget == null |
| 125 | && !mFindResults.useTopWallpaperAsTarget) { |
| 126 | // When we are replacing a window and there was wallpaper before replacement, we want to |
| 127 | // keep the window until the new windows fully appear and can determine the visibility, |
| 128 | // to avoid flickering. |
| 129 | mFindResults.setUseTopWallpaperAsTarget(true); |
| 130 | } |
| 131 | |
| 132 | final boolean keyguardGoingAwayWithWallpaper = (w.mAppToken != null |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame^] | 133 | && w.mAppToken.isSelfAnimating() |
| 134 | && AppTransition.isKeyguardGoingAwayTransit(w.mAppToken.getTransit()) |
| 135 | && (w.mAppToken.getTransitFlags() |
| 136 | & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER) != 0); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 137 | |
| 138 | boolean needsShowWhenLockedWallpaper = false; |
| 139 | if ((w.mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0 |
| 140 | && mService.mPolicy.isKeyguardLocked() |
| 141 | && mService.mPolicy.isKeyguardOccluded()) { |
| 142 | // The lowest show when locked window decides whether we need to put the wallpaper |
| 143 | // behind. |
| 144 | needsShowWhenLockedWallpaper = !isFullscreen(w.mAttrs) |
| 145 | || (w.mAppToken != null && !w.mAppToken.fillsParent()); |
| 146 | } |
| 147 | |
| 148 | if (keyguardGoingAwayWithWallpaper || needsShowWhenLockedWallpaper) { |
| 149 | // Keep the wallpaper during Keyguard exit but also when it's needed for a |
| 150 | // non-fullscreen show when locked activity. |
| 151 | mFindResults.setUseTopWallpaperAsTarget(true); |
| 152 | } |
| 153 | |
| 154 | final boolean hasWallpaper = (w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
| 155 | if (hasWallpaper && w.isOnScreen() && (mWallpaperTarget == w || w.isDrawFinishedLw())) { |
| 156 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Found wallpaper target: " + w); |
| 157 | mFindResults.setWallpaperTarget(w); |
| 158 | if (w == mWallpaperTarget && w.mWinAnimator.isAnimationSet()) { |
| 159 | // The current wallpaper target is animating, so we'll look behind it for |
| 160 | // another possible target and figure out what is going on later. |
| 161 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 162 | "Win " + w + ": token animating, looking behind."); |
| 163 | } |
| 164 | // Found a target! End search. |
| 165 | return true; |
| 166 | } else if (w == winAnimator.mWindowDetachedWallpaper) { |
| 167 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 168 | "Found animating detached wallpaper target win: " + w); |
| 169 | mFindResults.setUseTopWallpaperAsTarget(true); |
| 170 | } |
| 171 | return false; |
| 172 | }; |
| 173 | |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 174 | public WallpaperController(WindowManagerService service) { |
| 175 | mService = service; |
| 176 | } |
| 177 | |
| 178 | WindowState getWallpaperTarget() { |
| 179 | return mWallpaperTarget; |
| 180 | } |
| 181 | |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 182 | boolean isWallpaperTarget(WindowState win) { |
| 183 | return win == mWallpaperTarget; |
| 184 | } |
| 185 | |
| 186 | boolean isBelowWallpaperTarget(WindowState win) { |
| 187 | return mWallpaperTarget != null && mWallpaperTarget.mLayer >= win.mBaseLayer; |
| 188 | } |
| 189 | |
| 190 | boolean isWallpaperVisible() { |
| 191 | return isWallpaperVisible(mWallpaperTarget); |
| 192 | } |
| 193 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 194 | /** |
| 195 | * Starts {@param a} on all wallpaper windows. |
| 196 | */ |
| 197 | void startWallpaperAnimation(Animation a) { |
| 198 | for (int curTokenNdx = mWallpaperTokens.size() - 1; curTokenNdx >= 0; curTokenNdx--) { |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 199 | final WallpaperWindowToken token = mWallpaperTokens.get(curTokenNdx); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 200 | token.startAnimation(a); |
| 201 | } |
| 202 | } |
| 203 | |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 204 | private boolean isWallpaperVisible(WindowState wallpaperTarget) { |
| 205 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target " + wallpaperTarget + ", obscured=" |
| 206 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame^] | 207 | + " animating=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 208 | ? wallpaperTarget.mAppToken.isSelfAnimating() : null) |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 209 | + " prev=" + mPrevWallpaperTarget); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 210 | return (wallpaperTarget != null |
| 211 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame^] | 212 | && wallpaperTarget.mAppToken.isSelfAnimating()))) |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 213 | || mPrevWallpaperTarget != null; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | boolean isWallpaperTargetAnimating() { |
Jorim Jaggi | 5c80c41 | 2016-04-19 20:03:47 -0700 | [diff] [blame] | 217 | return mWallpaperTarget != null && mWallpaperTarget.mWinAnimator.isAnimationSet() |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame^] | 218 | && (mWallpaperTarget.mAppToken == null |
| 219 | || !mWallpaperTarget.mAppToken.isWaitingForTransitionStart()); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | void updateWallpaperVisibility() { |
Filip Gruszczynski | 63a35e2 | 2015-11-05 15:38:59 -0800 | [diff] [blame] | 223 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 224 | |
| 225 | for (int curTokenNdx = mWallpaperTokens.size() - 1; curTokenNdx >= 0; curTokenNdx--) { |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 226 | final WallpaperWindowToken token = mWallpaperTokens.get(curTokenNdx); |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 227 | token.updateWallpaperVisibility(visible); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | |
| 231 | void hideDeferredWallpapersIfNeeded() { |
| 232 | if (mDeferredHideWallpaper != null) { |
| 233 | hideWallpapers(mDeferredHideWallpaper); |
| 234 | mDeferredHideWallpaper = null; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | void hideWallpapers(final WindowState winGoingAway) { |
| 239 | if (mWallpaperTarget != null |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 240 | && (mWallpaperTarget != winGoingAway || mPrevWallpaperTarget != null)) { |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 241 | return; |
| 242 | } |
| 243 | if (mService.mAppTransition.isRunning()) { |
| 244 | // Defer hiding the wallpaper when app transition is running until the animations |
| 245 | // are done. |
| 246 | mDeferredHideWallpaper = winGoingAway; |
| 247 | return; |
| 248 | } |
| 249 | |
| 250 | final boolean wasDeferred = (mDeferredHideWallpaper == winGoingAway); |
| 251 | for (int i = mWallpaperTokens.size() - 1; i >= 0; i--) { |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 252 | final WallpaperWindowToken token = mWallpaperTokens.get(i); |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 253 | token.hideWallpaperToken(wasDeferred, "hideWallpapers"); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame^] | 254 | if (DEBUG_WALLPAPER_LIGHT && !token.isHidden()) Slog.d(TAG, "Hiding wallpaper " + token |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 255 | + " from " + winGoingAway + " target=" + mWallpaperTarget + " prev=" |
| 256 | + mPrevWallpaperTarget + "\n" + Debug.getCallers(5, " ")); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | |
| 260 | boolean updateWallpaperOffset(WindowState wallpaperWin, int dw, int dh, boolean sync) { |
| 261 | boolean rawChanged = false; |
Winson | 4b4ba90 | 2016-07-27 19:45:52 -0700 | [diff] [blame] | 262 | // Set the default wallpaper x-offset to either edge of the screen (depending on RTL), to |
| 263 | // match the behavior of most Launchers |
| 264 | float defaultWallpaperX = wallpaperWin.isRtl() ? 1f : 0f; |
| 265 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : defaultWallpaperX; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 266 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
| 267 | int availw = wallpaperWin.mFrame.right - wallpaperWin.mFrame.left - dw; |
| 268 | int offset = availw > 0 ? -(int)(availw * wpx + .5f) : 0; |
| 269 | if (mLastWallpaperDisplayOffsetX != Integer.MIN_VALUE) { |
| 270 | offset += mLastWallpaperDisplayOffsetX; |
| 271 | } |
| 272 | boolean changed = wallpaperWin.mXOffset != offset; |
| 273 | if (changed) { |
| 274 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " + wallpaperWin + " x: " + offset); |
| 275 | wallpaperWin.mXOffset = offset; |
| 276 | } |
| 277 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
| 278 | wallpaperWin.mWallpaperX = wpx; |
| 279 | wallpaperWin.mWallpaperXStep = wpxs; |
| 280 | rawChanged = true; |
| 281 | } |
| 282 | |
| 283 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
| 284 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
| 285 | int availh = wallpaperWin.mFrame.bottom - wallpaperWin.mFrame.top - dh; |
| 286 | offset = availh > 0 ? -(int)(availh * wpy + .5f) : 0; |
| 287 | if (mLastWallpaperDisplayOffsetY != Integer.MIN_VALUE) { |
| 288 | offset += mLastWallpaperDisplayOffsetY; |
| 289 | } |
| 290 | if (wallpaperWin.mYOffset != offset) { |
| 291 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " + wallpaperWin + " y: " + offset); |
| 292 | changed = true; |
| 293 | wallpaperWin.mYOffset = offset; |
| 294 | } |
| 295 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
| 296 | wallpaperWin.mWallpaperY = wpy; |
| 297 | wallpaperWin.mWallpaperYStep = wpys; |
| 298 | rawChanged = true; |
| 299 | } |
| 300 | |
| 301 | if (rawChanged && (wallpaperWin.mAttrs.privateFlags & |
| 302 | WindowManager.LayoutParams.PRIVATE_FLAG_WANTS_OFFSET_NOTIFICATIONS) != 0) { |
| 303 | try { |
| 304 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
| 305 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 306 | + " y=" + wallpaperWin.mWallpaperY); |
| 307 | if (sync) { |
| 308 | mWaitingOnWallpaper = wallpaperWin; |
| 309 | } |
| 310 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
| 311 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 312 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
| 313 | if (sync) { |
| 314 | if (mWaitingOnWallpaper != null) { |
| 315 | long start = SystemClock.uptimeMillis(); |
| 316 | if ((mLastWallpaperTimeoutTime + WALLPAPER_TIMEOUT_RECOVERY) |
| 317 | < start) { |
| 318 | try { |
| 319 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 320 | "Waiting for offset complete..."); |
| 321 | mService.mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 322 | } catch (InterruptedException e) { |
| 323 | } |
| 324 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
| 325 | if ((start + WALLPAPER_TIMEOUT) < SystemClock.uptimeMillis()) { |
| 326 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
| 327 | + wallpaperWin); |
| 328 | mLastWallpaperTimeoutTime = start; |
| 329 | } |
| 330 | } |
| 331 | mWaitingOnWallpaper = null; |
| 332 | } |
| 333 | } |
| 334 | } catch (RemoteException e) { |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | return changed; |
| 339 | } |
| 340 | |
| 341 | void setWindowWallpaperPosition( |
| 342 | WindowState window, float x, float y, float xStep, float yStep) { |
| 343 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 344 | window.mWallpaperX = x; |
| 345 | window.mWallpaperY = y; |
| 346 | window.mWallpaperXStep = xStep; |
| 347 | window.mWallpaperYStep = yStep; |
| 348 | updateWallpaperOffsetLocked(window, true); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | void setWindowWallpaperDisplayOffset(WindowState window, int x, int y) { |
| 353 | if (window.mWallpaperDisplayOffsetX != x || window.mWallpaperDisplayOffsetY != y) { |
| 354 | window.mWallpaperDisplayOffsetX = x; |
| 355 | window.mWallpaperDisplayOffsetY = y; |
| 356 | updateWallpaperOffsetLocked(window, true); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | Bundle sendWindowWallpaperCommand( |
| 361 | WindowState window, String action, int x, int y, int z, Bundle extras, boolean sync) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 362 | if (window == mWallpaperTarget || window == mPrevWallpaperTarget) { |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 363 | boolean doWait = sync; |
| 364 | for (int curTokenNdx = mWallpaperTokens.size() - 1; curTokenNdx >= 0; curTokenNdx--) { |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 365 | final WallpaperWindowToken token = mWallpaperTokens.get(curTokenNdx); |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 366 | token.sendWindowWallpaperCommand(action, x, y, z, extras, sync); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | if (doWait) { |
| 370 | // TODO: Need to wait for result. |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | return null; |
| 375 | } |
| 376 | |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 377 | private void updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 378 | final DisplayContent displayContent = changingTarget.getDisplayContent(); |
| 379 | if (displayContent == null) { |
| 380 | return; |
| 381 | } |
| 382 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 383 | final int dw = displayInfo.logicalWidth; |
| 384 | final int dh = displayInfo.logicalHeight; |
| 385 | |
| 386 | WindowState target = mWallpaperTarget; |
| 387 | if (target != null) { |
| 388 | if (target.mWallpaperX >= 0) { |
| 389 | mLastWallpaperX = target.mWallpaperX; |
| 390 | } else if (changingTarget.mWallpaperX >= 0) { |
| 391 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 392 | } |
| 393 | if (target.mWallpaperY >= 0) { |
| 394 | mLastWallpaperY = target.mWallpaperY; |
| 395 | } else if (changingTarget.mWallpaperY >= 0) { |
| 396 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 397 | } |
| 398 | if (target.mWallpaperDisplayOffsetX != Integer.MIN_VALUE) { |
| 399 | mLastWallpaperDisplayOffsetX = target.mWallpaperDisplayOffsetX; |
| 400 | } else if (changingTarget.mWallpaperDisplayOffsetX != Integer.MIN_VALUE) { |
| 401 | mLastWallpaperDisplayOffsetX = changingTarget.mWallpaperDisplayOffsetX; |
| 402 | } |
| 403 | if (target.mWallpaperDisplayOffsetY != Integer.MIN_VALUE) { |
| 404 | mLastWallpaperDisplayOffsetY = target.mWallpaperDisplayOffsetY; |
| 405 | } else if (changingTarget.mWallpaperDisplayOffsetY != Integer.MIN_VALUE) { |
| 406 | mLastWallpaperDisplayOffsetY = changingTarget.mWallpaperDisplayOffsetY; |
| 407 | } |
| 408 | if (target.mWallpaperXStep >= 0) { |
| 409 | mLastWallpaperXStep = target.mWallpaperXStep; |
| 410 | } else if (changingTarget.mWallpaperXStep >= 0) { |
| 411 | mLastWallpaperXStep = changingTarget.mWallpaperXStep; |
| 412 | } |
| 413 | if (target.mWallpaperYStep >= 0) { |
| 414 | mLastWallpaperYStep = target.mWallpaperYStep; |
| 415 | } else if (changingTarget.mWallpaperYStep >= 0) { |
| 416 | mLastWallpaperYStep = changingTarget.mWallpaperYStep; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | for (int curTokenNdx = mWallpaperTokens.size() - 1; curTokenNdx >= 0; curTokenNdx--) { |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 421 | mWallpaperTokens.get(curTokenNdx).updateWallpaperOffset(dw, dh, sync); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | |
| 425 | void clearLastWallpaperTimeoutTime() { |
| 426 | mLastWallpaperTimeoutTime = 0; |
| 427 | } |
| 428 | |
| 429 | void wallpaperCommandComplete(IBinder window) { |
| 430 | if (mWaitingOnWallpaper != null && |
| 431 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 432 | mWaitingOnWallpaper = null; |
| 433 | mService.mWindowMap.notifyAll(); |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | void wallpaperOffsetsComplete(IBinder window) { |
| 438 | if (mWaitingOnWallpaper != null && |
| 439 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 440 | mWaitingOnWallpaper = null; |
| 441 | mService.mWindowMap.notifyAll(); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | int getAnimLayerAdjustment() { |
| 446 | return mWallpaperAnimLayerAdjustment; |
| 447 | } |
| 448 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 449 | private void findWallpaperTarget(DisplayContent dc) { |
| 450 | mFindResults.reset(); |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 451 | if (dc.isStackVisible(WINDOWING_MODE_FREEFORM)) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 452 | // In freeform mode we set the wallpaper as its own target, so we don't need an |
| 453 | // additional window to make it visible. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 454 | mFindResults.setUseTopWallpaperAsTarget(true); |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 455 | } |
Wale Ogunwale | 6cbba70 | 2016-06-28 16:27:31 -0700 | [diff] [blame] | 456 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 457 | dc.forAllWindows(mFindWallpaperTargetFunction, true /* traverseTopToBottom */); |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 458 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 459 | if (mFindResults.wallpaperTarget == null && mFindResults.useTopWallpaperAsTarget) { |
| 460 | mFindResults.setWallpaperTarget(mFindResults.topWallpaper); |
Wale Ogunwale | 21fdd91 | 2015-08-20 12:34:57 -0700 | [diff] [blame] | 461 | } |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 462 | } |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 463 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 464 | private boolean isFullscreen(WindowManager.LayoutParams attrs) { |
| 465 | return attrs.x == 0 && attrs.y == 0 |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 466 | && attrs.width == MATCH_PARENT && attrs.height == MATCH_PARENT; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 467 | } |
| 468 | |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 469 | /** Updates the target wallpaper if needed and returns true if an update happened. */ |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 470 | private void updateWallpaperWindowsTarget(DisplayContent dc, |
| 471 | FindWallpaperTargetResult result) { |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 472 | |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 473 | WindowState wallpaperTarget = result.wallpaperTarget; |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 474 | |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 475 | if (mWallpaperTarget == wallpaperTarget |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 476 | || (mPrevWallpaperTarget != null && mPrevWallpaperTarget == wallpaperTarget)) { |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 477 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 478 | if (mPrevWallpaperTarget == null) { |
| 479 | return; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 482 | // Is it time to stop animating? |
| 483 | if (!mPrevWallpaperTarget.isAnimatingLw()) { |
| 484 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "No longer animating wallpaper targets!"); |
| 485 | mPrevWallpaperTarget = null; |
| 486 | mWallpaperTarget = wallpaperTarget; |
| 487 | } |
| 488 | return; |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 492 | "New wallpaper target: " + wallpaperTarget + " prevTarget: " + mWallpaperTarget); |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 493 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 494 | mPrevWallpaperTarget = null; |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 495 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 496 | final WindowState prevWallpaperTarget = mWallpaperTarget; |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 497 | mWallpaperTarget = wallpaperTarget; |
| 498 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 499 | if (wallpaperTarget == null || prevWallpaperTarget == null) { |
| 500 | return; |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | // Now what is happening... if the current and new targets are animating, |
| 504 | // then we are in our super special mode! |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 505 | boolean oldAnim = prevWallpaperTarget.isAnimatingLw(); |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 506 | boolean foundAnim = wallpaperTarget.isAnimatingLw(); |
| 507 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 508 | "New animation: " + foundAnim + " old animation: " + oldAnim); |
| 509 | |
| 510 | if (!foundAnim || !oldAnim) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 511 | return; |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 514 | if (dc.getWindow(w -> w == prevWallpaperTarget) == null) { |
| 515 | return; |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | final boolean newTargetHidden = wallpaperTarget.mAppToken != null |
| 519 | && wallpaperTarget.mAppToken.hiddenRequested; |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 520 | final boolean oldTargetHidden = prevWallpaperTarget.mAppToken != null |
| 521 | && prevWallpaperTarget.mAppToken.hiddenRequested; |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 522 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 523 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "Animating wallpapers:" + " old: " |
| 524 | + prevWallpaperTarget + " hidden=" + oldTargetHidden + " new: " + wallpaperTarget |
| 525 | + " hidden=" + newTargetHidden); |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 526 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 527 | mPrevWallpaperTarget = prevWallpaperTarget; |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 528 | |
| 529 | if (newTargetHidden && !oldTargetHidden) { |
| 530 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "Old wallpaper still the target."); |
| 531 | // Use the old target if new target is hidden but old target |
| 532 | // is not. If they're both hidden, still use the new target. |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 533 | mWallpaperTarget = prevWallpaperTarget; |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 534 | } else if (newTargetHidden == oldTargetHidden |
| 535 | && !mService.mOpeningApps.contains(wallpaperTarget.mAppToken) |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 536 | && (mService.mOpeningApps.contains(prevWallpaperTarget.mAppToken) |
| 537 | || mService.mClosingApps.contains(prevWallpaperTarget.mAppToken))) { |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 538 | // If they're both hidden (or both not hidden), prefer the one that's currently in |
| 539 | // opening or closing app list, this allows transition selection logic to better |
| 540 | // determine the wallpaper status of opening/closing apps. |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 541 | mWallpaperTarget = prevWallpaperTarget; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 544 | result.setWallpaperTarget(wallpaperTarget); |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 547 | private void updateWallpaperTokens(boolean visible) { |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 548 | for (int curTokenNdx = mWallpaperTokens.size() - 1; curTokenNdx >= 0; curTokenNdx--) { |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 549 | final WallpaperWindowToken token = mWallpaperTokens.get(curTokenNdx); |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 550 | token.updateWallpaperWindows(visible, mWallpaperAnimLayerAdjustment); |
Robert Carr | dee1b3f | 2017-02-27 11:33:33 -0800 | [diff] [blame] | 551 | token.getDisplayContent().assignWindowLayers(false); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 552 | } |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 553 | } |
| 554 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 555 | void adjustWallpaperWindows(DisplayContent dc) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 556 | mService.mRoot.mWallpaperMayChange = false; |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 557 | |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 558 | // First find top-most window that has asked to be on top of the wallpaper; |
| 559 | // all wallpapers go behind it. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 560 | findWallpaperTarget(dc); |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 561 | updateWallpaperWindowsTarget(dc, mFindResults); |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 562 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 563 | // The window is visible to the compositor...but is it visible to the user? |
| 564 | // That is what the wallpaper cares about. |
| 565 | final boolean visible = mWallpaperTarget != null && isWallpaperVisible(mWallpaperTarget); |
| 566 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 567 | |
| 568 | if (visible) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 569 | // If the wallpaper target is animating, we may need to copy its layer adjustment. |
| 570 | // Only do this if we are not transferring between two wallpaper targets. |
| 571 | mWallpaperAnimLayerAdjustment = |
| 572 | (mPrevWallpaperTarget == null && mWallpaperTarget.mAppToken != null) |
Robert Carr | dee1b3f | 2017-02-27 11:33:33 -0800 | [diff] [blame] | 573 | ? mWallpaperTarget.mAppToken.getAnimLayerAdjustment() : 0; |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 574 | |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 575 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 576 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
| 577 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
| 578 | } |
| 579 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 580 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
| 581 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
| 582 | } |
| 583 | if (mWallpaperTarget.mWallpaperDisplayOffsetX != Integer.MIN_VALUE) { |
| 584 | mLastWallpaperDisplayOffsetX = mWallpaperTarget.mWallpaperDisplayOffsetX; |
| 585 | } |
| 586 | if (mWallpaperTarget.mWallpaperDisplayOffsetY != Integer.MIN_VALUE) { |
| 587 | mLastWallpaperDisplayOffsetY = mWallpaperTarget.mWallpaperDisplayOffsetY; |
| 588 | } |
| 589 | } |
| 590 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 591 | updateWallpaperTokens(visible); |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 592 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 593 | if (DEBUG_WALLPAPER_LIGHT) Slog.d(TAG, "New wallpaper: target=" + mWallpaperTarget |
| 594 | + " prev=" + mPrevWallpaperTarget); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | boolean processWallpaperDrawPendingTimeout() { |
| 598 | if (mWallpaperDrawState == WALLPAPER_DRAW_PENDING) { |
| 599 | mWallpaperDrawState = WALLPAPER_DRAW_TIMEOUT; |
| 600 | if (DEBUG_APP_TRANSITIONS || DEBUG_WALLPAPER) Slog.v(TAG, |
| 601 | "*** WALLPAPER DRAW TIMEOUT"); |
| 602 | return true; |
| 603 | } |
| 604 | return false; |
| 605 | } |
| 606 | |
| 607 | boolean wallpaperTransitionReady() { |
| 608 | boolean transitionReady = true; |
| 609 | boolean wallpaperReady = true; |
| 610 | for (int curTokenIndex = mWallpaperTokens.size() - 1; |
| 611 | curTokenIndex >= 0 && wallpaperReady; curTokenIndex--) { |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 612 | final WallpaperWindowToken token = mWallpaperTokens.get(curTokenIndex); |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 613 | if (token.hasVisibleNotDrawnWallpaper()) { |
| 614 | // We've told this wallpaper to be visible, but it is not drawn yet |
| 615 | wallpaperReady = false; |
| 616 | if (mWallpaperDrawState != WALLPAPER_DRAW_TIMEOUT) { |
| 617 | // wait for this wallpaper until it is drawn or timeout |
| 618 | transitionReady = false; |
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 | if (mWallpaperDrawState == WALLPAPER_DRAW_NORMAL) { |
| 621 | mWallpaperDrawState = WALLPAPER_DRAW_PENDING; |
| 622 | mService.mH.removeMessages(WALLPAPER_DRAW_PENDING_TIMEOUT); |
| 623 | mService.mH.sendEmptyMessageDelayed(WALLPAPER_DRAW_PENDING_TIMEOUT, |
| 624 | WALLPAPER_DRAW_PENDING_TIMEOUT_DURATION); |
| 625 | } |
| 626 | if (DEBUG_APP_TRANSITIONS || DEBUG_WALLPAPER) Slog.v(TAG, |
| 627 | "Wallpaper should be visible but has not been drawn yet. " + |
| 628 | "mWallpaperDrawState=" + mWallpaperDrawState); |
| 629 | break; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 630 | } |
| 631 | } |
| 632 | if (wallpaperReady) { |
| 633 | mWallpaperDrawState = WALLPAPER_DRAW_NORMAL; |
| 634 | mService.mH.removeMessages(WALLPAPER_DRAW_PENDING_TIMEOUT); |
| 635 | } |
| 636 | |
| 637 | return transitionReady; |
| 638 | } |
| 639 | |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 640 | /** |
| 641 | * Adjusts the wallpaper windows if the input display has a pending wallpaper layout or one of |
| 642 | * the opening apps should be a wallpaper target. |
| 643 | */ |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 644 | void adjustWallpaperWindowsForAppTransitionIfNeeded(DisplayContent dc, |
| 645 | ArraySet<AppWindowToken> openingApps) { |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 646 | boolean adjust = false; |
| 647 | if ((dc.pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 648 | adjust = true; |
| 649 | } else { |
| 650 | for (int i = openingApps.size() - 1; i >= 0; --i) { |
| 651 | final AppWindowToken token = openingApps.valueAt(i); |
| 652 | if (token.windowsCanBeWallpaperTarget()) { |
| 653 | adjust = true; |
| 654 | break; |
| 655 | } |
| 656 | } |
| 657 | } |
| 658 | |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 659 | if (adjust) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 660 | adjustWallpaperWindows(dc); |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 661 | } |
| 662 | } |
| 663 | |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 664 | void addWallpaperToken(WallpaperWindowToken token) { |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 665 | mWallpaperTokens.add(token); |
| 666 | } |
| 667 | |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 668 | void removeWallpaperToken(WallpaperWindowToken token) { |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 669 | mWallpaperTokens.remove(token); |
| 670 | } |
| 671 | |
| 672 | void dump(PrintWriter pw, String prefix) { |
| 673 | pw.print(prefix); pw.print("mWallpaperTarget="); pw.println(mWallpaperTarget); |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 674 | if (mPrevWallpaperTarget != null) { |
| 675 | pw.print(prefix); pw.print("mPrevWallpaperTarget="); pw.println(mPrevWallpaperTarget); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 676 | } |
| 677 | pw.print(prefix); pw.print("mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 678 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
| 679 | if (mLastWallpaperDisplayOffsetX != Integer.MIN_VALUE |
| 680 | || mLastWallpaperDisplayOffsetY != Integer.MIN_VALUE) { |
| 681 | pw.print(prefix); |
| 682 | pw.print("mLastWallpaperDisplayOffsetX="); pw.print(mLastWallpaperDisplayOffsetX); |
| 683 | pw.print(" mLastWallpaperDisplayOffsetY="); pw.println(mLastWallpaperDisplayOffsetY); |
| 684 | } |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 685 | |
| 686 | if (mWallpaperAnimLayerAdjustment != 0) { |
| 687 | pw.println(prefix + "mWallpaperAnimLayerAdjustment=" + mWallpaperAnimLayerAdjustment); |
| 688 | } |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 689 | } |
| 690 | |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 691 | /** Helper class for storing the results of a wallpaper target find operation. */ |
| 692 | final private static class FindWallpaperTargetResult { |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 693 | WindowState topWallpaper = null; |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 694 | boolean useTopWallpaperAsTarget = false; |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 695 | WindowState wallpaperTarget = null; |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 696 | boolean resetTopWallpaper = false; |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 697 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 698 | void setTopWallpaper(WindowState win) { |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 699 | topWallpaper = win; |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 700 | } |
| 701 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 702 | void setWallpaperTarget(WindowState win) { |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 703 | wallpaperTarget = win; |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | void setUseTopWallpaperAsTarget(boolean topWallpaperAsTarget) { |
| 707 | useTopWallpaperAsTarget = topWallpaperAsTarget; |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | void reset() { |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 711 | topWallpaper = null; |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 712 | wallpaperTarget = null; |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 713 | useTopWallpaperAsTarget = false; |
| 714 | resetTopWallpaper = false; |
Wale Ogunwale | 5f61d04 | 2015-08-20 10:09:47 -0700 | [diff] [blame] | 715 | } |
| 716 | } |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 717 | } |