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