blob: ddda027595da4b5a816a2e3d33f5631dc95fef35 [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;
Jorim Jaggi879ff722016-11-04 18:08:17 -070020import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
21import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Jorim Jaggi879ff722016-11-04 18:08:17 -070022import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
23import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
24
25import android.os.Bundle;
26import android.os.IBinder;
27import android.os.RemoteException;
28import android.util.Slog;
29import android.view.DisplayInfo;
30import android.view.animation.Animation;
31
32/**
33 * A token that represents a set of wallpaper windows.
34 */
35class 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 Ogunwale5cd907d2017-01-26 14:14:08 -080040 DisplayContent dc, boolean ownerCanManageAppTokens) {
41 super(service, token, TYPE_WALLPAPER, explicit, dc, ownerCanManageAppTokens);
Jorim Jaggi879ff722016-11-04 18:08:17 -070042 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 Jaggif5f9e122017-10-24 18:21:09 +020056 setHidden(true);
Jorim Jaggi879ff722016-11-04 18:08:17 -070057 }
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)) {
Jorim Jaggi879ff722016-11-04 18:08:17 -070077 // We only want to be synchronous with one wallpaper.
78 sync = false;
79 }
80 }
81 }
82
83 void updateWallpaperVisibility(boolean visible) {
84 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
85 final int dw = displayInfo.logicalWidth;
86 final int dh = displayInfo.logicalHeight;
87
Jorim Jaggif5f9e122017-10-24 18:21:09 +020088 if (isHidden() == visible) {
89 setHidden(!visible);
90
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
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200118 if (isHidden() == visible) {
Jorim Jaggi879ff722016-11-04 18:08:17 -0700119 if (DEBUG_WALLPAPER_LIGHT) Slog.d(TAG,
120 "Wallpaper token " + token + " hidden=" + !visible);
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200121 setHidden(!visible);
Jorim Jaggi879ff722016-11-04 18:08:17 -0700122 // Need to do a layout to ensure the wallpaper now has the correct size.
123 mDisplayContent.setLayoutNeeded();
124 }
125
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800126 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
127 final int dw = displayInfo.logicalWidth;
128 final int dh = displayInfo.logicalHeight;
Jorim Jaggi879ff722016-11-04 18:08:17 -0700129 final WallpaperController wallpaperController = mDisplayContent.mWallpaperController;
130 for (int wallpaperNdx = mChildren.size() - 1; wallpaperNdx >= 0; wallpaperNdx--) {
131 final WindowState wallpaper = mChildren.get(wallpaperNdx);
132
133 if (visible) {
134 wallpaperController.updateWallpaperOffset(wallpaper, dw, dh, false);
135 }
136
137 // First, make sure the client has the current visibility state.
138 wallpaper.dispatchWallpaperVisibility(visible);
Jorim Jaggi879ff722016-11-04 18:08:17 -0700139
140 if (DEBUG_LAYERS || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "adjustWallpaper win "
141 + wallpaper + " anim layer: " + wallpaper.mWinAnimator.mAnimLayer);
Jorim Jaggi879ff722016-11-04 18:08:17 -0700142 }
Jorim Jaggi879ff722016-11-04 18:08:17 -0700143 }
144
145 boolean hasVisibleNotDrawnWallpaper() {
146 for (int j = mChildren.size() - 1; j >= 0; --j) {
147 final WindowState wallpaper = mChildren.get(j);
148 if (wallpaper.hasVisibleNotDrawnWallpaper()) {
149 return true;
150 }
151 }
152 return false;
153 }
154
155 @Override
156 public String toString() {
157 if (stringName == null) {
158 StringBuilder sb = new StringBuilder();
159 sb.append("WallpaperWindowToken{");
160 sb.append(Integer.toHexString(System.identityHashCode(this)));
161 sb.append(" token="); sb.append(token); sb.append('}');
162 stringName = sb.toString();
163 }
164 return stringName;
165 }
166}