blob: 1f8348dd9c1e847f6c5a71cdfd7f32968ec94f55 [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
Jeff Brown4532e612012-04-05 14:27:12 -070021import com.android.server.input.InputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080022import com.android.server.wm.WindowManagerService.H;
23
24import android.content.pm.ActivityInfo;
25import android.os.Message;
26import android.os.RemoteException;
27import android.util.Slog;
28import android.view.IApplicationToken;
29import android.view.View;
30import android.view.WindowManager;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080031
32import java.io.PrintWriter;
33import java.util.ArrayList;
34
35/**
36 * Version of WindowToken that is specifically for a particular application (or
37 * really activity) that is displaying windows.
38 */
Craig Mautnere32c3072012-03-12 15:25:35 -070039class AppWindowToken extends WindowToken {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080040 // Non-null only for application tokens.
41 final IApplicationToken appToken;
42
43 // All of the windows and child windows that are included in this
44 // application token. Note this list is NOT sorted!
45 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
Craig Mautner59431632012-04-04 11:56:44 -070046 final AppWindowAnimator mAppAnimator;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080047
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070048 final WindowAnimator mAnimator;
49
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080050 int groupId = -1;
51 boolean appFullscreen;
52 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Craig Mautnera2c77052012-03-26 12:14:43 -070053
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080054 // The input dispatching timeout for this application token in nanoseconds.
55 long inputDispatchingTimeoutNanos;
56
57 // These are used for determining when all windows associated with
58 // an activity have been drawn, so they can be made visible together
59 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -070060 // initialize so that it doesn't match mTransactionSequence which is an int.
61 long lastTransactionSequence = Long.MIN_VALUE;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080062 int numInterestingWindows;
63 int numDrawnWindows;
64 boolean inPendingTransaction;
65 boolean allDrawn;
66
67 // Is this token going to be hidden in a little while? If so, it
68 // won't be taken into account for setting the screen orientation.
69 boolean willBeHidden;
70
71 // Is this window's surface needed? This is almost like hidden, except
72 // it will sometimes be true a little earlier: when the token has
73 // been shown, but is still waiting for its app transition to execute
74 // before making its windows shown.
75 boolean hiddenRequested;
76
77 // Have we told the window clients to hide themselves?
78 boolean clientHidden;
79
80 // Last visibility state we reported to the app token.
81 boolean reportedVisible;
82
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -070083 // Last drawn state we reported to the app token.
84 boolean reportedDrawn;
85
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080086 // Set to true when the token has been removed from the window mgr.
87 boolean removed;
88
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080089 // Information about an application starting window if displayed.
90 StartingData startingData;
91 WindowState startingWindow;
92 View startingView;
93 boolean startingDisplayed;
94 boolean startingMoved;
95 boolean firstWindowDrawn;
96
97 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -070098 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080099
100 AppWindowToken(WindowManagerService _service, IApplicationToken _token) {
101 super(_service, _token.asBinder(),
102 WindowManager.LayoutParams.TYPE_APPLICATION, true);
103 appWindowToken = this;
104 appToken = _token;
105 mInputApplicationHandle = new InputApplicationHandle(this);
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700106 mAnimator = service.mAnimator;
Craig Mautner59431632012-04-04 11:56:44 -0700107 mAppAnimator = new AppWindowAnimator(_service, this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800108 }
109
110 void sendAppVisibilityToClients() {
111 final int N = allAppWindows.size();
112 for (int i=0; i<N; i++) {
113 WindowState win = allAppWindows.get(i);
114 if (win == startingWindow && clientHidden) {
115 // Don't hide the starting window.
116 continue;
117 }
118 try {
119 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
120 "Setting visibility of " + win + ": " + (!clientHidden));
121 win.mClient.dispatchAppVisibility(!clientHidden);
122 } catch (RemoteException e) {
123 }
124 }
125 }
126
Craig Mautner03273d02012-03-21 11:52:40 -0700127 boolean showAllWindowsLocked() {
128 boolean isAnimating = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800129 final int NW = allAppWindows.size();
130 for (int i=0; i<NW; i++) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700131 WindowStateAnimator winAnimator = allAppWindows.get(i).mWinAnimator;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800132 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700133 "performing show on: " + winAnimator);
134 winAnimator.performShowLocked();
135 isAnimating |= winAnimator.isAnimating();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800136 }
Craig Mautner03273d02012-03-21 11:52:40 -0700137 return isAnimating;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800138 }
139
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800140 void updateReportedVisibilityLocked() {
141 if (appToken == null) {
142 return;
143 }
144
145 int numInteresting = 0;
146 int numVisible = 0;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700147 int numDrawn = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800148 boolean nowGone = true;
149
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700150 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
151 "Update reported visibility: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800152 final int N = allAppWindows.size();
153 for (int i=0; i<N; i++) {
154 WindowState win = allAppWindows.get(i);
155 if (win == startingWindow || win.mAppFreezing
156 || win.mViewVisibility != View.VISIBLE
157 || win.mAttrs.type == TYPE_APPLICATION_STARTING
158 || win.mDestroying) {
159 continue;
160 }
161 if (WindowManagerService.DEBUG_VISIBILITY) {
162 Slog.v(WindowManagerService.TAG, "Win " + win + ": isDrawn="
163 + win.isDrawnLw()
Craig Mautnera2c77052012-03-26 12:14:43 -0700164 + ", isAnimating=" + win.mWinAnimator.isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800165 if (!win.isDrawnLw()) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700166 Slog.v(WindowManagerService.TAG, "Not displayed: s=" + win.mWinAnimator.mSurface
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800167 + " pv=" + win.mPolicyVisibility
Craig Mautner749a7bb2012-04-02 13:49:53 -0700168 + " mDrawState=" + win.mWinAnimator.mDrawState
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800169 + " ah=" + win.mAttachedHidden
170 + " th="
171 + (win.mAppToken != null
172 ? win.mAppToken.hiddenRequested : false)
Craig Mautnera2c77052012-03-26 12:14:43 -0700173 + " a=" + win.mWinAnimator.mAnimating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800174 }
175 }
176 numInteresting++;
177 if (win.isDrawnLw()) {
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700178 numDrawn++;
Craig Mautnera2c77052012-03-26 12:14:43 -0700179 if (!win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800180 numVisible++;
181 }
182 nowGone = false;
Craig Mautnera2c77052012-03-26 12:14:43 -0700183 } else if (win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800184 nowGone = false;
185 }
186 }
187
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700188 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800189 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700190 if (!nowGone) {
191 // If the app is not yet gone, then it can only become visible/drawn.
192 if (!nowDrawn) {
193 nowDrawn = reportedDrawn;
194 }
195 if (!nowVisible) {
196 nowVisible = reportedVisible;
197 }
198 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800199 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "VIS " + this + ": interesting="
200 + numInteresting + " visible=" + numVisible);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700201 if (nowDrawn != reportedDrawn) {
202 if (nowDrawn) {
203 Message m = service.mH.obtainMessage(
204 H.REPORT_APPLICATION_TOKEN_DRAWN, this);
205 service.mH.sendMessage(m);
206 }
207 reportedDrawn = nowDrawn;
208 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800209 if (nowVisible != reportedVisible) {
210 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(
211 WindowManagerService.TAG, "Visibility changed in " + this
212 + ": vis=" + nowVisible);
213 reportedVisible = nowVisible;
214 Message m = service.mH.obtainMessage(
215 H.REPORT_APPLICATION_TOKEN_WINDOWS,
216 nowVisible ? 1 : 0,
217 nowGone ? 1 : 0,
218 this);
219 service.mH.sendMessage(m);
220 }
221 }
222
223 WindowState findMainWindow() {
224 int j = windows.size();
225 while (j > 0) {
226 j--;
227 WindowState win = windows.get(j);
228 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
229 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
230 return win;
231 }
232 }
233 return null;
234 }
235
Craig Mautnerdbb79912012-03-01 18:59:14 -0800236 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800237 void dump(PrintWriter pw, String prefix) {
238 super.dump(pw, prefix);
239 if (appToken != null) {
240 pw.print(prefix); pw.println("app=true");
241 }
242 if (allAppWindows.size() > 0) {
243 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
244 }
245 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
246 pw.print(" appFullscreen="); pw.print(appFullscreen);
247 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
248 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
249 pw.print(" clientHidden="); pw.print(clientHidden);
250 pw.print(" willBeHidden="); pw.print(willBeHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700251 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800252 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -0700253 if (paused) {
254 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800255 }
256 if (numInterestingWindows != 0 || numDrawnWindows != 0
257 || inPendingTransaction || allDrawn) {
258 pw.print(prefix); pw.print("numInterestingWindows=");
259 pw.print(numInterestingWindows);
260 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
261 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
262 pw.print(" allDrawn="); pw.println(allDrawn);
263 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800264 if (startingData != null || removed || firstWindowDrawn) {
265 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
266 pw.print(" removed="); pw.print(removed);
267 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
268 }
269 if (startingWindow != null || startingView != null
270 || startingDisplayed || startingMoved) {
271 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
272 pw.print(" startingView="); pw.print(startingView);
273 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
274 pw.print(" startingMoved"); pw.println(startingMoved);
275 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800276 }
277
278 @Override
279 public String toString() {
280 if (stringName == null) {
281 StringBuilder sb = new StringBuilder();
282 sb.append("AppWindowToken{");
283 sb.append(Integer.toHexString(System.identityHashCode(this)));
284 sb.append(" token="); sb.append(token); sb.append('}');
285 stringName = sb.toString();
286 }
287 return stringName;
288 }
Jeff Browne9bdb312012-04-05 15:30:10 -0700289}