blob: 2ae5c7bd9c254f6c45207dcacc6d1935ba411124 [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)) {
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 Jaggif5f9e122017-10-24 18:21:09 +020092 if (isHidden() == visible) {
93 setHidden(!visible);
94
Jorim Jaggi879ff722016-11-04 18:08:17 -070095 // 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 Jaggia5e10572017-11-15 14:36:26 +0100116 windowState.startAnimation(anim);
Jorim Jaggi879ff722016-11-04 18:08:17 -0700117 }
118 }
119
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000120 void updateWallpaperWindows(boolean visible) {
Jorim Jaggi879ff722016-11-04 18:08:17 -0700121
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200122 if (isHidden() == visible) {
Jorim Jaggi879ff722016-11-04 18:08:17 -0700123 if (DEBUG_WALLPAPER_LIGHT) Slog.d(TAG,
124 "Wallpaper token " + token + " hidden=" + !visible);
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200125 setHidden(!visible);
Jorim Jaggi879ff722016-11-04 18:08:17 -0700126 // Need to do a layout to ensure the wallpaper now has the correct size.
127 mDisplayContent.setLayoutNeeded();
128 }
129
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800130 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
131 final int dw = displayInfo.logicalWidth;
132 final int dh = displayInfo.logicalHeight;
Jorim Jaggi879ff722016-11-04 18:08:17 -0700133 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 Jaggi879ff722016-11-04 18:08:17 -0700143
144 if (DEBUG_LAYERS || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "adjustWallpaper win "
145 + wallpaper + " anim layer: " + wallpaper.mWinAnimator.mAnimLayer);
Jorim Jaggi879ff722016-11-04 18:08:17 -0700146 }
Jorim Jaggi879ff722016-11-04 18:08:17 -0700147 }
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}