blob: 12c15e27d3e35985b5d22ddb026d61a91ad0ea6c [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 Hackborne30e02f2014-05-27 18:24:45 -070053 final boolean voiceInteraction;
54
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080055 int groupId = -1;
56 boolean appFullscreen;
57 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Craig Mautner4c5eb222013-11-18 12:59:05 -080058 boolean layoutConfigChanges;
Craig Mautner5962b122012-10-05 14:45:52 -070059 boolean showWhenLocked;
Craig Mautnera2c77052012-03-26 12:14:43 -070060
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080061 // The input dispatching timeout for this application token in nanoseconds.
62 long inputDispatchingTimeoutNanos;
63
64 // These are used for determining when all windows associated with
65 // an activity have been drawn, so they can be made visible together
66 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -070067 // initialize so that it doesn't match mTransactionSequence which is an int.
68 long lastTransactionSequence = Long.MIN_VALUE;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080069 int numInterestingWindows;
70 int numDrawnWindows;
71 boolean inPendingTransaction;
72 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -080073 // Set to true when this app creates a surface while in the middle of an animation. In that
74 // case do not clear allDrawn until the animation completes.
75 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080076
77 // Is this token going to be hidden in a little while? If so, it
78 // won't be taken into account for setting the screen orientation.
79 boolean willBeHidden;
80
81 // Is this window's surface needed? This is almost like hidden, except
82 // it will sometimes be true a little earlier: when the token has
83 // been shown, but is still waiting for its app transition to execute
84 // before making its windows shown.
85 boolean hiddenRequested;
86
87 // Have we told the window clients to hide themselves?
88 boolean clientHidden;
89
90 // Last visibility state we reported to the app token.
91 boolean reportedVisible;
92
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -070093 // Last drawn state we reported to the app token.
94 boolean reportedDrawn;
95
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080096 // Set to true when the token has been removed from the window mgr.
97 boolean removed;
98
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080099 // Information about an application starting window if displayed.
100 StartingData startingData;
101 WindowState startingWindow;
102 View startingView;
103 boolean startingDisplayed;
104 boolean startingMoved;
105 boolean firstWindowDrawn;
106
107 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700108 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800109
Craig Mautner9ef471f2014-02-07 13:11:47 -0800110 boolean mDeferRemoval;
111
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700112 AppWindowToken(WindowManagerService _service, IApplicationToken _token,
113 boolean _voiceInteraction) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800114 super(_service, _token.asBinder(),
115 WindowManager.LayoutParams.TYPE_APPLICATION, true);
116 appWindowToken = this;
117 appToken = _token;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700118 voiceInteraction = _voiceInteraction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800119 mInputApplicationHandle = new InputApplicationHandle(this);
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700120 mAnimator = service.mAnimator;
Craig Mautner322e4032012-07-13 13:35:20 -0700121 mAppAnimator = new AppWindowAnimator(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800122 }
123
124 void sendAppVisibilityToClients() {
125 final int N = allAppWindows.size();
126 for (int i=0; i<N; i++) {
127 WindowState win = allAppWindows.get(i);
128 if (win == startingWindow && clientHidden) {
129 // Don't hide the starting window.
130 continue;
131 }
132 try {
133 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
134 "Setting visibility of " + win + ": " + (!clientHidden));
135 win.mClient.dispatchAppVisibility(!clientHidden);
136 } catch (RemoteException e) {
137 }
138 }
139 }
140
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800141 void updateReportedVisibilityLocked() {
142 if (appToken == null) {
143 return;
144 }
145
146 int numInteresting = 0;
147 int numVisible = 0;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700148 int numDrawn = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800149 boolean nowGone = true;
150
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700151 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
152 "Update reported visibility: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800153 final int N = allAppWindows.size();
154 for (int i=0; i<N; i++) {
155 WindowState win = allAppWindows.get(i);
156 if (win == startingWindow || win.mAppFreezing
157 || win.mViewVisibility != View.VISIBLE
158 || win.mAttrs.type == TYPE_APPLICATION_STARTING
159 || win.mDestroying) {
160 continue;
161 }
162 if (WindowManagerService.DEBUG_VISIBILITY) {
163 Slog.v(WindowManagerService.TAG, "Win " + win + ": isDrawn="
164 + win.isDrawnLw()
Craig Mautnera2c77052012-03-26 12:14:43 -0700165 + ", isAnimating=" + win.mWinAnimator.isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800166 if (!win.isDrawnLw()) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800167 Slog.v(WindowManagerService.TAG, "Not displayed: s=" + win.mWinAnimator.mSurfaceControl
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800168 + " pv=" + win.mPolicyVisibility
Craig Mautner749a7bb2012-04-02 13:49:53 -0700169 + " mDrawState=" + win.mWinAnimator.mDrawState
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800170 + " ah=" + win.mAttachedHidden
171 + " th="
172 + (win.mAppToken != null
173 ? win.mAppToken.hiddenRequested : false)
Craig Mautnera2c77052012-03-26 12:14:43 -0700174 + " a=" + win.mWinAnimator.mAnimating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800175 }
176 }
177 numInteresting++;
178 if (win.isDrawnLw()) {
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700179 numDrawn++;
Craig Mautnera2c77052012-03-26 12:14:43 -0700180 if (!win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800181 numVisible++;
182 }
183 nowGone = false;
Craig Mautnera2c77052012-03-26 12:14:43 -0700184 } else if (win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800185 nowGone = false;
186 }
187 }
188
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700189 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800190 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700191 if (!nowGone) {
192 // If the app is not yet gone, then it can only become visible/drawn.
193 if (!nowDrawn) {
194 nowDrawn = reportedDrawn;
195 }
196 if (!nowVisible) {
197 nowVisible = reportedVisible;
198 }
199 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800200 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "VIS " + this + ": interesting="
201 + numInteresting + " visible=" + numVisible);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700202 if (nowDrawn != reportedDrawn) {
203 if (nowDrawn) {
204 Message m = service.mH.obtainMessage(
205 H.REPORT_APPLICATION_TOKEN_DRAWN, this);
206 service.mH.sendMessage(m);
207 }
208 reportedDrawn = nowDrawn;
209 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800210 if (nowVisible != reportedVisible) {
211 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(
212 WindowManagerService.TAG, "Visibility changed in " + this
213 + ": vis=" + nowVisible);
214 reportedVisible = nowVisible;
215 Message m = service.mH.obtainMessage(
216 H.REPORT_APPLICATION_TOKEN_WINDOWS,
217 nowVisible ? 1 : 0,
218 nowGone ? 1 : 0,
219 this);
220 service.mH.sendMessage(m);
221 }
222 }
223
224 WindowState findMainWindow() {
225 int j = windows.size();
226 while (j > 0) {
227 j--;
228 WindowState win = windows.get(j);
229 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
230 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
231 return win;
232 }
233 }
234 return null;
235 }
236
Craig Mautner72669d12012-12-18 17:23:54 -0800237 boolean isVisible() {
238 final int N = allAppWindows.size();
Craig Mautner72669d12012-12-18 17:23:54 -0800239 for (int i=0; i<N; i++) {
240 WindowState win = allAppWindows.get(i);
241 if (!win.mAppFreezing
242 && (win.mViewVisibility == View.VISIBLE ||
243 (win.mWinAnimator.isAnimating() &&
244 !service.mAppTransition.isTransitionSet()))
245 && !win.mDestroying && win.isDrawnLw()) {
246 return true;
247 }
248 }
249 return false;
250 }
251
Craig Mautnerdbb79912012-03-01 18:59:14 -0800252 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800253 void dump(PrintWriter pw, String prefix) {
254 super.dump(pw, prefix);
255 if (appToken != null) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700256 pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800257 }
258 if (allAppWindows.size() > 0) {
259 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
260 }
261 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
262 pw.print(" appFullscreen="); pw.print(appFullscreen);
263 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
264 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
265 pw.print(" clientHidden="); pw.print(clientHidden);
266 pw.print(" willBeHidden="); pw.print(willBeHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700267 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800268 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -0700269 if (paused) {
270 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800271 }
272 if (numInterestingWindows != 0 || numDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -0700273 || allDrawn || mAppAnimator.allDrawn) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800274 pw.print(prefix); pw.print("numInterestingWindows=");
275 pw.print(numInterestingWindows);
276 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
277 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -0700278 pw.print(" allDrawn="); pw.print(allDrawn);
279 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
280 pw.println(")");
281 }
282 if (inPendingTransaction) {
283 pw.print(prefix); pw.print("inPendingTransaction=");
284 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800285 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800286 if (startingData != null || removed || firstWindowDrawn) {
287 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
288 pw.print(" removed="); pw.print(removed);
289 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
290 }
291 if (startingWindow != null || startingView != null
292 || startingDisplayed || startingMoved) {
293 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
294 pw.print(" startingView="); pw.print(startingView);
295 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
296 pw.print(" startingMoved"); pw.println(startingMoved);
297 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800298 }
299
300 @Override
301 public String toString() {
302 if (stringName == null) {
303 StringBuilder sb = new StringBuilder();
304 sb.append("AppWindowToken{");
305 sb.append(Integer.toHexString(System.identityHashCode(this)));
306 sb.append(" token="); sb.append(token); sb.append('}');
307 stringName = sb.toString();
308 }
309 return stringName;
310 }
Jeff Browne9bdb312012-04-05 15:30:10 -0700311}