Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 19 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 20 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS; |
| 21 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT; |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 22 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 23 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
| 24 | |
| 25 | import android.os.Bundle; |
| 26 | import android.os.IBinder; |
| 27 | import android.os.RemoteException; |
| 28 | import android.util.Slog; |
| 29 | import android.view.DisplayInfo; |
| 30 | import android.view.animation.Animation; |
| 31 | |
| 32 | /** |
| 33 | * A token that represents a set of wallpaper windows. |
| 34 | */ |
| 35 | class WallpaperWindowToken extends WindowToken { |
| 36 | |
| 37 | private static final String TAG = TAG_WITH_CLASS_NAME ? "WallpaperWindowToken" : TAG_WM; |
| 38 | |
| 39 | WallpaperWindowToken(WindowManagerService service, IBinder token, boolean explicit, |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 40 | DisplayContent dc, boolean ownerCanManageAppTokens) { |
| 41 | super(service, token, TYPE_WALLPAPER, explicit, dc, ownerCanManageAppTokens); |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 42 | dc.mWallpaperController.addWallpaperToken(this); |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | void setExiting() { |
| 47 | super.setExiting(); |
| 48 | mDisplayContent.mWallpaperController.removeWallpaperToken(this); |
| 49 | } |
| 50 | |
| 51 | void hideWallpaperToken(boolean wasDeferred, String reason) { |
| 52 | for (int j = mChildren.size() - 1; j >= 0; j--) { |
| 53 | final WindowState wallpaper = mChildren.get(j); |
| 54 | wallpaper.hideWallpaperWindow(wasDeferred, reason); |
| 55 | } |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame^] | 56 | setHidden(true); |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | void sendWindowWallpaperCommand( |
| 60 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 61 | for (int wallpaperNdx = mChildren.size() - 1; wallpaperNdx >= 0; wallpaperNdx--) { |
| 62 | final WindowState wallpaper = mChildren.get(wallpaperNdx); |
| 63 | try { |
| 64 | wallpaper.mClient.dispatchWallpaperCommand(action, x, y, z, extras, sync); |
| 65 | // We only want to be synchronous with one wallpaper. |
| 66 | sync = false; |
| 67 | } catch (RemoteException e) { |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | void updateWallpaperOffset(int dw, int dh, boolean sync) { |
| 73 | final WallpaperController wallpaperController = mDisplayContent.mWallpaperController; |
| 74 | for (int wallpaperNdx = mChildren.size() - 1; wallpaperNdx >= 0; wallpaperNdx--) { |
| 75 | final WindowState wallpaper = mChildren.get(wallpaperNdx); |
| 76 | if (wallpaperController.updateWallpaperOffset(wallpaper, dw, dh, sync)) { |
| 77 | final WindowStateAnimator winAnimator = wallpaper.mWinAnimator; |
| 78 | winAnimator.computeShownFrameLocked(); |
| 79 | // No need to lay out the windows - we can just set the wallpaper position directly. |
| 80 | winAnimator.setWallpaperOffset(wallpaper.mShownPosition); |
| 81 | // We only want to be synchronous with one wallpaper. |
| 82 | sync = false; |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | void updateWallpaperVisibility(boolean visible) { |
| 88 | final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo(); |
| 89 | final int dw = displayInfo.logicalWidth; |
| 90 | final int dh = displayInfo.logicalHeight; |
| 91 | |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame^] | 92 | if (isHidden() == visible) { |
| 93 | setHidden(!visible); |
| 94 | |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 95 | // Need to do a layout to ensure the wallpaper now has the correct size. |
| 96 | mDisplayContent.setLayoutNeeded(); |
| 97 | } |
| 98 | |
| 99 | final WallpaperController wallpaperController = mDisplayContent.mWallpaperController; |
| 100 | for (int wallpaperNdx = mChildren.size() - 1; wallpaperNdx >= 0; wallpaperNdx--) { |
| 101 | final WindowState wallpaper = mChildren.get(wallpaperNdx); |
| 102 | if (visible) { |
| 103 | wallpaperController.updateWallpaperOffset(wallpaper, dw, dh, false); |
| 104 | } |
| 105 | |
| 106 | wallpaper.dispatchWallpaperVisibility(visible); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Starts {@param anim} on all children. |
| 112 | */ |
| 113 | void startAnimation(Animation anim) { |
| 114 | for (int ndx = mChildren.size() - 1; ndx >= 0; ndx--) { |
| 115 | final WindowState windowState = mChildren.get(ndx); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 116 | windowState.startAnimation(anim); |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 120 | void updateWallpaperWindows(boolean visible, int animLayerAdj) { |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 121 | |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame^] | 122 | if (isHidden() == visible) { |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 123 | if (DEBUG_WALLPAPER_LIGHT) Slog.d(TAG, |
| 124 | "Wallpaper token " + token + " hidden=" + !visible); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame^] | 125 | setHidden(!visible); |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 126 | // Need to do a layout to ensure the wallpaper now has the correct size. |
| 127 | mDisplayContent.setLayoutNeeded(); |
| 128 | } |
| 129 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 130 | final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo(); |
| 131 | final int dw = displayInfo.logicalWidth; |
| 132 | final int dh = displayInfo.logicalHeight; |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 133 | final WallpaperController wallpaperController = mDisplayContent.mWallpaperController; |
| 134 | for (int wallpaperNdx = mChildren.size() - 1; wallpaperNdx >= 0; wallpaperNdx--) { |
| 135 | final WindowState wallpaper = mChildren.get(wallpaperNdx); |
| 136 | |
| 137 | if (visible) { |
| 138 | wallpaperController.updateWallpaperOffset(wallpaper, dw, dh, false); |
| 139 | } |
| 140 | |
| 141 | // First, make sure the client has the current visibility state. |
| 142 | wallpaper.dispatchWallpaperVisibility(visible); |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 143 | |
| 144 | if (DEBUG_LAYERS || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "adjustWallpaper win " |
| 145 | + wallpaper + " anim layer: " + wallpaper.mWinAnimator.mAnimLayer); |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 146 | } |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | boolean hasVisibleNotDrawnWallpaper() { |
| 150 | for (int j = mChildren.size() - 1; j >= 0; --j) { |
| 151 | final WindowState wallpaper = mChildren.get(j); |
| 152 | if (wallpaper.hasVisibleNotDrawnWallpaper()) { |
| 153 | return true; |
| 154 | } |
| 155 | } |
| 156 | return false; |
| 157 | } |
| 158 | |
| 159 | @Override |
| 160 | public String toString() { |
| 161 | if (stringName == null) { |
| 162 | StringBuilder sb = new StringBuilder(); |
| 163 | sb.append("WallpaperWindowToken{"); |
| 164 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 165 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 166 | stringName = sb.toString(); |
| 167 | } |
| 168 | return stringName; |
| 169 | } |
| 170 | } |