blob: 528cece9a78b2637b44b267523a139456101fa12 [file] [log] [blame]
Jorim Jaggi879ff722016-11-04 18:08:17 -07001/*
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
17package com.android.server.wm;
18
Jorim Jaggi879ff722016-11-04 18:08:17 -070019import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Winson Chungd5852192019-09-06 17:20:28 -070020
Jorim Jaggi879ff722016-11-04 18:08:17 -070021import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
22import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Jorim Jaggi879ff722016-11-04 18:08:17 -070023import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
24import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
25
26import android.os.Bundle;
27import android.os.IBinder;
28import android.os.RemoteException;
29import android.util.Slog;
30import android.view.DisplayInfo;
31import android.view.animation.Animation;
32
Winson Chungd5852192019-09-06 17:20:28 -070033import java.util.function.Consumer;
34
Jorim Jaggi879ff722016-11-04 18:08:17 -070035/**
36 * A token that represents a set of wallpaper windows.
37 */
38class 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 Ogunwale5cd907d2017-01-26 14:14:08 -080043 DisplayContent dc, boolean ownerCanManageAppTokens) {
44 super(service, token, TYPE_WALLPAPER, explicit, dc, ownerCanManageAppTokens);
Jorim Jaggi879ff722016-11-04 18:08:17 -070045 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 }
Issei Suzuki7b9e2572019-11-14 16:19:54 +010059 setHidden(true);
Jorim Jaggi879ff722016-11-04 18:08:17 -070060 }
61
62 void sendWindowWallpaperCommand(
63 String action, int x, int y, int z, Bundle extras, boolean sync) {
64 for (int wallpaperNdx = mChildren.size() - 1; wallpaperNdx >= 0; wallpaperNdx--) {
65 final WindowState wallpaper = mChildren.get(wallpaperNdx);
66 try {
67 wallpaper.mClient.dispatchWallpaperCommand(action, x, y, z, extras, sync);
68 // We only want to be synchronous with one wallpaper.
69 sync = false;
70 } catch (RemoteException e) {
71 }
72 }
73 }
74
75 void updateWallpaperOffset(int dw, int dh, boolean sync) {
76 final WallpaperController wallpaperController = mDisplayContent.mWallpaperController;
77 for (int wallpaperNdx = mChildren.size() - 1; wallpaperNdx >= 0; wallpaperNdx--) {
78 final WindowState wallpaper = mChildren.get(wallpaperNdx);
79 if (wallpaperController.updateWallpaperOffset(wallpaper, dw, dh, sync)) {
Jorim Jaggi879ff722016-11-04 18:08:17 -070080 // We only want to be synchronous with one wallpaper.
81 sync = false;
82 }
83 }
84 }
85
86 void updateWallpaperVisibility(boolean visible) {
87 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
88 final int dw = displayInfo.logicalWidth;
89 final int dh = displayInfo.logicalHeight;
90
Issei Suzuki7b9e2572019-11-14 16:19:54 +010091 if (isHidden() == visible) {
92 setHidden(!visible);
93
Jorim Jaggi879ff722016-11-04 18:08:17 -070094 // Need to do a layout to ensure the wallpaper now has the correct size.
95 mDisplayContent.setLayoutNeeded();
96 }
97
98 final WallpaperController wallpaperController = mDisplayContent.mWallpaperController;
99 for (int wallpaperNdx = mChildren.size() - 1; wallpaperNdx >= 0; wallpaperNdx--) {
100 final WindowState wallpaper = mChildren.get(wallpaperNdx);
101 if (visible) {
102 wallpaperController.updateWallpaperOffset(wallpaper, dw, dh, false);
103 }
104
105 wallpaper.dispatchWallpaperVisibility(visible);
106 }
107 }
108
109 /**
110 * Starts {@param anim} on all children.
111 */
112 void startAnimation(Animation anim) {
113 for (int ndx = mChildren.size() - 1; ndx >= 0; ndx--) {
114 final WindowState windowState = mChildren.get(ndx);
Jorim Jaggia5e10572017-11-15 14:36:26 +0100115 windowState.startAnimation(anim);
Jorim Jaggi879ff722016-11-04 18:08:17 -0700116 }
117 }
118
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000119 void updateWallpaperWindows(boolean visible) {
Jorim Jaggi879ff722016-11-04 18:08:17 -0700120
Issei Suzuki7b9e2572019-11-14 16:19:54 +0100121 if (isHidden() == visible) {
Jorim Jaggi879ff722016-11-04 18:08:17 -0700122 if (DEBUG_WALLPAPER_LIGHT) Slog.d(TAG,
Issei Suzuki7b9e2572019-11-14 16:19:54 +0100123 "Wallpaper token " + token + " hidden=" + !visible);
124 setHidden(!visible);
Jorim Jaggi879ff722016-11-04 18:08:17 -0700125 // Need to do a layout to ensure the wallpaper now has the correct size.
126 mDisplayContent.setLayoutNeeded();
127 }
128
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800129 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
130 final int dw = displayInfo.logicalWidth;
131 final int dh = displayInfo.logicalHeight;
Jorim Jaggi879ff722016-11-04 18:08:17 -0700132 final WallpaperController wallpaperController = mDisplayContent.mWallpaperController;
133 for (int wallpaperNdx = mChildren.size() - 1; wallpaperNdx >= 0; wallpaperNdx--) {
134 final WindowState wallpaper = mChildren.get(wallpaperNdx);
135
136 if (visible) {
137 wallpaperController.updateWallpaperOffset(wallpaper, dw, dh, false);
138 }
139
140 // First, make sure the client has the current visibility state.
141 wallpaper.dispatchWallpaperVisibility(visible);
Jorim Jaggi879ff722016-11-04 18:08:17 -0700142
143 if (DEBUG_LAYERS || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "adjustWallpaper win "
Jorim Jaggi35d328a2018-08-14 17:00:20 +0200144 + wallpaper);
Jorim Jaggi879ff722016-11-04 18:08:17 -0700145 }
Jorim Jaggi879ff722016-11-04 18:08:17 -0700146 }
147
148 boolean hasVisibleNotDrawnWallpaper() {
149 for (int j = mChildren.size() - 1; j >= 0; --j) {
150 final WindowState wallpaper = mChildren.get(j);
151 if (wallpaper.hasVisibleNotDrawnWallpaper()) {
152 return true;
153 }
154 }
155 return false;
156 }
157
158 @Override
Winson Chungd5852192019-09-06 17:20:28 -0700159 void forAllWallpaperWindows(Consumer<WallpaperWindowToken> callback) {
160 callback.accept(this);
161 }
162
163 @Override
Jorim Jaggi879ff722016-11-04 18:08:17 -0700164 public String toString() {
165 if (stringName == null) {
166 StringBuilder sb = new StringBuilder();
167 sb.append("WallpaperWindowToken{");
168 sb.append(Integer.toHexString(System.identityHashCode(this)));
169 sb.append(" token="); sb.append(token); sb.append('}');
170 stringName = sb.toString();
171 }
172 return stringName;
173 }
174}