blob: 8fd5209e3bea54dce7b45b283a12165d9a44947d [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;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080033import java.util.ArrayList;
34
35class AppTokenList extends ArrayList<AppWindowToken> {
36}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080037
38/**
39 * Version of WindowToken that is specifically for a particular application (or
40 * really activity) that is displaying windows.
41 */
Craig Mautnere32c3072012-03-12 15:25:35 -070042class AppWindowToken extends WindowToken {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080043 // Non-null only for application tokens.
44 final IApplicationToken appToken;
45
46 // All of the windows and child windows that are included in this
47 // application token. Note this list is NOT sorted!
Craig Mautner96868332012-12-04 14:29:11 -080048 final WindowList allAppWindows = new WindowList();
Craig Mautner59431632012-04-04 11:56:44 -070049 final AppWindowAnimator mAppAnimator;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080050
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070051 final WindowAnimator mAnimator;
52
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080053 int groupId = -1;
54 boolean appFullscreen;
55 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Craig Mautner5962b122012-10-05 14:45:52 -070056 boolean showWhenLocked;
Craig Mautnera2c77052012-03-26 12:14:43 -070057
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080058 // The input dispatching timeout for this application token in nanoseconds.
59 long inputDispatchingTimeoutNanos;
60
61 // These are used for determining when all windows associated with
62 // an activity have been drawn, so they can be made visible together
63 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -070064 // initialize so that it doesn't match mTransactionSequence which is an int.
65 long lastTransactionSequence = Long.MIN_VALUE;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080066 int numInterestingWindows;
67 int numDrawnWindows;
68 boolean inPendingTransaction;
69 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -080070 // Set to true when this app creates a surface while in the middle of an animation. In that
71 // case do not clear allDrawn until the animation completes.
72 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080073
74 // Is this token going to be hidden in a little while? If so, it
75 // won't be taken into account for setting the screen orientation.
76 boolean willBeHidden;
77
78 // Is this window's surface needed? This is almost like hidden, except
79 // it will sometimes be true a little earlier: when the token has
80 // been shown, but is still waiting for its app transition to execute
81 // before making its windows shown.
82 boolean hiddenRequested;
83
84 // Have we told the window clients to hide themselves?
85 boolean clientHidden;
86
87 // Last visibility state we reported to the app token.
88 boolean reportedVisible;
89
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -070090 // Last drawn state we reported to the app token.
91 boolean reportedDrawn;
92
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080093 // Set to true when the token has been removed from the window mgr.
94 boolean removed;
95
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080096 // Information about an application starting window if displayed.
97 StartingData startingData;
98 WindowState startingWindow;
99 View startingView;
100 boolean startingDisplayed;
101 boolean startingMoved;
102 boolean firstWindowDrawn;
103
104 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700105 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800106
107 AppWindowToken(WindowManagerService _service, IApplicationToken _token) {
108 super(_service, _token.asBinder(),
109 WindowManager.LayoutParams.TYPE_APPLICATION, true);
110 appWindowToken = this;
111 appToken = _token;
112 mInputApplicationHandle = new InputApplicationHandle(this);
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700113 mAnimator = service.mAnimator;
Craig Mautner322e4032012-07-13 13:35:20 -0700114 mAppAnimator = new AppWindowAnimator(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800115 }
116
117 void sendAppVisibilityToClients() {
118 final int N = allAppWindows.size();
119 for (int i=0; i<N; i++) {
120 WindowState win = allAppWindows.get(i);
121 if (win == startingWindow && clientHidden) {
122 // Don't hide the starting window.
123 continue;
124 }
125 try {
126 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
127 "Setting visibility of " + win + ": " + (!clientHidden));
128 win.mClient.dispatchAppVisibility(!clientHidden);
129 } catch (RemoteException e) {
130 }
131 }
132 }
133
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800134 void updateReportedVisibilityLocked() {
135 if (appToken == null) {
136 return;
137 }
138
139 int numInteresting = 0;
140 int numVisible = 0;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700141 int numDrawn = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800142 boolean nowGone = true;
143
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700144 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
145 "Update reported visibility: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800146 final int N = allAppWindows.size();
147 for (int i=0; i<N; i++) {
148 WindowState win = allAppWindows.get(i);
149 if (win == startingWindow || win.mAppFreezing
150 || win.mViewVisibility != View.VISIBLE
151 || win.mAttrs.type == TYPE_APPLICATION_STARTING
152 || win.mDestroying) {
153 continue;
154 }
155 if (WindowManagerService.DEBUG_VISIBILITY) {
156 Slog.v(WindowManagerService.TAG, "Win " + win + ": isDrawn="
157 + win.isDrawnLw()
Craig Mautnera2c77052012-03-26 12:14:43 -0700158 + ", isAnimating=" + win.mWinAnimator.isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800159 if (!win.isDrawnLw()) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700160 Slog.v(WindowManagerService.TAG, "Not displayed: s=" + win.mWinAnimator.mSurface
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800161 + " pv=" + win.mPolicyVisibility
Craig Mautner749a7bb2012-04-02 13:49:53 -0700162 + " mDrawState=" + win.mWinAnimator.mDrawState
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800163 + " ah=" + win.mAttachedHidden
164 + " th="
165 + (win.mAppToken != null
166 ? win.mAppToken.hiddenRequested : false)
Craig Mautnera2c77052012-03-26 12:14:43 -0700167 + " a=" + win.mWinAnimator.mAnimating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800168 }
169 }
170 numInteresting++;
171 if (win.isDrawnLw()) {
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700172 numDrawn++;
Craig Mautnera2c77052012-03-26 12:14:43 -0700173 if (!win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800174 numVisible++;
175 }
176 nowGone = false;
Craig Mautnera2c77052012-03-26 12:14:43 -0700177 } else if (win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800178 nowGone = false;
179 }
180 }
181
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700182 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800183 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700184 if (!nowGone) {
185 // If the app is not yet gone, then it can only become visible/drawn.
186 if (!nowDrawn) {
187 nowDrawn = reportedDrawn;
188 }
189 if (!nowVisible) {
190 nowVisible = reportedVisible;
191 }
192 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800193 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "VIS " + this + ": interesting="
194 + numInteresting + " visible=" + numVisible);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700195 if (nowDrawn != reportedDrawn) {
196 if (nowDrawn) {
197 Message m = service.mH.obtainMessage(
198 H.REPORT_APPLICATION_TOKEN_DRAWN, this);
199 service.mH.sendMessage(m);
200 }
201 reportedDrawn = nowDrawn;
202 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800203 if (nowVisible != reportedVisible) {
204 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(
205 WindowManagerService.TAG, "Visibility changed in " + this
206 + ": vis=" + nowVisible);
207 reportedVisible = nowVisible;
208 Message m = service.mH.obtainMessage(
209 H.REPORT_APPLICATION_TOKEN_WINDOWS,
210 nowVisible ? 1 : 0,
211 nowGone ? 1 : 0,
212 this);
213 service.mH.sendMessage(m);
214 }
215 }
216
217 WindowState findMainWindow() {
218 int j = windows.size();
219 while (j > 0) {
220 j--;
221 WindowState win = windows.get(j);
222 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
223 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
224 return win;
225 }
226 }
227 return null;
228 }
229
Craig Mautner72669d12012-12-18 17:23:54 -0800230 boolean isVisible() {
231 final int N = allAppWindows.size();
Craig Mautner72669d12012-12-18 17:23:54 -0800232 for (int i=0; i<N; i++) {
233 WindowState win = allAppWindows.get(i);
234 if (!win.mAppFreezing
235 && (win.mViewVisibility == View.VISIBLE ||
236 (win.mWinAnimator.isAnimating() &&
237 !service.mAppTransition.isTransitionSet()))
238 && !win.mDestroying && win.isDrawnLw()) {
239 return true;
240 }
241 }
242 return false;
243 }
244
Craig Mautnerdbb79912012-03-01 18:59:14 -0800245 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800246 void dump(PrintWriter pw, String prefix) {
247 super.dump(pw, prefix);
248 if (appToken != null) {
249 pw.print(prefix); pw.println("app=true");
250 }
251 if (allAppWindows.size() > 0) {
252 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
253 }
254 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
255 pw.print(" appFullscreen="); pw.print(appFullscreen);
256 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
257 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
258 pw.print(" clientHidden="); pw.print(clientHidden);
259 pw.print(" willBeHidden="); pw.print(willBeHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700260 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -0700262 if (paused) {
263 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800264 }
265 if (numInterestingWindows != 0 || numDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -0700266 || allDrawn || mAppAnimator.allDrawn) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800267 pw.print(prefix); pw.print("numInterestingWindows=");
268 pw.print(numInterestingWindows);
269 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
270 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -0700271 pw.print(" allDrawn="); pw.print(allDrawn);
272 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
273 pw.println(")");
274 }
275 if (inPendingTransaction) {
276 pw.print(prefix); pw.print("inPendingTransaction=");
277 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800278 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800279 if (startingData != null || removed || firstWindowDrawn) {
280 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
281 pw.print(" removed="); pw.print(removed);
282 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
283 }
284 if (startingWindow != null || startingView != null
285 || startingDisplayed || startingMoved) {
286 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
287 pw.print(" startingView="); pw.print(startingView);
288 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
289 pw.print(" startingMoved"); pw.println(startingMoved);
290 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800291 }
292
293 @Override
294 public String toString() {
295 if (stringName == null) {
296 StringBuilder sb = new StringBuilder();
297 sb.append("AppWindowToken{");
298 sb.append(Integer.toHexString(System.identityHashCode(this)));
299 sb.append(" token="); sb.append(token); sb.append('}');
300 stringName = sb.toString();
301 }
302 return stringName;
303 }
Jeff Browne9bdb312012-04-05 15:30:10 -0700304}