blob: e3d46d8de174bcf66cfd65de25fa98420cb9abc5 [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001/*
2 * Copyright (C) 2011 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
19import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
20
21import com.android.server.wm.WindowManagerService.H;
22
23import android.content.pm.ActivityInfo;
24import android.os.Message;
25import android.os.RemoteException;
26import android.util.Slog;
27import android.view.IApplicationToken;
28import android.view.View;
29import android.view.WindowManager;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080030
31import java.io.PrintWriter;
32import java.util.ArrayList;
33
34/**
35 * Version of WindowToken that is specifically for a particular application (or
36 * really activity) that is displaying windows.
37 */
Craig Mautnere32c3072012-03-12 15:25:35 -070038class AppWindowToken extends WindowToken {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080039 // Non-null only for application tokens.
40 final IApplicationToken appToken;
41
42 // All of the windows and child windows that are included in this
43 // application token. Note this list is NOT sorted!
44 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
Craig Mautner59431632012-04-04 11:56:44 -070045 final AppWindowAnimator mAppAnimator;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080046
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070047 final WindowAnimator mAnimator;
48
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080049 int groupId = -1;
50 boolean appFullscreen;
51 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Craig Mautnera2c77052012-03-26 12:14:43 -070052
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080053 // The input dispatching timeout for this application token in nanoseconds.
54 long inputDispatchingTimeoutNanos;
55
56 // These are used for determining when all windows associated with
57 // an activity have been drawn, so they can be made visible together
58 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -070059 // initialize so that it doesn't match mTransactionSequence which is an int.
60 long lastTransactionSequence = Long.MIN_VALUE;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080061 int numInterestingWindows;
62 int numDrawnWindows;
63 boolean inPendingTransaction;
64 boolean allDrawn;
65
66 // Is this token going to be hidden in a little while? If so, it
67 // won't be taken into account for setting the screen orientation.
68 boolean willBeHidden;
69
70 // Is this window's surface needed? This is almost like hidden, except
71 // it will sometimes be true a little earlier: when the token has
72 // been shown, but is still waiting for its app transition to execute
73 // before making its windows shown.
74 boolean hiddenRequested;
75
76 // Have we told the window clients to hide themselves?
77 boolean clientHidden;
78
79 // Last visibility state we reported to the app token.
80 boolean reportedVisible;
81
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -070082 // Last drawn state we reported to the app token.
83 boolean reportedDrawn;
84
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080085 // Set to true when the token has been removed from the window mgr.
86 boolean removed;
87
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080088 // Information about an application starting window if displayed.
89 StartingData startingData;
90 WindowState startingWindow;
91 View startingView;
92 boolean startingDisplayed;
93 boolean startingMoved;
94 boolean firstWindowDrawn;
95
96 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -070097 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080098
99 AppWindowToken(WindowManagerService _service, IApplicationToken _token) {
100 super(_service, _token.asBinder(),
101 WindowManager.LayoutParams.TYPE_APPLICATION, true);
102 appWindowToken = this;
103 appToken = _token;
104 mInputApplicationHandle = new InputApplicationHandle(this);
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700105 mAnimator = service.mAnimator;
Craig Mautner59431632012-04-04 11:56:44 -0700106 mAppAnimator = new AppWindowAnimator(_service, this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800107 }
108
109 void sendAppVisibilityToClients() {
110 final int N = allAppWindows.size();
111 for (int i=0; i<N; i++) {
112 WindowState win = allAppWindows.get(i);
113 if (win == startingWindow && clientHidden) {
114 // Don't hide the starting window.
115 continue;
116 }
117 try {
118 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
119 "Setting visibility of " + win + ": " + (!clientHidden));
120 win.mClient.dispatchAppVisibility(!clientHidden);
121 } catch (RemoteException e) {
122 }
123 }
124 }
125
Craig Mautner03273d02012-03-21 11:52:40 -0700126 boolean showAllWindowsLocked() {
127 boolean isAnimating = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800128 final int NW = allAppWindows.size();
129 for (int i=0; i<NW; i++) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700130 WindowStateAnimator winAnimator = allAppWindows.get(i).mWinAnimator;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800131 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700132 "performing show on: " + winAnimator);
133 winAnimator.performShowLocked();
134 isAnimating |= winAnimator.isAnimating();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800135 }
Craig Mautner03273d02012-03-21 11:52:40 -0700136 return isAnimating;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800137 }
138
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800139 void updateReportedVisibilityLocked() {
140 if (appToken == null) {
141 return;
142 }
143
144 int numInteresting = 0;
145 int numVisible = 0;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700146 int numDrawn = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800147 boolean nowGone = true;
148
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700149 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
150 "Update reported visibility: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800151 final int N = allAppWindows.size();
152 for (int i=0; i<N; i++) {
153 WindowState win = allAppWindows.get(i);
154 if (win == startingWindow || win.mAppFreezing
155 || win.mViewVisibility != View.VISIBLE
156 || win.mAttrs.type == TYPE_APPLICATION_STARTING
157 || win.mDestroying) {
158 continue;
159 }
160 if (WindowManagerService.DEBUG_VISIBILITY) {
161 Slog.v(WindowManagerService.TAG, "Win " + win + ": isDrawn="
162 + win.isDrawnLw()
Craig Mautnera2c77052012-03-26 12:14:43 -0700163 + ", isAnimating=" + win.mWinAnimator.isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800164 if (!win.isDrawnLw()) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700165 Slog.v(WindowManagerService.TAG, "Not displayed: s=" + win.mWinAnimator.mSurface
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800166 + " pv=" + win.mPolicyVisibility
Craig Mautner749a7bb2012-04-02 13:49:53 -0700167 + " mDrawState=" + win.mWinAnimator.mDrawState
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800168 + " ah=" + win.mAttachedHidden
169 + " th="
170 + (win.mAppToken != null
171 ? win.mAppToken.hiddenRequested : false)
Craig Mautnera2c77052012-03-26 12:14:43 -0700172 + " a=" + win.mWinAnimator.mAnimating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800173 }
174 }
175 numInteresting++;
176 if (win.isDrawnLw()) {
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700177 numDrawn++;
Craig Mautnera2c77052012-03-26 12:14:43 -0700178 if (!win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800179 numVisible++;
180 }
181 nowGone = false;
Craig Mautnera2c77052012-03-26 12:14:43 -0700182 } else if (win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800183 nowGone = false;
184 }
185 }
186
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700187 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800188 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700189 if (!nowGone) {
190 // If the app is not yet gone, then it can only become visible/drawn.
191 if (!nowDrawn) {
192 nowDrawn = reportedDrawn;
193 }
194 if (!nowVisible) {
195 nowVisible = reportedVisible;
196 }
197 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800198 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "VIS " + this + ": interesting="
199 + numInteresting + " visible=" + numVisible);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700200 if (nowDrawn != reportedDrawn) {
201 if (nowDrawn) {
202 Message m = service.mH.obtainMessage(
203 H.REPORT_APPLICATION_TOKEN_DRAWN, this);
204 service.mH.sendMessage(m);
205 }
206 reportedDrawn = nowDrawn;
207 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800208 if (nowVisible != reportedVisible) {
209 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(
210 WindowManagerService.TAG, "Visibility changed in " + this
211 + ": vis=" + nowVisible);
212 reportedVisible = nowVisible;
213 Message m = service.mH.obtainMessage(
214 H.REPORT_APPLICATION_TOKEN_WINDOWS,
215 nowVisible ? 1 : 0,
216 nowGone ? 1 : 0,
217 this);
218 service.mH.sendMessage(m);
219 }
220 }
221
222 WindowState findMainWindow() {
223 int j = windows.size();
224 while (j > 0) {
225 j--;
226 WindowState win = windows.get(j);
227 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
228 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
229 return win;
230 }
231 }
232 return null;
233 }
234
Craig Mautnerdbb79912012-03-01 18:59:14 -0800235 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800236 void dump(PrintWriter pw, String prefix) {
237 super.dump(pw, prefix);
238 if (appToken != null) {
239 pw.print(prefix); pw.println("app=true");
240 }
241 if (allAppWindows.size() > 0) {
242 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
243 }
244 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
245 pw.print(" appFullscreen="); pw.print(appFullscreen);
246 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
247 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
248 pw.print(" clientHidden="); pw.print(clientHidden);
249 pw.print(" willBeHidden="); pw.print(willBeHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700250 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800251 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -0700252 if (paused) {
253 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800254 }
255 if (numInterestingWindows != 0 || numDrawnWindows != 0
256 || inPendingTransaction || allDrawn) {
257 pw.print(prefix); pw.print("numInterestingWindows=");
258 pw.print(numInterestingWindows);
259 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
260 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
261 pw.print(" allDrawn="); pw.println(allDrawn);
262 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800263 if (startingData != null || removed || firstWindowDrawn) {
264 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
265 pw.print(" removed="); pw.print(removed);
266 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
267 }
268 if (startingWindow != null || startingView != null
269 || startingDisplayed || startingMoved) {
270 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
271 pw.print(" startingView="); pw.print(startingView);
272 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
273 pw.print(" startingMoved"); pw.println(startingMoved);
274 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800275 }
276
277 @Override
278 public String toString() {
279 if (stringName == null) {
280 StringBuilder sb = new StringBuilder();
281 sb.append("AppWindowToken{");
282 sb.append(Integer.toHexString(System.identityHashCode(this)));
283 sb.append(" token="); sb.append(token); sb.append('}');
284 stringName = sb.toString();
285 }
286 return stringName;
287 }
288}