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