blob: 2802ad7444c1b7c887a16b77a8dbcca2c53b1c9c [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 Hackbornbb4ca522012-12-03 14:09:06 -080040 // The user who owns this app window token.
41 final int userId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080042 // Non-null only for application tokens.
43 final IApplicationToken appToken;
44
45 // All of the windows and child windows that are included in this
46 // application token. Note this list is NOT sorted!
47 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
Craig Mautner59431632012-04-04 11:56:44 -070048 final AppWindowAnimator mAppAnimator;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080049
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070050 final WindowAnimator mAnimator;
51
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080052 int groupId = -1;
53 boolean appFullscreen;
54 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Craig Mautner5962b122012-10-05 14:45:52 -070055 boolean showWhenLocked;
Craig Mautnera2c77052012-03-26 12:14:43 -070056
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080057 // The input dispatching timeout for this application token in nanoseconds.
58 long inputDispatchingTimeoutNanos;
59
60 // These are used for determining when all windows associated with
61 // an activity have been drawn, so they can be made visible together
62 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -070063 // initialize so that it doesn't match mTransactionSequence which is an int.
64 long lastTransactionSequence = Long.MIN_VALUE;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080065 int numInterestingWindows;
66 int numDrawnWindows;
67 boolean inPendingTransaction;
68 boolean allDrawn;
69
70 // Is this token going to be hidden in a little while? If so, it
71 // won't be taken into account for setting the screen orientation.
72 boolean willBeHidden;
73
74 // Is this window's surface needed? This is almost like hidden, except
75 // it will sometimes be true a little earlier: when the token has
76 // been shown, but is still waiting for its app transition to execute
77 // before making its windows shown.
78 boolean hiddenRequested;
79
80 // Have we told the window clients to hide themselves?
81 boolean clientHidden;
82
83 // Last visibility state we reported to the app token.
84 boolean reportedVisible;
85
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -070086 // Last drawn state we reported to the app token.
87 boolean reportedDrawn;
88
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080089 // Set to true when the token has been removed from the window mgr.
90 boolean removed;
91
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080092 // Information about an application starting window if displayed.
93 StartingData startingData;
94 WindowState startingWindow;
95 View startingView;
96 boolean startingDisplayed;
97 boolean startingMoved;
98 boolean firstWindowDrawn;
99
100 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700101 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800102
Dianne Hackbornbb4ca522012-12-03 14:09:06 -0800103 AppWindowToken(WindowManagerService _service, int _userId, IApplicationToken _token) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800104 super(_service, _token.asBinder(),
105 WindowManager.LayoutParams.TYPE_APPLICATION, true);
Dianne Hackbornbb4ca522012-12-03 14:09:06 -0800106 userId = _userId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800107 appWindowToken = this;
108 appToken = _token;
109 mInputApplicationHandle = new InputApplicationHandle(this);
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700110 mAnimator = service.mAnimator;
Craig Mautner322e4032012-07-13 13:35:20 -0700111 mAppAnimator = new AppWindowAnimator(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800112 }
113
114 void sendAppVisibilityToClients() {
115 final int N = allAppWindows.size();
116 for (int i=0; i<N; i++) {
117 WindowState win = allAppWindows.get(i);
118 if (win == startingWindow && clientHidden) {
119 // Don't hide the starting window.
120 continue;
121 }
122 try {
123 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
124 "Setting visibility of " + win + ": " + (!clientHidden));
125 win.mClient.dispatchAppVisibility(!clientHidden);
126 } catch (RemoteException e) {
127 }
128 }
129 }
130
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800131 void updateReportedVisibilityLocked() {
132 if (appToken == null) {
133 return;
134 }
135
136 int numInteresting = 0;
137 int numVisible = 0;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700138 int numDrawn = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800139 boolean nowGone = true;
140
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700141 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
142 "Update reported visibility: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800143 final int N = allAppWindows.size();
144 for (int i=0; i<N; i++) {
145 WindowState win = allAppWindows.get(i);
146 if (win == startingWindow || win.mAppFreezing
147 || win.mViewVisibility != View.VISIBLE
148 || win.mAttrs.type == TYPE_APPLICATION_STARTING
149 || win.mDestroying) {
150 continue;
151 }
152 if (WindowManagerService.DEBUG_VISIBILITY) {
153 Slog.v(WindowManagerService.TAG, "Win " + win + ": isDrawn="
154 + win.isDrawnLw()
Craig Mautnera2c77052012-03-26 12:14:43 -0700155 + ", isAnimating=" + win.mWinAnimator.isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800156 if (!win.isDrawnLw()) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700157 Slog.v(WindowManagerService.TAG, "Not displayed: s=" + win.mWinAnimator.mSurface
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800158 + " pv=" + win.mPolicyVisibility
Craig Mautner749a7bb2012-04-02 13:49:53 -0700159 + " mDrawState=" + win.mWinAnimator.mDrawState
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800160 + " ah=" + win.mAttachedHidden
161 + " th="
162 + (win.mAppToken != null
163 ? win.mAppToken.hiddenRequested : false)
Craig Mautnera2c77052012-03-26 12:14:43 -0700164 + " a=" + win.mWinAnimator.mAnimating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800165 }
166 }
167 numInteresting++;
168 if (win.isDrawnLw()) {
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700169 numDrawn++;
Craig Mautnera2c77052012-03-26 12:14:43 -0700170 if (!win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800171 numVisible++;
172 }
173 nowGone = false;
Craig Mautnera2c77052012-03-26 12:14:43 -0700174 } else if (win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800175 nowGone = false;
176 }
177 }
178
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700179 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800180 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700181 if (!nowGone) {
182 // If the app is not yet gone, then it can only become visible/drawn.
183 if (!nowDrawn) {
184 nowDrawn = reportedDrawn;
185 }
186 if (!nowVisible) {
187 nowVisible = reportedVisible;
188 }
189 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800190 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "VIS " + this + ": interesting="
191 + numInteresting + " visible=" + numVisible);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700192 if (nowDrawn != reportedDrawn) {
193 if (nowDrawn) {
194 Message m = service.mH.obtainMessage(
195 H.REPORT_APPLICATION_TOKEN_DRAWN, this);
196 service.mH.sendMessage(m);
197 }
198 reportedDrawn = nowDrawn;
199 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800200 if (nowVisible != reportedVisible) {
201 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(
202 WindowManagerService.TAG, "Visibility changed in " + this
203 + ": vis=" + nowVisible);
204 reportedVisible = nowVisible;
205 Message m = service.mH.obtainMessage(
206 H.REPORT_APPLICATION_TOKEN_WINDOWS,
207 nowVisible ? 1 : 0,
208 nowGone ? 1 : 0,
209 this);
210 service.mH.sendMessage(m);
211 }
212 }
213
214 WindowState findMainWindow() {
215 int j = windows.size();
216 while (j > 0) {
217 j--;
218 WindowState win = windows.get(j);
219 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
220 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
221 return win;
222 }
223 }
224 return null;
225 }
226
Craig Mautnerdbb79912012-03-01 18:59:14 -0800227 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800228 void dump(PrintWriter pw, String prefix) {
229 super.dump(pw, prefix);
230 if (appToken != null) {
Dianne Hackbornbb4ca522012-12-03 14:09:06 -0800231 pw.print(prefix); pw.print("app=true");
232 pw.print(" userId="); pw.println(userId);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800233 }
234 if (allAppWindows.size() > 0) {
235 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
236 }
237 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
238 pw.print(" appFullscreen="); pw.print(appFullscreen);
239 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
240 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
241 pw.print(" clientHidden="); pw.print(clientHidden);
242 pw.print(" willBeHidden="); pw.print(willBeHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700243 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800244 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -0700245 if (paused) {
246 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800247 }
248 if (numInterestingWindows != 0 || numDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -0700249 || allDrawn || mAppAnimator.allDrawn) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800250 pw.print(prefix); pw.print("numInterestingWindows=");
251 pw.print(numInterestingWindows);
252 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
253 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -0700254 pw.print(" allDrawn="); pw.print(allDrawn);
255 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
256 pw.println(")");
257 }
258 if (inPendingTransaction) {
259 pw.print(prefix); pw.print("inPendingTransaction=");
260 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800262 if (startingData != null || removed || firstWindowDrawn) {
263 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
264 pw.print(" removed="); pw.print(removed);
265 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
266 }
267 if (startingWindow != null || startingView != null
268 || startingDisplayed || startingMoved) {
269 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
270 pw.print(" startingView="); pw.print(startingView);
271 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
272 pw.print(" startingMoved"); pw.println(startingMoved);
273 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800274 }
275
276 @Override
277 public String toString() {
278 if (stringName == null) {
279 StringBuilder sb = new StringBuilder();
280 sb.append("AppWindowToken{");
281 sb.append(Integer.toHexString(System.identityHashCode(this)));
282 sb.append(" token="); sb.append(token); sb.append('}');
283 stringName = sb.toString();
284 }
285 return stringName;
286 }
Jeff Browne9bdb312012-04-05 15:30:10 -0700287}