blob: f5d3e8e151642f39722a9f9046de9d851e02f158 [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;
Dianne Hackborn75804932009-10-20 20:15:20 -070066import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import android.os.Debug;
68import android.os.Handler;
69import android.os.IBinder;
Michael Chan53071d62009-05-13 17:29:48 -070070import android.os.LatencyTimer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071import android.os.LocalPowerManager;
72import android.os.Looper;
73import android.os.Message;
74import android.os.Parcel;
75import android.os.ParcelFileDescriptor;
76import android.os.Power;
77import android.os.PowerManager;
78import android.os.Process;
79import android.os.RemoteException;
80import android.os.ServiceManager;
81import android.os.SystemClock;
82import android.os.SystemProperties;
83import android.os.TokenWatcher;
84import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070085import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086import android.util.EventLog;
Joe Onorato8a9b2202010-02-26 18:56:32 -080087import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088import android.util.SparseIntArray;
89import android.view.Display;
90import android.view.Gravity;
91import android.view.IApplicationToken;
92import android.view.IOnKeyguardExitResult;
93import android.view.IRotationWatcher;
94import android.view.IWindow;
95import android.view.IWindowManager;
96import android.view.IWindowSession;
97import android.view.KeyEvent;
98import android.view.MotionEvent;
99import android.view.RawInputEvent;
100import android.view.Surface;
101import android.view.SurfaceSession;
102import android.view.View;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -0700103import android.view.ViewConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104import android.view.ViewTreeObserver;
105import android.view.WindowManager;
106import android.view.WindowManagerImpl;
107import android.view.WindowManagerPolicy;
108import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700109import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110import android.view.animation.Animation;
111import android.view.animation.AnimationUtils;
112import android.view.animation.Transformation;
113
114import java.io.BufferedWriter;
115import java.io.File;
116import java.io.FileDescriptor;
117import java.io.IOException;
118import java.io.OutputStream;
119import java.io.OutputStreamWriter;
120import java.io.PrintWriter;
121import java.io.StringWriter;
122import java.net.Socket;
123import java.util.ArrayList;
124import java.util.HashMap;
125import java.util.HashSet;
126import java.util.Iterator;
127import java.util.List;
128
129/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700130public class WindowManagerService extends IWindowManager.Stub
131 implements Watchdog.Monitor, KeyInputQueue.HapticFeedbackCallback {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 static final String TAG = "WindowManager";
133 static final boolean DEBUG = false;
134 static final boolean DEBUG_FOCUS = false;
135 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800136 static final boolean DEBUG_LAYOUT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 static final boolean DEBUG_LAYERS = false;
138 static final boolean DEBUG_INPUT = false;
139 static final boolean DEBUG_INPUT_METHOD = false;
140 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700141 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 static final boolean DEBUG_ORIENTATION = false;
143 static final boolean DEBUG_APP_TRANSITIONS = false;
144 static final boolean DEBUG_STARTING_WINDOW = false;
145 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700146 static final boolean DEBUG_WALLPAPER = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700148 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700149 static final boolean MEASURE_LATENCY = false;
150 static private LatencyTimer lt;
151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 static final boolean PROFILE_ORIENTATION = false;
153 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700154 static final boolean localLOGV = DEBUG;
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;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800195
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.
Mike Lockwood983ee092009-11-22 01:42:24 -0500226 * This is set to true only if mKeyguardTokenWatcher.acquired() has
227 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500229 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230
Mike Lockwood983ee092009-11-22 01:42:24 -0500231 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
232 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 public void acquired() {
234 mPolicy.enableKeyguard(false);
Mike Lockwood983ee092009-11-22 01:42:24 -0500235 mKeyguardDisabled = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 }
237 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700238 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500239 synchronized (mKeyguardTokenWatcher) {
240 mKeyguardDisabled = false;
241 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 }
243 }
244 };
245
246 final Context mContext;
247
248 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
253
254 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258 /**
259 * All currently active sessions with clients.
260 */
261 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800263 /**
264 * Mapping from an IWindow IBinder to the server's Window object.
265 * This is also used as the lock for all of our state.
266 */
267 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
268
269 /**
270 * Mapping from a token IBinder to a WindowToken object.
271 */
272 final HashMap<IBinder, WindowToken> mTokenMap =
273 new HashMap<IBinder, WindowToken>();
274
275 /**
276 * The same tokens as mTokenMap, stored in a list for efficient iteration
277 * over them.
278 */
279 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 /**
282 * Window tokens that are in the process of exiting, but still
283 * on screen for animations.
284 */
285 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
286
287 /**
288 * Z-ordered (bottom-most first) list of all application tokens, for
289 * controlling the ordering of windows in different applications. This
290 * contains WindowToken objects.
291 */
292 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
293
294 /**
295 * Application tokens that are in the process of exiting, but still
296 * on screen for animations.
297 */
298 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
299
300 /**
301 * List of window tokens that have finished starting their application,
302 * and now need to have the policy remove their windows.
303 */
304 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
305
306 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700307 * This was the app token that was used to retrieve the last enter
308 * animation. It will be used for the next exit animation.
309 */
310 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800311
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700312 /**
313 * These were the layout params used to retrieve the last enter animation.
314 * They will be used for the next exit animation.
315 */
316 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800317
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700318 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 * Z-ordered (bottom-most first) list of all Window objects.
320 */
321 final ArrayList mWindows = new ArrayList();
322
323 /**
324 * Windows that are being resized. Used so we can tell the client about
325 * the resize after closing the transaction in which we resized the
326 * underlying surface.
327 */
328 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
329
330 /**
331 * Windows whose animations have ended and now must be removed.
332 */
333 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
334
335 /**
336 * Windows whose surface should be destroyed.
337 */
338 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
339
340 /**
341 * Windows that have lost input focus and are waiting for the new
342 * focus window to be displayed before they are told about this.
343 */
344 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
345
346 /**
347 * This is set when we have run out of memory, and will either be an empty
348 * list or contain windows that need to be force removed.
349 */
350 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700355 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 Surface mBlurSurface;
357 boolean mBlurShown;
Romain Guy06882f82009-06-10 13:36:04 -0700358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 final float[] mTmpFloats = new float[9];
362
363 boolean mSafeMode;
364 boolean mDisplayEnabled = false;
365 boolean mSystemBooted = false;
366 int mRotation = 0;
367 int mRequestedRotation = 0;
368 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700369 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 ArrayList<IRotationWatcher> mRotationWatchers
371 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 boolean mLayoutNeeded = true;
374 boolean mAnimationPending = false;
375 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800376 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 boolean mWindowsFreezingScreen = false;
378 long mFreezeGcPending = 0;
379 int mAppsFreezingScreen = 0;
380
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800381 int mLayoutSeq = 0;
382
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800383 // State while inside of layoutAndPlaceSurfacesLocked().
384 boolean mFocusMayChange;
385
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800386 Configuration mCurConfiguration = new Configuration();
387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 // This is held as long as we have the screen frozen, to give us time to
389 // perform a rotation animation when turning off shows the lock screen which
390 // changes the orientation.
391 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 // State management of app transitions. When we are preparing for a
394 // transition, mNextAppTransition will be the kind of transition to
395 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
396 // mOpeningApps and mClosingApps are the lists of tokens that will be
397 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700398 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700399 String mNextAppTransitionPackage;
400 int mNextAppTransitionEnter;
401 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700403 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 boolean mAppTransitionTimeout = false;
405 boolean mStartingIconInTransition = false;
406 boolean mSkipAppTransitionAnimation = false;
407 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
408 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700409 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
410 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412 //flag to detect fat touch events
413 boolean mFatTouch = false;
414 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416 H mH = new H();
417
418 WindowState mCurrentFocus = null;
419 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800421 // This just indicates the window the input method is on top of, not
422 // necessarily the window its input is going to.
423 WindowState mInputMethodTarget = null;
424 WindowState mUpcomingInputMethodTarget = null;
425 boolean mInputMethodTargetWaitingAnim;
426 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 WindowState mInputMethodWindow = null;
429 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
430
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700431 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800432
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700433 // If non-null, this is the currently visible window that is associated
434 // with the wallpaper.
435 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700436 // If non-null, we are in the middle of animating from one wallpaper target
437 // to another, and this is the lower one in Z-order.
438 WindowState mLowerWallpaperTarget = null;
439 // If non-null, we are in the middle of animating from one wallpaper target
440 // to another, and this is the higher one in Z-order.
441 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700442 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700443 float mLastWallpaperX = -1;
444 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800445 float mLastWallpaperXStep = -1;
446 float mLastWallpaperYStep = -1;
Dianne Hackborn6adba242009-11-10 11:10:09 -0800447 boolean mSendingPointersToWallpaper = false;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700448 // This is set when we are waiting for a wallpaper to tell us it is done
449 // changing its scroll position.
450 WindowState mWaitingOnWallpaper;
451 // The last time we had a timeout when waiting for a wallpaper.
452 long mLastWallpaperTimeoutTime;
453 // We give a wallpaper up to 150ms to finish scrolling.
454 static final long WALLPAPER_TIMEOUT = 150;
455 // Time we wait after a timeout before trying to wait again.
456 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800458 AppWindowToken mFocusedApp = null;
459
460 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 float mWindowAnimationScale = 1.0f;
463 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800465 final KeyWaiter mKeyWaiter = new KeyWaiter();
466 final KeyQ mQueue;
467 final InputDispatcherThread mInputThread;
468
469 // Who is holding the screen on.
470 Session mHoldingScreenOn;
Romain Guy06882f82009-06-10 13:36:04 -0700471
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700472 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800474 /**
475 * Whether the UI is currently running in touch mode (not showing
476 * navigational focus because the user is directly pressing the screen).
477 */
478 boolean mInTouchMode = false;
479
480 private ViewServer mViewServer;
481
482 final Rect mTempRect = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -0700483
Dianne Hackbornc485a602009-03-24 22:39:49 -0700484 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700485 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700486
487 // The frame use to limit the size of the app running in compatibility mode.
488 Rect mCompatibleScreenFrame = new Rect();
489 // The surface used to fill the outer rim of the app running in compatibility mode.
490 Surface mBackgroundFillerSurface = null;
491 boolean mBackgroundFillerShown = false;
492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493 public static WindowManagerService main(Context context,
494 PowerManagerService pm, boolean haveInputMethods) {
495 WMThread thr = new WMThread(context, pm, haveInputMethods);
496 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 synchronized (thr) {
499 while (thr.mService == null) {
500 try {
501 thr.wait();
502 } catch (InterruptedException e) {
503 }
504 }
505 }
Romain Guy06882f82009-06-10 13:36:04 -0700506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 return thr.mService;
508 }
Romain Guy06882f82009-06-10 13:36:04 -0700509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 static class WMThread extends Thread {
511 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 private final Context mContext;
514 private final PowerManagerService mPM;
515 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 public WMThread(Context context, PowerManagerService pm,
518 boolean haveInputMethods) {
519 super("WindowManager");
520 mContext = context;
521 mPM = pm;
522 mHaveInputMethods = haveInputMethods;
523 }
Romain Guy06882f82009-06-10 13:36:04 -0700524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800525 public void run() {
526 Looper.prepare();
527 WindowManagerService s = new WindowManagerService(mContext, mPM,
528 mHaveInputMethods);
529 android.os.Process.setThreadPriority(
530 android.os.Process.THREAD_PRIORITY_DISPLAY);
Romain Guy06882f82009-06-10 13:36:04 -0700531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 synchronized (this) {
533 mService = s;
534 notifyAll();
535 }
Romain Guy06882f82009-06-10 13:36:04 -0700536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 Looper.loop();
538 }
539 }
540
541 static class PolicyThread extends Thread {
542 private final WindowManagerPolicy mPolicy;
543 private final WindowManagerService mService;
544 private final Context mContext;
545 private final PowerManagerService mPM;
546 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 public PolicyThread(WindowManagerPolicy policy,
549 WindowManagerService service, Context context,
550 PowerManagerService pm) {
551 super("WindowManagerPolicy");
552 mPolicy = policy;
553 mService = service;
554 mContext = context;
555 mPM = pm;
556 }
Romain Guy06882f82009-06-10 13:36:04 -0700557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 public void run() {
559 Looper.prepare();
560 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800561 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 android.os.Process.setThreadPriority(
563 android.os.Process.THREAD_PRIORITY_FOREGROUND);
564 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 synchronized (this) {
567 mRunning = true;
568 notifyAll();
569 }
Romain Guy06882f82009-06-10 13:36:04 -0700570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 Looper.loop();
572 }
573 }
574
575 private WindowManagerService(Context context, PowerManagerService pm,
576 boolean haveInputMethods) {
Michael Chan53071d62009-05-13 17:29:48 -0700577 if (MEASURE_LATENCY) {
578 lt = new LatencyTimer(100, 1000);
579 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 mContext = context;
582 mHaveInputMethods = haveInputMethods;
583 mLimitedAlphaCompositing = context.getResources().getBoolean(
584 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 mPowerManager = pm;
587 mPowerManager.setPolicy(mPolicy);
588 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
589 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
590 "SCREEN_FROZEN");
591 mScreenFrozenLock.setReferenceCounted(false);
592
593 mActivityManager = ActivityManagerNative.getDefault();
594 mBatteryStats = BatteryStatsService.getService();
595
596 // Get persisted window scale setting
597 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
598 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
599 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
600 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700601
Michael Chan9f028e62009-08-04 17:37:46 -0700602 int max_events_per_sec = 35;
603 try {
604 max_events_per_sec = Integer.parseInt(SystemProperties
605 .get("windowsmgr.max_events_per_sec"));
606 if (max_events_per_sec < 1) {
607 max_events_per_sec = 35;
608 }
609 } catch (NumberFormatException e) {
610 }
611 mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec;
612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800613 mQueue = new KeyQ();
614
615 mInputThread = new InputDispatcherThread();
Romain Guy06882f82009-06-10 13:36:04 -0700616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800617 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
618 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 synchronized (thr) {
621 while (!thr.mRunning) {
622 try {
623 thr.wait();
624 } catch (InterruptedException e) {
625 }
626 }
627 }
Romain Guy06882f82009-06-10 13:36:04 -0700628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 mInputThread.start();
Romain Guy06882f82009-06-10 13:36:04 -0700630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631 // Add ourself to the Watchdog monitors.
632 Watchdog.getInstance().addMonitor(this);
633 }
634
635 @Override
636 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
637 throws RemoteException {
638 try {
639 return super.onTransact(code, data, reply, flags);
640 } catch (RuntimeException e) {
641 // The window manager only throws security exceptions, so let's
642 // log all others.
643 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800644 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 }
646 throw e;
647 }
648 }
649
650 private void placeWindowAfter(Object pos, WindowState window) {
651 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800652 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653 TAG, "Adding window " + window + " at "
654 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
655 mWindows.add(i+1, window);
656 }
657
658 private void placeWindowBefore(Object pos, WindowState window) {
659 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800660 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800661 TAG, "Adding window " + window + " at "
662 + i + " of " + mWindows.size() + " (before " + pos + ")");
663 mWindows.add(i, window);
664 }
665
666 //This method finds out the index of a window that has the same app token as
667 //win. used for z ordering the windows in mWindows
668 private int findIdxBasedOnAppTokens(WindowState win) {
669 //use a local variable to cache mWindows
670 ArrayList localmWindows = mWindows;
671 int jmax = localmWindows.size();
672 if(jmax == 0) {
673 return -1;
674 }
675 for(int j = (jmax-1); j >= 0; j--) {
676 WindowState wentry = (WindowState)localmWindows.get(j);
677 if(wentry.mAppToken == win.mAppToken) {
678 return j;
679 }
680 }
681 return -1;
682 }
Romain Guy06882f82009-06-10 13:36:04 -0700683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
685 final IWindow client = win.mClient;
686 final WindowToken token = win.mToken;
687 final ArrayList localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800689 final int N = localmWindows.size();
690 final WindowState attached = win.mAttachedWindow;
691 int i;
692 if (attached == null) {
693 int tokenWindowsPos = token.windows.size();
694 if (token.appWindowToken != null) {
695 int index = tokenWindowsPos-1;
696 if (index >= 0) {
697 // If this application has existing windows, we
698 // simply place the new window on top of them... but
699 // keep the starting window on top.
700 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
701 // Base windows go behind everything else.
702 placeWindowBefore(token.windows.get(0), win);
703 tokenWindowsPos = 0;
704 } else {
705 AppWindowToken atoken = win.mAppToken;
706 if (atoken != null &&
707 token.windows.get(index) == atoken.startingWindow) {
708 placeWindowBefore(token.windows.get(index), win);
709 tokenWindowsPos--;
710 } else {
711 int newIdx = findIdxBasedOnAppTokens(win);
712 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700713 //there is a window above this one associated with the same
714 //apptoken note that the window could be a floating window
715 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800716 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800717 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700718 TAG, "Adding window " + win + " at "
719 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800720 localmWindows.add(newIdx+1, win);
Romain Guy06882f82009-06-10 13:36:04 -0700721 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 }
723 }
724 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800725 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800726 TAG, "Figuring out where to add app window "
727 + client.asBinder() + " (token=" + token + ")");
728 // Figure out where the window should go, based on the
729 // order of applications.
730 final int NA = mAppTokens.size();
731 Object pos = null;
732 for (i=NA-1; i>=0; i--) {
733 AppWindowToken t = mAppTokens.get(i);
734 if (t == token) {
735 i--;
736 break;
737 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800738
Dianne Hackborna8f60182009-09-01 19:01:50 -0700739 // We haven't reached the token yet; if this token
740 // is not going to the bottom and has windows, we can
741 // use it as an anchor for when we do reach the token.
742 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 pos = t.windows.get(0);
744 }
745 }
746 // We now know the index into the apps. If we found
747 // an app window above, that gives us the position; else
748 // we need to look some more.
749 if (pos != null) {
750 // Move behind any windows attached to this one.
Romain Guy06882f82009-06-10 13:36:04 -0700751 WindowToken atoken =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800752 mTokenMap.get(((WindowState)pos).mClient.asBinder());
753 if (atoken != null) {
754 final int NC = atoken.windows.size();
755 if (NC > 0) {
756 WindowState bottom = atoken.windows.get(0);
757 if (bottom.mSubLayer < 0) {
758 pos = bottom;
759 }
760 }
761 }
762 placeWindowBefore(pos, win);
763 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700764 // Continue looking down until we find the first
765 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800766 while (i >= 0) {
767 AppWindowToken t = mAppTokens.get(i);
768 final int NW = t.windows.size();
769 if (NW > 0) {
770 pos = t.windows.get(NW-1);
771 break;
772 }
773 i--;
774 }
775 if (pos != null) {
776 // Move in front of any windows attached to this
777 // one.
778 WindowToken atoken =
779 mTokenMap.get(((WindowState)pos).mClient.asBinder());
780 if (atoken != null) {
781 final int NC = atoken.windows.size();
782 if (NC > 0) {
783 WindowState top = atoken.windows.get(NC-1);
784 if (top.mSubLayer >= 0) {
785 pos = top;
786 }
787 }
788 }
789 placeWindowAfter(pos, win);
790 } else {
791 // Just search for the start of this layer.
792 final int myLayer = win.mBaseLayer;
793 for (i=0; i<N; i++) {
794 WindowState w = (WindowState)localmWindows.get(i);
795 if (w.mBaseLayer > myLayer) {
796 break;
797 }
798 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800799 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700800 TAG, "Adding window " + win + " at "
801 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800802 localmWindows.add(i, win);
803 }
804 }
805 }
806 } else {
807 // Figure out where window should go, based on layer.
808 final int myLayer = win.mBaseLayer;
809 for (i=N-1; i>=0; i--) {
810 if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) {
811 i++;
812 break;
813 }
814 }
815 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800816 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700817 TAG, "Adding window " + win + " at "
818 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800819 localmWindows.add(i, win);
820 }
821 if (addToToken) {
822 token.windows.add(tokenWindowsPos, win);
823 }
824
825 } else {
826 // Figure out this window's ordering relative to the window
827 // it is attached to.
828 final int NA = token.windows.size();
829 final int sublayer = win.mSubLayer;
830 int largestSublayer = Integer.MIN_VALUE;
831 WindowState windowWithLargestSublayer = null;
832 for (i=0; i<NA; i++) {
833 WindowState w = token.windows.get(i);
834 final int wSublayer = w.mSubLayer;
835 if (wSublayer >= largestSublayer) {
836 largestSublayer = wSublayer;
837 windowWithLargestSublayer = w;
838 }
839 if (sublayer < 0) {
840 // For negative sublayers, we go below all windows
841 // in the same sublayer.
842 if (wSublayer >= sublayer) {
843 if (addToToken) {
844 token.windows.add(i, win);
845 }
846 placeWindowBefore(
847 wSublayer >= 0 ? attached : w, win);
848 break;
849 }
850 } else {
851 // For positive sublayers, we go above all windows
852 // in the same sublayer.
853 if (wSublayer > sublayer) {
854 if (addToToken) {
855 token.windows.add(i, win);
856 }
857 placeWindowBefore(w, win);
858 break;
859 }
860 }
861 }
862 if (i >= NA) {
863 if (addToToken) {
864 token.windows.add(win);
865 }
866 if (sublayer < 0) {
867 placeWindowBefore(attached, win);
868 } else {
869 placeWindowAfter(largestSublayer >= 0
870 ? windowWithLargestSublayer
871 : attached,
872 win);
873 }
874 }
875 }
Romain Guy06882f82009-06-10 13:36:04 -0700876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 if (win.mAppToken != null && addToToken) {
878 win.mAppToken.allAppWindows.add(win);
879 }
880 }
Romain Guy06882f82009-06-10 13:36:04 -0700881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800882 static boolean canBeImeTarget(WindowState w) {
883 final int fl = w.mAttrs.flags
884 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
885 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
886 return w.isVisibleOrAdding();
887 }
888 return false;
889 }
Romain Guy06882f82009-06-10 13:36:04 -0700890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
892 final ArrayList localmWindows = mWindows;
893 final int N = localmWindows.size();
894 WindowState w = null;
895 int i = N;
896 while (i > 0) {
897 i--;
898 w = (WindowState)localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700899
Joe Onorato8a9b2202010-02-26 18:56:32 -0800900 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901 // + Integer.toHexString(w.mAttrs.flags));
902 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800903 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800905 // Yet more tricksyness! If this window is a "starting"
906 // window, we do actually want to be on top of it, but
907 // it is not -really- where input will go. So if the caller
908 // is not actually looking to move the IME, look down below
909 // for a real window to target...
910 if (!willMove
911 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
912 && i > 0) {
913 WindowState wb = (WindowState)localmWindows.get(i-1);
914 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
915 i--;
916 w = wb;
917 }
918 }
919 break;
920 }
921 }
Romain Guy06882f82009-06-10 13:36:04 -0700922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700924
Joe Onorato8a9b2202010-02-26 18:56:32 -0800925 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 if (willMove && w != null) {
929 final WindowState curTarget = mInputMethodTarget;
930 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 // Now some fun for dealing with window animations that
933 // modify the Z order. We need to look at all windows below
934 // the current target that are in this app, finding the highest
935 // visible one in layering.
936 AppWindowToken token = curTarget.mAppToken;
937 WindowState highestTarget = null;
938 int highestPos = 0;
939 if (token.animating || token.animation != null) {
940 int pos = 0;
941 pos = localmWindows.indexOf(curTarget);
942 while (pos >= 0) {
943 WindowState win = (WindowState)localmWindows.get(pos);
944 if (win.mAppToken != token) {
945 break;
946 }
947 if (!win.mRemoved) {
948 if (highestTarget == null || win.mAnimLayer >
949 highestTarget.mAnimLayer) {
950 highestTarget = win;
951 highestPos = pos;
952 }
953 }
954 pos--;
955 }
956 }
Romain Guy06882f82009-06-10 13:36:04 -0700957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800958 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800959 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800960 + mNextAppTransition + " " + highestTarget
961 + " animating=" + highestTarget.isAnimating()
962 + " layer=" + highestTarget.mAnimLayer
963 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700964
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700965 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966 // If we are currently setting up for an animation,
967 // hold everything until we can find out what will happen.
968 mInputMethodTargetWaitingAnim = true;
969 mInputMethodTarget = highestTarget;
970 return highestPos + 1;
971 } else if (highestTarget.isAnimating() &&
972 highestTarget.mAnimLayer > w.mAnimLayer) {
973 // If the window we are currently targeting is involved
974 // with an animation, and it is on top of the next target
975 // we will be over, then hold off on moving until
976 // that is done.
977 mInputMethodTarget = highestTarget;
978 return highestPos + 1;
979 }
980 }
981 }
982 }
Romain Guy06882f82009-06-10 13:36:04 -0700983
Joe Onorato8a9b2202010-02-26 18:56:32 -0800984 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800985 if (w != null) {
986 if (willMove) {
987 RuntimeException e = new RuntimeException();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700988 if (!HIDE_STACK_CRAWLS) e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -0800989 if (DEBUG_INPUT_METHOD) Slog.w(TAG, "Moving IM target from "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 + mInputMethodTarget + " to " + w, e);
991 mInputMethodTarget = w;
992 if (w.mAppToken != null) {
993 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
994 } else {
995 setInputMethodAnimLayerAdjustment(0);
996 }
997 }
998 return i+1;
999 }
1000 if (willMove) {
1001 RuntimeException e = new RuntimeException();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001002 if (!HIDE_STACK_CRAWLS) e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001003 if (DEBUG_INPUT_METHOD) Slog.w(TAG, "Moving IM target from "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001004 + mInputMethodTarget + " to null", e);
1005 mInputMethodTarget = null;
1006 setInputMethodAnimLayerAdjustment(0);
1007 }
1008 return -1;
1009 }
Romain Guy06882f82009-06-10 13:36:04 -07001010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001011 void addInputMethodWindowToListLocked(WindowState win) {
1012 int pos = findDesiredInputMethodWindowIndexLocked(true);
1013 if (pos >= 0) {
1014 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001015 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001016 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001017 mWindows.add(pos, win);
1018 moveInputMethodDialogsLocked(pos+1);
1019 return;
1020 }
1021 win.mTargetAppToken = null;
1022 addWindowToListInOrderLocked(win, true);
1023 moveInputMethodDialogsLocked(pos);
1024 }
Romain Guy06882f82009-06-10 13:36:04 -07001025
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001026 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001027 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028 mInputMethodAnimLayerAdjustment = adj;
1029 WindowState imw = mInputMethodWindow;
1030 if (imw != null) {
1031 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001032 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001033 + " anim layer: " + imw.mAnimLayer);
1034 int wi = imw.mChildWindows.size();
1035 while (wi > 0) {
1036 wi--;
1037 WindowState cw = (WindowState)imw.mChildWindows.get(wi);
1038 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001039 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001040 + " anim layer: " + cw.mAnimLayer);
1041 }
1042 }
1043 int di = mInputMethodDialogs.size();
1044 while (di > 0) {
1045 di --;
1046 imw = mInputMethodDialogs.get(di);
1047 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001048 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 + " anim layer: " + imw.mAnimLayer);
1050 }
1051 }
Romain Guy06882f82009-06-10 13:36:04 -07001052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001053 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1054 int wpos = mWindows.indexOf(win);
1055 if (wpos >= 0) {
1056 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001057 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 mWindows.remove(wpos);
1059 int NC = win.mChildWindows.size();
1060 while (NC > 0) {
1061 NC--;
1062 WindowState cw = (WindowState)win.mChildWindows.get(NC);
1063 int cpos = mWindows.indexOf(cw);
1064 if (cpos >= 0) {
1065 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001066 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001067 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 mWindows.remove(cpos);
1069 }
1070 }
1071 }
1072 return interestingPos;
1073 }
Romain Guy06882f82009-06-10 13:36:04 -07001074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001075 private void reAddWindowToListInOrderLocked(WindowState win) {
1076 addWindowToListInOrderLocked(win, false);
1077 // This is a hack to get all of the child windows added as well
1078 // at the right position. Child windows should be rare and
1079 // this case should be rare, so it shouldn't be that big a deal.
1080 int wpos = mWindows.indexOf(win);
1081 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001082 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001083 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084 mWindows.remove(wpos);
1085 reAddWindowLocked(wpos, win);
1086 }
1087 }
Romain Guy06882f82009-06-10 13:36:04 -07001088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 void logWindowList(String prefix) {
1090 int N = mWindows.size();
1091 while (N > 0) {
1092 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001093 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 }
1095 }
Romain Guy06882f82009-06-10 13:36:04 -07001096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001097 void moveInputMethodDialogsLocked(int pos) {
1098 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001101 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001102 for (int i=0; i<N; i++) {
1103 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1104 }
1105 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001106 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 logWindowList(" ");
1108 }
Romain Guy06882f82009-06-10 13:36:04 -07001109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001110 if (pos >= 0) {
1111 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1112 if (pos < mWindows.size()) {
1113 WindowState wp = (WindowState)mWindows.get(pos);
1114 if (wp == mInputMethodWindow) {
1115 pos++;
1116 }
1117 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001118 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119 for (int i=0; i<N; i++) {
1120 WindowState win = dialogs.get(i);
1121 win.mTargetAppToken = targetAppToken;
1122 pos = reAddWindowLocked(pos, win);
1123 }
1124 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001125 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001126 logWindowList(" ");
1127 }
1128 return;
1129 }
1130 for (int i=0; i<N; i++) {
1131 WindowState win = dialogs.get(i);
1132 win.mTargetAppToken = null;
1133 reAddWindowToListInOrderLocked(win);
1134 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001135 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 logWindowList(" ");
1137 }
1138 }
1139 }
Romain Guy06882f82009-06-10 13:36:04 -07001140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1142 final WindowState imWin = mInputMethodWindow;
1143 final int DN = mInputMethodDialogs.size();
1144 if (imWin == null && DN == 0) {
1145 return false;
1146 }
Romain Guy06882f82009-06-10 13:36:04 -07001147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1149 if (imPos >= 0) {
1150 // In this case, the input method windows are to be placed
1151 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001153 // First check to see if the input method windows are already
1154 // located here, and contiguous.
1155 final int N = mWindows.size();
1156 WindowState firstImWin = imPos < N
1157 ? (WindowState)mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 // Figure out the actual input method window that should be
1160 // at the bottom of their stack.
1161 WindowState baseImWin = imWin != null
1162 ? imWin : mInputMethodDialogs.get(0);
1163 if (baseImWin.mChildWindows.size() > 0) {
1164 WindowState cw = (WindowState)baseImWin.mChildWindows.get(0);
1165 if (cw.mSubLayer < 0) baseImWin = cw;
1166 }
Romain Guy06882f82009-06-10 13:36:04 -07001167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001168 if (firstImWin == baseImWin) {
1169 // The windows haven't moved... but are they still contiguous?
1170 // First find the top IM window.
1171 int pos = imPos+1;
1172 while (pos < N) {
1173 if (!((WindowState)mWindows.get(pos)).mIsImWindow) {
1174 break;
1175 }
1176 pos++;
1177 }
1178 pos++;
1179 // Now there should be no more input method windows above.
1180 while (pos < N) {
1181 if (((WindowState)mWindows.get(pos)).mIsImWindow) {
1182 break;
1183 }
1184 pos++;
1185 }
1186 if (pos >= N) {
1187 // All is good!
1188 return false;
1189 }
1190 }
Romain Guy06882f82009-06-10 13:36:04 -07001191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001192 if (imWin != null) {
1193 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001194 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001195 logWindowList(" ");
1196 }
1197 imPos = tmpRemoveWindowLocked(imPos, imWin);
1198 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001199 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001200 logWindowList(" ");
1201 }
1202 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1203 reAddWindowLocked(imPos, imWin);
1204 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001205 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001206 logWindowList(" ");
1207 }
1208 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1209 } else {
1210 moveInputMethodDialogsLocked(imPos);
1211 }
Romain Guy06882f82009-06-10 13:36:04 -07001212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001213 } else {
1214 // In this case, the input method windows go in a fixed layer,
1215 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001218 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001219 tmpRemoveWindowLocked(0, imWin);
1220 imWin.mTargetAppToken = null;
1221 reAddWindowToListInOrderLocked(imWin);
1222 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001223 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 logWindowList(" ");
1225 }
1226 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1227 } else {
1228 moveInputMethodDialogsLocked(-1);;
1229 }
Romain Guy06882f82009-06-10 13:36:04 -07001230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001231 }
Romain Guy06882f82009-06-10 13:36:04 -07001232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001233 if (needAssignLayers) {
1234 assignLayersLocked();
1235 }
Romain Guy06882f82009-06-10 13:36:04 -07001236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001237 return true;
1238 }
Romain Guy06882f82009-06-10 13:36:04 -07001239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001240 void adjustInputMethodDialogsLocked() {
1241 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1242 }
Romain Guy06882f82009-06-10 13:36:04 -07001243
Dianne Hackborn25994b42009-09-04 14:21:19 -07001244 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001245 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001246 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1247 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1248 ? wallpaperTarget.mAppToken.animation : null)
1249 + " upper=" + mUpperWallpaperTarget
1250 + " lower=" + mLowerWallpaperTarget);
1251 return (wallpaperTarget != null
1252 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1253 && wallpaperTarget.mAppToken.animation != null)))
1254 || mUpperWallpaperTarget != null
1255 || mLowerWallpaperTarget != null;
1256 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001257
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001258 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1259 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001260
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001261 int adjustWallpaperWindowsLocked() {
1262 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001263
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001264 final int dw = mDisplay.getWidth();
1265 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001266
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001267 // First find top-most window that has asked to be on top of the
1268 // wallpaper; all wallpapers go behind it.
1269 final ArrayList localmWindows = mWindows;
1270 int N = localmWindows.size();
1271 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001272 WindowState foundW = null;
1273 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001274 WindowState topCurW = null;
1275 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001276 int i = N;
1277 while (i > 0) {
1278 i--;
1279 w = (WindowState)localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001280 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1281 if (topCurW == null) {
1282 topCurW = w;
1283 topCurI = i;
1284 }
1285 continue;
1286 }
1287 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001288 if (w.mAppToken != null) {
1289 // If this window's app token is hidden and not animating,
1290 // it is of no interest to us.
1291 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001292 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001293 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001294 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001295 continue;
1296 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001297 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001298 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001299 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1300 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001301 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001302 && (mWallpaperTarget == w
1303 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001304 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001305 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001306 foundW = w;
1307 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001308 if (w == mWallpaperTarget && ((w.mAppToken != null
1309 && w.mAppToken.animation != null)
1310 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001311 // The current wallpaper target is animating, so we'll
1312 // look behind it for another possible target and figure
1313 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001314 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001315 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001316 continue;
1317 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001318 break;
1319 }
1320 }
1321
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001322 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001323 // If we are currently waiting for an app transition, and either
1324 // the current target or the next target are involved with it,
1325 // then hold off on doing anything with the wallpaper.
1326 // Note that we are checking here for just whether the target
1327 // is part of an app token... which is potentially overly aggressive
1328 // (the app token may not be involved in the transition), but good
1329 // enough (we'll just wait until whatever transition is pending
1330 // executes).
1331 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001332 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001333 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001334 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001335 }
1336 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001337 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001338 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001339 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001340 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001341 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001342
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001343 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001344 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001345 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001346 + " oldTarget: " + mWallpaperTarget);
1347 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001348
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001349 mLowerWallpaperTarget = null;
1350 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001351
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001352 WindowState oldW = mWallpaperTarget;
1353 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001354
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001355 // Now what is happening... if the current and new targets are
1356 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001357 if (foundW != null && oldW != null) {
1358 boolean oldAnim = oldW.mAnimation != null
1359 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1360 boolean foundAnim = foundW.mAnimation != null
1361 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001362 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001363 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001364 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001365 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001366 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001367 int oldI = localmWindows.indexOf(oldW);
1368 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001369 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001370 }
1371 if (oldI >= 0) {
1372 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001373 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001374 + "=" + oldW + "; new#" + foundI
1375 + "=" + foundW);
1376 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001377
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001378 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001379 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001380 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001381 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001382 }
1383 mWallpaperTarget = oldW;
1384 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001385
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001386 // Now set the upper and lower wallpaper targets
1387 // correctly, and make sure that we are positioning
1388 // the wallpaper below the lower.
1389 if (foundI > oldI) {
1390 // The new target is on top of the old one.
1391 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001392 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001393 }
1394 mUpperWallpaperTarget = foundW;
1395 mLowerWallpaperTarget = oldW;
1396 foundW = oldW;
1397 foundI = oldI;
1398 } else {
1399 // The new target is below the old one.
1400 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001401 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001402 }
1403 mUpperWallpaperTarget = oldW;
1404 mLowerWallpaperTarget = foundW;
1405 }
1406 }
1407 }
1408 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001409
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001410 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001411 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001412 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1413 || (mLowerWallpaperTarget.mAppToken != null
1414 && mLowerWallpaperTarget.mAppToken.animation != null);
1415 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1416 || (mUpperWallpaperTarget.mAppToken != null
1417 && mUpperWallpaperTarget.mAppToken.animation != null);
1418 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001419 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001420 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001421 }
1422 mLowerWallpaperTarget = null;
1423 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001424 }
1425 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001426
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001427 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001428 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001429 // The window is visible to the compositor... but is it visible
1430 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001431 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001432 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001433
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001434 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001435 // its layer adjustment. Only do this if we are not transfering
1436 // between two wallpaper targets.
1437 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001438 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001439 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001440
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001441 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1442 * TYPE_LAYER_MULTIPLIER
1443 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001444
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001445 // Now w is the window we are supposed to be behind... but we
1446 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001447 // AND any starting window associated with it, AND below the
1448 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001449 while (foundI > 0) {
1450 WindowState wb = (WindowState)localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001451 if (wb.mBaseLayer < maxLayer &&
1452 wb.mAttachedWindow != foundW &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001453 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001454 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001455 // This window is not related to the previous one in any
1456 // interesting way, so stop here.
1457 break;
1458 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001459 foundW = wb;
1460 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001461 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001462 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001463 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001464 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001465
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001466 if (foundW == null && topCurW != null) {
1467 // There is no wallpaper target, so it goes at the bottom.
1468 // We will assume it is the same place as last time, if known.
1469 foundW = topCurW;
1470 foundI = topCurI+1;
1471 } else {
1472 // Okay i is the position immediately above the wallpaper. Look at
1473 // what is below it for later.
1474 foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null;
1475 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001476
Dianne Hackborn284ac932009-08-28 10:34:25 -07001477 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001478 if (mWallpaperTarget.mWallpaperX >= 0) {
1479 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001480 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001481 }
1482 if (mWallpaperTarget.mWallpaperY >= 0) {
1483 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001484 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001485 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001486 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001487
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001488 // Start stepping backwards from here, ensuring that our wallpaper windows
1489 // are correctly placed.
1490 int curTokenIndex = mWallpaperTokens.size();
1491 while (curTokenIndex > 0) {
1492 curTokenIndex--;
1493 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001494 if (token.hidden == visible) {
1495 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1496 token.hidden = !visible;
1497 // Need to do a layout to ensure the wallpaper now has the
1498 // correct size.
1499 mLayoutNeeded = true;
1500 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001501
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001502 int curWallpaperIndex = token.windows.size();
1503 while (curWallpaperIndex > 0) {
1504 curWallpaperIndex--;
1505 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001506
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001507 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001508 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001509 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001510
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001511 // First, make sure the client has the current visibility
1512 // state.
1513 if (wallpaper.mWallpaperVisible != visible) {
1514 wallpaper.mWallpaperVisible = visible;
1515 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001516 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001517 "Setting visibility of wallpaper " + wallpaper
1518 + ": " + visible);
1519 wallpaper.mClient.dispatchAppVisibility(visible);
1520 } catch (RemoteException e) {
1521 }
1522 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001523
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001524 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001525 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001526 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001527
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001528 // First, if this window is at the current index, then all
1529 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001530 if (wallpaper == foundW) {
1531 foundI--;
1532 foundW = foundI > 0
1533 ? (WindowState)localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001534 continue;
1535 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001536
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001537 // The window didn't match... the current wallpaper window,
1538 // wherever it is, is in the wrong place, so make sure it is
1539 // not in the list.
1540 int oldIndex = localmWindows.indexOf(wallpaper);
1541 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001542 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001543 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001544 localmWindows.remove(oldIndex);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001545 if (oldIndex < foundI) {
1546 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001547 }
1548 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001549
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001550 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001551 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001552 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001553 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001554
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001555 localmWindows.add(foundI, wallpaper);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001556 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001557 }
1558 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001559
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001560 return changed;
1561 }
1562
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001563 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001564 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001565 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001566 mWallpaperAnimLayerAdjustment = adj;
1567 int curTokenIndex = mWallpaperTokens.size();
1568 while (curTokenIndex > 0) {
1569 curTokenIndex--;
1570 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1571 int curWallpaperIndex = token.windows.size();
1572 while (curWallpaperIndex > 0) {
1573 curWallpaperIndex--;
1574 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1575 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001576 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001577 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001578 }
1579 }
1580 }
1581
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001582 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1583 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001584 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001585 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001586 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001587 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001588 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1589 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1590 changed = wallpaperWin.mXOffset != offset;
1591 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001592 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001593 + wallpaperWin + " x: " + offset);
1594 wallpaperWin.mXOffset = offset;
1595 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001596 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001597 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001598 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001599 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001600 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001601
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001602 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001603 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001604 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1605 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1606 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001607 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001608 + wallpaperWin + " y: " + offset);
1609 changed = true;
1610 wallpaperWin.mYOffset = offset;
1611 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001612 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001613 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001614 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001615 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001616 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001617
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001618 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001619 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001620 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001621 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1622 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001623 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001624 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001625 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001626 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001627 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1628 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001629 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001630 if (mWaitingOnWallpaper != null) {
1631 long start = SystemClock.uptimeMillis();
1632 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1633 < start) {
1634 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001635 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001636 "Waiting for offset complete...");
1637 mWindowMap.wait(WALLPAPER_TIMEOUT);
1638 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001639 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001640 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001641 if ((start+WALLPAPER_TIMEOUT)
1642 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001643 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001644 + wallpaperWin);
1645 mLastWallpaperTimeoutTime = start;
1646 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001647 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001648 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001649 }
1650 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001651 } catch (RemoteException e) {
1652 }
1653 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001654
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001655 return changed;
1656 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001657
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001658 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001659 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001660 if (mWaitingOnWallpaper != null &&
1661 mWaitingOnWallpaper.mClient.asBinder() == window) {
1662 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001663 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001664 }
1665 }
1666 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001667
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001668 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001669 final int dw = mDisplay.getWidth();
1670 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001671
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001672 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001673
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001674 WindowState target = mWallpaperTarget;
1675 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001676 if (target.mWallpaperX >= 0) {
1677 mLastWallpaperX = target.mWallpaperX;
1678 } else if (changingTarget.mWallpaperX >= 0) {
1679 mLastWallpaperX = changingTarget.mWallpaperX;
1680 }
1681 if (target.mWallpaperY >= 0) {
1682 mLastWallpaperY = target.mWallpaperY;
1683 } else if (changingTarget.mWallpaperY >= 0) {
1684 mLastWallpaperY = changingTarget.mWallpaperY;
1685 }
1686 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001687
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001688 int curTokenIndex = mWallpaperTokens.size();
1689 while (curTokenIndex > 0) {
1690 curTokenIndex--;
1691 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1692 int curWallpaperIndex = token.windows.size();
1693 while (curWallpaperIndex > 0) {
1694 curWallpaperIndex--;
1695 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1696 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1697 wallpaper.computeShownFrameLocked();
1698 changed = true;
1699 // We only want to be synchronous with one wallpaper.
1700 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001701 }
1702 }
1703 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001704
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001705 return changed;
1706 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001707
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001708 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001709 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001710 final int dw = mDisplay.getWidth();
1711 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001712
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001713 int curTokenIndex = mWallpaperTokens.size();
1714 while (curTokenIndex > 0) {
1715 curTokenIndex--;
1716 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001717 if (token.hidden == visible) {
1718 token.hidden = !visible;
1719 // Need to do a layout to ensure the wallpaper now has the
1720 // correct size.
1721 mLayoutNeeded = true;
1722 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001723
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001724 int curWallpaperIndex = token.windows.size();
1725 while (curWallpaperIndex > 0) {
1726 curWallpaperIndex--;
1727 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1728 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001729 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001730 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001731
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001732 if (wallpaper.mWallpaperVisible != visible) {
1733 wallpaper.mWallpaperVisible = visible;
1734 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001735 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001736 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001737 + ": " + visible);
1738 wallpaper.mClient.dispatchAppVisibility(visible);
1739 } catch (RemoteException e) {
1740 }
1741 }
1742 }
1743 }
1744 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001745
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001746 void sendPointerToWallpaperLocked(WindowState srcWin,
1747 MotionEvent pointer, long eventTime) {
1748 int curTokenIndex = mWallpaperTokens.size();
1749 while (curTokenIndex > 0) {
1750 curTokenIndex--;
1751 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1752 int curWallpaperIndex = token.windows.size();
1753 while (curWallpaperIndex > 0) {
1754 curWallpaperIndex--;
1755 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1756 if ((wallpaper.mAttrs.flags &
1757 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
1758 continue;
1759 }
1760 try {
1761 MotionEvent ev = MotionEvent.obtainNoHistory(pointer);
Dianne Hackborn6adba242009-11-10 11:10:09 -08001762 if (srcWin != null) {
1763 ev.offsetLocation(srcWin.mFrame.left-wallpaper.mFrame.left,
1764 srcWin.mFrame.top-wallpaper.mFrame.top);
1765 } else {
1766 ev.offsetLocation(-wallpaper.mFrame.left, -wallpaper.mFrame.top);
1767 }
1768 switch (pointer.getAction()) {
1769 case MotionEvent.ACTION_DOWN:
1770 mSendingPointersToWallpaper = true;
1771 break;
1772 case MotionEvent.ACTION_UP:
1773 mSendingPointersToWallpaper = false;
1774 break;
1775 }
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001776 wallpaper.mClient.dispatchPointer(ev, eventTime, false);
1777 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001778 Slog.w(TAG, "Failure sending pointer to wallpaper", e);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001779 }
1780 }
1781 }
1782 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001783
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001784 void dispatchPointerElsewhereLocked(WindowState srcWin, WindowState relWin,
1785 MotionEvent pointer, long eventTime, boolean skipped) {
1786 if (relWin != null) {
1787 mPolicy.dispatchedPointerEventLw(pointer, relWin.mFrame.left, relWin.mFrame.top);
1788 } else {
1789 mPolicy.dispatchedPointerEventLw(pointer, 0, 0);
1790 }
1791
1792 // If we sent an initial down to the wallpaper, then continue
1793 // sending events until the final up.
1794 if (mSendingPointersToWallpaper) {
1795 if (skipped) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001796 Slog.i(TAG, "Sending skipped pointer to wallpaper!");
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001797 }
1798 sendPointerToWallpaperLocked(relWin, pointer, eventTime);
1799
1800 // If we are on top of the wallpaper, then the wallpaper also
1801 // gets to see this movement.
1802 } else if (srcWin != null
1803 && pointer.getAction() == MotionEvent.ACTION_DOWN
1804 && mWallpaperTarget == srcWin
1805 && srcWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) {
1806 sendPointerToWallpaperLocked(relWin, pointer, eventTime);
1807 }
1808 }
1809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001810 public int addWindow(Session session, IWindow client,
1811 WindowManager.LayoutParams attrs, int viewVisibility,
1812 Rect outContentInsets) {
1813 int res = mPolicy.checkAddPermission(attrs);
1814 if (res != WindowManagerImpl.ADD_OKAY) {
1815 return res;
1816 }
Romain Guy06882f82009-06-10 13:36:04 -07001817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001818 boolean reportNewConfig = false;
1819 WindowState attachedWindow = null;
1820 WindowState win = null;
Romain Guy06882f82009-06-10 13:36:04 -07001821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001822 synchronized(mWindowMap) {
1823 // Instantiating a Display requires talking with the simulator,
1824 // so don't do it until we know the system is mostly up and
1825 // running.
1826 if (mDisplay == null) {
1827 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1828 mDisplay = wm.getDefaultDisplay();
1829 mQueue.setDisplay(mDisplay);
1830 reportNewConfig = true;
1831 }
Romain Guy06882f82009-06-10 13:36:04 -07001832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001833 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001834 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001835 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1836 }
1837
1838 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001839 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001840 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001841 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001842 + attrs.token + ". Aborting.");
1843 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1844 }
1845 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1846 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001847 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001848 + attrs.token + ". Aborting.");
1849 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1850 }
1851 }
1852
1853 boolean addToken = false;
1854 WindowToken token = mTokenMap.get(attrs.token);
1855 if (token == null) {
1856 if (attrs.type >= FIRST_APPLICATION_WINDOW
1857 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001858 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001859 + attrs.token + ". Aborting.");
1860 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1861 }
1862 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001863 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001864 + attrs.token + ". Aborting.");
1865 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1866 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001867 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001868 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001869 + attrs.token + ". Aborting.");
1870 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1871 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001872 token = new WindowToken(attrs.token, -1, false);
1873 addToken = true;
1874 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1875 && attrs.type <= LAST_APPLICATION_WINDOW) {
1876 AppWindowToken atoken = token.appWindowToken;
1877 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001878 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001879 + token + ". Aborting.");
1880 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1881 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001882 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001883 + token + ". Aborting.");
1884 return WindowManagerImpl.ADD_APP_EXITING;
1885 }
1886 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1887 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001888 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001889 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1890 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1891 }
1892 } else if (attrs.type == TYPE_INPUT_METHOD) {
1893 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001894 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001895 + attrs.token + ". Aborting.");
1896 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1897 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001898 } else if (attrs.type == TYPE_WALLPAPER) {
1899 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001900 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001901 + attrs.token + ". Aborting.");
1902 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1903 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001904 }
1905
1906 win = new WindowState(session, client, token,
1907 attachedWindow, attrs, viewVisibility);
1908 if (win.mDeathRecipient == null) {
1909 // Client has apparently died, so there is no reason to
1910 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001911 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001912 + " that is dead, aborting.");
1913 return WindowManagerImpl.ADD_APP_EXITING;
1914 }
1915
1916 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001918 res = mPolicy.prepareAddWindowLw(win, attrs);
1919 if (res != WindowManagerImpl.ADD_OKAY) {
1920 return res;
1921 }
1922
1923 // From now on, no exceptions or errors allowed!
1924
1925 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001927 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001929 if (addToken) {
1930 mTokenMap.put(attrs.token, token);
1931 mTokenList.add(token);
1932 }
1933 win.attach();
1934 mWindowMap.put(client.asBinder(), win);
1935
1936 if (attrs.type == TYPE_APPLICATION_STARTING &&
1937 token.appWindowToken != null) {
1938 token.appWindowToken.startingWindow = win;
1939 }
1940
1941 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001943 if (attrs.type == TYPE_INPUT_METHOD) {
1944 mInputMethodWindow = win;
1945 addInputMethodWindowToListLocked(win);
1946 imMayMove = false;
1947 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1948 mInputMethodDialogs.add(win);
1949 addWindowToListInOrderLocked(win, true);
1950 adjustInputMethodDialogsLocked();
1951 imMayMove = false;
1952 } else {
1953 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001954 if (attrs.type == TYPE_WALLPAPER) {
1955 mLastWallpaperTimeoutTime = 0;
1956 adjustWallpaperWindowsLocked();
1957 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001958 adjustWallpaperWindowsLocked();
1959 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001960 }
Romain Guy06882f82009-06-10 13:36:04 -07001961
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001962 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001964 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001966 if (mInTouchMode) {
1967 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1968 }
1969 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1970 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1971 }
Romain Guy06882f82009-06-10 13:36:04 -07001972
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001973 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001974 if (win.canReceiveKeys()) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001975 if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS))
1976 == true) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001977 imMayMove = false;
1978 }
1979 }
Romain Guy06882f82009-06-10 13:36:04 -07001980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001981 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001982 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001983 }
Romain Guy06882f82009-06-10 13:36:04 -07001984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001985 assignLayersLocked();
1986 // Don't do layout here, the window must call
1987 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07001988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001989 //dump();
1990
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001991 if (focusChanged) {
1992 if (mCurrentFocus != null) {
1993 mKeyWaiter.handleNewWindowLocked(mCurrentFocus);
1994 }
1995 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001996 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001997 TAG, "New client " + client.asBinder()
1998 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001999
2000 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2001 reportNewConfig = true;
2002 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002003 }
2004
2005 // sendNewConfiguration() checks caller permissions so we must call it with
2006 // privilege. updateOrientationFromAppTokens() clears and resets the caller
2007 // identity anyway, so it's safe to just clear & restore around this whole
2008 // block.
2009 final long origId = Binder.clearCallingIdentity();
2010 if (reportNewConfig) {
2011 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002012 }
2013 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002015 return res;
2016 }
Romain Guy06882f82009-06-10 13:36:04 -07002017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002018 public void removeWindow(Session session, IWindow client) {
2019 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002020 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002021 if (win == null) {
2022 return;
2023 }
2024 removeWindowLocked(session, win);
2025 }
2026 }
Romain Guy06882f82009-06-10 13:36:04 -07002027
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002028 public void removeWindowLocked(Session session, WindowState win) {
2029
Joe Onorato8a9b2202010-02-26 18:56:32 -08002030 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002031 TAG, "Remove " + win + " client="
2032 + Integer.toHexString(System.identityHashCode(
2033 win.mClient.asBinder()))
2034 + ", surface=" + win.mSurface);
2035
2036 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002037
Joe Onorato8a9b2202010-02-26 18:56:32 -08002038 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002039 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2040 + " mExiting=" + win.mExiting
2041 + " isAnimating=" + win.isAnimating()
2042 + " app-animation="
2043 + (win.mAppToken != null ? win.mAppToken.animation : null)
2044 + " inPendingTransaction="
2045 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2046 + " mDisplayFrozen=" + mDisplayFrozen);
2047 // Visibility of the removed window. Will be used later to update orientation later on.
2048 boolean wasVisible = false;
2049 // First, see if we need to run an animation. If we do, we have
2050 // to hold off on removing the window until the animation is done.
2051 // If the display is frozen, just remove immediately, since the
2052 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002053 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002054 // If we are not currently running the exit animation, we
2055 // need to see about starting one.
2056 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002058 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2059 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2060 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2061 }
2062 // Try starting an animation.
2063 if (applyAnimationLocked(win, transit, false)) {
2064 win.mExiting = true;
2065 }
2066 }
2067 if (win.mExiting || win.isAnimating()) {
2068 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002069 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002070 win.mExiting = true;
2071 win.mRemoveOnExit = true;
2072 mLayoutNeeded = true;
2073 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2074 performLayoutAndPlaceSurfacesLocked();
2075 if (win.mAppToken != null) {
2076 win.mAppToken.updateReportedVisibilityLocked();
2077 }
2078 //dump();
2079 Binder.restoreCallingIdentity(origId);
2080 return;
2081 }
2082 }
2083
2084 removeWindowInnerLocked(session, win);
2085 // Removing a visible window will effect the computed orientation
2086 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002087 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002088 != mForcedAppOrientation
2089 && updateOrientationFromAppTokensLocked()) {
2090 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002091 }
2092 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2093 Binder.restoreCallingIdentity(origId);
2094 }
Romain Guy06882f82009-06-10 13:36:04 -07002095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002096 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07002097 mKeyWaiter.finishedKey(session, win.mClient, true,
2098 KeyWaiter.RETURN_NOTHING);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002099 mKeyWaiter.releasePendingPointerLocked(win.mSession);
2100 mKeyWaiter.releasePendingTrackballLocked(win.mSession);
Romain Guy06882f82009-06-10 13:36:04 -07002101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002102 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002104 if (mInputMethodTarget == win) {
2105 moveInputMethodWindowsIfNeededLocked(false);
2106 }
Romain Guy06882f82009-06-10 13:36:04 -07002107
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002108 if (false) {
2109 RuntimeException e = new RuntimeException("here");
2110 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002111 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002112 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002114 mPolicy.removeWindowLw(win);
2115 win.removeLocked();
2116
2117 mWindowMap.remove(win.mClient.asBinder());
2118 mWindows.remove(win);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002119 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002120
2121 if (mInputMethodWindow == win) {
2122 mInputMethodWindow = null;
2123 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2124 mInputMethodDialogs.remove(win);
2125 }
Romain Guy06882f82009-06-10 13:36:04 -07002126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002127 final WindowToken token = win.mToken;
2128 final AppWindowToken atoken = win.mAppToken;
2129 token.windows.remove(win);
2130 if (atoken != null) {
2131 atoken.allAppWindows.remove(win);
2132 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002133 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002134 TAG, "**** Removing window " + win + ": count="
2135 + token.windows.size());
2136 if (token.windows.size() == 0) {
2137 if (!token.explicit) {
2138 mTokenMap.remove(token.token);
2139 mTokenList.remove(token);
2140 } else if (atoken != null) {
2141 atoken.firstWindowDrawn = false;
2142 }
2143 }
2144
2145 if (atoken != null) {
2146 if (atoken.startingWindow == win) {
2147 atoken.startingWindow = null;
2148 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2149 // If this is the last window and we had requested a starting
2150 // transition window, well there is no point now.
2151 atoken.startingData = null;
2152 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2153 // If this is the last window except for a starting transition
2154 // window, we need to get rid of the starting transition.
2155 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002156 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002157 + ": no more real windows");
2158 }
2159 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2160 mH.sendMessage(m);
2161 }
2162 }
Romain Guy06882f82009-06-10 13:36:04 -07002163
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002164 if (win.mAttrs.type == TYPE_WALLPAPER) {
2165 mLastWallpaperTimeoutTime = 0;
2166 adjustWallpaperWindowsLocked();
2167 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002168 adjustWallpaperWindowsLocked();
2169 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002171 if (!mInLayout) {
2172 assignLayersLocked();
2173 mLayoutNeeded = true;
2174 performLayoutAndPlaceSurfacesLocked();
2175 if (win.mAppToken != null) {
2176 win.mAppToken.updateReportedVisibilityLocked();
2177 }
2178 }
2179 }
2180
2181 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2182 long origId = Binder.clearCallingIdentity();
2183 try {
2184 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002185 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002186 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002187 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002188 Surface.openTransaction();
2189 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002190 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002191 TAG, " SURFACE " + w.mSurface
2192 + ": transparentRegionHint=" + region);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002193 w.mSurface.setTransparentRegionHint(region);
2194 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002195 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002196 Surface.closeTransaction();
2197 }
2198 }
2199 }
2200 } finally {
2201 Binder.restoreCallingIdentity(origId);
2202 }
2203 }
2204
2205 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002206 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002207 Rect visibleInsets) {
2208 long origId = Binder.clearCallingIdentity();
2209 try {
2210 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002211 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002212 if (w != null) {
2213 w.mGivenInsetsPending = false;
2214 w.mGivenContentInsets.set(contentInsets);
2215 w.mGivenVisibleInsets.set(visibleInsets);
2216 w.mTouchableInsets = touchableInsets;
2217 mLayoutNeeded = true;
2218 performLayoutAndPlaceSurfacesLocked();
2219 }
2220 }
2221 } finally {
2222 Binder.restoreCallingIdentity(origId);
2223 }
2224 }
Romain Guy06882f82009-06-10 13:36:04 -07002225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002226 public void getWindowDisplayFrame(Session session, IWindow client,
2227 Rect outDisplayFrame) {
2228 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002229 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002230 if (win == null) {
2231 outDisplayFrame.setEmpty();
2232 return;
2233 }
2234 outDisplayFrame.set(win.mDisplayFrame);
2235 }
2236 }
2237
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002238 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2239 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002240 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2241 window.mWallpaperX = x;
2242 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002243 window.mWallpaperXStep = xStep;
2244 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002245 if (updateWallpaperOffsetLocked(window, true)) {
2246 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002247 }
2248 }
2249 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002250
Dianne Hackborn75804932009-10-20 20:15:20 -07002251 void wallpaperCommandComplete(IBinder window, Bundle result) {
2252 synchronized (mWindowMap) {
2253 if (mWaitingOnWallpaper != null &&
2254 mWaitingOnWallpaper.mClient.asBinder() == window) {
2255 mWaitingOnWallpaper = null;
2256 mWindowMap.notifyAll();
2257 }
2258 }
2259 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002260
Dianne Hackborn75804932009-10-20 20:15:20 -07002261 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2262 String action, int x, int y, int z, Bundle extras, boolean sync) {
2263 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2264 || window == mUpperWallpaperTarget) {
2265 boolean doWait = sync;
2266 int curTokenIndex = mWallpaperTokens.size();
2267 while (curTokenIndex > 0) {
2268 curTokenIndex--;
2269 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2270 int curWallpaperIndex = token.windows.size();
2271 while (curWallpaperIndex > 0) {
2272 curWallpaperIndex--;
2273 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2274 try {
2275 wallpaper.mClient.dispatchWallpaperCommand(action,
2276 x, y, z, extras, sync);
2277 // We only want to be synchronous with one wallpaper.
2278 sync = false;
2279 } catch (RemoteException e) {
2280 }
2281 }
2282 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002283
Dianne Hackborn75804932009-10-20 20:15:20 -07002284 if (doWait) {
2285 // XXX Need to wait for result.
2286 }
2287 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002288
Dianne Hackborn75804932009-10-20 20:15:20 -07002289 return null;
2290 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002292 public int relayoutWindow(Session session, IWindow client,
2293 WindowManager.LayoutParams attrs, int requestedWidth,
2294 int requestedHeight, int viewVisibility, boolean insetsPending,
2295 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
2296 Surface outSurface) {
2297 boolean displayed = false;
2298 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002299 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002300 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002302 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002303 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002304 if (win == null) {
2305 return 0;
2306 }
2307 win.mRequestedWidth = requestedWidth;
2308 win.mRequestedHeight = requestedHeight;
2309
2310 if (attrs != null) {
2311 mPolicy.adjustWindowParamsLw(attrs);
2312 }
Romain Guy06882f82009-06-10 13:36:04 -07002313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002314 int attrChanges = 0;
2315 int flagChanges = 0;
2316 if (attrs != null) {
2317 flagChanges = win.mAttrs.flags ^= attrs.flags;
2318 attrChanges = win.mAttrs.copyFrom(attrs);
2319 }
2320
Joe Onorato8a9b2202010-02-26 18:56:32 -08002321 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002322
2323 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2324 win.mAlpha = attrs.alpha;
2325 }
2326
2327 final boolean scaledWindow =
2328 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2329
2330 if (scaledWindow) {
2331 // requested{Width|Height} Surface's physical size
2332 // attrs.{width|height} Size on screen
2333 win.mHScale = (attrs.width != requestedWidth) ?
2334 (attrs.width / (float)requestedWidth) : 1.0f;
2335 win.mVScale = (attrs.height != requestedHeight) ?
2336 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002337 } else {
2338 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002339 }
2340
2341 boolean imMayMove = (flagChanges&(
2342 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2343 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002345 boolean focusMayChange = win.mViewVisibility != viewVisibility
2346 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2347 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002348
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002349 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2350 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002352 win.mRelayoutCalled = true;
2353 final int oldVisibility = win.mViewVisibility;
2354 win.mViewVisibility = viewVisibility;
2355 if (viewVisibility == View.VISIBLE &&
2356 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2357 displayed = !win.isVisibleLw();
2358 if (win.mExiting) {
2359 win.mExiting = false;
2360 win.mAnimation = null;
2361 }
2362 if (win.mDestroying) {
2363 win.mDestroying = false;
2364 mDestroySurface.remove(win);
2365 }
2366 if (oldVisibility == View.GONE) {
2367 win.mEnterAnimationPending = true;
2368 }
2369 if (displayed && win.mSurface != null && !win.mDrawPending
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002370 && !win.mCommitDrawPending && !mDisplayFrozen
2371 && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002372 applyEnterAnimationLocked(win);
2373 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002374 if (displayed && (win.mAttrs.flags
2375 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08002376 if (DEBUG_VISIBILITY) Slog.v(TAG,
2377 "Relayout window turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002378 win.mTurnOnScreen = true;
2379 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002380 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2381 // To change the format, we need to re-build the surface.
2382 win.destroySurfaceLocked();
2383 displayed = true;
2384 }
2385 try {
2386 Surface surface = win.createSurfaceLocked();
2387 if (surface != null) {
2388 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002389 win.mReportDestroySurface = false;
2390 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002391 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002392 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002393 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002394 // For some reason there isn't a surface. Clear the
2395 // caller's object so they see the same state.
2396 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002397 }
2398 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002399 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002400 + client + " (" + win.mAttrs.getTitle() + ")",
2401 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002402 Binder.restoreCallingIdentity(origId);
2403 return 0;
2404 }
2405 if (displayed) {
2406 focusMayChange = true;
2407 }
2408 if (win.mAttrs.type == TYPE_INPUT_METHOD
2409 && mInputMethodWindow == null) {
2410 mInputMethodWindow = win;
2411 imMayMove = true;
2412 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002413 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2414 && win.mAppToken != null
2415 && win.mAppToken.startingWindow != null) {
2416 // Special handling of starting window over the base
2417 // window of the app: propagate lock screen flags to it,
2418 // to provide the correct semantics while starting.
2419 final int mask =
2420 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002421 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2422 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002423 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2424 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2425 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002426 } else {
2427 win.mEnterAnimationPending = false;
2428 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002429 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002430 + ": mExiting=" + win.mExiting
2431 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002432 // If we are not currently running the exit animation, we
2433 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002434 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002435 // Try starting an animation; if there isn't one, we
2436 // can destroy the surface right away.
2437 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2438 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2439 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2440 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002441 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002442 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002443 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002444 win.mExiting = true;
2445 mKeyWaiter.finishedKey(session, client, true,
2446 KeyWaiter.RETURN_NOTHING);
2447 } else if (win.isAnimating()) {
2448 // Currently in a hide animation... turn this into
2449 // an exit.
2450 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002451 } else if (win == mWallpaperTarget) {
2452 // If the wallpaper is currently behind this
2453 // window, we need to change both of them inside
2454 // of a transaction to avoid artifacts.
2455 win.mExiting = true;
2456 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002457 } else {
2458 if (mInputMethodWindow == win) {
2459 mInputMethodWindow = null;
2460 }
2461 win.destroySurfaceLocked();
2462 }
2463 }
2464 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002465
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002466 if (win.mSurface == null || (win.getAttrs().flags
2467 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2468 || win.mSurfacePendingDestroy) {
2469 // We are being called from a local process, which
2470 // means outSurface holds its current surface. Ensure the
2471 // surface object is cleared, but we don't want it actually
2472 // destroyed at this point.
2473 win.mSurfacePendingDestroy = false;
2474 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002475 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002476 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002477 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002478 "Keeping surface, will report destroy: " + win);
2479 win.mReportDestroySurface = true;
2480 outSurface.copyFrom(win.mSurface);
2481 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002482 }
2483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002484 if (focusMayChange) {
2485 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2486 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 imMayMove = false;
2488 }
2489 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2490 }
Romain Guy06882f82009-06-10 13:36:04 -07002491
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002492 // updateFocusedWindowLocked() already assigned layers so we only need to
2493 // reassign them at this point if the IM window state gets shuffled
2494 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002496 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002497 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2498 // Little hack here -- we -should- be able to rely on the
2499 // function to return true if the IME has moved and needs
2500 // its layer recomputed. However, if the IME was hidden
2501 // and isn't actually moved in the list, its layer may be
2502 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002503 assignLayers = true;
2504 }
2505 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002506 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002507 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002508 assignLayers = true;
2509 }
2510 }
Romain Guy06882f82009-06-10 13:36:04 -07002511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002512 mLayoutNeeded = true;
2513 win.mGivenInsetsPending = insetsPending;
2514 if (assignLayers) {
2515 assignLayersLocked();
2516 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002517 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002518 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002519 if (displayed && win.mIsWallpaper) {
2520 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002521 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002522 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002523 if (win.mAppToken != null) {
2524 win.mAppToken.updateReportedVisibilityLocked();
2525 }
2526 outFrame.set(win.mFrame);
2527 outContentInsets.set(win.mContentInsets);
2528 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002529 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002530 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002531 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002532 + ", requestedHeight=" + requestedHeight
2533 + ", viewVisibility=" + viewVisibility
2534 + "\nRelayout returning frame=" + outFrame
2535 + ", surface=" + outSurface);
2536
Joe Onorato8a9b2202010-02-26 18:56:32 -08002537 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002538 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2539
2540 inTouchMode = mInTouchMode;
2541 }
2542
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002543 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002544 sendNewConfiguration();
2545 }
Romain Guy06882f82009-06-10 13:36:04 -07002546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002549 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2550 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2551 }
2552
2553 public void finishDrawingWindow(Session session, IWindow client) {
2554 final long origId = Binder.clearCallingIdentity();
2555 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002556 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002557 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002558 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2559 adjustWallpaperWindowsLocked();
2560 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002561 mLayoutNeeded = true;
2562 performLayoutAndPlaceSurfacesLocked();
2563 }
2564 }
2565 Binder.restoreCallingIdentity(origId);
2566 }
2567
2568 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002569 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002570 + (lp != null ? lp.packageName : null)
2571 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2572 if (lp != null && lp.windowAnimations != 0) {
2573 // If this is a system resource, don't try to load it from the
2574 // application resources. It is nice to avoid loading application
2575 // resources if we can.
2576 String packageName = lp.packageName != null ? lp.packageName : "android";
2577 int resId = lp.windowAnimations;
2578 if ((resId&0xFF000000) == 0x01000000) {
2579 packageName = "android";
2580 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002581 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002582 + packageName);
2583 return AttributeCache.instance().get(packageName, resId,
2584 com.android.internal.R.styleable.WindowAnimation);
2585 }
2586 return null;
2587 }
Romain Guy06882f82009-06-10 13:36:04 -07002588
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002589 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002590 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002591 + packageName + " resId=0x" + Integer.toHexString(resId));
2592 if (packageName != null) {
2593 if ((resId&0xFF000000) == 0x01000000) {
2594 packageName = "android";
2595 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002596 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002597 + packageName);
2598 return AttributeCache.instance().get(packageName, resId,
2599 com.android.internal.R.styleable.WindowAnimation);
2600 }
2601 return null;
2602 }
2603
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002604 private void applyEnterAnimationLocked(WindowState win) {
2605 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2606 if (win.mEnterAnimationPending) {
2607 win.mEnterAnimationPending = false;
2608 transit = WindowManagerPolicy.TRANSIT_ENTER;
2609 }
2610
2611 applyAnimationLocked(win, transit, true);
2612 }
2613
2614 private boolean applyAnimationLocked(WindowState win,
2615 int transit, boolean isEntrance) {
2616 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2617 // If we are trying to apply an animation, but already running
2618 // an animation of the same type, then just leave that one alone.
2619 return true;
2620 }
Romain Guy06882f82009-06-10 13:36:04 -07002621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002622 // Only apply an animation if the display isn't frozen. If it is
2623 // frozen, there is no reason to animate and it can cause strange
2624 // artifacts when we unfreeze the display if some different animation
2625 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002626 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002627 int anim = mPolicy.selectAnimationLw(win, transit);
2628 int attr = -1;
2629 Animation a = null;
2630 if (anim != 0) {
2631 a = AnimationUtils.loadAnimation(mContext, anim);
2632 } else {
2633 switch (transit) {
2634 case WindowManagerPolicy.TRANSIT_ENTER:
2635 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2636 break;
2637 case WindowManagerPolicy.TRANSIT_EXIT:
2638 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2639 break;
2640 case WindowManagerPolicy.TRANSIT_SHOW:
2641 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2642 break;
2643 case WindowManagerPolicy.TRANSIT_HIDE:
2644 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2645 break;
2646 }
2647 if (attr >= 0) {
2648 a = loadAnimation(win.mAttrs, attr);
2649 }
2650 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002651 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002652 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2653 + " mAnimation=" + win.mAnimation
2654 + " isEntrance=" + isEntrance);
2655 if (a != null) {
2656 if (DEBUG_ANIM) {
2657 RuntimeException e = new RuntimeException();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002658 if (!HIDE_STACK_CRAWLS) e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002659 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002660 }
2661 win.setAnimation(a);
2662 win.mAnimationIsEntrance = isEntrance;
2663 }
2664 } else {
2665 win.clearAnimation();
2666 }
2667
2668 return win.mAnimation != null;
2669 }
2670
2671 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2672 int anim = 0;
2673 Context context = mContext;
2674 if (animAttr >= 0) {
2675 AttributeCache.Entry ent = getCachedAnimations(lp);
2676 if (ent != null) {
2677 context = ent.context;
2678 anim = ent.array.getResourceId(animAttr, 0);
2679 }
2680 }
2681 if (anim != 0) {
2682 return AnimationUtils.loadAnimation(context, anim);
2683 }
2684 return null;
2685 }
Romain Guy06882f82009-06-10 13:36:04 -07002686
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002687 private Animation loadAnimation(String packageName, int resId) {
2688 int anim = 0;
2689 Context context = mContext;
2690 if (resId >= 0) {
2691 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2692 if (ent != null) {
2693 context = ent.context;
2694 anim = resId;
2695 }
2696 }
2697 if (anim != 0) {
2698 return AnimationUtils.loadAnimation(context, anim);
2699 }
2700 return null;
2701 }
2702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002703 private boolean applyAnimationLocked(AppWindowToken wtoken,
2704 WindowManager.LayoutParams lp, int transit, boolean enter) {
2705 // Only apply an animation if the display isn't frozen. If it is
2706 // frozen, there is no reason to animate and it can cause strange
2707 // artifacts when we unfreeze the display if some different animation
2708 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002709 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002710 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002711 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002712 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002713 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002714 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002715 } else if (mNextAppTransitionPackage != null) {
2716 a = loadAnimation(mNextAppTransitionPackage, enter ?
2717 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002718 } else {
2719 int animAttr = 0;
2720 switch (transit) {
2721 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2722 animAttr = enter
2723 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2724 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2725 break;
2726 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2727 animAttr = enter
2728 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2729 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2730 break;
2731 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2732 animAttr = enter
2733 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2734 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2735 break;
2736 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2737 animAttr = enter
2738 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2739 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2740 break;
2741 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2742 animAttr = enter
2743 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2744 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2745 break;
2746 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2747 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002748 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002749 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2750 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002751 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002752 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002753 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2754 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002755 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002756 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002757 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002758 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2759 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2760 break;
2761 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2762 animAttr = enter
2763 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2764 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2765 break;
2766 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2767 animAttr = enter
2768 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2769 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002770 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002771 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002772 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002773 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002774 + " anim=" + a
2775 + " animAttr=0x" + Integer.toHexString(animAttr)
2776 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002777 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002778 if (a != null) {
2779 if (DEBUG_ANIM) {
2780 RuntimeException e = new RuntimeException();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002781 if (!HIDE_STACK_CRAWLS) e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002782 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002783 }
2784 wtoken.setAnimation(a);
2785 }
2786 } else {
2787 wtoken.clearAnimation();
2788 }
2789
2790 return wtoken.animation != null;
2791 }
2792
2793 // -------------------------------------------------------------
2794 // Application Window Tokens
2795 // -------------------------------------------------------------
2796
2797 public void validateAppTokens(List tokens) {
2798 int v = tokens.size()-1;
2799 int m = mAppTokens.size()-1;
2800 while (v >= 0 && m >= 0) {
2801 AppWindowToken wtoken = mAppTokens.get(m);
2802 if (wtoken.removed) {
2803 m--;
2804 continue;
2805 }
2806 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002807 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002808 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2809 }
2810 v--;
2811 m--;
2812 }
2813 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002814 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002815 v--;
2816 }
2817 while (m >= 0) {
2818 AppWindowToken wtoken = mAppTokens.get(m);
2819 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002820 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002821 }
2822 m--;
2823 }
2824 }
2825
2826 boolean checkCallingPermission(String permission, String func) {
2827 // Quick check: if the calling permission is me, it's all okay.
2828 if (Binder.getCallingPid() == Process.myPid()) {
2829 return true;
2830 }
Romain Guy06882f82009-06-10 13:36:04 -07002831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002832 if (mContext.checkCallingPermission(permission)
2833 == PackageManager.PERMISSION_GRANTED) {
2834 return true;
2835 }
2836 String msg = "Permission Denial: " + func + " from pid="
2837 + Binder.getCallingPid()
2838 + ", uid=" + Binder.getCallingUid()
2839 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002840 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002841 return false;
2842 }
Romain Guy06882f82009-06-10 13:36:04 -07002843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002844 AppWindowToken findAppWindowToken(IBinder token) {
2845 WindowToken wtoken = mTokenMap.get(token);
2846 if (wtoken == null) {
2847 return null;
2848 }
2849 return wtoken.appWindowToken;
2850 }
Romain Guy06882f82009-06-10 13:36:04 -07002851
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 public void addWindowToken(IBinder token, int type) {
2853 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2854 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002855 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002856 }
Romain Guy06882f82009-06-10 13:36:04 -07002857
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002858 synchronized(mWindowMap) {
2859 WindowToken wtoken = mTokenMap.get(token);
2860 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002861 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002862 return;
2863 }
2864 wtoken = new WindowToken(token, type, true);
2865 mTokenMap.put(token, wtoken);
2866 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002867 if (type == TYPE_WALLPAPER) {
2868 mWallpaperTokens.add(wtoken);
2869 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002870 }
2871 }
Romain Guy06882f82009-06-10 13:36:04 -07002872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002873 public void removeWindowToken(IBinder token) {
2874 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2875 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002876 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002877 }
2878
2879 final long origId = Binder.clearCallingIdentity();
2880 synchronized(mWindowMap) {
2881 WindowToken wtoken = mTokenMap.remove(token);
2882 mTokenList.remove(wtoken);
2883 if (wtoken != null) {
2884 boolean delayed = false;
2885 if (!wtoken.hidden) {
2886 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002888 final int N = wtoken.windows.size();
2889 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002891 for (int i=0; i<N; i++) {
2892 WindowState win = wtoken.windows.get(i);
2893
2894 if (win.isAnimating()) {
2895 delayed = true;
2896 }
Romain Guy06882f82009-06-10 13:36:04 -07002897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002898 if (win.isVisibleNow()) {
2899 applyAnimationLocked(win,
2900 WindowManagerPolicy.TRANSIT_EXIT, false);
2901 mKeyWaiter.finishedKey(win.mSession, win.mClient, true,
2902 KeyWaiter.RETURN_NOTHING);
2903 changed = true;
2904 }
2905 }
2906
2907 if (changed) {
2908 mLayoutNeeded = true;
2909 performLayoutAndPlaceSurfacesLocked();
2910 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2911 }
Romain Guy06882f82009-06-10 13:36:04 -07002912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002913 if (delayed) {
2914 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002915 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2916 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002917 }
2918 }
Romain Guy06882f82009-06-10 13:36:04 -07002919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002921 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002922 }
2923 }
2924 Binder.restoreCallingIdentity(origId);
2925 }
2926
2927 public void addAppToken(int addPos, IApplicationToken token,
2928 int groupId, int requestedOrientation, boolean fullscreen) {
2929 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2930 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002931 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002932 }
Romain Guy06882f82009-06-10 13:36:04 -07002933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002934 synchronized(mWindowMap) {
2935 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2936 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002937 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002938 return;
2939 }
2940 wtoken = new AppWindowToken(token);
2941 wtoken.groupId = groupId;
2942 wtoken.appFullscreen = fullscreen;
2943 wtoken.requestedOrientation = requestedOrientation;
2944 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002945 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002946 mTokenMap.put(token.asBinder(), wtoken);
2947 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002949 // Application tokens start out hidden.
2950 wtoken.hidden = true;
2951 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002953 //dump();
2954 }
2955 }
Romain Guy06882f82009-06-10 13:36:04 -07002956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002957 public void setAppGroupId(IBinder token, int groupId) {
2958 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2959 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002960 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002961 }
2962
2963 synchronized(mWindowMap) {
2964 AppWindowToken wtoken = findAppWindowToken(token);
2965 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002966 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002967 return;
2968 }
2969 wtoken.groupId = groupId;
2970 }
2971 }
Romain Guy06882f82009-06-10 13:36:04 -07002972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002973 public int getOrientationFromWindowsLocked() {
2974 int pos = mWindows.size() - 1;
2975 while (pos >= 0) {
2976 WindowState wtoken = (WindowState) mWindows.get(pos);
2977 pos--;
2978 if (wtoken.mAppToken != null) {
2979 // We hit an application window. so the orientation will be determined by the
2980 // app window. No point in continuing further.
2981 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
2982 }
2983 if (!wtoken.isVisibleLw()) {
2984 continue;
2985 }
2986 int req = wtoken.mAttrs.screenOrientation;
2987 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
2988 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
2989 continue;
2990 } else {
2991 return req;
2992 }
2993 }
2994 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
2995 }
Romain Guy06882f82009-06-10 13:36:04 -07002996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002997 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002998 int pos = mAppTokens.size() - 1;
2999 int curGroup = 0;
3000 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3001 boolean findingBehind = false;
3002 boolean haveGroup = false;
3003 boolean lastFullscreen = false;
3004 while (pos >= 0) {
3005 AppWindowToken wtoken = mAppTokens.get(pos);
3006 pos--;
3007 // if we're about to tear down this window and not seek for
3008 // the behind activity, don't use it for orientation
3009 if (!findingBehind
3010 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3011 continue;
3012 }
3013
3014 if (!haveGroup) {
3015 // We ignore any hidden applications on the top.
3016 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003017 continue;
3018 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003019 haveGroup = true;
3020 curGroup = wtoken.groupId;
3021 lastOrientation = wtoken.requestedOrientation;
3022 } else if (curGroup != wtoken.groupId) {
3023 // If we have hit a new application group, and the bottom
3024 // of the previous group didn't explicitly say to use
3025 // the orientation behind it, and the last app was
3026 // full screen, then we'll stick with the
3027 // user's orientation.
3028 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3029 && lastFullscreen) {
3030 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003031 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003032 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003033 int or = wtoken.requestedOrientation;
3034 // If this application is fullscreen, and didn't explicitly say
3035 // to use the orientation behind it, then just take whatever
3036 // orientation it has and ignores whatever is under it.
3037 lastFullscreen = wtoken.appFullscreen;
3038 if (lastFullscreen
3039 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3040 return or;
3041 }
3042 // If this application has requested an explicit orientation,
3043 // then use it.
3044 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3045 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3046 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3047 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3048 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3049 return or;
3050 }
3051 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3052 }
3053 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003054 }
Romain Guy06882f82009-06-10 13:36:04 -07003055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003056 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003057 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003058 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3059 "updateOrientationFromAppTokens()")) {
3060 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3061 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003062
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003063 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003064 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003065
3066 synchronized(mWindowMap) {
3067 if (updateOrientationFromAppTokensLocked()) {
3068 if (freezeThisOneIfNeeded != null) {
3069 AppWindowToken wtoken = findAppWindowToken(
3070 freezeThisOneIfNeeded);
3071 if (wtoken != null) {
3072 startAppFreezingScreenLocked(wtoken,
3073 ActivityInfo.CONFIG_ORIENTATION);
3074 }
3075 }
3076 config = computeNewConfigurationLocked();
3077
3078 } else if (currentConfig != null) {
3079 // No obvious action we need to take, but if our current
3080 // state mismatches the activity maanager's, update it
3081 mTempConfiguration.setToDefaults();
3082 if (computeNewConfigurationLocked(mTempConfiguration)) {
3083 if (currentConfig.diff(mTempConfiguration) != 0) {
3084 mWaitingForConfig = true;
3085 mLayoutNeeded = true;
3086 startFreezingDisplayLocked();
3087 config = new Configuration(mTempConfiguration);
3088 }
3089 }
3090 }
3091 }
3092
Dianne Hackborncfaef692009-06-15 14:24:44 -07003093 Binder.restoreCallingIdentity(ident);
3094 return config;
3095 }
3096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003097 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003098 * Determine the new desired orientation of the display, returning
3099 * a non-null new Configuration if it has changed from the current
3100 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3101 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3102 * SCREEN. This will typically be done for you if you call
3103 * sendNewConfiguration().
3104 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003105 * The orientation is computed from non-application windows first. If none of
3106 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003107 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003108 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3109 * android.os.IBinder)
3110 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003111 boolean updateOrientationFromAppTokensLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003112 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003113 long ident = Binder.clearCallingIdentity();
3114 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003115 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003117 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003118 mForcedAppOrientation = req;
3119 //send a message to Policy indicating orientation change to take
3120 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003121 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003122 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3123 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3124 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003125 }
3126 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003127
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003128 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003129 } finally {
3130 Binder.restoreCallingIdentity(ident);
3131 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003132 }
Romain Guy06882f82009-06-10 13:36:04 -07003133
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003134 int computeForcedAppOrientationLocked() {
3135 int req = getOrientationFromWindowsLocked();
3136 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3137 req = getOrientationFromAppTokensLocked();
3138 }
3139 return req;
3140 }
Romain Guy06882f82009-06-10 13:36:04 -07003141
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003142 public void setNewConfiguration(Configuration config) {
3143 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3144 "setNewConfiguration()")) {
3145 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3146 }
3147
3148 synchronized(mWindowMap) {
3149 mCurConfiguration = new Configuration(config);
3150 mWaitingForConfig = false;
3151 performLayoutAndPlaceSurfacesLocked();
3152 }
3153 }
3154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003155 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3156 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3157 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003158 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003159 }
Romain Guy06882f82009-06-10 13:36:04 -07003160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003161 synchronized(mWindowMap) {
3162 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3163 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003164 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003165 return;
3166 }
Romain Guy06882f82009-06-10 13:36:04 -07003167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003168 wtoken.requestedOrientation = requestedOrientation;
3169 }
3170 }
Romain Guy06882f82009-06-10 13:36:04 -07003171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003172 public int getAppOrientation(IApplicationToken token) {
3173 synchronized(mWindowMap) {
3174 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3175 if (wtoken == null) {
3176 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3177 }
Romain Guy06882f82009-06-10 13:36:04 -07003178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003179 return wtoken.requestedOrientation;
3180 }
3181 }
Romain Guy06882f82009-06-10 13:36:04 -07003182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003183 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3184 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3185 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003186 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 }
3188
3189 synchronized(mWindowMap) {
3190 boolean changed = false;
3191 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003192 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003193 changed = mFocusedApp != null;
3194 mFocusedApp = null;
3195 mKeyWaiter.tickle();
3196 } else {
3197 AppWindowToken newFocus = findAppWindowToken(token);
3198 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003199 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003200 return;
3201 }
3202 changed = mFocusedApp != newFocus;
3203 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003204 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003205 mKeyWaiter.tickle();
3206 }
3207
3208 if (moveFocusNow && changed) {
3209 final long origId = Binder.clearCallingIdentity();
3210 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3211 Binder.restoreCallingIdentity(origId);
3212 }
3213 }
3214 }
3215
3216 public void prepareAppTransition(int transit) {
3217 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3218 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003219 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003220 }
Romain Guy06882f82009-06-10 13:36:04 -07003221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003222 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003223 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003224 TAG, "Prepare app transition: transit=" + transit
3225 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003226 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003227 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3228 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003229 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003230 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3231 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3232 // Opening a new task always supersedes a close for the anim.
3233 mNextAppTransition = transit;
3234 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3235 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3236 // Opening a new activity always supersedes a close for the anim.
3237 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003238 }
3239 mAppTransitionReady = false;
3240 mAppTransitionTimeout = false;
3241 mStartingIconInTransition = false;
3242 mSkipAppTransitionAnimation = false;
3243 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3244 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3245 5000);
3246 }
3247 }
3248 }
3249
3250 public int getPendingAppTransition() {
3251 return mNextAppTransition;
3252 }
Romain Guy06882f82009-06-10 13:36:04 -07003253
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003254 public void overridePendingAppTransition(String packageName,
3255 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003256 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003257 mNextAppTransitionPackage = packageName;
3258 mNextAppTransitionEnter = enterAnim;
3259 mNextAppTransitionExit = exitAnim;
3260 }
3261 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003263 public void executeAppTransition() {
3264 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3265 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003266 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003267 }
Romain Guy06882f82009-06-10 13:36:04 -07003268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003269 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003270 if (DEBUG_APP_TRANSITIONS) {
3271 RuntimeException e = new RuntimeException("here");
3272 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003273 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003274 + mNextAppTransition, e);
3275 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003276 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003277 mAppTransitionReady = true;
3278 final long origId = Binder.clearCallingIdentity();
3279 performLayoutAndPlaceSurfacesLocked();
3280 Binder.restoreCallingIdentity(origId);
3281 }
3282 }
3283 }
3284
3285 public void setAppStartingWindow(IBinder token, String pkg,
3286 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3287 IBinder transferFrom, boolean createIfNeeded) {
3288 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3289 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003290 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003291 }
3292
3293 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003294 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003295 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3296 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003298 AppWindowToken wtoken = findAppWindowToken(token);
3299 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003300 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003301 return;
3302 }
3303
3304 // If the display is frozen, we won't do anything until the
3305 // actual window is displayed so there is no reason to put in
3306 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003307 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 return;
3309 }
Romain Guy06882f82009-06-10 13:36:04 -07003310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003311 if (wtoken.startingData != null) {
3312 return;
3313 }
Romain Guy06882f82009-06-10 13:36:04 -07003314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003315 if (transferFrom != null) {
3316 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3317 if (ttoken != null) {
3318 WindowState startingWindow = ttoken.startingWindow;
3319 if (startingWindow != null) {
3320 if (mStartingIconInTransition) {
3321 // In this case, the starting icon has already
3322 // been displayed, so start letting windows get
3323 // shown immediately without any more transitions.
3324 mSkipAppTransitionAnimation = true;
3325 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003326 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003327 "Moving existing starting from " + ttoken
3328 + " to " + wtoken);
3329 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003331 // Transfer the starting window over to the new
3332 // token.
3333 wtoken.startingData = ttoken.startingData;
3334 wtoken.startingView = ttoken.startingView;
3335 wtoken.startingWindow = startingWindow;
3336 ttoken.startingData = null;
3337 ttoken.startingView = null;
3338 ttoken.startingWindow = null;
3339 ttoken.startingMoved = true;
3340 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003341 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003342 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003343 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003344 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003345 mWindows.remove(startingWindow);
3346 ttoken.windows.remove(startingWindow);
3347 ttoken.allAppWindows.remove(startingWindow);
3348 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003350 // Propagate other interesting state between the
3351 // tokens. If the old token is displayed, we should
3352 // immediately force the new one to be displayed. If
3353 // it is animating, we need to move that animation to
3354 // the new one.
3355 if (ttoken.allDrawn) {
3356 wtoken.allDrawn = true;
3357 }
3358 if (ttoken.firstWindowDrawn) {
3359 wtoken.firstWindowDrawn = true;
3360 }
3361 if (!ttoken.hidden) {
3362 wtoken.hidden = false;
3363 wtoken.hiddenRequested = false;
3364 wtoken.willBeHidden = false;
3365 }
3366 if (wtoken.clientHidden != ttoken.clientHidden) {
3367 wtoken.clientHidden = ttoken.clientHidden;
3368 wtoken.sendAppVisibilityToClients();
3369 }
3370 if (ttoken.animation != null) {
3371 wtoken.animation = ttoken.animation;
3372 wtoken.animating = ttoken.animating;
3373 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3374 ttoken.animation = null;
3375 ttoken.animLayerAdjustment = 0;
3376 wtoken.updateLayers();
3377 ttoken.updateLayers();
3378 }
Romain Guy06882f82009-06-10 13:36:04 -07003379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003380 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003381 mLayoutNeeded = true;
3382 performLayoutAndPlaceSurfacesLocked();
3383 Binder.restoreCallingIdentity(origId);
3384 return;
3385 } else if (ttoken.startingData != null) {
3386 // The previous app was getting ready to show a
3387 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003388 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003389 "Moving pending starting from " + ttoken
3390 + " to " + wtoken);
3391 wtoken.startingData = ttoken.startingData;
3392 ttoken.startingData = null;
3393 ttoken.startingMoved = true;
3394 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3395 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3396 // want to process the message ASAP, before any other queued
3397 // messages.
3398 mH.sendMessageAtFrontOfQueue(m);
3399 return;
3400 }
3401 }
3402 }
3403
3404 // There is no existing starting window, and the caller doesn't
3405 // want us to create one, so that's it!
3406 if (!createIfNeeded) {
3407 return;
3408 }
Romain Guy06882f82009-06-10 13:36:04 -07003409
Dianne Hackborn284ac932009-08-28 10:34:25 -07003410 // If this is a translucent or wallpaper window, then don't
3411 // show a starting window -- the current effect (a full-screen
3412 // opaque starting window that fades away to the real contents
3413 // when it is ready) does not work for this.
3414 if (theme != 0) {
3415 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3416 com.android.internal.R.styleable.Window);
3417 if (ent.array.getBoolean(
3418 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3419 return;
3420 }
3421 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003422 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3423 return;
3424 }
3425 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003426 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3427 return;
3428 }
3429 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003431 mStartingIconInTransition = true;
3432 wtoken.startingData = new StartingData(
3433 pkg, theme, nonLocalizedLabel,
3434 labelRes, icon);
3435 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3436 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3437 // want to process the message ASAP, before any other queued
3438 // messages.
3439 mH.sendMessageAtFrontOfQueue(m);
3440 }
3441 }
3442
3443 public void setAppWillBeHidden(IBinder token) {
3444 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3445 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003446 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003447 }
3448
3449 AppWindowToken wtoken;
3450
3451 synchronized(mWindowMap) {
3452 wtoken = findAppWindowToken(token);
3453 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003454 Slog.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003455 return;
3456 }
3457 wtoken.willBeHidden = true;
3458 }
3459 }
Romain Guy06882f82009-06-10 13:36:04 -07003460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003461 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3462 boolean visible, int transit, boolean performLayout) {
3463 boolean delayed = false;
3464
3465 if (wtoken.clientHidden == visible) {
3466 wtoken.clientHidden = !visible;
3467 wtoken.sendAppVisibilityToClients();
3468 }
Romain Guy06882f82009-06-10 13:36:04 -07003469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003470 wtoken.willBeHidden = false;
3471 if (wtoken.hidden == visible) {
3472 final int N = wtoken.allAppWindows.size();
3473 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003474 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003475 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3476 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003478 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003479
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003480 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003481 if (wtoken.animation == sDummyAnimation) {
3482 wtoken.animation = null;
3483 }
3484 applyAnimationLocked(wtoken, lp, transit, visible);
3485 changed = true;
3486 if (wtoken.animation != null) {
3487 delayed = runningAppAnimation = true;
3488 }
3489 }
Romain Guy06882f82009-06-10 13:36:04 -07003490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003491 for (int i=0; i<N; i++) {
3492 WindowState win = wtoken.allAppWindows.get(i);
3493 if (win == wtoken.startingWindow) {
3494 continue;
3495 }
3496
3497 if (win.isAnimating()) {
3498 delayed = true;
3499 }
Romain Guy06882f82009-06-10 13:36:04 -07003500
Joe Onorato8a9b2202010-02-26 18:56:32 -08003501 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003502 //win.dump(" ");
3503 if (visible) {
3504 if (!win.isVisibleNow()) {
3505 if (!runningAppAnimation) {
3506 applyAnimationLocked(win,
3507 WindowManagerPolicy.TRANSIT_ENTER, true);
3508 }
3509 changed = true;
3510 }
3511 } else if (win.isVisibleNow()) {
3512 if (!runningAppAnimation) {
3513 applyAnimationLocked(win,
3514 WindowManagerPolicy.TRANSIT_EXIT, false);
3515 }
3516 mKeyWaiter.finishedKey(win.mSession, win.mClient, true,
3517 KeyWaiter.RETURN_NOTHING);
3518 changed = true;
3519 }
3520 }
3521
3522 wtoken.hidden = wtoken.hiddenRequested = !visible;
3523 if (!visible) {
3524 unsetAppFreezingScreenLocked(wtoken, true, true);
3525 } else {
3526 // If we are being set visible, and the starting window is
3527 // not yet displayed, then make sure it doesn't get displayed.
3528 WindowState swin = wtoken.startingWindow;
3529 if (swin != null && (swin.mDrawPending
3530 || swin.mCommitDrawPending)) {
3531 swin.mPolicyVisibility = false;
3532 swin.mPolicyVisibilityAfterAnim = false;
3533 }
3534 }
Romain Guy06882f82009-06-10 13:36:04 -07003535
Joe Onorato8a9b2202010-02-26 18:56:32 -08003536 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003537 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3538 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003539
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003540 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003541 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003542 if (performLayout) {
3543 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3544 performLayoutAndPlaceSurfacesLocked();
3545 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003546 }
3547 }
3548
3549 if (wtoken.animation != null) {
3550 delayed = true;
3551 }
Romain Guy06882f82009-06-10 13:36:04 -07003552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003553 return delayed;
3554 }
3555
3556 public void setAppVisibility(IBinder token, boolean visible) {
3557 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3558 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003559 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003560 }
3561
3562 AppWindowToken wtoken;
3563
3564 synchronized(mWindowMap) {
3565 wtoken = findAppWindowToken(token);
3566 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003567 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003568 return;
3569 }
3570
3571 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
3572 RuntimeException e = new RuntimeException();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003573 if (!HIDE_STACK_CRAWLS) e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003574 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003575 + "): mNextAppTransition=" + mNextAppTransition
3576 + " hidden=" + wtoken.hidden
3577 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3578 }
Romain Guy06882f82009-06-10 13:36:04 -07003579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003580 // If we are preparing an app transition, then delay changing
3581 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003582 if (!mDisplayFrozen && mPolicy.isScreenOn()
3583 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003584 // Already in requested state, don't do anything more.
3585 if (wtoken.hiddenRequested != visible) {
3586 return;
3587 }
3588 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003589
Joe Onorato8a9b2202010-02-26 18:56:32 -08003590 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003591 TAG, "Setting dummy animation on: " + wtoken);
3592 wtoken.setDummyAnimation();
3593 mOpeningApps.remove(wtoken);
3594 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003595 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003596 wtoken.inPendingTransaction = true;
3597 if (visible) {
3598 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003599 wtoken.startingDisplayed = false;
3600 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003601
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003602 // If the token is currently hidden (should be the
3603 // common case), then we need to set up to wait for
3604 // its windows to be ready.
3605 if (wtoken.hidden) {
3606 wtoken.allDrawn = false;
3607 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003608
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003609 if (wtoken.clientHidden) {
3610 // In the case where we are making an app visible
3611 // but holding off for a transition, we still need
3612 // to tell the client to make its windows visible so
3613 // they get drawn. Otherwise, we will wait on
3614 // performing the transition until all windows have
3615 // been drawn, they never will be, and we are sad.
3616 wtoken.clientHidden = false;
3617 wtoken.sendAppVisibilityToClients();
3618 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003619 }
3620 } else {
3621 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003622
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003623 // If the token is currently visible (should be the
3624 // common case), then set up to wait for it to be hidden.
3625 if (!wtoken.hidden) {
3626 wtoken.waitingToHide = true;
3627 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003628 }
3629 return;
3630 }
Romain Guy06882f82009-06-10 13:36:04 -07003631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003632 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003633 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003634 wtoken.updateReportedVisibilityLocked();
3635 Binder.restoreCallingIdentity(origId);
3636 }
3637 }
3638
3639 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3640 boolean unfreezeSurfaceNow, boolean force) {
3641 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003642 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003643 + " force=" + force);
3644 final int N = wtoken.allAppWindows.size();
3645 boolean unfrozeWindows = false;
3646 for (int i=0; i<N; i++) {
3647 WindowState w = wtoken.allAppWindows.get(i);
3648 if (w.mAppFreezing) {
3649 w.mAppFreezing = false;
3650 if (w.mSurface != null && !w.mOrientationChanging) {
3651 w.mOrientationChanging = true;
3652 }
3653 unfrozeWindows = true;
3654 }
3655 }
3656 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003657 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003658 wtoken.freezingScreen = false;
3659 mAppsFreezingScreen--;
3660 }
3661 if (unfreezeSurfaceNow) {
3662 if (unfrozeWindows) {
3663 mLayoutNeeded = true;
3664 performLayoutAndPlaceSurfacesLocked();
3665 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003666 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003667 }
3668 }
3669 }
Romain Guy06882f82009-06-10 13:36:04 -07003670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003671 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3672 int configChanges) {
3673 if (DEBUG_ORIENTATION) {
3674 RuntimeException e = new RuntimeException();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003675 if (!HIDE_STACK_CRAWLS) e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003676 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003677 + ": hidden=" + wtoken.hidden + " freezing="
3678 + wtoken.freezingScreen, e);
3679 }
3680 if (!wtoken.hiddenRequested) {
3681 if (!wtoken.freezingScreen) {
3682 wtoken.freezingScreen = true;
3683 mAppsFreezingScreen++;
3684 if (mAppsFreezingScreen == 1) {
3685 startFreezingDisplayLocked();
3686 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3687 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3688 5000);
3689 }
3690 }
3691 final int N = wtoken.allAppWindows.size();
3692 for (int i=0; i<N; i++) {
3693 WindowState w = wtoken.allAppWindows.get(i);
3694 w.mAppFreezing = true;
3695 }
3696 }
3697 }
Romain Guy06882f82009-06-10 13:36:04 -07003698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003699 public void startAppFreezingScreen(IBinder token, int configChanges) {
3700 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3701 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003702 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003703 }
3704
3705 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003706 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003707 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003708 return;
3709 }
Romain Guy06882f82009-06-10 13:36:04 -07003710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003711 AppWindowToken wtoken = findAppWindowToken(token);
3712 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003713 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003714 return;
3715 }
3716 final long origId = Binder.clearCallingIdentity();
3717 startAppFreezingScreenLocked(wtoken, configChanges);
3718 Binder.restoreCallingIdentity(origId);
3719 }
3720 }
Romain Guy06882f82009-06-10 13:36:04 -07003721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003722 public void stopAppFreezingScreen(IBinder token, boolean force) {
3723 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3724 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003725 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003726 }
3727
3728 synchronized(mWindowMap) {
3729 AppWindowToken wtoken = findAppWindowToken(token);
3730 if (wtoken == null || wtoken.appToken == null) {
3731 return;
3732 }
3733 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003734 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003735 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3736 unsetAppFreezingScreenLocked(wtoken, true, force);
3737 Binder.restoreCallingIdentity(origId);
3738 }
3739 }
Romain Guy06882f82009-06-10 13:36:04 -07003740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003741 public void removeAppToken(IBinder token) {
3742 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3743 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003744 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003745 }
3746
3747 AppWindowToken wtoken = null;
3748 AppWindowToken startingToken = null;
3749 boolean delayed = false;
3750
3751 final long origId = Binder.clearCallingIdentity();
3752 synchronized(mWindowMap) {
3753 WindowToken basewtoken = mTokenMap.remove(token);
3754 mTokenList.remove(basewtoken);
3755 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003756 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003757 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003758 wtoken.inPendingTransaction = false;
3759 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003760 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003761 if (mClosingApps.contains(wtoken)) {
3762 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003763 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003764 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003765 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003766 delayed = true;
3767 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003768 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003769 TAG, "Removing app " + wtoken + " delayed=" + delayed
3770 + " animation=" + wtoken.animation
3771 + " animating=" + wtoken.animating);
3772 if (delayed) {
3773 // set the token aside because it has an active animation to be finished
3774 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003775 } else {
3776 // Make sure there is no animation running on this token,
3777 // so any windows associated with it will be removed as
3778 // soon as their animations are complete
3779 wtoken.animation = null;
3780 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003781 }
3782 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003783 if (mLastEnterAnimToken == wtoken) {
3784 mLastEnterAnimToken = null;
3785 mLastEnterAnimParams = null;
3786 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003787 wtoken.removed = true;
3788 if (wtoken.startingData != null) {
3789 startingToken = wtoken;
3790 }
3791 unsetAppFreezingScreenLocked(wtoken, true, true);
3792 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003793 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003794 mFocusedApp = null;
3795 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3796 mKeyWaiter.tickle();
3797 }
3798 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003799 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003800 }
Romain Guy06882f82009-06-10 13:36:04 -07003801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003802 if (!delayed && wtoken != null) {
3803 wtoken.updateReportedVisibilityLocked();
3804 }
3805 }
3806 Binder.restoreCallingIdentity(origId);
3807
3808 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003809 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003810 + startingToken + ": app token removed");
3811 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3812 mH.sendMessage(m);
3813 }
3814 }
3815
3816 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3817 final int NW = token.windows.size();
3818 for (int i=0; i<NW; i++) {
3819 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003820 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003821 mWindows.remove(win);
3822 int j = win.mChildWindows.size();
3823 while (j > 0) {
3824 j--;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003825 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003826 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003827 "Tmp removing child window " + cwin);
3828 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003829 }
3830 }
3831 return NW > 0;
3832 }
3833
3834 void dumpAppTokensLocked() {
3835 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003836 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003837 }
3838 }
Romain Guy06882f82009-06-10 13:36:04 -07003839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003840 void dumpWindowsLocked() {
3841 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003842 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003843 }
3844 }
Romain Guy06882f82009-06-10 13:36:04 -07003845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003846 private int findWindowOffsetLocked(int tokenPos) {
3847 final int NW = mWindows.size();
3848
3849 if (tokenPos >= mAppTokens.size()) {
3850 int i = NW;
3851 while (i > 0) {
3852 i--;
3853 WindowState win = (WindowState)mWindows.get(i);
3854 if (win.getAppToken() != null) {
3855 return i+1;
3856 }
3857 }
3858 }
3859
3860 while (tokenPos > 0) {
3861 // Find the first app token below the new position that has
3862 // a window displayed.
3863 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003864 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003865 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003866 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003867 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003868 "Skipping token -- currently sending to bottom");
3869 tokenPos--;
3870 continue;
3871 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003872 int i = wtoken.windows.size();
3873 while (i > 0) {
3874 i--;
3875 WindowState win = wtoken.windows.get(i);
3876 int j = win.mChildWindows.size();
3877 while (j > 0) {
3878 j--;
3879 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003880 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003881 for (int pos=NW-1; pos>=0; pos--) {
3882 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003883 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003884 "Found child win @" + (pos+1));
3885 return pos+1;
3886 }
3887 }
3888 }
3889 }
3890 for (int pos=NW-1; pos>=0; pos--) {
3891 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003892 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003893 return pos+1;
3894 }
3895 }
3896 }
3897 tokenPos--;
3898 }
3899
3900 return 0;
3901 }
3902
3903 private final int reAddWindowLocked(int index, WindowState win) {
3904 final int NCW = win.mChildWindows.size();
3905 boolean added = false;
3906 for (int j=0; j<NCW; j++) {
3907 WindowState cwin = (WindowState)win.mChildWindows.get(j);
3908 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003909 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003910 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003911 mWindows.add(index, win);
3912 index++;
3913 added = true;
3914 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003915 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003916 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003917 mWindows.add(index, cwin);
3918 index++;
3919 }
3920 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003921 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003922 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003923 mWindows.add(index, win);
3924 index++;
3925 }
3926 return index;
3927 }
Romain Guy06882f82009-06-10 13:36:04 -07003928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003929 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3930 final int NW = token.windows.size();
3931 for (int i=0; i<NW; i++) {
3932 index = reAddWindowLocked(index, token.windows.get(i));
3933 }
3934 return index;
3935 }
3936
3937 public void moveAppToken(int index, IBinder token) {
3938 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3939 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003940 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003941 }
3942
3943 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003944 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003945 if (DEBUG_REORDER) dumpAppTokensLocked();
3946 final AppWindowToken wtoken = findAppWindowToken(token);
3947 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003948 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003949 + token + " (" + wtoken + ")");
3950 return;
3951 }
3952 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003953 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003954 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003956 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003957 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003958 if (DEBUG_REORDER) dumpWindowsLocked();
3959 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003960 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003961 if (DEBUG_REORDER) dumpWindowsLocked();
3962 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003963 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003964 if (DEBUG_REORDER) dumpWindowsLocked();
3965 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003966 mLayoutNeeded = true;
3967 performLayoutAndPlaceSurfacesLocked();
3968 }
3969 Binder.restoreCallingIdentity(origId);
3970 }
3971 }
3972
3973 private void removeAppTokensLocked(List<IBinder> tokens) {
3974 // XXX This should be done more efficiently!
3975 // (take advantage of the fact that both lists should be
3976 // ordered in the same way.)
3977 int N = tokens.size();
3978 for (int i=0; i<N; i++) {
3979 IBinder token = tokens.get(i);
3980 final AppWindowToken wtoken = findAppWindowToken(token);
3981 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003982 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003983 + token + " (" + wtoken + ")");
3984 i--;
3985 N--;
3986 }
3987 }
3988 }
3989
Dianne Hackborna8f60182009-09-01 19:01:50 -07003990 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
3991 boolean updateFocusAndLayout) {
3992 // First remove all of the windows from the list.
3993 tmpRemoveAppWindowsLocked(wtoken);
3994
3995 // Where to start adding?
3996 int pos = findWindowOffsetLocked(tokenPos);
3997
3998 // And now add them back at the correct place.
3999 pos = reAddAppWindowsLocked(pos, wtoken);
4000
4001 if (updateFocusAndLayout) {
4002 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4003 assignLayersLocked();
4004 }
4005 mLayoutNeeded = true;
4006 performLayoutAndPlaceSurfacesLocked();
4007 }
4008 }
4009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004010 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4011 // First remove all of the windows from the list.
4012 final int N = tokens.size();
4013 int i;
4014 for (i=0; i<N; i++) {
4015 WindowToken token = mTokenMap.get(tokens.get(i));
4016 if (token != null) {
4017 tmpRemoveAppWindowsLocked(token);
4018 }
4019 }
4020
4021 // Where to start adding?
4022 int pos = findWindowOffsetLocked(tokenPos);
4023
4024 // And now add them back at the correct place.
4025 for (i=0; i<N; i++) {
4026 WindowToken token = mTokenMap.get(tokens.get(i));
4027 if (token != null) {
4028 pos = reAddAppWindowsLocked(pos, token);
4029 }
4030 }
4031
Dianne Hackborna8f60182009-09-01 19:01:50 -07004032 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4033 assignLayersLocked();
4034 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004035 mLayoutNeeded = true;
4036 performLayoutAndPlaceSurfacesLocked();
4037
4038 //dump();
4039 }
4040
4041 public void moveAppTokensToTop(List<IBinder> tokens) {
4042 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4043 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004044 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004045 }
4046
4047 final long origId = Binder.clearCallingIdentity();
4048 synchronized(mWindowMap) {
4049 removeAppTokensLocked(tokens);
4050 final int N = tokens.size();
4051 for (int i=0; i<N; i++) {
4052 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4053 if (wt != null) {
4054 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004055 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004056 mToTopApps.remove(wt);
4057 mToBottomApps.remove(wt);
4058 mToTopApps.add(wt);
4059 wt.sendingToBottom = false;
4060 wt.sendingToTop = true;
4061 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004062 }
4063 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004064
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004065 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004066 moveAppWindowsLocked(tokens, mAppTokens.size());
4067 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004068 }
4069 Binder.restoreCallingIdentity(origId);
4070 }
4071
4072 public void moveAppTokensToBottom(List<IBinder> tokens) {
4073 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4074 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004075 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004076 }
4077
4078 final long origId = Binder.clearCallingIdentity();
4079 synchronized(mWindowMap) {
4080 removeAppTokensLocked(tokens);
4081 final int N = tokens.size();
4082 int pos = 0;
4083 for (int i=0; i<N; i++) {
4084 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4085 if (wt != null) {
4086 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004087 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004088 mToTopApps.remove(wt);
4089 mToBottomApps.remove(wt);
4090 mToBottomApps.add(i, wt);
4091 wt.sendingToTop = false;
4092 wt.sendingToBottom = true;
4093 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004094 pos++;
4095 }
4096 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004097
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004098 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004099 moveAppWindowsLocked(tokens, 0);
4100 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004101 }
4102 Binder.restoreCallingIdentity(origId);
4103 }
4104
4105 // -------------------------------------------------------------
4106 // Misc IWindowSession methods
4107 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004109 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004110 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004111 != PackageManager.PERMISSION_GRANTED) {
4112 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4113 }
Mike Lockwood983ee092009-11-22 01:42:24 -05004114 synchronized (mKeyguardTokenWatcher) {
4115 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004116 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004117 }
4118
4119 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004120 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004121 != PackageManager.PERMISSION_GRANTED) {
4122 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4123 }
Mike Lockwood983ee092009-11-22 01:42:24 -05004124 synchronized (mKeyguardTokenWatcher) {
4125 mKeyguardTokenWatcher.release(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004126
Mike Lockwood983ee092009-11-22 01:42:24 -05004127 if (!mKeyguardTokenWatcher.isAcquired()) {
4128 // If we are the last one to reenable the keyguard wait until
4129 // we have actaully finished reenabling until returning.
4130 // It is possible that reenableKeyguard() can be called before
4131 // the previous disableKeyguard() is handled, in which case
4132 // neither mKeyguardTokenWatcher.acquired() or released() would
4133 // be called. In that case mKeyguardDisabled will be false here
4134 // and we have nothing to wait for.
4135 while (mKeyguardDisabled) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004136 try {
Mike Lockwood983ee092009-11-22 01:42:24 -05004137 mKeyguardTokenWatcher.wait();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004138 } catch (InterruptedException e) {
4139 Thread.currentThread().interrupt();
4140 }
4141 }
4142 }
4143 }
4144 }
4145
4146 /**
4147 * @see android.app.KeyguardManager#exitKeyguardSecurely
4148 */
4149 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004150 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004151 != PackageManager.PERMISSION_GRANTED) {
4152 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4153 }
4154 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4155 public void onKeyguardExitResult(boolean success) {
4156 try {
4157 callback.onKeyguardExitResult(success);
4158 } catch (RemoteException e) {
4159 // Client has died, we don't care.
4160 }
4161 }
4162 });
4163 }
4164
4165 public boolean inKeyguardRestrictedInputMode() {
4166 return mPolicy.inKeyguardRestrictedKeyInputMode();
4167 }
Romain Guy06882f82009-06-10 13:36:04 -07004168
Dianne Hackbornffa42482009-09-23 22:20:11 -07004169 public void closeSystemDialogs(String reason) {
4170 synchronized(mWindowMap) {
4171 for (int i=mWindows.size()-1; i>=0; i--) {
4172 WindowState w = (WindowState)mWindows.get(i);
4173 if (w.mSurface != null) {
4174 try {
4175 w.mClient.closeSystemDialogs(reason);
4176 } catch (RemoteException e) {
4177 }
4178 }
4179 }
4180 }
4181 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004183 static float fixScale(float scale) {
4184 if (scale < 0) scale = 0;
4185 else if (scale > 20) scale = 20;
4186 return Math.abs(scale);
4187 }
Romain Guy06882f82009-06-10 13:36:04 -07004188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004189 public void setAnimationScale(int which, float scale) {
4190 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4191 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004192 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004193 }
4194
4195 if (scale < 0) scale = 0;
4196 else if (scale > 20) scale = 20;
4197 scale = Math.abs(scale);
4198 switch (which) {
4199 case 0: mWindowAnimationScale = fixScale(scale); break;
4200 case 1: mTransitionAnimationScale = fixScale(scale); break;
4201 }
Romain Guy06882f82009-06-10 13:36:04 -07004202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004203 // Persist setting
4204 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4205 }
Romain Guy06882f82009-06-10 13:36:04 -07004206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004207 public void setAnimationScales(float[] scales) {
4208 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4209 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004210 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004211 }
4212
4213 if (scales != null) {
4214 if (scales.length >= 1) {
4215 mWindowAnimationScale = fixScale(scales[0]);
4216 }
4217 if (scales.length >= 2) {
4218 mTransitionAnimationScale = fixScale(scales[1]);
4219 }
4220 }
Romain Guy06882f82009-06-10 13:36:04 -07004221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004222 // Persist setting
4223 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4224 }
Romain Guy06882f82009-06-10 13:36:04 -07004225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004226 public float getAnimationScale(int which) {
4227 switch (which) {
4228 case 0: return mWindowAnimationScale;
4229 case 1: return mTransitionAnimationScale;
4230 }
4231 return 0;
4232 }
Romain Guy06882f82009-06-10 13:36:04 -07004233
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004234 public float[] getAnimationScales() {
4235 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4236 }
Romain Guy06882f82009-06-10 13:36:04 -07004237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004238 public int getSwitchState(int sw) {
4239 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4240 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004241 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004242 }
4243 return KeyInputQueue.getSwitchState(sw);
4244 }
Romain Guy06882f82009-06-10 13:36:04 -07004245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004246 public int getSwitchStateForDevice(int devid, int sw) {
4247 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4248 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004249 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004250 }
4251 return KeyInputQueue.getSwitchState(devid, sw);
4252 }
Romain Guy06882f82009-06-10 13:36:04 -07004253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004254 public int getScancodeState(int sw) {
4255 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4256 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004257 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004258 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004259 return mQueue.getScancodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004260 }
Romain Guy06882f82009-06-10 13:36:04 -07004261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004262 public int getScancodeStateForDevice(int devid, int sw) {
4263 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4264 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004265 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004266 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004267 return mQueue.getScancodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004268 }
Romain Guy06882f82009-06-10 13:36:04 -07004269
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004270 public int getTrackballScancodeState(int sw) {
4271 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4272 "getTrackballScancodeState()")) {
4273 throw new SecurityException("Requires READ_INPUT_STATE permission");
4274 }
4275 return mQueue.getTrackballScancodeState(sw);
4276 }
4277
4278 public int getDPadScancodeState(int sw) {
4279 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4280 "getDPadScancodeState()")) {
4281 throw new SecurityException("Requires READ_INPUT_STATE permission");
4282 }
4283 return mQueue.getDPadScancodeState(sw);
4284 }
4285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004286 public int getKeycodeState(int sw) {
4287 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4288 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004289 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004290 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004291 return mQueue.getKeycodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004292 }
Romain Guy06882f82009-06-10 13:36:04 -07004293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004294 public int getKeycodeStateForDevice(int devid, int sw) {
4295 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4296 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004297 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004298 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004299 return mQueue.getKeycodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004300 }
Romain Guy06882f82009-06-10 13:36:04 -07004301
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004302 public int getTrackballKeycodeState(int sw) {
4303 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4304 "getTrackballKeycodeState()")) {
4305 throw new SecurityException("Requires READ_INPUT_STATE permission");
4306 }
4307 return mQueue.getTrackballKeycodeState(sw);
4308 }
4309
4310 public int getDPadKeycodeState(int sw) {
4311 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4312 "getDPadKeycodeState()")) {
4313 throw new SecurityException("Requires READ_INPUT_STATE permission");
4314 }
4315 return mQueue.getDPadKeycodeState(sw);
4316 }
4317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004318 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
4319 return KeyInputQueue.hasKeys(keycodes, keyExists);
4320 }
Romain Guy06882f82009-06-10 13:36:04 -07004321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004322 public void enableScreenAfterBoot() {
4323 synchronized(mWindowMap) {
4324 if (mSystemBooted) {
4325 return;
4326 }
4327 mSystemBooted = true;
4328 }
Romain Guy06882f82009-06-10 13:36:04 -07004329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004330 performEnableScreen();
4331 }
Romain Guy06882f82009-06-10 13:36:04 -07004332
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004333 public void enableScreenIfNeededLocked() {
4334 if (mDisplayEnabled) {
4335 return;
4336 }
4337 if (!mSystemBooted) {
4338 return;
4339 }
4340 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4341 }
Romain Guy06882f82009-06-10 13:36:04 -07004342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004343 public void performEnableScreen() {
4344 synchronized(mWindowMap) {
4345 if (mDisplayEnabled) {
4346 return;
4347 }
4348 if (!mSystemBooted) {
4349 return;
4350 }
Romain Guy06882f82009-06-10 13:36:04 -07004351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004352 // Don't enable the screen until all existing windows
4353 // have been drawn.
4354 final int N = mWindows.size();
4355 for (int i=0; i<N; i++) {
4356 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004357 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004358 return;
4359 }
4360 }
Romain Guy06882f82009-06-10 13:36:04 -07004361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004362 mDisplayEnabled = true;
4363 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004364 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004365 StringWriter sw = new StringWriter();
4366 PrintWriter pw = new PrintWriter(sw);
4367 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004368 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004369 }
4370 try {
4371 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4372 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004373 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004374 Parcel data = Parcel.obtain();
4375 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4376 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4377 data, null, 0);
4378 data.recycle();
4379 }
4380 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004381 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004382 }
4383 }
Romain Guy06882f82009-06-10 13:36:04 -07004384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004385 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004387 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004388 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4389 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004390 }
Romain Guy06882f82009-06-10 13:36:04 -07004391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004392 public void setInTouchMode(boolean mode) {
4393 synchronized(mWindowMap) {
4394 mInTouchMode = mode;
4395 }
4396 }
4397
Romain Guy06882f82009-06-10 13:36:04 -07004398 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004399 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004400 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004401 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004402 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004403 }
4404
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004405 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004406 }
Romain Guy06882f82009-06-10 13:36:04 -07004407
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004408 public void setRotationUnchecked(int rotation,
4409 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004410 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004411 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004413 long origId = Binder.clearCallingIdentity();
4414 boolean changed;
4415 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004416 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004417 }
Romain Guy06882f82009-06-10 13:36:04 -07004418
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004419 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004420 sendNewConfiguration();
4421 }
Romain Guy06882f82009-06-10 13:36:04 -07004422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004423 Binder.restoreCallingIdentity(origId);
4424 }
Romain Guy06882f82009-06-10 13:36:04 -07004425
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004426 /**
4427 * Apply a new rotation to the screen, respecting the requests of
4428 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4429 * re-evaluate the desired rotation.
4430 *
4431 * Returns null if the rotation has been changed. In this case YOU
4432 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4433 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004434 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004435 boolean changed;
4436 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4437 rotation = mRequestedRotation;
4438 } else {
4439 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004440 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004441 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004442 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004443 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004444 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004445 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004446 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004448 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004449 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004450 "Rotation changed to " + rotation
4451 + " from " + mRotation
4452 + " (forceApp=" + mForcedAppOrientation
4453 + ", req=" + mRequestedRotation + ")");
4454 mRotation = rotation;
4455 mWindowsFreezingScreen = true;
4456 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4457 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4458 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004459 mWaitingForConfig = true;
4460 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004461 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004462 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004463 mQueue.setOrientation(rotation);
4464 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004465 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004466 }
4467 for (int i=mWindows.size()-1; i>=0; i--) {
4468 WindowState w = (WindowState)mWindows.get(i);
4469 if (w.mSurface != null) {
4470 w.mOrientationChanging = true;
4471 }
4472 }
4473 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4474 try {
4475 mRotationWatchers.get(i).onRotationChanged(rotation);
4476 } catch (RemoteException e) {
4477 }
4478 }
4479 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004481 return changed;
4482 }
Romain Guy06882f82009-06-10 13:36:04 -07004483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004484 public int getRotation() {
4485 return mRotation;
4486 }
4487
4488 public int watchRotation(IRotationWatcher watcher) {
4489 final IBinder watcherBinder = watcher.asBinder();
4490 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4491 public void binderDied() {
4492 synchronized (mWindowMap) {
4493 for (int i=0; i<mRotationWatchers.size(); i++) {
4494 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004495 IRotationWatcher removed = mRotationWatchers.remove(i);
4496 if (removed != null) {
4497 removed.asBinder().unlinkToDeath(this, 0);
4498 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004499 i--;
4500 }
4501 }
4502 }
4503 }
4504 };
Romain Guy06882f82009-06-10 13:36:04 -07004505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004506 synchronized (mWindowMap) {
4507 try {
4508 watcher.asBinder().linkToDeath(dr, 0);
4509 mRotationWatchers.add(watcher);
4510 } catch (RemoteException e) {
4511 // Client died, no cleanup needed.
4512 }
Romain Guy06882f82009-06-10 13:36:04 -07004513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004514 return mRotation;
4515 }
4516 }
4517
4518 /**
4519 * Starts the view server on the specified port.
4520 *
4521 * @param port The port to listener to.
4522 *
4523 * @return True if the server was successfully started, false otherwise.
4524 *
4525 * @see com.android.server.ViewServer
4526 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4527 */
4528 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004529 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004530 return false;
4531 }
4532
4533 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4534 return false;
4535 }
4536
4537 if (port < 1024) {
4538 return false;
4539 }
4540
4541 if (mViewServer != null) {
4542 if (!mViewServer.isRunning()) {
4543 try {
4544 return mViewServer.start();
4545 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004546 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004547 }
4548 }
4549 return false;
4550 }
4551
4552 try {
4553 mViewServer = new ViewServer(this, port);
4554 return mViewServer.start();
4555 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004556 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004557 }
4558 return false;
4559 }
4560
Romain Guy06882f82009-06-10 13:36:04 -07004561 private boolean isSystemSecure() {
4562 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4563 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4564 }
4565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004566 /**
4567 * Stops the view server if it exists.
4568 *
4569 * @return True if the server stopped, false if it wasn't started or
4570 * couldn't be stopped.
4571 *
4572 * @see com.android.server.ViewServer
4573 */
4574 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004575 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004576 return false;
4577 }
4578
4579 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4580 return false;
4581 }
4582
4583 if (mViewServer != null) {
4584 return mViewServer.stop();
4585 }
4586 return false;
4587 }
4588
4589 /**
4590 * Indicates whether the view server is running.
4591 *
4592 * @return True if the server is running, false otherwise.
4593 *
4594 * @see com.android.server.ViewServer
4595 */
4596 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004597 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004598 return false;
4599 }
4600
4601 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4602 return false;
4603 }
4604
4605 return mViewServer != null && mViewServer.isRunning();
4606 }
4607
4608 /**
4609 * Lists all availble windows in the system. The listing is written in the
4610 * specified Socket's output stream with the following syntax:
4611 * windowHashCodeInHexadecimal windowName
4612 * Each line of the ouput represents a different window.
4613 *
4614 * @param client The remote client to send the listing to.
4615 * @return False if an error occured, true otherwise.
4616 */
4617 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004618 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004619 return false;
4620 }
4621
4622 boolean result = true;
4623
4624 Object[] windows;
4625 synchronized (mWindowMap) {
4626 windows = new Object[mWindows.size()];
4627 //noinspection unchecked
4628 windows = mWindows.toArray(windows);
4629 }
4630
4631 BufferedWriter out = null;
4632
4633 // Any uncaught exception will crash the system process
4634 try {
4635 OutputStream clientStream = client.getOutputStream();
4636 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4637
4638 final int count = windows.length;
4639 for (int i = 0; i < count; i++) {
4640 final WindowState w = (WindowState) windows[i];
4641 out.write(Integer.toHexString(System.identityHashCode(w)));
4642 out.write(' ');
4643 out.append(w.mAttrs.getTitle());
4644 out.write('\n');
4645 }
4646
4647 out.write("DONE.\n");
4648 out.flush();
4649 } catch (Exception e) {
4650 result = false;
4651 } finally {
4652 if (out != null) {
4653 try {
4654 out.close();
4655 } catch (IOException e) {
4656 result = false;
4657 }
4658 }
4659 }
4660
4661 return result;
4662 }
4663
4664 /**
4665 * Sends a command to a target window. The result of the command, if any, will be
4666 * written in the output stream of the specified socket.
4667 *
4668 * The parameters must follow this syntax:
4669 * windowHashcode extra
4670 *
4671 * Where XX is the length in characeters of the windowTitle.
4672 *
4673 * The first parameter is the target window. The window with the specified hashcode
4674 * will be the target. If no target can be found, nothing happens. The extra parameters
4675 * will be delivered to the target window and as parameters to the command itself.
4676 *
4677 * @param client The remote client to sent the result, if any, to.
4678 * @param command The command to execute.
4679 * @param parameters The command parameters.
4680 *
4681 * @return True if the command was successfully delivered, false otherwise. This does
4682 * not indicate whether the command itself was successful.
4683 */
4684 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004685 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004686 return false;
4687 }
4688
4689 boolean success = true;
4690 Parcel data = null;
4691 Parcel reply = null;
4692
4693 // Any uncaught exception will crash the system process
4694 try {
4695 // Find the hashcode of the window
4696 int index = parameters.indexOf(' ');
4697 if (index == -1) {
4698 index = parameters.length();
4699 }
4700 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004701 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004702
4703 // Extract the command's parameter after the window description
4704 if (index < parameters.length()) {
4705 parameters = parameters.substring(index + 1);
4706 } else {
4707 parameters = "";
4708 }
4709
4710 final WindowManagerService.WindowState window = findWindow(hashCode);
4711 if (window == null) {
4712 return false;
4713 }
4714
4715 data = Parcel.obtain();
4716 data.writeInterfaceToken("android.view.IWindow");
4717 data.writeString(command);
4718 data.writeString(parameters);
4719 data.writeInt(1);
4720 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4721
4722 reply = Parcel.obtain();
4723
4724 final IBinder binder = window.mClient.asBinder();
4725 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4726 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4727
4728 reply.readException();
4729
4730 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004731 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004732 success = false;
4733 } finally {
4734 if (data != null) {
4735 data.recycle();
4736 }
4737 if (reply != null) {
4738 reply.recycle();
4739 }
4740 }
4741
4742 return success;
4743 }
4744
4745 private WindowState findWindow(int hashCode) {
4746 if (hashCode == -1) {
4747 return getFocusedWindow();
4748 }
4749
4750 synchronized (mWindowMap) {
4751 final ArrayList windows = mWindows;
4752 final int count = windows.size();
4753
4754 for (int i = 0; i < count; i++) {
4755 WindowState w = (WindowState) windows.get(i);
4756 if (System.identityHashCode(w) == hashCode) {
4757 return w;
4758 }
4759 }
4760 }
4761
4762 return null;
4763 }
4764
4765 /*
4766 * Instruct the Activity Manager to fetch the current configuration and broadcast
4767 * that to config-changed listeners if appropriate.
4768 */
4769 void sendNewConfiguration() {
4770 try {
4771 mActivityManager.updateConfiguration(null);
4772 } catch (RemoteException e) {
4773 }
4774 }
Romain Guy06882f82009-06-10 13:36:04 -07004775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004776 public Configuration computeNewConfiguration() {
4777 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004778 return computeNewConfigurationLocked();
4779 }
4780 }
Romain Guy06882f82009-06-10 13:36:04 -07004781
Dianne Hackbornc485a602009-03-24 22:39:49 -07004782 Configuration computeNewConfigurationLocked() {
4783 Configuration config = new Configuration();
4784 if (!computeNewConfigurationLocked(config)) {
4785 return null;
4786 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004787 return config;
4788 }
Romain Guy06882f82009-06-10 13:36:04 -07004789
Dianne Hackbornc485a602009-03-24 22:39:49 -07004790 boolean computeNewConfigurationLocked(Configuration config) {
4791 if (mDisplay == null) {
4792 return false;
4793 }
4794 mQueue.getInputConfiguration(config);
4795 final int dw = mDisplay.getWidth();
4796 final int dh = mDisplay.getHeight();
4797 int orientation = Configuration.ORIENTATION_SQUARE;
4798 if (dw < dh) {
4799 orientation = Configuration.ORIENTATION_PORTRAIT;
4800 } else if (dw > dh) {
4801 orientation = Configuration.ORIENTATION_LANDSCAPE;
4802 }
4803 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004804
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004805 DisplayMetrics dm = new DisplayMetrics();
4806 mDisplay.getMetrics(dm);
4807 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4808
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004809 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004810 // Note we only do this once because at this point we don't
4811 // expect the screen to change in this way at runtime, and want
4812 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004813 int longSize = dw;
4814 int shortSize = dh;
4815 if (longSize < shortSize) {
4816 int tmp = longSize;
4817 longSize = shortSize;
4818 shortSize = tmp;
4819 }
4820 longSize = (int)(longSize/dm.density);
4821 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004822
Dianne Hackborn723738c2009-06-25 19:48:04 -07004823 // These semi-magic numbers define our compatibility modes for
4824 // applications with different screens. Don't change unless you
4825 // make sure to test lots and lots of apps!
4826 if (longSize < 470) {
4827 // This is shorter than an HVGA normal density screen (which
4828 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004829 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
4830 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07004831 } else {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004832 // Is this a large screen?
4833 if (longSize > 640 && shortSize >= 480) {
4834 // VGA or larger screens at medium density are the point
4835 // at which we consider it to be a large screen.
4836 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
4837 } else {
4838 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004839
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004840 // If this screen is wider than normal HVGA, or taller
4841 // than FWVGA, then for old apps we want to run in size
4842 // compatibility mode.
4843 if (shortSize > 321 || longSize > 570) {
4844 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
4845 }
4846 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004847
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004848 // Is this a long screen?
4849 if (((longSize*3)/5) >= (shortSize-1)) {
4850 // Anything wider than WVGA (5:3) is considering to be long.
4851 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
4852 } else {
4853 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
4854 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07004855 }
4856 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004857 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004858
Dianne Hackbornc485a602009-03-24 22:39:49 -07004859 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
4860 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
4861 mPolicy.adjustConfigurationLw(config);
4862 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004863 }
Romain Guy06882f82009-06-10 13:36:04 -07004864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004865 // -------------------------------------------------------------
4866 // Input Events and Focus Management
4867 // -------------------------------------------------------------
4868
4869 private final void wakeupIfNeeded(WindowState targetWin, int eventType) {
Michael Chane96440f2009-05-06 10:27:36 -07004870 long curTime = SystemClock.uptimeMillis();
4871
Michael Chane10de972009-05-18 11:24:50 -07004872 if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) {
Michael Chane96440f2009-05-06 10:27:36 -07004873 if (mLastTouchEventType == eventType &&
4874 (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) {
4875 return;
4876 }
4877 mLastUserActivityCallTime = curTime;
4878 mLastTouchEventType = eventType;
4879 }
4880
4881 if (targetWin == null
4882 || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) {
4883 mPowerManager.userActivity(curTime, false, eventType, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004884 }
4885 }
4886
4887 // tells if it's a cheek event or not -- this function is stateful
4888 private static final int EVENT_NONE = 0;
4889 private static final int EVENT_UNKNOWN = 0;
4890 private static final int EVENT_CHEEK = 0;
4891 private static final int EVENT_IGNORE_DURATION = 300; // ms
4892 private static final float CHEEK_THRESHOLD = 0.6f;
4893 private int mEventState = EVENT_NONE;
4894 private float mEventSize;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004896 private int eventType(MotionEvent ev) {
4897 float size = ev.getSize();
4898 switch (ev.getAction()) {
4899 case MotionEvent.ACTION_DOWN:
4900 mEventSize = size;
4901 return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT;
4902 case MotionEvent.ACTION_UP:
4903 if (size > mEventSize) mEventSize = size;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004904 return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004905 case MotionEvent.ACTION_MOVE:
4906 final int N = ev.getHistorySize();
4907 if (size > mEventSize) mEventSize = size;
4908 if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT;
4909 for (int i=0; i<N; i++) {
4910 size = ev.getHistoricalSize(i);
4911 if (size > mEventSize) mEventSize = size;
4912 if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT;
4913 }
4914 if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) {
4915 return TOUCH_EVENT;
4916 } else {
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004917 return LONG_TOUCH_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004918 }
4919 default:
4920 // not good
4921 return OTHER_EVENT;
4922 }
4923 }
4924
4925 /**
4926 * @return Returns true if event was dispatched, false if it was dropped for any reason
4927 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07004928 private int dispatchPointer(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004929 if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004930 "dispatchPointer " + ev);
4931
Michael Chan53071d62009-05-13 17:29:48 -07004932 if (MEASURE_LATENCY) {
4933 lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano);
4934 }
4935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004936 Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07004937 ev, true, false, pid, uid);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004938
Michael Chan53071d62009-05-13 17:29:48 -07004939 if (MEASURE_LATENCY) {
4940 lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano);
4941 }
4942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004943 int action = ev.getAction();
Romain Guy06882f82009-06-10 13:36:04 -07004944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004945 if (action == MotionEvent.ACTION_UP) {
4946 // let go of our target
4947 mKeyWaiter.mMotionTarget = null;
4948 mPowerManager.logPointerUpEvent();
4949 } else if (action == MotionEvent.ACTION_DOWN) {
4950 mPowerManager.logPointerDownEvent();
4951 }
4952
4953 if (targetObj == null) {
4954 // In this case we are either dropping the event, or have received
4955 // a move or up without a down. It is common to receive move
4956 // events in such a way, since this means the user is moving the
4957 // pointer without actually pressing down. All other cases should
4958 // be atypical, so let's log them.
Michael Chane96440f2009-05-06 10:27:36 -07004959 if (action != MotionEvent.ACTION_MOVE) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004960 Slog.w(TAG, "No window to dispatch pointer action " + ev.getAction());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004961 }
Dianne Hackborn6adba242009-11-10 11:10:09 -08004962 synchronized (mWindowMap) {
Dianne Hackborn90d2db32010-02-11 22:19:06 -08004963 dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true);
Dianne Hackborn6adba242009-11-10 11:10:09 -08004964 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004965 if (qev != null) {
4966 mQueue.recycleEvent(qev);
4967 }
4968 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07004969 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004970 }
4971 if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
Dianne Hackborn6adba242009-11-10 11:10:09 -08004972 synchronized (mWindowMap) {
Dianne Hackborn90d2db32010-02-11 22:19:06 -08004973 dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true);
Dianne Hackborn6adba242009-11-10 11:10:09 -08004974 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004975 if (qev != null) {
4976 mQueue.recycleEvent(qev);
4977 }
4978 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07004979 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004980 }
Romain Guy06882f82009-06-10 13:36:04 -07004981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004982 WindowState target = (WindowState)targetObj;
Romain Guy06882f82009-06-10 13:36:04 -07004983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004984 final long eventTime = ev.getEventTime();
Michael Chan53071d62009-05-13 17:29:48 -07004985 final long eventTimeNano = ev.getEventTimeNano();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004986
Joe Onorato8a9b2202010-02-26 18:56:32 -08004987 //Slog.i(TAG, "Sending " + ev + " to " + target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004988
4989 if (uid != 0 && uid != target.mSession.mUid) {
4990 if (mContext.checkPermission(
4991 android.Manifest.permission.INJECT_EVENTS, pid, uid)
4992 != PackageManager.PERMISSION_GRANTED) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004993 Slog.w(TAG, "Permission denied: injecting pointer event from pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004994 + pid + " uid " + uid + " to window " + target
4995 + " owned by uid " + target.mSession.mUid);
4996 if (qev != null) {
4997 mQueue.recycleEvent(qev);
4998 }
4999 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005000 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005001 }
5002 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005003
Michael Chan53071d62009-05-13 17:29:48 -07005004 if (MEASURE_LATENCY) {
5005 lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano);
5006 }
5007
Romain Guy06882f82009-06-10 13:36:04 -07005008 if ((target.mAttrs.flags &
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005009 WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) {
5010 //target wants to ignore fat touch events
5011 boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev);
5012 //explicit flag to return without processing event further
5013 boolean returnFlag = false;
5014 if((action == MotionEvent.ACTION_DOWN)) {
5015 mFatTouch = false;
5016 if(cheekPress) {
5017 mFatTouch = true;
5018 returnFlag = true;
5019 }
5020 } else {
5021 if(action == MotionEvent.ACTION_UP) {
5022 if(mFatTouch) {
5023 //earlier even was invalid doesnt matter if current up is cheekpress or not
5024 mFatTouch = false;
5025 returnFlag = true;
5026 } else if(cheekPress) {
5027 //cancel the earlier event
5028 ev.setAction(MotionEvent.ACTION_CANCEL);
5029 action = MotionEvent.ACTION_CANCEL;
5030 }
5031 } else if(action == MotionEvent.ACTION_MOVE) {
5032 if(mFatTouch) {
5033 //two cases here
5034 //an invalid down followed by 0 or moves(valid or invalid)
Romain Guy06882f82009-06-10 13:36:04 -07005035 //a valid down, invalid move, more moves. want to ignore till up
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005036 returnFlag = true;
5037 } else if(cheekPress) {
5038 //valid down followed by invalid moves
5039 //an invalid move have to cancel earlier action
5040 ev.setAction(MotionEvent.ACTION_CANCEL);
5041 action = MotionEvent.ACTION_CANCEL;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005042 if (DEBUG_INPUT) Slog.v(TAG, "Sending cancel for invalid ACTION_MOVE");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005043 //note that the subsequent invalid moves will not get here
5044 mFatTouch = true;
5045 }
5046 }
5047 } //else if action
5048 if(returnFlag) {
5049 //recycle que, ev
5050 if (qev != null) {
5051 mQueue.recycleEvent(qev);
5052 }
5053 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005054 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005055 }
5056 } //end if target
Michael Chane96440f2009-05-06 10:27:36 -07005057
Michael Chan9f028e62009-08-04 17:37:46 -07005058 // Enable this for testing the "right" value
5059 if (false && action == MotionEvent.ACTION_DOWN) {
Michael Chane96440f2009-05-06 10:27:36 -07005060 int max_events_per_sec = 35;
5061 try {
5062 max_events_per_sec = Integer.parseInt(SystemProperties
5063 .get("windowsmgr.max_events_per_sec"));
5064 if (max_events_per_sec < 1) {
5065 max_events_per_sec = 35;
5066 }
5067 } catch (NumberFormatException e) {
5068 }
5069 mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec;
5070 }
5071
5072 /*
5073 * Throttle events to minimize CPU usage when there's a flood of events
5074 * e.g. constant contact with the screen
5075 */
5076 if (action == MotionEvent.ACTION_MOVE) {
5077 long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents;
5078 long now = SystemClock.uptimeMillis();
5079 if (now < nextEventTime) {
5080 try {
5081 Thread.sleep(nextEventTime - now);
5082 } catch (InterruptedException e) {
5083 }
5084 mLastTouchEventTime = nextEventTime;
5085 } else {
5086 mLastTouchEventTime = now;
5087 }
5088 }
5089
Michael Chan53071d62009-05-13 17:29:48 -07005090 if (MEASURE_LATENCY) {
5091 lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano);
5092 }
5093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005094 synchronized(mWindowMap) {
Dianne Hackborn6adba242009-11-10 11:10:09 -08005095 if (!target.isVisibleLw()) {
5096 // During this motion dispatch, the target window has become
5097 // invisible.
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005098 dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), false);
Dianne Hackborn6adba242009-11-10 11:10:09 -08005099 if (qev != null) {
5100 mQueue.recycleEvent(qev);
5101 }
5102 ev.recycle();
5103 return INJECT_SUCCEEDED;
5104 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005106 if (qev != null && action == MotionEvent.ACTION_MOVE) {
5107 mKeyWaiter.bindTargetWindowLocked(target,
5108 KeyWaiter.RETURN_PENDING_POINTER, qev);
5109 ev = null;
5110 } else {
5111 if (action == MotionEvent.ACTION_DOWN) {
5112 WindowState out = mKeyWaiter.mOutsideTouchTargets;
5113 if (out != null) {
5114 MotionEvent oev = MotionEvent.obtain(ev);
5115 oev.setAction(MotionEvent.ACTION_OUTSIDE);
5116 do {
5117 final Rect frame = out.mFrame;
5118 oev.offsetLocation(-(float)frame.left, -(float)frame.top);
5119 try {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005120 out.mClient.dispatchPointer(oev, eventTime, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005121 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005122 Slog.i(TAG, "WINDOW DIED during outside motion dispatch: " + out);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005123 }
5124 oev.offsetLocation((float)frame.left, (float)frame.top);
5125 out = out.mNextOutsideTouch;
5126 } while (out != null);
5127 mKeyWaiter.mOutsideTouchTargets = null;
5128 }
5129 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005130
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005131 dispatchPointerElsewhereLocked(target, null, ev, ev.getEventTime(), false);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005132
Dianne Hackborn6adba242009-11-10 11:10:09 -08005133 final Rect frame = target.mFrame;
5134 ev.offsetLocation(-(float)frame.left, -(float)frame.top);
5135 mKeyWaiter.bindTargetWindowLocked(target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005136 }
5137 }
Romain Guy06882f82009-06-10 13:36:04 -07005138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005139 // finally offset the event to the target's coordinate system and
5140 // dispatch the event.
5141 try {
5142 if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005143 Slog.v(TAG, "Delivering pointer " + qev + " to " + target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005144 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005145
Michael Chan53071d62009-05-13 17:29:48 -07005146 if (MEASURE_LATENCY) {
5147 lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano);
5148 }
5149
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005150 target.mClient.dispatchPointer(ev, eventTime, true);
Michael Chan53071d62009-05-13 17:29:48 -07005151
5152 if (MEASURE_LATENCY) {
5153 lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano);
5154 }
Dianne Hackborncfaef692009-06-15 14:24:44 -07005155 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005156 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005157 Slog.i(TAG, "WINDOW DIED during motion dispatch: " + target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005158 mKeyWaiter.mMotionTarget = null;
5159 try {
5160 removeWindow(target.mSession, target.mClient);
5161 } catch (java.util.NoSuchElementException ex) {
5162 // This will happen if the window has already been
5163 // removed.
5164 }
5165 }
Dianne Hackborncfaef692009-06-15 14:24:44 -07005166 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005167 }
Romain Guy06882f82009-06-10 13:36:04 -07005168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005169 /**
5170 * @return Returns true if event was dispatched, false if it was dropped for any reason
5171 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07005172 private int dispatchTrackball(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005173 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005174 TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">");
Romain Guy06882f82009-06-10 13:36:04 -07005175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005176 Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005177 ev, false, false, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005178 if (focusObj == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005179 Slog.w(TAG, "No focus window, dropping trackball: " + ev);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005180 if (qev != null) {
5181 mQueue.recycleEvent(qev);
5182 }
5183 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005184 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005185 }
5186 if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
5187 if (qev != null) {
5188 mQueue.recycleEvent(qev);
5189 }
5190 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005191 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005192 }
Romain Guy06882f82009-06-10 13:36:04 -07005193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005194 WindowState focus = (WindowState)focusObj;
Romain Guy06882f82009-06-10 13:36:04 -07005195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005196 if (uid != 0 && uid != focus.mSession.mUid) {
5197 if (mContext.checkPermission(
5198 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5199 != PackageManager.PERMISSION_GRANTED) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005200 Slog.w(TAG, "Permission denied: injecting key event from pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005201 + pid + " uid " + uid + " to window " + focus
5202 + " owned by uid " + focus.mSession.mUid);
5203 if (qev != null) {
5204 mQueue.recycleEvent(qev);
5205 }
5206 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005207 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005208 }
5209 }
Romain Guy06882f82009-06-10 13:36:04 -07005210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005211 final long eventTime = ev.getEventTime();
Romain Guy06882f82009-06-10 13:36:04 -07005212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005213 synchronized(mWindowMap) {
5214 if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) {
5215 mKeyWaiter.bindTargetWindowLocked(focus,
5216 KeyWaiter.RETURN_PENDING_TRACKBALL, qev);
5217 // We don't deliver movement events to the client, we hold
5218 // them and wait for them to call back.
5219 ev = null;
5220 } else {
5221 mKeyWaiter.bindTargetWindowLocked(focus);
5222 }
5223 }
Romain Guy06882f82009-06-10 13:36:04 -07005224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005225 try {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005226 focus.mClient.dispatchTrackball(ev, eventTime, true);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005227 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005228 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005229 Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005230 try {
5231 removeWindow(focus.mSession, focus.mClient);
5232 } catch (java.util.NoSuchElementException ex) {
5233 // This will happen if the window has already been
5234 // removed.
5235 }
5236 }
Romain Guy06882f82009-06-10 13:36:04 -07005237
Dianne Hackborncfaef692009-06-15 14:24:44 -07005238 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005239 }
Romain Guy06882f82009-06-10 13:36:04 -07005240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005241 /**
5242 * @return Returns true if event was dispatched, false if it was dropped for any reason
5243 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07005244 private int dispatchKey(KeyEvent event, int pid, int uid) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005245 if (DEBUG_INPUT) Slog.v(TAG, "Dispatch key: " + event);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005246
5247 Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005248 null, false, false, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005249 if (focusObj == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005250 Slog.w(TAG, "No focus window, dropping: " + event);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005251 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005252 }
5253 if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005254 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005255 }
Romain Guy06882f82009-06-10 13:36:04 -07005256
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07005257 // Okay we have finished waiting for the last event to be processed.
5258 // First off, if this is a repeat event, check to see if there is
5259 // a corresponding up event in the queue. If there is, we will
5260 // just drop the repeat, because it makes no sense to repeat after
5261 // the user has released a key. (This is especially important for
5262 // long presses.)
5263 if (event.getRepeatCount() > 0 && mQueue.hasKeyUpEvent(event)) {
5264 return INJECT_SUCCEEDED;
5265 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005267 WindowState focus = (WindowState)focusObj;
Romain Guy06882f82009-06-10 13:36:04 -07005268
Joe Onorato8a9b2202010-02-26 18:56:32 -08005269 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005270 TAG, "Dispatching to " + focus + ": " + event);
5271
5272 if (uid != 0 && uid != focus.mSession.mUid) {
5273 if (mContext.checkPermission(
5274 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5275 != PackageManager.PERMISSION_GRANTED) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005276 Slog.w(TAG, "Permission denied: injecting key event from pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005277 + pid + " uid " + uid + " to window " + focus
5278 + " owned by uid " + focus.mSession.mUid);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005279 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005280 }
5281 }
Romain Guy06882f82009-06-10 13:36:04 -07005282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005283 synchronized(mWindowMap) {
5284 mKeyWaiter.bindTargetWindowLocked(focus);
5285 }
5286
5287 // NOSHIP extra state logging
5288 mKeyWaiter.recordDispatchState(event, focus);
5289 // END NOSHIP
Romain Guy06882f82009-06-10 13:36:04 -07005290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005291 try {
5292 if (DEBUG_INPUT || DEBUG_FOCUS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005293 Slog.v(TAG, "Delivering key " + event.getKeyCode()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005294 + " to " + focus);
5295 }
5296 focus.mClient.dispatchKey(event);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005297 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005298 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005299 Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005300 try {
5301 removeWindow(focus.mSession, focus.mClient);
5302 } catch (java.util.NoSuchElementException ex) {
5303 // This will happen if the window has already been
5304 // removed.
5305 }
5306 }
Romain Guy06882f82009-06-10 13:36:04 -07005307
Dianne Hackborncfaef692009-06-15 14:24:44 -07005308 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005309 }
Romain Guy06882f82009-06-10 13:36:04 -07005310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005311 public void pauseKeyDispatching(IBinder _token) {
5312 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5313 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005314 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005315 }
5316
5317 synchronized (mWindowMap) {
5318 WindowToken token = mTokenMap.get(_token);
5319 if (token != null) {
5320 mKeyWaiter.pauseDispatchingLocked(token);
5321 }
5322 }
5323 }
5324
5325 public void resumeKeyDispatching(IBinder _token) {
5326 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5327 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005328 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005329 }
5330
5331 synchronized (mWindowMap) {
5332 WindowToken token = mTokenMap.get(_token);
5333 if (token != null) {
5334 mKeyWaiter.resumeDispatchingLocked(token);
5335 }
5336 }
5337 }
5338
5339 public void setEventDispatching(boolean enabled) {
5340 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5341 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005342 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005343 }
5344
5345 synchronized (mWindowMap) {
5346 mKeyWaiter.setEventDispatchingLocked(enabled);
5347 }
5348 }
Romain Guy06882f82009-06-10 13:36:04 -07005349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005350 /**
5351 * Injects a keystroke event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005352 *
5353 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005354 * {@link SystemClock#uptimeMillis()} as the timebase.)
5355 * @param sync If true, wait for the event to be completed before returning to the caller.
5356 * @return Returns true if event was dispatched, false if it was dropped for any reason
5357 */
5358 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5359 long downTime = ev.getDownTime();
5360 long eventTime = ev.getEventTime();
5361
5362 int action = ev.getAction();
5363 int code = ev.getKeyCode();
5364 int repeatCount = ev.getRepeatCount();
5365 int metaState = ev.getMetaState();
5366 int deviceId = ev.getDeviceId();
5367 int scancode = ev.getScanCode();
5368
5369 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5370 if (downTime == 0) downTime = eventTime;
5371
5372 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
The Android Open Source Project10592532009-03-18 17:39:46 -07005373 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005374
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005375 final int pid = Binder.getCallingPid();
5376 final int uid = Binder.getCallingUid();
5377 final long ident = Binder.clearCallingIdentity();
5378 final int result = dispatchKey(newEvent, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005379 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005380 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005381 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005382 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005383 switch (result) {
5384 case INJECT_NO_PERMISSION:
5385 throw new SecurityException(
Chander S Pechetty27f3de62010-02-10 22:14:00 +05305386 "Injecting to another application requires INJECT_EVENTS permission");
Dianne Hackborncfaef692009-06-15 14:24:44 -07005387 case INJECT_SUCCEEDED:
5388 return true;
5389 }
5390 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005391 }
5392
5393 /**
5394 * Inject a pointer (touch) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005395 *
5396 * @param ev A motion event describing the pointer (touch) action. (As noted in
5397 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005398 * {@link SystemClock#uptimeMillis()} as the timebase.)
5399 * @param sync If true, wait for the event to be completed before returning to the caller.
5400 * @return Returns true if event was dispatched, false if it was dropped for any reason
5401 */
5402 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005403 final int pid = Binder.getCallingPid();
5404 final int uid = Binder.getCallingUid();
5405 final long ident = Binder.clearCallingIdentity();
5406 final int result = dispatchPointer(null, ev, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005407 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005408 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005409 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005410 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005411 switch (result) {
5412 case INJECT_NO_PERMISSION:
5413 throw new SecurityException(
Chander S Pechetty27f3de62010-02-10 22:14:00 +05305414 "Injecting to another application requires INJECT_EVENTS permission");
Dianne Hackborncfaef692009-06-15 14:24:44 -07005415 case INJECT_SUCCEEDED:
5416 return true;
5417 }
5418 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005419 }
Romain Guy06882f82009-06-10 13:36:04 -07005420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005421 /**
5422 * Inject a trackball (navigation device) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005423 *
5424 * @param ev A motion event describing the trackball action. (As noted in
5425 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005426 * {@link SystemClock#uptimeMillis()} as the timebase.)
5427 * @param sync If true, wait for the event to be completed before returning to the caller.
5428 * @return Returns true if event was dispatched, false if it was dropped for any reason
5429 */
5430 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005431 final int pid = Binder.getCallingPid();
5432 final int uid = Binder.getCallingUid();
5433 final long ident = Binder.clearCallingIdentity();
5434 final int result = dispatchTrackball(null, ev, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005435 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005436 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005437 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005438 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005439 switch (result) {
5440 case INJECT_NO_PERMISSION:
5441 throw new SecurityException(
Chander S Pechetty27f3de62010-02-10 22:14:00 +05305442 "Injecting to another application requires INJECT_EVENTS permission");
Dianne Hackborncfaef692009-06-15 14:24:44 -07005443 case INJECT_SUCCEEDED:
5444 return true;
5445 }
5446 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005447 }
Romain Guy06882f82009-06-10 13:36:04 -07005448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005449 private WindowState getFocusedWindow() {
5450 synchronized (mWindowMap) {
5451 return getFocusedWindowLocked();
5452 }
5453 }
5454
5455 private WindowState getFocusedWindowLocked() {
5456 return mCurrentFocus;
5457 }
Romain Guy06882f82009-06-10 13:36:04 -07005458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005459 /**
5460 * This class holds the state for dispatching key events. This state
5461 * is protected by the KeyWaiter instance, NOT by the window lock. You
5462 * can be holding the main window lock while acquire the KeyWaiter lock,
5463 * but not the other way around.
5464 */
5465 final class KeyWaiter {
5466 // NOSHIP debugging
5467 public class DispatchState {
5468 private KeyEvent event;
5469 private WindowState focus;
5470 private long time;
5471 private WindowState lastWin;
5472 private IBinder lastBinder;
5473 private boolean finished;
5474 private boolean gotFirstWindow;
5475 private boolean eventDispatching;
5476 private long timeToSwitch;
5477 private boolean wasFrozen;
5478 private boolean focusPaused;
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005479 private WindowState curFocus;
Romain Guy06882f82009-06-10 13:36:04 -07005480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005481 DispatchState(KeyEvent theEvent, WindowState theFocus) {
5482 focus = theFocus;
5483 event = theEvent;
5484 time = System.currentTimeMillis();
5485 // snapshot KeyWaiter state
5486 lastWin = mLastWin;
5487 lastBinder = mLastBinder;
5488 finished = mFinished;
5489 gotFirstWindow = mGotFirstWindow;
5490 eventDispatching = mEventDispatching;
5491 timeToSwitch = mTimeToSwitch;
5492 wasFrozen = mWasFrozen;
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005493 curFocus = mCurrentFocus;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005494 // cache the paused state at ctor time as well
5495 if (theFocus == null || theFocus.mToken == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005496 focusPaused = false;
5497 } else {
5498 focusPaused = theFocus.mToken.paused;
5499 }
5500 }
Romain Guy06882f82009-06-10 13:36:04 -07005501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005502 public String toString() {
5503 return "{{" + event + " to " + focus + " @ " + time
5504 + " lw=" + lastWin + " lb=" + lastBinder
5505 + " fin=" + finished + " gfw=" + gotFirstWindow
5506 + " ed=" + eventDispatching + " tts=" + timeToSwitch
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005507 + " wf=" + wasFrozen + " fp=" + focusPaused
Christopher Tate46d45252010-02-09 15:48:57 -08005508 + " mcf=" + curFocus + "}}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005509 }
5510 };
5511 private DispatchState mDispatchState = null;
5512 public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) {
5513 mDispatchState = new DispatchState(theEvent, theFocus);
5514 }
5515 // END NOSHIP
5516
5517 public static final int RETURN_NOTHING = 0;
5518 public static final int RETURN_PENDING_POINTER = 1;
5519 public static final int RETURN_PENDING_TRACKBALL = 2;
Romain Guy06882f82009-06-10 13:36:04 -07005520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005521 final Object SKIP_TARGET_TOKEN = new Object();
5522 final Object CONSUMED_EVENT_TOKEN = new Object();
Romain Guy06882f82009-06-10 13:36:04 -07005523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005524 private WindowState mLastWin = null;
5525 private IBinder mLastBinder = null;
5526 private boolean mFinished = true;
5527 private boolean mGotFirstWindow = false;
5528 private boolean mEventDispatching = true;
5529 private long mTimeToSwitch = 0;
5530 /* package */ boolean mWasFrozen = false;
Romain Guy06882f82009-06-10 13:36:04 -07005531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005532 // Target of Motion events
5533 WindowState mMotionTarget;
Romain Guy06882f82009-06-10 13:36:04 -07005534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005535 // Windows above the target who would like to receive an "outside"
5536 // touch event for any down events outside of them.
5537 WindowState mOutsideTouchTargets;
5538
5539 /**
5540 * Wait for the last event dispatch to complete, then find the next
5541 * target that should receive the given event and wait for that one
5542 * to be ready to receive it.
5543 */
5544 Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev,
5545 MotionEvent nextMotion, boolean isPointerEvent,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005546 boolean failIfTimeout, int callingPid, int callingUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005547 long startTime = SystemClock.uptimeMillis();
5548 long keyDispatchingTimeout = 5 * 1000;
5549 long waitedFor = 0;
5550
5551 while (true) {
5552 // Figure out which window we care about. It is either the
5553 // last window we are waiting to have process the event or,
5554 // if none, then the next window we think the event should go
5555 // to. Note: we retrieve mLastWin outside of the lock, so
5556 // it may change before we lock. Thus we must check it again.
5557 WindowState targetWin = mLastWin;
5558 boolean targetIsNew = targetWin == null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005559 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005560 TAG, "waitForLastKey: mFinished=" + mFinished +
5561 ", mLastWin=" + mLastWin);
5562 if (targetIsNew) {
5563 Object target = findTargetWindow(nextKey, qev, nextMotion,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005564 isPointerEvent, callingPid, callingUid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005565 if (target == SKIP_TARGET_TOKEN) {
5566 // The user has pressed a special key, and we are
5567 // dropping all pending events before it.
Joe Onorato8a9b2202010-02-26 18:56:32 -08005568 if (DEBUG_INPUT) Slog.v(TAG, "Skipping: " + nextKey
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005569 + " " + nextMotion);
5570 return null;
5571 }
5572 if (target == CONSUMED_EVENT_TOKEN) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005573 if (DEBUG_INPUT) Slog.v(TAG, "Consumed: " + nextKey
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005574 + " " + nextMotion);
5575 return target;
5576 }
5577 targetWin = (WindowState)target;
5578 }
Romain Guy06882f82009-06-10 13:36:04 -07005579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005580 AppWindowToken targetApp = null;
Romain Guy06882f82009-06-10 13:36:04 -07005581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005582 // Now: is it okay to send the next event to this window?
5583 synchronized (this) {
5584 // First: did we come here based on the last window not
5585 // being null, but it changed by the time we got here?
5586 // If so, try again.
5587 if (!targetIsNew && mLastWin == null) {
5588 continue;
5589 }
Romain Guy06882f82009-06-10 13:36:04 -07005590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005591 // We never dispatch events if not finished with the
5592 // last one, or the display is frozen.
5593 if (mFinished && !mDisplayFrozen) {
5594 // If event dispatching is disabled, then we
5595 // just consume the events.
5596 if (!mEventDispatching) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005597 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005598 "Skipping event; dispatching disabled: "
5599 + nextKey + " " + nextMotion);
5600 return null;
5601 }
5602 if (targetWin != null) {
5603 // If this is a new target, and that target is not
5604 // paused or unresponsive, then all looks good to
5605 // handle the event.
5606 if (targetIsNew && !targetWin.mToken.paused) {
5607 return targetWin;
5608 }
Romain Guy06882f82009-06-10 13:36:04 -07005609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005610 // If we didn't find a target window, and there is no
5611 // focused app window, then just eat the events.
5612 } else if (mFocusedApp == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005613 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005614 "Skipping event; no focused app: "
5615 + nextKey + " " + nextMotion);
5616 return null;
5617 }
5618 }
Romain Guy06882f82009-06-10 13:36:04 -07005619
Joe Onorato8a9b2202010-02-26 18:56:32 -08005620 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005621 TAG, "Waiting for last key in " + mLastBinder
5622 + " target=" + targetWin
5623 + " mFinished=" + mFinished
5624 + " mDisplayFrozen=" + mDisplayFrozen
5625 + " targetIsNew=" + targetIsNew
5626 + " paused="
5627 + (targetWin != null ? targetWin.mToken.paused : false)
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005628 + " mFocusedApp=" + mFocusedApp
5629 + " mCurrentFocus=" + mCurrentFocus);
Romain Guy06882f82009-06-10 13:36:04 -07005630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005631 targetApp = targetWin != null
5632 ? targetWin.mAppToken : mFocusedApp;
Romain Guy06882f82009-06-10 13:36:04 -07005633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005634 long curTimeout = keyDispatchingTimeout;
5635 if (mTimeToSwitch != 0) {
5636 long now = SystemClock.uptimeMillis();
5637 if (mTimeToSwitch <= now) {
5638 // If an app switch key has been pressed, and we have
5639 // waited too long for the current app to finish
5640 // processing keys, then wait no more!
Christopher Tate136b1f92010-02-11 17:51:24 -08005641 doFinishedKeyLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005642 continue;
5643 }
5644 long switchTimeout = mTimeToSwitch - now;
5645 if (curTimeout > switchTimeout) {
5646 curTimeout = switchTimeout;
5647 }
5648 }
Romain Guy06882f82009-06-10 13:36:04 -07005649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005650 try {
5651 // after that continue
5652 // processing keys, so we don't get stuck.
Joe Onorato8a9b2202010-02-26 18:56:32 -08005653 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005654 TAG, "Waiting for key dispatch: " + curTimeout);
5655 wait(curTimeout);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005656 if (DEBUG_INPUT) Slog.v(TAG, "Finished waiting @"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005657 + SystemClock.uptimeMillis() + " startTime="
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005658 + startTime + " switchTime=" + mTimeToSwitch
5659 + " target=" + targetWin + " mLW=" + mLastWin
5660 + " mLB=" + mLastBinder + " fin=" + mFinished
5661 + " mCurrentFocus=" + mCurrentFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005662 } catch (InterruptedException e) {
5663 }
5664 }
5665
5666 // If we were frozen during configuration change, restart the
5667 // timeout checks from now; otherwise look at whether we timed
5668 // out before awakening.
5669 if (mWasFrozen) {
5670 waitedFor = 0;
5671 mWasFrozen = false;
5672 } else {
5673 waitedFor = SystemClock.uptimeMillis() - startTime;
5674 }
5675
5676 if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) {
5677 IApplicationToken at = null;
5678 synchronized (this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005679 Slog.w(TAG, "Key dispatching timed out sending to " +
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005680 (targetWin != null ? targetWin.mAttrs.getTitle()
Ken Shirriff8200b202010-02-04 13:34:37 -08005681 : "<null>: no window ready for key dispatch"));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005682 // NOSHIP debugging
Joe Onorato8a9b2202010-02-26 18:56:32 -08005683 Slog.w(TAG, "Previous dispatch state: " + mDispatchState);
5684 Slog.w(TAG, "Current dispatch state: " +
Ken Shirriff8200b202010-02-04 13:34:37 -08005685 new DispatchState(nextKey, targetWin));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005686 // END NOSHIP
5687 //dump();
5688 if (targetWin != null) {
5689 at = targetWin.getAppToken();
5690 } else if (targetApp != null) {
5691 at = targetApp.appToken;
5692 }
5693 }
5694
5695 boolean abort = true;
5696 if (at != null) {
5697 try {
5698 long timeout = at.getKeyDispatchingTimeout();
5699 if (timeout > waitedFor) {
5700 // we did not wait the proper amount of time for this application.
5701 // set the timeout to be the real timeout and wait again.
5702 keyDispatchingTimeout = timeout - waitedFor;
5703 continue;
5704 } else {
5705 abort = at.keyDispatchingTimedOut();
5706 }
5707 } catch (RemoteException ex) {
5708 }
5709 }
5710
5711 synchronized (this) {
5712 if (abort && (mLastWin == targetWin || targetWin == null)) {
5713 mFinished = true;
Romain Guy06882f82009-06-10 13:36:04 -07005714 if (mLastWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005715 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005716 "Window " + mLastWin +
5717 " timed out on key input");
5718 if (mLastWin.mToken.paused) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005719 Slog.w(TAG, "Un-pausing dispatching to this window");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005720 mLastWin.mToken.paused = false;
5721 }
5722 }
5723 if (mMotionTarget == targetWin) {
5724 mMotionTarget = null;
5725 }
5726 mLastWin = null;
5727 mLastBinder = null;
5728 if (failIfTimeout || targetWin == null) {
5729 return null;
5730 }
5731 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005732 Slog.w(TAG, "Continuing to wait for key to be dispatched");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005733 startTime = SystemClock.uptimeMillis();
5734 }
5735 }
5736 }
5737 }
5738 }
Romain Guy06882f82009-06-10 13:36:04 -07005739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005740 Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005741 MotionEvent nextMotion, boolean isPointerEvent,
5742 int callingPid, int callingUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005743 mOutsideTouchTargets = null;
Romain Guy06882f82009-06-10 13:36:04 -07005744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005745 if (nextKey != null) {
5746 // Find the target window for a normal key event.
5747 final int keycode = nextKey.getKeyCode();
5748 final int repeatCount = nextKey.getRepeatCount();
5749 final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP;
5750 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005752 if (!dispatch) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005753 if (callingUid == 0 ||
5754 mContext.checkPermission(
5755 android.Manifest.permission.INJECT_EVENTS,
5756 callingPid, callingUid)
5757 == PackageManager.PERMISSION_GRANTED) {
5758 mPolicy.interceptKeyTi(null, keycode,
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07005759 nextKey.getMetaState(), down, repeatCount,
5760 nextKey.getFlags());
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005761 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08005762 Slog.w(TAG, "Event timeout during app switch: dropping "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005763 + nextKey);
5764 return SKIP_TARGET_TOKEN;
5765 }
Romain Guy06882f82009-06-10 13:36:04 -07005766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005767 // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")");
Romain Guy06882f82009-06-10 13:36:04 -07005768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005769 WindowState focus = null;
5770 synchronized(mWindowMap) {
5771 focus = getFocusedWindowLocked();
5772 }
Romain Guy06882f82009-06-10 13:36:04 -07005773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005774 wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT);
Romain Guy06882f82009-06-10 13:36:04 -07005775
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005776 if (callingUid == 0 ||
5777 (focus != null && callingUid == focus.mSession.mUid) ||
5778 mContext.checkPermission(
5779 android.Manifest.permission.INJECT_EVENTS,
5780 callingPid, callingUid)
5781 == PackageManager.PERMISSION_GRANTED) {
5782 if (mPolicy.interceptKeyTi(focus,
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005783 keycode, nextKey.getMetaState(), down, repeatCount,
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07005784 nextKey.getFlags())) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005785 return CONSUMED_EVENT_TOKEN;
5786 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005787 }
Romain Guy06882f82009-06-10 13:36:04 -07005788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005789 return focus;
Romain Guy06882f82009-06-10 13:36:04 -07005790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005791 } else if (!isPointerEvent) {
5792 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1);
5793 if (!dispatch) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005794 Slog.w(TAG, "Event timeout during app switch: dropping trackball "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005795 + nextMotion);
5796 return SKIP_TARGET_TOKEN;
5797 }
Romain Guy06882f82009-06-10 13:36:04 -07005798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005799 WindowState focus = null;
5800 synchronized(mWindowMap) {
5801 focus = getFocusedWindowLocked();
5802 }
Romain Guy06882f82009-06-10 13:36:04 -07005803
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005804 wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT);
5805 return focus;
5806 }
Romain Guy06882f82009-06-10 13:36:04 -07005807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005808 if (nextMotion == null) {
5809 return SKIP_TARGET_TOKEN;
5810 }
Romain Guy06882f82009-06-10 13:36:04 -07005811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005812 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(
5813 KeyEvent.KEYCODE_UNKNOWN);
5814 if (!dispatch) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005815 Slog.w(TAG, "Event timeout during app switch: dropping pointer "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005816 + nextMotion);
5817 return SKIP_TARGET_TOKEN;
5818 }
Romain Guy06882f82009-06-10 13:36:04 -07005819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005820 // Find the target window for a pointer event.
5821 int action = nextMotion.getAction();
5822 final float xf = nextMotion.getX();
5823 final float yf = nextMotion.getY();
5824 final long eventTime = nextMotion.getEventTime();
Romain Guy06882f82009-06-10 13:36:04 -07005825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005826 final boolean screenWasOff = qev != null
5827 && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07005828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005829 WindowState target = null;
Romain Guy06882f82009-06-10 13:36:04 -07005830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005831 synchronized(mWindowMap) {
5832 synchronized (this) {
5833 if (action == MotionEvent.ACTION_DOWN) {
5834 if (mMotionTarget != null) {
5835 // this is weird, we got a pen down, but we thought it was
5836 // already down!
5837 // XXX: We should probably send an ACTION_UP to the current
5838 // target.
Joe Onorato8a9b2202010-02-26 18:56:32 -08005839 Slog.w(TAG, "Pointer down received while already down in: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005840 + mMotionTarget);
5841 mMotionTarget = null;
5842 }
Romain Guy06882f82009-06-10 13:36:04 -07005843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005844 // ACTION_DOWN is special, because we need to lock next events to
5845 // the window we'll land onto.
5846 final int x = (int)xf;
5847 final int y = (int)yf;
Romain Guy06882f82009-06-10 13:36:04 -07005848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005849 final ArrayList windows = mWindows;
5850 final int N = windows.size();
5851 WindowState topErrWindow = null;
5852 final Rect tmpRect = mTempRect;
5853 for (int i=N-1; i>=0; i--) {
5854 WindowState child = (WindowState)windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005855 //Slog.i(TAG, "Checking dispatch to: " + child);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005856 final int flags = child.mAttrs.flags;
5857 if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) {
5858 if (topErrWindow == null) {
5859 topErrWindow = child;
5860 }
5861 }
5862 if (!child.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005863 //Slog.i(TAG, "Not visible!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005864 continue;
5865 }
5866 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005867 //Slog.i(TAG, "Not touchable!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005868 if ((flags & WindowManager.LayoutParams
5869 .FLAG_WATCH_OUTSIDE_TOUCH) != 0) {
5870 child.mNextOutsideTouch = mOutsideTouchTargets;
5871 mOutsideTouchTargets = child;
5872 }
5873 continue;
5874 }
5875 tmpRect.set(child.mFrame);
5876 if (child.mTouchableInsets == ViewTreeObserver
5877 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
5878 // The touch is inside of the window if it is
5879 // inside the frame, AND the content part of that
5880 // frame that was given by the application.
5881 tmpRect.left += child.mGivenContentInsets.left;
5882 tmpRect.top += child.mGivenContentInsets.top;
5883 tmpRect.right -= child.mGivenContentInsets.right;
5884 tmpRect.bottom -= child.mGivenContentInsets.bottom;
5885 } else if (child.mTouchableInsets == ViewTreeObserver
5886 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
5887 // The touch is inside of the window if it is
5888 // inside the frame, AND the visible part of that
5889 // frame that was given by the application.
5890 tmpRect.left += child.mGivenVisibleInsets.left;
5891 tmpRect.top += child.mGivenVisibleInsets.top;
5892 tmpRect.right -= child.mGivenVisibleInsets.right;
5893 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
5894 }
5895 final int touchFlags = flags &
5896 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
5897 |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
5898 if (tmpRect.contains(x, y) || touchFlags == 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005899 //Slog.i(TAG, "Using this target!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005900 if (!screenWasOff || (flags &
5901 WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) {
5902 mMotionTarget = child;
5903 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005904 //Slog.i(TAG, "Waking, skip!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005905 mMotionTarget = null;
5906 }
5907 break;
5908 }
Romain Guy06882f82009-06-10 13:36:04 -07005909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005910 if ((flags & WindowManager.LayoutParams
5911 .FLAG_WATCH_OUTSIDE_TOUCH) != 0) {
5912 child.mNextOutsideTouch = mOutsideTouchTargets;
5913 mOutsideTouchTargets = child;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005914 //Slog.i(TAG, "Adding to outside target list: " + child);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005915 }
5916 }
5917
5918 // if there's an error window but it's not accepting
5919 // focus (typically because it is not yet visible) just
5920 // wait for it -- any other focused window may in fact
5921 // be in ANR state.
5922 if (topErrWindow != null && mMotionTarget != topErrWindow) {
5923 mMotionTarget = null;
5924 }
5925 }
Romain Guy06882f82009-06-10 13:36:04 -07005926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005927 target = mMotionTarget;
5928 }
5929 }
Romain Guy06882f82009-06-10 13:36:04 -07005930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005931 wakeupIfNeeded(target, eventType(nextMotion));
Romain Guy06882f82009-06-10 13:36:04 -07005932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005933 // Pointer events are a little different -- if there isn't a
5934 // target found for any event, then just drop it.
5935 return target != null ? target : SKIP_TARGET_TOKEN;
5936 }
Romain Guy06882f82009-06-10 13:36:04 -07005937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005938 boolean checkShouldDispatchKey(int keycode) {
5939 synchronized (this) {
5940 if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) {
5941 mTimeToSwitch = 0;
5942 return true;
5943 }
5944 if (mTimeToSwitch != 0
5945 && mTimeToSwitch < SystemClock.uptimeMillis()) {
5946 return false;
5947 }
5948 return true;
5949 }
5950 }
Romain Guy06882f82009-06-10 13:36:04 -07005951
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005952 void bindTargetWindowLocked(WindowState win,
5953 int pendingWhat, QueuedEvent pendingMotion) {
5954 synchronized (this) {
5955 bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion);
5956 }
5957 }
Romain Guy06882f82009-06-10 13:36:04 -07005958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005959 void bindTargetWindowLocked(WindowState win) {
5960 synchronized (this) {
5961 bindTargetWindowLockedLocked(win, RETURN_NOTHING, null);
5962 }
5963 }
5964
5965 void bindTargetWindowLockedLocked(WindowState win,
5966 int pendingWhat, QueuedEvent pendingMotion) {
5967 mLastWin = win;
5968 mLastBinder = win.mClient.asBinder();
5969 mFinished = false;
5970 if (pendingMotion != null) {
5971 final Session s = win.mSession;
5972 if (pendingWhat == RETURN_PENDING_POINTER) {
5973 releasePendingPointerLocked(s);
5974 s.mPendingPointerMove = pendingMotion;
5975 s.mPendingPointerWindow = win;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005976 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005977 "bindTargetToWindow " + s.mPendingPointerMove);
5978 } else if (pendingWhat == RETURN_PENDING_TRACKBALL) {
5979 releasePendingTrackballLocked(s);
5980 s.mPendingTrackballMove = pendingMotion;
5981 s.mPendingTrackballWindow = win;
5982 }
5983 }
5984 }
Romain Guy06882f82009-06-10 13:36:04 -07005985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005986 void releasePendingPointerLocked(Session s) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005987 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005988 "releasePendingPointer " + s.mPendingPointerMove);
5989 if (s.mPendingPointerMove != null) {
5990 mQueue.recycleEvent(s.mPendingPointerMove);
5991 s.mPendingPointerMove = null;
5992 }
5993 }
Romain Guy06882f82009-06-10 13:36:04 -07005994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005995 void releasePendingTrackballLocked(Session s) {
5996 if (s.mPendingTrackballMove != null) {
5997 mQueue.recycleEvent(s.mPendingTrackballMove);
5998 s.mPendingTrackballMove = null;
5999 }
6000 }
Romain Guy06882f82009-06-10 13:36:04 -07006001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006002 MotionEvent finishedKey(Session session, IWindow client, boolean force,
6003 int returnWhat) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006004 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006005 TAG, "finishedKey: client=" + client + ", force=" + force);
6006
6007 if (client == null) {
6008 return null;
6009 }
6010
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006011 MotionEvent res = null;
6012 QueuedEvent qev = null;
6013 WindowState win = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006015 synchronized (this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006016 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006017 TAG, "finishedKey: client=" + client.asBinder()
6018 + ", force=" + force + ", last=" + mLastBinder
6019 + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")");
6020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006021 if (returnWhat == RETURN_PENDING_POINTER) {
6022 qev = session.mPendingPointerMove;
6023 win = session.mPendingPointerWindow;
6024 session.mPendingPointerMove = null;
6025 session.mPendingPointerWindow = null;
6026 } else if (returnWhat == RETURN_PENDING_TRACKBALL) {
6027 qev = session.mPendingTrackballMove;
6028 win = session.mPendingTrackballWindow;
6029 session.mPendingTrackballMove = null;
6030 session.mPendingTrackballWindow = null;
6031 }
Romain Guy06882f82009-06-10 13:36:04 -07006032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006033 if (mLastBinder == client.asBinder()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006034 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006035 TAG, "finishedKey: last paused="
6036 + ((mLastWin != null) ? mLastWin.mToken.paused : "null"));
6037 if (mLastWin != null && (!mLastWin.mToken.paused || force
6038 || !mEventDispatching)) {
Christopher Tate136b1f92010-02-11 17:51:24 -08006039 doFinishedKeyLocked(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006040 } else {
6041 // Make sure to wake up anyone currently waiting to
6042 // dispatch a key, so they can re-evaluate their
6043 // current situation.
6044 mFinished = true;
6045 notifyAll();
6046 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006047 }
Romain Guy06882f82009-06-10 13:36:04 -07006048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006049 if (qev != null) {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006050 res = (MotionEvent)qev.event;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006051 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006052 "Returning pending motion: " + res);
6053 mQueue.recycleEvent(qev);
6054 if (win != null && returnWhat == RETURN_PENDING_POINTER) {
6055 res.offsetLocation(-win.mFrame.left, -win.mFrame.top);
6056 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006057 }
Christopher Tate2624fbc2009-12-11 12:11:31 -08006058 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006059
Christopher Tate2624fbc2009-12-11 12:11:31 -08006060 if (res != null && returnWhat == RETURN_PENDING_POINTER) {
6061 synchronized (mWindowMap) {
Dianne Hackborn90d2db32010-02-11 22:19:06 -08006062 dispatchPointerElsewhereLocked(win, win, res, res.getEventTime(), false);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006063 }
6064 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006065
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006066 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006067 }
6068
6069 void tickle() {
6070 synchronized (this) {
6071 notifyAll();
6072 }
6073 }
Romain Guy06882f82009-06-10 13:36:04 -07006074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006075 void handleNewWindowLocked(WindowState newWindow) {
6076 if (!newWindow.canReceiveKeys()) {
6077 return;
6078 }
6079 synchronized (this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006080 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006081 TAG, "New key dispatch window: win="
6082 + newWindow.mClient.asBinder()
6083 + ", last=" + mLastBinder
6084 + " (token=" + (mLastWin != null ? mLastWin.mToken : null)
6085 + "), finished=" + mFinished + ", paused="
6086 + newWindow.mToken.paused);
6087
6088 // Displaying a window implicitly causes dispatching to
6089 // be unpaused. (This is to protect against bugs if someone
6090 // pauses dispatching but forgets to resume.)
6091 newWindow.mToken.paused = false;
6092
6093 mGotFirstWindow = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006094
6095 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006096 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006097 "New SYSTEM_ERROR window; resetting state");
6098 mLastWin = null;
6099 mLastBinder = null;
6100 mMotionTarget = null;
6101 mFinished = true;
6102 } else if (mLastWin != null) {
6103 // If the new window is above the window we are
6104 // waiting on, then stop waiting and let key dispatching
6105 // start on the new guy.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006106 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006107 TAG, "Last win layer=" + mLastWin.mLayer
6108 + ", new win layer=" + newWindow.mLayer);
6109 if (newWindow.mLayer >= mLastWin.mLayer) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08006110 // The new window is above the old; finish pending input to the last
6111 // window and start directing it to the new one.
6112 mLastWin.mToken.paused = false;
Christopher Tate136b1f92010-02-11 17:51:24 -08006113 doFinishedKeyLocked(false); // does a notifyAll()
6114 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006115 }
6116 }
6117
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08006118 // Now that we've put a new window state in place, make the event waiter
6119 // take notice and retarget its attentions.
6120 notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006121 }
6122 }
6123
6124 void pauseDispatchingLocked(WindowToken token) {
6125 synchronized (this)
6126 {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006127 if (DEBUG_INPUT) Slog.v(TAG, "Pausing WindowToken " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006128 token.paused = true;
6129
6130 /*
6131 if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) {
6132 mPaused = true;
6133 } else {
6134 if (mLastWin == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006135 Slog.i(TAG, "Key dispatching not paused: no last window.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006136 } else if (mFinished) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006137 Slog.i(TAG, "Key dispatching not paused: finished last key.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006138 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006139 Slog.i(TAG, "Key dispatching not paused: window in higher layer.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006140 }
6141 }
6142 */
6143 }
6144 }
6145
6146 void resumeDispatchingLocked(WindowToken token) {
6147 synchronized (this) {
6148 if (token.paused) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006149 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006150 TAG, "Resuming WindowToken " + token
6151 + ", last=" + mLastBinder
6152 + " (token=" + (mLastWin != null ? mLastWin.mToken : null)
6153 + "), finished=" + mFinished + ", paused="
6154 + token.paused);
6155 token.paused = false;
6156 if (mLastWin != null && mLastWin.mToken == token && mFinished) {
Christopher Tate136b1f92010-02-11 17:51:24 -08006157 doFinishedKeyLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006158 } else {
6159 notifyAll();
6160 }
6161 }
6162 }
6163 }
6164
6165 void setEventDispatchingLocked(boolean enabled) {
6166 synchronized (this) {
6167 mEventDispatching = enabled;
6168 notifyAll();
6169 }
6170 }
Romain Guy06882f82009-06-10 13:36:04 -07006171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006172 void appSwitchComing() {
6173 synchronized (this) {
6174 // Don't wait for more than .5 seconds for app to finish
6175 // processing the pending events.
6176 long now = SystemClock.uptimeMillis() + 500;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006177 if (DEBUG_INPUT) Slog.v(TAG, "appSwitchComing: " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006178 if (mTimeToSwitch == 0 || now < mTimeToSwitch) {
6179 mTimeToSwitch = now;
6180 }
6181 notifyAll();
6182 }
6183 }
Romain Guy06882f82009-06-10 13:36:04 -07006184
Christopher Tate136b1f92010-02-11 17:51:24 -08006185 private final void doFinishedKeyLocked(boolean force) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006186 if (mLastWin != null) {
6187 releasePendingPointerLocked(mLastWin.mSession);
6188 releasePendingTrackballLocked(mLastWin.mSession);
6189 }
Romain Guy06882f82009-06-10 13:36:04 -07006190
Christopher Tate136b1f92010-02-11 17:51:24 -08006191 if (force || mLastWin == null || !mLastWin.mToken.paused
6192 || !mLastWin.isVisibleLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006193 // If the current window has been paused, we aren't -really-
6194 // finished... so let the waiters still wait.
6195 mLastWin = null;
6196 mLastBinder = null;
6197 }
6198 mFinished = true;
6199 notifyAll();
6200 }
6201 }
6202
6203 private class KeyQ extends KeyInputQueue
6204 implements KeyInputQueue.FilterCallback {
6205 PowerManager.WakeLock mHoldingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07006206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006207 KeyQ() {
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07006208 super(mContext, WindowManagerService.this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006209 PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
6210 mHoldingScreen = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
6211 "KEEP_SCREEN_ON_FLAG");
6212 mHoldingScreen.setReferenceCounted(false);
6213 }
6214
6215 @Override
6216 boolean preprocessEvent(InputDevice device, RawInputEvent event) {
6217 if (mPolicy.preprocessInputEventTq(event)) {
6218 return true;
6219 }
Romain Guy06882f82009-06-10 13:36:04 -07006220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006221 switch (event.type) {
6222 case RawInputEvent.EV_KEY: {
6223 // XXX begin hack
6224 if (DEBUG) {
6225 if (event.keycode == KeyEvent.KEYCODE_G) {
6226 if (event.value != 0) {
6227 // G down
6228 mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
6229 }
6230 return false;
6231 }
6232 if (event.keycode == KeyEvent.KEYCODE_D) {
6233 if (event.value != 0) {
6234 //dump();
6235 }
6236 return false;
6237 }
6238 }
6239 // XXX end hack
Romain Guy06882f82009-06-10 13:36:04 -07006240
Charles Mendis322591c2009-10-29 11:06:59 -07006241 boolean screenIsOff = !mPowerManager.isScreenOn();
6242 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006243 int actions = mPolicy.interceptKeyTq(event, !screenIsOff);
Romain Guy06882f82009-06-10 13:36:04 -07006244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006245 if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) {
6246 mPowerManager.goToSleep(event.when);
6247 }
6248
6249 if (screenIsOff) {
6250 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6251 }
6252 if (screenIsDim) {
6253 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6254 }
6255 if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) {
6256 mPowerManager.userActivity(event.when, false,
Michael Chane96440f2009-05-06 10:27:36 -07006257 LocalPowerManager.BUTTON_EVENT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006258 }
Romain Guy06882f82009-06-10 13:36:04 -07006259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006260 if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) {
6261 if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) {
6262 filterQueue(this);
6263 mKeyWaiter.appSwitchComing();
6264 }
6265 return true;
6266 } else {
6267 return false;
6268 }
6269 }
Romain Guy06882f82009-06-10 13:36:04 -07006270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006271 case RawInputEvent.EV_REL: {
Charles Mendis322591c2009-10-29 11:06:59 -07006272 boolean screenIsOff = !mPowerManager.isScreenOn();
6273 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006274 if (screenIsOff) {
6275 if (!mPolicy.isWakeRelMovementTq(event.deviceId,
6276 device.classes, event)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006277 //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006278 return false;
6279 }
6280 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6281 }
6282 if (screenIsDim) {
6283 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6284 }
6285 return true;
6286 }
Romain Guy06882f82009-06-10 13:36:04 -07006287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006288 case RawInputEvent.EV_ABS: {
Charles Mendis322591c2009-10-29 11:06:59 -07006289 boolean screenIsOff = !mPowerManager.isScreenOn();
6290 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006291 if (screenIsOff) {
6292 if (!mPolicy.isWakeAbsMovementTq(event.deviceId,
6293 device.classes, event)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006294 //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006295 return false;
6296 }
6297 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6298 }
6299 if (screenIsDim) {
6300 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6301 }
6302 return true;
6303 }
Romain Guy06882f82009-06-10 13:36:04 -07006304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006305 default:
6306 return true;
6307 }
6308 }
6309
6310 public int filterEvent(QueuedEvent ev) {
6311 switch (ev.classType) {
6312 case RawInputEvent.CLASS_KEYBOARD:
6313 KeyEvent ke = (KeyEvent)ev.event;
6314 if (mPolicy.isMovementKeyTi(ke.getKeyCode())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006315 Slog.w(TAG, "Dropping movement key during app switch: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006316 + ke.getKeyCode() + ", action=" + ke.getAction());
6317 return FILTER_REMOVE;
6318 }
6319 return FILTER_ABORT;
6320 default:
6321 return FILTER_KEEP;
6322 }
6323 }
Romain Guy06882f82009-06-10 13:36:04 -07006324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006325 /**
6326 * Must be called with the main window manager lock held.
6327 */
6328 void setHoldScreenLocked(boolean holding) {
6329 boolean state = mHoldingScreen.isHeld();
6330 if (holding != state) {
6331 if (holding) {
6332 mHoldingScreen.acquire();
6333 } else {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006334 mPolicy.screenOnStoppedLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006335 mHoldingScreen.release();
6336 }
6337 }
6338 }
Michael Chan53071d62009-05-13 17:29:48 -07006339 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006340
6341 public boolean detectSafeMode() {
6342 mSafeMode = mPolicy.detectSafeMode();
6343 return mSafeMode;
6344 }
Romain Guy06882f82009-06-10 13:36:04 -07006345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006346 public void systemReady() {
6347 mPolicy.systemReady();
6348 }
Romain Guy06882f82009-06-10 13:36:04 -07006349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006350 private final class InputDispatcherThread extends Thread {
6351 // Time to wait when there is nothing to do: 9999 seconds.
6352 static final int LONG_WAIT=9999*1000;
6353
6354 public InputDispatcherThread() {
6355 super("InputDispatcher");
6356 }
Romain Guy06882f82009-06-10 13:36:04 -07006357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006358 @Override
6359 public void run() {
6360 while (true) {
6361 try {
6362 process();
6363 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006364 Slog.e(TAG, "Exception in input dispatcher", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006365 }
6366 }
6367 }
Romain Guy06882f82009-06-10 13:36:04 -07006368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006369 private void process() {
6370 android.os.Process.setThreadPriority(
6371 android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);
Romain Guy06882f82009-06-10 13:36:04 -07006372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006373 // The last key event we saw
6374 KeyEvent lastKey = null;
6375
6376 // Last keydown time for auto-repeating keys
6377 long lastKeyTime = SystemClock.uptimeMillis();
6378 long nextKeyTime = lastKeyTime+LONG_WAIT;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006379 long downTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006380
Romain Guy06882f82009-06-10 13:36:04 -07006381 // How many successive repeats we generated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006382 int keyRepeatCount = 0;
6383
6384 // Need to report that configuration has changed?
6385 boolean configChanged = false;
Romain Guy06882f82009-06-10 13:36:04 -07006386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006387 while (true) {
6388 long curTime = SystemClock.uptimeMillis();
6389
Joe Onorato8a9b2202010-02-26 18:56:32 -08006390 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006391 TAG, "Waiting for next key: now=" + curTime
6392 + ", repeat @ " + nextKeyTime);
6393
6394 // Retrieve next event, waiting only as long as the next
6395 // repeat timeout. If the configuration has changed, then
6396 // don't wait at all -- we'll report the change as soon as
6397 // we have processed all events.
6398 QueuedEvent ev = mQueue.getEvent(
6399 (int)((!configChanged && curTime < nextKeyTime)
6400 ? (nextKeyTime-curTime) : 0));
6401
Joe Onorato8a9b2202010-02-26 18:56:32 -08006402 if (DEBUG_INPUT && ev != null) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006403 TAG, "Event: type=" + ev.classType + " data=" + ev.event);
6404
Michael Chan53071d62009-05-13 17:29:48 -07006405 if (MEASURE_LATENCY) {
6406 lt.sample("2 got event ", System.nanoTime() - ev.whenNano);
6407 }
6408
Mike Lockwood3d0ea722009-10-21 22:58:29 -04006409 if (lastKey != null && !mPolicy.allowKeyRepeat()) {
6410 // cancel key repeat at the request of the policy.
6411 lastKey = null;
6412 downTime = 0;
6413 lastKeyTime = curTime;
6414 nextKeyTime = curTime + LONG_WAIT;
6415 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006416 try {
6417 if (ev != null) {
Michael Chan53071d62009-05-13 17:29:48 -07006418 curTime = SystemClock.uptimeMillis();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006419 int eventType;
6420 if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) {
6421 eventType = eventType((MotionEvent)ev.event);
6422 } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD ||
6423 ev.classType == RawInputEvent.CLASS_TRACKBALL) {
6424 eventType = LocalPowerManager.BUTTON_EVENT;
6425 } else {
6426 eventType = LocalPowerManager.OTHER_EVENT;
6427 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07006428 try {
Michael Chan53071d62009-05-13 17:29:48 -07006429 if ((curTime - mLastBatteryStatsCallTime)
Michael Chane96440f2009-05-06 10:27:36 -07006430 >= MIN_TIME_BETWEEN_USERACTIVITIES) {
Michael Chan53071d62009-05-13 17:29:48 -07006431 mLastBatteryStatsCallTime = curTime;
Michael Chane96440f2009-05-06 10:27:36 -07006432 mBatteryStats.noteInputEvent();
6433 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07006434 } catch (RemoteException e) {
6435 // Ignore
6436 }
Michael Chane10de972009-05-18 11:24:50 -07006437
Mike Lockwood5db42402009-11-30 14:51:51 -05006438 if (ev.classType == RawInputEvent.CLASS_CONFIGURATION_CHANGED) {
6439 // do not wake screen in this case
6440 } else if (eventType != TOUCH_EVENT
Michael Chane10de972009-05-18 11:24:50 -07006441 && eventType != LONG_TOUCH_EVENT
6442 && eventType != CHEEK_EVENT) {
6443 mPowerManager.userActivity(curTime, false,
6444 eventType, false);
6445 } else if (mLastTouchEventType != eventType
6446 || (curTime - mLastUserActivityCallTime)
6447 >= MIN_TIME_BETWEEN_USERACTIVITIES) {
6448 mLastUserActivityCallTime = curTime;
6449 mLastTouchEventType = eventType;
6450 mPowerManager.userActivity(curTime, false,
6451 eventType, false);
6452 }
6453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006454 switch (ev.classType) {
6455 case RawInputEvent.CLASS_KEYBOARD:
6456 KeyEvent ke = (KeyEvent)ev.event;
6457 if (ke.isDown()) {
6458 lastKey = ke;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006459 downTime = curTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006460 keyRepeatCount = 0;
6461 lastKeyTime = curTime;
6462 nextKeyTime = lastKeyTime
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006463 + ViewConfiguration.getLongPressTimeout();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006464 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006465 TAG, "Received key down: first repeat @ "
6466 + nextKeyTime);
6467 } else {
6468 lastKey = null;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006469 downTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006470 // Arbitrary long timeout.
6471 lastKeyTime = curTime;
6472 nextKeyTime = curTime + LONG_WAIT;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006473 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006474 TAG, "Received key up: ignore repeat @ "
6475 + nextKeyTime);
6476 }
6477 dispatchKey((KeyEvent)ev.event, 0, 0);
6478 mQueue.recycleEvent(ev);
6479 break;
6480 case RawInputEvent.CLASS_TOUCHSCREEN:
Joe Onorato8a9b2202010-02-26 18:56:32 -08006481 //Slog.i(TAG, "Read next event " + ev);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006482 dispatchPointer(ev, (MotionEvent)ev.event, 0, 0);
6483 break;
6484 case RawInputEvent.CLASS_TRACKBALL:
6485 dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0);
6486 break;
6487 case RawInputEvent.CLASS_CONFIGURATION_CHANGED:
6488 configChanged = true;
6489 break;
6490 default:
6491 mQueue.recycleEvent(ev);
6492 break;
6493 }
Romain Guy06882f82009-06-10 13:36:04 -07006494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006495 } else if (configChanged) {
6496 configChanged = false;
6497 sendNewConfiguration();
Romain Guy06882f82009-06-10 13:36:04 -07006498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006499 } else if (lastKey != null) {
6500 curTime = SystemClock.uptimeMillis();
Romain Guy06882f82009-06-10 13:36:04 -07006501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006502 // Timeout occurred while key was down. If it is at or
6503 // past the key repeat time, dispatch the repeat.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006504 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006505 TAG, "Key timeout: repeat=" + nextKeyTime
6506 + ", now=" + curTime);
6507 if (curTime < nextKeyTime) {
6508 continue;
6509 }
Romain Guy06882f82009-06-10 13:36:04 -07006510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006511 lastKeyTime = nextKeyTime;
6512 nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY;
6513 keyRepeatCount++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006514 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006515 TAG, "Key repeat: count=" + keyRepeatCount
6516 + ", next @ " + nextKeyTime);
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006517 KeyEvent newEvent;
6518 if (downTime != 0 && (downTime
6519 + ViewConfiguration.getLongPressTimeout())
6520 <= curTime) {
6521 newEvent = KeyEvent.changeTimeRepeat(lastKey,
6522 curTime, keyRepeatCount,
6523 lastKey.getFlags() | KeyEvent.FLAG_LONG_PRESS);
6524 downTime = 0;
6525 } else {
6526 newEvent = KeyEvent.changeTimeRepeat(lastKey,
6527 curTime, keyRepeatCount);
6528 }
6529 dispatchKey(newEvent, 0, 0);
Romain Guy06882f82009-06-10 13:36:04 -07006530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006531 } else {
6532 curTime = SystemClock.uptimeMillis();
Romain Guy06882f82009-06-10 13:36:04 -07006533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006534 lastKeyTime = curTime;
6535 nextKeyTime = curTime + LONG_WAIT;
6536 }
Romain Guy06882f82009-06-10 13:36:04 -07006537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006538 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006539 Slog.e(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006540 "Input thread received uncaught exception: " + e, e);
6541 }
6542 }
6543 }
6544 }
6545
6546 // -------------------------------------------------------------
6547 // Client Session State
6548 // -------------------------------------------------------------
6549
6550 private final class Session extends IWindowSession.Stub
6551 implements IBinder.DeathRecipient {
6552 final IInputMethodClient mClient;
6553 final IInputContext mInputContext;
6554 final int mUid;
6555 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006556 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006557 SurfaceSession mSurfaceSession;
6558 int mNumWindow = 0;
6559 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006561 /**
6562 * Current pointer move event being dispatched to client window... must
6563 * hold key lock to access.
6564 */
6565 QueuedEvent mPendingPointerMove;
6566 WindowState mPendingPointerWindow;
Romain Guy06882f82009-06-10 13:36:04 -07006567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006568 /**
6569 * Current trackball move event being dispatched to client window... must
6570 * hold key lock to access.
6571 */
6572 QueuedEvent mPendingTrackballMove;
6573 WindowState mPendingTrackballWindow;
6574
6575 public Session(IInputMethodClient client, IInputContext inputContext) {
6576 mClient = client;
6577 mInputContext = inputContext;
6578 mUid = Binder.getCallingUid();
6579 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006580 StringBuilder sb = new StringBuilder();
6581 sb.append("Session{");
6582 sb.append(Integer.toHexString(System.identityHashCode(this)));
6583 sb.append(" uid ");
6584 sb.append(mUid);
6585 sb.append("}");
6586 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006588 synchronized (mWindowMap) {
6589 if (mInputMethodManager == null && mHaveInputMethods) {
6590 IBinder b = ServiceManager.getService(
6591 Context.INPUT_METHOD_SERVICE);
6592 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6593 }
6594 }
6595 long ident = Binder.clearCallingIdentity();
6596 try {
6597 // Note: it is safe to call in to the input method manager
6598 // here because we are not holding our lock.
6599 if (mInputMethodManager != null) {
6600 mInputMethodManager.addClient(client, inputContext,
6601 mUid, mPid);
6602 } else {
6603 client.setUsingInputMethod(false);
6604 }
6605 client.asBinder().linkToDeath(this, 0);
6606 } catch (RemoteException e) {
6607 // The caller has died, so we can just forget about this.
6608 try {
6609 if (mInputMethodManager != null) {
6610 mInputMethodManager.removeClient(client);
6611 }
6612 } catch (RemoteException ee) {
6613 }
6614 } finally {
6615 Binder.restoreCallingIdentity(ident);
6616 }
6617 }
Romain Guy06882f82009-06-10 13:36:04 -07006618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006619 @Override
6620 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6621 throws RemoteException {
6622 try {
6623 return super.onTransact(code, data, reply, flags);
6624 } catch (RuntimeException e) {
6625 // Log all 'real' exceptions thrown to the caller
6626 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006627 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006628 }
6629 throw e;
6630 }
6631 }
6632
6633 public void binderDied() {
6634 // Note: it is safe to call in to the input method manager
6635 // here because we are not holding our lock.
6636 try {
6637 if (mInputMethodManager != null) {
6638 mInputMethodManager.removeClient(mClient);
6639 }
6640 } catch (RemoteException e) {
6641 }
6642 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006643 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006644 mClientDead = true;
6645 killSessionLocked();
6646 }
6647 }
6648
6649 public int add(IWindow window, WindowManager.LayoutParams attrs,
6650 int viewVisibility, Rect outContentInsets) {
6651 return addWindow(this, window, attrs, viewVisibility, outContentInsets);
6652 }
Romain Guy06882f82009-06-10 13:36:04 -07006653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006654 public void remove(IWindow window) {
6655 removeWindow(this, window);
6656 }
Romain Guy06882f82009-06-10 13:36:04 -07006657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006658 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6659 int requestedWidth, int requestedHeight, int viewFlags,
6660 boolean insetsPending, Rect outFrame, Rect outContentInsets,
6661 Rect outVisibleInsets, Surface outSurface) {
6662 return relayoutWindow(this, window, attrs,
6663 requestedWidth, requestedHeight, viewFlags, insetsPending,
6664 outFrame, outContentInsets, outVisibleInsets, outSurface);
6665 }
Romain Guy06882f82009-06-10 13:36:04 -07006666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006667 public void setTransparentRegion(IWindow window, Region region) {
6668 setTransparentRegionWindow(this, window, region);
6669 }
Romain Guy06882f82009-06-10 13:36:04 -07006670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006671 public void setInsets(IWindow window, int touchableInsets,
6672 Rect contentInsets, Rect visibleInsets) {
6673 setInsetsWindow(this, window, touchableInsets, contentInsets,
6674 visibleInsets);
6675 }
Romain Guy06882f82009-06-10 13:36:04 -07006676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006677 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6678 getWindowDisplayFrame(this, window, outDisplayFrame);
6679 }
Romain Guy06882f82009-06-10 13:36:04 -07006680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006681 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006682 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006683 TAG, "IWindow finishDrawing called for " + window);
6684 finishDrawingWindow(this, window);
6685 }
6686
6687 public void finishKey(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006688 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006689 TAG, "IWindow finishKey called for " + window);
6690 mKeyWaiter.finishedKey(this, window, false,
6691 KeyWaiter.RETURN_NOTHING);
6692 }
6693
6694 public MotionEvent getPendingPointerMove(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006695 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006696 TAG, "IWindow getPendingMotionEvent called for " + window);
6697 return mKeyWaiter.finishedKey(this, window, false,
6698 KeyWaiter.RETURN_PENDING_POINTER);
6699 }
Romain Guy06882f82009-06-10 13:36:04 -07006700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006701 public MotionEvent getPendingTrackballMove(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006702 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006703 TAG, "IWindow getPendingMotionEvent called for " + window);
6704 return mKeyWaiter.finishedKey(this, window, false,
6705 KeyWaiter.RETURN_PENDING_TRACKBALL);
6706 }
6707
6708 public void setInTouchMode(boolean mode) {
6709 synchronized(mWindowMap) {
6710 mInTouchMode = mode;
6711 }
6712 }
6713
6714 public boolean getInTouchMode() {
6715 synchronized(mWindowMap) {
6716 return mInTouchMode;
6717 }
6718 }
6719
6720 public boolean performHapticFeedback(IWindow window, int effectId,
6721 boolean always) {
6722 synchronized(mWindowMap) {
6723 long ident = Binder.clearCallingIdentity();
6724 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006725 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006726 windowForClientLocked(this, window, true),
6727 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006728 } finally {
6729 Binder.restoreCallingIdentity(ident);
6730 }
6731 }
6732 }
Romain Guy06882f82009-06-10 13:36:04 -07006733
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006734 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006735 synchronized(mWindowMap) {
6736 long ident = Binder.clearCallingIdentity();
6737 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006738 setWindowWallpaperPositionLocked(
6739 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006740 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006741 } finally {
6742 Binder.restoreCallingIdentity(ident);
6743 }
6744 }
6745 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006746
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006747 public void wallpaperOffsetsComplete(IBinder window) {
6748 WindowManagerService.this.wallpaperOffsetsComplete(window);
6749 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006750
Dianne Hackborn75804932009-10-20 20:15:20 -07006751 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6752 int z, Bundle extras, boolean sync) {
6753 synchronized(mWindowMap) {
6754 long ident = Binder.clearCallingIdentity();
6755 try {
6756 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006757 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006758 action, x, y, z, extras, sync);
6759 } finally {
6760 Binder.restoreCallingIdentity(ident);
6761 }
6762 }
6763 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006764
Dianne Hackborn75804932009-10-20 20:15:20 -07006765 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6766 WindowManagerService.this.wallpaperCommandComplete(window, result);
6767 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006769 void windowAddedLocked() {
6770 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006771 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006772 TAG, "First window added to " + this + ", creating SurfaceSession");
6773 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006774 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006775 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006776 mSessions.add(this);
6777 }
6778 mNumWindow++;
6779 }
6780
6781 void windowRemovedLocked() {
6782 mNumWindow--;
6783 killSessionLocked();
6784 }
Romain Guy06882f82009-06-10 13:36:04 -07006785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006786 void killSessionLocked() {
6787 if (mNumWindow <= 0 && mClientDead) {
6788 mSessions.remove(this);
6789 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006790 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006791 TAG, "Last window removed from " + this
6792 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006793 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006794 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006795 try {
6796 mSurfaceSession.kill();
6797 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006798 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006799 + mSurfaceSession + " in session " + this
6800 + ": " + e.toString());
6801 }
6802 mSurfaceSession = null;
6803 }
6804 }
6805 }
Romain Guy06882f82009-06-10 13:36:04 -07006806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006807 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006808 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6809 pw.print(" mClientDead="); pw.print(mClientDead);
6810 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
6811 if (mPendingPointerWindow != null || mPendingPointerMove != null) {
6812 pw.print(prefix);
6813 pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow);
6814 pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove);
6815 }
6816 if (mPendingTrackballWindow != null || mPendingTrackballMove != null) {
6817 pw.print(prefix);
6818 pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow);
6819 pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove);
6820 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006821 }
6822
6823 @Override
6824 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006825 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006826 }
6827 }
6828
6829 // -------------------------------------------------------------
6830 // Client Window State
6831 // -------------------------------------------------------------
6832
6833 private final class WindowState implements WindowManagerPolicy.WindowState {
6834 final Session mSession;
6835 final IWindow mClient;
6836 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006837 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006838 AppWindowToken mAppToken;
6839 AppWindowToken mTargetAppToken;
6840 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6841 final DeathRecipient mDeathRecipient;
6842 final WindowState mAttachedWindow;
6843 final ArrayList mChildWindows = new ArrayList();
6844 final int mBaseLayer;
6845 final int mSubLayer;
6846 final boolean mLayoutAttached;
6847 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006848 final boolean mIsWallpaper;
6849 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006850 int mViewVisibility;
6851 boolean mPolicyVisibility = true;
6852 boolean mPolicyVisibilityAfterAnim = true;
6853 boolean mAppFreezing;
6854 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006855 boolean mReportDestroySurface;
6856 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006857 boolean mAttachedHidden; // is our parent window hidden?
6858 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006859 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006860 int mRequestedWidth;
6861 int mRequestedHeight;
6862 int mLastRequestedWidth;
6863 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006864 int mLayer;
6865 int mAnimLayer;
6866 int mLastLayer;
6867 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006868 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006869 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006870
6871 WindowState mNextOutsideTouch;
Romain Guy06882f82009-06-10 13:36:04 -07006872
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006873 int mLayoutSeq = -1;
6874
6875 Configuration mConfiguration = null;
6876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006877 // Actual frame shown on-screen (may be modified by animation)
6878 final Rect mShownFrame = new Rect();
6879 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006881 /**
6882 * Insets that determine the actually visible area
6883 */
6884 final Rect mVisibleInsets = new Rect();
6885 final Rect mLastVisibleInsets = new Rect();
6886 boolean mVisibleInsetsChanged;
6887
6888 /**
6889 * Insets that are covered by system windows
6890 */
6891 final Rect mContentInsets = new Rect();
6892 final Rect mLastContentInsets = new Rect();
6893 boolean mContentInsetsChanged;
6894
6895 /**
6896 * Set to true if we are waiting for this window to receive its
6897 * given internal insets before laying out other windows based on it.
6898 */
6899 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006901 /**
6902 * These are the content insets that were given during layout for
6903 * this window, to be applied to windows behind it.
6904 */
6905 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006907 /**
6908 * These are the visible insets that were given during layout for
6909 * this window, to be applied to windows behind it.
6910 */
6911 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006913 /**
6914 * Flag indicating whether the touchable region should be adjusted by
6915 * the visible insets; if false the area outside the visible insets is
6916 * NOT touchable, so we must use those to adjust the frame during hit
6917 * tests.
6918 */
6919 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006921 // Current transformation being applied.
6922 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6923 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6924 float mHScale=1, mVScale=1;
6925 float mLastHScale=1, mLastVScale=1;
6926 final Matrix mTmpMatrix = new Matrix();
6927
6928 // "Real" frame that the application sees.
6929 final Rect mFrame = new Rect();
6930 final Rect mLastFrame = new Rect();
6931
6932 final Rect mContainingFrame = new Rect();
6933 final Rect mDisplayFrame = new Rect();
6934 final Rect mContentFrame = new Rect();
6935 final Rect mVisibleFrame = new Rect();
6936
6937 float mShownAlpha = 1;
6938 float mAlpha = 1;
6939 float mLastAlpha = 1;
6940
6941 // Set to true if, when the window gets displayed, it should perform
6942 // an enter animation.
6943 boolean mEnterAnimationPending;
6944
6945 // Currently running animation.
6946 boolean mAnimating;
6947 boolean mLocalAnimating;
6948 Animation mAnimation;
6949 boolean mAnimationIsEntrance;
6950 boolean mHasTransformation;
6951 boolean mHasLocalTransformation;
6952 final Transformation mTransformation = new Transformation();
6953
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006954 // If a window showing a wallpaper: the requested offset for the
6955 // wallpaper; if a wallpaper window: the currently applied offset.
6956 float mWallpaperX = -1;
6957 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006958
6959 // If a window showing a wallpaper: what fraction of the offset
6960 // range corresponds to a full virtual screen.
6961 float mWallpaperXStep = -1;
6962 float mWallpaperYStep = -1;
6963
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006964 // Wallpaper windows: pixels offset based on above variables.
6965 int mXOffset;
6966 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006968 // This is set after IWindowSession.relayout() has been called at
6969 // least once for the window. It allows us to detect the situation
6970 // where we don't yet have a surface, but should have one soon, so
6971 // we can give the window focus before waiting for the relayout.
6972 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006974 // This is set after the Surface has been created but before the
6975 // window has been drawn. During this time the surface is hidden.
6976 boolean mDrawPending;
6977
6978 // This is set after the window has finished drawing for the first
6979 // time but before its surface is shown. The surface will be
6980 // displayed when the next layout is run.
6981 boolean mCommitDrawPending;
6982
6983 // This is set during the time after the window's drawing has been
6984 // committed, and before its surface is actually shown. It is used
6985 // to delay showing the surface until all windows in a token are ready
6986 // to be shown.
6987 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006989 // Set when the window has been shown in the screen the first time.
6990 boolean mHasDrawn;
6991
6992 // Currently running an exit animation?
6993 boolean mExiting;
6994
6995 // Currently on the mDestroySurface list?
6996 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006998 // Completely remove from window manager after exit animation?
6999 boolean mRemoveOnExit;
7000
7001 // Set when the orientation is changing and this window has not yet
7002 // been updated for the new orientation.
7003 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07007004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007005 // Is this window now (or just being) removed?
7006 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07007007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007008 WindowState(Session s, IWindow c, WindowToken token,
7009 WindowState attachedWindow, WindowManager.LayoutParams a,
7010 int viewVisibility) {
7011 mSession = s;
7012 mClient = c;
7013 mToken = token;
7014 mAttrs.copyFrom(a);
7015 mViewVisibility = viewVisibility;
7016 DeathRecipient deathRecipient = new DeathRecipient();
7017 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007018 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007019 TAG, "Window " + this + " client=" + c.asBinder()
7020 + " token=" + token + " (" + mAttrs.token + ")");
7021 try {
7022 c.asBinder().linkToDeath(deathRecipient, 0);
7023 } catch (RemoteException e) {
7024 mDeathRecipient = null;
7025 mAttachedWindow = null;
7026 mLayoutAttached = false;
7027 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007028 mIsWallpaper = false;
7029 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007030 mBaseLayer = 0;
7031 mSubLayer = 0;
7032 return;
7033 }
7034 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07007035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007036 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
7037 mAttrs.type <= LAST_SUB_WINDOW)) {
7038 // The multiplier here is to reserve space for multiple
7039 // windows in the same type layer.
7040 mBaseLayer = mPolicy.windowTypeToLayerLw(
7041 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
7042 + TYPE_LAYER_OFFSET;
7043 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
7044 mAttachedWindow = attachedWindow;
7045 mAttachedWindow.mChildWindows.add(this);
7046 mLayoutAttached = mAttrs.type !=
7047 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
7048 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
7049 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007050 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
7051 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007052 } else {
7053 // The multiplier here is to reserve space for multiple
7054 // windows in the same type layer.
7055 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
7056 * TYPE_LAYER_MULTIPLIER
7057 + TYPE_LAYER_OFFSET;
7058 mSubLayer = 0;
7059 mAttachedWindow = null;
7060 mLayoutAttached = false;
7061 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
7062 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007063 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
7064 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007065 }
7066
7067 WindowState appWin = this;
7068 while (appWin.mAttachedWindow != null) {
7069 appWin = mAttachedWindow;
7070 }
7071 WindowToken appToken = appWin.mToken;
7072 while (appToken.appWindowToken == null) {
7073 WindowToken parent = mTokenMap.get(appToken.token);
7074 if (parent == null || appToken == parent) {
7075 break;
7076 }
7077 appToken = parent;
7078 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007079 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007080 mAppToken = appToken.appWindowToken;
7081
7082 mSurface = null;
7083 mRequestedWidth = 0;
7084 mRequestedHeight = 0;
7085 mLastRequestedWidth = 0;
7086 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007087 mXOffset = 0;
7088 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007089 mLayer = 0;
7090 mAnimLayer = 0;
7091 mLastLayer = 0;
7092 }
7093
7094 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007095 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007096 TAG, "Attaching " + this + " token=" + mToken
7097 + ", list=" + mToken.windows);
7098 mSession.windowAddedLocked();
7099 }
7100
7101 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7102 mHaveFrame = true;
7103
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007104 final Rect container = mContainingFrame;
7105 container.set(pf);
7106
7107 final Rect display = mDisplayFrame;
7108 display.set(df);
7109
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007110 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007111 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007112 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7113 display.intersect(mCompatibleScreenFrame);
7114 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007115 }
7116
7117 final int pw = container.right - container.left;
7118 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007119
7120 int w,h;
7121 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7122 w = mAttrs.width < 0 ? pw : mAttrs.width;
7123 h = mAttrs.height< 0 ? ph : mAttrs.height;
7124 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007125 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7126 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007127 }
Romain Guy06882f82009-06-10 13:36:04 -07007128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007129 final Rect content = mContentFrame;
7130 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007132 final Rect visible = mVisibleFrame;
7133 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007135 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007136 final int fw = frame.width();
7137 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007139 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7140 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7141
7142 Gravity.apply(mAttrs.gravity, w, h, container,
7143 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7144 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7145
7146 //System.out.println("Out: " + mFrame);
7147
7148 // Now make sure the window fits in the overall display.
7149 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007151 // Make sure the content and visible frames are inside of the
7152 // final window frame.
7153 if (content.left < frame.left) content.left = frame.left;
7154 if (content.top < frame.top) content.top = frame.top;
7155 if (content.right > frame.right) content.right = frame.right;
7156 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7157 if (visible.left < frame.left) visible.left = frame.left;
7158 if (visible.top < frame.top) visible.top = frame.top;
7159 if (visible.right > frame.right) visible.right = frame.right;
7160 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007162 final Rect contentInsets = mContentInsets;
7163 contentInsets.left = content.left-frame.left;
7164 contentInsets.top = content.top-frame.top;
7165 contentInsets.right = frame.right-content.right;
7166 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007168 final Rect visibleInsets = mVisibleInsets;
7169 visibleInsets.left = visible.left-frame.left;
7170 visibleInsets.top = visible.top-frame.top;
7171 visibleInsets.right = frame.right-visible.right;
7172 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007173
Dianne Hackborn284ac932009-08-28 10:34:25 -07007174 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7175 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007176 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007177 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007179 if (localLOGV) {
7180 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7181 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007182 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007183 + mRequestedWidth + ", mRequestedheight="
7184 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7185 + "): frame=" + mFrame.toShortString()
7186 + " ci=" + contentInsets.toShortString()
7187 + " vi=" + visibleInsets.toShortString());
7188 //}
7189 }
7190 }
Romain Guy06882f82009-06-10 13:36:04 -07007191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007192 public Rect getFrameLw() {
7193 return mFrame;
7194 }
7195
7196 public Rect getShownFrameLw() {
7197 return mShownFrame;
7198 }
7199
7200 public Rect getDisplayFrameLw() {
7201 return mDisplayFrame;
7202 }
7203
7204 public Rect getContentFrameLw() {
7205 return mContentFrame;
7206 }
7207
7208 public Rect getVisibleFrameLw() {
7209 return mVisibleFrame;
7210 }
7211
7212 public boolean getGivenInsetsPendingLw() {
7213 return mGivenInsetsPending;
7214 }
7215
7216 public Rect getGivenContentInsetsLw() {
7217 return mGivenContentInsets;
7218 }
Romain Guy06882f82009-06-10 13:36:04 -07007219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007220 public Rect getGivenVisibleInsetsLw() {
7221 return mGivenVisibleInsets;
7222 }
Romain Guy06882f82009-06-10 13:36:04 -07007223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007224 public WindowManager.LayoutParams getAttrs() {
7225 return mAttrs;
7226 }
7227
7228 public int getSurfaceLayer() {
7229 return mLayer;
7230 }
Romain Guy06882f82009-06-10 13:36:04 -07007231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007232 public IApplicationToken getAppToken() {
7233 return mAppToken != null ? mAppToken.appToken : null;
7234 }
7235
7236 public boolean hasAppShownWindows() {
7237 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7238 }
7239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007240 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007241 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007242 TAG, "Setting animation in " + this + ": " + anim);
7243 mAnimating = false;
7244 mLocalAnimating = false;
7245 mAnimation = anim;
7246 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7247 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7248 }
7249
7250 public void clearAnimation() {
7251 if (mAnimation != null) {
7252 mAnimating = true;
7253 mLocalAnimating = false;
7254 mAnimation = null;
7255 }
7256 }
Romain Guy06882f82009-06-10 13:36:04 -07007257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007258 Surface createSurfaceLocked() {
7259 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007260 mReportDestroySurface = false;
7261 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007262 mDrawPending = true;
7263 mCommitDrawPending = false;
7264 mReadyToShow = false;
7265 if (mAppToken != null) {
7266 mAppToken.allDrawn = false;
7267 }
7268
7269 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07007270 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007271 flags |= Surface.PUSH_BUFFERS;
7272 }
7273
7274 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7275 flags |= Surface.SECURE;
7276 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007277 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007278 TAG, "Creating surface in session "
7279 + mSession.mSurfaceSession + " window " + this
7280 + " w=" + mFrame.width()
7281 + " h=" + mFrame.height() + " format="
7282 + mAttrs.format + " flags=" + flags);
7283
7284 int w = mFrame.width();
7285 int h = mFrame.height();
7286 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7287 // for a scaled surface, we always want the requested
7288 // size.
7289 w = mRequestedWidth;
7290 h = mRequestedHeight;
7291 }
7292
Romain Guy9825ec62009-10-01 00:58:09 -07007293 // Something is wrong and SurfaceFlinger will not like this,
7294 // try to revert to sane values
7295 if (w <= 0) w = 1;
7296 if (h <= 0) h = 1;
7297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007298 try {
7299 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007300 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007301 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007302 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007303 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007304 + mSurface + " IN SESSION "
7305 + mSession.mSurfaceSession
7306 + ": pid=" + mSession.mPid + " format="
7307 + mAttrs.format + " flags=0x"
7308 + Integer.toHexString(flags));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007309 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007310 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007311 reclaimSomeSurfaceMemoryLocked(this, "create");
7312 return null;
7313 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007314 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007315 return null;
7316 }
Romain Guy06882f82009-06-10 13:36:04 -07007317
Joe Onorato8a9b2202010-02-26 18:56:32 -08007318 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007319 TAG, "Got surface: " + mSurface
7320 + ", set left=" + mFrame.left + " top=" + mFrame.top
7321 + ", animLayer=" + mAnimLayer);
7322 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007323 Slog.i(TAG, ">>> OPEN TRANSACTION");
7324 Slog.i(TAG, " SURFACE " + mSurface + ": CREATE ("
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007325 + mAttrs.getTitle() + ") pos=(" +
7326 mFrame.left + "," + mFrame.top + ") (" +
7327 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7328 mAnimLayer + " HIDE");
7329 }
7330 Surface.openTransaction();
7331 try {
7332 try {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007333 mSurface.setPosition(mFrame.left + mXOffset,
7334 mFrame.top + mYOffset);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007335 mSurface.setLayer(mAnimLayer);
7336 mSurface.hide();
7337 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007338 if (SHOW_TRANSACTIONS) Slog.i(TAG, " SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007339 + mSurface + ": DITHER");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007340 mSurface.setFlags(Surface.SURFACE_DITHER,
7341 Surface.SURFACE_DITHER);
7342 }
7343 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007344 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007345 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7346 }
7347 mLastHidden = true;
7348 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007349 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007350 Surface.closeTransaction();
7351 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007352 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007353 TAG, "Created surface " + this);
7354 }
7355 return mSurface;
7356 }
Romain Guy06882f82009-06-10 13:36:04 -07007357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007358 void destroySurfaceLocked() {
7359 // Window is no longer on-screen, so can no longer receive
7360 // key events... if we were waiting for it to finish
7361 // handling a key event, the wait is over!
7362 mKeyWaiter.finishedKey(mSession, mClient, true,
7363 KeyWaiter.RETURN_NOTHING);
7364 mKeyWaiter.releasePendingPointerLocked(mSession);
7365 mKeyWaiter.releasePendingTrackballLocked(mSession);
7366
7367 if (mAppToken != null && this == mAppToken.startingWindow) {
7368 mAppToken.startingDisplayed = false;
7369 }
Romain Guy06882f82009-06-10 13:36:04 -07007370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007371 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007372 mDrawPending = false;
7373 mCommitDrawPending = false;
7374 mReadyToShow = false;
7375
7376 int i = mChildWindows.size();
7377 while (i > 0) {
7378 i--;
7379 WindowState c = (WindowState)mChildWindows.get(i);
7380 c.mAttachedHidden = true;
7381 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007382
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007383 if (mReportDestroySurface) {
7384 mReportDestroySurface = false;
7385 mSurfacePendingDestroy = true;
7386 try {
7387 mClient.dispatchGetNewSurface();
7388 // We'll really destroy on the next time around.
7389 return;
7390 } catch (RemoteException e) {
7391 }
7392 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007394 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007395 if (DEBUG_VISIBILITY) {
7396 RuntimeException e = new RuntimeException();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07007397 if (!HIDE_STACK_CRAWLS) e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08007398 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007399 + mSurface + ", session " + mSession, e);
7400 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007401 if (SHOW_TRANSACTIONS) {
7402 RuntimeException ex = new RuntimeException();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07007403 if (!HIDE_STACK_CRAWLS) ex.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08007404 Slog.i(TAG, " SURFACE " + mSurface + ": DESTROY ("
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007405 + mAttrs.getTitle() + ")", ex);
7406 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007407 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007408 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007409 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007410 + " surface " + mSurface + " session " + mSession
7411 + ": " + e.toString());
7412 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007414 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007415 }
7416 }
7417
7418 boolean finishDrawingLocked() {
7419 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007420 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007421 TAG, "finishDrawingLocked: " + mSurface);
7422 mCommitDrawPending = true;
7423 mDrawPending = false;
7424 return true;
7425 }
7426 return false;
7427 }
7428
7429 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007430 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007431 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007432 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007433 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007434 }
7435 mCommitDrawPending = false;
7436 mReadyToShow = true;
7437 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7438 final AppWindowToken atoken = mAppToken;
7439 if (atoken == null || atoken.allDrawn || starting) {
7440 performShowLocked();
7441 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007442 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007443 }
7444
7445 // This must be called while inside a transaction.
7446 boolean performShowLocked() {
7447 if (DEBUG_VISIBILITY) {
7448 RuntimeException e = new RuntimeException();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07007449 if (!HIDE_STACK_CRAWLS) e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08007450 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007451 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7452 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7453 }
7454 if (mReadyToShow && isReadyForDisplay()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007455 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.i(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007456 TAG, " SURFACE " + mSurface + ": SHOW (performShowLocked)");
Joe Onorato8a9b2202010-02-26 18:56:32 -08007457 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007458 + " during animation: policyVis=" + mPolicyVisibility
7459 + " attHidden=" + mAttachedHidden
7460 + " tok.hiddenRequested="
7461 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007462 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007463 + (mAppToken != null ? mAppToken.hidden : false)
7464 + " animating=" + mAnimating
7465 + " tok animating="
7466 + (mAppToken != null ? mAppToken.animating : false));
7467 if (!showSurfaceRobustlyLocked(this)) {
7468 return false;
7469 }
7470 mLastAlpha = -1;
7471 mHasDrawn = true;
7472 mLastHidden = false;
7473 mReadyToShow = false;
7474 enableScreenIfNeededLocked();
7475
7476 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007478 int i = mChildWindows.size();
7479 while (i > 0) {
7480 i--;
7481 WindowState c = (WindowState)mChildWindows.get(i);
7482 if (c.mSurface != null && c.mAttachedHidden) {
7483 c.mAttachedHidden = false;
7484 c.performShowLocked();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007485 // It hadn't been shown, which means layout not
7486 // performed on it, so now we want to make sure to
7487 // do a layout. If called from within the transaction
7488 // loop, this will cause it to restart with a new
7489 // layout.
7490 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007491 }
7492 }
Romain Guy06882f82009-06-10 13:36:04 -07007493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007494 if (mAttrs.type != TYPE_APPLICATION_STARTING
7495 && mAppToken != null) {
7496 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007497
Dianne Hackborn248b1882009-09-16 16:46:44 -07007498 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007499 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007500 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007501 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007502 // If this initial window is animating, stop it -- we
7503 // will do an animation to reveal it from behind the
7504 // starting window, so there is no need for it to also
7505 // be doing its own stuff.
7506 if (mAnimation != null) {
7507 mAnimation = null;
7508 // Make sure we clean up the animation.
7509 mAnimating = true;
7510 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007511 mFinishedStarting.add(mAppToken);
7512 mH.sendEmptyMessage(H.FINISHED_STARTING);
7513 }
7514 mAppToken.updateReportedVisibilityLocked();
7515 }
7516 }
7517 return true;
7518 }
Romain Guy06882f82009-06-10 13:36:04 -07007519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007520 // This must be called while inside a transaction. Returns true if
7521 // there is more animation to run.
7522 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007523 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007524 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007526 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7527 mHasTransformation = true;
7528 mHasLocalTransformation = true;
7529 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007530 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007531 TAG, "Starting animation in " + this +
7532 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7533 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7534 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7535 mAnimation.setStartTime(currentTime);
7536 mLocalAnimating = true;
7537 mAnimating = true;
7538 }
7539 mTransformation.clear();
7540 final boolean more = mAnimation.getTransformation(
7541 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007542 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007543 TAG, "Stepped animation in " + this +
7544 ": more=" + more + ", xform=" + mTransformation);
7545 if (more) {
7546 // we're not done!
7547 return true;
7548 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007549 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007550 TAG, "Finished animation in " + this +
7551 " @ " + currentTime);
7552 mAnimation = null;
7553 //WindowManagerService.this.dump();
7554 }
7555 mHasLocalTransformation = false;
7556 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007557 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007558 // When our app token is animating, we kind-of pretend like
7559 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7560 // part of this check means that we will only do this if
7561 // our window is not currently exiting, or it is not
7562 // locally animating itself. The idea being that one that
7563 // is exiting and doing a local animation should be removed
7564 // once that animation is done.
7565 mAnimating = true;
7566 mHasTransformation = true;
7567 mTransformation.clear();
7568 return false;
7569 } else if (mHasTransformation) {
7570 // Little trick to get through the path below to act like
7571 // we have finished an animation.
7572 mAnimating = true;
7573 } else if (isAnimating()) {
7574 mAnimating = true;
7575 }
7576 } else if (mAnimation != null) {
7577 // If the display is frozen, and there is a pending animation,
7578 // clear it and make sure we run the cleanup code.
7579 mAnimating = true;
7580 mLocalAnimating = true;
7581 mAnimation = null;
7582 }
Romain Guy06882f82009-06-10 13:36:04 -07007583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007584 if (!mAnimating && !mLocalAnimating) {
7585 return false;
7586 }
7587
Joe Onorato8a9b2202010-02-26 18:56:32 -08007588 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007589 TAG, "Animation done in " + this + ": exiting=" + mExiting
7590 + ", reportedVisible="
7591 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007593 mAnimating = false;
7594 mLocalAnimating = false;
7595 mAnimation = null;
7596 mAnimLayer = mLayer;
7597 if (mIsImWindow) {
7598 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007599 } else if (mIsWallpaper) {
7600 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007601 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007602 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007603 + " anim layer: " + mAnimLayer);
7604 mHasTransformation = false;
7605 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007606 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7607 if (DEBUG_VISIBILITY) {
7608 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7609 + mPolicyVisibilityAfterAnim);
7610 }
7611 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7612 if (!mPolicyVisibility) {
7613 if (mCurrentFocus == this) {
7614 mFocusMayChange = true;
7615 }
7616 // Window is no longer visible -- make sure if we were waiting
7617 // for it to be displayed before enabling the display, that
7618 // we allow the display to be enabled now.
7619 enableScreenIfNeededLocked();
7620 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007621 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007622 mTransformation.clear();
7623 if (mHasDrawn
7624 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7625 && mAppToken != null
7626 && mAppToken.firstWindowDrawn
7627 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007628 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007629 + mToken + ": first real window done animating");
7630 mFinishedStarting.add(mAppToken);
7631 mH.sendEmptyMessage(H.FINISHED_STARTING);
7632 }
Romain Guy06882f82009-06-10 13:36:04 -07007633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007634 finishExit();
7635
7636 if (mAppToken != null) {
7637 mAppToken.updateReportedVisibilityLocked();
7638 }
7639
7640 return false;
7641 }
7642
7643 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007644 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007645 TAG, "finishExit in " + this
7646 + ": exiting=" + mExiting
7647 + " remove=" + mRemoveOnExit
7648 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007650 final int N = mChildWindows.size();
7651 for (int i=0; i<N; i++) {
7652 ((WindowState)mChildWindows.get(i)).finishExit();
7653 }
Romain Guy06882f82009-06-10 13:36:04 -07007654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007655 if (!mExiting) {
7656 return;
7657 }
Romain Guy06882f82009-06-10 13:36:04 -07007658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007659 if (isWindowAnimating()) {
7660 return;
7661 }
7662
Joe Onorato8a9b2202010-02-26 18:56:32 -08007663 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007664 TAG, "Exit animation finished in " + this
7665 + ": remove=" + mRemoveOnExit);
7666 if (mSurface != null) {
7667 mDestroySurface.add(this);
7668 mDestroying = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007669 if (SHOW_TRANSACTIONS) Slog.i(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007670 TAG, " SURFACE " + mSurface + ": HIDE (finishExit)");
7671 try {
7672 mSurface.hide();
7673 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007674 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007675 }
7676 mLastHidden = true;
7677 mKeyWaiter.releasePendingPointerLocked(mSession);
7678 }
7679 mExiting = false;
7680 if (mRemoveOnExit) {
7681 mPendingRemove.add(this);
7682 mRemoveOnExit = false;
7683 }
7684 }
Romain Guy06882f82009-06-10 13:36:04 -07007685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007686 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7687 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7688 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7689 if (dtdx < -.000001f || dtdx > .000001f) return false;
7690 if (dsdy < -.000001f || dsdy > .000001f) return false;
7691 return true;
7692 }
Romain Guy06882f82009-06-10 13:36:04 -07007693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007694 void computeShownFrameLocked() {
7695 final boolean selfTransformation = mHasLocalTransformation;
7696 Transformation attachedTransformation =
7697 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7698 ? mAttachedWindow.mTransformation : null;
7699 Transformation appTransformation =
7700 (mAppToken != null && mAppToken.hasTransformation)
7701 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007702
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007703 // Wallpapers are animated based on the "real" window they
7704 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007705 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007706 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007707 if (mWallpaperTarget.mHasLocalTransformation &&
7708 mWallpaperTarget.mAnimation != null &&
7709 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007710 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007711 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007712 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007713 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007714 }
7715 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007716 mWallpaperTarget.mAppToken.hasTransformation &&
7717 mWallpaperTarget.mAppToken.animation != null &&
7718 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007719 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007720 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007721 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007722 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007723 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007724 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007726 if (selfTransformation || attachedTransformation != null
7727 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007728 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007729 final Rect frame = mFrame;
7730 final float tmpFloats[] = mTmpFloats;
7731 final Matrix tmpMatrix = mTmpMatrix;
7732
7733 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007734 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007735 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007736 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007737 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007738 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007739 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007740 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007741 }
7742 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007743 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007744 }
7745
7746 // "convert" it into SurfaceFlinger's format
7747 // (a 2x2 matrix + an offset)
7748 // Here we must not transform the position of the surface
7749 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007750 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007752 tmpMatrix.getValues(tmpFloats);
7753 mDsDx = tmpFloats[Matrix.MSCALE_X];
7754 mDtDx = tmpFloats[Matrix.MSKEW_X];
7755 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7756 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007757 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7758 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007759 int w = frame.width();
7760 int h = frame.height();
7761 mShownFrame.set(x, y, x+w, y+h);
7762
7763 // Now set the alpha... but because our current hardware
7764 // can't do alpha transformation on a non-opaque surface,
7765 // turn it off if we are running an animation that is also
7766 // transforming since it is more important to have that
7767 // animation be smooth.
7768 mShownAlpha = mAlpha;
7769 if (!mLimitedAlphaCompositing
7770 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7771 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7772 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007773 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007774 if (selfTransformation) {
7775 mShownAlpha *= mTransformation.getAlpha();
7776 }
7777 if (attachedTransformation != null) {
7778 mShownAlpha *= attachedTransformation.getAlpha();
7779 }
7780 if (appTransformation != null) {
7781 mShownAlpha *= appTransformation.getAlpha();
7782 }
7783 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007784 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007785 }
Romain Guy06882f82009-06-10 13:36:04 -07007786
Joe Onorato8a9b2202010-02-26 18:56:32 -08007787 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007788 TAG, "Continuing animation in " + this +
7789 ": " + mShownFrame +
7790 ", alpha=" + mTransformation.getAlpha());
7791 return;
7792 }
Romain Guy06882f82009-06-10 13:36:04 -07007793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007794 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007795 if (mXOffset != 0 || mYOffset != 0) {
7796 mShownFrame.offset(mXOffset, mYOffset);
7797 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007798 mShownAlpha = mAlpha;
7799 mDsDx = 1;
7800 mDtDx = 0;
7801 mDsDy = 0;
7802 mDtDy = 1;
7803 }
Romain Guy06882f82009-06-10 13:36:04 -07007804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007805 /**
7806 * Is this window visible? It is not visible if there is no
7807 * surface, or we are in the process of running an exit animation
7808 * that will remove the surface, or its app token has been hidden.
7809 */
7810 public boolean isVisibleLw() {
7811 final AppWindowToken atoken = mAppToken;
7812 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7813 && (atoken == null || !atoken.hiddenRequested)
7814 && !mExiting && !mDestroying;
7815 }
7816
7817 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007818 * Like {@link #isVisibleLw}, but also counts a window that is currently
7819 * "hidden" behind the keyguard as visible. This allows us to apply
7820 * things like window flags that impact the keyguard.
7821 * XXX I am starting to think we need to have ANOTHER visibility flag
7822 * for this "hidden behind keyguard" state rather than overloading
7823 * mPolicyVisibility. Ungh.
7824 */
7825 public boolean isVisibleOrBehindKeyguardLw() {
7826 final AppWindowToken atoken = mAppToken;
7827 return mSurface != null && !mAttachedHidden
7828 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
7829 && !mExiting && !mDestroying;
7830 }
7831
7832 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007833 * Is this window visible, ignoring its app token? It is not visible
7834 * if there is no surface, or we are in the process of running an exit animation
7835 * that will remove the surface.
7836 */
7837 public boolean isWinVisibleLw() {
7838 final AppWindowToken atoken = mAppToken;
7839 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7840 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7841 && !mExiting && !mDestroying;
7842 }
7843
7844 /**
7845 * The same as isVisible(), but follows the current hidden state of
7846 * the associated app token, not the pending requested hidden state.
7847 */
7848 boolean isVisibleNow() {
7849 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007850 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007851 }
7852
7853 /**
7854 * Same as isVisible(), but we also count it as visible between the
7855 * call to IWindowSession.add() and the first relayout().
7856 */
7857 boolean isVisibleOrAdding() {
7858 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007859 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007860 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7861 && mPolicyVisibility && !mAttachedHidden
7862 && (atoken == null || !atoken.hiddenRequested)
7863 && !mExiting && !mDestroying;
7864 }
7865
7866 /**
7867 * Is this window currently on-screen? It is on-screen either if it
7868 * is visible or it is currently running an animation before no longer
7869 * being visible.
7870 */
7871 boolean isOnScreen() {
7872 final AppWindowToken atoken = mAppToken;
7873 if (atoken != null) {
7874 return mSurface != null && mPolicyVisibility && !mDestroying
7875 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007876 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007877 } else {
7878 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007879 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007880 }
7881 }
Romain Guy06882f82009-06-10 13:36:04 -07007882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007883 /**
7884 * Like isOnScreen(), but we don't return true if the window is part
7885 * of a transition that has not yet been started.
7886 */
7887 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007888 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007889 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007890 return false;
7891 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007892 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007893 final boolean animating = atoken != null
7894 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007895 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007896 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7897 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007898 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007899 }
7900
7901 /** Is the window or its container currently animating? */
7902 boolean isAnimating() {
7903 final WindowState attached = mAttachedWindow;
7904 final AppWindowToken atoken = mAppToken;
7905 return mAnimation != null
7906 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007907 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007908 (atoken.animation != null
7909 || atoken.inPendingTransaction));
7910 }
7911
7912 /** Is this window currently animating? */
7913 boolean isWindowAnimating() {
7914 return mAnimation != null;
7915 }
7916
7917 /**
7918 * Like isOnScreen, but returns false if the surface hasn't yet
7919 * been drawn.
7920 */
7921 public boolean isDisplayedLw() {
7922 final AppWindowToken atoken = mAppToken;
7923 return mSurface != null && mPolicyVisibility && !mDestroying
7924 && !mDrawPending && !mCommitDrawPending
7925 && ((!mAttachedHidden &&
7926 (atoken == null || !atoken.hiddenRequested))
7927 || mAnimating);
7928 }
7929
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007930 /**
7931 * Returns true if the window has a surface that it has drawn a
7932 * complete UI in to.
7933 */
7934 public boolean isDrawnLw() {
7935 final AppWindowToken atoken = mAppToken;
7936 return mSurface != null && !mDestroying
7937 && !mDrawPending && !mCommitDrawPending;
7938 }
7939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007940 public boolean fillsScreenLw(int screenWidth, int screenHeight,
7941 boolean shownFrame, boolean onlyOpaque) {
7942 if (mSurface == null) {
7943 return false;
7944 }
7945 if (mAppToken != null && !mAppToken.appFullscreen) {
7946 return false;
7947 }
7948 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
7949 return false;
7950 }
7951 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007952
7953 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
7954 return frame.left <= mCompatibleScreenFrame.left &&
7955 frame.top <= mCompatibleScreenFrame.top &&
7956 frame.right >= mCompatibleScreenFrame.right &&
7957 frame.bottom >= mCompatibleScreenFrame.bottom;
7958 } else {
7959 return frame.left <= 0 && frame.top <= 0
7960 && frame.right >= screenWidth
7961 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007962 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007963 }
Romain Guy06882f82009-06-10 13:36:04 -07007964
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007965 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007966 * Return true if the window is opaque and fully drawn. This indicates
7967 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007968 */
7969 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007970 return (mAttrs.format == PixelFormat.OPAQUE
7971 || mAttrs.type == TYPE_WALLPAPER)
7972 && mSurface != null && mAnimation == null
7973 && (mAppToken == null || mAppToken.animation == null)
7974 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007975 }
7976
7977 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7978 return
7979 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007980 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7981 // only if it's visible
7982 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007983 // and only if the application fills the compatible screen
7984 mFrame.left <= mCompatibleScreenFrame.left &&
7985 mFrame.top <= mCompatibleScreenFrame.top &&
7986 mFrame.right >= mCompatibleScreenFrame.right &&
7987 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007988 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007989 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007990 }
7991
7992 boolean isFullscreen(int screenWidth, int screenHeight) {
7993 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007994 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007995 }
7996
7997 void removeLocked() {
7998 if (mAttachedWindow != null) {
7999 mAttachedWindow.mChildWindows.remove(this);
8000 }
8001 destroySurfaceLocked();
8002 mSession.windowRemovedLocked();
8003 try {
8004 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
8005 } catch (RuntimeException e) {
8006 // Ignore if it has already been removed (usually because
8007 // we are doing this as part of processing a death note.)
8008 }
8009 }
8010
8011 private class DeathRecipient implements IBinder.DeathRecipient {
8012 public void binderDied() {
8013 try {
8014 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008015 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008016 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008017 if (win != null) {
8018 removeWindowLocked(mSession, win);
8019 }
8020 }
8021 } catch (IllegalArgumentException ex) {
8022 // This will happen if the window has already been
8023 // removed.
8024 }
8025 }
8026 }
8027
8028 /** Returns true if this window desires key events. */
8029 public final boolean canReceiveKeys() {
8030 return isVisibleOrAdding()
8031 && (mViewVisibility == View.VISIBLE)
8032 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8033 }
8034
8035 public boolean hasDrawnLw() {
8036 return mHasDrawn;
8037 }
8038
8039 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008040 return showLw(doAnimation, true);
8041 }
8042
8043 boolean showLw(boolean doAnimation, boolean requestAnim) {
8044 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8045 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008046 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008047 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008048 mPolicyVisibility = true;
8049 mPolicyVisibilityAfterAnim = true;
8050 if (doAnimation) {
8051 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8052 }
8053 if (requestAnim) {
8054 requestAnimationLocked(0);
8055 }
8056 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008057 }
8058
8059 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008060 return hideLw(doAnimation, true);
8061 }
8062
8063 boolean hideLw(boolean doAnimation, boolean requestAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008064 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8065 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008066 if (!current) {
8067 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008068 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008069 if (doAnimation) {
8070 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8071 if (mAnimation == null) {
8072 doAnimation = false;
8073 }
8074 }
8075 if (doAnimation) {
8076 mPolicyVisibilityAfterAnim = false;
8077 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008078 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008079 mPolicyVisibilityAfterAnim = false;
8080 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008081 // Window is no longer visible -- make sure if we were waiting
8082 // for it to be displayed before enabling the display, that
8083 // we allow the display to be enabled now.
8084 enableScreenIfNeededLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008085 }
8086 if (requestAnim) {
8087 requestAnimationLocked(0);
8088 }
8089 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008090 }
8091
8092 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008093 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8094 pw.print(" mClient="); pw.println(mClient.asBinder());
8095 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8096 if (mAttachedWindow != null || mLayoutAttached) {
8097 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8098 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8099 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008100 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8101 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8102 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008103 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8104 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008105 }
8106 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8107 pw.print(" mSubLayer="); pw.print(mSubLayer);
8108 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8109 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8110 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8111 pw.print("="); pw.print(mAnimLayer);
8112 pw.print(" mLastLayer="); pw.println(mLastLayer);
8113 if (mSurface != null) {
8114 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
8115 }
8116 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8117 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8118 if (mAppToken != null) {
8119 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8120 }
8121 if (mTargetAppToken != null) {
8122 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8123 }
8124 pw.print(prefix); pw.print("mViewVisibility=0x");
8125 pw.print(Integer.toHexString(mViewVisibility));
8126 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008127 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8128 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008129 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8130 pw.print(prefix); pw.print("mPolicyVisibility=");
8131 pw.print(mPolicyVisibility);
8132 pw.print(" mPolicyVisibilityAfterAnim=");
8133 pw.print(mPolicyVisibilityAfterAnim);
8134 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8135 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008136 if (!mRelayoutCalled) {
8137 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8138 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008139 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008140 pw.print(" h="); pw.print(mRequestedHeight);
8141 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008142 if (mXOffset != 0 || mYOffset != 0) {
8143 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8144 pw.print(" y="); pw.println(mYOffset);
8145 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008146 pw.print(prefix); pw.print("mGivenContentInsets=");
8147 mGivenContentInsets.printShortString(pw);
8148 pw.print(" mGivenVisibleInsets=");
8149 mGivenVisibleInsets.printShortString(pw);
8150 pw.println();
8151 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8152 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8153 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8154 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008155 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008156 pw.print(prefix); pw.print("mShownFrame=");
8157 mShownFrame.printShortString(pw);
8158 pw.print(" last="); mLastShownFrame.printShortString(pw);
8159 pw.println();
8160 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8161 pw.print(" last="); mLastFrame.printShortString(pw);
8162 pw.println();
8163 pw.print(prefix); pw.print("mContainingFrame=");
8164 mContainingFrame.printShortString(pw);
8165 pw.print(" mDisplayFrame=");
8166 mDisplayFrame.printShortString(pw);
8167 pw.println();
8168 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8169 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8170 pw.println();
8171 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8172 pw.print(" last="); mLastContentInsets.printShortString(pw);
8173 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8174 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8175 pw.println();
8176 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8177 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8178 pw.print(" mAlpha="); pw.print(mAlpha);
8179 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8180 }
8181 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8182 || mAnimation != null) {
8183 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8184 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8185 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8186 pw.print(" mAnimation="); pw.println(mAnimation);
8187 }
8188 if (mHasTransformation || mHasLocalTransformation) {
8189 pw.print(prefix); pw.print("XForm: has=");
8190 pw.print(mHasTransformation);
8191 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8192 pw.print(" "); mTransformation.printShortString(pw);
8193 pw.println();
8194 }
8195 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8196 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8197 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8198 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8199 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8200 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8201 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8202 pw.print(" mDestroying="); pw.print(mDestroying);
8203 pw.print(" mRemoved="); pw.println(mRemoved);
8204 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008205 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008206 pw.print(prefix); pw.print("mOrientationChanging=");
8207 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008208 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8209 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008210 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008211 if (mHScale != 1 || mVScale != 1) {
8212 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8213 pw.print(" mVScale="); pw.println(mVScale);
8214 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008215 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008216 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8217 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8218 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008219 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8220 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8221 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8222 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008223 }
8224
8225 @Override
8226 public String toString() {
8227 return "Window{"
8228 + Integer.toHexString(System.identityHashCode(this))
8229 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
8230 }
8231 }
Romain Guy06882f82009-06-10 13:36:04 -07008232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008233 // -------------------------------------------------------------
8234 // Window Token State
8235 // -------------------------------------------------------------
8236
8237 class WindowToken {
8238 // The actual token.
8239 final IBinder token;
8240
8241 // The type of window this token is for, as per WindowManager.LayoutParams.
8242 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008244 // Set if this token was explicitly added by a client, so should
8245 // not be removed when all windows are removed.
8246 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008247
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008248 // For printing.
8249 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008251 // If this is an AppWindowToken, this is non-null.
8252 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008254 // All of the windows associated with this token.
8255 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8256
8257 // Is key dispatching paused for this token?
8258 boolean paused = false;
8259
8260 // Should this token's windows be hidden?
8261 boolean hidden;
8262
8263 // Temporary for finding which tokens no longer have visible windows.
8264 boolean hasVisible;
8265
Dianne Hackborna8f60182009-09-01 19:01:50 -07008266 // Set to true when this token is in a pending transaction where it
8267 // will be shown.
8268 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008269
Dianne Hackborna8f60182009-09-01 19:01:50 -07008270 // Set to true when this token is in a pending transaction where it
8271 // will be hidden.
8272 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008273
Dianne Hackborna8f60182009-09-01 19:01:50 -07008274 // Set to true when this token is in a pending transaction where its
8275 // windows will be put to the bottom of the list.
8276 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008277
Dianne Hackborna8f60182009-09-01 19:01:50 -07008278 // Set to true when this token is in a pending transaction where its
8279 // windows will be put to the top of the list.
8280 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008282 WindowToken(IBinder _token, int type, boolean _explicit) {
8283 token = _token;
8284 windowType = type;
8285 explicit = _explicit;
8286 }
8287
8288 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008289 pw.print(prefix); pw.print("token="); pw.println(token);
8290 pw.print(prefix); pw.print("windows="); pw.println(windows);
8291 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8292 pw.print(" hidden="); pw.print(hidden);
8293 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008294 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8295 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8296 pw.print(" waitingToHide="); pw.print(waitingToHide);
8297 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8298 pw.print(" sendingToTop="); pw.println(sendingToTop);
8299 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008300 }
8301
8302 @Override
8303 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008304 if (stringName == null) {
8305 StringBuilder sb = new StringBuilder();
8306 sb.append("WindowToken{");
8307 sb.append(Integer.toHexString(System.identityHashCode(this)));
8308 sb.append(" token="); sb.append(token); sb.append('}');
8309 stringName = sb.toString();
8310 }
8311 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008312 }
8313 };
8314
8315 class AppWindowToken extends WindowToken {
8316 // Non-null only for application tokens.
8317 final IApplicationToken appToken;
8318
8319 // All of the windows and child windows that are included in this
8320 // application token. Note this list is NOT sorted!
8321 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8322
8323 int groupId = -1;
8324 boolean appFullscreen;
8325 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Romain Guy06882f82009-06-10 13:36:04 -07008326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008327 // These are used for determining when all windows associated with
8328 // an activity have been drawn, so they can be made visible together
8329 // at the same time.
8330 int lastTransactionSequence = mTransactionSequence-1;
8331 int numInterestingWindows;
8332 int numDrawnWindows;
8333 boolean inPendingTransaction;
8334 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008336 // Is this token going to be hidden in a little while? If so, it
8337 // won't be taken into account for setting the screen orientation.
8338 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008340 // Is this window's surface needed? This is almost like hidden, except
8341 // it will sometimes be true a little earlier: when the token has
8342 // been shown, but is still waiting for its app transition to execute
8343 // before making its windows shown.
8344 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008346 // Have we told the window clients to hide themselves?
8347 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008349 // Last visibility state we reported to the app token.
8350 boolean reportedVisible;
8351
8352 // Set to true when the token has been removed from the window mgr.
8353 boolean removed;
8354
8355 // Have we been asked to have this token keep the screen frozen?
8356 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008358 boolean animating;
8359 Animation animation;
8360 boolean hasTransformation;
8361 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008363 // Offset to the window of all layers in the token, for use by
8364 // AppWindowToken animations.
8365 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008367 // Information about an application starting window if displayed.
8368 StartingData startingData;
8369 WindowState startingWindow;
8370 View startingView;
8371 boolean startingDisplayed;
8372 boolean startingMoved;
8373 boolean firstWindowDrawn;
8374
8375 AppWindowToken(IApplicationToken _token) {
8376 super(_token.asBinder(),
8377 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8378 appWindowToken = this;
8379 appToken = _token;
8380 }
Romain Guy06882f82009-06-10 13:36:04 -07008381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008382 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008383 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008384 TAG, "Setting animation in " + this + ": " + anim);
8385 animation = anim;
8386 animating = false;
8387 anim.restrictDuration(MAX_ANIMATION_DURATION);
8388 anim.scaleCurrentDuration(mTransitionAnimationScale);
8389 int zorder = anim.getZAdjustment();
8390 int adj = 0;
8391 if (zorder == Animation.ZORDER_TOP) {
8392 adj = TYPE_LAYER_OFFSET;
8393 } else if (zorder == Animation.ZORDER_BOTTOM) {
8394 adj = -TYPE_LAYER_OFFSET;
8395 }
Romain Guy06882f82009-06-10 13:36:04 -07008396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008397 if (animLayerAdjustment != adj) {
8398 animLayerAdjustment = adj;
8399 updateLayers();
8400 }
8401 }
Romain Guy06882f82009-06-10 13:36:04 -07008402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008403 public void setDummyAnimation() {
8404 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008405 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008406 TAG, "Setting dummy animation in " + this);
8407 animation = sDummyAnimation;
8408 }
8409 }
8410
8411 public void clearAnimation() {
8412 if (animation != null) {
8413 animation = null;
8414 animating = true;
8415 }
8416 }
Romain Guy06882f82009-06-10 13:36:04 -07008417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008418 void updateLayers() {
8419 final int N = allAppWindows.size();
8420 final int adj = animLayerAdjustment;
8421 for (int i=0; i<N; i++) {
8422 WindowState w = allAppWindows.get(i);
8423 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008424 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008425 + w.mAnimLayer);
8426 if (w == mInputMethodTarget) {
8427 setInputMethodAnimLayerAdjustment(adj);
8428 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008429 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008430 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008431 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008432 }
8433 }
Romain Guy06882f82009-06-10 13:36:04 -07008434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008435 void sendAppVisibilityToClients() {
8436 final int N = allAppWindows.size();
8437 for (int i=0; i<N; i++) {
8438 WindowState win = allAppWindows.get(i);
8439 if (win == startingWindow && clientHidden) {
8440 // Don't hide the starting window.
8441 continue;
8442 }
8443 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008444 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008445 "Setting visibility of " + win + ": " + (!clientHidden));
8446 win.mClient.dispatchAppVisibility(!clientHidden);
8447 } catch (RemoteException e) {
8448 }
8449 }
8450 }
Romain Guy06882f82009-06-10 13:36:04 -07008451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008452 void showAllWindowsLocked() {
8453 final int NW = allAppWindows.size();
8454 for (int i=0; i<NW; i++) {
8455 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008456 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008457 "performing show on: " + w);
8458 w.performShowLocked();
8459 }
8460 }
Romain Guy06882f82009-06-10 13:36:04 -07008461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008462 // This must be called while inside a transaction.
8463 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008464 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008465 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008467 if (animation == sDummyAnimation) {
8468 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008469 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008470 // when it is really time to animate, this will be set to
8471 // a real animation and the next call will execute normally.
8472 return false;
8473 }
Romain Guy06882f82009-06-10 13:36:04 -07008474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008475 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8476 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008477 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008478 TAG, "Starting animation in " + this +
8479 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8480 + " scale=" + mTransitionAnimationScale
8481 + " allDrawn=" + allDrawn + " animating=" + animating);
8482 animation.initialize(dw, dh, dw, dh);
8483 animation.setStartTime(currentTime);
8484 animating = true;
8485 }
8486 transformation.clear();
8487 final boolean more = animation.getTransformation(
8488 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008489 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008490 TAG, "Stepped animation in " + this +
8491 ": more=" + more + ", xform=" + transformation);
8492 if (more) {
8493 // we're done!
8494 hasTransformation = true;
8495 return true;
8496 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008497 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008498 TAG, "Finished animation in " + this +
8499 " @ " + currentTime);
8500 animation = null;
8501 }
8502 } else if (animation != null) {
8503 // If the display is frozen, and there is a pending animation,
8504 // clear it and make sure we run the cleanup code.
8505 animating = true;
8506 animation = null;
8507 }
8508
8509 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008511 if (!animating) {
8512 return false;
8513 }
8514
8515 clearAnimation();
8516 animating = false;
8517 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8518 moveInputMethodWindowsIfNeededLocked(true);
8519 }
Romain Guy06882f82009-06-10 13:36:04 -07008520
Joe Onorato8a9b2202010-02-26 18:56:32 -08008521 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008522 TAG, "Animation done in " + this
8523 + ": reportedVisible=" + reportedVisible);
8524
8525 transformation.clear();
8526 if (animLayerAdjustment != 0) {
8527 animLayerAdjustment = 0;
8528 updateLayers();
8529 }
Romain Guy06882f82009-06-10 13:36:04 -07008530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008531 final int N = windows.size();
8532 for (int i=0; i<N; i++) {
8533 ((WindowState)windows.get(i)).finishExit();
8534 }
8535 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008537 return false;
8538 }
8539
8540 void updateReportedVisibilityLocked() {
8541 if (appToken == null) {
8542 return;
8543 }
Romain Guy06882f82009-06-10 13:36:04 -07008544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008545 int numInteresting = 0;
8546 int numVisible = 0;
8547 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008548
Joe Onorato8a9b2202010-02-26 18:56:32 -08008549 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008550 final int N = allAppWindows.size();
8551 for (int i=0; i<N; i++) {
8552 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008553 if (win == startingWindow || win.mAppFreezing
8554 || win.mViewVisibility != View.VISIBLE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008555 continue;
8556 }
8557 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008558 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008559 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008560 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008561 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008562 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008563 + " pv=" + win.mPolicyVisibility
8564 + " dp=" + win.mDrawPending
8565 + " cdp=" + win.mCommitDrawPending
8566 + " ah=" + win.mAttachedHidden
8567 + " th="
8568 + (win.mAppToken != null
8569 ? win.mAppToken.hiddenRequested : false)
8570 + " a=" + win.mAnimating);
8571 }
8572 }
8573 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008574 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008575 if (!win.isAnimating()) {
8576 numVisible++;
8577 }
8578 nowGone = false;
8579 } else if (win.isAnimating()) {
8580 nowGone = false;
8581 }
8582 }
Romain Guy06882f82009-06-10 13:36:04 -07008583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008584 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008585 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008586 + numInteresting + " visible=" + numVisible);
8587 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008588 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008589 TAG, "Visibility changed in " + this
8590 + ": vis=" + nowVisible);
8591 reportedVisible = nowVisible;
8592 Message m = mH.obtainMessage(
8593 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8594 nowVisible ? 1 : 0,
8595 nowGone ? 1 : 0,
8596 this);
8597 mH.sendMessage(m);
8598 }
8599 }
Romain Guy06882f82009-06-10 13:36:04 -07008600
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008601 WindowState findMainWindow() {
8602 int j = windows.size();
8603 while (j > 0) {
8604 j--;
8605 WindowState win = windows.get(j);
8606 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8607 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8608 return win;
8609 }
8610 }
8611 return null;
8612 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008614 void dump(PrintWriter pw, String prefix) {
8615 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008616 if (appToken != null) {
8617 pw.print(prefix); pw.println("app=true");
8618 }
8619 if (allAppWindows.size() > 0) {
8620 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8621 }
8622 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008623 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008624 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8625 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8626 pw.print(" clientHidden="); pw.print(clientHidden);
8627 pw.print(" willBeHidden="); pw.print(willBeHidden);
8628 pw.print(" reportedVisible="); pw.println(reportedVisible);
8629 if (paused || freezingScreen) {
8630 pw.print(prefix); pw.print("paused="); pw.print(paused);
8631 pw.print(" freezingScreen="); pw.println(freezingScreen);
8632 }
8633 if (numInterestingWindows != 0 || numDrawnWindows != 0
8634 || inPendingTransaction || allDrawn) {
8635 pw.print(prefix); pw.print("numInterestingWindows=");
8636 pw.print(numInterestingWindows);
8637 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8638 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8639 pw.print(" allDrawn="); pw.println(allDrawn);
8640 }
8641 if (animating || animation != null) {
8642 pw.print(prefix); pw.print("animating="); pw.print(animating);
8643 pw.print(" animation="); pw.println(animation);
8644 }
8645 if (animLayerAdjustment != 0) {
8646 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8647 }
8648 if (hasTransformation) {
8649 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8650 pw.print(" transformation="); transformation.printShortString(pw);
8651 pw.println();
8652 }
8653 if (startingData != null || removed || firstWindowDrawn) {
8654 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8655 pw.print(" removed="); pw.print(removed);
8656 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8657 }
8658 if (startingWindow != null || startingView != null
8659 || startingDisplayed || startingMoved) {
8660 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8661 pw.print(" startingView="); pw.print(startingView);
8662 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8663 pw.print(" startingMoved"); pw.println(startingMoved);
8664 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008665 }
8666
8667 @Override
8668 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008669 if (stringName == null) {
8670 StringBuilder sb = new StringBuilder();
8671 sb.append("AppWindowToken{");
8672 sb.append(Integer.toHexString(System.identityHashCode(this)));
8673 sb.append(" token="); sb.append(token); sb.append('}');
8674 stringName = sb.toString();
8675 }
8676 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008677 }
8678 }
Romain Guy06882f82009-06-10 13:36:04 -07008679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008680 // -------------------------------------------------------------
8681 // DummyAnimation
8682 // -------------------------------------------------------------
8683
8684 // This is an animation that does nothing: it just immediately finishes
8685 // itself every time it is called. It is used as a stub animation in cases
8686 // where we want to synchronize multiple things that may be animating.
8687 static final class DummyAnimation extends Animation {
8688 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8689 return false;
8690 }
8691 }
8692 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008694 // -------------------------------------------------------------
8695 // Async Handler
8696 // -------------------------------------------------------------
8697
8698 static final class StartingData {
8699 final String pkg;
8700 final int theme;
8701 final CharSequence nonLocalizedLabel;
8702 final int labelRes;
8703 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008705 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8706 int _labelRes, int _icon) {
8707 pkg = _pkg;
8708 theme = _theme;
8709 nonLocalizedLabel = _nonLocalizedLabel;
8710 labelRes = _labelRes;
8711 icon = _icon;
8712 }
8713 }
8714
8715 private final class H extends Handler {
8716 public static final int REPORT_FOCUS_CHANGE = 2;
8717 public static final int REPORT_LOSING_FOCUS = 3;
8718 public static final int ANIMATE = 4;
8719 public static final int ADD_STARTING = 5;
8720 public static final int REMOVE_STARTING = 6;
8721 public static final int FINISHED_STARTING = 7;
8722 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008723 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8724 public static final int HOLD_SCREEN_CHANGED = 12;
8725 public static final int APP_TRANSITION_TIMEOUT = 13;
8726 public static final int PERSIST_ANIMATION_SCALE = 14;
8727 public static final int FORCE_GC = 15;
8728 public static final int ENABLE_SCREEN = 16;
8729 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008730 public static final int SEND_NEW_CONFIGURATION = 18;
Romain Guy06882f82009-06-10 13:36:04 -07008731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008732 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008734 public H() {
8735 }
Romain Guy06882f82009-06-10 13:36:04 -07008736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008737 @Override
8738 public void handleMessage(Message msg) {
8739 switch (msg.what) {
8740 case REPORT_FOCUS_CHANGE: {
8741 WindowState lastFocus;
8742 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008744 synchronized(mWindowMap) {
8745 lastFocus = mLastFocus;
8746 newFocus = mCurrentFocus;
8747 if (lastFocus == newFocus) {
8748 // Focus is not changing, so nothing to do.
8749 return;
8750 }
8751 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008752 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008753 // + " to " + newFocus);
8754 if (newFocus != null && lastFocus != null
8755 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008756 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008757 mLosingFocus.add(lastFocus);
8758 lastFocus = null;
8759 }
8760 }
8761
8762 if (lastFocus != newFocus) {
8763 //System.out.println("Changing focus from " + lastFocus
8764 // + " to " + newFocus);
8765 if (newFocus != null) {
8766 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008767 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008768 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8769 } catch (RemoteException e) {
8770 // Ignore if process has died.
8771 }
8772 }
8773
8774 if (lastFocus != null) {
8775 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008776 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008777 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8778 } catch (RemoteException e) {
8779 // Ignore if process has died.
8780 }
8781 }
8782 }
8783 } break;
8784
8785 case REPORT_LOSING_FOCUS: {
8786 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008788 synchronized(mWindowMap) {
8789 losers = mLosingFocus;
8790 mLosingFocus = new ArrayList<WindowState>();
8791 }
8792
8793 final int N = losers.size();
8794 for (int i=0; i<N; i++) {
8795 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008796 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008797 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8798 } catch (RemoteException e) {
8799 // Ignore if process has died.
8800 }
8801 }
8802 } break;
8803
8804 case ANIMATE: {
8805 synchronized(mWindowMap) {
8806 mAnimationPending = false;
8807 performLayoutAndPlaceSurfacesLocked();
8808 }
8809 } break;
8810
8811 case ADD_STARTING: {
8812 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8813 final StartingData sd = wtoken.startingData;
8814
8815 if (sd == null) {
8816 // Animation has been canceled... do nothing.
8817 return;
8818 }
Romain Guy06882f82009-06-10 13:36:04 -07008819
Joe Onorato8a9b2202010-02-26 18:56:32 -08008820 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008821 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008823 View view = null;
8824 try {
8825 view = mPolicy.addStartingWindow(
8826 wtoken.token, sd.pkg,
8827 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8828 sd.icon);
8829 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008830 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008831 }
8832
8833 if (view != null) {
8834 boolean abort = false;
8835
8836 synchronized(mWindowMap) {
8837 if (wtoken.removed || wtoken.startingData == null) {
8838 // If the window was successfully added, then
8839 // we need to remove it.
8840 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008841 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008842 "Aborted starting " + wtoken
8843 + ": removed=" + wtoken.removed
8844 + " startingData=" + wtoken.startingData);
8845 wtoken.startingWindow = null;
8846 wtoken.startingData = null;
8847 abort = true;
8848 }
8849 } else {
8850 wtoken.startingView = view;
8851 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008852 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008853 "Added starting " + wtoken
8854 + ": startingWindow="
8855 + wtoken.startingWindow + " startingView="
8856 + wtoken.startingView);
8857 }
8858
8859 if (abort) {
8860 try {
8861 mPolicy.removeStartingWindow(wtoken.token, view);
8862 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008863 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008864 }
8865 }
8866 }
8867 } break;
8868
8869 case REMOVE_STARTING: {
8870 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8871 IBinder token = null;
8872 View view = null;
8873 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008874 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008875 + wtoken + ": startingWindow="
8876 + wtoken.startingWindow + " startingView="
8877 + wtoken.startingView);
8878 if (wtoken.startingWindow != null) {
8879 view = wtoken.startingView;
8880 token = wtoken.token;
8881 wtoken.startingData = null;
8882 wtoken.startingView = null;
8883 wtoken.startingWindow = null;
8884 }
8885 }
8886 if (view != null) {
8887 try {
8888 mPolicy.removeStartingWindow(token, view);
8889 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008890 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008891 }
8892 }
8893 } break;
8894
8895 case FINISHED_STARTING: {
8896 IBinder token = null;
8897 View view = null;
8898 while (true) {
8899 synchronized (mWindowMap) {
8900 final int N = mFinishedStarting.size();
8901 if (N <= 0) {
8902 break;
8903 }
8904 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8905
Joe Onorato8a9b2202010-02-26 18:56:32 -08008906 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008907 "Finished starting " + wtoken
8908 + ": startingWindow=" + wtoken.startingWindow
8909 + " startingView=" + wtoken.startingView);
8910
8911 if (wtoken.startingWindow == null) {
8912 continue;
8913 }
8914
8915 view = wtoken.startingView;
8916 token = wtoken.token;
8917 wtoken.startingData = null;
8918 wtoken.startingView = null;
8919 wtoken.startingWindow = null;
8920 }
8921
8922 try {
8923 mPolicy.removeStartingWindow(token, view);
8924 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008925 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008926 }
8927 }
8928 } break;
8929
8930 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8931 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8932
8933 boolean nowVisible = msg.arg1 != 0;
8934 boolean nowGone = msg.arg2 != 0;
8935
8936 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008937 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008938 TAG, "Reporting visible in " + wtoken
8939 + " visible=" + nowVisible
8940 + " gone=" + nowGone);
8941 if (nowVisible) {
8942 wtoken.appToken.windowsVisible();
8943 } else {
8944 wtoken.appToken.windowsGone();
8945 }
8946 } catch (RemoteException ex) {
8947 }
8948 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008950 case WINDOW_FREEZE_TIMEOUT: {
8951 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008952 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008953 int i = mWindows.size();
8954 while (i > 0) {
8955 i--;
8956 WindowState w = (WindowState)mWindows.get(i);
8957 if (w.mOrientationChanging) {
8958 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008959 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008960 }
8961 }
8962 performLayoutAndPlaceSurfacesLocked();
8963 }
8964 break;
8965 }
Romain Guy06882f82009-06-10 13:36:04 -07008966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008967 case HOLD_SCREEN_CHANGED: {
8968 Session oldHold;
8969 Session newHold;
8970 synchronized (mWindowMap) {
8971 oldHold = mLastReportedHold;
8972 newHold = (Session)msg.obj;
8973 mLastReportedHold = newHold;
8974 }
Romain Guy06882f82009-06-10 13:36:04 -07008975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008976 if (oldHold != newHold) {
8977 try {
8978 if (oldHold != null) {
8979 mBatteryStats.noteStopWakelock(oldHold.mUid,
8980 "window",
8981 BatteryStats.WAKE_TYPE_WINDOW);
8982 }
8983 if (newHold != null) {
8984 mBatteryStats.noteStartWakelock(newHold.mUid,
8985 "window",
8986 BatteryStats.WAKE_TYPE_WINDOW);
8987 }
8988 } catch (RemoteException e) {
8989 }
8990 }
8991 break;
8992 }
Romain Guy06882f82009-06-10 13:36:04 -07008993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008994 case APP_TRANSITION_TIMEOUT: {
8995 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008996 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008997 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008998 "*** APP TRANSITION TIMEOUT");
8999 mAppTransitionReady = true;
9000 mAppTransitionTimeout = true;
9001 performLayoutAndPlaceSurfacesLocked();
9002 }
9003 }
9004 break;
9005 }
Romain Guy06882f82009-06-10 13:36:04 -07009006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009007 case PERSIST_ANIMATION_SCALE: {
9008 Settings.System.putFloat(mContext.getContentResolver(),
9009 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9010 Settings.System.putFloat(mContext.getContentResolver(),
9011 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9012 break;
9013 }
Romain Guy06882f82009-06-10 13:36:04 -07009014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009015 case FORCE_GC: {
9016 synchronized(mWindowMap) {
9017 if (mAnimationPending) {
9018 // If we are animating, don't do the gc now but
9019 // delay a bit so we don't interrupt the animation.
9020 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9021 2000);
9022 return;
9023 }
9024 // If we are currently rotating the display, it will
9025 // schedule a new message when done.
9026 if (mDisplayFrozen) {
9027 return;
9028 }
9029 mFreezeGcPending = 0;
9030 }
9031 Runtime.getRuntime().gc();
9032 break;
9033 }
Romain Guy06882f82009-06-10 13:36:04 -07009034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009035 case ENABLE_SCREEN: {
9036 performEnableScreen();
9037 break;
9038 }
Romain Guy06882f82009-06-10 13:36:04 -07009039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009040 case APP_FREEZE_TIMEOUT: {
9041 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009042 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009043 int i = mAppTokens.size();
9044 while (i > 0) {
9045 i--;
9046 AppWindowToken tok = mAppTokens.get(i);
9047 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009048 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009049 unsetAppFreezingScreenLocked(tok, true, true);
9050 }
9051 }
9052 }
9053 break;
9054 }
Romain Guy06882f82009-06-10 13:36:04 -07009055
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009056 case SEND_NEW_CONFIGURATION: {
9057 removeMessages(SEND_NEW_CONFIGURATION);
9058 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009059 break;
9060 }
Romain Guy06882f82009-06-10 13:36:04 -07009061
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009062 }
9063 }
9064 }
9065
9066 // -------------------------------------------------------------
9067 // IWindowManager API
9068 // -------------------------------------------------------------
9069
9070 public IWindowSession openSession(IInputMethodClient client,
9071 IInputContext inputContext) {
9072 if (client == null) throw new IllegalArgumentException("null client");
9073 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
9074 return new Session(client, inputContext);
9075 }
9076
9077 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9078 synchronized (mWindowMap) {
9079 // The focus for the client is the window immediately below
9080 // where we would place the input method window.
9081 int idx = findDesiredInputMethodWindowIndexLocked(false);
9082 WindowState imFocus;
9083 if (idx > 0) {
9084 imFocus = (WindowState)mWindows.get(idx-1);
9085 if (imFocus != null) {
9086 if (imFocus.mSession.mClient != null &&
9087 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9088 return true;
9089 }
9090 }
9091 }
9092 }
9093 return false;
9094 }
Romain Guy06882f82009-06-10 13:36:04 -07009095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009096 // -------------------------------------------------------------
9097 // Internals
9098 // -------------------------------------------------------------
9099
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009100 final WindowState windowForClientLocked(Session session, IWindow client,
9101 boolean throwOnError) {
9102 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009103 }
Romain Guy06882f82009-06-10 13:36:04 -07009104
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009105 final WindowState windowForClientLocked(Session session, IBinder client,
9106 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009107 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009108 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009109 TAG, "Looking up client " + client + ": " + win);
9110 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009111 RuntimeException ex = new IllegalArgumentException(
9112 "Requested window " + client + " does not exist");
9113 if (throwOnError) {
9114 throw ex;
9115 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009116 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009117 return null;
9118 }
9119 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009120 RuntimeException ex = new IllegalArgumentException(
9121 "Requested window " + client + " is in session " +
9122 win.mSession + ", not " + session);
9123 if (throwOnError) {
9124 throw ex;
9125 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009126 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009127 return null;
9128 }
9129
9130 return win;
9131 }
9132
Dianne Hackborna8f60182009-09-01 19:01:50 -07009133 final void rebuildAppWindowListLocked() {
9134 int NW = mWindows.size();
9135 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009136 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009137 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009138
Dianne Hackborna8f60182009-09-01 19:01:50 -07009139 // First remove all existing app windows.
9140 i=0;
9141 while (i < NW) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009142 WindowState w = (WindowState)mWindows.get(i);
9143 if (w.mAppToken != null) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009144 WindowState win = (WindowState)mWindows.remove(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009145 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009146 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009147 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009148 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009149 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009150 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9151 && lastWallpaper == i-1) {
9152 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009153 }
9154 i++;
9155 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009156
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009157 // The wallpaper window(s) typically live at the bottom of the stack,
9158 // so skip them before adding app tokens.
9159 lastWallpaper++;
9160 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009161
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009162 // First add all of the exiting app tokens... these are no longer
9163 // in the main app list, but still have windows shown. We put them
9164 // in the back because now that the animation is over we no longer
9165 // will care about them.
9166 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009167 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009168 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9169 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009170
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009171 // And add in the still active app tokens in Z order.
9172 NT = mAppTokens.size();
9173 for (int j=0; j<NT; j++) {
9174 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009175 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009176
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009177 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009178 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009179 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009180 + " windows but added " + i);
9181 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009182 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009184 private final void assignLayersLocked() {
9185 int N = mWindows.size();
9186 int curBaseLayer = 0;
9187 int curLayer = 0;
9188 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009190 for (i=0; i<N; i++) {
9191 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009192 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9193 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009194 curLayer += WINDOW_LAYER_MULTIPLIER;
9195 w.mLayer = curLayer;
9196 } else {
9197 curBaseLayer = curLayer = w.mBaseLayer;
9198 w.mLayer = curLayer;
9199 }
9200 if (w.mTargetAppToken != null) {
9201 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9202 } else if (w.mAppToken != null) {
9203 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9204 } else {
9205 w.mAnimLayer = w.mLayer;
9206 }
9207 if (w.mIsImWindow) {
9208 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009209 } else if (w.mIsWallpaper) {
9210 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009211 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009212 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009213 + w.mAnimLayer);
9214 //System.out.println(
9215 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9216 }
9217 }
9218
9219 private boolean mInLayout = false;
9220 private final void performLayoutAndPlaceSurfacesLocked() {
9221 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009222 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009223 throw new RuntimeException("Recursive call!");
9224 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009225 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009226 return;
9227 }
9228
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009229 if (mWaitingForConfig) {
9230 // Our configuration has changed (most likely rotation), but we
9231 // don't yet have the complete configuration to report to
9232 // applications. Don't do any window layout until we have it.
9233 return;
9234 }
9235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009236 boolean recoveringMemory = false;
9237 if (mForceRemoves != null) {
9238 recoveringMemory = true;
9239 // Wait a little it for things to settle down, and off we go.
9240 for (int i=0; i<mForceRemoves.size(); i++) {
9241 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009242 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009243 removeWindowInnerLocked(ws.mSession, ws);
9244 }
9245 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009246 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009247 Object tmp = new Object();
9248 synchronized (tmp) {
9249 try {
9250 tmp.wait(250);
9251 } catch (InterruptedException e) {
9252 }
9253 }
9254 }
Romain Guy06882f82009-06-10 13:36:04 -07009255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009256 mInLayout = true;
9257 try {
9258 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009260 int i = mPendingRemove.size()-1;
9261 if (i >= 0) {
9262 while (i >= 0) {
9263 WindowState w = mPendingRemove.get(i);
9264 removeWindowInnerLocked(w.mSession, w);
9265 i--;
9266 }
9267 mPendingRemove.clear();
9268
9269 mInLayout = false;
9270 assignLayersLocked();
9271 mLayoutNeeded = true;
9272 performLayoutAndPlaceSurfacesLocked();
9273
9274 } else {
9275 mInLayout = false;
9276 if (mLayoutNeeded) {
9277 requestAnimationLocked(0);
9278 }
9279 }
9280 } catch (RuntimeException e) {
9281 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009282 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009283 }
9284 }
9285
9286 private final void performLayoutLockedInner() {
9287 final int dw = mDisplay.getWidth();
9288 final int dh = mDisplay.getHeight();
9289
9290 final int N = mWindows.size();
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009291 int repeats = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009292 int i;
9293
Joe Onorato8a9b2202010-02-26 18:56:32 -08009294 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009295 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009297 // FIRST LOOP: Perform a layout, if needed.
Romain Guy06882f82009-06-10 13:36:04 -07009298
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009299 while (mLayoutNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009300 mPolicy.beginLayoutLw(dw, dh);
9301
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009302 int seq = mLayoutSeq+1;
9303 if (seq < 0) seq = 0;
9304 mLayoutSeq = seq;
9305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009306 // First perform layout of any root windows (not attached
9307 // to another window).
9308 int topAttached = -1;
9309 for (i = N-1; i >= 0; i--) {
9310 WindowState win = (WindowState) mWindows.get(i);
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009311
9312 // Don't do layout of a window if it is not visible, or
9313 // soon won't be visible, to avoid wasting time and funky
9314 // changes while a window is animating away.
9315 final AppWindowToken atoken = win.mAppToken;
9316 final boolean gone = win.mViewVisibility == View.GONE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009317 || !win.mRelayoutCalled
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009318 || win.mRootToken.hidden
9319 || (atoken != null && atoken.hiddenRequested)
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009320 || win.mAttachedHidden
9321 || win.mExiting || win.mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009322
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009323 if (!win.mLayoutAttached) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009324 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009325 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9326 + " mLayoutAttached=" + win.mLayoutAttached);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009327 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009328 + win.mViewVisibility + " mRelayoutCalled="
9329 + win.mRelayoutCalled + " hidden="
9330 + win.mRootToken.hidden + " hiddenRequested="
9331 + (atoken != null && atoken.hiddenRequested)
9332 + " mAttachedHidden=" + win.mAttachedHidden);
9333 }
9334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009335 // If this view is GONE, then skip it -- keep the current
9336 // frame, and let the caller know so they can ignore it
9337 // if they want. (We do the normal layout for INVISIBLE
9338 // windows, since that means "perform layout as normal,
9339 // just don't display").
9340 if (!gone || !win.mHaveFrame) {
9341 if (!win.mLayoutAttached) {
9342 mPolicy.layoutWindowLw(win, win.mAttrs, null);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009343 win.mLayoutSeq = seq;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009344 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009345 + win.mFrame + " mContainingFrame="
9346 + win.mContainingFrame + " mDisplayFrame="
9347 + win.mDisplayFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009348 } else {
9349 if (topAttached < 0) topAttached = i;
9350 }
9351 }
9352 }
Romain Guy06882f82009-06-10 13:36:04 -07009353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009354 // Now perform layout of attached windows, which usually
9355 // depend on the position of the window they are attached to.
9356 // XXX does not deal with windows that are attached to windows
9357 // that are themselves attached.
9358 for (i = topAttached; i >= 0; i--) {
9359 WindowState win = (WindowState) mWindows.get(i);
9360
9361 // If this view is GONE, then skip it -- keep the current
9362 // frame, and let the caller know so they can ignore it
9363 // if they want. (We do the normal layout for INVISIBLE
9364 // windows, since that means "perform layout as normal,
9365 // just don't display").
9366 if (win.mLayoutAttached) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009367 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009368 + " mHaveFrame=" + win.mHaveFrame
9369 + " mViewVisibility=" + win.mViewVisibility
9370 + " mRelayoutCalled=" + win.mRelayoutCalled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009371 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9372 || !win.mHaveFrame) {
9373 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009374 win.mLayoutSeq = seq;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009375 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009376 + win.mFrame + " mContainingFrame="
9377 + win.mContainingFrame + " mDisplayFrame="
9378 + win.mDisplayFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009379 }
9380 }
9381 }
9382
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009383 int changes = mPolicy.finishLayoutLw();
9384 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9385 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9386 assignLayersLocked();
9387 }
9388 }
9389 if (changes == 0) {
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009390 mLayoutNeeded = false;
9391 } else if (repeats > 2) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009392 Slog.w(TAG, "Layout repeat aborted after too many iterations");
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009393 mLayoutNeeded = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009394 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009395 if (updateOrientationFromAppTokensLocked()) {
9396 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009397 }
9398 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009399 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009400 if (DEBUG_LAYOUT) Slog.v(TAG, "Repeating layout because changes=0x"
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009401 + Integer.toHexString(changes));
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009402 repeats++;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009403 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009404 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009405 if (updateOrientationFromAppTokensLocked()) {
9406 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009407 }
9408 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009409 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009410 }
9411 }
Romain Guy06882f82009-06-10 13:36:04 -07009412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009413 private final void performLayoutAndPlaceSurfacesLockedInner(
9414 boolean recoveringMemory) {
9415 final long currentTime = SystemClock.uptimeMillis();
9416 final int dw = mDisplay.getWidth();
9417 final int dh = mDisplay.getHeight();
9418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009419 int i;
9420
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009421 if (mFocusMayChange) {
9422 mFocusMayChange = false;
9423 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9424 }
9425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009426 // FIRST LOOP: Perform a layout, if needed.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009427 performLayoutLockedInner();
Romain Guy06882f82009-06-10 13:36:04 -07009428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009429 if (mFxSession == null) {
9430 mFxSession = new SurfaceSession();
9431 }
Romain Guy06882f82009-06-10 13:36:04 -07009432
Joe Onorato8a9b2202010-02-26 18:56:32 -08009433 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009434
9435 // Initialize state of exiting tokens.
9436 for (i=mExitingTokens.size()-1; i>=0; i--) {
9437 mExitingTokens.get(i).hasVisible = false;
9438 }
9439
9440 // Initialize state of exiting applications.
9441 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9442 mExitingAppTokens.get(i).hasVisible = false;
9443 }
9444
9445 // SECOND LOOP: Execute animations and update visibility of windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009446 boolean orientationChangeComplete = true;
9447 Session holdScreen = null;
9448 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009449 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009450 boolean focusDisplayed = false;
9451 boolean animating = false;
9452
9453 Surface.openTransaction();
9454 try {
9455 boolean restart;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009456 boolean forceHiding = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009457 boolean wallpaperForceHidingChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009458
9459 do {
9460 final int transactionSequence = ++mTransactionSequence;
9461
9462 // Update animations of all applications, including those
9463 // associated with exiting/removed apps
9464 boolean tokensAnimating = false;
9465 final int NAT = mAppTokens.size();
9466 for (i=0; i<NAT; i++) {
9467 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9468 tokensAnimating = true;
9469 }
9470 }
9471 final int NEAT = mExitingAppTokens.size();
9472 for (i=0; i<NEAT; i++) {
9473 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9474 tokensAnimating = true;
9475 }
9476 }
9477
Joe Onorato8a9b2202010-02-26 18:56:32 -08009478 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009479 + transactionSequence + " tokensAnimating="
9480 + tokensAnimating);
9481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009482 animating = tokensAnimating;
9483 restart = false;
9484
9485 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009486 boolean wallpaperMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009487
9488 mPolicy.beginAnimationLw(dw, dh);
9489
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009490 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009492 for (i=N-1; i>=0; i--) {
9493 WindowState w = (WindowState)mWindows.get(i);
9494
9495 final WindowManager.LayoutParams attrs = w.mAttrs;
9496
9497 if (w.mSurface != null) {
9498 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009499 if (w.commitFinishDrawingLocked(currentTime)) {
9500 if ((w.mAttrs.flags
9501 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009502 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009503 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009504 wallpaperMayChange = true;
9505 }
9506 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009507
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009508 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009509 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9510 animating = true;
9511 //w.dump(" ");
9512 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009513 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9514 wallpaperMayChange = true;
9515 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009516
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009517 if (mPolicy.doesForceHide(w, attrs)) {
9518 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009519 if (DEBUG_VISIBILITY) Slog.v(TAG,
9520 "Animation done that could impact force hide: "
9521 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009522 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009523 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009524 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9525 forceHiding = true;
9526 }
9527 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9528 boolean changed;
9529 if (forceHiding) {
9530 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009531 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9532 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009533 } else {
9534 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009535 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9536 "Now policy shown: " + w);
9537 if (changed) {
9538 if (wallpaperForceHidingChanged
9539 && w.isReadyForDisplay()) {
9540 // Assume we will need to animate. If
9541 // we don't (because the wallpaper will
9542 // stay with the lock screen), then we will
9543 // clean up later.
9544 Animation a = mPolicy.createForceHideEnterAnimation();
9545 if (a != null) {
9546 w.setAnimation(a);
9547 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009548 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009549 if (mCurrentFocus == null ||
9550 mCurrentFocus.mLayer < w.mLayer) {
9551 // We are showing on to of the current
9552 // focus, so re-evaluate focus to make
9553 // sure it is correct.
9554 mFocusMayChange = true;
9555 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009556 }
9557 }
9558 if (changed && (attrs.flags
9559 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9560 wallpaperMayChange = true;
9561 }
9562 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009564 mPolicy.animatingWindowLw(w, attrs);
9565 }
9566
9567 final AppWindowToken atoken = w.mAppToken;
9568 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9569 if (atoken.lastTransactionSequence != transactionSequence) {
9570 atoken.lastTransactionSequence = transactionSequence;
9571 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9572 atoken.startingDisplayed = false;
9573 }
9574 if ((w.isOnScreen() || w.mAttrs.type
9575 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9576 && !w.mExiting && !w.mDestroying) {
9577 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009578 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009579 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009580 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009581 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009582 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009583 + " pv=" + w.mPolicyVisibility
9584 + " dp=" + w.mDrawPending
9585 + " cdp=" + w.mCommitDrawPending
9586 + " ah=" + w.mAttachedHidden
9587 + " th=" + atoken.hiddenRequested
9588 + " a=" + w.mAnimating);
9589 }
9590 }
9591 if (w != atoken.startingWindow) {
9592 if (!atoken.freezingScreen || !w.mAppFreezing) {
9593 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009594 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009595 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009596 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009597 "tokenMayBeDrawn: " + atoken
9598 + " freezingScreen=" + atoken.freezingScreen
9599 + " mAppFreezing=" + w.mAppFreezing);
9600 tokenMayBeDrawn = true;
9601 }
9602 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009603 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009604 atoken.startingDisplayed = true;
9605 }
9606 }
9607 } else if (w.mReadyToShow) {
9608 w.performShowLocked();
9609 }
9610 }
9611
9612 if (mPolicy.finishAnimationLw()) {
9613 restart = true;
9614 }
9615
9616 if (tokenMayBeDrawn) {
9617 // See if any windows have been drawn, so they (and others
9618 // associated with them) can now be shown.
9619 final int NT = mTokenList.size();
9620 for (i=0; i<NT; i++) {
9621 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9622 if (wtoken == null) {
9623 continue;
9624 }
9625 if (wtoken.freezingScreen) {
9626 int numInteresting = wtoken.numInterestingWindows;
9627 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009628 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009629 "allDrawn: " + wtoken
9630 + " interesting=" + numInteresting
9631 + " drawn=" + wtoken.numDrawnWindows);
9632 wtoken.showAllWindowsLocked();
9633 unsetAppFreezingScreenLocked(wtoken, false, true);
9634 orientationChangeComplete = true;
9635 }
9636 } else if (!wtoken.allDrawn) {
9637 int numInteresting = wtoken.numInterestingWindows;
9638 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009639 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009640 "allDrawn: " + wtoken
9641 + " interesting=" + numInteresting
9642 + " drawn=" + wtoken.numDrawnWindows);
9643 wtoken.allDrawn = true;
9644 restart = true;
9645
9646 // We can now show all of the drawn windows!
9647 if (!mOpeningApps.contains(wtoken)) {
9648 wtoken.showAllWindowsLocked();
9649 }
9650 }
9651 }
9652 }
9653 }
9654
9655 // If we are ready to perform an app transition, check through
9656 // all of the app tokens to be shown and see if they are ready
9657 // to go.
9658 if (mAppTransitionReady) {
9659 int NN = mOpeningApps.size();
9660 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009661 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009662 "Checking " + NN + " opening apps (frozen="
9663 + mDisplayFrozen + " timeout="
9664 + mAppTransitionTimeout + ")...");
9665 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9666 // If the display isn't frozen, wait to do anything until
9667 // all of the apps are ready. Otherwise just go because
9668 // we'll unfreeze the display when everyone is ready.
9669 for (i=0; i<NN && goodToGo; i++) {
9670 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009671 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009672 "Check opening app" + wtoken + ": allDrawn="
9673 + wtoken.allDrawn + " startingDisplayed="
9674 + wtoken.startingDisplayed);
9675 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9676 && !wtoken.startingMoved) {
9677 goodToGo = false;
9678 }
9679 }
9680 }
9681 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009682 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009683 int transit = mNextAppTransition;
9684 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009685 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009686 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009687 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009688 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009689 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009690 mAppTransitionTimeout = false;
9691 mStartingIconInTransition = false;
9692 mSkipAppTransitionAnimation = false;
9693
9694 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9695
Dianne Hackborna8f60182009-09-01 19:01:50 -07009696 // If there are applications waiting to come to the
9697 // top of the stack, now is the time to move their windows.
9698 // (Note that we don't do apps going to the bottom
9699 // here -- we want to keep their windows in the old
9700 // Z-order until the animation completes.)
9701 if (mToTopApps.size() > 0) {
9702 NN = mAppTokens.size();
9703 for (i=0; i<NN; i++) {
9704 AppWindowToken wtoken = mAppTokens.get(i);
9705 if (wtoken.sendingToTop) {
9706 wtoken.sendingToTop = false;
9707 moveAppWindowsLocked(wtoken, NN, false);
9708 }
9709 }
9710 mToTopApps.clear();
9711 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009712
Dianne Hackborn25994b42009-09-04 14:21:19 -07009713 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009714
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009715 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009716 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009717
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009718 // The top-most window will supply the layout params,
9719 // and we will determine it below.
9720 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009721 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009722 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009723
Joe Onorato8a9b2202010-02-26 18:56:32 -08009724 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009725 "New wallpaper target=" + mWallpaperTarget
9726 + ", lower target=" + mLowerWallpaperTarget
9727 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009728 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009729 // Do a first pass through the tokens for two
9730 // things:
9731 // (1) Determine if both the closing and opening
9732 // app token sets are wallpaper targets, in which
9733 // case special animations are needed
9734 // (since the wallpaper needs to stay static
9735 // behind them).
9736 // (2) Find the layout params of the top-most
9737 // application window in the tokens, which is
9738 // what will control the animation theme.
9739 final int NC = mClosingApps.size();
9740 NN = NC + mOpeningApps.size();
9741 for (i=0; i<NN; i++) {
9742 AppWindowToken wtoken;
9743 int mode;
9744 if (i < NC) {
9745 wtoken = mClosingApps.get(i);
9746 mode = 1;
9747 } else {
9748 wtoken = mOpeningApps.get(i-NC);
9749 mode = 2;
9750 }
9751 if (mLowerWallpaperTarget != null) {
9752 if (mLowerWallpaperTarget.mAppToken == wtoken
9753 || mUpperWallpaperTarget.mAppToken == wtoken) {
9754 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009755 }
9756 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009757 if (wtoken.appFullscreen) {
9758 WindowState ws = wtoken.findMainWindow();
9759 if (ws != null) {
9760 // If this is a compatibility mode
9761 // window, we will always use its anim.
9762 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9763 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009764 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009765 bestAnimLayer = Integer.MAX_VALUE;
9766 } else if (ws.mLayer > bestAnimLayer) {
9767 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009768 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009769 bestAnimLayer = ws.mLayer;
9770 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009771 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009772 }
9773 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009774
Dianne Hackborn25994b42009-09-04 14:21:19 -07009775 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009776 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009777 "Wallpaper animation!");
9778 switch (transit) {
9779 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9780 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9781 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9782 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9783 break;
9784 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9785 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9786 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9787 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9788 break;
9789 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009790 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009791 "New transit: " + transit);
9792 } else if (oldWallpaper != null) {
9793 // We are transitioning from an activity with
9794 // a wallpaper to one without.
9795 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009796 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009797 "New transit away from wallpaper: " + transit);
9798 } else if (mWallpaperTarget != null) {
9799 // We are transitioning from an activity without
9800 // a wallpaper to now showing the wallpaper
9801 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009802 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009803 "New transit into wallpaper: " + transit);
9804 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009805
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009806 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9807 mLastEnterAnimToken = animToken;
9808 mLastEnterAnimParams = animLp;
9809 } else if (mLastEnterAnimParams != null) {
9810 animLp = mLastEnterAnimParams;
9811 mLastEnterAnimToken = null;
9812 mLastEnterAnimParams = null;
9813 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009814
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009815 // If all closing windows are obscured, then there is
9816 // no need to do an animation. This is the case, for
9817 // example, when this transition is being done behind
9818 // the lock screen.
9819 if (!mPolicy.allowAppAnimationsLw()) {
9820 animLp = null;
9821 }
9822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009823 NN = mOpeningApps.size();
9824 for (i=0; i<NN; i++) {
9825 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009826 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009827 "Now opening app" + wtoken);
9828 wtoken.reportedVisible = false;
9829 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009830 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009831 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009832 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009833 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009834 wtoken.showAllWindowsLocked();
9835 }
9836 NN = mClosingApps.size();
9837 for (i=0; i<NN; i++) {
9838 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009839 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009840 "Now closing app" + wtoken);
9841 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009842 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009843 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009844 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009845 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009846 // Force the allDrawn flag, because we want to start
9847 // this guy's animations regardless of whether it's
9848 // gotten drawn.
9849 wtoken.allDrawn = true;
9850 }
9851
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009852 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009854 mOpeningApps.clear();
9855 mClosingApps.clear();
9856
9857 // This has changed the visibility of windows, so perform
9858 // a new layout to get them all up-to-date.
9859 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009860 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9861 assignLayersLocked();
9862 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009863 performLayoutLockedInner();
9864 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009865 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009866
9867 restart = true;
9868 }
9869 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009870
Dianne Hackborna8f60182009-09-01 19:01:50 -07009871 if (!animating && mAppTransitionRunning) {
9872 // We have finished the animation of an app transition. To do
9873 // this, we have delayed a lot of operations like showing and
9874 // hiding apps, moving apps in Z-order, etc. The app token list
9875 // reflects the correct Z-order, but the window list may now
9876 // be out of sync with it. So here we will just rebuild the
9877 // entire app window list. Fun!
9878 mAppTransitionRunning = false;
9879 // Clear information about apps that were moving.
9880 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009881
Dianne Hackborna8f60182009-09-01 19:01:50 -07009882 rebuildAppWindowListLocked();
9883 restart = true;
9884 moveInputMethodWindowsIfNeededLocked(false);
9885 wallpaperMayChange = true;
9886 mLayoutNeeded = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009887 // Since the window list has been rebuilt, focus might
9888 // have to be recomputed since the actual order of windows
9889 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009890 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009891 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009892
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009893 int adjResult = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009894
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009895 if (wallpaperForceHidingChanged && !restart && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009896 // At this point, there was a window with a wallpaper that
9897 // was force hiding other windows behind it, but now it
9898 // is going away. This may be simple -- just animate
9899 // away the wallpaper and its window -- or it may be
9900 // hard -- the wallpaper now needs to be shown behind
9901 // something that was hidden.
9902 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009903 if (mLowerWallpaperTarget != null
9904 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009905 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009906 "wallpaperForceHiding changed with lower="
9907 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009908 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009909 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9910 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9911 if (mLowerWallpaperTarget.mAppToken.hidden) {
9912 // The lower target has become hidden before we
9913 // actually started the animation... let's completely
9914 // re-evaluate everything.
9915 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
9916 restart = true;
9917 }
9918 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009919 adjResult = adjustWallpaperWindowsLocked();
9920 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009921 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009922 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009923 + " NEW: " + mWallpaperTarget
9924 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009925 if (mLowerWallpaperTarget == null) {
9926 // Whoops, we don't need a special wallpaper animation.
9927 // Clear them out.
9928 forceHiding = false;
9929 for (i=N-1; i>=0; i--) {
9930 WindowState w = (WindowState)mWindows.get(i);
9931 if (w.mSurface != null) {
9932 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009933 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009934 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009935 forceHiding = true;
9936 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9937 if (!w.mAnimating) {
9938 // We set the animation above so it
9939 // is not yet running.
9940 w.clearAnimation();
9941 }
9942 }
9943 }
9944 }
9945 }
9946 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009947
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009948 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009949 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009950 "Wallpaper may change! Adjusting");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009951 adjResult = adjustWallpaperWindowsLocked();
9952 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009953
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009954 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009955 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009956 "Wallpaper layer changed: assigning layers + relayout");
9957 restart = true;
9958 mLayoutNeeded = true;
9959 assignLayersLocked();
9960 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009961 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009962 "Wallpaper visibility changed: relayout");
9963 restart = true;
9964 mLayoutNeeded = true;
9965 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009966
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009967 if (mFocusMayChange) {
9968 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009969 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009970 restart = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009971 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009972 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009973 }
9974
9975 if (mLayoutNeeded) {
9976 restart = true;
9977 performLayoutLockedInner();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009978 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009979
Joe Onorato8a9b2202010-02-26 18:56:32 -08009980 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: restart="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009981 + restart);
9982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009983 } while (restart);
9984
9985 // THIRD LOOP: Update the surfaces of all windows.
9986
9987 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9988
9989 boolean obscured = false;
9990 boolean blurring = false;
9991 boolean dimming = false;
9992 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009993 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009994 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009995
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009996 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009998 for (i=N-1; i>=0; i--) {
9999 WindowState w = (WindowState)mWindows.get(i);
10000
10001 boolean displayed = false;
10002 final WindowManager.LayoutParams attrs = w.mAttrs;
10003 final int attrFlags = attrs.flags;
10004
10005 if (w.mSurface != null) {
10006 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010007 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010008 TAG, "Placing surface #" + i + " " + w.mSurface
10009 + ": new=" + w.mShownFrame + ", old="
10010 + w.mLastShownFrame);
10011
10012 boolean resize;
10013 int width, height;
10014 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
10015 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
10016 w.mLastRequestedHeight != w.mRequestedHeight;
10017 // for a scaled surface, we just want to use
10018 // the requested size.
10019 width = w.mRequestedWidth;
10020 height = w.mRequestedHeight;
10021 w.mLastRequestedWidth = width;
10022 w.mLastRequestedHeight = height;
10023 w.mLastShownFrame.set(w.mShownFrame);
10024 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010025 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010026 TAG, " SURFACE " + w.mSurface
10027 + ": POS " + w.mShownFrame.left
10028 + ", " + w.mShownFrame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010029 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10030 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010031 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010032 if (!recoveringMemory) {
10033 reclaimSomeSurfaceMemoryLocked(w, "position");
10034 }
10035 }
10036 } else {
10037 resize = !w.mLastShownFrame.equals(w.mShownFrame);
10038 width = w.mShownFrame.width();
10039 height = w.mShownFrame.height();
10040 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010041 }
10042
10043 if (resize) {
10044 if (width < 1) width = 1;
10045 if (height < 1) height = 1;
10046 if (w.mSurface != null) {
10047 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010048 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010049 TAG, " SURFACE " + w.mSurface + ": POS "
10050 + w.mShownFrame.left + ","
10051 + w.mShownFrame.top + " SIZE "
10052 + w.mShownFrame.width() + "x"
10053 + w.mShownFrame.height());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010054 w.mSurface.setSize(width, height);
10055 w.mSurface.setPosition(w.mShownFrame.left,
10056 w.mShownFrame.top);
10057 } catch (RuntimeException e) {
10058 // If something goes wrong with the surface (such
10059 // as running out of memory), don't take down the
10060 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010061 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010062 + "size=(" + width + "x" + height
10063 + "), pos=(" + w.mShownFrame.left
10064 + "," + w.mShownFrame.top + ")", e);
10065 if (!recoveringMemory) {
10066 reclaimSomeSurfaceMemoryLocked(w, "size");
10067 }
10068 }
10069 }
10070 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010071 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010072 w.mContentInsetsChanged =
10073 !w.mLastContentInsets.equals(w.mContentInsets);
10074 w.mVisibleInsetsChanged =
10075 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010076 boolean configChanged =
10077 w.mConfiguration != mCurConfiguration
10078 && (w.mConfiguration == null
10079 || mCurConfiguration.diff(w.mConfiguration) != 0);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010080 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010081 + ": configChanged=" + configChanged
10082 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -070010083 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010084 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010085 || w.mVisibleInsetsChanged
10086 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010087 w.mLastFrame.set(w.mFrame);
10088 w.mLastContentInsets.set(w.mContentInsets);
10089 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010090 // If the screen is currently frozen, then keep
10091 // it frozen until this window draws at its new
10092 // orientation.
10093 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010094 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010095 "Resizing while display frozen: " + w);
10096 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010097 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010098 mWindowsFreezingScreen = true;
10099 // XXX should probably keep timeout from
10100 // when we first froze the display.
10101 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10102 mH.sendMessageDelayed(mH.obtainMessage(
10103 H.WINDOW_FREEZE_TIMEOUT), 2000);
10104 }
10105 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010106 // If the orientation is changing, then we need to
10107 // hold off on unfreezing the display until this
10108 // window has been redrawn; to do that, we need
10109 // to go through the process of getting informed
10110 // by the application when it has finished drawing.
10111 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010112 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010113 "Orientation start waiting for draw in "
10114 + w + ", surface " + w.mSurface);
10115 w.mDrawPending = true;
10116 w.mCommitDrawPending = false;
10117 w.mReadyToShow = false;
10118 if (w.mAppToken != null) {
10119 w.mAppToken.allDrawn = false;
10120 }
10121 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010122 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010123 "Resizing window " + w + " to " + w.mFrame);
10124 mResizingWindows.add(w);
10125 } else if (w.mOrientationChanging) {
10126 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010127 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010128 "Orientation not waiting for draw in "
10129 + w + ", surface " + w.mSurface);
10130 w.mOrientationChanging = false;
10131 }
10132 }
10133 }
10134
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010135 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010136 if (!w.mLastHidden) {
10137 //dump();
10138 w.mLastHidden = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010139 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010140 TAG, " SURFACE " + w.mSurface + ": HIDE (performLayout)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010141 if (w.mSurface != null) {
10142 try {
10143 w.mSurface.hide();
10144 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010145 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010146 }
10147 }
10148 mKeyWaiter.releasePendingPointerLocked(w.mSession);
10149 }
10150 // If we are waiting for this window to handle an
10151 // orientation change, well, it is hidden, so
10152 // doesn't really matter. Note that this does
10153 // introduce a potential glitch if the window
10154 // becomes unhidden before it has drawn for the
10155 // new orientation.
10156 if (w.mOrientationChanging) {
10157 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010158 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010159 "Orientation change skips hidden " + w);
10160 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010161 } else if (w.mLastLayer != w.mAnimLayer
10162 || w.mLastAlpha != w.mShownAlpha
10163 || w.mLastDsDx != w.mDsDx
10164 || w.mLastDtDx != w.mDtDx
10165 || w.mLastDsDy != w.mDsDy
10166 || w.mLastDtDy != w.mDtDy
10167 || w.mLastHScale != w.mHScale
10168 || w.mLastVScale != w.mVScale
10169 || w.mLastHidden) {
10170 displayed = true;
10171 w.mLastAlpha = w.mShownAlpha;
10172 w.mLastLayer = w.mAnimLayer;
10173 w.mLastDsDx = w.mDsDx;
10174 w.mLastDtDx = w.mDtDx;
10175 w.mLastDsDy = w.mDsDy;
10176 w.mLastDtDy = w.mDtDy;
10177 w.mLastHScale = w.mHScale;
10178 w.mLastVScale = w.mVScale;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010179 if (SHOW_TRANSACTIONS) Slog.i(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010180 TAG, " SURFACE " + w.mSurface + ": alpha="
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010181 + w.mShownAlpha + " layer=" + w.mAnimLayer
10182 + " matrix=[" + (w.mDsDx*w.mHScale)
10183 + "," + (w.mDtDx*w.mVScale)
10184 + "][" + (w.mDsDy*w.mHScale)
10185 + "," + (w.mDtDy*w.mVScale) + "]");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010186 if (w.mSurface != null) {
10187 try {
10188 w.mSurface.setAlpha(w.mShownAlpha);
10189 w.mSurface.setLayer(w.mAnimLayer);
10190 w.mSurface.setMatrix(
10191 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10192 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10193 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010194 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010195 if (!recoveringMemory) {
10196 reclaimSomeSurfaceMemoryLocked(w, "update");
10197 }
10198 }
10199 }
10200
10201 if (w.mLastHidden && !w.mDrawPending
10202 && !w.mCommitDrawPending
10203 && !w.mReadyToShow) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010204 if (SHOW_TRANSACTIONS) Slog.i(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010205 TAG, " SURFACE " + w.mSurface + ": SHOW (performLayout)");
Joe Onorato8a9b2202010-02-26 18:56:32 -080010206 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010207 + " during relayout");
10208 if (showSurfaceRobustlyLocked(w)) {
10209 w.mHasDrawn = true;
10210 w.mLastHidden = false;
10211 } else {
10212 w.mOrientationChanging = false;
10213 }
10214 }
10215 if (w.mSurface != null) {
10216 w.mToken.hasVisible = true;
10217 }
10218 } else {
10219 displayed = true;
10220 }
10221
10222 if (displayed) {
10223 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010224 if (attrs.width == LayoutParams.MATCH_PARENT
10225 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010226 covered = true;
10227 }
10228 }
10229 if (w.mOrientationChanging) {
10230 if (w.mDrawPending || w.mCommitDrawPending) {
10231 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010232 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010233 "Orientation continue waiting for draw in " + w);
10234 } else {
10235 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010236 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010237 "Orientation change complete in " + w);
10238 }
10239 }
10240 w.mToken.hasVisible = true;
10241 }
10242 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010243 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010244 "Orientation change skips hidden " + w);
10245 w.mOrientationChanging = false;
10246 }
10247
10248 final boolean canBeSeen = w.isDisplayedLw();
10249
10250 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10251 focusDisplayed = true;
10252 }
10253
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010254 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010256 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010257 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010258 if (w.mSurface != null) {
10259 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10260 holdScreen = w.mSession;
10261 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010262 if (!syswin && w.mAttrs.screenBrightness >= 0
10263 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010264 screenBrightness = w.mAttrs.screenBrightness;
10265 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010266 if (!syswin && w.mAttrs.buttonBrightness >= 0
10267 && buttonBrightness < 0) {
10268 buttonBrightness = w.mAttrs.buttonBrightness;
10269 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010270 if (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10271 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10272 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR) {
10273 syswin = true;
10274 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010275 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010276
Dianne Hackborn25994b42009-09-04 14:21:19 -070010277 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10278 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010279 // This window completely covers everything behind it,
10280 // so we want to leave all of them as unblurred (for
10281 // performance reasons).
10282 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010283 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010284 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010285 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010286 obscured = true;
10287 if (mBackgroundFillerSurface == null) {
10288 try {
10289 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010290 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010291 0, dw, dh,
10292 PixelFormat.OPAQUE,
10293 Surface.FX_SURFACE_NORMAL);
10294 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010295 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010296 }
10297 }
10298 try {
10299 mBackgroundFillerSurface.setPosition(0, 0);
10300 mBackgroundFillerSurface.setSize(dw, dh);
10301 // Using the same layer as Dim because they will never be shown at the
10302 // same time.
10303 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10304 mBackgroundFillerSurface.show();
10305 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010306 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010307 }
10308 backgroundFillerShown = true;
10309 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010310 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010311 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010312 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010313 + ": blurring=" + blurring
10314 + " obscured=" + obscured
10315 + " displayed=" + displayed);
10316 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10317 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010318 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010319 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010320 if (mDimAnimator == null) {
10321 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010322 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010323 mDimAnimator.show(dw, dh);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010324 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010325 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010326 }
10327 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10328 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010329 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010330 blurring = true;
10331 mBlurShown = true;
10332 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010333 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010334 + mBlurSurface + ": CREATE");
10335 try {
Romain Guy06882f82009-06-10 13:36:04 -070010336 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010337 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010338 -1, 16, 16,
10339 PixelFormat.OPAQUE,
10340 Surface.FX_SURFACE_BLUR);
10341 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010342 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010343 }
10344 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010345 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010346 + mBlurSurface + ": SHOW pos=(0,0) (" +
10347 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
10348 if (mBlurSurface != null) {
10349 mBlurSurface.setPosition(0, 0);
10350 mBlurSurface.setSize(dw, dh);
10351 try {
10352 mBlurSurface.show();
10353 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010354 Slog.w(TAG, "Failure showing blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010355 }
10356 }
10357 }
10358 mBlurSurface.setLayer(w.mAnimLayer-2);
10359 }
10360 }
10361 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010362
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010363 if (obscuredChanged && mWallpaperTarget == w) {
10364 // This is the wallpaper target and its obscured state
10365 // changed... make sure the current wallaper's visibility
10366 // has been updated accordingly.
10367 updateWallpaperVisibilityLocked();
10368 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010369 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010370
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010371 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10372 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010373 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010374 try {
10375 mBackgroundFillerSurface.hide();
10376 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010377 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010378 }
10379 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010380
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010381 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010382 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10383 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010384 }
Romain Guy06882f82009-06-10 13:36:04 -070010385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010386 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010387 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010388 + ": HIDE");
10389 try {
10390 mBlurSurface.hide();
10391 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010392 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010393 }
10394 mBlurShown = false;
10395 }
10396
Joe Onorato8a9b2202010-02-26 18:56:32 -080010397 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010398 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010399 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010400 }
10401
10402 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010403
Joe Onorato8a9b2202010-02-26 18:56:32 -080010404 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010405 "With display frozen, orientationChangeComplete="
10406 + orientationChangeComplete);
10407 if (orientationChangeComplete) {
10408 if (mWindowsFreezingScreen) {
10409 mWindowsFreezingScreen = false;
10410 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10411 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010412 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010413 }
Romain Guy06882f82009-06-10 13:36:04 -070010414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010415 i = mResizingWindows.size();
10416 if (i > 0) {
10417 do {
10418 i--;
10419 WindowState win = mResizingWindows.get(i);
10420 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010421 if (DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010422 + win + ": " + win.mFrame);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010423 boolean configChanged =
10424 win.mConfiguration != mCurConfiguration
10425 && (win.mConfiguration == null
10426 || mCurConfiguration.diff(win.mConfiguration) != 0);
10427 win.mConfiguration = mCurConfiguration;
10428 if (DEBUG_ORIENTATION && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010429 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010430 + win.mFrame.width() + "x" + win.mFrame.height()
10431 + " / " + win.mConfiguration);
10432 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010433 win.mClient.resized(win.mFrame.width(),
10434 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010435 win.mLastVisibleInsets, win.mDrawPending,
10436 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010437 win.mContentInsetsChanged = false;
10438 win.mVisibleInsetsChanged = false;
10439 } catch (RemoteException e) {
10440 win.mOrientationChanging = false;
10441 }
10442 } while (i > 0);
10443 mResizingWindows.clear();
10444 }
Romain Guy06882f82009-06-10 13:36:04 -070010445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010446 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010447 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010448 i = mDestroySurface.size();
10449 if (i > 0) {
10450 do {
10451 i--;
10452 WindowState win = mDestroySurface.get(i);
10453 win.mDestroying = false;
10454 if (mInputMethodWindow == win) {
10455 mInputMethodWindow = null;
10456 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010457 if (win == mWallpaperTarget) {
10458 wallpaperDestroyed = true;
10459 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010460 win.destroySurfaceLocked();
10461 } while (i > 0);
10462 mDestroySurface.clear();
10463 }
10464
10465 // Time to remove any exiting tokens?
10466 for (i=mExitingTokens.size()-1; i>=0; i--) {
10467 WindowToken token = mExitingTokens.get(i);
10468 if (!token.hasVisible) {
10469 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010470 if (token.windowType == TYPE_WALLPAPER) {
10471 mWallpaperTokens.remove(token);
10472 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010473 }
10474 }
10475
10476 // Time to remove any exiting applications?
10477 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10478 AppWindowToken token = mExitingAppTokens.get(i);
10479 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010480 // Make sure there is no animation running on this token,
10481 // so any windows associated with it will be removed as
10482 // soon as their animations are complete
10483 token.animation = null;
10484 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010485 mAppTokens.remove(token);
10486 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010487 if (mLastEnterAnimToken == token) {
10488 mLastEnterAnimToken = null;
10489 mLastEnterAnimParams = null;
10490 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010491 }
10492 }
10493
Dianne Hackborna8f60182009-09-01 19:01:50 -070010494 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010495
Dianne Hackborna8f60182009-09-01 19:01:50 -070010496 if (!animating && mAppTransitionRunning) {
10497 // We have finished the animation of an app transition. To do
10498 // this, we have delayed a lot of operations like showing and
10499 // hiding apps, moving apps in Z-order, etc. The app token list
10500 // reflects the correct Z-order, but the window list may now
10501 // be out of sync with it. So here we will just rebuild the
10502 // entire app window list. Fun!
10503 mAppTransitionRunning = false;
10504 needRelayout = true;
10505 rebuildAppWindowListLocked();
10506 // Clear information about apps that were moving.
10507 mToBottomApps.clear();
10508 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010510 if (focusDisplayed) {
10511 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10512 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010513 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010514 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010515 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010516 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010517 requestAnimationLocked(0);
10518 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010519 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10520 }
10521 mQueue.setHoldScreenLocked(holdScreen != null);
10522 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10523 mPowerManager.setScreenBrightnessOverride(-1);
10524 } else {
10525 mPowerManager.setScreenBrightnessOverride((int)
10526 (screenBrightness * Power.BRIGHTNESS_ON));
10527 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010528 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10529 mPowerManager.setButtonBrightnessOverride(-1);
10530 } else {
10531 mPowerManager.setButtonBrightnessOverride((int)
10532 (buttonBrightness * Power.BRIGHTNESS_ON));
10533 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010534 if (holdScreen != mHoldingScreenOn) {
10535 mHoldingScreenOn = holdScreen;
10536 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10537 mH.sendMessage(m);
10538 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010539
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010540 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010541 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010542 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10543 LocalPowerManager.BUTTON_EVENT, true);
10544 mTurnOnScreen = false;
10545 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010546
10547 // Check to see if we are now in a state where the screen should
10548 // be enabled, because the window obscured flags have changed.
10549 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010550 }
10551
10552 void requestAnimationLocked(long delay) {
10553 if (!mAnimationPending) {
10554 mAnimationPending = true;
10555 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10556 }
10557 }
Romain Guy06882f82009-06-10 13:36:04 -070010558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010559 /**
10560 * Have the surface flinger show a surface, robustly dealing with
10561 * error conditions. In particular, if there is not enough memory
10562 * to show the surface, then we will try to get rid of other surfaces
10563 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010564 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010565 * @return Returns true if the surface was successfully shown.
10566 */
10567 boolean showSurfaceRobustlyLocked(WindowState win) {
10568 try {
10569 if (win.mSurface != null) {
10570 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010571 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010572 if (DEBUG_VISIBILITY) Slog.v(TAG,
10573 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010574 win.mTurnOnScreen = false;
10575 mTurnOnScreen = true;
10576 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010577 }
10578 return true;
10579 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010580 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010581 }
Romain Guy06882f82009-06-10 13:36:04 -070010582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010583 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010585 return false;
10586 }
Romain Guy06882f82009-06-10 13:36:04 -070010587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010588 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10589 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010590
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010591 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010592 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010594 if (mForceRemoves == null) {
10595 mForceRemoves = new ArrayList<WindowState>();
10596 }
Romain Guy06882f82009-06-10 13:36:04 -070010597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010598 long callingIdentity = Binder.clearCallingIdentity();
10599 try {
10600 // There was some problem... first, do a sanity check of the
10601 // window list to make sure we haven't left any dangling surfaces
10602 // around.
10603 int N = mWindows.size();
10604 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010605 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010606 for (int i=0; i<N; i++) {
10607 WindowState ws = (WindowState)mWindows.get(i);
10608 if (ws.mSurface != null) {
10609 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010610 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010611 + ws + " surface=" + ws.mSurface
10612 + " token=" + win.mToken
10613 + " pid=" + ws.mSession.mPid
10614 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010615 ws.mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010616 ws.mSurface = null;
10617 mForceRemoves.add(ws);
10618 i--;
10619 N--;
10620 leakedSurface = true;
10621 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010622 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010623 + ws + " surface=" + ws.mSurface
10624 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010625 ws.mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010626 ws.mSurface = null;
10627 leakedSurface = true;
10628 }
10629 }
10630 }
Romain Guy06882f82009-06-10 13:36:04 -070010631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010632 boolean killedApps = false;
10633 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010634 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010635 SparseIntArray pidCandidates = new SparseIntArray();
10636 for (int i=0; i<N; i++) {
10637 WindowState ws = (WindowState)mWindows.get(i);
10638 if (ws.mSurface != null) {
10639 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10640 }
10641 }
10642 if (pidCandidates.size() > 0) {
10643 int[] pids = new int[pidCandidates.size()];
10644 for (int i=0; i<pids.length; i++) {
10645 pids[i] = pidCandidates.keyAt(i);
10646 }
10647 try {
10648 if (mActivityManager.killPidsForMemory(pids)) {
10649 killedApps = true;
10650 }
10651 } catch (RemoteException e) {
10652 }
10653 }
10654 }
Romain Guy06882f82009-06-10 13:36:04 -070010655
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010656 if (leakedSurface || killedApps) {
10657 // We managed to reclaim some memory, so get rid of the trouble
10658 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010659 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010660 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010661 surface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010662 win.mSurface = null;
10663 }
Romain Guy06882f82009-06-10 13:36:04 -070010664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010665 try {
10666 win.mClient.dispatchGetNewSurface();
10667 } catch (RemoteException e) {
10668 }
10669 }
10670 } finally {
10671 Binder.restoreCallingIdentity(callingIdentity);
10672 }
10673 }
Romain Guy06882f82009-06-10 13:36:04 -070010674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010675 private boolean updateFocusedWindowLocked(int mode) {
10676 WindowState newFocus = computeFocusedWindowLocked();
10677 if (mCurrentFocus != newFocus) {
10678 // This check makes sure that we don't already have the focus
10679 // change message pending.
10680 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10681 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010682 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010683 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10684 final WindowState oldFocus = mCurrentFocus;
10685 mCurrentFocus = newFocus;
10686 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010688 final WindowState imWindow = mInputMethodWindow;
10689 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010690 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010691 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010692 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10693 mLayoutNeeded = true;
10694 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010695 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10696 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010697 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10698 // Client will do the layout, but we need to assign layers
10699 // for handleNewWindowLocked() below.
10700 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010701 }
10702 }
Romain Guy06882f82009-06-10 13:36:04 -070010703
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010704 if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10705 mKeyWaiter.handleNewWindowLocked(newFocus);
10706 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010707 return true;
10708 }
10709 return false;
10710 }
10711
10712 private WindowState computeFocusedWindowLocked() {
10713 WindowState result = null;
10714 WindowState win;
10715
10716 int i = mWindows.size() - 1;
10717 int nextAppIndex = mAppTokens.size()-1;
10718 WindowToken nextApp = nextAppIndex >= 0
10719 ? mAppTokens.get(nextAppIndex) : null;
10720
10721 while (i >= 0) {
10722 win = (WindowState)mWindows.get(i);
10723
Joe Onorato8a9b2202010-02-26 18:56:32 -080010724 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010725 TAG, "Looking for focus: " + i
10726 + " = " + win
10727 + ", flags=" + win.mAttrs.flags
10728 + ", canReceive=" + win.canReceiveKeys());
10729
10730 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010732 // If this window's application has been removed, just skip it.
10733 if (thisApp != null && thisApp.removed) {
10734 i--;
10735 continue;
10736 }
Romain Guy06882f82009-06-10 13:36:04 -070010737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010738 // If there is a focused app, don't allow focus to go to any
10739 // windows below it. If this is an application window, step
10740 // through the app tokens until we find its app.
10741 if (thisApp != null && nextApp != null && thisApp != nextApp
10742 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10743 int origAppIndex = nextAppIndex;
10744 while (nextAppIndex > 0) {
10745 if (nextApp == mFocusedApp) {
10746 // Whoops, we are below the focused app... no focus
10747 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010748 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010749 TAG, "Reached focused app: " + mFocusedApp);
10750 return null;
10751 }
10752 nextAppIndex--;
10753 nextApp = mAppTokens.get(nextAppIndex);
10754 if (nextApp == thisApp) {
10755 break;
10756 }
10757 }
10758 if (thisApp != nextApp) {
10759 // Uh oh, the app token doesn't exist! This shouldn't
10760 // happen, but if it does we can get totally hosed...
10761 // so restart at the original app.
10762 nextAppIndex = origAppIndex;
10763 nextApp = mAppTokens.get(nextAppIndex);
10764 }
10765 }
10766
10767 // Dispatch to this window if it is wants key events.
10768 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010769 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010770 TAG, "Found focus @ " + i + " = " + win);
10771 result = win;
10772 break;
10773 }
10774
10775 i--;
10776 }
10777
10778 return result;
10779 }
10780
10781 private void startFreezingDisplayLocked() {
10782 if (mDisplayFrozen) {
Chris Tate2ad63a92009-03-25 17:36:48 -070010783 // Freezing the display also suspends key event delivery, to
10784 // keep events from going astray while the display is reconfigured.
10785 // If someone has changed orientation again while the screen is
10786 // still frozen, the events will continue to be blocked while the
10787 // successive orientation change is processed. To prevent spurious
10788 // ANRs, we reset the event dispatch timeout in this case.
10789 synchronized (mKeyWaiter) {
10790 mKeyWaiter.mWasFrozen = true;
10791 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010792 return;
10793 }
Romain Guy06882f82009-06-10 13:36:04 -070010794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010795 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010797 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010798 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010799 if (mFreezeGcPending != 0) {
10800 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010801 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010802 mH.removeMessages(H.FORCE_GC);
10803 Runtime.getRuntime().gc();
10804 mFreezeGcPending = now;
10805 }
10806 } else {
10807 mFreezeGcPending = now;
10808 }
Romain Guy06882f82009-06-10 13:36:04 -070010809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010810 mDisplayFrozen = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010811 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10812 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010813 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010814 mAppTransitionReady = true;
10815 }
Romain Guy06882f82009-06-10 13:36:04 -070010816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010817 if (PROFILE_ORIENTATION) {
10818 File file = new File("/data/system/frozen");
10819 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10820 }
10821 Surface.freezeDisplay(0);
10822 }
Romain Guy06882f82009-06-10 13:36:04 -070010823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010824 private void stopFreezingDisplayLocked() {
10825 if (!mDisplayFrozen) {
10826 return;
10827 }
Romain Guy06882f82009-06-10 13:36:04 -070010828
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010829 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10830 return;
10831 }
10832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010833 mDisplayFrozen = false;
10834 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10835 if (PROFILE_ORIENTATION) {
10836 Debug.stopMethodTracing();
10837 }
10838 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010839
Chris Tate2ad63a92009-03-25 17:36:48 -070010840 // Reset the key delivery timeout on unfreeze, too. We force a wakeup here
10841 // too because regular key delivery processing should resume immediately.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010842 synchronized (mKeyWaiter) {
10843 mKeyWaiter.mWasFrozen = true;
10844 mKeyWaiter.notifyAll();
10845 }
10846
10847 // A little kludge: a lot could have happened while the
10848 // display was frozen, so now that we are coming back we
10849 // do a gc so that any remote references the system
10850 // processes holds on others can be released if they are
10851 // no longer needed.
10852 mH.removeMessages(H.FORCE_GC);
10853 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10854 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010856 mScreenFrozenLock.release();
10857 }
Romain Guy06882f82009-06-10 13:36:04 -070010858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010859 @Override
10860 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10861 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10862 != PackageManager.PERMISSION_GRANTED) {
10863 pw.println("Permission Denial: can't dump WindowManager from from pid="
10864 + Binder.getCallingPid()
10865 + ", uid=" + Binder.getCallingUid());
10866 return;
10867 }
Romain Guy06882f82009-06-10 13:36:04 -070010868
Dianne Hackborna2e92262010-03-02 17:19:29 -080010869 pw.println("Input State:");
10870 mQueue.dump(pw, " ");
10871 pw.println(" ");
10872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010873 synchronized(mWindowMap) {
10874 pw.println("Current Window Manager state:");
10875 for (int i=mWindows.size()-1; i>=0; i--) {
10876 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010877 pw.print(" Window #"); pw.print(i); pw.print(' ');
10878 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010879 w.dump(pw, " ");
10880 }
10881 if (mInputMethodDialogs.size() > 0) {
10882 pw.println(" ");
10883 pw.println(" Input method dialogs:");
10884 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10885 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010886 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010887 }
10888 }
10889 if (mPendingRemove.size() > 0) {
10890 pw.println(" ");
10891 pw.println(" Remove pending for:");
10892 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10893 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010894 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10895 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010896 w.dump(pw, " ");
10897 }
10898 }
10899 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10900 pw.println(" ");
10901 pw.println(" Windows force removing:");
10902 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10903 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010904 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10905 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010906 w.dump(pw, " ");
10907 }
10908 }
10909 if (mDestroySurface.size() > 0) {
10910 pw.println(" ");
10911 pw.println(" Windows waiting to destroy their surface:");
10912 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10913 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010914 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10915 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010916 w.dump(pw, " ");
10917 }
10918 }
10919 if (mLosingFocus.size() > 0) {
10920 pw.println(" ");
10921 pw.println(" Windows losing focus:");
10922 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10923 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010924 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10925 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010926 w.dump(pw, " ");
10927 }
10928 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010929 if (mResizingWindows.size() > 0) {
10930 pw.println(" ");
10931 pw.println(" Windows waiting to resize:");
10932 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10933 WindowState w = mResizingWindows.get(i);
10934 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10935 pw.print(w); pw.println(":");
10936 w.dump(pw, " ");
10937 }
10938 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010939 if (mSessions.size() > 0) {
10940 pw.println(" ");
10941 pw.println(" All active sessions:");
10942 Iterator<Session> it = mSessions.iterator();
10943 while (it.hasNext()) {
10944 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010945 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010946 s.dump(pw, " ");
10947 }
10948 }
10949 if (mTokenMap.size() > 0) {
10950 pw.println(" ");
10951 pw.println(" All tokens:");
10952 Iterator<WindowToken> it = mTokenMap.values().iterator();
10953 while (it.hasNext()) {
10954 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010955 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010956 token.dump(pw, " ");
10957 }
10958 }
10959 if (mTokenList.size() > 0) {
10960 pw.println(" ");
10961 pw.println(" Window token list:");
10962 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010963 pw.print(" #"); pw.print(i); pw.print(": ");
10964 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010965 }
10966 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010967 if (mWallpaperTokens.size() > 0) {
10968 pw.println(" ");
10969 pw.println(" Wallpaper tokens:");
10970 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10971 WindowToken token = mWallpaperTokens.get(i);
10972 pw.print(" Wallpaper #"); pw.print(i);
10973 pw.print(' '); pw.print(token); pw.println(':');
10974 token.dump(pw, " ");
10975 }
10976 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010977 if (mAppTokens.size() > 0) {
10978 pw.println(" ");
10979 pw.println(" Application tokens in Z order:");
10980 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010981 pw.print(" App #"); pw.print(i); pw.print(": ");
10982 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010983 }
10984 }
10985 if (mFinishedStarting.size() > 0) {
10986 pw.println(" ");
10987 pw.println(" Finishing start of application tokens:");
10988 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10989 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010990 pw.print(" Finished Starting #"); pw.print(i);
10991 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010992 token.dump(pw, " ");
10993 }
10994 }
10995 if (mExitingTokens.size() > 0) {
10996 pw.println(" ");
10997 pw.println(" Exiting tokens:");
10998 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10999 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011000 pw.print(" Exiting #"); pw.print(i);
11001 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011002 token.dump(pw, " ");
11003 }
11004 }
11005 if (mExitingAppTokens.size() > 0) {
11006 pw.println(" ");
11007 pw.println(" Exiting application tokens:");
11008 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11009 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011010 pw.print(" Exiting App #"); pw.print(i);
11011 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011012 token.dump(pw, " ");
11013 }
11014 }
11015 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011016 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11017 pw.print(" mLastFocus="); pw.println(mLastFocus);
11018 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11019 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11020 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011021 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011022 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11023 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11024 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11025 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011026 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11027 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11028 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011029 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11030 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11031 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11032 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011033 if (mDimAnimator != null) {
11034 mDimAnimator.printTo(pw);
11035 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011036 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011037 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011038 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011039 pw.print(mInputMethodAnimLayerAdjustment);
11040 pw.print(" mWallpaperAnimLayerAdjustment=");
11041 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011042 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11043 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011044 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11045 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011046 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11047 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011048 pw.print(" mRotation="); pw.print(mRotation);
11049 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11050 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11051 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11052 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11053 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11054 pw.print(" mNextAppTransition=0x");
11055 pw.print(Integer.toHexString(mNextAppTransition));
11056 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011057 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011058 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011059 if (mNextAppTransitionPackage != null) {
11060 pw.print(" mNextAppTransitionPackage=");
11061 pw.print(mNextAppTransitionPackage);
11062 pw.print(", mNextAppTransitionEnter=0x");
11063 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11064 pw.print(", mNextAppTransitionExit=0x");
11065 pw.print(Integer.toHexString(mNextAppTransitionExit));
11066 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011067 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11068 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011069 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11070 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11071 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11072 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011073 if (mOpeningApps.size() > 0) {
11074 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11075 }
11076 if (mClosingApps.size() > 0) {
11077 pw.print(" mClosingApps="); pw.println(mClosingApps);
11078 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011079 if (mToTopApps.size() > 0) {
11080 pw.print(" mToTopApps="); pw.println(mToTopApps);
11081 }
11082 if (mToBottomApps.size() > 0) {
11083 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11084 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011085 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11086 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011087 pw.println(" KeyWaiter state:");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011088 pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin);
11089 pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder);
11090 pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished);
11091 pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow);
11092 pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching);
11093 pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011094 }
11095 }
11096
11097 public void monitor() {
11098 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011099 synchronized (mKeyguardTokenWatcher) { }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011100 synchronized (mKeyWaiter) { }
11101 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011102
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011103 public void virtualKeyFeedback(KeyEvent event) {
11104 mPolicy.keyFeedbackFromInput(event);
11105 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011106
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011107 /**
11108 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011109 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011110 */
11111 private static class DimAnimator {
11112 Surface mDimSurface;
11113 boolean mDimShown = false;
11114 float mDimCurrentAlpha;
11115 float mDimTargetAlpha;
11116 float mDimDeltaPerMs;
11117 long mLastDimAnimTime;
11118
11119 DimAnimator (SurfaceSession session) {
11120 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011121 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011122 + mDimSurface + ": CREATE");
11123 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011124 mDimSurface = new Surface(session, 0,
11125 "DimSurface",
11126 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011127 Surface.FX_SURFACE_DIM);
11128 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011129 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011130 }
11131 }
11132 }
11133
11134 /**
11135 * Show the dim surface.
11136 */
11137 void show(int dw, int dh) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011138 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011139 dw + "x" + dh + ")");
11140 mDimShown = true;
11141 try {
11142 mDimSurface.setPosition(0, 0);
11143 mDimSurface.setSize(dw, dh);
11144 mDimSurface.show();
11145 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011146 Slog.w(TAG, "Failure showing dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011147 }
11148 }
11149
11150 /**
11151 * Set's the dim surface's layer and update dim parameters that will be used in
11152 * {@link updateSurface} after all windows are examined.
11153 */
11154 void updateParameters(WindowState w, long currentTime) {
11155 mDimSurface.setLayer(w.mAnimLayer-1);
11156
11157 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011158 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011159 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011160 if (mDimTargetAlpha != target) {
11161 // If the desired dim level has changed, then
11162 // start an animation to it.
11163 mLastDimAnimTime = currentTime;
11164 long duration = (w.mAnimating && w.mAnimation != null)
11165 ? w.mAnimation.computeDurationHint()
11166 : DEFAULT_DIM_DURATION;
11167 if (target > mDimTargetAlpha) {
11168 // This is happening behind the activity UI,
11169 // so we can make it run a little longer to
11170 // give a stronger impression without disrupting
11171 // the user.
11172 duration *= DIM_DURATION_MULTIPLIER;
11173 }
11174 if (duration < 1) {
11175 // Don't divide by zero
11176 duration = 1;
11177 }
11178 mDimTargetAlpha = target;
11179 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11180 }
11181 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011182
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011183 /**
11184 * Updating the surface's alpha. Returns true if the animation continues, or returns
11185 * false when the animation is finished and the dim surface is hidden.
11186 */
11187 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11188 if (!dimming) {
11189 if (mDimTargetAlpha != 0) {
11190 mLastDimAnimTime = currentTime;
11191 mDimTargetAlpha = 0;
11192 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11193 }
11194 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011195
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011196 boolean animating = false;
11197 if (mLastDimAnimTime != 0) {
11198 mDimCurrentAlpha += mDimDeltaPerMs
11199 * (currentTime-mLastDimAnimTime);
11200 boolean more = true;
11201 if (displayFrozen) {
11202 // If the display is frozen, there is no reason to animate.
11203 more = false;
11204 } else if (mDimDeltaPerMs > 0) {
11205 if (mDimCurrentAlpha > mDimTargetAlpha) {
11206 more = false;
11207 }
11208 } else if (mDimDeltaPerMs < 0) {
11209 if (mDimCurrentAlpha < mDimTargetAlpha) {
11210 more = false;
11211 }
11212 } else {
11213 more = false;
11214 }
11215
11216 // Do we need to continue animating?
11217 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011218 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011219 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11220 mLastDimAnimTime = currentTime;
11221 mDimSurface.setAlpha(mDimCurrentAlpha);
11222 animating = true;
11223 } else {
11224 mDimCurrentAlpha = mDimTargetAlpha;
11225 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011226 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011227 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11228 mDimSurface.setAlpha(mDimCurrentAlpha);
11229 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011230 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011231 + ": HIDE");
11232 try {
11233 mDimSurface.hide();
11234 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011235 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011236 }
11237 mDimShown = false;
11238 }
11239 }
11240 }
11241 return animating;
11242 }
11243
11244 public void printTo(PrintWriter pw) {
11245 pw.print(" mDimShown="); pw.print(mDimShown);
11246 pw.print(" current="); pw.print(mDimCurrentAlpha);
11247 pw.print(" target="); pw.print(mDimTargetAlpha);
11248 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11249 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11250 }
11251 }
11252
11253 /**
11254 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11255 * This is used for opening/closing transition for apps in compatible mode.
11256 */
11257 private static class FadeInOutAnimation extends Animation {
11258 int mWidth;
11259 boolean mFadeIn;
11260
11261 public FadeInOutAnimation(boolean fadeIn) {
11262 setInterpolator(new AccelerateInterpolator());
11263 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11264 mFadeIn = fadeIn;
11265 }
11266
11267 @Override
11268 protected void applyTransformation(float interpolatedTime, Transformation t) {
11269 float x = interpolatedTime;
11270 if (!mFadeIn) {
11271 x = 1.0f - x; // reverse the interpolation for fade out
11272 }
11273 if (x < 0.5) {
11274 // move the window out of the screen.
11275 t.getMatrix().setTranslate(mWidth, 0);
11276 } else {
11277 t.getMatrix().setTranslate(0, 0);// show
11278 t.setAlpha((x - 0.5f) * 2);
11279 }
11280 }
11281
11282 @Override
11283 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11284 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11285 mWidth = width;
11286 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011287
11288 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011289 public int getZAdjustment() {
11290 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011291 }
11292 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011293}