blob: 642f5ffbbb8411ce34601a3f07fc35977016d26f [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> {
Craig Mautner926f3832013-02-13 11:56:07 -080060 WindowList() {
61 super();
62 }
63 WindowList(WindowList windows) {
64 super(windows);
65 }
Craig Mautner59c00972012-07-30 12:10:24 -070066}
67
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080068/**
69 * A window in the window manager.
70 */
Craig Mautnere32c3072012-03-12 15:25:35 -070071final class WindowState implements WindowManagerPolicy.WindowState {
Craig Mautnerd87946b2012-03-29 18:00:19 -070072 static final String TAG = "WindowState";
Craig Mautner164d4bb2012-11-26 13:51:23 -080073
Dianne Hackborn5fd21692011-06-07 14:09:47 -070074 static final boolean DEBUG_VISIBILITY = WindowManagerService.DEBUG_VISIBILITY;
75 static final boolean SHOW_TRANSACTIONS = WindowManagerService.SHOW_TRANSACTIONS;
Dianne Hackborn36991742011-10-11 21:35:26 -070076 static final boolean SHOW_LIGHT_TRANSACTIONS = WindowManagerService.SHOW_LIGHT_TRANSACTIONS;
Dianne Hackborn5fd21692011-06-07 14:09:47 -070077 static final boolean SHOW_SURFACE_ALLOC = WindowManagerService.SHOW_SURFACE_ALLOC;
78
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080079 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -070080 final WindowManagerPolicy mPolicy;
81 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080082 final Session mSession;
83 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -080084 final int mAppOp;
85 // UserId and appId of the owner. Don't display windows of non-current user.
86 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080087 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080088 WindowToken mToken;
89 WindowToken mRootToken;
90 AppWindowToken mAppToken;
91 AppWindowToken mTargetAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070092
93 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
94 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080095 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
96 final DeathRecipient mDeathRecipient;
97 final WindowState mAttachedWindow;
Craig Mautner7b1aa772012-11-30 16:14:45 -080098 final WindowList mChildWindows = new WindowList();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080099 final int mBaseLayer;
100 final int mSubLayer;
101 final boolean mLayoutAttached;
102 final boolean mIsImWindow;
103 final boolean mIsWallpaper;
104 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700105 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700106 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800107 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700108 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800109 boolean mPolicyVisibility = true;
110 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800111 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800112 boolean mAppFreezing;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800113 boolean mAttachedHidden; // is our parent window hidden?
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800114 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700115
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800116 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
117
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700118 /**
119 * The window size that was requested by the application. These are in
120 * the application's coordinate space (without compatibility scale applied).
121 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800122 int mRequestedWidth;
123 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700124 int mLastRequestedWidth;
125 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700126
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800127 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800128 boolean mHaveFrame;
129 boolean mObscured;
130 boolean mTurnOnScreen;
131
132 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700133
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800134 Configuration mConfiguration = null;
Craig Mautnere8552142012-11-07 13:55:47 -0800135 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
136 // Used only on {@link #TYPE_KEYGUARD}.
137 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700138
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700139 /**
140 * Actual frame shown on-screen (may be modified by animation). These
141 * are in the screen's coordinate space (WITH the compatibility scale
142 * applied).
143 */
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700144 final RectF mShownFrame = new RectF();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800145
146 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700147 * Insets that determine the actually visible area. These are in the application's
148 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800149 */
150 final Rect mVisibleInsets = new Rect();
151 final Rect mLastVisibleInsets = new Rect();
152 boolean mVisibleInsetsChanged;
153
154 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700155 * Insets that are covered by system windows (such as the status bar) and
156 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700157 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800158 */
159 final Rect mContentInsets = new Rect();
160 final Rect mLastContentInsets = new Rect();
161 boolean mContentInsetsChanged;
162
163 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800164 * Insets that determine the area covered by the display overscan region. These are in the
165 * application's coordinate space (without compatibility scale applied).
166 */
167 final Rect mOverscanInsets = new Rect();
168 final Rect mLastOverscanInsets = new Rect();
169 boolean mOverscanInsetsChanged;
170
171 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800172 * Set to true if we are waiting for this window to receive its
173 * given internal insets before laying out other windows based on it.
174 */
175 boolean mGivenInsetsPending;
176
177 /**
178 * These are the content insets that were given during layout for
179 * this window, to be applied to windows behind it.
180 */
181 final Rect mGivenContentInsets = new Rect();
182
183 /**
184 * These are the visible insets that were given during layout for
185 * this window, to be applied to windows behind it.
186 */
187 final Rect mGivenVisibleInsets = new Rect();
188
189 /**
190 * This is the given touchable area relative to the window frame, or null if none.
191 */
192 final Region mGivenTouchableRegion = new Region();
193
194 /**
195 * Flag indicating whether the touchable region should be adjusted by
196 * the visible insets; if false the area outside the visible insets is
197 * NOT touchable, so we must use those to adjust the frame during hit
198 * tests.
199 */
200 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
201
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700202 /**
203 * This is rectangle of the window's surface that is not covered by
204 * system decorations.
205 */
206 final Rect mSystemDecorRect = new Rect();
207 final Rect mLastSystemDecorRect = new Rect();
208
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800209 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400210 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700211 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800212 float mHScale=1, mVScale=1;
213 float mLastHScale=1, mLastVScale=1;
214 final Matrix mTmpMatrix = new Matrix();
215
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700216 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800217 final Rect mFrame = new Rect();
218 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700219 // Frame that is scaled to the application's coordinate space when in
220 // screen size compatibility mode.
221 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800222
223 final Rect mContainingFrame = new Rect();
224 final Rect mDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800225 final Rect mOverscanFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800226 final Rect mContentFrame = new Rect();
227 final Rect mParentFrame = new Rect();
228 final Rect mVisibleFrame = new Rect();
229
230 boolean mContentChanged;
231
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800232 // If a window showing a wallpaper: the requested offset for the
233 // wallpaper; if a wallpaper window: the currently applied offset.
234 float mWallpaperX = -1;
235 float mWallpaperY = -1;
236
237 // If a window showing a wallpaper: what fraction of the offset
238 // range corresponds to a full virtual screen.
239 float mWallpaperXStep = -1;
240 float mWallpaperYStep = -1;
241
242 // Wallpaper windows: pixels offset based on above variables.
243 int mXOffset;
244 int mYOffset;
245
Craig Mautner2268e7e2012-12-13 15:40:00 -0800246 /**
247 * This is set after IWindowSession.relayout() has been called at
248 * least once for the window. It allows us to detect the situation
249 * where we don't yet have a surface, but should have one soon, so
250 * we can give the window focus before waiting for the relayout.
251 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800252 boolean mRelayoutCalled;
253
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800254 /**
255 * If the application has called relayout() with changes that can
256 * impact its window's size, we need to perform a layout pass on it
257 * even if it is not currently visible for layout. This is set
258 * when in that case until the layout is done.
259 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800260 boolean mLayoutNeeded;
261
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800262 /** Currently running an exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800263 boolean mExiting;
264
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800265 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800266 boolean mDestroying;
267
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800268 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800269 boolean mRemoveOnExit;
270
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800271 /**
272 * Set when the orientation is changing and this window has not yet
273 * been updated for the new orientation.
274 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800275 boolean mOrientationChanging;
276
Dianne Hackborna57c6952013-03-29 14:46:40 -0700277 /**
278 * How long we last kept the screen frozen.
279 */
280 int mLastFreezeDuration;
281
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800282 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800283 boolean mRemoved;
284
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800285 /**
286 * Temp for keeping track of windows that have been removed when
287 * rebuilding window list.
288 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800289 boolean mRebuilding;
290
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800291 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700292 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800293 InputChannel mInputChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800294
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800295 // Used to improve performance of toString()
296 String mStringNameCache;
297 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700298 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800299
Craig Mautnera2c77052012-03-26 12:14:43 -0700300 final WindowStateAnimator mWinAnimator;
301
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700302 boolean mHasSurface = false;
303
Craig Mautner59c00972012-07-30 12:10:24 -0700304 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700305
Craig Mautner88400d32012-09-30 12:35:45 -0700306 /** When true this window can be displayed on screens owther than mOwnerUid's */
307 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700308
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800309 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800310 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700311 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800312 mService = service;
313 mSession = s;
314 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800315 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800316 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700317 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800318 mWindowId = new IWindowId.Stub() {
319 @Override
320 public void registerFocusObserver(IWindowFocusObserver observer) {
321 WindowState.this.registerFocusObserver(observer);
322 }
323 @Override
324 public void unregisterFocusObserver(IWindowFocusObserver observer) {
325 WindowState.this.unregisterFocusObserver(observer);
326 }
327 @Override
328 public boolean isFocused() {
329 return WindowState.this.isFocused();
330 }
331 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800332 mAttrs.copyFrom(a);
333 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700334 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700335 mPolicy = mService.mPolicy;
336 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800337 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700338 mSeq = seq;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400339 mEnforceSizeCompat = (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800340 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700341 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700342 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800343 try {
344 c.asBinder().linkToDeath(deathRecipient, 0);
345 } catch (RemoteException e) {
346 mDeathRecipient = null;
347 mAttachedWindow = null;
348 mLayoutAttached = false;
349 mIsImWindow = false;
350 mIsWallpaper = false;
351 mIsFloatingLayer = false;
352 mBaseLayer = 0;
353 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700354 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700355 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800356 return;
357 }
358 mDeathRecipient = deathRecipient;
359
360 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
361 mAttrs.type <= LAST_SUB_WINDOW)) {
362 // The multiplier here is to reserve space for multiple
363 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700364 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800365 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
366 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700367 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800368 mAttachedWindow = attachedWindow;
Craig Mautnerd87946b2012-03-29 18:00:19 -0700369 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800370 mAttachedWindow.mChildWindows.add(this);
371 mLayoutAttached = mAttrs.type !=
372 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
373 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
374 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
375 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
376 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
377 } else {
378 // The multiplier here is to reserve space for multiple
379 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700380 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800381 * WindowManagerService.TYPE_LAYER_MULTIPLIER
382 + WindowManagerService.TYPE_LAYER_OFFSET;
383 mSubLayer = 0;
384 mAttachedWindow = null;
385 mLayoutAttached = false;
386 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
387 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
388 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
389 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
390 }
391
392 WindowState appWin = this;
393 while (appWin.mAttachedWindow != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700394 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800395 }
396 WindowToken appToken = appWin.mToken;
397 while (appToken.appWindowToken == null) {
398 WindowToken parent = mService.mTokenMap.get(appToken.token);
399 if (parent == null || appToken == parent) {
400 break;
401 }
402 appToken = parent;
403 }
404 mRootToken = appToken;
405 mAppToken = appToken.appWindowToken;
406
Craig Mautner322e4032012-07-13 13:35:20 -0700407 mWinAnimator = new WindowStateAnimator(this);
408 mWinAnimator.mAlpha = a.alpha;
409
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800410 mRequestedWidth = 0;
411 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700412 mLastRequestedWidth = 0;
413 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800414 mXOffset = 0;
415 mYOffset = 0;
416 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800417 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700418 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
419 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800420 }
421
422 void attach() {
423 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700424 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800425 + ", list=" + mToken.windows);
426 mSession.windowAddedLocked();
427 }
428
Craig Mautnera2c77052012-03-26 12:14:43 -0700429 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800430 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800431 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800432 }
433
434 @Override
435 public String getOwningPackage() {
436 return mAttrs.packageName;
437 }
438
439 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800440 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800441 mHaveFrame = true;
442
Craig Mautner967212c2013-04-13 21:10:58 -0700443 final int type = mAttrs.type;
444 if (mAppToken != null) {
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700445 mContainingFrame.set(getStackBounds());
Craig Mautner967212c2013-04-13 21:10:58 -0700446 } else {
447 mContainingFrame.set(pf);
448 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800449
Craig Mautnereda67292013-04-28 13:50:14 -0700450 mDisplayFrame.set(df);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800451
Craig Mautner967212c2013-04-13 21:10:58 -0700452 final int pw = mContainingFrame.width();
453 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800454
455 int w,h;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700456 if ((mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0) {
457 if (mAttrs.width < 0) {
458 w = pw;
459 } else if (mEnforceSizeCompat) {
460 w = (int)(mAttrs.width * mGlobalScale + .5f);
461 } else {
462 w = mAttrs.width;
463 }
464 if (mAttrs.height < 0) {
465 h = ph;
466 } else if (mEnforceSizeCompat) {
467 h = (int)(mAttrs.height * mGlobalScale + .5f);
468 } else {
469 h = mAttrs.height;
470 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800471 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700472 if (mAttrs.width == WindowManager.LayoutParams.MATCH_PARENT) {
473 w = pw;
474 } else if (mEnforceSizeCompat) {
475 w = (int)(mRequestedWidth * mGlobalScale + .5f);
476 } else {
477 w = mRequestedWidth;
478 }
479 if (mAttrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
480 h = ph;
481 } else if (mEnforceSizeCompat) {
482 h = (int)(mRequestedHeight * mGlobalScale + .5f);
483 } else {
484 h = mRequestedHeight;
485 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800486 }
487
488 if (!mParentFrame.equals(pf)) {
489 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
490 // + " to " + pf);
491 mParentFrame.set(pf);
492 mContentChanged = true;
493 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700494 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
495 mLastRequestedWidth = mRequestedWidth;
496 mLastRequestedHeight = mRequestedHeight;
497 mContentChanged = true;
498 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800499
Craig Mautnereda67292013-04-28 13:50:14 -0700500 mOverscanFrame.set(of);
501 mContentFrame.set(cf);
502 mVisibleFrame.set(vf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800503
Craig Mautnereda67292013-04-28 13:50:14 -0700504 final int fw = mFrame.width();
505 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800506
507 //System.out.println("In: w=" + w + " h=" + h + " container=" +
508 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
509
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700510 float x, y;
511 if (mEnforceSizeCompat) {
512 x = mAttrs.x * mGlobalScale;
513 y = mAttrs.y * mGlobalScale;
514 } else {
515 x = mAttrs.x;
516 y = mAttrs.y;
517 }
518
Craig Mautner967212c2013-04-13 21:10:58 -0700519 Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700520 (int) (x + mAttrs.horizontalMargin * pw),
Craig Mautnereda67292013-04-28 13:50:14 -0700521 (int) (y + mAttrs.verticalMargin * ph), mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800522
523 //System.out.println("Out: " + mFrame);
524
525 // Now make sure the window fits in the overall display.
Craig Mautnereda67292013-04-28 13:50:14 -0700526 Gravity.applyDisplay(mAttrs.gravity, df, mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800527
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800528 // Make sure the overscan, content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800529 // final window frame.
Craig Mautnereda67292013-04-28 13:50:14 -0700530 mOverscanFrame.set(Math.max(mOverscanFrame.left, mFrame.left),
531 Math.max(mOverscanFrame.top, mFrame.top),
532 Math.min(mOverscanFrame.right, mFrame.right),
533 Math.min(mOverscanFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800534
Craig Mautnereda67292013-04-28 13:50:14 -0700535 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
536 Math.max(mContentFrame.top, mFrame.top),
537 Math.min(mContentFrame.right, mFrame.right),
538 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800539
Craig Mautnereda67292013-04-28 13:50:14 -0700540 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
541 Math.max(mVisibleFrame.top, mFrame.top),
542 Math.min(mVisibleFrame.right, mFrame.right),
543 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800544
Craig Mautnereda67292013-04-28 13:50:14 -0700545 mOverscanInsets.set(mOverscanFrame.left - mFrame.left,
546 mOverscanFrame.top - mFrame.top,
547 mFrame.right - mOverscanFrame.right,
548 mFrame.bottom - mOverscanFrame.bottom);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800549
Craig Mautnereda67292013-04-28 13:50:14 -0700550 mContentInsets.set(mContentFrame.left - mFrame.left,
551 mContentFrame.top - mFrame.top,
552 mFrame.right - mContentFrame.right,
553 mFrame.bottom - mContentFrame.bottom);
554
555 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
556 mVisibleFrame.top - mFrame.top,
557 mFrame.right - mVisibleFrame.right,
558 mFrame.bottom - mVisibleFrame.bottom);
559
560 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400561 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700562 // If there is a size compatibility scale being applied to the
563 // window, we need to apply this to its insets so that they are
564 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700565 mOverscanInsets.scale(mInvGlobalScale);
566 mContentInsets.scale(mInvGlobalScale);
567 mVisibleInsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700568
569 // Also the scaled frame that we report to the app needs to be
570 // adjusted to be in its coordinate space.
571 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400572 }
573
Craig Mautnereda67292013-04-28 13:50:14 -0700574 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautner59c00972012-07-30 12:10:24 -0700575 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
576 mService.updateWallpaperOffsetLocked(this, displayInfo.appWidth, displayInfo.appHeight,
577 false);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800578 }
579
580 if (WindowManagerService.localLOGV) {
581 //if ("com.google.android.youtube".equals(mAttrs.packageName)
582 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700583 Slog.v(TAG, "Resolving (mRequestedWidth="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800584 + mRequestedWidth + ", mRequestedheight="
585 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
586 + "): frame=" + mFrame.toShortString()
Craig Mautnereda67292013-04-28 13:50:14 -0700587 + " ci=" + mContentInsets.toShortString()
588 + " vi=" + mVisibleInsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800589 //}
590 }
591 }
592
Craig Mautnera2c77052012-03-26 12:14:43 -0700593 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800594 public Rect getFrameLw() {
595 return mFrame;
596 }
597
Craig Mautnera2c77052012-03-26 12:14:43 -0700598 @Override
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700599 public RectF getShownFrameLw() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800600 return mShownFrame;
601 }
602
Craig Mautnera2c77052012-03-26 12:14:43 -0700603 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800604 public Rect getDisplayFrameLw() {
605 return mDisplayFrame;
606 }
607
Craig Mautnera2c77052012-03-26 12:14:43 -0700608 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800609 public Rect getOverscanFrameLw() {
610 return mOverscanFrame;
611 }
612
613 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800614 public Rect getContentFrameLw() {
615 return mContentFrame;
616 }
617
Craig Mautnera2c77052012-03-26 12:14:43 -0700618 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800619 public Rect getVisibleFrameLw() {
620 return mVisibleFrame;
621 }
622
Craig Mautnera2c77052012-03-26 12:14:43 -0700623 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800624 public boolean getGivenInsetsPendingLw() {
625 return mGivenInsetsPending;
626 }
627
Craig Mautnera2c77052012-03-26 12:14:43 -0700628 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800629 public Rect getGivenContentInsetsLw() {
630 return mGivenContentInsets;
631 }
632
Craig Mautnera2c77052012-03-26 12:14:43 -0700633 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800634 public Rect getGivenVisibleInsetsLw() {
635 return mGivenVisibleInsets;
636 }
637
Craig Mautnera2c77052012-03-26 12:14:43 -0700638 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800639 public WindowManager.LayoutParams getAttrs() {
640 return mAttrs;
641 }
642
Craig Mautner812d2ca2012-09-27 15:35:34 -0700643 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800644 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
645 int index = -1;
646 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700647 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800648 while (true) {
649 if ((ws.mAttrs.privateFlags
650 & WindowManager.LayoutParams.PRIVATE_FLAG_SET_NEEDS_MENU_KEY) != 0) {
651 return (ws.mAttrs.flags & WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0;
652 }
653 // If we reached the bottom of the range of windows we are considering,
654 // assume no menu is needed.
655 if (ws == bottom) {
656 return false;
657 }
658 // The current window hasn't specified whether menu key is needed;
659 // look behind it.
660 // First, we may need to determine the starting position.
661 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700662 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800663 }
664 index--;
665 if (index < 0) {
666 return false;
667 }
Craig Mautner59c00972012-07-30 12:10:24 -0700668 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800669 }
670 }
671
Craig Mautner19d59bc2012-09-04 11:15:56 -0700672 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700673 public int getSystemUiVisibility() {
674 return mSystemUiVisibility;
675 }
676
Craig Mautner19d59bc2012-09-04 11:15:56 -0700677 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800678 public int getSurfaceLayer() {
679 return mLayer;
680 }
681
Craig Mautner812d2ca2012-09-27 15:35:34 -0700682 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800683 public IApplicationToken getAppToken() {
684 return mAppToken != null ? mAppToken.appToken : null;
685 }
Craig Mautner19d59bc2012-09-04 11:15:56 -0700686
687 public int getDisplayId() {
688 return mDisplayContent.getDisplayId();
689 }
690
Craig Mautnerd9a22882013-03-16 15:00:36 -0700691 TaskStack getStack() {
692 if (mAppToken != null) {
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700693 Task task = mService.mTaskIdToTask.get(mAppToken.groupId);
694 if (task != null) {
695 return task.mStack;
696 }
Craig Mautnerd9a22882013-03-16 15:00:36 -0700697 }
698 return null;
699 }
700
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700701 Rect getStackBounds() {
702 TaskStack stack = getStack();
703 if (stack != null) {
704 return stack.mStackBox.mBounds;
705 }
706 return mFrame;
707 }
708
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800709 public long getInputDispatchingTimeoutNanos() {
710 return mAppToken != null
711 ? mAppToken.inputDispatchingTimeoutNanos
712 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
713 }
714
Craig Mautnere8552142012-11-07 13:55:47 -0800715 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800716 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -0700717 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800718 }
719
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800720 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
721 if (dsdx < .99999f || dsdx > 1.00001f) return false;
722 if (dtdy < .99999f || dtdy > 1.00001f) return false;
723 if (dtdx < -.000001f || dtdx > .000001f) return false;
724 if (dsdy < -.000001f || dsdy > .000001f) return false;
725 return true;
726 }
727
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400728 void prelayout() {
729 if (mEnforceSizeCompat) {
730 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700731 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400732 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700733 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400734 }
735 }
736
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800737 /**
738 * Is this window visible? It is not visible if there is no
739 * surface, or we are in the process of running an exit animation
740 * that will remove the surface, or its app token has been hidden.
741 */
Craig Mautner88400d32012-09-30 12:35:45 -0700742 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800743 public boolean isVisibleLw() {
744 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700745 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800746 && (atoken == null || !atoken.hiddenRequested)
747 && !mExiting && !mDestroying;
748 }
749
750 /**
751 * Like {@link #isVisibleLw}, but also counts a window that is currently
752 * "hidden" behind the keyguard as visible. This allows us to apply
753 * things like window flags that impact the keyguard.
754 * XXX I am starting to think we need to have ANOTHER visibility flag
755 * for this "hidden behind keyguard" state rather than overloading
756 * mPolicyVisibility. Ungh.
757 */
Craig Mautner88400d32012-09-30 12:35:45 -0700758 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800759 public boolean isVisibleOrBehindKeyguardLw() {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700760 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -0800761 mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700762 return false;
763 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800764 final AppWindowToken atoken = mAppToken;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700765 final boolean animating = atoken != null
Craig Mautner59431632012-04-04 11:56:44 -0700766 ? (atoken.mAppAnimator.animation != null) : false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700767 return mHasSurface && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800768 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700769 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
770 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -0700771 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800772 }
773
774 /**
775 * Is this window visible, ignoring its app token? It is not visible
776 * if there is no surface, or we are in the process of running an exit animation
777 * that will remove the surface.
778 */
779 public boolean isWinVisibleLw() {
780 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700781 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautner59431632012-04-04 11:56:44 -0700782 && (atoken == null || !atoken.hiddenRequested || atoken.mAppAnimator.animating)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800783 && !mExiting && !mDestroying;
784 }
785
786 /**
787 * The same as isVisible(), but follows the current hidden state of
788 * the associated app token, not the pending requested hidden state.
789 */
790 boolean isVisibleNow() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700791 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800792 && !mRootToken.hidden && !mExiting && !mDestroying;
793 }
794
795 /**
796 * Can this window possibly be a drag/drop target? The test here is
797 * a combination of the above "visible now" with the check that the
798 * Input Manager uses when discarding windows from input consideration.
799 */
800 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -0700801 return isVisibleNow() && !mRemoved
802 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800803 }
804
805 /**
806 * Same as isVisible(), but we also count it as visible between the
807 * call to IWindowSession.add() and the first relayout().
808 */
809 boolean isVisibleOrAdding() {
810 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -0700811 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800812 && mPolicyVisibility && !mAttachedHidden
813 && (atoken == null || !atoken.hiddenRequested)
814 && !mExiting && !mDestroying;
815 }
816
817 /**
818 * Is this window currently on-screen? It is on-screen either if it
819 * is visible or it is currently running an animation before no longer
820 * being visible.
821 */
822 boolean isOnScreen() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700823 if (!mHasSurface || !mPolicyVisibility || mDestroying) {
824 return false;
825 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800826 final AppWindowToken atoken = mAppToken;
827 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700828 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -0800829 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800830 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700831 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800832 }
833
834 /**
835 * Like isOnScreen(), but we don't return true if the window is part
836 * of a transition that has not yet been started.
837 */
838 boolean isReadyForDisplay() {
839 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -0800840 mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800841 return false;
842 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700843 return mHasSurface && mPolicyVisibility && !mDestroying
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800844 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
845 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -0700846 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -0700847 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800848 }
849
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800850 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700851 * Like isReadyForDisplay(), but ignores any force hiding of the window due
852 * to the keyguard.
853 */
854 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800855 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700856 return false;
857 }
858 final AppWindowToken atoken = mAppToken;
859 if (atoken == null && !mPolicyVisibility) {
860 // If this is not an app window, and the policy has asked to force
861 // hide, then we really do want to hide.
862 return false;
863 }
864 return mHasSurface && !mDestroying
865 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
866 && !mRootToken.hidden)
867 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -0700868 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
869 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700870 }
871
872 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800873 * Like isOnScreen, but returns false if the surface hasn't yet
874 * been drawn.
875 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -0700876 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800877 public boolean isDisplayedLw() {
878 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700879 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800880 && ((!mAttachedHidden &&
881 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -0700882 || mWinAnimator.mAnimating
883 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800884 }
885
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700886 /**
Craig Mautnerae446592012-12-06 19:05:05 -0800887 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700888 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -0700889 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700890 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -0800891 return mWinAnimator.mAnimation != null
892 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700893 }
894
Craig Mautner812d2ca2012-09-27 15:35:34 -0700895 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -0800896 public boolean isGoneForLayoutLw() {
897 final AppWindowToken atoken = mAppToken;
898 return mViewVisibility == View.GONE
899 || !mRelayoutCalled
900 || (atoken == null && mRootToken.hidden)
Craig Mautner812d2ca2012-09-27 15:35:34 -0700901 || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
Dianne Hackborncfbf7de2012-01-12 14:05:03 -0800902 || mAttachedHidden
Craig Mautner0e415c62013-04-29 16:10:58 -0700903 || (mExiting && !isAnimatingLw())
904 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -0800905 }
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 Mautnerfb32c6e2013-02-12 15:08:44 -08001141 public void 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 Mautnerfb32c6e2013-02-12 15:08:44 -08001151 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001152 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001153 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001154 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001155 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001156 }
1157
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001158 @Override
1159 public boolean isAlive() {
1160 return mClient.asBinder().isBinderAlive();
1161 }
1162
Craig Mautnera987d432012-10-11 14:07:58 -07001163 boolean isClosing() {
1164 return mExiting || (mService.mClosingApps.contains(mAppToken));
1165 }
1166
Craig Mautner69b08182012-09-05 13:07:13 -07001167 @Override
1168 public boolean isDefaultDisplay() {
1169 return mDisplayContent.isDefaultDisplay;
1170 }
1171
Craig Mautner88400d32012-09-30 12:35:45 -07001172 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
1173 mShowToOwnerOnly = showToOwnerOnly;
1174 }
1175
Craig Mautner5962b122012-10-05 14:45:52 -07001176 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07001177 // Attached windows are evaluated based on the window that they are attached to.
1178 WindowState win = this;
1179 while (win.mAttachedWindow != null) {
1180 win = win.mAttachedWindow;
1181 }
1182 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1183 && win.mAppToken != null && win.mAppToken.showWhenLocked) {
1184 // Save some cycles by not calling getDisplayInfo unless it is an application
1185 // window intended for all users.
1186 final DisplayInfo displayInfo = win.mDisplayContent.getDisplayInfo();
1187 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
1188 && win.mFrame.right >= displayInfo.appWidth
1189 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07001190 // Is a fullscreen window, like the clock alarm. Show to everyone.
1191 return false;
1192 }
1193 }
1194
Craig Mautner341220f2012-10-16 15:20:09 -07001195 return win.mShowToOwnerOnly
1196 && UserHandle.getUserId(win.mOwnerUid) != mService.mCurrentUserId;
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001197 }
1198
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001199 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
1200 outRegion.set(
1201 frame.left + inset.left, frame.top + inset.top,
1202 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001203 }
1204
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001205 public void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001206 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001207 switch (mTouchableInsets) {
1208 default:
1209 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
1210 outRegion.set(frame);
1211 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001212 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001213 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001214 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001215 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001216 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001217 break;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001218 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
1219 final Region givenTouchableRegion = mGivenTouchableRegion;
1220 outRegion.set(givenTouchableRegion);
1221 outRegion.translate(frame.left, frame.top);
1222 break;
1223 }
1224 }
1225 }
1226
Craig Mautner59c00972012-07-30 12:10:24 -07001227 WindowList getWindowList() {
1228 return mDisplayContent.getWindowList();
1229 }
1230
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001231 /**
1232 * Report a focus change. Must be called with no locks held, and consistently
1233 * from the same serialized thread (such as dispatched from a handler).
1234 */
1235 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
1236 try {
1237 mClient.windowFocusChanged(focused, inTouchMode);
1238 } catch (RemoteException e) {
1239 }
1240 if (mFocusCallbacks != null) {
1241 final int N = mFocusCallbacks.beginBroadcast();
1242 for (int i=0; i<N; i++) {
1243 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
1244 try {
1245 if (focused) {
1246 obs.focusGained(mWindowId.asBinder());
1247 } else {
1248 obs.focusLost(mWindowId.asBinder());
1249 }
1250 } catch (RemoteException e) {
1251 }
1252 }
1253 mFocusCallbacks.finishBroadcast();
1254 }
1255 }
1256
1257 public void registerFocusObserver(IWindowFocusObserver observer) {
1258 synchronized(mService.mWindowMap) {
1259 if (mFocusCallbacks == null) {
1260 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
1261 }
1262 mFocusCallbacks.register(observer);
1263 }
1264 }
1265
1266 public void unregisterFocusObserver(IWindowFocusObserver observer) {
1267 synchronized(mService.mWindowMap) {
1268 if (mFocusCallbacks != null) {
1269 mFocusCallbacks.unregister(observer);
1270 }
1271 }
1272 }
1273
1274 public boolean isFocused() {
1275 synchronized(mService.mWindowMap) {
1276 return mService.mCurrentFocus == this;
1277 }
1278 }
1279
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001280 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Craig Mautner59c00972012-07-30 12:10:24 -07001281 pw.print(prefix); pw.print("mDisplayId="); pw.print(mDisplayContent.getDisplayId());
1282 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001283 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07001284 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08001285 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
1286 pw.print(" package="); pw.print(mAttrs.packageName);
1287 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001288 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001289 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
1290 pw.print(" h="); pw.print(mRequestedHeight);
1291 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07001292 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
1293 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
1294 pw.print(" h="); pw.println(mLastRequestedHeight);
1295 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001296 if (mAttachedWindow != null || mLayoutAttached) {
1297 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
1298 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
1299 }
1300 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
1301 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
1302 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
1303 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
1304 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
1305 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001306 if (dumpAll) {
1307 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
1308 pw.print(" mSubLayer="); pw.print(mSubLayer);
1309 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07001310 pw.print((mTargetAppToken != null ?
1311 mTargetAppToken.mAppAnimator.animLayerAdjustment
1312 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001313 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
1314 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08001315 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001316 if (dumpAll) {
1317 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
1318 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
1319 if (mAppToken != null) {
1320 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
1321 }
1322 if (mTargetAppToken != null) {
1323 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
1324 }
1325 pw.print(prefix); pw.print("mViewVisibility=0x");
1326 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001327 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
1328 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001329 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
1330 pw.print(" mSystemUiVisibility=0x");
1331 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001332 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001333 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
1334 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001335 pw.print(prefix); pw.print("mPolicyVisibility=");
1336 pw.print(mPolicyVisibility);
1337 pw.print(" mPolicyVisibilityAfterAnim=");
1338 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001339 pw.print(" mAppOpVisibility=");
1340 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001341 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
1342 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08001343 if (!mRelayoutCalled || mLayoutNeeded) {
1344 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
1345 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001346 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001347 if (mXOffset != 0 || mYOffset != 0) {
1348 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
1349 pw.print(" y="); pw.println(mYOffset);
1350 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001351 if (dumpAll) {
1352 pw.print(prefix); pw.print("mGivenContentInsets=");
1353 mGivenContentInsets.printShortString(pw);
1354 pw.print(" mGivenVisibleInsets=");
1355 mGivenVisibleInsets.printShortString(pw);
1356 pw.println();
1357 if (mTouchableInsets != 0 || mGivenInsetsPending) {
1358 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
1359 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001360 Region region = new Region();
1361 getTouchableRegion(region);
1362 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001363 }
1364 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001365 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001366 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Craig Mautner178af592012-09-17 10:37:29 -07001367 pw.print(" mShownFrame="); mShownFrame.printShortString(pw);
1368 pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001369 if (dumpAll) {
1370 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
1371 pw.print(" last="); mLastFrame.printShortString(pw);
1372 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001373 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
1374 pw.print(" last="); mLastSystemDecorRect.printShortString(pw);
1375 pw.println();
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001376 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001377 if (mEnforceSizeCompat) {
1378 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001379 pw.println();
1380 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001381 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001382 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001383 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001384 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001385 pw.println();
1386 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
1387 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001388 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001389 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001390 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001391 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001392 pw.print(prefix); pw.print("Cur insets: overscan=");
1393 mOverscanInsets.printShortString(pw);
1394 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001395 pw.print(" visible="); mVisibleInsets.printShortString(pw);
1396 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001397 pw.print(prefix); pw.print("Lst insets: overscan=");
1398 mLastOverscanInsets.printShortString(pw);
1399 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001400 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001401 pw.println();
1402 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07001403 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
1404 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001405 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
1406 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
1407 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
1408 pw.print(" mDestroying="); pw.print(mDestroying);
1409 pw.print(" mRemoved="); pw.println(mRemoved);
1410 }
1411 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
1412 pw.print(prefix); pw.print("mOrientationChanging=");
1413 pw.print(mOrientationChanging);
1414 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
1415 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
1416 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07001417 if (mLastFreezeDuration != 0) {
1418 pw.print(prefix); pw.print("mLastFreezeDuration=");
1419 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
1420 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001421 if (mHScale != 1 || mVScale != 1) {
1422 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
1423 pw.print(" mVScale="); pw.println(mVScale);
1424 }
1425 if (mWallpaperX != -1 || mWallpaperY != -1) {
1426 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
1427 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
1428 }
1429 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
1430 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
1431 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
1432 }
1433 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001434
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001435 String makeInputChannelName() {
1436 return Integer.toHexString(System.identityHashCode(this))
1437 + " " + mAttrs.getTitle();
1438 }
1439
1440 @Override
1441 public String toString() {
Dianne Hackbornc2293022013-02-06 23:14:49 -08001442 CharSequence title = mAttrs.getTitle();
1443 if (title == null || title.length() <= 0) {
1444 title = mAttrs.packageName;
1445 }
1446 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
1447 mLastTitle = title;
Dianne Hackborn529e7442012-11-01 14:22:28 -07001448 mWasExiting = mExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001449 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07001450 + " u" + UserHandle.getUserId(mSession.mUid)
Craig Mautnera987d432012-10-11 14:07:58 -07001451 + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001452 }
1453 return mStringNameCache;
1454 }
satokcef37fb2011-10-24 21:49:38 +09001455}