blob: 81e0136169cb6d50f2894e1d9db6e8cb93132bbe [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;
46import com.android.internal.view.IInputContext;
47import com.android.internal.view.IInputMethodClient;
48import com.android.internal.view.IInputMethodManager;
49import com.android.server.KeyInputQueue.QueuedEvent;
50import com.android.server.am.BatteryStatsService;
51
52import android.Manifest;
53import android.app.ActivityManagerNative;
54import android.app.IActivityManager;
55import android.content.Context;
56import android.content.pm.ActivityInfo;
57import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070058import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import android.content.res.Configuration;
60import android.graphics.Matrix;
61import android.graphics.PixelFormat;
62import android.graphics.Rect;
63import android.graphics.Region;
64import android.os.BatteryStats;
65import android.os.Binder;
66import android.os.Debug;
67import android.os.Handler;
68import android.os.IBinder;
Michael Chan53071d62009-05-13 17:29:48 -070069import android.os.LatencyTimer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070import android.os.LocalPowerManager;
71import android.os.Looper;
72import android.os.Message;
73import android.os.Parcel;
74import android.os.ParcelFileDescriptor;
75import android.os.Power;
76import android.os.PowerManager;
77import android.os.Process;
78import android.os.RemoteException;
79import android.os.ServiceManager;
80import android.os.SystemClock;
81import android.os.SystemProperties;
82import android.os.TokenWatcher;
83import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070084import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085import android.util.EventLog;
86import android.util.Log;
87import android.util.SparseIntArray;
88import android.view.Display;
89import android.view.Gravity;
90import android.view.IApplicationToken;
91import android.view.IOnKeyguardExitResult;
92import android.view.IRotationWatcher;
93import android.view.IWindow;
94import android.view.IWindowManager;
95import android.view.IWindowSession;
96import android.view.KeyEvent;
97import android.view.MotionEvent;
98import android.view.RawInputEvent;
99import android.view.Surface;
100import android.view.SurfaceSession;
101import android.view.View;
102import android.view.ViewTreeObserver;
103import android.view.WindowManager;
104import android.view.WindowManagerImpl;
105import android.view.WindowManagerPolicy;
106import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700107import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108import android.view.animation.Animation;
109import android.view.animation.AnimationUtils;
110import android.view.animation.Transformation;
111
112import java.io.BufferedWriter;
113import java.io.File;
114import java.io.FileDescriptor;
115import java.io.IOException;
116import java.io.OutputStream;
117import java.io.OutputStreamWriter;
118import java.io.PrintWriter;
119import java.io.StringWriter;
120import java.net.Socket;
121import java.util.ArrayList;
122import java.util.HashMap;
123import java.util.HashSet;
124import java.util.Iterator;
125import java.util.List;
126
127/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700128public class WindowManagerService extends IWindowManager.Stub
129 implements Watchdog.Monitor, KeyInputQueue.HapticFeedbackCallback {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 static final String TAG = "WindowManager";
131 static final boolean DEBUG = false;
132 static final boolean DEBUG_FOCUS = false;
133 static final boolean DEBUG_ANIM = false;
134 static final boolean DEBUG_LAYERS = false;
135 static final boolean DEBUG_INPUT = false;
136 static final boolean DEBUG_INPUT_METHOD = false;
137 static final boolean DEBUG_VISIBILITY = false;
138 static final boolean DEBUG_ORIENTATION = false;
139 static final boolean DEBUG_APP_TRANSITIONS = false;
140 static final boolean DEBUG_STARTING_WINDOW = false;
141 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700142 static final boolean DEBUG_WALLPAPER = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 static final boolean SHOW_TRANSACTIONS = false;
Michael Chan53071d62009-05-13 17:29:48 -0700144 static final boolean MEASURE_LATENCY = false;
145 static private LatencyTimer lt;
146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 static final boolean PROFILE_ORIENTATION = false;
148 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700149 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 static final int LOG_WM_NO_SURFACE_MEMORY = 31000;
Romain Guy06882f82009-06-10 13:36:04 -0700152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 /** How long to wait for first key repeat, in milliseconds */
154 static final int KEY_REPEAT_FIRST_DELAY = 750;
Romain Guy06882f82009-06-10 13:36:04 -0700155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 /** How long to wait for subsequent key repeats, in milliseconds */
157 static final int KEY_REPEAT_DELAY = 50;
158
159 /** How much to multiply the policy's type layer, to reserve room
160 * for multiple windows of the same type and Z-ordering adjustment
161 * with TYPE_LAYER_OFFSET. */
162 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
165 * or below others in the same layer. */
166 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 /** How much to increment the layer for each window, to reserve room
169 * for effect surfaces between them.
170 */
171 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 /** The maximum length we will accept for a loaded animation duration:
174 * this is 10 seconds.
175 */
176 static final int MAX_ANIMATION_DURATION = 10*1000;
177
178 /** Amount of time (in milliseconds) to animate the dim surface from one
179 * value to another, when no window animation is driving it.
180 */
181 static final int DEFAULT_DIM_DURATION = 200;
182
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700183 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
184 * compatible windows.
185 */
186 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 /** Adjustment to time to perform a dim, to make it more dramatic.
189 */
190 static final int DIM_DURATION_MULTIPLIER = 6;
Romain Guy06882f82009-06-10 13:36:04 -0700191
Dianne Hackborncfaef692009-06-15 14:24:44 -0700192 static final int INJECT_FAILED = 0;
193 static final int INJECT_SUCCEEDED = 1;
194 static final int INJECT_NO_PERMISSION = -1;
195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196 static final int UPDATE_FOCUS_NORMAL = 0;
197 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
198 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
199 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700200
Michael Chane96440f2009-05-06 10:27:36 -0700201 /** The minimum time between dispatching touch events. */
202 int mMinWaitTimeBetweenTouchEvents = 1000 / 35;
203
204 // Last touch event time
205 long mLastTouchEventTime = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700206
Michael Chane96440f2009-05-06 10:27:36 -0700207 // Last touch event type
208 int mLastTouchEventType = OTHER_EVENT;
Romain Guy06882f82009-06-10 13:36:04 -0700209
Michael Chane96440f2009-05-06 10:27:36 -0700210 // Time to wait before calling useractivity again. This saves CPU usage
211 // when we get a flood of touch events.
212 static final int MIN_TIME_BETWEEN_USERACTIVITIES = 1000;
213
214 // Last time we call user activity
215 long mLastUserActivityCallTime = 0;
216
Romain Guy06882f82009-06-10 13:36:04 -0700217 // Last time we updated battery stats
Michael Chane96440f2009-05-06 10:27:36 -0700218 long mLastBatteryStatsCallTime = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700221 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222
223 /**
224 * Condition waited on by {@link #reenableKeyguard} to know the call to
225 * the window policy has finished.
226 */
227 private boolean mWaitingUntilKeyguardReenabled = false;
228
229
230 final TokenWatcher mKeyguardDisabled = new TokenWatcher(
231 new Handler(), "WindowManagerService.mKeyguardDisabled") {
232 public void acquired() {
233 mPolicy.enableKeyguard(false);
234 }
235 public void released() {
236 synchronized (mKeyguardDisabled) {
237 mPolicy.enableKeyguard(true);
238 mWaitingUntilKeyguardReenabled = false;
239 mKeyguardDisabled.notifyAll();
240 }
241 }
242 };
243
244 final Context mContext;
245
246 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
251
252 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256 /**
257 * All currently active sessions with clients.
258 */
259 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 /**
262 * Mapping from an IWindow IBinder to the server's Window object.
263 * This is also used as the lock for all of our state.
264 */
265 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
266
267 /**
268 * Mapping from a token IBinder to a WindowToken object.
269 */
270 final HashMap<IBinder, WindowToken> mTokenMap =
271 new HashMap<IBinder, WindowToken>();
272
273 /**
274 * The same tokens as mTokenMap, stored in a list for efficient iteration
275 * over them.
276 */
277 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 /**
280 * Window tokens that are in the process of exiting, but still
281 * on screen for animations.
282 */
283 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
284
285 /**
286 * Z-ordered (bottom-most first) list of all application tokens, for
287 * controlling the ordering of windows in different applications. This
288 * contains WindowToken objects.
289 */
290 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
291
292 /**
293 * Application tokens that are in the process of exiting, but still
294 * on screen for animations.
295 */
296 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
297
298 /**
299 * List of window tokens that have finished starting their application,
300 * and now need to have the policy remove their windows.
301 */
302 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
303
304 /**
305 * Z-ordered (bottom-most first) list of all Window objects.
306 */
307 final ArrayList mWindows = new ArrayList();
308
309 /**
310 * Windows that are being resized. Used so we can tell the client about
311 * the resize after closing the transaction in which we resized the
312 * underlying surface.
313 */
314 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
315
316 /**
317 * Windows whose animations have ended and now must be removed.
318 */
319 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
320
321 /**
322 * Windows whose surface should be destroyed.
323 */
324 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
325
326 /**
327 * Windows that have lost input focus and are waiting for the new
328 * focus window to be displayed before they are told about this.
329 */
330 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
331
332 /**
333 * This is set when we have run out of memory, and will either be an empty
334 * list or contain windows that need to be force removed.
335 */
336 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700341 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 Surface mBlurSurface;
343 boolean mBlurShown;
Romain Guy06882f82009-06-10 13:36:04 -0700344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 final float[] mTmpFloats = new float[9];
348
349 boolean mSafeMode;
350 boolean mDisplayEnabled = false;
351 boolean mSystemBooted = false;
352 int mRotation = 0;
353 int mRequestedRotation = 0;
354 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700355 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 ArrayList<IRotationWatcher> mRotationWatchers
357 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 boolean mLayoutNeeded = true;
360 boolean mAnimationPending = false;
361 boolean mDisplayFrozen = false;
362 boolean mWindowsFreezingScreen = false;
363 long mFreezeGcPending = 0;
364 int mAppsFreezingScreen = 0;
365
366 // This is held as long as we have the screen frozen, to give us time to
367 // perform a rotation animation when turning off shows the lock screen which
368 // changes the orientation.
369 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 // State management of app transitions. When we are preparing for a
372 // transition, mNextAppTransition will be the kind of transition to
373 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
374 // mOpeningApps and mClosingApps are the lists of tokens that will be
375 // made visible or hidden at the next transition.
376 int mNextAppTransition = WindowManagerPolicy.TRANSIT_NONE;
377 boolean mAppTransitionReady = false;
378 boolean mAppTransitionTimeout = false;
379 boolean mStartingIconInTransition = false;
380 boolean mSkipAppTransitionAnimation = false;
381 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
382 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 //flag to detect fat touch events
385 boolean mFatTouch = false;
386 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 H mH = new H();
389
390 WindowState mCurrentFocus = null;
391 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 // This just indicates the window the input method is on top of, not
394 // necessarily the window its input is going to.
395 WindowState mInputMethodTarget = null;
396 WindowState mUpcomingInputMethodTarget = null;
397 boolean mInputMethodTargetWaitingAnim;
398 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 WindowState mInputMethodWindow = null;
401 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
402
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700403 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
404
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700405 // If non-null, this is the currently visible window that is associated
406 // with the wallpaper.
407 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700408 // If non-null, we are in the middle of animating from one wallpaper target
409 // to another, and this is the lower one in Z-order.
410 WindowState mLowerWallpaperTarget = null;
411 // If non-null, we are in the middle of animating from one wallpaper target
412 // to another, and this is the higher one in Z-order.
413 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700414 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn284ac932009-08-28 10:34:25 -0700415 float mLastWallpaperX;
416 float mLastWallpaperY;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 AppWindowToken mFocusedApp = null;
419
420 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 float mWindowAnimationScale = 1.0f;
423 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 final KeyWaiter mKeyWaiter = new KeyWaiter();
426 final KeyQ mQueue;
427 final InputDispatcherThread mInputThread;
428
429 // Who is holding the screen on.
430 Session mHoldingScreenOn;
Romain Guy06882f82009-06-10 13:36:04 -0700431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 /**
433 * Whether the UI is currently running in touch mode (not showing
434 * navigational focus because the user is directly pressing the screen).
435 */
436 boolean mInTouchMode = false;
437
438 private ViewServer mViewServer;
439
440 final Rect mTempRect = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -0700441
Dianne Hackbornc485a602009-03-24 22:39:49 -0700442 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700443 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700444
445 // The frame use to limit the size of the app running in compatibility mode.
446 Rect mCompatibleScreenFrame = new Rect();
447 // The surface used to fill the outer rim of the app running in compatibility mode.
448 Surface mBackgroundFillerSurface = null;
449 boolean mBackgroundFillerShown = false;
450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 public static WindowManagerService main(Context context,
452 PowerManagerService pm, boolean haveInputMethods) {
453 WMThread thr = new WMThread(context, pm, haveInputMethods);
454 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800456 synchronized (thr) {
457 while (thr.mService == null) {
458 try {
459 thr.wait();
460 } catch (InterruptedException e) {
461 }
462 }
463 }
Romain Guy06882f82009-06-10 13:36:04 -0700464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800465 return thr.mService;
466 }
Romain Guy06882f82009-06-10 13:36:04 -0700467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468 static class WMThread extends Thread {
469 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 private final Context mContext;
472 private final PowerManagerService mPM;
473 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 public WMThread(Context context, PowerManagerService pm,
476 boolean haveInputMethods) {
477 super("WindowManager");
478 mContext = context;
479 mPM = pm;
480 mHaveInputMethods = haveInputMethods;
481 }
Romain Guy06882f82009-06-10 13:36:04 -0700482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800483 public void run() {
484 Looper.prepare();
485 WindowManagerService s = new WindowManagerService(mContext, mPM,
486 mHaveInputMethods);
487 android.os.Process.setThreadPriority(
488 android.os.Process.THREAD_PRIORITY_DISPLAY);
Romain Guy06882f82009-06-10 13:36:04 -0700489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 synchronized (this) {
491 mService = s;
492 notifyAll();
493 }
Romain Guy06882f82009-06-10 13:36:04 -0700494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 Looper.loop();
496 }
497 }
498
499 static class PolicyThread extends Thread {
500 private final WindowManagerPolicy mPolicy;
501 private final WindowManagerService mService;
502 private final Context mContext;
503 private final PowerManagerService mPM;
504 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 public PolicyThread(WindowManagerPolicy policy,
507 WindowManagerService service, Context context,
508 PowerManagerService pm) {
509 super("WindowManagerPolicy");
510 mPolicy = policy;
511 mService = service;
512 mContext = context;
513 mPM = pm;
514 }
Romain Guy06882f82009-06-10 13:36:04 -0700515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 public void run() {
517 Looper.prepare();
518 //Looper.myLooper().setMessageLogging(new LogPrinter(
519 // Log.VERBOSE, "WindowManagerPolicy"));
520 android.os.Process.setThreadPriority(
521 android.os.Process.THREAD_PRIORITY_FOREGROUND);
522 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524 synchronized (this) {
525 mRunning = true;
526 notifyAll();
527 }
Romain Guy06882f82009-06-10 13:36:04 -0700528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 Looper.loop();
530 }
531 }
532
533 private WindowManagerService(Context context, PowerManagerService pm,
534 boolean haveInputMethods) {
Michael Chan53071d62009-05-13 17:29:48 -0700535 if (MEASURE_LATENCY) {
536 lt = new LatencyTimer(100, 1000);
537 }
538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 mContext = context;
540 mHaveInputMethods = haveInputMethods;
541 mLimitedAlphaCompositing = context.getResources().getBoolean(
542 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 mPowerManager = pm;
545 mPowerManager.setPolicy(mPolicy);
546 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
547 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
548 "SCREEN_FROZEN");
549 mScreenFrozenLock.setReferenceCounted(false);
550
551 mActivityManager = ActivityManagerNative.getDefault();
552 mBatteryStats = BatteryStatsService.getService();
553
554 // Get persisted window scale setting
555 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
556 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
557 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
558 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700559
Michael Chan9f028e62009-08-04 17:37:46 -0700560 int max_events_per_sec = 35;
561 try {
562 max_events_per_sec = Integer.parseInt(SystemProperties
563 .get("windowsmgr.max_events_per_sec"));
564 if (max_events_per_sec < 1) {
565 max_events_per_sec = 35;
566 }
567 } catch (NumberFormatException e) {
568 }
569 mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec;
570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 mQueue = new KeyQ();
572
573 mInputThread = new InputDispatcherThread();
Romain Guy06882f82009-06-10 13:36:04 -0700574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
576 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 synchronized (thr) {
579 while (!thr.mRunning) {
580 try {
581 thr.wait();
582 } catch (InterruptedException e) {
583 }
584 }
585 }
Romain Guy06882f82009-06-10 13:36:04 -0700586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 mInputThread.start();
Romain Guy06882f82009-06-10 13:36:04 -0700588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 // Add ourself to the Watchdog monitors.
590 Watchdog.getInstance().addMonitor(this);
591 }
592
593 @Override
594 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
595 throws RemoteException {
596 try {
597 return super.onTransact(code, data, reply, flags);
598 } catch (RuntimeException e) {
599 // The window manager only throws security exceptions, so let's
600 // log all others.
601 if (!(e instanceof SecurityException)) {
602 Log.e(TAG, "Window Manager Crash", e);
603 }
604 throw e;
605 }
606 }
607
608 private void placeWindowAfter(Object pos, WindowState window) {
609 final int i = mWindows.indexOf(pos);
610 if (localLOGV || DEBUG_FOCUS) Log.v(
611 TAG, "Adding window " + window + " at "
612 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
613 mWindows.add(i+1, window);
614 }
615
616 private void placeWindowBefore(Object pos, WindowState window) {
617 final int i = mWindows.indexOf(pos);
618 if (localLOGV || DEBUG_FOCUS) Log.v(
619 TAG, "Adding window " + window + " at "
620 + i + " of " + mWindows.size() + " (before " + pos + ")");
621 mWindows.add(i, window);
622 }
623
624 //This method finds out the index of a window that has the same app token as
625 //win. used for z ordering the windows in mWindows
626 private int findIdxBasedOnAppTokens(WindowState win) {
627 //use a local variable to cache mWindows
628 ArrayList localmWindows = mWindows;
629 int jmax = localmWindows.size();
630 if(jmax == 0) {
631 return -1;
632 }
633 for(int j = (jmax-1); j >= 0; j--) {
634 WindowState wentry = (WindowState)localmWindows.get(j);
635 if(wentry.mAppToken == win.mAppToken) {
636 return j;
637 }
638 }
639 return -1;
640 }
Romain Guy06882f82009-06-10 13:36:04 -0700641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800642 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
643 final IWindow client = win.mClient;
644 final WindowToken token = win.mToken;
645 final ArrayList localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647 final int N = localmWindows.size();
648 final WindowState attached = win.mAttachedWindow;
649 int i;
650 if (attached == null) {
651 int tokenWindowsPos = token.windows.size();
652 if (token.appWindowToken != null) {
653 int index = tokenWindowsPos-1;
654 if (index >= 0) {
655 // If this application has existing windows, we
656 // simply place the new window on top of them... but
657 // keep the starting window on top.
658 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
659 // Base windows go behind everything else.
660 placeWindowBefore(token.windows.get(0), win);
661 tokenWindowsPos = 0;
662 } else {
663 AppWindowToken atoken = win.mAppToken;
664 if (atoken != null &&
665 token.windows.get(index) == atoken.startingWindow) {
666 placeWindowBefore(token.windows.get(index), win);
667 tokenWindowsPos--;
668 } else {
669 int newIdx = findIdxBasedOnAppTokens(win);
670 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700671 //there is a window above this one associated with the same
672 //apptoken note that the window could be a floating window
673 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 //windows associated with this token.
675 localmWindows.add(newIdx+1, win);
Romain Guy06882f82009-06-10 13:36:04 -0700676 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 }
678 }
679 } else {
680 if (localLOGV) Log.v(
681 TAG, "Figuring out where to add app window "
682 + client.asBinder() + " (token=" + token + ")");
683 // Figure out where the window should go, based on the
684 // order of applications.
685 final int NA = mAppTokens.size();
686 Object pos = null;
687 for (i=NA-1; i>=0; i--) {
688 AppWindowToken t = mAppTokens.get(i);
689 if (t == token) {
690 i--;
691 break;
692 }
693 if (t.windows.size() > 0) {
694 pos = t.windows.get(0);
695 }
696 }
697 // We now know the index into the apps. If we found
698 // an app window above, that gives us the position; else
699 // we need to look some more.
700 if (pos != null) {
701 // Move behind any windows attached to this one.
Romain Guy06882f82009-06-10 13:36:04 -0700702 WindowToken atoken =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800703 mTokenMap.get(((WindowState)pos).mClient.asBinder());
704 if (atoken != null) {
705 final int NC = atoken.windows.size();
706 if (NC > 0) {
707 WindowState bottom = atoken.windows.get(0);
708 if (bottom.mSubLayer < 0) {
709 pos = bottom;
710 }
711 }
712 }
713 placeWindowBefore(pos, win);
714 } else {
715 while (i >= 0) {
716 AppWindowToken t = mAppTokens.get(i);
717 final int NW = t.windows.size();
718 if (NW > 0) {
719 pos = t.windows.get(NW-1);
720 break;
721 }
722 i--;
723 }
724 if (pos != null) {
725 // Move in front of any windows attached to this
726 // one.
727 WindowToken atoken =
728 mTokenMap.get(((WindowState)pos).mClient.asBinder());
729 if (atoken != null) {
730 final int NC = atoken.windows.size();
731 if (NC > 0) {
732 WindowState top = atoken.windows.get(NC-1);
733 if (top.mSubLayer >= 0) {
734 pos = top;
735 }
736 }
737 }
738 placeWindowAfter(pos, win);
739 } else {
740 // Just search for the start of this layer.
741 final int myLayer = win.mBaseLayer;
742 for (i=0; i<N; i++) {
743 WindowState w = (WindowState)localmWindows.get(i);
744 if (w.mBaseLayer > myLayer) {
745 break;
746 }
747 }
748 if (localLOGV || DEBUG_FOCUS) Log.v(
749 TAG, "Adding window " + win + " at "
750 + i + " of " + N);
751 localmWindows.add(i, win);
752 }
753 }
754 }
755 } else {
756 // Figure out where window should go, based on layer.
757 final int myLayer = win.mBaseLayer;
758 for (i=N-1; i>=0; i--) {
759 if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) {
760 i++;
761 break;
762 }
763 }
764 if (i < 0) i = 0;
765 if (localLOGV || DEBUG_FOCUS) Log.v(
766 TAG, "Adding window " + win + " at "
767 + i + " of " + N);
768 localmWindows.add(i, win);
769 }
770 if (addToToken) {
771 token.windows.add(tokenWindowsPos, win);
772 }
773
774 } else {
775 // Figure out this window's ordering relative to the window
776 // it is attached to.
777 final int NA = token.windows.size();
778 final int sublayer = win.mSubLayer;
779 int largestSublayer = Integer.MIN_VALUE;
780 WindowState windowWithLargestSublayer = null;
781 for (i=0; i<NA; i++) {
782 WindowState w = token.windows.get(i);
783 final int wSublayer = w.mSubLayer;
784 if (wSublayer >= largestSublayer) {
785 largestSublayer = wSublayer;
786 windowWithLargestSublayer = w;
787 }
788 if (sublayer < 0) {
789 // For negative sublayers, we go below all windows
790 // in the same sublayer.
791 if (wSublayer >= sublayer) {
792 if (addToToken) {
793 token.windows.add(i, win);
794 }
795 placeWindowBefore(
796 wSublayer >= 0 ? attached : w, win);
797 break;
798 }
799 } else {
800 // For positive sublayers, we go above all windows
801 // in the same sublayer.
802 if (wSublayer > sublayer) {
803 if (addToToken) {
804 token.windows.add(i, win);
805 }
806 placeWindowBefore(w, win);
807 break;
808 }
809 }
810 }
811 if (i >= NA) {
812 if (addToToken) {
813 token.windows.add(win);
814 }
815 if (sublayer < 0) {
816 placeWindowBefore(attached, win);
817 } else {
818 placeWindowAfter(largestSublayer >= 0
819 ? windowWithLargestSublayer
820 : attached,
821 win);
822 }
823 }
824 }
Romain Guy06882f82009-06-10 13:36:04 -0700825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800826 if (win.mAppToken != null && addToToken) {
827 win.mAppToken.allAppWindows.add(win);
828 }
829 }
Romain Guy06882f82009-06-10 13:36:04 -0700830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831 static boolean canBeImeTarget(WindowState w) {
832 final int fl = w.mAttrs.flags
833 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
834 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
835 return w.isVisibleOrAdding();
836 }
837 return false;
838 }
Romain Guy06882f82009-06-10 13:36:04 -0700839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
841 final ArrayList localmWindows = mWindows;
842 final int N = localmWindows.size();
843 WindowState w = null;
844 int i = N;
845 while (i > 0) {
846 i--;
847 w = (WindowState)localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 //Log.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
850 // + Integer.toHexString(w.mAttrs.flags));
851 if (canBeImeTarget(w)) {
852 //Log.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 // Yet more tricksyness! If this window is a "starting"
855 // window, we do actually want to be on top of it, but
856 // it is not -really- where input will go. So if the caller
857 // is not actually looking to move the IME, look down below
858 // for a real window to target...
859 if (!willMove
860 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
861 && i > 0) {
862 WindowState wb = (WindowState)localmWindows.get(i-1);
863 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
864 i--;
865 w = wb;
866 }
867 }
868 break;
869 }
870 }
Romain Guy06882f82009-06-10 13:36:04 -0700871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800872 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800874 if (DEBUG_INPUT_METHOD) Log.v(TAG, "Desired input method target="
875 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 if (willMove && w != null) {
878 final WindowState curTarget = mInputMethodTarget;
879 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800881 // Now some fun for dealing with window animations that
882 // modify the Z order. We need to look at all windows below
883 // the current target that are in this app, finding the highest
884 // visible one in layering.
885 AppWindowToken token = curTarget.mAppToken;
886 WindowState highestTarget = null;
887 int highestPos = 0;
888 if (token.animating || token.animation != null) {
889 int pos = 0;
890 pos = localmWindows.indexOf(curTarget);
891 while (pos >= 0) {
892 WindowState win = (WindowState)localmWindows.get(pos);
893 if (win.mAppToken != token) {
894 break;
895 }
896 if (!win.mRemoved) {
897 if (highestTarget == null || win.mAnimLayer >
898 highestTarget.mAnimLayer) {
899 highestTarget = win;
900 highestPos = pos;
901 }
902 }
903 pos--;
904 }
905 }
Romain Guy06882f82009-06-10 13:36:04 -0700906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800907 if (highestTarget != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700908 if (DEBUG_INPUT_METHOD) Log.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800909 + mNextAppTransition + " " + highestTarget
910 + " animating=" + highestTarget.isAnimating()
911 + " layer=" + highestTarget.mAnimLayer
912 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800914 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) {
915 // If we are currently setting up for an animation,
916 // hold everything until we can find out what will happen.
917 mInputMethodTargetWaitingAnim = true;
918 mInputMethodTarget = highestTarget;
919 return highestPos + 1;
920 } else if (highestTarget.isAnimating() &&
921 highestTarget.mAnimLayer > w.mAnimLayer) {
922 // If the window we are currently targeting is involved
923 // with an animation, and it is on top of the next target
924 // we will be over, then hold off on moving until
925 // that is done.
926 mInputMethodTarget = highestTarget;
927 return highestPos + 1;
928 }
929 }
930 }
931 }
Romain Guy06882f82009-06-10 13:36:04 -0700932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 //Log.i(TAG, "Placing input method @" + (i+1));
934 if (w != null) {
935 if (willMove) {
936 RuntimeException e = new RuntimeException();
937 e.fillInStackTrace();
938 if (DEBUG_INPUT_METHOD) Log.w(TAG, "Moving IM target from "
939 + mInputMethodTarget + " to " + w, e);
940 mInputMethodTarget = w;
941 if (w.mAppToken != null) {
942 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
943 } else {
944 setInputMethodAnimLayerAdjustment(0);
945 }
946 }
947 return i+1;
948 }
949 if (willMove) {
950 RuntimeException e = new RuntimeException();
951 e.fillInStackTrace();
952 if (DEBUG_INPUT_METHOD) Log.w(TAG, "Moving IM target from "
953 + mInputMethodTarget + " to null", e);
954 mInputMethodTarget = null;
955 setInputMethodAnimLayerAdjustment(0);
956 }
957 return -1;
958 }
Romain Guy06882f82009-06-10 13:36:04 -0700959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800960 void addInputMethodWindowToListLocked(WindowState win) {
961 int pos = findDesiredInputMethodWindowIndexLocked(true);
962 if (pos >= 0) {
963 win.mTargetAppToken = mInputMethodTarget.mAppToken;
964 mWindows.add(pos, win);
965 moveInputMethodDialogsLocked(pos+1);
966 return;
967 }
968 win.mTargetAppToken = null;
969 addWindowToListInOrderLocked(win, true);
970 moveInputMethodDialogsLocked(pos);
971 }
Romain Guy06882f82009-06-10 13:36:04 -0700972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800973 void setInputMethodAnimLayerAdjustment(int adj) {
974 if (DEBUG_LAYERS) Log.v(TAG, "Setting im layer adj to " + adj);
975 mInputMethodAnimLayerAdjustment = adj;
976 WindowState imw = mInputMethodWindow;
977 if (imw != null) {
978 imw.mAnimLayer = imw.mLayer + adj;
979 if (DEBUG_LAYERS) Log.v(TAG, "IM win " + imw
980 + " anim layer: " + imw.mAnimLayer);
981 int wi = imw.mChildWindows.size();
982 while (wi > 0) {
983 wi--;
984 WindowState cw = (WindowState)imw.mChildWindows.get(wi);
985 cw.mAnimLayer = cw.mLayer + adj;
986 if (DEBUG_LAYERS) Log.v(TAG, "IM win " + cw
987 + " anim layer: " + cw.mAnimLayer);
988 }
989 }
990 int di = mInputMethodDialogs.size();
991 while (di > 0) {
992 di --;
993 imw = mInputMethodDialogs.get(di);
994 imw.mAnimLayer = imw.mLayer + adj;
995 if (DEBUG_LAYERS) Log.v(TAG, "IM win " + imw
996 + " anim layer: " + imw.mAnimLayer);
997 }
998 }
Romain Guy06882f82009-06-10 13:36:04 -0700999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1001 int wpos = mWindows.indexOf(win);
1002 if (wpos >= 0) {
1003 if (wpos < interestingPos) interestingPos--;
1004 mWindows.remove(wpos);
1005 int NC = win.mChildWindows.size();
1006 while (NC > 0) {
1007 NC--;
1008 WindowState cw = (WindowState)win.mChildWindows.get(NC);
1009 int cpos = mWindows.indexOf(cw);
1010 if (cpos >= 0) {
1011 if (cpos < interestingPos) interestingPos--;
1012 mWindows.remove(cpos);
1013 }
1014 }
1015 }
1016 return interestingPos;
1017 }
Romain Guy06882f82009-06-10 13:36:04 -07001018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001019 private void reAddWindowToListInOrderLocked(WindowState win) {
1020 addWindowToListInOrderLocked(win, false);
1021 // This is a hack to get all of the child windows added as well
1022 // at the right position. Child windows should be rare and
1023 // this case should be rare, so it shouldn't be that big a deal.
1024 int wpos = mWindows.indexOf(win);
1025 if (wpos >= 0) {
1026 mWindows.remove(wpos);
1027 reAddWindowLocked(wpos, win);
1028 }
1029 }
Romain Guy06882f82009-06-10 13:36:04 -07001030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001031 void logWindowList(String prefix) {
1032 int N = mWindows.size();
1033 while (N > 0) {
1034 N--;
1035 Log.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
1036 }
1037 }
Romain Guy06882f82009-06-10 13:36:04 -07001038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039 void moveInputMethodDialogsLocked(int pos) {
1040 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001042 final int N = dialogs.size();
1043 if (DEBUG_INPUT_METHOD) Log.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
1044 for (int i=0; i<N; i++) {
1045 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1046 }
1047 if (DEBUG_INPUT_METHOD) {
1048 Log.v(TAG, "Window list w/pos=" + pos);
1049 logWindowList(" ");
1050 }
Romain Guy06882f82009-06-10 13:36:04 -07001051
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001052 if (pos >= 0) {
1053 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1054 if (pos < mWindows.size()) {
1055 WindowState wp = (WindowState)mWindows.get(pos);
1056 if (wp == mInputMethodWindow) {
1057 pos++;
1058 }
1059 }
1060 if (DEBUG_INPUT_METHOD) Log.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
1061 for (int i=0; i<N; i++) {
1062 WindowState win = dialogs.get(i);
1063 win.mTargetAppToken = targetAppToken;
1064 pos = reAddWindowLocked(pos, win);
1065 }
1066 if (DEBUG_INPUT_METHOD) {
1067 Log.v(TAG, "Final window list:");
1068 logWindowList(" ");
1069 }
1070 return;
1071 }
1072 for (int i=0; i<N; i++) {
1073 WindowState win = dialogs.get(i);
1074 win.mTargetAppToken = null;
1075 reAddWindowToListInOrderLocked(win);
1076 if (DEBUG_INPUT_METHOD) {
1077 Log.v(TAG, "No IM target, final list:");
1078 logWindowList(" ");
1079 }
1080 }
1081 }
Romain Guy06882f82009-06-10 13:36:04 -07001082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1084 final WindowState imWin = mInputMethodWindow;
1085 final int DN = mInputMethodDialogs.size();
1086 if (imWin == null && DN == 0) {
1087 return false;
1088 }
Romain Guy06882f82009-06-10 13:36:04 -07001089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001090 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1091 if (imPos >= 0) {
1092 // In this case, the input method windows are to be placed
1093 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 // First check to see if the input method windows are already
1096 // located here, and contiguous.
1097 final int N = mWindows.size();
1098 WindowState firstImWin = imPos < N
1099 ? (WindowState)mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 // Figure out the actual input method window that should be
1102 // at the bottom of their stack.
1103 WindowState baseImWin = imWin != null
1104 ? imWin : mInputMethodDialogs.get(0);
1105 if (baseImWin.mChildWindows.size() > 0) {
1106 WindowState cw = (WindowState)baseImWin.mChildWindows.get(0);
1107 if (cw.mSubLayer < 0) baseImWin = cw;
1108 }
Romain Guy06882f82009-06-10 13:36:04 -07001109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001110 if (firstImWin == baseImWin) {
1111 // The windows haven't moved... but are they still contiguous?
1112 // First find the top IM window.
1113 int pos = imPos+1;
1114 while (pos < N) {
1115 if (!((WindowState)mWindows.get(pos)).mIsImWindow) {
1116 break;
1117 }
1118 pos++;
1119 }
1120 pos++;
1121 // Now there should be no more input method windows above.
1122 while (pos < N) {
1123 if (((WindowState)mWindows.get(pos)).mIsImWindow) {
1124 break;
1125 }
1126 pos++;
1127 }
1128 if (pos >= N) {
1129 // All is good!
1130 return false;
1131 }
1132 }
Romain Guy06882f82009-06-10 13:36:04 -07001133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 if (imWin != null) {
1135 if (DEBUG_INPUT_METHOD) {
1136 Log.v(TAG, "Moving IM from " + imPos);
1137 logWindowList(" ");
1138 }
1139 imPos = tmpRemoveWindowLocked(imPos, imWin);
1140 if (DEBUG_INPUT_METHOD) {
1141 Log.v(TAG, "List after moving with new pos " + imPos + ":");
1142 logWindowList(" ");
1143 }
1144 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1145 reAddWindowLocked(imPos, imWin);
1146 if (DEBUG_INPUT_METHOD) {
1147 Log.v(TAG, "List after moving IM to " + imPos + ":");
1148 logWindowList(" ");
1149 }
1150 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1151 } else {
1152 moveInputMethodDialogsLocked(imPos);
1153 }
Romain Guy06882f82009-06-10 13:36:04 -07001154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 } else {
1156 // In this case, the input method windows go in a fixed layer,
1157 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 if (imWin != null) {
1160 if (DEBUG_INPUT_METHOD) Log.v(TAG, "Moving IM from " + imPos);
1161 tmpRemoveWindowLocked(0, imWin);
1162 imWin.mTargetAppToken = null;
1163 reAddWindowToListInOrderLocked(imWin);
1164 if (DEBUG_INPUT_METHOD) {
1165 Log.v(TAG, "List with no IM target:");
1166 logWindowList(" ");
1167 }
1168 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1169 } else {
1170 moveInputMethodDialogsLocked(-1);;
1171 }
Romain Guy06882f82009-06-10 13:36:04 -07001172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 }
Romain Guy06882f82009-06-10 13:36:04 -07001174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 if (needAssignLayers) {
1176 assignLayersLocked();
1177 }
Romain Guy06882f82009-06-10 13:36:04 -07001178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179 return true;
1180 }
Romain Guy06882f82009-06-10 13:36:04 -07001181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 void adjustInputMethodDialogsLocked() {
1183 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1184 }
Romain Guy06882f82009-06-10 13:36:04 -07001185
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001186 boolean adjustWallpaperWindowsLocked() {
1187 boolean changed = false;
1188
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001189 final int dw = mDisplay.getWidth();
1190 final int dh = mDisplay.getHeight();
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001191
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001192 // First find top-most window that has asked to be on top of the
1193 // wallpaper; all wallpapers go behind it.
1194 final ArrayList localmWindows = mWindows;
1195 int N = localmWindows.size();
1196 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001197 WindowState foundW = null;
1198 int foundI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001199 int i = N;
1200 while (i > 0) {
1201 i--;
1202 w = (WindowState)localmWindows.get(i);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001203 if (w.mAppToken != null) {
1204 // If this window's app token is hidden and not animating,
1205 // it is of no interest to us.
1206 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
1207 if (DEBUG_WALLPAPER) Log.v(TAG,
1208 "Skipping hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001209 continue;
1210 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001211 // If this window's app token is ot fullscreen, also irrelevant.
1212 if (!w.mAppToken.appFullscreen) {
1213 if (DEBUG_WALLPAPER) Log.v(TAG,
1214 "Skipping non-fullscreen token: " + w);
1215 continue;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001216 }
1217 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001218 if (DEBUG_WALLPAPER) Log.v(TAG, "Win " + w + ": readyfordisplay="
1219 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1220 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001221 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001222 && (mWallpaperTarget == w
1223 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001224 if (DEBUG_WALLPAPER) Log.v(TAG,
1225 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001226 foundW = w;
1227 foundI = i;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001228 if (w == mWallpaperTarget && w.mAppToken != null
1229 && w.mAppToken.animation != null) {
1230 // The current wallpaper target is animating, so we'll
1231 // look behind it for another possible target and figure
1232 // out what is going on below.
1233 if (DEBUG_WALLPAPER) Log.v(TAG, "Win " + w
1234 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001235 continue;
1236 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001237 break;
1238 }
1239 }
1240
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001241 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) {
1242 // If we are currently waiting for an app transition, and either
1243 // the current target or the next target are involved with it,
1244 // then hold off on doing anything with the wallpaper.
1245 // Note that we are checking here for just whether the target
1246 // is part of an app token... which is potentially overly aggressive
1247 // (the app token may not be involved in the transition), but good
1248 // enough (we'll just wait until whatever transition is pending
1249 // executes).
1250 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001251 if (DEBUG_WALLPAPER) Log.v(TAG,
1252 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001253 return false;
1254 }
1255 if (foundW != null && foundW.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001256 if (DEBUG_WALLPAPER) Log.v(TAG,
1257 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001258 return false;
1259 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001260 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001261
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001262 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001263 if (DEBUG_WALLPAPER) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001264 Log.v(TAG, "New wallpaper target: " + foundW
1265 + " oldTarget: " + mWallpaperTarget);
1266 }
1267
1268 mLowerWallpaperTarget = null;
1269 mUpperWallpaperTarget = null;
1270
1271 WindowState oldW = mWallpaperTarget;
1272 mWallpaperTarget = foundW;
1273
1274 // Now what is happening... if the current and new targets are
1275 // animating, then we are in our super special mode!
1276 if (foundW != null && foundW.mAppToken != null && oldW != null
1277 && oldW.mAppToken != null) {
1278 if (DEBUG_WALLPAPER) {
1279 Log.v(TAG, "New animation: " + foundW.mAppToken.animation
1280 + " old animation: " + oldW.mAppToken.animation);
1281 }
1282 if (foundW.mAppToken.animation != null
1283 && oldW.mAppToken.animation != null) {
1284 int oldI = localmWindows.indexOf(oldW);
1285 if (DEBUG_WALLPAPER) {
1286 Log.v(TAG, "New i: " + foundI + " old i: " + oldI);
1287 }
1288 if (oldI >= 0) {
1289 if (DEBUG_WALLPAPER) {
1290 Log.v(TAG, "Animating wallpapers: old#" + oldI
1291 + "=" + oldW + "; new#" + foundI
1292 + "=" + foundW);
1293 }
1294
1295 // Set the new target correctly.
1296 if (foundW.mAppToken.hiddenRequested) {
1297 if (DEBUG_WALLPAPER) {
1298 Log.v(TAG, "Old wallpaper still the target.");
1299 }
1300 mWallpaperTarget = oldW;
1301 }
1302
1303 // Now set the upper and lower wallpaper targets
1304 // correctly, and make sure that we are positioning
1305 // the wallpaper below the lower.
1306 if (foundI > oldI) {
1307 // The new target is on top of the old one.
1308 if (DEBUG_WALLPAPER) {
1309 Log.v(TAG, "Found target above old target.");
1310 }
1311 mUpperWallpaperTarget = foundW;
1312 mLowerWallpaperTarget = oldW;
1313 foundW = oldW;
1314 foundI = oldI;
1315 } else {
1316 // The new target is below the old one.
1317 if (DEBUG_WALLPAPER) {
1318 Log.v(TAG, "Found target below old target.");
1319 }
1320 mUpperWallpaperTarget = oldW;
1321 mLowerWallpaperTarget = foundW;
1322 }
1323 }
1324 }
1325 }
1326
1327 } else {
1328 // Is it time to stop animating?
1329 if (mLowerWallpaperTarget == null
1330 || mLowerWallpaperTarget.mAppToken.animation == null
1331 || mUpperWallpaperTarget == null
1332 || mUpperWallpaperTarget.mAppToken.animation == null) {
1333 if (DEBUG_WALLPAPER) {
1334 Log.v(TAG, "No longer animating wallpaper targets!");
1335 }
1336 mLowerWallpaperTarget = null;
1337 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001338 }
1339 }
1340
1341 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001342 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001343 // The window is visible to the compositor... but is it visible
1344 // to the user? That is what the wallpaper cares about.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001345 visible = !foundW.mObscured;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001346 if (DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper visibility: " + visible);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001347
1348 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001349 // its layer adjustment. Only do this if we are not transfering
1350 // between two wallpaper targets.
1351 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001352 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001353 ? foundW.mAppToken.animLayerAdjustment : 0;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001354
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001355 // Now w is the window we are supposed to be behind... but we
1356 // need to be sure to also be behind any of its attached windows,
1357 // AND any starting window associated with it.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001358 while (foundI > 0) {
1359 WindowState wb = (WindowState)localmWindows.get(foundI-1);
1360 if (wb.mAttachedWindow != foundW &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001361 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001362 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001363 // This window is not related to the previous one in any
1364 // interesting way, so stop here.
1365 break;
1366 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001367 foundW = wb;
1368 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001369 }
1370 }
1371
1372 // Okay i is the position immediately above the wallpaper. Look at
1373 // what is below it for later.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001374 foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001375
Dianne Hackborn284ac932009-08-28 10:34:25 -07001376 if (visible) {
1377 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
1378 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
1379 }
1380
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001381 // Start stepping backwards from here, ensuring that our wallpaper windows
1382 // are correctly placed.
1383 int curTokenIndex = mWallpaperTokens.size();
1384 while (curTokenIndex > 0) {
1385 curTokenIndex--;
1386 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1387 int curWallpaperIndex = token.windows.size();
1388 while (curWallpaperIndex > 0) {
1389 curWallpaperIndex--;
1390 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001391
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001392 if (visible) {
Dianne Hackborn284ac932009-08-28 10:34:25 -07001393 updateWallpaperOffsetLocked(wallpaper, dw, dh);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001394 }
1395
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001396 // First, make sure the client has the current visibility
1397 // state.
1398 if (wallpaper.mWallpaperVisible != visible) {
1399 wallpaper.mWallpaperVisible = visible;
1400 try {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001401 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Log.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001402 "Setting visibility of wallpaper " + wallpaper
1403 + ": " + visible);
1404 wallpaper.mClient.dispatchAppVisibility(visible);
1405 } catch (RemoteException e) {
1406 }
1407 }
1408
1409 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001410 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper win "
1411 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001412
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001413 // First, if this window is at the current index, then all
1414 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001415 if (wallpaper == foundW) {
1416 foundI--;
1417 foundW = foundI > 0
1418 ? (WindowState)localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001419 continue;
1420 }
1421
1422 // The window didn't match... the current wallpaper window,
1423 // wherever it is, is in the wrong place, so make sure it is
1424 // not in the list.
1425 int oldIndex = localmWindows.indexOf(wallpaper);
1426 if (oldIndex >= 0) {
1427 localmWindows.remove(oldIndex);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001428 if (oldIndex < foundI) {
1429 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001430 }
1431 }
1432
1433 // Now stick it in.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001434 if (DEBUG_WALLPAPER) Log.v(TAG, "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001435 + " from " + oldIndex + " to " + foundI);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001436
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001437 localmWindows.add(foundI, wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001438 changed = true;
1439 }
1440 }
1441
1442 return changed;
1443 }
1444
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001445 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001446 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Log.v(TAG,
1447 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001448 mWallpaperAnimLayerAdjustment = adj;
1449 int curTokenIndex = mWallpaperTokens.size();
1450 while (curTokenIndex > 0) {
1451 curTokenIndex--;
1452 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1453 int curWallpaperIndex = token.windows.size();
1454 while (curWallpaperIndex > 0) {
1455 curWallpaperIndex--;
1456 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1457 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001458 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper win "
1459 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001460 }
1461 }
1462 }
1463
Dianne Hackborn284ac932009-08-28 10:34:25 -07001464 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001465 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001466 boolean rawChanged = false;
Dianne Hackborn284ac932009-08-28 10:34:25 -07001467 if (mLastWallpaperX >= 0) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001468 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
Dianne Hackborn284ac932009-08-28 10:34:25 -07001469 int offset = availw > 0 ? -(int)(availw*mLastWallpaperX+.5f) : 0;
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001470 changed = wallpaperWin.mXOffset != offset;
1471 if (changed) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001472 if (DEBUG_WALLPAPER) Log.v(TAG, "Update wallpaper "
1473 + wallpaperWin + " x: " + offset);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001474 wallpaperWin.mXOffset = offset;
1475 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001476 if (wallpaperWin.mWallpaperX != mLastWallpaperX) {
1477 wallpaperWin.mWallpaperX = mLastWallpaperX;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001478 rawChanged = true;
1479 }
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001480 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001481
Dianne Hackborn284ac932009-08-28 10:34:25 -07001482 if (mLastWallpaperY >= 0) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001483 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
Dianne Hackborn284ac932009-08-28 10:34:25 -07001484 int offset = availh > 0 ? -(int)(availh*mLastWallpaperY+.5f) : 0;
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001485 if (wallpaperWin.mYOffset != offset) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001486 if (DEBUG_WALLPAPER) Log.v(TAG, "Update wallpaper "
1487 + wallpaperWin + " y: " + offset);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001488 changed = true;
1489 wallpaperWin.mYOffset = offset;
1490 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001491 if (wallpaperWin.mWallpaperY != mLastWallpaperY) {
1492 wallpaperWin.mWallpaperY = mLastWallpaperY;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001493 rawChanged = true;
1494 }
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001495 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001496
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001497 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001498 try {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001499 if (DEBUG_WALLPAPER) Log.v(TAG, "Report new wp offset "
1500 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1501 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001502 wallpaperWin.mClient.dispatchWallpaperOffsets(
1503 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY);
1504 } catch (RemoteException e) {
1505 }
1506 }
1507
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001508 return changed;
1509 }
1510
1511 boolean updateWallpaperOffsetLocked() {
1512 final int dw = mDisplay.getWidth();
1513 final int dh = mDisplay.getHeight();
1514
1515 boolean changed = false;
1516
1517 WindowState target = mWallpaperTarget;
1518 if (target != null) {
Dianne Hackborn284ac932009-08-28 10:34:25 -07001519 mLastWallpaperX = target.mWallpaperX;
1520 mLastWallpaperY = target.mWallpaperY;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001521 int curTokenIndex = mWallpaperTokens.size();
1522 while (curTokenIndex > 0) {
1523 curTokenIndex--;
1524 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1525 int curWallpaperIndex = token.windows.size();
1526 while (curWallpaperIndex > 0) {
1527 curWallpaperIndex--;
1528 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Dianne Hackborn284ac932009-08-28 10:34:25 -07001529 if (updateWallpaperOffsetLocked(wallpaper, dw, dh)) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001530 wallpaper.computeShownFrameLocked();
1531 changed = true;
1532 }
1533 }
1534 }
1535 }
1536
1537 return changed;
1538 }
1539
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001540 void updateWallpaperVisibilityLocked() {
1541 final boolean visible = mWallpaperTarget != null
1542 && !mWallpaperTarget.mObscured;
1543 final int dw = mDisplay.getWidth();
1544 final int dh = mDisplay.getHeight();
1545
1546 int curTokenIndex = mWallpaperTokens.size();
1547 while (curTokenIndex > 0) {
1548 curTokenIndex--;
1549 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1550 int curWallpaperIndex = token.windows.size();
1551 while (curWallpaperIndex > 0) {
1552 curWallpaperIndex--;
1553 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1554 if (visible) {
Dianne Hackborn284ac932009-08-28 10:34:25 -07001555 updateWallpaperOffsetLocked(wallpaper, dw, dh);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001556 }
1557
1558 if (wallpaper.mWallpaperVisible != visible) {
1559 wallpaper.mWallpaperVisible = visible;
1560 try {
1561 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Log.v(TAG,
1562 "Setting visibility of wallpaper " + wallpaper
1563 + ": " + visible);
1564 wallpaper.mClient.dispatchAppVisibility(visible);
1565 } catch (RemoteException e) {
1566 }
1567 }
1568 }
1569 }
1570 }
1571
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001572 void sendPointerToWallpaperLocked(WindowState srcWin,
1573 MotionEvent pointer, long eventTime) {
1574 int curTokenIndex = mWallpaperTokens.size();
1575 while (curTokenIndex > 0) {
1576 curTokenIndex--;
1577 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1578 int curWallpaperIndex = token.windows.size();
1579 while (curWallpaperIndex > 0) {
1580 curWallpaperIndex--;
1581 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1582 if ((wallpaper.mAttrs.flags &
1583 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
1584 continue;
1585 }
1586 try {
1587 MotionEvent ev = MotionEvent.obtainNoHistory(pointer);
1588 ev.offsetLocation(srcWin.mFrame.left-wallpaper.mFrame.left,
1589 srcWin.mFrame.top-wallpaper.mFrame.top);
1590 wallpaper.mClient.dispatchPointer(ev, eventTime, false);
1591 } catch (RemoteException e) {
1592 Log.w(TAG, "Failure sending pointer to wallpaper", e);
1593 }
1594 }
1595 }
1596 }
1597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001598 public int addWindow(Session session, IWindow client,
1599 WindowManager.LayoutParams attrs, int viewVisibility,
1600 Rect outContentInsets) {
1601 int res = mPolicy.checkAddPermission(attrs);
1602 if (res != WindowManagerImpl.ADD_OKAY) {
1603 return res;
1604 }
Romain Guy06882f82009-06-10 13:36:04 -07001605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001606 boolean reportNewConfig = false;
1607 WindowState attachedWindow = null;
1608 WindowState win = null;
Romain Guy06882f82009-06-10 13:36:04 -07001609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001610 synchronized(mWindowMap) {
1611 // Instantiating a Display requires talking with the simulator,
1612 // so don't do it until we know the system is mostly up and
1613 // running.
1614 if (mDisplay == null) {
1615 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1616 mDisplay = wm.getDefaultDisplay();
1617 mQueue.setDisplay(mDisplay);
1618 reportNewConfig = true;
1619 }
Romain Guy06882f82009-06-10 13:36:04 -07001620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001621 if (mWindowMap.containsKey(client.asBinder())) {
1622 Log.w(TAG, "Window " + client + " is already added");
1623 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1624 }
1625
1626 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Romain Guy06882f82009-06-10 13:36:04 -07001627 attachedWindow = windowForClientLocked(null, attrs.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001628 if (attachedWindow == null) {
1629 Log.w(TAG, "Attempted to add window with token that is not a window: "
1630 + attrs.token + ". Aborting.");
1631 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1632 }
1633 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1634 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
1635 Log.w(TAG, "Attempted to add window with token that is a sub-window: "
1636 + attrs.token + ". Aborting.");
1637 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1638 }
1639 }
1640
1641 boolean addToken = false;
1642 WindowToken token = mTokenMap.get(attrs.token);
1643 if (token == null) {
1644 if (attrs.type >= FIRST_APPLICATION_WINDOW
1645 && attrs.type <= LAST_APPLICATION_WINDOW) {
1646 Log.w(TAG, "Attempted to add application window with unknown token "
1647 + attrs.token + ". Aborting.");
1648 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1649 }
1650 if (attrs.type == TYPE_INPUT_METHOD) {
1651 Log.w(TAG, "Attempted to add input method window with unknown token "
1652 + attrs.token + ". Aborting.");
1653 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1654 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001655 if (attrs.type == TYPE_WALLPAPER) {
1656 Log.w(TAG, "Attempted to add wallpaper window with unknown token "
1657 + attrs.token + ". Aborting.");
1658 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1659 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001660 token = new WindowToken(attrs.token, -1, false);
1661 addToken = true;
1662 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1663 && attrs.type <= LAST_APPLICATION_WINDOW) {
1664 AppWindowToken atoken = token.appWindowToken;
1665 if (atoken == null) {
1666 Log.w(TAG, "Attempted to add window with non-application token "
1667 + token + ". Aborting.");
1668 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1669 } else if (atoken.removed) {
1670 Log.w(TAG, "Attempted to add window with exiting application token "
1671 + token + ". Aborting.");
1672 return WindowManagerImpl.ADD_APP_EXITING;
1673 }
1674 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1675 // No need for this guy!
1676 if (localLOGV) Log.v(
1677 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1678 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1679 }
1680 } else if (attrs.type == TYPE_INPUT_METHOD) {
1681 if (token.windowType != TYPE_INPUT_METHOD) {
1682 Log.w(TAG, "Attempted to add input method window with bad token "
1683 + attrs.token + ". Aborting.");
1684 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1685 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001686 } else if (attrs.type == TYPE_WALLPAPER) {
1687 if (token.windowType != TYPE_WALLPAPER) {
1688 Log.w(TAG, "Attempted to add wallpaper window with bad token "
1689 + attrs.token + ". Aborting.");
1690 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1691 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001692 }
1693
1694 win = new WindowState(session, client, token,
1695 attachedWindow, attrs, viewVisibility);
1696 if (win.mDeathRecipient == null) {
1697 // Client has apparently died, so there is no reason to
1698 // continue.
1699 Log.w(TAG, "Adding window client " + client.asBinder()
1700 + " that is dead, aborting.");
1701 return WindowManagerImpl.ADD_APP_EXITING;
1702 }
1703
1704 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001706 res = mPolicy.prepareAddWindowLw(win, attrs);
1707 if (res != WindowManagerImpl.ADD_OKAY) {
1708 return res;
1709 }
1710
1711 // From now on, no exceptions or errors allowed!
1712
1713 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001715 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001717 if (addToken) {
1718 mTokenMap.put(attrs.token, token);
1719 mTokenList.add(token);
1720 }
1721 win.attach();
1722 mWindowMap.put(client.asBinder(), win);
1723
1724 if (attrs.type == TYPE_APPLICATION_STARTING &&
1725 token.appWindowToken != null) {
1726 token.appWindowToken.startingWindow = win;
1727 }
1728
1729 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001730
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001731 if (attrs.type == TYPE_INPUT_METHOD) {
1732 mInputMethodWindow = win;
1733 addInputMethodWindowToListLocked(win);
1734 imMayMove = false;
1735 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1736 mInputMethodDialogs.add(win);
1737 addWindowToListInOrderLocked(win, true);
1738 adjustInputMethodDialogsLocked();
1739 imMayMove = false;
1740 } else {
1741 addWindowToListInOrderLocked(win, true);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001742 if (attrs.type == TYPE_WALLPAPER ||
1743 (attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
1744 adjustWallpaperWindowsLocked();
1745 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001746 }
Romain Guy06882f82009-06-10 13:36:04 -07001747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001748 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001750 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001752 if (mInTouchMode) {
1753 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1754 }
1755 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1756 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1757 }
Romain Guy06882f82009-06-10 13:36:04 -07001758
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001759 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001760 if (win.canReceiveKeys()) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001761 if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS))
1762 == true) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001763 imMayMove = false;
1764 }
1765 }
Romain Guy06882f82009-06-10 13:36:04 -07001766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001767 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001768 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001769 }
Romain Guy06882f82009-06-10 13:36:04 -07001770
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001771 assignLayersLocked();
1772 // Don't do layout here, the window must call
1773 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07001774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001775 //dump();
1776
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001777 if (focusChanged) {
1778 if (mCurrentFocus != null) {
1779 mKeyWaiter.handleNewWindowLocked(mCurrentFocus);
1780 }
1781 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001782 if (localLOGV) Log.v(
1783 TAG, "New client " + client.asBinder()
1784 + ": window=" + win);
1785 }
1786
1787 // sendNewConfiguration() checks caller permissions so we must call it with
1788 // privilege. updateOrientationFromAppTokens() clears and resets the caller
1789 // identity anyway, so it's safe to just clear & restore around this whole
1790 // block.
1791 final long origId = Binder.clearCallingIdentity();
1792 if (reportNewConfig) {
1793 sendNewConfiguration();
1794 } else {
1795 // Update Orientation after adding a window, only if the window needs to be
1796 // displayed right away
1797 if (win.isVisibleOrAdding()) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07001798 if (updateOrientationFromAppTokensUnchecked(null, null) != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001799 sendNewConfiguration();
1800 }
1801 }
1802 }
1803 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07001804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001805 return res;
1806 }
Romain Guy06882f82009-06-10 13:36:04 -07001807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001808 public void removeWindow(Session session, IWindow client) {
1809 synchronized(mWindowMap) {
1810 WindowState win = windowForClientLocked(session, client);
1811 if (win == null) {
1812 return;
1813 }
1814 removeWindowLocked(session, win);
1815 }
1816 }
Romain Guy06882f82009-06-10 13:36:04 -07001817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001818 public void removeWindowLocked(Session session, WindowState win) {
1819
1820 if (localLOGV || DEBUG_FOCUS) Log.v(
1821 TAG, "Remove " + win + " client="
1822 + Integer.toHexString(System.identityHashCode(
1823 win.mClient.asBinder()))
1824 + ", surface=" + win.mSurface);
1825
1826 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001827
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001828 if (DEBUG_APP_TRANSITIONS) Log.v(
1829 TAG, "Remove " + win + ": mSurface=" + win.mSurface
1830 + " mExiting=" + win.mExiting
1831 + " isAnimating=" + win.isAnimating()
1832 + " app-animation="
1833 + (win.mAppToken != null ? win.mAppToken.animation : null)
1834 + " inPendingTransaction="
1835 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
1836 + " mDisplayFrozen=" + mDisplayFrozen);
1837 // Visibility of the removed window. Will be used later to update orientation later on.
1838 boolean wasVisible = false;
1839 // First, see if we need to run an animation. If we do, we have
1840 // to hold off on removing the window until the animation is done.
1841 // If the display is frozen, just remove immediately, since the
1842 // animation wouldn't be seen.
1843 if (win.mSurface != null && !mDisplayFrozen) {
1844 // If we are not currently running the exit animation, we
1845 // need to see about starting one.
1846 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07001847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001848 int transit = WindowManagerPolicy.TRANSIT_EXIT;
1849 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
1850 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
1851 }
1852 // Try starting an animation.
1853 if (applyAnimationLocked(win, transit, false)) {
1854 win.mExiting = true;
1855 }
1856 }
1857 if (win.mExiting || win.isAnimating()) {
1858 // The exit animation is running... wait for it!
1859 //Log.i(TAG, "*** Running exit animation...");
1860 win.mExiting = true;
1861 win.mRemoveOnExit = true;
1862 mLayoutNeeded = true;
1863 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
1864 performLayoutAndPlaceSurfacesLocked();
1865 if (win.mAppToken != null) {
1866 win.mAppToken.updateReportedVisibilityLocked();
1867 }
1868 //dump();
1869 Binder.restoreCallingIdentity(origId);
1870 return;
1871 }
1872 }
1873
1874 removeWindowInnerLocked(session, win);
1875 // Removing a visible window will effect the computed orientation
1876 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001877 if (wasVisible && computeForcedAppOrientationLocked()
1878 != mForcedAppOrientation) {
1879 mH.sendMessage(mH.obtainMessage(H.COMPUTE_AND_SEND_NEW_CONFIGURATION));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001880 }
1881 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
1882 Binder.restoreCallingIdentity(origId);
1883 }
Romain Guy06882f82009-06-10 13:36:04 -07001884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001885 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001886 mKeyWaiter.finishedKey(session, win.mClient, true,
1887 KeyWaiter.RETURN_NOTHING);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001888 mKeyWaiter.releasePendingPointerLocked(win.mSession);
1889 mKeyWaiter.releasePendingTrackballLocked(win.mSession);
Romain Guy06882f82009-06-10 13:36:04 -07001890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001891 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07001892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001893 if (mInputMethodTarget == win) {
1894 moveInputMethodWindowsIfNeededLocked(false);
1895 }
Romain Guy06882f82009-06-10 13:36:04 -07001896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001897 mPolicy.removeWindowLw(win);
1898 win.removeLocked();
1899
1900 mWindowMap.remove(win.mClient.asBinder());
1901 mWindows.remove(win);
1902
1903 if (mInputMethodWindow == win) {
1904 mInputMethodWindow = null;
1905 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
1906 mInputMethodDialogs.remove(win);
1907 }
Romain Guy06882f82009-06-10 13:36:04 -07001908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001909 final WindowToken token = win.mToken;
1910 final AppWindowToken atoken = win.mAppToken;
1911 token.windows.remove(win);
1912 if (atoken != null) {
1913 atoken.allAppWindows.remove(win);
1914 }
1915 if (localLOGV) Log.v(
1916 TAG, "**** Removing window " + win + ": count="
1917 + token.windows.size());
1918 if (token.windows.size() == 0) {
1919 if (!token.explicit) {
1920 mTokenMap.remove(token.token);
1921 mTokenList.remove(token);
1922 } else if (atoken != null) {
1923 atoken.firstWindowDrawn = false;
1924 }
1925 }
1926
1927 if (atoken != null) {
1928 if (atoken.startingWindow == win) {
1929 atoken.startingWindow = null;
1930 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
1931 // If this is the last window and we had requested a starting
1932 // transition window, well there is no point now.
1933 atoken.startingData = null;
1934 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
1935 // If this is the last window except for a starting transition
1936 // window, we need to get rid of the starting transition.
1937 if (DEBUG_STARTING_WINDOW) {
1938 Log.v(TAG, "Schedule remove starting " + token
1939 + ": no more real windows");
1940 }
1941 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
1942 mH.sendMessage(m);
1943 }
1944 }
Romain Guy06882f82009-06-10 13:36:04 -07001945
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001946 if (win.mAttrs.type == TYPE_WALLPAPER ||
1947 (win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
1948 adjustWallpaperWindowsLocked();
1949 }
1950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001951 if (!mInLayout) {
1952 assignLayersLocked();
1953 mLayoutNeeded = true;
1954 performLayoutAndPlaceSurfacesLocked();
1955 if (win.mAppToken != null) {
1956 win.mAppToken.updateReportedVisibilityLocked();
1957 }
1958 }
1959 }
1960
1961 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
1962 long origId = Binder.clearCallingIdentity();
1963 try {
1964 synchronized (mWindowMap) {
1965 WindowState w = windowForClientLocked(session, client);
1966 if ((w != null) && (w.mSurface != null)) {
1967 Surface.openTransaction();
1968 try {
1969 w.mSurface.setTransparentRegionHint(region);
1970 } finally {
1971 Surface.closeTransaction();
1972 }
1973 }
1974 }
1975 } finally {
1976 Binder.restoreCallingIdentity(origId);
1977 }
1978 }
1979
1980 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07001981 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001982 Rect visibleInsets) {
1983 long origId = Binder.clearCallingIdentity();
1984 try {
1985 synchronized (mWindowMap) {
1986 WindowState w = windowForClientLocked(session, client);
1987 if (w != null) {
1988 w.mGivenInsetsPending = false;
1989 w.mGivenContentInsets.set(contentInsets);
1990 w.mGivenVisibleInsets.set(visibleInsets);
1991 w.mTouchableInsets = touchableInsets;
1992 mLayoutNeeded = true;
1993 performLayoutAndPlaceSurfacesLocked();
1994 }
1995 }
1996 } finally {
1997 Binder.restoreCallingIdentity(origId);
1998 }
1999 }
Romain Guy06882f82009-06-10 13:36:04 -07002000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001 public void getWindowDisplayFrame(Session session, IWindow client,
2002 Rect outDisplayFrame) {
2003 synchronized(mWindowMap) {
2004 WindowState win = windowForClientLocked(session, client);
2005 if (win == null) {
2006 outDisplayFrame.setEmpty();
2007 return;
2008 }
2009 outDisplayFrame.set(win.mDisplayFrame);
2010 }
2011 }
2012
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002013 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y) {
2014 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2015 window.mWallpaperX = x;
2016 window.mWallpaperY = y;
2017
2018 if (mWallpaperTarget == window) {
2019 if (updateWallpaperOffsetLocked()) {
2020 performLayoutAndPlaceSurfacesLocked();
2021 }
2022 }
2023 }
2024 }
2025
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002026 public int relayoutWindow(Session session, IWindow client,
2027 WindowManager.LayoutParams attrs, int requestedWidth,
2028 int requestedHeight, int viewVisibility, boolean insetsPending,
2029 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
2030 Surface outSurface) {
2031 boolean displayed = false;
2032 boolean inTouchMode;
2033 Configuration newConfig = null;
2034 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002036 synchronized(mWindowMap) {
2037 WindowState win = windowForClientLocked(session, client);
2038 if (win == null) {
2039 return 0;
2040 }
2041 win.mRequestedWidth = requestedWidth;
2042 win.mRequestedHeight = requestedHeight;
2043
2044 if (attrs != null) {
2045 mPolicy.adjustWindowParamsLw(attrs);
2046 }
Romain Guy06882f82009-06-10 13:36:04 -07002047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002048 int attrChanges = 0;
2049 int flagChanges = 0;
2050 if (attrs != null) {
2051 flagChanges = win.mAttrs.flags ^= attrs.flags;
2052 attrChanges = win.mAttrs.copyFrom(attrs);
2053 }
2054
2055 if (localLOGV) Log.v(
2056 TAG, "Relayout given client " + client.asBinder()
2057 + " (" + win.mAttrs.getTitle() + ")");
2058
2059
2060 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2061 win.mAlpha = attrs.alpha;
2062 }
2063
2064 final boolean scaledWindow =
2065 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2066
2067 if (scaledWindow) {
2068 // requested{Width|Height} Surface's physical size
2069 // attrs.{width|height} Size on screen
2070 win.mHScale = (attrs.width != requestedWidth) ?
2071 (attrs.width / (float)requestedWidth) : 1.0f;
2072 win.mVScale = (attrs.height != requestedHeight) ?
2073 (attrs.height / (float)requestedHeight) : 1.0f;
2074 }
2075
2076 boolean imMayMove = (flagChanges&(
2077 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2078 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002080 boolean focusMayChange = win.mViewVisibility != viewVisibility
2081 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2082 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002083
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002084 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2085 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
2086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002087 win.mRelayoutCalled = true;
2088 final int oldVisibility = win.mViewVisibility;
2089 win.mViewVisibility = viewVisibility;
2090 if (viewVisibility == View.VISIBLE &&
2091 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2092 displayed = !win.isVisibleLw();
2093 if (win.mExiting) {
2094 win.mExiting = false;
2095 win.mAnimation = null;
2096 }
2097 if (win.mDestroying) {
2098 win.mDestroying = false;
2099 mDestroySurface.remove(win);
2100 }
2101 if (oldVisibility == View.GONE) {
2102 win.mEnterAnimationPending = true;
2103 }
2104 if (displayed && win.mSurface != null && !win.mDrawPending
2105 && !win.mCommitDrawPending && !mDisplayFrozen) {
2106 applyEnterAnimationLocked(win);
2107 }
2108 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2109 // To change the format, we need to re-build the surface.
2110 win.destroySurfaceLocked();
2111 displayed = true;
2112 }
2113 try {
2114 Surface surface = win.createSurfaceLocked();
2115 if (surface != null) {
2116 outSurface.copyFrom(surface);
2117 } else {
2118 outSurface.clear();
2119 }
2120 } catch (Exception e) {
2121 Log.w(TAG, "Exception thrown when creating surface for client "
2122 + client + " (" + win.mAttrs.getTitle() + ")",
2123 e);
2124 Binder.restoreCallingIdentity(origId);
2125 return 0;
2126 }
2127 if (displayed) {
2128 focusMayChange = true;
2129 }
2130 if (win.mAttrs.type == TYPE_INPUT_METHOD
2131 && mInputMethodWindow == null) {
2132 mInputMethodWindow = win;
2133 imMayMove = true;
2134 }
2135 } else {
2136 win.mEnterAnimationPending = false;
2137 if (win.mSurface != null) {
2138 // If we are not currently running the exit animation, we
2139 // need to see about starting one.
2140 if (!win.mExiting) {
2141 // Try starting an animation; if there isn't one, we
2142 // can destroy the surface right away.
2143 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2144 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2145 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2146 }
2147 if (win.isWinVisibleLw() &&
2148 applyAnimationLocked(win, transit, false)) {
2149 win.mExiting = true;
2150 mKeyWaiter.finishedKey(session, client, true,
2151 KeyWaiter.RETURN_NOTHING);
2152 } else if (win.isAnimating()) {
2153 // Currently in a hide animation... turn this into
2154 // an exit.
2155 win.mExiting = true;
2156 } else {
2157 if (mInputMethodWindow == win) {
2158 mInputMethodWindow = null;
2159 }
2160 win.destroySurfaceLocked();
2161 }
2162 }
2163 }
2164 outSurface.clear();
2165 }
2166
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002167 if (focusMayChange) {
2168 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2169 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002170 imMayMove = false;
2171 }
2172 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2173 }
Romain Guy06882f82009-06-10 13:36:04 -07002174
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002175 // updateFocusedWindowLocked() already assigned layers so we only need to
2176 // reassign them at this point if the IM window state gets shuffled
2177 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002179 if (imMayMove) {
2180 if (moveInputMethodWindowsIfNeededLocked(false)) {
2181 assignLayers = true;
2182 }
2183 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002184 if (wallpaperMayMove) {
2185 if (adjustWallpaperWindowsLocked()) {
2186 assignLayers = true;
2187 }
2188 }
Romain Guy06882f82009-06-10 13:36:04 -07002189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002190 mLayoutNeeded = true;
2191 win.mGivenInsetsPending = insetsPending;
2192 if (assignLayers) {
2193 assignLayersLocked();
2194 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002195 newConfig = updateOrientationFromAppTokensLocked(null, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002196 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002197 if (displayed && win.mIsWallpaper) {
2198 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
2199 mDisplay.getHeight());
2200 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002201 if (win.mAppToken != null) {
2202 win.mAppToken.updateReportedVisibilityLocked();
2203 }
2204 outFrame.set(win.mFrame);
2205 outContentInsets.set(win.mContentInsets);
2206 outVisibleInsets.set(win.mVisibleInsets);
2207 if (localLOGV) Log.v(
2208 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002209 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002210 + ", requestedHeight=" + requestedHeight
2211 + ", viewVisibility=" + viewVisibility
2212 + "\nRelayout returning frame=" + outFrame
2213 + ", surface=" + outSurface);
2214
2215 if (localLOGV || DEBUG_FOCUS) Log.v(
2216 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2217
2218 inTouchMode = mInTouchMode;
2219 }
2220
2221 if (newConfig != null) {
2222 sendNewConfiguration();
2223 }
Romain Guy06882f82009-06-10 13:36:04 -07002224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002225 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002227 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2228 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2229 }
2230
2231 public void finishDrawingWindow(Session session, IWindow client) {
2232 final long origId = Binder.clearCallingIdentity();
2233 synchronized(mWindowMap) {
2234 WindowState win = windowForClientLocked(session, client);
2235 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002236 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2237 adjustWallpaperWindowsLocked();
2238 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002239 mLayoutNeeded = true;
2240 performLayoutAndPlaceSurfacesLocked();
2241 }
2242 }
2243 Binder.restoreCallingIdentity(origId);
2244 }
2245
2246 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
2247 if (DEBUG_ANIM) Log.v(TAG, "Loading animations: params package="
2248 + (lp != null ? lp.packageName : null)
2249 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2250 if (lp != null && lp.windowAnimations != 0) {
2251 // If this is a system resource, don't try to load it from the
2252 // application resources. It is nice to avoid loading application
2253 // resources if we can.
2254 String packageName = lp.packageName != null ? lp.packageName : "android";
2255 int resId = lp.windowAnimations;
2256 if ((resId&0xFF000000) == 0x01000000) {
2257 packageName = "android";
2258 }
2259 if (DEBUG_ANIM) Log.v(TAG, "Loading animations: picked package="
2260 + packageName);
2261 return AttributeCache.instance().get(packageName, resId,
2262 com.android.internal.R.styleable.WindowAnimation);
2263 }
2264 return null;
2265 }
Romain Guy06882f82009-06-10 13:36:04 -07002266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002267 private void applyEnterAnimationLocked(WindowState win) {
2268 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2269 if (win.mEnterAnimationPending) {
2270 win.mEnterAnimationPending = false;
2271 transit = WindowManagerPolicy.TRANSIT_ENTER;
2272 }
2273
2274 applyAnimationLocked(win, transit, true);
2275 }
2276
2277 private boolean applyAnimationLocked(WindowState win,
2278 int transit, boolean isEntrance) {
2279 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2280 // If we are trying to apply an animation, but already running
2281 // an animation of the same type, then just leave that one alone.
2282 return true;
2283 }
Romain Guy06882f82009-06-10 13:36:04 -07002284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002285 // Only apply an animation if the display isn't frozen. If it is
2286 // frozen, there is no reason to animate and it can cause strange
2287 // artifacts when we unfreeze the display if some different animation
2288 // is running.
2289 if (!mDisplayFrozen) {
2290 int anim = mPolicy.selectAnimationLw(win, transit);
2291 int attr = -1;
2292 Animation a = null;
2293 if (anim != 0) {
2294 a = AnimationUtils.loadAnimation(mContext, anim);
2295 } else {
2296 switch (transit) {
2297 case WindowManagerPolicy.TRANSIT_ENTER:
2298 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2299 break;
2300 case WindowManagerPolicy.TRANSIT_EXIT:
2301 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2302 break;
2303 case WindowManagerPolicy.TRANSIT_SHOW:
2304 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2305 break;
2306 case WindowManagerPolicy.TRANSIT_HIDE:
2307 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2308 break;
2309 }
2310 if (attr >= 0) {
2311 a = loadAnimation(win.mAttrs, attr);
2312 }
2313 }
2314 if (DEBUG_ANIM) Log.v(TAG, "applyAnimation: win=" + win
2315 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2316 + " mAnimation=" + win.mAnimation
2317 + " isEntrance=" + isEntrance);
2318 if (a != null) {
2319 if (DEBUG_ANIM) {
2320 RuntimeException e = new RuntimeException();
2321 e.fillInStackTrace();
2322 Log.v(TAG, "Loaded animation " + a + " for " + win, e);
2323 }
2324 win.setAnimation(a);
2325 win.mAnimationIsEntrance = isEntrance;
2326 }
2327 } else {
2328 win.clearAnimation();
2329 }
2330
2331 return win.mAnimation != null;
2332 }
2333
2334 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2335 int anim = 0;
2336 Context context = mContext;
2337 if (animAttr >= 0) {
2338 AttributeCache.Entry ent = getCachedAnimations(lp);
2339 if (ent != null) {
2340 context = ent.context;
2341 anim = ent.array.getResourceId(animAttr, 0);
2342 }
2343 }
2344 if (anim != 0) {
2345 return AnimationUtils.loadAnimation(context, anim);
2346 }
2347 return null;
2348 }
Romain Guy06882f82009-06-10 13:36:04 -07002349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002350 private boolean applyAnimationLocked(AppWindowToken wtoken,
2351 WindowManager.LayoutParams lp, int transit, boolean enter) {
2352 // Only apply an animation if the display isn't frozen. If it is
2353 // frozen, there is no reason to animate and it can cause strange
2354 // artifacts when we unfreeze the display if some different animation
2355 // is running.
2356 if (!mDisplayFrozen) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002357 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002358 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002359 a = new FadeInOutAnimation(enter);
2360 if (DEBUG_ANIM) Log.v(TAG,
2361 "applying FadeInOutAnimation for a window in compatibility mode");
2362 } else {
2363 int animAttr = 0;
2364 switch (transit) {
2365 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2366 animAttr = enter
2367 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2368 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2369 break;
2370 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2371 animAttr = enter
2372 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2373 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2374 break;
2375 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2376 animAttr = enter
2377 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2378 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2379 break;
2380 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2381 animAttr = enter
2382 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2383 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2384 break;
2385 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2386 animAttr = enter
2387 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2388 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2389 break;
2390 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2391 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002392 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002393 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2394 break;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002395 case WindowManagerPolicy.TRANSIT_WALLPAPER_ACTIVITY_OPEN:
2396 animAttr = enter
2397 ? com.android.internal.R.styleable.WindowAnimation_wallpaperActivityOpenEnterAnimation
2398 : com.android.internal.R.styleable.WindowAnimation_wallpaperActivityOpenExitAnimation;
2399 break;
2400 case WindowManagerPolicy.TRANSIT_WALLPAPER_ACTIVITY_CLOSE:
2401 animAttr = enter
2402 ? com.android.internal.R.styleable.WindowAnimation_wallpaperActivityCloseEnterAnimation
2403 : com.android.internal.R.styleable.WindowAnimation_wallpaperActivityCloseExitAnimation;
2404 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002405 }
2406 a = loadAnimation(lp, animAttr);
2407 if (DEBUG_ANIM) Log.v(TAG, "applyAnimation: wtoken=" + wtoken
2408 + " anim=" + a
2409 + " animAttr=0x" + Integer.toHexString(animAttr)
2410 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002411 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002412 if (a != null) {
2413 if (DEBUG_ANIM) {
2414 RuntimeException e = new RuntimeException();
2415 e.fillInStackTrace();
2416 Log.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
2417 }
2418 wtoken.setAnimation(a);
2419 }
2420 } else {
2421 wtoken.clearAnimation();
2422 }
2423
2424 return wtoken.animation != null;
2425 }
2426
2427 // -------------------------------------------------------------
2428 // Application Window Tokens
2429 // -------------------------------------------------------------
2430
2431 public void validateAppTokens(List tokens) {
2432 int v = tokens.size()-1;
2433 int m = mAppTokens.size()-1;
2434 while (v >= 0 && m >= 0) {
2435 AppWindowToken wtoken = mAppTokens.get(m);
2436 if (wtoken.removed) {
2437 m--;
2438 continue;
2439 }
2440 if (tokens.get(v) != wtoken.token) {
2441 Log.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
2442 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2443 }
2444 v--;
2445 m--;
2446 }
2447 while (v >= 0) {
2448 Log.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
2449 v--;
2450 }
2451 while (m >= 0) {
2452 AppWindowToken wtoken = mAppTokens.get(m);
2453 if (!wtoken.removed) {
2454 Log.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
2455 }
2456 m--;
2457 }
2458 }
2459
2460 boolean checkCallingPermission(String permission, String func) {
2461 // Quick check: if the calling permission is me, it's all okay.
2462 if (Binder.getCallingPid() == Process.myPid()) {
2463 return true;
2464 }
Romain Guy06882f82009-06-10 13:36:04 -07002465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002466 if (mContext.checkCallingPermission(permission)
2467 == PackageManager.PERMISSION_GRANTED) {
2468 return true;
2469 }
2470 String msg = "Permission Denial: " + func + " from pid="
2471 + Binder.getCallingPid()
2472 + ", uid=" + Binder.getCallingUid()
2473 + " requires " + permission;
2474 Log.w(TAG, msg);
2475 return false;
2476 }
Romain Guy06882f82009-06-10 13:36:04 -07002477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002478 AppWindowToken findAppWindowToken(IBinder token) {
2479 WindowToken wtoken = mTokenMap.get(token);
2480 if (wtoken == null) {
2481 return null;
2482 }
2483 return wtoken.appWindowToken;
2484 }
Romain Guy06882f82009-06-10 13:36:04 -07002485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002486 public void addWindowToken(IBinder token, int type) {
2487 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2488 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002489 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 }
Romain Guy06882f82009-06-10 13:36:04 -07002491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002492 synchronized(mWindowMap) {
2493 WindowToken wtoken = mTokenMap.get(token);
2494 if (wtoken != null) {
2495 Log.w(TAG, "Attempted to add existing input method token: " + token);
2496 return;
2497 }
2498 wtoken = new WindowToken(token, type, true);
2499 mTokenMap.put(token, wtoken);
2500 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002501 if (type == TYPE_WALLPAPER) {
2502 mWallpaperTokens.add(wtoken);
2503 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002504 }
2505 }
Romain Guy06882f82009-06-10 13:36:04 -07002506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002507 public void removeWindowToken(IBinder token) {
2508 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2509 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002510 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002511 }
2512
2513 final long origId = Binder.clearCallingIdentity();
2514 synchronized(mWindowMap) {
2515 WindowToken wtoken = mTokenMap.remove(token);
2516 mTokenList.remove(wtoken);
2517 if (wtoken != null) {
2518 boolean delayed = false;
2519 if (!wtoken.hidden) {
2520 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002522 final int N = wtoken.windows.size();
2523 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002525 for (int i=0; i<N; i++) {
2526 WindowState win = wtoken.windows.get(i);
2527
2528 if (win.isAnimating()) {
2529 delayed = true;
2530 }
Romain Guy06882f82009-06-10 13:36:04 -07002531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002532 if (win.isVisibleNow()) {
2533 applyAnimationLocked(win,
2534 WindowManagerPolicy.TRANSIT_EXIT, false);
2535 mKeyWaiter.finishedKey(win.mSession, win.mClient, true,
2536 KeyWaiter.RETURN_NOTHING);
2537 changed = true;
2538 }
2539 }
2540
2541 if (changed) {
2542 mLayoutNeeded = true;
2543 performLayoutAndPlaceSurfacesLocked();
2544 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2545 }
Romain Guy06882f82009-06-10 13:36:04 -07002546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 if (delayed) {
2548 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002549 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2550 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002551 }
2552 }
Romain Guy06882f82009-06-10 13:36:04 -07002553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002554 } else {
2555 Log.w(TAG, "Attempted to remove non-existing token: " + token);
2556 }
2557 }
2558 Binder.restoreCallingIdentity(origId);
2559 }
2560
2561 public void addAppToken(int addPos, IApplicationToken token,
2562 int groupId, int requestedOrientation, boolean fullscreen) {
2563 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2564 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002565 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002566 }
Romain Guy06882f82009-06-10 13:36:04 -07002567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568 synchronized(mWindowMap) {
2569 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2570 if (wtoken != null) {
2571 Log.w(TAG, "Attempted to add existing app token: " + token);
2572 return;
2573 }
2574 wtoken = new AppWindowToken(token);
2575 wtoken.groupId = groupId;
2576 wtoken.appFullscreen = fullscreen;
2577 wtoken.requestedOrientation = requestedOrientation;
2578 mAppTokens.add(addPos, wtoken);
Dave Bortcfe65242009-04-09 14:51:04 -07002579 if (localLOGV) Log.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002580 mTokenMap.put(token.asBinder(), wtoken);
2581 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002583 // Application tokens start out hidden.
2584 wtoken.hidden = true;
2585 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002587 //dump();
2588 }
2589 }
Romain Guy06882f82009-06-10 13:36:04 -07002590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002591 public void setAppGroupId(IBinder token, int groupId) {
2592 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2593 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002594 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002595 }
2596
2597 synchronized(mWindowMap) {
2598 AppWindowToken wtoken = findAppWindowToken(token);
2599 if (wtoken == null) {
2600 Log.w(TAG, "Attempted to set group id of non-existing app token: " + token);
2601 return;
2602 }
2603 wtoken.groupId = groupId;
2604 }
2605 }
Romain Guy06882f82009-06-10 13:36:04 -07002606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002607 public int getOrientationFromWindowsLocked() {
2608 int pos = mWindows.size() - 1;
2609 while (pos >= 0) {
2610 WindowState wtoken = (WindowState) mWindows.get(pos);
2611 pos--;
2612 if (wtoken.mAppToken != null) {
2613 // We hit an application window. so the orientation will be determined by the
2614 // app window. No point in continuing further.
2615 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
2616 }
2617 if (!wtoken.isVisibleLw()) {
2618 continue;
2619 }
2620 int req = wtoken.mAttrs.screenOrientation;
2621 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
2622 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
2623 continue;
2624 } else {
2625 return req;
2626 }
2627 }
2628 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
2629 }
Romain Guy06882f82009-06-10 13:36:04 -07002630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002631 public int getOrientationFromAppTokensLocked() {
2632 int pos = mAppTokens.size() - 1;
2633 int curGroup = 0;
2634 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Owen Lin3413b892009-05-01 17:12:32 -07002635 boolean findingBehind = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002636 boolean haveGroup = false;
The Android Open Source Project4df24232009-03-05 14:34:35 -08002637 boolean lastFullscreen = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002638 while (pos >= 0) {
2639 AppWindowToken wtoken = mAppTokens.get(pos);
2640 pos--;
Owen Lin3413b892009-05-01 17:12:32 -07002641 // if we're about to tear down this window and not seek for
2642 // the behind activity, don't use it for orientation
2643 if (!findingBehind
2644 && (!wtoken.hidden && wtoken.hiddenRequested)) {
The Android Open Source Project10592532009-03-18 17:39:46 -07002645 continue;
2646 }
2647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002648 if (!haveGroup) {
2649 // We ignore any hidden applications on the top.
2650 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
2651 continue;
2652 }
2653 haveGroup = true;
2654 curGroup = wtoken.groupId;
2655 lastOrientation = wtoken.requestedOrientation;
2656 } else if (curGroup != wtoken.groupId) {
2657 // If we have hit a new application group, and the bottom
2658 // of the previous group didn't explicitly say to use
The Android Open Source Project4df24232009-03-05 14:34:35 -08002659 // the orientation behind it, and the last app was
2660 // full screen, then we'll stick with the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002661 // user's orientation.
The Android Open Source Project4df24232009-03-05 14:34:35 -08002662 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
2663 && lastFullscreen) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002664 return lastOrientation;
2665 }
2666 }
2667 int or = wtoken.requestedOrientation;
Owen Lin3413b892009-05-01 17:12:32 -07002668 // If this application is fullscreen, and didn't explicitly say
2669 // to use the orientation behind it, then just take whatever
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002670 // orientation it has and ignores whatever is under it.
The Android Open Source Project4df24232009-03-05 14:34:35 -08002671 lastFullscreen = wtoken.appFullscreen;
Romain Guy06882f82009-06-10 13:36:04 -07002672 if (lastFullscreen
Owen Lin3413b892009-05-01 17:12:32 -07002673 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002674 return or;
2675 }
2676 // If this application has requested an explicit orientation,
2677 // then use it.
2678 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
2679 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
2680 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
2681 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
2682 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
2683 return or;
2684 }
Owen Lin3413b892009-05-01 17:12:32 -07002685 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002686 }
2687 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
2688 }
Romain Guy06882f82009-06-10 13:36:04 -07002689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002690 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07002691 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002692 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2693 "updateOrientationFromAppTokens()")) {
2694 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
2695 }
2696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002697 Configuration config;
2698 long ident = Binder.clearCallingIdentity();
Dianne Hackborncfaef692009-06-15 14:24:44 -07002699 config = updateOrientationFromAppTokensUnchecked(currentConfig,
2700 freezeThisOneIfNeeded);
2701 Binder.restoreCallingIdentity(ident);
2702 return config;
2703 }
2704
2705 Configuration updateOrientationFromAppTokensUnchecked(
2706 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
2707 Configuration config;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002708 synchronized(mWindowMap) {
The Android Open Source Project10592532009-03-18 17:39:46 -07002709 config = updateOrientationFromAppTokensLocked(currentConfig, freezeThisOneIfNeeded);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002710 }
2711 if (config != null) {
2712 mLayoutNeeded = true;
2713 performLayoutAndPlaceSurfacesLocked();
2714 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002715 return config;
2716 }
Romain Guy06882f82009-06-10 13:36:04 -07002717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002718 /*
2719 * The orientation is computed from non-application windows first. If none of
2720 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07002721 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002722 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
2723 * android.os.IBinder)
2724 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002725 Configuration updateOrientationFromAppTokensLocked(
The Android Open Source Project10592532009-03-18 17:39:46 -07002726 Configuration appConfig, IBinder freezeThisOneIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002727 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002728 long ident = Binder.clearCallingIdentity();
2729 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002730 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07002731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002732 if (req != mForcedAppOrientation) {
2733 changed = true;
2734 mForcedAppOrientation = req;
2735 //send a message to Policy indicating orientation change to take
2736 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002737 mPolicy.setCurrentOrientationLw(req);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002738 }
Romain Guy06882f82009-06-10 13:36:04 -07002739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002740 if (changed) {
2741 changed = setRotationUncheckedLocked(
Dianne Hackborn321ae682009-03-27 16:16:03 -07002742 WindowManagerPolicy.USE_LAST_ROTATION,
2743 mLastRotationFlags & (~Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002744 if (changed) {
2745 if (freezeThisOneIfNeeded != null) {
2746 AppWindowToken wtoken = findAppWindowToken(
2747 freezeThisOneIfNeeded);
2748 if (wtoken != null) {
2749 startAppFreezingScreenLocked(wtoken,
2750 ActivityInfo.CONFIG_ORIENTATION);
2751 }
2752 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07002753 return computeNewConfigurationLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002754 }
2755 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002756
2757 // No obvious action we need to take, but if our current
2758 // state mismatches the activity maanager's, update it
2759 if (appConfig != null) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07002760 mTempConfiguration.setToDefaults();
2761 if (computeNewConfigurationLocked(mTempConfiguration)) {
2762 if (appConfig.diff(mTempConfiguration) != 0) {
2763 Log.i(TAG, "Config changed: " + mTempConfiguration);
2764 return new Configuration(mTempConfiguration);
2765 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002766 }
2767 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002768 } finally {
2769 Binder.restoreCallingIdentity(ident);
2770 }
Romain Guy06882f82009-06-10 13:36:04 -07002771
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002772 return null;
2773 }
Romain Guy06882f82009-06-10 13:36:04 -07002774
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002775 int computeForcedAppOrientationLocked() {
2776 int req = getOrientationFromWindowsLocked();
2777 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
2778 req = getOrientationFromAppTokensLocked();
2779 }
2780 return req;
2781 }
Romain Guy06882f82009-06-10 13:36:04 -07002782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002783 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
2784 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2785 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002786 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002787 }
Romain Guy06882f82009-06-10 13:36:04 -07002788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002789 synchronized(mWindowMap) {
2790 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2791 if (wtoken == null) {
2792 Log.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
2793 return;
2794 }
Romain Guy06882f82009-06-10 13:36:04 -07002795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002796 wtoken.requestedOrientation = requestedOrientation;
2797 }
2798 }
Romain Guy06882f82009-06-10 13:36:04 -07002799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002800 public int getAppOrientation(IApplicationToken token) {
2801 synchronized(mWindowMap) {
2802 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2803 if (wtoken == null) {
2804 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
2805 }
Romain Guy06882f82009-06-10 13:36:04 -07002806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002807 return wtoken.requestedOrientation;
2808 }
2809 }
Romain Guy06882f82009-06-10 13:36:04 -07002810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002811 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
2812 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2813 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002814 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002815 }
2816
2817 synchronized(mWindowMap) {
2818 boolean changed = false;
2819 if (token == null) {
2820 if (DEBUG_FOCUS) Log.v(TAG, "Clearing focused app, was " + mFocusedApp);
2821 changed = mFocusedApp != null;
2822 mFocusedApp = null;
2823 mKeyWaiter.tickle();
2824 } else {
2825 AppWindowToken newFocus = findAppWindowToken(token);
2826 if (newFocus == null) {
2827 Log.w(TAG, "Attempted to set focus to non-existing app token: " + token);
2828 return;
2829 }
2830 changed = mFocusedApp != newFocus;
2831 mFocusedApp = newFocus;
2832 if (DEBUG_FOCUS) Log.v(TAG, "Set focused app to: " + mFocusedApp);
2833 mKeyWaiter.tickle();
2834 }
2835
2836 if (moveFocusNow && changed) {
2837 final long origId = Binder.clearCallingIdentity();
2838 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2839 Binder.restoreCallingIdentity(origId);
2840 }
2841 }
2842 }
2843
2844 public void prepareAppTransition(int transit) {
2845 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2846 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002847 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002848 }
Romain Guy06882f82009-06-10 13:36:04 -07002849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002850 synchronized(mWindowMap) {
2851 if (DEBUG_APP_TRANSITIONS) Log.v(
2852 TAG, "Prepare app transition: transit=" + transit
2853 + " mNextAppTransition=" + mNextAppTransition);
2854 if (!mDisplayFrozen) {
2855 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
2856 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07002857 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
2858 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
2859 // Opening a new task always supersedes a close for the anim.
2860 mNextAppTransition = transit;
2861 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
2862 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
2863 // Opening a new activity always supersedes a close for the anim.
2864 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002865 }
2866 mAppTransitionReady = false;
2867 mAppTransitionTimeout = false;
2868 mStartingIconInTransition = false;
2869 mSkipAppTransitionAnimation = false;
2870 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
2871 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
2872 5000);
2873 }
2874 }
2875 }
2876
2877 public int getPendingAppTransition() {
2878 return mNextAppTransition;
2879 }
Romain Guy06882f82009-06-10 13:36:04 -07002880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002881 public void executeAppTransition() {
2882 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2883 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002884 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002885 }
Romain Guy06882f82009-06-10 13:36:04 -07002886
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002887 synchronized(mWindowMap) {
2888 if (DEBUG_APP_TRANSITIONS) Log.v(
2889 TAG, "Execute app transition: mNextAppTransition=" + mNextAppTransition);
2890 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) {
2891 mAppTransitionReady = true;
2892 final long origId = Binder.clearCallingIdentity();
2893 performLayoutAndPlaceSurfacesLocked();
2894 Binder.restoreCallingIdentity(origId);
2895 }
2896 }
2897 }
2898
2899 public void setAppStartingWindow(IBinder token, String pkg,
2900 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
2901 IBinder transferFrom, boolean createIfNeeded) {
2902 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2903 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002904 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002905 }
2906
2907 synchronized(mWindowMap) {
2908 if (DEBUG_STARTING_WINDOW) Log.v(
2909 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
2910 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07002911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 AppWindowToken wtoken = findAppWindowToken(token);
2913 if (wtoken == null) {
2914 Log.w(TAG, "Attempted to set icon of non-existing app token: " + token);
2915 return;
2916 }
2917
2918 // If the display is frozen, we won't do anything until the
2919 // actual window is displayed so there is no reason to put in
2920 // the starting window.
2921 if (mDisplayFrozen) {
2922 return;
2923 }
Romain Guy06882f82009-06-10 13:36:04 -07002924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002925 if (wtoken.startingData != null) {
2926 return;
2927 }
Romain Guy06882f82009-06-10 13:36:04 -07002928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002929 if (transferFrom != null) {
2930 AppWindowToken ttoken = findAppWindowToken(transferFrom);
2931 if (ttoken != null) {
2932 WindowState startingWindow = ttoken.startingWindow;
2933 if (startingWindow != null) {
2934 if (mStartingIconInTransition) {
2935 // In this case, the starting icon has already
2936 // been displayed, so start letting windows get
2937 // shown immediately without any more transitions.
2938 mSkipAppTransitionAnimation = true;
2939 }
2940 if (DEBUG_STARTING_WINDOW) Log.v(TAG,
2941 "Moving existing starting from " + ttoken
2942 + " to " + wtoken);
2943 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002945 // Transfer the starting window over to the new
2946 // token.
2947 wtoken.startingData = ttoken.startingData;
2948 wtoken.startingView = ttoken.startingView;
2949 wtoken.startingWindow = startingWindow;
2950 ttoken.startingData = null;
2951 ttoken.startingView = null;
2952 ttoken.startingWindow = null;
2953 ttoken.startingMoved = true;
2954 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07002955 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002956 startingWindow.mAppToken = wtoken;
2957 mWindows.remove(startingWindow);
2958 ttoken.windows.remove(startingWindow);
2959 ttoken.allAppWindows.remove(startingWindow);
2960 addWindowToListInOrderLocked(startingWindow, true);
2961 wtoken.allAppWindows.add(startingWindow);
Romain Guy06882f82009-06-10 13:36:04 -07002962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002963 // Propagate other interesting state between the
2964 // tokens. If the old token is displayed, we should
2965 // immediately force the new one to be displayed. If
2966 // it is animating, we need to move that animation to
2967 // the new one.
2968 if (ttoken.allDrawn) {
2969 wtoken.allDrawn = true;
2970 }
2971 if (ttoken.firstWindowDrawn) {
2972 wtoken.firstWindowDrawn = true;
2973 }
2974 if (!ttoken.hidden) {
2975 wtoken.hidden = false;
2976 wtoken.hiddenRequested = false;
2977 wtoken.willBeHidden = false;
2978 }
2979 if (wtoken.clientHidden != ttoken.clientHidden) {
2980 wtoken.clientHidden = ttoken.clientHidden;
2981 wtoken.sendAppVisibilityToClients();
2982 }
2983 if (ttoken.animation != null) {
2984 wtoken.animation = ttoken.animation;
2985 wtoken.animating = ttoken.animating;
2986 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
2987 ttoken.animation = null;
2988 ttoken.animLayerAdjustment = 0;
2989 wtoken.updateLayers();
2990 ttoken.updateLayers();
2991 }
Romain Guy06882f82009-06-10 13:36:04 -07002992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002993 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002994 mLayoutNeeded = true;
2995 performLayoutAndPlaceSurfacesLocked();
2996 Binder.restoreCallingIdentity(origId);
2997 return;
2998 } else if (ttoken.startingData != null) {
2999 // The previous app was getting ready to show a
3000 // starting window, but hasn't yet done so. Steal it!
3001 if (DEBUG_STARTING_WINDOW) Log.v(TAG,
3002 "Moving pending starting from " + ttoken
3003 + " to " + wtoken);
3004 wtoken.startingData = ttoken.startingData;
3005 ttoken.startingData = null;
3006 ttoken.startingMoved = true;
3007 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3008 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3009 // want to process the message ASAP, before any other queued
3010 // messages.
3011 mH.sendMessageAtFrontOfQueue(m);
3012 return;
3013 }
3014 }
3015 }
3016
3017 // There is no existing starting window, and the caller doesn't
3018 // want us to create one, so that's it!
3019 if (!createIfNeeded) {
3020 return;
3021 }
Romain Guy06882f82009-06-10 13:36:04 -07003022
Dianne Hackborn284ac932009-08-28 10:34:25 -07003023 // If this is a translucent or wallpaper window, then don't
3024 // show a starting window -- the current effect (a full-screen
3025 // opaque starting window that fades away to the real contents
3026 // when it is ready) does not work for this.
3027 if (theme != 0) {
3028 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3029 com.android.internal.R.styleable.Window);
3030 if (ent.array.getBoolean(
3031 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3032 return;
3033 }
3034 if (ent.array.getBoolean(
3035 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3036 return;
3037 }
3038 }
3039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003040 mStartingIconInTransition = true;
3041 wtoken.startingData = new StartingData(
3042 pkg, theme, nonLocalizedLabel,
3043 labelRes, icon);
3044 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3045 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3046 // want to process the message ASAP, before any other queued
3047 // messages.
3048 mH.sendMessageAtFrontOfQueue(m);
3049 }
3050 }
3051
3052 public void setAppWillBeHidden(IBinder token) {
3053 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3054 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003055 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003056 }
3057
3058 AppWindowToken wtoken;
3059
3060 synchronized(mWindowMap) {
3061 wtoken = findAppWindowToken(token);
3062 if (wtoken == null) {
3063 Log.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token);
3064 return;
3065 }
3066 wtoken.willBeHidden = true;
3067 }
3068 }
Romain Guy06882f82009-06-10 13:36:04 -07003069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003070 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3071 boolean visible, int transit, boolean performLayout) {
3072 boolean delayed = false;
3073
3074 if (wtoken.clientHidden == visible) {
3075 wtoken.clientHidden = !visible;
3076 wtoken.sendAppVisibilityToClients();
3077 }
Romain Guy06882f82009-06-10 13:36:04 -07003078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003079 wtoken.willBeHidden = false;
3080 if (wtoken.hidden == visible) {
3081 final int N = wtoken.allAppWindows.size();
3082 boolean changed = false;
3083 if (DEBUG_APP_TRANSITIONS) Log.v(
3084 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3085 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003087 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003089 if (transit != WindowManagerPolicy.TRANSIT_NONE) {
3090 if (wtoken.animation == sDummyAnimation) {
3091 wtoken.animation = null;
3092 }
3093 applyAnimationLocked(wtoken, lp, transit, visible);
3094 changed = true;
3095 if (wtoken.animation != null) {
3096 delayed = runningAppAnimation = true;
3097 }
3098 }
Romain Guy06882f82009-06-10 13:36:04 -07003099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003100 for (int i=0; i<N; i++) {
3101 WindowState win = wtoken.allAppWindows.get(i);
3102 if (win == wtoken.startingWindow) {
3103 continue;
3104 }
3105
3106 if (win.isAnimating()) {
3107 delayed = true;
3108 }
Romain Guy06882f82009-06-10 13:36:04 -07003109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003110 //Log.i(TAG, "Window " + win + ": vis=" + win.isVisible());
3111 //win.dump(" ");
3112 if (visible) {
3113 if (!win.isVisibleNow()) {
3114 if (!runningAppAnimation) {
3115 applyAnimationLocked(win,
3116 WindowManagerPolicy.TRANSIT_ENTER, true);
3117 }
3118 changed = true;
3119 }
3120 } else if (win.isVisibleNow()) {
3121 if (!runningAppAnimation) {
3122 applyAnimationLocked(win,
3123 WindowManagerPolicy.TRANSIT_EXIT, false);
3124 }
3125 mKeyWaiter.finishedKey(win.mSession, win.mClient, true,
3126 KeyWaiter.RETURN_NOTHING);
3127 changed = true;
3128 }
3129 }
3130
3131 wtoken.hidden = wtoken.hiddenRequested = !visible;
3132 if (!visible) {
3133 unsetAppFreezingScreenLocked(wtoken, true, true);
3134 } else {
3135 // If we are being set visible, and the starting window is
3136 // not yet displayed, then make sure it doesn't get displayed.
3137 WindowState swin = wtoken.startingWindow;
3138 if (swin != null && (swin.mDrawPending
3139 || swin.mCommitDrawPending)) {
3140 swin.mPolicyVisibility = false;
3141 swin.mPolicyVisibilityAfterAnim = false;
3142 }
3143 }
Romain Guy06882f82009-06-10 13:36:04 -07003144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003145 if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "setTokenVisibilityLocked: " + wtoken
3146 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3147 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003149 if (changed && performLayout) {
3150 mLayoutNeeded = true;
3151 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152 performLayoutAndPlaceSurfacesLocked();
3153 }
3154 }
3155
3156 if (wtoken.animation != null) {
3157 delayed = true;
3158 }
Romain Guy06882f82009-06-10 13:36:04 -07003159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003160 return delayed;
3161 }
3162
3163 public void setAppVisibility(IBinder token, boolean visible) {
3164 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3165 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003166 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003167 }
3168
3169 AppWindowToken wtoken;
3170
3171 synchronized(mWindowMap) {
3172 wtoken = findAppWindowToken(token);
3173 if (wtoken == null) {
3174 Log.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
3175 return;
3176 }
3177
3178 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
3179 RuntimeException e = new RuntimeException();
3180 e.fillInStackTrace();
3181 Log.v(TAG, "setAppVisibility(" + token + ", " + visible
3182 + "): mNextAppTransition=" + mNextAppTransition
3183 + " hidden=" + wtoken.hidden
3184 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3185 }
Romain Guy06882f82009-06-10 13:36:04 -07003186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 // If we are preparing an app transition, then delay changing
3188 // the visibility of this token until we execute that transition.
3189 if (!mDisplayFrozen && mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) {
3190 // Already in requested state, don't do anything more.
3191 if (wtoken.hiddenRequested != visible) {
3192 return;
3193 }
3194 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003196 if (DEBUG_APP_TRANSITIONS) Log.v(
3197 TAG, "Setting dummy animation on: " + wtoken);
3198 wtoken.setDummyAnimation();
3199 mOpeningApps.remove(wtoken);
3200 mClosingApps.remove(wtoken);
3201 wtoken.inPendingTransaction = true;
3202 if (visible) {
3203 mOpeningApps.add(wtoken);
3204 wtoken.allDrawn = false;
3205 wtoken.startingDisplayed = false;
3206 wtoken.startingMoved = false;
Romain Guy06882f82009-06-10 13:36:04 -07003207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003208 if (wtoken.clientHidden) {
3209 // In the case where we are making an app visible
3210 // but holding off for a transition, we still need
3211 // to tell the client to make its windows visible so
3212 // they get drawn. Otherwise, we will wait on
3213 // performing the transition until all windows have
3214 // been drawn, they never will be, and we are sad.
3215 wtoken.clientHidden = false;
3216 wtoken.sendAppVisibilityToClients();
3217 }
3218 } else {
3219 mClosingApps.add(wtoken);
3220 }
3221 return;
3222 }
Romain Guy06882f82009-06-10 13:36:04 -07003223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003224 final long origId = Binder.clearCallingIdentity();
3225 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_NONE, true);
3226 wtoken.updateReportedVisibilityLocked();
3227 Binder.restoreCallingIdentity(origId);
3228 }
3229 }
3230
3231 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3232 boolean unfreezeSurfaceNow, boolean force) {
3233 if (wtoken.freezingScreen) {
3234 if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + wtoken
3235 + " force=" + force);
3236 final int N = wtoken.allAppWindows.size();
3237 boolean unfrozeWindows = false;
3238 for (int i=0; i<N; i++) {
3239 WindowState w = wtoken.allAppWindows.get(i);
3240 if (w.mAppFreezing) {
3241 w.mAppFreezing = false;
3242 if (w.mSurface != null && !w.mOrientationChanging) {
3243 w.mOrientationChanging = true;
3244 }
3245 unfrozeWindows = true;
3246 }
3247 }
3248 if (force || unfrozeWindows) {
3249 if (DEBUG_ORIENTATION) Log.v(TAG, "No longer freezing: " + wtoken);
3250 wtoken.freezingScreen = false;
3251 mAppsFreezingScreen--;
3252 }
3253 if (unfreezeSurfaceNow) {
3254 if (unfrozeWindows) {
3255 mLayoutNeeded = true;
3256 performLayoutAndPlaceSurfacesLocked();
3257 }
3258 if (mAppsFreezingScreen == 0 && !mWindowsFreezingScreen) {
3259 stopFreezingDisplayLocked();
3260 }
3261 }
3262 }
3263 }
Romain Guy06882f82009-06-10 13:36:04 -07003264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003265 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3266 int configChanges) {
3267 if (DEBUG_ORIENTATION) {
3268 RuntimeException e = new RuntimeException();
3269 e.fillInStackTrace();
3270 Log.i(TAG, "Set freezing of " + wtoken.appToken
3271 + ": hidden=" + wtoken.hidden + " freezing="
3272 + wtoken.freezingScreen, e);
3273 }
3274 if (!wtoken.hiddenRequested) {
3275 if (!wtoken.freezingScreen) {
3276 wtoken.freezingScreen = true;
3277 mAppsFreezingScreen++;
3278 if (mAppsFreezingScreen == 1) {
3279 startFreezingDisplayLocked();
3280 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3281 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3282 5000);
3283 }
3284 }
3285 final int N = wtoken.allAppWindows.size();
3286 for (int i=0; i<N; i++) {
3287 WindowState w = wtoken.allAppWindows.get(i);
3288 w.mAppFreezing = true;
3289 }
3290 }
3291 }
Romain Guy06882f82009-06-10 13:36:04 -07003292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003293 public void startAppFreezingScreen(IBinder token, int configChanges) {
3294 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3295 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003296 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003297 }
3298
3299 synchronized(mWindowMap) {
3300 if (configChanges == 0 && !mDisplayFrozen) {
3301 if (DEBUG_ORIENTATION) Log.v(TAG, "Skipping set freeze of " + token);
3302 return;
3303 }
Romain Guy06882f82009-06-10 13:36:04 -07003304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003305 AppWindowToken wtoken = findAppWindowToken(token);
3306 if (wtoken == null || wtoken.appToken == null) {
3307 Log.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
3308 return;
3309 }
3310 final long origId = Binder.clearCallingIdentity();
3311 startAppFreezingScreenLocked(wtoken, configChanges);
3312 Binder.restoreCallingIdentity(origId);
3313 }
3314 }
Romain Guy06882f82009-06-10 13:36:04 -07003315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003316 public void stopAppFreezingScreen(IBinder token, boolean force) {
3317 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3318 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003319 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003320 }
3321
3322 synchronized(mWindowMap) {
3323 AppWindowToken wtoken = findAppWindowToken(token);
3324 if (wtoken == null || wtoken.appToken == null) {
3325 return;
3326 }
3327 final long origId = Binder.clearCallingIdentity();
3328 if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + token
3329 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3330 unsetAppFreezingScreenLocked(wtoken, true, force);
3331 Binder.restoreCallingIdentity(origId);
3332 }
3333 }
Romain Guy06882f82009-06-10 13:36:04 -07003334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003335 public void removeAppToken(IBinder token) {
3336 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3337 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003338 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003339 }
3340
3341 AppWindowToken wtoken = null;
3342 AppWindowToken startingToken = null;
3343 boolean delayed = false;
3344
3345 final long origId = Binder.clearCallingIdentity();
3346 synchronized(mWindowMap) {
3347 WindowToken basewtoken = mTokenMap.remove(token);
3348 mTokenList.remove(basewtoken);
3349 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
3350 if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "Removing app token: " + wtoken);
3351 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_NONE, true);
3352 wtoken.inPendingTransaction = false;
3353 mOpeningApps.remove(wtoken);
3354 if (mClosingApps.contains(wtoken)) {
3355 delayed = true;
3356 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) {
3357 mClosingApps.add(wtoken);
3358 delayed = true;
3359 }
3360 if (DEBUG_APP_TRANSITIONS) Log.v(
3361 TAG, "Removing app " + wtoken + " delayed=" + delayed
3362 + " animation=" + wtoken.animation
3363 + " animating=" + wtoken.animating);
3364 if (delayed) {
3365 // set the token aside because it has an active animation to be finished
3366 mExitingAppTokens.add(wtoken);
3367 }
3368 mAppTokens.remove(wtoken);
3369 wtoken.removed = true;
3370 if (wtoken.startingData != null) {
3371 startingToken = wtoken;
3372 }
3373 unsetAppFreezingScreenLocked(wtoken, true, true);
3374 if (mFocusedApp == wtoken) {
3375 if (DEBUG_FOCUS) Log.v(TAG, "Removing focused app token:" + wtoken);
3376 mFocusedApp = null;
3377 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3378 mKeyWaiter.tickle();
3379 }
3380 } else {
3381 Log.w(TAG, "Attempted to remove non-existing app token: " + token);
3382 }
Romain Guy06882f82009-06-10 13:36:04 -07003383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003384 if (!delayed && wtoken != null) {
3385 wtoken.updateReportedVisibilityLocked();
3386 }
3387 }
3388 Binder.restoreCallingIdentity(origId);
3389
3390 if (startingToken != null) {
3391 if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Schedule remove starting "
3392 + startingToken + ": app token removed");
3393 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3394 mH.sendMessage(m);
3395 }
3396 }
3397
3398 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3399 final int NW = token.windows.size();
3400 for (int i=0; i<NW; i++) {
3401 WindowState win = token.windows.get(i);
3402 mWindows.remove(win);
3403 int j = win.mChildWindows.size();
3404 while (j > 0) {
3405 j--;
3406 mWindows.remove(win.mChildWindows.get(j));
3407 }
3408 }
3409 return NW > 0;
3410 }
3411
3412 void dumpAppTokensLocked() {
3413 for (int i=mAppTokens.size()-1; i>=0; i--) {
3414 Log.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
3415 }
3416 }
Romain Guy06882f82009-06-10 13:36:04 -07003417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003418 void dumpWindowsLocked() {
3419 for (int i=mWindows.size()-1; i>=0; i--) {
3420 Log.v(TAG, " #" + i + ": " + mWindows.get(i));
3421 }
3422 }
Romain Guy06882f82009-06-10 13:36:04 -07003423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003424 private int findWindowOffsetLocked(int tokenPos) {
3425 final int NW = mWindows.size();
3426
3427 if (tokenPos >= mAppTokens.size()) {
3428 int i = NW;
3429 while (i > 0) {
3430 i--;
3431 WindowState win = (WindowState)mWindows.get(i);
3432 if (win.getAppToken() != null) {
3433 return i+1;
3434 }
3435 }
3436 }
3437
3438 while (tokenPos > 0) {
3439 // Find the first app token below the new position that has
3440 // a window displayed.
3441 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
3442 if (DEBUG_REORDER) Log.v(TAG, "Looking for lower windows @ "
3443 + tokenPos + " -- " + wtoken.token);
3444 int i = wtoken.windows.size();
3445 while (i > 0) {
3446 i--;
3447 WindowState win = wtoken.windows.get(i);
3448 int j = win.mChildWindows.size();
3449 while (j > 0) {
3450 j--;
3451 WindowState cwin = (WindowState)win.mChildWindows.get(j);
3452 if (cwin.mSubLayer >= 0 ) {
3453 for (int pos=NW-1; pos>=0; pos--) {
3454 if (mWindows.get(pos) == cwin) {
3455 if (DEBUG_REORDER) Log.v(TAG,
3456 "Found child win @" + (pos+1));
3457 return pos+1;
3458 }
3459 }
3460 }
3461 }
3462 for (int pos=NW-1; pos>=0; pos--) {
3463 if (mWindows.get(pos) == win) {
3464 if (DEBUG_REORDER) Log.v(TAG, "Found win @" + (pos+1));
3465 return pos+1;
3466 }
3467 }
3468 }
3469 tokenPos--;
3470 }
3471
3472 return 0;
3473 }
3474
3475 private final int reAddWindowLocked(int index, WindowState win) {
3476 final int NCW = win.mChildWindows.size();
3477 boolean added = false;
3478 for (int j=0; j<NCW; j++) {
3479 WindowState cwin = (WindowState)win.mChildWindows.get(j);
3480 if (!added && cwin.mSubLayer >= 0) {
3481 mWindows.add(index, win);
3482 index++;
3483 added = true;
3484 }
3485 mWindows.add(index, cwin);
3486 index++;
3487 }
3488 if (!added) {
3489 mWindows.add(index, win);
3490 index++;
3491 }
3492 return index;
3493 }
Romain Guy06882f82009-06-10 13:36:04 -07003494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003495 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3496 final int NW = token.windows.size();
3497 for (int i=0; i<NW; i++) {
3498 index = reAddWindowLocked(index, token.windows.get(i));
3499 }
3500 return index;
3501 }
3502
3503 public void moveAppToken(int index, IBinder token) {
3504 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3505 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003506 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003507 }
3508
3509 synchronized(mWindowMap) {
3510 if (DEBUG_REORDER) Log.v(TAG, "Initial app tokens:");
3511 if (DEBUG_REORDER) dumpAppTokensLocked();
3512 final AppWindowToken wtoken = findAppWindowToken(token);
3513 if (wtoken == null || !mAppTokens.remove(wtoken)) {
3514 Log.w(TAG, "Attempting to reorder token that doesn't exist: "
3515 + token + " (" + wtoken + ")");
3516 return;
3517 }
3518 mAppTokens.add(index, wtoken);
3519 if (DEBUG_REORDER) Log.v(TAG, "Moved " + token + " to " + index + ":");
3520 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003522 final long origId = Binder.clearCallingIdentity();
3523 if (DEBUG_REORDER) Log.v(TAG, "Removing windows in " + token + ":");
3524 if (DEBUG_REORDER) dumpWindowsLocked();
3525 if (tmpRemoveAppWindowsLocked(wtoken)) {
3526 if (DEBUG_REORDER) Log.v(TAG, "Adding windows back in:");
3527 if (DEBUG_REORDER) dumpWindowsLocked();
3528 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
3529 if (DEBUG_REORDER) Log.v(TAG, "Final window list:");
3530 if (DEBUG_REORDER) dumpWindowsLocked();
3531 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003532 mLayoutNeeded = true;
3533 performLayoutAndPlaceSurfacesLocked();
3534 }
3535 Binder.restoreCallingIdentity(origId);
3536 }
3537 }
3538
3539 private void removeAppTokensLocked(List<IBinder> tokens) {
3540 // XXX This should be done more efficiently!
3541 // (take advantage of the fact that both lists should be
3542 // ordered in the same way.)
3543 int N = tokens.size();
3544 for (int i=0; i<N; i++) {
3545 IBinder token = tokens.get(i);
3546 final AppWindowToken wtoken = findAppWindowToken(token);
3547 if (!mAppTokens.remove(wtoken)) {
3548 Log.w(TAG, "Attempting to reorder token that doesn't exist: "
3549 + token + " (" + wtoken + ")");
3550 i--;
3551 N--;
3552 }
3553 }
3554 }
3555
3556 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
3557 // First remove all of the windows from the list.
3558 final int N = tokens.size();
3559 int i;
3560 for (i=0; i<N; i++) {
3561 WindowToken token = mTokenMap.get(tokens.get(i));
3562 if (token != null) {
3563 tmpRemoveAppWindowsLocked(token);
3564 }
3565 }
3566
3567 // Where to start adding?
3568 int pos = findWindowOffsetLocked(tokenPos);
3569
3570 // And now add them back at the correct place.
3571 for (i=0; i<N; i++) {
3572 WindowToken token = mTokenMap.get(tokens.get(i));
3573 if (token != null) {
3574 pos = reAddAppWindowsLocked(pos, token);
3575 }
3576 }
3577
3578 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003579 mLayoutNeeded = true;
3580 performLayoutAndPlaceSurfacesLocked();
3581
3582 //dump();
3583 }
3584
3585 public void moveAppTokensToTop(List<IBinder> tokens) {
3586 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3587 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003588 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003589 }
3590
3591 final long origId = Binder.clearCallingIdentity();
3592 synchronized(mWindowMap) {
3593 removeAppTokensLocked(tokens);
3594 final int N = tokens.size();
3595 for (int i=0; i<N; i++) {
3596 AppWindowToken wt = findAppWindowToken(tokens.get(i));
3597 if (wt != null) {
3598 mAppTokens.add(wt);
3599 }
3600 }
3601 moveAppWindowsLocked(tokens, mAppTokens.size());
3602 }
3603 Binder.restoreCallingIdentity(origId);
3604 }
3605
3606 public void moveAppTokensToBottom(List<IBinder> tokens) {
3607 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3608 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003609 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003610 }
3611
3612 final long origId = Binder.clearCallingIdentity();
3613 synchronized(mWindowMap) {
3614 removeAppTokensLocked(tokens);
3615 final int N = tokens.size();
3616 int pos = 0;
3617 for (int i=0; i<N; i++) {
3618 AppWindowToken wt = findAppWindowToken(tokens.get(i));
3619 if (wt != null) {
3620 mAppTokens.add(pos, wt);
3621 pos++;
3622 }
3623 }
3624 moveAppWindowsLocked(tokens, 0);
3625 }
3626 Binder.restoreCallingIdentity(origId);
3627 }
3628
3629 // -------------------------------------------------------------
3630 // Misc IWindowSession methods
3631 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07003632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003633 public void disableKeyguard(IBinder token, String tag) {
3634 if (mContext.checkCallingPermission(android.Manifest.permission.DISABLE_KEYGUARD)
3635 != PackageManager.PERMISSION_GRANTED) {
3636 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
3637 }
3638 mKeyguardDisabled.acquire(token, tag);
3639 }
3640
3641 public void reenableKeyguard(IBinder token) {
3642 if (mContext.checkCallingPermission(android.Manifest.permission.DISABLE_KEYGUARD)
3643 != PackageManager.PERMISSION_GRANTED) {
3644 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
3645 }
3646 synchronized (mKeyguardDisabled) {
3647 mKeyguardDisabled.release(token);
3648
3649 if (!mKeyguardDisabled.isAcquired()) {
3650 // if we are the last one to reenable the keyguard wait until
3651 // we have actaully finished reenabling until returning
3652 mWaitingUntilKeyguardReenabled = true;
3653 while (mWaitingUntilKeyguardReenabled) {
3654 try {
3655 mKeyguardDisabled.wait();
3656 } catch (InterruptedException e) {
3657 Thread.currentThread().interrupt();
3658 }
3659 }
3660 }
3661 }
3662 }
3663
3664 /**
3665 * @see android.app.KeyguardManager#exitKeyguardSecurely
3666 */
3667 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
3668 if (mContext.checkCallingPermission(android.Manifest.permission.DISABLE_KEYGUARD)
3669 != PackageManager.PERMISSION_GRANTED) {
3670 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
3671 }
3672 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
3673 public void onKeyguardExitResult(boolean success) {
3674 try {
3675 callback.onKeyguardExitResult(success);
3676 } catch (RemoteException e) {
3677 // Client has died, we don't care.
3678 }
3679 }
3680 });
3681 }
3682
3683 public boolean inKeyguardRestrictedInputMode() {
3684 return mPolicy.inKeyguardRestrictedKeyInputMode();
3685 }
Romain Guy06882f82009-06-10 13:36:04 -07003686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003687 static float fixScale(float scale) {
3688 if (scale < 0) scale = 0;
3689 else if (scale > 20) scale = 20;
3690 return Math.abs(scale);
3691 }
Romain Guy06882f82009-06-10 13:36:04 -07003692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003693 public void setAnimationScale(int which, float scale) {
3694 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
3695 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003696 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003697 }
3698
3699 if (scale < 0) scale = 0;
3700 else if (scale > 20) scale = 20;
3701 scale = Math.abs(scale);
3702 switch (which) {
3703 case 0: mWindowAnimationScale = fixScale(scale); break;
3704 case 1: mTransitionAnimationScale = fixScale(scale); break;
3705 }
Romain Guy06882f82009-06-10 13:36:04 -07003706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003707 // Persist setting
3708 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
3709 }
Romain Guy06882f82009-06-10 13:36:04 -07003710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003711 public void setAnimationScales(float[] scales) {
3712 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
3713 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003714 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003715 }
3716
3717 if (scales != null) {
3718 if (scales.length >= 1) {
3719 mWindowAnimationScale = fixScale(scales[0]);
3720 }
3721 if (scales.length >= 2) {
3722 mTransitionAnimationScale = fixScale(scales[1]);
3723 }
3724 }
Romain Guy06882f82009-06-10 13:36:04 -07003725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003726 // Persist setting
3727 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
3728 }
Romain Guy06882f82009-06-10 13:36:04 -07003729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003730 public float getAnimationScale(int which) {
3731 switch (which) {
3732 case 0: return mWindowAnimationScale;
3733 case 1: return mTransitionAnimationScale;
3734 }
3735 return 0;
3736 }
Romain Guy06882f82009-06-10 13:36:04 -07003737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003738 public float[] getAnimationScales() {
3739 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
3740 }
Romain Guy06882f82009-06-10 13:36:04 -07003741
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003742 public int getSwitchState(int sw) {
3743 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
3744 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003745 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003746 }
3747 return KeyInputQueue.getSwitchState(sw);
3748 }
Romain Guy06882f82009-06-10 13:36:04 -07003749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003750 public int getSwitchStateForDevice(int devid, int sw) {
3751 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
3752 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003753 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003754 }
3755 return KeyInputQueue.getSwitchState(devid, sw);
3756 }
Romain Guy06882f82009-06-10 13:36:04 -07003757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003758 public int getScancodeState(int sw) {
3759 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
3760 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003761 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003762 }
3763 return KeyInputQueue.getScancodeState(sw);
3764 }
Romain Guy06882f82009-06-10 13:36:04 -07003765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003766 public int getScancodeStateForDevice(int devid, int sw) {
3767 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
3768 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003769 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003770 }
3771 return KeyInputQueue.getScancodeState(devid, sw);
3772 }
Romain Guy06882f82009-06-10 13:36:04 -07003773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003774 public int getKeycodeState(int sw) {
3775 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
3776 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003777 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003778 }
3779 return KeyInputQueue.getKeycodeState(sw);
3780 }
Romain Guy06882f82009-06-10 13:36:04 -07003781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003782 public int getKeycodeStateForDevice(int devid, int sw) {
3783 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
3784 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003785 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003786 }
3787 return KeyInputQueue.getKeycodeState(devid, sw);
3788 }
Romain Guy06882f82009-06-10 13:36:04 -07003789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003790 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
3791 return KeyInputQueue.hasKeys(keycodes, keyExists);
3792 }
Romain Guy06882f82009-06-10 13:36:04 -07003793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003794 public void enableScreenAfterBoot() {
3795 synchronized(mWindowMap) {
3796 if (mSystemBooted) {
3797 return;
3798 }
3799 mSystemBooted = true;
3800 }
Romain Guy06882f82009-06-10 13:36:04 -07003801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003802 performEnableScreen();
3803 }
Romain Guy06882f82009-06-10 13:36:04 -07003804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003805 public void enableScreenIfNeededLocked() {
3806 if (mDisplayEnabled) {
3807 return;
3808 }
3809 if (!mSystemBooted) {
3810 return;
3811 }
3812 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
3813 }
Romain Guy06882f82009-06-10 13:36:04 -07003814
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003815 public void performEnableScreen() {
3816 synchronized(mWindowMap) {
3817 if (mDisplayEnabled) {
3818 return;
3819 }
3820 if (!mSystemBooted) {
3821 return;
3822 }
Romain Guy06882f82009-06-10 13:36:04 -07003823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003824 // Don't enable the screen until all existing windows
3825 // have been drawn.
3826 final int N = mWindows.size();
3827 for (int i=0; i<N; i++) {
3828 WindowState w = (WindowState)mWindows.get(i);
3829 if (w.isVisibleLw() && !w.isDisplayedLw()) {
3830 return;
3831 }
3832 }
Romain Guy06882f82009-06-10 13:36:04 -07003833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003834 mDisplayEnabled = true;
3835 if (false) {
3836 Log.i(TAG, "ENABLING SCREEN!");
3837 StringWriter sw = new StringWriter();
3838 PrintWriter pw = new PrintWriter(sw);
3839 this.dump(null, pw, null);
3840 Log.i(TAG, sw.toString());
3841 }
3842 try {
3843 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
3844 if (surfaceFlinger != null) {
3845 //Log.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
3846 Parcel data = Parcel.obtain();
3847 data.writeInterfaceToken("android.ui.ISurfaceComposer");
3848 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
3849 data, null, 0);
3850 data.recycle();
3851 }
3852 } catch (RemoteException ex) {
3853 Log.e(TAG, "Boot completed: SurfaceFlinger is dead!");
3854 }
3855 }
Romain Guy06882f82009-06-10 13:36:04 -07003856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003857 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07003858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003859 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07003860 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
3861 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003862 }
Romain Guy06882f82009-06-10 13:36:04 -07003863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003864 public void setInTouchMode(boolean mode) {
3865 synchronized(mWindowMap) {
3866 mInTouchMode = mode;
3867 }
3868 }
3869
Romain Guy06882f82009-06-10 13:36:04 -07003870 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07003871 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003872 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07003873 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003874 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003875 }
3876
Dianne Hackborn1e880db2009-03-27 16:04:08 -07003877 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003878 }
Romain Guy06882f82009-06-10 13:36:04 -07003879
Dianne Hackborn1e880db2009-03-27 16:04:08 -07003880 public void setRotationUnchecked(int rotation,
3881 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003882 if(DEBUG_ORIENTATION) Log.v(TAG,
3883 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07003884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003885 long origId = Binder.clearCallingIdentity();
3886 boolean changed;
3887 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07003888 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003889 }
Romain Guy06882f82009-06-10 13:36:04 -07003890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003891 if (changed) {
3892 sendNewConfiguration();
3893 synchronized(mWindowMap) {
3894 mLayoutNeeded = true;
3895 performLayoutAndPlaceSurfacesLocked();
3896 }
3897 } else if (alwaysSendConfiguration) {
3898 //update configuration ignoring orientation change
3899 sendNewConfiguration();
3900 }
Romain Guy06882f82009-06-10 13:36:04 -07003901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003902 Binder.restoreCallingIdentity(origId);
3903 }
Romain Guy06882f82009-06-10 13:36:04 -07003904
Dianne Hackborn1e880db2009-03-27 16:04:08 -07003905 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003906 boolean changed;
3907 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
3908 rotation = mRequestedRotation;
3909 } else {
3910 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07003911 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003912 }
3913 if (DEBUG_ORIENTATION) Log.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003914 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003915 mRotation, mDisplayEnabled);
3916 if (DEBUG_ORIENTATION) Log.v(TAG, "new rotation is set to " + rotation);
3917 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07003918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003919 if (changed) {
Romain Guy06882f82009-06-10 13:36:04 -07003920 if (DEBUG_ORIENTATION) Log.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003921 "Rotation changed to " + rotation
3922 + " from " + mRotation
3923 + " (forceApp=" + mForcedAppOrientation
3924 + ", req=" + mRequestedRotation + ")");
3925 mRotation = rotation;
3926 mWindowsFreezingScreen = true;
3927 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
3928 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
3929 2000);
3930 startFreezingDisplayLocked();
Dianne Hackborn1e880db2009-03-27 16:04:08 -07003931 Log.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003932 mQueue.setOrientation(rotation);
3933 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07003934 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003935 }
3936 for (int i=mWindows.size()-1; i>=0; i--) {
3937 WindowState w = (WindowState)mWindows.get(i);
3938 if (w.mSurface != null) {
3939 w.mOrientationChanging = true;
3940 }
3941 }
3942 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
3943 try {
3944 mRotationWatchers.get(i).onRotationChanged(rotation);
3945 } catch (RemoteException e) {
3946 }
3947 }
3948 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07003949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003950 return changed;
3951 }
Romain Guy06882f82009-06-10 13:36:04 -07003952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003953 public int getRotation() {
3954 return mRotation;
3955 }
3956
3957 public int watchRotation(IRotationWatcher watcher) {
3958 final IBinder watcherBinder = watcher.asBinder();
3959 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
3960 public void binderDied() {
3961 synchronized (mWindowMap) {
3962 for (int i=0; i<mRotationWatchers.size(); i++) {
3963 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07003964 IRotationWatcher removed = mRotationWatchers.remove(i);
3965 if (removed != null) {
3966 removed.asBinder().unlinkToDeath(this, 0);
3967 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003968 i--;
3969 }
3970 }
3971 }
3972 }
3973 };
Romain Guy06882f82009-06-10 13:36:04 -07003974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003975 synchronized (mWindowMap) {
3976 try {
3977 watcher.asBinder().linkToDeath(dr, 0);
3978 mRotationWatchers.add(watcher);
3979 } catch (RemoteException e) {
3980 // Client died, no cleanup needed.
3981 }
Romain Guy06882f82009-06-10 13:36:04 -07003982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003983 return mRotation;
3984 }
3985 }
3986
3987 /**
3988 * Starts the view server on the specified port.
3989 *
3990 * @param port The port to listener to.
3991 *
3992 * @return True if the server was successfully started, false otherwise.
3993 *
3994 * @see com.android.server.ViewServer
3995 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
3996 */
3997 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07003998 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003999 return false;
4000 }
4001
4002 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4003 return false;
4004 }
4005
4006 if (port < 1024) {
4007 return false;
4008 }
4009
4010 if (mViewServer != null) {
4011 if (!mViewServer.isRunning()) {
4012 try {
4013 return mViewServer.start();
4014 } catch (IOException e) {
Romain Guy06882f82009-06-10 13:36:04 -07004015 Log.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004016 }
4017 }
4018 return false;
4019 }
4020
4021 try {
4022 mViewServer = new ViewServer(this, port);
4023 return mViewServer.start();
4024 } catch (IOException e) {
4025 Log.w(TAG, "View server did not start");
4026 }
4027 return false;
4028 }
4029
Romain Guy06882f82009-06-10 13:36:04 -07004030 private boolean isSystemSecure() {
4031 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4032 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4033 }
4034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004035 /**
4036 * Stops the view server if it exists.
4037 *
4038 * @return True if the server stopped, false if it wasn't started or
4039 * couldn't be stopped.
4040 *
4041 * @see com.android.server.ViewServer
4042 */
4043 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004044 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004045 return false;
4046 }
4047
4048 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4049 return false;
4050 }
4051
4052 if (mViewServer != null) {
4053 return mViewServer.stop();
4054 }
4055 return false;
4056 }
4057
4058 /**
4059 * Indicates whether the view server is running.
4060 *
4061 * @return True if the server is running, false otherwise.
4062 *
4063 * @see com.android.server.ViewServer
4064 */
4065 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004066 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004067 return false;
4068 }
4069
4070 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4071 return false;
4072 }
4073
4074 return mViewServer != null && mViewServer.isRunning();
4075 }
4076
4077 /**
4078 * Lists all availble windows in the system. The listing is written in the
4079 * specified Socket's output stream with the following syntax:
4080 * windowHashCodeInHexadecimal windowName
4081 * Each line of the ouput represents a different window.
4082 *
4083 * @param client The remote client to send the listing to.
4084 * @return False if an error occured, true otherwise.
4085 */
4086 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004087 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004088 return false;
4089 }
4090
4091 boolean result = true;
4092
4093 Object[] windows;
4094 synchronized (mWindowMap) {
4095 windows = new Object[mWindows.size()];
4096 //noinspection unchecked
4097 windows = mWindows.toArray(windows);
4098 }
4099
4100 BufferedWriter out = null;
4101
4102 // Any uncaught exception will crash the system process
4103 try {
4104 OutputStream clientStream = client.getOutputStream();
4105 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4106
4107 final int count = windows.length;
4108 for (int i = 0; i < count; i++) {
4109 final WindowState w = (WindowState) windows[i];
4110 out.write(Integer.toHexString(System.identityHashCode(w)));
4111 out.write(' ');
4112 out.append(w.mAttrs.getTitle());
4113 out.write('\n');
4114 }
4115
4116 out.write("DONE.\n");
4117 out.flush();
4118 } catch (Exception e) {
4119 result = false;
4120 } finally {
4121 if (out != null) {
4122 try {
4123 out.close();
4124 } catch (IOException e) {
4125 result = false;
4126 }
4127 }
4128 }
4129
4130 return result;
4131 }
4132
4133 /**
4134 * Sends a command to a target window. The result of the command, if any, will be
4135 * written in the output stream of the specified socket.
4136 *
4137 * The parameters must follow this syntax:
4138 * windowHashcode extra
4139 *
4140 * Where XX is the length in characeters of the windowTitle.
4141 *
4142 * The first parameter is the target window. The window with the specified hashcode
4143 * will be the target. If no target can be found, nothing happens. The extra parameters
4144 * will be delivered to the target window and as parameters to the command itself.
4145 *
4146 * @param client The remote client to sent the result, if any, to.
4147 * @param command The command to execute.
4148 * @param parameters The command parameters.
4149 *
4150 * @return True if the command was successfully delivered, false otherwise. This does
4151 * not indicate whether the command itself was successful.
4152 */
4153 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004154 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004155 return false;
4156 }
4157
4158 boolean success = true;
4159 Parcel data = null;
4160 Parcel reply = null;
4161
4162 // Any uncaught exception will crash the system process
4163 try {
4164 // Find the hashcode of the window
4165 int index = parameters.indexOf(' ');
4166 if (index == -1) {
4167 index = parameters.length();
4168 }
4169 final String code = parameters.substring(0, index);
4170 int hashCode = "ffffffff".equals(code) ? -1 : Integer.parseInt(code, 16);
4171
4172 // Extract the command's parameter after the window description
4173 if (index < parameters.length()) {
4174 parameters = parameters.substring(index + 1);
4175 } else {
4176 parameters = "";
4177 }
4178
4179 final WindowManagerService.WindowState window = findWindow(hashCode);
4180 if (window == null) {
4181 return false;
4182 }
4183
4184 data = Parcel.obtain();
4185 data.writeInterfaceToken("android.view.IWindow");
4186 data.writeString(command);
4187 data.writeString(parameters);
4188 data.writeInt(1);
4189 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4190
4191 reply = Parcel.obtain();
4192
4193 final IBinder binder = window.mClient.asBinder();
4194 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4195 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4196
4197 reply.readException();
4198
4199 } catch (Exception e) {
4200 Log.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
4201 success = false;
4202 } finally {
4203 if (data != null) {
4204 data.recycle();
4205 }
4206 if (reply != null) {
4207 reply.recycle();
4208 }
4209 }
4210
4211 return success;
4212 }
4213
4214 private WindowState findWindow(int hashCode) {
4215 if (hashCode == -1) {
4216 return getFocusedWindow();
4217 }
4218
4219 synchronized (mWindowMap) {
4220 final ArrayList windows = mWindows;
4221 final int count = windows.size();
4222
4223 for (int i = 0; i < count; i++) {
4224 WindowState w = (WindowState) windows.get(i);
4225 if (System.identityHashCode(w) == hashCode) {
4226 return w;
4227 }
4228 }
4229 }
4230
4231 return null;
4232 }
4233
4234 /*
4235 * Instruct the Activity Manager to fetch the current configuration and broadcast
4236 * that to config-changed listeners if appropriate.
4237 */
4238 void sendNewConfiguration() {
4239 try {
4240 mActivityManager.updateConfiguration(null);
4241 } catch (RemoteException e) {
4242 }
4243 }
Romain Guy06882f82009-06-10 13:36:04 -07004244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004245 public Configuration computeNewConfiguration() {
4246 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004247 return computeNewConfigurationLocked();
4248 }
4249 }
Romain Guy06882f82009-06-10 13:36:04 -07004250
Dianne Hackbornc485a602009-03-24 22:39:49 -07004251 Configuration computeNewConfigurationLocked() {
4252 Configuration config = new Configuration();
4253 if (!computeNewConfigurationLocked(config)) {
4254 return null;
4255 }
4256 Log.i(TAG, "Config changed: " + config);
4257 long now = SystemClock.uptimeMillis();
4258 //Log.i(TAG, "Config changing, gc pending: " + mFreezeGcPending + ", now " + now);
4259 if (mFreezeGcPending != 0) {
4260 if (now > (mFreezeGcPending+1000)) {
4261 //Log.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
4262 mH.removeMessages(H.FORCE_GC);
4263 Runtime.getRuntime().gc();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004264 mFreezeGcPending = now;
4265 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004266 } else {
4267 mFreezeGcPending = now;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004268 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004269 return config;
4270 }
Romain Guy06882f82009-06-10 13:36:04 -07004271
Dianne Hackbornc485a602009-03-24 22:39:49 -07004272 boolean computeNewConfigurationLocked(Configuration config) {
4273 if (mDisplay == null) {
4274 return false;
4275 }
4276 mQueue.getInputConfiguration(config);
4277 final int dw = mDisplay.getWidth();
4278 final int dh = mDisplay.getHeight();
4279 int orientation = Configuration.ORIENTATION_SQUARE;
4280 if (dw < dh) {
4281 orientation = Configuration.ORIENTATION_PORTRAIT;
4282 } else if (dw > dh) {
4283 orientation = Configuration.ORIENTATION_LANDSCAPE;
4284 }
4285 config.orientation = orientation;
Dianne Hackborn723738c2009-06-25 19:48:04 -07004286
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004287 DisplayMetrics dm = new DisplayMetrics();
4288 mDisplay.getMetrics(dm);
4289 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4290
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004291 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004292 // Note we only do this once because at this point we don't
4293 // expect the screen to change in this way at runtime, and want
4294 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004295 int longSize = dw;
4296 int shortSize = dh;
4297 if (longSize < shortSize) {
4298 int tmp = longSize;
4299 longSize = shortSize;
4300 shortSize = tmp;
4301 }
4302 longSize = (int)(longSize/dm.density);
4303 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004304
Dianne Hackborn723738c2009-06-25 19:48:04 -07004305 // These semi-magic numbers define our compatibility modes for
4306 // applications with different screens. Don't change unless you
4307 // make sure to test lots and lots of apps!
4308 if (longSize < 470) {
4309 // This is shorter than an HVGA normal density screen (which
4310 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004311 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
4312 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07004313 } else {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004314 // Is this a large screen?
4315 if (longSize > 640 && shortSize >= 480) {
4316 // VGA or larger screens at medium density are the point
4317 // at which we consider it to be a large screen.
4318 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
4319 } else {
4320 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
4321
4322 // If this screen is wider than normal HVGA, or taller
4323 // than FWVGA, then for old apps we want to run in size
4324 // compatibility mode.
4325 if (shortSize > 321 || longSize > 570) {
4326 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
4327 }
4328 }
4329
4330 // Is this a long screen?
4331 if (((longSize*3)/5) >= (shortSize-1)) {
4332 // Anything wider than WVGA (5:3) is considering to be long.
4333 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
4334 } else {
4335 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
4336 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07004337 }
4338 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004339 config.screenLayout = mScreenLayout;
Dianne Hackborn723738c2009-06-25 19:48:04 -07004340
Dianne Hackbornc485a602009-03-24 22:39:49 -07004341 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
4342 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
4343 mPolicy.adjustConfigurationLw(config);
4344 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004345 }
Romain Guy06882f82009-06-10 13:36:04 -07004346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004347 // -------------------------------------------------------------
4348 // Input Events and Focus Management
4349 // -------------------------------------------------------------
4350
4351 private final void wakeupIfNeeded(WindowState targetWin, int eventType) {
Michael Chane96440f2009-05-06 10:27:36 -07004352 long curTime = SystemClock.uptimeMillis();
4353
Michael Chane10de972009-05-18 11:24:50 -07004354 if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) {
Michael Chane96440f2009-05-06 10:27:36 -07004355 if (mLastTouchEventType == eventType &&
4356 (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) {
4357 return;
4358 }
4359 mLastUserActivityCallTime = curTime;
4360 mLastTouchEventType = eventType;
4361 }
4362
4363 if (targetWin == null
4364 || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) {
4365 mPowerManager.userActivity(curTime, false, eventType, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004366 }
4367 }
4368
4369 // tells if it's a cheek event or not -- this function is stateful
4370 private static final int EVENT_NONE = 0;
4371 private static final int EVENT_UNKNOWN = 0;
4372 private static final int EVENT_CHEEK = 0;
4373 private static final int EVENT_IGNORE_DURATION = 300; // ms
4374 private static final float CHEEK_THRESHOLD = 0.6f;
4375 private int mEventState = EVENT_NONE;
4376 private float mEventSize;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004378 private int eventType(MotionEvent ev) {
4379 float size = ev.getSize();
4380 switch (ev.getAction()) {
4381 case MotionEvent.ACTION_DOWN:
4382 mEventSize = size;
4383 return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT;
4384 case MotionEvent.ACTION_UP:
4385 if (size > mEventSize) mEventSize = size;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004386 return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004387 case MotionEvent.ACTION_MOVE:
4388 final int N = ev.getHistorySize();
4389 if (size > mEventSize) mEventSize = size;
4390 if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT;
4391 for (int i=0; i<N; i++) {
4392 size = ev.getHistoricalSize(i);
4393 if (size > mEventSize) mEventSize = size;
4394 if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT;
4395 }
4396 if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) {
4397 return TOUCH_EVENT;
4398 } else {
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004399 return LONG_TOUCH_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004400 }
4401 default:
4402 // not good
4403 return OTHER_EVENT;
4404 }
4405 }
4406
4407 /**
4408 * @return Returns true if event was dispatched, false if it was dropped for any reason
4409 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07004410 private int dispatchPointer(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004411 if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Log.v(TAG,
4412 "dispatchPointer " + ev);
4413
Michael Chan53071d62009-05-13 17:29:48 -07004414 if (MEASURE_LATENCY) {
4415 lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano);
4416 }
4417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004418 Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07004419 ev, true, false, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004420
Michael Chan53071d62009-05-13 17:29:48 -07004421 if (MEASURE_LATENCY) {
4422 lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano);
4423 }
4424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004425 int action = ev.getAction();
Romain Guy06882f82009-06-10 13:36:04 -07004426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004427 if (action == MotionEvent.ACTION_UP) {
4428 // let go of our target
4429 mKeyWaiter.mMotionTarget = null;
4430 mPowerManager.logPointerUpEvent();
4431 } else if (action == MotionEvent.ACTION_DOWN) {
4432 mPowerManager.logPointerDownEvent();
4433 }
4434
4435 if (targetObj == null) {
4436 // In this case we are either dropping the event, or have received
4437 // a move or up without a down. It is common to receive move
4438 // events in such a way, since this means the user is moving the
4439 // pointer without actually pressing down. All other cases should
4440 // be atypical, so let's log them.
Michael Chane96440f2009-05-06 10:27:36 -07004441 if (action != MotionEvent.ACTION_MOVE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004442 Log.w(TAG, "No window to dispatch pointer action " + ev.getAction());
4443 }
4444 if (qev != null) {
4445 mQueue.recycleEvent(qev);
4446 }
4447 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07004448 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004449 }
4450 if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
4451 if (qev != null) {
4452 mQueue.recycleEvent(qev);
4453 }
4454 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07004455 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004456 }
Romain Guy06882f82009-06-10 13:36:04 -07004457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004458 WindowState target = (WindowState)targetObj;
Romain Guy06882f82009-06-10 13:36:04 -07004459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004460 final long eventTime = ev.getEventTime();
Michael Chan53071d62009-05-13 17:29:48 -07004461 final long eventTimeNano = ev.getEventTimeNano();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004462
4463 //Log.i(TAG, "Sending " + ev + " to " + target);
4464
4465 if (uid != 0 && uid != target.mSession.mUid) {
4466 if (mContext.checkPermission(
4467 android.Manifest.permission.INJECT_EVENTS, pid, uid)
4468 != PackageManager.PERMISSION_GRANTED) {
4469 Log.w(TAG, "Permission denied: injecting pointer event from pid "
4470 + pid + " uid " + uid + " to window " + target
4471 + " owned by uid " + target.mSession.mUid);
4472 if (qev != null) {
4473 mQueue.recycleEvent(qev);
4474 }
4475 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07004476 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004477 }
4478 }
4479
Michael Chan53071d62009-05-13 17:29:48 -07004480 if (MEASURE_LATENCY) {
4481 lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano);
4482 }
4483
Romain Guy06882f82009-06-10 13:36:04 -07004484 if ((target.mAttrs.flags &
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004485 WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) {
4486 //target wants to ignore fat touch events
4487 boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev);
4488 //explicit flag to return without processing event further
4489 boolean returnFlag = false;
4490 if((action == MotionEvent.ACTION_DOWN)) {
4491 mFatTouch = false;
4492 if(cheekPress) {
4493 mFatTouch = true;
4494 returnFlag = true;
4495 }
4496 } else {
4497 if(action == MotionEvent.ACTION_UP) {
4498 if(mFatTouch) {
4499 //earlier even was invalid doesnt matter if current up is cheekpress or not
4500 mFatTouch = false;
4501 returnFlag = true;
4502 } else if(cheekPress) {
4503 //cancel the earlier event
4504 ev.setAction(MotionEvent.ACTION_CANCEL);
4505 action = MotionEvent.ACTION_CANCEL;
4506 }
4507 } else if(action == MotionEvent.ACTION_MOVE) {
4508 if(mFatTouch) {
4509 //two cases here
4510 //an invalid down followed by 0 or moves(valid or invalid)
Romain Guy06882f82009-06-10 13:36:04 -07004511 //a valid down, invalid move, more moves. want to ignore till up
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004512 returnFlag = true;
4513 } else if(cheekPress) {
4514 //valid down followed by invalid moves
4515 //an invalid move have to cancel earlier action
4516 ev.setAction(MotionEvent.ACTION_CANCEL);
4517 action = MotionEvent.ACTION_CANCEL;
4518 if (DEBUG_INPUT) Log.v(TAG, "Sending cancel for invalid ACTION_MOVE");
4519 //note that the subsequent invalid moves will not get here
4520 mFatTouch = true;
4521 }
4522 }
4523 } //else if action
4524 if(returnFlag) {
4525 //recycle que, ev
4526 if (qev != null) {
4527 mQueue.recycleEvent(qev);
4528 }
4529 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07004530 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004531 }
4532 } //end if target
Michael Chane96440f2009-05-06 10:27:36 -07004533
Michael Chan9f028e62009-08-04 17:37:46 -07004534 // Enable this for testing the "right" value
4535 if (false && action == MotionEvent.ACTION_DOWN) {
Michael Chane96440f2009-05-06 10:27:36 -07004536 int max_events_per_sec = 35;
4537 try {
4538 max_events_per_sec = Integer.parseInt(SystemProperties
4539 .get("windowsmgr.max_events_per_sec"));
4540 if (max_events_per_sec < 1) {
4541 max_events_per_sec = 35;
4542 }
4543 } catch (NumberFormatException e) {
4544 }
4545 mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec;
4546 }
4547
4548 /*
4549 * Throttle events to minimize CPU usage when there's a flood of events
4550 * e.g. constant contact with the screen
4551 */
4552 if (action == MotionEvent.ACTION_MOVE) {
4553 long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents;
4554 long now = SystemClock.uptimeMillis();
4555 if (now < nextEventTime) {
4556 try {
4557 Thread.sleep(nextEventTime - now);
4558 } catch (InterruptedException e) {
4559 }
4560 mLastTouchEventTime = nextEventTime;
4561 } else {
4562 mLastTouchEventTime = now;
4563 }
4564 }
4565
Michael Chan53071d62009-05-13 17:29:48 -07004566 if (MEASURE_LATENCY) {
4567 lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano);
4568 }
4569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004570 synchronized(mWindowMap) {
4571 if (qev != null && action == MotionEvent.ACTION_MOVE) {
4572 mKeyWaiter.bindTargetWindowLocked(target,
4573 KeyWaiter.RETURN_PENDING_POINTER, qev);
4574 ev = null;
4575 } else {
4576 if (action == MotionEvent.ACTION_DOWN) {
4577 WindowState out = mKeyWaiter.mOutsideTouchTargets;
4578 if (out != null) {
4579 MotionEvent oev = MotionEvent.obtain(ev);
4580 oev.setAction(MotionEvent.ACTION_OUTSIDE);
4581 do {
4582 final Rect frame = out.mFrame;
4583 oev.offsetLocation(-(float)frame.left, -(float)frame.top);
4584 try {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07004585 out.mClient.dispatchPointer(oev, eventTime, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004586 } catch (android.os.RemoteException e) {
4587 Log.i(TAG, "WINDOW DIED during outside motion dispatch: " + out);
4588 }
4589 oev.offsetLocation((float)frame.left, (float)frame.top);
4590 out = out.mNextOutsideTouch;
4591 } while (out != null);
4592 mKeyWaiter.mOutsideTouchTargets = null;
4593 }
4594 }
4595 final Rect frame = target.mFrame;
4596 ev.offsetLocation(-(float)frame.left, -(float)frame.top);
4597 mKeyWaiter.bindTargetWindowLocked(target);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07004598
4599 // If we are on top of the wallpaper, then the wallpaper also
4600 // gets to see this movement.
4601 if (mWallpaperTarget == target) {
4602 sendPointerToWallpaperLocked(target, ev, eventTime);
4603 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004604 }
4605 }
Romain Guy06882f82009-06-10 13:36:04 -07004606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004607 // finally offset the event to the target's coordinate system and
4608 // dispatch the event.
4609 try {
4610 if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) {
4611 Log.v(TAG, "Delivering pointer " + qev + " to " + target);
4612 }
Michael Chan53071d62009-05-13 17:29:48 -07004613
4614 if (MEASURE_LATENCY) {
4615 lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano);
4616 }
4617
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07004618 target.mClient.dispatchPointer(ev, eventTime, true);
Michael Chan53071d62009-05-13 17:29:48 -07004619
4620 if (MEASURE_LATENCY) {
4621 lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano);
4622 }
Dianne Hackborncfaef692009-06-15 14:24:44 -07004623 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004624 } catch (android.os.RemoteException e) {
4625 Log.i(TAG, "WINDOW DIED during motion dispatch: " + target);
4626 mKeyWaiter.mMotionTarget = null;
4627 try {
4628 removeWindow(target.mSession, target.mClient);
4629 } catch (java.util.NoSuchElementException ex) {
4630 // This will happen if the window has already been
4631 // removed.
4632 }
4633 }
Dianne Hackborncfaef692009-06-15 14:24:44 -07004634 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004635 }
Romain Guy06882f82009-06-10 13:36:04 -07004636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004637 /**
4638 * @return Returns true if event was dispatched, false if it was dropped for any reason
4639 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07004640 private int dispatchTrackball(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004641 if (DEBUG_INPUT) Log.v(
4642 TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">");
Romain Guy06882f82009-06-10 13:36:04 -07004643
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004644 Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07004645 ev, false, false, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004646 if (focusObj == null) {
4647 Log.w(TAG, "No focus window, dropping trackball: " + ev);
4648 if (qev != null) {
4649 mQueue.recycleEvent(qev);
4650 }
4651 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07004652 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004653 }
4654 if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
4655 if (qev != null) {
4656 mQueue.recycleEvent(qev);
4657 }
4658 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07004659 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004660 }
Romain Guy06882f82009-06-10 13:36:04 -07004661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004662 WindowState focus = (WindowState)focusObj;
Romain Guy06882f82009-06-10 13:36:04 -07004663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004664 if (uid != 0 && uid != focus.mSession.mUid) {
4665 if (mContext.checkPermission(
4666 android.Manifest.permission.INJECT_EVENTS, pid, uid)
4667 != PackageManager.PERMISSION_GRANTED) {
4668 Log.w(TAG, "Permission denied: injecting key event from pid "
4669 + pid + " uid " + uid + " to window " + focus
4670 + " owned by uid " + focus.mSession.mUid);
4671 if (qev != null) {
4672 mQueue.recycleEvent(qev);
4673 }
4674 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07004675 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004676 }
4677 }
Romain Guy06882f82009-06-10 13:36:04 -07004678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004679 final long eventTime = ev.getEventTime();
Romain Guy06882f82009-06-10 13:36:04 -07004680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004681 synchronized(mWindowMap) {
4682 if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) {
4683 mKeyWaiter.bindTargetWindowLocked(focus,
4684 KeyWaiter.RETURN_PENDING_TRACKBALL, qev);
4685 // We don't deliver movement events to the client, we hold
4686 // them and wait for them to call back.
4687 ev = null;
4688 } else {
4689 mKeyWaiter.bindTargetWindowLocked(focus);
4690 }
4691 }
Romain Guy06882f82009-06-10 13:36:04 -07004692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004693 try {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07004694 focus.mClient.dispatchTrackball(ev, eventTime, true);
Dianne Hackborncfaef692009-06-15 14:24:44 -07004695 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004696 } catch (android.os.RemoteException e) {
4697 Log.i(TAG, "WINDOW DIED during key dispatch: " + focus);
4698 try {
4699 removeWindow(focus.mSession, focus.mClient);
4700 } catch (java.util.NoSuchElementException ex) {
4701 // This will happen if the window has already been
4702 // removed.
4703 }
4704 }
Romain Guy06882f82009-06-10 13:36:04 -07004705
Dianne Hackborncfaef692009-06-15 14:24:44 -07004706 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004707 }
Romain Guy06882f82009-06-10 13:36:04 -07004708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004709 /**
4710 * @return Returns true if event was dispatched, false if it was dropped for any reason
4711 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07004712 private int dispatchKey(KeyEvent event, int pid, int uid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004713 if (DEBUG_INPUT) Log.v(TAG, "Dispatch key: " + event);
4714
4715 Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07004716 null, false, false, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004717 if (focusObj == null) {
4718 Log.w(TAG, "No focus window, dropping: " + event);
Dianne Hackborncfaef692009-06-15 14:24:44 -07004719 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004720 }
4721 if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004722 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004723 }
Romain Guy06882f82009-06-10 13:36:04 -07004724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004725 WindowState focus = (WindowState)focusObj;
Romain Guy06882f82009-06-10 13:36:04 -07004726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004727 if (DEBUG_INPUT) Log.v(
4728 TAG, "Dispatching to " + focus + ": " + event);
4729
4730 if (uid != 0 && uid != focus.mSession.mUid) {
4731 if (mContext.checkPermission(
4732 android.Manifest.permission.INJECT_EVENTS, pid, uid)
4733 != PackageManager.PERMISSION_GRANTED) {
4734 Log.w(TAG, "Permission denied: injecting key event from pid "
4735 + pid + " uid " + uid + " to window " + focus
4736 + " owned by uid " + focus.mSession.mUid);
Dianne Hackborncfaef692009-06-15 14:24:44 -07004737 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004738 }
4739 }
Romain Guy06882f82009-06-10 13:36:04 -07004740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004741 synchronized(mWindowMap) {
4742 mKeyWaiter.bindTargetWindowLocked(focus);
4743 }
4744
4745 // NOSHIP extra state logging
4746 mKeyWaiter.recordDispatchState(event, focus);
4747 // END NOSHIP
Romain Guy06882f82009-06-10 13:36:04 -07004748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004749 try {
4750 if (DEBUG_INPUT || DEBUG_FOCUS) {
4751 Log.v(TAG, "Delivering key " + event.getKeyCode()
4752 + " to " + focus);
4753 }
4754 focus.mClient.dispatchKey(event);
Dianne Hackborncfaef692009-06-15 14:24:44 -07004755 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004756 } catch (android.os.RemoteException e) {
4757 Log.i(TAG, "WINDOW DIED during key dispatch: " + focus);
4758 try {
4759 removeWindow(focus.mSession, focus.mClient);
4760 } catch (java.util.NoSuchElementException ex) {
4761 // This will happen if the window has already been
4762 // removed.
4763 }
4764 }
Romain Guy06882f82009-06-10 13:36:04 -07004765
Dianne Hackborncfaef692009-06-15 14:24:44 -07004766 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004767 }
Romain Guy06882f82009-06-10 13:36:04 -07004768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004769 public void pauseKeyDispatching(IBinder _token) {
4770 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4771 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004772 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004773 }
4774
4775 synchronized (mWindowMap) {
4776 WindowToken token = mTokenMap.get(_token);
4777 if (token != null) {
4778 mKeyWaiter.pauseDispatchingLocked(token);
4779 }
4780 }
4781 }
4782
4783 public void resumeKeyDispatching(IBinder _token) {
4784 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4785 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004786 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004787 }
4788
4789 synchronized (mWindowMap) {
4790 WindowToken token = mTokenMap.get(_token);
4791 if (token != null) {
4792 mKeyWaiter.resumeDispatchingLocked(token);
4793 }
4794 }
4795 }
4796
4797 public void setEventDispatching(boolean enabled) {
4798 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4799 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004800 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004801 }
4802
4803 synchronized (mWindowMap) {
4804 mKeyWaiter.setEventDispatchingLocked(enabled);
4805 }
4806 }
Romain Guy06882f82009-06-10 13:36:04 -07004807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004808 /**
4809 * Injects a keystroke event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07004810 *
4811 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004812 * {@link SystemClock#uptimeMillis()} as the timebase.)
4813 * @param sync If true, wait for the event to be completed before returning to the caller.
4814 * @return Returns true if event was dispatched, false if it was dropped for any reason
4815 */
4816 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
4817 long downTime = ev.getDownTime();
4818 long eventTime = ev.getEventTime();
4819
4820 int action = ev.getAction();
4821 int code = ev.getKeyCode();
4822 int repeatCount = ev.getRepeatCount();
4823 int metaState = ev.getMetaState();
4824 int deviceId = ev.getDeviceId();
4825 int scancode = ev.getScanCode();
4826
4827 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
4828 if (downTime == 0) downTime = eventTime;
4829
4830 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
The Android Open Source Project10592532009-03-18 17:39:46 -07004831 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004832
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07004833 final int pid = Binder.getCallingPid();
4834 final int uid = Binder.getCallingUid();
4835 final long ident = Binder.clearCallingIdentity();
4836 final int result = dispatchKey(newEvent, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004837 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07004838 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004839 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07004840 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07004841 switch (result) {
4842 case INJECT_NO_PERMISSION:
4843 throw new SecurityException(
4844 "Injecting to another application requires INJECT_EVENT permission");
4845 case INJECT_SUCCEEDED:
4846 return true;
4847 }
4848 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004849 }
4850
4851 /**
4852 * Inject a pointer (touch) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07004853 *
4854 * @param ev A motion event describing the pointer (touch) action. (As noted in
4855 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004856 * {@link SystemClock#uptimeMillis()} as the timebase.)
4857 * @param sync If true, wait for the event to be completed before returning to the caller.
4858 * @return Returns true if event was dispatched, false if it was dropped for any reason
4859 */
4860 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07004861 final int pid = Binder.getCallingPid();
4862 final int uid = Binder.getCallingUid();
4863 final long ident = Binder.clearCallingIdentity();
4864 final int result = dispatchPointer(null, ev, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004865 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07004866 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004867 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07004868 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07004869 switch (result) {
4870 case INJECT_NO_PERMISSION:
4871 throw new SecurityException(
4872 "Injecting to another application requires INJECT_EVENT permission");
4873 case INJECT_SUCCEEDED:
4874 return true;
4875 }
4876 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004877 }
Romain Guy06882f82009-06-10 13:36:04 -07004878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004879 /**
4880 * Inject a trackball (navigation device) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07004881 *
4882 * @param ev A motion event describing the trackball action. (As noted in
4883 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004884 * {@link SystemClock#uptimeMillis()} as the timebase.)
4885 * @param sync If true, wait for the event to be completed before returning to the caller.
4886 * @return Returns true if event was dispatched, false if it was dropped for any reason
4887 */
4888 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07004889 final int pid = Binder.getCallingPid();
4890 final int uid = Binder.getCallingUid();
4891 final long ident = Binder.clearCallingIdentity();
4892 final int result = dispatchTrackball(null, ev, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004893 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07004894 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004895 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07004896 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07004897 switch (result) {
4898 case INJECT_NO_PERMISSION:
4899 throw new SecurityException(
4900 "Injecting to another application requires INJECT_EVENT permission");
4901 case INJECT_SUCCEEDED:
4902 return true;
4903 }
4904 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004905 }
Romain Guy06882f82009-06-10 13:36:04 -07004906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004907 private WindowState getFocusedWindow() {
4908 synchronized (mWindowMap) {
4909 return getFocusedWindowLocked();
4910 }
4911 }
4912
4913 private WindowState getFocusedWindowLocked() {
4914 return mCurrentFocus;
4915 }
Romain Guy06882f82009-06-10 13:36:04 -07004916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004917 /**
4918 * This class holds the state for dispatching key events. This state
4919 * is protected by the KeyWaiter instance, NOT by the window lock. You
4920 * can be holding the main window lock while acquire the KeyWaiter lock,
4921 * but not the other way around.
4922 */
4923 final class KeyWaiter {
4924 // NOSHIP debugging
4925 public class DispatchState {
4926 private KeyEvent event;
4927 private WindowState focus;
4928 private long time;
4929 private WindowState lastWin;
4930 private IBinder lastBinder;
4931 private boolean finished;
4932 private boolean gotFirstWindow;
4933 private boolean eventDispatching;
4934 private long timeToSwitch;
4935 private boolean wasFrozen;
4936 private boolean focusPaused;
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08004937 private WindowState curFocus;
Romain Guy06882f82009-06-10 13:36:04 -07004938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004939 DispatchState(KeyEvent theEvent, WindowState theFocus) {
4940 focus = theFocus;
4941 event = theEvent;
4942 time = System.currentTimeMillis();
4943 // snapshot KeyWaiter state
4944 lastWin = mLastWin;
4945 lastBinder = mLastBinder;
4946 finished = mFinished;
4947 gotFirstWindow = mGotFirstWindow;
4948 eventDispatching = mEventDispatching;
4949 timeToSwitch = mTimeToSwitch;
4950 wasFrozen = mWasFrozen;
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08004951 curFocus = mCurrentFocus;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004952 // cache the paused state at ctor time as well
4953 if (theFocus == null || theFocus.mToken == null) {
4954 Log.i(TAG, "focus " + theFocus + " mToken is null at event dispatch!");
4955 focusPaused = false;
4956 } else {
4957 focusPaused = theFocus.mToken.paused;
4958 }
4959 }
Romain Guy06882f82009-06-10 13:36:04 -07004960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004961 public String toString() {
4962 return "{{" + event + " to " + focus + " @ " + time
4963 + " lw=" + lastWin + " lb=" + lastBinder
4964 + " fin=" + finished + " gfw=" + gotFirstWindow
4965 + " ed=" + eventDispatching + " tts=" + timeToSwitch
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08004966 + " wf=" + wasFrozen + " fp=" + focusPaused
4967 + " mcf=" + mCurrentFocus + "}}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004968 }
4969 };
4970 private DispatchState mDispatchState = null;
4971 public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) {
4972 mDispatchState = new DispatchState(theEvent, theFocus);
4973 }
4974 // END NOSHIP
4975
4976 public static final int RETURN_NOTHING = 0;
4977 public static final int RETURN_PENDING_POINTER = 1;
4978 public static final int RETURN_PENDING_TRACKBALL = 2;
Romain Guy06882f82009-06-10 13:36:04 -07004979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004980 final Object SKIP_TARGET_TOKEN = new Object();
4981 final Object CONSUMED_EVENT_TOKEN = new Object();
Romain Guy06882f82009-06-10 13:36:04 -07004982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004983 private WindowState mLastWin = null;
4984 private IBinder mLastBinder = null;
4985 private boolean mFinished = true;
4986 private boolean mGotFirstWindow = false;
4987 private boolean mEventDispatching = true;
4988 private long mTimeToSwitch = 0;
4989 /* package */ boolean mWasFrozen = false;
Romain Guy06882f82009-06-10 13:36:04 -07004990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004991 // Target of Motion events
4992 WindowState mMotionTarget;
Romain Guy06882f82009-06-10 13:36:04 -07004993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004994 // Windows above the target who would like to receive an "outside"
4995 // touch event for any down events outside of them.
4996 WindowState mOutsideTouchTargets;
4997
4998 /**
4999 * Wait for the last event dispatch to complete, then find the next
5000 * target that should receive the given event and wait for that one
5001 * to be ready to receive it.
5002 */
5003 Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev,
5004 MotionEvent nextMotion, boolean isPointerEvent,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005005 boolean failIfTimeout, int callingPid, int callingUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005006 long startTime = SystemClock.uptimeMillis();
5007 long keyDispatchingTimeout = 5 * 1000;
5008 long waitedFor = 0;
5009
5010 while (true) {
5011 // Figure out which window we care about. It is either the
5012 // last window we are waiting to have process the event or,
5013 // if none, then the next window we think the event should go
5014 // to. Note: we retrieve mLastWin outside of the lock, so
5015 // it may change before we lock. Thus we must check it again.
5016 WindowState targetWin = mLastWin;
5017 boolean targetIsNew = targetWin == null;
5018 if (DEBUG_INPUT) Log.v(
5019 TAG, "waitForLastKey: mFinished=" + mFinished +
5020 ", mLastWin=" + mLastWin);
5021 if (targetIsNew) {
5022 Object target = findTargetWindow(nextKey, qev, nextMotion,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005023 isPointerEvent, callingPid, callingUid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005024 if (target == SKIP_TARGET_TOKEN) {
5025 // The user has pressed a special key, and we are
5026 // dropping all pending events before it.
5027 if (DEBUG_INPUT) Log.v(TAG, "Skipping: " + nextKey
5028 + " " + nextMotion);
5029 return null;
5030 }
5031 if (target == CONSUMED_EVENT_TOKEN) {
5032 if (DEBUG_INPUT) Log.v(TAG, "Consumed: " + nextKey
5033 + " " + nextMotion);
5034 return target;
5035 }
5036 targetWin = (WindowState)target;
5037 }
Romain Guy06882f82009-06-10 13:36:04 -07005038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005039 AppWindowToken targetApp = null;
Romain Guy06882f82009-06-10 13:36:04 -07005040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005041 // Now: is it okay to send the next event to this window?
5042 synchronized (this) {
5043 // First: did we come here based on the last window not
5044 // being null, but it changed by the time we got here?
5045 // If so, try again.
5046 if (!targetIsNew && mLastWin == null) {
5047 continue;
5048 }
Romain Guy06882f82009-06-10 13:36:04 -07005049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005050 // We never dispatch events if not finished with the
5051 // last one, or the display is frozen.
5052 if (mFinished && !mDisplayFrozen) {
5053 // If event dispatching is disabled, then we
5054 // just consume the events.
5055 if (!mEventDispatching) {
5056 if (DEBUG_INPUT) Log.v(TAG,
5057 "Skipping event; dispatching disabled: "
5058 + nextKey + " " + nextMotion);
5059 return null;
5060 }
5061 if (targetWin != null) {
5062 // If this is a new target, and that target is not
5063 // paused or unresponsive, then all looks good to
5064 // handle the event.
5065 if (targetIsNew && !targetWin.mToken.paused) {
5066 return targetWin;
5067 }
Romain Guy06882f82009-06-10 13:36:04 -07005068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005069 // If we didn't find a target window, and there is no
5070 // focused app window, then just eat the events.
5071 } else if (mFocusedApp == null) {
5072 if (DEBUG_INPUT) Log.v(TAG,
5073 "Skipping event; no focused app: "
5074 + nextKey + " " + nextMotion);
5075 return null;
5076 }
5077 }
Romain Guy06882f82009-06-10 13:36:04 -07005078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005079 if (DEBUG_INPUT) Log.v(
5080 TAG, "Waiting for last key in " + mLastBinder
5081 + " target=" + targetWin
5082 + " mFinished=" + mFinished
5083 + " mDisplayFrozen=" + mDisplayFrozen
5084 + " targetIsNew=" + targetIsNew
5085 + " paused="
5086 + (targetWin != null ? targetWin.mToken.paused : false)
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005087 + " mFocusedApp=" + mFocusedApp
5088 + " mCurrentFocus=" + mCurrentFocus);
Romain Guy06882f82009-06-10 13:36:04 -07005089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005090 targetApp = targetWin != null
5091 ? targetWin.mAppToken : mFocusedApp;
Romain Guy06882f82009-06-10 13:36:04 -07005092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005093 long curTimeout = keyDispatchingTimeout;
5094 if (mTimeToSwitch != 0) {
5095 long now = SystemClock.uptimeMillis();
5096 if (mTimeToSwitch <= now) {
5097 // If an app switch key has been pressed, and we have
5098 // waited too long for the current app to finish
5099 // processing keys, then wait no more!
5100 doFinishedKeyLocked(true);
5101 continue;
5102 }
5103 long switchTimeout = mTimeToSwitch - now;
5104 if (curTimeout > switchTimeout) {
5105 curTimeout = switchTimeout;
5106 }
5107 }
Romain Guy06882f82009-06-10 13:36:04 -07005108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005109 try {
5110 // after that continue
5111 // processing keys, so we don't get stuck.
5112 if (DEBUG_INPUT) Log.v(
5113 TAG, "Waiting for key dispatch: " + curTimeout);
5114 wait(curTimeout);
5115 if (DEBUG_INPUT) Log.v(TAG, "Finished waiting @"
5116 + SystemClock.uptimeMillis() + " startTime="
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005117 + startTime + " switchTime=" + mTimeToSwitch
5118 + " target=" + targetWin + " mLW=" + mLastWin
5119 + " mLB=" + mLastBinder + " fin=" + mFinished
5120 + " mCurrentFocus=" + mCurrentFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005121 } catch (InterruptedException e) {
5122 }
5123 }
5124
5125 // If we were frozen during configuration change, restart the
5126 // timeout checks from now; otherwise look at whether we timed
5127 // out before awakening.
5128 if (mWasFrozen) {
5129 waitedFor = 0;
5130 mWasFrozen = false;
5131 } else {
5132 waitedFor = SystemClock.uptimeMillis() - startTime;
5133 }
5134
5135 if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) {
5136 IApplicationToken at = null;
5137 synchronized (this) {
5138 Log.w(TAG, "Key dispatching timed out sending to " +
5139 (targetWin != null ? targetWin.mAttrs.getTitle()
5140 : "<null>"));
5141 // NOSHIP debugging
5142 Log.w(TAG, "Dispatch state: " + mDispatchState);
5143 Log.w(TAG, "Current state: " + new DispatchState(nextKey, targetWin));
5144 // END NOSHIP
5145 //dump();
5146 if (targetWin != null) {
5147 at = targetWin.getAppToken();
5148 } else if (targetApp != null) {
5149 at = targetApp.appToken;
5150 }
5151 }
5152
5153 boolean abort = true;
5154 if (at != null) {
5155 try {
5156 long timeout = at.getKeyDispatchingTimeout();
5157 if (timeout > waitedFor) {
5158 // we did not wait the proper amount of time for this application.
5159 // set the timeout to be the real timeout and wait again.
5160 keyDispatchingTimeout = timeout - waitedFor;
5161 continue;
5162 } else {
5163 abort = at.keyDispatchingTimedOut();
5164 }
5165 } catch (RemoteException ex) {
5166 }
5167 }
5168
5169 synchronized (this) {
5170 if (abort && (mLastWin == targetWin || targetWin == null)) {
5171 mFinished = true;
Romain Guy06882f82009-06-10 13:36:04 -07005172 if (mLastWin != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005173 if (DEBUG_INPUT) Log.v(TAG,
5174 "Window " + mLastWin +
5175 " timed out on key input");
5176 if (mLastWin.mToken.paused) {
5177 Log.w(TAG, "Un-pausing dispatching to this window");
5178 mLastWin.mToken.paused = false;
5179 }
5180 }
5181 if (mMotionTarget == targetWin) {
5182 mMotionTarget = null;
5183 }
5184 mLastWin = null;
5185 mLastBinder = null;
5186 if (failIfTimeout || targetWin == null) {
5187 return null;
5188 }
5189 } else {
5190 Log.w(TAG, "Continuing to wait for key to be dispatched");
5191 startTime = SystemClock.uptimeMillis();
5192 }
5193 }
5194 }
5195 }
5196 }
Romain Guy06882f82009-06-10 13:36:04 -07005197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005198 Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005199 MotionEvent nextMotion, boolean isPointerEvent,
5200 int callingPid, int callingUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005201 mOutsideTouchTargets = null;
Romain Guy06882f82009-06-10 13:36:04 -07005202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005203 if (nextKey != null) {
5204 // Find the target window for a normal key event.
5205 final int keycode = nextKey.getKeyCode();
5206 final int repeatCount = nextKey.getRepeatCount();
5207 final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP;
5208 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode);
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005210 if (!dispatch) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005211 if (callingUid == 0 ||
5212 mContext.checkPermission(
5213 android.Manifest.permission.INJECT_EVENTS,
5214 callingPid, callingUid)
5215 == PackageManager.PERMISSION_GRANTED) {
5216 mPolicy.interceptKeyTi(null, keycode,
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07005217 nextKey.getMetaState(), down, repeatCount,
5218 nextKey.getFlags());
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005219 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005220 Log.w(TAG, "Event timeout during app switch: dropping "
5221 + nextKey);
5222 return SKIP_TARGET_TOKEN;
5223 }
Romain Guy06882f82009-06-10 13:36:04 -07005224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005225 // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")");
Romain Guy06882f82009-06-10 13:36:04 -07005226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005227 WindowState focus = null;
5228 synchronized(mWindowMap) {
5229 focus = getFocusedWindowLocked();
5230 }
Romain Guy06882f82009-06-10 13:36:04 -07005231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005232 wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT);
Romain Guy06882f82009-06-10 13:36:04 -07005233
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005234 if (callingUid == 0 ||
5235 (focus != null && callingUid == focus.mSession.mUid) ||
5236 mContext.checkPermission(
5237 android.Manifest.permission.INJECT_EVENTS,
5238 callingPid, callingUid)
5239 == PackageManager.PERMISSION_GRANTED) {
5240 if (mPolicy.interceptKeyTi(focus,
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07005241 keycode, nextKey.getMetaState(), down, repeatCount,
5242 nextKey.getFlags())) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005243 return CONSUMED_EVENT_TOKEN;
5244 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005245 }
Romain Guy06882f82009-06-10 13:36:04 -07005246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005247 return focus;
Romain Guy06882f82009-06-10 13:36:04 -07005248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005249 } else if (!isPointerEvent) {
5250 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1);
5251 if (!dispatch) {
5252 Log.w(TAG, "Event timeout during app switch: dropping trackball "
5253 + nextMotion);
5254 return SKIP_TARGET_TOKEN;
5255 }
Romain Guy06882f82009-06-10 13:36:04 -07005256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005257 WindowState focus = null;
5258 synchronized(mWindowMap) {
5259 focus = getFocusedWindowLocked();
5260 }
Romain Guy06882f82009-06-10 13:36:04 -07005261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005262 wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT);
5263 return focus;
5264 }
Romain Guy06882f82009-06-10 13:36:04 -07005265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005266 if (nextMotion == null) {
5267 return SKIP_TARGET_TOKEN;
5268 }
Romain Guy06882f82009-06-10 13:36:04 -07005269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005270 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(
5271 KeyEvent.KEYCODE_UNKNOWN);
5272 if (!dispatch) {
5273 Log.w(TAG, "Event timeout during app switch: dropping pointer "
5274 + nextMotion);
5275 return SKIP_TARGET_TOKEN;
5276 }
Romain Guy06882f82009-06-10 13:36:04 -07005277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005278 // Find the target window for a pointer event.
5279 int action = nextMotion.getAction();
5280 final float xf = nextMotion.getX();
5281 final float yf = nextMotion.getY();
5282 final long eventTime = nextMotion.getEventTime();
Romain Guy06882f82009-06-10 13:36:04 -07005283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005284 final boolean screenWasOff = qev != null
5285 && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07005286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005287 WindowState target = null;
Romain Guy06882f82009-06-10 13:36:04 -07005288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005289 synchronized(mWindowMap) {
5290 synchronized (this) {
5291 if (action == MotionEvent.ACTION_DOWN) {
5292 if (mMotionTarget != null) {
5293 // this is weird, we got a pen down, but we thought it was
5294 // already down!
5295 // XXX: We should probably send an ACTION_UP to the current
5296 // target.
5297 Log.w(TAG, "Pointer down received while already down in: "
5298 + mMotionTarget);
5299 mMotionTarget = null;
5300 }
Romain Guy06882f82009-06-10 13:36:04 -07005301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005302 // ACTION_DOWN is special, because we need to lock next events to
5303 // the window we'll land onto.
5304 final int x = (int)xf;
5305 final int y = (int)yf;
Romain Guy06882f82009-06-10 13:36:04 -07005306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005307 final ArrayList windows = mWindows;
5308 final int N = windows.size();
5309 WindowState topErrWindow = null;
5310 final Rect tmpRect = mTempRect;
5311 for (int i=N-1; i>=0; i--) {
5312 WindowState child = (WindowState)windows.get(i);
5313 //Log.i(TAG, "Checking dispatch to: " + child);
5314 final int flags = child.mAttrs.flags;
5315 if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) {
5316 if (topErrWindow == null) {
5317 topErrWindow = child;
5318 }
5319 }
5320 if (!child.isVisibleLw()) {
5321 //Log.i(TAG, "Not visible!");
5322 continue;
5323 }
5324 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
5325 //Log.i(TAG, "Not touchable!");
5326 if ((flags & WindowManager.LayoutParams
5327 .FLAG_WATCH_OUTSIDE_TOUCH) != 0) {
5328 child.mNextOutsideTouch = mOutsideTouchTargets;
5329 mOutsideTouchTargets = child;
5330 }
5331 continue;
5332 }
5333 tmpRect.set(child.mFrame);
5334 if (child.mTouchableInsets == ViewTreeObserver
5335 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
5336 // The touch is inside of the window if it is
5337 // inside the frame, AND the content part of that
5338 // frame that was given by the application.
5339 tmpRect.left += child.mGivenContentInsets.left;
5340 tmpRect.top += child.mGivenContentInsets.top;
5341 tmpRect.right -= child.mGivenContentInsets.right;
5342 tmpRect.bottom -= child.mGivenContentInsets.bottom;
5343 } else if (child.mTouchableInsets == ViewTreeObserver
5344 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
5345 // The touch is inside of the window if it is
5346 // inside the frame, AND the visible part of that
5347 // frame that was given by the application.
5348 tmpRect.left += child.mGivenVisibleInsets.left;
5349 tmpRect.top += child.mGivenVisibleInsets.top;
5350 tmpRect.right -= child.mGivenVisibleInsets.right;
5351 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
5352 }
5353 final int touchFlags = flags &
5354 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
5355 |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
5356 if (tmpRect.contains(x, y) || touchFlags == 0) {
5357 //Log.i(TAG, "Using this target!");
5358 if (!screenWasOff || (flags &
5359 WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) {
5360 mMotionTarget = child;
5361 } else {
5362 //Log.i(TAG, "Waking, skip!");
5363 mMotionTarget = null;
5364 }
5365 break;
5366 }
Romain Guy06882f82009-06-10 13:36:04 -07005367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005368 if ((flags & WindowManager.LayoutParams
5369 .FLAG_WATCH_OUTSIDE_TOUCH) != 0) {
5370 child.mNextOutsideTouch = mOutsideTouchTargets;
5371 mOutsideTouchTargets = child;
5372 //Log.i(TAG, "Adding to outside target list: " + child);
5373 }
5374 }
5375
5376 // if there's an error window but it's not accepting
5377 // focus (typically because it is not yet visible) just
5378 // wait for it -- any other focused window may in fact
5379 // be in ANR state.
5380 if (topErrWindow != null && mMotionTarget != topErrWindow) {
5381 mMotionTarget = null;
5382 }
5383 }
Romain Guy06882f82009-06-10 13:36:04 -07005384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005385 target = mMotionTarget;
5386 }
5387 }
Romain Guy06882f82009-06-10 13:36:04 -07005388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005389 wakeupIfNeeded(target, eventType(nextMotion));
Romain Guy06882f82009-06-10 13:36:04 -07005390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005391 // Pointer events are a little different -- if there isn't a
5392 // target found for any event, then just drop it.
5393 return target != null ? target : SKIP_TARGET_TOKEN;
5394 }
Romain Guy06882f82009-06-10 13:36:04 -07005395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005396 boolean checkShouldDispatchKey(int keycode) {
5397 synchronized (this) {
5398 if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) {
5399 mTimeToSwitch = 0;
5400 return true;
5401 }
5402 if (mTimeToSwitch != 0
5403 && mTimeToSwitch < SystemClock.uptimeMillis()) {
5404 return false;
5405 }
5406 return true;
5407 }
5408 }
Romain Guy06882f82009-06-10 13:36:04 -07005409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005410 void bindTargetWindowLocked(WindowState win,
5411 int pendingWhat, QueuedEvent pendingMotion) {
5412 synchronized (this) {
5413 bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion);
5414 }
5415 }
Romain Guy06882f82009-06-10 13:36:04 -07005416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005417 void bindTargetWindowLocked(WindowState win) {
5418 synchronized (this) {
5419 bindTargetWindowLockedLocked(win, RETURN_NOTHING, null);
5420 }
5421 }
5422
5423 void bindTargetWindowLockedLocked(WindowState win,
5424 int pendingWhat, QueuedEvent pendingMotion) {
5425 mLastWin = win;
5426 mLastBinder = win.mClient.asBinder();
5427 mFinished = false;
5428 if (pendingMotion != null) {
5429 final Session s = win.mSession;
5430 if (pendingWhat == RETURN_PENDING_POINTER) {
5431 releasePendingPointerLocked(s);
5432 s.mPendingPointerMove = pendingMotion;
5433 s.mPendingPointerWindow = win;
Romain Guy06882f82009-06-10 13:36:04 -07005434 if (DEBUG_INPUT) Log.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005435 "bindTargetToWindow " + s.mPendingPointerMove);
5436 } else if (pendingWhat == RETURN_PENDING_TRACKBALL) {
5437 releasePendingTrackballLocked(s);
5438 s.mPendingTrackballMove = pendingMotion;
5439 s.mPendingTrackballWindow = win;
5440 }
5441 }
5442 }
Romain Guy06882f82009-06-10 13:36:04 -07005443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005444 void releasePendingPointerLocked(Session s) {
5445 if (DEBUG_INPUT) Log.v(TAG,
5446 "releasePendingPointer " + s.mPendingPointerMove);
5447 if (s.mPendingPointerMove != null) {
5448 mQueue.recycleEvent(s.mPendingPointerMove);
5449 s.mPendingPointerMove = null;
5450 }
5451 }
Romain Guy06882f82009-06-10 13:36:04 -07005452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005453 void releasePendingTrackballLocked(Session s) {
5454 if (s.mPendingTrackballMove != null) {
5455 mQueue.recycleEvent(s.mPendingTrackballMove);
5456 s.mPendingTrackballMove = null;
5457 }
5458 }
Romain Guy06882f82009-06-10 13:36:04 -07005459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005460 MotionEvent finishedKey(Session session, IWindow client, boolean force,
5461 int returnWhat) {
5462 if (DEBUG_INPUT) Log.v(
5463 TAG, "finishedKey: client=" + client + ", force=" + force);
5464
5465 if (client == null) {
5466 return null;
5467 }
5468
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005469 MotionEvent res = null;
5470 QueuedEvent qev = null;
5471 WindowState win = null;
5472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005473 synchronized (this) {
5474 if (DEBUG_INPUT) Log.v(
5475 TAG, "finishedKey: client=" + client.asBinder()
5476 + ", force=" + force + ", last=" + mLastBinder
5477 + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")");
5478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005479 if (returnWhat == RETURN_PENDING_POINTER) {
5480 qev = session.mPendingPointerMove;
5481 win = session.mPendingPointerWindow;
5482 session.mPendingPointerMove = null;
5483 session.mPendingPointerWindow = null;
5484 } else if (returnWhat == RETURN_PENDING_TRACKBALL) {
5485 qev = session.mPendingTrackballMove;
5486 win = session.mPendingTrackballWindow;
5487 session.mPendingTrackballMove = null;
5488 session.mPendingTrackballWindow = null;
5489 }
Romain Guy06882f82009-06-10 13:36:04 -07005490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005491 if (mLastBinder == client.asBinder()) {
5492 if (DEBUG_INPUT) Log.v(
5493 TAG, "finishedKey: last paused="
5494 + ((mLastWin != null) ? mLastWin.mToken.paused : "null"));
5495 if (mLastWin != null && (!mLastWin.mToken.paused || force
5496 || !mEventDispatching)) {
5497 doFinishedKeyLocked(false);
5498 } else {
5499 // Make sure to wake up anyone currently waiting to
5500 // dispatch a key, so they can re-evaluate their
5501 // current situation.
5502 mFinished = true;
5503 notifyAll();
5504 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005505 }
Romain Guy06882f82009-06-10 13:36:04 -07005506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005507 if (qev != null) {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005508 res = (MotionEvent)qev.event;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005509 if (DEBUG_INPUT) Log.v(TAG,
5510 "Returning pending motion: " + res);
5511 mQueue.recycleEvent(qev);
5512 if (win != null && returnWhat == RETURN_PENDING_POINTER) {
5513 res.offsetLocation(-win.mFrame.left, -win.mFrame.top);
5514 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005515 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005516 }
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005517
5518 if (res != null && returnWhat == RETURN_PENDING_POINTER) {
5519 synchronized (mWindowMap) {
5520 if (mWallpaperTarget == win) {
5521 sendPointerToWallpaperLocked(win, res, res.getEventTime());
5522 }
5523 }
5524 }
5525
5526 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005527 }
5528
5529 void tickle() {
5530 synchronized (this) {
5531 notifyAll();
5532 }
5533 }
Romain Guy06882f82009-06-10 13:36:04 -07005534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005535 void handleNewWindowLocked(WindowState newWindow) {
5536 if (!newWindow.canReceiveKeys()) {
5537 return;
5538 }
5539 synchronized (this) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005540 if (DEBUG_INPUT) Log.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005541 TAG, "New key dispatch window: win="
5542 + newWindow.mClient.asBinder()
5543 + ", last=" + mLastBinder
5544 + " (token=" + (mLastWin != null ? mLastWin.mToken : null)
5545 + "), finished=" + mFinished + ", paused="
5546 + newWindow.mToken.paused);
5547
5548 // Displaying a window implicitly causes dispatching to
5549 // be unpaused. (This is to protect against bugs if someone
5550 // pauses dispatching but forgets to resume.)
5551 newWindow.mToken.paused = false;
5552
5553 mGotFirstWindow = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005554
5555 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
5556 if (DEBUG_INPUT) Log.v(TAG,
5557 "New SYSTEM_ERROR window; resetting state");
5558 mLastWin = null;
5559 mLastBinder = null;
5560 mMotionTarget = null;
5561 mFinished = true;
5562 } else if (mLastWin != null) {
5563 // If the new window is above the window we are
5564 // waiting on, then stop waiting and let key dispatching
5565 // start on the new guy.
5566 if (DEBUG_INPUT) Log.v(
5567 TAG, "Last win layer=" + mLastWin.mLayer
5568 + ", new win layer=" + newWindow.mLayer);
5569 if (newWindow.mLayer >= mLastWin.mLayer) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005570 // The new window is above the old; finish pending input to the last
5571 // window and start directing it to the new one.
5572 mLastWin.mToken.paused = false;
5573 doFinishedKeyLocked(true); // does a notifyAll()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005574 }
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005575 // Either the new window is lower, so there is no need to wake key waiters,
5576 // or we just finished key input to the previous window, which implicitly
5577 // notified the key waiters. In both cases, we don't need to issue the
5578 // notification here.
5579 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005580 }
5581
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005582 // Now that we've put a new window state in place, make the event waiter
5583 // take notice and retarget its attentions.
5584 notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005585 }
5586 }
5587
5588 void pauseDispatchingLocked(WindowToken token) {
5589 synchronized (this)
5590 {
5591 if (DEBUG_INPUT) Log.v(TAG, "Pausing WindowToken " + token);
5592 token.paused = true;
5593
5594 /*
5595 if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) {
5596 mPaused = true;
5597 } else {
5598 if (mLastWin == null) {
Dave Bortcfe65242009-04-09 14:51:04 -07005599 Log.i(TAG, "Key dispatching not paused: no last window.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005600 } else if (mFinished) {
Dave Bortcfe65242009-04-09 14:51:04 -07005601 Log.i(TAG, "Key dispatching not paused: finished last key.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005602 } else {
Dave Bortcfe65242009-04-09 14:51:04 -07005603 Log.i(TAG, "Key dispatching not paused: window in higher layer.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005604 }
5605 }
5606 */
5607 }
5608 }
5609
5610 void resumeDispatchingLocked(WindowToken token) {
5611 synchronized (this) {
5612 if (token.paused) {
5613 if (DEBUG_INPUT) Log.v(
5614 TAG, "Resuming WindowToken " + token
5615 + ", last=" + mLastBinder
5616 + " (token=" + (mLastWin != null ? mLastWin.mToken : null)
5617 + "), finished=" + mFinished + ", paused="
5618 + token.paused);
5619 token.paused = false;
5620 if (mLastWin != null && mLastWin.mToken == token && mFinished) {
5621 doFinishedKeyLocked(true);
5622 } else {
5623 notifyAll();
5624 }
5625 }
5626 }
5627 }
5628
5629 void setEventDispatchingLocked(boolean enabled) {
5630 synchronized (this) {
5631 mEventDispatching = enabled;
5632 notifyAll();
5633 }
5634 }
Romain Guy06882f82009-06-10 13:36:04 -07005635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005636 void appSwitchComing() {
5637 synchronized (this) {
5638 // Don't wait for more than .5 seconds for app to finish
5639 // processing the pending events.
5640 long now = SystemClock.uptimeMillis() + 500;
5641 if (DEBUG_INPUT) Log.v(TAG, "appSwitchComing: " + now);
5642 if (mTimeToSwitch == 0 || now < mTimeToSwitch) {
5643 mTimeToSwitch = now;
5644 }
5645 notifyAll();
5646 }
5647 }
Romain Guy06882f82009-06-10 13:36:04 -07005648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005649 private final void doFinishedKeyLocked(boolean doRecycle) {
5650 if (mLastWin != null) {
5651 releasePendingPointerLocked(mLastWin.mSession);
5652 releasePendingTrackballLocked(mLastWin.mSession);
5653 }
Romain Guy06882f82009-06-10 13:36:04 -07005654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005655 if (mLastWin == null || !mLastWin.mToken.paused
5656 || !mLastWin.isVisibleLw()) {
5657 // If the current window has been paused, we aren't -really-
5658 // finished... so let the waiters still wait.
5659 mLastWin = null;
5660 mLastBinder = null;
5661 }
5662 mFinished = true;
5663 notifyAll();
5664 }
5665 }
5666
5667 private class KeyQ extends KeyInputQueue
5668 implements KeyInputQueue.FilterCallback {
5669 PowerManager.WakeLock mHoldingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07005670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005671 KeyQ() {
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07005672 super(mContext, WindowManagerService.this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005673 PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
5674 mHoldingScreen = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
5675 "KEEP_SCREEN_ON_FLAG");
5676 mHoldingScreen.setReferenceCounted(false);
5677 }
5678
5679 @Override
5680 boolean preprocessEvent(InputDevice device, RawInputEvent event) {
5681 if (mPolicy.preprocessInputEventTq(event)) {
5682 return true;
5683 }
Romain Guy06882f82009-06-10 13:36:04 -07005684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005685 switch (event.type) {
5686 case RawInputEvent.EV_KEY: {
5687 // XXX begin hack
5688 if (DEBUG) {
5689 if (event.keycode == KeyEvent.KEYCODE_G) {
5690 if (event.value != 0) {
5691 // G down
5692 mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
5693 }
5694 return false;
5695 }
5696 if (event.keycode == KeyEvent.KEYCODE_D) {
5697 if (event.value != 0) {
5698 //dump();
5699 }
5700 return false;
5701 }
5702 }
5703 // XXX end hack
Romain Guy06882f82009-06-10 13:36:04 -07005704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005705 boolean screenIsOff = !mPowerManager.screenIsOn();
5706 boolean screenIsDim = !mPowerManager.screenIsBright();
5707 int actions = mPolicy.interceptKeyTq(event, !screenIsOff);
Romain Guy06882f82009-06-10 13:36:04 -07005708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005709 if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) {
5710 mPowerManager.goToSleep(event.when);
5711 }
5712
5713 if (screenIsOff) {
5714 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
5715 }
5716 if (screenIsDim) {
5717 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
5718 }
5719 if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) {
5720 mPowerManager.userActivity(event.when, false,
Michael Chane96440f2009-05-06 10:27:36 -07005721 LocalPowerManager.BUTTON_EVENT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005722 }
Romain Guy06882f82009-06-10 13:36:04 -07005723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005724 if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) {
5725 if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) {
5726 filterQueue(this);
5727 mKeyWaiter.appSwitchComing();
5728 }
5729 return true;
5730 } else {
5731 return false;
5732 }
5733 }
Romain Guy06882f82009-06-10 13:36:04 -07005734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005735 case RawInputEvent.EV_REL: {
5736 boolean screenIsOff = !mPowerManager.screenIsOn();
5737 boolean screenIsDim = !mPowerManager.screenIsBright();
5738 if (screenIsOff) {
5739 if (!mPolicy.isWakeRelMovementTq(event.deviceId,
5740 device.classes, event)) {
5741 //Log.i(TAG, "dropping because screenIsOff and !isWakeKey");
5742 return false;
5743 }
5744 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
5745 }
5746 if (screenIsDim) {
5747 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
5748 }
5749 return true;
5750 }
Romain Guy06882f82009-06-10 13:36:04 -07005751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005752 case RawInputEvent.EV_ABS: {
5753 boolean screenIsOff = !mPowerManager.screenIsOn();
5754 boolean screenIsDim = !mPowerManager.screenIsBright();
5755 if (screenIsOff) {
5756 if (!mPolicy.isWakeAbsMovementTq(event.deviceId,
5757 device.classes, event)) {
5758 //Log.i(TAG, "dropping because screenIsOff and !isWakeKey");
5759 return false;
5760 }
5761 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
5762 }
5763 if (screenIsDim) {
5764 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
5765 }
5766 return true;
5767 }
Romain Guy06882f82009-06-10 13:36:04 -07005768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005769 default:
5770 return true;
5771 }
5772 }
5773
5774 public int filterEvent(QueuedEvent ev) {
5775 switch (ev.classType) {
5776 case RawInputEvent.CLASS_KEYBOARD:
5777 KeyEvent ke = (KeyEvent)ev.event;
5778 if (mPolicy.isMovementKeyTi(ke.getKeyCode())) {
5779 Log.w(TAG, "Dropping movement key during app switch: "
5780 + ke.getKeyCode() + ", action=" + ke.getAction());
5781 return FILTER_REMOVE;
5782 }
5783 return FILTER_ABORT;
5784 default:
5785 return FILTER_KEEP;
5786 }
5787 }
Romain Guy06882f82009-06-10 13:36:04 -07005788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005789 /**
5790 * Must be called with the main window manager lock held.
5791 */
5792 void setHoldScreenLocked(boolean holding) {
5793 boolean state = mHoldingScreen.isHeld();
5794 if (holding != state) {
5795 if (holding) {
5796 mHoldingScreen.acquire();
5797 } else {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005798 mPolicy.screenOnStoppedLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005799 mHoldingScreen.release();
5800 }
5801 }
5802 }
Michael Chan53071d62009-05-13 17:29:48 -07005803 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005804
5805 public boolean detectSafeMode() {
5806 mSafeMode = mPolicy.detectSafeMode();
5807 return mSafeMode;
5808 }
Romain Guy06882f82009-06-10 13:36:04 -07005809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005810 public void systemReady() {
5811 mPolicy.systemReady();
5812 }
Romain Guy06882f82009-06-10 13:36:04 -07005813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005814 private final class InputDispatcherThread extends Thread {
5815 // Time to wait when there is nothing to do: 9999 seconds.
5816 static final int LONG_WAIT=9999*1000;
5817
5818 public InputDispatcherThread() {
5819 super("InputDispatcher");
5820 }
Romain Guy06882f82009-06-10 13:36:04 -07005821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005822 @Override
5823 public void run() {
5824 while (true) {
5825 try {
5826 process();
5827 } catch (Exception e) {
5828 Log.e(TAG, "Exception in input dispatcher", e);
5829 }
5830 }
5831 }
Romain Guy06882f82009-06-10 13:36:04 -07005832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005833 private void process() {
5834 android.os.Process.setThreadPriority(
5835 android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);
Romain Guy06882f82009-06-10 13:36:04 -07005836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005837 // The last key event we saw
5838 KeyEvent lastKey = null;
5839
5840 // Last keydown time for auto-repeating keys
5841 long lastKeyTime = SystemClock.uptimeMillis();
5842 long nextKeyTime = lastKeyTime+LONG_WAIT;
5843
Romain Guy06882f82009-06-10 13:36:04 -07005844 // How many successive repeats we generated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005845 int keyRepeatCount = 0;
5846
5847 // Need to report that configuration has changed?
5848 boolean configChanged = false;
Romain Guy06882f82009-06-10 13:36:04 -07005849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005850 while (true) {
5851 long curTime = SystemClock.uptimeMillis();
5852
5853 if (DEBUG_INPUT) Log.v(
5854 TAG, "Waiting for next key: now=" + curTime
5855 + ", repeat @ " + nextKeyTime);
5856
5857 // Retrieve next event, waiting only as long as the next
5858 // repeat timeout. If the configuration has changed, then
5859 // don't wait at all -- we'll report the change as soon as
5860 // we have processed all events.
5861 QueuedEvent ev = mQueue.getEvent(
5862 (int)((!configChanged && curTime < nextKeyTime)
5863 ? (nextKeyTime-curTime) : 0));
5864
5865 if (DEBUG_INPUT && ev != null) Log.v(
5866 TAG, "Event: type=" + ev.classType + " data=" + ev.event);
5867
Michael Chan53071d62009-05-13 17:29:48 -07005868 if (MEASURE_LATENCY) {
5869 lt.sample("2 got event ", System.nanoTime() - ev.whenNano);
5870 }
5871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005872 try {
5873 if (ev != null) {
Michael Chan53071d62009-05-13 17:29:48 -07005874 curTime = SystemClock.uptimeMillis();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005875 int eventType;
5876 if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) {
5877 eventType = eventType((MotionEvent)ev.event);
5878 } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD ||
5879 ev.classType == RawInputEvent.CLASS_TRACKBALL) {
5880 eventType = LocalPowerManager.BUTTON_EVENT;
5881 } else {
5882 eventType = LocalPowerManager.OTHER_EVENT;
5883 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07005884 try {
Michael Chan53071d62009-05-13 17:29:48 -07005885 if ((curTime - mLastBatteryStatsCallTime)
Michael Chane96440f2009-05-06 10:27:36 -07005886 >= MIN_TIME_BETWEEN_USERACTIVITIES) {
Michael Chan53071d62009-05-13 17:29:48 -07005887 mLastBatteryStatsCallTime = curTime;
Michael Chane96440f2009-05-06 10:27:36 -07005888 mBatteryStats.noteInputEvent();
5889 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07005890 } catch (RemoteException e) {
5891 // Ignore
5892 }
Michael Chane10de972009-05-18 11:24:50 -07005893
5894 if (eventType != TOUCH_EVENT
5895 && eventType != LONG_TOUCH_EVENT
5896 && eventType != CHEEK_EVENT) {
5897 mPowerManager.userActivity(curTime, false,
5898 eventType, false);
5899 } else if (mLastTouchEventType != eventType
5900 || (curTime - mLastUserActivityCallTime)
5901 >= MIN_TIME_BETWEEN_USERACTIVITIES) {
5902 mLastUserActivityCallTime = curTime;
5903 mLastTouchEventType = eventType;
5904 mPowerManager.userActivity(curTime, false,
5905 eventType, false);
5906 }
5907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005908 switch (ev.classType) {
5909 case RawInputEvent.CLASS_KEYBOARD:
5910 KeyEvent ke = (KeyEvent)ev.event;
5911 if (ke.isDown()) {
5912 lastKey = ke;
5913 keyRepeatCount = 0;
5914 lastKeyTime = curTime;
5915 nextKeyTime = lastKeyTime
5916 + KEY_REPEAT_FIRST_DELAY;
5917 if (DEBUG_INPUT) Log.v(
5918 TAG, "Received key down: first repeat @ "
5919 + nextKeyTime);
5920 } else {
5921 lastKey = null;
5922 // Arbitrary long timeout.
5923 lastKeyTime = curTime;
5924 nextKeyTime = curTime + LONG_WAIT;
5925 if (DEBUG_INPUT) Log.v(
5926 TAG, "Received key up: ignore repeat @ "
5927 + nextKeyTime);
5928 }
5929 dispatchKey((KeyEvent)ev.event, 0, 0);
5930 mQueue.recycleEvent(ev);
5931 break;
5932 case RawInputEvent.CLASS_TOUCHSCREEN:
5933 //Log.i(TAG, "Read next event " + ev);
5934 dispatchPointer(ev, (MotionEvent)ev.event, 0, 0);
5935 break;
5936 case RawInputEvent.CLASS_TRACKBALL:
5937 dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0);
5938 break;
5939 case RawInputEvent.CLASS_CONFIGURATION_CHANGED:
5940 configChanged = true;
5941 break;
5942 default:
5943 mQueue.recycleEvent(ev);
5944 break;
5945 }
Romain Guy06882f82009-06-10 13:36:04 -07005946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005947 } else if (configChanged) {
5948 configChanged = false;
5949 sendNewConfiguration();
Romain Guy06882f82009-06-10 13:36:04 -07005950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005951 } else if (lastKey != null) {
5952 curTime = SystemClock.uptimeMillis();
Romain Guy06882f82009-06-10 13:36:04 -07005953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005954 // Timeout occurred while key was down. If it is at or
5955 // past the key repeat time, dispatch the repeat.
5956 if (DEBUG_INPUT) Log.v(
5957 TAG, "Key timeout: repeat=" + nextKeyTime
5958 + ", now=" + curTime);
5959 if (curTime < nextKeyTime) {
5960 continue;
5961 }
Romain Guy06882f82009-06-10 13:36:04 -07005962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005963 lastKeyTime = nextKeyTime;
5964 nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY;
5965 keyRepeatCount++;
5966 if (DEBUG_INPUT) Log.v(
5967 TAG, "Key repeat: count=" + keyRepeatCount
5968 + ", next @ " + nextKeyTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07005969 dispatchKey(KeyEvent.changeTimeRepeat(lastKey, curTime, keyRepeatCount), 0, 0);
Romain Guy06882f82009-06-10 13:36:04 -07005970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005971 } else {
5972 curTime = SystemClock.uptimeMillis();
Romain Guy06882f82009-06-10 13:36:04 -07005973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005974 lastKeyTime = curTime;
5975 nextKeyTime = curTime + LONG_WAIT;
5976 }
Romain Guy06882f82009-06-10 13:36:04 -07005977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005978 } catch (Exception e) {
5979 Log.e(TAG,
5980 "Input thread received uncaught exception: " + e, e);
5981 }
5982 }
5983 }
5984 }
5985
5986 // -------------------------------------------------------------
5987 // Client Session State
5988 // -------------------------------------------------------------
5989
5990 private final class Session extends IWindowSession.Stub
5991 implements IBinder.DeathRecipient {
5992 final IInputMethodClient mClient;
5993 final IInputContext mInputContext;
5994 final int mUid;
5995 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005996 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005997 SurfaceSession mSurfaceSession;
5998 int mNumWindow = 0;
5999 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006001 /**
6002 * Current pointer move event being dispatched to client window... must
6003 * hold key lock to access.
6004 */
6005 QueuedEvent mPendingPointerMove;
6006 WindowState mPendingPointerWindow;
Romain Guy06882f82009-06-10 13:36:04 -07006007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006008 /**
6009 * Current trackball move event being dispatched to client window... must
6010 * hold key lock to access.
6011 */
6012 QueuedEvent mPendingTrackballMove;
6013 WindowState mPendingTrackballWindow;
6014
6015 public Session(IInputMethodClient client, IInputContext inputContext) {
6016 mClient = client;
6017 mInputContext = inputContext;
6018 mUid = Binder.getCallingUid();
6019 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006020 StringBuilder sb = new StringBuilder();
6021 sb.append("Session{");
6022 sb.append(Integer.toHexString(System.identityHashCode(this)));
6023 sb.append(" uid ");
6024 sb.append(mUid);
6025 sb.append("}");
6026 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006027
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006028 synchronized (mWindowMap) {
6029 if (mInputMethodManager == null && mHaveInputMethods) {
6030 IBinder b = ServiceManager.getService(
6031 Context.INPUT_METHOD_SERVICE);
6032 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6033 }
6034 }
6035 long ident = Binder.clearCallingIdentity();
6036 try {
6037 // Note: it is safe to call in to the input method manager
6038 // here because we are not holding our lock.
6039 if (mInputMethodManager != null) {
6040 mInputMethodManager.addClient(client, inputContext,
6041 mUid, mPid);
6042 } else {
6043 client.setUsingInputMethod(false);
6044 }
6045 client.asBinder().linkToDeath(this, 0);
6046 } catch (RemoteException e) {
6047 // The caller has died, so we can just forget about this.
6048 try {
6049 if (mInputMethodManager != null) {
6050 mInputMethodManager.removeClient(client);
6051 }
6052 } catch (RemoteException ee) {
6053 }
6054 } finally {
6055 Binder.restoreCallingIdentity(ident);
6056 }
6057 }
Romain Guy06882f82009-06-10 13:36:04 -07006058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006059 @Override
6060 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6061 throws RemoteException {
6062 try {
6063 return super.onTransact(code, data, reply, flags);
6064 } catch (RuntimeException e) {
6065 // Log all 'real' exceptions thrown to the caller
6066 if (!(e instanceof SecurityException)) {
6067 Log.e(TAG, "Window Session Crash", e);
6068 }
6069 throw e;
6070 }
6071 }
6072
6073 public void binderDied() {
6074 // Note: it is safe to call in to the input method manager
6075 // here because we are not holding our lock.
6076 try {
6077 if (mInputMethodManager != null) {
6078 mInputMethodManager.removeClient(mClient);
6079 }
6080 } catch (RemoteException e) {
6081 }
6082 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006083 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006084 mClientDead = true;
6085 killSessionLocked();
6086 }
6087 }
6088
6089 public int add(IWindow window, WindowManager.LayoutParams attrs,
6090 int viewVisibility, Rect outContentInsets) {
6091 return addWindow(this, window, attrs, viewVisibility, outContentInsets);
6092 }
Romain Guy06882f82009-06-10 13:36:04 -07006093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006094 public void remove(IWindow window) {
6095 removeWindow(this, window);
6096 }
Romain Guy06882f82009-06-10 13:36:04 -07006097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006098 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6099 int requestedWidth, int requestedHeight, int viewFlags,
6100 boolean insetsPending, Rect outFrame, Rect outContentInsets,
6101 Rect outVisibleInsets, Surface outSurface) {
6102 return relayoutWindow(this, window, attrs,
6103 requestedWidth, requestedHeight, viewFlags, insetsPending,
6104 outFrame, outContentInsets, outVisibleInsets, outSurface);
6105 }
Romain Guy06882f82009-06-10 13:36:04 -07006106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006107 public void setTransparentRegion(IWindow window, Region region) {
6108 setTransparentRegionWindow(this, window, region);
6109 }
Romain Guy06882f82009-06-10 13:36:04 -07006110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006111 public void setInsets(IWindow window, int touchableInsets,
6112 Rect contentInsets, Rect visibleInsets) {
6113 setInsetsWindow(this, window, touchableInsets, contentInsets,
6114 visibleInsets);
6115 }
Romain Guy06882f82009-06-10 13:36:04 -07006116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006117 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6118 getWindowDisplayFrame(this, window, outDisplayFrame);
6119 }
Romain Guy06882f82009-06-10 13:36:04 -07006120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006121 public void finishDrawing(IWindow window) {
6122 if (localLOGV) Log.v(
6123 TAG, "IWindow finishDrawing called for " + window);
6124 finishDrawingWindow(this, window);
6125 }
6126
6127 public void finishKey(IWindow window) {
6128 if (localLOGV) Log.v(
6129 TAG, "IWindow finishKey called for " + window);
6130 mKeyWaiter.finishedKey(this, window, false,
6131 KeyWaiter.RETURN_NOTHING);
6132 }
6133
6134 public MotionEvent getPendingPointerMove(IWindow window) {
6135 if (localLOGV) Log.v(
6136 TAG, "IWindow getPendingMotionEvent called for " + window);
6137 return mKeyWaiter.finishedKey(this, window, false,
6138 KeyWaiter.RETURN_PENDING_POINTER);
6139 }
Romain Guy06882f82009-06-10 13:36:04 -07006140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006141 public MotionEvent getPendingTrackballMove(IWindow window) {
6142 if (localLOGV) Log.v(
6143 TAG, "IWindow getPendingMotionEvent called for " + window);
6144 return mKeyWaiter.finishedKey(this, window, false,
6145 KeyWaiter.RETURN_PENDING_TRACKBALL);
6146 }
6147
6148 public void setInTouchMode(boolean mode) {
6149 synchronized(mWindowMap) {
6150 mInTouchMode = mode;
6151 }
6152 }
6153
6154 public boolean getInTouchMode() {
6155 synchronized(mWindowMap) {
6156 return mInTouchMode;
6157 }
6158 }
6159
6160 public boolean performHapticFeedback(IWindow window, int effectId,
6161 boolean always) {
6162 synchronized(mWindowMap) {
6163 long ident = Binder.clearCallingIdentity();
6164 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006165 return mPolicy.performHapticFeedbackLw(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006166 windowForClientLocked(this, window), effectId, always);
6167 } finally {
6168 Binder.restoreCallingIdentity(ident);
6169 }
6170 }
6171 }
Romain Guy06882f82009-06-10 13:36:04 -07006172
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006173 public void setWallpaperPosition(IBinder window, float x, float y) {
6174 synchronized(mWindowMap) {
6175 long ident = Binder.clearCallingIdentity();
6176 try {
6177 setWindowWallpaperPositionLocked(windowForClientLocked(this, window),
6178 x, y);
6179 } finally {
6180 Binder.restoreCallingIdentity(ident);
6181 }
6182 }
6183 }
6184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006185 void windowAddedLocked() {
6186 if (mSurfaceSession == null) {
6187 if (localLOGV) Log.v(
6188 TAG, "First window added to " + this + ", creating SurfaceSession");
6189 mSurfaceSession = new SurfaceSession();
6190 mSessions.add(this);
6191 }
6192 mNumWindow++;
6193 }
6194
6195 void windowRemovedLocked() {
6196 mNumWindow--;
6197 killSessionLocked();
6198 }
Romain Guy06882f82009-06-10 13:36:04 -07006199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006200 void killSessionLocked() {
6201 if (mNumWindow <= 0 && mClientDead) {
6202 mSessions.remove(this);
6203 if (mSurfaceSession != null) {
6204 if (localLOGV) Log.v(
6205 TAG, "Last window removed from " + this
6206 + ", destroying " + mSurfaceSession);
6207 try {
6208 mSurfaceSession.kill();
6209 } catch (Exception e) {
6210 Log.w(TAG, "Exception thrown when killing surface session "
6211 + mSurfaceSession + " in session " + this
6212 + ": " + e.toString());
6213 }
6214 mSurfaceSession = null;
6215 }
6216 }
6217 }
Romain Guy06882f82009-06-10 13:36:04 -07006218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006219 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006220 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6221 pw.print(" mClientDead="); pw.print(mClientDead);
6222 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
6223 if (mPendingPointerWindow != null || mPendingPointerMove != null) {
6224 pw.print(prefix);
6225 pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow);
6226 pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove);
6227 }
6228 if (mPendingTrackballWindow != null || mPendingTrackballMove != null) {
6229 pw.print(prefix);
6230 pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow);
6231 pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove);
6232 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006233 }
6234
6235 @Override
6236 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006237 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006238 }
6239 }
6240
6241 // -------------------------------------------------------------
6242 // Client Window State
6243 // -------------------------------------------------------------
6244
6245 private final class WindowState implements WindowManagerPolicy.WindowState {
6246 final Session mSession;
6247 final IWindow mClient;
6248 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006249 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006250 AppWindowToken mAppToken;
6251 AppWindowToken mTargetAppToken;
6252 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6253 final DeathRecipient mDeathRecipient;
6254 final WindowState mAttachedWindow;
6255 final ArrayList mChildWindows = new ArrayList();
6256 final int mBaseLayer;
6257 final int mSubLayer;
6258 final boolean mLayoutAttached;
6259 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006260 final boolean mIsWallpaper;
6261 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006262 int mViewVisibility;
6263 boolean mPolicyVisibility = true;
6264 boolean mPolicyVisibilityAfterAnim = true;
6265 boolean mAppFreezing;
6266 Surface mSurface;
6267 boolean mAttachedHidden; // is our parent window hidden?
6268 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006269 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006270 int mRequestedWidth;
6271 int mRequestedHeight;
6272 int mLastRequestedWidth;
6273 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006274 int mLayer;
6275 int mAnimLayer;
6276 int mLastLayer;
6277 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006278 boolean mObscured;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006279
6280 WindowState mNextOutsideTouch;
Romain Guy06882f82009-06-10 13:36:04 -07006281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006282 // Actual frame shown on-screen (may be modified by animation)
6283 final Rect mShownFrame = new Rect();
6284 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006286 /**
6287 * Insets that determine the actually visible area
6288 */
6289 final Rect mVisibleInsets = new Rect();
6290 final Rect mLastVisibleInsets = new Rect();
6291 boolean mVisibleInsetsChanged;
6292
6293 /**
6294 * Insets that are covered by system windows
6295 */
6296 final Rect mContentInsets = new Rect();
6297 final Rect mLastContentInsets = new Rect();
6298 boolean mContentInsetsChanged;
6299
6300 /**
6301 * Set to true if we are waiting for this window to receive its
6302 * given internal insets before laying out other windows based on it.
6303 */
6304 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006306 /**
6307 * These are the content insets that were given during layout for
6308 * this window, to be applied to windows behind it.
6309 */
6310 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006312 /**
6313 * These are the visible insets that were given during layout for
6314 * this window, to be applied to windows behind it.
6315 */
6316 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006318 /**
6319 * Flag indicating whether the touchable region should be adjusted by
6320 * the visible insets; if false the area outside the visible insets is
6321 * NOT touchable, so we must use those to adjust the frame during hit
6322 * tests.
6323 */
6324 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006326 // Current transformation being applied.
6327 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6328 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6329 float mHScale=1, mVScale=1;
6330 float mLastHScale=1, mLastVScale=1;
6331 final Matrix mTmpMatrix = new Matrix();
6332
6333 // "Real" frame that the application sees.
6334 final Rect mFrame = new Rect();
6335 final Rect mLastFrame = new Rect();
6336
6337 final Rect mContainingFrame = new Rect();
6338 final Rect mDisplayFrame = new Rect();
6339 final Rect mContentFrame = new Rect();
6340 final Rect mVisibleFrame = new Rect();
6341
6342 float mShownAlpha = 1;
6343 float mAlpha = 1;
6344 float mLastAlpha = 1;
6345
6346 // Set to true if, when the window gets displayed, it should perform
6347 // an enter animation.
6348 boolean mEnterAnimationPending;
6349
6350 // Currently running animation.
6351 boolean mAnimating;
6352 boolean mLocalAnimating;
6353 Animation mAnimation;
6354 boolean mAnimationIsEntrance;
6355 boolean mHasTransformation;
6356 boolean mHasLocalTransformation;
6357 final Transformation mTransformation = new Transformation();
6358
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006359 // If a window showing a wallpaper: the requested offset for the
6360 // wallpaper; if a wallpaper window: the currently applied offset.
6361 float mWallpaperX = -1;
6362 float mWallpaperY = -1;
6363
6364 // Wallpaper windows: pixels offset based on above variables.
6365 int mXOffset;
6366 int mYOffset;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006368 // This is set after IWindowSession.relayout() has been called at
6369 // least once for the window. It allows us to detect the situation
6370 // where we don't yet have a surface, but should have one soon, so
6371 // we can give the window focus before waiting for the relayout.
6372 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006374 // This is set after the Surface has been created but before the
6375 // window has been drawn. During this time the surface is hidden.
6376 boolean mDrawPending;
6377
6378 // This is set after the window has finished drawing for the first
6379 // time but before its surface is shown. The surface will be
6380 // displayed when the next layout is run.
6381 boolean mCommitDrawPending;
6382
6383 // This is set during the time after the window's drawing has been
6384 // committed, and before its surface is actually shown. It is used
6385 // to delay showing the surface until all windows in a token are ready
6386 // to be shown.
6387 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006389 // Set when the window has been shown in the screen the first time.
6390 boolean mHasDrawn;
6391
6392 // Currently running an exit animation?
6393 boolean mExiting;
6394
6395 // Currently on the mDestroySurface list?
6396 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006398 // Completely remove from window manager after exit animation?
6399 boolean mRemoveOnExit;
6400
6401 // Set when the orientation is changing and this window has not yet
6402 // been updated for the new orientation.
6403 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006405 // Is this window now (or just being) removed?
6406 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006407
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006408 WindowState(Session s, IWindow c, WindowToken token,
6409 WindowState attachedWindow, WindowManager.LayoutParams a,
6410 int viewVisibility) {
6411 mSession = s;
6412 mClient = c;
6413 mToken = token;
6414 mAttrs.copyFrom(a);
6415 mViewVisibility = viewVisibility;
6416 DeathRecipient deathRecipient = new DeathRecipient();
6417 mAlpha = a.alpha;
6418 if (localLOGV) Log.v(
6419 TAG, "Window " + this + " client=" + c.asBinder()
6420 + " token=" + token + " (" + mAttrs.token + ")");
6421 try {
6422 c.asBinder().linkToDeath(deathRecipient, 0);
6423 } catch (RemoteException e) {
6424 mDeathRecipient = null;
6425 mAttachedWindow = null;
6426 mLayoutAttached = false;
6427 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006428 mIsWallpaper = false;
6429 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006430 mBaseLayer = 0;
6431 mSubLayer = 0;
6432 return;
6433 }
6434 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006436 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6437 mAttrs.type <= LAST_SUB_WINDOW)) {
6438 // The multiplier here is to reserve space for multiple
6439 // windows in the same type layer.
6440 mBaseLayer = mPolicy.windowTypeToLayerLw(
6441 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6442 + TYPE_LAYER_OFFSET;
6443 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6444 mAttachedWindow = attachedWindow;
6445 mAttachedWindow.mChildWindows.add(this);
6446 mLayoutAttached = mAttrs.type !=
6447 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6448 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6449 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006450 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6451 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006452 } else {
6453 // The multiplier here is to reserve space for multiple
6454 // windows in the same type layer.
6455 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6456 * TYPE_LAYER_MULTIPLIER
6457 + TYPE_LAYER_OFFSET;
6458 mSubLayer = 0;
6459 mAttachedWindow = null;
6460 mLayoutAttached = false;
6461 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6462 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006463 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6464 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006465 }
6466
6467 WindowState appWin = this;
6468 while (appWin.mAttachedWindow != null) {
6469 appWin = mAttachedWindow;
6470 }
6471 WindowToken appToken = appWin.mToken;
6472 while (appToken.appWindowToken == null) {
6473 WindowToken parent = mTokenMap.get(appToken.token);
6474 if (parent == null || appToken == parent) {
6475 break;
6476 }
6477 appToken = parent;
6478 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006479 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006480 mAppToken = appToken.appWindowToken;
6481
6482 mSurface = null;
6483 mRequestedWidth = 0;
6484 mRequestedHeight = 0;
6485 mLastRequestedWidth = 0;
6486 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006487 mXOffset = 0;
6488 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006489 mLayer = 0;
6490 mAnimLayer = 0;
6491 mLastLayer = 0;
6492 }
6493
6494 void attach() {
6495 if (localLOGV) Log.v(
6496 TAG, "Attaching " + this + " token=" + mToken
6497 + ", list=" + mToken.windows);
6498 mSession.windowAddedLocked();
6499 }
6500
6501 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6502 mHaveFrame = true;
6503
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006504 final Rect container = mContainingFrame;
6505 container.set(pf);
6506
6507 final Rect display = mDisplayFrame;
6508 display.set(df);
6509
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006510 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006511 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006512 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6513 display.intersect(mCompatibleScreenFrame);
6514 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006515 }
6516
6517 final int pw = container.right - container.left;
6518 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006519
6520 int w,h;
6521 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6522 w = mAttrs.width < 0 ? pw : mAttrs.width;
6523 h = mAttrs.height< 0 ? ph : mAttrs.height;
6524 } else {
6525 w = mAttrs.width == mAttrs.FILL_PARENT ? pw : mRequestedWidth;
6526 h = mAttrs.height== mAttrs.FILL_PARENT ? ph : mRequestedHeight;
6527 }
Romain Guy06882f82009-06-10 13:36:04 -07006528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006529 final Rect content = mContentFrame;
6530 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006532 final Rect visible = mVisibleFrame;
6533 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006535 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006536 final int fw = frame.width();
6537 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006539 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6540 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6541
6542 Gravity.apply(mAttrs.gravity, w, h, container,
6543 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6544 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6545
6546 //System.out.println("Out: " + mFrame);
6547
6548 // Now make sure the window fits in the overall display.
6549 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006551 // Make sure the content and visible frames are inside of the
6552 // final window frame.
6553 if (content.left < frame.left) content.left = frame.left;
6554 if (content.top < frame.top) content.top = frame.top;
6555 if (content.right > frame.right) content.right = frame.right;
6556 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6557 if (visible.left < frame.left) visible.left = frame.left;
6558 if (visible.top < frame.top) visible.top = frame.top;
6559 if (visible.right > frame.right) visible.right = frame.right;
6560 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006562 final Rect contentInsets = mContentInsets;
6563 contentInsets.left = content.left-frame.left;
6564 contentInsets.top = content.top-frame.top;
6565 contentInsets.right = frame.right-content.right;
6566 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006568 final Rect visibleInsets = mVisibleInsets;
6569 visibleInsets.left = visible.left-frame.left;
6570 visibleInsets.top = visible.top-frame.top;
6571 visibleInsets.right = frame.right-visible.right;
6572 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006573
Dianne Hackborn284ac932009-08-28 10:34:25 -07006574 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6575 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
6576 mDisplay.getHeight());
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006577 }
6578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006579 if (localLOGV) {
6580 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6581 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
6582 Log.v(TAG, "Resolving (mRequestedWidth="
6583 + mRequestedWidth + ", mRequestedheight="
6584 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6585 + "): frame=" + mFrame.toShortString()
6586 + " ci=" + contentInsets.toShortString()
6587 + " vi=" + visibleInsets.toShortString());
6588 //}
6589 }
6590 }
Romain Guy06882f82009-06-10 13:36:04 -07006591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006592 public Rect getFrameLw() {
6593 return mFrame;
6594 }
6595
6596 public Rect getShownFrameLw() {
6597 return mShownFrame;
6598 }
6599
6600 public Rect getDisplayFrameLw() {
6601 return mDisplayFrame;
6602 }
6603
6604 public Rect getContentFrameLw() {
6605 return mContentFrame;
6606 }
6607
6608 public Rect getVisibleFrameLw() {
6609 return mVisibleFrame;
6610 }
6611
6612 public boolean getGivenInsetsPendingLw() {
6613 return mGivenInsetsPending;
6614 }
6615
6616 public Rect getGivenContentInsetsLw() {
6617 return mGivenContentInsets;
6618 }
Romain Guy06882f82009-06-10 13:36:04 -07006619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006620 public Rect getGivenVisibleInsetsLw() {
6621 return mGivenVisibleInsets;
6622 }
Romain Guy06882f82009-06-10 13:36:04 -07006623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006624 public WindowManager.LayoutParams getAttrs() {
6625 return mAttrs;
6626 }
6627
6628 public int getSurfaceLayer() {
6629 return mLayer;
6630 }
Romain Guy06882f82009-06-10 13:36:04 -07006631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006632 public IApplicationToken getAppToken() {
6633 return mAppToken != null ? mAppToken.appToken : null;
6634 }
6635
6636 public boolean hasAppShownWindows() {
6637 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6638 }
6639
6640 public boolean hasAppStartingIcon() {
6641 return mAppToken != null ? (mAppToken.startingData != null) : false;
6642 }
6643
6644 public WindowManagerPolicy.WindowState getAppStartingWindow() {
6645 return mAppToken != null ? mAppToken.startingWindow : null;
6646 }
6647
6648 public void setAnimation(Animation anim) {
6649 if (localLOGV) Log.v(
6650 TAG, "Setting animation in " + this + ": " + anim);
6651 mAnimating = false;
6652 mLocalAnimating = false;
6653 mAnimation = anim;
6654 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6655 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6656 }
6657
6658 public void clearAnimation() {
6659 if (mAnimation != null) {
6660 mAnimating = true;
6661 mLocalAnimating = false;
6662 mAnimation = null;
6663 }
6664 }
Romain Guy06882f82009-06-10 13:36:04 -07006665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006666 Surface createSurfaceLocked() {
6667 if (mSurface == null) {
6668 mDrawPending = true;
6669 mCommitDrawPending = false;
6670 mReadyToShow = false;
6671 if (mAppToken != null) {
6672 mAppToken.allDrawn = false;
6673 }
6674
6675 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006676 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006677 flags |= Surface.PUSH_BUFFERS;
6678 }
6679
6680 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6681 flags |= Surface.SECURE;
6682 }
6683 if (DEBUG_VISIBILITY) Log.v(
6684 TAG, "Creating surface in session "
6685 + mSession.mSurfaceSession + " window " + this
6686 + " w=" + mFrame.width()
6687 + " h=" + mFrame.height() + " format="
6688 + mAttrs.format + " flags=" + flags);
6689
6690 int w = mFrame.width();
6691 int h = mFrame.height();
6692 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6693 // for a scaled surface, we always want the requested
6694 // size.
6695 w = mRequestedWidth;
6696 h = mRequestedHeight;
6697 }
6698
6699 try {
6700 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006701 mSession.mSurfaceSession, mSession.mPid,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006702 0, w, h, mAttrs.format, flags);
6703 } catch (Surface.OutOfResourcesException e) {
6704 Log.w(TAG, "OutOfResourcesException creating surface");
6705 reclaimSomeSurfaceMemoryLocked(this, "create");
6706 return null;
6707 } catch (Exception e) {
6708 Log.e(TAG, "Exception creating surface", e);
6709 return null;
6710 }
Romain Guy06882f82009-06-10 13:36:04 -07006711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006712 if (localLOGV) Log.v(
6713 TAG, "Got surface: " + mSurface
6714 + ", set left=" + mFrame.left + " top=" + mFrame.top
6715 + ", animLayer=" + mAnimLayer);
6716 if (SHOW_TRANSACTIONS) {
6717 Log.i(TAG, ">>> OPEN TRANSACTION");
6718 Log.i(TAG, " SURFACE " + mSurface + ": CREATE ("
6719 + mAttrs.getTitle() + ") pos=(" +
6720 mFrame.left + "," + mFrame.top + ") (" +
6721 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6722 mAnimLayer + " HIDE");
6723 }
6724 Surface.openTransaction();
6725 try {
6726 try {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006727 mSurface.setPosition(mFrame.left + mXOffset,
6728 mFrame.top + mYOffset);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006729 mSurface.setLayer(mAnimLayer);
6730 mSurface.hide();
6731 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
6732 mSurface.setFlags(Surface.SURFACE_DITHER,
6733 Surface.SURFACE_DITHER);
6734 }
6735 } catch (RuntimeException e) {
6736 Log.w(TAG, "Error creating surface in " + w, e);
6737 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6738 }
6739 mLastHidden = true;
6740 } finally {
6741 if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION");
6742 Surface.closeTransaction();
6743 }
6744 if (localLOGV) Log.v(
6745 TAG, "Created surface " + this);
6746 }
6747 return mSurface;
6748 }
Romain Guy06882f82009-06-10 13:36:04 -07006749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006750 void destroySurfaceLocked() {
6751 // Window is no longer on-screen, so can no longer receive
6752 // key events... if we were waiting for it to finish
6753 // handling a key event, the wait is over!
6754 mKeyWaiter.finishedKey(mSession, mClient, true,
6755 KeyWaiter.RETURN_NOTHING);
6756 mKeyWaiter.releasePendingPointerLocked(mSession);
6757 mKeyWaiter.releasePendingTrackballLocked(mSession);
6758
6759 if (mAppToken != null && this == mAppToken.startingWindow) {
6760 mAppToken.startingDisplayed = false;
6761 }
Romain Guy06882f82009-06-10 13:36:04 -07006762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006763 if (mSurface != null) {
6764 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006765 if (DEBUG_VISIBILITY) {
6766 RuntimeException e = new RuntimeException();
6767 e.fillInStackTrace();
6768 Log.w(TAG, "Window " + this + " destroying surface "
6769 + mSurface + ", session " + mSession, e);
6770 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006771 if (SHOW_TRANSACTIONS) {
6772 RuntimeException ex = new RuntimeException();
6773 ex.fillInStackTrace();
6774 Log.i(TAG, " SURFACE " + mSurface + ": DESTROY ("
6775 + mAttrs.getTitle() + ")", ex);
6776 }
6777 mSurface.clear();
6778 } catch (RuntimeException e) {
6779 Log.w(TAG, "Exception thrown when destroying Window " + this
6780 + " surface " + mSurface + " session " + mSession
6781 + ": " + e.toString());
6782 }
6783 mSurface = null;
6784 mDrawPending = false;
6785 mCommitDrawPending = false;
6786 mReadyToShow = false;
6787
6788 int i = mChildWindows.size();
6789 while (i > 0) {
6790 i--;
6791 WindowState c = (WindowState)mChildWindows.get(i);
6792 c.mAttachedHidden = true;
6793 }
6794 }
6795 }
6796
6797 boolean finishDrawingLocked() {
6798 if (mDrawPending) {
6799 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.v(
6800 TAG, "finishDrawingLocked: " + mSurface);
6801 mCommitDrawPending = true;
6802 mDrawPending = false;
6803 return true;
6804 }
6805 return false;
6806 }
6807
6808 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006809 boolean commitFinishDrawingLocked(long currentTime) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006810 //Log.i(TAG, "commitFinishDrawingLocked: " + mSurface);
6811 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006812 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006813 }
6814 mCommitDrawPending = false;
6815 mReadyToShow = true;
6816 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6817 final AppWindowToken atoken = mAppToken;
6818 if (atoken == null || atoken.allDrawn || starting) {
6819 performShowLocked();
6820 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006821 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006822 }
6823
6824 // This must be called while inside a transaction.
6825 boolean performShowLocked() {
6826 if (DEBUG_VISIBILITY) {
6827 RuntimeException e = new RuntimeException();
6828 e.fillInStackTrace();
6829 Log.v(TAG, "performShow on " + this
6830 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6831 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6832 }
6833 if (mReadyToShow && isReadyForDisplay()) {
6834 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.i(
6835 TAG, " SURFACE " + mSurface + ": SHOW (performShowLocked)");
6836 if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + this
6837 + " during animation: policyVis=" + mPolicyVisibility
6838 + " attHidden=" + mAttachedHidden
6839 + " tok.hiddenRequested="
6840 + (mAppToken != null ? mAppToken.hiddenRequested : false)
6841 + " tok.idden="
6842 + (mAppToken != null ? mAppToken.hidden : false)
6843 + " animating=" + mAnimating
6844 + " tok animating="
6845 + (mAppToken != null ? mAppToken.animating : false));
6846 if (!showSurfaceRobustlyLocked(this)) {
6847 return false;
6848 }
6849 mLastAlpha = -1;
6850 mHasDrawn = true;
6851 mLastHidden = false;
6852 mReadyToShow = false;
6853 enableScreenIfNeededLocked();
6854
6855 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07006856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006857 int i = mChildWindows.size();
6858 while (i > 0) {
6859 i--;
6860 WindowState c = (WindowState)mChildWindows.get(i);
6861 if (c.mSurface != null && c.mAttachedHidden) {
6862 c.mAttachedHidden = false;
6863 c.performShowLocked();
6864 }
6865 }
Romain Guy06882f82009-06-10 13:36:04 -07006866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006867 if (mAttrs.type != TYPE_APPLICATION_STARTING
6868 && mAppToken != null) {
6869 mAppToken.firstWindowDrawn = true;
6870 if (mAnimation == null && mAppToken.startingData != null) {
6871 if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Finish starting "
6872 + mToken
6873 + ": first real window is shown, no animation");
6874 mFinishedStarting.add(mAppToken);
6875 mH.sendEmptyMessage(H.FINISHED_STARTING);
6876 }
6877 mAppToken.updateReportedVisibilityLocked();
6878 }
6879 }
6880 return true;
6881 }
Romain Guy06882f82009-06-10 13:36:04 -07006882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006883 // This must be called while inside a transaction. Returns true if
6884 // there is more animation to run.
6885 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
6886 if (!mDisplayFrozen) {
6887 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07006888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006889 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
6890 mHasTransformation = true;
6891 mHasLocalTransformation = true;
6892 if (!mLocalAnimating) {
6893 if (DEBUG_ANIM) Log.v(
6894 TAG, "Starting animation in " + this +
6895 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
6896 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
6897 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
6898 mAnimation.setStartTime(currentTime);
6899 mLocalAnimating = true;
6900 mAnimating = true;
6901 }
6902 mTransformation.clear();
6903 final boolean more = mAnimation.getTransformation(
6904 currentTime, mTransformation);
6905 if (DEBUG_ANIM) Log.v(
6906 TAG, "Stepped animation in " + this +
6907 ": more=" + more + ", xform=" + mTransformation);
6908 if (more) {
6909 // we're not done!
6910 return true;
6911 }
6912 if (DEBUG_ANIM) Log.v(
6913 TAG, "Finished animation in " + this +
6914 " @ " + currentTime);
6915 mAnimation = null;
6916 //WindowManagerService.this.dump();
6917 }
6918 mHasLocalTransformation = false;
6919 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006920 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006921 // When our app token is animating, we kind-of pretend like
6922 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
6923 // part of this check means that we will only do this if
6924 // our window is not currently exiting, or it is not
6925 // locally animating itself. The idea being that one that
6926 // is exiting and doing a local animation should be removed
6927 // once that animation is done.
6928 mAnimating = true;
6929 mHasTransformation = true;
6930 mTransformation.clear();
6931 return false;
6932 } else if (mHasTransformation) {
6933 // Little trick to get through the path below to act like
6934 // we have finished an animation.
6935 mAnimating = true;
6936 } else if (isAnimating()) {
6937 mAnimating = true;
6938 }
6939 } else if (mAnimation != null) {
6940 // If the display is frozen, and there is a pending animation,
6941 // clear it and make sure we run the cleanup code.
6942 mAnimating = true;
6943 mLocalAnimating = true;
6944 mAnimation = null;
6945 }
Romain Guy06882f82009-06-10 13:36:04 -07006946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006947 if (!mAnimating && !mLocalAnimating) {
6948 return false;
6949 }
6950
6951 if (DEBUG_ANIM) Log.v(
6952 TAG, "Animation done in " + this + ": exiting=" + mExiting
6953 + ", reportedVisible="
6954 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07006955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006956 mAnimating = false;
6957 mLocalAnimating = false;
6958 mAnimation = null;
6959 mAnimLayer = mLayer;
6960 if (mIsImWindow) {
6961 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006962 } else if (mIsWallpaper) {
6963 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006964 }
6965 if (DEBUG_LAYERS) Log.v(TAG, "Stepping win " + this
6966 + " anim layer: " + mAnimLayer);
6967 mHasTransformation = false;
6968 mHasLocalTransformation = false;
6969 mPolicyVisibility = mPolicyVisibilityAfterAnim;
6970 mTransformation.clear();
6971 if (mHasDrawn
6972 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
6973 && mAppToken != null
6974 && mAppToken.firstWindowDrawn
6975 && mAppToken.startingData != null) {
6976 if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Finish starting "
6977 + mToken + ": first real window done animating");
6978 mFinishedStarting.add(mAppToken);
6979 mH.sendEmptyMessage(H.FINISHED_STARTING);
6980 }
Romain Guy06882f82009-06-10 13:36:04 -07006981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006982 finishExit();
6983
6984 if (mAppToken != null) {
6985 mAppToken.updateReportedVisibilityLocked();
6986 }
6987
6988 return false;
6989 }
6990
6991 void finishExit() {
6992 if (DEBUG_ANIM) Log.v(
6993 TAG, "finishExit in " + this
6994 + ": exiting=" + mExiting
6995 + " remove=" + mRemoveOnExit
6996 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07006997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006998 final int N = mChildWindows.size();
6999 for (int i=0; i<N; i++) {
7000 ((WindowState)mChildWindows.get(i)).finishExit();
7001 }
Romain Guy06882f82009-06-10 13:36:04 -07007002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007003 if (!mExiting) {
7004 return;
7005 }
Romain Guy06882f82009-06-10 13:36:04 -07007006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007007 if (isWindowAnimating()) {
7008 return;
7009 }
7010
7011 if (localLOGV) Log.v(
7012 TAG, "Exit animation finished in " + this
7013 + ": remove=" + mRemoveOnExit);
7014 if (mSurface != null) {
7015 mDestroySurface.add(this);
7016 mDestroying = true;
7017 if (SHOW_TRANSACTIONS) Log.i(
7018 TAG, " SURFACE " + mSurface + ": HIDE (finishExit)");
7019 try {
7020 mSurface.hide();
7021 } catch (RuntimeException e) {
7022 Log.w(TAG, "Error hiding surface in " + this, e);
7023 }
7024 mLastHidden = true;
7025 mKeyWaiter.releasePendingPointerLocked(mSession);
7026 }
7027 mExiting = false;
7028 if (mRemoveOnExit) {
7029 mPendingRemove.add(this);
7030 mRemoveOnExit = false;
7031 }
7032 }
Romain Guy06882f82009-06-10 13:36:04 -07007033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007034 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7035 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7036 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7037 if (dtdx < -.000001f || dtdx > .000001f) return false;
7038 if (dsdy < -.000001f || dsdy > .000001f) return false;
7039 return true;
7040 }
Romain Guy06882f82009-06-10 13:36:04 -07007041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007042 void computeShownFrameLocked() {
7043 final boolean selfTransformation = mHasLocalTransformation;
7044 Transformation attachedTransformation =
7045 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7046 ? mAttachedWindow.mTransformation : null;
7047 Transformation appTransformation =
7048 (mAppToken != null && mAppToken.hasTransformation)
7049 ? mAppToken.transformation : null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007050
7051 // Wallpapers are animated based on the "real" window they
7052 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007053 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007054 && mWallpaperTarget != null) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007055 if (mWallpaperTarget.mHasLocalTransformation) {
7056 attachedTransformation = mWallpaperTarget.mTransformation;
7057 }
7058 if (mWallpaperTarget.mAppToken != null &&
7059 mWallpaperTarget.mAppToken.hasTransformation) {
7060 appTransformation = mWallpaperTarget.mAppToken.transformation;
7061 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007062 if (DEBUG_WALLPAPER && attachedTransformation != null) {
7063 Log.v(TAG, "WP target attached xform: " + attachedTransformation);
7064 }
7065 if (DEBUG_WALLPAPER && appTransformation != null) {
7066 Log.v(TAG, "WP target app xform: " + appTransformation);
7067 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007068 }
7069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007070 if (selfTransformation || attachedTransformation != null
7071 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007072 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007073 final Rect frame = mFrame;
7074 final float tmpFloats[] = mTmpFloats;
7075 final Matrix tmpMatrix = mTmpMatrix;
7076
7077 // Compute the desired transformation.
7078 tmpMatrix.setTranslate(frame.left, frame.top);
7079 if (selfTransformation) {
7080 tmpMatrix.preConcat(mTransformation.getMatrix());
7081 }
7082 if (attachedTransformation != null) {
7083 tmpMatrix.preConcat(attachedTransformation.getMatrix());
7084 }
7085 if (appTransformation != null) {
7086 tmpMatrix.preConcat(appTransformation.getMatrix());
7087 }
7088
7089 // "convert" it into SurfaceFlinger's format
7090 // (a 2x2 matrix + an offset)
7091 // Here we must not transform the position of the surface
7092 // since it is already included in the transformation.
7093 //Log.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007095 tmpMatrix.getValues(tmpFloats);
7096 mDsDx = tmpFloats[Matrix.MSCALE_X];
7097 mDtDx = tmpFloats[Matrix.MSKEW_X];
7098 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7099 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007100 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7101 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007102 int w = frame.width();
7103 int h = frame.height();
7104 mShownFrame.set(x, y, x+w, y+h);
7105
7106 // Now set the alpha... but because our current hardware
7107 // can't do alpha transformation on a non-opaque surface,
7108 // turn it off if we are running an animation that is also
7109 // transforming since it is more important to have that
7110 // animation be smooth.
7111 mShownAlpha = mAlpha;
7112 if (!mLimitedAlphaCompositing
7113 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7114 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7115 && x == frame.left && y == frame.top))) {
7116 //Log.i(TAG, "Applying alpha transform");
7117 if (selfTransformation) {
7118 mShownAlpha *= mTransformation.getAlpha();
7119 }
7120 if (attachedTransformation != null) {
7121 mShownAlpha *= attachedTransformation.getAlpha();
7122 }
7123 if (appTransformation != null) {
7124 mShownAlpha *= appTransformation.getAlpha();
7125 }
7126 } else {
7127 //Log.i(TAG, "Not applying alpha transform");
7128 }
Romain Guy06882f82009-06-10 13:36:04 -07007129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007130 if (localLOGV) Log.v(
7131 TAG, "Continuing animation in " + this +
7132 ": " + mShownFrame +
7133 ", alpha=" + mTransformation.getAlpha());
7134 return;
7135 }
Romain Guy06882f82009-06-10 13:36:04 -07007136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007137 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007138 if (mXOffset != 0 || mYOffset != 0) {
7139 mShownFrame.offset(mXOffset, mYOffset);
7140 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007141 mShownAlpha = mAlpha;
7142 mDsDx = 1;
7143 mDtDx = 0;
7144 mDsDy = 0;
7145 mDtDy = 1;
7146 }
Romain Guy06882f82009-06-10 13:36:04 -07007147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007148 /**
7149 * Is this window visible? It is not visible if there is no
7150 * surface, or we are in the process of running an exit animation
7151 * that will remove the surface, or its app token has been hidden.
7152 */
7153 public boolean isVisibleLw() {
7154 final AppWindowToken atoken = mAppToken;
7155 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7156 && (atoken == null || !atoken.hiddenRequested)
7157 && !mExiting && !mDestroying;
7158 }
7159
7160 /**
7161 * Is this window visible, ignoring its app token? It is not visible
7162 * if there is no surface, or we are in the process of running an exit animation
7163 * that will remove the surface.
7164 */
7165 public boolean isWinVisibleLw() {
7166 final AppWindowToken atoken = mAppToken;
7167 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7168 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7169 && !mExiting && !mDestroying;
7170 }
7171
7172 /**
7173 * The same as isVisible(), but follows the current hidden state of
7174 * the associated app token, not the pending requested hidden state.
7175 */
7176 boolean isVisibleNow() {
7177 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007178 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007179 }
7180
7181 /**
7182 * Same as isVisible(), but we also count it as visible between the
7183 * call to IWindowSession.add() and the first relayout().
7184 */
7185 boolean isVisibleOrAdding() {
7186 final AppWindowToken atoken = mAppToken;
7187 return (mSurface != null
7188 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7189 && mPolicyVisibility && !mAttachedHidden
7190 && (atoken == null || !atoken.hiddenRequested)
7191 && !mExiting && !mDestroying;
7192 }
7193
7194 /**
7195 * Is this window currently on-screen? It is on-screen either if it
7196 * is visible or it is currently running an animation before no longer
7197 * being visible.
7198 */
7199 boolean isOnScreen() {
7200 final AppWindowToken atoken = mAppToken;
7201 if (atoken != null) {
7202 return mSurface != null && mPolicyVisibility && !mDestroying
7203 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007204 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007205 } else {
7206 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007207 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007208 }
7209 }
Romain Guy06882f82009-06-10 13:36:04 -07007210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007211 /**
7212 * Like isOnScreen(), but we don't return true if the window is part
7213 * of a transition that has not yet been started.
7214 */
7215 boolean isReadyForDisplay() {
7216 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007217 final boolean animating = atoken != null
7218 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007219 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007220 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7221 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007222 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007223 }
7224
7225 /** Is the window or its container currently animating? */
7226 boolean isAnimating() {
7227 final WindowState attached = mAttachedWindow;
7228 final AppWindowToken atoken = mAppToken;
7229 return mAnimation != null
7230 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007231 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007232 (atoken.animation != null
7233 || atoken.inPendingTransaction));
7234 }
7235
7236 /** Is this window currently animating? */
7237 boolean isWindowAnimating() {
7238 return mAnimation != null;
7239 }
7240
7241 /**
7242 * Like isOnScreen, but returns false if the surface hasn't yet
7243 * been drawn.
7244 */
7245 public boolean isDisplayedLw() {
7246 final AppWindowToken atoken = mAppToken;
7247 return mSurface != null && mPolicyVisibility && !mDestroying
7248 && !mDrawPending && !mCommitDrawPending
7249 && ((!mAttachedHidden &&
7250 (atoken == null || !atoken.hiddenRequested))
7251 || mAnimating);
7252 }
7253
7254 public boolean fillsScreenLw(int screenWidth, int screenHeight,
7255 boolean shownFrame, boolean onlyOpaque) {
7256 if (mSurface == null) {
7257 return false;
7258 }
7259 if (mAppToken != null && !mAppToken.appFullscreen) {
7260 return false;
7261 }
7262 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
7263 return false;
7264 }
7265 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007266
7267 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
7268 return frame.left <= mCompatibleScreenFrame.left &&
7269 frame.top <= mCompatibleScreenFrame.top &&
7270 frame.right >= mCompatibleScreenFrame.right &&
7271 frame.bottom >= mCompatibleScreenFrame.bottom;
7272 } else {
7273 return frame.left <= 0 && frame.top <= 0
7274 && frame.right >= screenWidth
7275 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007276 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007277 }
Romain Guy06882f82009-06-10 13:36:04 -07007278
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007279 /**
7280 * Return true if the window is opaque and fully drawn.
7281 */
7282 boolean isOpaqueDrawn() {
7283 return mAttrs.format == PixelFormat.OPAQUE && mSurface != null
7284 && mAnimation == null && !mDrawPending && !mCommitDrawPending;
7285 }
7286
7287 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7288 return
7289 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007290 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7291 // only if it's visible
7292 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007293 // and only if the application fills the compatible screen
7294 mFrame.left <= mCompatibleScreenFrame.left &&
7295 mFrame.top <= mCompatibleScreenFrame.top &&
7296 mFrame.right >= mCompatibleScreenFrame.right &&
7297 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007298 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007299 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007300 }
7301
7302 boolean isFullscreen(int screenWidth, int screenHeight) {
7303 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007304 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007305 }
7306
7307 void removeLocked() {
7308 if (mAttachedWindow != null) {
7309 mAttachedWindow.mChildWindows.remove(this);
7310 }
7311 destroySurfaceLocked();
7312 mSession.windowRemovedLocked();
7313 try {
7314 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7315 } catch (RuntimeException e) {
7316 // Ignore if it has already been removed (usually because
7317 // we are doing this as part of processing a death note.)
7318 }
7319 }
7320
7321 private class DeathRecipient implements IBinder.DeathRecipient {
7322 public void binderDied() {
7323 try {
7324 synchronized(mWindowMap) {
7325 WindowState win = windowForClientLocked(mSession, mClient);
7326 Log.i(TAG, "WIN DEATH: " + win);
7327 if (win != null) {
7328 removeWindowLocked(mSession, win);
7329 }
7330 }
7331 } catch (IllegalArgumentException ex) {
7332 // This will happen if the window has already been
7333 // removed.
7334 }
7335 }
7336 }
7337
7338 /** Returns true if this window desires key events. */
7339 public final boolean canReceiveKeys() {
7340 return isVisibleOrAdding()
7341 && (mViewVisibility == View.VISIBLE)
7342 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7343 }
7344
7345 public boolean hasDrawnLw() {
7346 return mHasDrawn;
7347 }
7348
7349 public boolean showLw(boolean doAnimation) {
7350 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim) {
7351 mPolicyVisibility = true;
7352 mPolicyVisibilityAfterAnim = true;
7353 if (doAnimation) {
7354 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7355 }
7356 requestAnimationLocked(0);
7357 return true;
7358 }
7359 return false;
7360 }
7361
7362 public boolean hideLw(boolean doAnimation) {
7363 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7364 : mPolicyVisibility;
7365 if (current) {
7366 if (doAnimation) {
7367 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7368 if (mAnimation == null) {
7369 doAnimation = false;
7370 }
7371 }
7372 if (doAnimation) {
7373 mPolicyVisibilityAfterAnim = false;
7374 } else {
7375 mPolicyVisibilityAfterAnim = false;
7376 mPolicyVisibility = false;
7377 }
7378 requestAnimationLocked(0);
7379 return true;
7380 }
7381 return false;
7382 }
7383
7384 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007385 StringBuilder sb = new StringBuilder(64);
Romain Guy06882f82009-06-10 13:36:04 -07007386
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007387 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7388 pw.print(" mClient="); pw.println(mClient.asBinder());
7389 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7390 if (mAttachedWindow != null || mLayoutAttached) {
7391 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7392 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7393 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007394 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7395 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7396 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007397 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7398 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007399 }
7400 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7401 pw.print(" mSubLayer="); pw.print(mSubLayer);
7402 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7403 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7404 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7405 pw.print("="); pw.print(mAnimLayer);
7406 pw.print(" mLastLayer="); pw.println(mLastLayer);
7407 if (mSurface != null) {
7408 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
7409 }
7410 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7411 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7412 if (mAppToken != null) {
7413 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7414 }
7415 if (mTargetAppToken != null) {
7416 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7417 }
7418 pw.print(prefix); pw.print("mViewVisibility=0x");
7419 pw.print(Integer.toHexString(mViewVisibility));
7420 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007421 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7422 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007423 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7424 pw.print(prefix); pw.print("mPolicyVisibility=");
7425 pw.print(mPolicyVisibility);
7426 pw.print(" mPolicyVisibilityAfterAnim=");
7427 pw.print(mPolicyVisibilityAfterAnim);
7428 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7429 }
7430 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007431 pw.print(" h="); pw.println(mRequestedHeight);
7432 if (mXOffset != 0 || mYOffset != 0) {
7433 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7434 pw.print(" y="); pw.println(mYOffset);
7435 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007436 pw.print(prefix); pw.print("mGivenContentInsets=");
7437 mGivenContentInsets.printShortString(pw);
7438 pw.print(" mGivenVisibleInsets=");
7439 mGivenVisibleInsets.printShortString(pw);
7440 pw.println();
7441 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7442 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7443 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7444 }
7445 pw.print(prefix); pw.print("mShownFrame=");
7446 mShownFrame.printShortString(pw);
7447 pw.print(" last="); mLastShownFrame.printShortString(pw);
7448 pw.println();
7449 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7450 pw.print(" last="); mLastFrame.printShortString(pw);
7451 pw.println();
7452 pw.print(prefix); pw.print("mContainingFrame=");
7453 mContainingFrame.printShortString(pw);
7454 pw.print(" mDisplayFrame=");
7455 mDisplayFrame.printShortString(pw);
7456 pw.println();
7457 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7458 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7459 pw.println();
7460 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7461 pw.print(" last="); mLastContentInsets.printShortString(pw);
7462 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7463 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7464 pw.println();
7465 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7466 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7467 pw.print(" mAlpha="); pw.print(mAlpha);
7468 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7469 }
7470 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7471 || mAnimation != null) {
7472 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7473 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7474 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7475 pw.print(" mAnimation="); pw.println(mAnimation);
7476 }
7477 if (mHasTransformation || mHasLocalTransformation) {
7478 pw.print(prefix); pw.print("XForm: has=");
7479 pw.print(mHasTransformation);
7480 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7481 pw.print(" "); mTransformation.printShortString(pw);
7482 pw.println();
7483 }
7484 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7485 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7486 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7487 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7488 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7489 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7490 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7491 pw.print(" mDestroying="); pw.print(mDestroying);
7492 pw.print(" mRemoved="); pw.println(mRemoved);
7493 }
7494 if (mOrientationChanging || mAppFreezing) {
7495 pw.print(prefix); pw.print("mOrientationChanging=");
7496 pw.print(mOrientationChanging);
7497 pw.print(" mAppFreezing="); pw.println(mAppFreezing);
7498 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007499 if (mHScale != 1 || mVScale != 1) {
7500 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7501 pw.print(" mVScale="); pw.println(mVScale);
7502 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007503 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007504 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7505 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7506 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007507 }
7508
7509 @Override
7510 public String toString() {
7511 return "Window{"
7512 + Integer.toHexString(System.identityHashCode(this))
7513 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7514 }
7515 }
Romain Guy06882f82009-06-10 13:36:04 -07007516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007517 // -------------------------------------------------------------
7518 // Window Token State
7519 // -------------------------------------------------------------
7520
7521 class WindowToken {
7522 // The actual token.
7523 final IBinder token;
7524
7525 // The type of window this token is for, as per WindowManager.LayoutParams.
7526 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007528 // Set if this token was explicitly added by a client, so should
7529 // not be removed when all windows are removed.
7530 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007531
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007532 // For printing.
7533 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007535 // If this is an AppWindowToken, this is non-null.
7536 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007538 // All of the windows associated with this token.
7539 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7540
7541 // Is key dispatching paused for this token?
7542 boolean paused = false;
7543
7544 // Should this token's windows be hidden?
7545 boolean hidden;
7546
7547 // Temporary for finding which tokens no longer have visible windows.
7548 boolean hasVisible;
7549
7550 WindowToken(IBinder _token, int type, boolean _explicit) {
7551 token = _token;
7552 windowType = type;
7553 explicit = _explicit;
7554 }
7555
7556 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007557 pw.print(prefix); pw.print("token="); pw.println(token);
7558 pw.print(prefix); pw.print("windows="); pw.println(windows);
7559 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7560 pw.print(" hidden="); pw.print(hidden);
7561 pw.print(" hasVisible="); pw.println(hasVisible);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007562 }
7563
7564 @Override
7565 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007566 if (stringName == null) {
7567 StringBuilder sb = new StringBuilder();
7568 sb.append("WindowToken{");
7569 sb.append(Integer.toHexString(System.identityHashCode(this)));
7570 sb.append(" token="); sb.append(token); sb.append('}');
7571 stringName = sb.toString();
7572 }
7573 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007574 }
7575 };
7576
7577 class AppWindowToken extends WindowToken {
7578 // Non-null only for application tokens.
7579 final IApplicationToken appToken;
7580
7581 // All of the windows and child windows that are included in this
7582 // application token. Note this list is NOT sorted!
7583 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7584
7585 int groupId = -1;
7586 boolean appFullscreen;
7587 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Romain Guy06882f82009-06-10 13:36:04 -07007588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007589 // These are used for determining when all windows associated with
7590 // an activity have been drawn, so they can be made visible together
7591 // at the same time.
7592 int lastTransactionSequence = mTransactionSequence-1;
7593 int numInterestingWindows;
7594 int numDrawnWindows;
7595 boolean inPendingTransaction;
7596 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007598 // Is this token going to be hidden in a little while? If so, it
7599 // won't be taken into account for setting the screen orientation.
7600 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007602 // Is this window's surface needed? This is almost like hidden, except
7603 // it will sometimes be true a little earlier: when the token has
7604 // been shown, but is still waiting for its app transition to execute
7605 // before making its windows shown.
7606 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007608 // Have we told the window clients to hide themselves?
7609 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007611 // Last visibility state we reported to the app token.
7612 boolean reportedVisible;
7613
7614 // Set to true when the token has been removed from the window mgr.
7615 boolean removed;
7616
7617 // Have we been asked to have this token keep the screen frozen?
7618 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007620 boolean animating;
7621 Animation animation;
7622 boolean hasTransformation;
7623 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007625 // Offset to the window of all layers in the token, for use by
7626 // AppWindowToken animations.
7627 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007629 // Information about an application starting window if displayed.
7630 StartingData startingData;
7631 WindowState startingWindow;
7632 View startingView;
7633 boolean startingDisplayed;
7634 boolean startingMoved;
7635 boolean firstWindowDrawn;
7636
7637 AppWindowToken(IApplicationToken _token) {
7638 super(_token.asBinder(),
7639 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7640 appWindowToken = this;
7641 appToken = _token;
7642 }
Romain Guy06882f82009-06-10 13:36:04 -07007643
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007644 public void setAnimation(Animation anim) {
7645 if (localLOGV) Log.v(
7646 TAG, "Setting animation in " + this + ": " + anim);
7647 animation = anim;
7648 animating = false;
7649 anim.restrictDuration(MAX_ANIMATION_DURATION);
7650 anim.scaleCurrentDuration(mTransitionAnimationScale);
7651 int zorder = anim.getZAdjustment();
7652 int adj = 0;
7653 if (zorder == Animation.ZORDER_TOP) {
7654 adj = TYPE_LAYER_OFFSET;
7655 } else if (zorder == Animation.ZORDER_BOTTOM) {
7656 adj = -TYPE_LAYER_OFFSET;
7657 }
Romain Guy06882f82009-06-10 13:36:04 -07007658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007659 if (animLayerAdjustment != adj) {
7660 animLayerAdjustment = adj;
7661 updateLayers();
7662 }
7663 }
Romain Guy06882f82009-06-10 13:36:04 -07007664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007665 public void setDummyAnimation() {
7666 if (animation == null) {
7667 if (localLOGV) Log.v(
7668 TAG, "Setting dummy animation in " + this);
7669 animation = sDummyAnimation;
7670 }
7671 }
7672
7673 public void clearAnimation() {
7674 if (animation != null) {
7675 animation = null;
7676 animating = true;
7677 }
7678 }
Romain Guy06882f82009-06-10 13:36:04 -07007679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007680 void updateLayers() {
7681 final int N = allAppWindows.size();
7682 final int adj = animLayerAdjustment;
7683 for (int i=0; i<N; i++) {
7684 WindowState w = allAppWindows.get(i);
7685 w.mAnimLayer = w.mLayer + adj;
7686 if (DEBUG_LAYERS) Log.v(TAG, "Updating layer " + w + ": "
7687 + w.mAnimLayer);
7688 if (w == mInputMethodTarget) {
7689 setInputMethodAnimLayerAdjustment(adj);
7690 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007691 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007692 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007693 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007694 }
7695 }
Romain Guy06882f82009-06-10 13:36:04 -07007696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007697 void sendAppVisibilityToClients() {
7698 final int N = allAppWindows.size();
7699 for (int i=0; i<N; i++) {
7700 WindowState win = allAppWindows.get(i);
7701 if (win == startingWindow && clientHidden) {
7702 // Don't hide the starting window.
7703 continue;
7704 }
7705 try {
7706 if (DEBUG_VISIBILITY) Log.v(TAG,
7707 "Setting visibility of " + win + ": " + (!clientHidden));
7708 win.mClient.dispatchAppVisibility(!clientHidden);
7709 } catch (RemoteException e) {
7710 }
7711 }
7712 }
Romain Guy06882f82009-06-10 13:36:04 -07007713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007714 void showAllWindowsLocked() {
7715 final int NW = allAppWindows.size();
7716 for (int i=0; i<NW; i++) {
7717 WindowState w = allAppWindows.get(i);
7718 if (DEBUG_VISIBILITY) Log.v(TAG,
7719 "performing show on: " + w);
7720 w.performShowLocked();
7721 }
7722 }
Romain Guy06882f82009-06-10 13:36:04 -07007723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007724 // This must be called while inside a transaction.
7725 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
7726 if (!mDisplayFrozen) {
7727 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007728
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007729 if (animation == sDummyAnimation) {
7730 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007731 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007732 // when it is really time to animate, this will be set to
7733 // a real animation and the next call will execute normally.
7734 return false;
7735 }
Romain Guy06882f82009-06-10 13:36:04 -07007736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007737 if ((allDrawn || animating || startingDisplayed) && animation != null) {
7738 if (!animating) {
7739 if (DEBUG_ANIM) Log.v(
7740 TAG, "Starting animation in " + this +
7741 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
7742 + " scale=" + mTransitionAnimationScale
7743 + " allDrawn=" + allDrawn + " animating=" + animating);
7744 animation.initialize(dw, dh, dw, dh);
7745 animation.setStartTime(currentTime);
7746 animating = true;
7747 }
7748 transformation.clear();
7749 final boolean more = animation.getTransformation(
7750 currentTime, transformation);
7751 if (DEBUG_ANIM) Log.v(
7752 TAG, "Stepped animation in " + this +
7753 ": more=" + more + ", xform=" + transformation);
7754 if (more) {
7755 // we're done!
7756 hasTransformation = true;
7757 return true;
7758 }
7759 if (DEBUG_ANIM) Log.v(
7760 TAG, "Finished animation in " + this +
7761 " @ " + currentTime);
7762 animation = null;
7763 }
7764 } else if (animation != null) {
7765 // If the display is frozen, and there is a pending animation,
7766 // clear it and make sure we run the cleanup code.
7767 animating = true;
7768 animation = null;
7769 }
7770
7771 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07007772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007773 if (!animating) {
7774 return false;
7775 }
7776
7777 clearAnimation();
7778 animating = false;
7779 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
7780 moveInputMethodWindowsIfNeededLocked(true);
7781 }
Romain Guy06882f82009-06-10 13:36:04 -07007782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007783 if (DEBUG_ANIM) Log.v(
7784 TAG, "Animation done in " + this
7785 + ": reportedVisible=" + reportedVisible);
7786
7787 transformation.clear();
7788 if (animLayerAdjustment != 0) {
7789 animLayerAdjustment = 0;
7790 updateLayers();
7791 }
Romain Guy06882f82009-06-10 13:36:04 -07007792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007793 final int N = windows.size();
7794 for (int i=0; i<N; i++) {
7795 ((WindowState)windows.get(i)).finishExit();
7796 }
7797 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07007798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007799 return false;
7800 }
7801
7802 void updateReportedVisibilityLocked() {
7803 if (appToken == null) {
7804 return;
7805 }
Romain Guy06882f82009-06-10 13:36:04 -07007806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007807 int numInteresting = 0;
7808 int numVisible = 0;
7809 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07007810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007811 if (DEBUG_VISIBILITY) Log.v(TAG, "Update reported visibility: " + this);
7812 final int N = allAppWindows.size();
7813 for (int i=0; i<N; i++) {
7814 WindowState win = allAppWindows.get(i);
7815 if (win == startingWindow || win.mAppFreezing) {
7816 continue;
7817 }
7818 if (DEBUG_VISIBILITY) {
7819 Log.v(TAG, "Win " + win + ": isDisplayed="
7820 + win.isDisplayedLw()
7821 + ", isAnimating=" + win.isAnimating());
7822 if (!win.isDisplayedLw()) {
7823 Log.v(TAG, "Not displayed: s=" + win.mSurface
7824 + " pv=" + win.mPolicyVisibility
7825 + " dp=" + win.mDrawPending
7826 + " cdp=" + win.mCommitDrawPending
7827 + " ah=" + win.mAttachedHidden
7828 + " th="
7829 + (win.mAppToken != null
7830 ? win.mAppToken.hiddenRequested : false)
7831 + " a=" + win.mAnimating);
7832 }
7833 }
7834 numInteresting++;
7835 if (win.isDisplayedLw()) {
7836 if (!win.isAnimating()) {
7837 numVisible++;
7838 }
7839 nowGone = false;
7840 } else if (win.isAnimating()) {
7841 nowGone = false;
7842 }
7843 }
Romain Guy06882f82009-06-10 13:36:04 -07007844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007845 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
7846 if (DEBUG_VISIBILITY) Log.v(TAG, "VIS " + this + ": interesting="
7847 + numInteresting + " visible=" + numVisible);
7848 if (nowVisible != reportedVisible) {
7849 if (DEBUG_VISIBILITY) Log.v(
7850 TAG, "Visibility changed in " + this
7851 + ": vis=" + nowVisible);
7852 reportedVisible = nowVisible;
7853 Message m = mH.obtainMessage(
7854 H.REPORT_APPLICATION_TOKEN_WINDOWS,
7855 nowVisible ? 1 : 0,
7856 nowGone ? 1 : 0,
7857 this);
7858 mH.sendMessage(m);
7859 }
7860 }
Romain Guy06882f82009-06-10 13:36:04 -07007861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007862 void dump(PrintWriter pw, String prefix) {
7863 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007864 if (appToken != null) {
7865 pw.print(prefix); pw.println("app=true");
7866 }
7867 if (allAppWindows.size() > 0) {
7868 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
7869 }
7870 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007871 pw.print(" appFullscreen="); pw.println(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007872 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
7873 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
7874 pw.print(" clientHidden="); pw.print(clientHidden);
7875 pw.print(" willBeHidden="); pw.print(willBeHidden);
7876 pw.print(" reportedVisible="); pw.println(reportedVisible);
7877 if (paused || freezingScreen) {
7878 pw.print(prefix); pw.print("paused="); pw.print(paused);
7879 pw.print(" freezingScreen="); pw.println(freezingScreen);
7880 }
7881 if (numInterestingWindows != 0 || numDrawnWindows != 0
7882 || inPendingTransaction || allDrawn) {
7883 pw.print(prefix); pw.print("numInterestingWindows=");
7884 pw.print(numInterestingWindows);
7885 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
7886 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
7887 pw.print(" allDrawn="); pw.println(allDrawn);
7888 }
7889 if (animating || animation != null) {
7890 pw.print(prefix); pw.print("animating="); pw.print(animating);
7891 pw.print(" animation="); pw.println(animation);
7892 }
7893 if (animLayerAdjustment != 0) {
7894 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
7895 }
7896 if (hasTransformation) {
7897 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
7898 pw.print(" transformation="); transformation.printShortString(pw);
7899 pw.println();
7900 }
7901 if (startingData != null || removed || firstWindowDrawn) {
7902 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
7903 pw.print(" removed="); pw.print(removed);
7904 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
7905 }
7906 if (startingWindow != null || startingView != null
7907 || startingDisplayed || startingMoved) {
7908 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
7909 pw.print(" startingView="); pw.print(startingView);
7910 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
7911 pw.print(" startingMoved"); pw.println(startingMoved);
7912 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007913 }
7914
7915 @Override
7916 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007917 if (stringName == null) {
7918 StringBuilder sb = new StringBuilder();
7919 sb.append("AppWindowToken{");
7920 sb.append(Integer.toHexString(System.identityHashCode(this)));
7921 sb.append(" token="); sb.append(token); sb.append('}');
7922 stringName = sb.toString();
7923 }
7924 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007925 }
7926 }
Romain Guy06882f82009-06-10 13:36:04 -07007927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007928 public static WindowManager.LayoutParams findAnimations(
7929 ArrayList<AppWindowToken> order,
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07007930 ArrayList<AppWindowToken> openingTokenList1,
7931 ArrayList<AppWindowToken> closingTokenList2) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007932 // We need to figure out which animation to use...
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07007933
7934 // First, check if there is a compatible window in opening/closing
7935 // apps, and use it if exists.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007936 WindowManager.LayoutParams animParams = null;
7937 int animSrc = 0;
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07007938 animParams = findCompatibleWindowParams(openingTokenList1);
7939 if (animParams == null) {
7940 animParams = findCompatibleWindowParams(closingTokenList2);
7941 }
7942 if (animParams != null) {
7943 return animParams;
7944 }
7945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007946 //Log.i(TAG, "Looking for animations...");
7947 for (int i=order.size()-1; i>=0; i--) {
7948 AppWindowToken wtoken = order.get(i);
7949 //Log.i(TAG, "Token " + wtoken + " with " + wtoken.windows.size() + " windows");
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07007950 if (openingTokenList1.contains(wtoken) || closingTokenList2.contains(wtoken)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007951 int j = wtoken.windows.size();
7952 while (j > 0) {
7953 j--;
7954 WindowState win = wtoken.windows.get(j);
7955 //Log.i(TAG, "Window " + win + ": type=" + win.mAttrs.type);
7956 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
7957 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
7958 //Log.i(TAG, "Found base or application window, done!");
7959 if (wtoken.appFullscreen) {
7960 return win.mAttrs;
7961 }
7962 if (animSrc < 2) {
7963 animParams = win.mAttrs;
7964 animSrc = 2;
7965 }
7966 } else if (animSrc < 1 && win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION) {
7967 //Log.i(TAG, "Found normal window, we may use this...");
7968 animParams = win.mAttrs;
7969 animSrc = 1;
7970 }
7971 }
7972 }
7973 }
Romain Guy06882f82009-06-10 13:36:04 -07007974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007975 return animParams;
7976 }
Romain Guy06882f82009-06-10 13:36:04 -07007977
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07007978 private static LayoutParams findCompatibleWindowParams(ArrayList<AppWindowToken> tokenList) {
7979 for (int appCount = tokenList.size() - 1; appCount >= 0; appCount--) {
7980 AppWindowToken wtoken = tokenList.get(appCount);
7981 // Just checking one window is sufficient as all windows have the compatible flag
7982 // if the application is in compatibility mode.
7983 if (wtoken.windows.size() > 0) {
7984 WindowManager.LayoutParams params = wtoken.windows.get(0).mAttrs;
7985 if ((params.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
7986 return params;
7987 }
7988 }
7989 }
7990 return null;
7991 }
7992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007993 // -------------------------------------------------------------
7994 // DummyAnimation
7995 // -------------------------------------------------------------
7996
7997 // This is an animation that does nothing: it just immediately finishes
7998 // itself every time it is called. It is used as a stub animation in cases
7999 // where we want to synchronize multiple things that may be animating.
8000 static final class DummyAnimation extends Animation {
8001 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8002 return false;
8003 }
8004 }
8005 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008007 // -------------------------------------------------------------
8008 // Async Handler
8009 // -------------------------------------------------------------
8010
8011 static final class StartingData {
8012 final String pkg;
8013 final int theme;
8014 final CharSequence nonLocalizedLabel;
8015 final int labelRes;
8016 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008018 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8019 int _labelRes, int _icon) {
8020 pkg = _pkg;
8021 theme = _theme;
8022 nonLocalizedLabel = _nonLocalizedLabel;
8023 labelRes = _labelRes;
8024 icon = _icon;
8025 }
8026 }
8027
8028 private final class H extends Handler {
8029 public static final int REPORT_FOCUS_CHANGE = 2;
8030 public static final int REPORT_LOSING_FOCUS = 3;
8031 public static final int ANIMATE = 4;
8032 public static final int ADD_STARTING = 5;
8033 public static final int REMOVE_STARTING = 6;
8034 public static final int FINISHED_STARTING = 7;
8035 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008036 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8037 public static final int HOLD_SCREEN_CHANGED = 12;
8038 public static final int APP_TRANSITION_TIMEOUT = 13;
8039 public static final int PERSIST_ANIMATION_SCALE = 14;
8040 public static final int FORCE_GC = 15;
8041 public static final int ENABLE_SCREEN = 16;
8042 public static final int APP_FREEZE_TIMEOUT = 17;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008043 public static final int COMPUTE_AND_SEND_NEW_CONFIGURATION = 18;
Romain Guy06882f82009-06-10 13:36:04 -07008044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008045 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008047 public H() {
8048 }
Romain Guy06882f82009-06-10 13:36:04 -07008049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008050 @Override
8051 public void handleMessage(Message msg) {
8052 switch (msg.what) {
8053 case REPORT_FOCUS_CHANGE: {
8054 WindowState lastFocus;
8055 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008057 synchronized(mWindowMap) {
8058 lastFocus = mLastFocus;
8059 newFocus = mCurrentFocus;
8060 if (lastFocus == newFocus) {
8061 // Focus is not changing, so nothing to do.
8062 return;
8063 }
8064 mLastFocus = newFocus;
8065 //Log.i(TAG, "Focus moving from " + lastFocus
8066 // + " to " + newFocus);
8067 if (newFocus != null && lastFocus != null
8068 && !newFocus.isDisplayedLw()) {
8069 //Log.i(TAG, "Delaying loss of focus...");
8070 mLosingFocus.add(lastFocus);
8071 lastFocus = null;
8072 }
8073 }
8074
8075 if (lastFocus != newFocus) {
8076 //System.out.println("Changing focus from " + lastFocus
8077 // + " to " + newFocus);
8078 if (newFocus != null) {
8079 try {
8080 //Log.i(TAG, "Gaining focus: " + newFocus);
8081 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8082 } catch (RemoteException e) {
8083 // Ignore if process has died.
8084 }
8085 }
8086
8087 if (lastFocus != null) {
8088 try {
8089 //Log.i(TAG, "Losing focus: " + lastFocus);
8090 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8091 } catch (RemoteException e) {
8092 // Ignore if process has died.
8093 }
8094 }
8095 }
8096 } break;
8097
8098 case REPORT_LOSING_FOCUS: {
8099 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008101 synchronized(mWindowMap) {
8102 losers = mLosingFocus;
8103 mLosingFocus = new ArrayList<WindowState>();
8104 }
8105
8106 final int N = losers.size();
8107 for (int i=0; i<N; i++) {
8108 try {
8109 //Log.i(TAG, "Losing delayed focus: " + losers.get(i));
8110 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8111 } catch (RemoteException e) {
8112 // Ignore if process has died.
8113 }
8114 }
8115 } break;
8116
8117 case ANIMATE: {
8118 synchronized(mWindowMap) {
8119 mAnimationPending = false;
8120 performLayoutAndPlaceSurfacesLocked();
8121 }
8122 } break;
8123
8124 case ADD_STARTING: {
8125 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8126 final StartingData sd = wtoken.startingData;
8127
8128 if (sd == null) {
8129 // Animation has been canceled... do nothing.
8130 return;
8131 }
Romain Guy06882f82009-06-10 13:36:04 -07008132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008133 if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Add starting "
8134 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008136 View view = null;
8137 try {
8138 view = mPolicy.addStartingWindow(
8139 wtoken.token, sd.pkg,
8140 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8141 sd.icon);
8142 } catch (Exception e) {
8143 Log.w(TAG, "Exception when adding starting window", e);
8144 }
8145
8146 if (view != null) {
8147 boolean abort = false;
8148
8149 synchronized(mWindowMap) {
8150 if (wtoken.removed || wtoken.startingData == null) {
8151 // If the window was successfully added, then
8152 // we need to remove it.
8153 if (wtoken.startingWindow != null) {
8154 if (DEBUG_STARTING_WINDOW) Log.v(TAG,
8155 "Aborted starting " + wtoken
8156 + ": removed=" + wtoken.removed
8157 + " startingData=" + wtoken.startingData);
8158 wtoken.startingWindow = null;
8159 wtoken.startingData = null;
8160 abort = true;
8161 }
8162 } else {
8163 wtoken.startingView = view;
8164 }
8165 if (DEBUG_STARTING_WINDOW && !abort) Log.v(TAG,
8166 "Added starting " + wtoken
8167 + ": startingWindow="
8168 + wtoken.startingWindow + " startingView="
8169 + wtoken.startingView);
8170 }
8171
8172 if (abort) {
8173 try {
8174 mPolicy.removeStartingWindow(wtoken.token, view);
8175 } catch (Exception e) {
8176 Log.w(TAG, "Exception when removing starting window", e);
8177 }
8178 }
8179 }
8180 } break;
8181
8182 case REMOVE_STARTING: {
8183 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8184 IBinder token = null;
8185 View view = null;
8186 synchronized (mWindowMap) {
8187 if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Remove starting "
8188 + wtoken + ": startingWindow="
8189 + wtoken.startingWindow + " startingView="
8190 + wtoken.startingView);
8191 if (wtoken.startingWindow != null) {
8192 view = wtoken.startingView;
8193 token = wtoken.token;
8194 wtoken.startingData = null;
8195 wtoken.startingView = null;
8196 wtoken.startingWindow = null;
8197 }
8198 }
8199 if (view != null) {
8200 try {
8201 mPolicy.removeStartingWindow(token, view);
8202 } catch (Exception e) {
8203 Log.w(TAG, "Exception when removing starting window", e);
8204 }
8205 }
8206 } break;
8207
8208 case FINISHED_STARTING: {
8209 IBinder token = null;
8210 View view = null;
8211 while (true) {
8212 synchronized (mWindowMap) {
8213 final int N = mFinishedStarting.size();
8214 if (N <= 0) {
8215 break;
8216 }
8217 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8218
8219 if (DEBUG_STARTING_WINDOW) Log.v(TAG,
8220 "Finished starting " + wtoken
8221 + ": startingWindow=" + wtoken.startingWindow
8222 + " startingView=" + wtoken.startingView);
8223
8224 if (wtoken.startingWindow == null) {
8225 continue;
8226 }
8227
8228 view = wtoken.startingView;
8229 token = wtoken.token;
8230 wtoken.startingData = null;
8231 wtoken.startingView = null;
8232 wtoken.startingWindow = null;
8233 }
8234
8235 try {
8236 mPolicy.removeStartingWindow(token, view);
8237 } catch (Exception e) {
8238 Log.w(TAG, "Exception when removing starting window", e);
8239 }
8240 }
8241 } break;
8242
8243 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8244 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8245
8246 boolean nowVisible = msg.arg1 != 0;
8247 boolean nowGone = msg.arg2 != 0;
8248
8249 try {
8250 if (DEBUG_VISIBILITY) Log.v(
8251 TAG, "Reporting visible in " + wtoken
8252 + " visible=" + nowVisible
8253 + " gone=" + nowGone);
8254 if (nowVisible) {
8255 wtoken.appToken.windowsVisible();
8256 } else {
8257 wtoken.appToken.windowsGone();
8258 }
8259 } catch (RemoteException ex) {
8260 }
8261 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008263 case WINDOW_FREEZE_TIMEOUT: {
8264 synchronized (mWindowMap) {
8265 Log.w(TAG, "Window freeze timeout expired.");
8266 int i = mWindows.size();
8267 while (i > 0) {
8268 i--;
8269 WindowState w = (WindowState)mWindows.get(i);
8270 if (w.mOrientationChanging) {
8271 w.mOrientationChanging = false;
8272 Log.w(TAG, "Force clearing orientation change: " + w);
8273 }
8274 }
8275 performLayoutAndPlaceSurfacesLocked();
8276 }
8277 break;
8278 }
Romain Guy06882f82009-06-10 13:36:04 -07008279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008280 case HOLD_SCREEN_CHANGED: {
8281 Session oldHold;
8282 Session newHold;
8283 synchronized (mWindowMap) {
8284 oldHold = mLastReportedHold;
8285 newHold = (Session)msg.obj;
8286 mLastReportedHold = newHold;
8287 }
Romain Guy06882f82009-06-10 13:36:04 -07008288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008289 if (oldHold != newHold) {
8290 try {
8291 if (oldHold != null) {
8292 mBatteryStats.noteStopWakelock(oldHold.mUid,
8293 "window",
8294 BatteryStats.WAKE_TYPE_WINDOW);
8295 }
8296 if (newHold != null) {
8297 mBatteryStats.noteStartWakelock(newHold.mUid,
8298 "window",
8299 BatteryStats.WAKE_TYPE_WINDOW);
8300 }
8301 } catch (RemoteException e) {
8302 }
8303 }
8304 break;
8305 }
Romain Guy06882f82009-06-10 13:36:04 -07008306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008307 case APP_TRANSITION_TIMEOUT: {
8308 synchronized (mWindowMap) {
8309 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) {
8310 if (DEBUG_APP_TRANSITIONS) Log.v(TAG,
8311 "*** APP TRANSITION TIMEOUT");
8312 mAppTransitionReady = true;
8313 mAppTransitionTimeout = true;
8314 performLayoutAndPlaceSurfacesLocked();
8315 }
8316 }
8317 break;
8318 }
Romain Guy06882f82009-06-10 13:36:04 -07008319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008320 case PERSIST_ANIMATION_SCALE: {
8321 Settings.System.putFloat(mContext.getContentResolver(),
8322 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8323 Settings.System.putFloat(mContext.getContentResolver(),
8324 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8325 break;
8326 }
Romain Guy06882f82009-06-10 13:36:04 -07008327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008328 case FORCE_GC: {
8329 synchronized(mWindowMap) {
8330 if (mAnimationPending) {
8331 // If we are animating, don't do the gc now but
8332 // delay a bit so we don't interrupt the animation.
8333 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8334 2000);
8335 return;
8336 }
8337 // If we are currently rotating the display, it will
8338 // schedule a new message when done.
8339 if (mDisplayFrozen) {
8340 return;
8341 }
8342 mFreezeGcPending = 0;
8343 }
8344 Runtime.getRuntime().gc();
8345 break;
8346 }
Romain Guy06882f82009-06-10 13:36:04 -07008347
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008348 case ENABLE_SCREEN: {
8349 performEnableScreen();
8350 break;
8351 }
Romain Guy06882f82009-06-10 13:36:04 -07008352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008353 case APP_FREEZE_TIMEOUT: {
8354 synchronized (mWindowMap) {
8355 Log.w(TAG, "App freeze timeout expired.");
8356 int i = mAppTokens.size();
8357 while (i > 0) {
8358 i--;
8359 AppWindowToken tok = mAppTokens.get(i);
8360 if (tok.freezingScreen) {
8361 Log.w(TAG, "Force clearing freeze: " + tok);
8362 unsetAppFreezingScreenLocked(tok, true, true);
8363 }
8364 }
8365 }
8366 break;
8367 }
Romain Guy06882f82009-06-10 13:36:04 -07008368
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008369 case COMPUTE_AND_SEND_NEW_CONFIGURATION: {
Dianne Hackborncfaef692009-06-15 14:24:44 -07008370 if (updateOrientationFromAppTokensUnchecked(null, null) != null) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008371 sendNewConfiguration();
8372 }
8373 break;
8374 }
Romain Guy06882f82009-06-10 13:36:04 -07008375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008376 }
8377 }
8378 }
8379
8380 // -------------------------------------------------------------
8381 // IWindowManager API
8382 // -------------------------------------------------------------
8383
8384 public IWindowSession openSession(IInputMethodClient client,
8385 IInputContext inputContext) {
8386 if (client == null) throw new IllegalArgumentException("null client");
8387 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
8388 return new Session(client, inputContext);
8389 }
8390
8391 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8392 synchronized (mWindowMap) {
8393 // The focus for the client is the window immediately below
8394 // where we would place the input method window.
8395 int idx = findDesiredInputMethodWindowIndexLocked(false);
8396 WindowState imFocus;
8397 if (idx > 0) {
8398 imFocus = (WindowState)mWindows.get(idx-1);
8399 if (imFocus != null) {
8400 if (imFocus.mSession.mClient != null &&
8401 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8402 return true;
8403 }
8404 }
8405 }
8406 }
8407 return false;
8408 }
Romain Guy06882f82009-06-10 13:36:04 -07008409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008410 // -------------------------------------------------------------
8411 // Internals
8412 // -------------------------------------------------------------
8413
8414 final WindowState windowForClientLocked(Session session, IWindow client) {
8415 return windowForClientLocked(session, client.asBinder());
8416 }
Romain Guy06882f82009-06-10 13:36:04 -07008417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008418 final WindowState windowForClientLocked(Session session, IBinder client) {
8419 WindowState win = mWindowMap.get(client);
8420 if (localLOGV) Log.v(
8421 TAG, "Looking up client " + client + ": " + win);
8422 if (win == null) {
8423 RuntimeException ex = new RuntimeException();
8424 Log.w(TAG, "Requested window " + client + " does not exist", ex);
8425 return null;
8426 }
8427 if (session != null && win.mSession != session) {
8428 RuntimeException ex = new RuntimeException();
8429 Log.w(TAG, "Requested window " + client + " is in session " +
8430 win.mSession + ", not " + session, ex);
8431 return null;
8432 }
8433
8434 return win;
8435 }
8436
8437 private final void assignLayersLocked() {
8438 int N = mWindows.size();
8439 int curBaseLayer = 0;
8440 int curLayer = 0;
8441 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008443 for (i=0; i<N; i++) {
8444 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008445 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8446 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008447 curLayer += WINDOW_LAYER_MULTIPLIER;
8448 w.mLayer = curLayer;
8449 } else {
8450 curBaseLayer = curLayer = w.mBaseLayer;
8451 w.mLayer = curLayer;
8452 }
8453 if (w.mTargetAppToken != null) {
8454 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8455 } else if (w.mAppToken != null) {
8456 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8457 } else {
8458 w.mAnimLayer = w.mLayer;
8459 }
8460 if (w.mIsImWindow) {
8461 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008462 } else if (w.mIsWallpaper) {
8463 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008464 }
8465 if (DEBUG_LAYERS) Log.v(TAG, "Assign layer " + w + ": "
8466 + w.mAnimLayer);
8467 //System.out.println(
8468 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8469 }
8470 }
8471
8472 private boolean mInLayout = false;
8473 private final void performLayoutAndPlaceSurfacesLocked() {
8474 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008475 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008476 throw new RuntimeException("Recursive call!");
8477 }
8478 Log.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
8479 return;
8480 }
8481
8482 boolean recoveringMemory = false;
8483 if (mForceRemoves != null) {
8484 recoveringMemory = true;
8485 // Wait a little it for things to settle down, and off we go.
8486 for (int i=0; i<mForceRemoves.size(); i++) {
8487 WindowState ws = mForceRemoves.get(i);
8488 Log.i(TAG, "Force removing: " + ws);
8489 removeWindowInnerLocked(ws.mSession, ws);
8490 }
8491 mForceRemoves = null;
8492 Log.w(TAG, "Due to memory failure, waiting a bit for next layout");
8493 Object tmp = new Object();
8494 synchronized (tmp) {
8495 try {
8496 tmp.wait(250);
8497 } catch (InterruptedException e) {
8498 }
8499 }
8500 }
Romain Guy06882f82009-06-10 13:36:04 -07008501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008502 mInLayout = true;
8503 try {
8504 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008506 int i = mPendingRemove.size()-1;
8507 if (i >= 0) {
8508 while (i >= 0) {
8509 WindowState w = mPendingRemove.get(i);
8510 removeWindowInnerLocked(w.mSession, w);
8511 i--;
8512 }
8513 mPendingRemove.clear();
8514
8515 mInLayout = false;
8516 assignLayersLocked();
8517 mLayoutNeeded = true;
8518 performLayoutAndPlaceSurfacesLocked();
8519
8520 } else {
8521 mInLayout = false;
8522 if (mLayoutNeeded) {
8523 requestAnimationLocked(0);
8524 }
8525 }
8526 } catch (RuntimeException e) {
8527 mInLayout = false;
8528 Log.e(TAG, "Unhandled exception while layout out windows", e);
8529 }
8530 }
8531
8532 private final void performLayoutLockedInner() {
8533 final int dw = mDisplay.getWidth();
8534 final int dh = mDisplay.getHeight();
8535
8536 final int N = mWindows.size();
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008537 int repeats = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008538 int i;
8539
8540 // FIRST LOOP: Perform a layout, if needed.
Romain Guy06882f82009-06-10 13:36:04 -07008541
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008542 while (mLayoutNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008543 mPolicy.beginLayoutLw(dw, dh);
8544
8545 // First perform layout of any root windows (not attached
8546 // to another window).
8547 int topAttached = -1;
8548 for (i = N-1; i >= 0; i--) {
8549 WindowState win = (WindowState) mWindows.get(i);
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008550
8551 // Don't do layout of a window if it is not visible, or
8552 // soon won't be visible, to avoid wasting time and funky
8553 // changes while a window is animating away.
8554 final AppWindowToken atoken = win.mAppToken;
8555 final boolean gone = win.mViewVisibility == View.GONE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008556 || !win.mRelayoutCalled
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008557 || win.mRootToken.hidden
8558 || (atoken != null && atoken.hiddenRequested)
8559 || !win.mPolicyVisibility
8560 || win.mAttachedHidden
8561 || win.mExiting || win.mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008562
8563 // If this view is GONE, then skip it -- keep the current
8564 // frame, and let the caller know so they can ignore it
8565 // if they want. (We do the normal layout for INVISIBLE
8566 // windows, since that means "perform layout as normal,
8567 // just don't display").
8568 if (!gone || !win.mHaveFrame) {
8569 if (!win.mLayoutAttached) {
8570 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8571 } else {
8572 if (topAttached < 0) topAttached = i;
8573 }
8574 }
8575 }
Romain Guy06882f82009-06-10 13:36:04 -07008576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008577 // Now perform layout of attached windows, which usually
8578 // depend on the position of the window they are attached to.
8579 // XXX does not deal with windows that are attached to windows
8580 // that are themselves attached.
8581 for (i = topAttached; i >= 0; i--) {
8582 WindowState win = (WindowState) mWindows.get(i);
8583
8584 // If this view is GONE, then skip it -- keep the current
8585 // frame, and let the caller know so they can ignore it
8586 // if they want. (We do the normal layout for INVISIBLE
8587 // windows, since that means "perform layout as normal,
8588 // just don't display").
8589 if (win.mLayoutAttached) {
8590 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8591 || !win.mHaveFrame) {
8592 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8593 }
8594 }
8595 }
8596
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008597 if (!mPolicy.finishLayoutLw()) {
8598 mLayoutNeeded = false;
8599 } else if (repeats > 2) {
8600 Log.w(TAG, "Layout repeat aborted after too many iterations");
8601 mLayoutNeeded = false;
8602 } else {
8603 repeats++;
8604 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008605 }
8606 }
Romain Guy06882f82009-06-10 13:36:04 -07008607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008608 private final void performLayoutAndPlaceSurfacesLockedInner(
8609 boolean recoveringMemory) {
8610 final long currentTime = SystemClock.uptimeMillis();
8611 final int dw = mDisplay.getWidth();
8612 final int dh = mDisplay.getHeight();
8613
8614 final int N = mWindows.size();
8615 int i;
8616
8617 // FIRST LOOP: Perform a layout, if needed.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008618 performLayoutLockedInner();
Romain Guy06882f82009-06-10 13:36:04 -07008619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008620 if (mFxSession == null) {
8621 mFxSession = new SurfaceSession();
8622 }
Romain Guy06882f82009-06-10 13:36:04 -07008623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008624 if (SHOW_TRANSACTIONS) Log.i(TAG, ">>> OPEN TRANSACTION");
8625
8626 // Initialize state of exiting tokens.
8627 for (i=mExitingTokens.size()-1; i>=0; i--) {
8628 mExitingTokens.get(i).hasVisible = false;
8629 }
8630
8631 // Initialize state of exiting applications.
8632 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
8633 mExitingAppTokens.get(i).hasVisible = false;
8634 }
8635
8636 // SECOND LOOP: Execute animations and update visibility of windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008637 boolean orientationChangeComplete = true;
8638 Session holdScreen = null;
8639 float screenBrightness = -1;
8640 boolean focusDisplayed = false;
8641 boolean animating = false;
8642
8643 Surface.openTransaction();
8644 try {
8645 boolean restart;
8646
8647 do {
8648 final int transactionSequence = ++mTransactionSequence;
8649
8650 // Update animations of all applications, including those
8651 // associated with exiting/removed apps
8652 boolean tokensAnimating = false;
8653 final int NAT = mAppTokens.size();
8654 for (i=0; i<NAT; i++) {
8655 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8656 tokensAnimating = true;
8657 }
8658 }
8659 final int NEAT = mExitingAppTokens.size();
8660 for (i=0; i<NEAT; i++) {
8661 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8662 tokensAnimating = true;
8663 }
8664 }
8665
8666 animating = tokensAnimating;
8667 restart = false;
8668
8669 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008670 boolean wallpaperMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008671
8672 mPolicy.beginAnimationLw(dw, dh);
8673
8674 for (i=N-1; i>=0; i--) {
8675 WindowState w = (WindowState)mWindows.get(i);
8676
8677 final WindowManager.LayoutParams attrs = w.mAttrs;
8678
8679 if (w.mSurface != null) {
8680 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008681 if (w.commitFinishDrawingLocked(currentTime)) {
8682 if ((w.mAttrs.flags
8683 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8684 wallpaperMayChange = true;
8685 }
8686 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008687 if (w.stepAnimationLocked(currentTime, dw, dh)) {
8688 animating = true;
8689 //w.dump(" ");
8690 }
8691
8692 mPolicy.animatingWindowLw(w, attrs);
8693 }
8694
8695 final AppWindowToken atoken = w.mAppToken;
8696 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
8697 if (atoken.lastTransactionSequence != transactionSequence) {
8698 atoken.lastTransactionSequence = transactionSequence;
8699 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
8700 atoken.startingDisplayed = false;
8701 }
8702 if ((w.isOnScreen() || w.mAttrs.type
8703 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
8704 && !w.mExiting && !w.mDestroying) {
8705 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
8706 Log.v(TAG, "Eval win " + w + ": isDisplayed="
8707 + w.isDisplayedLw()
8708 + ", isAnimating=" + w.isAnimating());
8709 if (!w.isDisplayedLw()) {
8710 Log.v(TAG, "Not displayed: s=" + w.mSurface
8711 + " pv=" + w.mPolicyVisibility
8712 + " dp=" + w.mDrawPending
8713 + " cdp=" + w.mCommitDrawPending
8714 + " ah=" + w.mAttachedHidden
8715 + " th=" + atoken.hiddenRequested
8716 + " a=" + w.mAnimating);
8717 }
8718 }
8719 if (w != atoken.startingWindow) {
8720 if (!atoken.freezingScreen || !w.mAppFreezing) {
8721 atoken.numInterestingWindows++;
8722 if (w.isDisplayedLw()) {
8723 atoken.numDrawnWindows++;
8724 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Log.v(TAG,
8725 "tokenMayBeDrawn: " + atoken
8726 + " freezingScreen=" + atoken.freezingScreen
8727 + " mAppFreezing=" + w.mAppFreezing);
8728 tokenMayBeDrawn = true;
8729 }
8730 }
8731 } else if (w.isDisplayedLw()) {
8732 atoken.startingDisplayed = true;
8733 }
8734 }
8735 } else if (w.mReadyToShow) {
8736 w.performShowLocked();
8737 }
8738 }
8739
8740 if (mPolicy.finishAnimationLw()) {
8741 restart = true;
8742 }
8743
8744 if (tokenMayBeDrawn) {
8745 // See if any windows have been drawn, so they (and others
8746 // associated with them) can now be shown.
8747 final int NT = mTokenList.size();
8748 for (i=0; i<NT; i++) {
8749 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
8750 if (wtoken == null) {
8751 continue;
8752 }
8753 if (wtoken.freezingScreen) {
8754 int numInteresting = wtoken.numInterestingWindows;
8755 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
8756 if (DEBUG_VISIBILITY) Log.v(TAG,
8757 "allDrawn: " + wtoken
8758 + " interesting=" + numInteresting
8759 + " drawn=" + wtoken.numDrawnWindows);
8760 wtoken.showAllWindowsLocked();
8761 unsetAppFreezingScreenLocked(wtoken, false, true);
8762 orientationChangeComplete = true;
8763 }
8764 } else if (!wtoken.allDrawn) {
8765 int numInteresting = wtoken.numInterestingWindows;
8766 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
8767 if (DEBUG_VISIBILITY) Log.v(TAG,
8768 "allDrawn: " + wtoken
8769 + " interesting=" + numInteresting
8770 + " drawn=" + wtoken.numDrawnWindows);
8771 wtoken.allDrawn = true;
8772 restart = true;
8773
8774 // We can now show all of the drawn windows!
8775 if (!mOpeningApps.contains(wtoken)) {
8776 wtoken.showAllWindowsLocked();
8777 }
8778 }
8779 }
8780 }
8781 }
8782
8783 // If we are ready to perform an app transition, check through
8784 // all of the app tokens to be shown and see if they are ready
8785 // to go.
8786 if (mAppTransitionReady) {
8787 int NN = mOpeningApps.size();
8788 boolean goodToGo = true;
8789 if (DEBUG_APP_TRANSITIONS) Log.v(TAG,
8790 "Checking " + NN + " opening apps (frozen="
8791 + mDisplayFrozen + " timeout="
8792 + mAppTransitionTimeout + ")...");
8793 if (!mDisplayFrozen && !mAppTransitionTimeout) {
8794 // If the display isn't frozen, wait to do anything until
8795 // all of the apps are ready. Otherwise just go because
8796 // we'll unfreeze the display when everyone is ready.
8797 for (i=0; i<NN && goodToGo; i++) {
8798 AppWindowToken wtoken = mOpeningApps.get(i);
8799 if (DEBUG_APP_TRANSITIONS) Log.v(TAG,
8800 "Check opening app" + wtoken + ": allDrawn="
8801 + wtoken.allDrawn + " startingDisplayed="
8802 + wtoken.startingDisplayed);
8803 if (!wtoken.allDrawn && !wtoken.startingDisplayed
8804 && !wtoken.startingMoved) {
8805 goodToGo = false;
8806 }
8807 }
8808 }
8809 if (goodToGo) {
8810 if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "**** GOOD TO GO");
8811 int transit = mNextAppTransition;
8812 if (mSkipAppTransitionAnimation) {
8813 transit = WindowManagerPolicy.TRANSIT_NONE;
8814 }
8815 mNextAppTransition = WindowManagerPolicy.TRANSIT_NONE;
8816 mAppTransitionReady = false;
8817 mAppTransitionTimeout = false;
8818 mStartingIconInTransition = false;
8819 mSkipAppTransitionAnimation = false;
8820
8821 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
8822
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008823 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008824 wallpaperMayChange = false;
8825
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008826 if (DEBUG_APP_TRANSITIONS) Log.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008827 "New wallpaper target=" + mWallpaperTarget
8828 + ", lower target=" + mLowerWallpaperTarget
8829 + ", upper target=" + mUpperWallpaperTarget);
8830 if (mLowerWallpaperTarget != null) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008831 // Need to determine if both the closing and
8832 // opening app token sets are wallpaper targets,
8833 // in which case special animations are needed
8834 // (since the wallpaper needs to stay static
8835 // behind them).
8836 int found = 0;
8837 NN = mOpeningApps.size();
8838 for (i=0; i<NN; i++) {
8839 AppWindowToken wtoken = mOpeningApps.get(i);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008840 if (mLowerWallpaperTarget.mAppToken == wtoken) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008841 found |= 1;
8842 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008843 if (mUpperWallpaperTarget.mAppToken == wtoken) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008844 found |= 1;
8845 }
8846 }
8847 NN = mClosingApps.size();
8848 for (i=0; i<NN; i++) {
8849 AppWindowToken wtoken = mClosingApps.get(i);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008850 if (mLowerWallpaperTarget.mAppToken == wtoken) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008851 found |= 2;
8852 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008853 if (mUpperWallpaperTarget.mAppToken == wtoken) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008854 found |= 2;
8855 }
8856 }
8857
8858 if (found == 3) {
8859 if (DEBUG_APP_TRANSITIONS) Log.v(TAG,
8860 "Wallpaper animation!");
8861 switch (transit) {
8862 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
8863 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
8864 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
8865 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_ACTIVITY_OPEN;
8866 break;
8867 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
8868 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
8869 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
8870 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_ACTIVITY_CLOSE;
8871 break;
8872 }
8873 if (DEBUG_APP_TRANSITIONS) Log.v(TAG,
8874 "New transit: " + transit);
8875 }
8876 }
8877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008878 // We need to figure out which animation to use...
8879 WindowManager.LayoutParams lp = findAnimations(mAppTokens,
8880 mOpeningApps, mClosingApps);
8881
8882 NN = mOpeningApps.size();
8883 for (i=0; i<NN; i++) {
8884 AppWindowToken wtoken = mOpeningApps.get(i);
8885 if (DEBUG_APP_TRANSITIONS) Log.v(TAG,
8886 "Now opening app" + wtoken);
8887 wtoken.reportedVisible = false;
8888 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008889 wtoken.animation = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008890 setTokenVisibilityLocked(wtoken, lp, true, transit, false);
8891 wtoken.updateReportedVisibilityLocked();
8892 wtoken.showAllWindowsLocked();
8893 }
8894 NN = mClosingApps.size();
8895 for (i=0; i<NN; i++) {
8896 AppWindowToken wtoken = mClosingApps.get(i);
8897 if (DEBUG_APP_TRANSITIONS) Log.v(TAG,
8898 "Now closing app" + wtoken);
8899 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008900 wtoken.animation = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008901 setTokenVisibilityLocked(wtoken, lp, false, transit, false);
8902 wtoken.updateReportedVisibilityLocked();
8903 // Force the allDrawn flag, because we want to start
8904 // this guy's animations regardless of whether it's
8905 // gotten drawn.
8906 wtoken.allDrawn = true;
8907 }
8908
8909 mOpeningApps.clear();
8910 mClosingApps.clear();
8911
8912 // This has changed the visibility of windows, so perform
8913 // a new layout to get them all up-to-date.
8914 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07008915 if (!moveInputMethodWindowsIfNeededLocked(true)) {
8916 assignLayersLocked();
8917 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008918 performLayoutLockedInner();
8919 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
8920
8921 restart = true;
8922 }
8923 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008924
8925 if (wallpaperMayChange) {
8926 if (adjustWallpaperWindowsLocked()) {
8927 assignLayersLocked();
8928 }
8929 }
8930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008931 } while (restart);
8932
8933 // THIRD LOOP: Update the surfaces of all windows.
8934
8935 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
8936
8937 boolean obscured = false;
8938 boolean blurring = false;
8939 boolean dimming = false;
8940 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07008941 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008942 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008943
8944 for (i=N-1; i>=0; i--) {
8945 WindowState w = (WindowState)mWindows.get(i);
8946
8947 boolean displayed = false;
8948 final WindowManager.LayoutParams attrs = w.mAttrs;
8949 final int attrFlags = attrs.flags;
8950
8951 if (w.mSurface != null) {
8952 w.computeShownFrameLocked();
8953 if (localLOGV) Log.v(
8954 TAG, "Placing surface #" + i + " " + w.mSurface
8955 + ": new=" + w.mShownFrame + ", old="
8956 + w.mLastShownFrame);
8957
8958 boolean resize;
8959 int width, height;
8960 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
8961 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
8962 w.mLastRequestedHeight != w.mRequestedHeight;
8963 // for a scaled surface, we just want to use
8964 // the requested size.
8965 width = w.mRequestedWidth;
8966 height = w.mRequestedHeight;
8967 w.mLastRequestedWidth = width;
8968 w.mLastRequestedHeight = height;
8969 w.mLastShownFrame.set(w.mShownFrame);
8970 try {
8971 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
8972 } catch (RuntimeException e) {
8973 Log.w(TAG, "Error positioning surface in " + w, e);
8974 if (!recoveringMemory) {
8975 reclaimSomeSurfaceMemoryLocked(w, "position");
8976 }
8977 }
8978 } else {
8979 resize = !w.mLastShownFrame.equals(w.mShownFrame);
8980 width = w.mShownFrame.width();
8981 height = w.mShownFrame.height();
8982 w.mLastShownFrame.set(w.mShownFrame);
8983 if (resize) {
8984 if (SHOW_TRANSACTIONS) Log.i(
8985 TAG, " SURFACE " + w.mSurface + ": ("
8986 + w.mShownFrame.left + ","
8987 + w.mShownFrame.top + ") ("
8988 + w.mShownFrame.width() + "x"
8989 + w.mShownFrame.height() + ")");
8990 }
8991 }
8992
8993 if (resize) {
8994 if (width < 1) width = 1;
8995 if (height < 1) height = 1;
8996 if (w.mSurface != null) {
8997 try {
8998 w.mSurface.setSize(width, height);
8999 w.mSurface.setPosition(w.mShownFrame.left,
9000 w.mShownFrame.top);
9001 } catch (RuntimeException e) {
9002 // If something goes wrong with the surface (such
9003 // as running out of memory), don't take down the
9004 // entire system.
9005 Log.e(TAG, "Failure updating surface of " + w
9006 + "size=(" + width + "x" + height
9007 + "), pos=(" + w.mShownFrame.left
9008 + "," + w.mShownFrame.top + ")", e);
9009 if (!recoveringMemory) {
9010 reclaimSomeSurfaceMemoryLocked(w, "size");
9011 }
9012 }
9013 }
9014 }
9015 if (!w.mAppFreezing) {
9016 w.mContentInsetsChanged =
9017 !w.mLastContentInsets.equals(w.mContentInsets);
9018 w.mVisibleInsetsChanged =
9019 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Romain Guy06882f82009-06-10 13:36:04 -07009020 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009021 || w.mContentInsetsChanged
9022 || w.mVisibleInsetsChanged) {
9023 w.mLastFrame.set(w.mFrame);
9024 w.mLastContentInsets.set(w.mContentInsets);
9025 w.mLastVisibleInsets.set(w.mVisibleInsets);
9026 // If the orientation is changing, then we need to
9027 // hold off on unfreezing the display until this
9028 // window has been redrawn; to do that, we need
9029 // to go through the process of getting informed
9030 // by the application when it has finished drawing.
9031 if (w.mOrientationChanging) {
9032 if (DEBUG_ORIENTATION) Log.v(TAG,
9033 "Orientation start waiting for draw in "
9034 + w + ", surface " + w.mSurface);
9035 w.mDrawPending = true;
9036 w.mCommitDrawPending = false;
9037 w.mReadyToShow = false;
9038 if (w.mAppToken != null) {
9039 w.mAppToken.allDrawn = false;
9040 }
9041 }
Romain Guy06882f82009-06-10 13:36:04 -07009042 if (DEBUG_ORIENTATION) Log.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009043 "Resizing window " + w + " to " + w.mFrame);
9044 mResizingWindows.add(w);
9045 } else if (w.mOrientationChanging) {
9046 if (!w.mDrawPending && !w.mCommitDrawPending) {
9047 if (DEBUG_ORIENTATION) Log.v(TAG,
9048 "Orientation not waiting for draw in "
9049 + w + ", surface " + w.mSurface);
9050 w.mOrientationChanging = false;
9051 }
9052 }
9053 }
9054
9055 if (w.mAttachedHidden) {
9056 if (!w.mLastHidden) {
9057 //dump();
9058 w.mLastHidden = true;
9059 if (SHOW_TRANSACTIONS) Log.i(
9060 TAG, " SURFACE " + w.mSurface + ": HIDE (performLayout-attached)");
9061 if (w.mSurface != null) {
9062 try {
9063 w.mSurface.hide();
9064 } catch (RuntimeException e) {
9065 Log.w(TAG, "Exception hiding surface in " + w);
9066 }
9067 }
9068 mKeyWaiter.releasePendingPointerLocked(w.mSession);
9069 }
9070 // If we are waiting for this window to handle an
9071 // orientation change, well, it is hidden, so
9072 // doesn't really matter. Note that this does
9073 // introduce a potential glitch if the window
9074 // becomes unhidden before it has drawn for the
9075 // new orientation.
9076 if (w.mOrientationChanging) {
9077 w.mOrientationChanging = false;
9078 if (DEBUG_ORIENTATION) Log.v(TAG,
9079 "Orientation change skips hidden " + w);
9080 }
9081 } else if (!w.isReadyForDisplay()) {
9082 if (!w.mLastHidden) {
9083 //dump();
9084 w.mLastHidden = true;
9085 if (SHOW_TRANSACTIONS) Log.i(
9086 TAG, " SURFACE " + w.mSurface + ": HIDE (performLayout-ready)");
9087 if (w.mSurface != null) {
9088 try {
9089 w.mSurface.hide();
9090 } catch (RuntimeException e) {
9091 Log.w(TAG, "Exception exception hiding surface in " + w);
9092 }
9093 }
9094 mKeyWaiter.releasePendingPointerLocked(w.mSession);
9095 }
9096 // If we are waiting for this window to handle an
9097 // orientation change, well, it is hidden, so
9098 // doesn't really matter. Note that this does
9099 // introduce a potential glitch if the window
9100 // becomes unhidden before it has drawn for the
9101 // new orientation.
9102 if (w.mOrientationChanging) {
9103 w.mOrientationChanging = false;
9104 if (DEBUG_ORIENTATION) Log.v(TAG,
9105 "Orientation change skips hidden " + w);
9106 }
9107 } else if (w.mLastLayer != w.mAnimLayer
9108 || w.mLastAlpha != w.mShownAlpha
9109 || w.mLastDsDx != w.mDsDx
9110 || w.mLastDtDx != w.mDtDx
9111 || w.mLastDsDy != w.mDsDy
9112 || w.mLastDtDy != w.mDtDy
9113 || w.mLastHScale != w.mHScale
9114 || w.mLastVScale != w.mVScale
9115 || w.mLastHidden) {
9116 displayed = true;
9117 w.mLastAlpha = w.mShownAlpha;
9118 w.mLastLayer = w.mAnimLayer;
9119 w.mLastDsDx = w.mDsDx;
9120 w.mLastDtDx = w.mDtDx;
9121 w.mLastDsDy = w.mDsDy;
9122 w.mLastDtDy = w.mDtDy;
9123 w.mLastHScale = w.mHScale;
9124 w.mLastVScale = w.mVScale;
9125 if (SHOW_TRANSACTIONS) Log.i(
9126 TAG, " SURFACE " + w.mSurface + ": alpha="
9127 + w.mShownAlpha + " layer=" + w.mAnimLayer);
9128 if (w.mSurface != null) {
9129 try {
9130 w.mSurface.setAlpha(w.mShownAlpha);
9131 w.mSurface.setLayer(w.mAnimLayer);
9132 w.mSurface.setMatrix(
9133 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9134 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9135 } catch (RuntimeException e) {
9136 Log.w(TAG, "Error updating surface in " + w, e);
9137 if (!recoveringMemory) {
9138 reclaimSomeSurfaceMemoryLocked(w, "update");
9139 }
9140 }
9141 }
9142
9143 if (w.mLastHidden && !w.mDrawPending
9144 && !w.mCommitDrawPending
9145 && !w.mReadyToShow) {
9146 if (SHOW_TRANSACTIONS) Log.i(
9147 TAG, " SURFACE " + w.mSurface + ": SHOW (performLayout)");
9148 if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + w
9149 + " during relayout");
9150 if (showSurfaceRobustlyLocked(w)) {
9151 w.mHasDrawn = true;
9152 w.mLastHidden = false;
9153 } else {
9154 w.mOrientationChanging = false;
9155 }
9156 }
9157 if (w.mSurface != null) {
9158 w.mToken.hasVisible = true;
9159 }
9160 } else {
9161 displayed = true;
9162 }
9163
9164 if (displayed) {
9165 if (!covered) {
9166 if (attrs.width == LayoutParams.FILL_PARENT
9167 && attrs.height == LayoutParams.FILL_PARENT) {
9168 covered = true;
9169 }
9170 }
9171 if (w.mOrientationChanging) {
9172 if (w.mDrawPending || w.mCommitDrawPending) {
9173 orientationChangeComplete = false;
9174 if (DEBUG_ORIENTATION) Log.v(TAG,
9175 "Orientation continue waiting for draw in " + w);
9176 } else {
9177 w.mOrientationChanging = false;
9178 if (DEBUG_ORIENTATION) Log.v(TAG,
9179 "Orientation change complete in " + w);
9180 }
9181 }
9182 w.mToken.hasVisible = true;
9183 }
9184 } else if (w.mOrientationChanging) {
9185 if (DEBUG_ORIENTATION) Log.v(TAG,
9186 "Orientation change skips hidden " + w);
9187 w.mOrientationChanging = false;
9188 }
9189
9190 final boolean canBeSeen = w.isDisplayedLw();
9191
9192 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9193 focusDisplayed = true;
9194 }
9195
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009196 final boolean obscuredChanged = w.mObscured != obscured;
9197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009198 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009199 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009200 if (w.mSurface != null) {
9201 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9202 holdScreen = w.mSession;
9203 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009204 if (!syswin && w.mAttrs.screenBrightness >= 0
9205 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009206 screenBrightness = w.mAttrs.screenBrightness;
9207 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009208 if (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9209 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9210 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR) {
9211 syswin = true;
9212 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009213 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009214
9215 boolean opaqueDrawn = w.isOpaqueDrawn();
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009216 if ((opaqueDrawn && w.isFullscreen(dw, dh))
9217 || attrs.type == TYPE_WALLPAPER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009218 // This window completely covers everything behind it,
9219 // so we want to leave all of them as unblurred (for
9220 // performance reasons).
9221 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009222 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
9223 if (SHOW_TRANSACTIONS) Log.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009224 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009225 obscured = true;
9226 if (mBackgroundFillerSurface == null) {
9227 try {
9228 mBackgroundFillerSurface = new Surface(mFxSession, 0,
9229 0, dw, dh,
9230 PixelFormat.OPAQUE,
9231 Surface.FX_SURFACE_NORMAL);
9232 } catch (Exception e) {
9233 Log.e(TAG, "Exception creating filler surface", e);
9234 }
9235 }
9236 try {
9237 mBackgroundFillerSurface.setPosition(0, 0);
9238 mBackgroundFillerSurface.setSize(dw, dh);
9239 // Using the same layer as Dim because they will never be shown at the
9240 // same time.
9241 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9242 mBackgroundFillerSurface.show();
9243 } catch (RuntimeException e) {
9244 Log.e(TAG, "Exception showing filler surface");
9245 }
9246 backgroundFillerShown = true;
9247 mBackgroundFillerShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009248 } else if (canBeSeen && !obscured &&
9249 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
9250 if (localLOGV) Log.v(TAG, "Win " + w
9251 + ": blurring=" + blurring
9252 + " obscured=" + obscured
9253 + " displayed=" + displayed);
9254 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9255 if (!dimming) {
9256 //Log.i(TAG, "DIM BEHIND: " + w);
9257 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009258 if (mDimAnimator == null) {
9259 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009260 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009261 mDimAnimator.show(dw, dh);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009262 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009263 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009264 }
9265 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9266 if (!blurring) {
9267 //Log.i(TAG, "BLUR BEHIND: " + w);
9268 blurring = true;
9269 mBlurShown = true;
9270 if (mBlurSurface == null) {
9271 if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR "
9272 + mBlurSurface + ": CREATE");
9273 try {
Romain Guy06882f82009-06-10 13:36:04 -07009274 mBlurSurface = new Surface(mFxSession, 0,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009275 -1, 16, 16,
9276 PixelFormat.OPAQUE,
9277 Surface.FX_SURFACE_BLUR);
9278 } catch (Exception e) {
9279 Log.e(TAG, "Exception creating Blur surface", e);
9280 }
9281 }
9282 if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR "
9283 + mBlurSurface + ": SHOW pos=(0,0) (" +
9284 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
9285 if (mBlurSurface != null) {
9286 mBlurSurface.setPosition(0, 0);
9287 mBlurSurface.setSize(dw, dh);
9288 try {
9289 mBlurSurface.show();
9290 } catch (RuntimeException e) {
9291 Log.w(TAG, "Failure showing blur surface", e);
9292 }
9293 }
9294 }
9295 mBlurSurface.setLayer(w.mAnimLayer-2);
9296 }
9297 }
9298 }
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009299
9300 if (obscuredChanged && mWallpaperTarget == w) {
9301 // This is the wallpaper target and its obscured state
9302 // changed... make sure the current wallaper's visibility
9303 // has been updated accordingly.
9304 updateWallpaperVisibilityLocked();
9305 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009306 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009307
9308 if (backgroundFillerShown == false && mBackgroundFillerShown) {
9309 mBackgroundFillerShown = false;
9310 if (SHOW_TRANSACTIONS) Log.d(TAG, "hiding background filler");
9311 try {
9312 mBackgroundFillerSurface.hide();
9313 } catch (RuntimeException e) {
9314 Log.e(TAG, "Exception hiding filler surface", e);
9315 }
9316 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009317
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009318 if (mDimAnimator != null && mDimAnimator.mDimShown) {
9319 animating |= mDimAnimator.updateSurface(dimming, currentTime, mDisplayFrozen);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009320 }
Romain Guy06882f82009-06-10 13:36:04 -07009321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009322 if (!blurring && mBlurShown) {
9323 if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " + mBlurSurface
9324 + ": HIDE");
9325 try {
9326 mBlurSurface.hide();
9327 } catch (IllegalArgumentException e) {
9328 Log.w(TAG, "Illegal argument exception hiding blur surface");
9329 }
9330 mBlurShown = false;
9331 }
9332
9333 if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION");
9334 } catch (RuntimeException e) {
9335 Log.e(TAG, "Unhandled exception in Window Manager", e);
9336 }
9337
9338 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07009339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009340 if (DEBUG_ORIENTATION && mDisplayFrozen) Log.v(TAG,
9341 "With display frozen, orientationChangeComplete="
9342 + orientationChangeComplete);
9343 if (orientationChangeComplete) {
9344 if (mWindowsFreezingScreen) {
9345 mWindowsFreezingScreen = false;
9346 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9347 }
9348 if (mAppsFreezingScreen == 0) {
9349 stopFreezingDisplayLocked();
9350 }
9351 }
Romain Guy06882f82009-06-10 13:36:04 -07009352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009353 i = mResizingWindows.size();
9354 if (i > 0) {
9355 do {
9356 i--;
9357 WindowState win = mResizingWindows.get(i);
9358 try {
9359 win.mClient.resized(win.mFrame.width(),
9360 win.mFrame.height(), win.mLastContentInsets,
9361 win.mLastVisibleInsets, win.mDrawPending);
9362 win.mContentInsetsChanged = false;
9363 win.mVisibleInsetsChanged = false;
9364 } catch (RemoteException e) {
9365 win.mOrientationChanging = false;
9366 }
9367 } while (i > 0);
9368 mResizingWindows.clear();
9369 }
Romain Guy06882f82009-06-10 13:36:04 -07009370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009371 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009372 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009373 i = mDestroySurface.size();
9374 if (i > 0) {
9375 do {
9376 i--;
9377 WindowState win = mDestroySurface.get(i);
9378 win.mDestroying = false;
9379 if (mInputMethodWindow == win) {
9380 mInputMethodWindow = null;
9381 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009382 if (win == mWallpaperTarget) {
9383 wallpaperDestroyed = true;
9384 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009385 win.destroySurfaceLocked();
9386 } while (i > 0);
9387 mDestroySurface.clear();
9388 }
9389
9390 // Time to remove any exiting tokens?
9391 for (i=mExitingTokens.size()-1; i>=0; i--) {
9392 WindowToken token = mExitingTokens.get(i);
9393 if (!token.hasVisible) {
9394 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009395 if (token.windowType == TYPE_WALLPAPER) {
9396 mWallpaperTokens.remove(token);
9397 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009398 }
9399 }
9400
9401 // Time to remove any exiting applications?
9402 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9403 AppWindowToken token = mExitingAppTokens.get(i);
9404 if (!token.hasVisible && !mClosingApps.contains(token)) {
9405 mAppTokens.remove(token);
9406 mExitingAppTokens.remove(i);
9407 }
9408 }
9409
9410 if (focusDisplayed) {
9411 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
9412 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009413 if (wallpaperDestroyed) {
9414 wallpaperDestroyed = adjustWallpaperWindowsLocked();
9415 }
9416 if (wallpaperDestroyed) {
9417 requestAnimationLocked(0);
9418 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009419 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
9420 }
9421 mQueue.setHoldScreenLocked(holdScreen != null);
9422 if (screenBrightness < 0 || screenBrightness > 1.0f) {
9423 mPowerManager.setScreenBrightnessOverride(-1);
9424 } else {
9425 mPowerManager.setScreenBrightnessOverride((int)
9426 (screenBrightness * Power.BRIGHTNESS_ON));
9427 }
9428 if (holdScreen != mHoldingScreenOn) {
9429 mHoldingScreenOn = holdScreen;
9430 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
9431 mH.sendMessage(m);
9432 }
9433 }
9434
9435 void requestAnimationLocked(long delay) {
9436 if (!mAnimationPending) {
9437 mAnimationPending = true;
9438 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
9439 }
9440 }
Romain Guy06882f82009-06-10 13:36:04 -07009441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009442 /**
9443 * Have the surface flinger show a surface, robustly dealing with
9444 * error conditions. In particular, if there is not enough memory
9445 * to show the surface, then we will try to get rid of other surfaces
9446 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07009447 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009448 * @return Returns true if the surface was successfully shown.
9449 */
9450 boolean showSurfaceRobustlyLocked(WindowState win) {
9451 try {
9452 if (win.mSurface != null) {
9453 win.mSurface.show();
9454 }
9455 return true;
9456 } catch (RuntimeException e) {
9457 Log.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
9458 }
Romain Guy06882f82009-06-10 13:36:04 -07009459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009460 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -07009461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009462 return false;
9463 }
Romain Guy06882f82009-06-10 13:36:04 -07009464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009465 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
9466 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -07009467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009468 EventLog.writeEvent(LOG_WM_NO_SURFACE_MEMORY, win.toString(),
9469 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07009470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009471 if (mForceRemoves == null) {
9472 mForceRemoves = new ArrayList<WindowState>();
9473 }
Romain Guy06882f82009-06-10 13:36:04 -07009474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009475 long callingIdentity = Binder.clearCallingIdentity();
9476 try {
9477 // There was some problem... first, do a sanity check of the
9478 // window list to make sure we haven't left any dangling surfaces
9479 // around.
9480 int N = mWindows.size();
9481 boolean leakedSurface = false;
9482 Log.i(TAG, "Out of memory for surface! Looking for leaks...");
9483 for (int i=0; i<N; i++) {
9484 WindowState ws = (WindowState)mWindows.get(i);
9485 if (ws.mSurface != null) {
9486 if (!mSessions.contains(ws.mSession)) {
9487 Log.w(TAG, "LEAKED SURFACE (session doesn't exist): "
9488 + ws + " surface=" + ws.mSurface
9489 + " token=" + win.mToken
9490 + " pid=" + ws.mSession.mPid
9491 + " uid=" + ws.mSession.mUid);
9492 ws.mSurface.clear();
9493 ws.mSurface = null;
9494 mForceRemoves.add(ws);
9495 i--;
9496 N--;
9497 leakedSurface = true;
9498 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
9499 Log.w(TAG, "LEAKED SURFACE (app token hidden): "
9500 + ws + " surface=" + ws.mSurface
9501 + " token=" + win.mAppToken);
9502 ws.mSurface.clear();
9503 ws.mSurface = null;
9504 leakedSurface = true;
9505 }
9506 }
9507 }
Romain Guy06882f82009-06-10 13:36:04 -07009508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009509 boolean killedApps = false;
9510 if (!leakedSurface) {
9511 Log.w(TAG, "No leaked surfaces; killing applicatons!");
9512 SparseIntArray pidCandidates = new SparseIntArray();
9513 for (int i=0; i<N; i++) {
9514 WindowState ws = (WindowState)mWindows.get(i);
9515 if (ws.mSurface != null) {
9516 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
9517 }
9518 }
9519 if (pidCandidates.size() > 0) {
9520 int[] pids = new int[pidCandidates.size()];
9521 for (int i=0; i<pids.length; i++) {
9522 pids[i] = pidCandidates.keyAt(i);
9523 }
9524 try {
9525 if (mActivityManager.killPidsForMemory(pids)) {
9526 killedApps = true;
9527 }
9528 } catch (RemoteException e) {
9529 }
9530 }
9531 }
Romain Guy06882f82009-06-10 13:36:04 -07009532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009533 if (leakedSurface || killedApps) {
9534 // We managed to reclaim some memory, so get rid of the trouble
9535 // surface and ask the app to request another one.
9536 Log.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
9537 if (surface != null) {
9538 surface.clear();
9539 win.mSurface = null;
9540 }
Romain Guy06882f82009-06-10 13:36:04 -07009541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009542 try {
9543 win.mClient.dispatchGetNewSurface();
9544 } catch (RemoteException e) {
9545 }
9546 }
9547 } finally {
9548 Binder.restoreCallingIdentity(callingIdentity);
9549 }
9550 }
Romain Guy06882f82009-06-10 13:36:04 -07009551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009552 private boolean updateFocusedWindowLocked(int mode) {
9553 WindowState newFocus = computeFocusedWindowLocked();
9554 if (mCurrentFocus != newFocus) {
9555 // This check makes sure that we don't already have the focus
9556 // change message pending.
9557 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
9558 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
9559 if (localLOGV) Log.v(
9560 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
9561 final WindowState oldFocus = mCurrentFocus;
9562 mCurrentFocus = newFocus;
9563 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07009564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009565 final WindowState imWindow = mInputMethodWindow;
9566 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009567 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009568 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009569 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
9570 mLayoutNeeded = true;
9571 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009572 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
9573 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009574 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
9575 // Client will do the layout, but we need to assign layers
9576 // for handleNewWindowLocked() below.
9577 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009578 }
9579 }
Romain Guy06882f82009-06-10 13:36:04 -07009580
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009581 if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
9582 mKeyWaiter.handleNewWindowLocked(newFocus);
9583 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009584 return true;
9585 }
9586 return false;
9587 }
9588
9589 private WindowState computeFocusedWindowLocked() {
9590 WindowState result = null;
9591 WindowState win;
9592
9593 int i = mWindows.size() - 1;
9594 int nextAppIndex = mAppTokens.size()-1;
9595 WindowToken nextApp = nextAppIndex >= 0
9596 ? mAppTokens.get(nextAppIndex) : null;
9597
9598 while (i >= 0) {
9599 win = (WindowState)mWindows.get(i);
9600
9601 if (localLOGV || DEBUG_FOCUS) Log.v(
9602 TAG, "Looking for focus: " + i
9603 + " = " + win
9604 + ", flags=" + win.mAttrs.flags
9605 + ", canReceive=" + win.canReceiveKeys());
9606
9607 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07009608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009609 // If this window's application has been removed, just skip it.
9610 if (thisApp != null && thisApp.removed) {
9611 i--;
9612 continue;
9613 }
Romain Guy06882f82009-06-10 13:36:04 -07009614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009615 // If there is a focused app, don't allow focus to go to any
9616 // windows below it. If this is an application window, step
9617 // through the app tokens until we find its app.
9618 if (thisApp != null && nextApp != null && thisApp != nextApp
9619 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
9620 int origAppIndex = nextAppIndex;
9621 while (nextAppIndex > 0) {
9622 if (nextApp == mFocusedApp) {
9623 // Whoops, we are below the focused app... no focus
9624 // for you!
9625 if (localLOGV || DEBUG_FOCUS) Log.v(
9626 TAG, "Reached focused app: " + mFocusedApp);
9627 return null;
9628 }
9629 nextAppIndex--;
9630 nextApp = mAppTokens.get(nextAppIndex);
9631 if (nextApp == thisApp) {
9632 break;
9633 }
9634 }
9635 if (thisApp != nextApp) {
9636 // Uh oh, the app token doesn't exist! This shouldn't
9637 // happen, but if it does we can get totally hosed...
9638 // so restart at the original app.
9639 nextAppIndex = origAppIndex;
9640 nextApp = mAppTokens.get(nextAppIndex);
9641 }
9642 }
9643
9644 // Dispatch to this window if it is wants key events.
9645 if (win.canReceiveKeys()) {
9646 if (DEBUG_FOCUS) Log.v(
9647 TAG, "Found focus @ " + i + " = " + win);
9648 result = win;
9649 break;
9650 }
9651
9652 i--;
9653 }
9654
9655 return result;
9656 }
9657
9658 private void startFreezingDisplayLocked() {
9659 if (mDisplayFrozen) {
Chris Tate2ad63a92009-03-25 17:36:48 -07009660 // Freezing the display also suspends key event delivery, to
9661 // keep events from going astray while the display is reconfigured.
9662 // If someone has changed orientation again while the screen is
9663 // still frozen, the events will continue to be blocked while the
9664 // successive orientation change is processed. To prevent spurious
9665 // ANRs, we reset the event dispatch timeout in this case.
9666 synchronized (mKeyWaiter) {
9667 mKeyWaiter.mWasFrozen = true;
9668 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009669 return;
9670 }
Romain Guy06882f82009-06-10 13:36:04 -07009671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009672 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -07009673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009674 long now = SystemClock.uptimeMillis();
9675 //Log.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
9676 if (mFreezeGcPending != 0) {
9677 if (now > (mFreezeGcPending+1000)) {
9678 //Log.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
9679 mH.removeMessages(H.FORCE_GC);
9680 Runtime.getRuntime().gc();
9681 mFreezeGcPending = now;
9682 }
9683 } else {
9684 mFreezeGcPending = now;
9685 }
Romain Guy06882f82009-06-10 13:36:04 -07009686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009687 mDisplayFrozen = true;
9688 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) {
9689 mNextAppTransition = WindowManagerPolicy.TRANSIT_NONE;
9690 mAppTransitionReady = true;
9691 }
Romain Guy06882f82009-06-10 13:36:04 -07009692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009693 if (PROFILE_ORIENTATION) {
9694 File file = new File("/data/system/frozen");
9695 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
9696 }
9697 Surface.freezeDisplay(0);
9698 }
Romain Guy06882f82009-06-10 13:36:04 -07009699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009700 private void stopFreezingDisplayLocked() {
9701 if (!mDisplayFrozen) {
9702 return;
9703 }
Romain Guy06882f82009-06-10 13:36:04 -07009704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009705 mDisplayFrozen = false;
9706 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
9707 if (PROFILE_ORIENTATION) {
9708 Debug.stopMethodTracing();
9709 }
9710 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -07009711
Chris Tate2ad63a92009-03-25 17:36:48 -07009712 // Reset the key delivery timeout on unfreeze, too. We force a wakeup here
9713 // too because regular key delivery processing should resume immediately.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009714 synchronized (mKeyWaiter) {
9715 mKeyWaiter.mWasFrozen = true;
9716 mKeyWaiter.notifyAll();
9717 }
9718
9719 // A little kludge: a lot could have happened while the
9720 // display was frozen, so now that we are coming back we
9721 // do a gc so that any remote references the system
9722 // processes holds on others can be released if they are
9723 // no longer needed.
9724 mH.removeMessages(H.FORCE_GC);
9725 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9726 2000);
Romain Guy06882f82009-06-10 13:36:04 -07009727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009728 mScreenFrozenLock.release();
9729 }
Romain Guy06882f82009-06-10 13:36:04 -07009730
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009731 @Override
9732 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
9733 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
9734 != PackageManager.PERMISSION_GRANTED) {
9735 pw.println("Permission Denial: can't dump WindowManager from from pid="
9736 + Binder.getCallingPid()
9737 + ", uid=" + Binder.getCallingUid());
9738 return;
9739 }
Romain Guy06882f82009-06-10 13:36:04 -07009740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009741 synchronized(mWindowMap) {
9742 pw.println("Current Window Manager state:");
9743 for (int i=mWindows.size()-1; i>=0; i--) {
9744 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009745 pw.print(" Window #"); pw.print(i); pw.print(' ');
9746 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009747 w.dump(pw, " ");
9748 }
9749 if (mInputMethodDialogs.size() > 0) {
9750 pw.println(" ");
9751 pw.println(" Input method dialogs:");
9752 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
9753 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009754 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009755 }
9756 }
9757 if (mPendingRemove.size() > 0) {
9758 pw.println(" ");
9759 pw.println(" Remove pending for:");
9760 for (int i=mPendingRemove.size()-1; i>=0; i--) {
9761 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009762 pw.print(" Remove #"); pw.print(i); pw.print(' ');
9763 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009764 w.dump(pw, " ");
9765 }
9766 }
9767 if (mForceRemoves != null && mForceRemoves.size() > 0) {
9768 pw.println(" ");
9769 pw.println(" Windows force removing:");
9770 for (int i=mForceRemoves.size()-1; i>=0; i--) {
9771 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009772 pw.print(" Removing #"); pw.print(i); pw.print(' ');
9773 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009774 w.dump(pw, " ");
9775 }
9776 }
9777 if (mDestroySurface.size() > 0) {
9778 pw.println(" ");
9779 pw.println(" Windows waiting to destroy their surface:");
9780 for (int i=mDestroySurface.size()-1; i>=0; i--) {
9781 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009782 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
9783 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009784 w.dump(pw, " ");
9785 }
9786 }
9787 if (mLosingFocus.size() > 0) {
9788 pw.println(" ");
9789 pw.println(" Windows losing focus:");
9790 for (int i=mLosingFocus.size()-1; i>=0; i--) {
9791 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009792 pw.print(" Losing #"); pw.print(i); pw.print(' ');
9793 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009794 w.dump(pw, " ");
9795 }
9796 }
9797 if (mSessions.size() > 0) {
9798 pw.println(" ");
9799 pw.println(" All active sessions:");
9800 Iterator<Session> it = mSessions.iterator();
9801 while (it.hasNext()) {
9802 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009803 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009804 s.dump(pw, " ");
9805 }
9806 }
9807 if (mTokenMap.size() > 0) {
9808 pw.println(" ");
9809 pw.println(" All tokens:");
9810 Iterator<WindowToken> it = mTokenMap.values().iterator();
9811 while (it.hasNext()) {
9812 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009813 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009814 token.dump(pw, " ");
9815 }
9816 }
9817 if (mTokenList.size() > 0) {
9818 pw.println(" ");
9819 pw.println(" Window token list:");
9820 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009821 pw.print(" #"); pw.print(i); pw.print(": ");
9822 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009823 }
9824 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009825 if (mWallpaperTokens.size() > 0) {
9826 pw.println(" ");
9827 pw.println(" Wallpaper tokens:");
9828 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
9829 WindowToken token = mWallpaperTokens.get(i);
9830 pw.print(" Wallpaper #"); pw.print(i);
9831 pw.print(' '); pw.print(token); pw.println(':');
9832 token.dump(pw, " ");
9833 }
9834 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009835 if (mAppTokens.size() > 0) {
9836 pw.println(" ");
9837 pw.println(" Application tokens in Z order:");
9838 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009839 pw.print(" App #"); pw.print(i); pw.print(": ");
9840 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009841 }
9842 }
9843 if (mFinishedStarting.size() > 0) {
9844 pw.println(" ");
9845 pw.println(" Finishing start of application tokens:");
9846 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
9847 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009848 pw.print(" Finished Starting #"); pw.print(i);
9849 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009850 token.dump(pw, " ");
9851 }
9852 }
9853 if (mExitingTokens.size() > 0) {
9854 pw.println(" ");
9855 pw.println(" Exiting tokens:");
9856 for (int i=mExitingTokens.size()-1; i>=0; i--) {
9857 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009858 pw.print(" Exiting #"); pw.print(i);
9859 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009860 token.dump(pw, " ");
9861 }
9862 }
9863 if (mExitingAppTokens.size() > 0) {
9864 pw.println(" ");
9865 pw.println(" Exiting application tokens:");
9866 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
9867 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009868 pw.print(" Exiting App #"); pw.print(i);
9869 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009870 token.dump(pw, " ");
9871 }
9872 }
9873 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009874 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
9875 pw.print(" mLastFocus="); pw.println(mLastFocus);
9876 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
9877 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
9878 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -07009879 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -07009880 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
9881 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
9882 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
9883 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009884 pw.print(" mInTouchMode="); pw.println(mInTouchMode);
9885 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
9886 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
9887 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
9888 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009889 if (mDimAnimator != null) {
9890 mDimAnimator.printTo(pw);
9891 } else {
9892 pw.print( " no DimAnimator ");
9893 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009894 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009895 pw.print(mInputMethodAnimLayerAdjustment);
9896 pw.print(" mWallpaperAnimLayerAdjustment=");
9897 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -07009898 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
9899 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009900 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
9901 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
9902 pw.print(" mAppsFreezingScreen="); pw.println(mAppsFreezingScreen);
9903 pw.print(" mRotation="); pw.print(mRotation);
9904 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
9905 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
9906 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
9907 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
9908 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
9909 pw.print(" mNextAppTransition=0x");
9910 pw.print(Integer.toHexString(mNextAppTransition));
9911 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
9912 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
9913 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
9914 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
9915 if (mOpeningApps.size() > 0) {
9916 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
9917 }
9918 if (mClosingApps.size() > 0) {
9919 pw.print(" mClosingApps="); pw.println(mClosingApps);
9920 }
9921 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
9922 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009923 pw.println(" KeyWaiter state:");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07009924 pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin);
9925 pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder);
9926 pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished);
9927 pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow);
9928 pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching);
9929 pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009930 }
9931 }
9932
9933 public void monitor() {
9934 synchronized (mWindowMap) { }
9935 synchronized (mKeyguardDisabled) { }
9936 synchronized (mKeyWaiter) { }
9937 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009938
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07009939 public void virtualKeyFeedback(KeyEvent event) {
9940 mPolicy.keyFeedbackFromInput(event);
9941 }
9942
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009943 /**
9944 * DimAnimator class that controls the dim animation. This holds the surface and
9945 * all state used for dim animation.
9946 */
9947 private static class DimAnimator {
9948 Surface mDimSurface;
9949 boolean mDimShown = false;
9950 float mDimCurrentAlpha;
9951 float mDimTargetAlpha;
9952 float mDimDeltaPerMs;
9953 long mLastDimAnimTime;
9954
9955 DimAnimator (SurfaceSession session) {
9956 if (mDimSurface == null) {
9957 if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM "
9958 + mDimSurface + ": CREATE");
9959 try {
9960 mDimSurface = new Surface(session, 0, -1, 16, 16, PixelFormat.OPAQUE,
9961 Surface.FX_SURFACE_DIM);
9962 } catch (Exception e) {
9963 Log.e(TAG, "Exception creating Dim surface", e);
9964 }
9965 }
9966 }
9967
9968 /**
9969 * Show the dim surface.
9970 */
9971 void show(int dw, int dh) {
9972 if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
9973 dw + "x" + dh + ")");
9974 mDimShown = true;
9975 try {
9976 mDimSurface.setPosition(0, 0);
9977 mDimSurface.setSize(dw, dh);
9978 mDimSurface.show();
9979 } catch (RuntimeException e) {
9980 Log.w(TAG, "Failure showing dim surface", e);
9981 }
9982 }
9983
9984 /**
9985 * Set's the dim surface's layer and update dim parameters that will be used in
9986 * {@link updateSurface} after all windows are examined.
9987 */
9988 void updateParameters(WindowState w, long currentTime) {
9989 mDimSurface.setLayer(w.mAnimLayer-1);
9990
9991 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
9992 if (SHOW_TRANSACTIONS) Log.i(TAG, "layer=" + (w.mAnimLayer-1) + ", target=" + target);
9993 if (mDimTargetAlpha != target) {
9994 // If the desired dim level has changed, then
9995 // start an animation to it.
9996 mLastDimAnimTime = currentTime;
9997 long duration = (w.mAnimating && w.mAnimation != null)
9998 ? w.mAnimation.computeDurationHint()
9999 : DEFAULT_DIM_DURATION;
10000 if (target > mDimTargetAlpha) {
10001 // This is happening behind the activity UI,
10002 // so we can make it run a little longer to
10003 // give a stronger impression without disrupting
10004 // the user.
10005 duration *= DIM_DURATION_MULTIPLIER;
10006 }
10007 if (duration < 1) {
10008 // Don't divide by zero
10009 duration = 1;
10010 }
10011 mDimTargetAlpha = target;
10012 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
10013 }
10014 }
10015
10016 /**
10017 * Updating the surface's alpha. Returns true if the animation continues, or returns
10018 * false when the animation is finished and the dim surface is hidden.
10019 */
10020 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
10021 if (!dimming) {
10022 if (mDimTargetAlpha != 0) {
10023 mLastDimAnimTime = currentTime;
10024 mDimTargetAlpha = 0;
10025 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
10026 }
10027 }
10028
10029 boolean animating = false;
10030 if (mLastDimAnimTime != 0) {
10031 mDimCurrentAlpha += mDimDeltaPerMs
10032 * (currentTime-mLastDimAnimTime);
10033 boolean more = true;
10034 if (displayFrozen) {
10035 // If the display is frozen, there is no reason to animate.
10036 more = false;
10037 } else if (mDimDeltaPerMs > 0) {
10038 if (mDimCurrentAlpha > mDimTargetAlpha) {
10039 more = false;
10040 }
10041 } else if (mDimDeltaPerMs < 0) {
10042 if (mDimCurrentAlpha < mDimTargetAlpha) {
10043 more = false;
10044 }
10045 } else {
10046 more = false;
10047 }
10048
10049 // Do we need to continue animating?
10050 if (more) {
10051 if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM "
10052 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
10053 mLastDimAnimTime = currentTime;
10054 mDimSurface.setAlpha(mDimCurrentAlpha);
10055 animating = true;
10056 } else {
10057 mDimCurrentAlpha = mDimTargetAlpha;
10058 mLastDimAnimTime = 0;
10059 if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM "
10060 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
10061 mDimSurface.setAlpha(mDimCurrentAlpha);
10062 if (!dimming) {
10063 if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface
10064 + ": HIDE");
10065 try {
10066 mDimSurface.hide();
10067 } catch (RuntimeException e) {
10068 Log.w(TAG, "Illegal argument exception hiding dim surface");
10069 }
10070 mDimShown = false;
10071 }
10072 }
10073 }
10074 return animating;
10075 }
10076
10077 public void printTo(PrintWriter pw) {
10078 pw.print(" mDimShown="); pw.print(mDimShown);
10079 pw.print(" current="); pw.print(mDimCurrentAlpha);
10080 pw.print(" target="); pw.print(mDimTargetAlpha);
10081 pw.print(" delta="); pw.print(mDimDeltaPerMs);
10082 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
10083 }
10084 }
10085
10086 /**
10087 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
10088 * This is used for opening/closing transition for apps in compatible mode.
10089 */
10090 private static class FadeInOutAnimation extends Animation {
10091 int mWidth;
10092 boolean mFadeIn;
10093
10094 public FadeInOutAnimation(boolean fadeIn) {
10095 setInterpolator(new AccelerateInterpolator());
10096 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
10097 mFadeIn = fadeIn;
10098 }
10099
10100 @Override
10101 protected void applyTransformation(float interpolatedTime, Transformation t) {
10102 float x = interpolatedTime;
10103 if (!mFadeIn) {
10104 x = 1.0f - x; // reverse the interpolation for fade out
10105 }
10106 if (x < 0.5) {
10107 // move the window out of the screen.
10108 t.getMatrix().setTranslate(mWidth, 0);
10109 } else {
10110 t.getMatrix().setTranslate(0, 0);// show
10111 t.setAlpha((x - 0.5f) * 2);
10112 }
10113 }
10114
10115 @Override
10116 public void initialize(int width, int height, int parentWidth, int parentHeight) {
10117 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
10118 mWidth = width;
10119 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010120
10121 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070010122 public int getZAdjustment() {
10123 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010124 }
10125 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010126}