blob: da1585660a983d7f86accb1b692be0dab266897b [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.FIRST_SUB_WINDOW;
20import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080021import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Dianne Hackborn1c5383c2013-04-15 15:07:21 -070022import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080023import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
24import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Craig Mautnere8552142012-11-07 13:55:47 -080025import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080026import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
27
Dianne Hackbornc2293022013-02-06 23:14:49 -080028import android.app.AppOpsManager;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080029import android.os.RemoteCallbackList;
Dianne Hackborna57c6952013-03-29 14:46:40 -070030import android.util.TimeUtils;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080031import android.view.IWindowFocusObserver;
32import android.view.IWindowId;
Jeff Brown4532e612012-04-05 14:27:12 -070033import com.android.server.input.InputWindowHandle;
34
Craig Mautnere7ae2502012-03-26 17:11:19 -070035import android.content.Context;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080036import android.content.res.Configuration;
37import android.graphics.Matrix;
38import android.graphics.PixelFormat;
39import android.graphics.Rect;
Dianne Hackbornd040edb2011-08-31 12:47:58 -070040import android.graphics.RectF;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080041import android.graphics.Region;
42import android.os.IBinder;
43import android.os.RemoteException;
Craig Mautner9dc52bc2012-08-06 14:15:42 -070044import android.os.UserHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080045import android.util.Slog;
Craig Mautner59c00972012-07-30 12:10:24 -070046import android.view.DisplayInfo;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080047import android.view.Gravity;
48import android.view.IApplicationToken;
49import android.view.IWindow;
50import android.view.InputChannel;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080051import android.view.View;
52import android.view.ViewTreeObserver;
53import android.view.WindowManager;
54import android.view.WindowManagerPolicy;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080055
56import java.io.PrintWriter;
57import java.util.ArrayList;
58
Craig Mautner59c00972012-07-30 12:10:24 -070059class WindowList extends ArrayList<WindowState> {
60}
61
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080062/**
63 * A window in the window manager.
64 */
Craig Mautnere32c3072012-03-12 15:25:35 -070065final class WindowState implements WindowManagerPolicy.WindowState {
Craig Mautnerd87946b2012-03-29 18:00:19 -070066 static final String TAG = "WindowState";
Craig Mautner164d4bb2012-11-26 13:51:23 -080067
Dianne Hackborn5fd21692011-06-07 14:09:47 -070068 static final boolean DEBUG_VISIBILITY = WindowManagerService.DEBUG_VISIBILITY;
69 static final boolean SHOW_TRANSACTIONS = WindowManagerService.SHOW_TRANSACTIONS;
Dianne Hackborn36991742011-10-11 21:35:26 -070070 static final boolean SHOW_LIGHT_TRANSACTIONS = WindowManagerService.SHOW_LIGHT_TRANSACTIONS;
Dianne Hackborn5fd21692011-06-07 14:09:47 -070071 static final boolean SHOW_SURFACE_ALLOC = WindowManagerService.SHOW_SURFACE_ALLOC;
72
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080073 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -070074 final WindowManagerPolicy mPolicy;
75 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080076 final Session mSession;
77 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -080078 final int mAppOp;
79 // UserId and appId of the owner. Don't display windows of non-current user.
80 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080081 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080082 WindowToken mToken;
83 WindowToken mRootToken;
84 AppWindowToken mAppToken;
85 AppWindowToken mTargetAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070086
87 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
88 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080089 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
90 final DeathRecipient mDeathRecipient;
91 final WindowState mAttachedWindow;
Craig Mautner7b1aa772012-11-30 16:14:45 -080092 final WindowList mChildWindows = new WindowList();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080093 final int mBaseLayer;
94 final int mSubLayer;
95 final boolean mLayoutAttached;
96 final boolean mIsImWindow;
97 final boolean mIsWallpaper;
98 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -070099 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700100 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800101 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700102 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800103 boolean mPolicyVisibility = true;
104 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800105 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800106 boolean mAppFreezing;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800107 boolean mAttachedHidden; // is our parent window hidden?
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800108 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700109
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800110 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
111
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700112 /**
113 * The window size that was requested by the application. These are in
114 * the application's coordinate space (without compatibility scale applied).
115 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800116 int mRequestedWidth;
117 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700118 int mLastRequestedWidth;
119 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700120
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800121 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800122 boolean mHaveFrame;
123 boolean mObscured;
124 boolean mTurnOnScreen;
125
126 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700127
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800128 Configuration mConfiguration = null;
Craig Mautnere8552142012-11-07 13:55:47 -0800129 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
130 // Used only on {@link #TYPE_KEYGUARD}.
131 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700132
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700133 /**
134 * Actual frame shown on-screen (may be modified by animation). These
135 * are in the screen's coordinate space (WITH the compatibility scale
136 * applied).
137 */
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700138 final RectF mShownFrame = new RectF();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800139
140 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700141 * Insets that determine the actually visible area. These are in the application's
142 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800143 */
144 final Rect mVisibleInsets = new Rect();
145 final Rect mLastVisibleInsets = new Rect();
146 boolean mVisibleInsetsChanged;
147
148 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700149 * Insets that are covered by system windows (such as the status bar) and
150 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700151 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800152 */
153 final Rect mContentInsets = new Rect();
154 final Rect mLastContentInsets = new Rect();
155 boolean mContentInsetsChanged;
156
157 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800158 * Insets that determine the area covered by the display overscan region. These are in the
159 * application's coordinate space (without compatibility scale applied).
160 */
161 final Rect mOverscanInsets = new Rect();
162 final Rect mLastOverscanInsets = new Rect();
163 boolean mOverscanInsetsChanged;
164
165 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800166 * Set to true if we are waiting for this window to receive its
167 * given internal insets before laying out other windows based on it.
168 */
169 boolean mGivenInsetsPending;
170
171 /**
172 * These are the content insets that were given during layout for
173 * this window, to be applied to windows behind it.
174 */
175 final Rect mGivenContentInsets = new Rect();
176
177 /**
178 * These are the visible insets that were given during layout for
179 * this window, to be applied to windows behind it.
180 */
181 final Rect mGivenVisibleInsets = new Rect();
182
183 /**
184 * This is the given touchable area relative to the window frame, or null if none.
185 */
186 final Region mGivenTouchableRegion = new Region();
187
188 /**
189 * Flag indicating whether the touchable region should be adjusted by
190 * the visible insets; if false the area outside the visible insets is
191 * NOT touchable, so we must use those to adjust the frame during hit
192 * tests.
193 */
194 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
195
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700196 /**
197 * This is rectangle of the window's surface that is not covered by
198 * system decorations.
199 */
200 final Rect mSystemDecorRect = new Rect();
201 final Rect mLastSystemDecorRect = new Rect();
202
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800203 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400204 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700205 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800206 float mHScale=1, mVScale=1;
207 float mLastHScale=1, mLastVScale=1;
208 final Matrix mTmpMatrix = new Matrix();
209
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700210 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800211 final Rect mFrame = new Rect();
212 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700213 // Frame that is scaled to the application's coordinate space when in
214 // screen size compatibility mode.
215 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800216
217 final Rect mContainingFrame = new Rect();
218 final Rect mDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800219 final Rect mOverscanFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800220 final Rect mContentFrame = new Rect();
221 final Rect mParentFrame = new Rect();
222 final Rect mVisibleFrame = new Rect();
223
224 boolean mContentChanged;
225
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800226 // If a window showing a wallpaper: the requested offset for the
227 // wallpaper; if a wallpaper window: the currently applied offset.
228 float mWallpaperX = -1;
229 float mWallpaperY = -1;
230
231 // If a window showing a wallpaper: what fraction of the offset
232 // range corresponds to a full virtual screen.
233 float mWallpaperXStep = -1;
234 float mWallpaperYStep = -1;
235
236 // Wallpaper windows: pixels offset based on above variables.
237 int mXOffset;
238 int mYOffset;
239
Craig Mautner2268e7e2012-12-13 15:40:00 -0800240 /**
241 * This is set after IWindowSession.relayout() has been called at
242 * least once for the window. It allows us to detect the situation
243 * where we don't yet have a surface, but should have one soon, so
244 * we can give the window focus before waiting for the relayout.
245 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800246 boolean mRelayoutCalled;
247
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800248 /**
249 * If the application has called relayout() with changes that can
250 * impact its window's size, we need to perform a layout pass on it
251 * even if it is not currently visible for layout. This is set
252 * when in that case until the layout is done.
253 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800254 boolean mLayoutNeeded;
255
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800256 /** Currently running an exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800257 boolean mExiting;
258
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800259 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800260 boolean mDestroying;
261
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800262 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800263 boolean mRemoveOnExit;
264
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800265 /**
266 * Set when the orientation is changing and this window has not yet
267 * been updated for the new orientation.
268 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800269 boolean mOrientationChanging;
270
Dianne Hackborna57c6952013-03-29 14:46:40 -0700271 /**
272 * How long we last kept the screen frozen.
273 */
274 int mLastFreezeDuration;
275
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800276 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800277 boolean mRemoved;
278
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800279 /**
280 * Temp for keeping track of windows that have been removed when
281 * rebuilding window list.
282 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800283 boolean mRebuilding;
284
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800285 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700286 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800287 InputChannel mInputChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800288
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800289 // Used to improve performance of toString()
290 String mStringNameCache;
291 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700292 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800293
Craig Mautnera2c77052012-03-26 12:14:43 -0700294 final WindowStateAnimator mWinAnimator;
295
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700296 boolean mHasSurface = false;
297
Craig Mautner59c00972012-07-30 12:10:24 -0700298 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700299
Craig Mautner88400d32012-09-30 12:35:45 -0700300 /** When true this window can be displayed on screens owther than mOwnerUid's */
301 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700302
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800303 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800304 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700305 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800306 mService = service;
307 mSession = s;
308 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800309 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800310 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700311 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800312 mWindowId = new IWindowId.Stub() {
313 @Override
314 public void registerFocusObserver(IWindowFocusObserver observer) {
315 WindowState.this.registerFocusObserver(observer);
316 }
317 @Override
318 public void unregisterFocusObserver(IWindowFocusObserver observer) {
319 WindowState.this.unregisterFocusObserver(observer);
320 }
321 @Override
322 public boolean isFocused() {
323 return WindowState.this.isFocused();
324 }
325 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800326 mAttrs.copyFrom(a);
327 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700328 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700329 mPolicy = mService.mPolicy;
330 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800331 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700332 mSeq = seq;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400333 mEnforceSizeCompat = (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800334 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700335 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700336 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800337 try {
338 c.asBinder().linkToDeath(deathRecipient, 0);
339 } catch (RemoteException e) {
340 mDeathRecipient = null;
341 mAttachedWindow = null;
342 mLayoutAttached = false;
343 mIsImWindow = false;
344 mIsWallpaper = false;
345 mIsFloatingLayer = false;
346 mBaseLayer = 0;
347 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700348 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700349 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800350 return;
351 }
352 mDeathRecipient = deathRecipient;
353
354 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
355 mAttrs.type <= LAST_SUB_WINDOW)) {
356 // The multiplier here is to reserve space for multiple
357 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700358 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800359 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
360 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700361 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800362 mAttachedWindow = attachedWindow;
Craig Mautnerd87946b2012-03-29 18:00:19 -0700363 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900364
365 int children_size = mAttachedWindow.mChildWindows.size();
366 if (children_size == 0) {
367 mAttachedWindow.mChildWindows.add(this);
368 } else {
369 for (int i = 0; i < children_size; i++) {
370 WindowState child = (WindowState)mAttachedWindow.mChildWindows.get(i);
371 if (this.mSubLayer < child.mSubLayer) {
372 mAttachedWindow.mChildWindows.add(i, this);
373 break;
374 } else if (this.mSubLayer > child.mSubLayer) {
375 continue;
376 }
377
378 if (this.mBaseLayer <= child.mBaseLayer) {
379 mAttachedWindow.mChildWindows.add(i, this);
380 break;
381 } else {
382 continue;
383 }
384 }
385 if (children_size == mAttachedWindow.mChildWindows.size()) {
386 mAttachedWindow.mChildWindows.add(this);
387 }
388 }
389
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800390 mLayoutAttached = mAttrs.type !=
391 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
392 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
393 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
394 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
395 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
396 } else {
397 // The multiplier here is to reserve space for multiple
398 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700399 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800400 * WindowManagerService.TYPE_LAYER_MULTIPLIER
401 + WindowManagerService.TYPE_LAYER_OFFSET;
402 mSubLayer = 0;
403 mAttachedWindow = null;
404 mLayoutAttached = false;
405 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
406 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
407 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
408 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
409 }
410
411 WindowState appWin = this;
412 while (appWin.mAttachedWindow != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700413 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800414 }
415 WindowToken appToken = appWin.mToken;
416 while (appToken.appWindowToken == null) {
417 WindowToken parent = mService.mTokenMap.get(appToken.token);
418 if (parent == null || appToken == parent) {
419 break;
420 }
421 appToken = parent;
422 }
423 mRootToken = appToken;
424 mAppToken = appToken.appWindowToken;
425
Craig Mautner322e4032012-07-13 13:35:20 -0700426 mWinAnimator = new WindowStateAnimator(this);
427 mWinAnimator.mAlpha = a.alpha;
428
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800429 mRequestedWidth = 0;
430 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700431 mLastRequestedWidth = 0;
432 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800433 mXOffset = 0;
434 mYOffset = 0;
435 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800436 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700437 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
438 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800439 }
440
441 void attach() {
442 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700443 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800444 + ", list=" + mToken.windows);
445 mSession.windowAddedLocked();
446 }
447
Craig Mautnera2c77052012-03-26 12:14:43 -0700448 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800449 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800450 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800451 }
452
453 @Override
454 public String getOwningPackage() {
455 return mAttrs.packageName;
456 }
457
458 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800459 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800460 mHaveFrame = true;
461
462 final Rect container = mContainingFrame;
463 container.set(pf);
464
465 final Rect display = mDisplayFrame;
466 display.set(df);
467
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800468 final int pw = container.right - container.left;
469 final int ph = container.bottom - container.top;
470
471 int w,h;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700472 if ((mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0) {
473 if (mAttrs.width < 0) {
474 w = pw;
475 } else if (mEnforceSizeCompat) {
476 w = (int)(mAttrs.width * mGlobalScale + .5f);
477 } else {
478 w = mAttrs.width;
479 }
480 if (mAttrs.height < 0) {
481 h = ph;
482 } else if (mEnforceSizeCompat) {
483 h = (int)(mAttrs.height * mGlobalScale + .5f);
484 } else {
485 h = mAttrs.height;
486 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800487 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700488 if (mAttrs.width == WindowManager.LayoutParams.MATCH_PARENT) {
489 w = pw;
490 } else if (mEnforceSizeCompat) {
491 w = (int)(mRequestedWidth * mGlobalScale + .5f);
492 } else {
493 w = mRequestedWidth;
494 }
495 if (mAttrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
496 h = ph;
497 } else if (mEnforceSizeCompat) {
498 h = (int)(mRequestedHeight * mGlobalScale + .5f);
499 } else {
500 h = mRequestedHeight;
501 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800502 }
503
504 if (!mParentFrame.equals(pf)) {
505 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
506 // + " to " + pf);
507 mParentFrame.set(pf);
508 mContentChanged = true;
509 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700510 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
511 mLastRequestedWidth = mRequestedWidth;
512 mLastRequestedHeight = mRequestedHeight;
513 mContentChanged = true;
514 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800515
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800516 final Rect overscan = mOverscanFrame;
517 overscan.set(of);
518
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800519 final Rect content = mContentFrame;
520 content.set(cf);
521
522 final Rect visible = mVisibleFrame;
523 visible.set(vf);
524
525 final Rect frame = mFrame;
526 final int fw = frame.width();
527 final int fh = frame.height();
528
529 //System.out.println("In: w=" + w + " h=" + h + " container=" +
530 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
531
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700532 float x, y;
533 if (mEnforceSizeCompat) {
534 x = mAttrs.x * mGlobalScale;
535 y = mAttrs.y * mGlobalScale;
536 } else {
537 x = mAttrs.x;
538 y = mAttrs.y;
539 }
540
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800541 Gravity.apply(mAttrs.gravity, w, h, container,
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700542 (int) (x + mAttrs.horizontalMargin * pw),
543 (int) (y + mAttrs.verticalMargin * ph), frame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800544
545 //System.out.println("Out: " + mFrame);
546
547 // Now make sure the window fits in the overall display.
548 Gravity.applyDisplay(mAttrs.gravity, df, frame);
549
Craig Mautnera248eee2013-05-07 11:41:27 -0700550 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800551 // final window frame.
552 if (content.left < frame.left) content.left = frame.left;
553 if (content.top < frame.top) content.top = frame.top;
554 if (content.right > frame.right) content.right = frame.right;
555 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
556 if (visible.left < frame.left) visible.left = frame.left;
557 if (visible.top < frame.top) visible.top = frame.top;
558 if (visible.right > frame.right) visible.right = frame.right;
559 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
560
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800561 final Rect overscanInsets = mOverscanInsets;
Dianne Hackbornbee1fb92013-05-08 15:51:26 -0700562 overscanInsets.left = overscan.left > frame.left ? overscan.left-frame.left : 0;
563 overscanInsets.top = overscan.top > frame.top ? overscan.top-frame.top : 0;
564 overscanInsets.right = overscan.right < frame.right ? frame.right-overscan.right : 0;
565 overscanInsets.bottom = overscan.bottom < frame.bottom ? frame.bottom-overscan.bottom : 0;
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800566
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800567 final Rect contentInsets = mContentInsets;
568 contentInsets.left = content.left-frame.left;
569 contentInsets.top = content.top-frame.top;
570 contentInsets.right = frame.right-content.right;
571 contentInsets.bottom = frame.bottom-content.bottom;
572
573 final Rect visibleInsets = mVisibleInsets;
574 visibleInsets.left = visible.left-frame.left;
575 visibleInsets.top = visible.top-frame.top;
576 visibleInsets.right = frame.right-visible.right;
577 visibleInsets.bottom = frame.bottom-visible.bottom;
578
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700579 mCompatFrame.set(frame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400580 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700581 // If there is a size compatibility scale being applied to the
582 // window, we need to apply this to its insets so that they are
583 // reported to the app in its coordinate space.
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800584 overscanInsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700585 contentInsets.scale(mInvGlobalScale);
586 visibleInsets.scale(mInvGlobalScale);
587
588 // Also the scaled frame that we report to the app needs to be
589 // adjusted to be in its coordinate space.
590 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400591 }
592
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800593 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
Craig Mautner59c00972012-07-30 12:10:24 -0700594 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
595 mService.updateWallpaperOffsetLocked(this, displayInfo.appWidth, displayInfo.appHeight,
596 false);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800597 }
598
599 if (WindowManagerService.localLOGV) {
600 //if ("com.google.android.youtube".equals(mAttrs.packageName)
601 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700602 Slog.v(TAG, "Resolving (mRequestedWidth="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800603 + mRequestedWidth + ", mRequestedheight="
604 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
605 + "): frame=" + mFrame.toShortString()
606 + " ci=" + contentInsets.toShortString()
607 + " vi=" + visibleInsets.toShortString());
608 //}
609 }
610 }
611
Craig Mautnera2c77052012-03-26 12:14:43 -0700612 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800613 public Rect getFrameLw() {
614 return mFrame;
615 }
616
Craig Mautnera2c77052012-03-26 12:14:43 -0700617 @Override
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700618 public RectF getShownFrameLw() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800619 return mShownFrame;
620 }
621
Craig Mautnera2c77052012-03-26 12:14:43 -0700622 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800623 public Rect getDisplayFrameLw() {
624 return mDisplayFrame;
625 }
626
Craig Mautnera2c77052012-03-26 12:14:43 -0700627 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800628 public Rect getOverscanFrameLw() {
629 return mOverscanFrame;
630 }
631
632 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800633 public Rect getContentFrameLw() {
634 return mContentFrame;
635 }
636
Craig Mautnera2c77052012-03-26 12:14:43 -0700637 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800638 public Rect getVisibleFrameLw() {
639 return mVisibleFrame;
640 }
641
Craig Mautnera2c77052012-03-26 12:14:43 -0700642 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800643 public boolean getGivenInsetsPendingLw() {
644 return mGivenInsetsPending;
645 }
646
Craig Mautnera2c77052012-03-26 12:14:43 -0700647 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800648 public Rect getGivenContentInsetsLw() {
649 return mGivenContentInsets;
650 }
651
Craig Mautnera2c77052012-03-26 12:14:43 -0700652 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800653 public Rect getGivenVisibleInsetsLw() {
654 return mGivenVisibleInsets;
655 }
656
Craig Mautnera2c77052012-03-26 12:14:43 -0700657 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800658 public WindowManager.LayoutParams getAttrs() {
659 return mAttrs;
660 }
661
Craig Mautner812d2ca2012-09-27 15:35:34 -0700662 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800663 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
664 int index = -1;
665 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700666 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800667 while (true) {
668 if ((ws.mAttrs.privateFlags
669 & WindowManager.LayoutParams.PRIVATE_FLAG_SET_NEEDS_MENU_KEY) != 0) {
670 return (ws.mAttrs.flags & WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0;
671 }
672 // If we reached the bottom of the range of windows we are considering,
673 // assume no menu is needed.
674 if (ws == bottom) {
675 return false;
676 }
677 // The current window hasn't specified whether menu key is needed;
678 // look behind it.
679 // First, we may need to determine the starting position.
680 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700681 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800682 }
683 index--;
684 if (index < 0) {
685 return false;
686 }
Craig Mautner59c00972012-07-30 12:10:24 -0700687 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800688 }
689 }
690
Craig Mautner19d59bc2012-09-04 11:15:56 -0700691 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700692 public int getSystemUiVisibility() {
693 return mSystemUiVisibility;
694 }
695
Craig Mautner19d59bc2012-09-04 11:15:56 -0700696 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800697 public int getSurfaceLayer() {
698 return mLayer;
699 }
700
Craig Mautner812d2ca2012-09-27 15:35:34 -0700701 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800702 public IApplicationToken getAppToken() {
703 return mAppToken != null ? mAppToken.appToken : null;
704 }
Craig Mautner19d59bc2012-09-04 11:15:56 -0700705
706 public int getDisplayId() {
707 return mDisplayContent.getDisplayId();
708 }
709
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800710 public long getInputDispatchingTimeoutNanos() {
711 return mAppToken != null
712 ? mAppToken.inputDispatchingTimeoutNanos
713 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
714 }
715
Craig Mautnere8552142012-11-07 13:55:47 -0800716 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800717 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -0700718 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800719 }
720
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800721 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
722 if (dsdx < .99999f || dsdx > 1.00001f) return false;
723 if (dtdy < .99999f || dtdy > 1.00001f) return false;
724 if (dtdx < -.000001f || dtdx > .000001f) return false;
725 if (dsdy < -.000001f || dsdy > .000001f) return false;
726 return true;
727 }
728
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400729 void prelayout() {
730 if (mEnforceSizeCompat) {
731 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700732 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400733 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700734 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400735 }
736 }
737
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800738 /**
739 * Is this window visible? It is not visible if there is no
740 * surface, or we are in the process of running an exit animation
741 * that will remove the surface, or its app token has been hidden.
742 */
Craig Mautner88400d32012-09-30 12:35:45 -0700743 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800744 public boolean isVisibleLw() {
745 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700746 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800747 && (atoken == null || !atoken.hiddenRequested)
748 && !mExiting && !mDestroying;
749 }
750
751 /**
752 * Like {@link #isVisibleLw}, but also counts a window that is currently
753 * "hidden" behind the keyguard as visible. This allows us to apply
754 * things like window flags that impact the keyguard.
755 * XXX I am starting to think we need to have ANOTHER visibility flag
756 * for this "hidden behind keyguard" state rather than overloading
757 * mPolicyVisibility. Ungh.
758 */
Craig Mautner88400d32012-09-30 12:35:45 -0700759 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800760 public boolean isVisibleOrBehindKeyguardLw() {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700761 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -0800762 mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700763 return false;
764 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800765 final AppWindowToken atoken = mAppToken;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700766 final boolean animating = atoken != null
Craig Mautner59431632012-04-04 11:56:44 -0700767 ? (atoken.mAppAnimator.animation != null) : false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700768 return mHasSurface && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800769 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700770 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
771 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -0700772 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800773 }
774
775 /**
776 * Is this window visible, ignoring its app token? It is not visible
777 * if there is no surface, or we are in the process of running an exit animation
778 * that will remove the surface.
779 */
780 public boolean isWinVisibleLw() {
781 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700782 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautner59431632012-04-04 11:56:44 -0700783 && (atoken == null || !atoken.hiddenRequested || atoken.mAppAnimator.animating)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800784 && !mExiting && !mDestroying;
785 }
786
787 /**
788 * The same as isVisible(), but follows the current hidden state of
789 * the associated app token, not the pending requested hidden state.
790 */
791 boolean isVisibleNow() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700792 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800793 && !mRootToken.hidden && !mExiting && !mDestroying;
794 }
795
796 /**
797 * Can this window possibly be a drag/drop target? The test here is
798 * a combination of the above "visible now" with the check that the
799 * Input Manager uses when discarding windows from input consideration.
800 */
801 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -0700802 return isVisibleNow() && !mRemoved
803 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800804 }
805
806 /**
807 * Same as isVisible(), but we also count it as visible between the
808 * call to IWindowSession.add() and the first relayout().
809 */
810 boolean isVisibleOrAdding() {
811 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -0700812 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800813 && mPolicyVisibility && !mAttachedHidden
814 && (atoken == null || !atoken.hiddenRequested)
815 && !mExiting && !mDestroying;
816 }
817
818 /**
819 * Is this window currently on-screen? It is on-screen either if it
820 * is visible or it is currently running an animation before no longer
821 * being visible.
822 */
823 boolean isOnScreen() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700824 if (!mHasSurface || !mPolicyVisibility || mDestroying) {
825 return false;
826 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800827 final AppWindowToken atoken = mAppToken;
828 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700829 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -0800830 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800831 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700832 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800833 }
834
835 /**
836 * Like isOnScreen(), but we don't return true if the window is part
837 * of a transition that has not yet been started.
838 */
839 boolean isReadyForDisplay() {
840 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -0800841 mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800842 return false;
843 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700844 return mHasSurface && mPolicyVisibility && !mDestroying
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800845 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
846 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -0700847 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -0700848 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800849 }
850
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800851 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700852 * Like isReadyForDisplay(), but ignores any force hiding of the window due
853 * to the keyguard.
854 */
855 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800856 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700857 return false;
858 }
859 final AppWindowToken atoken = mAppToken;
860 if (atoken == null && !mPolicyVisibility) {
861 // If this is not an app window, and the policy has asked to force
862 // hide, then we really do want to hide.
863 return false;
864 }
865 return mHasSurface && !mDestroying
866 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
867 && !mRootToken.hidden)
868 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -0700869 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
870 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700871 }
872
873 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800874 * Like isOnScreen, but returns false if the surface hasn't yet
875 * been drawn.
876 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -0700877 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800878 public boolean isDisplayedLw() {
879 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700880 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800881 && ((!mAttachedHidden &&
882 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -0700883 || mWinAnimator.mAnimating
884 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800885 }
886
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700887 /**
Craig Mautnerae446592012-12-06 19:05:05 -0800888 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700889 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -0700890 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700891 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -0800892 return mWinAnimator.mAnimation != null
893 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700894 }
895
Craig Mautner812d2ca2012-09-27 15:35:34 -0700896 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -0800897 public boolean isGoneForLayoutLw() {
898 final AppWindowToken atoken = mAppToken;
899 return mViewVisibility == View.GONE
900 || !mRelayoutCalled
901 || (atoken == null && mRootToken.hidden)
Craig Mautner812d2ca2012-09-27 15:35:34 -0700902 || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
Dianne Hackborncfbf7de2012-01-12 14:05:03 -0800903 || mAttachedHidden
904 || mExiting || mDestroying;
905 }
906
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800907 /**
908 * Returns true if the window has a surface that it has drawn a
909 * complete UI in to.
910 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -0800911 public boolean isDrawFinishedLw() {
912 return mHasSurface && !mDestroying &&
913 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
914 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
915 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
916 }
917
918 /**
919 * Returns true if the window has a surface that it has drawn a
920 * complete UI in to.
921 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800922 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700923 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -0700924 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
925 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800926 }
927
928 /**
929 * Return true if the window is opaque and fully drawn. This indicates
930 * it may obscure windows behind it.
931 */
932 boolean isOpaqueDrawn() {
933 return (mAttrs.format == PixelFormat.OPAQUE
934 || mAttrs.type == TYPE_WALLPAPER)
Craig Mautnera2c77052012-03-26 12:14:43 -0700935 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -0700936 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800937 }
938
939 /**
940 * Return whether this window is wanting to have a translation
941 * animation applied to it for an in-progress move. (Only makes
942 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
943 */
944 boolean shouldAnimateMove() {
Craig Mautner749a7bb2012-04-02 13:49:53 -0700945 return mContentChanged && !mExiting && !mWinAnimator.mLastHidden && mService.okToDisplay()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800946 && (mFrame.top != mLastFrame.top
947 || mFrame.left != mLastFrame.left)
Dianne Hackborn1c5383c2013-04-15 15:07:21 -0700948 && (mAttrs.privateFlags&PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
Craig Mautner2fb98b12012-03-20 17:24:00 -0700949 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800950 }
951
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800952 boolean isFullscreen(int screenWidth, int screenHeight) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700953 return mFrame.left <= 0 && mFrame.top <= 0 &&
954 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800955 }
956
Craig Mautner812d2ca2012-09-27 15:35:34 -0700957 boolean isConfigChanged() {
Craig Mautnere8552142012-11-07 13:55:47 -0800958 boolean configChanged = mConfiguration != mService.mCurConfiguration
Craig Mautner812d2ca2012-09-27 15:35:34 -0700959 && (mConfiguration == null
960 || (mConfiguration.diff(mService.mCurConfiguration) != 0));
Craig Mautnere8552142012-11-07 13:55:47 -0800961
962 if (mAttrs.type == TYPE_KEYGUARD) {
963 // Retain configuration changed status until resetConfiguration called.
964 mConfigHasChanged |= configChanged;
965 configChanged = mConfigHasChanged;
966 }
967
968 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -0700969 }
970
971 boolean isConfigDiff(int mask) {
972 return mConfiguration != mService.mCurConfiguration
973 && mConfiguration != null
974 && (mConfiguration.diff(mService.mCurConfiguration) & mask) != 0;
975 }
976
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800977 void removeLocked() {
978 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800979
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800980 if (mAttachedWindow != null) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700981 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800982 mAttachedWindow.mChildWindows.remove(this);
983 }
Craig Mautner96868332012-12-04 14:29:11 -0800984 mWinAnimator.destroyDeferredSurfaceLocked();
985 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800986 mSession.windowRemovedLocked();
987 try {
988 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
989 } catch (RuntimeException e) {
990 // Ignore if it has already been removed (usually because
991 // we are doing this as part of processing a death note.)
992 }
993 }
Jeff Browncc4f7db2011-08-30 20:34:48 -0700994
Craig Mautnere8552142012-11-07 13:55:47 -0800995 void setConfiguration(final Configuration newConfig) {
996 mConfiguration = newConfig;
997 mConfigHasChanged = false;
998 }
999
Jeff Browncc4f7db2011-08-30 20:34:48 -07001000 void setInputChannel(InputChannel inputChannel) {
1001 if (mInputChannel != null) {
1002 throw new IllegalStateException("Window already has an input channel.");
1003 }
1004
1005 mInputChannel = inputChannel;
1006 mInputWindowHandle.inputChannel = inputChannel;
1007 }
1008
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001009 void disposeInputChannel() {
1010 if (mInputChannel != null) {
1011 mService.mInputManager.unregisterInputChannel(mInputChannel);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001012
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001013 mInputChannel.dispose();
1014 mInputChannel = null;
1015 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001016
1017 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001018 }
1019
1020 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001021 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001022 public void binderDied() {
1023 try {
1024 synchronized(mService.mWindowMap) {
1025 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001026 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001027 if (win != null) {
1028 mService.removeWindowLocked(mSession, win);
Craig Mautnera99764e2013-03-06 10:22:16 -08001029 } else if (WindowState.this.mHasSurface) {
1030 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
1031 mService.removeWindowLocked(mSession, WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001032 }
1033 }
1034 } catch (IllegalArgumentException ex) {
1035 // This will happen if the window has already been
1036 // removed.
1037 }
1038 }
1039 }
1040
Craig Mautner58106812012-12-28 12:27:40 -08001041 /**
1042 * @return true if this window desires key events.
Craig Mautneref25d7a2012-05-15 23:01:47 -07001043 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001044 public final boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001045 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001046 && (mViewVisibility == View.VISIBLE)
1047 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
1048 }
1049
Craig Mautner749a7bb2012-04-02 13:49:53 -07001050 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001051 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001052 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001053 }
1054
Craig Mautner749a7bb2012-04-02 13:49:53 -07001055 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001056 public boolean showLw(boolean doAnimation) {
1057 return showLw(doAnimation, true);
1058 }
1059
1060 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001061 if (isHiddenFromUserLocked()) {
Craig Mautner88400d32012-09-30 12:35:45 -07001062 Slog.w(TAG, "current user violation " + mService.mCurrentUserId + " trying to display "
Craig Mautnera2d7b112012-08-21 15:12:20 -07001063 + this + ", type " + mAttrs.type + ", belonging to " + mOwnerUid);
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001064 return false;
1065 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001066 if (!mAppOpVisibility) {
1067 // Being hidden due to app op request.
1068 return false;
1069 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001070 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001071 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001072 return false;
1073 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001074 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001075 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001076 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001077 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001078 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001079 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001080 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001081 // Check for the case where we are currently visible and
1082 // not animating; we do not want to do animation at such a
1083 // point to become visible when we already are.
1084 doAnimation = false;
1085 }
1086 }
1087 mPolicyVisibility = true;
1088 mPolicyVisibilityAfterAnim = true;
1089 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001090 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001091 }
1092 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001093 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001094 }
1095 return true;
1096 }
1097
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001098 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001099 public boolean hideLw(boolean doAnimation) {
1100 return hideLw(doAnimation, true);
1101 }
1102
1103 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1104 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001105 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001106 doAnimation = false;
1107 }
1108 }
1109 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1110 : mPolicyVisibility;
1111 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001112 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001113 return false;
1114 }
1115 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001116 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001117 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001118 doAnimation = false;
1119 }
1120 }
1121 if (doAnimation) {
1122 mPolicyVisibilityAfterAnim = false;
1123 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001124 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001125 mPolicyVisibilityAfterAnim = false;
1126 mPolicyVisibility = false;
1127 // Window is no longer visible -- make sure if we were waiting
1128 // for it to be displayed before enabling the display, that
1129 // we allow the display to be enabled now.
1130 mService.enableScreenIfNeededLocked();
1131 if (mService.mCurrentFocus == this) {
1132 mService.mFocusMayChange = true;
1133 }
1134 }
1135 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001136 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001137 }
1138 return true;
1139 }
1140
Craig Mautner2ad92072013-02-25 16:19:24 -08001141 public boolean setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001142 if (mAppOpVisibility != state) {
1143 mAppOpVisibility = state;
1144 if (state) {
1145 // If the policy visibility had last been to hide, then this
1146 // will incorrectly show at this point since we lost that
1147 // information. Not a big deal -- for the windows that have app
1148 // ops modifies they should only be hidden by policy due to the
1149 // lock screen, and the user won't be changing this if locked.
1150 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautner2ad92072013-02-25 16:19:24 -08001151 showLw(true, false);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001152 } else {
Craig Mautner2ad92072013-02-25 16:19:24 -08001153 hideLw(true, false);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001154 }
Craig Mautner2ad92072013-02-25 16:19:24 -08001155 return true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001156 }
Craig Mautner2ad92072013-02-25 16:19:24 -08001157 return false;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001158 }
1159
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001160 @Override
1161 public boolean isAlive() {
1162 return mClient.asBinder().isBinderAlive();
1163 }
1164
Craig Mautnera987d432012-10-11 14:07:58 -07001165 boolean isClosing() {
1166 return mExiting || (mService.mClosingApps.contains(mAppToken));
1167 }
1168
Craig Mautner69b08182012-09-05 13:07:13 -07001169 @Override
1170 public boolean isDefaultDisplay() {
1171 return mDisplayContent.isDefaultDisplay;
1172 }
1173
Craig Mautner88400d32012-09-30 12:35:45 -07001174 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
1175 mShowToOwnerOnly = showToOwnerOnly;
1176 }
1177
Craig Mautner5962b122012-10-05 14:45:52 -07001178 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07001179 // Attached windows are evaluated based on the window that they are attached to.
1180 WindowState win = this;
1181 while (win.mAttachedWindow != null) {
1182 win = win.mAttachedWindow;
1183 }
1184 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1185 && win.mAppToken != null && win.mAppToken.showWhenLocked) {
1186 // Save some cycles by not calling getDisplayInfo unless it is an application
1187 // window intended for all users.
1188 final DisplayInfo displayInfo = win.mDisplayContent.getDisplayInfo();
1189 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
1190 && win.mFrame.right >= displayInfo.appWidth
1191 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07001192 // Is a fullscreen window, like the clock alarm. Show to everyone.
1193 return false;
1194 }
1195 }
1196
Craig Mautner341220f2012-10-16 15:20:09 -07001197 return win.mShowToOwnerOnly
1198 && UserHandle.getUserId(win.mOwnerUid) != mService.mCurrentUserId;
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001199 }
1200
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001201 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
1202 outRegion.set(
1203 frame.left + inset.left, frame.top + inset.top,
1204 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001205 }
1206
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001207 public void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001208 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001209 switch (mTouchableInsets) {
1210 default:
1211 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
1212 outRegion.set(frame);
1213 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001214 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001215 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001216 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001217 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001218 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001219 break;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001220 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
1221 final Region givenTouchableRegion = mGivenTouchableRegion;
1222 outRegion.set(givenTouchableRegion);
1223 outRegion.translate(frame.left, frame.top);
1224 break;
1225 }
1226 }
1227 }
1228
Craig Mautner59c00972012-07-30 12:10:24 -07001229 WindowList getWindowList() {
1230 return mDisplayContent.getWindowList();
1231 }
1232
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001233 /**
1234 * Report a focus change. Must be called with no locks held, and consistently
1235 * from the same serialized thread (such as dispatched from a handler).
1236 */
1237 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
1238 try {
1239 mClient.windowFocusChanged(focused, inTouchMode);
1240 } catch (RemoteException e) {
1241 }
1242 if (mFocusCallbacks != null) {
1243 final int N = mFocusCallbacks.beginBroadcast();
1244 for (int i=0; i<N; i++) {
1245 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
1246 try {
1247 if (focused) {
1248 obs.focusGained(mWindowId.asBinder());
1249 } else {
1250 obs.focusLost(mWindowId.asBinder());
1251 }
1252 } catch (RemoteException e) {
1253 }
1254 }
1255 mFocusCallbacks.finishBroadcast();
1256 }
1257 }
1258
1259 public void registerFocusObserver(IWindowFocusObserver observer) {
1260 synchronized(mService.mWindowMap) {
1261 if (mFocusCallbacks == null) {
1262 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
1263 }
1264 mFocusCallbacks.register(observer);
1265 }
1266 }
1267
1268 public void unregisterFocusObserver(IWindowFocusObserver observer) {
1269 synchronized(mService.mWindowMap) {
1270 if (mFocusCallbacks != null) {
1271 mFocusCallbacks.unregister(observer);
1272 }
1273 }
1274 }
1275
1276 public boolean isFocused() {
1277 synchronized(mService.mWindowMap) {
1278 return mService.mCurrentFocus == this;
1279 }
1280 }
1281
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001282 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Craig Mautner59c00972012-07-30 12:10:24 -07001283 pw.print(prefix); pw.print("mDisplayId="); pw.print(mDisplayContent.getDisplayId());
1284 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001285 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07001286 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08001287 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
1288 pw.print(" package="); pw.print(mAttrs.packageName);
1289 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001290 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001291 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
1292 pw.print(" h="); pw.print(mRequestedHeight);
1293 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07001294 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
1295 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
1296 pw.print(" h="); pw.println(mLastRequestedHeight);
1297 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001298 if (mAttachedWindow != null || mLayoutAttached) {
1299 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
1300 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
1301 }
1302 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
1303 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
1304 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
1305 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
1306 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
1307 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001308 if (dumpAll) {
1309 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
1310 pw.print(" mSubLayer="); pw.print(mSubLayer);
1311 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07001312 pw.print((mTargetAppToken != null ?
1313 mTargetAppToken.mAppAnimator.animLayerAdjustment
1314 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001315 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
1316 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08001317 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001318 if (dumpAll) {
1319 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
1320 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
1321 if (mAppToken != null) {
1322 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
1323 }
1324 if (mTargetAppToken != null) {
1325 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
1326 }
1327 pw.print(prefix); pw.print("mViewVisibility=0x");
1328 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001329 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
1330 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001331 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
1332 pw.print(" mSystemUiVisibility=0x");
1333 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001334 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001335 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
1336 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001337 pw.print(prefix); pw.print("mPolicyVisibility=");
1338 pw.print(mPolicyVisibility);
1339 pw.print(" mPolicyVisibilityAfterAnim=");
1340 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001341 pw.print(" mAppOpVisibility=");
1342 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001343 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
1344 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08001345 if (!mRelayoutCalled || mLayoutNeeded) {
1346 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
1347 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001348 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001349 if (mXOffset != 0 || mYOffset != 0) {
1350 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
1351 pw.print(" y="); pw.println(mYOffset);
1352 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001353 if (dumpAll) {
1354 pw.print(prefix); pw.print("mGivenContentInsets=");
1355 mGivenContentInsets.printShortString(pw);
1356 pw.print(" mGivenVisibleInsets=");
1357 mGivenVisibleInsets.printShortString(pw);
1358 pw.println();
1359 if (mTouchableInsets != 0 || mGivenInsetsPending) {
1360 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
1361 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001362 Region region = new Region();
1363 getTouchableRegion(region);
1364 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001365 }
1366 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001367 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001368 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Craig Mautner178af592012-09-17 10:37:29 -07001369 pw.print(" mShownFrame="); mShownFrame.printShortString(pw);
1370 pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001371 if (dumpAll) {
1372 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
1373 pw.print(" last="); mLastFrame.printShortString(pw);
1374 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001375 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
1376 pw.print(" last="); mLastSystemDecorRect.printShortString(pw);
1377 pw.println();
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001378 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001379 if (mEnforceSizeCompat) {
1380 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001381 pw.println();
1382 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001383 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001384 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001385 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001386 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001387 pw.println();
1388 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
1389 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001390 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001391 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001392 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001393 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001394 pw.print(prefix); pw.print("Cur insets: overscan=");
1395 mOverscanInsets.printShortString(pw);
1396 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001397 pw.print(" visible="); mVisibleInsets.printShortString(pw);
1398 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001399 pw.print(prefix); pw.print("Lst insets: overscan=");
1400 mLastOverscanInsets.printShortString(pw);
1401 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001402 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001403 pw.println();
1404 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07001405 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
1406 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001407 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
1408 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
1409 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
1410 pw.print(" mDestroying="); pw.print(mDestroying);
1411 pw.print(" mRemoved="); pw.println(mRemoved);
1412 }
1413 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
1414 pw.print(prefix); pw.print("mOrientationChanging=");
1415 pw.print(mOrientationChanging);
1416 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
1417 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
1418 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07001419 if (mLastFreezeDuration != 0) {
1420 pw.print(prefix); pw.print("mLastFreezeDuration=");
1421 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
1422 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001423 if (mHScale != 1 || mVScale != 1) {
1424 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
1425 pw.print(" mVScale="); pw.println(mVScale);
1426 }
1427 if (mWallpaperX != -1 || mWallpaperY != -1) {
1428 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
1429 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
1430 }
1431 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
1432 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
1433 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
1434 }
1435 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001436
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001437 String makeInputChannelName() {
1438 return Integer.toHexString(System.identityHashCode(this))
1439 + " " + mAttrs.getTitle();
1440 }
1441
1442 @Override
1443 public String toString() {
Dianne Hackbornc2293022013-02-06 23:14:49 -08001444 CharSequence title = mAttrs.getTitle();
1445 if (title == null || title.length() <= 0) {
1446 title = mAttrs.packageName;
1447 }
1448 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
1449 mLastTitle = title;
Dianne Hackborn529e7442012-11-01 14:22:28 -07001450 mWasExiting = mExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001451 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07001452 + " u" + UserHandle.getUserId(mSession.mUid)
Craig Mautnera987d432012-10-11 14:07:58 -07001453 + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001454 }
1455 return mStringNameCache;
1456 }
satokcef37fb2011-10-24 21:49:38 +09001457}