blob: 3ec6d26e98f0b9ed14aea44faf2493f5ee92c6f4 [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 Mautner5962b122012-10-05 14:45:52 -070053 boolean showWhenLocked;
Craig Mautnera2c77052012-03-26 12:14:43 -070054
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080055 // The input dispatching timeout for this application token in nanoseconds.
56 long inputDispatchingTimeoutNanos;
57
58 // These are used for determining when all windows associated with
59 // an activity have been drawn, so they can be made visible together
60 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -070061 // initialize so that it doesn't match mTransactionSequence which is an int.
62 long lastTransactionSequence = Long.MIN_VALUE;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080063 int numInterestingWindows;
64 int numDrawnWindows;
65 boolean inPendingTransaction;
66 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -080067 // Set to true when this app creates a surface while in the middle of an animation. In that
68 // case do not clear allDrawn until the animation completes.
69 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080070
71 // Is this token going to be hidden in a little while? If so, it
72 // won't be taken into account for setting the screen orientation.
73 boolean willBeHidden;
74
75 // Is this window's surface needed? This is almost like hidden, except
76 // it will sometimes be true a little earlier: when the token has
77 // been shown, but is still waiting for its app transition to execute
78 // before making its windows shown.
79 boolean hiddenRequested;
80
81 // Have we told the window clients to hide themselves?
82 boolean clientHidden;
83
84 // Last visibility state we reported to the app token.
85 boolean reportedVisible;
86
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -070087 // Last drawn state we reported to the app token.
88 boolean reportedDrawn;
89
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080090 // Set to true when the token has been removed from the window mgr.
91 boolean removed;
92
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080093 // Information about an application starting window if displayed.
94 StartingData startingData;
95 WindowState startingWindow;
96 View startingView;
97 boolean startingDisplayed;
98 boolean startingMoved;
99 boolean firstWindowDrawn;
100
101 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700102 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800103
104 AppWindowToken(WindowManagerService _service, IApplicationToken _token) {
105 super(_service, _token.asBinder(),
106 WindowManager.LayoutParams.TYPE_APPLICATION, true);
107 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) {
231 pw.print(prefix); pw.println("app=true");
232 }
233 if (allAppWindows.size() > 0) {
234 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
235 }
236 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
237 pw.print(" appFullscreen="); pw.print(appFullscreen);
238 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
239 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
240 pw.print(" clientHidden="); pw.print(clientHidden);
241 pw.print(" willBeHidden="); pw.print(willBeHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700242 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800243 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -0700244 if (paused) {
245 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800246 }
247 if (numInterestingWindows != 0 || numDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -0700248 || allDrawn || mAppAnimator.allDrawn) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800249 pw.print(prefix); pw.print("numInterestingWindows=");
250 pw.print(numInterestingWindows);
251 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
252 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -0700253 pw.print(" allDrawn="); pw.print(allDrawn);
254 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
255 pw.println(")");
256 }
257 if (inPendingTransaction) {
258 pw.print(prefix); pw.print("inPendingTransaction=");
259 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800260 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261 if (startingData != null || removed || firstWindowDrawn) {
262 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
263 pw.print(" removed="); pw.print(removed);
264 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
265 }
266 if (startingWindow != null || startingView != null
267 || startingDisplayed || startingMoved) {
268 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
269 pw.print(" startingView="); pw.print(startingView);
270 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
271 pw.print(" startingMoved"); pw.println(startingMoved);
272 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800273 }
274
275 @Override
276 public String toString() {
277 if (stringName == null) {
278 StringBuilder sb = new StringBuilder();
279 sb.append("AppWindowToken{");
280 sb.append(Integer.toHexString(System.identityHashCode(this)));
281 sb.append(" token="); sb.append(token); sb.append('}');
282 stringName = sb.toString();
283 }
284 return stringName;
285 }
Jeff Browne9bdb312012-04-05 15:30:10 -0700286}