blob: 6ee2c3952f2d34d8d9b3a1783f737dee21580189 [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
Craig Mautner83162a92015-01-26 14:43:30 -080055 Task mTask;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080056 boolean appFullscreen;
57 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Craig Mautner4c5eb222013-11-18 12:59:05 -080058 boolean layoutConfigChanges;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070059 boolean showForAllUsers;
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 Mautner799bc1d2015-01-14 10:33:48 -0800110 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800111
Craig Mautnerbb742462014-07-07 15:28:55 -0700112 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700113 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700114
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -0700115 // This application will have its window replaced due to relaunch. This allows window manager
116 // to differentiate between simple removal of a window and replacement. In the latter case it
117 // will preserve the old window until the new one is drawn.
118 boolean mReplacingWindow;
119
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700120 AppWindowToken(WindowManagerService _service, IApplicationToken _token,
121 boolean _voiceInteraction) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800122 super(_service, _token.asBinder(),
123 WindowManager.LayoutParams.TYPE_APPLICATION, true);
124 appWindowToken = this;
125 appToken = _token;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700126 voiceInteraction = _voiceInteraction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800127 mInputApplicationHandle = new InputApplicationHandle(this);
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700128 mAnimator = service.mAnimator;
Craig Mautner322e4032012-07-13 13:35:20 -0700129 mAppAnimator = new AppWindowAnimator(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800130 }
131
132 void sendAppVisibilityToClients() {
133 final int N = allAppWindows.size();
134 for (int i=0; i<N; i++) {
135 WindowState win = allAppWindows.get(i);
136 if (win == startingWindow && clientHidden) {
137 // Don't hide the starting window.
138 continue;
139 }
140 try {
141 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
142 "Setting visibility of " + win + ": " + (!clientHidden));
143 win.mClient.dispatchAppVisibility(!clientHidden);
144 } catch (RemoteException e) {
145 }
146 }
147 }
148
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800149 void updateReportedVisibilityLocked() {
150 if (appToken == null) {
151 return;
152 }
153
154 int numInteresting = 0;
155 int numVisible = 0;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700156 int numDrawn = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800157 boolean nowGone = true;
158
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700159 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
160 "Update reported visibility: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800161 final int N = allAppWindows.size();
162 for (int i=0; i<N; i++) {
163 WindowState win = allAppWindows.get(i);
164 if (win == startingWindow || win.mAppFreezing
165 || win.mViewVisibility != View.VISIBLE
166 || win.mAttrs.type == TYPE_APPLICATION_STARTING
167 || win.mDestroying) {
168 continue;
169 }
170 if (WindowManagerService.DEBUG_VISIBILITY) {
171 Slog.v(WindowManagerService.TAG, "Win " + win + ": isDrawn="
172 + win.isDrawnLw()
Craig Mautnera2c77052012-03-26 12:14:43 -0700173 + ", isAnimating=" + win.mWinAnimator.isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800174 if (!win.isDrawnLw()) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800175 Slog.v(WindowManagerService.TAG, "Not displayed: s=" + win.mWinAnimator.mSurfaceControl
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800176 + " pv=" + win.mPolicyVisibility
Craig Mautner749a7bb2012-04-02 13:49:53 -0700177 + " mDrawState=" + win.mWinAnimator.mDrawState
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800178 + " ah=" + win.mAttachedHidden
179 + " th="
180 + (win.mAppToken != null
181 ? win.mAppToken.hiddenRequested : false)
Craig Mautnera2c77052012-03-26 12:14:43 -0700182 + " a=" + win.mWinAnimator.mAnimating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800183 }
184 }
185 numInteresting++;
186 if (win.isDrawnLw()) {
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700187 numDrawn++;
Craig Mautnera2c77052012-03-26 12:14:43 -0700188 if (!win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800189 numVisible++;
190 }
191 nowGone = false;
Craig Mautnera2c77052012-03-26 12:14:43 -0700192 } else if (win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800193 nowGone = false;
194 }
195 }
196
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700197 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800198 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700199 if (!nowGone) {
200 // If the app is not yet gone, then it can only become visible/drawn.
201 if (!nowDrawn) {
202 nowDrawn = reportedDrawn;
203 }
204 if (!nowVisible) {
205 nowVisible = reportedVisible;
206 }
207 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800208 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "VIS " + this + ": interesting="
209 + numInteresting + " visible=" + numVisible);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700210 if (nowDrawn != reportedDrawn) {
211 if (nowDrawn) {
212 Message m = service.mH.obtainMessage(
213 H.REPORT_APPLICATION_TOKEN_DRAWN, this);
214 service.mH.sendMessage(m);
215 }
216 reportedDrawn = nowDrawn;
217 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800218 if (nowVisible != reportedVisible) {
219 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(
220 WindowManagerService.TAG, "Visibility changed in " + this
221 + ": vis=" + nowVisible);
222 reportedVisible = nowVisible;
223 Message m = service.mH.obtainMessage(
224 H.REPORT_APPLICATION_TOKEN_WINDOWS,
225 nowVisible ? 1 : 0,
226 nowGone ? 1 : 0,
227 this);
228 service.mH.sendMessage(m);
229 }
230 }
231
232 WindowState findMainWindow() {
233 int j = windows.size();
234 while (j > 0) {
235 j--;
236 WindowState win = windows.get(j);
237 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
238 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
239 return win;
240 }
241 }
242 return null;
243 }
244
Craig Mautner72669d12012-12-18 17:23:54 -0800245 boolean isVisible() {
246 final int N = allAppWindows.size();
Craig Mautner72669d12012-12-18 17:23:54 -0800247 for (int i=0; i<N; i++) {
248 WindowState win = allAppWindows.get(i);
249 if (!win.mAppFreezing
250 && (win.mViewVisibility == View.VISIBLE ||
251 (win.mWinAnimator.isAnimating() &&
252 !service.mAppTransition.isTransitionSet()))
253 && !win.mDestroying && win.isDrawnLw()) {
254 return true;
255 }
256 }
257 return false;
258 }
259
Craig Mautnere3119b72015-01-20 15:02:36 -0800260 void removeAppFromTaskLocked() {
261 mIsExiting = false;
262 removeAllWindows();
263
Craig Mautner83162a92015-01-26 14:43:30 -0800264 // Use local variable because removeAppToken will null out mTask.
265 final Task task = mTask;
Craig Mautnere3119b72015-01-20 15:02:36 -0800266 if (task != null) {
267 if (!task.removeAppToken(this)) {
268 Slog.e(WindowManagerService.TAG, "removeAppFromTaskLocked: token=" + this
269 + " not found.");
270 }
271 task.mStack.mExitingAppTokens.remove(this);
272 }
273 }
274
Wale Ogunwale98e70d02014-11-10 12:12:27 -0800275 @Override
Craig Mautner7c9ee192014-08-14 16:08:26 -0700276 void removeAllWindows() {
Craig Mautner7b4655d2014-11-20 12:13:22 -0800277 for (int winNdx = allAppWindows.size() - 1; winNdx >= 0;
278 // removeWindowLocked at bottom of loop may remove multiple entries from
279 // allAppWindows if the window to be removed has child windows. It also may
280 // not remove any windows from allAppWindows at all if win is exiting and
281 // currently animating away. This ensures that winNdx is monotonically decreasing
282 // and never beyond allAppWindows bounds.
283 winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) {
284 WindowState win = allAppWindows.get(winNdx);
Wale Ogunwale98e70d02014-11-10 12:12:27 -0800285 if (WindowManagerService.DEBUG_WINDOW_MOVEMENT) {
286 Slog.w(WindowManagerService.TAG, "removeAllWindows: removing win=" + win);
287 }
288
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -0700289 service.removeWindowLocked(win);
Craig Mautner7c9ee192014-08-14 16:08:26 -0700290 }
Craig Mautnere3119b72015-01-20 15:02:36 -0800291 allAppWindows.clear();
292 windows.clear();
Craig Mautner7c9ee192014-08-14 16:08:26 -0700293 }
294
Craig Mautnerdbb79912012-03-01 18:59:14 -0800295 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800296 void dump(PrintWriter pw, String prefix) {
297 super.dump(pw, prefix);
298 if (appToken != null) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700299 pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800300 }
301 if (allAppWindows.size() > 0) {
302 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
303 }
Craig Mautner83162a92015-01-26 14:43:30 -0800304 pw.print(prefix); pw.print("task="); pw.println(mTask);
305 pw.print(prefix); pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800306 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
307 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
308 pw.print(" clientHidden="); pw.print(clientHidden);
309 pw.print(" willBeHidden="); pw.print(willBeHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700310 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800311 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -0700312 if (paused) {
313 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800314 }
315 if (numInterestingWindows != 0 || numDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -0700316 || allDrawn || mAppAnimator.allDrawn) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800317 pw.print(prefix); pw.print("numInterestingWindows=");
318 pw.print(numInterestingWindows);
319 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
320 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -0700321 pw.print(" allDrawn="); pw.print(allDrawn);
322 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
323 pw.println(")");
324 }
325 if (inPendingTransaction) {
326 pw.print(prefix); pw.print("inPendingTransaction=");
327 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800328 }
Craig Mautner799bc1d2015-01-14 10:33:48 -0800329 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800330 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
331 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -0800332 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -0800333 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800334 }
335 if (startingWindow != null || startingView != null
336 || startingDisplayed || startingMoved) {
337 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
338 pw.print(" startingView="); pw.print(startingView);
339 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
340 pw.print(" startingMoved"); pw.println(startingMoved);
341 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800342 }
343
344 @Override
345 public String toString() {
346 if (stringName == null) {
347 StringBuilder sb = new StringBuilder();
348 sb.append("AppWindowToken{");
349 sb.append(Integer.toHexString(System.identityHashCode(this)));
350 sb.append(" token="); sb.append(token); sb.append('}');
351 stringName = sb.toString();
352 }
353 return stringName;
354 }
Jeff Browne9bdb312012-04-05 15:30:10 -0700355}