blob: d23bf978cbaba023bb4d0202df6a61ed26fac160 [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 }
Jorim Jaggi879ff722016-11-04 18:08:17 -070059 }
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 Jaggi879ff722016-11-04 18:08:17 -070079 // 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 Suzukif2f6c912019-11-08 11:24:18 +010090 if (isVisible() != visible) {
Jorim Jaggi879ff722016-11-04 18:08:17 -070091 // 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 Jaggia5e10572017-11-15 14:36:26 +0100112 windowState.startAnimation(anim);
Jorim Jaggi879ff722016-11-04 18:08:17 -0700113 }
114 }
115
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000116 void updateWallpaperWindows(boolean visible) {
Jorim Jaggi879ff722016-11-04 18:08:17 -0700117
Issei Suzukif2f6c912019-11-08 11:24:18 +0100118 if (isVisible() != visible) {
Jorim Jaggi879ff722016-11-04 18:08:17 -0700119 if (DEBUG_WALLPAPER_LIGHT) Slog.d(TAG,
Issei Suzukif2f6c912019-11-08 11:24:18 +0100120 "Wallpaper token " + token + " visible=" + visible);
Jorim Jaggi879ff722016-11-04 18:08:17 -0700121 // Need to do a layout to ensure the wallpaper now has the correct size.
122 mDisplayContent.setLayoutNeeded();
123 }
124
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800125 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
126 final int dw = displayInfo.logicalWidth;
127 final int dh = displayInfo.logicalHeight;
Jorim Jaggi879ff722016-11-04 18:08:17 -0700128 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 Jaggi879ff722016-11-04 18:08:17 -0700138
139 if (DEBUG_LAYERS || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "adjustWallpaper win "
Jorim Jaggi35d328a2018-08-14 17:00:20 +0200140 + wallpaper);
Jorim Jaggi879ff722016-11-04 18:08:17 -0700141 }
Jorim Jaggi879ff722016-11-04 18:08:17 -0700142 }
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 Chungd5852192019-09-06 17:20:28 -0700155 void forAllWallpaperWindows(Consumer<WallpaperWindowToken> callback) {
156 callback.accept(this);
157 }
158
159 @Override
Jorim Jaggi879ff722016-11-04 18:08:17 -0700160 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}