blob: 943e3ea736d40e101ea8df70bbdb050dc297e59c [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
Chong Zhangdb20b5f2015-10-23 14:01:43 -070055 // Whether the window has a saved surface from last pause, which can be
56 // used to start an entering animation earlier.
57 boolean mHasSavedSurface;
58
59 // Whether we're performing an entering animation with a saved surface.
60 boolean mAnimatingWithSavedSurface;
61
Craig Mautner83162a92015-01-26 14:43:30 -080062 Task mTask;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080063 boolean appFullscreen;
64 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Craig Mautner4c5eb222013-11-18 12:59:05 -080065 boolean layoutConfigChanges;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070066 boolean showForAllUsers;
Craig Mautnera2c77052012-03-26 12:14:43 -070067
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080068 // The input dispatching timeout for this application token in nanoseconds.
69 long inputDispatchingTimeoutNanos;
70
71 // These are used for determining when all windows associated with
72 // an activity have been drawn, so they can be made visible together
73 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -070074 // initialize so that it doesn't match mTransactionSequence which is an int.
75 long lastTransactionSequence = Long.MIN_VALUE;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080076 int numInterestingWindows;
77 int numDrawnWindows;
78 boolean inPendingTransaction;
79 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -080080 // Set to true when this app creates a surface while in the middle of an animation. In that
81 // case do not clear allDrawn until the animation completes.
82 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080083
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080084 // Is this window's surface needed? This is almost like hidden, except
85 // it will sometimes be true a little earlier: when the token has
86 // been shown, but is still waiting for its app transition to execute
87 // before making its windows shown.
88 boolean hiddenRequested;
89
90 // Have we told the window clients to hide themselves?
91 boolean clientHidden;
92
93 // Last visibility state we reported to the app token.
94 boolean reportedVisible;
95
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -070096 // Last drawn state we reported to the app token.
97 boolean reportedDrawn;
98
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080099 // Set to true when the token has been removed from the window mgr.
100 boolean removed;
101
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800102 // Information about an application starting window if displayed.
103 StartingData startingData;
104 WindowState startingWindow;
105 View startingView;
106 boolean startingDisplayed;
107 boolean startingMoved;
108 boolean firstWindowDrawn;
109
110 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700111 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800112
Craig Mautner799bc1d2015-01-14 10:33:48 -0800113 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800114
Craig Mautnerbb742462014-07-07 15:28:55 -0700115 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700116 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700117
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700118 // True if the windows associated with this token should be cropped to their stack bounds.
119 boolean mCropWindowsToStack;
120
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -0700121 // This application will have its window replaced due to relaunch. This allows window manager
122 // to differentiate between simple removal of a window and replacement. In the latter case it
123 // will preserve the old window until the new one is drawn.
Filip Gruszczynskib6e66622015-10-25 16:05:27 -0700124 boolean mWillReplaceWindow;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700125 // If true, the replaced window was already requested to be removed.
126 boolean mReplacingRemoveRequested;
127 // Whether the replacement of the window should trigger app transition animation.
128 boolean mAnimateReplacingWindow;
Filip Gruszczynskib6e66622015-10-25 16:05:27 -0700129 // If not null, the window that will be used to replace the old one. This is being set when
130 // the window is added and unset when this window reports its first draw.
131 WindowState mReplacingWindow;
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -0700132
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700133 AppWindowToken(WindowManagerService _service, IApplicationToken _token,
134 boolean _voiceInteraction) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800135 super(_service, _token.asBinder(),
136 WindowManager.LayoutParams.TYPE_APPLICATION, true);
137 appWindowToken = this;
138 appToken = _token;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700139 voiceInteraction = _voiceInteraction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800140 mInputApplicationHandle = new InputApplicationHandle(this);
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700141 mAnimator = service.mAnimator;
Craig Mautner322e4032012-07-13 13:35:20 -0700142 mAppAnimator = new AppWindowAnimator(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800143 }
144
145 void sendAppVisibilityToClients() {
146 final int N = allAppWindows.size();
147 for (int i=0; i<N; i++) {
148 WindowState win = allAppWindows.get(i);
149 if (win == startingWindow && clientHidden) {
150 // Don't hide the starting window.
151 continue;
152 }
153 try {
154 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
155 "Setting visibility of " + win + ": " + (!clientHidden));
156 win.mClient.dispatchAppVisibility(!clientHidden);
157 } catch (RemoteException e) {
158 }
159 }
160 }
161
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800162 void updateReportedVisibilityLocked() {
163 if (appToken == null) {
164 return;
165 }
166
167 int numInteresting = 0;
168 int numVisible = 0;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700169 int numDrawn = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800170 boolean nowGone = true;
171
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700172 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
173 "Update reported visibility: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800174 final int N = allAppWindows.size();
175 for (int i=0; i<N; i++) {
176 WindowState win = allAppWindows.get(i);
177 if (win == startingWindow || win.mAppFreezing
178 || win.mViewVisibility != View.VISIBLE
179 || win.mAttrs.type == TYPE_APPLICATION_STARTING
180 || win.mDestroying) {
181 continue;
182 }
183 if (WindowManagerService.DEBUG_VISIBILITY) {
184 Slog.v(WindowManagerService.TAG, "Win " + win + ": isDrawn="
185 + win.isDrawnLw()
Craig Mautnera2c77052012-03-26 12:14:43 -0700186 + ", isAnimating=" + win.mWinAnimator.isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800187 if (!win.isDrawnLw()) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800188 Slog.v(WindowManagerService.TAG, "Not displayed: s=" + win.mWinAnimator.mSurfaceControl
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800189 + " pv=" + win.mPolicyVisibility
Craig Mautner749a7bb2012-04-02 13:49:53 -0700190 + " mDrawState=" + win.mWinAnimator.mDrawState
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800191 + " ah=" + win.mAttachedHidden
192 + " th="
193 + (win.mAppToken != null
194 ? win.mAppToken.hiddenRequested : false)
Craig Mautnera2c77052012-03-26 12:14:43 -0700195 + " a=" + win.mWinAnimator.mAnimating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800196 }
197 }
198 numInteresting++;
199 if (win.isDrawnLw()) {
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700200 numDrawn++;
Craig Mautnera2c77052012-03-26 12:14:43 -0700201 if (!win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800202 numVisible++;
203 }
204 nowGone = false;
Craig Mautnera2c77052012-03-26 12:14:43 -0700205 } else if (win.mWinAnimator.isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800206 nowGone = false;
207 }
208 }
209
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700210 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800211 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700212 if (!nowGone) {
213 // If the app is not yet gone, then it can only become visible/drawn.
214 if (!nowDrawn) {
215 nowDrawn = reportedDrawn;
216 }
217 if (!nowVisible) {
218 nowVisible = reportedVisible;
219 }
220 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800221 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "VIS " + this + ": interesting="
222 + numInteresting + " visible=" + numVisible);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700223 if (nowDrawn != reportedDrawn) {
224 if (nowDrawn) {
225 Message m = service.mH.obtainMessage(
226 H.REPORT_APPLICATION_TOKEN_DRAWN, this);
227 service.mH.sendMessage(m);
228 }
229 reportedDrawn = nowDrawn;
230 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800231 if (nowVisible != reportedVisible) {
232 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(
233 WindowManagerService.TAG, "Visibility changed in " + this
234 + ": vis=" + nowVisible);
235 reportedVisible = nowVisible;
236 Message m = service.mH.obtainMessage(
237 H.REPORT_APPLICATION_TOKEN_WINDOWS,
238 nowVisible ? 1 : 0,
239 nowGone ? 1 : 0,
240 this);
241 service.mH.sendMessage(m);
242 }
243 }
244
245 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700246 WindowState candidate = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800247 int j = windows.size();
248 while (j > 0) {
249 j--;
250 WindowState win = windows.get(j);
251 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
252 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700253 // In cases where there are multiple windows, we prefer the non-exiting window. This
254 // happens for example when when replacing windows during an activity relaunch. When
255 // constructing the animation, we want the new window, not the exiting one.
256 if (win.mExiting) {
257 candidate = win;
258 } else {
259 return win;
260 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261 }
262 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700263 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800264 }
265
Craig Mautner72669d12012-12-18 17:23:54 -0800266 boolean isVisible() {
267 final int N = allAppWindows.size();
Craig Mautner72669d12012-12-18 17:23:54 -0800268 for (int i=0; i<N; i++) {
269 WindowState win = allAppWindows.get(i);
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700270 // If we're animating with a saved surface, we're already visible.
271 // Return true so that the alpha doesn't get cleared.
Craig Mautner72669d12012-12-18 17:23:54 -0800272 if (!win.mAppFreezing
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700273 && (win.mViewVisibility == View.VISIBLE
274 || mAnimatingWithSavedSurface
275 || (win.mWinAnimator.isAnimating() &&
276 !service.mAppTransition.isTransitionSet()))
Craig Mautner72669d12012-12-18 17:23:54 -0800277 && !win.mDestroying && win.isDrawnLw()) {
278 return true;
279 }
280 }
281 return false;
282 }
283
Craig Mautnere3119b72015-01-20 15:02:36 -0800284 void removeAppFromTaskLocked() {
285 mIsExiting = false;
286 removeAllWindows();
287
Craig Mautner83162a92015-01-26 14:43:30 -0800288 // Use local variable because removeAppToken will null out mTask.
289 final Task task = mTask;
Craig Mautnere3119b72015-01-20 15:02:36 -0800290 if (task != null) {
291 if (!task.removeAppToken(this)) {
292 Slog.e(WindowManagerService.TAG, "removeAppFromTaskLocked: token=" + this
293 + " not found.");
294 }
295 task.mStack.mExitingAppTokens.remove(this);
296 }
297 }
298
Wale Ogunwale98e70d02014-11-10 12:12:27 -0800299 @Override
Craig Mautner7c9ee192014-08-14 16:08:26 -0700300 void removeAllWindows() {
Craig Mautner7b4655d2014-11-20 12:13:22 -0800301 for (int winNdx = allAppWindows.size() - 1; winNdx >= 0;
302 // removeWindowLocked at bottom of loop may remove multiple entries from
303 // allAppWindows if the window to be removed has child windows. It also may
304 // not remove any windows from allAppWindows at all if win is exiting and
305 // currently animating away. This ensures that winNdx is monotonically decreasing
306 // and never beyond allAppWindows bounds.
307 winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) {
308 WindowState win = allAppWindows.get(winNdx);
Wale Ogunwale98e70d02014-11-10 12:12:27 -0800309 if (WindowManagerService.DEBUG_WINDOW_MOVEMENT) {
310 Slog.w(WindowManagerService.TAG, "removeAllWindows: removing win=" + win);
311 }
312
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -0700313 service.removeWindowLocked(win);
Craig Mautner7c9ee192014-08-14 16:08:26 -0700314 }
Craig Mautnere3119b72015-01-20 15:02:36 -0800315 allAppWindows.clear();
316 windows.clear();
Craig Mautner7c9ee192014-08-14 16:08:26 -0700317 }
318
Craig Mautnerdbb79912012-03-01 18:59:14 -0800319 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800320 void dump(PrintWriter pw, String prefix) {
321 super.dump(pw, prefix);
322 if (appToken != null) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700323 pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800324 }
325 if (allAppWindows.size() > 0) {
326 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
327 }
Craig Mautner83162a92015-01-26 14:43:30 -0800328 pw.print(prefix); pw.print("task="); pw.println(mTask);
329 pw.print(prefix); pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800330 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
331 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
332 pw.print(" clientHidden="); pw.print(clientHidden);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700333 pw.print(" reportedDrawn="); pw.print(reportedDrawn);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800334 pw.print(" reportedVisible="); pw.println(reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -0700335 if (paused) {
336 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800337 }
338 if (numInterestingWindows != 0 || numDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -0700339 || allDrawn || mAppAnimator.allDrawn) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800340 pw.print(prefix); pw.print("numInterestingWindows=");
341 pw.print(numInterestingWindows);
342 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
343 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -0700344 pw.print(" allDrawn="); pw.print(allDrawn);
345 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
346 pw.println(")");
347 }
348 if (inPendingTransaction) {
349 pw.print(prefix); pw.print("inPendingTransaction=");
350 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800351 }
Craig Mautner799bc1d2015-01-14 10:33:48 -0800352 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800353 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
354 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -0800355 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -0800356 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800357 }
358 if (startingWindow != null || startingView != null
359 || startingDisplayed || startingMoved) {
360 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
361 pw.print(" startingView="); pw.print(startingView);
362 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
363 pw.print(" startingMoved"); pw.println(startingMoved);
364 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800365 }
366
367 @Override
368 public String toString() {
369 if (stringName == null) {
370 StringBuilder sb = new StringBuilder();
371 sb.append("AppWindowToken{");
372 sb.append(Integer.toHexString(System.identityHashCode(this)));
373 sb.append(" token="); sb.append(token); sb.append('}');
374 stringName = sb.toString();
375 }
376 return stringName;
377 }
Jeff Browne9bdb312012-04-05 15:30:10 -0700378}