blob: 989fe2aa1b126bd6f7bcd3a6dd5d498ebb5ca90b [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 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;
18
19import static android.os.LocalPowerManager.CHEEK_EVENT;
20import static android.os.LocalPowerManager.OTHER_EVENT;
21import static android.os.LocalPowerManager.TOUCH_EVENT;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -070022import static android.os.LocalPowerManager.LONG_TOUCH_EVENT;
23import static android.os.LocalPowerManager.TOUCH_UP_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
25import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
26import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070027import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
29import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070030import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
32import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
33import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070034import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
36import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
38import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
39import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
40import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
41import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070042import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
44import com.android.internal.app.IBatteryStats;
45import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080046import com.android.internal.policy.impl.PhoneWindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import com.android.internal.view.IInputContext;
48import com.android.internal.view.IInputMethodClient;
49import com.android.internal.view.IInputMethodManager;
50import com.android.server.KeyInputQueue.QueuedEvent;
51import com.android.server.am.BatteryStatsService;
52
53import android.Manifest;
54import android.app.ActivityManagerNative;
55import android.app.IActivityManager;
56import android.content.Context;
57import android.content.pm.ActivityInfo;
58import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070059import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.content.res.Configuration;
61import android.graphics.Matrix;
62import android.graphics.PixelFormat;
63import android.graphics.Rect;
64import android.graphics.Region;
65import android.os.BatteryStats;
66import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070067import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import android.os.Debug;
69import android.os.Handler;
70import android.os.IBinder;
Michael Chan53071d62009-05-13 17:29:48 -070071import android.os.LatencyTimer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.LocalPowerManager;
73import android.os.Looper;
74import android.os.Message;
75import android.os.Parcel;
76import android.os.ParcelFileDescriptor;
77import android.os.Power;
78import android.os.PowerManager;
79import android.os.Process;
80import android.os.RemoteException;
81import android.os.ServiceManager;
82import android.os.SystemClock;
83import android.os.SystemProperties;
84import android.os.TokenWatcher;
85import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070086import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087import android.util.EventLog;
Joe Onorato8a9b2202010-02-26 18:56:32 -080088import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089import android.util.SparseIntArray;
90import android.view.Display;
91import android.view.Gravity;
92import android.view.IApplicationToken;
93import android.view.IOnKeyguardExitResult;
94import android.view.IRotationWatcher;
95import android.view.IWindow;
96import android.view.IWindowManager;
97import android.view.IWindowSession;
98import android.view.KeyEvent;
99import android.view.MotionEvent;
100import android.view.RawInputEvent;
101import android.view.Surface;
102import android.view.SurfaceSession;
103import android.view.View;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -0700104import android.view.ViewConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105import android.view.ViewTreeObserver;
106import android.view.WindowManager;
107import android.view.WindowManagerImpl;
108import android.view.WindowManagerPolicy;
109import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700110import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111import android.view.animation.Animation;
112import android.view.animation.AnimationUtils;
113import android.view.animation.Transformation;
114
115import java.io.BufferedWriter;
116import java.io.File;
117import java.io.FileDescriptor;
118import java.io.IOException;
119import java.io.OutputStream;
120import java.io.OutputStreamWriter;
121import java.io.PrintWriter;
122import java.io.StringWriter;
123import java.net.Socket;
124import java.util.ArrayList;
125import java.util.HashMap;
126import java.util.HashSet;
127import java.util.Iterator;
128import java.util.List;
129
130/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700131public class WindowManagerService extends IWindowManager.Stub
132 implements Watchdog.Monitor, KeyInputQueue.HapticFeedbackCallback {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 static final String TAG = "WindowManager";
134 static final boolean DEBUG = false;
135 static final boolean DEBUG_FOCUS = false;
136 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800137 static final boolean DEBUG_LAYOUT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 static final boolean DEBUG_LAYERS = false;
139 static final boolean DEBUG_INPUT = false;
140 static final boolean DEBUG_INPUT_METHOD = false;
141 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700142 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 static final boolean DEBUG_ORIENTATION = false;
144 static final boolean DEBUG_APP_TRANSITIONS = false;
145 static final boolean DEBUG_STARTING_WINDOW = false;
146 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700147 static final boolean DEBUG_WALLPAPER = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700149 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700150 static final boolean MEASURE_LATENCY = false;
151 static private LatencyTimer lt;
152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 static final boolean PROFILE_ORIENTATION = false;
154 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700155 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 /** How long to wait for subsequent key repeats, in milliseconds */
158 static final int KEY_REPEAT_DELAY = 50;
159
160 /** How much to multiply the policy's type layer, to reserve room
161 * for multiple windows of the same type and Z-ordering adjustment
162 * with TYPE_LAYER_OFFSET. */
163 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
166 * or below others in the same layer. */
167 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 /** How much to increment the layer for each window, to reserve room
170 * for effect surfaces between them.
171 */
172 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 /** The maximum length we will accept for a loaded animation duration:
175 * this is 10 seconds.
176 */
177 static final int MAX_ANIMATION_DURATION = 10*1000;
178
179 /** Amount of time (in milliseconds) to animate the dim surface from one
180 * value to another, when no window animation is driving it.
181 */
182 static final int DEFAULT_DIM_DURATION = 200;
183
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700184 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
185 * compatible windows.
186 */
187 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 /** Adjustment to time to perform a dim, to make it more dramatic.
190 */
191 static final int DIM_DURATION_MULTIPLIER = 6;
Romain Guy06882f82009-06-10 13:36:04 -0700192
Dianne Hackborncfaef692009-06-15 14:24:44 -0700193 static final int INJECT_FAILED = 0;
194 static final int INJECT_SUCCEEDED = 1;
195 static final int INJECT_NO_PERMISSION = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 static final int UPDATE_FOCUS_NORMAL = 0;
198 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
199 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
200 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700201
Michael Chane96440f2009-05-06 10:27:36 -0700202 /** The minimum time between dispatching touch events. */
203 int mMinWaitTimeBetweenTouchEvents = 1000 / 35;
204
205 // Last touch event time
206 long mLastTouchEventTime = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700207
Michael Chane96440f2009-05-06 10:27:36 -0700208 // Last touch event type
209 int mLastTouchEventType = OTHER_EVENT;
Romain Guy06882f82009-06-10 13:36:04 -0700210
Michael Chane96440f2009-05-06 10:27:36 -0700211 // Time to wait before calling useractivity again. This saves CPU usage
212 // when we get a flood of touch events.
213 static final int MIN_TIME_BETWEEN_USERACTIVITIES = 1000;
214
215 // Last time we call user activity
216 long mLastUserActivityCallTime = 0;
217
Romain Guy06882f82009-06-10 13:36:04 -0700218 // Last time we updated battery stats
Michael Chane96440f2009-05-06 10:27:36 -0700219 long mLastBatteryStatsCallTime = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700222 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223
224 /**
225 * Condition waited on by {@link #reenableKeyguard} to know the call to
226 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500227 * This is set to true only if mKeyguardTokenWatcher.acquired() has
228 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500230 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231
Mike Lockwood983ee092009-11-22 01:42:24 -0500232 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
233 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800234 public void acquired() {
235 mPolicy.enableKeyguard(false);
Mike Lockwood983ee092009-11-22 01:42:24 -0500236 mKeyguardDisabled = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 }
238 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700239 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500240 synchronized (mKeyguardTokenWatcher) {
241 mKeyguardDisabled = false;
242 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 }
244 }
245 };
246
247 final Context mContext;
248
249 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
254
255 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 /**
260 * All currently active sessions with clients.
261 */
262 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264 /**
265 * Mapping from an IWindow IBinder to the server's Window object.
266 * This is also used as the lock for all of our state.
267 */
268 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
269
270 /**
271 * Mapping from a token IBinder to a WindowToken object.
272 */
273 final HashMap<IBinder, WindowToken> mTokenMap =
274 new HashMap<IBinder, WindowToken>();
275
276 /**
277 * The same tokens as mTokenMap, stored in a list for efficient iteration
278 * over them.
279 */
280 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282 /**
283 * Window tokens that are in the process of exiting, but still
284 * on screen for animations.
285 */
286 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
287
288 /**
289 * Z-ordered (bottom-most first) list of all application tokens, for
290 * controlling the ordering of windows in different applications. This
291 * contains WindowToken objects.
292 */
293 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
294
295 /**
296 * Application tokens that are in the process of exiting, but still
297 * on screen for animations.
298 */
299 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
300
301 /**
302 * List of window tokens that have finished starting their application,
303 * and now need to have the policy remove their windows.
304 */
305 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
306
307 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700308 * This was the app token that was used to retrieve the last enter
309 * animation. It will be used for the next exit animation.
310 */
311 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800312
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700313 /**
314 * These were the layout params used to retrieve the last enter animation.
315 * They will be used for the next exit animation.
316 */
317 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800318
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700319 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320 * Z-ordered (bottom-most first) list of all Window objects.
321 */
322 final ArrayList mWindows = new ArrayList();
323
324 /**
325 * Windows that are being resized. Used so we can tell the client about
326 * the resize after closing the transaction in which we resized the
327 * underlying surface.
328 */
329 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
330
331 /**
332 * Windows whose animations have ended and now must be removed.
333 */
334 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
335
336 /**
337 * Windows whose surface should be destroyed.
338 */
339 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
340
341 /**
342 * Windows that have lost input focus and are waiting for the new
343 * focus window to be displayed before they are told about this.
344 */
345 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
346
347 /**
348 * This is set when we have run out of memory, and will either be an empty
349 * list or contain windows that need to be force removed.
350 */
351 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700356 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 Surface mBlurSurface;
358 boolean mBlurShown;
Romain Guy06882f82009-06-10 13:36:04 -0700359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800362 final float[] mTmpFloats = new float[9];
363
364 boolean mSafeMode;
365 boolean mDisplayEnabled = false;
366 boolean mSystemBooted = false;
367 int mRotation = 0;
368 int mRequestedRotation = 0;
369 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700370 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 ArrayList<IRotationWatcher> mRotationWatchers
372 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 boolean mLayoutNeeded = true;
375 boolean mAnimationPending = false;
376 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800377 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 boolean mWindowsFreezingScreen = false;
379 long mFreezeGcPending = 0;
380 int mAppsFreezingScreen = 0;
381
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800382 int mLayoutSeq = 0;
383
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800384 // State while inside of layoutAndPlaceSurfacesLocked().
385 boolean mFocusMayChange;
386
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800387 Configuration mCurConfiguration = new Configuration();
388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 // This is held as long as we have the screen frozen, to give us time to
390 // perform a rotation animation when turning off shows the lock screen which
391 // changes the orientation.
392 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 // State management of app transitions. When we are preparing for a
395 // transition, mNextAppTransition will be the kind of transition to
396 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
397 // mOpeningApps and mClosingApps are the lists of tokens that will be
398 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700399 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700400 String mNextAppTransitionPackage;
401 int mNextAppTransitionEnter;
402 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700404 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 boolean mAppTransitionTimeout = false;
406 boolean mStartingIconInTransition = false;
407 boolean mSkipAppTransitionAnimation = false;
408 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
409 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700410 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
411 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 //flag to detect fat touch events
414 boolean mFatTouch = false;
415 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417 H mH = new H();
418
419 WindowState mCurrentFocus = null;
420 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 // This just indicates the window the input method is on top of, not
423 // necessarily the window its input is going to.
424 WindowState mInputMethodTarget = null;
425 WindowState mUpcomingInputMethodTarget = null;
426 boolean mInputMethodTargetWaitingAnim;
427 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 WindowState mInputMethodWindow = null;
430 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
431
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700432 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800433
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700434 // If non-null, this is the currently visible window that is associated
435 // with the wallpaper.
436 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700437 // If non-null, we are in the middle of animating from one wallpaper target
438 // to another, and this is the lower one in Z-order.
439 WindowState mLowerWallpaperTarget = null;
440 // If non-null, we are in the middle of animating from one wallpaper target
441 // to another, and this is the higher one in Z-order.
442 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700443 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700444 float mLastWallpaperX = -1;
445 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800446 float mLastWallpaperXStep = -1;
447 float mLastWallpaperYStep = -1;
Dianne Hackborn6adba242009-11-10 11:10:09 -0800448 boolean mSendingPointersToWallpaper = false;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700449 // This is set when we are waiting for a wallpaper to tell us it is done
450 // changing its scroll position.
451 WindowState mWaitingOnWallpaper;
452 // The last time we had a timeout when waiting for a wallpaper.
453 long mLastWallpaperTimeoutTime;
454 // We give a wallpaper up to 150ms to finish scrolling.
455 static final long WALLPAPER_TIMEOUT = 150;
456 // Time we wait after a timeout before trying to wait again.
457 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 AppWindowToken mFocusedApp = null;
460
461 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800463 float mWindowAnimationScale = 1.0f;
464 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466 final KeyWaiter mKeyWaiter = new KeyWaiter();
467 final KeyQ mQueue;
468 final InputDispatcherThread mInputThread;
469
470 // Who is holding the screen on.
471 Session mHoldingScreenOn;
Romain Guy06882f82009-06-10 13:36:04 -0700472
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700473 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 /**
476 * Whether the UI is currently running in touch mode (not showing
477 * navigational focus because the user is directly pressing the screen).
478 */
479 boolean mInTouchMode = false;
480
481 private ViewServer mViewServer;
482
483 final Rect mTempRect = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -0700484
Dianne Hackbornc485a602009-03-24 22:39:49 -0700485 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700486 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700487
488 // The frame use to limit the size of the app running in compatibility mode.
489 Rect mCompatibleScreenFrame = new Rect();
490 // The surface used to fill the outer rim of the app running in compatibility mode.
491 Surface mBackgroundFillerSurface = null;
492 boolean mBackgroundFillerShown = false;
493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494 public static WindowManagerService main(Context context,
495 PowerManagerService pm, boolean haveInputMethods) {
496 WMThread thr = new WMThread(context, pm, haveInputMethods);
497 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800499 synchronized (thr) {
500 while (thr.mService == null) {
501 try {
502 thr.wait();
503 } catch (InterruptedException e) {
504 }
505 }
506 }
Romain Guy06882f82009-06-10 13:36:04 -0700507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 return thr.mService;
509 }
Romain Guy06882f82009-06-10 13:36:04 -0700510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 static class WMThread extends Thread {
512 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 private final Context mContext;
515 private final PowerManagerService mPM;
516 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 public WMThread(Context context, PowerManagerService pm,
519 boolean haveInputMethods) {
520 super("WindowManager");
521 mContext = context;
522 mPM = pm;
523 mHaveInputMethods = haveInputMethods;
524 }
Romain Guy06882f82009-06-10 13:36:04 -0700525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800526 public void run() {
527 Looper.prepare();
528 WindowManagerService s = new WindowManagerService(mContext, mPM,
529 mHaveInputMethods);
530 android.os.Process.setThreadPriority(
531 android.os.Process.THREAD_PRIORITY_DISPLAY);
Romain Guy06882f82009-06-10 13:36:04 -0700532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 synchronized (this) {
534 mService = s;
535 notifyAll();
536 }
Romain Guy06882f82009-06-10 13:36:04 -0700537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538 Looper.loop();
539 }
540 }
541
542 static class PolicyThread extends Thread {
543 private final WindowManagerPolicy mPolicy;
544 private final WindowManagerService mService;
545 private final Context mContext;
546 private final PowerManagerService mPM;
547 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 public PolicyThread(WindowManagerPolicy policy,
550 WindowManagerService service, Context context,
551 PowerManagerService pm) {
552 super("WindowManagerPolicy");
553 mPolicy = policy;
554 mService = service;
555 mContext = context;
556 mPM = pm;
557 }
Romain Guy06882f82009-06-10 13:36:04 -0700558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559 public void run() {
560 Looper.prepare();
561 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800562 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 android.os.Process.setThreadPriority(
564 android.os.Process.THREAD_PRIORITY_FOREGROUND);
565 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 synchronized (this) {
568 mRunning = true;
569 notifyAll();
570 }
Romain Guy06882f82009-06-10 13:36:04 -0700571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 Looper.loop();
573 }
574 }
575
576 private WindowManagerService(Context context, PowerManagerService pm,
577 boolean haveInputMethods) {
Michael Chan53071d62009-05-13 17:29:48 -0700578 if (MEASURE_LATENCY) {
579 lt = new LatencyTimer(100, 1000);
580 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 mContext = context;
583 mHaveInputMethods = haveInputMethods;
584 mLimitedAlphaCompositing = context.getResources().getBoolean(
585 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 mPowerManager = pm;
588 mPowerManager.setPolicy(mPolicy);
589 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
590 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
591 "SCREEN_FROZEN");
592 mScreenFrozenLock.setReferenceCounted(false);
593
594 mActivityManager = ActivityManagerNative.getDefault();
595 mBatteryStats = BatteryStatsService.getService();
596
597 // Get persisted window scale setting
598 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
599 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
600 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
601 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700602
Michael Chan9f028e62009-08-04 17:37:46 -0700603 int max_events_per_sec = 35;
604 try {
605 max_events_per_sec = Integer.parseInt(SystemProperties
606 .get("windowsmgr.max_events_per_sec"));
607 if (max_events_per_sec < 1) {
608 max_events_per_sec = 35;
609 }
610 } catch (NumberFormatException e) {
611 }
612 mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec;
613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 mQueue = new KeyQ();
615
616 mInputThread = new InputDispatcherThread();
Romain Guy06882f82009-06-10 13:36:04 -0700617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
619 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 synchronized (thr) {
622 while (!thr.mRunning) {
623 try {
624 thr.wait();
625 } catch (InterruptedException e) {
626 }
627 }
628 }
Romain Guy06882f82009-06-10 13:36:04 -0700629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630 mInputThread.start();
Romain Guy06882f82009-06-10 13:36:04 -0700631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 // Add ourself to the Watchdog monitors.
633 Watchdog.getInstance().addMonitor(this);
634 }
635
636 @Override
637 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
638 throws RemoteException {
639 try {
640 return super.onTransact(code, data, reply, flags);
641 } catch (RuntimeException e) {
642 // The window manager only throws security exceptions, so let's
643 // log all others.
644 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800645 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800646 }
647 throw e;
648 }
649 }
650
651 private void placeWindowAfter(Object pos, WindowState window) {
652 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800653 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654 TAG, "Adding window " + window + " at "
655 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
656 mWindows.add(i+1, window);
657 }
658
659 private void placeWindowBefore(Object pos, WindowState window) {
660 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800661 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 TAG, "Adding window " + window + " at "
663 + i + " of " + mWindows.size() + " (before " + pos + ")");
664 mWindows.add(i, window);
665 }
666
667 //This method finds out the index of a window that has the same app token as
668 //win. used for z ordering the windows in mWindows
669 private int findIdxBasedOnAppTokens(WindowState win) {
670 //use a local variable to cache mWindows
671 ArrayList localmWindows = mWindows;
672 int jmax = localmWindows.size();
673 if(jmax == 0) {
674 return -1;
675 }
676 for(int j = (jmax-1); j >= 0; j--) {
677 WindowState wentry = (WindowState)localmWindows.get(j);
678 if(wentry.mAppToken == win.mAppToken) {
679 return j;
680 }
681 }
682 return -1;
683 }
Romain Guy06882f82009-06-10 13:36:04 -0700684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800685 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
686 final IWindow client = win.mClient;
687 final WindowToken token = win.mToken;
688 final ArrayList localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800690 final int N = localmWindows.size();
691 final WindowState attached = win.mAttachedWindow;
692 int i;
693 if (attached == null) {
694 int tokenWindowsPos = token.windows.size();
695 if (token.appWindowToken != null) {
696 int index = tokenWindowsPos-1;
697 if (index >= 0) {
698 // If this application has existing windows, we
699 // simply place the new window on top of them... but
700 // keep the starting window on top.
701 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
702 // Base windows go behind everything else.
703 placeWindowBefore(token.windows.get(0), win);
704 tokenWindowsPos = 0;
705 } else {
706 AppWindowToken atoken = win.mAppToken;
707 if (atoken != null &&
708 token.windows.get(index) == atoken.startingWindow) {
709 placeWindowBefore(token.windows.get(index), win);
710 tokenWindowsPos--;
711 } else {
712 int newIdx = findIdxBasedOnAppTokens(win);
713 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700714 //there is a window above this one associated with the same
715 //apptoken note that the window could be a floating window
716 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800717 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800718 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700719 TAG, "Adding window " + win + " at "
720 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800721 localmWindows.add(newIdx+1, win);
Romain Guy06882f82009-06-10 13:36:04 -0700722 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800723 }
724 }
725 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800726 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727 TAG, "Figuring out where to add app window "
728 + client.asBinder() + " (token=" + token + ")");
729 // Figure out where the window should go, based on the
730 // order of applications.
731 final int NA = mAppTokens.size();
732 Object pos = null;
733 for (i=NA-1; i>=0; i--) {
734 AppWindowToken t = mAppTokens.get(i);
735 if (t == token) {
736 i--;
737 break;
738 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800739
Dianne Hackborna8f60182009-09-01 19:01:50 -0700740 // We haven't reached the token yet; if this token
741 // is not going to the bottom and has windows, we can
742 // use it as an anchor for when we do reach the token.
743 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 pos = t.windows.get(0);
745 }
746 }
747 // We now know the index into the apps. If we found
748 // an app window above, that gives us the position; else
749 // we need to look some more.
750 if (pos != null) {
751 // Move behind any windows attached to this one.
Romain Guy06882f82009-06-10 13:36:04 -0700752 WindowToken atoken =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753 mTokenMap.get(((WindowState)pos).mClient.asBinder());
754 if (atoken != null) {
755 final int NC = atoken.windows.size();
756 if (NC > 0) {
757 WindowState bottom = atoken.windows.get(0);
758 if (bottom.mSubLayer < 0) {
759 pos = bottom;
760 }
761 }
762 }
763 placeWindowBefore(pos, win);
764 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700765 // Continue looking down until we find the first
766 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767 while (i >= 0) {
768 AppWindowToken t = mAppTokens.get(i);
769 final int NW = t.windows.size();
770 if (NW > 0) {
771 pos = t.windows.get(NW-1);
772 break;
773 }
774 i--;
775 }
776 if (pos != null) {
777 // Move in front of any windows attached to this
778 // one.
779 WindowToken atoken =
780 mTokenMap.get(((WindowState)pos).mClient.asBinder());
781 if (atoken != null) {
782 final int NC = atoken.windows.size();
783 if (NC > 0) {
784 WindowState top = atoken.windows.get(NC-1);
785 if (top.mSubLayer >= 0) {
786 pos = top;
787 }
788 }
789 }
790 placeWindowAfter(pos, win);
791 } else {
792 // Just search for the start of this layer.
793 final int myLayer = win.mBaseLayer;
794 for (i=0; i<N; i++) {
795 WindowState w = (WindowState)localmWindows.get(i);
796 if (w.mBaseLayer > myLayer) {
797 break;
798 }
799 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800800 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700801 TAG, "Adding window " + win + " at "
802 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800803 localmWindows.add(i, win);
804 }
805 }
806 }
807 } else {
808 // Figure out where window should go, based on layer.
809 final int myLayer = win.mBaseLayer;
810 for (i=N-1; i>=0; i--) {
811 if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) {
812 i++;
813 break;
814 }
815 }
816 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800817 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700818 TAG, "Adding window " + win + " at "
819 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820 localmWindows.add(i, win);
821 }
822 if (addToToken) {
823 token.windows.add(tokenWindowsPos, win);
824 }
825
826 } else {
827 // Figure out this window's ordering relative to the window
828 // it is attached to.
829 final int NA = token.windows.size();
830 final int sublayer = win.mSubLayer;
831 int largestSublayer = Integer.MIN_VALUE;
832 WindowState windowWithLargestSublayer = null;
833 for (i=0; i<NA; i++) {
834 WindowState w = token.windows.get(i);
835 final int wSublayer = w.mSubLayer;
836 if (wSublayer >= largestSublayer) {
837 largestSublayer = wSublayer;
838 windowWithLargestSublayer = w;
839 }
840 if (sublayer < 0) {
841 // For negative sublayers, we go below all windows
842 // in the same sublayer.
843 if (wSublayer >= sublayer) {
844 if (addToToken) {
845 token.windows.add(i, win);
846 }
847 placeWindowBefore(
848 wSublayer >= 0 ? attached : w, win);
849 break;
850 }
851 } else {
852 // For positive sublayers, we go above all windows
853 // in the same sublayer.
854 if (wSublayer > sublayer) {
855 if (addToToken) {
856 token.windows.add(i, win);
857 }
858 placeWindowBefore(w, win);
859 break;
860 }
861 }
862 }
863 if (i >= NA) {
864 if (addToToken) {
865 token.windows.add(win);
866 }
867 if (sublayer < 0) {
868 placeWindowBefore(attached, win);
869 } else {
870 placeWindowAfter(largestSublayer >= 0
871 ? windowWithLargestSublayer
872 : attached,
873 win);
874 }
875 }
876 }
Romain Guy06882f82009-06-10 13:36:04 -0700877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800878 if (win.mAppToken != null && addToToken) {
879 win.mAppToken.allAppWindows.add(win);
880 }
881 }
Romain Guy06882f82009-06-10 13:36:04 -0700882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 static boolean canBeImeTarget(WindowState w) {
884 final int fl = w.mAttrs.flags
885 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
886 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
887 return w.isVisibleOrAdding();
888 }
889 return false;
890 }
Romain Guy06882f82009-06-10 13:36:04 -0700891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800892 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
893 final ArrayList localmWindows = mWindows;
894 final int N = localmWindows.size();
895 WindowState w = null;
896 int i = N;
897 while (i > 0) {
898 i--;
899 w = (WindowState)localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700900
Joe Onorato8a9b2202010-02-26 18:56:32 -0800901 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800902 // + Integer.toHexString(w.mAttrs.flags));
903 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800904 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 // Yet more tricksyness! If this window is a "starting"
907 // window, we do actually want to be on top of it, but
908 // it is not -really- where input will go. So if the caller
909 // is not actually looking to move the IME, look down below
910 // for a real window to target...
911 if (!willMove
912 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
913 && i > 0) {
914 WindowState wb = (WindowState)localmWindows.get(i-1);
915 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
916 i--;
917 w = wb;
918 }
919 }
920 break;
921 }
922 }
Romain Guy06882f82009-06-10 13:36:04 -0700923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700925
Joe Onorato8a9b2202010-02-26 18:56:32 -0800926 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 if (willMove && w != null) {
930 final WindowState curTarget = mInputMethodTarget;
931 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 // Now some fun for dealing with window animations that
934 // modify the Z order. We need to look at all windows below
935 // the current target that are in this app, finding the highest
936 // visible one in layering.
937 AppWindowToken token = curTarget.mAppToken;
938 WindowState highestTarget = null;
939 int highestPos = 0;
940 if (token.animating || token.animation != null) {
941 int pos = 0;
942 pos = localmWindows.indexOf(curTarget);
943 while (pos >= 0) {
944 WindowState win = (WindowState)localmWindows.get(pos);
945 if (win.mAppToken != token) {
946 break;
947 }
948 if (!win.mRemoved) {
949 if (highestTarget == null || win.mAnimLayer >
950 highestTarget.mAnimLayer) {
951 highestTarget = win;
952 highestPos = pos;
953 }
954 }
955 pos--;
956 }
957 }
Romain Guy06882f82009-06-10 13:36:04 -0700958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800959 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800960 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961 + mNextAppTransition + " " + highestTarget
962 + " animating=" + highestTarget.isAnimating()
963 + " layer=" + highestTarget.mAnimLayer
964 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700965
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700966 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800967 // If we are currently setting up for an animation,
968 // hold everything until we can find out what will happen.
969 mInputMethodTargetWaitingAnim = true;
970 mInputMethodTarget = highestTarget;
971 return highestPos + 1;
972 } else if (highestTarget.isAnimating() &&
973 highestTarget.mAnimLayer > w.mAnimLayer) {
974 // If the window we are currently targeting is involved
975 // with an animation, and it is on top of the next target
976 // we will be over, then hold off on moving until
977 // that is done.
978 mInputMethodTarget = highestTarget;
979 return highestPos + 1;
980 }
981 }
982 }
983 }
Romain Guy06882f82009-06-10 13:36:04 -0700984
Joe Onorato8a9b2202010-02-26 18:56:32 -0800985 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800986 if (w != null) {
987 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -0800988 if (DEBUG_INPUT_METHOD) {
989 RuntimeException e = null;
990 if (!HIDE_STACK_CRAWLS) {
991 e = new RuntimeException();
992 e.fillInStackTrace();
993 }
994 Slog.w(TAG, "Moving IM target from "
995 + mInputMethodTarget + " to " + w, e);
996 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800997 mInputMethodTarget = w;
998 if (w.mAppToken != null) {
999 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1000 } else {
1001 setInputMethodAnimLayerAdjustment(0);
1002 }
1003 }
1004 return i+1;
1005 }
1006 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001007 if (DEBUG_INPUT_METHOD) {
1008 RuntimeException e = null;
1009 if (!HIDE_STACK_CRAWLS) {
1010 e = new RuntimeException();
1011 e.fillInStackTrace();
1012 }
1013 Slog.w(TAG, "Moving IM target from "
1014 + mInputMethodTarget + " to null", e);
1015 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001016 mInputMethodTarget = null;
1017 setInputMethodAnimLayerAdjustment(0);
1018 }
1019 return -1;
1020 }
Romain Guy06882f82009-06-10 13:36:04 -07001021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001022 void addInputMethodWindowToListLocked(WindowState win) {
1023 int pos = findDesiredInputMethodWindowIndexLocked(true);
1024 if (pos >= 0) {
1025 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001026 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001027 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028 mWindows.add(pos, win);
1029 moveInputMethodDialogsLocked(pos+1);
1030 return;
1031 }
1032 win.mTargetAppToken = null;
1033 addWindowToListInOrderLocked(win, true);
1034 moveInputMethodDialogsLocked(pos);
1035 }
Romain Guy06882f82009-06-10 13:36:04 -07001036
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001037 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001038 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039 mInputMethodAnimLayerAdjustment = adj;
1040 WindowState imw = mInputMethodWindow;
1041 if (imw != null) {
1042 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001043 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 + " anim layer: " + imw.mAnimLayer);
1045 int wi = imw.mChildWindows.size();
1046 while (wi > 0) {
1047 wi--;
1048 WindowState cw = (WindowState)imw.mChildWindows.get(wi);
1049 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001050 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 + " anim layer: " + cw.mAnimLayer);
1052 }
1053 }
1054 int di = mInputMethodDialogs.size();
1055 while (di > 0) {
1056 di --;
1057 imw = mInputMethodDialogs.get(di);
1058 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001059 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001060 + " anim layer: " + imw.mAnimLayer);
1061 }
1062 }
Romain Guy06882f82009-06-10 13:36:04 -07001063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001064 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1065 int wpos = mWindows.indexOf(win);
1066 if (wpos >= 0) {
1067 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001068 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 mWindows.remove(wpos);
1070 int NC = win.mChildWindows.size();
1071 while (NC > 0) {
1072 NC--;
1073 WindowState cw = (WindowState)win.mChildWindows.get(NC);
1074 int cpos = mWindows.indexOf(cw);
1075 if (cpos >= 0) {
1076 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001077 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001078 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001079 mWindows.remove(cpos);
1080 }
1081 }
1082 }
1083 return interestingPos;
1084 }
Romain Guy06882f82009-06-10 13:36:04 -07001085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 private void reAddWindowToListInOrderLocked(WindowState win) {
1087 addWindowToListInOrderLocked(win, false);
1088 // This is a hack to get all of the child windows added as well
1089 // at the right position. Child windows should be rare and
1090 // this case should be rare, so it shouldn't be that big a deal.
1091 int wpos = mWindows.indexOf(win);
1092 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001093 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001094 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 mWindows.remove(wpos);
1096 reAddWindowLocked(wpos, win);
1097 }
1098 }
Romain Guy06882f82009-06-10 13:36:04 -07001099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 void logWindowList(String prefix) {
1101 int N = mWindows.size();
1102 while (N > 0) {
1103 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001104 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 }
1106 }
Romain Guy06882f82009-06-10 13:36:04 -07001107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001108 void moveInputMethodDialogsLocked(int pos) {
1109 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001111 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001112 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 for (int i=0; i<N; i++) {
1114 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1115 }
1116 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001117 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001118 logWindowList(" ");
1119 }
Romain Guy06882f82009-06-10 13:36:04 -07001120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001121 if (pos >= 0) {
1122 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1123 if (pos < mWindows.size()) {
1124 WindowState wp = (WindowState)mWindows.get(pos);
1125 if (wp == mInputMethodWindow) {
1126 pos++;
1127 }
1128 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001129 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001130 for (int i=0; i<N; i++) {
1131 WindowState win = dialogs.get(i);
1132 win.mTargetAppToken = targetAppToken;
1133 pos = reAddWindowLocked(pos, win);
1134 }
1135 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001136 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001137 logWindowList(" ");
1138 }
1139 return;
1140 }
1141 for (int i=0; i<N; i++) {
1142 WindowState win = dialogs.get(i);
1143 win.mTargetAppToken = null;
1144 reAddWindowToListInOrderLocked(win);
1145 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001146 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001147 logWindowList(" ");
1148 }
1149 }
1150 }
Romain Guy06882f82009-06-10 13:36:04 -07001151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1153 final WindowState imWin = mInputMethodWindow;
1154 final int DN = mInputMethodDialogs.size();
1155 if (imWin == null && DN == 0) {
1156 return false;
1157 }
Romain Guy06882f82009-06-10 13:36:04 -07001158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1160 if (imPos >= 0) {
1161 // In this case, the input method windows are to be placed
1162 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001164 // First check to see if the input method windows are already
1165 // located here, and contiguous.
1166 final int N = mWindows.size();
1167 WindowState firstImWin = imPos < N
1168 ? (WindowState)mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001170 // Figure out the actual input method window that should be
1171 // at the bottom of their stack.
1172 WindowState baseImWin = imWin != null
1173 ? imWin : mInputMethodDialogs.get(0);
1174 if (baseImWin.mChildWindows.size() > 0) {
1175 WindowState cw = (WindowState)baseImWin.mChildWindows.get(0);
1176 if (cw.mSubLayer < 0) baseImWin = cw;
1177 }
Romain Guy06882f82009-06-10 13:36:04 -07001178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179 if (firstImWin == baseImWin) {
1180 // The windows haven't moved... but are they still contiguous?
1181 // First find the top IM window.
1182 int pos = imPos+1;
1183 while (pos < N) {
1184 if (!((WindowState)mWindows.get(pos)).mIsImWindow) {
1185 break;
1186 }
1187 pos++;
1188 }
1189 pos++;
1190 // Now there should be no more input method windows above.
1191 while (pos < N) {
1192 if (((WindowState)mWindows.get(pos)).mIsImWindow) {
1193 break;
1194 }
1195 pos++;
1196 }
1197 if (pos >= N) {
1198 // All is good!
1199 return false;
1200 }
1201 }
Romain Guy06882f82009-06-10 13:36:04 -07001202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 if (imWin != null) {
1204 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001205 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001206 logWindowList(" ");
1207 }
1208 imPos = tmpRemoveWindowLocked(imPos, imWin);
1209 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001210 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001211 logWindowList(" ");
1212 }
1213 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1214 reAddWindowLocked(imPos, imWin);
1215 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001216 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 logWindowList(" ");
1218 }
1219 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1220 } else {
1221 moveInputMethodDialogsLocked(imPos);
1222 }
Romain Guy06882f82009-06-10 13:36:04 -07001223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 } else {
1225 // In this case, the input method windows go in a fixed layer,
1226 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001228 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001229 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001230 tmpRemoveWindowLocked(0, imWin);
1231 imWin.mTargetAppToken = null;
1232 reAddWindowToListInOrderLocked(imWin);
1233 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001234 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235 logWindowList(" ");
1236 }
1237 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1238 } else {
1239 moveInputMethodDialogsLocked(-1);;
1240 }
Romain Guy06882f82009-06-10 13:36:04 -07001241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001242 }
Romain Guy06882f82009-06-10 13:36:04 -07001243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 if (needAssignLayers) {
1245 assignLayersLocked();
1246 }
Romain Guy06882f82009-06-10 13:36:04 -07001247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 return true;
1249 }
Romain Guy06882f82009-06-10 13:36:04 -07001250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001251 void adjustInputMethodDialogsLocked() {
1252 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1253 }
Romain Guy06882f82009-06-10 13:36:04 -07001254
Dianne Hackborn25994b42009-09-04 14:21:19 -07001255 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001256 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001257 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1258 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1259 ? wallpaperTarget.mAppToken.animation : null)
1260 + " upper=" + mUpperWallpaperTarget
1261 + " lower=" + mLowerWallpaperTarget);
1262 return (wallpaperTarget != null
1263 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1264 && wallpaperTarget.mAppToken.animation != null)))
1265 || mUpperWallpaperTarget != null
1266 || mLowerWallpaperTarget != null;
1267 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001268
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001269 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1270 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001271
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001272 int adjustWallpaperWindowsLocked() {
1273 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001274
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001275 final int dw = mDisplay.getWidth();
1276 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001277
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001278 // First find top-most window that has asked to be on top of the
1279 // wallpaper; all wallpapers go behind it.
1280 final ArrayList localmWindows = mWindows;
1281 int N = localmWindows.size();
1282 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001283 WindowState foundW = null;
1284 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001285 WindowState topCurW = null;
1286 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001287 int i = N;
1288 while (i > 0) {
1289 i--;
1290 w = (WindowState)localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001291 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1292 if (topCurW == null) {
1293 topCurW = w;
1294 topCurI = i;
1295 }
1296 continue;
1297 }
1298 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001299 if (w.mAppToken != null) {
1300 // If this window's app token is hidden and not animating,
1301 // it is of no interest to us.
1302 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001303 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001304 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001305 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001306 continue;
1307 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001308 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001309 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001310 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1311 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001312 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001313 && (mWallpaperTarget == w
1314 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001315 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001316 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001317 foundW = w;
1318 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001319 if (w == mWallpaperTarget && ((w.mAppToken != null
1320 && w.mAppToken.animation != null)
1321 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001322 // The current wallpaper target is animating, so we'll
1323 // look behind it for another possible target and figure
1324 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001325 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001326 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001327 continue;
1328 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001329 break;
1330 }
1331 }
1332
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001333 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001334 // If we are currently waiting for an app transition, and either
1335 // the current target or the next target are involved with it,
1336 // then hold off on doing anything with the wallpaper.
1337 // Note that we are checking here for just whether the target
1338 // is part of an app token... which is potentially overly aggressive
1339 // (the app token may not be involved in the transition), but good
1340 // enough (we'll just wait until whatever transition is pending
1341 // executes).
1342 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001343 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001344 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001345 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001346 }
1347 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001348 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001349 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001350 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001351 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001352 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001353
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001354 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001355 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001356 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001357 + " oldTarget: " + mWallpaperTarget);
1358 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001359
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001360 mLowerWallpaperTarget = null;
1361 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001362
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001363 WindowState oldW = mWallpaperTarget;
1364 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001365
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001366 // Now what is happening... if the current and new targets are
1367 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001368 if (foundW != null && oldW != null) {
1369 boolean oldAnim = oldW.mAnimation != null
1370 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1371 boolean foundAnim = foundW.mAnimation != null
1372 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001373 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001374 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001375 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001376 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001377 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001378 int oldI = localmWindows.indexOf(oldW);
1379 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001380 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001381 }
1382 if (oldI >= 0) {
1383 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001384 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001385 + "=" + oldW + "; new#" + foundI
1386 + "=" + foundW);
1387 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001388
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001389 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001390 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001391 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001392 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001393 }
1394 mWallpaperTarget = oldW;
1395 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001396
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001397 // Now set the upper and lower wallpaper targets
1398 // correctly, and make sure that we are positioning
1399 // the wallpaper below the lower.
1400 if (foundI > oldI) {
1401 // The new target is on top of the old one.
1402 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001403 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001404 }
1405 mUpperWallpaperTarget = foundW;
1406 mLowerWallpaperTarget = oldW;
1407 foundW = oldW;
1408 foundI = oldI;
1409 } else {
1410 // The new target is below the old one.
1411 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001412 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001413 }
1414 mUpperWallpaperTarget = oldW;
1415 mLowerWallpaperTarget = foundW;
1416 }
1417 }
1418 }
1419 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001420
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001421 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001422 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001423 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1424 || (mLowerWallpaperTarget.mAppToken != null
1425 && mLowerWallpaperTarget.mAppToken.animation != null);
1426 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1427 || (mUpperWallpaperTarget.mAppToken != null
1428 && mUpperWallpaperTarget.mAppToken.animation != null);
1429 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001430 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001431 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001432 }
1433 mLowerWallpaperTarget = null;
1434 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001435 }
1436 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001437
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001438 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001439 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001440 // The window is visible to the compositor... but is it visible
1441 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001442 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001443 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001444
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001445 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001446 // its layer adjustment. Only do this if we are not transfering
1447 // between two wallpaper targets.
1448 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001449 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001450 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001451
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001452 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1453 * TYPE_LAYER_MULTIPLIER
1454 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001455
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001456 // Now w is the window we are supposed to be behind... but we
1457 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001458 // AND any starting window associated with it, AND below the
1459 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001460 while (foundI > 0) {
1461 WindowState wb = (WindowState)localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001462 if (wb.mBaseLayer < maxLayer &&
1463 wb.mAttachedWindow != foundW &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001464 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001465 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001466 // This window is not related to the previous one in any
1467 // interesting way, so stop here.
1468 break;
1469 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001470 foundW = wb;
1471 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001472 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001473 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001474 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001475 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001476
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001477 if (foundW == null && topCurW != null) {
1478 // There is no wallpaper target, so it goes at the bottom.
1479 // We will assume it is the same place as last time, if known.
1480 foundW = topCurW;
1481 foundI = topCurI+1;
1482 } else {
1483 // Okay i is the position immediately above the wallpaper. Look at
1484 // what is below it for later.
1485 foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null;
1486 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001487
Dianne Hackborn284ac932009-08-28 10:34:25 -07001488 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001489 if (mWallpaperTarget.mWallpaperX >= 0) {
1490 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001491 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001492 }
1493 if (mWallpaperTarget.mWallpaperY >= 0) {
1494 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001495 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001496 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001497 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001498
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001499 // Start stepping backwards from here, ensuring that our wallpaper windows
1500 // are correctly placed.
1501 int curTokenIndex = mWallpaperTokens.size();
1502 while (curTokenIndex > 0) {
1503 curTokenIndex--;
1504 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001505 if (token.hidden == visible) {
1506 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1507 token.hidden = !visible;
1508 // Need to do a layout to ensure the wallpaper now has the
1509 // correct size.
1510 mLayoutNeeded = true;
1511 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001512
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001513 int curWallpaperIndex = token.windows.size();
1514 while (curWallpaperIndex > 0) {
1515 curWallpaperIndex--;
1516 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001517
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001518 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001519 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001520 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001521
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001522 // First, make sure the client has the current visibility
1523 // state.
1524 if (wallpaper.mWallpaperVisible != visible) {
1525 wallpaper.mWallpaperVisible = visible;
1526 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001527 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001528 "Setting visibility of wallpaper " + wallpaper
1529 + ": " + visible);
1530 wallpaper.mClient.dispatchAppVisibility(visible);
1531 } catch (RemoteException e) {
1532 }
1533 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001534
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001535 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001536 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001537 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001538
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001539 // First, if this window is at the current index, then all
1540 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001541 if (wallpaper == foundW) {
1542 foundI--;
1543 foundW = foundI > 0
1544 ? (WindowState)localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001545 continue;
1546 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001547
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001548 // The window didn't match... the current wallpaper window,
1549 // wherever it is, is in the wrong place, so make sure it is
1550 // not in the list.
1551 int oldIndex = localmWindows.indexOf(wallpaper);
1552 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001553 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001554 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001555 localmWindows.remove(oldIndex);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001556 if (oldIndex < foundI) {
1557 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001558 }
1559 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001560
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001561 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001562 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001563 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001564 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001565
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001566 localmWindows.add(foundI, wallpaper);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001567 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001568 }
1569 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001570
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001571 return changed;
1572 }
1573
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001574 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001575 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001576 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001577 mWallpaperAnimLayerAdjustment = adj;
1578 int curTokenIndex = mWallpaperTokens.size();
1579 while (curTokenIndex > 0) {
1580 curTokenIndex--;
1581 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1582 int curWallpaperIndex = token.windows.size();
1583 while (curWallpaperIndex > 0) {
1584 curWallpaperIndex--;
1585 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1586 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001587 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001588 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001589 }
1590 }
1591 }
1592
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001593 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1594 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001595 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001596 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001597 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001598 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001599 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1600 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1601 changed = wallpaperWin.mXOffset != offset;
1602 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001603 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001604 + wallpaperWin + " x: " + offset);
1605 wallpaperWin.mXOffset = offset;
1606 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001607 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001608 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001609 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001610 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001611 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001612
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001613 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001614 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001615 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1616 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1617 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001618 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001619 + wallpaperWin + " y: " + offset);
1620 changed = true;
1621 wallpaperWin.mYOffset = offset;
1622 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001623 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001624 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001625 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001626 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001627 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001628
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001629 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001630 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001631 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001632 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1633 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001634 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001635 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001636 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001637 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001638 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1639 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001640 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001641 if (mWaitingOnWallpaper != null) {
1642 long start = SystemClock.uptimeMillis();
1643 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1644 < start) {
1645 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001646 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001647 "Waiting for offset complete...");
1648 mWindowMap.wait(WALLPAPER_TIMEOUT);
1649 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001650 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001651 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001652 if ((start+WALLPAPER_TIMEOUT)
1653 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001654 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001655 + wallpaperWin);
1656 mLastWallpaperTimeoutTime = start;
1657 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001658 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001659 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001660 }
1661 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001662 } catch (RemoteException e) {
1663 }
1664 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001665
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001666 return changed;
1667 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001668
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001669 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001670 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001671 if (mWaitingOnWallpaper != null &&
1672 mWaitingOnWallpaper.mClient.asBinder() == window) {
1673 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001674 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001675 }
1676 }
1677 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001678
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001679 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001680 final int dw = mDisplay.getWidth();
1681 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001682
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001683 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001684
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001685 WindowState target = mWallpaperTarget;
1686 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001687 if (target.mWallpaperX >= 0) {
1688 mLastWallpaperX = target.mWallpaperX;
1689 } else if (changingTarget.mWallpaperX >= 0) {
1690 mLastWallpaperX = changingTarget.mWallpaperX;
1691 }
1692 if (target.mWallpaperY >= 0) {
1693 mLastWallpaperY = target.mWallpaperY;
1694 } else if (changingTarget.mWallpaperY >= 0) {
1695 mLastWallpaperY = changingTarget.mWallpaperY;
1696 }
1697 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001698
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001699 int curTokenIndex = mWallpaperTokens.size();
1700 while (curTokenIndex > 0) {
1701 curTokenIndex--;
1702 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1703 int curWallpaperIndex = token.windows.size();
1704 while (curWallpaperIndex > 0) {
1705 curWallpaperIndex--;
1706 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1707 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1708 wallpaper.computeShownFrameLocked();
1709 changed = true;
1710 // We only want to be synchronous with one wallpaper.
1711 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001712 }
1713 }
1714 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001715
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001716 return changed;
1717 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001718
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001719 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001720 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001721 final int dw = mDisplay.getWidth();
1722 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001723
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001724 int curTokenIndex = mWallpaperTokens.size();
1725 while (curTokenIndex > 0) {
1726 curTokenIndex--;
1727 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001728 if (token.hidden == visible) {
1729 token.hidden = !visible;
1730 // Need to do a layout to ensure the wallpaper now has the
1731 // correct size.
1732 mLayoutNeeded = true;
1733 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001734
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001735 int curWallpaperIndex = token.windows.size();
1736 while (curWallpaperIndex > 0) {
1737 curWallpaperIndex--;
1738 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1739 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001740 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001741 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001742
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001743 if (wallpaper.mWallpaperVisible != visible) {
1744 wallpaper.mWallpaperVisible = visible;
1745 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001746 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001747 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001748 + ": " + visible);
1749 wallpaper.mClient.dispatchAppVisibility(visible);
1750 } catch (RemoteException e) {
1751 }
1752 }
1753 }
1754 }
1755 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001756
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001757 void sendPointerToWallpaperLocked(WindowState srcWin,
1758 MotionEvent pointer, long eventTime) {
1759 int curTokenIndex = mWallpaperTokens.size();
1760 while (curTokenIndex > 0) {
1761 curTokenIndex--;
1762 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1763 int curWallpaperIndex = token.windows.size();
1764 while (curWallpaperIndex > 0) {
1765 curWallpaperIndex--;
1766 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1767 if ((wallpaper.mAttrs.flags &
1768 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
1769 continue;
1770 }
1771 try {
1772 MotionEvent ev = MotionEvent.obtainNoHistory(pointer);
Dianne Hackborn6adba242009-11-10 11:10:09 -08001773 if (srcWin != null) {
1774 ev.offsetLocation(srcWin.mFrame.left-wallpaper.mFrame.left,
1775 srcWin.mFrame.top-wallpaper.mFrame.top);
1776 } else {
1777 ev.offsetLocation(-wallpaper.mFrame.left, -wallpaper.mFrame.top);
1778 }
1779 switch (pointer.getAction()) {
1780 case MotionEvent.ACTION_DOWN:
1781 mSendingPointersToWallpaper = true;
1782 break;
1783 case MotionEvent.ACTION_UP:
1784 mSendingPointersToWallpaper = false;
1785 break;
1786 }
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001787 wallpaper.mClient.dispatchPointer(ev, eventTime, false);
1788 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001789 Slog.w(TAG, "Failure sending pointer to wallpaper", e);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001790 }
1791 }
1792 }
1793 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001794
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001795 void dispatchPointerElsewhereLocked(WindowState srcWin, WindowState relWin,
1796 MotionEvent pointer, long eventTime, boolean skipped) {
1797 if (relWin != null) {
1798 mPolicy.dispatchedPointerEventLw(pointer, relWin.mFrame.left, relWin.mFrame.top);
1799 } else {
1800 mPolicy.dispatchedPointerEventLw(pointer, 0, 0);
1801 }
1802
1803 // If we sent an initial down to the wallpaper, then continue
1804 // sending events until the final up.
1805 if (mSendingPointersToWallpaper) {
1806 if (skipped) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001807 Slog.i(TAG, "Sending skipped pointer to wallpaper!");
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001808 }
1809 sendPointerToWallpaperLocked(relWin, pointer, eventTime);
1810
1811 // If we are on top of the wallpaper, then the wallpaper also
1812 // gets to see this movement.
1813 } else if (srcWin != null
1814 && pointer.getAction() == MotionEvent.ACTION_DOWN
1815 && mWallpaperTarget == srcWin
1816 && srcWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) {
1817 sendPointerToWallpaperLocked(relWin, pointer, eventTime);
1818 }
1819 }
1820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001821 public int addWindow(Session session, IWindow client,
1822 WindowManager.LayoutParams attrs, int viewVisibility,
1823 Rect outContentInsets) {
1824 int res = mPolicy.checkAddPermission(attrs);
1825 if (res != WindowManagerImpl.ADD_OKAY) {
1826 return res;
1827 }
Romain Guy06882f82009-06-10 13:36:04 -07001828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001829 boolean reportNewConfig = false;
1830 WindowState attachedWindow = null;
1831 WindowState win = null;
Romain Guy06882f82009-06-10 13:36:04 -07001832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001833 synchronized(mWindowMap) {
1834 // Instantiating a Display requires talking with the simulator,
1835 // so don't do it until we know the system is mostly up and
1836 // running.
1837 if (mDisplay == null) {
1838 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1839 mDisplay = wm.getDefaultDisplay();
1840 mQueue.setDisplay(mDisplay);
1841 reportNewConfig = true;
1842 }
Romain Guy06882f82009-06-10 13:36:04 -07001843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001844 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001845 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001846 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1847 }
1848
1849 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001850 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001851 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001852 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001853 + attrs.token + ". Aborting.");
1854 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1855 }
1856 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1857 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001858 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001859 + attrs.token + ". Aborting.");
1860 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1861 }
1862 }
1863
1864 boolean addToken = false;
1865 WindowToken token = mTokenMap.get(attrs.token);
1866 if (token == null) {
1867 if (attrs.type >= FIRST_APPLICATION_WINDOW
1868 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001869 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001870 + attrs.token + ". Aborting.");
1871 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1872 }
1873 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001874 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001875 + attrs.token + ". Aborting.");
1876 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1877 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001878 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001879 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001880 + attrs.token + ". Aborting.");
1881 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1882 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001883 token = new WindowToken(attrs.token, -1, false);
1884 addToken = true;
1885 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1886 && attrs.type <= LAST_APPLICATION_WINDOW) {
1887 AppWindowToken atoken = token.appWindowToken;
1888 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001889 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001890 + token + ". Aborting.");
1891 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1892 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001893 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001894 + token + ". Aborting.");
1895 return WindowManagerImpl.ADD_APP_EXITING;
1896 }
1897 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1898 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001899 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001900 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1901 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1902 }
1903 } else if (attrs.type == TYPE_INPUT_METHOD) {
1904 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001905 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001906 + attrs.token + ". Aborting.");
1907 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1908 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001909 } else if (attrs.type == TYPE_WALLPAPER) {
1910 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001911 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001912 + attrs.token + ". Aborting.");
1913 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1914 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001915 }
1916
1917 win = new WindowState(session, client, token,
1918 attachedWindow, attrs, viewVisibility);
1919 if (win.mDeathRecipient == null) {
1920 // Client has apparently died, so there is no reason to
1921 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001922 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001923 + " that is dead, aborting.");
1924 return WindowManagerImpl.ADD_APP_EXITING;
1925 }
1926
1927 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001929 res = mPolicy.prepareAddWindowLw(win, attrs);
1930 if (res != WindowManagerImpl.ADD_OKAY) {
1931 return res;
1932 }
1933
1934 // From now on, no exceptions or errors allowed!
1935
1936 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001938 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001940 if (addToken) {
1941 mTokenMap.put(attrs.token, token);
1942 mTokenList.add(token);
1943 }
1944 win.attach();
1945 mWindowMap.put(client.asBinder(), win);
1946
1947 if (attrs.type == TYPE_APPLICATION_STARTING &&
1948 token.appWindowToken != null) {
1949 token.appWindowToken.startingWindow = win;
1950 }
1951
1952 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001954 if (attrs.type == TYPE_INPUT_METHOD) {
1955 mInputMethodWindow = win;
1956 addInputMethodWindowToListLocked(win);
1957 imMayMove = false;
1958 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1959 mInputMethodDialogs.add(win);
1960 addWindowToListInOrderLocked(win, true);
1961 adjustInputMethodDialogsLocked();
1962 imMayMove = false;
1963 } else {
1964 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001965 if (attrs.type == TYPE_WALLPAPER) {
1966 mLastWallpaperTimeoutTime = 0;
1967 adjustWallpaperWindowsLocked();
1968 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001969 adjustWallpaperWindowsLocked();
1970 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001971 }
Romain Guy06882f82009-06-10 13:36:04 -07001972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001973 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001975 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001977 if (mInTouchMode) {
1978 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1979 }
1980 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1981 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1982 }
Romain Guy06882f82009-06-10 13:36:04 -07001983
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001984 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001985 if (win.canReceiveKeys()) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001986 if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS))
1987 == true) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001988 imMayMove = false;
1989 }
1990 }
Romain Guy06882f82009-06-10 13:36:04 -07001991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001992 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001993 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001994 }
Romain Guy06882f82009-06-10 13:36:04 -07001995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001996 assignLayersLocked();
1997 // Don't do layout here, the window must call
1998 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07001999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002000 //dump();
2001
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002002 if (focusChanged) {
2003 if (mCurrentFocus != null) {
2004 mKeyWaiter.handleNewWindowLocked(mCurrentFocus);
2005 }
2006 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002007 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002008 TAG, "New client " + client.asBinder()
2009 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002010
2011 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2012 reportNewConfig = true;
2013 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002014 }
2015
2016 // sendNewConfiguration() checks caller permissions so we must call it with
2017 // privilege. updateOrientationFromAppTokens() clears and resets the caller
2018 // identity anyway, so it's safe to just clear & restore around this whole
2019 // block.
2020 final long origId = Binder.clearCallingIdentity();
2021 if (reportNewConfig) {
2022 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002023 }
2024 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002025
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002026 return res;
2027 }
Romain Guy06882f82009-06-10 13:36:04 -07002028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002029 public void removeWindow(Session session, IWindow client) {
2030 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002031 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002032 if (win == null) {
2033 return;
2034 }
2035 removeWindowLocked(session, win);
2036 }
2037 }
Romain Guy06882f82009-06-10 13:36:04 -07002038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002039 public void removeWindowLocked(Session session, WindowState win) {
2040
Joe Onorato8a9b2202010-02-26 18:56:32 -08002041 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002042 TAG, "Remove " + win + " client="
2043 + Integer.toHexString(System.identityHashCode(
2044 win.mClient.asBinder()))
2045 + ", surface=" + win.mSurface);
2046
2047 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002048
Joe Onorato8a9b2202010-02-26 18:56:32 -08002049 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002050 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2051 + " mExiting=" + win.mExiting
2052 + " isAnimating=" + win.isAnimating()
2053 + " app-animation="
2054 + (win.mAppToken != null ? win.mAppToken.animation : null)
2055 + " inPendingTransaction="
2056 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2057 + " mDisplayFrozen=" + mDisplayFrozen);
2058 // Visibility of the removed window. Will be used later to update orientation later on.
2059 boolean wasVisible = false;
2060 // First, see if we need to run an animation. If we do, we have
2061 // to hold off on removing the window until the animation is done.
2062 // If the display is frozen, just remove immediately, since the
2063 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002064 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002065 // If we are not currently running the exit animation, we
2066 // need to see about starting one.
2067 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002069 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2070 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2071 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2072 }
2073 // Try starting an animation.
2074 if (applyAnimationLocked(win, transit, false)) {
2075 win.mExiting = true;
2076 }
2077 }
2078 if (win.mExiting || win.isAnimating()) {
2079 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002080 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002081 win.mExiting = true;
2082 win.mRemoveOnExit = true;
2083 mLayoutNeeded = true;
2084 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2085 performLayoutAndPlaceSurfacesLocked();
2086 if (win.mAppToken != null) {
2087 win.mAppToken.updateReportedVisibilityLocked();
2088 }
2089 //dump();
2090 Binder.restoreCallingIdentity(origId);
2091 return;
2092 }
2093 }
2094
2095 removeWindowInnerLocked(session, win);
2096 // Removing a visible window will effect the computed orientation
2097 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002098 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002099 != mForcedAppOrientation
2100 && updateOrientationFromAppTokensLocked()) {
2101 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002102 }
2103 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2104 Binder.restoreCallingIdentity(origId);
2105 }
Romain Guy06882f82009-06-10 13:36:04 -07002106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002107 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07002108 mKeyWaiter.finishedKey(session, win.mClient, true,
2109 KeyWaiter.RETURN_NOTHING);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002110 mKeyWaiter.releasePendingPointerLocked(win.mSession);
2111 mKeyWaiter.releasePendingTrackballLocked(win.mSession);
Romain Guy06882f82009-06-10 13:36:04 -07002112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002113 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002115 if (mInputMethodTarget == win) {
2116 moveInputMethodWindowsIfNeededLocked(false);
2117 }
Romain Guy06882f82009-06-10 13:36:04 -07002118
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002119 if (false) {
2120 RuntimeException e = new RuntimeException("here");
2121 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002122 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002123 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002125 mPolicy.removeWindowLw(win);
2126 win.removeLocked();
2127
2128 mWindowMap.remove(win.mClient.asBinder());
2129 mWindows.remove(win);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002130 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002131
2132 if (mInputMethodWindow == win) {
2133 mInputMethodWindow = null;
2134 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2135 mInputMethodDialogs.remove(win);
2136 }
Romain Guy06882f82009-06-10 13:36:04 -07002137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002138 final WindowToken token = win.mToken;
2139 final AppWindowToken atoken = win.mAppToken;
2140 token.windows.remove(win);
2141 if (atoken != null) {
2142 atoken.allAppWindows.remove(win);
2143 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002144 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002145 TAG, "**** Removing window " + win + ": count="
2146 + token.windows.size());
2147 if (token.windows.size() == 0) {
2148 if (!token.explicit) {
2149 mTokenMap.remove(token.token);
2150 mTokenList.remove(token);
2151 } else if (atoken != null) {
2152 atoken.firstWindowDrawn = false;
2153 }
2154 }
2155
2156 if (atoken != null) {
2157 if (atoken.startingWindow == win) {
2158 atoken.startingWindow = null;
2159 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2160 // If this is the last window and we had requested a starting
2161 // transition window, well there is no point now.
2162 atoken.startingData = null;
2163 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2164 // If this is the last window except for a starting transition
2165 // window, we need to get rid of the starting transition.
2166 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002167 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002168 + ": no more real windows");
2169 }
2170 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2171 mH.sendMessage(m);
2172 }
2173 }
Romain Guy06882f82009-06-10 13:36:04 -07002174
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002175 if (win.mAttrs.type == TYPE_WALLPAPER) {
2176 mLastWallpaperTimeoutTime = 0;
2177 adjustWallpaperWindowsLocked();
2178 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002179 adjustWallpaperWindowsLocked();
2180 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002182 if (!mInLayout) {
2183 assignLayersLocked();
2184 mLayoutNeeded = true;
2185 performLayoutAndPlaceSurfacesLocked();
2186 if (win.mAppToken != null) {
2187 win.mAppToken.updateReportedVisibilityLocked();
2188 }
2189 }
2190 }
2191
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002192 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2193 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2194 + ": " + msg + " / " + w.mAttrs.getTitle();
2195 if (where != null) {
2196 Slog.i(TAG, str, where);
2197 } else {
2198 Slog.i(TAG, str);
2199 }
2200 }
2201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002202 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2203 long origId = Binder.clearCallingIdentity();
2204 try {
2205 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002206 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002207 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002208 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002209 Surface.openTransaction();
2210 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002211 if (SHOW_TRANSACTIONS) logSurface(w,
2212 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002213 w.mSurface.setTransparentRegionHint(region);
2214 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002215 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002216 Surface.closeTransaction();
2217 }
2218 }
2219 }
2220 } finally {
2221 Binder.restoreCallingIdentity(origId);
2222 }
2223 }
2224
2225 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002226 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002227 Rect visibleInsets) {
2228 long origId = Binder.clearCallingIdentity();
2229 try {
2230 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002231 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002232 if (w != null) {
2233 w.mGivenInsetsPending = false;
2234 w.mGivenContentInsets.set(contentInsets);
2235 w.mGivenVisibleInsets.set(visibleInsets);
2236 w.mTouchableInsets = touchableInsets;
2237 mLayoutNeeded = true;
2238 performLayoutAndPlaceSurfacesLocked();
2239 }
2240 }
2241 } finally {
2242 Binder.restoreCallingIdentity(origId);
2243 }
2244 }
Romain Guy06882f82009-06-10 13:36:04 -07002245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002246 public void getWindowDisplayFrame(Session session, IWindow client,
2247 Rect outDisplayFrame) {
2248 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002249 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002250 if (win == null) {
2251 outDisplayFrame.setEmpty();
2252 return;
2253 }
2254 outDisplayFrame.set(win.mDisplayFrame);
2255 }
2256 }
2257
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002258 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2259 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002260 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2261 window.mWallpaperX = x;
2262 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002263 window.mWallpaperXStep = xStep;
2264 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002265 if (updateWallpaperOffsetLocked(window, true)) {
2266 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002267 }
2268 }
2269 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002270
Dianne Hackborn75804932009-10-20 20:15:20 -07002271 void wallpaperCommandComplete(IBinder window, Bundle result) {
2272 synchronized (mWindowMap) {
2273 if (mWaitingOnWallpaper != null &&
2274 mWaitingOnWallpaper.mClient.asBinder() == window) {
2275 mWaitingOnWallpaper = null;
2276 mWindowMap.notifyAll();
2277 }
2278 }
2279 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002280
Dianne Hackborn75804932009-10-20 20:15:20 -07002281 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2282 String action, int x, int y, int z, Bundle extras, boolean sync) {
2283 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2284 || window == mUpperWallpaperTarget) {
2285 boolean doWait = sync;
2286 int curTokenIndex = mWallpaperTokens.size();
2287 while (curTokenIndex > 0) {
2288 curTokenIndex--;
2289 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2290 int curWallpaperIndex = token.windows.size();
2291 while (curWallpaperIndex > 0) {
2292 curWallpaperIndex--;
2293 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2294 try {
2295 wallpaper.mClient.dispatchWallpaperCommand(action,
2296 x, y, z, extras, sync);
2297 // We only want to be synchronous with one wallpaper.
2298 sync = false;
2299 } catch (RemoteException e) {
2300 }
2301 }
2302 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002303
Dianne Hackborn75804932009-10-20 20:15:20 -07002304 if (doWait) {
2305 // XXX Need to wait for result.
2306 }
2307 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002308
Dianne Hackborn75804932009-10-20 20:15:20 -07002309 return null;
2310 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002312 public int relayoutWindow(Session session, IWindow client,
2313 WindowManager.LayoutParams attrs, int requestedWidth,
2314 int requestedHeight, int viewVisibility, boolean insetsPending,
2315 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
2316 Surface outSurface) {
2317 boolean displayed = false;
2318 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002319 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002320 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002322 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002323 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002324 if (win == null) {
2325 return 0;
2326 }
2327 win.mRequestedWidth = requestedWidth;
2328 win.mRequestedHeight = requestedHeight;
2329
2330 if (attrs != null) {
2331 mPolicy.adjustWindowParamsLw(attrs);
2332 }
Romain Guy06882f82009-06-10 13:36:04 -07002333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002334 int attrChanges = 0;
2335 int flagChanges = 0;
2336 if (attrs != null) {
2337 flagChanges = win.mAttrs.flags ^= attrs.flags;
2338 attrChanges = win.mAttrs.copyFrom(attrs);
2339 }
2340
Joe Onorato8a9b2202010-02-26 18:56:32 -08002341 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002342
2343 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2344 win.mAlpha = attrs.alpha;
2345 }
2346
2347 final boolean scaledWindow =
2348 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2349
2350 if (scaledWindow) {
2351 // requested{Width|Height} Surface's physical size
2352 // attrs.{width|height} Size on screen
2353 win.mHScale = (attrs.width != requestedWidth) ?
2354 (attrs.width / (float)requestedWidth) : 1.0f;
2355 win.mVScale = (attrs.height != requestedHeight) ?
2356 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002357 } else {
2358 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002359 }
2360
2361 boolean imMayMove = (flagChanges&(
2362 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2363 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002365 boolean focusMayChange = win.mViewVisibility != viewVisibility
2366 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2367 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002368
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002369 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2370 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002372 win.mRelayoutCalled = true;
2373 final int oldVisibility = win.mViewVisibility;
2374 win.mViewVisibility = viewVisibility;
2375 if (viewVisibility == View.VISIBLE &&
2376 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2377 displayed = !win.isVisibleLw();
2378 if (win.mExiting) {
2379 win.mExiting = false;
2380 win.mAnimation = null;
2381 }
2382 if (win.mDestroying) {
2383 win.mDestroying = false;
2384 mDestroySurface.remove(win);
2385 }
2386 if (oldVisibility == View.GONE) {
2387 win.mEnterAnimationPending = true;
2388 }
2389 if (displayed && win.mSurface != null && !win.mDrawPending
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002390 && !win.mCommitDrawPending && !mDisplayFrozen
2391 && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002392 applyEnterAnimationLocked(win);
2393 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002394 if (displayed && (win.mAttrs.flags
2395 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08002396 if (DEBUG_VISIBILITY) Slog.v(TAG,
2397 "Relayout window turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002398 win.mTurnOnScreen = true;
2399 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002400 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2401 // To change the format, we need to re-build the surface.
2402 win.destroySurfaceLocked();
2403 displayed = true;
2404 }
2405 try {
2406 Surface surface = win.createSurfaceLocked();
2407 if (surface != null) {
2408 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002409 win.mReportDestroySurface = false;
2410 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002411 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002412 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002413 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002414 // For some reason there isn't a surface. Clear the
2415 // caller's object so they see the same state.
2416 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002417 }
2418 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002419 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002420 + client + " (" + win.mAttrs.getTitle() + ")",
2421 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002422 Binder.restoreCallingIdentity(origId);
2423 return 0;
2424 }
2425 if (displayed) {
2426 focusMayChange = true;
2427 }
2428 if (win.mAttrs.type == TYPE_INPUT_METHOD
2429 && mInputMethodWindow == null) {
2430 mInputMethodWindow = win;
2431 imMayMove = true;
2432 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002433 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2434 && win.mAppToken != null
2435 && win.mAppToken.startingWindow != null) {
2436 // Special handling of starting window over the base
2437 // window of the app: propagate lock screen flags to it,
2438 // to provide the correct semantics while starting.
2439 final int mask =
2440 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002441 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2442 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002443 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2444 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2445 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002446 } else {
2447 win.mEnterAnimationPending = false;
2448 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002449 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002450 + ": mExiting=" + win.mExiting
2451 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002452 // If we are not currently running the exit animation, we
2453 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002454 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002455 // Try starting an animation; if there isn't one, we
2456 // can destroy the surface right away.
2457 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2458 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2459 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2460 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002461 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002462 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002463 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002464 win.mExiting = true;
2465 mKeyWaiter.finishedKey(session, client, true,
2466 KeyWaiter.RETURN_NOTHING);
2467 } else if (win.isAnimating()) {
2468 // Currently in a hide animation... turn this into
2469 // an exit.
2470 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002471 } else if (win == mWallpaperTarget) {
2472 // If the wallpaper is currently behind this
2473 // window, we need to change both of them inside
2474 // of a transaction to avoid artifacts.
2475 win.mExiting = true;
2476 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002477 } else {
2478 if (mInputMethodWindow == win) {
2479 mInputMethodWindow = null;
2480 }
2481 win.destroySurfaceLocked();
2482 }
2483 }
2484 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002485
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002486 if (win.mSurface == null || (win.getAttrs().flags
2487 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2488 || win.mSurfacePendingDestroy) {
2489 // We are being called from a local process, which
2490 // means outSurface holds its current surface. Ensure the
2491 // surface object is cleared, but we don't want it actually
2492 // destroyed at this point.
2493 win.mSurfacePendingDestroy = false;
2494 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002495 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002496 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002497 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002498 "Keeping surface, will report destroy: " + win);
2499 win.mReportDestroySurface = true;
2500 outSurface.copyFrom(win.mSurface);
2501 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002502 }
2503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002504 if (focusMayChange) {
2505 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2506 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002507 imMayMove = false;
2508 }
2509 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2510 }
Romain Guy06882f82009-06-10 13:36:04 -07002511
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002512 // updateFocusedWindowLocked() already assigned layers so we only need to
2513 // reassign them at this point if the IM window state gets shuffled
2514 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002516 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002517 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2518 // Little hack here -- we -should- be able to rely on the
2519 // function to return true if the IME has moved and needs
2520 // its layer recomputed. However, if the IME was hidden
2521 // and isn't actually moved in the list, its layer may be
2522 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002523 assignLayers = true;
2524 }
2525 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002526 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002527 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002528 assignLayers = true;
2529 }
2530 }
Romain Guy06882f82009-06-10 13:36:04 -07002531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002532 mLayoutNeeded = true;
2533 win.mGivenInsetsPending = insetsPending;
2534 if (assignLayers) {
2535 assignLayersLocked();
2536 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002537 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002538 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002539 if (displayed && win.mIsWallpaper) {
2540 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002541 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002542 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002543 if (win.mAppToken != null) {
2544 win.mAppToken.updateReportedVisibilityLocked();
2545 }
2546 outFrame.set(win.mFrame);
2547 outContentInsets.set(win.mContentInsets);
2548 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002549 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002550 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002551 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002552 + ", requestedHeight=" + requestedHeight
2553 + ", viewVisibility=" + viewVisibility
2554 + "\nRelayout returning frame=" + outFrame
2555 + ", surface=" + outSurface);
2556
Joe Onorato8a9b2202010-02-26 18:56:32 -08002557 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002558 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2559
2560 inTouchMode = mInTouchMode;
2561 }
2562
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002563 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002564 sendNewConfiguration();
2565 }
Romain Guy06882f82009-06-10 13:36:04 -07002566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002567 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002569 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2570 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2571 }
2572
2573 public void finishDrawingWindow(Session session, IWindow client) {
2574 final long origId = Binder.clearCallingIdentity();
2575 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002576 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002577 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002578 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2579 adjustWallpaperWindowsLocked();
2580 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002581 mLayoutNeeded = true;
2582 performLayoutAndPlaceSurfacesLocked();
2583 }
2584 }
2585 Binder.restoreCallingIdentity(origId);
2586 }
2587
2588 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002589 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002590 + (lp != null ? lp.packageName : null)
2591 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2592 if (lp != null && lp.windowAnimations != 0) {
2593 // If this is a system resource, don't try to load it from the
2594 // application resources. It is nice to avoid loading application
2595 // resources if we can.
2596 String packageName = lp.packageName != null ? lp.packageName : "android";
2597 int resId = lp.windowAnimations;
2598 if ((resId&0xFF000000) == 0x01000000) {
2599 packageName = "android";
2600 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002601 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002602 + packageName);
2603 return AttributeCache.instance().get(packageName, resId,
2604 com.android.internal.R.styleable.WindowAnimation);
2605 }
2606 return null;
2607 }
Romain Guy06882f82009-06-10 13:36:04 -07002608
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002609 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002610 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002611 + packageName + " resId=0x" + Integer.toHexString(resId));
2612 if (packageName != null) {
2613 if ((resId&0xFF000000) == 0x01000000) {
2614 packageName = "android";
2615 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002616 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002617 + packageName);
2618 return AttributeCache.instance().get(packageName, resId,
2619 com.android.internal.R.styleable.WindowAnimation);
2620 }
2621 return null;
2622 }
2623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002624 private void applyEnterAnimationLocked(WindowState win) {
2625 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2626 if (win.mEnterAnimationPending) {
2627 win.mEnterAnimationPending = false;
2628 transit = WindowManagerPolicy.TRANSIT_ENTER;
2629 }
2630
2631 applyAnimationLocked(win, transit, true);
2632 }
2633
2634 private boolean applyAnimationLocked(WindowState win,
2635 int transit, boolean isEntrance) {
2636 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2637 // If we are trying to apply an animation, but already running
2638 // an animation of the same type, then just leave that one alone.
2639 return true;
2640 }
Romain Guy06882f82009-06-10 13:36:04 -07002641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002642 // Only apply an animation if the display isn't frozen. If it is
2643 // frozen, there is no reason to animate and it can cause strange
2644 // artifacts when we unfreeze the display if some different animation
2645 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002646 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002647 int anim = mPolicy.selectAnimationLw(win, transit);
2648 int attr = -1;
2649 Animation a = null;
2650 if (anim != 0) {
2651 a = AnimationUtils.loadAnimation(mContext, anim);
2652 } else {
2653 switch (transit) {
2654 case WindowManagerPolicy.TRANSIT_ENTER:
2655 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2656 break;
2657 case WindowManagerPolicy.TRANSIT_EXIT:
2658 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2659 break;
2660 case WindowManagerPolicy.TRANSIT_SHOW:
2661 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2662 break;
2663 case WindowManagerPolicy.TRANSIT_HIDE:
2664 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2665 break;
2666 }
2667 if (attr >= 0) {
2668 a = loadAnimation(win.mAttrs, attr);
2669 }
2670 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002671 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002672 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2673 + " mAnimation=" + win.mAnimation
2674 + " isEntrance=" + isEntrance);
2675 if (a != null) {
2676 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002677 RuntimeException e = null;
2678 if (!HIDE_STACK_CRAWLS) {
2679 e = new RuntimeException();
2680 e.fillInStackTrace();
2681 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002682 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002683 }
2684 win.setAnimation(a);
2685 win.mAnimationIsEntrance = isEntrance;
2686 }
2687 } else {
2688 win.clearAnimation();
2689 }
2690
2691 return win.mAnimation != null;
2692 }
2693
2694 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2695 int anim = 0;
2696 Context context = mContext;
2697 if (animAttr >= 0) {
2698 AttributeCache.Entry ent = getCachedAnimations(lp);
2699 if (ent != null) {
2700 context = ent.context;
2701 anim = ent.array.getResourceId(animAttr, 0);
2702 }
2703 }
2704 if (anim != 0) {
2705 return AnimationUtils.loadAnimation(context, anim);
2706 }
2707 return null;
2708 }
Romain Guy06882f82009-06-10 13:36:04 -07002709
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002710 private Animation loadAnimation(String packageName, int resId) {
2711 int anim = 0;
2712 Context context = mContext;
2713 if (resId >= 0) {
2714 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2715 if (ent != null) {
2716 context = ent.context;
2717 anim = resId;
2718 }
2719 }
2720 if (anim != 0) {
2721 return AnimationUtils.loadAnimation(context, anim);
2722 }
2723 return null;
2724 }
2725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002726 private boolean applyAnimationLocked(AppWindowToken wtoken,
2727 WindowManager.LayoutParams lp, int transit, boolean enter) {
2728 // Only apply an animation if the display isn't frozen. If it is
2729 // frozen, there is no reason to animate and it can cause strange
2730 // artifacts when we unfreeze the display if some different animation
2731 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002732 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002733 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002734 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002735 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002736 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002737 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002738 } else if (mNextAppTransitionPackage != null) {
2739 a = loadAnimation(mNextAppTransitionPackage, enter ?
2740 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002741 } else {
2742 int animAttr = 0;
2743 switch (transit) {
2744 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2745 animAttr = enter
2746 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2747 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2748 break;
2749 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2750 animAttr = enter
2751 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2752 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2753 break;
2754 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2755 animAttr = enter
2756 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2757 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2758 break;
2759 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2760 animAttr = enter
2761 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2762 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2763 break;
2764 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2765 animAttr = enter
2766 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2767 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2768 break;
2769 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2770 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002771 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002772 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2773 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002774 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002775 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002776 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2777 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002778 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002779 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002780 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002781 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2782 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2783 break;
2784 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2785 animAttr = enter
2786 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2787 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2788 break;
2789 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2790 animAttr = enter
2791 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2792 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002793 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002794 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002795 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002796 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002797 + " anim=" + a
2798 + " animAttr=0x" + Integer.toHexString(animAttr)
2799 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002800 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002801 if (a != null) {
2802 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002803 RuntimeException e = null;
2804 if (!HIDE_STACK_CRAWLS) {
2805 e = new RuntimeException();
2806 e.fillInStackTrace();
2807 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002808 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002809 }
2810 wtoken.setAnimation(a);
2811 }
2812 } else {
2813 wtoken.clearAnimation();
2814 }
2815
2816 return wtoken.animation != null;
2817 }
2818
2819 // -------------------------------------------------------------
2820 // Application Window Tokens
2821 // -------------------------------------------------------------
2822
2823 public void validateAppTokens(List tokens) {
2824 int v = tokens.size()-1;
2825 int m = mAppTokens.size()-1;
2826 while (v >= 0 && m >= 0) {
2827 AppWindowToken wtoken = mAppTokens.get(m);
2828 if (wtoken.removed) {
2829 m--;
2830 continue;
2831 }
2832 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002833 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002834 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2835 }
2836 v--;
2837 m--;
2838 }
2839 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002840 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002841 v--;
2842 }
2843 while (m >= 0) {
2844 AppWindowToken wtoken = mAppTokens.get(m);
2845 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002846 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002847 }
2848 m--;
2849 }
2850 }
2851
2852 boolean checkCallingPermission(String permission, String func) {
2853 // Quick check: if the calling permission is me, it's all okay.
2854 if (Binder.getCallingPid() == Process.myPid()) {
2855 return true;
2856 }
Romain Guy06882f82009-06-10 13:36:04 -07002857
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002858 if (mContext.checkCallingPermission(permission)
2859 == PackageManager.PERMISSION_GRANTED) {
2860 return true;
2861 }
2862 String msg = "Permission Denial: " + func + " from pid="
2863 + Binder.getCallingPid()
2864 + ", uid=" + Binder.getCallingUid()
2865 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002866 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002867 return false;
2868 }
Romain Guy06882f82009-06-10 13:36:04 -07002869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002870 AppWindowToken findAppWindowToken(IBinder token) {
2871 WindowToken wtoken = mTokenMap.get(token);
2872 if (wtoken == null) {
2873 return null;
2874 }
2875 return wtoken.appWindowToken;
2876 }
Romain Guy06882f82009-06-10 13:36:04 -07002877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002878 public void addWindowToken(IBinder token, int type) {
2879 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2880 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002881 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002882 }
Romain Guy06882f82009-06-10 13:36:04 -07002883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002884 synchronized(mWindowMap) {
2885 WindowToken wtoken = mTokenMap.get(token);
2886 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002887 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002888 return;
2889 }
2890 wtoken = new WindowToken(token, type, true);
2891 mTokenMap.put(token, wtoken);
2892 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002893 if (type == TYPE_WALLPAPER) {
2894 mWallpaperTokens.add(wtoken);
2895 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002896 }
2897 }
Romain Guy06882f82009-06-10 13:36:04 -07002898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002899 public void removeWindowToken(IBinder token) {
2900 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2901 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002902 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002903 }
2904
2905 final long origId = Binder.clearCallingIdentity();
2906 synchronized(mWindowMap) {
2907 WindowToken wtoken = mTokenMap.remove(token);
2908 mTokenList.remove(wtoken);
2909 if (wtoken != null) {
2910 boolean delayed = false;
2911 if (!wtoken.hidden) {
2912 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002914 final int N = wtoken.windows.size();
2915 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002917 for (int i=0; i<N; i++) {
2918 WindowState win = wtoken.windows.get(i);
2919
2920 if (win.isAnimating()) {
2921 delayed = true;
2922 }
Romain Guy06882f82009-06-10 13:36:04 -07002923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002924 if (win.isVisibleNow()) {
2925 applyAnimationLocked(win,
2926 WindowManagerPolicy.TRANSIT_EXIT, false);
2927 mKeyWaiter.finishedKey(win.mSession, win.mClient, true,
2928 KeyWaiter.RETURN_NOTHING);
2929 changed = true;
2930 }
2931 }
2932
2933 if (changed) {
2934 mLayoutNeeded = true;
2935 performLayoutAndPlaceSurfacesLocked();
2936 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2937 }
Romain Guy06882f82009-06-10 13:36:04 -07002938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002939 if (delayed) {
2940 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002941 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2942 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002943 }
2944 }
Romain Guy06882f82009-06-10 13:36:04 -07002945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002946 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002947 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002948 }
2949 }
2950 Binder.restoreCallingIdentity(origId);
2951 }
2952
2953 public void addAppToken(int addPos, IApplicationToken token,
2954 int groupId, int requestedOrientation, boolean fullscreen) {
2955 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2956 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002957 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002958 }
Romain Guy06882f82009-06-10 13:36:04 -07002959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002960 synchronized(mWindowMap) {
2961 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2962 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002963 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002964 return;
2965 }
2966 wtoken = new AppWindowToken(token);
2967 wtoken.groupId = groupId;
2968 wtoken.appFullscreen = fullscreen;
2969 wtoken.requestedOrientation = requestedOrientation;
2970 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002971 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002972 mTokenMap.put(token.asBinder(), wtoken);
2973 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002975 // Application tokens start out hidden.
2976 wtoken.hidden = true;
2977 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002979 //dump();
2980 }
2981 }
Romain Guy06882f82009-06-10 13:36:04 -07002982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002983 public void setAppGroupId(IBinder token, int groupId) {
2984 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2985 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002986 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987 }
2988
2989 synchronized(mWindowMap) {
2990 AppWindowToken wtoken = findAppWindowToken(token);
2991 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002992 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002993 return;
2994 }
2995 wtoken.groupId = groupId;
2996 }
2997 }
Romain Guy06882f82009-06-10 13:36:04 -07002998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999 public int getOrientationFromWindowsLocked() {
3000 int pos = mWindows.size() - 1;
3001 while (pos >= 0) {
3002 WindowState wtoken = (WindowState) mWindows.get(pos);
3003 pos--;
3004 if (wtoken.mAppToken != null) {
3005 // We hit an application window. so the orientation will be determined by the
3006 // app window. No point in continuing further.
3007 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3008 }
3009 if (!wtoken.isVisibleLw()) {
3010 continue;
3011 }
3012 int req = wtoken.mAttrs.screenOrientation;
3013 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3014 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3015 continue;
3016 } else {
3017 return req;
3018 }
3019 }
3020 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3021 }
Romain Guy06882f82009-06-10 13:36:04 -07003022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003023 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003024 int pos = mAppTokens.size() - 1;
3025 int curGroup = 0;
3026 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3027 boolean findingBehind = false;
3028 boolean haveGroup = false;
3029 boolean lastFullscreen = false;
3030 while (pos >= 0) {
3031 AppWindowToken wtoken = mAppTokens.get(pos);
3032 pos--;
3033 // if we're about to tear down this window and not seek for
3034 // the behind activity, don't use it for orientation
3035 if (!findingBehind
3036 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3037 continue;
3038 }
3039
3040 if (!haveGroup) {
3041 // We ignore any hidden applications on the top.
3042 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003043 continue;
3044 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003045 haveGroup = true;
3046 curGroup = wtoken.groupId;
3047 lastOrientation = wtoken.requestedOrientation;
3048 } else if (curGroup != wtoken.groupId) {
3049 // If we have hit a new application group, and the bottom
3050 // of the previous group didn't explicitly say to use
3051 // the orientation behind it, and the last app was
3052 // full screen, then we'll stick with the
3053 // user's orientation.
3054 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3055 && lastFullscreen) {
3056 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003057 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003058 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003059 int or = wtoken.requestedOrientation;
3060 // If this application is fullscreen, and didn't explicitly say
3061 // to use the orientation behind it, then just take whatever
3062 // orientation it has and ignores whatever is under it.
3063 lastFullscreen = wtoken.appFullscreen;
3064 if (lastFullscreen
3065 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3066 return or;
3067 }
3068 // If this application has requested an explicit orientation,
3069 // then use it.
3070 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3071 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3072 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3073 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3074 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3075 return or;
3076 }
3077 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3078 }
3079 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003080 }
Romain Guy06882f82009-06-10 13:36:04 -07003081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003082 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003083 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003084 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3085 "updateOrientationFromAppTokens()")) {
3086 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3087 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003088
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003089 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003090 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003091
3092 synchronized(mWindowMap) {
3093 if (updateOrientationFromAppTokensLocked()) {
3094 if (freezeThisOneIfNeeded != null) {
3095 AppWindowToken wtoken = findAppWindowToken(
3096 freezeThisOneIfNeeded);
3097 if (wtoken != null) {
3098 startAppFreezingScreenLocked(wtoken,
3099 ActivityInfo.CONFIG_ORIENTATION);
3100 }
3101 }
3102 config = computeNewConfigurationLocked();
3103
3104 } else if (currentConfig != null) {
3105 // No obvious action we need to take, but if our current
3106 // state mismatches the activity maanager's, update it
3107 mTempConfiguration.setToDefaults();
3108 if (computeNewConfigurationLocked(mTempConfiguration)) {
3109 if (currentConfig.diff(mTempConfiguration) != 0) {
3110 mWaitingForConfig = true;
3111 mLayoutNeeded = true;
3112 startFreezingDisplayLocked();
3113 config = new Configuration(mTempConfiguration);
3114 }
3115 }
3116 }
3117 }
3118
Dianne Hackborncfaef692009-06-15 14:24:44 -07003119 Binder.restoreCallingIdentity(ident);
3120 return config;
3121 }
3122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003123 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003124 * Determine the new desired orientation of the display, returning
3125 * a non-null new Configuration if it has changed from the current
3126 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3127 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3128 * SCREEN. This will typically be done for you if you call
3129 * sendNewConfiguration().
3130 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003131 * The orientation is computed from non-application windows first. If none of
3132 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003133 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003134 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3135 * android.os.IBinder)
3136 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003137 boolean updateOrientationFromAppTokensLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003138 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003139 long ident = Binder.clearCallingIdentity();
3140 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003141 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003143 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003144 mForcedAppOrientation = req;
3145 //send a message to Policy indicating orientation change to take
3146 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003147 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003148 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3149 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3150 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003151 }
3152 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003153
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003154 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003155 } finally {
3156 Binder.restoreCallingIdentity(ident);
3157 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003158 }
Romain Guy06882f82009-06-10 13:36:04 -07003159
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003160 int computeForcedAppOrientationLocked() {
3161 int req = getOrientationFromWindowsLocked();
3162 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3163 req = getOrientationFromAppTokensLocked();
3164 }
3165 return req;
3166 }
Romain Guy06882f82009-06-10 13:36:04 -07003167
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003168 public void setNewConfiguration(Configuration config) {
3169 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3170 "setNewConfiguration()")) {
3171 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3172 }
3173
3174 synchronized(mWindowMap) {
3175 mCurConfiguration = new Configuration(config);
3176 mWaitingForConfig = false;
3177 performLayoutAndPlaceSurfacesLocked();
3178 }
3179 }
3180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003181 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3182 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3183 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003184 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003185 }
Romain Guy06882f82009-06-10 13:36:04 -07003186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 synchronized(mWindowMap) {
3188 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3189 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003190 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003191 return;
3192 }
Romain Guy06882f82009-06-10 13:36:04 -07003193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003194 wtoken.requestedOrientation = requestedOrientation;
3195 }
3196 }
Romain Guy06882f82009-06-10 13:36:04 -07003197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003198 public int getAppOrientation(IApplicationToken token) {
3199 synchronized(mWindowMap) {
3200 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3201 if (wtoken == null) {
3202 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3203 }
Romain Guy06882f82009-06-10 13:36:04 -07003204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003205 return wtoken.requestedOrientation;
3206 }
3207 }
Romain Guy06882f82009-06-10 13:36:04 -07003208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003209 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3210 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3211 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003212 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003213 }
3214
3215 synchronized(mWindowMap) {
3216 boolean changed = false;
3217 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003218 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003219 changed = mFocusedApp != null;
3220 mFocusedApp = null;
3221 mKeyWaiter.tickle();
3222 } else {
3223 AppWindowToken newFocus = findAppWindowToken(token);
3224 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003225 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003226 return;
3227 }
3228 changed = mFocusedApp != newFocus;
3229 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003230 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003231 mKeyWaiter.tickle();
3232 }
3233
3234 if (moveFocusNow && changed) {
3235 final long origId = Binder.clearCallingIdentity();
3236 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3237 Binder.restoreCallingIdentity(origId);
3238 }
3239 }
3240 }
3241
3242 public void prepareAppTransition(int transit) {
3243 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3244 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003245 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003246 }
Romain Guy06882f82009-06-10 13:36:04 -07003247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003248 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003249 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003250 TAG, "Prepare app transition: transit=" + transit
3251 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003252 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003253 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3254 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003255 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003256 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3257 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3258 // Opening a new task always supersedes a close for the anim.
3259 mNextAppTransition = transit;
3260 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3261 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3262 // Opening a new activity always supersedes a close for the anim.
3263 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003264 }
3265 mAppTransitionReady = false;
3266 mAppTransitionTimeout = false;
3267 mStartingIconInTransition = false;
3268 mSkipAppTransitionAnimation = false;
3269 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3270 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3271 5000);
3272 }
3273 }
3274 }
3275
3276 public int getPendingAppTransition() {
3277 return mNextAppTransition;
3278 }
Romain Guy06882f82009-06-10 13:36:04 -07003279
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003280 public void overridePendingAppTransition(String packageName,
3281 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003282 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003283 mNextAppTransitionPackage = packageName;
3284 mNextAppTransitionEnter = enterAnim;
3285 mNextAppTransitionExit = exitAnim;
3286 }
3287 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003289 public void executeAppTransition() {
3290 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3291 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003292 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003293 }
Romain Guy06882f82009-06-10 13:36:04 -07003294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003295 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003296 if (DEBUG_APP_TRANSITIONS) {
3297 RuntimeException e = new RuntimeException("here");
3298 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003299 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003300 + mNextAppTransition, e);
3301 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003302 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003303 mAppTransitionReady = true;
3304 final long origId = Binder.clearCallingIdentity();
3305 performLayoutAndPlaceSurfacesLocked();
3306 Binder.restoreCallingIdentity(origId);
3307 }
3308 }
3309 }
3310
3311 public void setAppStartingWindow(IBinder token, String pkg,
3312 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3313 IBinder transferFrom, boolean createIfNeeded) {
3314 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3315 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003316 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003317 }
3318
3319 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003320 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003321 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3322 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003324 AppWindowToken wtoken = findAppWindowToken(token);
3325 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003326 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003327 return;
3328 }
3329
3330 // If the display is frozen, we won't do anything until the
3331 // actual window is displayed so there is no reason to put in
3332 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003333 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003334 return;
3335 }
Romain Guy06882f82009-06-10 13:36:04 -07003336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003337 if (wtoken.startingData != null) {
3338 return;
3339 }
Romain Guy06882f82009-06-10 13:36:04 -07003340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003341 if (transferFrom != null) {
3342 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3343 if (ttoken != null) {
3344 WindowState startingWindow = ttoken.startingWindow;
3345 if (startingWindow != null) {
3346 if (mStartingIconInTransition) {
3347 // In this case, the starting icon has already
3348 // been displayed, so start letting windows get
3349 // shown immediately without any more transitions.
3350 mSkipAppTransitionAnimation = true;
3351 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003352 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003353 "Moving existing starting from " + ttoken
3354 + " to " + wtoken);
3355 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003357 // Transfer the starting window over to the new
3358 // token.
3359 wtoken.startingData = ttoken.startingData;
3360 wtoken.startingView = ttoken.startingView;
3361 wtoken.startingWindow = startingWindow;
3362 ttoken.startingData = null;
3363 ttoken.startingView = null;
3364 ttoken.startingWindow = null;
3365 ttoken.startingMoved = true;
3366 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003367 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003368 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003369 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003370 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003371 mWindows.remove(startingWindow);
3372 ttoken.windows.remove(startingWindow);
3373 ttoken.allAppWindows.remove(startingWindow);
3374 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003376 // Propagate other interesting state between the
3377 // tokens. If the old token is displayed, we should
3378 // immediately force the new one to be displayed. If
3379 // it is animating, we need to move that animation to
3380 // the new one.
3381 if (ttoken.allDrawn) {
3382 wtoken.allDrawn = true;
3383 }
3384 if (ttoken.firstWindowDrawn) {
3385 wtoken.firstWindowDrawn = true;
3386 }
3387 if (!ttoken.hidden) {
3388 wtoken.hidden = false;
3389 wtoken.hiddenRequested = false;
3390 wtoken.willBeHidden = false;
3391 }
3392 if (wtoken.clientHidden != ttoken.clientHidden) {
3393 wtoken.clientHidden = ttoken.clientHidden;
3394 wtoken.sendAppVisibilityToClients();
3395 }
3396 if (ttoken.animation != null) {
3397 wtoken.animation = ttoken.animation;
3398 wtoken.animating = ttoken.animating;
3399 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3400 ttoken.animation = null;
3401 ttoken.animLayerAdjustment = 0;
3402 wtoken.updateLayers();
3403 ttoken.updateLayers();
3404 }
Romain Guy06882f82009-06-10 13:36:04 -07003405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003406 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003407 mLayoutNeeded = true;
3408 performLayoutAndPlaceSurfacesLocked();
3409 Binder.restoreCallingIdentity(origId);
3410 return;
3411 } else if (ttoken.startingData != null) {
3412 // The previous app was getting ready to show a
3413 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003414 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003415 "Moving pending starting from " + ttoken
3416 + " to " + wtoken);
3417 wtoken.startingData = ttoken.startingData;
3418 ttoken.startingData = null;
3419 ttoken.startingMoved = true;
3420 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3421 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3422 // want to process the message ASAP, before any other queued
3423 // messages.
3424 mH.sendMessageAtFrontOfQueue(m);
3425 return;
3426 }
3427 }
3428 }
3429
3430 // There is no existing starting window, and the caller doesn't
3431 // want us to create one, so that's it!
3432 if (!createIfNeeded) {
3433 return;
3434 }
Romain Guy06882f82009-06-10 13:36:04 -07003435
Dianne Hackborn284ac932009-08-28 10:34:25 -07003436 // If this is a translucent or wallpaper window, then don't
3437 // show a starting window -- the current effect (a full-screen
3438 // opaque starting window that fades away to the real contents
3439 // when it is ready) does not work for this.
3440 if (theme != 0) {
3441 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3442 com.android.internal.R.styleable.Window);
3443 if (ent.array.getBoolean(
3444 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3445 return;
3446 }
3447 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003448 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3449 return;
3450 }
3451 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003452 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3453 return;
3454 }
3455 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003457 mStartingIconInTransition = true;
3458 wtoken.startingData = new StartingData(
3459 pkg, theme, nonLocalizedLabel,
3460 labelRes, icon);
3461 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3462 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3463 // want to process the message ASAP, before any other queued
3464 // messages.
3465 mH.sendMessageAtFrontOfQueue(m);
3466 }
3467 }
3468
3469 public void setAppWillBeHidden(IBinder token) {
3470 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3471 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003472 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003473 }
3474
3475 AppWindowToken wtoken;
3476
3477 synchronized(mWindowMap) {
3478 wtoken = findAppWindowToken(token);
3479 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003480 Slog.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003481 return;
3482 }
3483 wtoken.willBeHidden = true;
3484 }
3485 }
Romain Guy06882f82009-06-10 13:36:04 -07003486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003487 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3488 boolean visible, int transit, boolean performLayout) {
3489 boolean delayed = false;
3490
3491 if (wtoken.clientHidden == visible) {
3492 wtoken.clientHidden = !visible;
3493 wtoken.sendAppVisibilityToClients();
3494 }
Romain Guy06882f82009-06-10 13:36:04 -07003495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003496 wtoken.willBeHidden = false;
3497 if (wtoken.hidden == visible) {
3498 final int N = wtoken.allAppWindows.size();
3499 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003500 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003501 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3502 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003504 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003505
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003506 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003507 if (wtoken.animation == sDummyAnimation) {
3508 wtoken.animation = null;
3509 }
3510 applyAnimationLocked(wtoken, lp, transit, visible);
3511 changed = true;
3512 if (wtoken.animation != null) {
3513 delayed = runningAppAnimation = true;
3514 }
3515 }
Romain Guy06882f82009-06-10 13:36:04 -07003516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003517 for (int i=0; i<N; i++) {
3518 WindowState win = wtoken.allAppWindows.get(i);
3519 if (win == wtoken.startingWindow) {
3520 continue;
3521 }
3522
3523 if (win.isAnimating()) {
3524 delayed = true;
3525 }
Romain Guy06882f82009-06-10 13:36:04 -07003526
Joe Onorato8a9b2202010-02-26 18:56:32 -08003527 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003528 //win.dump(" ");
3529 if (visible) {
3530 if (!win.isVisibleNow()) {
3531 if (!runningAppAnimation) {
3532 applyAnimationLocked(win,
3533 WindowManagerPolicy.TRANSIT_ENTER, true);
3534 }
3535 changed = true;
3536 }
3537 } else if (win.isVisibleNow()) {
3538 if (!runningAppAnimation) {
3539 applyAnimationLocked(win,
3540 WindowManagerPolicy.TRANSIT_EXIT, false);
3541 }
3542 mKeyWaiter.finishedKey(win.mSession, win.mClient, true,
3543 KeyWaiter.RETURN_NOTHING);
3544 changed = true;
3545 }
3546 }
3547
3548 wtoken.hidden = wtoken.hiddenRequested = !visible;
3549 if (!visible) {
3550 unsetAppFreezingScreenLocked(wtoken, true, true);
3551 } else {
3552 // If we are being set visible, and the starting window is
3553 // not yet displayed, then make sure it doesn't get displayed.
3554 WindowState swin = wtoken.startingWindow;
3555 if (swin != null && (swin.mDrawPending
3556 || swin.mCommitDrawPending)) {
3557 swin.mPolicyVisibility = false;
3558 swin.mPolicyVisibilityAfterAnim = false;
3559 }
3560 }
Romain Guy06882f82009-06-10 13:36:04 -07003561
Joe Onorato8a9b2202010-02-26 18:56:32 -08003562 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003563 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3564 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003565
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003566 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003567 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003568 if (performLayout) {
3569 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3570 performLayoutAndPlaceSurfacesLocked();
3571 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003572 }
3573 }
3574
3575 if (wtoken.animation != null) {
3576 delayed = true;
3577 }
Romain Guy06882f82009-06-10 13:36:04 -07003578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003579 return delayed;
3580 }
3581
3582 public void setAppVisibility(IBinder token, boolean visible) {
3583 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3584 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003585 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003586 }
3587
3588 AppWindowToken wtoken;
3589
3590 synchronized(mWindowMap) {
3591 wtoken = findAppWindowToken(token);
3592 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003593 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003594 return;
3595 }
3596
3597 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003598 RuntimeException e = null;
3599 if (!HIDE_STACK_CRAWLS) {
3600 e = new RuntimeException();
3601 e.fillInStackTrace();
3602 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003603 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003604 + "): mNextAppTransition=" + mNextAppTransition
3605 + " hidden=" + wtoken.hidden
3606 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3607 }
Romain Guy06882f82009-06-10 13:36:04 -07003608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003609 // If we are preparing an app transition, then delay changing
3610 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003611 if (!mDisplayFrozen && mPolicy.isScreenOn()
3612 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003613 // Already in requested state, don't do anything more.
3614 if (wtoken.hiddenRequested != visible) {
3615 return;
3616 }
3617 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003618
Joe Onorato8a9b2202010-02-26 18:56:32 -08003619 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003620 TAG, "Setting dummy animation on: " + wtoken);
3621 wtoken.setDummyAnimation();
3622 mOpeningApps.remove(wtoken);
3623 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003624 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003625 wtoken.inPendingTransaction = true;
3626 if (visible) {
3627 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003628 wtoken.startingDisplayed = false;
3629 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003630
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003631 // If the token is currently hidden (should be the
3632 // common case), then we need to set up to wait for
3633 // its windows to be ready.
3634 if (wtoken.hidden) {
3635 wtoken.allDrawn = false;
3636 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003637
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003638 if (wtoken.clientHidden) {
3639 // In the case where we are making an app visible
3640 // but holding off for a transition, we still need
3641 // to tell the client to make its windows visible so
3642 // they get drawn. Otherwise, we will wait on
3643 // performing the transition until all windows have
3644 // been drawn, they never will be, and we are sad.
3645 wtoken.clientHidden = false;
3646 wtoken.sendAppVisibilityToClients();
3647 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003648 }
3649 } else {
3650 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003651
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003652 // If the token is currently visible (should be the
3653 // common case), then set up to wait for it to be hidden.
3654 if (!wtoken.hidden) {
3655 wtoken.waitingToHide = true;
3656 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003657 }
3658 return;
3659 }
Romain Guy06882f82009-06-10 13:36:04 -07003660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003661 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003662 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003663 wtoken.updateReportedVisibilityLocked();
3664 Binder.restoreCallingIdentity(origId);
3665 }
3666 }
3667
3668 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3669 boolean unfreezeSurfaceNow, boolean force) {
3670 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003671 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003672 + " force=" + force);
3673 final int N = wtoken.allAppWindows.size();
3674 boolean unfrozeWindows = false;
3675 for (int i=0; i<N; i++) {
3676 WindowState w = wtoken.allAppWindows.get(i);
3677 if (w.mAppFreezing) {
3678 w.mAppFreezing = false;
3679 if (w.mSurface != null && !w.mOrientationChanging) {
3680 w.mOrientationChanging = true;
3681 }
3682 unfrozeWindows = true;
3683 }
3684 }
3685 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003686 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003687 wtoken.freezingScreen = false;
3688 mAppsFreezingScreen--;
3689 }
3690 if (unfreezeSurfaceNow) {
3691 if (unfrozeWindows) {
3692 mLayoutNeeded = true;
3693 performLayoutAndPlaceSurfacesLocked();
3694 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003695 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003696 }
3697 }
3698 }
Romain Guy06882f82009-06-10 13:36:04 -07003699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003700 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3701 int configChanges) {
3702 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003703 RuntimeException e = null;
3704 if (!HIDE_STACK_CRAWLS) {
3705 e = new RuntimeException();
3706 e.fillInStackTrace();
3707 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003708 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003709 + ": hidden=" + wtoken.hidden + " freezing="
3710 + wtoken.freezingScreen, e);
3711 }
3712 if (!wtoken.hiddenRequested) {
3713 if (!wtoken.freezingScreen) {
3714 wtoken.freezingScreen = true;
3715 mAppsFreezingScreen++;
3716 if (mAppsFreezingScreen == 1) {
3717 startFreezingDisplayLocked();
3718 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3719 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3720 5000);
3721 }
3722 }
3723 final int N = wtoken.allAppWindows.size();
3724 for (int i=0; i<N; i++) {
3725 WindowState w = wtoken.allAppWindows.get(i);
3726 w.mAppFreezing = true;
3727 }
3728 }
3729 }
Romain Guy06882f82009-06-10 13:36:04 -07003730
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003731 public void startAppFreezingScreen(IBinder token, int configChanges) {
3732 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3733 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003734 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003735 }
3736
3737 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003738 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003739 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003740 return;
3741 }
Romain Guy06882f82009-06-10 13:36:04 -07003742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003743 AppWindowToken wtoken = findAppWindowToken(token);
3744 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003745 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003746 return;
3747 }
3748 final long origId = Binder.clearCallingIdentity();
3749 startAppFreezingScreenLocked(wtoken, configChanges);
3750 Binder.restoreCallingIdentity(origId);
3751 }
3752 }
Romain Guy06882f82009-06-10 13:36:04 -07003753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003754 public void stopAppFreezingScreen(IBinder token, boolean force) {
3755 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3756 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003757 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003758 }
3759
3760 synchronized(mWindowMap) {
3761 AppWindowToken wtoken = findAppWindowToken(token);
3762 if (wtoken == null || wtoken.appToken == null) {
3763 return;
3764 }
3765 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003766 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003767 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3768 unsetAppFreezingScreenLocked(wtoken, true, force);
3769 Binder.restoreCallingIdentity(origId);
3770 }
3771 }
Romain Guy06882f82009-06-10 13:36:04 -07003772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003773 public void removeAppToken(IBinder token) {
3774 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3775 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003776 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003777 }
3778
3779 AppWindowToken wtoken = null;
3780 AppWindowToken startingToken = null;
3781 boolean delayed = false;
3782
3783 final long origId = Binder.clearCallingIdentity();
3784 synchronized(mWindowMap) {
3785 WindowToken basewtoken = mTokenMap.remove(token);
3786 mTokenList.remove(basewtoken);
3787 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003788 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003789 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003790 wtoken.inPendingTransaction = false;
3791 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003792 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003793 if (mClosingApps.contains(wtoken)) {
3794 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003795 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003796 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003797 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003798 delayed = true;
3799 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003800 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003801 TAG, "Removing app " + wtoken + " delayed=" + delayed
3802 + " animation=" + wtoken.animation
3803 + " animating=" + wtoken.animating);
3804 if (delayed) {
3805 // set the token aside because it has an active animation to be finished
3806 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003807 } else {
3808 // Make sure there is no animation running on this token,
3809 // so any windows associated with it will be removed as
3810 // soon as their animations are complete
3811 wtoken.animation = null;
3812 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003813 }
3814 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003815 if (mLastEnterAnimToken == wtoken) {
3816 mLastEnterAnimToken = null;
3817 mLastEnterAnimParams = null;
3818 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003819 wtoken.removed = true;
3820 if (wtoken.startingData != null) {
3821 startingToken = wtoken;
3822 }
3823 unsetAppFreezingScreenLocked(wtoken, true, true);
3824 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003825 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 mFocusedApp = null;
3827 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3828 mKeyWaiter.tickle();
3829 }
3830 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003831 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003832 }
Romain Guy06882f82009-06-10 13:36:04 -07003833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003834 if (!delayed && wtoken != null) {
3835 wtoken.updateReportedVisibilityLocked();
3836 }
3837 }
3838 Binder.restoreCallingIdentity(origId);
3839
3840 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003841 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003842 + startingToken + ": app token removed");
3843 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3844 mH.sendMessage(m);
3845 }
3846 }
3847
3848 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3849 final int NW = token.windows.size();
3850 for (int i=0; i<NW; i++) {
3851 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003852 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003853 mWindows.remove(win);
3854 int j = win.mChildWindows.size();
3855 while (j > 0) {
3856 j--;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003857 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003858 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003859 "Tmp removing child window " + cwin);
3860 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003861 }
3862 }
3863 return NW > 0;
3864 }
3865
3866 void dumpAppTokensLocked() {
3867 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003868 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003869 }
3870 }
Romain Guy06882f82009-06-10 13:36:04 -07003871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003872 void dumpWindowsLocked() {
3873 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003874 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003875 }
3876 }
Romain Guy06882f82009-06-10 13:36:04 -07003877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003878 private int findWindowOffsetLocked(int tokenPos) {
3879 final int NW = mWindows.size();
3880
3881 if (tokenPos >= mAppTokens.size()) {
3882 int i = NW;
3883 while (i > 0) {
3884 i--;
3885 WindowState win = (WindowState)mWindows.get(i);
3886 if (win.getAppToken() != null) {
3887 return i+1;
3888 }
3889 }
3890 }
3891
3892 while (tokenPos > 0) {
3893 // Find the first app token below the new position that has
3894 // a window displayed.
3895 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003896 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003897 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003898 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003899 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003900 "Skipping token -- currently sending to bottom");
3901 tokenPos--;
3902 continue;
3903 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003904 int i = wtoken.windows.size();
3905 while (i > 0) {
3906 i--;
3907 WindowState win = wtoken.windows.get(i);
3908 int j = win.mChildWindows.size();
3909 while (j > 0) {
3910 j--;
3911 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003912 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003913 for (int pos=NW-1; pos>=0; pos--) {
3914 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003915 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003916 "Found child win @" + (pos+1));
3917 return pos+1;
3918 }
3919 }
3920 }
3921 }
3922 for (int pos=NW-1; pos>=0; pos--) {
3923 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003924 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003925 return pos+1;
3926 }
3927 }
3928 }
3929 tokenPos--;
3930 }
3931
3932 return 0;
3933 }
3934
3935 private final int reAddWindowLocked(int index, WindowState win) {
3936 final int NCW = win.mChildWindows.size();
3937 boolean added = false;
3938 for (int j=0; j<NCW; j++) {
3939 WindowState cwin = (WindowState)win.mChildWindows.get(j);
3940 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003941 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003942 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003943 mWindows.add(index, win);
3944 index++;
3945 added = true;
3946 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003947 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003948 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003949 mWindows.add(index, cwin);
3950 index++;
3951 }
3952 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003953 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003954 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003955 mWindows.add(index, win);
3956 index++;
3957 }
3958 return index;
3959 }
Romain Guy06882f82009-06-10 13:36:04 -07003960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003961 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3962 final int NW = token.windows.size();
3963 for (int i=0; i<NW; i++) {
3964 index = reAddWindowLocked(index, token.windows.get(i));
3965 }
3966 return index;
3967 }
3968
3969 public void moveAppToken(int index, IBinder token) {
3970 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3971 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003972 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003973 }
3974
3975 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003976 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003977 if (DEBUG_REORDER) dumpAppTokensLocked();
3978 final AppWindowToken wtoken = findAppWindowToken(token);
3979 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003980 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003981 + token + " (" + wtoken + ")");
3982 return;
3983 }
3984 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003985 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003986 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003988 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003989 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003990 if (DEBUG_REORDER) dumpWindowsLocked();
3991 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003992 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003993 if (DEBUG_REORDER) dumpWindowsLocked();
3994 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003995 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003996 if (DEBUG_REORDER) dumpWindowsLocked();
3997 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003998 mLayoutNeeded = true;
3999 performLayoutAndPlaceSurfacesLocked();
4000 }
4001 Binder.restoreCallingIdentity(origId);
4002 }
4003 }
4004
4005 private void removeAppTokensLocked(List<IBinder> tokens) {
4006 // XXX This should be done more efficiently!
4007 // (take advantage of the fact that both lists should be
4008 // ordered in the same way.)
4009 int N = tokens.size();
4010 for (int i=0; i<N; i++) {
4011 IBinder token = tokens.get(i);
4012 final AppWindowToken wtoken = findAppWindowToken(token);
4013 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004014 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004015 + token + " (" + wtoken + ")");
4016 i--;
4017 N--;
4018 }
4019 }
4020 }
4021
Dianne Hackborna8f60182009-09-01 19:01:50 -07004022 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4023 boolean updateFocusAndLayout) {
4024 // First remove all of the windows from the list.
4025 tmpRemoveAppWindowsLocked(wtoken);
4026
4027 // Where to start adding?
4028 int pos = findWindowOffsetLocked(tokenPos);
4029
4030 // And now add them back at the correct place.
4031 pos = reAddAppWindowsLocked(pos, wtoken);
4032
4033 if (updateFocusAndLayout) {
4034 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4035 assignLayersLocked();
4036 }
4037 mLayoutNeeded = true;
4038 performLayoutAndPlaceSurfacesLocked();
4039 }
4040 }
4041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004042 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4043 // First remove all of the windows from the list.
4044 final int N = tokens.size();
4045 int i;
4046 for (i=0; i<N; i++) {
4047 WindowToken token = mTokenMap.get(tokens.get(i));
4048 if (token != null) {
4049 tmpRemoveAppWindowsLocked(token);
4050 }
4051 }
4052
4053 // Where to start adding?
4054 int pos = findWindowOffsetLocked(tokenPos);
4055
4056 // And now add them back at the correct place.
4057 for (i=0; i<N; i++) {
4058 WindowToken token = mTokenMap.get(tokens.get(i));
4059 if (token != null) {
4060 pos = reAddAppWindowsLocked(pos, token);
4061 }
4062 }
4063
Dianne Hackborna8f60182009-09-01 19:01:50 -07004064 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4065 assignLayersLocked();
4066 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004067 mLayoutNeeded = true;
4068 performLayoutAndPlaceSurfacesLocked();
4069
4070 //dump();
4071 }
4072
4073 public void moveAppTokensToTop(List<IBinder> tokens) {
4074 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4075 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004076 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004077 }
4078
4079 final long origId = Binder.clearCallingIdentity();
4080 synchronized(mWindowMap) {
4081 removeAppTokensLocked(tokens);
4082 final int N = tokens.size();
4083 for (int i=0; i<N; i++) {
4084 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4085 if (wt != null) {
4086 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004087 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004088 mToTopApps.remove(wt);
4089 mToBottomApps.remove(wt);
4090 mToTopApps.add(wt);
4091 wt.sendingToBottom = false;
4092 wt.sendingToTop = true;
4093 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004094 }
4095 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004096
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004097 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004098 moveAppWindowsLocked(tokens, mAppTokens.size());
4099 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004100 }
4101 Binder.restoreCallingIdentity(origId);
4102 }
4103
4104 public void moveAppTokensToBottom(List<IBinder> tokens) {
4105 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4106 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004107 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004108 }
4109
4110 final long origId = Binder.clearCallingIdentity();
4111 synchronized(mWindowMap) {
4112 removeAppTokensLocked(tokens);
4113 final int N = tokens.size();
4114 int pos = 0;
4115 for (int i=0; i<N; i++) {
4116 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4117 if (wt != null) {
4118 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004119 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004120 mToTopApps.remove(wt);
4121 mToBottomApps.remove(wt);
4122 mToBottomApps.add(i, wt);
4123 wt.sendingToTop = false;
4124 wt.sendingToBottom = true;
4125 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004126 pos++;
4127 }
4128 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004129
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004130 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004131 moveAppWindowsLocked(tokens, 0);
4132 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004133 }
4134 Binder.restoreCallingIdentity(origId);
4135 }
4136
4137 // -------------------------------------------------------------
4138 // Misc IWindowSession methods
4139 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004141 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004142 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004143 != PackageManager.PERMISSION_GRANTED) {
4144 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4145 }
Mike Lockwood983ee092009-11-22 01:42:24 -05004146 synchronized (mKeyguardTokenWatcher) {
4147 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004148 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004149 }
4150
4151 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004152 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004153 != PackageManager.PERMISSION_GRANTED) {
4154 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4155 }
Mike Lockwood983ee092009-11-22 01:42:24 -05004156 synchronized (mKeyguardTokenWatcher) {
4157 mKeyguardTokenWatcher.release(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004158
Mike Lockwood983ee092009-11-22 01:42:24 -05004159 if (!mKeyguardTokenWatcher.isAcquired()) {
4160 // If we are the last one to reenable the keyguard wait until
4161 // we have actaully finished reenabling until returning.
4162 // It is possible that reenableKeyguard() can be called before
4163 // the previous disableKeyguard() is handled, in which case
4164 // neither mKeyguardTokenWatcher.acquired() or released() would
4165 // be called. In that case mKeyguardDisabled will be false here
4166 // and we have nothing to wait for.
4167 while (mKeyguardDisabled) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004168 try {
Mike Lockwood983ee092009-11-22 01:42:24 -05004169 mKeyguardTokenWatcher.wait();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004170 } catch (InterruptedException e) {
4171 Thread.currentThread().interrupt();
4172 }
4173 }
4174 }
4175 }
4176 }
4177
4178 /**
4179 * @see android.app.KeyguardManager#exitKeyguardSecurely
4180 */
4181 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004182 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004183 != PackageManager.PERMISSION_GRANTED) {
4184 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4185 }
4186 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4187 public void onKeyguardExitResult(boolean success) {
4188 try {
4189 callback.onKeyguardExitResult(success);
4190 } catch (RemoteException e) {
4191 // Client has died, we don't care.
4192 }
4193 }
4194 });
4195 }
4196
4197 public boolean inKeyguardRestrictedInputMode() {
4198 return mPolicy.inKeyguardRestrictedKeyInputMode();
4199 }
Romain Guy06882f82009-06-10 13:36:04 -07004200
Dianne Hackbornffa42482009-09-23 22:20:11 -07004201 public void closeSystemDialogs(String reason) {
4202 synchronized(mWindowMap) {
4203 for (int i=mWindows.size()-1; i>=0; i--) {
4204 WindowState w = (WindowState)mWindows.get(i);
4205 if (w.mSurface != null) {
4206 try {
4207 w.mClient.closeSystemDialogs(reason);
4208 } catch (RemoteException e) {
4209 }
4210 }
4211 }
4212 }
4213 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004215 static float fixScale(float scale) {
4216 if (scale < 0) scale = 0;
4217 else if (scale > 20) scale = 20;
4218 return Math.abs(scale);
4219 }
Romain Guy06882f82009-06-10 13:36:04 -07004220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004221 public void setAnimationScale(int which, float scale) {
4222 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4223 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004224 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004225 }
4226
4227 if (scale < 0) scale = 0;
4228 else if (scale > 20) scale = 20;
4229 scale = Math.abs(scale);
4230 switch (which) {
4231 case 0: mWindowAnimationScale = fixScale(scale); break;
4232 case 1: mTransitionAnimationScale = fixScale(scale); break;
4233 }
Romain Guy06882f82009-06-10 13:36:04 -07004234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004235 // Persist setting
4236 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4237 }
Romain Guy06882f82009-06-10 13:36:04 -07004238
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004239 public void setAnimationScales(float[] scales) {
4240 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4241 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004242 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004243 }
4244
4245 if (scales != null) {
4246 if (scales.length >= 1) {
4247 mWindowAnimationScale = fixScale(scales[0]);
4248 }
4249 if (scales.length >= 2) {
4250 mTransitionAnimationScale = fixScale(scales[1]);
4251 }
4252 }
Romain Guy06882f82009-06-10 13:36:04 -07004253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004254 // Persist setting
4255 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4256 }
Romain Guy06882f82009-06-10 13:36:04 -07004257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004258 public float getAnimationScale(int which) {
4259 switch (which) {
4260 case 0: return mWindowAnimationScale;
4261 case 1: return mTransitionAnimationScale;
4262 }
4263 return 0;
4264 }
Romain Guy06882f82009-06-10 13:36:04 -07004265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004266 public float[] getAnimationScales() {
4267 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4268 }
Romain Guy06882f82009-06-10 13:36:04 -07004269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004270 public int getSwitchState(int sw) {
4271 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4272 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004273 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004274 }
4275 return KeyInputQueue.getSwitchState(sw);
4276 }
Romain Guy06882f82009-06-10 13:36:04 -07004277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004278 public int getSwitchStateForDevice(int devid, int sw) {
4279 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4280 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004281 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004282 }
4283 return KeyInputQueue.getSwitchState(devid, sw);
4284 }
Romain Guy06882f82009-06-10 13:36:04 -07004285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004286 public int getScancodeState(int sw) {
4287 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4288 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004289 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004290 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004291 return mQueue.getScancodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004292 }
Romain Guy06882f82009-06-10 13:36:04 -07004293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004294 public int getScancodeStateForDevice(int devid, int sw) {
4295 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4296 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004297 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004298 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004299 return mQueue.getScancodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004300 }
Romain Guy06882f82009-06-10 13:36:04 -07004301
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004302 public int getTrackballScancodeState(int sw) {
4303 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4304 "getTrackballScancodeState()")) {
4305 throw new SecurityException("Requires READ_INPUT_STATE permission");
4306 }
4307 return mQueue.getTrackballScancodeState(sw);
4308 }
4309
4310 public int getDPadScancodeState(int sw) {
4311 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4312 "getDPadScancodeState()")) {
4313 throw new SecurityException("Requires READ_INPUT_STATE permission");
4314 }
4315 return mQueue.getDPadScancodeState(sw);
4316 }
4317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004318 public int getKeycodeState(int sw) {
4319 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4320 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004321 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004322 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004323 return mQueue.getKeycodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004324 }
Romain Guy06882f82009-06-10 13:36:04 -07004325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004326 public int getKeycodeStateForDevice(int devid, int sw) {
4327 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4328 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004329 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004330 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004331 return mQueue.getKeycodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004332 }
Romain Guy06882f82009-06-10 13:36:04 -07004333
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004334 public int getTrackballKeycodeState(int sw) {
4335 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4336 "getTrackballKeycodeState()")) {
4337 throw new SecurityException("Requires READ_INPUT_STATE permission");
4338 }
4339 return mQueue.getTrackballKeycodeState(sw);
4340 }
4341
4342 public int getDPadKeycodeState(int sw) {
4343 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4344 "getDPadKeycodeState()")) {
4345 throw new SecurityException("Requires READ_INPUT_STATE permission");
4346 }
4347 return mQueue.getDPadKeycodeState(sw);
4348 }
4349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004350 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
4351 return KeyInputQueue.hasKeys(keycodes, keyExists);
4352 }
Romain Guy06882f82009-06-10 13:36:04 -07004353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004354 public void enableScreenAfterBoot() {
4355 synchronized(mWindowMap) {
4356 if (mSystemBooted) {
4357 return;
4358 }
4359 mSystemBooted = true;
4360 }
Romain Guy06882f82009-06-10 13:36:04 -07004361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004362 performEnableScreen();
4363 }
Romain Guy06882f82009-06-10 13:36:04 -07004364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004365 public void enableScreenIfNeededLocked() {
4366 if (mDisplayEnabled) {
4367 return;
4368 }
4369 if (!mSystemBooted) {
4370 return;
4371 }
4372 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4373 }
Romain Guy06882f82009-06-10 13:36:04 -07004374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004375 public void performEnableScreen() {
4376 synchronized(mWindowMap) {
4377 if (mDisplayEnabled) {
4378 return;
4379 }
4380 if (!mSystemBooted) {
4381 return;
4382 }
Romain Guy06882f82009-06-10 13:36:04 -07004383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004384 // Don't enable the screen until all existing windows
4385 // have been drawn.
4386 final int N = mWindows.size();
4387 for (int i=0; i<N; i++) {
4388 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004389 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004390 return;
4391 }
4392 }
Romain Guy06882f82009-06-10 13:36:04 -07004393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004394 mDisplayEnabled = true;
4395 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004396 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004397 StringWriter sw = new StringWriter();
4398 PrintWriter pw = new PrintWriter(sw);
4399 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004400 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004401 }
4402 try {
4403 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4404 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004405 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004406 Parcel data = Parcel.obtain();
4407 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4408 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4409 data, null, 0);
4410 data.recycle();
4411 }
4412 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004413 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004414 }
4415 }
Romain Guy06882f82009-06-10 13:36:04 -07004416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004417 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004419 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004420 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4421 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004422 }
Romain Guy06882f82009-06-10 13:36:04 -07004423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004424 public void setInTouchMode(boolean mode) {
4425 synchronized(mWindowMap) {
4426 mInTouchMode = mode;
4427 }
4428 }
4429
Romain Guy06882f82009-06-10 13:36:04 -07004430 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004431 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004432 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004433 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004434 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004435 }
4436
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004437 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004438 }
Romain Guy06882f82009-06-10 13:36:04 -07004439
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004440 public void setRotationUnchecked(int rotation,
4441 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004442 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004443 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004445 long origId = Binder.clearCallingIdentity();
4446 boolean changed;
4447 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004448 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004449 }
Romain Guy06882f82009-06-10 13:36:04 -07004450
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004451 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004452 sendNewConfiguration();
4453 }
Romain Guy06882f82009-06-10 13:36:04 -07004454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004455 Binder.restoreCallingIdentity(origId);
4456 }
Romain Guy06882f82009-06-10 13:36:04 -07004457
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004458 /**
4459 * Apply a new rotation to the screen, respecting the requests of
4460 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4461 * re-evaluate the desired rotation.
4462 *
4463 * Returns null if the rotation has been changed. In this case YOU
4464 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4465 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004466 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004467 boolean changed;
4468 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4469 rotation = mRequestedRotation;
4470 } else {
4471 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004472 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004473 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004474 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004475 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004476 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004477 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004478 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004480 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004481 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004482 "Rotation changed to " + rotation
4483 + " from " + mRotation
4484 + " (forceApp=" + mForcedAppOrientation
4485 + ", req=" + mRequestedRotation + ")");
4486 mRotation = rotation;
4487 mWindowsFreezingScreen = true;
4488 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4489 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4490 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004491 mWaitingForConfig = true;
4492 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004493 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004494 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004495 mQueue.setOrientation(rotation);
4496 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004497 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004498 }
4499 for (int i=mWindows.size()-1; i>=0; i--) {
4500 WindowState w = (WindowState)mWindows.get(i);
4501 if (w.mSurface != null) {
4502 w.mOrientationChanging = true;
4503 }
4504 }
4505 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4506 try {
4507 mRotationWatchers.get(i).onRotationChanged(rotation);
4508 } catch (RemoteException e) {
4509 }
4510 }
4511 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004513 return changed;
4514 }
Romain Guy06882f82009-06-10 13:36:04 -07004515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004516 public int getRotation() {
4517 return mRotation;
4518 }
4519
4520 public int watchRotation(IRotationWatcher watcher) {
4521 final IBinder watcherBinder = watcher.asBinder();
4522 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4523 public void binderDied() {
4524 synchronized (mWindowMap) {
4525 for (int i=0; i<mRotationWatchers.size(); i++) {
4526 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004527 IRotationWatcher removed = mRotationWatchers.remove(i);
4528 if (removed != null) {
4529 removed.asBinder().unlinkToDeath(this, 0);
4530 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004531 i--;
4532 }
4533 }
4534 }
4535 }
4536 };
Romain Guy06882f82009-06-10 13:36:04 -07004537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004538 synchronized (mWindowMap) {
4539 try {
4540 watcher.asBinder().linkToDeath(dr, 0);
4541 mRotationWatchers.add(watcher);
4542 } catch (RemoteException e) {
4543 // Client died, no cleanup needed.
4544 }
Romain Guy06882f82009-06-10 13:36:04 -07004545
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004546 return mRotation;
4547 }
4548 }
4549
4550 /**
4551 * Starts the view server on the specified port.
4552 *
4553 * @param port The port to listener to.
4554 *
4555 * @return True if the server was successfully started, false otherwise.
4556 *
4557 * @see com.android.server.ViewServer
4558 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4559 */
4560 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004561 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004562 return false;
4563 }
4564
4565 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4566 return false;
4567 }
4568
4569 if (port < 1024) {
4570 return false;
4571 }
4572
4573 if (mViewServer != null) {
4574 if (!mViewServer.isRunning()) {
4575 try {
4576 return mViewServer.start();
4577 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004578 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004579 }
4580 }
4581 return false;
4582 }
4583
4584 try {
4585 mViewServer = new ViewServer(this, port);
4586 return mViewServer.start();
4587 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004588 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004589 }
4590 return false;
4591 }
4592
Romain Guy06882f82009-06-10 13:36:04 -07004593 private boolean isSystemSecure() {
4594 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4595 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4596 }
4597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004598 /**
4599 * Stops the view server if it exists.
4600 *
4601 * @return True if the server stopped, false if it wasn't started or
4602 * couldn't be stopped.
4603 *
4604 * @see com.android.server.ViewServer
4605 */
4606 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004607 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004608 return false;
4609 }
4610
4611 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4612 return false;
4613 }
4614
4615 if (mViewServer != null) {
4616 return mViewServer.stop();
4617 }
4618 return false;
4619 }
4620
4621 /**
4622 * Indicates whether the view server is running.
4623 *
4624 * @return True if the server is running, false otherwise.
4625 *
4626 * @see com.android.server.ViewServer
4627 */
4628 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004629 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004630 return false;
4631 }
4632
4633 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4634 return false;
4635 }
4636
4637 return mViewServer != null && mViewServer.isRunning();
4638 }
4639
4640 /**
4641 * Lists all availble windows in the system. The listing is written in the
4642 * specified Socket's output stream with the following syntax:
4643 * windowHashCodeInHexadecimal windowName
4644 * Each line of the ouput represents a different window.
4645 *
4646 * @param client The remote client to send the listing to.
4647 * @return False if an error occured, true otherwise.
4648 */
4649 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004650 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004651 return false;
4652 }
4653
4654 boolean result = true;
4655
4656 Object[] windows;
4657 synchronized (mWindowMap) {
4658 windows = new Object[mWindows.size()];
4659 //noinspection unchecked
4660 windows = mWindows.toArray(windows);
4661 }
4662
4663 BufferedWriter out = null;
4664
4665 // Any uncaught exception will crash the system process
4666 try {
4667 OutputStream clientStream = client.getOutputStream();
4668 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4669
4670 final int count = windows.length;
4671 for (int i = 0; i < count; i++) {
4672 final WindowState w = (WindowState) windows[i];
4673 out.write(Integer.toHexString(System.identityHashCode(w)));
4674 out.write(' ');
4675 out.append(w.mAttrs.getTitle());
4676 out.write('\n');
4677 }
4678
4679 out.write("DONE.\n");
4680 out.flush();
4681 } catch (Exception e) {
4682 result = false;
4683 } finally {
4684 if (out != null) {
4685 try {
4686 out.close();
4687 } catch (IOException e) {
4688 result = false;
4689 }
4690 }
4691 }
4692
4693 return result;
4694 }
4695
4696 /**
4697 * Sends a command to a target window. The result of the command, if any, will be
4698 * written in the output stream of the specified socket.
4699 *
4700 * The parameters must follow this syntax:
4701 * windowHashcode extra
4702 *
4703 * Where XX is the length in characeters of the windowTitle.
4704 *
4705 * The first parameter is the target window. The window with the specified hashcode
4706 * will be the target. If no target can be found, nothing happens. The extra parameters
4707 * will be delivered to the target window and as parameters to the command itself.
4708 *
4709 * @param client The remote client to sent the result, if any, to.
4710 * @param command The command to execute.
4711 * @param parameters The command parameters.
4712 *
4713 * @return True if the command was successfully delivered, false otherwise. This does
4714 * not indicate whether the command itself was successful.
4715 */
4716 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004717 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004718 return false;
4719 }
4720
4721 boolean success = true;
4722 Parcel data = null;
4723 Parcel reply = null;
4724
4725 // Any uncaught exception will crash the system process
4726 try {
4727 // Find the hashcode of the window
4728 int index = parameters.indexOf(' ');
4729 if (index == -1) {
4730 index = parameters.length();
4731 }
4732 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004733 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004734
4735 // Extract the command's parameter after the window description
4736 if (index < parameters.length()) {
4737 parameters = parameters.substring(index + 1);
4738 } else {
4739 parameters = "";
4740 }
4741
4742 final WindowManagerService.WindowState window = findWindow(hashCode);
4743 if (window == null) {
4744 return false;
4745 }
4746
4747 data = Parcel.obtain();
4748 data.writeInterfaceToken("android.view.IWindow");
4749 data.writeString(command);
4750 data.writeString(parameters);
4751 data.writeInt(1);
4752 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4753
4754 reply = Parcel.obtain();
4755
4756 final IBinder binder = window.mClient.asBinder();
4757 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4758 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4759
4760 reply.readException();
4761
4762 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004763 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004764 success = false;
4765 } finally {
4766 if (data != null) {
4767 data.recycle();
4768 }
4769 if (reply != null) {
4770 reply.recycle();
4771 }
4772 }
4773
4774 return success;
4775 }
4776
4777 private WindowState findWindow(int hashCode) {
4778 if (hashCode == -1) {
4779 return getFocusedWindow();
4780 }
4781
4782 synchronized (mWindowMap) {
4783 final ArrayList windows = mWindows;
4784 final int count = windows.size();
4785
4786 for (int i = 0; i < count; i++) {
4787 WindowState w = (WindowState) windows.get(i);
4788 if (System.identityHashCode(w) == hashCode) {
4789 return w;
4790 }
4791 }
4792 }
4793
4794 return null;
4795 }
4796
4797 /*
4798 * Instruct the Activity Manager to fetch the current configuration and broadcast
4799 * that to config-changed listeners if appropriate.
4800 */
4801 void sendNewConfiguration() {
4802 try {
4803 mActivityManager.updateConfiguration(null);
4804 } catch (RemoteException e) {
4805 }
4806 }
Romain Guy06882f82009-06-10 13:36:04 -07004807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004808 public Configuration computeNewConfiguration() {
4809 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004810 return computeNewConfigurationLocked();
4811 }
4812 }
Romain Guy06882f82009-06-10 13:36:04 -07004813
Dianne Hackbornc485a602009-03-24 22:39:49 -07004814 Configuration computeNewConfigurationLocked() {
4815 Configuration config = new Configuration();
4816 if (!computeNewConfigurationLocked(config)) {
4817 return null;
4818 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004819 return config;
4820 }
Romain Guy06882f82009-06-10 13:36:04 -07004821
Dianne Hackbornc485a602009-03-24 22:39:49 -07004822 boolean computeNewConfigurationLocked(Configuration config) {
4823 if (mDisplay == null) {
4824 return false;
4825 }
4826 mQueue.getInputConfiguration(config);
4827 final int dw = mDisplay.getWidth();
4828 final int dh = mDisplay.getHeight();
4829 int orientation = Configuration.ORIENTATION_SQUARE;
4830 if (dw < dh) {
4831 orientation = Configuration.ORIENTATION_PORTRAIT;
4832 } else if (dw > dh) {
4833 orientation = Configuration.ORIENTATION_LANDSCAPE;
4834 }
4835 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004836
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004837 DisplayMetrics dm = new DisplayMetrics();
4838 mDisplay.getMetrics(dm);
4839 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4840
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004841 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004842 // Note we only do this once because at this point we don't
4843 // expect the screen to change in this way at runtime, and want
4844 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004845 int longSize = dw;
4846 int shortSize = dh;
4847 if (longSize < shortSize) {
4848 int tmp = longSize;
4849 longSize = shortSize;
4850 shortSize = tmp;
4851 }
4852 longSize = (int)(longSize/dm.density);
4853 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004854
Dianne Hackborn723738c2009-06-25 19:48:04 -07004855 // These semi-magic numbers define our compatibility modes for
4856 // applications with different screens. Don't change unless you
4857 // make sure to test lots and lots of apps!
4858 if (longSize < 470) {
4859 // This is shorter than an HVGA normal density screen (which
4860 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004861 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
4862 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07004863 } else {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004864 // Is this a large screen?
4865 if (longSize > 640 && shortSize >= 480) {
4866 // VGA or larger screens at medium density are the point
4867 // at which we consider it to be a large screen.
4868 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
4869 } else {
4870 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004871
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004872 // If this screen is wider than normal HVGA, or taller
4873 // than FWVGA, then for old apps we want to run in size
4874 // compatibility mode.
4875 if (shortSize > 321 || longSize > 570) {
4876 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
4877 }
4878 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004879
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004880 // Is this a long screen?
4881 if (((longSize*3)/5) >= (shortSize-1)) {
4882 // Anything wider than WVGA (5:3) is considering to be long.
4883 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
4884 } else {
4885 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
4886 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07004887 }
4888 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004889 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004890
Dianne Hackbornc485a602009-03-24 22:39:49 -07004891 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
4892 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
4893 mPolicy.adjustConfigurationLw(config);
4894 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004895 }
Romain Guy06882f82009-06-10 13:36:04 -07004896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004897 // -------------------------------------------------------------
4898 // Input Events and Focus Management
4899 // -------------------------------------------------------------
4900
4901 private final void wakeupIfNeeded(WindowState targetWin, int eventType) {
Michael Chane96440f2009-05-06 10:27:36 -07004902 long curTime = SystemClock.uptimeMillis();
4903
Michael Chane10de972009-05-18 11:24:50 -07004904 if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) {
Michael Chane96440f2009-05-06 10:27:36 -07004905 if (mLastTouchEventType == eventType &&
4906 (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) {
4907 return;
4908 }
4909 mLastUserActivityCallTime = curTime;
4910 mLastTouchEventType = eventType;
4911 }
4912
4913 if (targetWin == null
4914 || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) {
4915 mPowerManager.userActivity(curTime, false, eventType, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004916 }
4917 }
4918
4919 // tells if it's a cheek event or not -- this function is stateful
4920 private static final int EVENT_NONE = 0;
4921 private static final int EVENT_UNKNOWN = 0;
4922 private static final int EVENT_CHEEK = 0;
4923 private static final int EVENT_IGNORE_DURATION = 300; // ms
4924 private static final float CHEEK_THRESHOLD = 0.6f;
4925 private int mEventState = EVENT_NONE;
4926 private float mEventSize;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004928 private int eventType(MotionEvent ev) {
4929 float size = ev.getSize();
4930 switch (ev.getAction()) {
4931 case MotionEvent.ACTION_DOWN:
4932 mEventSize = size;
4933 return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT;
4934 case MotionEvent.ACTION_UP:
4935 if (size > mEventSize) mEventSize = size;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004936 return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004937 case MotionEvent.ACTION_MOVE:
4938 final int N = ev.getHistorySize();
4939 if (size > mEventSize) mEventSize = size;
4940 if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT;
4941 for (int i=0; i<N; i++) {
4942 size = ev.getHistoricalSize(i);
4943 if (size > mEventSize) mEventSize = size;
4944 if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT;
4945 }
4946 if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) {
4947 return TOUCH_EVENT;
4948 } else {
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004949 return LONG_TOUCH_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004950 }
4951 default:
4952 // not good
4953 return OTHER_EVENT;
4954 }
4955 }
4956
4957 /**
4958 * @return Returns true if event was dispatched, false if it was dropped for any reason
4959 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07004960 private int dispatchPointer(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004961 if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004962 "dispatchPointer " + ev);
4963
Michael Chan53071d62009-05-13 17:29:48 -07004964 if (MEASURE_LATENCY) {
4965 lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano);
4966 }
4967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004968 Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07004969 ev, true, false, pid, uid);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004970
Michael Chan53071d62009-05-13 17:29:48 -07004971 if (MEASURE_LATENCY) {
4972 lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano);
4973 }
4974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004975 int action = ev.getAction();
Romain Guy06882f82009-06-10 13:36:04 -07004976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004977 if (action == MotionEvent.ACTION_UP) {
4978 // let go of our target
4979 mKeyWaiter.mMotionTarget = null;
4980 mPowerManager.logPointerUpEvent();
4981 } else if (action == MotionEvent.ACTION_DOWN) {
4982 mPowerManager.logPointerDownEvent();
4983 }
4984
4985 if (targetObj == null) {
4986 // In this case we are either dropping the event, or have received
4987 // a move or up without a down. It is common to receive move
4988 // events in such a way, since this means the user is moving the
4989 // pointer without actually pressing down. All other cases should
4990 // be atypical, so let's log them.
Michael Chane96440f2009-05-06 10:27:36 -07004991 if (action != MotionEvent.ACTION_MOVE) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004992 Slog.w(TAG, "No window to dispatch pointer action " + ev.getAction());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004993 }
Dianne Hackborn6adba242009-11-10 11:10:09 -08004994 synchronized (mWindowMap) {
Dianne Hackborn90d2db32010-02-11 22:19:06 -08004995 dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true);
Dianne Hackborn6adba242009-11-10 11:10:09 -08004996 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004997 if (qev != null) {
4998 mQueue.recycleEvent(qev);
4999 }
5000 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005001 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005002 }
5003 if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
Dianne Hackborn6adba242009-11-10 11:10:09 -08005004 synchronized (mWindowMap) {
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005005 dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true);
Dianne Hackborn6adba242009-11-10 11:10:09 -08005006 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005007 if (qev != null) {
5008 mQueue.recycleEvent(qev);
5009 }
5010 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005011 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005012 }
Romain Guy06882f82009-06-10 13:36:04 -07005013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005014 WindowState target = (WindowState)targetObj;
Romain Guy06882f82009-06-10 13:36:04 -07005015
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005016 final long eventTime = ev.getEventTime();
Michael Chan53071d62009-05-13 17:29:48 -07005017 final long eventTimeNano = ev.getEventTimeNano();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005018
Joe Onorato8a9b2202010-02-26 18:56:32 -08005019 //Slog.i(TAG, "Sending " + ev + " to " + target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005020
5021 if (uid != 0 && uid != target.mSession.mUid) {
5022 if (mContext.checkPermission(
5023 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5024 != PackageManager.PERMISSION_GRANTED) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005025 Slog.w(TAG, "Permission denied: injecting pointer event from pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005026 + pid + " uid " + uid + " to window " + target
5027 + " owned by uid " + target.mSession.mUid);
5028 if (qev != null) {
5029 mQueue.recycleEvent(qev);
5030 }
5031 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005032 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005033 }
5034 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005035
Michael Chan53071d62009-05-13 17:29:48 -07005036 if (MEASURE_LATENCY) {
5037 lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano);
5038 }
5039
Romain Guy06882f82009-06-10 13:36:04 -07005040 if ((target.mAttrs.flags &
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005041 WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) {
5042 //target wants to ignore fat touch events
5043 boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev);
5044 //explicit flag to return without processing event further
5045 boolean returnFlag = false;
5046 if((action == MotionEvent.ACTION_DOWN)) {
5047 mFatTouch = false;
5048 if(cheekPress) {
5049 mFatTouch = true;
5050 returnFlag = true;
5051 }
5052 } else {
5053 if(action == MotionEvent.ACTION_UP) {
5054 if(mFatTouch) {
5055 //earlier even was invalid doesnt matter if current up is cheekpress or not
5056 mFatTouch = false;
5057 returnFlag = true;
5058 } else if(cheekPress) {
5059 //cancel the earlier event
5060 ev.setAction(MotionEvent.ACTION_CANCEL);
5061 action = MotionEvent.ACTION_CANCEL;
5062 }
5063 } else if(action == MotionEvent.ACTION_MOVE) {
5064 if(mFatTouch) {
5065 //two cases here
5066 //an invalid down followed by 0 or moves(valid or invalid)
Romain Guy06882f82009-06-10 13:36:04 -07005067 //a valid down, invalid move, more moves. want to ignore till up
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005068 returnFlag = true;
5069 } else if(cheekPress) {
5070 //valid down followed by invalid moves
5071 //an invalid move have to cancel earlier action
5072 ev.setAction(MotionEvent.ACTION_CANCEL);
5073 action = MotionEvent.ACTION_CANCEL;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005074 if (DEBUG_INPUT) Slog.v(TAG, "Sending cancel for invalid ACTION_MOVE");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005075 //note that the subsequent invalid moves will not get here
5076 mFatTouch = true;
5077 }
5078 }
5079 } //else if action
5080 if(returnFlag) {
5081 //recycle que, ev
5082 if (qev != null) {
5083 mQueue.recycleEvent(qev);
5084 }
5085 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005086 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005087 }
5088 } //end if target
Michael Chane96440f2009-05-06 10:27:36 -07005089
Michael Chan9f028e62009-08-04 17:37:46 -07005090 // Enable this for testing the "right" value
5091 if (false && action == MotionEvent.ACTION_DOWN) {
Michael Chane96440f2009-05-06 10:27:36 -07005092 int max_events_per_sec = 35;
5093 try {
5094 max_events_per_sec = Integer.parseInt(SystemProperties
5095 .get("windowsmgr.max_events_per_sec"));
5096 if (max_events_per_sec < 1) {
5097 max_events_per_sec = 35;
5098 }
5099 } catch (NumberFormatException e) {
5100 }
5101 mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec;
5102 }
5103
5104 /*
5105 * Throttle events to minimize CPU usage when there's a flood of events
5106 * e.g. constant contact with the screen
5107 */
5108 if (action == MotionEvent.ACTION_MOVE) {
5109 long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents;
5110 long now = SystemClock.uptimeMillis();
5111 if (now < nextEventTime) {
5112 try {
5113 Thread.sleep(nextEventTime - now);
5114 } catch (InterruptedException e) {
5115 }
5116 mLastTouchEventTime = nextEventTime;
5117 } else {
5118 mLastTouchEventTime = now;
5119 }
5120 }
5121
Michael Chan53071d62009-05-13 17:29:48 -07005122 if (MEASURE_LATENCY) {
5123 lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano);
5124 }
5125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005126 synchronized(mWindowMap) {
Dianne Hackborn6adba242009-11-10 11:10:09 -08005127 if (!target.isVisibleLw()) {
5128 // During this motion dispatch, the target window has become
5129 // invisible.
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005130 dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), false);
Dianne Hackborn6adba242009-11-10 11:10:09 -08005131 if (qev != null) {
5132 mQueue.recycleEvent(qev);
5133 }
5134 ev.recycle();
5135 return INJECT_SUCCEEDED;
5136 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005138 if (qev != null && action == MotionEvent.ACTION_MOVE) {
5139 mKeyWaiter.bindTargetWindowLocked(target,
5140 KeyWaiter.RETURN_PENDING_POINTER, qev);
5141 ev = null;
5142 } else {
5143 if (action == MotionEvent.ACTION_DOWN) {
5144 WindowState out = mKeyWaiter.mOutsideTouchTargets;
5145 if (out != null) {
5146 MotionEvent oev = MotionEvent.obtain(ev);
5147 oev.setAction(MotionEvent.ACTION_OUTSIDE);
5148 do {
5149 final Rect frame = out.mFrame;
5150 oev.offsetLocation(-(float)frame.left, -(float)frame.top);
5151 try {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005152 out.mClient.dispatchPointer(oev, eventTime, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005153 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005154 Slog.i(TAG, "WINDOW DIED during outside motion dispatch: " + out);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005155 }
5156 oev.offsetLocation((float)frame.left, (float)frame.top);
5157 out = out.mNextOutsideTouch;
5158 } while (out != null);
5159 mKeyWaiter.mOutsideTouchTargets = null;
5160 }
5161 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005162
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005163 dispatchPointerElsewhereLocked(target, null, ev, ev.getEventTime(), false);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005164
Dianne Hackborn6adba242009-11-10 11:10:09 -08005165 final Rect frame = target.mFrame;
5166 ev.offsetLocation(-(float)frame.left, -(float)frame.top);
5167 mKeyWaiter.bindTargetWindowLocked(target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005168 }
5169 }
Romain Guy06882f82009-06-10 13:36:04 -07005170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005171 // finally offset the event to the target's coordinate system and
5172 // dispatch the event.
5173 try {
5174 if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005175 Slog.v(TAG, "Delivering pointer " + qev + " to " + target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005176 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005177
Michael Chan53071d62009-05-13 17:29:48 -07005178 if (MEASURE_LATENCY) {
5179 lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano);
5180 }
5181
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005182 target.mClient.dispatchPointer(ev, eventTime, true);
Michael Chan53071d62009-05-13 17:29:48 -07005183
5184 if (MEASURE_LATENCY) {
5185 lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano);
5186 }
Dianne Hackborncfaef692009-06-15 14:24:44 -07005187 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005188 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005189 Slog.i(TAG, "WINDOW DIED during motion dispatch: " + target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005190 mKeyWaiter.mMotionTarget = null;
5191 try {
5192 removeWindow(target.mSession, target.mClient);
5193 } catch (java.util.NoSuchElementException ex) {
5194 // This will happen if the window has already been
5195 // removed.
5196 }
5197 }
Dianne Hackborncfaef692009-06-15 14:24:44 -07005198 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005199 }
Romain Guy06882f82009-06-10 13:36:04 -07005200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005201 /**
5202 * @return Returns true if event was dispatched, false if it was dropped for any reason
5203 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07005204 private int dispatchTrackball(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005205 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005206 TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">");
Romain Guy06882f82009-06-10 13:36:04 -07005207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005208 Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005209 ev, false, false, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005210 if (focusObj == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005211 Slog.w(TAG, "No focus window, dropping trackball: " + ev);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005212 if (qev != null) {
5213 mQueue.recycleEvent(qev);
5214 }
5215 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005216 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005217 }
5218 if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
5219 if (qev != null) {
5220 mQueue.recycleEvent(qev);
5221 }
5222 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005223 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005224 }
Romain Guy06882f82009-06-10 13:36:04 -07005225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005226 WindowState focus = (WindowState)focusObj;
Romain Guy06882f82009-06-10 13:36:04 -07005227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005228 if (uid != 0 && uid != focus.mSession.mUid) {
5229 if (mContext.checkPermission(
5230 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5231 != PackageManager.PERMISSION_GRANTED) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005232 Slog.w(TAG, "Permission denied: injecting key event from pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005233 + pid + " uid " + uid + " to window " + focus
5234 + " owned by uid " + focus.mSession.mUid);
5235 if (qev != null) {
5236 mQueue.recycleEvent(qev);
5237 }
5238 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005239 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005240 }
5241 }
Romain Guy06882f82009-06-10 13:36:04 -07005242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005243 final long eventTime = ev.getEventTime();
Romain Guy06882f82009-06-10 13:36:04 -07005244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005245 synchronized(mWindowMap) {
5246 if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) {
5247 mKeyWaiter.bindTargetWindowLocked(focus,
5248 KeyWaiter.RETURN_PENDING_TRACKBALL, qev);
5249 // We don't deliver movement events to the client, we hold
5250 // them and wait for them to call back.
5251 ev = null;
5252 } else {
5253 mKeyWaiter.bindTargetWindowLocked(focus);
5254 }
5255 }
Romain Guy06882f82009-06-10 13:36:04 -07005256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005257 try {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005258 focus.mClient.dispatchTrackball(ev, eventTime, true);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005259 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005260 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005261 Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005262 try {
5263 removeWindow(focus.mSession, focus.mClient);
5264 } catch (java.util.NoSuchElementException ex) {
5265 // This will happen if the window has already been
5266 // removed.
5267 }
5268 }
Romain Guy06882f82009-06-10 13:36:04 -07005269
Dianne Hackborncfaef692009-06-15 14:24:44 -07005270 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005271 }
Romain Guy06882f82009-06-10 13:36:04 -07005272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005273 /**
5274 * @return Returns true if event was dispatched, false if it was dropped for any reason
5275 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07005276 private int dispatchKey(KeyEvent event, int pid, int uid) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005277 if (DEBUG_INPUT) Slog.v(TAG, "Dispatch key: " + event);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005278
5279 Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005280 null, false, false, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005281 if (focusObj == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005282 Slog.w(TAG, "No focus window, dropping: " + event);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005283 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005284 }
5285 if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005286 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005287 }
Romain Guy06882f82009-06-10 13:36:04 -07005288
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07005289 // Okay we have finished waiting for the last event to be processed.
5290 // First off, if this is a repeat event, check to see if there is
5291 // a corresponding up event in the queue. If there is, we will
5292 // just drop the repeat, because it makes no sense to repeat after
5293 // the user has released a key. (This is especially important for
5294 // long presses.)
5295 if (event.getRepeatCount() > 0 && mQueue.hasKeyUpEvent(event)) {
5296 return INJECT_SUCCEEDED;
5297 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005299 WindowState focus = (WindowState)focusObj;
Romain Guy06882f82009-06-10 13:36:04 -07005300
Joe Onorato8a9b2202010-02-26 18:56:32 -08005301 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005302 TAG, "Dispatching to " + focus + ": " + event);
5303
5304 if (uid != 0 && uid != focus.mSession.mUid) {
5305 if (mContext.checkPermission(
5306 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5307 != PackageManager.PERMISSION_GRANTED) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005308 Slog.w(TAG, "Permission denied: injecting key event from pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005309 + pid + " uid " + uid + " to window " + focus
5310 + " owned by uid " + focus.mSession.mUid);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005311 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005312 }
5313 }
Romain Guy06882f82009-06-10 13:36:04 -07005314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005315 synchronized(mWindowMap) {
5316 mKeyWaiter.bindTargetWindowLocked(focus);
5317 }
5318
5319 // NOSHIP extra state logging
5320 mKeyWaiter.recordDispatchState(event, focus);
5321 // END NOSHIP
Romain Guy06882f82009-06-10 13:36:04 -07005322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005323 try {
5324 if (DEBUG_INPUT || DEBUG_FOCUS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005325 Slog.v(TAG, "Delivering key " + event.getKeyCode()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005326 + " to " + focus);
5327 }
5328 focus.mClient.dispatchKey(event);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005329 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005330 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005331 Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005332 try {
5333 removeWindow(focus.mSession, focus.mClient);
5334 } catch (java.util.NoSuchElementException ex) {
5335 // This will happen if the window has already been
5336 // removed.
5337 }
5338 }
Romain Guy06882f82009-06-10 13:36:04 -07005339
Dianne Hackborncfaef692009-06-15 14:24:44 -07005340 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005341 }
Romain Guy06882f82009-06-10 13:36:04 -07005342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005343 public void pauseKeyDispatching(IBinder _token) {
5344 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5345 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005346 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005347 }
5348
5349 synchronized (mWindowMap) {
5350 WindowToken token = mTokenMap.get(_token);
5351 if (token != null) {
5352 mKeyWaiter.pauseDispatchingLocked(token);
5353 }
5354 }
5355 }
5356
5357 public void resumeKeyDispatching(IBinder _token) {
5358 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5359 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005360 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005361 }
5362
5363 synchronized (mWindowMap) {
5364 WindowToken token = mTokenMap.get(_token);
5365 if (token != null) {
5366 mKeyWaiter.resumeDispatchingLocked(token);
5367 }
5368 }
5369 }
5370
5371 public void setEventDispatching(boolean enabled) {
5372 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5373 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005374 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005375 }
5376
5377 synchronized (mWindowMap) {
5378 mKeyWaiter.setEventDispatchingLocked(enabled);
5379 }
5380 }
Romain Guy06882f82009-06-10 13:36:04 -07005381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005382 /**
5383 * Injects a keystroke event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005384 *
5385 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005386 * {@link SystemClock#uptimeMillis()} as the timebase.)
5387 * @param sync If true, wait for the event to be completed before returning to the caller.
5388 * @return Returns true if event was dispatched, false if it was dropped for any reason
5389 */
5390 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5391 long downTime = ev.getDownTime();
5392 long eventTime = ev.getEventTime();
5393
5394 int action = ev.getAction();
5395 int code = ev.getKeyCode();
5396 int repeatCount = ev.getRepeatCount();
5397 int metaState = ev.getMetaState();
5398 int deviceId = ev.getDeviceId();
5399 int scancode = ev.getScanCode();
5400
5401 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5402 if (downTime == 0) downTime = eventTime;
5403
5404 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
The Android Open Source Project10592532009-03-18 17:39:46 -07005405 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005406
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005407 final int pid = Binder.getCallingPid();
5408 final int uid = Binder.getCallingUid();
5409 final long ident = Binder.clearCallingIdentity();
5410 final int result = dispatchKey(newEvent, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005411 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005412 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005413 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005414 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005415 switch (result) {
5416 case INJECT_NO_PERMISSION:
5417 throw new SecurityException(
Chander S Pechetty27f3de62010-02-10 22:14:00 +05305418 "Injecting to another application requires INJECT_EVENTS permission");
Dianne Hackborncfaef692009-06-15 14:24:44 -07005419 case INJECT_SUCCEEDED:
5420 return true;
5421 }
5422 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005423 }
5424
5425 /**
5426 * Inject a pointer (touch) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005427 *
5428 * @param ev A motion event describing the pointer (touch) action. (As noted in
5429 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005430 * {@link SystemClock#uptimeMillis()} as the timebase.)
5431 * @param sync If true, wait for the event to be completed before returning to the caller.
5432 * @return Returns true if event was dispatched, false if it was dropped for any reason
5433 */
5434 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005435 final int pid = Binder.getCallingPid();
5436 final int uid = Binder.getCallingUid();
5437 final long ident = Binder.clearCallingIdentity();
5438 final int result = dispatchPointer(null, ev, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005439 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005440 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005441 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005442 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005443 switch (result) {
5444 case INJECT_NO_PERMISSION:
5445 throw new SecurityException(
Chander S Pechetty27f3de62010-02-10 22:14:00 +05305446 "Injecting to another application requires INJECT_EVENTS permission");
Dianne Hackborncfaef692009-06-15 14:24:44 -07005447 case INJECT_SUCCEEDED:
5448 return true;
5449 }
5450 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005451 }
Romain Guy06882f82009-06-10 13:36:04 -07005452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005453 /**
5454 * Inject a trackball (navigation device) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005455 *
5456 * @param ev A motion event describing the trackball action. (As noted in
5457 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005458 * {@link SystemClock#uptimeMillis()} as the timebase.)
5459 * @param sync If true, wait for the event to be completed before returning to the caller.
5460 * @return Returns true if event was dispatched, false if it was dropped for any reason
5461 */
5462 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005463 final int pid = Binder.getCallingPid();
5464 final int uid = Binder.getCallingUid();
5465 final long ident = Binder.clearCallingIdentity();
5466 final int result = dispatchTrackball(null, ev, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005467 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005468 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005469 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005470 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005471 switch (result) {
5472 case INJECT_NO_PERMISSION:
5473 throw new SecurityException(
Chander S Pechetty27f3de62010-02-10 22:14:00 +05305474 "Injecting to another application requires INJECT_EVENTS permission");
Dianne Hackborncfaef692009-06-15 14:24:44 -07005475 case INJECT_SUCCEEDED:
5476 return true;
5477 }
5478 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005479 }
Romain Guy06882f82009-06-10 13:36:04 -07005480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005481 private WindowState getFocusedWindow() {
5482 synchronized (mWindowMap) {
5483 return getFocusedWindowLocked();
5484 }
5485 }
5486
5487 private WindowState getFocusedWindowLocked() {
5488 return mCurrentFocus;
5489 }
Romain Guy06882f82009-06-10 13:36:04 -07005490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005491 /**
5492 * This class holds the state for dispatching key events. This state
5493 * is protected by the KeyWaiter instance, NOT by the window lock. You
5494 * can be holding the main window lock while acquire the KeyWaiter lock,
5495 * but not the other way around.
5496 */
5497 final class KeyWaiter {
5498 // NOSHIP debugging
5499 public class DispatchState {
5500 private KeyEvent event;
5501 private WindowState focus;
5502 private long time;
5503 private WindowState lastWin;
5504 private IBinder lastBinder;
5505 private boolean finished;
5506 private boolean gotFirstWindow;
5507 private boolean eventDispatching;
5508 private long timeToSwitch;
5509 private boolean wasFrozen;
5510 private boolean focusPaused;
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005511 private WindowState curFocus;
Romain Guy06882f82009-06-10 13:36:04 -07005512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005513 DispatchState(KeyEvent theEvent, WindowState theFocus) {
5514 focus = theFocus;
5515 event = theEvent;
5516 time = System.currentTimeMillis();
5517 // snapshot KeyWaiter state
5518 lastWin = mLastWin;
5519 lastBinder = mLastBinder;
5520 finished = mFinished;
5521 gotFirstWindow = mGotFirstWindow;
5522 eventDispatching = mEventDispatching;
5523 timeToSwitch = mTimeToSwitch;
5524 wasFrozen = mWasFrozen;
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005525 curFocus = mCurrentFocus;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005526 // cache the paused state at ctor time as well
5527 if (theFocus == null || theFocus.mToken == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005528 focusPaused = false;
5529 } else {
5530 focusPaused = theFocus.mToken.paused;
5531 }
5532 }
Romain Guy06882f82009-06-10 13:36:04 -07005533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005534 public String toString() {
5535 return "{{" + event + " to " + focus + " @ " + time
5536 + " lw=" + lastWin + " lb=" + lastBinder
5537 + " fin=" + finished + " gfw=" + gotFirstWindow
5538 + " ed=" + eventDispatching + " tts=" + timeToSwitch
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005539 + " wf=" + wasFrozen + " fp=" + focusPaused
Christopher Tate46d45252010-02-09 15:48:57 -08005540 + " mcf=" + curFocus + "}}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005541 }
5542 };
5543 private DispatchState mDispatchState = null;
5544 public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) {
5545 mDispatchState = new DispatchState(theEvent, theFocus);
5546 }
5547 // END NOSHIP
5548
5549 public static final int RETURN_NOTHING = 0;
5550 public static final int RETURN_PENDING_POINTER = 1;
5551 public static final int RETURN_PENDING_TRACKBALL = 2;
Romain Guy06882f82009-06-10 13:36:04 -07005552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005553 final Object SKIP_TARGET_TOKEN = new Object();
5554 final Object CONSUMED_EVENT_TOKEN = new Object();
Romain Guy06882f82009-06-10 13:36:04 -07005555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005556 private WindowState mLastWin = null;
5557 private IBinder mLastBinder = null;
5558 private boolean mFinished = true;
5559 private boolean mGotFirstWindow = false;
5560 private boolean mEventDispatching = true;
5561 private long mTimeToSwitch = 0;
5562 /* package */ boolean mWasFrozen = false;
Romain Guy06882f82009-06-10 13:36:04 -07005563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005564 // Target of Motion events
5565 WindowState mMotionTarget;
Romain Guy06882f82009-06-10 13:36:04 -07005566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005567 // Windows above the target who would like to receive an "outside"
5568 // touch event for any down events outside of them.
5569 WindowState mOutsideTouchTargets;
5570
5571 /**
5572 * Wait for the last event dispatch to complete, then find the next
5573 * target that should receive the given event and wait for that one
5574 * to be ready to receive it.
5575 */
5576 Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev,
5577 MotionEvent nextMotion, boolean isPointerEvent,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005578 boolean failIfTimeout, int callingPid, int callingUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005579 long startTime = SystemClock.uptimeMillis();
5580 long keyDispatchingTimeout = 5 * 1000;
5581 long waitedFor = 0;
5582
5583 while (true) {
5584 // Figure out which window we care about. It is either the
5585 // last window we are waiting to have process the event or,
5586 // if none, then the next window we think the event should go
5587 // to. Note: we retrieve mLastWin outside of the lock, so
5588 // it may change before we lock. Thus we must check it again.
5589 WindowState targetWin = mLastWin;
5590 boolean targetIsNew = targetWin == null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005591 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005592 TAG, "waitForLastKey: mFinished=" + mFinished +
5593 ", mLastWin=" + mLastWin);
5594 if (targetIsNew) {
5595 Object target = findTargetWindow(nextKey, qev, nextMotion,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005596 isPointerEvent, callingPid, callingUid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005597 if (target == SKIP_TARGET_TOKEN) {
5598 // The user has pressed a special key, and we are
5599 // dropping all pending events before it.
Joe Onorato8a9b2202010-02-26 18:56:32 -08005600 if (DEBUG_INPUT) Slog.v(TAG, "Skipping: " + nextKey
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005601 + " " + nextMotion);
5602 return null;
5603 }
5604 if (target == CONSUMED_EVENT_TOKEN) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005605 if (DEBUG_INPUT) Slog.v(TAG, "Consumed: " + nextKey
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005606 + " " + nextMotion);
5607 return target;
5608 }
5609 targetWin = (WindowState)target;
5610 }
Romain Guy06882f82009-06-10 13:36:04 -07005611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005612 AppWindowToken targetApp = null;
Romain Guy06882f82009-06-10 13:36:04 -07005613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005614 // Now: is it okay to send the next event to this window?
5615 synchronized (this) {
5616 // First: did we come here based on the last window not
5617 // being null, but it changed by the time we got here?
5618 // If so, try again.
5619 if (!targetIsNew && mLastWin == null) {
5620 continue;
5621 }
Romain Guy06882f82009-06-10 13:36:04 -07005622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005623 // We never dispatch events if not finished with the
5624 // last one, or the display is frozen.
5625 if (mFinished && !mDisplayFrozen) {
5626 // If event dispatching is disabled, then we
5627 // just consume the events.
5628 if (!mEventDispatching) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005629 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005630 "Skipping event; dispatching disabled: "
5631 + nextKey + " " + nextMotion);
5632 return null;
5633 }
5634 if (targetWin != null) {
5635 // If this is a new target, and that target is not
5636 // paused or unresponsive, then all looks good to
5637 // handle the event.
5638 if (targetIsNew && !targetWin.mToken.paused) {
5639 return targetWin;
5640 }
Romain Guy06882f82009-06-10 13:36:04 -07005641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005642 // If we didn't find a target window, and there is no
5643 // focused app window, then just eat the events.
5644 } else if (mFocusedApp == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005645 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005646 "Skipping event; no focused app: "
5647 + nextKey + " " + nextMotion);
5648 return null;
5649 }
5650 }
Romain Guy06882f82009-06-10 13:36:04 -07005651
Joe Onorato8a9b2202010-02-26 18:56:32 -08005652 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005653 TAG, "Waiting for last key in " + mLastBinder
5654 + " target=" + targetWin
5655 + " mFinished=" + mFinished
5656 + " mDisplayFrozen=" + mDisplayFrozen
5657 + " targetIsNew=" + targetIsNew
5658 + " paused="
5659 + (targetWin != null ? targetWin.mToken.paused : false)
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005660 + " mFocusedApp=" + mFocusedApp
5661 + " mCurrentFocus=" + mCurrentFocus);
Romain Guy06882f82009-06-10 13:36:04 -07005662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005663 targetApp = targetWin != null
5664 ? targetWin.mAppToken : mFocusedApp;
Romain Guy06882f82009-06-10 13:36:04 -07005665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005666 long curTimeout = keyDispatchingTimeout;
5667 if (mTimeToSwitch != 0) {
5668 long now = SystemClock.uptimeMillis();
5669 if (mTimeToSwitch <= now) {
5670 // If an app switch key has been pressed, and we have
5671 // waited too long for the current app to finish
5672 // processing keys, then wait no more!
Christopher Tate136b1f92010-02-11 17:51:24 -08005673 doFinishedKeyLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005674 continue;
5675 }
5676 long switchTimeout = mTimeToSwitch - now;
5677 if (curTimeout > switchTimeout) {
5678 curTimeout = switchTimeout;
5679 }
5680 }
Romain Guy06882f82009-06-10 13:36:04 -07005681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005682 try {
5683 // after that continue
5684 // processing keys, so we don't get stuck.
Joe Onorato8a9b2202010-02-26 18:56:32 -08005685 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005686 TAG, "Waiting for key dispatch: " + curTimeout);
5687 wait(curTimeout);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005688 if (DEBUG_INPUT) Slog.v(TAG, "Finished waiting @"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005689 + SystemClock.uptimeMillis() + " startTime="
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005690 + startTime + " switchTime=" + mTimeToSwitch
5691 + " target=" + targetWin + " mLW=" + mLastWin
5692 + " mLB=" + mLastBinder + " fin=" + mFinished
5693 + " mCurrentFocus=" + mCurrentFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005694 } catch (InterruptedException e) {
5695 }
5696 }
5697
5698 // If we were frozen during configuration change, restart the
5699 // timeout checks from now; otherwise look at whether we timed
5700 // out before awakening.
5701 if (mWasFrozen) {
5702 waitedFor = 0;
5703 mWasFrozen = false;
5704 } else {
5705 waitedFor = SystemClock.uptimeMillis() - startTime;
5706 }
5707
5708 if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) {
5709 IApplicationToken at = null;
5710 synchronized (this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005711 Slog.w(TAG, "Key dispatching timed out sending to " +
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005712 (targetWin != null ? targetWin.mAttrs.getTitle()
Ken Shirriff8200b202010-02-04 13:34:37 -08005713 : "<null>: no window ready for key dispatch"));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005714 // NOSHIP debugging
Joe Onorato8a9b2202010-02-26 18:56:32 -08005715 Slog.w(TAG, "Previous dispatch state: " + mDispatchState);
5716 Slog.w(TAG, "Current dispatch state: " +
Ken Shirriff8200b202010-02-04 13:34:37 -08005717 new DispatchState(nextKey, targetWin));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005718 // END NOSHIP
5719 //dump();
5720 if (targetWin != null) {
5721 at = targetWin.getAppToken();
5722 } else if (targetApp != null) {
5723 at = targetApp.appToken;
5724 }
5725 }
5726
5727 boolean abort = true;
5728 if (at != null) {
5729 try {
5730 long timeout = at.getKeyDispatchingTimeout();
5731 if (timeout > waitedFor) {
5732 // we did not wait the proper amount of time for this application.
5733 // set the timeout to be the real timeout and wait again.
5734 keyDispatchingTimeout = timeout - waitedFor;
5735 continue;
5736 } else {
5737 abort = at.keyDispatchingTimedOut();
5738 }
5739 } catch (RemoteException ex) {
5740 }
5741 }
5742
5743 synchronized (this) {
5744 if (abort && (mLastWin == targetWin || targetWin == null)) {
5745 mFinished = true;
Romain Guy06882f82009-06-10 13:36:04 -07005746 if (mLastWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005747 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005748 "Window " + mLastWin +
5749 " timed out on key input");
5750 if (mLastWin.mToken.paused) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005751 Slog.w(TAG, "Un-pausing dispatching to this window");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005752 mLastWin.mToken.paused = false;
5753 }
5754 }
5755 if (mMotionTarget == targetWin) {
5756 mMotionTarget = null;
5757 }
5758 mLastWin = null;
5759 mLastBinder = null;
5760 if (failIfTimeout || targetWin == null) {
5761 return null;
5762 }
5763 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005764 Slog.w(TAG, "Continuing to wait for key to be dispatched");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005765 startTime = SystemClock.uptimeMillis();
5766 }
5767 }
5768 }
5769 }
5770 }
Romain Guy06882f82009-06-10 13:36:04 -07005771
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005772 Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005773 MotionEvent nextMotion, boolean isPointerEvent,
5774 int callingPid, int callingUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005775 mOutsideTouchTargets = null;
Romain Guy06882f82009-06-10 13:36:04 -07005776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005777 if (nextKey != null) {
5778 // Find the target window for a normal key event.
5779 final int keycode = nextKey.getKeyCode();
5780 final int repeatCount = nextKey.getRepeatCount();
5781 final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP;
5782 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005784 if (!dispatch) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005785 if (callingUid == 0 ||
5786 mContext.checkPermission(
5787 android.Manifest.permission.INJECT_EVENTS,
5788 callingPid, callingUid)
5789 == PackageManager.PERMISSION_GRANTED) {
5790 mPolicy.interceptKeyTi(null, keycode,
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07005791 nextKey.getMetaState(), down, repeatCount,
5792 nextKey.getFlags());
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005793 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08005794 Slog.w(TAG, "Event timeout during app switch: dropping "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005795 + nextKey);
5796 return SKIP_TARGET_TOKEN;
5797 }
Romain Guy06882f82009-06-10 13:36:04 -07005798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005799 // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")");
Romain Guy06882f82009-06-10 13:36:04 -07005800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005801 WindowState focus = null;
5802 synchronized(mWindowMap) {
5803 focus = getFocusedWindowLocked();
5804 }
Romain Guy06882f82009-06-10 13:36:04 -07005805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005806 wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT);
Romain Guy06882f82009-06-10 13:36:04 -07005807
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005808 if (callingUid == 0 ||
5809 (focus != null && callingUid == focus.mSession.mUid) ||
5810 mContext.checkPermission(
5811 android.Manifest.permission.INJECT_EVENTS,
5812 callingPid, callingUid)
5813 == PackageManager.PERMISSION_GRANTED) {
5814 if (mPolicy.interceptKeyTi(focus,
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005815 keycode, nextKey.getMetaState(), down, repeatCount,
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07005816 nextKey.getFlags())) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005817 return CONSUMED_EVENT_TOKEN;
5818 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005819 }
Romain Guy06882f82009-06-10 13:36:04 -07005820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005821 return focus;
Romain Guy06882f82009-06-10 13:36:04 -07005822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005823 } else if (!isPointerEvent) {
5824 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1);
5825 if (!dispatch) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005826 Slog.w(TAG, "Event timeout during app switch: dropping trackball "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005827 + nextMotion);
5828 return SKIP_TARGET_TOKEN;
5829 }
Romain Guy06882f82009-06-10 13:36:04 -07005830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005831 WindowState focus = null;
5832 synchronized(mWindowMap) {
5833 focus = getFocusedWindowLocked();
5834 }
Romain Guy06882f82009-06-10 13:36:04 -07005835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005836 wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT);
5837 return focus;
5838 }
Romain Guy06882f82009-06-10 13:36:04 -07005839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005840 if (nextMotion == null) {
5841 return SKIP_TARGET_TOKEN;
5842 }
Romain Guy06882f82009-06-10 13:36:04 -07005843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005844 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(
5845 KeyEvent.KEYCODE_UNKNOWN);
5846 if (!dispatch) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005847 Slog.w(TAG, "Event timeout during app switch: dropping pointer "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005848 + nextMotion);
5849 return SKIP_TARGET_TOKEN;
5850 }
Romain Guy06882f82009-06-10 13:36:04 -07005851
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005852 // Find the target window for a pointer event.
5853 int action = nextMotion.getAction();
5854 final float xf = nextMotion.getX();
5855 final float yf = nextMotion.getY();
5856 final long eventTime = nextMotion.getEventTime();
Romain Guy06882f82009-06-10 13:36:04 -07005857
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005858 final boolean screenWasOff = qev != null
5859 && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07005860
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005861 WindowState target = null;
Romain Guy06882f82009-06-10 13:36:04 -07005862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005863 synchronized(mWindowMap) {
5864 synchronized (this) {
5865 if (action == MotionEvent.ACTION_DOWN) {
5866 if (mMotionTarget != null) {
5867 // this is weird, we got a pen down, but we thought it was
5868 // already down!
5869 // XXX: We should probably send an ACTION_UP to the current
5870 // target.
Joe Onorato8a9b2202010-02-26 18:56:32 -08005871 Slog.w(TAG, "Pointer down received while already down in: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005872 + mMotionTarget);
5873 mMotionTarget = null;
5874 }
Romain Guy06882f82009-06-10 13:36:04 -07005875
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005876 // ACTION_DOWN is special, because we need to lock next events to
5877 // the window we'll land onto.
5878 final int x = (int)xf;
5879 final int y = (int)yf;
Romain Guy06882f82009-06-10 13:36:04 -07005880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005881 final ArrayList windows = mWindows;
5882 final int N = windows.size();
5883 WindowState topErrWindow = null;
5884 final Rect tmpRect = mTempRect;
5885 for (int i=N-1; i>=0; i--) {
5886 WindowState child = (WindowState)windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005887 //Slog.i(TAG, "Checking dispatch to: " + child);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005888 final int flags = child.mAttrs.flags;
5889 if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) {
5890 if (topErrWindow == null) {
5891 topErrWindow = child;
5892 }
5893 }
5894 if (!child.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005895 //Slog.i(TAG, "Not visible!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005896 continue;
5897 }
5898 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005899 //Slog.i(TAG, "Not touchable!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005900 if ((flags & WindowManager.LayoutParams
5901 .FLAG_WATCH_OUTSIDE_TOUCH) != 0) {
5902 child.mNextOutsideTouch = mOutsideTouchTargets;
5903 mOutsideTouchTargets = child;
5904 }
5905 continue;
5906 }
5907 tmpRect.set(child.mFrame);
5908 if (child.mTouchableInsets == ViewTreeObserver
5909 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
5910 // The touch is inside of the window if it is
5911 // inside the frame, AND the content part of that
5912 // frame that was given by the application.
5913 tmpRect.left += child.mGivenContentInsets.left;
5914 tmpRect.top += child.mGivenContentInsets.top;
5915 tmpRect.right -= child.mGivenContentInsets.right;
5916 tmpRect.bottom -= child.mGivenContentInsets.bottom;
5917 } else if (child.mTouchableInsets == ViewTreeObserver
5918 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
5919 // The touch is inside of the window if it is
5920 // inside the frame, AND the visible part of that
5921 // frame that was given by the application.
5922 tmpRect.left += child.mGivenVisibleInsets.left;
5923 tmpRect.top += child.mGivenVisibleInsets.top;
5924 tmpRect.right -= child.mGivenVisibleInsets.right;
5925 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
5926 }
5927 final int touchFlags = flags &
5928 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
5929 |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
5930 if (tmpRect.contains(x, y) || touchFlags == 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005931 //Slog.i(TAG, "Using this target!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005932 if (!screenWasOff || (flags &
5933 WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) {
5934 mMotionTarget = child;
5935 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005936 //Slog.i(TAG, "Waking, skip!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005937 mMotionTarget = null;
5938 }
5939 break;
5940 }
Romain Guy06882f82009-06-10 13:36:04 -07005941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005942 if ((flags & WindowManager.LayoutParams
5943 .FLAG_WATCH_OUTSIDE_TOUCH) != 0) {
5944 child.mNextOutsideTouch = mOutsideTouchTargets;
5945 mOutsideTouchTargets = child;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005946 //Slog.i(TAG, "Adding to outside target list: " + child);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005947 }
5948 }
5949
5950 // if there's an error window but it's not accepting
5951 // focus (typically because it is not yet visible) just
5952 // wait for it -- any other focused window may in fact
5953 // be in ANR state.
5954 if (topErrWindow != null && mMotionTarget != topErrWindow) {
5955 mMotionTarget = null;
5956 }
5957 }
Romain Guy06882f82009-06-10 13:36:04 -07005958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005959 target = mMotionTarget;
5960 }
5961 }
Romain Guy06882f82009-06-10 13:36:04 -07005962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005963 wakeupIfNeeded(target, eventType(nextMotion));
Romain Guy06882f82009-06-10 13:36:04 -07005964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005965 // Pointer events are a little different -- if there isn't a
5966 // target found for any event, then just drop it.
5967 return target != null ? target : SKIP_TARGET_TOKEN;
5968 }
Romain Guy06882f82009-06-10 13:36:04 -07005969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005970 boolean checkShouldDispatchKey(int keycode) {
5971 synchronized (this) {
5972 if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) {
5973 mTimeToSwitch = 0;
5974 return true;
5975 }
5976 if (mTimeToSwitch != 0
5977 && mTimeToSwitch < SystemClock.uptimeMillis()) {
5978 return false;
5979 }
5980 return true;
5981 }
5982 }
Romain Guy06882f82009-06-10 13:36:04 -07005983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005984 void bindTargetWindowLocked(WindowState win,
5985 int pendingWhat, QueuedEvent pendingMotion) {
5986 synchronized (this) {
5987 bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion);
5988 }
5989 }
Romain Guy06882f82009-06-10 13:36:04 -07005990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005991 void bindTargetWindowLocked(WindowState win) {
5992 synchronized (this) {
5993 bindTargetWindowLockedLocked(win, RETURN_NOTHING, null);
5994 }
5995 }
5996
5997 void bindTargetWindowLockedLocked(WindowState win,
5998 int pendingWhat, QueuedEvent pendingMotion) {
5999 mLastWin = win;
6000 mLastBinder = win.mClient.asBinder();
6001 mFinished = false;
6002 if (pendingMotion != null) {
6003 final Session s = win.mSession;
6004 if (pendingWhat == RETURN_PENDING_POINTER) {
6005 releasePendingPointerLocked(s);
6006 s.mPendingPointerMove = pendingMotion;
6007 s.mPendingPointerWindow = win;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006008 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006009 "bindTargetToWindow " + s.mPendingPointerMove);
6010 } else if (pendingWhat == RETURN_PENDING_TRACKBALL) {
6011 releasePendingTrackballLocked(s);
6012 s.mPendingTrackballMove = pendingMotion;
6013 s.mPendingTrackballWindow = win;
6014 }
6015 }
6016 }
Romain Guy06882f82009-06-10 13:36:04 -07006017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006018 void releasePendingPointerLocked(Session s) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006019 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006020 "releasePendingPointer " + s.mPendingPointerMove);
6021 if (s.mPendingPointerMove != null) {
6022 mQueue.recycleEvent(s.mPendingPointerMove);
6023 s.mPendingPointerMove = null;
6024 }
6025 }
Romain Guy06882f82009-06-10 13:36:04 -07006026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006027 void releasePendingTrackballLocked(Session s) {
6028 if (s.mPendingTrackballMove != null) {
6029 mQueue.recycleEvent(s.mPendingTrackballMove);
6030 s.mPendingTrackballMove = null;
6031 }
6032 }
Romain Guy06882f82009-06-10 13:36:04 -07006033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006034 MotionEvent finishedKey(Session session, IWindow client, boolean force,
6035 int returnWhat) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006036 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006037 TAG, "finishedKey: client=" + client + ", force=" + force);
6038
6039 if (client == null) {
6040 return null;
6041 }
6042
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006043 MotionEvent res = null;
6044 QueuedEvent qev = null;
6045 WindowState win = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006047 synchronized (this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006048 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006049 TAG, "finishedKey: client=" + client.asBinder()
6050 + ", force=" + force + ", last=" + mLastBinder
6051 + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")");
6052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006053 if (returnWhat == RETURN_PENDING_POINTER) {
6054 qev = session.mPendingPointerMove;
6055 win = session.mPendingPointerWindow;
6056 session.mPendingPointerMove = null;
6057 session.mPendingPointerWindow = null;
6058 } else if (returnWhat == RETURN_PENDING_TRACKBALL) {
6059 qev = session.mPendingTrackballMove;
6060 win = session.mPendingTrackballWindow;
6061 session.mPendingTrackballMove = null;
6062 session.mPendingTrackballWindow = null;
6063 }
Romain Guy06882f82009-06-10 13:36:04 -07006064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006065 if (mLastBinder == client.asBinder()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006066 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006067 TAG, "finishedKey: last paused="
6068 + ((mLastWin != null) ? mLastWin.mToken.paused : "null"));
6069 if (mLastWin != null && (!mLastWin.mToken.paused || force
6070 || !mEventDispatching)) {
Christopher Tate136b1f92010-02-11 17:51:24 -08006071 doFinishedKeyLocked(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006072 } else {
6073 // Make sure to wake up anyone currently waiting to
6074 // dispatch a key, so they can re-evaluate their
6075 // current situation.
6076 mFinished = true;
6077 notifyAll();
6078 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006079 }
Romain Guy06882f82009-06-10 13:36:04 -07006080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006081 if (qev != null) {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006082 res = (MotionEvent)qev.event;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006083 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006084 "Returning pending motion: " + res);
6085 mQueue.recycleEvent(qev);
6086 if (win != null && returnWhat == RETURN_PENDING_POINTER) {
6087 res.offsetLocation(-win.mFrame.left, -win.mFrame.top);
6088 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006089 }
Christopher Tate2624fbc2009-12-11 12:11:31 -08006090 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006091
Christopher Tate2624fbc2009-12-11 12:11:31 -08006092 if (res != null && returnWhat == RETURN_PENDING_POINTER) {
6093 synchronized (mWindowMap) {
Dianne Hackborn90d2db32010-02-11 22:19:06 -08006094 dispatchPointerElsewhereLocked(win, win, res, res.getEventTime(), false);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006095 }
6096 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006097
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006098 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006099 }
6100
6101 void tickle() {
6102 synchronized (this) {
6103 notifyAll();
6104 }
6105 }
Romain Guy06882f82009-06-10 13:36:04 -07006106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006107 void handleNewWindowLocked(WindowState newWindow) {
6108 if (!newWindow.canReceiveKeys()) {
6109 return;
6110 }
6111 synchronized (this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006112 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006113 TAG, "New key dispatch window: win="
6114 + newWindow.mClient.asBinder()
6115 + ", last=" + mLastBinder
6116 + " (token=" + (mLastWin != null ? mLastWin.mToken : null)
6117 + "), finished=" + mFinished + ", paused="
6118 + newWindow.mToken.paused);
6119
6120 // Displaying a window implicitly causes dispatching to
6121 // be unpaused. (This is to protect against bugs if someone
6122 // pauses dispatching but forgets to resume.)
6123 newWindow.mToken.paused = false;
6124
6125 mGotFirstWindow = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006126
6127 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006128 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006129 "New SYSTEM_ERROR window; resetting state");
6130 mLastWin = null;
6131 mLastBinder = null;
6132 mMotionTarget = null;
6133 mFinished = true;
6134 } else if (mLastWin != null) {
6135 // If the new window is above the window we are
6136 // waiting on, then stop waiting and let key dispatching
6137 // start on the new guy.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006138 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006139 TAG, "Last win layer=" + mLastWin.mLayer
6140 + ", new win layer=" + newWindow.mLayer);
6141 if (newWindow.mLayer >= mLastWin.mLayer) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08006142 // The new window is above the old; finish pending input to the last
6143 // window and start directing it to the new one.
6144 mLastWin.mToken.paused = false;
Christopher Tate136b1f92010-02-11 17:51:24 -08006145 doFinishedKeyLocked(false); // does a notifyAll()
6146 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006147 }
6148 }
6149
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08006150 // Now that we've put a new window state in place, make the event waiter
6151 // take notice and retarget its attentions.
6152 notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006153 }
6154 }
6155
6156 void pauseDispatchingLocked(WindowToken token) {
6157 synchronized (this)
6158 {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006159 if (DEBUG_INPUT) Slog.v(TAG, "Pausing WindowToken " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006160 token.paused = true;
6161
6162 /*
6163 if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) {
6164 mPaused = true;
6165 } else {
6166 if (mLastWin == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006167 Slog.i(TAG, "Key dispatching not paused: no last window.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006168 } else if (mFinished) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006169 Slog.i(TAG, "Key dispatching not paused: finished last key.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006170 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006171 Slog.i(TAG, "Key dispatching not paused: window in higher layer.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006172 }
6173 }
6174 */
6175 }
6176 }
6177
6178 void resumeDispatchingLocked(WindowToken token) {
6179 synchronized (this) {
6180 if (token.paused) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006181 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006182 TAG, "Resuming WindowToken " + token
6183 + ", last=" + mLastBinder
6184 + " (token=" + (mLastWin != null ? mLastWin.mToken : null)
6185 + "), finished=" + mFinished + ", paused="
6186 + token.paused);
6187 token.paused = false;
6188 if (mLastWin != null && mLastWin.mToken == token && mFinished) {
Christopher Tate136b1f92010-02-11 17:51:24 -08006189 doFinishedKeyLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006190 } else {
6191 notifyAll();
6192 }
6193 }
6194 }
6195 }
6196
6197 void setEventDispatchingLocked(boolean enabled) {
6198 synchronized (this) {
6199 mEventDispatching = enabled;
6200 notifyAll();
6201 }
6202 }
Romain Guy06882f82009-06-10 13:36:04 -07006203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006204 void appSwitchComing() {
6205 synchronized (this) {
6206 // Don't wait for more than .5 seconds for app to finish
6207 // processing the pending events.
6208 long now = SystemClock.uptimeMillis() + 500;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006209 if (DEBUG_INPUT) Slog.v(TAG, "appSwitchComing: " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006210 if (mTimeToSwitch == 0 || now < mTimeToSwitch) {
6211 mTimeToSwitch = now;
6212 }
6213 notifyAll();
6214 }
6215 }
Romain Guy06882f82009-06-10 13:36:04 -07006216
Christopher Tate136b1f92010-02-11 17:51:24 -08006217 private final void doFinishedKeyLocked(boolean force) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006218 if (mLastWin != null) {
6219 releasePendingPointerLocked(mLastWin.mSession);
6220 releasePendingTrackballLocked(mLastWin.mSession);
6221 }
Romain Guy06882f82009-06-10 13:36:04 -07006222
Christopher Tate136b1f92010-02-11 17:51:24 -08006223 if (force || mLastWin == null || !mLastWin.mToken.paused
6224 || !mLastWin.isVisibleLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006225 // If the current window has been paused, we aren't -really-
6226 // finished... so let the waiters still wait.
6227 mLastWin = null;
6228 mLastBinder = null;
6229 }
6230 mFinished = true;
6231 notifyAll();
6232 }
6233 }
6234
6235 private class KeyQ extends KeyInputQueue
6236 implements KeyInputQueue.FilterCallback {
6237 PowerManager.WakeLock mHoldingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07006238
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006239 KeyQ() {
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07006240 super(mContext, WindowManagerService.this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006241 PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
6242 mHoldingScreen = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
6243 "KEEP_SCREEN_ON_FLAG");
6244 mHoldingScreen.setReferenceCounted(false);
6245 }
6246
6247 @Override
6248 boolean preprocessEvent(InputDevice device, RawInputEvent event) {
6249 if (mPolicy.preprocessInputEventTq(event)) {
6250 return true;
6251 }
Romain Guy06882f82009-06-10 13:36:04 -07006252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006253 switch (event.type) {
6254 case RawInputEvent.EV_KEY: {
6255 // XXX begin hack
6256 if (DEBUG) {
6257 if (event.keycode == KeyEvent.KEYCODE_G) {
6258 if (event.value != 0) {
6259 // G down
6260 mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
6261 }
6262 return false;
6263 }
6264 if (event.keycode == KeyEvent.KEYCODE_D) {
6265 if (event.value != 0) {
6266 //dump();
6267 }
6268 return false;
6269 }
6270 }
6271 // XXX end hack
Romain Guy06882f82009-06-10 13:36:04 -07006272
Charles Mendis322591c2009-10-29 11:06:59 -07006273 boolean screenIsOff = !mPowerManager.isScreenOn();
6274 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006275 int actions = mPolicy.interceptKeyTq(event, !screenIsOff);
Romain Guy06882f82009-06-10 13:36:04 -07006276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006277 if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) {
6278 mPowerManager.goToSleep(event.when);
6279 }
6280
6281 if (screenIsOff) {
6282 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6283 }
6284 if (screenIsDim) {
6285 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6286 }
6287 if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) {
6288 mPowerManager.userActivity(event.when, false,
Michael Chane96440f2009-05-06 10:27:36 -07006289 LocalPowerManager.BUTTON_EVENT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006290 }
Romain Guy06882f82009-06-10 13:36:04 -07006291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006292 if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) {
6293 if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) {
6294 filterQueue(this);
6295 mKeyWaiter.appSwitchComing();
6296 }
6297 return true;
6298 } else {
6299 return false;
6300 }
6301 }
Romain Guy06882f82009-06-10 13:36:04 -07006302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006303 case RawInputEvent.EV_REL: {
Charles Mendis322591c2009-10-29 11:06:59 -07006304 boolean screenIsOff = !mPowerManager.isScreenOn();
6305 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006306 if (screenIsOff) {
6307 if (!mPolicy.isWakeRelMovementTq(event.deviceId,
6308 device.classes, event)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006309 //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006310 return false;
6311 }
6312 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6313 }
6314 if (screenIsDim) {
6315 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6316 }
6317 return true;
6318 }
Romain Guy06882f82009-06-10 13:36:04 -07006319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006320 case RawInputEvent.EV_ABS: {
Charles Mendis322591c2009-10-29 11:06:59 -07006321 boolean screenIsOff = !mPowerManager.isScreenOn();
6322 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006323 if (screenIsOff) {
6324 if (!mPolicy.isWakeAbsMovementTq(event.deviceId,
6325 device.classes, event)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006326 //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006327 return false;
6328 }
6329 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6330 }
6331 if (screenIsDim) {
6332 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6333 }
6334 return true;
6335 }
Romain Guy06882f82009-06-10 13:36:04 -07006336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006337 default:
6338 return true;
6339 }
6340 }
6341
6342 public int filterEvent(QueuedEvent ev) {
6343 switch (ev.classType) {
6344 case RawInputEvent.CLASS_KEYBOARD:
6345 KeyEvent ke = (KeyEvent)ev.event;
6346 if (mPolicy.isMovementKeyTi(ke.getKeyCode())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006347 Slog.w(TAG, "Dropping movement key during app switch: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006348 + ke.getKeyCode() + ", action=" + ke.getAction());
6349 return FILTER_REMOVE;
6350 }
6351 return FILTER_ABORT;
6352 default:
6353 return FILTER_KEEP;
6354 }
6355 }
Romain Guy06882f82009-06-10 13:36:04 -07006356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006357 /**
6358 * Must be called with the main window manager lock held.
6359 */
6360 void setHoldScreenLocked(boolean holding) {
6361 boolean state = mHoldingScreen.isHeld();
6362 if (holding != state) {
6363 if (holding) {
6364 mHoldingScreen.acquire();
6365 } else {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006366 mPolicy.screenOnStoppedLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006367 mHoldingScreen.release();
6368 }
6369 }
6370 }
Michael Chan53071d62009-05-13 17:29:48 -07006371 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006372
6373 public boolean detectSafeMode() {
6374 mSafeMode = mPolicy.detectSafeMode();
6375 return mSafeMode;
6376 }
Romain Guy06882f82009-06-10 13:36:04 -07006377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006378 public void systemReady() {
6379 mPolicy.systemReady();
6380 }
Romain Guy06882f82009-06-10 13:36:04 -07006381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006382 private final class InputDispatcherThread extends Thread {
6383 // Time to wait when there is nothing to do: 9999 seconds.
6384 static final int LONG_WAIT=9999*1000;
6385
6386 public InputDispatcherThread() {
6387 super("InputDispatcher");
6388 }
Romain Guy06882f82009-06-10 13:36:04 -07006389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006390 @Override
6391 public void run() {
6392 while (true) {
6393 try {
6394 process();
6395 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006396 Slog.e(TAG, "Exception in input dispatcher", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006397 }
6398 }
6399 }
Romain Guy06882f82009-06-10 13:36:04 -07006400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006401 private void process() {
6402 android.os.Process.setThreadPriority(
6403 android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);
Romain Guy06882f82009-06-10 13:36:04 -07006404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006405 // The last key event we saw
6406 KeyEvent lastKey = null;
6407
6408 // Last keydown time for auto-repeating keys
6409 long lastKeyTime = SystemClock.uptimeMillis();
6410 long nextKeyTime = lastKeyTime+LONG_WAIT;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006411 long downTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006412
Romain Guy06882f82009-06-10 13:36:04 -07006413 // How many successive repeats we generated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006414 int keyRepeatCount = 0;
6415
6416 // Need to report that configuration has changed?
6417 boolean configChanged = false;
Romain Guy06882f82009-06-10 13:36:04 -07006418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006419 while (true) {
6420 long curTime = SystemClock.uptimeMillis();
6421
Joe Onorato8a9b2202010-02-26 18:56:32 -08006422 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006423 TAG, "Waiting for next key: now=" + curTime
6424 + ", repeat @ " + nextKeyTime);
6425
6426 // Retrieve next event, waiting only as long as the next
6427 // repeat timeout. If the configuration has changed, then
6428 // don't wait at all -- we'll report the change as soon as
6429 // we have processed all events.
6430 QueuedEvent ev = mQueue.getEvent(
6431 (int)((!configChanged && curTime < nextKeyTime)
6432 ? (nextKeyTime-curTime) : 0));
6433
Joe Onorato8a9b2202010-02-26 18:56:32 -08006434 if (DEBUG_INPUT && ev != null) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006435 TAG, "Event: type=" + ev.classType + " data=" + ev.event);
6436
Michael Chan53071d62009-05-13 17:29:48 -07006437 if (MEASURE_LATENCY) {
6438 lt.sample("2 got event ", System.nanoTime() - ev.whenNano);
6439 }
6440
Mike Lockwood3d0ea722009-10-21 22:58:29 -04006441 if (lastKey != null && !mPolicy.allowKeyRepeat()) {
6442 // cancel key repeat at the request of the policy.
6443 lastKey = null;
6444 downTime = 0;
6445 lastKeyTime = curTime;
6446 nextKeyTime = curTime + LONG_WAIT;
6447 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006448 try {
6449 if (ev != null) {
Michael Chan53071d62009-05-13 17:29:48 -07006450 curTime = SystemClock.uptimeMillis();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006451 int eventType;
6452 if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) {
6453 eventType = eventType((MotionEvent)ev.event);
6454 } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD ||
6455 ev.classType == RawInputEvent.CLASS_TRACKBALL) {
6456 eventType = LocalPowerManager.BUTTON_EVENT;
6457 } else {
6458 eventType = LocalPowerManager.OTHER_EVENT;
6459 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07006460 try {
Michael Chan53071d62009-05-13 17:29:48 -07006461 if ((curTime - mLastBatteryStatsCallTime)
Michael Chane96440f2009-05-06 10:27:36 -07006462 >= MIN_TIME_BETWEEN_USERACTIVITIES) {
Michael Chan53071d62009-05-13 17:29:48 -07006463 mLastBatteryStatsCallTime = curTime;
Michael Chane96440f2009-05-06 10:27:36 -07006464 mBatteryStats.noteInputEvent();
6465 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07006466 } catch (RemoteException e) {
6467 // Ignore
6468 }
Michael Chane10de972009-05-18 11:24:50 -07006469
Mike Lockwood5db42402009-11-30 14:51:51 -05006470 if (ev.classType == RawInputEvent.CLASS_CONFIGURATION_CHANGED) {
6471 // do not wake screen in this case
6472 } else if (eventType != TOUCH_EVENT
Michael Chane10de972009-05-18 11:24:50 -07006473 && eventType != LONG_TOUCH_EVENT
6474 && eventType != CHEEK_EVENT) {
6475 mPowerManager.userActivity(curTime, false,
6476 eventType, false);
6477 } else if (mLastTouchEventType != eventType
6478 || (curTime - mLastUserActivityCallTime)
6479 >= MIN_TIME_BETWEEN_USERACTIVITIES) {
6480 mLastUserActivityCallTime = curTime;
6481 mLastTouchEventType = eventType;
6482 mPowerManager.userActivity(curTime, false,
6483 eventType, false);
6484 }
6485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006486 switch (ev.classType) {
6487 case RawInputEvent.CLASS_KEYBOARD:
6488 KeyEvent ke = (KeyEvent)ev.event;
6489 if (ke.isDown()) {
6490 lastKey = ke;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006491 downTime = curTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006492 keyRepeatCount = 0;
6493 lastKeyTime = curTime;
6494 nextKeyTime = lastKeyTime
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006495 + ViewConfiguration.getLongPressTimeout();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006496 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006497 TAG, "Received key down: first repeat @ "
6498 + nextKeyTime);
6499 } else {
6500 lastKey = null;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006501 downTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006502 // Arbitrary long timeout.
6503 lastKeyTime = curTime;
6504 nextKeyTime = curTime + LONG_WAIT;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006505 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006506 TAG, "Received key up: ignore repeat @ "
6507 + nextKeyTime);
6508 }
6509 dispatchKey((KeyEvent)ev.event, 0, 0);
6510 mQueue.recycleEvent(ev);
6511 break;
6512 case RawInputEvent.CLASS_TOUCHSCREEN:
Joe Onorato8a9b2202010-02-26 18:56:32 -08006513 //Slog.i(TAG, "Read next event " + ev);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006514 dispatchPointer(ev, (MotionEvent)ev.event, 0, 0);
6515 break;
6516 case RawInputEvent.CLASS_TRACKBALL:
6517 dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0);
6518 break;
6519 case RawInputEvent.CLASS_CONFIGURATION_CHANGED:
6520 configChanged = true;
6521 break;
6522 default:
6523 mQueue.recycleEvent(ev);
6524 break;
6525 }
Romain Guy06882f82009-06-10 13:36:04 -07006526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006527 } else if (configChanged) {
6528 configChanged = false;
6529 sendNewConfiguration();
Romain Guy06882f82009-06-10 13:36:04 -07006530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006531 } else if (lastKey != null) {
6532 curTime = SystemClock.uptimeMillis();
Romain Guy06882f82009-06-10 13:36:04 -07006533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006534 // Timeout occurred while key was down. If it is at or
6535 // past the key repeat time, dispatch the repeat.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006536 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006537 TAG, "Key timeout: repeat=" + nextKeyTime
6538 + ", now=" + curTime);
6539 if (curTime < nextKeyTime) {
6540 continue;
6541 }
Romain Guy06882f82009-06-10 13:36:04 -07006542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006543 lastKeyTime = nextKeyTime;
6544 nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY;
6545 keyRepeatCount++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006546 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006547 TAG, "Key repeat: count=" + keyRepeatCount
6548 + ", next @ " + nextKeyTime);
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006549 KeyEvent newEvent;
6550 if (downTime != 0 && (downTime
6551 + ViewConfiguration.getLongPressTimeout())
6552 <= curTime) {
6553 newEvent = KeyEvent.changeTimeRepeat(lastKey,
6554 curTime, keyRepeatCount,
6555 lastKey.getFlags() | KeyEvent.FLAG_LONG_PRESS);
6556 downTime = 0;
6557 } else {
6558 newEvent = KeyEvent.changeTimeRepeat(lastKey,
6559 curTime, keyRepeatCount);
6560 }
6561 dispatchKey(newEvent, 0, 0);
Romain Guy06882f82009-06-10 13:36:04 -07006562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006563 } else {
6564 curTime = SystemClock.uptimeMillis();
Romain Guy06882f82009-06-10 13:36:04 -07006565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006566 lastKeyTime = curTime;
6567 nextKeyTime = curTime + LONG_WAIT;
6568 }
Romain Guy06882f82009-06-10 13:36:04 -07006569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006570 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006571 Slog.e(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006572 "Input thread received uncaught exception: " + e, e);
6573 }
6574 }
6575 }
6576 }
6577
6578 // -------------------------------------------------------------
6579 // Client Session State
6580 // -------------------------------------------------------------
6581
6582 private final class Session extends IWindowSession.Stub
6583 implements IBinder.DeathRecipient {
6584 final IInputMethodClient mClient;
6585 final IInputContext mInputContext;
6586 final int mUid;
6587 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006588 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006589 SurfaceSession mSurfaceSession;
6590 int mNumWindow = 0;
6591 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006593 /**
6594 * Current pointer move event being dispatched to client window... must
6595 * hold key lock to access.
6596 */
6597 QueuedEvent mPendingPointerMove;
6598 WindowState mPendingPointerWindow;
Romain Guy06882f82009-06-10 13:36:04 -07006599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006600 /**
6601 * Current trackball move event being dispatched to client window... must
6602 * hold key lock to access.
6603 */
6604 QueuedEvent mPendingTrackballMove;
6605 WindowState mPendingTrackballWindow;
6606
6607 public Session(IInputMethodClient client, IInputContext inputContext) {
6608 mClient = client;
6609 mInputContext = inputContext;
6610 mUid = Binder.getCallingUid();
6611 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006612 StringBuilder sb = new StringBuilder();
6613 sb.append("Session{");
6614 sb.append(Integer.toHexString(System.identityHashCode(this)));
6615 sb.append(" uid ");
6616 sb.append(mUid);
6617 sb.append("}");
6618 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006620 synchronized (mWindowMap) {
6621 if (mInputMethodManager == null && mHaveInputMethods) {
6622 IBinder b = ServiceManager.getService(
6623 Context.INPUT_METHOD_SERVICE);
6624 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6625 }
6626 }
6627 long ident = Binder.clearCallingIdentity();
6628 try {
6629 // Note: it is safe to call in to the input method manager
6630 // here because we are not holding our lock.
6631 if (mInputMethodManager != null) {
6632 mInputMethodManager.addClient(client, inputContext,
6633 mUid, mPid);
6634 } else {
6635 client.setUsingInputMethod(false);
6636 }
6637 client.asBinder().linkToDeath(this, 0);
6638 } catch (RemoteException e) {
6639 // The caller has died, so we can just forget about this.
6640 try {
6641 if (mInputMethodManager != null) {
6642 mInputMethodManager.removeClient(client);
6643 }
6644 } catch (RemoteException ee) {
6645 }
6646 } finally {
6647 Binder.restoreCallingIdentity(ident);
6648 }
6649 }
Romain Guy06882f82009-06-10 13:36:04 -07006650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006651 @Override
6652 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6653 throws RemoteException {
6654 try {
6655 return super.onTransact(code, data, reply, flags);
6656 } catch (RuntimeException e) {
6657 // Log all 'real' exceptions thrown to the caller
6658 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006659 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006660 }
6661 throw e;
6662 }
6663 }
6664
6665 public void binderDied() {
6666 // Note: it is safe to call in to the input method manager
6667 // here because we are not holding our lock.
6668 try {
6669 if (mInputMethodManager != null) {
6670 mInputMethodManager.removeClient(mClient);
6671 }
6672 } catch (RemoteException e) {
6673 }
6674 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006675 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006676 mClientDead = true;
6677 killSessionLocked();
6678 }
6679 }
6680
6681 public int add(IWindow window, WindowManager.LayoutParams attrs,
6682 int viewVisibility, Rect outContentInsets) {
6683 return addWindow(this, window, attrs, viewVisibility, outContentInsets);
6684 }
Romain Guy06882f82009-06-10 13:36:04 -07006685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006686 public void remove(IWindow window) {
6687 removeWindow(this, window);
6688 }
Romain Guy06882f82009-06-10 13:36:04 -07006689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006690 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6691 int requestedWidth, int requestedHeight, int viewFlags,
6692 boolean insetsPending, Rect outFrame, Rect outContentInsets,
6693 Rect outVisibleInsets, Surface outSurface) {
6694 return relayoutWindow(this, window, attrs,
6695 requestedWidth, requestedHeight, viewFlags, insetsPending,
6696 outFrame, outContentInsets, outVisibleInsets, outSurface);
6697 }
Romain Guy06882f82009-06-10 13:36:04 -07006698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006699 public void setTransparentRegion(IWindow window, Region region) {
6700 setTransparentRegionWindow(this, window, region);
6701 }
Romain Guy06882f82009-06-10 13:36:04 -07006702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006703 public void setInsets(IWindow window, int touchableInsets,
6704 Rect contentInsets, Rect visibleInsets) {
6705 setInsetsWindow(this, window, touchableInsets, contentInsets,
6706 visibleInsets);
6707 }
Romain Guy06882f82009-06-10 13:36:04 -07006708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006709 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6710 getWindowDisplayFrame(this, window, outDisplayFrame);
6711 }
Romain Guy06882f82009-06-10 13:36:04 -07006712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006713 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006714 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006715 TAG, "IWindow finishDrawing called for " + window);
6716 finishDrawingWindow(this, window);
6717 }
6718
6719 public void finishKey(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006720 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006721 TAG, "IWindow finishKey called for " + window);
6722 mKeyWaiter.finishedKey(this, window, false,
6723 KeyWaiter.RETURN_NOTHING);
6724 }
6725
6726 public MotionEvent getPendingPointerMove(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006727 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006728 TAG, "IWindow getPendingMotionEvent called for " + window);
6729 return mKeyWaiter.finishedKey(this, window, false,
6730 KeyWaiter.RETURN_PENDING_POINTER);
6731 }
Romain Guy06882f82009-06-10 13:36:04 -07006732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006733 public MotionEvent getPendingTrackballMove(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006734 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006735 TAG, "IWindow getPendingMotionEvent called for " + window);
6736 return mKeyWaiter.finishedKey(this, window, false,
6737 KeyWaiter.RETURN_PENDING_TRACKBALL);
6738 }
6739
6740 public void setInTouchMode(boolean mode) {
6741 synchronized(mWindowMap) {
6742 mInTouchMode = mode;
6743 }
6744 }
6745
6746 public boolean getInTouchMode() {
6747 synchronized(mWindowMap) {
6748 return mInTouchMode;
6749 }
6750 }
6751
6752 public boolean performHapticFeedback(IWindow window, int effectId,
6753 boolean always) {
6754 synchronized(mWindowMap) {
6755 long ident = Binder.clearCallingIdentity();
6756 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006757 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006758 windowForClientLocked(this, window, true),
6759 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006760 } finally {
6761 Binder.restoreCallingIdentity(ident);
6762 }
6763 }
6764 }
Romain Guy06882f82009-06-10 13:36:04 -07006765
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006766 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006767 synchronized(mWindowMap) {
6768 long ident = Binder.clearCallingIdentity();
6769 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006770 setWindowWallpaperPositionLocked(
6771 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006772 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006773 } finally {
6774 Binder.restoreCallingIdentity(ident);
6775 }
6776 }
6777 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006778
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006779 public void wallpaperOffsetsComplete(IBinder window) {
6780 WindowManagerService.this.wallpaperOffsetsComplete(window);
6781 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006782
Dianne Hackborn75804932009-10-20 20:15:20 -07006783 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6784 int z, Bundle extras, boolean sync) {
6785 synchronized(mWindowMap) {
6786 long ident = Binder.clearCallingIdentity();
6787 try {
6788 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006789 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006790 action, x, y, z, extras, sync);
6791 } finally {
6792 Binder.restoreCallingIdentity(ident);
6793 }
6794 }
6795 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006796
Dianne Hackborn75804932009-10-20 20:15:20 -07006797 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6798 WindowManagerService.this.wallpaperCommandComplete(window, result);
6799 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006801 void windowAddedLocked() {
6802 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006803 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006804 TAG, "First window added to " + this + ", creating SurfaceSession");
6805 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006806 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006807 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006808 mSessions.add(this);
6809 }
6810 mNumWindow++;
6811 }
6812
6813 void windowRemovedLocked() {
6814 mNumWindow--;
6815 killSessionLocked();
6816 }
Romain Guy06882f82009-06-10 13:36:04 -07006817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006818 void killSessionLocked() {
6819 if (mNumWindow <= 0 && mClientDead) {
6820 mSessions.remove(this);
6821 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006822 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006823 TAG, "Last window removed from " + this
6824 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006825 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006826 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006827 try {
6828 mSurfaceSession.kill();
6829 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006830 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006831 + mSurfaceSession + " in session " + this
6832 + ": " + e.toString());
6833 }
6834 mSurfaceSession = null;
6835 }
6836 }
6837 }
Romain Guy06882f82009-06-10 13:36:04 -07006838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006839 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006840 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6841 pw.print(" mClientDead="); pw.print(mClientDead);
6842 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
6843 if (mPendingPointerWindow != null || mPendingPointerMove != null) {
6844 pw.print(prefix);
6845 pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow);
6846 pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove);
6847 }
6848 if (mPendingTrackballWindow != null || mPendingTrackballMove != null) {
6849 pw.print(prefix);
6850 pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow);
6851 pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove);
6852 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006853 }
6854
6855 @Override
6856 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006857 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006858 }
6859 }
6860
6861 // -------------------------------------------------------------
6862 // Client Window State
6863 // -------------------------------------------------------------
6864
6865 private final class WindowState implements WindowManagerPolicy.WindowState {
6866 final Session mSession;
6867 final IWindow mClient;
6868 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006869 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006870 AppWindowToken mAppToken;
6871 AppWindowToken mTargetAppToken;
6872 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6873 final DeathRecipient mDeathRecipient;
6874 final WindowState mAttachedWindow;
6875 final ArrayList mChildWindows = new ArrayList();
6876 final int mBaseLayer;
6877 final int mSubLayer;
6878 final boolean mLayoutAttached;
6879 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006880 final boolean mIsWallpaper;
6881 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006882 int mViewVisibility;
6883 boolean mPolicyVisibility = true;
6884 boolean mPolicyVisibilityAfterAnim = true;
6885 boolean mAppFreezing;
6886 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006887 boolean mReportDestroySurface;
6888 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006889 boolean mAttachedHidden; // is our parent window hidden?
6890 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006891 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006892 int mRequestedWidth;
6893 int mRequestedHeight;
6894 int mLastRequestedWidth;
6895 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006896 int mLayer;
6897 int mAnimLayer;
6898 int mLastLayer;
6899 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006900 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006901 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006902
6903 WindowState mNextOutsideTouch;
Romain Guy06882f82009-06-10 13:36:04 -07006904
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006905 int mLayoutSeq = -1;
6906
6907 Configuration mConfiguration = null;
6908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006909 // Actual frame shown on-screen (may be modified by animation)
6910 final Rect mShownFrame = new Rect();
6911 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006913 /**
6914 * Insets that determine the actually visible area
6915 */
6916 final Rect mVisibleInsets = new Rect();
6917 final Rect mLastVisibleInsets = new Rect();
6918 boolean mVisibleInsetsChanged;
6919
6920 /**
6921 * Insets that are covered by system windows
6922 */
6923 final Rect mContentInsets = new Rect();
6924 final Rect mLastContentInsets = new Rect();
6925 boolean mContentInsetsChanged;
6926
6927 /**
6928 * Set to true if we are waiting for this window to receive its
6929 * given internal insets before laying out other windows based on it.
6930 */
6931 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006933 /**
6934 * These are the content insets that were given during layout for
6935 * this window, to be applied to windows behind it.
6936 */
6937 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006939 /**
6940 * These are the visible insets that were given during layout for
6941 * this window, to be applied to windows behind it.
6942 */
6943 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006945 /**
6946 * Flag indicating whether the touchable region should be adjusted by
6947 * the visible insets; if false the area outside the visible insets is
6948 * NOT touchable, so we must use those to adjust the frame during hit
6949 * tests.
6950 */
6951 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006953 // Current transformation being applied.
6954 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6955 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6956 float mHScale=1, mVScale=1;
6957 float mLastHScale=1, mLastVScale=1;
6958 final Matrix mTmpMatrix = new Matrix();
6959
6960 // "Real" frame that the application sees.
6961 final Rect mFrame = new Rect();
6962 final Rect mLastFrame = new Rect();
6963
6964 final Rect mContainingFrame = new Rect();
6965 final Rect mDisplayFrame = new Rect();
6966 final Rect mContentFrame = new Rect();
6967 final Rect mVisibleFrame = new Rect();
6968
6969 float mShownAlpha = 1;
6970 float mAlpha = 1;
6971 float mLastAlpha = 1;
6972
6973 // Set to true if, when the window gets displayed, it should perform
6974 // an enter animation.
6975 boolean mEnterAnimationPending;
6976
6977 // Currently running animation.
6978 boolean mAnimating;
6979 boolean mLocalAnimating;
6980 Animation mAnimation;
6981 boolean mAnimationIsEntrance;
6982 boolean mHasTransformation;
6983 boolean mHasLocalTransformation;
6984 final Transformation mTransformation = new Transformation();
6985
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006986 // If a window showing a wallpaper: the requested offset for the
6987 // wallpaper; if a wallpaper window: the currently applied offset.
6988 float mWallpaperX = -1;
6989 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006990
6991 // If a window showing a wallpaper: what fraction of the offset
6992 // range corresponds to a full virtual screen.
6993 float mWallpaperXStep = -1;
6994 float mWallpaperYStep = -1;
6995
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006996 // Wallpaper windows: pixels offset based on above variables.
6997 int mXOffset;
6998 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007000 // This is set after IWindowSession.relayout() has been called at
7001 // least once for the window. It allows us to detect the situation
7002 // where we don't yet have a surface, but should have one soon, so
7003 // we can give the window focus before waiting for the relayout.
7004 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07007005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007006 // This is set after the Surface has been created but before the
7007 // window has been drawn. During this time the surface is hidden.
7008 boolean mDrawPending;
7009
7010 // This is set after the window has finished drawing for the first
7011 // time but before its surface is shown. The surface will be
7012 // displayed when the next layout is run.
7013 boolean mCommitDrawPending;
7014
7015 // This is set during the time after the window's drawing has been
7016 // committed, and before its surface is actually shown. It is used
7017 // to delay showing the surface until all windows in a token are ready
7018 // to be shown.
7019 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07007020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007021 // Set when the window has been shown in the screen the first time.
7022 boolean mHasDrawn;
7023
7024 // Currently running an exit animation?
7025 boolean mExiting;
7026
7027 // Currently on the mDestroySurface list?
7028 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07007029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007030 // Completely remove from window manager after exit animation?
7031 boolean mRemoveOnExit;
7032
7033 // Set when the orientation is changing and this window has not yet
7034 // been updated for the new orientation.
7035 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07007036
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007037 // Is this window now (or just being) removed?
7038 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07007039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007040 WindowState(Session s, IWindow c, WindowToken token,
7041 WindowState attachedWindow, WindowManager.LayoutParams a,
7042 int viewVisibility) {
7043 mSession = s;
7044 mClient = c;
7045 mToken = token;
7046 mAttrs.copyFrom(a);
7047 mViewVisibility = viewVisibility;
7048 DeathRecipient deathRecipient = new DeathRecipient();
7049 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007050 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007051 TAG, "Window " + this + " client=" + c.asBinder()
7052 + " token=" + token + " (" + mAttrs.token + ")");
7053 try {
7054 c.asBinder().linkToDeath(deathRecipient, 0);
7055 } catch (RemoteException e) {
7056 mDeathRecipient = null;
7057 mAttachedWindow = null;
7058 mLayoutAttached = false;
7059 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007060 mIsWallpaper = false;
7061 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007062 mBaseLayer = 0;
7063 mSubLayer = 0;
7064 return;
7065 }
7066 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07007067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007068 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
7069 mAttrs.type <= LAST_SUB_WINDOW)) {
7070 // The multiplier here is to reserve space for multiple
7071 // windows in the same type layer.
7072 mBaseLayer = mPolicy.windowTypeToLayerLw(
7073 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
7074 + TYPE_LAYER_OFFSET;
7075 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
7076 mAttachedWindow = attachedWindow;
7077 mAttachedWindow.mChildWindows.add(this);
7078 mLayoutAttached = mAttrs.type !=
7079 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
7080 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
7081 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007082 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
7083 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007084 } else {
7085 // The multiplier here is to reserve space for multiple
7086 // windows in the same type layer.
7087 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
7088 * TYPE_LAYER_MULTIPLIER
7089 + TYPE_LAYER_OFFSET;
7090 mSubLayer = 0;
7091 mAttachedWindow = null;
7092 mLayoutAttached = false;
7093 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
7094 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007095 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
7096 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007097 }
7098
7099 WindowState appWin = this;
7100 while (appWin.mAttachedWindow != null) {
7101 appWin = mAttachedWindow;
7102 }
7103 WindowToken appToken = appWin.mToken;
7104 while (appToken.appWindowToken == null) {
7105 WindowToken parent = mTokenMap.get(appToken.token);
7106 if (parent == null || appToken == parent) {
7107 break;
7108 }
7109 appToken = parent;
7110 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007111 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007112 mAppToken = appToken.appWindowToken;
7113
7114 mSurface = null;
7115 mRequestedWidth = 0;
7116 mRequestedHeight = 0;
7117 mLastRequestedWidth = 0;
7118 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007119 mXOffset = 0;
7120 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007121 mLayer = 0;
7122 mAnimLayer = 0;
7123 mLastLayer = 0;
7124 }
7125
7126 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007127 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007128 TAG, "Attaching " + this + " token=" + mToken
7129 + ", list=" + mToken.windows);
7130 mSession.windowAddedLocked();
7131 }
7132
7133 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7134 mHaveFrame = true;
7135
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007136 final Rect container = mContainingFrame;
7137 container.set(pf);
7138
7139 final Rect display = mDisplayFrame;
7140 display.set(df);
7141
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007142 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007143 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007144 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7145 display.intersect(mCompatibleScreenFrame);
7146 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007147 }
7148
7149 final int pw = container.right - container.left;
7150 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007151
7152 int w,h;
7153 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7154 w = mAttrs.width < 0 ? pw : mAttrs.width;
7155 h = mAttrs.height< 0 ? ph : mAttrs.height;
7156 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007157 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7158 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007159 }
Romain Guy06882f82009-06-10 13:36:04 -07007160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007161 final Rect content = mContentFrame;
7162 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007164 final Rect visible = mVisibleFrame;
7165 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007166
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007167 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007168 final int fw = frame.width();
7169 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007171 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7172 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7173
7174 Gravity.apply(mAttrs.gravity, w, h, container,
7175 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7176 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7177
7178 //System.out.println("Out: " + mFrame);
7179
7180 // Now make sure the window fits in the overall display.
7181 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007183 // Make sure the content and visible frames are inside of the
7184 // final window frame.
7185 if (content.left < frame.left) content.left = frame.left;
7186 if (content.top < frame.top) content.top = frame.top;
7187 if (content.right > frame.right) content.right = frame.right;
7188 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7189 if (visible.left < frame.left) visible.left = frame.left;
7190 if (visible.top < frame.top) visible.top = frame.top;
7191 if (visible.right > frame.right) visible.right = frame.right;
7192 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007194 final Rect contentInsets = mContentInsets;
7195 contentInsets.left = content.left-frame.left;
7196 contentInsets.top = content.top-frame.top;
7197 contentInsets.right = frame.right-content.right;
7198 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007200 final Rect visibleInsets = mVisibleInsets;
7201 visibleInsets.left = visible.left-frame.left;
7202 visibleInsets.top = visible.top-frame.top;
7203 visibleInsets.right = frame.right-visible.right;
7204 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007205
Dianne Hackborn284ac932009-08-28 10:34:25 -07007206 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7207 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007208 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007209 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007211 if (localLOGV) {
7212 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7213 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007214 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007215 + mRequestedWidth + ", mRequestedheight="
7216 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7217 + "): frame=" + mFrame.toShortString()
7218 + " ci=" + contentInsets.toShortString()
7219 + " vi=" + visibleInsets.toShortString());
7220 //}
7221 }
7222 }
Romain Guy06882f82009-06-10 13:36:04 -07007223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007224 public Rect getFrameLw() {
7225 return mFrame;
7226 }
7227
7228 public Rect getShownFrameLw() {
7229 return mShownFrame;
7230 }
7231
7232 public Rect getDisplayFrameLw() {
7233 return mDisplayFrame;
7234 }
7235
7236 public Rect getContentFrameLw() {
7237 return mContentFrame;
7238 }
7239
7240 public Rect getVisibleFrameLw() {
7241 return mVisibleFrame;
7242 }
7243
7244 public boolean getGivenInsetsPendingLw() {
7245 return mGivenInsetsPending;
7246 }
7247
7248 public Rect getGivenContentInsetsLw() {
7249 return mGivenContentInsets;
7250 }
Romain Guy06882f82009-06-10 13:36:04 -07007251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007252 public Rect getGivenVisibleInsetsLw() {
7253 return mGivenVisibleInsets;
7254 }
Romain Guy06882f82009-06-10 13:36:04 -07007255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007256 public WindowManager.LayoutParams getAttrs() {
7257 return mAttrs;
7258 }
7259
7260 public int getSurfaceLayer() {
7261 return mLayer;
7262 }
Romain Guy06882f82009-06-10 13:36:04 -07007263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007264 public IApplicationToken getAppToken() {
7265 return mAppToken != null ? mAppToken.appToken : null;
7266 }
7267
7268 public boolean hasAppShownWindows() {
7269 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7270 }
7271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007272 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007273 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007274 TAG, "Setting animation in " + this + ": " + anim);
7275 mAnimating = false;
7276 mLocalAnimating = false;
7277 mAnimation = anim;
7278 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7279 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7280 }
7281
7282 public void clearAnimation() {
7283 if (mAnimation != null) {
7284 mAnimating = true;
7285 mLocalAnimating = false;
7286 mAnimation = null;
7287 }
7288 }
Romain Guy06882f82009-06-10 13:36:04 -07007289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007290 Surface createSurfaceLocked() {
7291 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007292 mReportDestroySurface = false;
7293 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007294 mDrawPending = true;
7295 mCommitDrawPending = false;
7296 mReadyToShow = false;
7297 if (mAppToken != null) {
7298 mAppToken.allDrawn = false;
7299 }
7300
7301 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07007302 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007303 flags |= Surface.PUSH_BUFFERS;
7304 }
7305
7306 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7307 flags |= Surface.SECURE;
7308 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007309 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007310 TAG, "Creating surface in session "
7311 + mSession.mSurfaceSession + " window " + this
7312 + " w=" + mFrame.width()
7313 + " h=" + mFrame.height() + " format="
7314 + mAttrs.format + " flags=" + flags);
7315
7316 int w = mFrame.width();
7317 int h = mFrame.height();
7318 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7319 // for a scaled surface, we always want the requested
7320 // size.
7321 w = mRequestedWidth;
7322 h = mRequestedHeight;
7323 }
7324
Romain Guy9825ec62009-10-01 00:58:09 -07007325 // Something is wrong and SurfaceFlinger will not like this,
7326 // try to revert to sane values
7327 if (w <= 0) w = 1;
7328 if (h <= 0) h = 1;
7329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007330 try {
7331 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007332 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007333 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007334 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007335 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007336 + mSurface + " IN SESSION "
7337 + mSession.mSurfaceSession
7338 + ": pid=" + mSession.mPid + " format="
7339 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007340 + Integer.toHexString(flags)
7341 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007342 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007343 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007344 reclaimSomeSurfaceMemoryLocked(this, "create");
7345 return null;
7346 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007347 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007348 return null;
7349 }
Romain Guy06882f82009-06-10 13:36:04 -07007350
Joe Onorato8a9b2202010-02-26 18:56:32 -08007351 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007352 TAG, "Got surface: " + mSurface
7353 + ", set left=" + mFrame.left + " top=" + mFrame.top
7354 + ", animLayer=" + mAnimLayer);
7355 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007356 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007357 if (SHOW_TRANSACTIONS) logSurface(this,
7358 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
7359 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7360 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007361 }
7362 Surface.openTransaction();
7363 try {
7364 try {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007365 mSurface.setPosition(mFrame.left + mXOffset,
7366 mFrame.top + mYOffset);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007367 mSurface.setLayer(mAnimLayer);
7368 mSurface.hide();
7369 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007370 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007371 mSurface.setFlags(Surface.SURFACE_DITHER,
7372 Surface.SURFACE_DITHER);
7373 }
7374 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007375 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007376 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7377 }
7378 mLastHidden = true;
7379 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007380 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007381 Surface.closeTransaction();
7382 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007383 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007384 TAG, "Created surface " + this);
7385 }
7386 return mSurface;
7387 }
Romain Guy06882f82009-06-10 13:36:04 -07007388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007389 void destroySurfaceLocked() {
7390 // Window is no longer on-screen, so can no longer receive
7391 // key events... if we were waiting for it to finish
7392 // handling a key event, the wait is over!
7393 mKeyWaiter.finishedKey(mSession, mClient, true,
7394 KeyWaiter.RETURN_NOTHING);
7395 mKeyWaiter.releasePendingPointerLocked(mSession);
7396 mKeyWaiter.releasePendingTrackballLocked(mSession);
7397
7398 if (mAppToken != null && this == mAppToken.startingWindow) {
7399 mAppToken.startingDisplayed = false;
7400 }
Romain Guy06882f82009-06-10 13:36:04 -07007401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007402 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007403 mDrawPending = false;
7404 mCommitDrawPending = false;
7405 mReadyToShow = false;
7406
7407 int i = mChildWindows.size();
7408 while (i > 0) {
7409 i--;
7410 WindowState c = (WindowState)mChildWindows.get(i);
7411 c.mAttachedHidden = true;
7412 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007413
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007414 if (mReportDestroySurface) {
7415 mReportDestroySurface = false;
7416 mSurfacePendingDestroy = true;
7417 try {
7418 mClient.dispatchGetNewSurface();
7419 // We'll really destroy on the next time around.
7420 return;
7421 } catch (RemoteException e) {
7422 }
7423 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007425 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007426 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007427 RuntimeException e = null;
7428 if (!HIDE_STACK_CRAWLS) {
7429 e = new RuntimeException();
7430 e.fillInStackTrace();
7431 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007432 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007433 + mSurface + ", session " + mSession, e);
7434 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007435 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007436 RuntimeException e = null;
7437 if (!HIDE_STACK_CRAWLS) {
7438 e = new RuntimeException();
7439 e.fillInStackTrace();
7440 }
7441 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007442 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007443 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007444 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007445 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007446 + " surface " + mSurface + " session " + mSession
7447 + ": " + e.toString());
7448 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007450 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007451 }
7452 }
7453
7454 boolean finishDrawingLocked() {
7455 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007456 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007457 TAG, "finishDrawingLocked: " + mSurface);
7458 mCommitDrawPending = true;
7459 mDrawPending = false;
7460 return true;
7461 }
7462 return false;
7463 }
7464
7465 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007466 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007467 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007468 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007469 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007470 }
7471 mCommitDrawPending = false;
7472 mReadyToShow = true;
7473 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7474 final AppWindowToken atoken = mAppToken;
7475 if (atoken == null || atoken.allDrawn || starting) {
7476 performShowLocked();
7477 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007478 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007479 }
7480
7481 // This must be called while inside a transaction.
7482 boolean performShowLocked() {
7483 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007484 RuntimeException e = null;
7485 if (!HIDE_STACK_CRAWLS) {
7486 e = new RuntimeException();
7487 e.fillInStackTrace();
7488 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007489 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007490 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7491 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7492 }
7493 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007494 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7495 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007496 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007497 + " during animation: policyVis=" + mPolicyVisibility
7498 + " attHidden=" + mAttachedHidden
7499 + " tok.hiddenRequested="
7500 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007501 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007502 + (mAppToken != null ? mAppToken.hidden : false)
7503 + " animating=" + mAnimating
7504 + " tok animating="
7505 + (mAppToken != null ? mAppToken.animating : false));
7506 if (!showSurfaceRobustlyLocked(this)) {
7507 return false;
7508 }
7509 mLastAlpha = -1;
7510 mHasDrawn = true;
7511 mLastHidden = false;
7512 mReadyToShow = false;
7513 enableScreenIfNeededLocked();
7514
7515 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007517 int i = mChildWindows.size();
7518 while (i > 0) {
7519 i--;
7520 WindowState c = (WindowState)mChildWindows.get(i);
7521 if (c.mSurface != null && c.mAttachedHidden) {
7522 c.mAttachedHidden = false;
7523 c.performShowLocked();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007524 // It hadn't been shown, which means layout not
7525 // performed on it, so now we want to make sure to
7526 // do a layout. If called from within the transaction
7527 // loop, this will cause it to restart with a new
7528 // layout.
7529 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007530 }
7531 }
Romain Guy06882f82009-06-10 13:36:04 -07007532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007533 if (mAttrs.type != TYPE_APPLICATION_STARTING
7534 && mAppToken != null) {
7535 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007536
Dianne Hackborn248b1882009-09-16 16:46:44 -07007537 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007538 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007539 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007540 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007541 // If this initial window is animating, stop it -- we
7542 // will do an animation to reveal it from behind the
7543 // starting window, so there is no need for it to also
7544 // be doing its own stuff.
7545 if (mAnimation != null) {
7546 mAnimation = null;
7547 // Make sure we clean up the animation.
7548 mAnimating = true;
7549 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007550 mFinishedStarting.add(mAppToken);
7551 mH.sendEmptyMessage(H.FINISHED_STARTING);
7552 }
7553 mAppToken.updateReportedVisibilityLocked();
7554 }
7555 }
7556 return true;
7557 }
Romain Guy06882f82009-06-10 13:36:04 -07007558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007559 // This must be called while inside a transaction. Returns true if
7560 // there is more animation to run.
7561 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007562 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007563 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007565 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7566 mHasTransformation = true;
7567 mHasLocalTransformation = true;
7568 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007569 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007570 TAG, "Starting animation in " + this +
7571 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7572 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7573 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7574 mAnimation.setStartTime(currentTime);
7575 mLocalAnimating = true;
7576 mAnimating = true;
7577 }
7578 mTransformation.clear();
7579 final boolean more = mAnimation.getTransformation(
7580 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007581 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007582 TAG, "Stepped animation in " + this +
7583 ": more=" + more + ", xform=" + mTransformation);
7584 if (more) {
7585 // we're not done!
7586 return true;
7587 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007588 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007589 TAG, "Finished animation in " + this +
7590 " @ " + currentTime);
7591 mAnimation = null;
7592 //WindowManagerService.this.dump();
7593 }
7594 mHasLocalTransformation = false;
7595 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007596 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007597 // When our app token is animating, we kind-of pretend like
7598 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7599 // part of this check means that we will only do this if
7600 // our window is not currently exiting, or it is not
7601 // locally animating itself. The idea being that one that
7602 // is exiting and doing a local animation should be removed
7603 // once that animation is done.
7604 mAnimating = true;
7605 mHasTransformation = true;
7606 mTransformation.clear();
7607 return false;
7608 } else if (mHasTransformation) {
7609 // Little trick to get through the path below to act like
7610 // we have finished an animation.
7611 mAnimating = true;
7612 } else if (isAnimating()) {
7613 mAnimating = true;
7614 }
7615 } else if (mAnimation != null) {
7616 // If the display is frozen, and there is a pending animation,
7617 // clear it and make sure we run the cleanup code.
7618 mAnimating = true;
7619 mLocalAnimating = true;
7620 mAnimation = null;
7621 }
Romain Guy06882f82009-06-10 13:36:04 -07007622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007623 if (!mAnimating && !mLocalAnimating) {
7624 return false;
7625 }
7626
Joe Onorato8a9b2202010-02-26 18:56:32 -08007627 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007628 TAG, "Animation done in " + this + ": exiting=" + mExiting
7629 + ", reportedVisible="
7630 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007632 mAnimating = false;
7633 mLocalAnimating = false;
7634 mAnimation = null;
7635 mAnimLayer = mLayer;
7636 if (mIsImWindow) {
7637 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007638 } else if (mIsWallpaper) {
7639 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007640 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007641 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007642 + " anim layer: " + mAnimLayer);
7643 mHasTransformation = false;
7644 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007645 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7646 if (DEBUG_VISIBILITY) {
7647 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7648 + mPolicyVisibilityAfterAnim);
7649 }
7650 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7651 if (!mPolicyVisibility) {
7652 if (mCurrentFocus == this) {
7653 mFocusMayChange = true;
7654 }
7655 // Window is no longer visible -- make sure if we were waiting
7656 // for it to be displayed before enabling the display, that
7657 // we allow the display to be enabled now.
7658 enableScreenIfNeededLocked();
7659 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007660 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007661 mTransformation.clear();
7662 if (mHasDrawn
7663 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7664 && mAppToken != null
7665 && mAppToken.firstWindowDrawn
7666 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007667 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007668 + mToken + ": first real window done animating");
7669 mFinishedStarting.add(mAppToken);
7670 mH.sendEmptyMessage(H.FINISHED_STARTING);
7671 }
Romain Guy06882f82009-06-10 13:36:04 -07007672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007673 finishExit();
7674
7675 if (mAppToken != null) {
7676 mAppToken.updateReportedVisibilityLocked();
7677 }
7678
7679 return false;
7680 }
7681
7682 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007683 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007684 TAG, "finishExit in " + this
7685 + ": exiting=" + mExiting
7686 + " remove=" + mRemoveOnExit
7687 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007689 final int N = mChildWindows.size();
7690 for (int i=0; i<N; i++) {
7691 ((WindowState)mChildWindows.get(i)).finishExit();
7692 }
Romain Guy06882f82009-06-10 13:36:04 -07007693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007694 if (!mExiting) {
7695 return;
7696 }
Romain Guy06882f82009-06-10 13:36:04 -07007697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007698 if (isWindowAnimating()) {
7699 return;
7700 }
7701
Joe Onorato8a9b2202010-02-26 18:56:32 -08007702 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007703 TAG, "Exit animation finished in " + this
7704 + ": remove=" + mRemoveOnExit);
7705 if (mSurface != null) {
7706 mDestroySurface.add(this);
7707 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007708 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007709 try {
7710 mSurface.hide();
7711 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007712 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007713 }
7714 mLastHidden = true;
7715 mKeyWaiter.releasePendingPointerLocked(mSession);
7716 }
7717 mExiting = false;
7718 if (mRemoveOnExit) {
7719 mPendingRemove.add(this);
7720 mRemoveOnExit = false;
7721 }
7722 }
Romain Guy06882f82009-06-10 13:36:04 -07007723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007724 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7725 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7726 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7727 if (dtdx < -.000001f || dtdx > .000001f) return false;
7728 if (dsdy < -.000001f || dsdy > .000001f) return false;
7729 return true;
7730 }
Romain Guy06882f82009-06-10 13:36:04 -07007731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007732 void computeShownFrameLocked() {
7733 final boolean selfTransformation = mHasLocalTransformation;
7734 Transformation attachedTransformation =
7735 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7736 ? mAttachedWindow.mTransformation : null;
7737 Transformation appTransformation =
7738 (mAppToken != null && mAppToken.hasTransformation)
7739 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007740
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007741 // Wallpapers are animated based on the "real" window they
7742 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007743 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007744 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007745 if (mWallpaperTarget.mHasLocalTransformation &&
7746 mWallpaperTarget.mAnimation != null &&
7747 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007748 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007749 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007750 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007751 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007752 }
7753 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007754 mWallpaperTarget.mAppToken.hasTransformation &&
7755 mWallpaperTarget.mAppToken.animation != null &&
7756 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007757 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007758 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007759 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007760 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007761 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007762 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007764 if (selfTransformation || attachedTransformation != null
7765 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007766 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007767 final Rect frame = mFrame;
7768 final float tmpFloats[] = mTmpFloats;
7769 final Matrix tmpMatrix = mTmpMatrix;
7770
7771 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007772 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007773 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007774 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007775 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007776 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007777 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007778 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007779 }
7780 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007781 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007782 }
7783
7784 // "convert" it into SurfaceFlinger's format
7785 // (a 2x2 matrix + an offset)
7786 // Here we must not transform the position of the surface
7787 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007788 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007790 tmpMatrix.getValues(tmpFloats);
7791 mDsDx = tmpFloats[Matrix.MSCALE_X];
7792 mDtDx = tmpFloats[Matrix.MSKEW_X];
7793 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7794 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007795 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7796 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007797 int w = frame.width();
7798 int h = frame.height();
7799 mShownFrame.set(x, y, x+w, y+h);
7800
7801 // Now set the alpha... but because our current hardware
7802 // can't do alpha transformation on a non-opaque surface,
7803 // turn it off if we are running an animation that is also
7804 // transforming since it is more important to have that
7805 // animation be smooth.
7806 mShownAlpha = mAlpha;
7807 if (!mLimitedAlphaCompositing
7808 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7809 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7810 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007811 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007812 if (selfTransformation) {
7813 mShownAlpha *= mTransformation.getAlpha();
7814 }
7815 if (attachedTransformation != null) {
7816 mShownAlpha *= attachedTransformation.getAlpha();
7817 }
7818 if (appTransformation != null) {
7819 mShownAlpha *= appTransformation.getAlpha();
7820 }
7821 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007822 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007823 }
Romain Guy06882f82009-06-10 13:36:04 -07007824
Joe Onorato8a9b2202010-02-26 18:56:32 -08007825 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007826 TAG, "Continuing animation in " + this +
7827 ": " + mShownFrame +
7828 ", alpha=" + mTransformation.getAlpha());
7829 return;
7830 }
Romain Guy06882f82009-06-10 13:36:04 -07007831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007832 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007833 if (mXOffset != 0 || mYOffset != 0) {
7834 mShownFrame.offset(mXOffset, mYOffset);
7835 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007836 mShownAlpha = mAlpha;
7837 mDsDx = 1;
7838 mDtDx = 0;
7839 mDsDy = 0;
7840 mDtDy = 1;
7841 }
Romain Guy06882f82009-06-10 13:36:04 -07007842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007843 /**
7844 * Is this window visible? It is not visible if there is no
7845 * surface, or we are in the process of running an exit animation
7846 * that will remove the surface, or its app token has been hidden.
7847 */
7848 public boolean isVisibleLw() {
7849 final AppWindowToken atoken = mAppToken;
7850 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7851 && (atoken == null || !atoken.hiddenRequested)
7852 && !mExiting && !mDestroying;
7853 }
7854
7855 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007856 * Like {@link #isVisibleLw}, but also counts a window that is currently
7857 * "hidden" behind the keyguard as visible. This allows us to apply
7858 * things like window flags that impact the keyguard.
7859 * XXX I am starting to think we need to have ANOTHER visibility flag
7860 * for this "hidden behind keyguard" state rather than overloading
7861 * mPolicyVisibility. Ungh.
7862 */
7863 public boolean isVisibleOrBehindKeyguardLw() {
7864 final AppWindowToken atoken = mAppToken;
7865 return mSurface != null && !mAttachedHidden
7866 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007867 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007868 && !mExiting && !mDestroying;
7869 }
7870
7871 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007872 * Is this window visible, ignoring its app token? It is not visible
7873 * if there is no surface, or we are in the process of running an exit animation
7874 * that will remove the surface.
7875 */
7876 public boolean isWinVisibleLw() {
7877 final AppWindowToken atoken = mAppToken;
7878 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7879 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7880 && !mExiting && !mDestroying;
7881 }
7882
7883 /**
7884 * The same as isVisible(), but follows the current hidden state of
7885 * the associated app token, not the pending requested hidden state.
7886 */
7887 boolean isVisibleNow() {
7888 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007889 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007890 }
7891
7892 /**
7893 * Same as isVisible(), but we also count it as visible between the
7894 * call to IWindowSession.add() and the first relayout().
7895 */
7896 boolean isVisibleOrAdding() {
7897 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007898 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007899 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7900 && mPolicyVisibility && !mAttachedHidden
7901 && (atoken == null || !atoken.hiddenRequested)
7902 && !mExiting && !mDestroying;
7903 }
7904
7905 /**
7906 * Is this window currently on-screen? It is on-screen either if it
7907 * is visible or it is currently running an animation before no longer
7908 * being visible.
7909 */
7910 boolean isOnScreen() {
7911 final AppWindowToken atoken = mAppToken;
7912 if (atoken != null) {
7913 return mSurface != null && mPolicyVisibility && !mDestroying
7914 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007915 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007916 } else {
7917 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007918 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007919 }
7920 }
Romain Guy06882f82009-06-10 13:36:04 -07007921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007922 /**
7923 * Like isOnScreen(), but we don't return true if the window is part
7924 * of a transition that has not yet been started.
7925 */
7926 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007927 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007928 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007929 return false;
7930 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007931 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007932 final boolean animating = atoken != null
7933 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007934 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007935 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7936 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007937 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007938 }
7939
7940 /** Is the window or its container currently animating? */
7941 boolean isAnimating() {
7942 final WindowState attached = mAttachedWindow;
7943 final AppWindowToken atoken = mAppToken;
7944 return mAnimation != null
7945 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007946 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007947 (atoken.animation != null
7948 || atoken.inPendingTransaction));
7949 }
7950
7951 /** Is this window currently animating? */
7952 boolean isWindowAnimating() {
7953 return mAnimation != null;
7954 }
7955
7956 /**
7957 * Like isOnScreen, but returns false if the surface hasn't yet
7958 * been drawn.
7959 */
7960 public boolean isDisplayedLw() {
7961 final AppWindowToken atoken = mAppToken;
7962 return mSurface != null && mPolicyVisibility && !mDestroying
7963 && !mDrawPending && !mCommitDrawPending
7964 && ((!mAttachedHidden &&
7965 (atoken == null || !atoken.hiddenRequested))
7966 || mAnimating);
7967 }
7968
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007969 /**
7970 * Returns true if the window has a surface that it has drawn a
7971 * complete UI in to.
7972 */
7973 public boolean isDrawnLw() {
7974 final AppWindowToken atoken = mAppToken;
7975 return mSurface != null && !mDestroying
7976 && !mDrawPending && !mCommitDrawPending;
7977 }
7978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007979 public boolean fillsScreenLw(int screenWidth, int screenHeight,
7980 boolean shownFrame, boolean onlyOpaque) {
7981 if (mSurface == null) {
7982 return false;
7983 }
7984 if (mAppToken != null && !mAppToken.appFullscreen) {
7985 return false;
7986 }
7987 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
7988 return false;
7989 }
7990 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007991
7992 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
7993 return frame.left <= mCompatibleScreenFrame.left &&
7994 frame.top <= mCompatibleScreenFrame.top &&
7995 frame.right >= mCompatibleScreenFrame.right &&
7996 frame.bottom >= mCompatibleScreenFrame.bottom;
7997 } else {
7998 return frame.left <= 0 && frame.top <= 0
7999 && frame.right >= screenWidth
8000 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008001 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008002 }
Romain Guy06882f82009-06-10 13:36:04 -07008003
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008004 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07008005 * Return true if the window is opaque and fully drawn. This indicates
8006 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008007 */
8008 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07008009 return (mAttrs.format == PixelFormat.OPAQUE
8010 || mAttrs.type == TYPE_WALLPAPER)
8011 && mSurface != null && mAnimation == null
8012 && (mAppToken == null || mAppToken.animation == null)
8013 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008014 }
8015
8016 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
8017 return
8018 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008019 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
8020 // only if it's visible
8021 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008022 // and only if the application fills the compatible screen
8023 mFrame.left <= mCompatibleScreenFrame.left &&
8024 mFrame.top <= mCompatibleScreenFrame.top &&
8025 mFrame.right >= mCompatibleScreenFrame.right &&
8026 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008027 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008028 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008029 }
8030
8031 boolean isFullscreen(int screenWidth, int screenHeight) {
8032 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008033 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008034 }
8035
8036 void removeLocked() {
8037 if (mAttachedWindow != null) {
8038 mAttachedWindow.mChildWindows.remove(this);
8039 }
8040 destroySurfaceLocked();
8041 mSession.windowRemovedLocked();
8042 try {
8043 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
8044 } catch (RuntimeException e) {
8045 // Ignore if it has already been removed (usually because
8046 // we are doing this as part of processing a death note.)
8047 }
8048 }
8049
8050 private class DeathRecipient implements IBinder.DeathRecipient {
8051 public void binderDied() {
8052 try {
8053 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008054 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008055 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008056 if (win != null) {
8057 removeWindowLocked(mSession, win);
8058 }
8059 }
8060 } catch (IllegalArgumentException ex) {
8061 // This will happen if the window has already been
8062 // removed.
8063 }
8064 }
8065 }
8066
8067 /** Returns true if this window desires key events. */
8068 public final boolean canReceiveKeys() {
8069 return isVisibleOrAdding()
8070 && (mViewVisibility == View.VISIBLE)
8071 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8072 }
8073
8074 public boolean hasDrawnLw() {
8075 return mHasDrawn;
8076 }
8077
8078 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008079 return showLw(doAnimation, true);
8080 }
8081
8082 boolean showLw(boolean doAnimation, boolean requestAnim) {
8083 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8084 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008085 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008086 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008087 if (doAnimation) {
8088 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8089 + mPolicyVisibility + " mAnimation=" + mAnimation);
8090 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8091 doAnimation = false;
8092 } else if (mPolicyVisibility && mAnimation == null) {
8093 // Check for the case where we are currently visible and
8094 // not animating; we do not want to do animation at such a
8095 // point to become visible when we already are.
8096 doAnimation = false;
8097 }
8098 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008099 mPolicyVisibility = true;
8100 mPolicyVisibilityAfterAnim = true;
8101 if (doAnimation) {
8102 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8103 }
8104 if (requestAnim) {
8105 requestAnimationLocked(0);
8106 }
8107 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008108 }
8109
8110 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008111 return hideLw(doAnimation, true);
8112 }
8113
8114 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008115 if (doAnimation) {
8116 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8117 doAnimation = false;
8118 }
8119 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008120 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8121 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008122 if (!current) {
8123 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008124 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008125 if (doAnimation) {
8126 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8127 if (mAnimation == null) {
8128 doAnimation = false;
8129 }
8130 }
8131 if (doAnimation) {
8132 mPolicyVisibilityAfterAnim = false;
8133 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008134 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008135 mPolicyVisibilityAfterAnim = false;
8136 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008137 // Window is no longer visible -- make sure if we were waiting
8138 // for it to be displayed before enabling the display, that
8139 // we allow the display to be enabled now.
8140 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008141 if (mCurrentFocus == this) {
8142 mFocusMayChange = true;
8143 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008144 }
8145 if (requestAnim) {
8146 requestAnimationLocked(0);
8147 }
8148 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008149 }
8150
8151 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008152 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8153 pw.print(" mClient="); pw.println(mClient.asBinder());
8154 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8155 if (mAttachedWindow != null || mLayoutAttached) {
8156 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8157 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8158 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008159 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8160 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8161 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008162 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8163 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008164 }
8165 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8166 pw.print(" mSubLayer="); pw.print(mSubLayer);
8167 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8168 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8169 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8170 pw.print("="); pw.print(mAnimLayer);
8171 pw.print(" mLastLayer="); pw.println(mLastLayer);
8172 if (mSurface != null) {
8173 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
8174 }
8175 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8176 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8177 if (mAppToken != null) {
8178 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8179 }
8180 if (mTargetAppToken != null) {
8181 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8182 }
8183 pw.print(prefix); pw.print("mViewVisibility=0x");
8184 pw.print(Integer.toHexString(mViewVisibility));
8185 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008186 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8187 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008188 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8189 pw.print(prefix); pw.print("mPolicyVisibility=");
8190 pw.print(mPolicyVisibility);
8191 pw.print(" mPolicyVisibilityAfterAnim=");
8192 pw.print(mPolicyVisibilityAfterAnim);
8193 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8194 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008195 if (!mRelayoutCalled) {
8196 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8197 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008198 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008199 pw.print(" h="); pw.print(mRequestedHeight);
8200 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008201 if (mXOffset != 0 || mYOffset != 0) {
8202 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8203 pw.print(" y="); pw.println(mYOffset);
8204 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008205 pw.print(prefix); pw.print("mGivenContentInsets=");
8206 mGivenContentInsets.printShortString(pw);
8207 pw.print(" mGivenVisibleInsets=");
8208 mGivenVisibleInsets.printShortString(pw);
8209 pw.println();
8210 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8211 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8212 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8213 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008214 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008215 pw.print(prefix); pw.print("mShownFrame=");
8216 mShownFrame.printShortString(pw);
8217 pw.print(" last="); mLastShownFrame.printShortString(pw);
8218 pw.println();
8219 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8220 pw.print(" last="); mLastFrame.printShortString(pw);
8221 pw.println();
8222 pw.print(prefix); pw.print("mContainingFrame=");
8223 mContainingFrame.printShortString(pw);
8224 pw.print(" mDisplayFrame=");
8225 mDisplayFrame.printShortString(pw);
8226 pw.println();
8227 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8228 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8229 pw.println();
8230 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8231 pw.print(" last="); mLastContentInsets.printShortString(pw);
8232 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8233 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8234 pw.println();
8235 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8236 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8237 pw.print(" mAlpha="); pw.print(mAlpha);
8238 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8239 }
8240 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8241 || mAnimation != null) {
8242 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8243 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8244 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8245 pw.print(" mAnimation="); pw.println(mAnimation);
8246 }
8247 if (mHasTransformation || mHasLocalTransformation) {
8248 pw.print(prefix); pw.print("XForm: has=");
8249 pw.print(mHasTransformation);
8250 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8251 pw.print(" "); mTransformation.printShortString(pw);
8252 pw.println();
8253 }
8254 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8255 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8256 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8257 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8258 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8259 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8260 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8261 pw.print(" mDestroying="); pw.print(mDestroying);
8262 pw.print(" mRemoved="); pw.println(mRemoved);
8263 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008264 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008265 pw.print(prefix); pw.print("mOrientationChanging=");
8266 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008267 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8268 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008269 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008270 if (mHScale != 1 || mVScale != 1) {
8271 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8272 pw.print(" mVScale="); pw.println(mVScale);
8273 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008274 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008275 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8276 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8277 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008278 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8279 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8280 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8281 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008282 }
8283
8284 @Override
8285 public String toString() {
8286 return "Window{"
8287 + Integer.toHexString(System.identityHashCode(this))
8288 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
8289 }
8290 }
Romain Guy06882f82009-06-10 13:36:04 -07008291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008292 // -------------------------------------------------------------
8293 // Window Token State
8294 // -------------------------------------------------------------
8295
8296 class WindowToken {
8297 // The actual token.
8298 final IBinder token;
8299
8300 // The type of window this token is for, as per WindowManager.LayoutParams.
8301 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008303 // Set if this token was explicitly added by a client, so should
8304 // not be removed when all windows are removed.
8305 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008306
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008307 // For printing.
8308 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008310 // If this is an AppWindowToken, this is non-null.
8311 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008313 // All of the windows associated with this token.
8314 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8315
8316 // Is key dispatching paused for this token?
8317 boolean paused = false;
8318
8319 // Should this token's windows be hidden?
8320 boolean hidden;
8321
8322 // Temporary for finding which tokens no longer have visible windows.
8323 boolean hasVisible;
8324
Dianne Hackborna8f60182009-09-01 19:01:50 -07008325 // Set to true when this token is in a pending transaction where it
8326 // will be shown.
8327 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008328
Dianne Hackborna8f60182009-09-01 19:01:50 -07008329 // Set to true when this token is in a pending transaction where it
8330 // will be hidden.
8331 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008332
Dianne Hackborna8f60182009-09-01 19:01:50 -07008333 // Set to true when this token is in a pending transaction where its
8334 // windows will be put to the bottom of the list.
8335 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008336
Dianne Hackborna8f60182009-09-01 19:01:50 -07008337 // Set to true when this token is in a pending transaction where its
8338 // windows will be put to the top of the list.
8339 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008341 WindowToken(IBinder _token, int type, boolean _explicit) {
8342 token = _token;
8343 windowType = type;
8344 explicit = _explicit;
8345 }
8346
8347 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008348 pw.print(prefix); pw.print("token="); pw.println(token);
8349 pw.print(prefix); pw.print("windows="); pw.println(windows);
8350 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8351 pw.print(" hidden="); pw.print(hidden);
8352 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008353 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8354 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8355 pw.print(" waitingToHide="); pw.print(waitingToHide);
8356 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8357 pw.print(" sendingToTop="); pw.println(sendingToTop);
8358 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008359 }
8360
8361 @Override
8362 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008363 if (stringName == null) {
8364 StringBuilder sb = new StringBuilder();
8365 sb.append("WindowToken{");
8366 sb.append(Integer.toHexString(System.identityHashCode(this)));
8367 sb.append(" token="); sb.append(token); sb.append('}');
8368 stringName = sb.toString();
8369 }
8370 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008371 }
8372 };
8373
8374 class AppWindowToken extends WindowToken {
8375 // Non-null only for application tokens.
8376 final IApplicationToken appToken;
8377
8378 // All of the windows and child windows that are included in this
8379 // application token. Note this list is NOT sorted!
8380 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8381
8382 int groupId = -1;
8383 boolean appFullscreen;
8384 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Romain Guy06882f82009-06-10 13:36:04 -07008385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008386 // These are used for determining when all windows associated with
8387 // an activity have been drawn, so they can be made visible together
8388 // at the same time.
8389 int lastTransactionSequence = mTransactionSequence-1;
8390 int numInterestingWindows;
8391 int numDrawnWindows;
8392 boolean inPendingTransaction;
8393 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008395 // Is this token going to be hidden in a little while? If so, it
8396 // won't be taken into account for setting the screen orientation.
8397 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008399 // Is this window's surface needed? This is almost like hidden, except
8400 // it will sometimes be true a little earlier: when the token has
8401 // been shown, but is still waiting for its app transition to execute
8402 // before making its windows shown.
8403 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008405 // Have we told the window clients to hide themselves?
8406 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008407
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008408 // Last visibility state we reported to the app token.
8409 boolean reportedVisible;
8410
8411 // Set to true when the token has been removed from the window mgr.
8412 boolean removed;
8413
8414 // Have we been asked to have this token keep the screen frozen?
8415 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008417 boolean animating;
8418 Animation animation;
8419 boolean hasTransformation;
8420 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008422 // Offset to the window of all layers in the token, for use by
8423 // AppWindowToken animations.
8424 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008426 // Information about an application starting window if displayed.
8427 StartingData startingData;
8428 WindowState startingWindow;
8429 View startingView;
8430 boolean startingDisplayed;
8431 boolean startingMoved;
8432 boolean firstWindowDrawn;
8433
8434 AppWindowToken(IApplicationToken _token) {
8435 super(_token.asBinder(),
8436 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8437 appWindowToken = this;
8438 appToken = _token;
8439 }
Romain Guy06882f82009-06-10 13:36:04 -07008440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008441 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008442 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008443 TAG, "Setting animation in " + this + ": " + anim);
8444 animation = anim;
8445 animating = false;
8446 anim.restrictDuration(MAX_ANIMATION_DURATION);
8447 anim.scaleCurrentDuration(mTransitionAnimationScale);
8448 int zorder = anim.getZAdjustment();
8449 int adj = 0;
8450 if (zorder == Animation.ZORDER_TOP) {
8451 adj = TYPE_LAYER_OFFSET;
8452 } else if (zorder == Animation.ZORDER_BOTTOM) {
8453 adj = -TYPE_LAYER_OFFSET;
8454 }
Romain Guy06882f82009-06-10 13:36:04 -07008455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008456 if (animLayerAdjustment != adj) {
8457 animLayerAdjustment = adj;
8458 updateLayers();
8459 }
8460 }
Romain Guy06882f82009-06-10 13:36:04 -07008461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008462 public void setDummyAnimation() {
8463 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008464 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008465 TAG, "Setting dummy animation in " + this);
8466 animation = sDummyAnimation;
8467 }
8468 }
8469
8470 public void clearAnimation() {
8471 if (animation != null) {
8472 animation = null;
8473 animating = true;
8474 }
8475 }
Romain Guy06882f82009-06-10 13:36:04 -07008476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008477 void updateLayers() {
8478 final int N = allAppWindows.size();
8479 final int adj = animLayerAdjustment;
8480 for (int i=0; i<N; i++) {
8481 WindowState w = allAppWindows.get(i);
8482 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008483 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008484 + w.mAnimLayer);
8485 if (w == mInputMethodTarget) {
8486 setInputMethodAnimLayerAdjustment(adj);
8487 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008488 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008489 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008490 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008491 }
8492 }
Romain Guy06882f82009-06-10 13:36:04 -07008493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008494 void sendAppVisibilityToClients() {
8495 final int N = allAppWindows.size();
8496 for (int i=0; i<N; i++) {
8497 WindowState win = allAppWindows.get(i);
8498 if (win == startingWindow && clientHidden) {
8499 // Don't hide the starting window.
8500 continue;
8501 }
8502 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008503 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008504 "Setting visibility of " + win + ": " + (!clientHidden));
8505 win.mClient.dispatchAppVisibility(!clientHidden);
8506 } catch (RemoteException e) {
8507 }
8508 }
8509 }
Romain Guy06882f82009-06-10 13:36:04 -07008510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008511 void showAllWindowsLocked() {
8512 final int NW = allAppWindows.size();
8513 for (int i=0; i<NW; i++) {
8514 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008515 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008516 "performing show on: " + w);
8517 w.performShowLocked();
8518 }
8519 }
Romain Guy06882f82009-06-10 13:36:04 -07008520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008521 // This must be called while inside a transaction.
8522 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008523 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008524 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008526 if (animation == sDummyAnimation) {
8527 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008528 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008529 // when it is really time to animate, this will be set to
8530 // a real animation and the next call will execute normally.
8531 return false;
8532 }
Romain Guy06882f82009-06-10 13:36:04 -07008533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008534 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8535 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008536 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008537 TAG, "Starting animation in " + this +
8538 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8539 + " scale=" + mTransitionAnimationScale
8540 + " allDrawn=" + allDrawn + " animating=" + animating);
8541 animation.initialize(dw, dh, dw, dh);
8542 animation.setStartTime(currentTime);
8543 animating = true;
8544 }
8545 transformation.clear();
8546 final boolean more = animation.getTransformation(
8547 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008548 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008549 TAG, "Stepped animation in " + this +
8550 ": more=" + more + ", xform=" + transformation);
8551 if (more) {
8552 // we're done!
8553 hasTransformation = true;
8554 return true;
8555 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008556 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008557 TAG, "Finished animation in " + this +
8558 " @ " + currentTime);
8559 animation = null;
8560 }
8561 } else if (animation != null) {
8562 // If the display is frozen, and there is a pending animation,
8563 // clear it and make sure we run the cleanup code.
8564 animating = true;
8565 animation = null;
8566 }
8567
8568 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008570 if (!animating) {
8571 return false;
8572 }
8573
8574 clearAnimation();
8575 animating = false;
8576 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8577 moveInputMethodWindowsIfNeededLocked(true);
8578 }
Romain Guy06882f82009-06-10 13:36:04 -07008579
Joe Onorato8a9b2202010-02-26 18:56:32 -08008580 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008581 TAG, "Animation done in " + this
8582 + ": reportedVisible=" + reportedVisible);
8583
8584 transformation.clear();
8585 if (animLayerAdjustment != 0) {
8586 animLayerAdjustment = 0;
8587 updateLayers();
8588 }
Romain Guy06882f82009-06-10 13:36:04 -07008589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008590 final int N = windows.size();
8591 for (int i=0; i<N; i++) {
8592 ((WindowState)windows.get(i)).finishExit();
8593 }
8594 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008596 return false;
8597 }
8598
8599 void updateReportedVisibilityLocked() {
8600 if (appToken == null) {
8601 return;
8602 }
Romain Guy06882f82009-06-10 13:36:04 -07008603
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008604 int numInteresting = 0;
8605 int numVisible = 0;
8606 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008607
Joe Onorato8a9b2202010-02-26 18:56:32 -08008608 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008609 final int N = allAppWindows.size();
8610 for (int i=0; i<N; i++) {
8611 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008612 if (win == startingWindow || win.mAppFreezing
8613 || win.mViewVisibility != View.VISIBLE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008614 continue;
8615 }
8616 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008617 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008618 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008619 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008620 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008621 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008622 + " pv=" + win.mPolicyVisibility
8623 + " dp=" + win.mDrawPending
8624 + " cdp=" + win.mCommitDrawPending
8625 + " ah=" + win.mAttachedHidden
8626 + " th="
8627 + (win.mAppToken != null
8628 ? win.mAppToken.hiddenRequested : false)
8629 + " a=" + win.mAnimating);
8630 }
8631 }
8632 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008633 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008634 if (!win.isAnimating()) {
8635 numVisible++;
8636 }
8637 nowGone = false;
8638 } else if (win.isAnimating()) {
8639 nowGone = false;
8640 }
8641 }
Romain Guy06882f82009-06-10 13:36:04 -07008642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008643 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008644 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008645 + numInteresting + " visible=" + numVisible);
8646 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008647 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008648 TAG, "Visibility changed in " + this
8649 + ": vis=" + nowVisible);
8650 reportedVisible = nowVisible;
8651 Message m = mH.obtainMessage(
8652 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8653 nowVisible ? 1 : 0,
8654 nowGone ? 1 : 0,
8655 this);
8656 mH.sendMessage(m);
8657 }
8658 }
Romain Guy06882f82009-06-10 13:36:04 -07008659
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008660 WindowState findMainWindow() {
8661 int j = windows.size();
8662 while (j > 0) {
8663 j--;
8664 WindowState win = windows.get(j);
8665 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8666 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8667 return win;
8668 }
8669 }
8670 return null;
8671 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008673 void dump(PrintWriter pw, String prefix) {
8674 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008675 if (appToken != null) {
8676 pw.print(prefix); pw.println("app=true");
8677 }
8678 if (allAppWindows.size() > 0) {
8679 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8680 }
8681 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008682 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008683 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8684 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8685 pw.print(" clientHidden="); pw.print(clientHidden);
8686 pw.print(" willBeHidden="); pw.print(willBeHidden);
8687 pw.print(" reportedVisible="); pw.println(reportedVisible);
8688 if (paused || freezingScreen) {
8689 pw.print(prefix); pw.print("paused="); pw.print(paused);
8690 pw.print(" freezingScreen="); pw.println(freezingScreen);
8691 }
8692 if (numInterestingWindows != 0 || numDrawnWindows != 0
8693 || inPendingTransaction || allDrawn) {
8694 pw.print(prefix); pw.print("numInterestingWindows=");
8695 pw.print(numInterestingWindows);
8696 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8697 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8698 pw.print(" allDrawn="); pw.println(allDrawn);
8699 }
8700 if (animating || animation != null) {
8701 pw.print(prefix); pw.print("animating="); pw.print(animating);
8702 pw.print(" animation="); pw.println(animation);
8703 }
8704 if (animLayerAdjustment != 0) {
8705 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8706 }
8707 if (hasTransformation) {
8708 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8709 pw.print(" transformation="); transformation.printShortString(pw);
8710 pw.println();
8711 }
8712 if (startingData != null || removed || firstWindowDrawn) {
8713 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8714 pw.print(" removed="); pw.print(removed);
8715 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8716 }
8717 if (startingWindow != null || startingView != null
8718 || startingDisplayed || startingMoved) {
8719 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8720 pw.print(" startingView="); pw.print(startingView);
8721 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8722 pw.print(" startingMoved"); pw.println(startingMoved);
8723 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008724 }
8725
8726 @Override
8727 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008728 if (stringName == null) {
8729 StringBuilder sb = new StringBuilder();
8730 sb.append("AppWindowToken{");
8731 sb.append(Integer.toHexString(System.identityHashCode(this)));
8732 sb.append(" token="); sb.append(token); sb.append('}');
8733 stringName = sb.toString();
8734 }
8735 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008736 }
8737 }
Romain Guy06882f82009-06-10 13:36:04 -07008738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008739 // -------------------------------------------------------------
8740 // DummyAnimation
8741 // -------------------------------------------------------------
8742
8743 // This is an animation that does nothing: it just immediately finishes
8744 // itself every time it is called. It is used as a stub animation in cases
8745 // where we want to synchronize multiple things that may be animating.
8746 static final class DummyAnimation extends Animation {
8747 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8748 return false;
8749 }
8750 }
8751 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008753 // -------------------------------------------------------------
8754 // Async Handler
8755 // -------------------------------------------------------------
8756
8757 static final class StartingData {
8758 final String pkg;
8759 final int theme;
8760 final CharSequence nonLocalizedLabel;
8761 final int labelRes;
8762 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008764 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8765 int _labelRes, int _icon) {
8766 pkg = _pkg;
8767 theme = _theme;
8768 nonLocalizedLabel = _nonLocalizedLabel;
8769 labelRes = _labelRes;
8770 icon = _icon;
8771 }
8772 }
8773
8774 private final class H extends Handler {
8775 public static final int REPORT_FOCUS_CHANGE = 2;
8776 public static final int REPORT_LOSING_FOCUS = 3;
8777 public static final int ANIMATE = 4;
8778 public static final int ADD_STARTING = 5;
8779 public static final int REMOVE_STARTING = 6;
8780 public static final int FINISHED_STARTING = 7;
8781 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008782 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8783 public static final int HOLD_SCREEN_CHANGED = 12;
8784 public static final int APP_TRANSITION_TIMEOUT = 13;
8785 public static final int PERSIST_ANIMATION_SCALE = 14;
8786 public static final int FORCE_GC = 15;
8787 public static final int ENABLE_SCREEN = 16;
8788 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008789 public static final int SEND_NEW_CONFIGURATION = 18;
Romain Guy06882f82009-06-10 13:36:04 -07008790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008791 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008793 public H() {
8794 }
Romain Guy06882f82009-06-10 13:36:04 -07008795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008796 @Override
8797 public void handleMessage(Message msg) {
8798 switch (msg.what) {
8799 case REPORT_FOCUS_CHANGE: {
8800 WindowState lastFocus;
8801 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008803 synchronized(mWindowMap) {
8804 lastFocus = mLastFocus;
8805 newFocus = mCurrentFocus;
8806 if (lastFocus == newFocus) {
8807 // Focus is not changing, so nothing to do.
8808 return;
8809 }
8810 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008811 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008812 // + " to " + newFocus);
8813 if (newFocus != null && lastFocus != null
8814 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008815 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008816 mLosingFocus.add(lastFocus);
8817 lastFocus = null;
8818 }
8819 }
8820
8821 if (lastFocus != newFocus) {
8822 //System.out.println("Changing focus from " + lastFocus
8823 // + " to " + newFocus);
8824 if (newFocus != null) {
8825 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008826 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008827 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8828 } catch (RemoteException e) {
8829 // Ignore if process has died.
8830 }
8831 }
8832
8833 if (lastFocus != null) {
8834 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008835 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008836 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8837 } catch (RemoteException e) {
8838 // Ignore if process has died.
8839 }
8840 }
8841 }
8842 } break;
8843
8844 case REPORT_LOSING_FOCUS: {
8845 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008846
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008847 synchronized(mWindowMap) {
8848 losers = mLosingFocus;
8849 mLosingFocus = new ArrayList<WindowState>();
8850 }
8851
8852 final int N = losers.size();
8853 for (int i=0; i<N; i++) {
8854 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008855 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008856 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8857 } catch (RemoteException e) {
8858 // Ignore if process has died.
8859 }
8860 }
8861 } break;
8862
8863 case ANIMATE: {
8864 synchronized(mWindowMap) {
8865 mAnimationPending = false;
8866 performLayoutAndPlaceSurfacesLocked();
8867 }
8868 } break;
8869
8870 case ADD_STARTING: {
8871 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8872 final StartingData sd = wtoken.startingData;
8873
8874 if (sd == null) {
8875 // Animation has been canceled... do nothing.
8876 return;
8877 }
Romain Guy06882f82009-06-10 13:36:04 -07008878
Joe Onorato8a9b2202010-02-26 18:56:32 -08008879 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008880 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008882 View view = null;
8883 try {
8884 view = mPolicy.addStartingWindow(
8885 wtoken.token, sd.pkg,
8886 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8887 sd.icon);
8888 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008889 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008890 }
8891
8892 if (view != null) {
8893 boolean abort = false;
8894
8895 synchronized(mWindowMap) {
8896 if (wtoken.removed || wtoken.startingData == null) {
8897 // If the window was successfully added, then
8898 // we need to remove it.
8899 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008900 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008901 "Aborted starting " + wtoken
8902 + ": removed=" + wtoken.removed
8903 + " startingData=" + wtoken.startingData);
8904 wtoken.startingWindow = null;
8905 wtoken.startingData = null;
8906 abort = true;
8907 }
8908 } else {
8909 wtoken.startingView = view;
8910 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008911 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008912 "Added starting " + wtoken
8913 + ": startingWindow="
8914 + wtoken.startingWindow + " startingView="
8915 + wtoken.startingView);
8916 }
8917
8918 if (abort) {
8919 try {
8920 mPolicy.removeStartingWindow(wtoken.token, view);
8921 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008922 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008923 }
8924 }
8925 }
8926 } break;
8927
8928 case REMOVE_STARTING: {
8929 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8930 IBinder token = null;
8931 View view = null;
8932 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008933 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008934 + wtoken + ": startingWindow="
8935 + wtoken.startingWindow + " startingView="
8936 + wtoken.startingView);
8937 if (wtoken.startingWindow != null) {
8938 view = wtoken.startingView;
8939 token = wtoken.token;
8940 wtoken.startingData = null;
8941 wtoken.startingView = null;
8942 wtoken.startingWindow = null;
8943 }
8944 }
8945 if (view != null) {
8946 try {
8947 mPolicy.removeStartingWindow(token, view);
8948 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008949 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008950 }
8951 }
8952 } break;
8953
8954 case FINISHED_STARTING: {
8955 IBinder token = null;
8956 View view = null;
8957 while (true) {
8958 synchronized (mWindowMap) {
8959 final int N = mFinishedStarting.size();
8960 if (N <= 0) {
8961 break;
8962 }
8963 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8964
Joe Onorato8a9b2202010-02-26 18:56:32 -08008965 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008966 "Finished starting " + wtoken
8967 + ": startingWindow=" + wtoken.startingWindow
8968 + " startingView=" + wtoken.startingView);
8969
8970 if (wtoken.startingWindow == null) {
8971 continue;
8972 }
8973
8974 view = wtoken.startingView;
8975 token = wtoken.token;
8976 wtoken.startingData = null;
8977 wtoken.startingView = null;
8978 wtoken.startingWindow = null;
8979 }
8980
8981 try {
8982 mPolicy.removeStartingWindow(token, view);
8983 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008984 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008985 }
8986 }
8987 } break;
8988
8989 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8990 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8991
8992 boolean nowVisible = msg.arg1 != 0;
8993 boolean nowGone = msg.arg2 != 0;
8994
8995 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008996 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008997 TAG, "Reporting visible in " + wtoken
8998 + " visible=" + nowVisible
8999 + " gone=" + nowGone);
9000 if (nowVisible) {
9001 wtoken.appToken.windowsVisible();
9002 } else {
9003 wtoken.appToken.windowsGone();
9004 }
9005 } catch (RemoteException ex) {
9006 }
9007 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009009 case WINDOW_FREEZE_TIMEOUT: {
9010 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009011 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009012 int i = mWindows.size();
9013 while (i > 0) {
9014 i--;
9015 WindowState w = (WindowState)mWindows.get(i);
9016 if (w.mOrientationChanging) {
9017 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009018 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009019 }
9020 }
9021 performLayoutAndPlaceSurfacesLocked();
9022 }
9023 break;
9024 }
Romain Guy06882f82009-06-10 13:36:04 -07009025
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009026 case HOLD_SCREEN_CHANGED: {
9027 Session oldHold;
9028 Session newHold;
9029 synchronized (mWindowMap) {
9030 oldHold = mLastReportedHold;
9031 newHold = (Session)msg.obj;
9032 mLastReportedHold = newHold;
9033 }
Romain Guy06882f82009-06-10 13:36:04 -07009034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009035 if (oldHold != newHold) {
9036 try {
9037 if (oldHold != null) {
9038 mBatteryStats.noteStopWakelock(oldHold.mUid,
9039 "window",
9040 BatteryStats.WAKE_TYPE_WINDOW);
9041 }
9042 if (newHold != null) {
9043 mBatteryStats.noteStartWakelock(newHold.mUid,
9044 "window",
9045 BatteryStats.WAKE_TYPE_WINDOW);
9046 }
9047 } catch (RemoteException e) {
9048 }
9049 }
9050 break;
9051 }
Romain Guy06882f82009-06-10 13:36:04 -07009052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009053 case APP_TRANSITION_TIMEOUT: {
9054 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009055 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009056 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009057 "*** APP TRANSITION TIMEOUT");
9058 mAppTransitionReady = true;
9059 mAppTransitionTimeout = true;
9060 performLayoutAndPlaceSurfacesLocked();
9061 }
9062 }
9063 break;
9064 }
Romain Guy06882f82009-06-10 13:36:04 -07009065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009066 case PERSIST_ANIMATION_SCALE: {
9067 Settings.System.putFloat(mContext.getContentResolver(),
9068 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9069 Settings.System.putFloat(mContext.getContentResolver(),
9070 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9071 break;
9072 }
Romain Guy06882f82009-06-10 13:36:04 -07009073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009074 case FORCE_GC: {
9075 synchronized(mWindowMap) {
9076 if (mAnimationPending) {
9077 // If we are animating, don't do the gc now but
9078 // delay a bit so we don't interrupt the animation.
9079 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9080 2000);
9081 return;
9082 }
9083 // If we are currently rotating the display, it will
9084 // schedule a new message when done.
9085 if (mDisplayFrozen) {
9086 return;
9087 }
9088 mFreezeGcPending = 0;
9089 }
9090 Runtime.getRuntime().gc();
9091 break;
9092 }
Romain Guy06882f82009-06-10 13:36:04 -07009093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009094 case ENABLE_SCREEN: {
9095 performEnableScreen();
9096 break;
9097 }
Romain Guy06882f82009-06-10 13:36:04 -07009098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009099 case APP_FREEZE_TIMEOUT: {
9100 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009101 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009102 int i = mAppTokens.size();
9103 while (i > 0) {
9104 i--;
9105 AppWindowToken tok = mAppTokens.get(i);
9106 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009107 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009108 unsetAppFreezingScreenLocked(tok, true, true);
9109 }
9110 }
9111 }
9112 break;
9113 }
Romain Guy06882f82009-06-10 13:36:04 -07009114
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009115 case SEND_NEW_CONFIGURATION: {
9116 removeMessages(SEND_NEW_CONFIGURATION);
9117 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009118 break;
9119 }
Romain Guy06882f82009-06-10 13:36:04 -07009120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009121 }
9122 }
9123 }
9124
9125 // -------------------------------------------------------------
9126 // IWindowManager API
9127 // -------------------------------------------------------------
9128
9129 public IWindowSession openSession(IInputMethodClient client,
9130 IInputContext inputContext) {
9131 if (client == null) throw new IllegalArgumentException("null client");
9132 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
9133 return new Session(client, inputContext);
9134 }
9135
9136 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9137 synchronized (mWindowMap) {
9138 // The focus for the client is the window immediately below
9139 // where we would place the input method window.
9140 int idx = findDesiredInputMethodWindowIndexLocked(false);
9141 WindowState imFocus;
9142 if (idx > 0) {
9143 imFocus = (WindowState)mWindows.get(idx-1);
9144 if (imFocus != null) {
9145 if (imFocus.mSession.mClient != null &&
9146 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9147 return true;
9148 }
9149 }
9150 }
9151 }
9152 return false;
9153 }
Romain Guy06882f82009-06-10 13:36:04 -07009154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009155 // -------------------------------------------------------------
9156 // Internals
9157 // -------------------------------------------------------------
9158
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009159 final WindowState windowForClientLocked(Session session, IWindow client,
9160 boolean throwOnError) {
9161 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009162 }
Romain Guy06882f82009-06-10 13:36:04 -07009163
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009164 final WindowState windowForClientLocked(Session session, IBinder client,
9165 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009166 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009167 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009168 TAG, "Looking up client " + client + ": " + win);
9169 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009170 RuntimeException ex = new IllegalArgumentException(
9171 "Requested window " + client + " does not exist");
9172 if (throwOnError) {
9173 throw ex;
9174 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009175 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009176 return null;
9177 }
9178 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009179 RuntimeException ex = new IllegalArgumentException(
9180 "Requested window " + client + " is in session " +
9181 win.mSession + ", not " + session);
9182 if (throwOnError) {
9183 throw ex;
9184 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009185 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009186 return null;
9187 }
9188
9189 return win;
9190 }
9191
Dianne Hackborna8f60182009-09-01 19:01:50 -07009192 final void rebuildAppWindowListLocked() {
9193 int NW = mWindows.size();
9194 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009195 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009196 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009197
Dianne Hackborna8f60182009-09-01 19:01:50 -07009198 // First remove all existing app windows.
9199 i=0;
9200 while (i < NW) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009201 WindowState w = (WindowState)mWindows.get(i);
9202 if (w.mAppToken != null) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009203 WindowState win = (WindowState)mWindows.remove(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009204 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009205 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009206 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009207 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009208 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009209 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9210 && lastWallpaper == i-1) {
9211 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009212 }
9213 i++;
9214 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009215
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009216 // The wallpaper window(s) typically live at the bottom of the stack,
9217 // so skip them before adding app tokens.
9218 lastWallpaper++;
9219 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009220
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009221 // First add all of the exiting app tokens... these are no longer
9222 // in the main app list, but still have windows shown. We put them
9223 // in the back because now that the animation is over we no longer
9224 // will care about them.
9225 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009226 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009227 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9228 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009229
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009230 // And add in the still active app tokens in Z order.
9231 NT = mAppTokens.size();
9232 for (int j=0; j<NT; j++) {
9233 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009234 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009235
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009236 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009237 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009238 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009239 + " windows but added " + i);
9240 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009241 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009243 private final void assignLayersLocked() {
9244 int N = mWindows.size();
9245 int curBaseLayer = 0;
9246 int curLayer = 0;
9247 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009249 for (i=0; i<N; i++) {
9250 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009251 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9252 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009253 curLayer += WINDOW_LAYER_MULTIPLIER;
9254 w.mLayer = curLayer;
9255 } else {
9256 curBaseLayer = curLayer = w.mBaseLayer;
9257 w.mLayer = curLayer;
9258 }
9259 if (w.mTargetAppToken != null) {
9260 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9261 } else if (w.mAppToken != null) {
9262 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9263 } else {
9264 w.mAnimLayer = w.mLayer;
9265 }
9266 if (w.mIsImWindow) {
9267 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009268 } else if (w.mIsWallpaper) {
9269 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009270 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009271 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009272 + w.mAnimLayer);
9273 //System.out.println(
9274 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9275 }
9276 }
9277
9278 private boolean mInLayout = false;
9279 private final void performLayoutAndPlaceSurfacesLocked() {
9280 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009281 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009282 throw new RuntimeException("Recursive call!");
9283 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009284 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009285 return;
9286 }
9287
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009288 if (mWaitingForConfig) {
9289 // Our configuration has changed (most likely rotation), but we
9290 // don't yet have the complete configuration to report to
9291 // applications. Don't do any window layout until we have it.
9292 return;
9293 }
9294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009295 boolean recoveringMemory = false;
9296 if (mForceRemoves != null) {
9297 recoveringMemory = true;
9298 // Wait a little it for things to settle down, and off we go.
9299 for (int i=0; i<mForceRemoves.size(); i++) {
9300 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009301 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009302 removeWindowInnerLocked(ws.mSession, ws);
9303 }
9304 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009305 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009306 Object tmp = new Object();
9307 synchronized (tmp) {
9308 try {
9309 tmp.wait(250);
9310 } catch (InterruptedException e) {
9311 }
9312 }
9313 }
Romain Guy06882f82009-06-10 13:36:04 -07009314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009315 mInLayout = true;
9316 try {
9317 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009319 int i = mPendingRemove.size()-1;
9320 if (i >= 0) {
9321 while (i >= 0) {
9322 WindowState w = mPendingRemove.get(i);
9323 removeWindowInnerLocked(w.mSession, w);
9324 i--;
9325 }
9326 mPendingRemove.clear();
9327
9328 mInLayout = false;
9329 assignLayersLocked();
9330 mLayoutNeeded = true;
9331 performLayoutAndPlaceSurfacesLocked();
9332
9333 } else {
9334 mInLayout = false;
9335 if (mLayoutNeeded) {
9336 requestAnimationLocked(0);
9337 }
9338 }
9339 } catch (RuntimeException e) {
9340 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009341 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009342 }
9343 }
9344
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009345 private final int performLayoutLockedInner() {
9346 if (!mLayoutNeeded) {
9347 return 0;
9348 }
9349
9350 mLayoutNeeded = false;
9351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009352 final int dw = mDisplay.getWidth();
9353 final int dh = mDisplay.getHeight();
9354
9355 final int N = mWindows.size();
9356 int i;
9357
Joe Onorato8a9b2202010-02-26 18:56:32 -08009358 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009359 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9360
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009361 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009362
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009363 int seq = mLayoutSeq+1;
9364 if (seq < 0) seq = 0;
9365 mLayoutSeq = seq;
9366
9367 // First perform layout of any root windows (not attached
9368 // to another window).
9369 int topAttached = -1;
9370 for (i = N-1; i >= 0; i--) {
9371 WindowState win = (WindowState) mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009372
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009373 // Don't do layout of a window if it is not visible, or
9374 // soon won't be visible, to avoid wasting time and funky
9375 // changes while a window is animating away.
9376 final AppWindowToken atoken = win.mAppToken;
9377 final boolean gone = win.mViewVisibility == View.GONE
9378 || !win.mRelayoutCalled
9379 || win.mRootToken.hidden
9380 || (atoken != null && atoken.hiddenRequested)
9381 || win.mAttachedHidden
9382 || win.mExiting || win.mDestroying;
9383
9384 if (!win.mLayoutAttached) {
9385 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
9386 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9387 + " mLayoutAttached=" + win.mLayoutAttached);
9388 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
9389 + win.mViewVisibility + " mRelayoutCalled="
9390 + win.mRelayoutCalled + " hidden="
9391 + win.mRootToken.hidden + " hiddenRequested="
9392 + (atoken != null && atoken.hiddenRequested)
9393 + " mAttachedHidden=" + win.mAttachedHidden);
9394 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009395
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009396 // If this view is GONE, then skip it -- keep the current
9397 // frame, and let the caller know so they can ignore it
9398 // if they want. (We do the normal layout for INVISIBLE
9399 // windows, since that means "perform layout as normal,
9400 // just don't display").
9401 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009402 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009403 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9404 win.mLayoutSeq = seq;
9405 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9406 + win.mFrame + " mContainingFrame="
9407 + win.mContainingFrame + " mDisplayFrame="
9408 + win.mDisplayFrame);
9409 } else {
9410 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009411 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009412 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009413 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009414
9415 // Now perform layout of attached windows, which usually
9416 // depend on the position of the window they are attached to.
9417 // XXX does not deal with windows that are attached to windows
9418 // that are themselves attached.
9419 for (i = topAttached; i >= 0; i--) {
9420 WindowState win = (WindowState) mWindows.get(i);
9421
9422 // If this view is GONE, then skip it -- keep the current
9423 // frame, and let the caller know so they can ignore it
9424 // if they want. (We do the normal layout for INVISIBLE
9425 // windows, since that means "perform layout as normal,
9426 // just don't display").
9427 if (win.mLayoutAttached) {
9428 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9429 + " mHaveFrame=" + win.mHaveFrame
9430 + " mViewVisibility=" + win.mViewVisibility
9431 + " mRelayoutCalled=" + win.mRelayoutCalled);
9432 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9433 || !win.mHaveFrame) {
9434 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9435 win.mLayoutSeq = seq;
9436 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9437 + win.mFrame + " mContainingFrame="
9438 + win.mContainingFrame + " mDisplayFrame="
9439 + win.mDisplayFrame);
9440 }
9441 }
9442 }
9443
9444 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009445 }
Romain Guy06882f82009-06-10 13:36:04 -07009446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009447 private final void performLayoutAndPlaceSurfacesLockedInner(
9448 boolean recoveringMemory) {
9449 final long currentTime = SystemClock.uptimeMillis();
9450 final int dw = mDisplay.getWidth();
9451 final int dh = mDisplay.getHeight();
9452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009453 int i;
9454
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009455 if (mFocusMayChange) {
9456 mFocusMayChange = false;
9457 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9458 }
9459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009460 if (mFxSession == null) {
9461 mFxSession = new SurfaceSession();
9462 }
Romain Guy06882f82009-06-10 13:36:04 -07009463
Joe Onorato8a9b2202010-02-26 18:56:32 -08009464 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009465
9466 // Initialize state of exiting tokens.
9467 for (i=mExitingTokens.size()-1; i>=0; i--) {
9468 mExitingTokens.get(i).hasVisible = false;
9469 }
9470
9471 // Initialize state of exiting applications.
9472 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9473 mExitingAppTokens.get(i).hasVisible = false;
9474 }
9475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009476 boolean orientationChangeComplete = true;
9477 Session holdScreen = null;
9478 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009479 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009480 boolean focusDisplayed = false;
9481 boolean animating = false;
9482
9483 Surface.openTransaction();
9484 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009485 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009486 int repeats = 0;
9487 int changes = 0;
9488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009489 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009490 repeats++;
9491 if (repeats > 6) {
9492 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9493 mLayoutNeeded = false;
9494 break;
9495 }
9496
9497 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9498 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9499 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9500 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9501 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9502 assignLayersLocked();
9503 mLayoutNeeded = true;
9504 }
9505 }
9506 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9507 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9508 if (updateOrientationFromAppTokensLocked()) {
9509 mLayoutNeeded = true;
9510 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9511 }
9512 }
9513 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9514 mLayoutNeeded = true;
9515 }
9516 }
9517
9518 // FIRST LOOP: Perform a layout, if needed.
9519 if (repeats < 4) {
9520 changes = performLayoutLockedInner();
9521 if (changes != 0) {
9522 continue;
9523 }
9524 } else {
9525 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9526 changes = 0;
9527 }
9528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009529 final int transactionSequence = ++mTransactionSequence;
9530
9531 // Update animations of all applications, including those
9532 // associated with exiting/removed apps
9533 boolean tokensAnimating = false;
9534 final int NAT = mAppTokens.size();
9535 for (i=0; i<NAT; i++) {
9536 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9537 tokensAnimating = true;
9538 }
9539 }
9540 final int NEAT = mExitingAppTokens.size();
9541 for (i=0; i<NEAT; i++) {
9542 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9543 tokensAnimating = true;
9544 }
9545 }
9546
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009547 // SECOND LOOP: Execute animations and update visibility of windows.
9548
Joe Onorato8a9b2202010-02-26 18:56:32 -08009549 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009550 + transactionSequence + " tokensAnimating="
9551 + tokensAnimating);
9552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009553 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009554
9555 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009556 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009557 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009558
9559 mPolicy.beginAnimationLw(dw, dh);
9560
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009561 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009563 for (i=N-1; i>=0; i--) {
9564 WindowState w = (WindowState)mWindows.get(i);
9565
9566 final WindowManager.LayoutParams attrs = w.mAttrs;
9567
9568 if (w.mSurface != null) {
9569 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009570 if (w.commitFinishDrawingLocked(currentTime)) {
9571 if ((w.mAttrs.flags
9572 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009573 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009574 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009575 wallpaperMayChange = true;
9576 }
9577 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009578
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009579 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009580 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9581 animating = true;
9582 //w.dump(" ");
9583 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009584 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9585 wallpaperMayChange = true;
9586 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009587
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009588 if (mPolicy.doesForceHide(w, attrs)) {
9589 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009590 if (DEBUG_VISIBILITY) Slog.v(TAG,
9591 "Animation done that could impact force hide: "
9592 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009593 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009594 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009595 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9596 forceHiding = true;
9597 }
9598 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9599 boolean changed;
9600 if (forceHiding) {
9601 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009602 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9603 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009604 } else {
9605 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009606 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9607 "Now policy shown: " + w);
9608 if (changed) {
9609 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009610 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009611 // Assume we will need to animate. If
9612 // we don't (because the wallpaper will
9613 // stay with the lock screen), then we will
9614 // clean up later.
9615 Animation a = mPolicy.createForceHideEnterAnimation();
9616 if (a != null) {
9617 w.setAnimation(a);
9618 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009619 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009620 if (mCurrentFocus == null ||
9621 mCurrentFocus.mLayer < w.mLayer) {
9622 // We are showing on to of the current
9623 // focus, so re-evaluate focus to make
9624 // sure it is correct.
9625 mFocusMayChange = true;
9626 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009627 }
9628 }
9629 if (changed && (attrs.flags
9630 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9631 wallpaperMayChange = true;
9632 }
9633 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009635 mPolicy.animatingWindowLw(w, attrs);
9636 }
9637
9638 final AppWindowToken atoken = w.mAppToken;
9639 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9640 if (atoken.lastTransactionSequence != transactionSequence) {
9641 atoken.lastTransactionSequence = transactionSequence;
9642 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9643 atoken.startingDisplayed = false;
9644 }
9645 if ((w.isOnScreen() || w.mAttrs.type
9646 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9647 && !w.mExiting && !w.mDestroying) {
9648 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009649 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009650 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009651 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009652 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009653 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009654 + " pv=" + w.mPolicyVisibility
9655 + " dp=" + w.mDrawPending
9656 + " cdp=" + w.mCommitDrawPending
9657 + " ah=" + w.mAttachedHidden
9658 + " th=" + atoken.hiddenRequested
9659 + " a=" + w.mAnimating);
9660 }
9661 }
9662 if (w != atoken.startingWindow) {
9663 if (!atoken.freezingScreen || !w.mAppFreezing) {
9664 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009665 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009666 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009667 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009668 "tokenMayBeDrawn: " + atoken
9669 + " freezingScreen=" + atoken.freezingScreen
9670 + " mAppFreezing=" + w.mAppFreezing);
9671 tokenMayBeDrawn = true;
9672 }
9673 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009674 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009675 atoken.startingDisplayed = true;
9676 }
9677 }
9678 } else if (w.mReadyToShow) {
9679 w.performShowLocked();
9680 }
9681 }
9682
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009683 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009684
9685 if (tokenMayBeDrawn) {
9686 // See if any windows have been drawn, so they (and others
9687 // associated with them) can now be shown.
9688 final int NT = mTokenList.size();
9689 for (i=0; i<NT; i++) {
9690 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9691 if (wtoken == null) {
9692 continue;
9693 }
9694 if (wtoken.freezingScreen) {
9695 int numInteresting = wtoken.numInterestingWindows;
9696 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009697 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009698 "allDrawn: " + wtoken
9699 + " interesting=" + numInteresting
9700 + " drawn=" + wtoken.numDrawnWindows);
9701 wtoken.showAllWindowsLocked();
9702 unsetAppFreezingScreenLocked(wtoken, false, true);
9703 orientationChangeComplete = true;
9704 }
9705 } else if (!wtoken.allDrawn) {
9706 int numInteresting = wtoken.numInterestingWindows;
9707 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009708 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009709 "allDrawn: " + wtoken
9710 + " interesting=" + numInteresting
9711 + " drawn=" + wtoken.numDrawnWindows);
9712 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009713 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009714
9715 // We can now show all of the drawn windows!
9716 if (!mOpeningApps.contains(wtoken)) {
9717 wtoken.showAllWindowsLocked();
9718 }
9719 }
9720 }
9721 }
9722 }
9723
9724 // If we are ready to perform an app transition, check through
9725 // all of the app tokens to be shown and see if they are ready
9726 // to go.
9727 if (mAppTransitionReady) {
9728 int NN = mOpeningApps.size();
9729 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009730 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009731 "Checking " + NN + " opening apps (frozen="
9732 + mDisplayFrozen + " timeout="
9733 + mAppTransitionTimeout + ")...");
9734 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9735 // If the display isn't frozen, wait to do anything until
9736 // all of the apps are ready. Otherwise just go because
9737 // we'll unfreeze the display when everyone is ready.
9738 for (i=0; i<NN && goodToGo; i++) {
9739 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009740 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009741 "Check opening app" + wtoken + ": allDrawn="
9742 + wtoken.allDrawn + " startingDisplayed="
9743 + wtoken.startingDisplayed);
9744 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9745 && !wtoken.startingMoved) {
9746 goodToGo = false;
9747 }
9748 }
9749 }
9750 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009751 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009752 int transit = mNextAppTransition;
9753 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009754 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009755 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009756 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009757 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009758 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009759 mAppTransitionTimeout = false;
9760 mStartingIconInTransition = false;
9761 mSkipAppTransitionAnimation = false;
9762
9763 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9764
Dianne Hackborna8f60182009-09-01 19:01:50 -07009765 // If there are applications waiting to come to the
9766 // top of the stack, now is the time to move their windows.
9767 // (Note that we don't do apps going to the bottom
9768 // here -- we want to keep their windows in the old
9769 // Z-order until the animation completes.)
9770 if (mToTopApps.size() > 0) {
9771 NN = mAppTokens.size();
9772 for (i=0; i<NN; i++) {
9773 AppWindowToken wtoken = mAppTokens.get(i);
9774 if (wtoken.sendingToTop) {
9775 wtoken.sendingToTop = false;
9776 moveAppWindowsLocked(wtoken, NN, false);
9777 }
9778 }
9779 mToTopApps.clear();
9780 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009781
Dianne Hackborn25994b42009-09-04 14:21:19 -07009782 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009783
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009784 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009785 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009786
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009787 // The top-most window will supply the layout params,
9788 // and we will determine it below.
9789 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009790 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009791 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009792
Joe Onorato8a9b2202010-02-26 18:56:32 -08009793 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009794 "New wallpaper target=" + mWallpaperTarget
9795 + ", lower target=" + mLowerWallpaperTarget
9796 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009797 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009798 // Do a first pass through the tokens for two
9799 // things:
9800 // (1) Determine if both the closing and opening
9801 // app token sets are wallpaper targets, in which
9802 // case special animations are needed
9803 // (since the wallpaper needs to stay static
9804 // behind them).
9805 // (2) Find the layout params of the top-most
9806 // application window in the tokens, which is
9807 // what will control the animation theme.
9808 final int NC = mClosingApps.size();
9809 NN = NC + mOpeningApps.size();
9810 for (i=0; i<NN; i++) {
9811 AppWindowToken wtoken;
9812 int mode;
9813 if (i < NC) {
9814 wtoken = mClosingApps.get(i);
9815 mode = 1;
9816 } else {
9817 wtoken = mOpeningApps.get(i-NC);
9818 mode = 2;
9819 }
9820 if (mLowerWallpaperTarget != null) {
9821 if (mLowerWallpaperTarget.mAppToken == wtoken
9822 || mUpperWallpaperTarget.mAppToken == wtoken) {
9823 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009824 }
9825 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009826 if (wtoken.appFullscreen) {
9827 WindowState ws = wtoken.findMainWindow();
9828 if (ws != null) {
9829 // If this is a compatibility mode
9830 // window, we will always use its anim.
9831 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9832 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009833 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009834 bestAnimLayer = Integer.MAX_VALUE;
9835 } else if (ws.mLayer > bestAnimLayer) {
9836 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009837 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009838 bestAnimLayer = ws.mLayer;
9839 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009840 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009841 }
9842 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009843
Dianne Hackborn25994b42009-09-04 14:21:19 -07009844 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009845 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009846 "Wallpaper animation!");
9847 switch (transit) {
9848 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9849 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9850 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9851 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9852 break;
9853 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9854 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9855 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9856 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9857 break;
9858 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009859 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009860 "New transit: " + transit);
9861 } else if (oldWallpaper != null) {
9862 // We are transitioning from an activity with
9863 // a wallpaper to one without.
9864 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009865 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009866 "New transit away from wallpaper: " + transit);
9867 } else if (mWallpaperTarget != null) {
9868 // We are transitioning from an activity without
9869 // a wallpaper to now showing the wallpaper
9870 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009871 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009872 "New transit into wallpaper: " + transit);
9873 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009874
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009875 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9876 mLastEnterAnimToken = animToken;
9877 mLastEnterAnimParams = animLp;
9878 } else if (mLastEnterAnimParams != null) {
9879 animLp = mLastEnterAnimParams;
9880 mLastEnterAnimToken = null;
9881 mLastEnterAnimParams = null;
9882 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009883
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009884 // If all closing windows are obscured, then there is
9885 // no need to do an animation. This is the case, for
9886 // example, when this transition is being done behind
9887 // the lock screen.
9888 if (!mPolicy.allowAppAnimationsLw()) {
9889 animLp = null;
9890 }
9891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009892 NN = mOpeningApps.size();
9893 for (i=0; i<NN; i++) {
9894 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009895 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009896 "Now opening app" + wtoken);
9897 wtoken.reportedVisible = false;
9898 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009899 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009900 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009901 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009902 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009903 wtoken.showAllWindowsLocked();
9904 }
9905 NN = mClosingApps.size();
9906 for (i=0; i<NN; i++) {
9907 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009908 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009909 "Now closing app" + wtoken);
9910 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009911 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009912 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009913 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009914 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009915 // Force the allDrawn flag, because we want to start
9916 // this guy's animations regardless of whether it's
9917 // gotten drawn.
9918 wtoken.allDrawn = true;
9919 }
9920
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009921 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009923 mOpeningApps.clear();
9924 mClosingApps.clear();
9925
9926 // This has changed the visibility of windows, so perform
9927 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009928 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009929 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009930 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9931 assignLayersLocked();
9932 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009933 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009934 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009935 }
9936 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009937
Dianne Hackborna8f60182009-09-01 19:01:50 -07009938 if (!animating && mAppTransitionRunning) {
9939 // We have finished the animation of an app transition. To do
9940 // this, we have delayed a lot of operations like showing and
9941 // hiding apps, moving apps in Z-order, etc. The app token list
9942 // reflects the correct Z-order, but the window list may now
9943 // be out of sync with it. So here we will just rebuild the
9944 // entire app window list. Fun!
9945 mAppTransitionRunning = false;
9946 // Clear information about apps that were moving.
9947 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009948
Dianne Hackborna8f60182009-09-01 19:01:50 -07009949 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009950 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009951 moveInputMethodWindowsIfNeededLocked(false);
9952 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009953 // Since the window list has been rebuilt, focus might
9954 // have to be recomputed since the actual order of windows
9955 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009956 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009957 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009958
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009959 int adjResult = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009960
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009961 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009962 // At this point, there was a window with a wallpaper that
9963 // was force hiding other windows behind it, but now it
9964 // is going away. This may be simple -- just animate
9965 // away the wallpaper and its window -- or it may be
9966 // hard -- the wallpaper now needs to be shown behind
9967 // something that was hidden.
9968 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009969 if (mLowerWallpaperTarget != null
9970 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009971 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009972 "wallpaperForceHiding changed with lower="
9973 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009974 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009975 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9976 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9977 if (mLowerWallpaperTarget.mAppToken.hidden) {
9978 // The lower target has become hidden before we
9979 // actually started the animation... let's completely
9980 // re-evaluate everything.
9981 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009982 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009983 }
9984 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009985 adjResult = adjustWallpaperWindowsLocked();
9986 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009987 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009988 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009989 + " NEW: " + mWallpaperTarget
9990 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009991 if (mLowerWallpaperTarget == null) {
9992 // Whoops, we don't need a special wallpaper animation.
9993 // Clear them out.
9994 forceHiding = false;
9995 for (i=N-1; i>=0; i--) {
9996 WindowState w = (WindowState)mWindows.get(i);
9997 if (w.mSurface != null) {
9998 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009999 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010000 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010001 forceHiding = true;
10002 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10003 if (!w.mAnimating) {
10004 // We set the animation above so it
10005 // is not yet running.
10006 w.clearAnimation();
10007 }
10008 }
10009 }
10010 }
10011 }
10012 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010013
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010014 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010015 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010016 "Wallpaper may change! Adjusting");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010017 adjResult = adjustWallpaperWindowsLocked();
10018 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010019
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010020 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010021 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010022 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010023 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010024 assignLayersLocked();
10025 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010026 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010027 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010028 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010029 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010030
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010031 if (mFocusMayChange) {
10032 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010033 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010034 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010035 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010036 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010037 }
10038
10039 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010040 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010041 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010042
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010043 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10044 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010045
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010046 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010047
10048 // THIRD LOOP: Update the surfaces of all windows.
10049
10050 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10051
10052 boolean obscured = false;
10053 boolean blurring = false;
10054 boolean dimming = false;
10055 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010056 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010057 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010058
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010059 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010060
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010061 for (i=N-1; i>=0; i--) {
10062 WindowState w = (WindowState)mWindows.get(i);
10063
10064 boolean displayed = false;
10065 final WindowManager.LayoutParams attrs = w.mAttrs;
10066 final int attrFlags = attrs.flags;
10067
10068 if (w.mSurface != null) {
10069 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010070 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010071 TAG, "Placing surface #" + i + " " + w.mSurface
10072 + ": new=" + w.mShownFrame + ", old="
10073 + w.mLastShownFrame);
10074
10075 boolean resize;
10076 int width, height;
10077 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
10078 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
10079 w.mLastRequestedHeight != w.mRequestedHeight;
10080 // for a scaled surface, we just want to use
10081 // the requested size.
10082 width = w.mRequestedWidth;
10083 height = w.mRequestedHeight;
10084 w.mLastRequestedWidth = width;
10085 w.mLastRequestedHeight = height;
10086 w.mLastShownFrame.set(w.mShownFrame);
10087 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010088 if (SHOW_TRANSACTIONS) logSurface(w,
10089 "POS " + w.mShownFrame.left
10090 + ", " + w.mShownFrame.top, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010091 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10092 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010093 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010094 if (!recoveringMemory) {
10095 reclaimSomeSurfaceMemoryLocked(w, "position");
10096 }
10097 }
10098 } else {
10099 resize = !w.mLastShownFrame.equals(w.mShownFrame);
10100 width = w.mShownFrame.width();
10101 height = w.mShownFrame.height();
10102 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010103 }
10104
10105 if (resize) {
10106 if (width < 1) width = 1;
10107 if (height < 1) height = 1;
10108 if (w.mSurface != null) {
10109 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010110 if (SHOW_TRANSACTIONS) logSurface(w,
10111 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010112 + w.mShownFrame.top + " SIZE "
10113 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010114 + w.mShownFrame.height(), null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010115 w.mSurface.setSize(width, height);
10116 w.mSurface.setPosition(w.mShownFrame.left,
10117 w.mShownFrame.top);
10118 } catch (RuntimeException e) {
10119 // If something goes wrong with the surface (such
10120 // as running out of memory), don't take down the
10121 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010122 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010123 + "size=(" + width + "x" + height
10124 + "), pos=(" + w.mShownFrame.left
10125 + "," + w.mShownFrame.top + ")", e);
10126 if (!recoveringMemory) {
10127 reclaimSomeSurfaceMemoryLocked(w, "size");
10128 }
10129 }
10130 }
10131 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010132 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010133 w.mContentInsetsChanged =
10134 !w.mLastContentInsets.equals(w.mContentInsets);
10135 w.mVisibleInsetsChanged =
10136 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010137 boolean configChanged =
10138 w.mConfiguration != mCurConfiguration
10139 && (w.mConfiguration == null
10140 || mCurConfiguration.diff(w.mConfiguration) != 0);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010141 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010142 + ": configChanged=" + configChanged
10143 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -070010144 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010145 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010146 || w.mVisibleInsetsChanged
10147 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010148 w.mLastFrame.set(w.mFrame);
10149 w.mLastContentInsets.set(w.mContentInsets);
10150 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010151 // If the screen is currently frozen, then keep
10152 // it frozen until this window draws at its new
10153 // orientation.
10154 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010155 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010156 "Resizing while display frozen: " + w);
10157 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010158 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010159 mWindowsFreezingScreen = true;
10160 // XXX should probably keep timeout from
10161 // when we first froze the display.
10162 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10163 mH.sendMessageDelayed(mH.obtainMessage(
10164 H.WINDOW_FREEZE_TIMEOUT), 2000);
10165 }
10166 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010167 // If the orientation is changing, then we need to
10168 // hold off on unfreezing the display until this
10169 // window has been redrawn; to do that, we need
10170 // to go through the process of getting informed
10171 // by the application when it has finished drawing.
10172 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010173 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010174 "Orientation start waiting for draw in "
10175 + w + ", surface " + w.mSurface);
10176 w.mDrawPending = true;
10177 w.mCommitDrawPending = false;
10178 w.mReadyToShow = false;
10179 if (w.mAppToken != null) {
10180 w.mAppToken.allDrawn = false;
10181 }
10182 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010183 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010184 "Resizing window " + w + " to " + w.mFrame);
10185 mResizingWindows.add(w);
10186 } else if (w.mOrientationChanging) {
10187 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010188 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010189 "Orientation not waiting for draw in "
10190 + w + ", surface " + w.mSurface);
10191 w.mOrientationChanging = false;
10192 }
10193 }
10194 }
10195
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010196 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010197 if (!w.mLastHidden) {
10198 //dump();
10199 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010200 if (SHOW_TRANSACTIONS) logSurface(w,
10201 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010202 if (w.mSurface != null) {
10203 try {
10204 w.mSurface.hide();
10205 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010206 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010207 }
10208 }
10209 mKeyWaiter.releasePendingPointerLocked(w.mSession);
10210 }
10211 // If we are waiting for this window to handle an
10212 // orientation change, well, it is hidden, so
10213 // doesn't really matter. Note that this does
10214 // introduce a potential glitch if the window
10215 // becomes unhidden before it has drawn for the
10216 // new orientation.
10217 if (w.mOrientationChanging) {
10218 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010219 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010220 "Orientation change skips hidden " + w);
10221 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010222 } else if (w.mLastLayer != w.mAnimLayer
10223 || w.mLastAlpha != w.mShownAlpha
10224 || w.mLastDsDx != w.mDsDx
10225 || w.mLastDtDx != w.mDtDx
10226 || w.mLastDsDy != w.mDsDy
10227 || w.mLastDtDy != w.mDtDy
10228 || w.mLastHScale != w.mHScale
10229 || w.mLastVScale != w.mVScale
10230 || w.mLastHidden) {
10231 displayed = true;
10232 w.mLastAlpha = w.mShownAlpha;
10233 w.mLastLayer = w.mAnimLayer;
10234 w.mLastDsDx = w.mDsDx;
10235 w.mLastDtDx = w.mDtDx;
10236 w.mLastDsDy = w.mDsDy;
10237 w.mLastDtDy = w.mDtDy;
10238 w.mLastHScale = w.mHScale;
10239 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010240 if (SHOW_TRANSACTIONS) logSurface(w,
10241 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010242 + " matrix=[" + (w.mDsDx*w.mHScale)
10243 + "," + (w.mDtDx*w.mVScale)
10244 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010245 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010246 if (w.mSurface != null) {
10247 try {
10248 w.mSurface.setAlpha(w.mShownAlpha);
10249 w.mSurface.setLayer(w.mAnimLayer);
10250 w.mSurface.setMatrix(
10251 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10252 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10253 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010254 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010255 if (!recoveringMemory) {
10256 reclaimSomeSurfaceMemoryLocked(w, "update");
10257 }
10258 }
10259 }
10260
10261 if (w.mLastHidden && !w.mDrawPending
10262 && !w.mCommitDrawPending
10263 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010264 if (SHOW_TRANSACTIONS) logSurface(w,
10265 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010266 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010267 + " during relayout");
10268 if (showSurfaceRobustlyLocked(w)) {
10269 w.mHasDrawn = true;
10270 w.mLastHidden = false;
10271 } else {
10272 w.mOrientationChanging = false;
10273 }
10274 }
10275 if (w.mSurface != null) {
10276 w.mToken.hasVisible = true;
10277 }
10278 } else {
10279 displayed = true;
10280 }
10281
10282 if (displayed) {
10283 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010284 if (attrs.width == LayoutParams.MATCH_PARENT
10285 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010286 covered = true;
10287 }
10288 }
10289 if (w.mOrientationChanging) {
10290 if (w.mDrawPending || w.mCommitDrawPending) {
10291 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010292 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010293 "Orientation continue waiting for draw in " + w);
10294 } else {
10295 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010296 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010297 "Orientation change complete in " + w);
10298 }
10299 }
10300 w.mToken.hasVisible = true;
10301 }
10302 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010303 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010304 "Orientation change skips hidden " + w);
10305 w.mOrientationChanging = false;
10306 }
10307
10308 final boolean canBeSeen = w.isDisplayedLw();
10309
10310 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10311 focusDisplayed = true;
10312 }
10313
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010314 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010316 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010317 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010318 if (w.mSurface != null) {
10319 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10320 holdScreen = w.mSession;
10321 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010322 if (!syswin && w.mAttrs.screenBrightness >= 0
10323 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010324 screenBrightness = w.mAttrs.screenBrightness;
10325 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010326 if (!syswin && w.mAttrs.buttonBrightness >= 0
10327 && buttonBrightness < 0) {
10328 buttonBrightness = w.mAttrs.buttonBrightness;
10329 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010330 if (canBeSeen
10331 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10332 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10333 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010334 syswin = true;
10335 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010336 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010337
Dianne Hackborn25994b42009-09-04 14:21:19 -070010338 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10339 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010340 // This window completely covers everything behind it,
10341 // so we want to leave all of them as unblurred (for
10342 // performance reasons).
10343 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010344 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010345 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010346 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010347 obscured = true;
10348 if (mBackgroundFillerSurface == null) {
10349 try {
10350 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010351 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010352 0, dw, dh,
10353 PixelFormat.OPAQUE,
10354 Surface.FX_SURFACE_NORMAL);
10355 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010356 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010357 }
10358 }
10359 try {
10360 mBackgroundFillerSurface.setPosition(0, 0);
10361 mBackgroundFillerSurface.setSize(dw, dh);
10362 // Using the same layer as Dim because they will never be shown at the
10363 // same time.
10364 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10365 mBackgroundFillerSurface.show();
10366 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010367 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010368 }
10369 backgroundFillerShown = true;
10370 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010371 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010372 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010373 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010374 + ": blurring=" + blurring
10375 + " obscured=" + obscured
10376 + " displayed=" + displayed);
10377 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10378 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010379 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010380 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010381 if (mDimAnimator == null) {
10382 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010383 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010384 mDimAnimator.show(dw, dh);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010385 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010386 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010387 }
10388 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10389 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010390 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010391 blurring = true;
10392 mBlurShown = true;
10393 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010394 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010395 + mBlurSurface + ": CREATE");
10396 try {
Romain Guy06882f82009-06-10 13:36:04 -070010397 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010398 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010399 -1, 16, 16,
10400 PixelFormat.OPAQUE,
10401 Surface.FX_SURFACE_BLUR);
10402 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010403 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010404 }
10405 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010406 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010407 + mBlurSurface + ": SHOW pos=(0,0) (" +
10408 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
10409 if (mBlurSurface != null) {
10410 mBlurSurface.setPosition(0, 0);
10411 mBlurSurface.setSize(dw, dh);
10412 try {
10413 mBlurSurface.show();
10414 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010415 Slog.w(TAG, "Failure showing blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010416 }
10417 }
10418 }
10419 mBlurSurface.setLayer(w.mAnimLayer-2);
10420 }
10421 }
10422 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010423
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010424 if (obscuredChanged && mWallpaperTarget == w) {
10425 // This is the wallpaper target and its obscured state
10426 // changed... make sure the current wallaper's visibility
10427 // has been updated accordingly.
10428 updateWallpaperVisibilityLocked();
10429 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010430 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010431
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010432 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10433 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010434 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010435 try {
10436 mBackgroundFillerSurface.hide();
10437 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010438 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010439 }
10440 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010441
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010442 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010443 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10444 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010445 }
Romain Guy06882f82009-06-10 13:36:04 -070010446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010447 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010448 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010449 + ": HIDE");
10450 try {
10451 mBlurSurface.hide();
10452 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010453 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010454 }
10455 mBlurShown = false;
10456 }
10457
Joe Onorato8a9b2202010-02-26 18:56:32 -080010458 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010459 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010460 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010461 }
10462
10463 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010464
Joe Onorato8a9b2202010-02-26 18:56:32 -080010465 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010466 "With display frozen, orientationChangeComplete="
10467 + orientationChangeComplete);
10468 if (orientationChangeComplete) {
10469 if (mWindowsFreezingScreen) {
10470 mWindowsFreezingScreen = false;
10471 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10472 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010473 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010474 }
Romain Guy06882f82009-06-10 13:36:04 -070010475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010476 i = mResizingWindows.size();
10477 if (i > 0) {
10478 do {
10479 i--;
10480 WindowState win = mResizingWindows.get(i);
10481 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010482 if (DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010483 + win + ": " + win.mFrame);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010484 boolean configChanged =
10485 win.mConfiguration != mCurConfiguration
10486 && (win.mConfiguration == null
10487 || mCurConfiguration.diff(win.mConfiguration) != 0);
10488 win.mConfiguration = mCurConfiguration;
10489 if (DEBUG_ORIENTATION && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010490 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010491 + win.mFrame.width() + "x" + win.mFrame.height()
10492 + " / " + win.mConfiguration);
10493 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010494 win.mClient.resized(win.mFrame.width(),
10495 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010496 win.mLastVisibleInsets, win.mDrawPending,
10497 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010498 win.mContentInsetsChanged = false;
10499 win.mVisibleInsetsChanged = false;
10500 } catch (RemoteException e) {
10501 win.mOrientationChanging = false;
10502 }
10503 } while (i > 0);
10504 mResizingWindows.clear();
10505 }
Romain Guy06882f82009-06-10 13:36:04 -070010506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010507 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010508 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010509 i = mDestroySurface.size();
10510 if (i > 0) {
10511 do {
10512 i--;
10513 WindowState win = mDestroySurface.get(i);
10514 win.mDestroying = false;
10515 if (mInputMethodWindow == win) {
10516 mInputMethodWindow = null;
10517 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010518 if (win == mWallpaperTarget) {
10519 wallpaperDestroyed = true;
10520 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010521 win.destroySurfaceLocked();
10522 } while (i > 0);
10523 mDestroySurface.clear();
10524 }
10525
10526 // Time to remove any exiting tokens?
10527 for (i=mExitingTokens.size()-1; i>=0; i--) {
10528 WindowToken token = mExitingTokens.get(i);
10529 if (!token.hasVisible) {
10530 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010531 if (token.windowType == TYPE_WALLPAPER) {
10532 mWallpaperTokens.remove(token);
10533 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010534 }
10535 }
10536
10537 // Time to remove any exiting applications?
10538 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10539 AppWindowToken token = mExitingAppTokens.get(i);
10540 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010541 // Make sure there is no animation running on this token,
10542 // so any windows associated with it will be removed as
10543 // soon as their animations are complete
10544 token.animation = null;
10545 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010546 mAppTokens.remove(token);
10547 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010548 if (mLastEnterAnimToken == token) {
10549 mLastEnterAnimToken = null;
10550 mLastEnterAnimParams = null;
10551 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010552 }
10553 }
10554
Dianne Hackborna8f60182009-09-01 19:01:50 -070010555 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010556
Dianne Hackborna8f60182009-09-01 19:01:50 -070010557 if (!animating && mAppTransitionRunning) {
10558 // We have finished the animation of an app transition. To do
10559 // this, we have delayed a lot of operations like showing and
10560 // hiding apps, moving apps in Z-order, etc. The app token list
10561 // reflects the correct Z-order, but the window list may now
10562 // be out of sync with it. So here we will just rebuild the
10563 // entire app window list. Fun!
10564 mAppTransitionRunning = false;
10565 needRelayout = true;
10566 rebuildAppWindowListLocked();
10567 // Clear information about apps that were moving.
10568 mToBottomApps.clear();
10569 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010571 if (focusDisplayed) {
10572 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10573 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010574 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010575 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010576 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010577 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010578 requestAnimationLocked(0);
10579 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010580 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10581 }
10582 mQueue.setHoldScreenLocked(holdScreen != null);
10583 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10584 mPowerManager.setScreenBrightnessOverride(-1);
10585 } else {
10586 mPowerManager.setScreenBrightnessOverride((int)
10587 (screenBrightness * Power.BRIGHTNESS_ON));
10588 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010589 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10590 mPowerManager.setButtonBrightnessOverride(-1);
10591 } else {
10592 mPowerManager.setButtonBrightnessOverride((int)
10593 (buttonBrightness * Power.BRIGHTNESS_ON));
10594 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010595 if (holdScreen != mHoldingScreenOn) {
10596 mHoldingScreenOn = holdScreen;
10597 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10598 mH.sendMessage(m);
10599 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010600
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010601 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010602 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010603 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10604 LocalPowerManager.BUTTON_EVENT, true);
10605 mTurnOnScreen = false;
10606 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010607
10608 // Check to see if we are now in a state where the screen should
10609 // be enabled, because the window obscured flags have changed.
10610 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010611 }
10612
10613 void requestAnimationLocked(long delay) {
10614 if (!mAnimationPending) {
10615 mAnimationPending = true;
10616 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10617 }
10618 }
Romain Guy06882f82009-06-10 13:36:04 -070010619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010620 /**
10621 * Have the surface flinger show a surface, robustly dealing with
10622 * error conditions. In particular, if there is not enough memory
10623 * to show the surface, then we will try to get rid of other surfaces
10624 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010625 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010626 * @return Returns true if the surface was successfully shown.
10627 */
10628 boolean showSurfaceRobustlyLocked(WindowState win) {
10629 try {
10630 if (win.mSurface != null) {
10631 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010632 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010633 if (DEBUG_VISIBILITY) Slog.v(TAG,
10634 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010635 win.mTurnOnScreen = false;
10636 mTurnOnScreen = true;
10637 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010638 }
10639 return true;
10640 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010641 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010642 }
Romain Guy06882f82009-06-10 13:36:04 -070010643
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010644 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010646 return false;
10647 }
Romain Guy06882f82009-06-10 13:36:04 -070010648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010649 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10650 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010651
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010652 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010653 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010655 if (mForceRemoves == null) {
10656 mForceRemoves = new ArrayList<WindowState>();
10657 }
Romain Guy06882f82009-06-10 13:36:04 -070010658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010659 long callingIdentity = Binder.clearCallingIdentity();
10660 try {
10661 // There was some problem... first, do a sanity check of the
10662 // window list to make sure we haven't left any dangling surfaces
10663 // around.
10664 int N = mWindows.size();
10665 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010666 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010667 for (int i=0; i<N; i++) {
10668 WindowState ws = (WindowState)mWindows.get(i);
10669 if (ws.mSurface != null) {
10670 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010671 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010672 + ws + " surface=" + ws.mSurface
10673 + " token=" + win.mToken
10674 + " pid=" + ws.mSession.mPid
10675 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010676 ws.mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010677 ws.mSurface = null;
10678 mForceRemoves.add(ws);
10679 i--;
10680 N--;
10681 leakedSurface = true;
10682 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010683 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010684 + ws + " surface=" + ws.mSurface
10685 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010686 ws.mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010687 ws.mSurface = null;
10688 leakedSurface = true;
10689 }
10690 }
10691 }
Romain Guy06882f82009-06-10 13:36:04 -070010692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010693 boolean killedApps = false;
10694 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010695 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010696 SparseIntArray pidCandidates = new SparseIntArray();
10697 for (int i=0; i<N; i++) {
10698 WindowState ws = (WindowState)mWindows.get(i);
10699 if (ws.mSurface != null) {
10700 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10701 }
10702 }
10703 if (pidCandidates.size() > 0) {
10704 int[] pids = new int[pidCandidates.size()];
10705 for (int i=0; i<pids.length; i++) {
10706 pids[i] = pidCandidates.keyAt(i);
10707 }
10708 try {
10709 if (mActivityManager.killPidsForMemory(pids)) {
10710 killedApps = true;
10711 }
10712 } catch (RemoteException e) {
10713 }
10714 }
10715 }
Romain Guy06882f82009-06-10 13:36:04 -070010716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010717 if (leakedSurface || killedApps) {
10718 // We managed to reclaim some memory, so get rid of the trouble
10719 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010720 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010721 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010722 surface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010723 win.mSurface = null;
10724 }
Romain Guy06882f82009-06-10 13:36:04 -070010725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010726 try {
10727 win.mClient.dispatchGetNewSurface();
10728 } catch (RemoteException e) {
10729 }
10730 }
10731 } finally {
10732 Binder.restoreCallingIdentity(callingIdentity);
10733 }
10734 }
Romain Guy06882f82009-06-10 13:36:04 -070010735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010736 private boolean updateFocusedWindowLocked(int mode) {
10737 WindowState newFocus = computeFocusedWindowLocked();
10738 if (mCurrentFocus != newFocus) {
10739 // This check makes sure that we don't already have the focus
10740 // change message pending.
10741 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10742 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010743 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010744 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10745 final WindowState oldFocus = mCurrentFocus;
10746 mCurrentFocus = newFocus;
10747 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010749 final WindowState imWindow = mInputMethodWindow;
10750 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010751 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010752 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010753 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10754 mLayoutNeeded = true;
10755 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010756 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10757 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010758 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10759 // Client will do the layout, but we need to assign layers
10760 // for handleNewWindowLocked() below.
10761 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010762 }
10763 }
Romain Guy06882f82009-06-10 13:36:04 -070010764
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010765 if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10766 mKeyWaiter.handleNewWindowLocked(newFocus);
10767 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010768 return true;
10769 }
10770 return false;
10771 }
10772
10773 private WindowState computeFocusedWindowLocked() {
10774 WindowState result = null;
10775 WindowState win;
10776
10777 int i = mWindows.size() - 1;
10778 int nextAppIndex = mAppTokens.size()-1;
10779 WindowToken nextApp = nextAppIndex >= 0
10780 ? mAppTokens.get(nextAppIndex) : null;
10781
10782 while (i >= 0) {
10783 win = (WindowState)mWindows.get(i);
10784
Joe Onorato8a9b2202010-02-26 18:56:32 -080010785 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010786 TAG, "Looking for focus: " + i
10787 + " = " + win
10788 + ", flags=" + win.mAttrs.flags
10789 + ", canReceive=" + win.canReceiveKeys());
10790
10791 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010793 // If this window's application has been removed, just skip it.
10794 if (thisApp != null && thisApp.removed) {
10795 i--;
10796 continue;
10797 }
Romain Guy06882f82009-06-10 13:36:04 -070010798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010799 // If there is a focused app, don't allow focus to go to any
10800 // windows below it. If this is an application window, step
10801 // through the app tokens until we find its app.
10802 if (thisApp != null && nextApp != null && thisApp != nextApp
10803 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10804 int origAppIndex = nextAppIndex;
10805 while (nextAppIndex > 0) {
10806 if (nextApp == mFocusedApp) {
10807 // Whoops, we are below the focused app... no focus
10808 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010809 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010810 TAG, "Reached focused app: " + mFocusedApp);
10811 return null;
10812 }
10813 nextAppIndex--;
10814 nextApp = mAppTokens.get(nextAppIndex);
10815 if (nextApp == thisApp) {
10816 break;
10817 }
10818 }
10819 if (thisApp != nextApp) {
10820 // Uh oh, the app token doesn't exist! This shouldn't
10821 // happen, but if it does we can get totally hosed...
10822 // so restart at the original app.
10823 nextAppIndex = origAppIndex;
10824 nextApp = mAppTokens.get(nextAppIndex);
10825 }
10826 }
10827
10828 // Dispatch to this window if it is wants key events.
10829 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010830 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010831 TAG, "Found focus @ " + i + " = " + win);
10832 result = win;
10833 break;
10834 }
10835
10836 i--;
10837 }
10838
10839 return result;
10840 }
10841
10842 private void startFreezingDisplayLocked() {
10843 if (mDisplayFrozen) {
Chris Tate2ad63a92009-03-25 17:36:48 -070010844 // Freezing the display also suspends key event delivery, to
10845 // keep events from going astray while the display is reconfigured.
10846 // If someone has changed orientation again while the screen is
10847 // still frozen, the events will continue to be blocked while the
10848 // successive orientation change is processed. To prevent spurious
10849 // ANRs, we reset the event dispatch timeout in this case.
10850 synchronized (mKeyWaiter) {
10851 mKeyWaiter.mWasFrozen = true;
10852 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010853 return;
10854 }
Romain Guy06882f82009-06-10 13:36:04 -070010855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010856 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010857
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010858 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010859 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010860 if (mFreezeGcPending != 0) {
10861 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010862 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010863 mH.removeMessages(H.FORCE_GC);
10864 Runtime.getRuntime().gc();
10865 mFreezeGcPending = now;
10866 }
10867 } else {
10868 mFreezeGcPending = now;
10869 }
Romain Guy06882f82009-06-10 13:36:04 -070010870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010871 mDisplayFrozen = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010872 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10873 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010874 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010875 mAppTransitionReady = true;
10876 }
Romain Guy06882f82009-06-10 13:36:04 -070010877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010878 if (PROFILE_ORIENTATION) {
10879 File file = new File("/data/system/frozen");
10880 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10881 }
10882 Surface.freezeDisplay(0);
10883 }
Romain Guy06882f82009-06-10 13:36:04 -070010884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010885 private void stopFreezingDisplayLocked() {
10886 if (!mDisplayFrozen) {
10887 return;
10888 }
Romain Guy06882f82009-06-10 13:36:04 -070010889
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010890 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10891 return;
10892 }
10893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010894 mDisplayFrozen = false;
10895 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10896 if (PROFILE_ORIENTATION) {
10897 Debug.stopMethodTracing();
10898 }
10899 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010900
Chris Tate2ad63a92009-03-25 17:36:48 -070010901 // Reset the key delivery timeout on unfreeze, too. We force a wakeup here
10902 // too because regular key delivery processing should resume immediately.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010903 synchronized (mKeyWaiter) {
10904 mKeyWaiter.mWasFrozen = true;
10905 mKeyWaiter.notifyAll();
10906 }
10907
10908 // A little kludge: a lot could have happened while the
10909 // display was frozen, so now that we are coming back we
10910 // do a gc so that any remote references the system
10911 // processes holds on others can be released if they are
10912 // no longer needed.
10913 mH.removeMessages(H.FORCE_GC);
10914 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10915 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010917 mScreenFrozenLock.release();
10918 }
Romain Guy06882f82009-06-10 13:36:04 -070010919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010920 @Override
10921 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10922 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10923 != PackageManager.PERMISSION_GRANTED) {
10924 pw.println("Permission Denial: can't dump WindowManager from from pid="
10925 + Binder.getCallingPid()
10926 + ", uid=" + Binder.getCallingUid());
10927 return;
10928 }
Romain Guy06882f82009-06-10 13:36:04 -070010929
Dianne Hackborna2e92262010-03-02 17:19:29 -080010930 pw.println("Input State:");
10931 mQueue.dump(pw, " ");
10932 pw.println(" ");
10933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010934 synchronized(mWindowMap) {
10935 pw.println("Current Window Manager state:");
10936 for (int i=mWindows.size()-1; i>=0; i--) {
10937 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010938 pw.print(" Window #"); pw.print(i); pw.print(' ');
10939 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010940 w.dump(pw, " ");
10941 }
10942 if (mInputMethodDialogs.size() > 0) {
10943 pw.println(" ");
10944 pw.println(" Input method dialogs:");
10945 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10946 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010947 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010948 }
10949 }
10950 if (mPendingRemove.size() > 0) {
10951 pw.println(" ");
10952 pw.println(" Remove pending for:");
10953 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10954 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010955 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10956 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010957 w.dump(pw, " ");
10958 }
10959 }
10960 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10961 pw.println(" ");
10962 pw.println(" Windows force removing:");
10963 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10964 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010965 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10966 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010967 w.dump(pw, " ");
10968 }
10969 }
10970 if (mDestroySurface.size() > 0) {
10971 pw.println(" ");
10972 pw.println(" Windows waiting to destroy their surface:");
10973 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10974 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010975 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10976 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010977 w.dump(pw, " ");
10978 }
10979 }
10980 if (mLosingFocus.size() > 0) {
10981 pw.println(" ");
10982 pw.println(" Windows losing focus:");
10983 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10984 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010985 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10986 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010987 w.dump(pw, " ");
10988 }
10989 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010990 if (mResizingWindows.size() > 0) {
10991 pw.println(" ");
10992 pw.println(" Windows waiting to resize:");
10993 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10994 WindowState w = mResizingWindows.get(i);
10995 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10996 pw.print(w); pw.println(":");
10997 w.dump(pw, " ");
10998 }
10999 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011000 if (mSessions.size() > 0) {
11001 pw.println(" ");
11002 pw.println(" All active sessions:");
11003 Iterator<Session> it = mSessions.iterator();
11004 while (it.hasNext()) {
11005 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011006 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011007 s.dump(pw, " ");
11008 }
11009 }
11010 if (mTokenMap.size() > 0) {
11011 pw.println(" ");
11012 pw.println(" All tokens:");
11013 Iterator<WindowToken> it = mTokenMap.values().iterator();
11014 while (it.hasNext()) {
11015 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011016 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011017 token.dump(pw, " ");
11018 }
11019 }
11020 if (mTokenList.size() > 0) {
11021 pw.println(" ");
11022 pw.println(" Window token list:");
11023 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011024 pw.print(" #"); pw.print(i); pw.print(": ");
11025 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011026 }
11027 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011028 if (mWallpaperTokens.size() > 0) {
11029 pw.println(" ");
11030 pw.println(" Wallpaper tokens:");
11031 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11032 WindowToken token = mWallpaperTokens.get(i);
11033 pw.print(" Wallpaper #"); pw.print(i);
11034 pw.print(' '); pw.print(token); pw.println(':');
11035 token.dump(pw, " ");
11036 }
11037 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011038 if (mAppTokens.size() > 0) {
11039 pw.println(" ");
11040 pw.println(" Application tokens in Z order:");
11041 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011042 pw.print(" App #"); pw.print(i); pw.print(": ");
11043 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011044 }
11045 }
11046 if (mFinishedStarting.size() > 0) {
11047 pw.println(" ");
11048 pw.println(" Finishing start of application tokens:");
11049 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11050 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011051 pw.print(" Finished Starting #"); pw.print(i);
11052 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011053 token.dump(pw, " ");
11054 }
11055 }
11056 if (mExitingTokens.size() > 0) {
11057 pw.println(" ");
11058 pw.println(" Exiting tokens:");
11059 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11060 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011061 pw.print(" Exiting #"); pw.print(i);
11062 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011063 token.dump(pw, " ");
11064 }
11065 }
11066 if (mExitingAppTokens.size() > 0) {
11067 pw.println(" ");
11068 pw.println(" Exiting application tokens:");
11069 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11070 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011071 pw.print(" Exiting App #"); pw.print(i);
11072 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011073 token.dump(pw, " ");
11074 }
11075 }
11076 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011077 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11078 pw.print(" mLastFocus="); pw.println(mLastFocus);
11079 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11080 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11081 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011082 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011083 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11084 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11085 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11086 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011087 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11088 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11089 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011090 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11091 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11092 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11093 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011094 if (mDimAnimator != null) {
11095 mDimAnimator.printTo(pw);
11096 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011097 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011098 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011099 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011100 pw.print(mInputMethodAnimLayerAdjustment);
11101 pw.print(" mWallpaperAnimLayerAdjustment=");
11102 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011103 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11104 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011105 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11106 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011107 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11108 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011109 pw.print(" mRotation="); pw.print(mRotation);
11110 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11111 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11112 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11113 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11114 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11115 pw.print(" mNextAppTransition=0x");
11116 pw.print(Integer.toHexString(mNextAppTransition));
11117 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011118 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011119 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011120 if (mNextAppTransitionPackage != null) {
11121 pw.print(" mNextAppTransitionPackage=");
11122 pw.print(mNextAppTransitionPackage);
11123 pw.print(", mNextAppTransitionEnter=0x");
11124 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11125 pw.print(", mNextAppTransitionExit=0x");
11126 pw.print(Integer.toHexString(mNextAppTransitionExit));
11127 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011128 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11129 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011130 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11131 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11132 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11133 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011134 if (mOpeningApps.size() > 0) {
11135 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11136 }
11137 if (mClosingApps.size() > 0) {
11138 pw.print(" mClosingApps="); pw.println(mClosingApps);
11139 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011140 if (mToTopApps.size() > 0) {
11141 pw.print(" mToTopApps="); pw.println(mToTopApps);
11142 }
11143 if (mToBottomApps.size() > 0) {
11144 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11145 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011146 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11147 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011148 pw.println(" KeyWaiter state:");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011149 pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin);
11150 pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder);
11151 pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished);
11152 pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow);
11153 pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching);
11154 pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011155 }
11156 }
11157
11158 public void monitor() {
11159 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011160 synchronized (mKeyguardTokenWatcher) { }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011161 synchronized (mKeyWaiter) { }
11162 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011163
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011164 public void virtualKeyFeedback(KeyEvent event) {
11165 mPolicy.keyFeedbackFromInput(event);
11166 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011167
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011168 /**
11169 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011170 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011171 */
11172 private static class DimAnimator {
11173 Surface mDimSurface;
11174 boolean mDimShown = false;
11175 float mDimCurrentAlpha;
11176 float mDimTargetAlpha;
11177 float mDimDeltaPerMs;
11178 long mLastDimAnimTime;
11179
11180 DimAnimator (SurfaceSession session) {
11181 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011182 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011183 + mDimSurface + ": CREATE");
11184 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011185 mDimSurface = new Surface(session, 0,
11186 "DimSurface",
11187 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011188 Surface.FX_SURFACE_DIM);
11189 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011190 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011191 }
11192 }
11193 }
11194
11195 /**
11196 * Show the dim surface.
11197 */
11198 void show(int dw, int dh) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011199 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011200 dw + "x" + dh + ")");
11201 mDimShown = true;
11202 try {
11203 mDimSurface.setPosition(0, 0);
11204 mDimSurface.setSize(dw, dh);
11205 mDimSurface.show();
11206 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011207 Slog.w(TAG, "Failure showing dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011208 }
11209 }
11210
11211 /**
11212 * Set's the dim surface's layer and update dim parameters that will be used in
11213 * {@link updateSurface} after all windows are examined.
11214 */
11215 void updateParameters(WindowState w, long currentTime) {
11216 mDimSurface.setLayer(w.mAnimLayer-1);
11217
11218 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011219 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011220 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011221 if (mDimTargetAlpha != target) {
11222 // If the desired dim level has changed, then
11223 // start an animation to it.
11224 mLastDimAnimTime = currentTime;
11225 long duration = (w.mAnimating && w.mAnimation != null)
11226 ? w.mAnimation.computeDurationHint()
11227 : DEFAULT_DIM_DURATION;
11228 if (target > mDimTargetAlpha) {
11229 // This is happening behind the activity UI,
11230 // so we can make it run a little longer to
11231 // give a stronger impression without disrupting
11232 // the user.
11233 duration *= DIM_DURATION_MULTIPLIER;
11234 }
11235 if (duration < 1) {
11236 // Don't divide by zero
11237 duration = 1;
11238 }
11239 mDimTargetAlpha = target;
11240 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11241 }
11242 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011243
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011244 /**
11245 * Updating the surface's alpha. Returns true if the animation continues, or returns
11246 * false when the animation is finished and the dim surface is hidden.
11247 */
11248 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11249 if (!dimming) {
11250 if (mDimTargetAlpha != 0) {
11251 mLastDimAnimTime = currentTime;
11252 mDimTargetAlpha = 0;
11253 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11254 }
11255 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011256
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011257 boolean animating = false;
11258 if (mLastDimAnimTime != 0) {
11259 mDimCurrentAlpha += mDimDeltaPerMs
11260 * (currentTime-mLastDimAnimTime);
11261 boolean more = true;
11262 if (displayFrozen) {
11263 // If the display is frozen, there is no reason to animate.
11264 more = false;
11265 } else if (mDimDeltaPerMs > 0) {
11266 if (mDimCurrentAlpha > mDimTargetAlpha) {
11267 more = false;
11268 }
11269 } else if (mDimDeltaPerMs < 0) {
11270 if (mDimCurrentAlpha < mDimTargetAlpha) {
11271 more = false;
11272 }
11273 } else {
11274 more = false;
11275 }
11276
11277 // Do we need to continue animating?
11278 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011279 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011280 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11281 mLastDimAnimTime = currentTime;
11282 mDimSurface.setAlpha(mDimCurrentAlpha);
11283 animating = true;
11284 } else {
11285 mDimCurrentAlpha = mDimTargetAlpha;
11286 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011287 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011288 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11289 mDimSurface.setAlpha(mDimCurrentAlpha);
11290 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011291 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011292 + ": HIDE");
11293 try {
11294 mDimSurface.hide();
11295 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011296 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011297 }
11298 mDimShown = false;
11299 }
11300 }
11301 }
11302 return animating;
11303 }
11304
11305 public void printTo(PrintWriter pw) {
11306 pw.print(" mDimShown="); pw.print(mDimShown);
11307 pw.print(" current="); pw.print(mDimCurrentAlpha);
11308 pw.print(" target="); pw.print(mDimTargetAlpha);
11309 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11310 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11311 }
11312 }
11313
11314 /**
11315 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11316 * This is used for opening/closing transition for apps in compatible mode.
11317 */
11318 private static class FadeInOutAnimation extends Animation {
11319 int mWidth;
11320 boolean mFadeIn;
11321
11322 public FadeInOutAnimation(boolean fadeIn) {
11323 setInterpolator(new AccelerateInterpolator());
11324 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11325 mFadeIn = fadeIn;
11326 }
11327
11328 @Override
11329 protected void applyTransformation(float interpolatedTime, Transformation t) {
11330 float x = interpolatedTime;
11331 if (!mFadeIn) {
11332 x = 1.0f - x; // reverse the interpolation for fade out
11333 }
11334 if (x < 0.5) {
11335 // move the window out of the screen.
11336 t.getMatrix().setTranslate(mWidth, 0);
11337 } else {
11338 t.getMatrix().setTranslate(0, 0);// show
11339 t.setAlpha((x - 0.5f) * 2);
11340 }
11341 }
11342
11343 @Override
11344 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11345 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11346 mWidth = width;
11347 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011348
11349 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011350 public int getZAdjustment() {
11351 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011352 }
11353 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011354}