blob: 53de7d99e51771a56ea90c9cdd495edbeb9d4a08 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
19import static android.os.LocalPowerManager.CHEEK_EVENT;
20import static android.os.LocalPowerManager.OTHER_EVENT;
21import static android.os.LocalPowerManager.TOUCH_EVENT;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -070022import static android.os.LocalPowerManager.LONG_TOUCH_EVENT;
23import static android.os.LocalPowerManager.TOUCH_UP_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
25import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
26import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070027import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
29import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070030import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
32import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
33import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070034import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
36import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
38import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
39import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
40import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
41import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070042import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
44import com.android.internal.app.IBatteryStats;
45import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080046import com.android.internal.policy.impl.PhoneWindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import com.android.internal.view.IInputContext;
48import com.android.internal.view.IInputMethodClient;
49import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080050import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import com.android.server.KeyInputQueue.QueuedEvent;
52import com.android.server.am.BatteryStatsService;
53
54import android.Manifest;
55import android.app.ActivityManagerNative;
56import android.app.IActivityManager;
57import android.content.Context;
58import android.content.pm.ActivityInfo;
59import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070060import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.content.res.Configuration;
62import android.graphics.Matrix;
63import android.graphics.PixelFormat;
64import android.graphics.Rect;
65import android.graphics.Region;
66import android.os.BatteryStats;
67import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070068import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069import android.os.Debug;
70import android.os.Handler;
71import android.os.IBinder;
Michael Chan53071d62009-05-13 17:29:48 -070072import android.os.LatencyTimer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073import android.os.LocalPowerManager;
74import android.os.Looper;
75import android.os.Message;
76import android.os.Parcel;
77import android.os.ParcelFileDescriptor;
78import android.os.Power;
79import android.os.PowerManager;
80import android.os.Process;
81import android.os.RemoteException;
82import android.os.ServiceManager;
83import android.os.SystemClock;
84import android.os.SystemProperties;
85import android.os.TokenWatcher;
86import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070087import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088import android.util.EventLog;
Joe Onorato8a9b2202010-02-26 18:56:32 -080089import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090import android.util.SparseIntArray;
91import android.view.Display;
92import android.view.Gravity;
93import android.view.IApplicationToken;
94import android.view.IOnKeyguardExitResult;
95import android.view.IRotationWatcher;
96import android.view.IWindow;
97import android.view.IWindowManager;
98import android.view.IWindowSession;
99import android.view.KeyEvent;
100import android.view.MotionEvent;
101import android.view.RawInputEvent;
102import android.view.Surface;
103import android.view.SurfaceSession;
104import android.view.View;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -0700105import android.view.ViewConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106import android.view.ViewTreeObserver;
107import android.view.WindowManager;
108import android.view.WindowManagerImpl;
109import android.view.WindowManagerPolicy;
110import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700111import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112import android.view.animation.Animation;
113import android.view.animation.AnimationUtils;
114import android.view.animation.Transformation;
115
116import java.io.BufferedWriter;
117import java.io.File;
118import java.io.FileDescriptor;
119import java.io.IOException;
120import java.io.OutputStream;
121import java.io.OutputStreamWriter;
122import java.io.PrintWriter;
123import java.io.StringWriter;
124import java.net.Socket;
125import java.util.ArrayList;
126import java.util.HashMap;
127import java.util.HashSet;
128import java.util.Iterator;
129import java.util.List;
130
131/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700132public class WindowManagerService extends IWindowManager.Stub
133 implements Watchdog.Monitor, KeyInputQueue.HapticFeedbackCallback {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 static final String TAG = "WindowManager";
135 static final boolean DEBUG = false;
136 static final boolean DEBUG_FOCUS = false;
137 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800138 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800139 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 static final boolean DEBUG_LAYERS = false;
141 static final boolean DEBUG_INPUT = false;
142 static final boolean DEBUG_INPUT_METHOD = false;
143 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700144 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700146 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 static final boolean DEBUG_APP_TRANSITIONS = false;
148 static final boolean DEBUG_STARTING_WINDOW = false;
149 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700150 static final boolean DEBUG_WALLPAPER = false;
Dianne Hackbornce73c1e2010-04-12 23:11:38 -0700151 static final boolean DEBUG_FREEZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700153 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700154 static final boolean MEASURE_LATENCY = false;
155 static private LatencyTimer lt;
156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 static final boolean PROFILE_ORIENTATION = false;
158 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700159 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 /** How long to wait for subsequent key repeats, in milliseconds */
162 static final int KEY_REPEAT_DELAY = 50;
163
164 /** How much to multiply the policy's type layer, to reserve room
165 * for multiple windows of the same type and Z-ordering adjustment
166 * with TYPE_LAYER_OFFSET. */
167 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
170 * or below others in the same layer. */
171 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 /** How much to increment the layer for each window, to reserve room
174 * for effect surfaces between them.
175 */
176 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 /** The maximum length we will accept for a loaded animation duration:
179 * this is 10 seconds.
180 */
181 static final int MAX_ANIMATION_DURATION = 10*1000;
182
183 /** Amount of time (in milliseconds) to animate the dim surface from one
184 * value to another, when no window animation is driving it.
185 */
186 static final int DEFAULT_DIM_DURATION = 200;
187
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700188 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
189 * compatible windows.
190 */
191 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 /** Adjustment to time to perform a dim, to make it more dramatic.
194 */
195 static final int DIM_DURATION_MULTIPLIER = 6;
Romain Guy06882f82009-06-10 13:36:04 -0700196
Dianne Hackborncfaef692009-06-15 14:24:44 -0700197 static final int INJECT_FAILED = 0;
198 static final int INJECT_SUCCEEDED = 1;
199 static final int INJECT_NO_PERMISSION = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201 static final int UPDATE_FOCUS_NORMAL = 0;
202 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
203 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
204 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700205
Michael Chane96440f2009-05-06 10:27:36 -0700206 /** The minimum time between dispatching touch events. */
207 int mMinWaitTimeBetweenTouchEvents = 1000 / 35;
208
209 // Last touch event time
210 long mLastTouchEventTime = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700211
Michael Chane96440f2009-05-06 10:27:36 -0700212 // Last touch event type
213 int mLastTouchEventType = OTHER_EVENT;
Romain Guy06882f82009-06-10 13:36:04 -0700214
Michael Chane96440f2009-05-06 10:27:36 -0700215 // Time to wait before calling useractivity again. This saves CPU usage
216 // when we get a flood of touch events.
217 static final int MIN_TIME_BETWEEN_USERACTIVITIES = 1000;
218
219 // Last time we call user activity
220 long mLastUserActivityCallTime = 0;
221
Romain Guy06882f82009-06-10 13:36:04 -0700222 // Last time we updated battery stats
Michael Chane96440f2009-05-06 10:27:36 -0700223 long mLastBatteryStatsCallTime = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700226 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227
228 /**
229 * Condition waited on by {@link #reenableKeyguard} to know the call to
230 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500231 * This is set to true only if mKeyguardTokenWatcher.acquired() has
232 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500234 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235
Mike Lockwood983ee092009-11-22 01:42:24 -0500236 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
237 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 public void acquired() {
239 mPolicy.enableKeyguard(false);
Mike Lockwood983ee092009-11-22 01:42:24 -0500240 mKeyguardDisabled = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 }
242 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700243 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500244 synchronized (mKeyguardTokenWatcher) {
245 mKeyguardDisabled = false;
246 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 }
248 }
249 };
250
251 final Context mContext;
252
253 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
258
259 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800263 /**
264 * All currently active sessions with clients.
265 */
266 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 /**
269 * Mapping from an IWindow IBinder to the server's Window object.
270 * This is also used as the lock for all of our state.
271 */
272 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
273
274 /**
275 * Mapping from a token IBinder to a WindowToken object.
276 */
277 final HashMap<IBinder, WindowToken> mTokenMap =
278 new HashMap<IBinder, WindowToken>();
279
280 /**
281 * The same tokens as mTokenMap, stored in a list for efficient iteration
282 * over them.
283 */
284 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 /**
287 * Window tokens that are in the process of exiting, but still
288 * on screen for animations.
289 */
290 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
291
292 /**
293 * Z-ordered (bottom-most first) list of all application tokens, for
294 * controlling the ordering of windows in different applications. This
295 * contains WindowToken objects.
296 */
297 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
298
299 /**
300 * Application tokens that are in the process of exiting, but still
301 * on screen for animations.
302 */
303 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
304
305 /**
306 * List of window tokens that have finished starting their application,
307 * and now need to have the policy remove their windows.
308 */
309 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
310
311 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700312 * This was the app token that was used to retrieve the last enter
313 * animation. It will be used for the next exit animation.
314 */
315 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800316
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700317 /**
318 * These were the layout params used to retrieve the last enter animation.
319 * They will be used for the next exit animation.
320 */
321 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800322
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700323 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800324 * Z-ordered (bottom-most first) list of all Window objects.
325 */
326 final ArrayList mWindows = new ArrayList();
327
328 /**
329 * Windows that are being resized. Used so we can tell the client about
330 * the resize after closing the transaction in which we resized the
331 * underlying surface.
332 */
333 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
334
335 /**
336 * Windows whose animations have ended and now must be removed.
337 */
338 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
339
340 /**
341 * Windows whose surface should be destroyed.
342 */
343 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
344
345 /**
346 * Windows that have lost input focus and are waiting for the new
347 * focus window to be displayed before they are told about this.
348 */
349 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
350
351 /**
352 * This is set when we have run out of memory, and will either be an empty
353 * list or contain windows that need to be force removed.
354 */
355 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700360 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 Surface mBlurSurface;
362 boolean mBlurShown;
Romain Guy06882f82009-06-10 13:36:04 -0700363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800364 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 final float[] mTmpFloats = new float[9];
367
368 boolean mSafeMode;
369 boolean mDisplayEnabled = false;
370 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700371 int mInitialDisplayWidth = 0;
372 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 int mRotation = 0;
374 int mRequestedRotation = 0;
375 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700376 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 ArrayList<IRotationWatcher> mRotationWatchers
378 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 boolean mLayoutNeeded = true;
381 boolean mAnimationPending = false;
382 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800383 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 boolean mWindowsFreezingScreen = false;
385 long mFreezeGcPending = 0;
386 int mAppsFreezingScreen = 0;
387
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800388 int mLayoutSeq = 0;
389
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800390 // State while inside of layoutAndPlaceSurfacesLocked().
391 boolean mFocusMayChange;
392
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800393 Configuration mCurConfiguration = new Configuration();
394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 // This is held as long as we have the screen frozen, to give us time to
396 // perform a rotation animation when turning off shows the lock screen which
397 // changes the orientation.
398 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 // State management of app transitions. When we are preparing for a
401 // transition, mNextAppTransition will be the kind of transition to
402 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
403 // mOpeningApps and mClosingApps are the lists of tokens that will be
404 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700405 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700406 String mNextAppTransitionPackage;
407 int mNextAppTransitionEnter;
408 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700410 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 boolean mAppTransitionTimeout = false;
412 boolean mStartingIconInTransition = false;
413 boolean mSkipAppTransitionAnimation = false;
414 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
415 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700416 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
417 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 //flag to detect fat touch events
420 boolean mFatTouch = false;
421 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 H mH = new H();
424
425 WindowState mCurrentFocus = null;
426 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 // This just indicates the window the input method is on top of, not
429 // necessarily the window its input is going to.
430 WindowState mInputMethodTarget = null;
431 WindowState mUpcomingInputMethodTarget = null;
432 boolean mInputMethodTargetWaitingAnim;
433 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 WindowState mInputMethodWindow = null;
436 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
437
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700438 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800439
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700440 // If non-null, this is the currently visible window that is associated
441 // with the wallpaper.
442 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700443 // If non-null, we are in the middle of animating from one wallpaper target
444 // to another, and this is the lower one in Z-order.
445 WindowState mLowerWallpaperTarget = null;
446 // If non-null, we are in the middle of animating from one wallpaper target
447 // to another, and this is the higher one in Z-order.
448 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700449 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700450 float mLastWallpaperX = -1;
451 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800452 float mLastWallpaperXStep = -1;
453 float mLastWallpaperYStep = -1;
Dianne Hackborn6adba242009-11-10 11:10:09 -0800454 boolean mSendingPointersToWallpaper = false;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700455 // This is set when we are waiting for a wallpaper to tell us it is done
456 // changing its scroll position.
457 WindowState mWaitingOnWallpaper;
458 // The last time we had a timeout when waiting for a wallpaper.
459 long mLastWallpaperTimeoutTime;
460 // We give a wallpaper up to 150ms to finish scrolling.
461 static final long WALLPAPER_TIMEOUT = 150;
462 // Time we wait after a timeout before trying to wait again.
463 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800465 AppWindowToken mFocusedApp = null;
466
467 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469 float mWindowAnimationScale = 1.0f;
470 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800472 final KeyWaiter mKeyWaiter = new KeyWaiter();
473 final KeyQ mQueue;
474 final InputDispatcherThread mInputThread;
475
476 // Who is holding the screen on.
477 Session mHoldingScreenOn;
Romain Guy06882f82009-06-10 13:36:04 -0700478
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700479 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481 /**
482 * Whether the UI is currently running in touch mode (not showing
483 * navigational focus because the user is directly pressing the screen).
484 */
485 boolean mInTouchMode = false;
486
487 private ViewServer mViewServer;
488
489 final Rect mTempRect = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -0700490
Dianne Hackbornc485a602009-03-24 22:39:49 -0700491 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700492 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700493
494 // The frame use to limit the size of the app running in compatibility mode.
495 Rect mCompatibleScreenFrame = new Rect();
496 // The surface used to fill the outer rim of the app running in compatibility mode.
497 Surface mBackgroundFillerSurface = null;
498 boolean mBackgroundFillerShown = false;
499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 public static WindowManagerService main(Context context,
501 PowerManagerService pm, boolean haveInputMethods) {
502 WMThread thr = new WMThread(context, pm, haveInputMethods);
503 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 synchronized (thr) {
506 while (thr.mService == null) {
507 try {
508 thr.wait();
509 } catch (InterruptedException e) {
510 }
511 }
512 }
Romain Guy06882f82009-06-10 13:36:04 -0700513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 return thr.mService;
515 }
Romain Guy06882f82009-06-10 13:36:04 -0700516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 static class WMThread extends Thread {
518 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 private final Context mContext;
521 private final PowerManagerService mPM;
522 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524 public WMThread(Context context, PowerManagerService pm,
525 boolean haveInputMethods) {
526 super("WindowManager");
527 mContext = context;
528 mPM = pm;
529 mHaveInputMethods = haveInputMethods;
530 }
Romain Guy06882f82009-06-10 13:36:04 -0700531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 public void run() {
533 Looper.prepare();
534 WindowManagerService s = new WindowManagerService(mContext, mPM,
535 mHaveInputMethods);
536 android.os.Process.setThreadPriority(
537 android.os.Process.THREAD_PRIORITY_DISPLAY);
Romain Guy06882f82009-06-10 13:36:04 -0700538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 synchronized (this) {
540 mService = s;
541 notifyAll();
542 }
Romain Guy06882f82009-06-10 13:36:04 -0700543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 Looper.loop();
545 }
546 }
547
548 static class PolicyThread extends Thread {
549 private final WindowManagerPolicy mPolicy;
550 private final WindowManagerService mService;
551 private final Context mContext;
552 private final PowerManagerService mPM;
553 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800555 public PolicyThread(WindowManagerPolicy policy,
556 WindowManagerService service, Context context,
557 PowerManagerService pm) {
558 super("WindowManagerPolicy");
559 mPolicy = policy;
560 mService = service;
561 mContext = context;
562 mPM = pm;
563 }
Romain Guy06882f82009-06-10 13:36:04 -0700564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 public void run() {
566 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800567 WindowManagerPolicyThread.set(this, Looper.myLooper());
568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800570 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 android.os.Process.setThreadPriority(
572 android.os.Process.THREAD_PRIORITY_FOREGROUND);
573 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 synchronized (this) {
576 mRunning = true;
577 notifyAll();
578 }
Romain Guy06882f82009-06-10 13:36:04 -0700579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580 Looper.loop();
581 }
582 }
583
584 private WindowManagerService(Context context, PowerManagerService pm,
585 boolean haveInputMethods) {
Michael Chan53071d62009-05-13 17:29:48 -0700586 if (MEASURE_LATENCY) {
587 lt = new LatencyTimer(100, 1000);
588 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 mContext = context;
591 mHaveInputMethods = haveInputMethods;
592 mLimitedAlphaCompositing = context.getResources().getBoolean(
593 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 mPowerManager = pm;
596 mPowerManager.setPolicy(mPolicy);
597 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
598 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
599 "SCREEN_FROZEN");
600 mScreenFrozenLock.setReferenceCounted(false);
601
602 mActivityManager = ActivityManagerNative.getDefault();
603 mBatteryStats = BatteryStatsService.getService();
604
605 // Get persisted window scale setting
606 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
607 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
608 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
609 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700610
Michael Chan9f028e62009-08-04 17:37:46 -0700611 int max_events_per_sec = 35;
612 try {
613 max_events_per_sec = Integer.parseInt(SystemProperties
614 .get("windowsmgr.max_events_per_sec"));
615 if (max_events_per_sec < 1) {
616 max_events_per_sec = 35;
617 }
618 } catch (NumberFormatException e) {
619 }
620 mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec;
621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 mQueue = new KeyQ();
623
624 mInputThread = new InputDispatcherThread();
Romain Guy06882f82009-06-10 13:36:04 -0700625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
627 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 synchronized (thr) {
630 while (!thr.mRunning) {
631 try {
632 thr.wait();
633 } catch (InterruptedException e) {
634 }
635 }
636 }
Romain Guy06882f82009-06-10 13:36:04 -0700637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 mInputThread.start();
Romain Guy06882f82009-06-10 13:36:04 -0700639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 // Add ourself to the Watchdog monitors.
641 Watchdog.getInstance().addMonitor(this);
642 }
643
644 @Override
645 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
646 throws RemoteException {
647 try {
648 return super.onTransact(code, data, reply, flags);
649 } catch (RuntimeException e) {
650 // The window manager only throws security exceptions, so let's
651 // log all others.
652 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800653 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654 }
655 throw e;
656 }
657 }
658
659 private void placeWindowAfter(Object pos, WindowState window) {
660 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800661 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 TAG, "Adding window " + window + " at "
663 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
664 mWindows.add(i+1, window);
665 }
666
667 private void placeWindowBefore(Object pos, WindowState window) {
668 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800669 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 TAG, "Adding window " + window + " at "
671 + i + " of " + mWindows.size() + " (before " + pos + ")");
672 mWindows.add(i, window);
673 }
674
675 //This method finds out the index of a window that has the same app token as
676 //win. used for z ordering the windows in mWindows
677 private int findIdxBasedOnAppTokens(WindowState win) {
678 //use a local variable to cache mWindows
679 ArrayList localmWindows = mWindows;
680 int jmax = localmWindows.size();
681 if(jmax == 0) {
682 return -1;
683 }
684 for(int j = (jmax-1); j >= 0; j--) {
685 WindowState wentry = (WindowState)localmWindows.get(j);
686 if(wentry.mAppToken == win.mAppToken) {
687 return j;
688 }
689 }
690 return -1;
691 }
Romain Guy06882f82009-06-10 13:36:04 -0700692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800693 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
694 final IWindow client = win.mClient;
695 final WindowToken token = win.mToken;
696 final ArrayList localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 final int N = localmWindows.size();
699 final WindowState attached = win.mAttachedWindow;
700 int i;
701 if (attached == null) {
702 int tokenWindowsPos = token.windows.size();
703 if (token.appWindowToken != null) {
704 int index = tokenWindowsPos-1;
705 if (index >= 0) {
706 // If this application has existing windows, we
707 // simply place the new window on top of them... but
708 // keep the starting window on top.
709 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
710 // Base windows go behind everything else.
711 placeWindowBefore(token.windows.get(0), win);
712 tokenWindowsPos = 0;
713 } else {
714 AppWindowToken atoken = win.mAppToken;
715 if (atoken != null &&
716 token.windows.get(index) == atoken.startingWindow) {
717 placeWindowBefore(token.windows.get(index), win);
718 tokenWindowsPos--;
719 } else {
720 int newIdx = findIdxBasedOnAppTokens(win);
721 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700722 //there is a window above this one associated with the same
723 //apptoken note that the window could be a floating window
724 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800726 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700727 TAG, "Adding window " + win + " at "
728 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800729 localmWindows.add(newIdx+1, win);
Romain Guy06882f82009-06-10 13:36:04 -0700730 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800731 }
732 }
733 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800734 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 TAG, "Figuring out where to add app window "
736 + client.asBinder() + " (token=" + token + ")");
737 // Figure out where the window should go, based on the
738 // order of applications.
739 final int NA = mAppTokens.size();
740 Object pos = null;
741 for (i=NA-1; i>=0; i--) {
742 AppWindowToken t = mAppTokens.get(i);
743 if (t == token) {
744 i--;
745 break;
746 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800747
Dianne Hackborna8f60182009-09-01 19:01:50 -0700748 // We haven't reached the token yet; if this token
749 // is not going to the bottom and has windows, we can
750 // use it as an anchor for when we do reach the token.
751 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800752 pos = t.windows.get(0);
753 }
754 }
755 // We now know the index into the apps. If we found
756 // an app window above, that gives us the position; else
757 // we need to look some more.
758 if (pos != null) {
759 // Move behind any windows attached to this one.
Romain Guy06882f82009-06-10 13:36:04 -0700760 WindowToken atoken =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 mTokenMap.get(((WindowState)pos).mClient.asBinder());
762 if (atoken != null) {
763 final int NC = atoken.windows.size();
764 if (NC > 0) {
765 WindowState bottom = atoken.windows.get(0);
766 if (bottom.mSubLayer < 0) {
767 pos = bottom;
768 }
769 }
770 }
771 placeWindowBefore(pos, win);
772 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700773 // Continue looking down until we find the first
774 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 while (i >= 0) {
776 AppWindowToken t = mAppTokens.get(i);
777 final int NW = t.windows.size();
778 if (NW > 0) {
779 pos = t.windows.get(NW-1);
780 break;
781 }
782 i--;
783 }
784 if (pos != null) {
785 // Move in front of any windows attached to this
786 // one.
787 WindowToken atoken =
788 mTokenMap.get(((WindowState)pos).mClient.asBinder());
789 if (atoken != null) {
790 final int NC = atoken.windows.size();
791 if (NC > 0) {
792 WindowState top = atoken.windows.get(NC-1);
793 if (top.mSubLayer >= 0) {
794 pos = top;
795 }
796 }
797 }
798 placeWindowAfter(pos, win);
799 } else {
800 // Just search for the start of this layer.
801 final int myLayer = win.mBaseLayer;
802 for (i=0; i<N; i++) {
803 WindowState w = (WindowState)localmWindows.get(i);
804 if (w.mBaseLayer > myLayer) {
805 break;
806 }
807 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800808 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700809 TAG, "Adding window " + win + " at "
810 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800811 localmWindows.add(i, win);
812 }
813 }
814 }
815 } else {
816 // Figure out where window should go, based on layer.
817 final int myLayer = win.mBaseLayer;
818 for (i=N-1; i>=0; i--) {
819 if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) {
820 i++;
821 break;
822 }
823 }
824 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800825 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700826 TAG, "Adding window " + win + " at "
827 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 localmWindows.add(i, win);
829 }
830 if (addToToken) {
831 token.windows.add(tokenWindowsPos, win);
832 }
833
834 } else {
835 // Figure out this window's ordering relative to the window
836 // it is attached to.
837 final int NA = token.windows.size();
838 final int sublayer = win.mSubLayer;
839 int largestSublayer = Integer.MIN_VALUE;
840 WindowState windowWithLargestSublayer = null;
841 for (i=0; i<NA; i++) {
842 WindowState w = token.windows.get(i);
843 final int wSublayer = w.mSubLayer;
844 if (wSublayer >= largestSublayer) {
845 largestSublayer = wSublayer;
846 windowWithLargestSublayer = w;
847 }
848 if (sublayer < 0) {
849 // For negative sublayers, we go below all windows
850 // in the same sublayer.
851 if (wSublayer >= sublayer) {
852 if (addToToken) {
853 token.windows.add(i, win);
854 }
855 placeWindowBefore(
856 wSublayer >= 0 ? attached : w, win);
857 break;
858 }
859 } else {
860 // For positive sublayers, we go above all windows
861 // in the same sublayer.
862 if (wSublayer > sublayer) {
863 if (addToToken) {
864 token.windows.add(i, win);
865 }
866 placeWindowBefore(w, win);
867 break;
868 }
869 }
870 }
871 if (i >= NA) {
872 if (addToToken) {
873 token.windows.add(win);
874 }
875 if (sublayer < 0) {
876 placeWindowBefore(attached, win);
877 } else {
878 placeWindowAfter(largestSublayer >= 0
879 ? windowWithLargestSublayer
880 : attached,
881 win);
882 }
883 }
884 }
Romain Guy06882f82009-06-10 13:36:04 -0700885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800886 if (win.mAppToken != null && addToToken) {
887 win.mAppToken.allAppWindows.add(win);
888 }
889 }
Romain Guy06882f82009-06-10 13:36:04 -0700890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891 static boolean canBeImeTarget(WindowState w) {
892 final int fl = w.mAttrs.flags
893 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
894 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
895 return w.isVisibleOrAdding();
896 }
897 return false;
898 }
Romain Guy06882f82009-06-10 13:36:04 -0700899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
901 final ArrayList localmWindows = mWindows;
902 final int N = localmWindows.size();
903 WindowState w = null;
904 int i = N;
905 while (i > 0) {
906 i--;
907 w = (WindowState)localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700908
Joe Onorato8a9b2202010-02-26 18:56:32 -0800909 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800910 // + Integer.toHexString(w.mAttrs.flags));
911 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800912 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800914 // Yet more tricksyness! If this window is a "starting"
915 // window, we do actually want to be on top of it, but
916 // it is not -really- where input will go. So if the caller
917 // is not actually looking to move the IME, look down below
918 // for a real window to target...
919 if (!willMove
920 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
921 && i > 0) {
922 WindowState wb = (WindowState)localmWindows.get(i-1);
923 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
924 i--;
925 w = wb;
926 }
927 }
928 break;
929 }
930 }
Romain Guy06882f82009-06-10 13:36:04 -0700931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700933
Joe Onorato8a9b2202010-02-26 18:56:32 -0800934 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 if (willMove && w != null) {
938 final WindowState curTarget = mInputMethodTarget;
939 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800941 // Now some fun for dealing with window animations that
942 // modify the Z order. We need to look at all windows below
943 // the current target that are in this app, finding the highest
944 // visible one in layering.
945 AppWindowToken token = curTarget.mAppToken;
946 WindowState highestTarget = null;
947 int highestPos = 0;
948 if (token.animating || token.animation != null) {
949 int pos = 0;
950 pos = localmWindows.indexOf(curTarget);
951 while (pos >= 0) {
952 WindowState win = (WindowState)localmWindows.get(pos);
953 if (win.mAppToken != token) {
954 break;
955 }
956 if (!win.mRemoved) {
957 if (highestTarget == null || win.mAnimLayer >
958 highestTarget.mAnimLayer) {
959 highestTarget = win;
960 highestPos = pos;
961 }
962 }
963 pos--;
964 }
965 }
Romain Guy06882f82009-06-10 13:36:04 -0700966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800967 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800968 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 + mNextAppTransition + " " + highestTarget
970 + " animating=" + highestTarget.isAnimating()
971 + " layer=" + highestTarget.mAnimLayer
972 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700973
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700974 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800975 // If we are currently setting up for an animation,
976 // hold everything until we can find out what will happen.
977 mInputMethodTargetWaitingAnim = true;
978 mInputMethodTarget = highestTarget;
979 return highestPos + 1;
980 } else if (highestTarget.isAnimating() &&
981 highestTarget.mAnimLayer > w.mAnimLayer) {
982 // If the window we are currently targeting is involved
983 // with an animation, and it is on top of the next target
984 // we will be over, then hold off on moving until
985 // that is done.
986 mInputMethodTarget = highestTarget;
987 return highestPos + 1;
988 }
989 }
990 }
991 }
Romain Guy06882f82009-06-10 13:36:04 -0700992
Joe Onorato8a9b2202010-02-26 18:56:32 -0800993 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800994 if (w != null) {
995 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -0800996 if (DEBUG_INPUT_METHOD) {
997 RuntimeException e = null;
998 if (!HIDE_STACK_CRAWLS) {
999 e = new RuntimeException();
1000 e.fillInStackTrace();
1001 }
1002 Slog.w(TAG, "Moving IM target from "
1003 + mInputMethodTarget + " to " + w, e);
1004 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005 mInputMethodTarget = w;
1006 if (w.mAppToken != null) {
1007 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1008 } else {
1009 setInputMethodAnimLayerAdjustment(0);
1010 }
1011 }
1012 return i+1;
1013 }
1014 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001015 if (DEBUG_INPUT_METHOD) {
1016 RuntimeException e = null;
1017 if (!HIDE_STACK_CRAWLS) {
1018 e = new RuntimeException();
1019 e.fillInStackTrace();
1020 }
1021 Slog.w(TAG, "Moving IM target from "
1022 + mInputMethodTarget + " to null", e);
1023 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001024 mInputMethodTarget = null;
1025 setInputMethodAnimLayerAdjustment(0);
1026 }
1027 return -1;
1028 }
Romain Guy06882f82009-06-10 13:36:04 -07001029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001030 void addInputMethodWindowToListLocked(WindowState win) {
1031 int pos = findDesiredInputMethodWindowIndexLocked(true);
1032 if (pos >= 0) {
1033 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001034 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001035 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 mWindows.add(pos, win);
1037 moveInputMethodDialogsLocked(pos+1);
1038 return;
1039 }
1040 win.mTargetAppToken = null;
1041 addWindowToListInOrderLocked(win, true);
1042 moveInputMethodDialogsLocked(pos);
1043 }
Romain Guy06882f82009-06-10 13:36:04 -07001044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001046 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 mInputMethodAnimLayerAdjustment = adj;
1048 WindowState imw = mInputMethodWindow;
1049 if (imw != null) {
1050 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001051 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001052 + " anim layer: " + imw.mAnimLayer);
1053 int wi = imw.mChildWindows.size();
1054 while (wi > 0) {
1055 wi--;
1056 WindowState cw = (WindowState)imw.mChildWindows.get(wi);
1057 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001058 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059 + " anim layer: " + cw.mAnimLayer);
1060 }
1061 }
1062 int di = mInputMethodDialogs.size();
1063 while (di > 0) {
1064 di --;
1065 imw = mInputMethodDialogs.get(di);
1066 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001067 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 + " anim layer: " + imw.mAnimLayer);
1069 }
1070 }
Romain Guy06882f82009-06-10 13:36:04 -07001071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1073 int wpos = mWindows.indexOf(win);
1074 if (wpos >= 0) {
1075 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001076 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077 mWindows.remove(wpos);
1078 int NC = win.mChildWindows.size();
1079 while (NC > 0) {
1080 NC--;
1081 WindowState cw = (WindowState)win.mChildWindows.get(NC);
1082 int cpos = mWindows.indexOf(cw);
1083 if (cpos >= 0) {
1084 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001085 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001086 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 mWindows.remove(cpos);
1088 }
1089 }
1090 }
1091 return interestingPos;
1092 }
Romain Guy06882f82009-06-10 13:36:04 -07001093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 private void reAddWindowToListInOrderLocked(WindowState win) {
1095 addWindowToListInOrderLocked(win, false);
1096 // This is a hack to get all of the child windows added as well
1097 // at the right position. Child windows should be rare and
1098 // this case should be rare, so it shouldn't be that big a deal.
1099 int wpos = mWindows.indexOf(win);
1100 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001101 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001102 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 mWindows.remove(wpos);
1104 reAddWindowLocked(wpos, win);
1105 }
1106 }
Romain Guy06882f82009-06-10 13:36:04 -07001107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001108 void logWindowList(String prefix) {
1109 int N = mWindows.size();
1110 while (N > 0) {
1111 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001112 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 }
1114 }
Romain Guy06882f82009-06-10 13:36:04 -07001115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 void moveInputMethodDialogsLocked(int pos) {
1117 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001120 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001121 for (int i=0; i<N; i++) {
1122 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1123 }
1124 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001125 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001126 logWindowList(" ");
1127 }
Romain Guy06882f82009-06-10 13:36:04 -07001128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001129 if (pos >= 0) {
1130 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1131 if (pos < mWindows.size()) {
1132 WindowState wp = (WindowState)mWindows.get(pos);
1133 if (wp == mInputMethodWindow) {
1134 pos++;
1135 }
1136 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001137 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001138 for (int i=0; i<N; i++) {
1139 WindowState win = dialogs.get(i);
1140 win.mTargetAppToken = targetAppToken;
1141 pos = reAddWindowLocked(pos, win);
1142 }
1143 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001144 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 logWindowList(" ");
1146 }
1147 return;
1148 }
1149 for (int i=0; i<N; i++) {
1150 WindowState win = dialogs.get(i);
1151 win.mTargetAppToken = null;
1152 reAddWindowToListInOrderLocked(win);
1153 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001154 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 logWindowList(" ");
1156 }
1157 }
1158 }
Romain Guy06882f82009-06-10 13:36:04 -07001159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1161 final WindowState imWin = mInputMethodWindow;
1162 final int DN = mInputMethodDialogs.size();
1163 if (imWin == null && DN == 0) {
1164 return false;
1165 }
Romain Guy06882f82009-06-10 13:36:04 -07001166
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001167 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1168 if (imPos >= 0) {
1169 // In this case, the input method windows are to be placed
1170 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001172 // First check to see if the input method windows are already
1173 // located here, and contiguous.
1174 final int N = mWindows.size();
1175 WindowState firstImWin = imPos < N
1176 ? (WindowState)mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001178 // Figure out the actual input method window that should be
1179 // at the bottom of their stack.
1180 WindowState baseImWin = imWin != null
1181 ? imWin : mInputMethodDialogs.get(0);
1182 if (baseImWin.mChildWindows.size() > 0) {
1183 WindowState cw = (WindowState)baseImWin.mChildWindows.get(0);
1184 if (cw.mSubLayer < 0) baseImWin = cw;
1185 }
Romain Guy06882f82009-06-10 13:36:04 -07001186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001187 if (firstImWin == baseImWin) {
1188 // The windows haven't moved... but are they still contiguous?
1189 // First find the top IM window.
1190 int pos = imPos+1;
1191 while (pos < N) {
1192 if (!((WindowState)mWindows.get(pos)).mIsImWindow) {
1193 break;
1194 }
1195 pos++;
1196 }
1197 pos++;
1198 // Now there should be no more input method windows above.
1199 while (pos < N) {
1200 if (((WindowState)mWindows.get(pos)).mIsImWindow) {
1201 break;
1202 }
1203 pos++;
1204 }
1205 if (pos >= N) {
1206 // All is good!
1207 return false;
1208 }
1209 }
Romain Guy06882f82009-06-10 13:36:04 -07001210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001211 if (imWin != null) {
1212 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001213 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001214 logWindowList(" ");
1215 }
1216 imPos = tmpRemoveWindowLocked(imPos, imWin);
1217 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001218 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001219 logWindowList(" ");
1220 }
1221 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1222 reAddWindowLocked(imPos, imWin);
1223 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001224 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001225 logWindowList(" ");
1226 }
1227 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1228 } else {
1229 moveInputMethodDialogsLocked(imPos);
1230 }
Romain Guy06882f82009-06-10 13:36:04 -07001231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 } else {
1233 // In this case, the input method windows go in a fixed layer,
1234 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001236 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001237 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001238 tmpRemoveWindowLocked(0, imWin);
1239 imWin.mTargetAppToken = null;
1240 reAddWindowToListInOrderLocked(imWin);
1241 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001242 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243 logWindowList(" ");
1244 }
1245 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1246 } else {
1247 moveInputMethodDialogsLocked(-1);;
1248 }
Romain Guy06882f82009-06-10 13:36:04 -07001249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001250 }
Romain Guy06882f82009-06-10 13:36:04 -07001251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 if (needAssignLayers) {
1253 assignLayersLocked();
1254 }
Romain Guy06882f82009-06-10 13:36:04 -07001255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 return true;
1257 }
Romain Guy06882f82009-06-10 13:36:04 -07001258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001259 void adjustInputMethodDialogsLocked() {
1260 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1261 }
Romain Guy06882f82009-06-10 13:36:04 -07001262
Dianne Hackborn25994b42009-09-04 14:21:19 -07001263 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001264 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001265 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1266 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1267 ? wallpaperTarget.mAppToken.animation : null)
1268 + " upper=" + mUpperWallpaperTarget
1269 + " lower=" + mLowerWallpaperTarget);
1270 return (wallpaperTarget != null
1271 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1272 && wallpaperTarget.mAppToken.animation != null)))
1273 || mUpperWallpaperTarget != null
1274 || mLowerWallpaperTarget != null;
1275 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001276
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001277 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1278 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001279
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001280 int adjustWallpaperWindowsLocked() {
1281 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001282
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001283 final int dw = mDisplay.getWidth();
1284 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001285
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001286 // First find top-most window that has asked to be on top of the
1287 // wallpaper; all wallpapers go behind it.
1288 final ArrayList localmWindows = mWindows;
1289 int N = localmWindows.size();
1290 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001291 WindowState foundW = null;
1292 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001293 WindowState topCurW = null;
1294 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001295 int i = N;
1296 while (i > 0) {
1297 i--;
1298 w = (WindowState)localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001299 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1300 if (topCurW == null) {
1301 topCurW = w;
1302 topCurI = i;
1303 }
1304 continue;
1305 }
1306 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001307 if (w.mAppToken != null) {
1308 // If this window's app token is hidden and not animating,
1309 // it is of no interest to us.
1310 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001311 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001312 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001313 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001314 continue;
1315 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001316 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001317 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001318 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1319 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001320 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001321 && (mWallpaperTarget == w
1322 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001323 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001324 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001325 foundW = w;
1326 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001327 if (w == mWallpaperTarget && ((w.mAppToken != null
1328 && w.mAppToken.animation != null)
1329 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001330 // The current wallpaper target is animating, so we'll
1331 // look behind it for another possible target and figure
1332 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001333 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001334 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001335 continue;
1336 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001337 break;
1338 }
1339 }
1340
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001341 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001342 // If we are currently waiting for an app transition, and either
1343 // the current target or the next target are involved with it,
1344 // then hold off on doing anything with the wallpaper.
1345 // Note that we are checking here for just whether the target
1346 // is part of an app token... which is potentially overly aggressive
1347 // (the app token may not be involved in the transition), but good
1348 // enough (we'll just wait until whatever transition is pending
1349 // executes).
1350 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001351 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001352 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001353 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001354 }
1355 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001356 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001357 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001358 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001359 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001360 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001361
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001362 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001363 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001364 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001365 + " oldTarget: " + mWallpaperTarget);
1366 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001367
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001368 mLowerWallpaperTarget = null;
1369 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001370
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001371 WindowState oldW = mWallpaperTarget;
1372 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001373
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001374 // Now what is happening... if the current and new targets are
1375 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001376 if (foundW != null && oldW != null) {
1377 boolean oldAnim = oldW.mAnimation != null
1378 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1379 boolean foundAnim = foundW.mAnimation != null
1380 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001381 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001382 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001383 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001384 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001385 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001386 int oldI = localmWindows.indexOf(oldW);
1387 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001388 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001389 }
1390 if (oldI >= 0) {
1391 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001392 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001393 + "=" + oldW + "; new#" + foundI
1394 + "=" + foundW);
1395 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001396
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001397 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001398 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001399 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001400 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001401 }
1402 mWallpaperTarget = oldW;
1403 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001404
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001405 // Now set the upper and lower wallpaper targets
1406 // correctly, and make sure that we are positioning
1407 // the wallpaper below the lower.
1408 if (foundI > oldI) {
1409 // The new target is on top of the old one.
1410 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001411 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001412 }
1413 mUpperWallpaperTarget = foundW;
1414 mLowerWallpaperTarget = oldW;
1415 foundW = oldW;
1416 foundI = oldI;
1417 } else {
1418 // The new target is below the old one.
1419 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001420 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001421 }
1422 mUpperWallpaperTarget = oldW;
1423 mLowerWallpaperTarget = foundW;
1424 }
1425 }
1426 }
1427 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001428
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001429 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001430 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001431 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1432 || (mLowerWallpaperTarget.mAppToken != null
1433 && mLowerWallpaperTarget.mAppToken.animation != null);
1434 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1435 || (mUpperWallpaperTarget.mAppToken != null
1436 && mUpperWallpaperTarget.mAppToken.animation != null);
1437 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001438 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001439 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001440 }
1441 mLowerWallpaperTarget = null;
1442 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001443 }
1444 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001445
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001446 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001447 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001448 // The window is visible to the compositor... but is it visible
1449 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001450 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001451 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001452
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001453 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001454 // its layer adjustment. Only do this if we are not transfering
1455 // between two wallpaper targets.
1456 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001457 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001458 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001459
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001460 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1461 * TYPE_LAYER_MULTIPLIER
1462 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001463
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001464 // Now w is the window we are supposed to be behind... but we
1465 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001466 // AND any starting window associated with it, AND below the
1467 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001468 while (foundI > 0) {
1469 WindowState wb = (WindowState)localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001470 if (wb.mBaseLayer < maxLayer &&
1471 wb.mAttachedWindow != foundW &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001472 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001473 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001474 // This window is not related to the previous one in any
1475 // interesting way, so stop here.
1476 break;
1477 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001478 foundW = wb;
1479 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001480 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001481 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001482 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001483 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001484
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001485 if (foundW == null && topCurW != null) {
1486 // There is no wallpaper target, so it goes at the bottom.
1487 // We will assume it is the same place as last time, if known.
1488 foundW = topCurW;
1489 foundI = topCurI+1;
1490 } else {
1491 // Okay i is the position immediately above the wallpaper. Look at
1492 // what is below it for later.
1493 foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null;
1494 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001495
Dianne Hackborn284ac932009-08-28 10:34:25 -07001496 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001497 if (mWallpaperTarget.mWallpaperX >= 0) {
1498 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001499 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001500 }
1501 if (mWallpaperTarget.mWallpaperY >= 0) {
1502 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001503 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001504 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001505 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001506
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001507 // Start stepping backwards from here, ensuring that our wallpaper windows
1508 // are correctly placed.
1509 int curTokenIndex = mWallpaperTokens.size();
1510 while (curTokenIndex > 0) {
1511 curTokenIndex--;
1512 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001513 if (token.hidden == visible) {
1514 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1515 token.hidden = !visible;
1516 // Need to do a layout to ensure the wallpaper now has the
1517 // correct size.
1518 mLayoutNeeded = true;
1519 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001520
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001521 int curWallpaperIndex = token.windows.size();
1522 while (curWallpaperIndex > 0) {
1523 curWallpaperIndex--;
1524 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001525
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001526 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001527 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001528 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001529
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001530 // First, make sure the client has the current visibility
1531 // state.
1532 if (wallpaper.mWallpaperVisible != visible) {
1533 wallpaper.mWallpaperVisible = visible;
1534 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001535 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001536 "Setting visibility of wallpaper " + wallpaper
1537 + ": " + visible);
1538 wallpaper.mClient.dispatchAppVisibility(visible);
1539 } catch (RemoteException e) {
1540 }
1541 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001542
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001543 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001544 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001545 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001546
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001547 // First, if this window is at the current index, then all
1548 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001549 if (wallpaper == foundW) {
1550 foundI--;
1551 foundW = foundI > 0
1552 ? (WindowState)localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001553 continue;
1554 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001555
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001556 // The window didn't match... the current wallpaper window,
1557 // wherever it is, is in the wrong place, so make sure it is
1558 // not in the list.
1559 int oldIndex = localmWindows.indexOf(wallpaper);
1560 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001561 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001562 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001563 localmWindows.remove(oldIndex);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001564 if (oldIndex < foundI) {
1565 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001566 }
1567 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001568
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001569 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001570 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001571 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001572 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001573
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001574 localmWindows.add(foundI, wallpaper);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001575 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001576 }
1577 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001578
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001579 return changed;
1580 }
1581
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001582 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001583 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001584 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001585 mWallpaperAnimLayerAdjustment = adj;
1586 int curTokenIndex = mWallpaperTokens.size();
1587 while (curTokenIndex > 0) {
1588 curTokenIndex--;
1589 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1590 int curWallpaperIndex = token.windows.size();
1591 while (curWallpaperIndex > 0) {
1592 curWallpaperIndex--;
1593 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1594 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001595 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001596 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001597 }
1598 }
1599 }
1600
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001601 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1602 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001603 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001604 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001605 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001606 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001607 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1608 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1609 changed = wallpaperWin.mXOffset != offset;
1610 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001611 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001612 + wallpaperWin + " x: " + offset);
1613 wallpaperWin.mXOffset = offset;
1614 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001615 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001616 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001617 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001618 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001619 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001620
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001621 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001622 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001623 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1624 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1625 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001626 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001627 + wallpaperWin + " y: " + offset);
1628 changed = true;
1629 wallpaperWin.mYOffset = offset;
1630 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001631 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001632 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001633 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001634 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001635 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001636
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001637 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001638 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001639 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001640 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1641 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001642 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001643 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001644 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001645 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001646 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1647 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001648 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001649 if (mWaitingOnWallpaper != null) {
1650 long start = SystemClock.uptimeMillis();
1651 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1652 < start) {
1653 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001654 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001655 "Waiting for offset complete...");
1656 mWindowMap.wait(WALLPAPER_TIMEOUT);
1657 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001658 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001659 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001660 if ((start+WALLPAPER_TIMEOUT)
1661 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001662 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001663 + wallpaperWin);
1664 mLastWallpaperTimeoutTime = start;
1665 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001666 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001667 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001668 }
1669 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001670 } catch (RemoteException e) {
1671 }
1672 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001673
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001674 return changed;
1675 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001676
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001677 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001678 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001679 if (mWaitingOnWallpaper != null &&
1680 mWaitingOnWallpaper.mClient.asBinder() == window) {
1681 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001682 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001683 }
1684 }
1685 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001686
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001687 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001688 final int dw = mDisplay.getWidth();
1689 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001690
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001691 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001692
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001693 WindowState target = mWallpaperTarget;
1694 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001695 if (target.mWallpaperX >= 0) {
1696 mLastWallpaperX = target.mWallpaperX;
1697 } else if (changingTarget.mWallpaperX >= 0) {
1698 mLastWallpaperX = changingTarget.mWallpaperX;
1699 }
1700 if (target.mWallpaperY >= 0) {
1701 mLastWallpaperY = target.mWallpaperY;
1702 } else if (changingTarget.mWallpaperY >= 0) {
1703 mLastWallpaperY = changingTarget.mWallpaperY;
1704 }
1705 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001706
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001707 int curTokenIndex = mWallpaperTokens.size();
1708 while (curTokenIndex > 0) {
1709 curTokenIndex--;
1710 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1711 int curWallpaperIndex = token.windows.size();
1712 while (curWallpaperIndex > 0) {
1713 curWallpaperIndex--;
1714 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1715 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1716 wallpaper.computeShownFrameLocked();
1717 changed = true;
1718 // We only want to be synchronous with one wallpaper.
1719 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001720 }
1721 }
1722 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001723
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001724 return changed;
1725 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001726
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001727 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001728 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001729 final int dw = mDisplay.getWidth();
1730 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001731
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001732 int curTokenIndex = mWallpaperTokens.size();
1733 while (curTokenIndex > 0) {
1734 curTokenIndex--;
1735 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001736 if (token.hidden == visible) {
1737 token.hidden = !visible;
1738 // Need to do a layout to ensure the wallpaper now has the
1739 // correct size.
1740 mLayoutNeeded = true;
1741 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001742
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001743 int curWallpaperIndex = token.windows.size();
1744 while (curWallpaperIndex > 0) {
1745 curWallpaperIndex--;
1746 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1747 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001748 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001749 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001750
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001751 if (wallpaper.mWallpaperVisible != visible) {
1752 wallpaper.mWallpaperVisible = visible;
1753 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001754 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001755 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001756 + ": " + visible);
1757 wallpaper.mClient.dispatchAppVisibility(visible);
1758 } catch (RemoteException e) {
1759 }
1760 }
1761 }
1762 }
1763 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001764
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001765 void sendPointerToWallpaperLocked(WindowState srcWin,
1766 MotionEvent pointer, long eventTime) {
1767 int curTokenIndex = mWallpaperTokens.size();
1768 while (curTokenIndex > 0) {
1769 curTokenIndex--;
1770 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1771 int curWallpaperIndex = token.windows.size();
1772 while (curWallpaperIndex > 0) {
1773 curWallpaperIndex--;
1774 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1775 if ((wallpaper.mAttrs.flags &
1776 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
1777 continue;
1778 }
1779 try {
1780 MotionEvent ev = MotionEvent.obtainNoHistory(pointer);
Dianne Hackborn6adba242009-11-10 11:10:09 -08001781 if (srcWin != null) {
1782 ev.offsetLocation(srcWin.mFrame.left-wallpaper.mFrame.left,
1783 srcWin.mFrame.top-wallpaper.mFrame.top);
1784 } else {
1785 ev.offsetLocation(-wallpaper.mFrame.left, -wallpaper.mFrame.top);
1786 }
1787 switch (pointer.getAction()) {
1788 case MotionEvent.ACTION_DOWN:
1789 mSendingPointersToWallpaper = true;
1790 break;
1791 case MotionEvent.ACTION_UP:
1792 mSendingPointersToWallpaper = false;
1793 break;
1794 }
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001795 wallpaper.mClient.dispatchPointer(ev, eventTime, false);
1796 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001797 Slog.w(TAG, "Failure sending pointer to wallpaper", e);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001798 }
1799 }
1800 }
1801 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001802
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001803 void dispatchPointerElsewhereLocked(WindowState srcWin, WindowState relWin,
1804 MotionEvent pointer, long eventTime, boolean skipped) {
1805 if (relWin != null) {
1806 mPolicy.dispatchedPointerEventLw(pointer, relWin.mFrame.left, relWin.mFrame.top);
1807 } else {
1808 mPolicy.dispatchedPointerEventLw(pointer, 0, 0);
1809 }
1810
1811 // If we sent an initial down to the wallpaper, then continue
1812 // sending events until the final up.
1813 if (mSendingPointersToWallpaper) {
1814 if (skipped) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001815 Slog.i(TAG, "Sending skipped pointer to wallpaper!");
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001816 }
1817 sendPointerToWallpaperLocked(relWin, pointer, eventTime);
1818
1819 // If we are on top of the wallpaper, then the wallpaper also
1820 // gets to see this movement.
1821 } else if (srcWin != null
1822 && pointer.getAction() == MotionEvent.ACTION_DOWN
1823 && mWallpaperTarget == srcWin
1824 && srcWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) {
1825 sendPointerToWallpaperLocked(relWin, pointer, eventTime);
1826 }
1827 }
1828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001829 public int addWindow(Session session, IWindow client,
1830 WindowManager.LayoutParams attrs, int viewVisibility,
1831 Rect outContentInsets) {
1832 int res = mPolicy.checkAddPermission(attrs);
1833 if (res != WindowManagerImpl.ADD_OKAY) {
1834 return res;
1835 }
Romain Guy06882f82009-06-10 13:36:04 -07001836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001837 boolean reportNewConfig = false;
1838 WindowState attachedWindow = null;
1839 WindowState win = null;
Romain Guy06882f82009-06-10 13:36:04 -07001840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001841 synchronized(mWindowMap) {
1842 // Instantiating a Display requires talking with the simulator,
1843 // so don't do it until we know the system is mostly up and
1844 // running.
1845 if (mDisplay == null) {
1846 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1847 mDisplay = wm.getDefaultDisplay();
Christopher Tateb696aee2010-04-02 19:08:30 -07001848 mInitialDisplayWidth = mDisplay.getWidth();
1849 mInitialDisplayHeight = mDisplay.getHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001850 mQueue.setDisplay(mDisplay);
1851 reportNewConfig = true;
1852 }
Romain Guy06882f82009-06-10 13:36:04 -07001853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001854 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001855 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001856 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1857 }
1858
1859 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001860 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001861 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001862 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001863 + attrs.token + ". Aborting.");
1864 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1865 }
1866 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1867 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001868 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001869 + attrs.token + ". Aborting.");
1870 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1871 }
1872 }
1873
1874 boolean addToken = false;
1875 WindowToken token = mTokenMap.get(attrs.token);
1876 if (token == null) {
1877 if (attrs.type >= FIRST_APPLICATION_WINDOW
1878 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001879 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001880 + attrs.token + ". Aborting.");
1881 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1882 }
1883 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001884 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001885 + attrs.token + ". Aborting.");
1886 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1887 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001888 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001889 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001890 + attrs.token + ". Aborting.");
1891 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1892 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001893 token = new WindowToken(attrs.token, -1, false);
1894 addToken = true;
1895 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1896 && attrs.type <= LAST_APPLICATION_WINDOW) {
1897 AppWindowToken atoken = token.appWindowToken;
1898 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001899 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001900 + token + ". Aborting.");
1901 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1902 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001903 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001904 + token + ". Aborting.");
1905 return WindowManagerImpl.ADD_APP_EXITING;
1906 }
1907 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1908 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001909 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001910 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1911 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1912 }
1913 } else if (attrs.type == TYPE_INPUT_METHOD) {
1914 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001915 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001916 + attrs.token + ". Aborting.");
1917 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1918 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001919 } else if (attrs.type == TYPE_WALLPAPER) {
1920 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001921 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001922 + attrs.token + ". Aborting.");
1923 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1924 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001925 }
1926
1927 win = new WindowState(session, client, token,
1928 attachedWindow, attrs, viewVisibility);
1929 if (win.mDeathRecipient == null) {
1930 // Client has apparently died, so there is no reason to
1931 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001932 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001933 + " that is dead, aborting.");
1934 return WindowManagerImpl.ADD_APP_EXITING;
1935 }
1936
1937 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001939 res = mPolicy.prepareAddWindowLw(win, attrs);
1940 if (res != WindowManagerImpl.ADD_OKAY) {
1941 return res;
1942 }
1943
1944 // From now on, no exceptions or errors allowed!
1945
1946 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001948 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001950 if (addToken) {
1951 mTokenMap.put(attrs.token, token);
1952 mTokenList.add(token);
1953 }
1954 win.attach();
1955 mWindowMap.put(client.asBinder(), win);
1956
1957 if (attrs.type == TYPE_APPLICATION_STARTING &&
1958 token.appWindowToken != null) {
1959 token.appWindowToken.startingWindow = win;
1960 }
1961
1962 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001964 if (attrs.type == TYPE_INPUT_METHOD) {
1965 mInputMethodWindow = win;
1966 addInputMethodWindowToListLocked(win);
1967 imMayMove = false;
1968 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1969 mInputMethodDialogs.add(win);
1970 addWindowToListInOrderLocked(win, true);
1971 adjustInputMethodDialogsLocked();
1972 imMayMove = false;
1973 } else {
1974 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001975 if (attrs.type == TYPE_WALLPAPER) {
1976 mLastWallpaperTimeoutTime = 0;
1977 adjustWallpaperWindowsLocked();
1978 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001979 adjustWallpaperWindowsLocked();
1980 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001981 }
Romain Guy06882f82009-06-10 13:36:04 -07001982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001983 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001985 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001987 if (mInTouchMode) {
1988 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1989 }
1990 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1991 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1992 }
Romain Guy06882f82009-06-10 13:36:04 -07001993
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001994 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001995 if (win.canReceiveKeys()) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001996 if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS))
1997 == true) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998 imMayMove = false;
1999 }
2000 }
Romain Guy06882f82009-06-10 13:36:04 -07002001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002002 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002003 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002004 }
Romain Guy06882f82009-06-10 13:36:04 -07002005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002006 assignLayersLocked();
2007 // Don't do layout here, the window must call
2008 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002010 //dump();
2011
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002012 if (focusChanged) {
2013 if (mCurrentFocus != null) {
2014 mKeyWaiter.handleNewWindowLocked(mCurrentFocus);
2015 }
2016 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002017 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002018 TAG, "New client " + client.asBinder()
2019 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002020
2021 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2022 reportNewConfig = true;
2023 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002024 }
2025
2026 // sendNewConfiguration() checks caller permissions so we must call it with
2027 // privilege. updateOrientationFromAppTokens() clears and resets the caller
2028 // identity anyway, so it's safe to just clear & restore around this whole
2029 // block.
2030 final long origId = Binder.clearCallingIdentity();
2031 if (reportNewConfig) {
2032 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002033 }
2034 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002036 return res;
2037 }
Romain Guy06882f82009-06-10 13:36:04 -07002038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002039 public void removeWindow(Session session, IWindow client) {
2040 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002041 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002042 if (win == null) {
2043 return;
2044 }
2045 removeWindowLocked(session, win);
2046 }
2047 }
Romain Guy06882f82009-06-10 13:36:04 -07002048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002049 public void removeWindowLocked(Session session, WindowState win) {
2050
Joe Onorato8a9b2202010-02-26 18:56:32 -08002051 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002052 TAG, "Remove " + win + " client="
2053 + Integer.toHexString(System.identityHashCode(
2054 win.mClient.asBinder()))
2055 + ", surface=" + win.mSurface);
2056
2057 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002058
Joe Onorato8a9b2202010-02-26 18:56:32 -08002059 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002060 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2061 + " mExiting=" + win.mExiting
2062 + " isAnimating=" + win.isAnimating()
2063 + " app-animation="
2064 + (win.mAppToken != null ? win.mAppToken.animation : null)
2065 + " inPendingTransaction="
2066 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2067 + " mDisplayFrozen=" + mDisplayFrozen);
2068 // Visibility of the removed window. Will be used later to update orientation later on.
2069 boolean wasVisible = false;
2070 // First, see if we need to run an animation. If we do, we have
2071 // to hold off on removing the window until the animation is done.
2072 // If the display is frozen, just remove immediately, since the
2073 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002074 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002075 // If we are not currently running the exit animation, we
2076 // need to see about starting one.
2077 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002079 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2080 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2081 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2082 }
2083 // Try starting an animation.
2084 if (applyAnimationLocked(win, transit, false)) {
2085 win.mExiting = true;
2086 }
2087 }
2088 if (win.mExiting || win.isAnimating()) {
2089 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002090 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002091 win.mExiting = true;
2092 win.mRemoveOnExit = true;
2093 mLayoutNeeded = true;
2094 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2095 performLayoutAndPlaceSurfacesLocked();
2096 if (win.mAppToken != null) {
2097 win.mAppToken.updateReportedVisibilityLocked();
2098 }
2099 //dump();
2100 Binder.restoreCallingIdentity(origId);
2101 return;
2102 }
2103 }
2104
2105 removeWindowInnerLocked(session, win);
2106 // Removing a visible window will effect the computed orientation
2107 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002108 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002109 != mForcedAppOrientation
2110 && updateOrientationFromAppTokensLocked()) {
2111 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002112 }
2113 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2114 Binder.restoreCallingIdentity(origId);
2115 }
Romain Guy06882f82009-06-10 13:36:04 -07002116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002117 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07002118 mKeyWaiter.finishedKey(session, win.mClient, true,
2119 KeyWaiter.RETURN_NOTHING);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002120 mKeyWaiter.releasePendingPointerLocked(win.mSession);
2121 mKeyWaiter.releasePendingTrackballLocked(win.mSession);
Romain Guy06882f82009-06-10 13:36:04 -07002122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002123 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002125 if (mInputMethodTarget == win) {
2126 moveInputMethodWindowsIfNeededLocked(false);
2127 }
Romain Guy06882f82009-06-10 13:36:04 -07002128
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002129 if (false) {
2130 RuntimeException e = new RuntimeException("here");
2131 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002132 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002133 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002135 mPolicy.removeWindowLw(win);
2136 win.removeLocked();
2137
2138 mWindowMap.remove(win.mClient.asBinder());
2139 mWindows.remove(win);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002140 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002141
2142 if (mInputMethodWindow == win) {
2143 mInputMethodWindow = null;
2144 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2145 mInputMethodDialogs.remove(win);
2146 }
Romain Guy06882f82009-06-10 13:36:04 -07002147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002148 final WindowToken token = win.mToken;
2149 final AppWindowToken atoken = win.mAppToken;
2150 token.windows.remove(win);
2151 if (atoken != null) {
2152 atoken.allAppWindows.remove(win);
2153 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002154 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002155 TAG, "**** Removing window " + win + ": count="
2156 + token.windows.size());
2157 if (token.windows.size() == 0) {
2158 if (!token.explicit) {
2159 mTokenMap.remove(token.token);
2160 mTokenList.remove(token);
2161 } else if (atoken != null) {
2162 atoken.firstWindowDrawn = false;
2163 }
2164 }
2165
2166 if (atoken != null) {
2167 if (atoken.startingWindow == win) {
2168 atoken.startingWindow = null;
2169 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2170 // If this is the last window and we had requested a starting
2171 // transition window, well there is no point now.
2172 atoken.startingData = null;
2173 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2174 // If this is the last window except for a starting transition
2175 // window, we need to get rid of the starting transition.
2176 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002177 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002178 + ": no more real windows");
2179 }
2180 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2181 mH.sendMessage(m);
2182 }
2183 }
Romain Guy06882f82009-06-10 13:36:04 -07002184
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002185 if (win.mAttrs.type == TYPE_WALLPAPER) {
2186 mLastWallpaperTimeoutTime = 0;
2187 adjustWallpaperWindowsLocked();
2188 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002189 adjustWallpaperWindowsLocked();
2190 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002192 if (!mInLayout) {
2193 assignLayersLocked();
2194 mLayoutNeeded = true;
2195 performLayoutAndPlaceSurfacesLocked();
2196 if (win.mAppToken != null) {
2197 win.mAppToken.updateReportedVisibilityLocked();
2198 }
2199 }
2200 }
2201
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002202 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2203 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2204 + ": " + msg + " / " + w.mAttrs.getTitle();
2205 if (where != null) {
2206 Slog.i(TAG, str, where);
2207 } else {
2208 Slog.i(TAG, str);
2209 }
2210 }
2211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002212 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2213 long origId = Binder.clearCallingIdentity();
2214 try {
2215 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002216 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002217 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002218 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002219 Surface.openTransaction();
2220 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002221 if (SHOW_TRANSACTIONS) logSurface(w,
2222 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002223 w.mSurface.setTransparentRegionHint(region);
2224 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002225 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002226 Surface.closeTransaction();
2227 }
2228 }
2229 }
2230 } finally {
2231 Binder.restoreCallingIdentity(origId);
2232 }
2233 }
2234
2235 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002236 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002237 Rect visibleInsets) {
2238 long origId = Binder.clearCallingIdentity();
2239 try {
2240 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002241 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002242 if (w != null) {
2243 w.mGivenInsetsPending = false;
2244 w.mGivenContentInsets.set(contentInsets);
2245 w.mGivenVisibleInsets.set(visibleInsets);
2246 w.mTouchableInsets = touchableInsets;
2247 mLayoutNeeded = true;
2248 performLayoutAndPlaceSurfacesLocked();
2249 }
2250 }
2251 } finally {
2252 Binder.restoreCallingIdentity(origId);
2253 }
2254 }
Romain Guy06882f82009-06-10 13:36:04 -07002255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002256 public void getWindowDisplayFrame(Session session, IWindow client,
2257 Rect outDisplayFrame) {
2258 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002259 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002260 if (win == null) {
2261 outDisplayFrame.setEmpty();
2262 return;
2263 }
2264 outDisplayFrame.set(win.mDisplayFrame);
2265 }
2266 }
2267
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002268 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2269 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002270 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2271 window.mWallpaperX = x;
2272 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002273 window.mWallpaperXStep = xStep;
2274 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002275 if (updateWallpaperOffsetLocked(window, true)) {
2276 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002277 }
2278 }
2279 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002280
Dianne Hackborn75804932009-10-20 20:15:20 -07002281 void wallpaperCommandComplete(IBinder window, Bundle result) {
2282 synchronized (mWindowMap) {
2283 if (mWaitingOnWallpaper != null &&
2284 mWaitingOnWallpaper.mClient.asBinder() == window) {
2285 mWaitingOnWallpaper = null;
2286 mWindowMap.notifyAll();
2287 }
2288 }
2289 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002290
Dianne Hackborn75804932009-10-20 20:15:20 -07002291 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2292 String action, int x, int y, int z, Bundle extras, boolean sync) {
2293 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2294 || window == mUpperWallpaperTarget) {
2295 boolean doWait = sync;
2296 int curTokenIndex = mWallpaperTokens.size();
2297 while (curTokenIndex > 0) {
2298 curTokenIndex--;
2299 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2300 int curWallpaperIndex = token.windows.size();
2301 while (curWallpaperIndex > 0) {
2302 curWallpaperIndex--;
2303 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2304 try {
2305 wallpaper.mClient.dispatchWallpaperCommand(action,
2306 x, y, z, extras, sync);
2307 // We only want to be synchronous with one wallpaper.
2308 sync = false;
2309 } catch (RemoteException e) {
2310 }
2311 }
2312 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002313
Dianne Hackborn75804932009-10-20 20:15:20 -07002314 if (doWait) {
2315 // XXX Need to wait for result.
2316 }
2317 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002318
Dianne Hackborn75804932009-10-20 20:15:20 -07002319 return null;
2320 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002322 public int relayoutWindow(Session session, IWindow client,
2323 WindowManager.LayoutParams attrs, int requestedWidth,
2324 int requestedHeight, int viewVisibility, boolean insetsPending,
2325 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002326 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002327 boolean displayed = false;
2328 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002329 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002330 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002332 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002333 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002334 if (win == null) {
2335 return 0;
2336 }
2337 win.mRequestedWidth = requestedWidth;
2338 win.mRequestedHeight = requestedHeight;
2339
2340 if (attrs != null) {
2341 mPolicy.adjustWindowParamsLw(attrs);
2342 }
Romain Guy06882f82009-06-10 13:36:04 -07002343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002344 int attrChanges = 0;
2345 int flagChanges = 0;
2346 if (attrs != null) {
2347 flagChanges = win.mAttrs.flags ^= attrs.flags;
2348 attrChanges = win.mAttrs.copyFrom(attrs);
2349 }
2350
Joe Onorato8a9b2202010-02-26 18:56:32 -08002351 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002352
2353 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2354 win.mAlpha = attrs.alpha;
2355 }
2356
2357 final boolean scaledWindow =
2358 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2359
2360 if (scaledWindow) {
2361 // requested{Width|Height} Surface's physical size
2362 // attrs.{width|height} Size on screen
2363 win.mHScale = (attrs.width != requestedWidth) ?
2364 (attrs.width / (float)requestedWidth) : 1.0f;
2365 win.mVScale = (attrs.height != requestedHeight) ?
2366 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002367 } else {
2368 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002369 }
2370
2371 boolean imMayMove = (flagChanges&(
2372 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2373 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002375 boolean focusMayChange = win.mViewVisibility != viewVisibility
2376 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2377 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002378
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002379 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2380 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002382 win.mRelayoutCalled = true;
2383 final int oldVisibility = win.mViewVisibility;
2384 win.mViewVisibility = viewVisibility;
2385 if (viewVisibility == View.VISIBLE &&
2386 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2387 displayed = !win.isVisibleLw();
2388 if (win.mExiting) {
2389 win.mExiting = false;
2390 win.mAnimation = null;
2391 }
2392 if (win.mDestroying) {
2393 win.mDestroying = false;
2394 mDestroySurface.remove(win);
2395 }
2396 if (oldVisibility == View.GONE) {
2397 win.mEnterAnimationPending = true;
2398 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002399 if (displayed) {
2400 if (win.mSurface != null && !win.mDrawPending
2401 && !win.mCommitDrawPending && !mDisplayFrozen
2402 && mPolicy.isScreenOn()) {
2403 applyEnterAnimationLocked(win);
2404 }
2405 if ((win.mAttrs.flags
2406 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2407 if (DEBUG_VISIBILITY) Slog.v(TAG,
2408 "Relayout window turning screen on: " + win);
2409 win.mTurnOnScreen = true;
2410 }
2411 int diff = 0;
2412 if (win.mConfiguration != mCurConfiguration
2413 && (win.mConfiguration == null
2414 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2415 win.mConfiguration = mCurConfiguration;
2416 if (DEBUG_CONFIGURATION) {
2417 Slog.i(TAG, "Window " + win + " visible with new config: "
2418 + win.mConfiguration + " / 0x"
2419 + Integer.toHexString(diff));
2420 }
2421 outConfig.setTo(mCurConfiguration);
2422 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002423 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002424 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2425 // To change the format, we need to re-build the surface.
2426 win.destroySurfaceLocked();
2427 displayed = true;
2428 }
2429 try {
2430 Surface surface = win.createSurfaceLocked();
2431 if (surface != null) {
2432 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002433 win.mReportDestroySurface = false;
2434 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002435 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002436 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002437 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002438 // For some reason there isn't a surface. Clear the
2439 // caller's object so they see the same state.
2440 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002441 }
2442 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002443 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002444 + client + " (" + win.mAttrs.getTitle() + ")",
2445 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002446 Binder.restoreCallingIdentity(origId);
2447 return 0;
2448 }
2449 if (displayed) {
2450 focusMayChange = true;
2451 }
2452 if (win.mAttrs.type == TYPE_INPUT_METHOD
2453 && mInputMethodWindow == null) {
2454 mInputMethodWindow = win;
2455 imMayMove = true;
2456 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002457 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2458 && win.mAppToken != null
2459 && win.mAppToken.startingWindow != null) {
2460 // Special handling of starting window over the base
2461 // window of the app: propagate lock screen flags to it,
2462 // to provide the correct semantics while starting.
2463 final int mask =
2464 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002465 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2466 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002467 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2468 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2469 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002470 } else {
2471 win.mEnterAnimationPending = false;
2472 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002473 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002474 + ": mExiting=" + win.mExiting
2475 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002476 // If we are not currently running the exit animation, we
2477 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002478 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002479 // Try starting an animation; if there isn't one, we
2480 // can destroy the surface right away.
2481 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2482 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2483 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2484 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002485 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002486 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002487 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002488 win.mExiting = true;
2489 mKeyWaiter.finishedKey(session, client, true,
2490 KeyWaiter.RETURN_NOTHING);
2491 } else if (win.isAnimating()) {
2492 // Currently in a hide animation... turn this into
2493 // an exit.
2494 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002495 } else if (win == mWallpaperTarget) {
2496 // If the wallpaper is currently behind this
2497 // window, we need to change both of them inside
2498 // of a transaction to avoid artifacts.
2499 win.mExiting = true;
2500 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002501 } else {
2502 if (mInputMethodWindow == win) {
2503 mInputMethodWindow = null;
2504 }
2505 win.destroySurfaceLocked();
2506 }
2507 }
2508 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002509
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002510 if (win.mSurface == null || (win.getAttrs().flags
2511 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2512 || win.mSurfacePendingDestroy) {
2513 // We are being called from a local process, which
2514 // means outSurface holds its current surface. Ensure the
2515 // surface object is cleared, but we don't want it actually
2516 // destroyed at this point.
2517 win.mSurfacePendingDestroy = false;
2518 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002519 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002520 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002521 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002522 "Keeping surface, will report destroy: " + win);
2523 win.mReportDestroySurface = true;
2524 outSurface.copyFrom(win.mSurface);
2525 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002526 }
2527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002528 if (focusMayChange) {
2529 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2530 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 imMayMove = false;
2532 }
2533 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2534 }
Romain Guy06882f82009-06-10 13:36:04 -07002535
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002536 // updateFocusedWindowLocked() already assigned layers so we only need to
2537 // reassign them at this point if the IM window state gets shuffled
2538 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002540 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002541 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2542 // Little hack here -- we -should- be able to rely on the
2543 // function to return true if the IME has moved and needs
2544 // its layer recomputed. However, if the IME was hidden
2545 // and isn't actually moved in the list, its layer may be
2546 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 assignLayers = true;
2548 }
2549 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002550 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002551 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002552 assignLayers = true;
2553 }
2554 }
Romain Guy06882f82009-06-10 13:36:04 -07002555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002556 mLayoutNeeded = true;
2557 win.mGivenInsetsPending = insetsPending;
2558 if (assignLayers) {
2559 assignLayersLocked();
2560 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002561 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002562 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002563 if (displayed && win.mIsWallpaper) {
2564 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002565 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002566 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002567 if (win.mAppToken != null) {
2568 win.mAppToken.updateReportedVisibilityLocked();
2569 }
2570 outFrame.set(win.mFrame);
2571 outContentInsets.set(win.mContentInsets);
2572 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002573 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002574 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002575 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002576 + ", requestedHeight=" + requestedHeight
2577 + ", viewVisibility=" + viewVisibility
2578 + "\nRelayout returning frame=" + outFrame
2579 + ", surface=" + outSurface);
2580
Joe Onorato8a9b2202010-02-26 18:56:32 -08002581 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002582 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2583
2584 inTouchMode = mInTouchMode;
2585 }
2586
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002587 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002588 sendNewConfiguration();
2589 }
Romain Guy06882f82009-06-10 13:36:04 -07002590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002591 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002593 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2594 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2595 }
2596
2597 public void finishDrawingWindow(Session session, IWindow client) {
2598 final long origId = Binder.clearCallingIdentity();
2599 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002600 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002601 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002602 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2603 adjustWallpaperWindowsLocked();
2604 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002605 mLayoutNeeded = true;
2606 performLayoutAndPlaceSurfacesLocked();
2607 }
2608 }
2609 Binder.restoreCallingIdentity(origId);
2610 }
2611
2612 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002613 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002614 + (lp != null ? lp.packageName : null)
2615 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2616 if (lp != null && lp.windowAnimations != 0) {
2617 // If this is a system resource, don't try to load it from the
2618 // application resources. It is nice to avoid loading application
2619 // resources if we can.
2620 String packageName = lp.packageName != null ? lp.packageName : "android";
2621 int resId = lp.windowAnimations;
2622 if ((resId&0xFF000000) == 0x01000000) {
2623 packageName = "android";
2624 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002625 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002626 + packageName);
2627 return AttributeCache.instance().get(packageName, resId,
2628 com.android.internal.R.styleable.WindowAnimation);
2629 }
2630 return null;
2631 }
Romain Guy06882f82009-06-10 13:36:04 -07002632
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002633 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002634 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002635 + packageName + " resId=0x" + Integer.toHexString(resId));
2636 if (packageName != null) {
2637 if ((resId&0xFF000000) == 0x01000000) {
2638 packageName = "android";
2639 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002640 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002641 + packageName);
2642 return AttributeCache.instance().get(packageName, resId,
2643 com.android.internal.R.styleable.WindowAnimation);
2644 }
2645 return null;
2646 }
2647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002648 private void applyEnterAnimationLocked(WindowState win) {
2649 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2650 if (win.mEnterAnimationPending) {
2651 win.mEnterAnimationPending = false;
2652 transit = WindowManagerPolicy.TRANSIT_ENTER;
2653 }
2654
2655 applyAnimationLocked(win, transit, true);
2656 }
2657
2658 private boolean applyAnimationLocked(WindowState win,
2659 int transit, boolean isEntrance) {
2660 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2661 // If we are trying to apply an animation, but already running
2662 // an animation of the same type, then just leave that one alone.
2663 return true;
2664 }
Romain Guy06882f82009-06-10 13:36:04 -07002665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002666 // Only apply an animation if the display isn't frozen. If it is
2667 // frozen, there is no reason to animate and it can cause strange
2668 // artifacts when we unfreeze the display if some different animation
2669 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002670 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002671 int anim = mPolicy.selectAnimationLw(win, transit);
2672 int attr = -1;
2673 Animation a = null;
2674 if (anim != 0) {
2675 a = AnimationUtils.loadAnimation(mContext, anim);
2676 } else {
2677 switch (transit) {
2678 case WindowManagerPolicy.TRANSIT_ENTER:
2679 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2680 break;
2681 case WindowManagerPolicy.TRANSIT_EXIT:
2682 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2683 break;
2684 case WindowManagerPolicy.TRANSIT_SHOW:
2685 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2686 break;
2687 case WindowManagerPolicy.TRANSIT_HIDE:
2688 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2689 break;
2690 }
2691 if (attr >= 0) {
2692 a = loadAnimation(win.mAttrs, attr);
2693 }
2694 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002695 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002696 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2697 + " mAnimation=" + win.mAnimation
2698 + " isEntrance=" + isEntrance);
2699 if (a != null) {
2700 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002701 RuntimeException e = null;
2702 if (!HIDE_STACK_CRAWLS) {
2703 e = new RuntimeException();
2704 e.fillInStackTrace();
2705 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002706 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002707 }
2708 win.setAnimation(a);
2709 win.mAnimationIsEntrance = isEntrance;
2710 }
2711 } else {
2712 win.clearAnimation();
2713 }
2714
2715 return win.mAnimation != null;
2716 }
2717
2718 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2719 int anim = 0;
2720 Context context = mContext;
2721 if (animAttr >= 0) {
2722 AttributeCache.Entry ent = getCachedAnimations(lp);
2723 if (ent != null) {
2724 context = ent.context;
2725 anim = ent.array.getResourceId(animAttr, 0);
2726 }
2727 }
2728 if (anim != 0) {
2729 return AnimationUtils.loadAnimation(context, anim);
2730 }
2731 return null;
2732 }
Romain Guy06882f82009-06-10 13:36:04 -07002733
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002734 private Animation loadAnimation(String packageName, int resId) {
2735 int anim = 0;
2736 Context context = mContext;
2737 if (resId >= 0) {
2738 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2739 if (ent != null) {
2740 context = ent.context;
2741 anim = resId;
2742 }
2743 }
2744 if (anim != 0) {
2745 return AnimationUtils.loadAnimation(context, anim);
2746 }
2747 return null;
2748 }
2749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002750 private boolean applyAnimationLocked(AppWindowToken wtoken,
2751 WindowManager.LayoutParams lp, int transit, boolean enter) {
2752 // Only apply an animation if the display isn't frozen. If it is
2753 // frozen, there is no reason to animate and it can cause strange
2754 // artifacts when we unfreeze the display if some different animation
2755 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002756 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002757 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002758 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002759 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002760 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002761 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002762 } else if (mNextAppTransitionPackage != null) {
2763 a = loadAnimation(mNextAppTransitionPackage, enter ?
2764 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002765 } else {
2766 int animAttr = 0;
2767 switch (transit) {
2768 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2769 animAttr = enter
2770 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2771 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2772 break;
2773 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2774 animAttr = enter
2775 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2776 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2777 break;
2778 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2779 animAttr = enter
2780 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2781 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2782 break;
2783 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2784 animAttr = enter
2785 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2786 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2787 break;
2788 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2789 animAttr = enter
2790 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2791 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2792 break;
2793 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2794 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002795 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002796 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2797 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002798 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002799 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002800 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2801 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002802 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002803 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002804 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002805 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2806 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2807 break;
2808 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2809 animAttr = enter
2810 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2811 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2812 break;
2813 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2814 animAttr = enter
2815 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2816 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002817 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002818 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002819 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002820 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002821 + " anim=" + a
2822 + " animAttr=0x" + Integer.toHexString(animAttr)
2823 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002824 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002825 if (a != null) {
2826 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002827 RuntimeException e = null;
2828 if (!HIDE_STACK_CRAWLS) {
2829 e = new RuntimeException();
2830 e.fillInStackTrace();
2831 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002832 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002833 }
2834 wtoken.setAnimation(a);
2835 }
2836 } else {
2837 wtoken.clearAnimation();
2838 }
2839
2840 return wtoken.animation != null;
2841 }
2842
2843 // -------------------------------------------------------------
2844 // Application Window Tokens
2845 // -------------------------------------------------------------
2846
2847 public void validateAppTokens(List tokens) {
2848 int v = tokens.size()-1;
2849 int m = mAppTokens.size()-1;
2850 while (v >= 0 && m >= 0) {
2851 AppWindowToken wtoken = mAppTokens.get(m);
2852 if (wtoken.removed) {
2853 m--;
2854 continue;
2855 }
2856 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002857 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002858 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2859 }
2860 v--;
2861 m--;
2862 }
2863 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002864 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002865 v--;
2866 }
2867 while (m >= 0) {
2868 AppWindowToken wtoken = mAppTokens.get(m);
2869 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002870 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002871 }
2872 m--;
2873 }
2874 }
2875
2876 boolean checkCallingPermission(String permission, String func) {
2877 // Quick check: if the calling permission is me, it's all okay.
2878 if (Binder.getCallingPid() == Process.myPid()) {
2879 return true;
2880 }
Romain Guy06882f82009-06-10 13:36:04 -07002881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002882 if (mContext.checkCallingPermission(permission)
2883 == PackageManager.PERMISSION_GRANTED) {
2884 return true;
2885 }
2886 String msg = "Permission Denial: " + func + " from pid="
2887 + Binder.getCallingPid()
2888 + ", uid=" + Binder.getCallingUid()
2889 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002890 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002891 return false;
2892 }
Romain Guy06882f82009-06-10 13:36:04 -07002893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002894 AppWindowToken findAppWindowToken(IBinder token) {
2895 WindowToken wtoken = mTokenMap.get(token);
2896 if (wtoken == null) {
2897 return null;
2898 }
2899 return wtoken.appWindowToken;
2900 }
Romain Guy06882f82009-06-10 13:36:04 -07002901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002902 public void addWindowToken(IBinder token, int type) {
2903 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2904 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002905 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002906 }
Romain Guy06882f82009-06-10 13:36:04 -07002907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002908 synchronized(mWindowMap) {
2909 WindowToken wtoken = mTokenMap.get(token);
2910 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002911 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 return;
2913 }
2914 wtoken = new WindowToken(token, type, true);
2915 mTokenMap.put(token, wtoken);
2916 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002917 if (type == TYPE_WALLPAPER) {
2918 mWallpaperTokens.add(wtoken);
2919 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920 }
2921 }
Romain Guy06882f82009-06-10 13:36:04 -07002922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002923 public void removeWindowToken(IBinder token) {
2924 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2925 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002926 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002927 }
2928
2929 final long origId = Binder.clearCallingIdentity();
2930 synchronized(mWindowMap) {
2931 WindowToken wtoken = mTokenMap.remove(token);
2932 mTokenList.remove(wtoken);
2933 if (wtoken != null) {
2934 boolean delayed = false;
2935 if (!wtoken.hidden) {
2936 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002938 final int N = wtoken.windows.size();
2939 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002941 for (int i=0; i<N; i++) {
2942 WindowState win = wtoken.windows.get(i);
2943
2944 if (win.isAnimating()) {
2945 delayed = true;
2946 }
Romain Guy06882f82009-06-10 13:36:04 -07002947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002948 if (win.isVisibleNow()) {
2949 applyAnimationLocked(win,
2950 WindowManagerPolicy.TRANSIT_EXIT, false);
2951 mKeyWaiter.finishedKey(win.mSession, win.mClient, true,
2952 KeyWaiter.RETURN_NOTHING);
2953 changed = true;
2954 }
2955 }
2956
2957 if (changed) {
2958 mLayoutNeeded = true;
2959 performLayoutAndPlaceSurfacesLocked();
2960 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2961 }
Romain Guy06882f82009-06-10 13:36:04 -07002962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002963 if (delayed) {
2964 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002965 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2966 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002967 }
2968 }
Romain Guy06882f82009-06-10 13:36:04 -07002969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002970 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002971 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002972 }
2973 }
2974 Binder.restoreCallingIdentity(origId);
2975 }
2976
2977 public void addAppToken(int addPos, IApplicationToken token,
2978 int groupId, int requestedOrientation, boolean fullscreen) {
2979 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2980 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002981 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002982 }
Romain Guy06882f82009-06-10 13:36:04 -07002983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002984 synchronized(mWindowMap) {
2985 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2986 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002987 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002988 return;
2989 }
2990 wtoken = new AppWindowToken(token);
2991 wtoken.groupId = groupId;
2992 wtoken.appFullscreen = fullscreen;
2993 wtoken.requestedOrientation = requestedOrientation;
2994 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002995 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002996 mTokenMap.put(token.asBinder(), wtoken);
2997 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999 // Application tokens start out hidden.
3000 wtoken.hidden = true;
3001 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003003 //dump();
3004 }
3005 }
Romain Guy06882f82009-06-10 13:36:04 -07003006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003007 public void setAppGroupId(IBinder token, int groupId) {
3008 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3009 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003010 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003011 }
3012
3013 synchronized(mWindowMap) {
3014 AppWindowToken wtoken = findAppWindowToken(token);
3015 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003016 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003017 return;
3018 }
3019 wtoken.groupId = groupId;
3020 }
3021 }
Romain Guy06882f82009-06-10 13:36:04 -07003022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003023 public int getOrientationFromWindowsLocked() {
3024 int pos = mWindows.size() - 1;
3025 while (pos >= 0) {
3026 WindowState wtoken = (WindowState) mWindows.get(pos);
3027 pos--;
3028 if (wtoken.mAppToken != null) {
3029 // We hit an application window. so the orientation will be determined by the
3030 // app window. No point in continuing further.
3031 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3032 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003033 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003034 continue;
3035 }
3036 int req = wtoken.mAttrs.screenOrientation;
3037 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3038 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3039 continue;
3040 } else {
3041 return req;
3042 }
3043 }
3044 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3045 }
Romain Guy06882f82009-06-10 13:36:04 -07003046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003047 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003048 int pos = mAppTokens.size() - 1;
3049 int curGroup = 0;
3050 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3051 boolean findingBehind = false;
3052 boolean haveGroup = false;
3053 boolean lastFullscreen = false;
3054 while (pos >= 0) {
3055 AppWindowToken wtoken = mAppTokens.get(pos);
3056 pos--;
3057 // if we're about to tear down this window and not seek for
3058 // the behind activity, don't use it for orientation
3059 if (!findingBehind
3060 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3061 continue;
3062 }
3063
3064 if (!haveGroup) {
3065 // We ignore any hidden applications on the top.
3066 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003067 continue;
3068 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003069 haveGroup = true;
3070 curGroup = wtoken.groupId;
3071 lastOrientation = wtoken.requestedOrientation;
3072 } else if (curGroup != wtoken.groupId) {
3073 // If we have hit a new application group, and the bottom
3074 // of the previous group didn't explicitly say to use
3075 // the orientation behind it, and the last app was
3076 // full screen, then we'll stick with the
3077 // user's orientation.
3078 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3079 && lastFullscreen) {
3080 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003081 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003082 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003083 int or = wtoken.requestedOrientation;
3084 // If this application is fullscreen, and didn't explicitly say
3085 // to use the orientation behind it, then just take whatever
3086 // orientation it has and ignores whatever is under it.
3087 lastFullscreen = wtoken.appFullscreen;
3088 if (lastFullscreen
3089 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3090 return or;
3091 }
3092 // If this application has requested an explicit orientation,
3093 // then use it.
3094 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3095 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3096 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3097 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3098 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3099 return or;
3100 }
3101 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3102 }
3103 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003104 }
Romain Guy06882f82009-06-10 13:36:04 -07003105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003106 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003107 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003108 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3109 "updateOrientationFromAppTokens()")) {
3110 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3111 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003112
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003113 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003114 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003115
3116 synchronized(mWindowMap) {
3117 if (updateOrientationFromAppTokensLocked()) {
3118 if (freezeThisOneIfNeeded != null) {
3119 AppWindowToken wtoken = findAppWindowToken(
3120 freezeThisOneIfNeeded);
3121 if (wtoken != null) {
3122 startAppFreezingScreenLocked(wtoken,
3123 ActivityInfo.CONFIG_ORIENTATION);
3124 }
3125 }
3126 config = computeNewConfigurationLocked();
3127
3128 } else if (currentConfig != null) {
3129 // No obvious action we need to take, but if our current
3130 // state mismatches the activity maanager's, update it
3131 mTempConfiguration.setToDefaults();
3132 if (computeNewConfigurationLocked(mTempConfiguration)) {
3133 if (currentConfig.diff(mTempConfiguration) != 0) {
3134 mWaitingForConfig = true;
3135 mLayoutNeeded = true;
3136 startFreezingDisplayLocked();
3137 config = new Configuration(mTempConfiguration);
3138 }
3139 }
3140 }
3141 }
3142
Dianne Hackborncfaef692009-06-15 14:24:44 -07003143 Binder.restoreCallingIdentity(ident);
3144 return config;
3145 }
3146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003147 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003148 * Determine the new desired orientation of the display, returning
3149 * a non-null new Configuration if it has changed from the current
3150 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3151 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3152 * SCREEN. This will typically be done for you if you call
3153 * sendNewConfiguration().
3154 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003155 * The orientation is computed from non-application windows first. If none of
3156 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003157 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003158 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3159 * android.os.IBinder)
3160 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003161 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003162 if (mDisplayFrozen) {
3163 // If the display is frozen, some activities may be in the middle
3164 // of restarting, and thus have removed their old window. If the
3165 // window has the flag to hide the lock screen, then the lock screen
3166 // can re-appear and inflict its own orientation on us. Keep the
3167 // orientation stable until this all settles down.
3168 return false;
3169 }
3170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003171 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003172 long ident = Binder.clearCallingIdentity();
3173 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003174 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003176 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003177 mForcedAppOrientation = req;
3178 //send a message to Policy indicating orientation change to take
3179 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003180 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003181 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3182 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3183 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003184 }
3185 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003186
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003187 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003188 } finally {
3189 Binder.restoreCallingIdentity(ident);
3190 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003191 }
Romain Guy06882f82009-06-10 13:36:04 -07003192
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003193 int computeForcedAppOrientationLocked() {
3194 int req = getOrientationFromWindowsLocked();
3195 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3196 req = getOrientationFromAppTokensLocked();
3197 }
3198 return req;
3199 }
Romain Guy06882f82009-06-10 13:36:04 -07003200
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003201 public void setNewConfiguration(Configuration config) {
3202 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3203 "setNewConfiguration()")) {
3204 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3205 }
3206
3207 synchronized(mWindowMap) {
3208 mCurConfiguration = new Configuration(config);
3209 mWaitingForConfig = false;
3210 performLayoutAndPlaceSurfacesLocked();
3211 }
3212 }
3213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003214 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3215 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3216 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003217 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003218 }
Romain Guy06882f82009-06-10 13:36:04 -07003219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003220 synchronized(mWindowMap) {
3221 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3222 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003223 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003224 return;
3225 }
Romain Guy06882f82009-06-10 13:36:04 -07003226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003227 wtoken.requestedOrientation = requestedOrientation;
3228 }
3229 }
Romain Guy06882f82009-06-10 13:36:04 -07003230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003231 public int getAppOrientation(IApplicationToken token) {
3232 synchronized(mWindowMap) {
3233 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3234 if (wtoken == null) {
3235 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3236 }
Romain Guy06882f82009-06-10 13:36:04 -07003237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003238 return wtoken.requestedOrientation;
3239 }
3240 }
Romain Guy06882f82009-06-10 13:36:04 -07003241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003242 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3243 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3244 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003245 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003246 }
3247
3248 synchronized(mWindowMap) {
3249 boolean changed = false;
3250 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003251 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003252 changed = mFocusedApp != null;
3253 mFocusedApp = null;
3254 mKeyWaiter.tickle();
3255 } else {
3256 AppWindowToken newFocus = findAppWindowToken(token);
3257 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003258 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003259 return;
3260 }
3261 changed = mFocusedApp != newFocus;
3262 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003263 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003264 mKeyWaiter.tickle();
3265 }
3266
3267 if (moveFocusNow && changed) {
3268 final long origId = Binder.clearCallingIdentity();
3269 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3270 Binder.restoreCallingIdentity(origId);
3271 }
3272 }
3273 }
3274
3275 public void prepareAppTransition(int transit) {
3276 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3277 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003278 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003279 }
Romain Guy06882f82009-06-10 13:36:04 -07003280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003281 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003282 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003283 TAG, "Prepare app transition: transit=" + transit
3284 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003285 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003286 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3287 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003288 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003289 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3290 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3291 // Opening a new task always supersedes a close for the anim.
3292 mNextAppTransition = transit;
3293 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3294 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3295 // Opening a new activity always supersedes a close for the anim.
3296 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003297 }
3298 mAppTransitionReady = false;
3299 mAppTransitionTimeout = false;
3300 mStartingIconInTransition = false;
3301 mSkipAppTransitionAnimation = false;
3302 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3303 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3304 5000);
3305 }
3306 }
3307 }
3308
3309 public int getPendingAppTransition() {
3310 return mNextAppTransition;
3311 }
Romain Guy06882f82009-06-10 13:36:04 -07003312
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003313 public void overridePendingAppTransition(String packageName,
3314 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003315 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003316 mNextAppTransitionPackage = packageName;
3317 mNextAppTransitionEnter = enterAnim;
3318 mNextAppTransitionExit = exitAnim;
3319 }
3320 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003322 public void executeAppTransition() {
3323 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3324 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003325 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003326 }
Romain Guy06882f82009-06-10 13:36:04 -07003327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003328 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003329 if (DEBUG_APP_TRANSITIONS) {
3330 RuntimeException e = new RuntimeException("here");
3331 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003332 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003333 + mNextAppTransition, e);
3334 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003335 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003336 mAppTransitionReady = true;
3337 final long origId = Binder.clearCallingIdentity();
3338 performLayoutAndPlaceSurfacesLocked();
3339 Binder.restoreCallingIdentity(origId);
3340 }
3341 }
3342 }
3343
3344 public void setAppStartingWindow(IBinder token, String pkg,
3345 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3346 IBinder transferFrom, boolean createIfNeeded) {
3347 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3348 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003349 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003350 }
3351
3352 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003353 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003354 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3355 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003357 AppWindowToken wtoken = findAppWindowToken(token);
3358 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003359 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003360 return;
3361 }
3362
3363 // If the display is frozen, we won't do anything until the
3364 // actual window is displayed so there is no reason to put in
3365 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003366 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003367 return;
3368 }
Romain Guy06882f82009-06-10 13:36:04 -07003369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003370 if (wtoken.startingData != null) {
3371 return;
3372 }
Romain Guy06882f82009-06-10 13:36:04 -07003373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003374 if (transferFrom != null) {
3375 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3376 if (ttoken != null) {
3377 WindowState startingWindow = ttoken.startingWindow;
3378 if (startingWindow != null) {
3379 if (mStartingIconInTransition) {
3380 // In this case, the starting icon has already
3381 // been displayed, so start letting windows get
3382 // shown immediately without any more transitions.
3383 mSkipAppTransitionAnimation = true;
3384 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003385 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003386 "Moving existing starting from " + ttoken
3387 + " to " + wtoken);
3388 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003390 // Transfer the starting window over to the new
3391 // token.
3392 wtoken.startingData = ttoken.startingData;
3393 wtoken.startingView = ttoken.startingView;
3394 wtoken.startingWindow = startingWindow;
3395 ttoken.startingData = null;
3396 ttoken.startingView = null;
3397 ttoken.startingWindow = null;
3398 ttoken.startingMoved = true;
3399 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003400 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003401 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003402 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003403 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003404 mWindows.remove(startingWindow);
3405 ttoken.windows.remove(startingWindow);
3406 ttoken.allAppWindows.remove(startingWindow);
3407 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003409 // Propagate other interesting state between the
3410 // tokens. If the old token is displayed, we should
3411 // immediately force the new one to be displayed. If
3412 // it is animating, we need to move that animation to
3413 // the new one.
3414 if (ttoken.allDrawn) {
3415 wtoken.allDrawn = true;
3416 }
3417 if (ttoken.firstWindowDrawn) {
3418 wtoken.firstWindowDrawn = true;
3419 }
3420 if (!ttoken.hidden) {
3421 wtoken.hidden = false;
3422 wtoken.hiddenRequested = false;
3423 wtoken.willBeHidden = false;
3424 }
3425 if (wtoken.clientHidden != ttoken.clientHidden) {
3426 wtoken.clientHidden = ttoken.clientHidden;
3427 wtoken.sendAppVisibilityToClients();
3428 }
3429 if (ttoken.animation != null) {
3430 wtoken.animation = ttoken.animation;
3431 wtoken.animating = ttoken.animating;
3432 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3433 ttoken.animation = null;
3434 ttoken.animLayerAdjustment = 0;
3435 wtoken.updateLayers();
3436 ttoken.updateLayers();
3437 }
Romain Guy06882f82009-06-10 13:36:04 -07003438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003439 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003440 mLayoutNeeded = true;
3441 performLayoutAndPlaceSurfacesLocked();
3442 Binder.restoreCallingIdentity(origId);
3443 return;
3444 } else if (ttoken.startingData != null) {
3445 // The previous app was getting ready to show a
3446 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003447 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003448 "Moving pending starting from " + ttoken
3449 + " to " + wtoken);
3450 wtoken.startingData = ttoken.startingData;
3451 ttoken.startingData = null;
3452 ttoken.startingMoved = true;
3453 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3454 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3455 // want to process the message ASAP, before any other queued
3456 // messages.
3457 mH.sendMessageAtFrontOfQueue(m);
3458 return;
3459 }
3460 }
3461 }
3462
3463 // There is no existing starting window, and the caller doesn't
3464 // want us to create one, so that's it!
3465 if (!createIfNeeded) {
3466 return;
3467 }
Romain Guy06882f82009-06-10 13:36:04 -07003468
Dianne Hackborn284ac932009-08-28 10:34:25 -07003469 // If this is a translucent or wallpaper window, then don't
3470 // show a starting window -- the current effect (a full-screen
3471 // opaque starting window that fades away to the real contents
3472 // when it is ready) does not work for this.
3473 if (theme != 0) {
3474 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3475 com.android.internal.R.styleable.Window);
3476 if (ent.array.getBoolean(
3477 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3478 return;
3479 }
3480 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003481 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3482 return;
3483 }
3484 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003485 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3486 return;
3487 }
3488 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003490 mStartingIconInTransition = true;
3491 wtoken.startingData = new StartingData(
3492 pkg, theme, nonLocalizedLabel,
3493 labelRes, icon);
3494 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3495 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3496 // want to process the message ASAP, before any other queued
3497 // messages.
3498 mH.sendMessageAtFrontOfQueue(m);
3499 }
3500 }
3501
3502 public void setAppWillBeHidden(IBinder token) {
3503 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3504 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003505 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003506 }
3507
3508 AppWindowToken wtoken;
3509
3510 synchronized(mWindowMap) {
3511 wtoken = findAppWindowToken(token);
3512 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003513 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 -08003514 return;
3515 }
3516 wtoken.willBeHidden = true;
3517 }
3518 }
Romain Guy06882f82009-06-10 13:36:04 -07003519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003520 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3521 boolean visible, int transit, boolean performLayout) {
3522 boolean delayed = false;
3523
3524 if (wtoken.clientHidden == visible) {
3525 wtoken.clientHidden = !visible;
3526 wtoken.sendAppVisibilityToClients();
3527 }
Romain Guy06882f82009-06-10 13:36:04 -07003528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003529 wtoken.willBeHidden = false;
3530 if (wtoken.hidden == visible) {
3531 final int N = wtoken.allAppWindows.size();
3532 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003533 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003534 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3535 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003537 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003538
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003539 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003540 if (wtoken.animation == sDummyAnimation) {
3541 wtoken.animation = null;
3542 }
3543 applyAnimationLocked(wtoken, lp, transit, visible);
3544 changed = true;
3545 if (wtoken.animation != null) {
3546 delayed = runningAppAnimation = true;
3547 }
3548 }
Romain Guy06882f82009-06-10 13:36:04 -07003549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003550 for (int i=0; i<N; i++) {
3551 WindowState win = wtoken.allAppWindows.get(i);
3552 if (win == wtoken.startingWindow) {
3553 continue;
3554 }
3555
3556 if (win.isAnimating()) {
3557 delayed = true;
3558 }
Romain Guy06882f82009-06-10 13:36:04 -07003559
Joe Onorato8a9b2202010-02-26 18:56:32 -08003560 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003561 //win.dump(" ");
3562 if (visible) {
3563 if (!win.isVisibleNow()) {
3564 if (!runningAppAnimation) {
3565 applyAnimationLocked(win,
3566 WindowManagerPolicy.TRANSIT_ENTER, true);
3567 }
3568 changed = true;
3569 }
3570 } else if (win.isVisibleNow()) {
3571 if (!runningAppAnimation) {
3572 applyAnimationLocked(win,
3573 WindowManagerPolicy.TRANSIT_EXIT, false);
3574 }
3575 mKeyWaiter.finishedKey(win.mSession, win.mClient, true,
3576 KeyWaiter.RETURN_NOTHING);
3577 changed = true;
3578 }
3579 }
3580
3581 wtoken.hidden = wtoken.hiddenRequested = !visible;
3582 if (!visible) {
3583 unsetAppFreezingScreenLocked(wtoken, true, true);
3584 } else {
3585 // If we are being set visible, and the starting window is
3586 // not yet displayed, then make sure it doesn't get displayed.
3587 WindowState swin = wtoken.startingWindow;
3588 if (swin != null && (swin.mDrawPending
3589 || swin.mCommitDrawPending)) {
3590 swin.mPolicyVisibility = false;
3591 swin.mPolicyVisibilityAfterAnim = false;
3592 }
3593 }
Romain Guy06882f82009-06-10 13:36:04 -07003594
Joe Onorato8a9b2202010-02-26 18:56:32 -08003595 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003596 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3597 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003598
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003599 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003600 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003601 if (performLayout) {
3602 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3603 performLayoutAndPlaceSurfacesLocked();
3604 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003605 }
3606 }
3607
3608 if (wtoken.animation != null) {
3609 delayed = true;
3610 }
Romain Guy06882f82009-06-10 13:36:04 -07003611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003612 return delayed;
3613 }
3614
3615 public void setAppVisibility(IBinder token, boolean visible) {
3616 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3617 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003618 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003619 }
3620
3621 AppWindowToken wtoken;
3622
3623 synchronized(mWindowMap) {
3624 wtoken = findAppWindowToken(token);
3625 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003626 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003627 return;
3628 }
3629
3630 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003631 RuntimeException e = null;
3632 if (!HIDE_STACK_CRAWLS) {
3633 e = new RuntimeException();
3634 e.fillInStackTrace();
3635 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003636 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003637 + "): mNextAppTransition=" + mNextAppTransition
3638 + " hidden=" + wtoken.hidden
3639 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3640 }
Romain Guy06882f82009-06-10 13:36:04 -07003641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003642 // If we are preparing an app transition, then delay changing
3643 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003644 if (!mDisplayFrozen && mPolicy.isScreenOn()
3645 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003646 // Already in requested state, don't do anything more.
3647 if (wtoken.hiddenRequested != visible) {
3648 return;
3649 }
3650 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003651
Joe Onorato8a9b2202010-02-26 18:56:32 -08003652 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003653 TAG, "Setting dummy animation on: " + wtoken);
3654 wtoken.setDummyAnimation();
3655 mOpeningApps.remove(wtoken);
3656 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003657 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003658 wtoken.inPendingTransaction = true;
3659 if (visible) {
3660 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003661 wtoken.startingDisplayed = false;
3662 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003663
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003664 // If the token is currently hidden (should be the
3665 // common case), then we need to set up to wait for
3666 // its windows to be ready.
3667 if (wtoken.hidden) {
3668 wtoken.allDrawn = false;
3669 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003670
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003671 if (wtoken.clientHidden) {
3672 // In the case where we are making an app visible
3673 // but holding off for a transition, we still need
3674 // to tell the client to make its windows visible so
3675 // they get drawn. Otherwise, we will wait on
3676 // performing the transition until all windows have
3677 // been drawn, they never will be, and we are sad.
3678 wtoken.clientHidden = false;
3679 wtoken.sendAppVisibilityToClients();
3680 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003681 }
3682 } else {
3683 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003684
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003685 // If the token is currently visible (should be the
3686 // common case), then set up to wait for it to be hidden.
3687 if (!wtoken.hidden) {
3688 wtoken.waitingToHide = true;
3689 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003690 }
3691 return;
3692 }
Romain Guy06882f82009-06-10 13:36:04 -07003693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003694 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003695 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003696 wtoken.updateReportedVisibilityLocked();
3697 Binder.restoreCallingIdentity(origId);
3698 }
3699 }
3700
3701 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3702 boolean unfreezeSurfaceNow, boolean force) {
3703 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003704 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003705 + " force=" + force);
3706 final int N = wtoken.allAppWindows.size();
3707 boolean unfrozeWindows = false;
3708 for (int i=0; i<N; i++) {
3709 WindowState w = wtoken.allAppWindows.get(i);
3710 if (w.mAppFreezing) {
3711 w.mAppFreezing = false;
3712 if (w.mSurface != null && !w.mOrientationChanging) {
3713 w.mOrientationChanging = true;
3714 }
3715 unfrozeWindows = true;
3716 }
3717 }
3718 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003719 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003720 wtoken.freezingScreen = false;
3721 mAppsFreezingScreen--;
3722 }
3723 if (unfreezeSurfaceNow) {
3724 if (unfrozeWindows) {
3725 mLayoutNeeded = true;
3726 performLayoutAndPlaceSurfacesLocked();
3727 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003728 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003729 }
3730 }
3731 }
Romain Guy06882f82009-06-10 13:36:04 -07003732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003733 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3734 int configChanges) {
3735 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003736 RuntimeException e = null;
3737 if (!HIDE_STACK_CRAWLS) {
3738 e = new RuntimeException();
3739 e.fillInStackTrace();
3740 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003741 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003742 + ": hidden=" + wtoken.hidden + " freezing="
3743 + wtoken.freezingScreen, e);
3744 }
3745 if (!wtoken.hiddenRequested) {
3746 if (!wtoken.freezingScreen) {
3747 wtoken.freezingScreen = true;
3748 mAppsFreezingScreen++;
3749 if (mAppsFreezingScreen == 1) {
3750 startFreezingDisplayLocked();
3751 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3752 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3753 5000);
3754 }
3755 }
3756 final int N = wtoken.allAppWindows.size();
3757 for (int i=0; i<N; i++) {
3758 WindowState w = wtoken.allAppWindows.get(i);
3759 w.mAppFreezing = true;
3760 }
3761 }
3762 }
Romain Guy06882f82009-06-10 13:36:04 -07003763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003764 public void startAppFreezingScreen(IBinder token, int configChanges) {
3765 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3766 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003767 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003768 }
3769
3770 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003771 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003772 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003773 return;
3774 }
Romain Guy06882f82009-06-10 13:36:04 -07003775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003776 AppWindowToken wtoken = findAppWindowToken(token);
3777 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003778 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003779 return;
3780 }
3781 final long origId = Binder.clearCallingIdentity();
3782 startAppFreezingScreenLocked(wtoken, configChanges);
3783 Binder.restoreCallingIdentity(origId);
3784 }
3785 }
Romain Guy06882f82009-06-10 13:36:04 -07003786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003787 public void stopAppFreezingScreen(IBinder token, boolean force) {
3788 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3789 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003790 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003791 }
3792
3793 synchronized(mWindowMap) {
3794 AppWindowToken wtoken = findAppWindowToken(token);
3795 if (wtoken == null || wtoken.appToken == null) {
3796 return;
3797 }
3798 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003799 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003800 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3801 unsetAppFreezingScreenLocked(wtoken, true, force);
3802 Binder.restoreCallingIdentity(origId);
3803 }
3804 }
Romain Guy06882f82009-06-10 13:36:04 -07003805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 public void removeAppToken(IBinder token) {
3807 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3808 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003809 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003810 }
3811
3812 AppWindowToken wtoken = null;
3813 AppWindowToken startingToken = null;
3814 boolean delayed = false;
3815
3816 final long origId = Binder.clearCallingIdentity();
3817 synchronized(mWindowMap) {
3818 WindowToken basewtoken = mTokenMap.remove(token);
3819 mTokenList.remove(basewtoken);
3820 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003821 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003822 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003823 wtoken.inPendingTransaction = false;
3824 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003825 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 if (mClosingApps.contains(wtoken)) {
3827 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003828 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003829 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003830 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003831 delayed = true;
3832 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003833 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003834 TAG, "Removing app " + wtoken + " delayed=" + delayed
3835 + " animation=" + wtoken.animation
3836 + " animating=" + wtoken.animating);
3837 if (delayed) {
3838 // set the token aside because it has an active animation to be finished
3839 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003840 } else {
3841 // Make sure there is no animation running on this token,
3842 // so any windows associated with it will be removed as
3843 // soon as their animations are complete
3844 wtoken.animation = null;
3845 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003846 }
3847 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003848 if (mLastEnterAnimToken == wtoken) {
3849 mLastEnterAnimToken = null;
3850 mLastEnterAnimParams = null;
3851 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003852 wtoken.removed = true;
3853 if (wtoken.startingData != null) {
3854 startingToken = wtoken;
3855 }
3856 unsetAppFreezingScreenLocked(wtoken, true, true);
3857 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003858 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003859 mFocusedApp = null;
3860 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3861 mKeyWaiter.tickle();
3862 }
3863 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003864 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003865 }
Romain Guy06882f82009-06-10 13:36:04 -07003866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003867 if (!delayed && wtoken != null) {
3868 wtoken.updateReportedVisibilityLocked();
3869 }
3870 }
3871 Binder.restoreCallingIdentity(origId);
3872
3873 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003874 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003875 + startingToken + ": app token removed");
3876 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3877 mH.sendMessage(m);
3878 }
3879 }
3880
3881 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3882 final int NW = token.windows.size();
3883 for (int i=0; i<NW; i++) {
3884 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003885 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003886 mWindows.remove(win);
3887 int j = win.mChildWindows.size();
3888 while (j > 0) {
3889 j--;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003890 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003891 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003892 "Tmp removing child window " + cwin);
3893 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003894 }
3895 }
3896 return NW > 0;
3897 }
3898
3899 void dumpAppTokensLocked() {
3900 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003901 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003902 }
3903 }
Romain Guy06882f82009-06-10 13:36:04 -07003904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003905 void dumpWindowsLocked() {
3906 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003907 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003908 }
3909 }
Romain Guy06882f82009-06-10 13:36:04 -07003910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003911 private int findWindowOffsetLocked(int tokenPos) {
3912 final int NW = mWindows.size();
3913
3914 if (tokenPos >= mAppTokens.size()) {
3915 int i = NW;
3916 while (i > 0) {
3917 i--;
3918 WindowState win = (WindowState)mWindows.get(i);
3919 if (win.getAppToken() != null) {
3920 return i+1;
3921 }
3922 }
3923 }
3924
3925 while (tokenPos > 0) {
3926 // Find the first app token below the new position that has
3927 // a window displayed.
3928 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003929 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003930 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003931 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003932 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003933 "Skipping token -- currently sending to bottom");
3934 tokenPos--;
3935 continue;
3936 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003937 int i = wtoken.windows.size();
3938 while (i > 0) {
3939 i--;
3940 WindowState win = wtoken.windows.get(i);
3941 int j = win.mChildWindows.size();
3942 while (j > 0) {
3943 j--;
3944 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003945 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003946 for (int pos=NW-1; pos>=0; pos--) {
3947 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003948 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003949 "Found child win @" + (pos+1));
3950 return pos+1;
3951 }
3952 }
3953 }
3954 }
3955 for (int pos=NW-1; pos>=0; pos--) {
3956 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003957 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003958 return pos+1;
3959 }
3960 }
3961 }
3962 tokenPos--;
3963 }
3964
3965 return 0;
3966 }
3967
3968 private final int reAddWindowLocked(int index, WindowState win) {
3969 final int NCW = win.mChildWindows.size();
3970 boolean added = false;
3971 for (int j=0; j<NCW; j++) {
3972 WindowState cwin = (WindowState)win.mChildWindows.get(j);
3973 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003974 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003975 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003976 mWindows.add(index, win);
3977 index++;
3978 added = true;
3979 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003980 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003981 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003982 mWindows.add(index, cwin);
3983 index++;
3984 }
3985 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003986 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003987 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003988 mWindows.add(index, win);
3989 index++;
3990 }
3991 return index;
3992 }
Romain Guy06882f82009-06-10 13:36:04 -07003993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003994 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3995 final int NW = token.windows.size();
3996 for (int i=0; i<NW; i++) {
3997 index = reAddWindowLocked(index, token.windows.get(i));
3998 }
3999 return index;
4000 }
4001
4002 public void moveAppToken(int index, IBinder token) {
4003 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4004 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004005 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004006 }
4007
4008 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004009 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004010 if (DEBUG_REORDER) dumpAppTokensLocked();
4011 final AppWindowToken wtoken = findAppWindowToken(token);
4012 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004013 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004014 + token + " (" + wtoken + ")");
4015 return;
4016 }
4017 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004018 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004019 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004021 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004022 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004023 if (DEBUG_REORDER) dumpWindowsLocked();
4024 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004025 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004026 if (DEBUG_REORDER) dumpWindowsLocked();
4027 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004028 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004029 if (DEBUG_REORDER) dumpWindowsLocked();
4030 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004031 mLayoutNeeded = true;
4032 performLayoutAndPlaceSurfacesLocked();
4033 }
4034 Binder.restoreCallingIdentity(origId);
4035 }
4036 }
4037
4038 private void removeAppTokensLocked(List<IBinder> tokens) {
4039 // XXX This should be done more efficiently!
4040 // (take advantage of the fact that both lists should be
4041 // ordered in the same way.)
4042 int N = tokens.size();
4043 for (int i=0; i<N; i++) {
4044 IBinder token = tokens.get(i);
4045 final AppWindowToken wtoken = findAppWindowToken(token);
4046 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004047 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004048 + token + " (" + wtoken + ")");
4049 i--;
4050 N--;
4051 }
4052 }
4053 }
4054
Dianne Hackborna8f60182009-09-01 19:01:50 -07004055 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4056 boolean updateFocusAndLayout) {
4057 // First remove all of the windows from the list.
4058 tmpRemoveAppWindowsLocked(wtoken);
4059
4060 // Where to start adding?
4061 int pos = findWindowOffsetLocked(tokenPos);
4062
4063 // And now add them back at the correct place.
4064 pos = reAddAppWindowsLocked(pos, wtoken);
4065
4066 if (updateFocusAndLayout) {
4067 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4068 assignLayersLocked();
4069 }
4070 mLayoutNeeded = true;
4071 performLayoutAndPlaceSurfacesLocked();
4072 }
4073 }
4074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004075 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4076 // First remove all of the windows from the list.
4077 final int N = tokens.size();
4078 int i;
4079 for (i=0; i<N; i++) {
4080 WindowToken token = mTokenMap.get(tokens.get(i));
4081 if (token != null) {
4082 tmpRemoveAppWindowsLocked(token);
4083 }
4084 }
4085
4086 // Where to start adding?
4087 int pos = findWindowOffsetLocked(tokenPos);
4088
4089 // And now add them back at the correct place.
4090 for (i=0; i<N; i++) {
4091 WindowToken token = mTokenMap.get(tokens.get(i));
4092 if (token != null) {
4093 pos = reAddAppWindowsLocked(pos, token);
4094 }
4095 }
4096
Dianne Hackborna8f60182009-09-01 19:01:50 -07004097 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4098 assignLayersLocked();
4099 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004100 mLayoutNeeded = true;
4101 performLayoutAndPlaceSurfacesLocked();
4102
4103 //dump();
4104 }
4105
4106 public void moveAppTokensToTop(List<IBinder> tokens) {
4107 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4108 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004109 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004110 }
4111
4112 final long origId = Binder.clearCallingIdentity();
4113 synchronized(mWindowMap) {
4114 removeAppTokensLocked(tokens);
4115 final int N = tokens.size();
4116 for (int i=0; i<N; i++) {
4117 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4118 if (wt != null) {
4119 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004120 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004121 mToTopApps.remove(wt);
4122 mToBottomApps.remove(wt);
4123 mToTopApps.add(wt);
4124 wt.sendingToBottom = false;
4125 wt.sendingToTop = true;
4126 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004127 }
4128 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004129
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004130 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004131 moveAppWindowsLocked(tokens, mAppTokens.size());
4132 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004133 }
4134 Binder.restoreCallingIdentity(origId);
4135 }
4136
4137 public void moveAppTokensToBottom(List<IBinder> tokens) {
4138 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4139 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004140 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004141 }
4142
4143 final long origId = Binder.clearCallingIdentity();
4144 synchronized(mWindowMap) {
4145 removeAppTokensLocked(tokens);
4146 final int N = tokens.size();
4147 int pos = 0;
4148 for (int i=0; i<N; i++) {
4149 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4150 if (wt != null) {
4151 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004152 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004153 mToTopApps.remove(wt);
4154 mToBottomApps.remove(wt);
4155 mToBottomApps.add(i, wt);
4156 wt.sendingToTop = false;
4157 wt.sendingToBottom = true;
4158 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004159 pos++;
4160 }
4161 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004162
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004163 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004164 moveAppWindowsLocked(tokens, 0);
4165 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004166 }
4167 Binder.restoreCallingIdentity(origId);
4168 }
4169
4170 // -------------------------------------------------------------
4171 // Misc IWindowSession methods
4172 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004174 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004175 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004176 != PackageManager.PERMISSION_GRANTED) {
4177 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4178 }
Mike Lockwood983ee092009-11-22 01:42:24 -05004179 synchronized (mKeyguardTokenWatcher) {
4180 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004181 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004182 }
4183
4184 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004185 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004186 != PackageManager.PERMISSION_GRANTED) {
4187 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4188 }
Mike Lockwood983ee092009-11-22 01:42:24 -05004189 synchronized (mKeyguardTokenWatcher) {
4190 mKeyguardTokenWatcher.release(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004191
Mike Lockwood983ee092009-11-22 01:42:24 -05004192 if (!mKeyguardTokenWatcher.isAcquired()) {
4193 // If we are the last one to reenable the keyguard wait until
4194 // we have actaully finished reenabling until returning.
4195 // It is possible that reenableKeyguard() can be called before
4196 // the previous disableKeyguard() is handled, in which case
4197 // neither mKeyguardTokenWatcher.acquired() or released() would
4198 // be called. In that case mKeyguardDisabled will be false here
4199 // and we have nothing to wait for.
4200 while (mKeyguardDisabled) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004201 try {
Mike Lockwood983ee092009-11-22 01:42:24 -05004202 mKeyguardTokenWatcher.wait();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004203 } catch (InterruptedException e) {
4204 Thread.currentThread().interrupt();
4205 }
4206 }
4207 }
4208 }
4209 }
4210
4211 /**
4212 * @see android.app.KeyguardManager#exitKeyguardSecurely
4213 */
4214 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004215 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004216 != PackageManager.PERMISSION_GRANTED) {
4217 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4218 }
4219 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4220 public void onKeyguardExitResult(boolean success) {
4221 try {
4222 callback.onKeyguardExitResult(success);
4223 } catch (RemoteException e) {
4224 // Client has died, we don't care.
4225 }
4226 }
4227 });
4228 }
4229
4230 public boolean inKeyguardRestrictedInputMode() {
4231 return mPolicy.inKeyguardRestrictedKeyInputMode();
4232 }
Romain Guy06882f82009-06-10 13:36:04 -07004233
Dianne Hackbornffa42482009-09-23 22:20:11 -07004234 public void closeSystemDialogs(String reason) {
4235 synchronized(mWindowMap) {
4236 for (int i=mWindows.size()-1; i>=0; i--) {
4237 WindowState w = (WindowState)mWindows.get(i);
4238 if (w.mSurface != null) {
4239 try {
4240 w.mClient.closeSystemDialogs(reason);
4241 } catch (RemoteException e) {
4242 }
4243 }
4244 }
4245 }
4246 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004248 static float fixScale(float scale) {
4249 if (scale < 0) scale = 0;
4250 else if (scale > 20) scale = 20;
4251 return Math.abs(scale);
4252 }
Romain Guy06882f82009-06-10 13:36:04 -07004253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004254 public void setAnimationScale(int which, float scale) {
4255 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4256 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004257 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004258 }
4259
4260 if (scale < 0) scale = 0;
4261 else if (scale > 20) scale = 20;
4262 scale = Math.abs(scale);
4263 switch (which) {
4264 case 0: mWindowAnimationScale = fixScale(scale); break;
4265 case 1: mTransitionAnimationScale = fixScale(scale); break;
4266 }
Romain Guy06882f82009-06-10 13:36:04 -07004267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004268 // Persist setting
4269 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4270 }
Romain Guy06882f82009-06-10 13:36:04 -07004271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004272 public void setAnimationScales(float[] scales) {
4273 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4274 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004275 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004276 }
4277
4278 if (scales != null) {
4279 if (scales.length >= 1) {
4280 mWindowAnimationScale = fixScale(scales[0]);
4281 }
4282 if (scales.length >= 2) {
4283 mTransitionAnimationScale = fixScale(scales[1]);
4284 }
4285 }
Romain Guy06882f82009-06-10 13:36:04 -07004286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004287 // Persist setting
4288 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4289 }
Romain Guy06882f82009-06-10 13:36:04 -07004290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004291 public float getAnimationScale(int which) {
4292 switch (which) {
4293 case 0: return mWindowAnimationScale;
4294 case 1: return mTransitionAnimationScale;
4295 }
4296 return 0;
4297 }
Romain Guy06882f82009-06-10 13:36:04 -07004298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004299 public float[] getAnimationScales() {
4300 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4301 }
Romain Guy06882f82009-06-10 13:36:04 -07004302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004303 public int getSwitchState(int sw) {
4304 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4305 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004306 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004307 }
4308 return KeyInputQueue.getSwitchState(sw);
4309 }
Romain Guy06882f82009-06-10 13:36:04 -07004310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004311 public int getSwitchStateForDevice(int devid, int sw) {
4312 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4313 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004314 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004315 }
4316 return KeyInputQueue.getSwitchState(devid, sw);
4317 }
Romain Guy06882f82009-06-10 13:36:04 -07004318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004319 public int getScancodeState(int sw) {
4320 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4321 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004322 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004323 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004324 return mQueue.getScancodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004325 }
Romain Guy06882f82009-06-10 13:36:04 -07004326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004327 public int getScancodeStateForDevice(int devid, int sw) {
4328 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4329 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004330 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004331 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004332 return mQueue.getScancodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004333 }
Romain Guy06882f82009-06-10 13:36:04 -07004334
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004335 public int getTrackballScancodeState(int sw) {
4336 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4337 "getTrackballScancodeState()")) {
4338 throw new SecurityException("Requires READ_INPUT_STATE permission");
4339 }
4340 return mQueue.getTrackballScancodeState(sw);
4341 }
4342
4343 public int getDPadScancodeState(int sw) {
4344 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4345 "getDPadScancodeState()")) {
4346 throw new SecurityException("Requires READ_INPUT_STATE permission");
4347 }
4348 return mQueue.getDPadScancodeState(sw);
4349 }
4350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004351 public int getKeycodeState(int sw) {
4352 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4353 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004354 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004355 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004356 return mQueue.getKeycodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004357 }
Romain Guy06882f82009-06-10 13:36:04 -07004358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004359 public int getKeycodeStateForDevice(int devid, int sw) {
4360 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4361 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004362 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004363 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004364 return mQueue.getKeycodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004365 }
Romain Guy06882f82009-06-10 13:36:04 -07004366
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004367 public int getTrackballKeycodeState(int sw) {
4368 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4369 "getTrackballKeycodeState()")) {
4370 throw new SecurityException("Requires READ_INPUT_STATE permission");
4371 }
4372 return mQueue.getTrackballKeycodeState(sw);
4373 }
4374
4375 public int getDPadKeycodeState(int sw) {
4376 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4377 "getDPadKeycodeState()")) {
4378 throw new SecurityException("Requires READ_INPUT_STATE permission");
4379 }
4380 return mQueue.getDPadKeycodeState(sw);
4381 }
4382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004383 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
4384 return KeyInputQueue.hasKeys(keycodes, keyExists);
4385 }
Romain Guy06882f82009-06-10 13:36:04 -07004386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004387 public void enableScreenAfterBoot() {
4388 synchronized(mWindowMap) {
4389 if (mSystemBooted) {
4390 return;
4391 }
4392 mSystemBooted = true;
4393 }
Romain Guy06882f82009-06-10 13:36:04 -07004394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004395 performEnableScreen();
4396 }
Romain Guy06882f82009-06-10 13:36:04 -07004397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004398 public void enableScreenIfNeededLocked() {
4399 if (mDisplayEnabled) {
4400 return;
4401 }
4402 if (!mSystemBooted) {
4403 return;
4404 }
4405 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4406 }
Romain Guy06882f82009-06-10 13:36:04 -07004407
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004408 public void performEnableScreen() {
4409 synchronized(mWindowMap) {
4410 if (mDisplayEnabled) {
4411 return;
4412 }
4413 if (!mSystemBooted) {
4414 return;
4415 }
Romain Guy06882f82009-06-10 13:36:04 -07004416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004417 // Don't enable the screen until all existing windows
4418 // have been drawn.
4419 final int N = mWindows.size();
4420 for (int i=0; i<N; i++) {
4421 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn5943c202010-04-12 21:36:49 -07004422 if (w.isVisibleLw() && !w.mObscured
4423 && (w.mOrientationChanging || !w.isDrawnLw())) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004424 return;
4425 }
4426 }
Romain Guy06882f82009-06-10 13:36:04 -07004427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004428 mDisplayEnabled = true;
4429 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004430 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004431 StringWriter sw = new StringWriter();
4432 PrintWriter pw = new PrintWriter(sw);
4433 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004434 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004435 }
4436 try {
4437 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4438 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004439 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004440 Parcel data = Parcel.obtain();
4441 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4442 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4443 data, null, 0);
4444 data.recycle();
4445 }
4446 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004447 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004448 }
4449 }
Romain Guy06882f82009-06-10 13:36:04 -07004450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004451 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004453 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004454 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4455 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004456 }
Romain Guy06882f82009-06-10 13:36:04 -07004457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004458 public void setInTouchMode(boolean mode) {
4459 synchronized(mWindowMap) {
4460 mInTouchMode = mode;
4461 }
4462 }
4463
Romain Guy06882f82009-06-10 13:36:04 -07004464 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004465 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004466 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004467 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004468 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004469 }
4470
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004471 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004472 }
Romain Guy06882f82009-06-10 13:36:04 -07004473
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004474 public void setRotationUnchecked(int rotation,
4475 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004476 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004477 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004479 long origId = Binder.clearCallingIdentity();
4480 boolean changed;
4481 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004482 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004483 }
Romain Guy06882f82009-06-10 13:36:04 -07004484
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004485 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004486 sendNewConfiguration();
4487 }
Romain Guy06882f82009-06-10 13:36:04 -07004488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004489 Binder.restoreCallingIdentity(origId);
4490 }
Romain Guy06882f82009-06-10 13:36:04 -07004491
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004492 /**
4493 * Apply a new rotation to the screen, respecting the requests of
4494 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4495 * re-evaluate the desired rotation.
4496 *
4497 * Returns null if the rotation has been changed. In this case YOU
4498 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4499 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004500 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004501 boolean changed;
4502 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4503 rotation = mRequestedRotation;
4504 } else {
4505 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004506 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004507 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004508 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004509 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004510 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004511 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004512 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004514 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004515 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004516 "Rotation changed to " + rotation
4517 + " from " + mRotation
4518 + " (forceApp=" + mForcedAppOrientation
4519 + ", req=" + mRequestedRotation + ")");
4520 mRotation = rotation;
4521 mWindowsFreezingScreen = true;
4522 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4523 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4524 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004525 mWaitingForConfig = true;
4526 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004527 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004528 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004529 mQueue.setOrientation(rotation);
4530 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004531 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004532 }
4533 for (int i=mWindows.size()-1; i>=0; i--) {
4534 WindowState w = (WindowState)mWindows.get(i);
4535 if (w.mSurface != null) {
4536 w.mOrientationChanging = true;
4537 }
4538 }
4539 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4540 try {
4541 mRotationWatchers.get(i).onRotationChanged(rotation);
4542 } catch (RemoteException e) {
4543 }
4544 }
4545 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004547 return changed;
4548 }
Romain Guy06882f82009-06-10 13:36:04 -07004549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004550 public int getRotation() {
4551 return mRotation;
4552 }
4553
4554 public int watchRotation(IRotationWatcher watcher) {
4555 final IBinder watcherBinder = watcher.asBinder();
4556 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4557 public void binderDied() {
4558 synchronized (mWindowMap) {
4559 for (int i=0; i<mRotationWatchers.size(); i++) {
4560 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004561 IRotationWatcher removed = mRotationWatchers.remove(i);
4562 if (removed != null) {
4563 removed.asBinder().unlinkToDeath(this, 0);
4564 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004565 i--;
4566 }
4567 }
4568 }
4569 }
4570 };
Romain Guy06882f82009-06-10 13:36:04 -07004571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004572 synchronized (mWindowMap) {
4573 try {
4574 watcher.asBinder().linkToDeath(dr, 0);
4575 mRotationWatchers.add(watcher);
4576 } catch (RemoteException e) {
4577 // Client died, no cleanup needed.
4578 }
Romain Guy06882f82009-06-10 13:36:04 -07004579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004580 return mRotation;
4581 }
4582 }
4583
4584 /**
4585 * Starts the view server on the specified port.
4586 *
4587 * @param port The port to listener to.
4588 *
4589 * @return True if the server was successfully started, false otherwise.
4590 *
4591 * @see com.android.server.ViewServer
4592 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4593 */
4594 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004595 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004596 return false;
4597 }
4598
4599 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4600 return false;
4601 }
4602
4603 if (port < 1024) {
4604 return false;
4605 }
4606
4607 if (mViewServer != null) {
4608 if (!mViewServer.isRunning()) {
4609 try {
4610 return mViewServer.start();
4611 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004612 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004613 }
4614 }
4615 return false;
4616 }
4617
4618 try {
4619 mViewServer = new ViewServer(this, port);
4620 return mViewServer.start();
4621 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004622 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004623 }
4624 return false;
4625 }
4626
Romain Guy06882f82009-06-10 13:36:04 -07004627 private boolean isSystemSecure() {
4628 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4629 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4630 }
4631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004632 /**
4633 * Stops the view server if it exists.
4634 *
4635 * @return True if the server stopped, false if it wasn't started or
4636 * couldn't be stopped.
4637 *
4638 * @see com.android.server.ViewServer
4639 */
4640 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004641 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004642 return false;
4643 }
4644
4645 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4646 return false;
4647 }
4648
4649 if (mViewServer != null) {
4650 return mViewServer.stop();
4651 }
4652 return false;
4653 }
4654
4655 /**
4656 * Indicates whether the view server is running.
4657 *
4658 * @return True if the server is running, false otherwise.
4659 *
4660 * @see com.android.server.ViewServer
4661 */
4662 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004663 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004664 return false;
4665 }
4666
4667 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4668 return false;
4669 }
4670
4671 return mViewServer != null && mViewServer.isRunning();
4672 }
4673
4674 /**
4675 * Lists all availble windows in the system. The listing is written in the
4676 * specified Socket's output stream with the following syntax:
4677 * windowHashCodeInHexadecimal windowName
4678 * Each line of the ouput represents a different window.
4679 *
4680 * @param client The remote client to send the listing to.
4681 * @return False if an error occured, true otherwise.
4682 */
4683 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004684 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004685 return false;
4686 }
4687
4688 boolean result = true;
4689
4690 Object[] windows;
4691 synchronized (mWindowMap) {
4692 windows = new Object[mWindows.size()];
4693 //noinspection unchecked
4694 windows = mWindows.toArray(windows);
4695 }
4696
4697 BufferedWriter out = null;
4698
4699 // Any uncaught exception will crash the system process
4700 try {
4701 OutputStream clientStream = client.getOutputStream();
4702 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4703
4704 final int count = windows.length;
4705 for (int i = 0; i < count; i++) {
4706 final WindowState w = (WindowState) windows[i];
4707 out.write(Integer.toHexString(System.identityHashCode(w)));
4708 out.write(' ');
4709 out.append(w.mAttrs.getTitle());
4710 out.write('\n');
4711 }
4712
4713 out.write("DONE.\n");
4714 out.flush();
4715 } catch (Exception e) {
4716 result = false;
4717 } finally {
4718 if (out != null) {
4719 try {
4720 out.close();
4721 } catch (IOException e) {
4722 result = false;
4723 }
4724 }
4725 }
4726
4727 return result;
4728 }
4729
4730 /**
4731 * Sends a command to a target window. The result of the command, if any, will be
4732 * written in the output stream of the specified socket.
4733 *
4734 * The parameters must follow this syntax:
4735 * windowHashcode extra
4736 *
4737 * Where XX is the length in characeters of the windowTitle.
4738 *
4739 * The first parameter is the target window. The window with the specified hashcode
4740 * will be the target. If no target can be found, nothing happens. The extra parameters
4741 * will be delivered to the target window and as parameters to the command itself.
4742 *
4743 * @param client The remote client to sent the result, if any, to.
4744 * @param command The command to execute.
4745 * @param parameters The command parameters.
4746 *
4747 * @return True if the command was successfully delivered, false otherwise. This does
4748 * not indicate whether the command itself was successful.
4749 */
4750 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004751 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004752 return false;
4753 }
4754
4755 boolean success = true;
4756 Parcel data = null;
4757 Parcel reply = null;
4758
4759 // Any uncaught exception will crash the system process
4760 try {
4761 // Find the hashcode of the window
4762 int index = parameters.indexOf(' ');
4763 if (index == -1) {
4764 index = parameters.length();
4765 }
4766 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004767 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004768
4769 // Extract the command's parameter after the window description
4770 if (index < parameters.length()) {
4771 parameters = parameters.substring(index + 1);
4772 } else {
4773 parameters = "";
4774 }
4775
4776 final WindowManagerService.WindowState window = findWindow(hashCode);
4777 if (window == null) {
4778 return false;
4779 }
4780
4781 data = Parcel.obtain();
4782 data.writeInterfaceToken("android.view.IWindow");
4783 data.writeString(command);
4784 data.writeString(parameters);
4785 data.writeInt(1);
4786 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4787
4788 reply = Parcel.obtain();
4789
4790 final IBinder binder = window.mClient.asBinder();
4791 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4792 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4793
4794 reply.readException();
4795
4796 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004797 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004798 success = false;
4799 } finally {
4800 if (data != null) {
4801 data.recycle();
4802 }
4803 if (reply != null) {
4804 reply.recycle();
4805 }
4806 }
4807
4808 return success;
4809 }
4810
4811 private WindowState findWindow(int hashCode) {
4812 if (hashCode == -1) {
4813 return getFocusedWindow();
4814 }
4815
4816 synchronized (mWindowMap) {
4817 final ArrayList windows = mWindows;
4818 final int count = windows.size();
4819
4820 for (int i = 0; i < count; i++) {
4821 WindowState w = (WindowState) windows.get(i);
4822 if (System.identityHashCode(w) == hashCode) {
4823 return w;
4824 }
4825 }
4826 }
4827
4828 return null;
4829 }
4830
4831 /*
4832 * Instruct the Activity Manager to fetch the current configuration and broadcast
4833 * that to config-changed listeners if appropriate.
4834 */
4835 void sendNewConfiguration() {
4836 try {
4837 mActivityManager.updateConfiguration(null);
4838 } catch (RemoteException e) {
4839 }
4840 }
Romain Guy06882f82009-06-10 13:36:04 -07004841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004842 public Configuration computeNewConfiguration() {
4843 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004844 return computeNewConfigurationLocked();
4845 }
4846 }
Romain Guy06882f82009-06-10 13:36:04 -07004847
Dianne Hackbornc485a602009-03-24 22:39:49 -07004848 Configuration computeNewConfigurationLocked() {
4849 Configuration config = new Configuration();
4850 if (!computeNewConfigurationLocked(config)) {
4851 return null;
4852 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004853 return config;
4854 }
Romain Guy06882f82009-06-10 13:36:04 -07004855
Dianne Hackbornc485a602009-03-24 22:39:49 -07004856 boolean computeNewConfigurationLocked(Configuration config) {
4857 if (mDisplay == null) {
4858 return false;
4859 }
4860 mQueue.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07004861
4862 // Use the effective "visual" dimensions based on current rotation
4863 final boolean rotated = (mRotation == Surface.ROTATION_90
4864 || mRotation == Surface.ROTATION_270);
4865 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
4866 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
4867
Dianne Hackbornc485a602009-03-24 22:39:49 -07004868 int orientation = Configuration.ORIENTATION_SQUARE;
4869 if (dw < dh) {
4870 orientation = Configuration.ORIENTATION_PORTRAIT;
4871 } else if (dw > dh) {
4872 orientation = Configuration.ORIENTATION_LANDSCAPE;
4873 }
4874 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004875
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004876 DisplayMetrics dm = new DisplayMetrics();
4877 mDisplay.getMetrics(dm);
4878 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4879
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004880 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004881 // Note we only do this once because at this point we don't
4882 // expect the screen to change in this way at runtime, and want
4883 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004884 int longSize = dw;
4885 int shortSize = dh;
4886 if (longSize < shortSize) {
4887 int tmp = longSize;
4888 longSize = shortSize;
4889 shortSize = tmp;
4890 }
4891 longSize = (int)(longSize/dm.density);
4892 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004893
Dianne Hackborn723738c2009-06-25 19:48:04 -07004894 // These semi-magic numbers define our compatibility modes for
4895 // applications with different screens. Don't change unless you
4896 // make sure to test lots and lots of apps!
4897 if (longSize < 470) {
4898 // This is shorter than an HVGA normal density screen (which
4899 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004900 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
4901 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07004902 } else {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004903 // Is this a large screen?
4904 if (longSize > 640 && shortSize >= 480) {
4905 // VGA or larger screens at medium density are the point
4906 // at which we consider it to be a large screen.
4907 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
4908 } else {
4909 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004910
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004911 // If this screen is wider than normal HVGA, or taller
4912 // than FWVGA, then for old apps we want to run in size
4913 // compatibility mode.
4914 if (shortSize > 321 || longSize > 570) {
4915 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
4916 }
4917 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004918
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004919 // Is this a long screen?
4920 if (((longSize*3)/5) >= (shortSize-1)) {
4921 // Anything wider than WVGA (5:3) is considering to be long.
4922 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
4923 } else {
4924 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
4925 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07004926 }
4927 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004928 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004929
Dianne Hackbornc485a602009-03-24 22:39:49 -07004930 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
4931 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
4932 mPolicy.adjustConfigurationLw(config);
4933 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004934 }
Romain Guy06882f82009-06-10 13:36:04 -07004935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004936 // -------------------------------------------------------------
4937 // Input Events and Focus Management
4938 // -------------------------------------------------------------
4939
4940 private final void wakeupIfNeeded(WindowState targetWin, int eventType) {
Michael Chane96440f2009-05-06 10:27:36 -07004941 long curTime = SystemClock.uptimeMillis();
4942
Michael Chane10de972009-05-18 11:24:50 -07004943 if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) {
Michael Chane96440f2009-05-06 10:27:36 -07004944 if (mLastTouchEventType == eventType &&
4945 (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) {
4946 return;
4947 }
4948 mLastUserActivityCallTime = curTime;
4949 mLastTouchEventType = eventType;
4950 }
4951
4952 if (targetWin == null
4953 || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) {
4954 mPowerManager.userActivity(curTime, false, eventType, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004955 }
4956 }
4957
4958 // tells if it's a cheek event or not -- this function is stateful
4959 private static final int EVENT_NONE = 0;
4960 private static final int EVENT_UNKNOWN = 0;
4961 private static final int EVENT_CHEEK = 0;
4962 private static final int EVENT_IGNORE_DURATION = 300; // ms
4963 private static final float CHEEK_THRESHOLD = 0.6f;
4964 private int mEventState = EVENT_NONE;
4965 private float mEventSize;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004967 private int eventType(MotionEvent ev) {
4968 float size = ev.getSize();
4969 switch (ev.getAction()) {
4970 case MotionEvent.ACTION_DOWN:
4971 mEventSize = size;
4972 return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT;
4973 case MotionEvent.ACTION_UP:
4974 if (size > mEventSize) mEventSize = size;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004975 return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004976 case MotionEvent.ACTION_MOVE:
4977 final int N = ev.getHistorySize();
4978 if (size > mEventSize) mEventSize = size;
4979 if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT;
4980 for (int i=0; i<N; i++) {
4981 size = ev.getHistoricalSize(i);
4982 if (size > mEventSize) mEventSize = size;
4983 if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT;
4984 }
4985 if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) {
4986 return TOUCH_EVENT;
4987 } else {
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004988 return LONG_TOUCH_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004989 }
4990 default:
4991 // not good
4992 return OTHER_EVENT;
4993 }
4994 }
4995
4996 /**
4997 * @return Returns true if event was dispatched, false if it was dropped for any reason
4998 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07004999 private int dispatchPointer(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005000 if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005001 "dispatchPointer " + ev);
5002
Michael Chan53071d62009-05-13 17:29:48 -07005003 if (MEASURE_LATENCY) {
5004 lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano);
5005 }
5006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005007 Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005008 ev, true, false, pid, uid);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005009
Michael Chan53071d62009-05-13 17:29:48 -07005010 if (MEASURE_LATENCY) {
5011 lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano);
5012 }
5013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005014 int action = ev.getAction();
Romain Guy06882f82009-06-10 13:36:04 -07005015
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005016 if (action == MotionEvent.ACTION_UP) {
5017 // let go of our target
5018 mKeyWaiter.mMotionTarget = null;
5019 mPowerManager.logPointerUpEvent();
5020 } else if (action == MotionEvent.ACTION_DOWN) {
5021 mPowerManager.logPointerDownEvent();
5022 }
5023
5024 if (targetObj == null) {
5025 // In this case we are either dropping the event, or have received
5026 // a move or up without a down. It is common to receive move
5027 // events in such a way, since this means the user is moving the
5028 // pointer without actually pressing down. All other cases should
5029 // be atypical, so let's log them.
Michael Chane96440f2009-05-06 10:27:36 -07005030 if (action != MotionEvent.ACTION_MOVE) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005031 Slog.w(TAG, "No window to dispatch pointer action " + ev.getAction());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005032 }
Dianne Hackborn6adba242009-11-10 11:10:09 -08005033 synchronized (mWindowMap) {
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005034 dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true);
Dianne Hackborn6adba242009-11-10 11:10:09 -08005035 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005036 if (qev != null) {
5037 mQueue.recycleEvent(qev);
5038 }
5039 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005040 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005041 }
5042 if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
Dianne Hackborn6adba242009-11-10 11:10:09 -08005043 synchronized (mWindowMap) {
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005044 dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true);
Dianne Hackborn6adba242009-11-10 11:10:09 -08005045 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005046 if (qev != null) {
5047 mQueue.recycleEvent(qev);
5048 }
5049 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005050 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005051 }
Romain Guy06882f82009-06-10 13:36:04 -07005052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005053 WindowState target = (WindowState)targetObj;
Romain Guy06882f82009-06-10 13:36:04 -07005054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005055 final long eventTime = ev.getEventTime();
Michael Chan53071d62009-05-13 17:29:48 -07005056 final long eventTimeNano = ev.getEventTimeNano();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005057
Joe Onorato8a9b2202010-02-26 18:56:32 -08005058 //Slog.i(TAG, "Sending " + ev + " to " + target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005059
5060 if (uid != 0 && uid != target.mSession.mUid) {
5061 if (mContext.checkPermission(
5062 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5063 != PackageManager.PERMISSION_GRANTED) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005064 Slog.w(TAG, "Permission denied: injecting pointer event from pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005065 + pid + " uid " + uid + " to window " + target
5066 + " owned by uid " + target.mSession.mUid);
5067 if (qev != null) {
5068 mQueue.recycleEvent(qev);
5069 }
5070 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005071 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005072 }
5073 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005074
Michael Chan53071d62009-05-13 17:29:48 -07005075 if (MEASURE_LATENCY) {
5076 lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano);
5077 }
5078
Romain Guy06882f82009-06-10 13:36:04 -07005079 if ((target.mAttrs.flags &
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005080 WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) {
5081 //target wants to ignore fat touch events
5082 boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev);
5083 //explicit flag to return without processing event further
5084 boolean returnFlag = false;
5085 if((action == MotionEvent.ACTION_DOWN)) {
5086 mFatTouch = false;
5087 if(cheekPress) {
5088 mFatTouch = true;
5089 returnFlag = true;
5090 }
5091 } else {
5092 if(action == MotionEvent.ACTION_UP) {
5093 if(mFatTouch) {
5094 //earlier even was invalid doesnt matter if current up is cheekpress or not
5095 mFatTouch = false;
5096 returnFlag = true;
5097 } else if(cheekPress) {
5098 //cancel the earlier event
5099 ev.setAction(MotionEvent.ACTION_CANCEL);
5100 action = MotionEvent.ACTION_CANCEL;
5101 }
5102 } else if(action == MotionEvent.ACTION_MOVE) {
5103 if(mFatTouch) {
5104 //two cases here
5105 //an invalid down followed by 0 or moves(valid or invalid)
Romain Guy06882f82009-06-10 13:36:04 -07005106 //a valid down, invalid move, more moves. want to ignore till up
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005107 returnFlag = true;
5108 } else if(cheekPress) {
5109 //valid down followed by invalid moves
5110 //an invalid move have to cancel earlier action
5111 ev.setAction(MotionEvent.ACTION_CANCEL);
5112 action = MotionEvent.ACTION_CANCEL;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005113 if (DEBUG_INPUT) Slog.v(TAG, "Sending cancel for invalid ACTION_MOVE");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005114 //note that the subsequent invalid moves will not get here
5115 mFatTouch = true;
5116 }
5117 }
5118 } //else if action
5119 if(returnFlag) {
5120 //recycle que, ev
5121 if (qev != null) {
5122 mQueue.recycleEvent(qev);
5123 }
5124 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005125 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005126 }
5127 } //end if target
Michael Chane96440f2009-05-06 10:27:36 -07005128
Michael Chan9f028e62009-08-04 17:37:46 -07005129 // Enable this for testing the "right" value
5130 if (false && action == MotionEvent.ACTION_DOWN) {
Michael Chane96440f2009-05-06 10:27:36 -07005131 int max_events_per_sec = 35;
5132 try {
5133 max_events_per_sec = Integer.parseInt(SystemProperties
5134 .get("windowsmgr.max_events_per_sec"));
5135 if (max_events_per_sec < 1) {
5136 max_events_per_sec = 35;
5137 }
5138 } catch (NumberFormatException e) {
5139 }
5140 mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec;
5141 }
5142
5143 /*
5144 * Throttle events to minimize CPU usage when there's a flood of events
5145 * e.g. constant contact with the screen
5146 */
5147 if (action == MotionEvent.ACTION_MOVE) {
5148 long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents;
5149 long now = SystemClock.uptimeMillis();
5150 if (now < nextEventTime) {
5151 try {
5152 Thread.sleep(nextEventTime - now);
5153 } catch (InterruptedException e) {
5154 }
5155 mLastTouchEventTime = nextEventTime;
5156 } else {
5157 mLastTouchEventTime = now;
5158 }
5159 }
5160
Michael Chan53071d62009-05-13 17:29:48 -07005161 if (MEASURE_LATENCY) {
5162 lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano);
5163 }
5164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005165 synchronized(mWindowMap) {
Dianne Hackborn6adba242009-11-10 11:10:09 -08005166 if (!target.isVisibleLw()) {
5167 // During this motion dispatch, the target window has become
5168 // invisible.
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005169 dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), false);
Dianne Hackborn6adba242009-11-10 11:10:09 -08005170 if (qev != null) {
5171 mQueue.recycleEvent(qev);
5172 }
5173 ev.recycle();
5174 return INJECT_SUCCEEDED;
5175 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005177 if (qev != null && action == MotionEvent.ACTION_MOVE) {
5178 mKeyWaiter.bindTargetWindowLocked(target,
5179 KeyWaiter.RETURN_PENDING_POINTER, qev);
5180 ev = null;
5181 } else {
5182 if (action == MotionEvent.ACTION_DOWN) {
5183 WindowState out = mKeyWaiter.mOutsideTouchTargets;
5184 if (out != null) {
5185 MotionEvent oev = MotionEvent.obtain(ev);
5186 oev.setAction(MotionEvent.ACTION_OUTSIDE);
5187 do {
5188 final Rect frame = out.mFrame;
5189 oev.offsetLocation(-(float)frame.left, -(float)frame.top);
5190 try {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005191 out.mClient.dispatchPointer(oev, eventTime, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005192 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005193 Slog.i(TAG, "WINDOW DIED during outside motion dispatch: " + out);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005194 }
5195 oev.offsetLocation((float)frame.left, (float)frame.top);
5196 out = out.mNextOutsideTouch;
5197 } while (out != null);
5198 mKeyWaiter.mOutsideTouchTargets = null;
5199 }
5200 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005201
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005202 dispatchPointerElsewhereLocked(target, null, ev, ev.getEventTime(), false);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005203
Dianne Hackborn6adba242009-11-10 11:10:09 -08005204 final Rect frame = target.mFrame;
5205 ev.offsetLocation(-(float)frame.left, -(float)frame.top);
5206 mKeyWaiter.bindTargetWindowLocked(target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005207 }
5208 }
Romain Guy06882f82009-06-10 13:36:04 -07005209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005210 // finally offset the event to the target's coordinate system and
5211 // dispatch the event.
5212 try {
5213 if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005214 Slog.v(TAG, "Delivering pointer " + qev + " to " + target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005215 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005216
Michael Chan53071d62009-05-13 17:29:48 -07005217 if (MEASURE_LATENCY) {
5218 lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano);
5219 }
5220
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005221 target.mClient.dispatchPointer(ev, eventTime, true);
Michael Chan53071d62009-05-13 17:29:48 -07005222
5223 if (MEASURE_LATENCY) {
5224 lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano);
5225 }
Dianne Hackborncfaef692009-06-15 14:24:44 -07005226 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005227 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005228 Slog.i(TAG, "WINDOW DIED during motion dispatch: " + target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005229 mKeyWaiter.mMotionTarget = null;
5230 try {
5231 removeWindow(target.mSession, target.mClient);
5232 } catch (java.util.NoSuchElementException ex) {
5233 // This will happen if the window has already been
5234 // removed.
5235 }
5236 }
Dianne Hackborncfaef692009-06-15 14:24:44 -07005237 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005238 }
Romain Guy06882f82009-06-10 13:36:04 -07005239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005240 /**
5241 * @return Returns true if event was dispatched, false if it was dropped for any reason
5242 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07005243 private int dispatchTrackball(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005244 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005245 TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">");
Romain Guy06882f82009-06-10 13:36:04 -07005246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005247 Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005248 ev, 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 trackball: " + ev);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005251 if (qev != null) {
5252 mQueue.recycleEvent(qev);
5253 }
5254 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005255 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005256 }
5257 if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
5258 if (qev != null) {
5259 mQueue.recycleEvent(qev);
5260 }
5261 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005262 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005263 }
Romain Guy06882f82009-06-10 13:36:04 -07005264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005265 WindowState focus = (WindowState)focusObj;
Romain Guy06882f82009-06-10 13:36:04 -07005266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005267 if (uid != 0 && uid != focus.mSession.mUid) {
5268 if (mContext.checkPermission(
5269 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5270 != PackageManager.PERMISSION_GRANTED) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005271 Slog.w(TAG, "Permission denied: injecting key event from pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005272 + pid + " uid " + uid + " to window " + focus
5273 + " owned by uid " + focus.mSession.mUid);
5274 if (qev != null) {
5275 mQueue.recycleEvent(qev);
5276 }
5277 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005278 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005279 }
5280 }
Romain Guy06882f82009-06-10 13:36:04 -07005281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005282 final long eventTime = ev.getEventTime();
Romain Guy06882f82009-06-10 13:36:04 -07005283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005284 synchronized(mWindowMap) {
5285 if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) {
5286 mKeyWaiter.bindTargetWindowLocked(focus,
5287 KeyWaiter.RETURN_PENDING_TRACKBALL, qev);
5288 // We don't deliver movement events to the client, we hold
5289 // them and wait for them to call back.
5290 ev = null;
5291 } else {
5292 mKeyWaiter.bindTargetWindowLocked(focus);
5293 }
5294 }
Romain Guy06882f82009-06-10 13:36:04 -07005295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005296 try {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005297 focus.mClient.dispatchTrackball(ev, eventTime, true);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005298 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005299 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005300 Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005301 try {
5302 removeWindow(focus.mSession, focus.mClient);
5303 } catch (java.util.NoSuchElementException ex) {
5304 // This will happen if the window has already been
5305 // removed.
5306 }
5307 }
Romain Guy06882f82009-06-10 13:36:04 -07005308
Dianne Hackborncfaef692009-06-15 14:24:44 -07005309 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005310 }
Romain Guy06882f82009-06-10 13:36:04 -07005311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005312 /**
5313 * @return Returns true if event was dispatched, false if it was dropped for any reason
5314 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07005315 private int dispatchKey(KeyEvent event, int pid, int uid) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005316 if (DEBUG_INPUT) Slog.v(TAG, "Dispatch key: " + event);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005317
5318 Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005319 null, false, false, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005320 if (focusObj == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005321 Slog.w(TAG, "No focus window, dropping: " + event);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005322 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005323 }
5324 if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005325 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005326 }
Romain Guy06882f82009-06-10 13:36:04 -07005327
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07005328 // Okay we have finished waiting for the last event to be processed.
5329 // First off, if this is a repeat event, check to see if there is
5330 // a corresponding up event in the queue. If there is, we will
5331 // just drop the repeat, because it makes no sense to repeat after
5332 // the user has released a key. (This is especially important for
5333 // long presses.)
5334 if (event.getRepeatCount() > 0 && mQueue.hasKeyUpEvent(event)) {
5335 return INJECT_SUCCEEDED;
5336 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005338 WindowState focus = (WindowState)focusObj;
Romain Guy06882f82009-06-10 13:36:04 -07005339
Joe Onorato8a9b2202010-02-26 18:56:32 -08005340 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005341 TAG, "Dispatching to " + focus + ": " + event);
5342
5343 if (uid != 0 && uid != focus.mSession.mUid) {
5344 if (mContext.checkPermission(
5345 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5346 != PackageManager.PERMISSION_GRANTED) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005347 Slog.w(TAG, "Permission denied: injecting key event from pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005348 + pid + " uid " + uid + " to window " + focus
5349 + " owned by uid " + focus.mSession.mUid);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005350 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005351 }
5352 }
Romain Guy06882f82009-06-10 13:36:04 -07005353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005354 synchronized(mWindowMap) {
5355 mKeyWaiter.bindTargetWindowLocked(focus);
5356 }
5357
5358 // NOSHIP extra state logging
5359 mKeyWaiter.recordDispatchState(event, focus);
5360 // END NOSHIP
Romain Guy06882f82009-06-10 13:36:04 -07005361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005362 try {
5363 if (DEBUG_INPUT || DEBUG_FOCUS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005364 Slog.v(TAG, "Delivering key " + event.getKeyCode()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005365 + " to " + focus);
5366 }
5367 focus.mClient.dispatchKey(event);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005368 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005369 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005370 Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005371 try {
5372 removeWindow(focus.mSession, focus.mClient);
5373 } catch (java.util.NoSuchElementException ex) {
5374 // This will happen if the window has already been
5375 // removed.
5376 }
5377 }
Romain Guy06882f82009-06-10 13:36:04 -07005378
Dianne Hackborncfaef692009-06-15 14:24:44 -07005379 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005380 }
Romain Guy06882f82009-06-10 13:36:04 -07005381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005382 public void pauseKeyDispatching(IBinder _token) {
5383 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5384 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005385 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005386 }
5387
5388 synchronized (mWindowMap) {
5389 WindowToken token = mTokenMap.get(_token);
5390 if (token != null) {
5391 mKeyWaiter.pauseDispatchingLocked(token);
5392 }
5393 }
5394 }
5395
5396 public void resumeKeyDispatching(IBinder _token) {
5397 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5398 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005399 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005400 }
5401
5402 synchronized (mWindowMap) {
5403 WindowToken token = mTokenMap.get(_token);
5404 if (token != null) {
5405 mKeyWaiter.resumeDispatchingLocked(token);
5406 }
5407 }
5408 }
5409
5410 public void setEventDispatching(boolean enabled) {
5411 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5412 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005413 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005414 }
5415
5416 synchronized (mWindowMap) {
5417 mKeyWaiter.setEventDispatchingLocked(enabled);
5418 }
5419 }
Romain Guy06882f82009-06-10 13:36:04 -07005420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005421 /**
5422 * Injects a keystroke event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005423 *
5424 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005425 * {@link SystemClock#uptimeMillis()} as the timebase.)
5426 * @param sync If true, wait for the event to be completed before returning to the caller.
5427 * @return Returns true if event was dispatched, false if it was dropped for any reason
5428 */
5429 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5430 long downTime = ev.getDownTime();
5431 long eventTime = ev.getEventTime();
5432
5433 int action = ev.getAction();
5434 int code = ev.getKeyCode();
5435 int repeatCount = ev.getRepeatCount();
5436 int metaState = ev.getMetaState();
5437 int deviceId = ev.getDeviceId();
5438 int scancode = ev.getScanCode();
5439
5440 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5441 if (downTime == 0) downTime = eventTime;
5442
5443 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
The Android Open Source Project10592532009-03-18 17:39:46 -07005444 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005445
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005446 final int pid = Binder.getCallingPid();
5447 final int uid = Binder.getCallingUid();
5448 final long ident = Binder.clearCallingIdentity();
5449 final int result = dispatchKey(newEvent, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005450 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005451 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005452 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005453 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005454 switch (result) {
5455 case INJECT_NO_PERMISSION:
5456 throw new SecurityException(
Chander S Pechetty27f3de62010-02-10 22:14:00 +05305457 "Injecting to another application requires INJECT_EVENTS permission");
Dianne Hackborncfaef692009-06-15 14:24:44 -07005458 case INJECT_SUCCEEDED:
5459 return true;
5460 }
5461 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005462 }
5463
5464 /**
5465 * Inject a pointer (touch) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005466 *
5467 * @param ev A motion event describing the pointer (touch) action. (As noted in
5468 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005469 * {@link SystemClock#uptimeMillis()} as the timebase.)
5470 * @param sync If true, wait for the event to be completed before returning to the caller.
5471 * @return Returns true if event was dispatched, false if it was dropped for any reason
5472 */
5473 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005474 final int pid = Binder.getCallingPid();
5475 final int uid = Binder.getCallingUid();
5476 final long ident = Binder.clearCallingIdentity();
5477 final int result = dispatchPointer(null, ev, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005478 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005479 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005480 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005481 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005482 switch (result) {
5483 case INJECT_NO_PERMISSION:
5484 throw new SecurityException(
Chander S Pechetty27f3de62010-02-10 22:14:00 +05305485 "Injecting to another application requires INJECT_EVENTS permission");
Dianne Hackborncfaef692009-06-15 14:24:44 -07005486 case INJECT_SUCCEEDED:
5487 return true;
5488 }
5489 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005490 }
Romain Guy06882f82009-06-10 13:36:04 -07005491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005492 /**
5493 * Inject a trackball (navigation device) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005494 *
5495 * @param ev A motion event describing the trackball action. (As noted in
5496 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005497 * {@link SystemClock#uptimeMillis()} as the timebase.)
5498 * @param sync If true, wait for the event to be completed before returning to the caller.
5499 * @return Returns true if event was dispatched, false if it was dropped for any reason
5500 */
5501 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005502 final int pid = Binder.getCallingPid();
5503 final int uid = Binder.getCallingUid();
5504 final long ident = Binder.clearCallingIdentity();
5505 final int result = dispatchTrackball(null, ev, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005506 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005507 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005508 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005509 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005510 switch (result) {
5511 case INJECT_NO_PERMISSION:
5512 throw new SecurityException(
Chander S Pechetty27f3de62010-02-10 22:14:00 +05305513 "Injecting to another application requires INJECT_EVENTS permission");
Dianne Hackborncfaef692009-06-15 14:24:44 -07005514 case INJECT_SUCCEEDED:
5515 return true;
5516 }
5517 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005518 }
Romain Guy06882f82009-06-10 13:36:04 -07005519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005520 private WindowState getFocusedWindow() {
5521 synchronized (mWindowMap) {
5522 return getFocusedWindowLocked();
5523 }
5524 }
5525
5526 private WindowState getFocusedWindowLocked() {
5527 return mCurrentFocus;
5528 }
Romain Guy06882f82009-06-10 13:36:04 -07005529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005530 /**
5531 * This class holds the state for dispatching key events. This state
5532 * is protected by the KeyWaiter instance, NOT by the window lock. You
5533 * can be holding the main window lock while acquire the KeyWaiter lock,
5534 * but not the other way around.
5535 */
5536 final class KeyWaiter {
5537 // NOSHIP debugging
5538 public class DispatchState {
5539 private KeyEvent event;
5540 private WindowState focus;
5541 private long time;
5542 private WindowState lastWin;
5543 private IBinder lastBinder;
5544 private boolean finished;
5545 private boolean gotFirstWindow;
5546 private boolean eventDispatching;
5547 private long timeToSwitch;
5548 private boolean wasFrozen;
5549 private boolean focusPaused;
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005550 private WindowState curFocus;
Romain Guy06882f82009-06-10 13:36:04 -07005551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005552 DispatchState(KeyEvent theEvent, WindowState theFocus) {
5553 focus = theFocus;
5554 event = theEvent;
5555 time = System.currentTimeMillis();
5556 // snapshot KeyWaiter state
5557 lastWin = mLastWin;
5558 lastBinder = mLastBinder;
5559 finished = mFinished;
5560 gotFirstWindow = mGotFirstWindow;
5561 eventDispatching = mEventDispatching;
5562 timeToSwitch = mTimeToSwitch;
5563 wasFrozen = mWasFrozen;
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005564 curFocus = mCurrentFocus;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005565 // cache the paused state at ctor time as well
5566 if (theFocus == null || theFocus.mToken == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005567 focusPaused = false;
5568 } else {
5569 focusPaused = theFocus.mToken.paused;
5570 }
5571 }
Romain Guy06882f82009-06-10 13:36:04 -07005572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005573 public String toString() {
5574 return "{{" + event + " to " + focus + " @ " + time
5575 + " lw=" + lastWin + " lb=" + lastBinder
5576 + " fin=" + finished + " gfw=" + gotFirstWindow
5577 + " ed=" + eventDispatching + " tts=" + timeToSwitch
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005578 + " wf=" + wasFrozen + " fp=" + focusPaused
Christopher Tate46d45252010-02-09 15:48:57 -08005579 + " mcf=" + curFocus + "}}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005580 }
5581 };
5582 private DispatchState mDispatchState = null;
5583 public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) {
5584 mDispatchState = new DispatchState(theEvent, theFocus);
5585 }
5586 // END NOSHIP
5587
5588 public static final int RETURN_NOTHING = 0;
5589 public static final int RETURN_PENDING_POINTER = 1;
5590 public static final int RETURN_PENDING_TRACKBALL = 2;
Romain Guy06882f82009-06-10 13:36:04 -07005591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005592 final Object SKIP_TARGET_TOKEN = new Object();
5593 final Object CONSUMED_EVENT_TOKEN = new Object();
Romain Guy06882f82009-06-10 13:36:04 -07005594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005595 private WindowState mLastWin = null;
5596 private IBinder mLastBinder = null;
5597 private boolean mFinished = true;
5598 private boolean mGotFirstWindow = false;
5599 private boolean mEventDispatching = true;
5600 private long mTimeToSwitch = 0;
5601 /* package */ boolean mWasFrozen = false;
Romain Guy06882f82009-06-10 13:36:04 -07005602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005603 // Target of Motion events
5604 WindowState mMotionTarget;
Romain Guy06882f82009-06-10 13:36:04 -07005605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005606 // Windows above the target who would like to receive an "outside"
5607 // touch event for any down events outside of them.
5608 WindowState mOutsideTouchTargets;
5609
5610 /**
5611 * Wait for the last event dispatch to complete, then find the next
5612 * target that should receive the given event and wait for that one
5613 * to be ready to receive it.
5614 */
5615 Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev,
5616 MotionEvent nextMotion, boolean isPointerEvent,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005617 boolean failIfTimeout, int callingPid, int callingUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005618 long startTime = SystemClock.uptimeMillis();
5619 long keyDispatchingTimeout = 5 * 1000;
5620 long waitedFor = 0;
5621
5622 while (true) {
5623 // Figure out which window we care about. It is either the
5624 // last window we are waiting to have process the event or,
5625 // if none, then the next window we think the event should go
5626 // to. Note: we retrieve mLastWin outside of the lock, so
5627 // it may change before we lock. Thus we must check it again.
5628 WindowState targetWin = mLastWin;
5629 boolean targetIsNew = targetWin == null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005630 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005631 TAG, "waitForLastKey: mFinished=" + mFinished +
5632 ", mLastWin=" + mLastWin);
5633 if (targetIsNew) {
5634 Object target = findTargetWindow(nextKey, qev, nextMotion,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005635 isPointerEvent, callingPid, callingUid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005636 if (target == SKIP_TARGET_TOKEN) {
5637 // The user has pressed a special key, and we are
5638 // dropping all pending events before it.
Joe Onorato8a9b2202010-02-26 18:56:32 -08005639 if (DEBUG_INPUT) Slog.v(TAG, "Skipping: " + nextKey
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005640 + " " + nextMotion);
5641 return null;
5642 }
5643 if (target == CONSUMED_EVENT_TOKEN) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005644 if (DEBUG_INPUT) Slog.v(TAG, "Consumed: " + nextKey
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005645 + " " + nextMotion);
5646 return target;
5647 }
5648 targetWin = (WindowState)target;
5649 }
Romain Guy06882f82009-06-10 13:36:04 -07005650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005651 AppWindowToken targetApp = null;
Romain Guy06882f82009-06-10 13:36:04 -07005652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005653 // Now: is it okay to send the next event to this window?
5654 synchronized (this) {
5655 // First: did we come here based on the last window not
5656 // being null, but it changed by the time we got here?
5657 // If so, try again.
5658 if (!targetIsNew && mLastWin == null) {
5659 continue;
5660 }
Romain Guy06882f82009-06-10 13:36:04 -07005661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005662 // We never dispatch events if not finished with the
5663 // last one, or the display is frozen.
5664 if (mFinished && !mDisplayFrozen) {
5665 // If event dispatching is disabled, then we
5666 // just consume the events.
5667 if (!mEventDispatching) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005668 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005669 "Skipping event; dispatching disabled: "
5670 + nextKey + " " + nextMotion);
5671 return null;
5672 }
5673 if (targetWin != null) {
5674 // If this is a new target, and that target is not
5675 // paused or unresponsive, then all looks good to
5676 // handle the event.
5677 if (targetIsNew && !targetWin.mToken.paused) {
5678 return targetWin;
5679 }
Romain Guy06882f82009-06-10 13:36:04 -07005680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005681 // If we didn't find a target window, and there is no
5682 // focused app window, then just eat the events.
5683 } else if (mFocusedApp == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005684 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005685 "Skipping event; no focused app: "
5686 + nextKey + " " + nextMotion);
5687 return null;
5688 }
5689 }
Romain Guy06882f82009-06-10 13:36:04 -07005690
Joe Onorato8a9b2202010-02-26 18:56:32 -08005691 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005692 TAG, "Waiting for last key in " + mLastBinder
5693 + " target=" + targetWin
5694 + " mFinished=" + mFinished
5695 + " mDisplayFrozen=" + mDisplayFrozen
5696 + " targetIsNew=" + targetIsNew
5697 + " paused="
5698 + (targetWin != null ? targetWin.mToken.paused : false)
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005699 + " mFocusedApp=" + mFocusedApp
5700 + " mCurrentFocus=" + mCurrentFocus);
Romain Guy06882f82009-06-10 13:36:04 -07005701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005702 targetApp = targetWin != null
5703 ? targetWin.mAppToken : mFocusedApp;
Romain Guy06882f82009-06-10 13:36:04 -07005704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005705 long curTimeout = keyDispatchingTimeout;
5706 if (mTimeToSwitch != 0) {
5707 long now = SystemClock.uptimeMillis();
5708 if (mTimeToSwitch <= now) {
5709 // If an app switch key has been pressed, and we have
5710 // waited too long for the current app to finish
5711 // processing keys, then wait no more!
Christopher Tate136b1f92010-02-11 17:51:24 -08005712 doFinishedKeyLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005713 continue;
5714 }
5715 long switchTimeout = mTimeToSwitch - now;
5716 if (curTimeout > switchTimeout) {
5717 curTimeout = switchTimeout;
5718 }
5719 }
Romain Guy06882f82009-06-10 13:36:04 -07005720
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005721 try {
5722 // after that continue
5723 // processing keys, so we don't get stuck.
Joe Onorato8a9b2202010-02-26 18:56:32 -08005724 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005725 TAG, "Waiting for key dispatch: " + curTimeout);
5726 wait(curTimeout);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005727 if (DEBUG_INPUT) Slog.v(TAG, "Finished waiting @"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005728 + SystemClock.uptimeMillis() + " startTime="
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005729 + startTime + " switchTime=" + mTimeToSwitch
5730 + " target=" + targetWin + " mLW=" + mLastWin
5731 + " mLB=" + mLastBinder + " fin=" + mFinished
5732 + " mCurrentFocus=" + mCurrentFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005733 } catch (InterruptedException e) {
5734 }
5735 }
5736
5737 // If we were frozen during configuration change, restart the
5738 // timeout checks from now; otherwise look at whether we timed
5739 // out before awakening.
5740 if (mWasFrozen) {
5741 waitedFor = 0;
5742 mWasFrozen = false;
5743 } else {
5744 waitedFor = SystemClock.uptimeMillis() - startTime;
5745 }
5746
5747 if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) {
5748 IApplicationToken at = null;
5749 synchronized (this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005750 Slog.w(TAG, "Key dispatching timed out sending to " +
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005751 (targetWin != null ? targetWin.mAttrs.getTitle()
Ken Shirriff8200b202010-02-04 13:34:37 -08005752 : "<null>: no window ready for key dispatch"));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005753 // NOSHIP debugging
Joe Onorato8a9b2202010-02-26 18:56:32 -08005754 Slog.w(TAG, "Previous dispatch state: " + mDispatchState);
5755 Slog.w(TAG, "Current dispatch state: " +
Ken Shirriff8200b202010-02-04 13:34:37 -08005756 new DispatchState(nextKey, targetWin));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005757 // END NOSHIP
5758 //dump();
5759 if (targetWin != null) {
5760 at = targetWin.getAppToken();
5761 } else if (targetApp != null) {
5762 at = targetApp.appToken;
5763 }
5764 }
5765
5766 boolean abort = true;
5767 if (at != null) {
5768 try {
5769 long timeout = at.getKeyDispatchingTimeout();
5770 if (timeout > waitedFor) {
5771 // we did not wait the proper amount of time for this application.
5772 // set the timeout to be the real timeout and wait again.
5773 keyDispatchingTimeout = timeout - waitedFor;
5774 continue;
5775 } else {
5776 abort = at.keyDispatchingTimedOut();
5777 }
5778 } catch (RemoteException ex) {
5779 }
5780 }
5781
5782 synchronized (this) {
5783 if (abort && (mLastWin == targetWin || targetWin == null)) {
5784 mFinished = true;
Romain Guy06882f82009-06-10 13:36:04 -07005785 if (mLastWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005786 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005787 "Window " + mLastWin +
5788 " timed out on key input");
5789 if (mLastWin.mToken.paused) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005790 Slog.w(TAG, "Un-pausing dispatching to this window");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005791 mLastWin.mToken.paused = false;
5792 }
5793 }
5794 if (mMotionTarget == targetWin) {
5795 mMotionTarget = null;
5796 }
5797 mLastWin = null;
5798 mLastBinder = null;
5799 if (failIfTimeout || targetWin == null) {
5800 return null;
5801 }
5802 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005803 Slog.w(TAG, "Continuing to wait for key to be dispatched");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005804 startTime = SystemClock.uptimeMillis();
5805 }
5806 }
5807 }
5808 }
5809 }
Romain Guy06882f82009-06-10 13:36:04 -07005810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005811 Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005812 MotionEvent nextMotion, boolean isPointerEvent,
5813 int callingPid, int callingUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005814 mOutsideTouchTargets = null;
Romain Guy06882f82009-06-10 13:36:04 -07005815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005816 if (nextKey != null) {
5817 // Find the target window for a normal key event.
5818 final int keycode = nextKey.getKeyCode();
5819 final int repeatCount = nextKey.getRepeatCount();
5820 final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP;
5821 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005823 if (!dispatch) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005824 if (callingUid == 0 ||
5825 mContext.checkPermission(
5826 android.Manifest.permission.INJECT_EVENTS,
5827 callingPid, callingUid)
5828 == PackageManager.PERMISSION_GRANTED) {
5829 mPolicy.interceptKeyTi(null, keycode,
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07005830 nextKey.getMetaState(), down, repeatCount,
5831 nextKey.getFlags());
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005832 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08005833 Slog.w(TAG, "Event timeout during app switch: dropping "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005834 + nextKey);
5835 return SKIP_TARGET_TOKEN;
5836 }
Romain Guy06882f82009-06-10 13:36:04 -07005837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005838 // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")");
Romain Guy06882f82009-06-10 13:36:04 -07005839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005840 WindowState focus = null;
5841 synchronized(mWindowMap) {
5842 focus = getFocusedWindowLocked();
5843 }
Romain Guy06882f82009-06-10 13:36:04 -07005844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005845 wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT);
Romain Guy06882f82009-06-10 13:36:04 -07005846
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005847 if (callingUid == 0 ||
5848 (focus != null && callingUid == focus.mSession.mUid) ||
5849 mContext.checkPermission(
5850 android.Manifest.permission.INJECT_EVENTS,
5851 callingPid, callingUid)
5852 == PackageManager.PERMISSION_GRANTED) {
5853 if (mPolicy.interceptKeyTi(focus,
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005854 keycode, nextKey.getMetaState(), down, repeatCount,
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07005855 nextKey.getFlags())) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005856 return CONSUMED_EVENT_TOKEN;
5857 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005858 }
Romain Guy06882f82009-06-10 13:36:04 -07005859
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005860 return focus;
Romain Guy06882f82009-06-10 13:36:04 -07005861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005862 } else if (!isPointerEvent) {
5863 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1);
5864 if (!dispatch) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005865 Slog.w(TAG, "Event timeout during app switch: dropping trackball "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005866 + nextMotion);
5867 return SKIP_TARGET_TOKEN;
5868 }
Romain Guy06882f82009-06-10 13:36:04 -07005869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005870 WindowState focus = null;
5871 synchronized(mWindowMap) {
5872 focus = getFocusedWindowLocked();
5873 }
Romain Guy06882f82009-06-10 13:36:04 -07005874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005875 wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT);
5876 return focus;
5877 }
Romain Guy06882f82009-06-10 13:36:04 -07005878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005879 if (nextMotion == null) {
5880 return SKIP_TARGET_TOKEN;
5881 }
Romain Guy06882f82009-06-10 13:36:04 -07005882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005883 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(
5884 KeyEvent.KEYCODE_UNKNOWN);
5885 if (!dispatch) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005886 Slog.w(TAG, "Event timeout during app switch: dropping pointer "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005887 + nextMotion);
5888 return SKIP_TARGET_TOKEN;
5889 }
Romain Guy06882f82009-06-10 13:36:04 -07005890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005891 // Find the target window for a pointer event.
5892 int action = nextMotion.getAction();
5893 final float xf = nextMotion.getX();
5894 final float yf = nextMotion.getY();
5895 final long eventTime = nextMotion.getEventTime();
Romain Guy06882f82009-06-10 13:36:04 -07005896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005897 final boolean screenWasOff = qev != null
5898 && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07005899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005900 WindowState target = null;
Romain Guy06882f82009-06-10 13:36:04 -07005901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005902 synchronized(mWindowMap) {
5903 synchronized (this) {
5904 if (action == MotionEvent.ACTION_DOWN) {
5905 if (mMotionTarget != null) {
5906 // this is weird, we got a pen down, but we thought it was
5907 // already down!
5908 // XXX: We should probably send an ACTION_UP to the current
5909 // target.
Joe Onorato8a9b2202010-02-26 18:56:32 -08005910 Slog.w(TAG, "Pointer down received while already down in: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005911 + mMotionTarget);
5912 mMotionTarget = null;
5913 }
Romain Guy06882f82009-06-10 13:36:04 -07005914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005915 // ACTION_DOWN is special, because we need to lock next events to
5916 // the window we'll land onto.
5917 final int x = (int)xf;
5918 final int y = (int)yf;
Romain Guy06882f82009-06-10 13:36:04 -07005919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005920 final ArrayList windows = mWindows;
5921 final int N = windows.size();
5922 WindowState topErrWindow = null;
5923 final Rect tmpRect = mTempRect;
5924 for (int i=N-1; i>=0; i--) {
5925 WindowState child = (WindowState)windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005926 //Slog.i(TAG, "Checking dispatch to: " + child);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005927 final int flags = child.mAttrs.flags;
5928 if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) {
5929 if (topErrWindow == null) {
5930 topErrWindow = child;
5931 }
5932 }
5933 if (!child.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005934 //Slog.i(TAG, "Not visible!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005935 continue;
5936 }
5937 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005938 //Slog.i(TAG, "Not touchable!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005939 if ((flags & WindowManager.LayoutParams
5940 .FLAG_WATCH_OUTSIDE_TOUCH) != 0) {
5941 child.mNextOutsideTouch = mOutsideTouchTargets;
5942 mOutsideTouchTargets = child;
5943 }
5944 continue;
5945 }
5946 tmpRect.set(child.mFrame);
5947 if (child.mTouchableInsets == ViewTreeObserver
5948 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
5949 // The touch is inside of the window if it is
5950 // inside the frame, AND the content part of that
5951 // frame that was given by the application.
5952 tmpRect.left += child.mGivenContentInsets.left;
5953 tmpRect.top += child.mGivenContentInsets.top;
5954 tmpRect.right -= child.mGivenContentInsets.right;
5955 tmpRect.bottom -= child.mGivenContentInsets.bottom;
5956 } else if (child.mTouchableInsets == ViewTreeObserver
5957 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
5958 // The touch is inside of the window if it is
5959 // inside the frame, AND the visible part of that
5960 // frame that was given by the application.
5961 tmpRect.left += child.mGivenVisibleInsets.left;
5962 tmpRect.top += child.mGivenVisibleInsets.top;
5963 tmpRect.right -= child.mGivenVisibleInsets.right;
5964 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
5965 }
5966 final int touchFlags = flags &
5967 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
5968 |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
5969 if (tmpRect.contains(x, y) || touchFlags == 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005970 //Slog.i(TAG, "Using this target!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005971 if (!screenWasOff || (flags &
5972 WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) {
5973 mMotionTarget = child;
5974 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005975 //Slog.i(TAG, "Waking, skip!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005976 mMotionTarget = null;
5977 }
5978 break;
5979 }
Romain Guy06882f82009-06-10 13:36:04 -07005980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005981 if ((flags & WindowManager.LayoutParams
5982 .FLAG_WATCH_OUTSIDE_TOUCH) != 0) {
5983 child.mNextOutsideTouch = mOutsideTouchTargets;
5984 mOutsideTouchTargets = child;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005985 //Slog.i(TAG, "Adding to outside target list: " + child);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005986 }
5987 }
5988
5989 // if there's an error window but it's not accepting
5990 // focus (typically because it is not yet visible) just
5991 // wait for it -- any other focused window may in fact
5992 // be in ANR state.
5993 if (topErrWindow != null && mMotionTarget != topErrWindow) {
5994 mMotionTarget = null;
5995 }
5996 }
Romain Guy06882f82009-06-10 13:36:04 -07005997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005998 target = mMotionTarget;
5999 }
6000 }
Romain Guy06882f82009-06-10 13:36:04 -07006001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006002 wakeupIfNeeded(target, eventType(nextMotion));
Romain Guy06882f82009-06-10 13:36:04 -07006003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006004 // Pointer events are a little different -- if there isn't a
6005 // target found for any event, then just drop it.
6006 return target != null ? target : SKIP_TARGET_TOKEN;
6007 }
Romain Guy06882f82009-06-10 13:36:04 -07006008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006009 boolean checkShouldDispatchKey(int keycode) {
6010 synchronized (this) {
6011 if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) {
6012 mTimeToSwitch = 0;
6013 return true;
6014 }
6015 if (mTimeToSwitch != 0
6016 && mTimeToSwitch < SystemClock.uptimeMillis()) {
6017 return false;
6018 }
6019 return true;
6020 }
6021 }
Romain Guy06882f82009-06-10 13:36:04 -07006022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006023 void bindTargetWindowLocked(WindowState win,
6024 int pendingWhat, QueuedEvent pendingMotion) {
6025 synchronized (this) {
6026 bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion);
6027 }
6028 }
Romain Guy06882f82009-06-10 13:36:04 -07006029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006030 void bindTargetWindowLocked(WindowState win) {
6031 synchronized (this) {
6032 bindTargetWindowLockedLocked(win, RETURN_NOTHING, null);
6033 }
6034 }
6035
6036 void bindTargetWindowLockedLocked(WindowState win,
6037 int pendingWhat, QueuedEvent pendingMotion) {
6038 mLastWin = win;
6039 mLastBinder = win.mClient.asBinder();
6040 mFinished = false;
6041 if (pendingMotion != null) {
6042 final Session s = win.mSession;
6043 if (pendingWhat == RETURN_PENDING_POINTER) {
6044 releasePendingPointerLocked(s);
6045 s.mPendingPointerMove = pendingMotion;
6046 s.mPendingPointerWindow = win;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006047 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006048 "bindTargetToWindow " + s.mPendingPointerMove);
6049 } else if (pendingWhat == RETURN_PENDING_TRACKBALL) {
6050 releasePendingTrackballLocked(s);
6051 s.mPendingTrackballMove = pendingMotion;
6052 s.mPendingTrackballWindow = win;
6053 }
6054 }
6055 }
Romain Guy06882f82009-06-10 13:36:04 -07006056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006057 void releasePendingPointerLocked(Session s) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006058 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006059 "releasePendingPointer " + s.mPendingPointerMove);
6060 if (s.mPendingPointerMove != null) {
6061 mQueue.recycleEvent(s.mPendingPointerMove);
6062 s.mPendingPointerMove = null;
6063 }
6064 }
Romain Guy06882f82009-06-10 13:36:04 -07006065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006066 void releasePendingTrackballLocked(Session s) {
6067 if (s.mPendingTrackballMove != null) {
6068 mQueue.recycleEvent(s.mPendingTrackballMove);
6069 s.mPendingTrackballMove = null;
6070 }
6071 }
Romain Guy06882f82009-06-10 13:36:04 -07006072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006073 MotionEvent finishedKey(Session session, IWindow client, boolean force,
6074 int returnWhat) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006075 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006076 TAG, "finishedKey: client=" + client + ", force=" + force);
6077
6078 if (client == null) {
6079 return null;
6080 }
6081
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006082 MotionEvent res = null;
6083 QueuedEvent qev = null;
6084 WindowState win = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006086 synchronized (this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006087 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006088 TAG, "finishedKey: client=" + client.asBinder()
6089 + ", force=" + force + ", last=" + mLastBinder
6090 + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")");
6091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006092 if (returnWhat == RETURN_PENDING_POINTER) {
6093 qev = session.mPendingPointerMove;
6094 win = session.mPendingPointerWindow;
6095 session.mPendingPointerMove = null;
6096 session.mPendingPointerWindow = null;
6097 } else if (returnWhat == RETURN_PENDING_TRACKBALL) {
6098 qev = session.mPendingTrackballMove;
6099 win = session.mPendingTrackballWindow;
6100 session.mPendingTrackballMove = null;
6101 session.mPendingTrackballWindow = null;
6102 }
Romain Guy06882f82009-06-10 13:36:04 -07006103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006104 if (mLastBinder == client.asBinder()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006105 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006106 TAG, "finishedKey: last paused="
6107 + ((mLastWin != null) ? mLastWin.mToken.paused : "null"));
6108 if (mLastWin != null && (!mLastWin.mToken.paused || force
6109 || !mEventDispatching)) {
Christopher Tate136b1f92010-02-11 17:51:24 -08006110 doFinishedKeyLocked(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006111 } else {
6112 // Make sure to wake up anyone currently waiting to
6113 // dispatch a key, so they can re-evaluate their
6114 // current situation.
6115 mFinished = true;
6116 notifyAll();
6117 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006118 }
Romain Guy06882f82009-06-10 13:36:04 -07006119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006120 if (qev != null) {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006121 res = (MotionEvent)qev.event;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006122 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006123 "Returning pending motion: " + res);
6124 mQueue.recycleEvent(qev);
6125 if (win != null && returnWhat == RETURN_PENDING_POINTER) {
6126 res.offsetLocation(-win.mFrame.left, -win.mFrame.top);
6127 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006128 }
Christopher Tate2624fbc2009-12-11 12:11:31 -08006129 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006130
Christopher Tate2624fbc2009-12-11 12:11:31 -08006131 if (res != null && returnWhat == RETURN_PENDING_POINTER) {
6132 synchronized (mWindowMap) {
Dianne Hackborn90d2db32010-02-11 22:19:06 -08006133 dispatchPointerElsewhereLocked(win, win, res, res.getEventTime(), false);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006134 }
6135 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006136
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006137 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006138 }
6139
6140 void tickle() {
6141 synchronized (this) {
6142 notifyAll();
6143 }
6144 }
Romain Guy06882f82009-06-10 13:36:04 -07006145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006146 void handleNewWindowLocked(WindowState newWindow) {
6147 if (!newWindow.canReceiveKeys()) {
6148 return;
6149 }
6150 synchronized (this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006151 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006152 TAG, "New key dispatch window: win="
6153 + newWindow.mClient.asBinder()
6154 + ", last=" + mLastBinder
6155 + " (token=" + (mLastWin != null ? mLastWin.mToken : null)
6156 + "), finished=" + mFinished + ", paused="
6157 + newWindow.mToken.paused);
6158
6159 // Displaying a window implicitly causes dispatching to
6160 // be unpaused. (This is to protect against bugs if someone
6161 // pauses dispatching but forgets to resume.)
6162 newWindow.mToken.paused = false;
6163
6164 mGotFirstWindow = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006165
6166 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006167 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006168 "New SYSTEM_ERROR window; resetting state");
6169 mLastWin = null;
6170 mLastBinder = null;
6171 mMotionTarget = null;
6172 mFinished = true;
6173 } else if (mLastWin != null) {
6174 // If the new window is above the window we are
6175 // waiting on, then stop waiting and let key dispatching
6176 // start on the new guy.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006177 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006178 TAG, "Last win layer=" + mLastWin.mLayer
6179 + ", new win layer=" + newWindow.mLayer);
6180 if (newWindow.mLayer >= mLastWin.mLayer) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08006181 // The new window is above the old; finish pending input to the last
6182 // window and start directing it to the new one.
6183 mLastWin.mToken.paused = false;
Christopher Tate136b1f92010-02-11 17:51:24 -08006184 doFinishedKeyLocked(false); // does a notifyAll()
6185 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006186 }
6187 }
6188
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08006189 // Now that we've put a new window state in place, make the event waiter
6190 // take notice and retarget its attentions.
6191 notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006192 }
6193 }
6194
6195 void pauseDispatchingLocked(WindowToken token) {
6196 synchronized (this)
6197 {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006198 if (DEBUG_INPUT) Slog.v(TAG, "Pausing WindowToken " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006199 token.paused = true;
6200
6201 /*
6202 if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) {
6203 mPaused = true;
6204 } else {
6205 if (mLastWin == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006206 Slog.i(TAG, "Key dispatching not paused: no last window.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006207 } else if (mFinished) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006208 Slog.i(TAG, "Key dispatching not paused: finished last key.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006209 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006210 Slog.i(TAG, "Key dispatching not paused: window in higher layer.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006211 }
6212 }
6213 */
6214 }
6215 }
6216
6217 void resumeDispatchingLocked(WindowToken token) {
6218 synchronized (this) {
6219 if (token.paused) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006220 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006221 TAG, "Resuming WindowToken " + token
6222 + ", last=" + mLastBinder
6223 + " (token=" + (mLastWin != null ? mLastWin.mToken : null)
6224 + "), finished=" + mFinished + ", paused="
6225 + token.paused);
6226 token.paused = false;
6227 if (mLastWin != null && mLastWin.mToken == token && mFinished) {
Christopher Tate136b1f92010-02-11 17:51:24 -08006228 doFinishedKeyLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006229 } else {
6230 notifyAll();
6231 }
6232 }
6233 }
6234 }
6235
6236 void setEventDispatchingLocked(boolean enabled) {
6237 synchronized (this) {
6238 mEventDispatching = enabled;
6239 notifyAll();
6240 }
6241 }
Romain Guy06882f82009-06-10 13:36:04 -07006242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006243 void appSwitchComing() {
6244 synchronized (this) {
6245 // Don't wait for more than .5 seconds for app to finish
6246 // processing the pending events.
6247 long now = SystemClock.uptimeMillis() + 500;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006248 if (DEBUG_INPUT) Slog.v(TAG, "appSwitchComing: " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006249 if (mTimeToSwitch == 0 || now < mTimeToSwitch) {
6250 mTimeToSwitch = now;
6251 }
6252 notifyAll();
6253 }
6254 }
Romain Guy06882f82009-06-10 13:36:04 -07006255
Christopher Tate136b1f92010-02-11 17:51:24 -08006256 private final void doFinishedKeyLocked(boolean force) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006257 if (mLastWin != null) {
6258 releasePendingPointerLocked(mLastWin.mSession);
6259 releasePendingTrackballLocked(mLastWin.mSession);
6260 }
Romain Guy06882f82009-06-10 13:36:04 -07006261
Christopher Tate136b1f92010-02-11 17:51:24 -08006262 if (force || mLastWin == null || !mLastWin.mToken.paused
6263 || !mLastWin.isVisibleLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006264 // If the current window has been paused, we aren't -really-
6265 // finished... so let the waiters still wait.
6266 mLastWin = null;
6267 mLastBinder = null;
6268 }
6269 mFinished = true;
6270 notifyAll();
6271 }
6272 }
6273
6274 private class KeyQ extends KeyInputQueue
6275 implements KeyInputQueue.FilterCallback {
6276 PowerManager.WakeLock mHoldingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07006277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006278 KeyQ() {
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07006279 super(mContext, WindowManagerService.this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006280 PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
6281 mHoldingScreen = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
6282 "KEEP_SCREEN_ON_FLAG");
6283 mHoldingScreen.setReferenceCounted(false);
6284 }
6285
6286 @Override
6287 boolean preprocessEvent(InputDevice device, RawInputEvent event) {
6288 if (mPolicy.preprocessInputEventTq(event)) {
6289 return true;
6290 }
Romain Guy06882f82009-06-10 13:36:04 -07006291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006292 switch (event.type) {
6293 case RawInputEvent.EV_KEY: {
6294 // XXX begin hack
6295 if (DEBUG) {
6296 if (event.keycode == KeyEvent.KEYCODE_G) {
6297 if (event.value != 0) {
6298 // G down
6299 mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
6300 }
6301 return false;
6302 }
6303 if (event.keycode == KeyEvent.KEYCODE_D) {
6304 if (event.value != 0) {
6305 //dump();
6306 }
6307 return false;
6308 }
6309 }
6310 // XXX end hack
Romain Guy06882f82009-06-10 13:36:04 -07006311
Charles Mendis322591c2009-10-29 11:06:59 -07006312 boolean screenIsOff = !mPowerManager.isScreenOn();
6313 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006314 int actions = mPolicy.interceptKeyTq(event, !screenIsOff);
Romain Guy06882f82009-06-10 13:36:04 -07006315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006316 if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) {
6317 mPowerManager.goToSleep(event.when);
6318 }
6319
6320 if (screenIsOff) {
6321 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6322 }
6323 if (screenIsDim) {
6324 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6325 }
6326 if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) {
6327 mPowerManager.userActivity(event.when, false,
Michael Chane96440f2009-05-06 10:27:36 -07006328 LocalPowerManager.BUTTON_EVENT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006329 }
Romain Guy06882f82009-06-10 13:36:04 -07006330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006331 if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) {
6332 if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) {
6333 filterQueue(this);
6334 mKeyWaiter.appSwitchComing();
6335 }
6336 return true;
6337 } else {
6338 return false;
6339 }
6340 }
Romain Guy06882f82009-06-10 13:36:04 -07006341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006342 case RawInputEvent.EV_REL: {
Charles Mendis322591c2009-10-29 11:06:59 -07006343 boolean screenIsOff = !mPowerManager.isScreenOn();
6344 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006345 if (screenIsOff) {
6346 if (!mPolicy.isWakeRelMovementTq(event.deviceId,
6347 device.classes, event)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006348 //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006349 return false;
6350 }
6351 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6352 }
6353 if (screenIsDim) {
6354 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6355 }
6356 return true;
6357 }
Romain Guy06882f82009-06-10 13:36:04 -07006358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006359 case RawInputEvent.EV_ABS: {
Charles Mendis322591c2009-10-29 11:06:59 -07006360 boolean screenIsOff = !mPowerManager.isScreenOn();
6361 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006362 if (screenIsOff) {
6363 if (!mPolicy.isWakeAbsMovementTq(event.deviceId,
6364 device.classes, event)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006365 //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006366 return false;
6367 }
6368 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6369 }
6370 if (screenIsDim) {
6371 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6372 }
6373 return true;
6374 }
Romain Guy06882f82009-06-10 13:36:04 -07006375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006376 default:
6377 return true;
6378 }
6379 }
6380
6381 public int filterEvent(QueuedEvent ev) {
6382 switch (ev.classType) {
6383 case RawInputEvent.CLASS_KEYBOARD:
6384 KeyEvent ke = (KeyEvent)ev.event;
6385 if (mPolicy.isMovementKeyTi(ke.getKeyCode())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006386 Slog.w(TAG, "Dropping movement key during app switch: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006387 + ke.getKeyCode() + ", action=" + ke.getAction());
6388 return FILTER_REMOVE;
6389 }
6390 return FILTER_ABORT;
6391 default:
6392 return FILTER_KEEP;
6393 }
6394 }
Romain Guy06882f82009-06-10 13:36:04 -07006395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006396 /**
6397 * Must be called with the main window manager lock held.
6398 */
6399 void setHoldScreenLocked(boolean holding) {
6400 boolean state = mHoldingScreen.isHeld();
6401 if (holding != state) {
6402 if (holding) {
6403 mHoldingScreen.acquire();
6404 } else {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006405 mPolicy.screenOnStoppedLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006406 mHoldingScreen.release();
6407 }
6408 }
6409 }
Michael Chan53071d62009-05-13 17:29:48 -07006410 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006411
6412 public boolean detectSafeMode() {
6413 mSafeMode = mPolicy.detectSafeMode();
6414 return mSafeMode;
6415 }
Romain Guy06882f82009-06-10 13:36:04 -07006416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006417 public void systemReady() {
6418 mPolicy.systemReady();
6419 }
Romain Guy06882f82009-06-10 13:36:04 -07006420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006421 private final class InputDispatcherThread extends Thread {
6422 // Time to wait when there is nothing to do: 9999 seconds.
6423 static final int LONG_WAIT=9999*1000;
6424
6425 public InputDispatcherThread() {
6426 super("InputDispatcher");
6427 }
Romain Guy06882f82009-06-10 13:36:04 -07006428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006429 @Override
6430 public void run() {
6431 while (true) {
6432 try {
6433 process();
6434 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006435 Slog.e(TAG, "Exception in input dispatcher", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006436 }
6437 }
6438 }
Romain Guy06882f82009-06-10 13:36:04 -07006439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006440 private void process() {
6441 android.os.Process.setThreadPriority(
6442 android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);
Romain Guy06882f82009-06-10 13:36:04 -07006443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006444 // The last key event we saw
6445 KeyEvent lastKey = null;
6446
6447 // Last keydown time for auto-repeating keys
6448 long lastKeyTime = SystemClock.uptimeMillis();
6449 long nextKeyTime = lastKeyTime+LONG_WAIT;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006450 long downTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006451
Romain Guy06882f82009-06-10 13:36:04 -07006452 // How many successive repeats we generated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006453 int keyRepeatCount = 0;
6454
6455 // Need to report that configuration has changed?
6456 boolean configChanged = false;
Romain Guy06882f82009-06-10 13:36:04 -07006457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006458 while (true) {
6459 long curTime = SystemClock.uptimeMillis();
6460
Joe Onorato8a9b2202010-02-26 18:56:32 -08006461 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006462 TAG, "Waiting for next key: now=" + curTime
6463 + ", repeat @ " + nextKeyTime);
6464
6465 // Retrieve next event, waiting only as long as the next
6466 // repeat timeout. If the configuration has changed, then
6467 // don't wait at all -- we'll report the change as soon as
6468 // we have processed all events.
6469 QueuedEvent ev = mQueue.getEvent(
6470 (int)((!configChanged && curTime < nextKeyTime)
6471 ? (nextKeyTime-curTime) : 0));
6472
Joe Onorato8a9b2202010-02-26 18:56:32 -08006473 if (DEBUG_INPUT && ev != null) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006474 TAG, "Event: type=" + ev.classType + " data=" + ev.event);
6475
Michael Chan53071d62009-05-13 17:29:48 -07006476 if (MEASURE_LATENCY) {
6477 lt.sample("2 got event ", System.nanoTime() - ev.whenNano);
6478 }
6479
Mike Lockwood3d0ea722009-10-21 22:58:29 -04006480 if (lastKey != null && !mPolicy.allowKeyRepeat()) {
6481 // cancel key repeat at the request of the policy.
6482 lastKey = null;
6483 downTime = 0;
6484 lastKeyTime = curTime;
6485 nextKeyTime = curTime + LONG_WAIT;
6486 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006487 try {
6488 if (ev != null) {
Michael Chan53071d62009-05-13 17:29:48 -07006489 curTime = SystemClock.uptimeMillis();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006490 int eventType;
6491 if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) {
6492 eventType = eventType((MotionEvent)ev.event);
6493 } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD ||
6494 ev.classType == RawInputEvent.CLASS_TRACKBALL) {
6495 eventType = LocalPowerManager.BUTTON_EVENT;
6496 } else {
6497 eventType = LocalPowerManager.OTHER_EVENT;
6498 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07006499 try {
Michael Chan53071d62009-05-13 17:29:48 -07006500 if ((curTime - mLastBatteryStatsCallTime)
Michael Chane96440f2009-05-06 10:27:36 -07006501 >= MIN_TIME_BETWEEN_USERACTIVITIES) {
Michael Chan53071d62009-05-13 17:29:48 -07006502 mLastBatteryStatsCallTime = curTime;
Michael Chane96440f2009-05-06 10:27:36 -07006503 mBatteryStats.noteInputEvent();
6504 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07006505 } catch (RemoteException e) {
6506 // Ignore
6507 }
Michael Chane10de972009-05-18 11:24:50 -07006508
Mike Lockwood5db42402009-11-30 14:51:51 -05006509 if (ev.classType == RawInputEvent.CLASS_CONFIGURATION_CHANGED) {
6510 // do not wake screen in this case
6511 } else if (eventType != TOUCH_EVENT
Michael Chane10de972009-05-18 11:24:50 -07006512 && eventType != LONG_TOUCH_EVENT
6513 && eventType != CHEEK_EVENT) {
6514 mPowerManager.userActivity(curTime, false,
6515 eventType, false);
6516 } else if (mLastTouchEventType != eventType
6517 || (curTime - mLastUserActivityCallTime)
6518 >= MIN_TIME_BETWEEN_USERACTIVITIES) {
6519 mLastUserActivityCallTime = curTime;
6520 mLastTouchEventType = eventType;
6521 mPowerManager.userActivity(curTime, false,
6522 eventType, false);
6523 }
6524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006525 switch (ev.classType) {
6526 case RawInputEvent.CLASS_KEYBOARD:
6527 KeyEvent ke = (KeyEvent)ev.event;
6528 if (ke.isDown()) {
6529 lastKey = ke;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006530 downTime = curTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006531 keyRepeatCount = 0;
6532 lastKeyTime = curTime;
6533 nextKeyTime = lastKeyTime
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006534 + ViewConfiguration.getLongPressTimeout();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006535 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006536 TAG, "Received key down: first repeat @ "
6537 + nextKeyTime);
6538 } else {
6539 lastKey = null;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006540 downTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006541 // Arbitrary long timeout.
6542 lastKeyTime = curTime;
6543 nextKeyTime = curTime + LONG_WAIT;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006544 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006545 TAG, "Received key up: ignore repeat @ "
6546 + nextKeyTime);
6547 }
6548 dispatchKey((KeyEvent)ev.event, 0, 0);
6549 mQueue.recycleEvent(ev);
6550 break;
6551 case RawInputEvent.CLASS_TOUCHSCREEN:
Joe Onorato8a9b2202010-02-26 18:56:32 -08006552 //Slog.i(TAG, "Read next event " + ev);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006553 dispatchPointer(ev, (MotionEvent)ev.event, 0, 0);
6554 break;
6555 case RawInputEvent.CLASS_TRACKBALL:
6556 dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0);
6557 break;
6558 case RawInputEvent.CLASS_CONFIGURATION_CHANGED:
6559 configChanged = true;
6560 break;
6561 default:
6562 mQueue.recycleEvent(ev);
6563 break;
6564 }
Romain Guy06882f82009-06-10 13:36:04 -07006565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006566 } else if (configChanged) {
6567 configChanged = false;
6568 sendNewConfiguration();
Romain Guy06882f82009-06-10 13:36:04 -07006569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006570 } else if (lastKey != null) {
6571 curTime = SystemClock.uptimeMillis();
Romain Guy06882f82009-06-10 13:36:04 -07006572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006573 // Timeout occurred while key was down. If it is at or
6574 // past the key repeat time, dispatch the repeat.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006575 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006576 TAG, "Key timeout: repeat=" + nextKeyTime
6577 + ", now=" + curTime);
6578 if (curTime < nextKeyTime) {
6579 continue;
6580 }
Romain Guy06882f82009-06-10 13:36:04 -07006581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006582 lastKeyTime = nextKeyTime;
6583 nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY;
6584 keyRepeatCount++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006585 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006586 TAG, "Key repeat: count=" + keyRepeatCount
6587 + ", next @ " + nextKeyTime);
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006588 KeyEvent newEvent;
6589 if (downTime != 0 && (downTime
6590 + ViewConfiguration.getLongPressTimeout())
6591 <= curTime) {
6592 newEvent = KeyEvent.changeTimeRepeat(lastKey,
6593 curTime, keyRepeatCount,
6594 lastKey.getFlags() | KeyEvent.FLAG_LONG_PRESS);
6595 downTime = 0;
6596 } else {
6597 newEvent = KeyEvent.changeTimeRepeat(lastKey,
6598 curTime, keyRepeatCount);
6599 }
6600 dispatchKey(newEvent, 0, 0);
Romain Guy06882f82009-06-10 13:36:04 -07006601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006602 } else {
6603 curTime = SystemClock.uptimeMillis();
Romain Guy06882f82009-06-10 13:36:04 -07006604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006605 lastKeyTime = curTime;
6606 nextKeyTime = curTime + LONG_WAIT;
6607 }
Romain Guy06882f82009-06-10 13:36:04 -07006608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006609 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006610 Slog.e(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006611 "Input thread received uncaught exception: " + e, e);
6612 }
6613 }
6614 }
6615 }
6616
6617 // -------------------------------------------------------------
6618 // Client Session State
6619 // -------------------------------------------------------------
6620
6621 private final class Session extends IWindowSession.Stub
6622 implements IBinder.DeathRecipient {
6623 final IInputMethodClient mClient;
6624 final IInputContext mInputContext;
6625 final int mUid;
6626 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006627 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006628 SurfaceSession mSurfaceSession;
6629 int mNumWindow = 0;
6630 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006632 /**
6633 * Current pointer move event being dispatched to client window... must
6634 * hold key lock to access.
6635 */
6636 QueuedEvent mPendingPointerMove;
6637 WindowState mPendingPointerWindow;
Romain Guy06882f82009-06-10 13:36:04 -07006638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006639 /**
6640 * Current trackball move event being dispatched to client window... must
6641 * hold key lock to access.
6642 */
6643 QueuedEvent mPendingTrackballMove;
6644 WindowState mPendingTrackballWindow;
6645
6646 public Session(IInputMethodClient client, IInputContext inputContext) {
6647 mClient = client;
6648 mInputContext = inputContext;
6649 mUid = Binder.getCallingUid();
6650 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006651 StringBuilder sb = new StringBuilder();
6652 sb.append("Session{");
6653 sb.append(Integer.toHexString(System.identityHashCode(this)));
6654 sb.append(" uid ");
6655 sb.append(mUid);
6656 sb.append("}");
6657 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006659 synchronized (mWindowMap) {
6660 if (mInputMethodManager == null && mHaveInputMethods) {
6661 IBinder b = ServiceManager.getService(
6662 Context.INPUT_METHOD_SERVICE);
6663 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6664 }
6665 }
6666 long ident = Binder.clearCallingIdentity();
6667 try {
6668 // Note: it is safe to call in to the input method manager
6669 // here because we are not holding our lock.
6670 if (mInputMethodManager != null) {
6671 mInputMethodManager.addClient(client, inputContext,
6672 mUid, mPid);
6673 } else {
6674 client.setUsingInputMethod(false);
6675 }
6676 client.asBinder().linkToDeath(this, 0);
6677 } catch (RemoteException e) {
6678 // The caller has died, so we can just forget about this.
6679 try {
6680 if (mInputMethodManager != null) {
6681 mInputMethodManager.removeClient(client);
6682 }
6683 } catch (RemoteException ee) {
6684 }
6685 } finally {
6686 Binder.restoreCallingIdentity(ident);
6687 }
6688 }
Romain Guy06882f82009-06-10 13:36:04 -07006689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006690 @Override
6691 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6692 throws RemoteException {
6693 try {
6694 return super.onTransact(code, data, reply, flags);
6695 } catch (RuntimeException e) {
6696 // Log all 'real' exceptions thrown to the caller
6697 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006698 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006699 }
6700 throw e;
6701 }
6702 }
6703
6704 public void binderDied() {
6705 // Note: it is safe to call in to the input method manager
6706 // here because we are not holding our lock.
6707 try {
6708 if (mInputMethodManager != null) {
6709 mInputMethodManager.removeClient(mClient);
6710 }
6711 } catch (RemoteException e) {
6712 }
6713 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006714 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006715 mClientDead = true;
6716 killSessionLocked();
6717 }
6718 }
6719
6720 public int add(IWindow window, WindowManager.LayoutParams attrs,
6721 int viewVisibility, Rect outContentInsets) {
6722 return addWindow(this, window, attrs, viewVisibility, outContentInsets);
6723 }
Romain Guy06882f82009-06-10 13:36:04 -07006724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006725 public void remove(IWindow window) {
6726 removeWindow(this, window);
6727 }
Romain Guy06882f82009-06-10 13:36:04 -07006728
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006729 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6730 int requestedWidth, int requestedHeight, int viewFlags,
6731 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006732 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006733 return relayoutWindow(this, window, attrs,
6734 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006735 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006736 }
Romain Guy06882f82009-06-10 13:36:04 -07006737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006738 public void setTransparentRegion(IWindow window, Region region) {
6739 setTransparentRegionWindow(this, window, region);
6740 }
Romain Guy06882f82009-06-10 13:36:04 -07006741
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006742 public void setInsets(IWindow window, int touchableInsets,
6743 Rect contentInsets, Rect visibleInsets) {
6744 setInsetsWindow(this, window, touchableInsets, contentInsets,
6745 visibleInsets);
6746 }
Romain Guy06882f82009-06-10 13:36:04 -07006747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006748 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6749 getWindowDisplayFrame(this, window, outDisplayFrame);
6750 }
Romain Guy06882f82009-06-10 13:36:04 -07006751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006752 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006753 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006754 TAG, "IWindow finishDrawing called for " + window);
6755 finishDrawingWindow(this, window);
6756 }
6757
6758 public void finishKey(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006759 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006760 TAG, "IWindow finishKey called for " + window);
6761 mKeyWaiter.finishedKey(this, window, false,
6762 KeyWaiter.RETURN_NOTHING);
6763 }
6764
6765 public MotionEvent getPendingPointerMove(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006766 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006767 TAG, "IWindow getPendingMotionEvent called for " + window);
6768 return mKeyWaiter.finishedKey(this, window, false,
6769 KeyWaiter.RETURN_PENDING_POINTER);
6770 }
Romain Guy06882f82009-06-10 13:36:04 -07006771
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006772 public MotionEvent getPendingTrackballMove(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006773 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006774 TAG, "IWindow getPendingMotionEvent called for " + window);
6775 return mKeyWaiter.finishedKey(this, window, false,
6776 KeyWaiter.RETURN_PENDING_TRACKBALL);
6777 }
6778
6779 public void setInTouchMode(boolean mode) {
6780 synchronized(mWindowMap) {
6781 mInTouchMode = mode;
6782 }
6783 }
6784
6785 public boolean getInTouchMode() {
6786 synchronized(mWindowMap) {
6787 return mInTouchMode;
6788 }
6789 }
6790
6791 public boolean performHapticFeedback(IWindow window, int effectId,
6792 boolean always) {
6793 synchronized(mWindowMap) {
6794 long ident = Binder.clearCallingIdentity();
6795 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006796 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006797 windowForClientLocked(this, window, true),
6798 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006799 } finally {
6800 Binder.restoreCallingIdentity(ident);
6801 }
6802 }
6803 }
Romain Guy06882f82009-06-10 13:36:04 -07006804
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006805 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006806 synchronized(mWindowMap) {
6807 long ident = Binder.clearCallingIdentity();
6808 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006809 setWindowWallpaperPositionLocked(
6810 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006811 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006812 } finally {
6813 Binder.restoreCallingIdentity(ident);
6814 }
6815 }
6816 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006817
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006818 public void wallpaperOffsetsComplete(IBinder window) {
6819 WindowManagerService.this.wallpaperOffsetsComplete(window);
6820 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006821
Dianne Hackborn75804932009-10-20 20:15:20 -07006822 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6823 int z, Bundle extras, boolean sync) {
6824 synchronized(mWindowMap) {
6825 long ident = Binder.clearCallingIdentity();
6826 try {
6827 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006828 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006829 action, x, y, z, extras, sync);
6830 } finally {
6831 Binder.restoreCallingIdentity(ident);
6832 }
6833 }
6834 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006835
Dianne Hackborn75804932009-10-20 20:15:20 -07006836 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6837 WindowManagerService.this.wallpaperCommandComplete(window, result);
6838 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006840 void windowAddedLocked() {
6841 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006842 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006843 TAG, "First window added to " + this + ", creating SurfaceSession");
6844 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006845 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006846 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006847 mSessions.add(this);
6848 }
6849 mNumWindow++;
6850 }
6851
6852 void windowRemovedLocked() {
6853 mNumWindow--;
6854 killSessionLocked();
6855 }
Romain Guy06882f82009-06-10 13:36:04 -07006856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006857 void killSessionLocked() {
6858 if (mNumWindow <= 0 && mClientDead) {
6859 mSessions.remove(this);
6860 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006861 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006862 TAG, "Last window removed from " + this
6863 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006864 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006865 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006866 try {
6867 mSurfaceSession.kill();
6868 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006869 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006870 + mSurfaceSession + " in session " + this
6871 + ": " + e.toString());
6872 }
6873 mSurfaceSession = null;
6874 }
6875 }
6876 }
Romain Guy06882f82009-06-10 13:36:04 -07006877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006878 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006879 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6880 pw.print(" mClientDead="); pw.print(mClientDead);
6881 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
6882 if (mPendingPointerWindow != null || mPendingPointerMove != null) {
6883 pw.print(prefix);
6884 pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow);
6885 pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove);
6886 }
6887 if (mPendingTrackballWindow != null || mPendingTrackballMove != null) {
6888 pw.print(prefix);
6889 pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow);
6890 pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove);
6891 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006892 }
6893
6894 @Override
6895 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006896 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006897 }
6898 }
6899
6900 // -------------------------------------------------------------
6901 // Client Window State
6902 // -------------------------------------------------------------
6903
6904 private final class WindowState implements WindowManagerPolicy.WindowState {
6905 final Session mSession;
6906 final IWindow mClient;
6907 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006908 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006909 AppWindowToken mAppToken;
6910 AppWindowToken mTargetAppToken;
6911 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6912 final DeathRecipient mDeathRecipient;
6913 final WindowState mAttachedWindow;
6914 final ArrayList mChildWindows = new ArrayList();
6915 final int mBaseLayer;
6916 final int mSubLayer;
6917 final boolean mLayoutAttached;
6918 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006919 final boolean mIsWallpaper;
6920 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006921 int mViewVisibility;
6922 boolean mPolicyVisibility = true;
6923 boolean mPolicyVisibilityAfterAnim = true;
6924 boolean mAppFreezing;
6925 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006926 boolean mReportDestroySurface;
6927 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006928 boolean mAttachedHidden; // is our parent window hidden?
6929 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006930 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006931 int mRequestedWidth;
6932 int mRequestedHeight;
6933 int mLastRequestedWidth;
6934 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006935 int mLayer;
6936 int mAnimLayer;
6937 int mLastLayer;
6938 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006939 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006940 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006941
6942 WindowState mNextOutsideTouch;
Romain Guy06882f82009-06-10 13:36:04 -07006943
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006944 int mLayoutSeq = -1;
6945
6946 Configuration mConfiguration = null;
6947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006948 // Actual frame shown on-screen (may be modified by animation)
6949 final Rect mShownFrame = new Rect();
6950 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006951
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006952 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006953 * Set when we have changed the size of the surface, to know that
6954 * we must tell them application to resize (and thus redraw itself).
6955 */
6956 boolean mSurfaceResized;
6957
6958 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006959 * Insets that determine the actually visible area
6960 */
6961 final Rect mVisibleInsets = new Rect();
6962 final Rect mLastVisibleInsets = new Rect();
6963 boolean mVisibleInsetsChanged;
6964
6965 /**
6966 * Insets that are covered by system windows
6967 */
6968 final Rect mContentInsets = new Rect();
6969 final Rect mLastContentInsets = new Rect();
6970 boolean mContentInsetsChanged;
6971
6972 /**
6973 * Set to true if we are waiting for this window to receive its
6974 * given internal insets before laying out other windows based on it.
6975 */
6976 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006978 /**
6979 * These are the content insets that were given during layout for
6980 * this window, to be applied to windows behind it.
6981 */
6982 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006984 /**
6985 * These are the visible insets that were given during layout for
6986 * this window, to be applied to windows behind it.
6987 */
6988 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006989
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006990 /**
6991 * Flag indicating whether the touchable region should be adjusted by
6992 * the visible insets; if false the area outside the visible insets is
6993 * NOT touchable, so we must use those to adjust the frame during hit
6994 * tests.
6995 */
6996 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006998 // Current transformation being applied.
6999 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
7000 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
7001 float mHScale=1, mVScale=1;
7002 float mLastHScale=1, mLastVScale=1;
7003 final Matrix mTmpMatrix = new Matrix();
7004
7005 // "Real" frame that the application sees.
7006 final Rect mFrame = new Rect();
7007 final Rect mLastFrame = new Rect();
7008
7009 final Rect mContainingFrame = new Rect();
7010 final Rect mDisplayFrame = new Rect();
7011 final Rect mContentFrame = new Rect();
7012 final Rect mVisibleFrame = new Rect();
7013
7014 float mShownAlpha = 1;
7015 float mAlpha = 1;
7016 float mLastAlpha = 1;
7017
7018 // Set to true if, when the window gets displayed, it should perform
7019 // an enter animation.
7020 boolean mEnterAnimationPending;
7021
7022 // Currently running animation.
7023 boolean mAnimating;
7024 boolean mLocalAnimating;
7025 Animation mAnimation;
7026 boolean mAnimationIsEntrance;
7027 boolean mHasTransformation;
7028 boolean mHasLocalTransformation;
7029 final Transformation mTransformation = new Transformation();
7030
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007031 // If a window showing a wallpaper: the requested offset for the
7032 // wallpaper; if a wallpaper window: the currently applied offset.
7033 float mWallpaperX = -1;
7034 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007035
7036 // If a window showing a wallpaper: what fraction of the offset
7037 // range corresponds to a full virtual screen.
7038 float mWallpaperXStep = -1;
7039 float mWallpaperYStep = -1;
7040
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007041 // Wallpaper windows: pixels offset based on above variables.
7042 int mXOffset;
7043 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007045 // This is set after IWindowSession.relayout() has been called at
7046 // least once for the window. It allows us to detect the situation
7047 // where we don't yet have a surface, but should have one soon, so
7048 // we can give the window focus before waiting for the relayout.
7049 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07007050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007051 // This is set after the Surface has been created but before the
7052 // window has been drawn. During this time the surface is hidden.
7053 boolean mDrawPending;
7054
7055 // This is set after the window has finished drawing for the first
7056 // time but before its surface is shown. The surface will be
7057 // displayed when the next layout is run.
7058 boolean mCommitDrawPending;
7059
7060 // This is set during the time after the window's drawing has been
7061 // committed, and before its surface is actually shown. It is used
7062 // to delay showing the surface until all windows in a token are ready
7063 // to be shown.
7064 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07007065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007066 // Set when the window has been shown in the screen the first time.
7067 boolean mHasDrawn;
7068
7069 // Currently running an exit animation?
7070 boolean mExiting;
7071
7072 // Currently on the mDestroySurface list?
7073 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07007074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007075 // Completely remove from window manager after exit animation?
7076 boolean mRemoveOnExit;
7077
7078 // Set when the orientation is changing and this window has not yet
7079 // been updated for the new orientation.
7080 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07007081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007082 // Is this window now (or just being) removed?
7083 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07007084
Dianne Hackborn16064f92010-03-25 00:47:24 -07007085 // For debugging, this is the last information given to the surface flinger.
7086 boolean mSurfaceShown;
7087 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
7088 int mSurfaceLayer;
7089 float mSurfaceAlpha;
7090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007091 WindowState(Session s, IWindow c, WindowToken token,
7092 WindowState attachedWindow, WindowManager.LayoutParams a,
7093 int viewVisibility) {
7094 mSession = s;
7095 mClient = c;
7096 mToken = token;
7097 mAttrs.copyFrom(a);
7098 mViewVisibility = viewVisibility;
7099 DeathRecipient deathRecipient = new DeathRecipient();
7100 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007101 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007102 TAG, "Window " + this + " client=" + c.asBinder()
7103 + " token=" + token + " (" + mAttrs.token + ")");
7104 try {
7105 c.asBinder().linkToDeath(deathRecipient, 0);
7106 } catch (RemoteException e) {
7107 mDeathRecipient = null;
7108 mAttachedWindow = null;
7109 mLayoutAttached = false;
7110 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007111 mIsWallpaper = false;
7112 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007113 mBaseLayer = 0;
7114 mSubLayer = 0;
7115 return;
7116 }
7117 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07007118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007119 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
7120 mAttrs.type <= LAST_SUB_WINDOW)) {
7121 // The multiplier here is to reserve space for multiple
7122 // windows in the same type layer.
7123 mBaseLayer = mPolicy.windowTypeToLayerLw(
7124 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
7125 + TYPE_LAYER_OFFSET;
7126 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
7127 mAttachedWindow = attachedWindow;
7128 mAttachedWindow.mChildWindows.add(this);
7129 mLayoutAttached = mAttrs.type !=
7130 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
7131 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
7132 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007133 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
7134 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007135 } else {
7136 // The multiplier here is to reserve space for multiple
7137 // windows in the same type layer.
7138 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
7139 * TYPE_LAYER_MULTIPLIER
7140 + TYPE_LAYER_OFFSET;
7141 mSubLayer = 0;
7142 mAttachedWindow = null;
7143 mLayoutAttached = false;
7144 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
7145 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007146 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
7147 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007148 }
7149
7150 WindowState appWin = this;
7151 while (appWin.mAttachedWindow != null) {
7152 appWin = mAttachedWindow;
7153 }
7154 WindowToken appToken = appWin.mToken;
7155 while (appToken.appWindowToken == null) {
7156 WindowToken parent = mTokenMap.get(appToken.token);
7157 if (parent == null || appToken == parent) {
7158 break;
7159 }
7160 appToken = parent;
7161 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007162 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007163 mAppToken = appToken.appWindowToken;
7164
7165 mSurface = null;
7166 mRequestedWidth = 0;
7167 mRequestedHeight = 0;
7168 mLastRequestedWidth = 0;
7169 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007170 mXOffset = 0;
7171 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007172 mLayer = 0;
7173 mAnimLayer = 0;
7174 mLastLayer = 0;
7175 }
7176
7177 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007178 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007179 TAG, "Attaching " + this + " token=" + mToken
7180 + ", list=" + mToken.windows);
7181 mSession.windowAddedLocked();
7182 }
7183
7184 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7185 mHaveFrame = true;
7186
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007187 final Rect container = mContainingFrame;
7188 container.set(pf);
7189
7190 final Rect display = mDisplayFrame;
7191 display.set(df);
7192
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007193 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007194 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007195 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7196 display.intersect(mCompatibleScreenFrame);
7197 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007198 }
7199
7200 final int pw = container.right - container.left;
7201 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007202
7203 int w,h;
7204 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7205 w = mAttrs.width < 0 ? pw : mAttrs.width;
7206 h = mAttrs.height< 0 ? ph : mAttrs.height;
7207 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007208 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7209 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007210 }
Romain Guy06882f82009-06-10 13:36:04 -07007211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007212 final Rect content = mContentFrame;
7213 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007215 final Rect visible = mVisibleFrame;
7216 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007218 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007219 final int fw = frame.width();
7220 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007222 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7223 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7224
7225 Gravity.apply(mAttrs.gravity, w, h, container,
7226 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7227 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7228
7229 //System.out.println("Out: " + mFrame);
7230
7231 // Now make sure the window fits in the overall display.
7232 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007233
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007234 // Make sure the content and visible frames are inside of the
7235 // final window frame.
7236 if (content.left < frame.left) content.left = frame.left;
7237 if (content.top < frame.top) content.top = frame.top;
7238 if (content.right > frame.right) content.right = frame.right;
7239 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7240 if (visible.left < frame.left) visible.left = frame.left;
7241 if (visible.top < frame.top) visible.top = frame.top;
7242 if (visible.right > frame.right) visible.right = frame.right;
7243 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007245 final Rect contentInsets = mContentInsets;
7246 contentInsets.left = content.left-frame.left;
7247 contentInsets.top = content.top-frame.top;
7248 contentInsets.right = frame.right-content.right;
7249 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007251 final Rect visibleInsets = mVisibleInsets;
7252 visibleInsets.left = visible.left-frame.left;
7253 visibleInsets.top = visible.top-frame.top;
7254 visibleInsets.right = frame.right-visible.right;
7255 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007256
Dianne Hackborn284ac932009-08-28 10:34:25 -07007257 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7258 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007259 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007260 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007262 if (localLOGV) {
7263 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7264 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007265 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007266 + mRequestedWidth + ", mRequestedheight="
7267 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7268 + "): frame=" + mFrame.toShortString()
7269 + " ci=" + contentInsets.toShortString()
7270 + " vi=" + visibleInsets.toShortString());
7271 //}
7272 }
7273 }
Romain Guy06882f82009-06-10 13:36:04 -07007274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007275 public Rect getFrameLw() {
7276 return mFrame;
7277 }
7278
7279 public Rect getShownFrameLw() {
7280 return mShownFrame;
7281 }
7282
7283 public Rect getDisplayFrameLw() {
7284 return mDisplayFrame;
7285 }
7286
7287 public Rect getContentFrameLw() {
7288 return mContentFrame;
7289 }
7290
7291 public Rect getVisibleFrameLw() {
7292 return mVisibleFrame;
7293 }
7294
7295 public boolean getGivenInsetsPendingLw() {
7296 return mGivenInsetsPending;
7297 }
7298
7299 public Rect getGivenContentInsetsLw() {
7300 return mGivenContentInsets;
7301 }
Romain Guy06882f82009-06-10 13:36:04 -07007302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007303 public Rect getGivenVisibleInsetsLw() {
7304 return mGivenVisibleInsets;
7305 }
Romain Guy06882f82009-06-10 13:36:04 -07007306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007307 public WindowManager.LayoutParams getAttrs() {
7308 return mAttrs;
7309 }
7310
7311 public int getSurfaceLayer() {
7312 return mLayer;
7313 }
Romain Guy06882f82009-06-10 13:36:04 -07007314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007315 public IApplicationToken getAppToken() {
7316 return mAppToken != null ? mAppToken.appToken : null;
7317 }
7318
7319 public boolean hasAppShownWindows() {
7320 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7321 }
7322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007323 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007324 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007325 TAG, "Setting animation in " + this + ": " + anim);
7326 mAnimating = false;
7327 mLocalAnimating = false;
7328 mAnimation = anim;
7329 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7330 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7331 }
7332
7333 public void clearAnimation() {
7334 if (mAnimation != null) {
7335 mAnimating = true;
7336 mLocalAnimating = false;
7337 mAnimation = null;
7338 }
7339 }
Romain Guy06882f82009-06-10 13:36:04 -07007340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007341 Surface createSurfaceLocked() {
7342 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007343 mReportDestroySurface = false;
7344 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007345 mDrawPending = true;
7346 mCommitDrawPending = false;
7347 mReadyToShow = false;
7348 if (mAppToken != null) {
7349 mAppToken.allDrawn = false;
7350 }
7351
7352 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07007353 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007354 flags |= Surface.PUSH_BUFFERS;
7355 }
7356
7357 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7358 flags |= Surface.SECURE;
7359 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007360 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007361 TAG, "Creating surface in session "
7362 + mSession.mSurfaceSession + " window " + this
7363 + " w=" + mFrame.width()
7364 + " h=" + mFrame.height() + " format="
7365 + mAttrs.format + " flags=" + flags);
7366
7367 int w = mFrame.width();
7368 int h = mFrame.height();
7369 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7370 // for a scaled surface, we always want the requested
7371 // size.
7372 w = mRequestedWidth;
7373 h = mRequestedHeight;
7374 }
7375
Romain Guy9825ec62009-10-01 00:58:09 -07007376 // Something is wrong and SurfaceFlinger will not like this,
7377 // try to revert to sane values
7378 if (w <= 0) w = 1;
7379 if (h <= 0) h = 1;
7380
Dianne Hackborn16064f92010-03-25 00:47:24 -07007381 mSurfaceShown = false;
7382 mSurfaceLayer = 0;
7383 mSurfaceAlpha = 1;
7384 mSurfaceX = 0;
7385 mSurfaceY = 0;
7386 mSurfaceW = w;
7387 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007388 try {
7389 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007390 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007391 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007392 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007393 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007394 + mSurface + " IN SESSION "
7395 + mSession.mSurfaceSession
7396 + ": pid=" + mSession.mPid + " format="
7397 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007398 + Integer.toHexString(flags)
7399 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007400 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007401 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007402 reclaimSomeSurfaceMemoryLocked(this, "create");
7403 return null;
7404 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007405 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007406 return null;
7407 }
Romain Guy06882f82009-06-10 13:36:04 -07007408
Joe Onorato8a9b2202010-02-26 18:56:32 -08007409 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007410 TAG, "Got surface: " + mSurface
7411 + ", set left=" + mFrame.left + " top=" + mFrame.top
7412 + ", animLayer=" + mAnimLayer);
7413 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007414 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007415 if (SHOW_TRANSACTIONS) logSurface(this,
7416 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
7417 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7418 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007419 }
7420 Surface.openTransaction();
7421 try {
7422 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007423 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007424 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007425 mSurface.setPosition(mSurfaceX, mSurfaceY);
7426 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007427 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007428 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007429 mSurface.hide();
7430 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007431 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007432 mSurface.setFlags(Surface.SURFACE_DITHER,
7433 Surface.SURFACE_DITHER);
7434 }
7435 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007436 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007437 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7438 }
7439 mLastHidden = true;
7440 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007441 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007442 Surface.closeTransaction();
7443 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007444 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007445 TAG, "Created surface " + this);
7446 }
7447 return mSurface;
7448 }
Romain Guy06882f82009-06-10 13:36:04 -07007449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007450 void destroySurfaceLocked() {
7451 // Window is no longer on-screen, so can no longer receive
7452 // key events... if we were waiting for it to finish
7453 // handling a key event, the wait is over!
7454 mKeyWaiter.finishedKey(mSession, mClient, true,
7455 KeyWaiter.RETURN_NOTHING);
7456 mKeyWaiter.releasePendingPointerLocked(mSession);
7457 mKeyWaiter.releasePendingTrackballLocked(mSession);
7458
7459 if (mAppToken != null && this == mAppToken.startingWindow) {
7460 mAppToken.startingDisplayed = false;
7461 }
Romain Guy06882f82009-06-10 13:36:04 -07007462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007463 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007464 mDrawPending = false;
7465 mCommitDrawPending = false;
7466 mReadyToShow = false;
7467
7468 int i = mChildWindows.size();
7469 while (i > 0) {
7470 i--;
7471 WindowState c = (WindowState)mChildWindows.get(i);
7472 c.mAttachedHidden = true;
7473 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007474
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007475 if (mReportDestroySurface) {
7476 mReportDestroySurface = false;
7477 mSurfacePendingDestroy = true;
7478 try {
7479 mClient.dispatchGetNewSurface();
7480 // We'll really destroy on the next time around.
7481 return;
7482 } catch (RemoteException e) {
7483 }
7484 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007486 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007487 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007488 RuntimeException e = null;
7489 if (!HIDE_STACK_CRAWLS) {
7490 e = new RuntimeException();
7491 e.fillInStackTrace();
7492 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007493 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007494 + mSurface + ", session " + mSession, e);
7495 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007496 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007497 RuntimeException e = null;
7498 if (!HIDE_STACK_CRAWLS) {
7499 e = new RuntimeException();
7500 e.fillInStackTrace();
7501 }
7502 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007503 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007504 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007505 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007506 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007507 + " surface " + mSurface + " session " + mSession
7508 + ": " + e.toString());
7509 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007510
Dianne Hackborn16064f92010-03-25 00:47:24 -07007511 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007512 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007513 }
7514 }
7515
7516 boolean finishDrawingLocked() {
7517 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007518 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007519 TAG, "finishDrawingLocked: " + mSurface);
7520 mCommitDrawPending = true;
7521 mDrawPending = false;
7522 return true;
7523 }
7524 return false;
7525 }
7526
7527 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007528 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007529 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007530 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007531 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007532 }
7533 mCommitDrawPending = false;
7534 mReadyToShow = true;
7535 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7536 final AppWindowToken atoken = mAppToken;
7537 if (atoken == null || atoken.allDrawn || starting) {
7538 performShowLocked();
7539 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007540 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007541 }
7542
7543 // This must be called while inside a transaction.
7544 boolean performShowLocked() {
7545 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007546 RuntimeException e = null;
7547 if (!HIDE_STACK_CRAWLS) {
7548 e = new RuntimeException();
7549 e.fillInStackTrace();
7550 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007551 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007552 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7553 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7554 }
7555 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007556 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7557 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007558 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007559 + " during animation: policyVis=" + mPolicyVisibility
7560 + " attHidden=" + mAttachedHidden
7561 + " tok.hiddenRequested="
7562 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007563 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007564 + (mAppToken != null ? mAppToken.hidden : false)
7565 + " animating=" + mAnimating
7566 + " tok animating="
7567 + (mAppToken != null ? mAppToken.animating : false));
7568 if (!showSurfaceRobustlyLocked(this)) {
7569 return false;
7570 }
7571 mLastAlpha = -1;
7572 mHasDrawn = true;
7573 mLastHidden = false;
7574 mReadyToShow = false;
7575 enableScreenIfNeededLocked();
7576
7577 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007579 int i = mChildWindows.size();
7580 while (i > 0) {
7581 i--;
7582 WindowState c = (WindowState)mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007583 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007584 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007585 if (c.mSurface != null) {
7586 c.performShowLocked();
7587 // It hadn't been shown, which means layout not
7588 // performed on it, so now we want to make sure to
7589 // do a layout. If called from within the transaction
7590 // loop, this will cause it to restart with a new
7591 // layout.
7592 mLayoutNeeded = true;
7593 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007594 }
7595 }
Romain Guy06882f82009-06-10 13:36:04 -07007596
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007597 if (mAttrs.type != TYPE_APPLICATION_STARTING
7598 && mAppToken != null) {
7599 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007600
Dianne Hackborn248b1882009-09-16 16:46:44 -07007601 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007602 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007603 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007604 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007605 // If this initial window is animating, stop it -- we
7606 // will do an animation to reveal it from behind the
7607 // starting window, so there is no need for it to also
7608 // be doing its own stuff.
7609 if (mAnimation != null) {
7610 mAnimation = null;
7611 // Make sure we clean up the animation.
7612 mAnimating = true;
7613 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007614 mFinishedStarting.add(mAppToken);
7615 mH.sendEmptyMessage(H.FINISHED_STARTING);
7616 }
7617 mAppToken.updateReportedVisibilityLocked();
7618 }
7619 }
7620 return true;
7621 }
Romain Guy06882f82009-06-10 13:36:04 -07007622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007623 // This must be called while inside a transaction. Returns true if
7624 // there is more animation to run.
7625 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007626 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007627 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007629 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7630 mHasTransformation = true;
7631 mHasLocalTransformation = true;
7632 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007633 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007634 TAG, "Starting animation in " + this +
7635 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7636 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7637 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7638 mAnimation.setStartTime(currentTime);
7639 mLocalAnimating = true;
7640 mAnimating = true;
7641 }
7642 mTransformation.clear();
7643 final boolean more = mAnimation.getTransformation(
7644 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007645 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007646 TAG, "Stepped animation in " + this +
7647 ": more=" + more + ", xform=" + mTransformation);
7648 if (more) {
7649 // we're not done!
7650 return true;
7651 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007652 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007653 TAG, "Finished animation in " + this +
7654 " @ " + currentTime);
7655 mAnimation = null;
7656 //WindowManagerService.this.dump();
7657 }
7658 mHasLocalTransformation = false;
7659 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007660 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007661 // When our app token is animating, we kind-of pretend like
7662 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7663 // part of this check means that we will only do this if
7664 // our window is not currently exiting, or it is not
7665 // locally animating itself. The idea being that one that
7666 // is exiting and doing a local animation should be removed
7667 // once that animation is done.
7668 mAnimating = true;
7669 mHasTransformation = true;
7670 mTransformation.clear();
7671 return false;
7672 } else if (mHasTransformation) {
7673 // Little trick to get through the path below to act like
7674 // we have finished an animation.
7675 mAnimating = true;
7676 } else if (isAnimating()) {
7677 mAnimating = true;
7678 }
7679 } else if (mAnimation != null) {
7680 // If the display is frozen, and there is a pending animation,
7681 // clear it and make sure we run the cleanup code.
7682 mAnimating = true;
7683 mLocalAnimating = true;
7684 mAnimation = null;
7685 }
Romain Guy06882f82009-06-10 13:36:04 -07007686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007687 if (!mAnimating && !mLocalAnimating) {
7688 return false;
7689 }
7690
Joe Onorato8a9b2202010-02-26 18:56:32 -08007691 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007692 TAG, "Animation done in " + this + ": exiting=" + mExiting
7693 + ", reportedVisible="
7694 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007695
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007696 mAnimating = false;
7697 mLocalAnimating = false;
7698 mAnimation = null;
7699 mAnimLayer = mLayer;
7700 if (mIsImWindow) {
7701 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007702 } else if (mIsWallpaper) {
7703 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007704 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007705 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007706 + " anim layer: " + mAnimLayer);
7707 mHasTransformation = false;
7708 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007709 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7710 if (DEBUG_VISIBILITY) {
7711 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7712 + mPolicyVisibilityAfterAnim);
7713 }
7714 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7715 if (!mPolicyVisibility) {
7716 if (mCurrentFocus == this) {
7717 mFocusMayChange = true;
7718 }
7719 // Window is no longer visible -- make sure if we were waiting
7720 // for it to be displayed before enabling the display, that
7721 // we allow the display to be enabled now.
7722 enableScreenIfNeededLocked();
7723 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007724 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007725 mTransformation.clear();
7726 if (mHasDrawn
7727 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7728 && mAppToken != null
7729 && mAppToken.firstWindowDrawn
7730 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007731 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007732 + mToken + ": first real window done animating");
7733 mFinishedStarting.add(mAppToken);
7734 mH.sendEmptyMessage(H.FINISHED_STARTING);
7735 }
Romain Guy06882f82009-06-10 13:36:04 -07007736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007737 finishExit();
7738
7739 if (mAppToken != null) {
7740 mAppToken.updateReportedVisibilityLocked();
7741 }
7742
7743 return false;
7744 }
7745
7746 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007747 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007748 TAG, "finishExit in " + this
7749 + ": exiting=" + mExiting
7750 + " remove=" + mRemoveOnExit
7751 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007753 final int N = mChildWindows.size();
7754 for (int i=0; i<N; i++) {
7755 ((WindowState)mChildWindows.get(i)).finishExit();
7756 }
Romain Guy06882f82009-06-10 13:36:04 -07007757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007758 if (!mExiting) {
7759 return;
7760 }
Romain Guy06882f82009-06-10 13:36:04 -07007761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007762 if (isWindowAnimating()) {
7763 return;
7764 }
7765
Joe Onorato8a9b2202010-02-26 18:56:32 -08007766 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007767 TAG, "Exit animation finished in " + this
7768 + ": remove=" + mRemoveOnExit);
7769 if (mSurface != null) {
7770 mDestroySurface.add(this);
7771 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007772 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007773 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007774 try {
7775 mSurface.hide();
7776 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007777 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007778 }
7779 mLastHidden = true;
7780 mKeyWaiter.releasePendingPointerLocked(mSession);
7781 }
7782 mExiting = false;
7783 if (mRemoveOnExit) {
7784 mPendingRemove.add(this);
7785 mRemoveOnExit = false;
7786 }
7787 }
Romain Guy06882f82009-06-10 13:36:04 -07007788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007789 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7790 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7791 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7792 if (dtdx < -.000001f || dtdx > .000001f) return false;
7793 if (dsdy < -.000001f || dsdy > .000001f) return false;
7794 return true;
7795 }
Romain Guy06882f82009-06-10 13:36:04 -07007796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007797 void computeShownFrameLocked() {
7798 final boolean selfTransformation = mHasLocalTransformation;
7799 Transformation attachedTransformation =
7800 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7801 ? mAttachedWindow.mTransformation : null;
7802 Transformation appTransformation =
7803 (mAppToken != null && mAppToken.hasTransformation)
7804 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007805
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007806 // Wallpapers are animated based on the "real" window they
7807 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007808 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007809 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007810 if (mWallpaperTarget.mHasLocalTransformation &&
7811 mWallpaperTarget.mAnimation != null &&
7812 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007813 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007814 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007815 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007816 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007817 }
7818 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007819 mWallpaperTarget.mAppToken.hasTransformation &&
7820 mWallpaperTarget.mAppToken.animation != null &&
7821 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007822 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007823 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007824 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007825 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007826 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007827 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007829 if (selfTransformation || attachedTransformation != null
7830 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007831 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007832 final Rect frame = mFrame;
7833 final float tmpFloats[] = mTmpFloats;
7834 final Matrix tmpMatrix = mTmpMatrix;
7835
7836 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007837 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007838 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007839 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007840 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007841 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007842 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007843 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007844 }
7845 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007846 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007847 }
7848
7849 // "convert" it into SurfaceFlinger's format
7850 // (a 2x2 matrix + an offset)
7851 // Here we must not transform the position of the surface
7852 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007853 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007855 tmpMatrix.getValues(tmpFloats);
7856 mDsDx = tmpFloats[Matrix.MSCALE_X];
7857 mDtDx = tmpFloats[Matrix.MSKEW_X];
7858 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7859 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007860 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7861 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007862 int w = frame.width();
7863 int h = frame.height();
7864 mShownFrame.set(x, y, x+w, y+h);
7865
7866 // Now set the alpha... but because our current hardware
7867 // can't do alpha transformation on a non-opaque surface,
7868 // turn it off if we are running an animation that is also
7869 // transforming since it is more important to have that
7870 // animation be smooth.
7871 mShownAlpha = mAlpha;
7872 if (!mLimitedAlphaCompositing
7873 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7874 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7875 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007876 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007877 if (selfTransformation) {
7878 mShownAlpha *= mTransformation.getAlpha();
7879 }
7880 if (attachedTransformation != null) {
7881 mShownAlpha *= attachedTransformation.getAlpha();
7882 }
7883 if (appTransformation != null) {
7884 mShownAlpha *= appTransformation.getAlpha();
7885 }
7886 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007887 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007888 }
Romain Guy06882f82009-06-10 13:36:04 -07007889
Joe Onorato8a9b2202010-02-26 18:56:32 -08007890 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007891 TAG, "Continuing animation in " + this +
7892 ": " + mShownFrame +
7893 ", alpha=" + mTransformation.getAlpha());
7894 return;
7895 }
Romain Guy06882f82009-06-10 13:36:04 -07007896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007897 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007898 if (mXOffset != 0 || mYOffset != 0) {
7899 mShownFrame.offset(mXOffset, mYOffset);
7900 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007901 mShownAlpha = mAlpha;
7902 mDsDx = 1;
7903 mDtDx = 0;
7904 mDsDy = 0;
7905 mDtDy = 1;
7906 }
Romain Guy06882f82009-06-10 13:36:04 -07007907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007908 /**
7909 * Is this window visible? It is not visible if there is no
7910 * surface, or we are in the process of running an exit animation
7911 * that will remove the surface, or its app token has been hidden.
7912 */
7913 public boolean isVisibleLw() {
7914 final AppWindowToken atoken = mAppToken;
7915 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7916 && (atoken == null || !atoken.hiddenRequested)
7917 && !mExiting && !mDestroying;
7918 }
7919
7920 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007921 * Like {@link #isVisibleLw}, but also counts a window that is currently
7922 * "hidden" behind the keyguard as visible. This allows us to apply
7923 * things like window flags that impact the keyguard.
7924 * XXX I am starting to think we need to have ANOTHER visibility flag
7925 * for this "hidden behind keyguard" state rather than overloading
7926 * mPolicyVisibility. Ungh.
7927 */
7928 public boolean isVisibleOrBehindKeyguardLw() {
7929 final AppWindowToken atoken = mAppToken;
7930 return mSurface != null && !mAttachedHidden
7931 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackborn5943c202010-04-12 21:36:49 -07007932 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending))
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007933 && !mExiting && !mDestroying;
7934 }
7935
7936 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007937 * Is this window visible, ignoring its app token? It is not visible
7938 * if there is no surface, or we are in the process of running an exit animation
7939 * that will remove the surface.
7940 */
7941 public boolean isWinVisibleLw() {
7942 final AppWindowToken atoken = mAppToken;
7943 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7944 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7945 && !mExiting && !mDestroying;
7946 }
7947
7948 /**
7949 * The same as isVisible(), but follows the current hidden state of
7950 * the associated app token, not the pending requested hidden state.
7951 */
7952 boolean isVisibleNow() {
7953 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007954 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007955 }
7956
7957 /**
7958 * Same as isVisible(), but we also count it as visible between the
7959 * call to IWindowSession.add() and the first relayout().
7960 */
7961 boolean isVisibleOrAdding() {
7962 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007963 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007964 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7965 && mPolicyVisibility && !mAttachedHidden
7966 && (atoken == null || !atoken.hiddenRequested)
7967 && !mExiting && !mDestroying;
7968 }
7969
7970 /**
7971 * Is this window currently on-screen? It is on-screen either if it
7972 * is visible or it is currently running an animation before no longer
7973 * being visible.
7974 */
7975 boolean isOnScreen() {
7976 final AppWindowToken atoken = mAppToken;
7977 if (atoken != null) {
7978 return mSurface != null && mPolicyVisibility && !mDestroying
7979 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007980 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007981 } else {
7982 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007983 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007984 }
7985 }
Romain Guy06882f82009-06-10 13:36:04 -07007986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007987 /**
7988 * Like isOnScreen(), but we don't return true if the window is part
7989 * of a transition that has not yet been started.
7990 */
7991 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007992 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007993 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007994 return false;
7995 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007996 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007997 final boolean animating = atoken != null
7998 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007999 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008000 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
8001 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008002 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008003 }
8004
8005 /** Is the window or its container currently animating? */
8006 boolean isAnimating() {
8007 final WindowState attached = mAttachedWindow;
8008 final AppWindowToken atoken = mAppToken;
8009 return mAnimation != null
8010 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07008011 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008012 (atoken.animation != null
8013 || atoken.inPendingTransaction));
8014 }
8015
8016 /** Is this window currently animating? */
8017 boolean isWindowAnimating() {
8018 return mAnimation != null;
8019 }
8020
8021 /**
8022 * Like isOnScreen, but returns false if the surface hasn't yet
8023 * been drawn.
8024 */
8025 public boolean isDisplayedLw() {
8026 final AppWindowToken atoken = mAppToken;
8027 return mSurface != null && mPolicyVisibility && !mDestroying
8028 && !mDrawPending && !mCommitDrawPending
8029 && ((!mAttachedHidden &&
8030 (atoken == null || !atoken.hiddenRequested))
8031 || mAnimating);
8032 }
8033
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008034 /**
8035 * Returns true if the window has a surface that it has drawn a
Dianne Hackborn5943c202010-04-12 21:36:49 -07008036 * complete UI in to. Note that this returns true if the orientation
8037 * is changing even if the window hasn't redrawn because we don't want
8038 * to stop things from executing during that time.
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008039 */
8040 public boolean isDrawnLw() {
8041 final AppWindowToken atoken = mAppToken;
8042 return mSurface != null && !mDestroying
Dianne Hackborn5943c202010-04-12 21:36:49 -07008043 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending));
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008044 }
8045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008046 public boolean fillsScreenLw(int screenWidth, int screenHeight,
8047 boolean shownFrame, boolean onlyOpaque) {
8048 if (mSurface == null) {
8049 return false;
8050 }
8051 if (mAppToken != null && !mAppToken.appFullscreen) {
8052 return false;
8053 }
8054 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
8055 return false;
8056 }
8057 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008058
8059 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
8060 return frame.left <= mCompatibleScreenFrame.left &&
8061 frame.top <= mCompatibleScreenFrame.top &&
8062 frame.right >= mCompatibleScreenFrame.right &&
8063 frame.bottom >= mCompatibleScreenFrame.bottom;
8064 } else {
8065 return frame.left <= 0 && frame.top <= 0
8066 && frame.right >= screenWidth
8067 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008068 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008069 }
Romain Guy06882f82009-06-10 13:36:04 -07008070
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008071 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07008072 * Return true if the window is opaque and fully drawn. This indicates
8073 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008074 */
8075 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07008076 return (mAttrs.format == PixelFormat.OPAQUE
8077 || mAttrs.type == TYPE_WALLPAPER)
8078 && mSurface != null && mAnimation == null
8079 && (mAppToken == null || mAppToken.animation == null)
8080 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008081 }
8082
8083 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
8084 return
8085 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008086 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
8087 // only if it's visible
8088 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008089 // and only if the application fills the compatible screen
8090 mFrame.left <= mCompatibleScreenFrame.left &&
8091 mFrame.top <= mCompatibleScreenFrame.top &&
8092 mFrame.right >= mCompatibleScreenFrame.right &&
8093 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008094 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008095 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008096 }
8097
8098 boolean isFullscreen(int screenWidth, int screenHeight) {
8099 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008100 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008101 }
8102
8103 void removeLocked() {
8104 if (mAttachedWindow != null) {
8105 mAttachedWindow.mChildWindows.remove(this);
8106 }
8107 destroySurfaceLocked();
8108 mSession.windowRemovedLocked();
8109 try {
8110 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
8111 } catch (RuntimeException e) {
8112 // Ignore if it has already been removed (usually because
8113 // we are doing this as part of processing a death note.)
8114 }
8115 }
8116
8117 private class DeathRecipient implements IBinder.DeathRecipient {
8118 public void binderDied() {
8119 try {
8120 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008121 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008122 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008123 if (win != null) {
8124 removeWindowLocked(mSession, win);
8125 }
8126 }
8127 } catch (IllegalArgumentException ex) {
8128 // This will happen if the window has already been
8129 // removed.
8130 }
8131 }
8132 }
8133
8134 /** Returns true if this window desires key events. */
8135 public final boolean canReceiveKeys() {
8136 return isVisibleOrAdding()
8137 && (mViewVisibility == View.VISIBLE)
8138 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8139 }
8140
8141 public boolean hasDrawnLw() {
8142 return mHasDrawn;
8143 }
8144
8145 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008146 return showLw(doAnimation, true);
8147 }
8148
8149 boolean showLw(boolean doAnimation, boolean requestAnim) {
8150 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8151 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008152 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008153 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008154 if (doAnimation) {
8155 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8156 + mPolicyVisibility + " mAnimation=" + mAnimation);
8157 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8158 doAnimation = false;
8159 } else if (mPolicyVisibility && mAnimation == null) {
8160 // Check for the case where we are currently visible and
8161 // not animating; we do not want to do animation at such a
8162 // point to become visible when we already are.
8163 doAnimation = false;
8164 }
8165 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008166 mPolicyVisibility = true;
8167 mPolicyVisibilityAfterAnim = true;
8168 if (doAnimation) {
8169 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8170 }
8171 if (requestAnim) {
8172 requestAnimationLocked(0);
8173 }
8174 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008175 }
8176
8177 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008178 return hideLw(doAnimation, true);
8179 }
8180
8181 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008182 if (doAnimation) {
8183 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8184 doAnimation = false;
8185 }
8186 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008187 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8188 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008189 if (!current) {
8190 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008191 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008192 if (doAnimation) {
8193 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8194 if (mAnimation == null) {
8195 doAnimation = false;
8196 }
8197 }
8198 if (doAnimation) {
8199 mPolicyVisibilityAfterAnim = false;
8200 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008201 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008202 mPolicyVisibilityAfterAnim = false;
8203 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008204 // Window is no longer visible -- make sure if we were waiting
8205 // for it to be displayed before enabling the display, that
8206 // we allow the display to be enabled now.
8207 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008208 if (mCurrentFocus == this) {
8209 mFocusMayChange = true;
8210 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008211 }
8212 if (requestAnim) {
8213 requestAnimationLocked(0);
8214 }
8215 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008216 }
8217
8218 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008219 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8220 pw.print(" mClient="); pw.println(mClient.asBinder());
8221 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8222 if (mAttachedWindow != null || mLayoutAttached) {
8223 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8224 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8225 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008226 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8227 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8228 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008229 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8230 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008231 }
8232 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8233 pw.print(" mSubLayer="); pw.print(mSubLayer);
8234 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8235 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8236 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8237 pw.print("="); pw.print(mAnimLayer);
8238 pw.print(" mLastLayer="); pw.println(mLastLayer);
8239 if (mSurface != null) {
8240 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008241 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8242 pw.print(" layer="); pw.print(mSurfaceLayer);
8243 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8244 pw.print(" rect=("); pw.print(mSurfaceX);
8245 pw.print(","); pw.print(mSurfaceY);
8246 pw.print(") "); pw.print(mSurfaceW);
8247 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008248 }
8249 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8250 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8251 if (mAppToken != null) {
8252 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8253 }
8254 if (mTargetAppToken != null) {
8255 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8256 }
8257 pw.print(prefix); pw.print("mViewVisibility=0x");
8258 pw.print(Integer.toHexString(mViewVisibility));
8259 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008260 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8261 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008262 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8263 pw.print(prefix); pw.print("mPolicyVisibility=");
8264 pw.print(mPolicyVisibility);
8265 pw.print(" mPolicyVisibilityAfterAnim=");
8266 pw.print(mPolicyVisibilityAfterAnim);
8267 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8268 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008269 if (!mRelayoutCalled) {
8270 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8271 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008272 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008273 pw.print(" h="); pw.print(mRequestedHeight);
8274 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008275 if (mXOffset != 0 || mYOffset != 0) {
8276 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8277 pw.print(" y="); pw.println(mYOffset);
8278 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008279 pw.print(prefix); pw.print("mGivenContentInsets=");
8280 mGivenContentInsets.printShortString(pw);
8281 pw.print(" mGivenVisibleInsets=");
8282 mGivenVisibleInsets.printShortString(pw);
8283 pw.println();
8284 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8285 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8286 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8287 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008288 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008289 pw.print(prefix); pw.print("mShownFrame=");
8290 mShownFrame.printShortString(pw);
8291 pw.print(" last="); mLastShownFrame.printShortString(pw);
8292 pw.println();
8293 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8294 pw.print(" last="); mLastFrame.printShortString(pw);
8295 pw.println();
8296 pw.print(prefix); pw.print("mContainingFrame=");
8297 mContainingFrame.printShortString(pw);
8298 pw.print(" mDisplayFrame=");
8299 mDisplayFrame.printShortString(pw);
8300 pw.println();
8301 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8302 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8303 pw.println();
8304 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8305 pw.print(" last="); mLastContentInsets.printShortString(pw);
8306 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8307 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8308 pw.println();
8309 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8310 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8311 pw.print(" mAlpha="); pw.print(mAlpha);
8312 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8313 }
8314 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8315 || mAnimation != null) {
8316 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8317 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8318 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8319 pw.print(" mAnimation="); pw.println(mAnimation);
8320 }
8321 if (mHasTransformation || mHasLocalTransformation) {
8322 pw.print(prefix); pw.print("XForm: has=");
8323 pw.print(mHasTransformation);
8324 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8325 pw.print(" "); mTransformation.printShortString(pw);
8326 pw.println();
8327 }
8328 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8329 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8330 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8331 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8332 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8333 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8334 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8335 pw.print(" mDestroying="); pw.print(mDestroying);
8336 pw.print(" mRemoved="); pw.println(mRemoved);
8337 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008338 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008339 pw.print(prefix); pw.print("mOrientationChanging=");
8340 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008341 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8342 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008343 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008344 if (mHScale != 1 || mVScale != 1) {
8345 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8346 pw.print(" mVScale="); pw.println(mVScale);
8347 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008348 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008349 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8350 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8351 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008352 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8353 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8354 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8355 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008356 }
8357
8358 @Override
8359 public String toString() {
8360 return "Window{"
8361 + Integer.toHexString(System.identityHashCode(this))
8362 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
8363 }
8364 }
Romain Guy06882f82009-06-10 13:36:04 -07008365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008366 // -------------------------------------------------------------
8367 // Window Token State
8368 // -------------------------------------------------------------
8369
8370 class WindowToken {
8371 // The actual token.
8372 final IBinder token;
8373
8374 // The type of window this token is for, as per WindowManager.LayoutParams.
8375 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008377 // Set if this token was explicitly added by a client, so should
8378 // not be removed when all windows are removed.
8379 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008380
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008381 // For printing.
8382 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008384 // If this is an AppWindowToken, this is non-null.
8385 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008387 // All of the windows associated with this token.
8388 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8389
8390 // Is key dispatching paused for this token?
8391 boolean paused = false;
8392
8393 // Should this token's windows be hidden?
8394 boolean hidden;
8395
8396 // Temporary for finding which tokens no longer have visible windows.
8397 boolean hasVisible;
8398
Dianne Hackborna8f60182009-09-01 19:01:50 -07008399 // Set to true when this token is in a pending transaction where it
8400 // will be shown.
8401 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008402
Dianne Hackborna8f60182009-09-01 19:01:50 -07008403 // Set to true when this token is in a pending transaction where it
8404 // will be hidden.
8405 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008406
Dianne Hackborna8f60182009-09-01 19:01:50 -07008407 // Set to true when this token is in a pending transaction where its
8408 // windows will be put to the bottom of the list.
8409 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008410
Dianne Hackborna8f60182009-09-01 19:01:50 -07008411 // Set to true when this token is in a pending transaction where its
8412 // windows will be put to the top of the list.
8413 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008415 WindowToken(IBinder _token, int type, boolean _explicit) {
8416 token = _token;
8417 windowType = type;
8418 explicit = _explicit;
8419 }
8420
8421 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008422 pw.print(prefix); pw.print("token="); pw.println(token);
8423 pw.print(prefix); pw.print("windows="); pw.println(windows);
8424 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8425 pw.print(" hidden="); pw.print(hidden);
8426 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008427 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8428 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8429 pw.print(" waitingToHide="); pw.print(waitingToHide);
8430 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8431 pw.print(" sendingToTop="); pw.println(sendingToTop);
8432 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008433 }
8434
8435 @Override
8436 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008437 if (stringName == null) {
8438 StringBuilder sb = new StringBuilder();
8439 sb.append("WindowToken{");
8440 sb.append(Integer.toHexString(System.identityHashCode(this)));
8441 sb.append(" token="); sb.append(token); sb.append('}');
8442 stringName = sb.toString();
8443 }
8444 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008445 }
8446 };
8447
8448 class AppWindowToken extends WindowToken {
8449 // Non-null only for application tokens.
8450 final IApplicationToken appToken;
8451
8452 // All of the windows and child windows that are included in this
8453 // application token. Note this list is NOT sorted!
8454 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8455
8456 int groupId = -1;
8457 boolean appFullscreen;
8458 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Romain Guy06882f82009-06-10 13:36:04 -07008459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008460 // These are used for determining when all windows associated with
8461 // an activity have been drawn, so they can be made visible together
8462 // at the same time.
8463 int lastTransactionSequence = mTransactionSequence-1;
8464 int numInterestingWindows;
8465 int numDrawnWindows;
8466 boolean inPendingTransaction;
8467 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008469 // Is this token going to be hidden in a little while? If so, it
8470 // won't be taken into account for setting the screen orientation.
8471 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008473 // Is this window's surface needed? This is almost like hidden, except
8474 // it will sometimes be true a little earlier: when the token has
8475 // been shown, but is still waiting for its app transition to execute
8476 // before making its windows shown.
8477 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008479 // Have we told the window clients to hide themselves?
8480 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008482 // Last visibility state we reported to the app token.
8483 boolean reportedVisible;
8484
8485 // Set to true when the token has been removed from the window mgr.
8486 boolean removed;
8487
8488 // Have we been asked to have this token keep the screen frozen?
8489 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008491 boolean animating;
8492 Animation animation;
8493 boolean hasTransformation;
8494 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008496 // Offset to the window of all layers in the token, for use by
8497 // AppWindowToken animations.
8498 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008500 // Information about an application starting window if displayed.
8501 StartingData startingData;
8502 WindowState startingWindow;
8503 View startingView;
8504 boolean startingDisplayed;
8505 boolean startingMoved;
8506 boolean firstWindowDrawn;
8507
8508 AppWindowToken(IApplicationToken _token) {
8509 super(_token.asBinder(),
8510 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8511 appWindowToken = this;
8512 appToken = _token;
8513 }
Romain Guy06882f82009-06-10 13:36:04 -07008514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008515 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008516 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008517 TAG, "Setting animation in " + this + ": " + anim);
8518 animation = anim;
8519 animating = false;
8520 anim.restrictDuration(MAX_ANIMATION_DURATION);
8521 anim.scaleCurrentDuration(mTransitionAnimationScale);
8522 int zorder = anim.getZAdjustment();
8523 int adj = 0;
8524 if (zorder == Animation.ZORDER_TOP) {
8525 adj = TYPE_LAYER_OFFSET;
8526 } else if (zorder == Animation.ZORDER_BOTTOM) {
8527 adj = -TYPE_LAYER_OFFSET;
8528 }
Romain Guy06882f82009-06-10 13:36:04 -07008529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008530 if (animLayerAdjustment != adj) {
8531 animLayerAdjustment = adj;
8532 updateLayers();
8533 }
8534 }
Romain Guy06882f82009-06-10 13:36:04 -07008535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008536 public void setDummyAnimation() {
8537 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008538 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008539 TAG, "Setting dummy animation in " + this);
8540 animation = sDummyAnimation;
8541 }
8542 }
8543
8544 public void clearAnimation() {
8545 if (animation != null) {
8546 animation = null;
8547 animating = true;
8548 }
8549 }
Romain Guy06882f82009-06-10 13:36:04 -07008550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008551 void updateLayers() {
8552 final int N = allAppWindows.size();
8553 final int adj = animLayerAdjustment;
8554 for (int i=0; i<N; i++) {
8555 WindowState w = allAppWindows.get(i);
8556 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008557 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008558 + w.mAnimLayer);
8559 if (w == mInputMethodTarget) {
8560 setInputMethodAnimLayerAdjustment(adj);
8561 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008562 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008563 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008564 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008565 }
8566 }
Romain Guy06882f82009-06-10 13:36:04 -07008567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008568 void sendAppVisibilityToClients() {
8569 final int N = allAppWindows.size();
8570 for (int i=0; i<N; i++) {
8571 WindowState win = allAppWindows.get(i);
8572 if (win == startingWindow && clientHidden) {
8573 // Don't hide the starting window.
8574 continue;
8575 }
8576 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008577 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008578 "Setting visibility of " + win + ": " + (!clientHidden));
8579 win.mClient.dispatchAppVisibility(!clientHidden);
8580 } catch (RemoteException e) {
8581 }
8582 }
8583 }
Romain Guy06882f82009-06-10 13:36:04 -07008584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008585 void showAllWindowsLocked() {
8586 final int NW = allAppWindows.size();
8587 for (int i=0; i<NW; i++) {
8588 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008589 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008590 "performing show on: " + w);
8591 w.performShowLocked();
8592 }
8593 }
Romain Guy06882f82009-06-10 13:36:04 -07008594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008595 // This must be called while inside a transaction.
8596 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008597 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008598 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008600 if (animation == sDummyAnimation) {
8601 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008602 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008603 // when it is really time to animate, this will be set to
8604 // a real animation and the next call will execute normally.
8605 return false;
8606 }
Romain Guy06882f82009-06-10 13:36:04 -07008607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008608 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8609 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008610 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008611 TAG, "Starting animation in " + this +
8612 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8613 + " scale=" + mTransitionAnimationScale
8614 + " allDrawn=" + allDrawn + " animating=" + animating);
8615 animation.initialize(dw, dh, dw, dh);
8616 animation.setStartTime(currentTime);
8617 animating = true;
8618 }
8619 transformation.clear();
8620 final boolean more = animation.getTransformation(
8621 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008622 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008623 TAG, "Stepped animation in " + this +
8624 ": more=" + more + ", xform=" + transformation);
8625 if (more) {
8626 // we're done!
8627 hasTransformation = true;
8628 return true;
8629 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008630 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008631 TAG, "Finished animation in " + this +
8632 " @ " + currentTime);
8633 animation = null;
8634 }
8635 } else if (animation != null) {
8636 // If the display is frozen, and there is a pending animation,
8637 // clear it and make sure we run the cleanup code.
8638 animating = true;
8639 animation = null;
8640 }
8641
8642 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008643
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008644 if (!animating) {
8645 return false;
8646 }
8647
8648 clearAnimation();
8649 animating = false;
8650 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8651 moveInputMethodWindowsIfNeededLocked(true);
8652 }
Romain Guy06882f82009-06-10 13:36:04 -07008653
Joe Onorato8a9b2202010-02-26 18:56:32 -08008654 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008655 TAG, "Animation done in " + this
8656 + ": reportedVisible=" + reportedVisible);
8657
8658 transformation.clear();
8659 if (animLayerAdjustment != 0) {
8660 animLayerAdjustment = 0;
8661 updateLayers();
8662 }
Romain Guy06882f82009-06-10 13:36:04 -07008663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008664 final int N = windows.size();
8665 for (int i=0; i<N; i++) {
8666 ((WindowState)windows.get(i)).finishExit();
8667 }
8668 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008670 return false;
8671 }
8672
8673 void updateReportedVisibilityLocked() {
8674 if (appToken == null) {
8675 return;
8676 }
Romain Guy06882f82009-06-10 13:36:04 -07008677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008678 int numInteresting = 0;
8679 int numVisible = 0;
8680 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008681
Joe Onorato8a9b2202010-02-26 18:56:32 -08008682 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008683 final int N = allAppWindows.size();
8684 for (int i=0; i<N; i++) {
8685 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008686 if (win == startingWindow || win.mAppFreezing
8687 || win.mViewVisibility != View.VISIBLE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008688 continue;
8689 }
8690 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008691 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008692 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008693 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008694 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008695 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008696 + " pv=" + win.mPolicyVisibility
8697 + " dp=" + win.mDrawPending
8698 + " cdp=" + win.mCommitDrawPending
8699 + " ah=" + win.mAttachedHidden
8700 + " th="
8701 + (win.mAppToken != null
8702 ? win.mAppToken.hiddenRequested : false)
8703 + " a=" + win.mAnimating);
8704 }
8705 }
8706 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008707 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008708 if (!win.isAnimating()) {
8709 numVisible++;
8710 }
8711 nowGone = false;
8712 } else if (win.isAnimating()) {
8713 nowGone = false;
8714 }
8715 }
Romain Guy06882f82009-06-10 13:36:04 -07008716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008717 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008718 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008719 + numInteresting + " visible=" + numVisible);
8720 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008721 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008722 TAG, "Visibility changed in " + this
8723 + ": vis=" + nowVisible);
8724 reportedVisible = nowVisible;
8725 Message m = mH.obtainMessage(
8726 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8727 nowVisible ? 1 : 0,
8728 nowGone ? 1 : 0,
8729 this);
8730 mH.sendMessage(m);
8731 }
8732 }
Romain Guy06882f82009-06-10 13:36:04 -07008733
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008734 WindowState findMainWindow() {
8735 int j = windows.size();
8736 while (j > 0) {
8737 j--;
8738 WindowState win = windows.get(j);
8739 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8740 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8741 return win;
8742 }
8743 }
8744 return null;
8745 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008747 void dump(PrintWriter pw, String prefix) {
8748 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008749 if (appToken != null) {
8750 pw.print(prefix); pw.println("app=true");
8751 }
8752 if (allAppWindows.size() > 0) {
8753 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8754 }
8755 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008756 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008757 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8758 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8759 pw.print(" clientHidden="); pw.print(clientHidden);
8760 pw.print(" willBeHidden="); pw.print(willBeHidden);
8761 pw.print(" reportedVisible="); pw.println(reportedVisible);
8762 if (paused || freezingScreen) {
8763 pw.print(prefix); pw.print("paused="); pw.print(paused);
8764 pw.print(" freezingScreen="); pw.println(freezingScreen);
8765 }
8766 if (numInterestingWindows != 0 || numDrawnWindows != 0
8767 || inPendingTransaction || allDrawn) {
8768 pw.print(prefix); pw.print("numInterestingWindows=");
8769 pw.print(numInterestingWindows);
8770 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8771 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8772 pw.print(" allDrawn="); pw.println(allDrawn);
8773 }
8774 if (animating || animation != null) {
8775 pw.print(prefix); pw.print("animating="); pw.print(animating);
8776 pw.print(" animation="); pw.println(animation);
8777 }
8778 if (animLayerAdjustment != 0) {
8779 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8780 }
8781 if (hasTransformation) {
8782 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8783 pw.print(" transformation="); transformation.printShortString(pw);
8784 pw.println();
8785 }
8786 if (startingData != null || removed || firstWindowDrawn) {
8787 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8788 pw.print(" removed="); pw.print(removed);
8789 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8790 }
8791 if (startingWindow != null || startingView != null
8792 || startingDisplayed || startingMoved) {
8793 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8794 pw.print(" startingView="); pw.print(startingView);
8795 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8796 pw.print(" startingMoved"); pw.println(startingMoved);
8797 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008798 }
8799
8800 @Override
8801 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008802 if (stringName == null) {
8803 StringBuilder sb = new StringBuilder();
8804 sb.append("AppWindowToken{");
8805 sb.append(Integer.toHexString(System.identityHashCode(this)));
8806 sb.append(" token="); sb.append(token); sb.append('}');
8807 stringName = sb.toString();
8808 }
8809 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008810 }
8811 }
Romain Guy06882f82009-06-10 13:36:04 -07008812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008813 // -------------------------------------------------------------
8814 // DummyAnimation
8815 // -------------------------------------------------------------
8816
8817 // This is an animation that does nothing: it just immediately finishes
8818 // itself every time it is called. It is used as a stub animation in cases
8819 // where we want to synchronize multiple things that may be animating.
8820 static final class DummyAnimation extends Animation {
8821 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8822 return false;
8823 }
8824 }
8825 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008827 // -------------------------------------------------------------
8828 // Async Handler
8829 // -------------------------------------------------------------
8830
8831 static final class StartingData {
8832 final String pkg;
8833 final int theme;
8834 final CharSequence nonLocalizedLabel;
8835 final int labelRes;
8836 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008838 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8839 int _labelRes, int _icon) {
8840 pkg = _pkg;
8841 theme = _theme;
8842 nonLocalizedLabel = _nonLocalizedLabel;
8843 labelRes = _labelRes;
8844 icon = _icon;
8845 }
8846 }
8847
8848 private final class H extends Handler {
8849 public static final int REPORT_FOCUS_CHANGE = 2;
8850 public static final int REPORT_LOSING_FOCUS = 3;
8851 public static final int ANIMATE = 4;
8852 public static final int ADD_STARTING = 5;
8853 public static final int REMOVE_STARTING = 6;
8854 public static final int FINISHED_STARTING = 7;
8855 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008856 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8857 public static final int HOLD_SCREEN_CHANGED = 12;
8858 public static final int APP_TRANSITION_TIMEOUT = 13;
8859 public static final int PERSIST_ANIMATION_SCALE = 14;
8860 public static final int FORCE_GC = 15;
8861 public static final int ENABLE_SCREEN = 16;
8862 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008863 public static final int SEND_NEW_CONFIGURATION = 18;
Romain Guy06882f82009-06-10 13:36:04 -07008864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008865 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008867 public H() {
8868 }
Romain Guy06882f82009-06-10 13:36:04 -07008869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008870 @Override
8871 public void handleMessage(Message msg) {
8872 switch (msg.what) {
8873 case REPORT_FOCUS_CHANGE: {
8874 WindowState lastFocus;
8875 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008877 synchronized(mWindowMap) {
8878 lastFocus = mLastFocus;
8879 newFocus = mCurrentFocus;
8880 if (lastFocus == newFocus) {
8881 // Focus is not changing, so nothing to do.
8882 return;
8883 }
8884 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008885 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008886 // + " to " + newFocus);
8887 if (newFocus != null && lastFocus != null
8888 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008889 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008890 mLosingFocus.add(lastFocus);
8891 lastFocus = null;
8892 }
8893 }
8894
8895 if (lastFocus != newFocus) {
8896 //System.out.println("Changing focus from " + lastFocus
8897 // + " to " + newFocus);
8898 if (newFocus != null) {
8899 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008900 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008901 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8902 } catch (RemoteException e) {
8903 // Ignore if process has died.
8904 }
8905 }
8906
8907 if (lastFocus != null) {
8908 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008909 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008910 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8911 } catch (RemoteException e) {
8912 // Ignore if process has died.
8913 }
8914 }
8915 }
8916 } break;
8917
8918 case REPORT_LOSING_FOCUS: {
8919 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008921 synchronized(mWindowMap) {
8922 losers = mLosingFocus;
8923 mLosingFocus = new ArrayList<WindowState>();
8924 }
8925
8926 final int N = losers.size();
8927 for (int i=0; i<N; i++) {
8928 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008929 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008930 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8931 } catch (RemoteException e) {
8932 // Ignore if process has died.
8933 }
8934 }
8935 } break;
8936
8937 case ANIMATE: {
8938 synchronized(mWindowMap) {
8939 mAnimationPending = false;
8940 performLayoutAndPlaceSurfacesLocked();
8941 }
8942 } break;
8943
8944 case ADD_STARTING: {
8945 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8946 final StartingData sd = wtoken.startingData;
8947
8948 if (sd == null) {
8949 // Animation has been canceled... do nothing.
8950 return;
8951 }
Romain Guy06882f82009-06-10 13:36:04 -07008952
Joe Onorato8a9b2202010-02-26 18:56:32 -08008953 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008954 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008956 View view = null;
8957 try {
8958 view = mPolicy.addStartingWindow(
8959 wtoken.token, sd.pkg,
8960 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8961 sd.icon);
8962 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008963 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008964 }
8965
8966 if (view != null) {
8967 boolean abort = false;
8968
8969 synchronized(mWindowMap) {
8970 if (wtoken.removed || wtoken.startingData == null) {
8971 // If the window was successfully added, then
8972 // we need to remove it.
8973 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008974 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008975 "Aborted starting " + wtoken
8976 + ": removed=" + wtoken.removed
8977 + " startingData=" + wtoken.startingData);
8978 wtoken.startingWindow = null;
8979 wtoken.startingData = null;
8980 abort = true;
8981 }
8982 } else {
8983 wtoken.startingView = view;
8984 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008985 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008986 "Added starting " + wtoken
8987 + ": startingWindow="
8988 + wtoken.startingWindow + " startingView="
8989 + wtoken.startingView);
8990 }
8991
8992 if (abort) {
8993 try {
8994 mPolicy.removeStartingWindow(wtoken.token, view);
8995 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008996 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008997 }
8998 }
8999 }
9000 } break;
9001
9002 case REMOVE_STARTING: {
9003 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9004 IBinder token = null;
9005 View view = null;
9006 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009007 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009008 + wtoken + ": startingWindow="
9009 + wtoken.startingWindow + " startingView="
9010 + wtoken.startingView);
9011 if (wtoken.startingWindow != null) {
9012 view = wtoken.startingView;
9013 token = wtoken.token;
9014 wtoken.startingData = null;
9015 wtoken.startingView = null;
9016 wtoken.startingWindow = null;
9017 }
9018 }
9019 if (view != null) {
9020 try {
9021 mPolicy.removeStartingWindow(token, view);
9022 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009023 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009024 }
9025 }
9026 } break;
9027
9028 case FINISHED_STARTING: {
9029 IBinder token = null;
9030 View view = null;
9031 while (true) {
9032 synchronized (mWindowMap) {
9033 final int N = mFinishedStarting.size();
9034 if (N <= 0) {
9035 break;
9036 }
9037 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
9038
Joe Onorato8a9b2202010-02-26 18:56:32 -08009039 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009040 "Finished starting " + wtoken
9041 + ": startingWindow=" + wtoken.startingWindow
9042 + " startingView=" + wtoken.startingView);
9043
9044 if (wtoken.startingWindow == null) {
9045 continue;
9046 }
9047
9048 view = wtoken.startingView;
9049 token = wtoken.token;
9050 wtoken.startingData = null;
9051 wtoken.startingView = null;
9052 wtoken.startingWindow = null;
9053 }
9054
9055 try {
9056 mPolicy.removeStartingWindow(token, view);
9057 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009058 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009059 }
9060 }
9061 } break;
9062
9063 case REPORT_APPLICATION_TOKEN_WINDOWS: {
9064 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9065
9066 boolean nowVisible = msg.arg1 != 0;
9067 boolean nowGone = msg.arg2 != 0;
9068
9069 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009070 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009071 TAG, "Reporting visible in " + wtoken
9072 + " visible=" + nowVisible
9073 + " gone=" + nowGone);
9074 if (nowVisible) {
9075 wtoken.appToken.windowsVisible();
9076 } else {
9077 wtoken.appToken.windowsGone();
9078 }
9079 } catch (RemoteException ex) {
9080 }
9081 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009083 case WINDOW_FREEZE_TIMEOUT: {
9084 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009085 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009086 int i = mWindows.size();
9087 while (i > 0) {
9088 i--;
9089 WindowState w = (WindowState)mWindows.get(i);
9090 if (w.mOrientationChanging) {
9091 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009092 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009093 }
9094 }
9095 performLayoutAndPlaceSurfacesLocked();
9096 }
9097 break;
9098 }
Romain Guy06882f82009-06-10 13:36:04 -07009099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009100 case HOLD_SCREEN_CHANGED: {
9101 Session oldHold;
9102 Session newHold;
9103 synchronized (mWindowMap) {
9104 oldHold = mLastReportedHold;
9105 newHold = (Session)msg.obj;
9106 mLastReportedHold = newHold;
9107 }
Romain Guy06882f82009-06-10 13:36:04 -07009108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009109 if (oldHold != newHold) {
9110 try {
9111 if (oldHold != null) {
9112 mBatteryStats.noteStopWakelock(oldHold.mUid,
9113 "window",
9114 BatteryStats.WAKE_TYPE_WINDOW);
9115 }
9116 if (newHold != null) {
9117 mBatteryStats.noteStartWakelock(newHold.mUid,
9118 "window",
9119 BatteryStats.WAKE_TYPE_WINDOW);
9120 }
9121 } catch (RemoteException e) {
9122 }
9123 }
9124 break;
9125 }
Romain Guy06882f82009-06-10 13:36:04 -07009126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009127 case APP_TRANSITION_TIMEOUT: {
9128 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009129 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009130 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009131 "*** APP TRANSITION TIMEOUT");
9132 mAppTransitionReady = true;
9133 mAppTransitionTimeout = true;
9134 performLayoutAndPlaceSurfacesLocked();
9135 }
9136 }
9137 break;
9138 }
Romain Guy06882f82009-06-10 13:36:04 -07009139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009140 case PERSIST_ANIMATION_SCALE: {
9141 Settings.System.putFloat(mContext.getContentResolver(),
9142 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9143 Settings.System.putFloat(mContext.getContentResolver(),
9144 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9145 break;
9146 }
Romain Guy06882f82009-06-10 13:36:04 -07009147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009148 case FORCE_GC: {
9149 synchronized(mWindowMap) {
9150 if (mAnimationPending) {
9151 // If we are animating, don't do the gc now but
9152 // delay a bit so we don't interrupt the animation.
9153 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9154 2000);
9155 return;
9156 }
9157 // If we are currently rotating the display, it will
9158 // schedule a new message when done.
9159 if (mDisplayFrozen) {
9160 return;
9161 }
9162 mFreezeGcPending = 0;
9163 }
9164 Runtime.getRuntime().gc();
9165 break;
9166 }
Romain Guy06882f82009-06-10 13:36:04 -07009167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009168 case ENABLE_SCREEN: {
9169 performEnableScreen();
9170 break;
9171 }
Romain Guy06882f82009-06-10 13:36:04 -07009172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009173 case APP_FREEZE_TIMEOUT: {
9174 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009175 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009176 int i = mAppTokens.size();
9177 while (i > 0) {
9178 i--;
9179 AppWindowToken tok = mAppTokens.get(i);
9180 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009181 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009182 unsetAppFreezingScreenLocked(tok, true, true);
9183 }
9184 }
9185 }
9186 break;
9187 }
Romain Guy06882f82009-06-10 13:36:04 -07009188
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009189 case SEND_NEW_CONFIGURATION: {
9190 removeMessages(SEND_NEW_CONFIGURATION);
9191 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009192 break;
9193 }
Romain Guy06882f82009-06-10 13:36:04 -07009194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009195 }
9196 }
9197 }
9198
9199 // -------------------------------------------------------------
9200 // IWindowManager API
9201 // -------------------------------------------------------------
9202
9203 public IWindowSession openSession(IInputMethodClient client,
9204 IInputContext inputContext) {
9205 if (client == null) throw new IllegalArgumentException("null client");
9206 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
9207 return new Session(client, inputContext);
9208 }
9209
9210 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9211 synchronized (mWindowMap) {
9212 // The focus for the client is the window immediately below
9213 // where we would place the input method window.
9214 int idx = findDesiredInputMethodWindowIndexLocked(false);
9215 WindowState imFocus;
9216 if (idx > 0) {
9217 imFocus = (WindowState)mWindows.get(idx-1);
9218 if (imFocus != null) {
9219 if (imFocus.mSession.mClient != null &&
9220 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9221 return true;
9222 }
9223 }
9224 }
9225 }
9226 return false;
9227 }
Romain Guy06882f82009-06-10 13:36:04 -07009228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009229 // -------------------------------------------------------------
9230 // Internals
9231 // -------------------------------------------------------------
9232
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009233 final WindowState windowForClientLocked(Session session, IWindow client,
9234 boolean throwOnError) {
9235 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009236 }
Romain Guy06882f82009-06-10 13:36:04 -07009237
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009238 final WindowState windowForClientLocked(Session session, IBinder client,
9239 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009240 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009241 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009242 TAG, "Looking up client " + client + ": " + win);
9243 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009244 RuntimeException ex = new IllegalArgumentException(
9245 "Requested window " + client + " does not exist");
9246 if (throwOnError) {
9247 throw ex;
9248 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009249 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009250 return null;
9251 }
9252 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009253 RuntimeException ex = new IllegalArgumentException(
9254 "Requested window " + client + " is in session " +
9255 win.mSession + ", not " + session);
9256 if (throwOnError) {
9257 throw ex;
9258 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009259 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009260 return null;
9261 }
9262
9263 return win;
9264 }
9265
Dianne Hackborna8f60182009-09-01 19:01:50 -07009266 final void rebuildAppWindowListLocked() {
9267 int NW = mWindows.size();
9268 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009269 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009270 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009271
Dianne Hackborna8f60182009-09-01 19:01:50 -07009272 // First remove all existing app windows.
9273 i=0;
9274 while (i < NW) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009275 WindowState w = (WindowState)mWindows.get(i);
9276 if (w.mAppToken != null) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009277 WindowState win = (WindowState)mWindows.remove(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009278 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009279 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009280 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009281 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009282 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009283 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9284 && lastWallpaper == i-1) {
9285 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009286 }
9287 i++;
9288 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009289
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009290 // The wallpaper window(s) typically live at the bottom of the stack,
9291 // so skip them before adding app tokens.
9292 lastWallpaper++;
9293 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009294
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009295 // First add all of the exiting app tokens... these are no longer
9296 // in the main app list, but still have windows shown. We put them
9297 // in the back because now that the animation is over we no longer
9298 // will care about them.
9299 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009300 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009301 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9302 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009303
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009304 // And add in the still active app tokens in Z order.
9305 NT = mAppTokens.size();
9306 for (int j=0; j<NT; j++) {
9307 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009308 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009309
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009310 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009311 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009312 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009313 + " windows but added " + i);
9314 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009315 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009317 private final void assignLayersLocked() {
9318 int N = mWindows.size();
9319 int curBaseLayer = 0;
9320 int curLayer = 0;
9321 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009323 for (i=0; i<N; i++) {
9324 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009325 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9326 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009327 curLayer += WINDOW_LAYER_MULTIPLIER;
9328 w.mLayer = curLayer;
9329 } else {
9330 curBaseLayer = curLayer = w.mBaseLayer;
9331 w.mLayer = curLayer;
9332 }
9333 if (w.mTargetAppToken != null) {
9334 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9335 } else if (w.mAppToken != null) {
9336 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9337 } else {
9338 w.mAnimLayer = w.mLayer;
9339 }
9340 if (w.mIsImWindow) {
9341 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009342 } else if (w.mIsWallpaper) {
9343 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009344 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009345 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009346 + w.mAnimLayer);
9347 //System.out.println(
9348 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9349 }
9350 }
9351
9352 private boolean mInLayout = false;
9353 private final void performLayoutAndPlaceSurfacesLocked() {
9354 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009355 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009356 throw new RuntimeException("Recursive call!");
9357 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009358 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009359 return;
9360 }
9361
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009362 if (mWaitingForConfig) {
9363 // Our configuration has changed (most likely rotation), but we
9364 // don't yet have the complete configuration to report to
9365 // applications. Don't do any window layout until we have it.
9366 return;
9367 }
9368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009369 boolean recoveringMemory = false;
9370 if (mForceRemoves != null) {
9371 recoveringMemory = true;
9372 // Wait a little it for things to settle down, and off we go.
9373 for (int i=0; i<mForceRemoves.size(); i++) {
9374 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009375 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009376 removeWindowInnerLocked(ws.mSession, ws);
9377 }
9378 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009379 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009380 Object tmp = new Object();
9381 synchronized (tmp) {
9382 try {
9383 tmp.wait(250);
9384 } catch (InterruptedException e) {
9385 }
9386 }
9387 }
Romain Guy06882f82009-06-10 13:36:04 -07009388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009389 mInLayout = true;
9390 try {
9391 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009393 int i = mPendingRemove.size()-1;
9394 if (i >= 0) {
9395 while (i >= 0) {
9396 WindowState w = mPendingRemove.get(i);
9397 removeWindowInnerLocked(w.mSession, w);
9398 i--;
9399 }
9400 mPendingRemove.clear();
9401
9402 mInLayout = false;
9403 assignLayersLocked();
9404 mLayoutNeeded = true;
9405 performLayoutAndPlaceSurfacesLocked();
9406
9407 } else {
9408 mInLayout = false;
9409 if (mLayoutNeeded) {
9410 requestAnimationLocked(0);
9411 }
9412 }
9413 } catch (RuntimeException e) {
9414 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009415 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009416 }
9417 }
9418
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009419 private final int performLayoutLockedInner() {
9420 if (!mLayoutNeeded) {
9421 return 0;
9422 }
9423
9424 mLayoutNeeded = false;
9425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009426 final int dw = mDisplay.getWidth();
9427 final int dh = mDisplay.getHeight();
9428
9429 final int N = mWindows.size();
9430 int i;
9431
Joe Onorato8a9b2202010-02-26 18:56:32 -08009432 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009433 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9434
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009435 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009436
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009437 int seq = mLayoutSeq+1;
9438 if (seq < 0) seq = 0;
9439 mLayoutSeq = seq;
9440
9441 // First perform layout of any root windows (not attached
9442 // to another window).
9443 int topAttached = -1;
9444 for (i = N-1; i >= 0; i--) {
9445 WindowState win = (WindowState) mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009446
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009447 // Don't do layout of a window if it is not visible, or
9448 // soon won't be visible, to avoid wasting time and funky
9449 // changes while a window is animating away.
9450 final AppWindowToken atoken = win.mAppToken;
9451 final boolean gone = win.mViewVisibility == View.GONE
9452 || !win.mRelayoutCalled
9453 || win.mRootToken.hidden
9454 || (atoken != null && atoken.hiddenRequested)
9455 || win.mAttachedHidden
9456 || win.mExiting || win.mDestroying;
9457
9458 if (!win.mLayoutAttached) {
9459 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
9460 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9461 + " mLayoutAttached=" + win.mLayoutAttached);
9462 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
9463 + win.mViewVisibility + " mRelayoutCalled="
9464 + win.mRelayoutCalled + " hidden="
9465 + win.mRootToken.hidden + " hiddenRequested="
9466 + (atoken != null && atoken.hiddenRequested)
9467 + " mAttachedHidden=" + win.mAttachedHidden);
9468 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009469
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009470 // If this view is GONE, then skip it -- keep the current
9471 // frame, and let the caller know so they can ignore it
9472 // if they want. (We do the normal layout for INVISIBLE
9473 // windows, since that means "perform layout as normal,
9474 // just don't display").
9475 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009476 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009477 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9478 win.mLayoutSeq = seq;
9479 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9480 + win.mFrame + " mContainingFrame="
9481 + win.mContainingFrame + " mDisplayFrame="
9482 + win.mDisplayFrame);
9483 } else {
9484 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009485 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009486 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009487 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009488
9489 // Now perform layout of attached windows, which usually
9490 // depend on the position of the window they are attached to.
9491 // XXX does not deal with windows that are attached to windows
9492 // that are themselves attached.
9493 for (i = topAttached; i >= 0; i--) {
9494 WindowState win = (WindowState) mWindows.get(i);
9495
9496 // If this view is GONE, then skip it -- keep the current
9497 // frame, and let the caller know so they can ignore it
9498 // if they want. (We do the normal layout for INVISIBLE
9499 // windows, since that means "perform layout as normal,
9500 // just don't display").
9501 if (win.mLayoutAttached) {
9502 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9503 + " mHaveFrame=" + win.mHaveFrame
9504 + " mViewVisibility=" + win.mViewVisibility
9505 + " mRelayoutCalled=" + win.mRelayoutCalled);
9506 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9507 || !win.mHaveFrame) {
9508 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9509 win.mLayoutSeq = seq;
9510 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9511 + win.mFrame + " mContainingFrame="
9512 + win.mContainingFrame + " mDisplayFrame="
9513 + win.mDisplayFrame);
9514 }
9515 }
9516 }
9517
9518 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009519 }
Romain Guy06882f82009-06-10 13:36:04 -07009520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009521 private final void performLayoutAndPlaceSurfacesLockedInner(
9522 boolean recoveringMemory) {
9523 final long currentTime = SystemClock.uptimeMillis();
9524 final int dw = mDisplay.getWidth();
9525 final int dh = mDisplay.getHeight();
9526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009527 int i;
9528
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009529 if (mFocusMayChange) {
9530 mFocusMayChange = false;
9531 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9532 }
9533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009534 if (mFxSession == null) {
9535 mFxSession = new SurfaceSession();
9536 }
Romain Guy06882f82009-06-10 13:36:04 -07009537
Joe Onorato8a9b2202010-02-26 18:56:32 -08009538 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009539
9540 // Initialize state of exiting tokens.
9541 for (i=mExitingTokens.size()-1; i>=0; i--) {
9542 mExitingTokens.get(i).hasVisible = false;
9543 }
9544
9545 // Initialize state of exiting applications.
9546 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9547 mExitingAppTokens.get(i).hasVisible = false;
9548 }
9549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009550 boolean orientationChangeComplete = true;
9551 Session holdScreen = null;
9552 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009553 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009554 boolean focusDisplayed = false;
9555 boolean animating = false;
9556
9557 Surface.openTransaction();
9558 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009559 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009560 int repeats = 0;
9561 int changes = 0;
9562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009563 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009564 repeats++;
9565 if (repeats > 6) {
9566 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9567 mLayoutNeeded = false;
9568 break;
9569 }
9570
9571 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9572 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9573 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9574 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9575 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9576 assignLayersLocked();
9577 mLayoutNeeded = true;
9578 }
9579 }
9580 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9581 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9582 if (updateOrientationFromAppTokensLocked()) {
9583 mLayoutNeeded = true;
9584 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9585 }
9586 }
9587 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9588 mLayoutNeeded = true;
9589 }
9590 }
9591
9592 // FIRST LOOP: Perform a layout, if needed.
9593 if (repeats < 4) {
9594 changes = performLayoutLockedInner();
9595 if (changes != 0) {
9596 continue;
9597 }
9598 } else {
9599 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9600 changes = 0;
9601 }
9602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009603 final int transactionSequence = ++mTransactionSequence;
9604
9605 // Update animations of all applications, including those
9606 // associated with exiting/removed apps
9607 boolean tokensAnimating = false;
9608 final int NAT = mAppTokens.size();
9609 for (i=0; i<NAT; i++) {
9610 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9611 tokensAnimating = true;
9612 }
9613 }
9614 final int NEAT = mExitingAppTokens.size();
9615 for (i=0; i<NEAT; i++) {
9616 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9617 tokensAnimating = true;
9618 }
9619 }
9620
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009621 // SECOND LOOP: Execute animations and update visibility of windows.
9622
Joe Onorato8a9b2202010-02-26 18:56:32 -08009623 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009624 + transactionSequence + " tokensAnimating="
9625 + tokensAnimating);
9626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009627 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009628
9629 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009630 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009631 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009632
9633 mPolicy.beginAnimationLw(dw, dh);
9634
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009635 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009637 for (i=N-1; i>=0; i--) {
9638 WindowState w = (WindowState)mWindows.get(i);
9639
9640 final WindowManager.LayoutParams attrs = w.mAttrs;
9641
9642 if (w.mSurface != null) {
9643 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009644 if (w.commitFinishDrawingLocked(currentTime)) {
9645 if ((w.mAttrs.flags
9646 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009647 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009648 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009649 wallpaperMayChange = true;
9650 }
9651 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009652
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009653 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009654 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9655 animating = true;
9656 //w.dump(" ");
9657 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009658 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9659 wallpaperMayChange = true;
9660 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009661
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009662 if (mPolicy.doesForceHide(w, attrs)) {
9663 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009664 if (DEBUG_VISIBILITY) Slog.v(TAG,
9665 "Animation done that could impact force hide: "
9666 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009667 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009668 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009669 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9670 forceHiding = true;
9671 }
9672 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9673 boolean changed;
9674 if (forceHiding) {
9675 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009676 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9677 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009678 } else {
9679 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009680 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9681 "Now policy shown: " + w);
9682 if (changed) {
9683 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009684 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009685 // Assume we will need to animate. If
9686 // we don't (because the wallpaper will
9687 // stay with the lock screen), then we will
9688 // clean up later.
9689 Animation a = mPolicy.createForceHideEnterAnimation();
9690 if (a != null) {
9691 w.setAnimation(a);
9692 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009693 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009694 if (mCurrentFocus == null ||
9695 mCurrentFocus.mLayer < w.mLayer) {
9696 // We are showing on to of the current
9697 // focus, so re-evaluate focus to make
9698 // sure it is correct.
9699 mFocusMayChange = true;
9700 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009701 }
9702 }
9703 if (changed && (attrs.flags
9704 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9705 wallpaperMayChange = true;
9706 }
9707 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009709 mPolicy.animatingWindowLw(w, attrs);
9710 }
9711
9712 final AppWindowToken atoken = w.mAppToken;
9713 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9714 if (atoken.lastTransactionSequence != transactionSequence) {
9715 atoken.lastTransactionSequence = transactionSequence;
9716 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9717 atoken.startingDisplayed = false;
9718 }
9719 if ((w.isOnScreen() || w.mAttrs.type
9720 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9721 && !w.mExiting && !w.mDestroying) {
9722 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009723 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009724 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009725 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009726 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009727 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009728 + " pv=" + w.mPolicyVisibility
9729 + " dp=" + w.mDrawPending
9730 + " cdp=" + w.mCommitDrawPending
9731 + " ah=" + w.mAttachedHidden
9732 + " th=" + atoken.hiddenRequested
9733 + " a=" + w.mAnimating);
9734 }
9735 }
9736 if (w != atoken.startingWindow) {
9737 if (!atoken.freezingScreen || !w.mAppFreezing) {
9738 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009739 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009740 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009741 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009742 "tokenMayBeDrawn: " + atoken
9743 + " freezingScreen=" + atoken.freezingScreen
9744 + " mAppFreezing=" + w.mAppFreezing);
9745 tokenMayBeDrawn = true;
9746 }
9747 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009748 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009749 atoken.startingDisplayed = true;
9750 }
9751 }
9752 } else if (w.mReadyToShow) {
9753 w.performShowLocked();
9754 }
9755 }
9756
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009757 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009758
9759 if (tokenMayBeDrawn) {
9760 // See if any windows have been drawn, so they (and others
9761 // associated with them) can now be shown.
9762 final int NT = mTokenList.size();
9763 for (i=0; i<NT; i++) {
9764 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9765 if (wtoken == null) {
9766 continue;
9767 }
9768 if (wtoken.freezingScreen) {
9769 int numInteresting = wtoken.numInterestingWindows;
9770 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009771 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009772 "allDrawn: " + wtoken
9773 + " interesting=" + numInteresting
9774 + " drawn=" + wtoken.numDrawnWindows);
9775 wtoken.showAllWindowsLocked();
9776 unsetAppFreezingScreenLocked(wtoken, false, true);
9777 orientationChangeComplete = true;
9778 }
9779 } else if (!wtoken.allDrawn) {
9780 int numInteresting = wtoken.numInterestingWindows;
9781 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009782 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009783 "allDrawn: " + wtoken
9784 + " interesting=" + numInteresting
9785 + " drawn=" + wtoken.numDrawnWindows);
9786 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009787 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009788
9789 // We can now show all of the drawn windows!
9790 if (!mOpeningApps.contains(wtoken)) {
9791 wtoken.showAllWindowsLocked();
9792 }
9793 }
9794 }
9795 }
9796 }
9797
9798 // If we are ready to perform an app transition, check through
9799 // all of the app tokens to be shown and see if they are ready
9800 // to go.
9801 if (mAppTransitionReady) {
9802 int NN = mOpeningApps.size();
9803 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009804 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009805 "Checking " + NN + " opening apps (frozen="
9806 + mDisplayFrozen + " timeout="
9807 + mAppTransitionTimeout + ")...");
9808 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9809 // If the display isn't frozen, wait to do anything until
9810 // all of the apps are ready. Otherwise just go because
9811 // we'll unfreeze the display when everyone is ready.
9812 for (i=0; i<NN && goodToGo; i++) {
9813 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009814 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009815 "Check opening app" + wtoken + ": allDrawn="
9816 + wtoken.allDrawn + " startingDisplayed="
9817 + wtoken.startingDisplayed);
9818 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9819 && !wtoken.startingMoved) {
9820 goodToGo = false;
9821 }
9822 }
9823 }
9824 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009825 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009826 int transit = mNextAppTransition;
9827 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009828 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009829 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009830 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009831 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009832 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009833 mAppTransitionTimeout = false;
9834 mStartingIconInTransition = false;
9835 mSkipAppTransitionAnimation = false;
9836
9837 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9838
Dianne Hackborna8f60182009-09-01 19:01:50 -07009839 // If there are applications waiting to come to the
9840 // top of the stack, now is the time to move their windows.
9841 // (Note that we don't do apps going to the bottom
9842 // here -- we want to keep their windows in the old
9843 // Z-order until the animation completes.)
9844 if (mToTopApps.size() > 0) {
9845 NN = mAppTokens.size();
9846 for (i=0; i<NN; i++) {
9847 AppWindowToken wtoken = mAppTokens.get(i);
9848 if (wtoken.sendingToTop) {
9849 wtoken.sendingToTop = false;
9850 moveAppWindowsLocked(wtoken, NN, false);
9851 }
9852 }
9853 mToTopApps.clear();
9854 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009855
Dianne Hackborn25994b42009-09-04 14:21:19 -07009856 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009857
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009858 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009859 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009860
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009861 // The top-most window will supply the layout params,
9862 // and we will determine it below.
9863 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009864 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009865 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009866
Joe Onorato8a9b2202010-02-26 18:56:32 -08009867 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009868 "New wallpaper target=" + mWallpaperTarget
9869 + ", lower target=" + mLowerWallpaperTarget
9870 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009871 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009872 // Do a first pass through the tokens for two
9873 // things:
9874 // (1) Determine if both the closing and opening
9875 // app token sets are wallpaper targets, in which
9876 // case special animations are needed
9877 // (since the wallpaper needs to stay static
9878 // behind them).
9879 // (2) Find the layout params of the top-most
9880 // application window in the tokens, which is
9881 // what will control the animation theme.
9882 final int NC = mClosingApps.size();
9883 NN = NC + mOpeningApps.size();
9884 for (i=0; i<NN; i++) {
9885 AppWindowToken wtoken;
9886 int mode;
9887 if (i < NC) {
9888 wtoken = mClosingApps.get(i);
9889 mode = 1;
9890 } else {
9891 wtoken = mOpeningApps.get(i-NC);
9892 mode = 2;
9893 }
9894 if (mLowerWallpaperTarget != null) {
9895 if (mLowerWallpaperTarget.mAppToken == wtoken
9896 || mUpperWallpaperTarget.mAppToken == wtoken) {
9897 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009898 }
9899 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009900 if (wtoken.appFullscreen) {
9901 WindowState ws = wtoken.findMainWindow();
9902 if (ws != null) {
9903 // If this is a compatibility mode
9904 // window, we will always use its anim.
9905 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9906 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009907 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009908 bestAnimLayer = Integer.MAX_VALUE;
9909 } else if (ws.mLayer > bestAnimLayer) {
9910 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009911 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009912 bestAnimLayer = ws.mLayer;
9913 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009914 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009915 }
9916 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009917
Dianne Hackborn25994b42009-09-04 14:21:19 -07009918 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009919 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009920 "Wallpaper animation!");
9921 switch (transit) {
9922 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9923 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9924 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9925 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9926 break;
9927 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9928 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9929 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9930 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9931 break;
9932 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009933 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009934 "New transit: " + transit);
9935 } else if (oldWallpaper != null) {
9936 // We are transitioning from an activity with
9937 // a wallpaper to one without.
9938 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009939 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009940 "New transit away from wallpaper: " + transit);
9941 } else if (mWallpaperTarget != null) {
9942 // We are transitioning from an activity without
9943 // a wallpaper to now showing the wallpaper
9944 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009945 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009946 "New transit into wallpaper: " + transit);
9947 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009948
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009949 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9950 mLastEnterAnimToken = animToken;
9951 mLastEnterAnimParams = animLp;
9952 } else if (mLastEnterAnimParams != null) {
9953 animLp = mLastEnterAnimParams;
9954 mLastEnterAnimToken = null;
9955 mLastEnterAnimParams = null;
9956 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009957
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009958 // If all closing windows are obscured, then there is
9959 // no need to do an animation. This is the case, for
9960 // example, when this transition is being done behind
9961 // the lock screen.
9962 if (!mPolicy.allowAppAnimationsLw()) {
9963 animLp = null;
9964 }
9965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009966 NN = mOpeningApps.size();
9967 for (i=0; i<NN; i++) {
9968 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009969 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009970 "Now opening app" + wtoken);
9971 wtoken.reportedVisible = false;
9972 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009973 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009974 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009975 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009976 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009977 wtoken.showAllWindowsLocked();
9978 }
9979 NN = mClosingApps.size();
9980 for (i=0; i<NN; i++) {
9981 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009982 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009983 "Now closing app" + wtoken);
9984 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009985 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009986 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009987 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009988 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009989 // Force the allDrawn flag, because we want to start
9990 // this guy's animations regardless of whether it's
9991 // gotten drawn.
9992 wtoken.allDrawn = true;
9993 }
9994
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009995 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009997 mOpeningApps.clear();
9998 mClosingApps.clear();
9999
10000 // This has changed the visibility of windows, so perform
10001 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010002 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010003 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -070010004 if (!moveInputMethodWindowsIfNeededLocked(true)) {
10005 assignLayersLocked();
10006 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010007 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010008 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010009 }
10010 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010011
Dianne Hackborn16064f92010-03-25 00:47:24 -070010012 int adjResult = 0;
10013
Dianne Hackborna8f60182009-09-01 19:01:50 -070010014 if (!animating && mAppTransitionRunning) {
10015 // We have finished the animation of an app transition. To do
10016 // this, we have delayed a lot of operations like showing and
10017 // hiding apps, moving apps in Z-order, etc. The app token list
10018 // reflects the correct Z-order, but the window list may now
10019 // be out of sync with it. So here we will just rebuild the
10020 // entire app window list. Fun!
10021 mAppTransitionRunning = false;
10022 // Clear information about apps that were moving.
10023 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010024
Dianne Hackborna8f60182009-09-01 19:01:50 -070010025 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010026 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010027 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010028 moveInputMethodWindowsIfNeededLocked(false);
10029 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010030 // Since the window list has been rebuilt, focus might
10031 // have to be recomputed since the actual order of windows
10032 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010033 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010034 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010035
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010036 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010037 // At this point, there was a window with a wallpaper that
10038 // was force hiding other windows behind it, but now it
10039 // is going away. This may be simple -- just animate
10040 // away the wallpaper and its window -- or it may be
10041 // hard -- the wallpaper now needs to be shown behind
10042 // something that was hidden.
10043 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010044 if (mLowerWallpaperTarget != null
10045 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010046 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010047 "wallpaperForceHiding changed with lower="
10048 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010049 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010050 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10051 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10052 if (mLowerWallpaperTarget.mAppToken.hidden) {
10053 // The lower target has become hidden before we
10054 // actually started the animation... let's completely
10055 // re-evaluate everything.
10056 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010057 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010058 }
10059 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010060 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010061 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010062 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010063 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010064 + " NEW: " + mWallpaperTarget
10065 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010066 if (mLowerWallpaperTarget == null) {
10067 // Whoops, we don't need a special wallpaper animation.
10068 // Clear them out.
10069 forceHiding = false;
10070 for (i=N-1; i>=0; i--) {
10071 WindowState w = (WindowState)mWindows.get(i);
10072 if (w.mSurface != null) {
10073 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010074 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010075 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010076 forceHiding = true;
10077 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10078 if (!w.mAnimating) {
10079 // We set the animation above so it
10080 // is not yet running.
10081 w.clearAnimation();
10082 }
10083 }
10084 }
10085 }
10086 }
10087 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010088
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010089 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010090 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010091 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010092 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010093 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010094
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010095 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010096 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010097 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010098 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010099 assignLayersLocked();
10100 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010101 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010102 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010103 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010104 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010105
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010106 if (mFocusMayChange) {
10107 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010108 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010109 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010110 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010111 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010112 }
10113
10114 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010115 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010116 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010117
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010118 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10119 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010120
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010121 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010122
10123 // THIRD LOOP: Update the surfaces of all windows.
10124
10125 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10126
10127 boolean obscured = false;
10128 boolean blurring = false;
10129 boolean dimming = false;
10130 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010131 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010132 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010133
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010134 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010136 for (i=N-1; i>=0; i--) {
10137 WindowState w = (WindowState)mWindows.get(i);
10138
10139 boolean displayed = false;
10140 final WindowManager.LayoutParams attrs = w.mAttrs;
10141 final int attrFlags = attrs.flags;
10142
10143 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010144 // XXX NOTE: The logic here could be improved. We have
10145 // the decision about whether to resize a window separated
10146 // from whether to hide the surface. This can cause us to
10147 // resize a surface even if we are going to hide it. You
10148 // can see this by (1) holding device in landscape mode on
10149 // home screen; (2) tapping browser icon (device will rotate
10150 // to landscape; (3) tap home. The wallpaper will be resized
10151 // in step 2 but then immediately hidden, causing us to
10152 // have to resize and then redraw it again in step 3. It
10153 // would be nice to figure out how to avoid this, but it is
10154 // difficult because we do need to resize surfaces in some
10155 // cases while they are hidden such as when first showing a
10156 // window.
10157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010158 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010159 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010160 TAG, "Placing surface #" + i + " " + w.mSurface
10161 + ": new=" + w.mShownFrame + ", old="
10162 + w.mLastShownFrame);
10163
10164 boolean resize;
10165 int width, height;
10166 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
10167 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
10168 w.mLastRequestedHeight != w.mRequestedHeight;
10169 // for a scaled surface, we just want to use
10170 // the requested size.
10171 width = w.mRequestedWidth;
10172 height = w.mRequestedHeight;
10173 w.mLastRequestedWidth = width;
10174 w.mLastRequestedHeight = height;
10175 w.mLastShownFrame.set(w.mShownFrame);
10176 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010177 if (SHOW_TRANSACTIONS) logSurface(w,
10178 "POS " + w.mShownFrame.left
10179 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010180 w.mSurfaceX = w.mShownFrame.left;
10181 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010182 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10183 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010184 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010185 if (!recoveringMemory) {
10186 reclaimSomeSurfaceMemoryLocked(w, "position");
10187 }
10188 }
10189 } else {
10190 resize = !w.mLastShownFrame.equals(w.mShownFrame);
10191 width = w.mShownFrame.width();
10192 height = w.mShownFrame.height();
10193 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010194 }
10195
10196 if (resize) {
10197 if (width < 1) width = 1;
10198 if (height < 1) height = 1;
10199 if (w.mSurface != null) {
10200 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010201 if (SHOW_TRANSACTIONS) logSurface(w,
10202 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010203 + w.mShownFrame.top + " SIZE "
10204 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010205 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010206 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010207 w.mSurfaceW = width;
10208 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010209 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010210 w.mSurfaceX = w.mShownFrame.left;
10211 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010212 w.mSurface.setPosition(w.mShownFrame.left,
10213 w.mShownFrame.top);
10214 } catch (RuntimeException e) {
10215 // If something goes wrong with the surface (such
10216 // as running out of memory), don't take down the
10217 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010218 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010219 + "size=(" + width + "x" + height
10220 + "), pos=(" + w.mShownFrame.left
10221 + "," + w.mShownFrame.top + ")", e);
10222 if (!recoveringMemory) {
10223 reclaimSomeSurfaceMemoryLocked(w, "size");
10224 }
10225 }
10226 }
10227 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010228 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010229 w.mContentInsetsChanged =
10230 !w.mLastContentInsets.equals(w.mContentInsets);
10231 w.mVisibleInsetsChanged =
10232 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010233 boolean configChanged =
10234 w.mConfiguration != mCurConfiguration
10235 && (w.mConfiguration == null
10236 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010237 if (DEBUG_CONFIGURATION && configChanged) {
10238 Slog.v(TAG, "Win " + w + " config changed: "
10239 + mCurConfiguration);
10240 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010241 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010242 + ": configChanged=" + configChanged
10243 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -070010244 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010245 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010246 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010247 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010248 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010249 w.mLastFrame.set(w.mFrame);
10250 w.mLastContentInsets.set(w.mContentInsets);
10251 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010252 // If the screen is currently frozen, then keep
10253 // it frozen until this window draws at its new
10254 // orientation.
10255 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010256 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010257 "Resizing while display frozen: " + w);
10258 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010259 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010260 mWindowsFreezingScreen = true;
10261 // XXX should probably keep timeout from
10262 // when we first froze the display.
10263 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10264 mH.sendMessageDelayed(mH.obtainMessage(
10265 H.WINDOW_FREEZE_TIMEOUT), 2000);
10266 }
10267 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010268 // If the orientation is changing, then we need to
10269 // hold off on unfreezing the display until this
10270 // window has been redrawn; to do that, we need
10271 // to go through the process of getting informed
10272 // by the application when it has finished drawing.
10273 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010274 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010275 "Orientation start waiting for draw in "
10276 + w + ", surface " + w.mSurface);
10277 w.mDrawPending = true;
10278 w.mCommitDrawPending = false;
10279 w.mReadyToShow = false;
10280 if (w.mAppToken != null) {
10281 w.mAppToken.allDrawn = false;
10282 }
10283 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010284 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010285 "Resizing window " + w + " to " + w.mFrame);
10286 mResizingWindows.add(w);
10287 } else if (w.mOrientationChanging) {
10288 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010289 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010290 "Orientation not waiting for draw in "
10291 + w + ", surface " + w.mSurface);
10292 w.mOrientationChanging = false;
10293 }
10294 }
10295 }
10296
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010297 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010298 if (!w.mLastHidden) {
10299 //dump();
Dianne Hackborn5943c202010-04-12 21:36:49 -070010300 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Window hiding: waitingToShow="
10301 + w.mRootToken.waitingToShow + " polvis="
10302 + w.mPolicyVisibility + " atthid="
10303 + w.mAttachedHidden + " tokhid="
10304 + w.mRootToken.hidden + " vis="
10305 + w.mViewVisibility);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010306 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010307 if (SHOW_TRANSACTIONS) logSurface(w,
10308 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010309 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010310 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010311 try {
10312 w.mSurface.hide();
10313 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010314 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010315 }
10316 }
10317 mKeyWaiter.releasePendingPointerLocked(w.mSession);
10318 }
10319 // If we are waiting for this window to handle an
10320 // orientation change, well, it is hidden, so
10321 // doesn't really matter. Note that this does
10322 // introduce a potential glitch if the window
10323 // becomes unhidden before it has drawn for the
10324 // new orientation.
10325 if (w.mOrientationChanging) {
10326 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010327 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010328 "Orientation change skips hidden " + w);
10329 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010330 } else if (w.mLastLayer != w.mAnimLayer
10331 || w.mLastAlpha != w.mShownAlpha
10332 || w.mLastDsDx != w.mDsDx
10333 || w.mLastDtDx != w.mDtDx
10334 || w.mLastDsDy != w.mDsDy
10335 || w.mLastDtDy != w.mDtDy
10336 || w.mLastHScale != w.mHScale
10337 || w.mLastVScale != w.mVScale
10338 || w.mLastHidden) {
10339 displayed = true;
10340 w.mLastAlpha = w.mShownAlpha;
10341 w.mLastLayer = w.mAnimLayer;
10342 w.mLastDsDx = w.mDsDx;
10343 w.mLastDtDx = w.mDtDx;
10344 w.mLastDsDy = w.mDsDy;
10345 w.mLastDtDy = w.mDtDy;
10346 w.mLastHScale = w.mHScale;
10347 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010348 if (SHOW_TRANSACTIONS) logSurface(w,
10349 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010350 + " matrix=[" + (w.mDsDx*w.mHScale)
10351 + "," + (w.mDtDx*w.mVScale)
10352 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010353 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010354 if (w.mSurface != null) {
10355 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010356 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010357 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010358 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010359 w.mSurface.setLayer(w.mAnimLayer);
10360 w.mSurface.setMatrix(
10361 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10362 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10363 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010364 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010365 if (!recoveringMemory) {
10366 reclaimSomeSurfaceMemoryLocked(w, "update");
10367 }
10368 }
10369 }
10370
10371 if (w.mLastHidden && !w.mDrawPending
10372 && !w.mCommitDrawPending
10373 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010374 if (SHOW_TRANSACTIONS) logSurface(w,
10375 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010376 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010377 + " during relayout");
10378 if (showSurfaceRobustlyLocked(w)) {
10379 w.mHasDrawn = true;
10380 w.mLastHidden = false;
10381 } else {
10382 w.mOrientationChanging = false;
10383 }
10384 }
10385 if (w.mSurface != null) {
10386 w.mToken.hasVisible = true;
10387 }
10388 } else {
10389 displayed = true;
10390 }
10391
10392 if (displayed) {
10393 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010394 if (attrs.width == LayoutParams.MATCH_PARENT
10395 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010396 covered = true;
10397 }
10398 }
10399 if (w.mOrientationChanging) {
10400 if (w.mDrawPending || w.mCommitDrawPending) {
10401 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010402 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010403 "Orientation continue waiting for draw in " + w);
10404 } else {
10405 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010406 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010407 "Orientation change complete in " + w);
10408 }
10409 }
10410 w.mToken.hasVisible = true;
10411 }
10412 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010413 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010414 "Orientation change skips hidden " + w);
10415 w.mOrientationChanging = false;
10416 }
10417
10418 final boolean canBeSeen = w.isDisplayedLw();
10419
10420 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10421 focusDisplayed = true;
10422 }
10423
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010424 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010426 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010427 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010428 if (w.mSurface != null) {
10429 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10430 holdScreen = w.mSession;
10431 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010432 if (!syswin && w.mAttrs.screenBrightness >= 0
10433 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010434 screenBrightness = w.mAttrs.screenBrightness;
10435 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010436 if (!syswin && w.mAttrs.buttonBrightness >= 0
10437 && buttonBrightness < 0) {
10438 buttonBrightness = w.mAttrs.buttonBrightness;
10439 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010440 if (canBeSeen
10441 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10442 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10443 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010444 syswin = true;
10445 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010446 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010447
Dianne Hackborn25994b42009-09-04 14:21:19 -070010448 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10449 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010450 // This window completely covers everything behind it,
10451 // so we want to leave all of them as unblurred (for
10452 // performance reasons).
10453 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010454 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010455 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010456 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010457 obscured = true;
10458 if (mBackgroundFillerSurface == null) {
10459 try {
10460 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010461 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010462 0, dw, dh,
10463 PixelFormat.OPAQUE,
10464 Surface.FX_SURFACE_NORMAL);
10465 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010466 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010467 }
10468 }
10469 try {
10470 mBackgroundFillerSurface.setPosition(0, 0);
10471 mBackgroundFillerSurface.setSize(dw, dh);
10472 // Using the same layer as Dim because they will never be shown at the
10473 // same time.
10474 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10475 mBackgroundFillerSurface.show();
10476 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010477 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010478 }
10479 backgroundFillerShown = true;
10480 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010481 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010482 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010483 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010484 + ": blurring=" + blurring
10485 + " obscured=" + obscured
10486 + " displayed=" + displayed);
10487 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10488 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010489 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010490 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010491 if (mDimAnimator == null) {
10492 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010493 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010494 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010495 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010496 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010497 }
10498 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10499 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010500 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010501 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010502 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010503 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010504 + mBlurSurface + ": CREATE");
10505 try {
Romain Guy06882f82009-06-10 13:36:04 -070010506 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010507 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010508 -1, 16, 16,
10509 PixelFormat.OPAQUE,
10510 Surface.FX_SURFACE_BLUR);
10511 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010512 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010513 }
10514 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010515 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010516 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10517 + mBlurSurface + ": pos=(0,0) (" +
10518 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010519 mBlurSurface.setPosition(0, 0);
10520 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010521 mBlurSurface.setLayer(w.mAnimLayer-2);
10522 if (!mBlurShown) {
10523 try {
10524 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10525 + mBlurSurface + ": SHOW");
10526 mBlurSurface.show();
10527 } catch (RuntimeException e) {
10528 Slog.w(TAG, "Failure showing blur surface", e);
10529 }
10530 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010531 }
10532 }
10533 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010534 }
10535 }
10536 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010537
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010538 if (obscuredChanged && mWallpaperTarget == w) {
10539 // This is the wallpaper target and its obscured state
10540 // changed... make sure the current wallaper's visibility
10541 // has been updated accordingly.
10542 updateWallpaperVisibilityLocked();
10543 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010544 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010545
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010546 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10547 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010548 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010549 try {
10550 mBackgroundFillerSurface.hide();
10551 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010552 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010553 }
10554 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010555
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010556 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010557 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10558 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010559 }
Romain Guy06882f82009-06-10 13:36:04 -070010560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010561 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010562 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010563 + ": HIDE");
10564 try {
10565 mBlurSurface.hide();
10566 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010567 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010568 }
10569 mBlurShown = false;
10570 }
10571
Joe Onorato8a9b2202010-02-26 18:56:32 -080010572 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010573 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010574 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010575 }
10576
10577 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010578
Joe Onorato8a9b2202010-02-26 18:56:32 -080010579 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010580 "With display frozen, orientationChangeComplete="
10581 + orientationChangeComplete);
10582 if (orientationChangeComplete) {
10583 if (mWindowsFreezingScreen) {
10584 mWindowsFreezingScreen = false;
10585 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10586 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010587 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010588 }
Romain Guy06882f82009-06-10 13:36:04 -070010589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010590 i = mResizingWindows.size();
10591 if (i > 0) {
10592 do {
10593 i--;
10594 WindowState win = mResizingWindows.get(i);
10595 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010596 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10597 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010598 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010599 boolean configChanged =
10600 win.mConfiguration != mCurConfiguration
10601 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010602 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10603 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10604 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010605 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010606 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010607 + " / " + mCurConfiguration + " / 0x"
10608 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010609 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010610 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010611 win.mClient.resized(win.mFrame.width(),
10612 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010613 win.mLastVisibleInsets, win.mDrawPending,
10614 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010615 win.mContentInsetsChanged = false;
10616 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010617 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010618 } catch (RemoteException e) {
10619 win.mOrientationChanging = false;
10620 }
10621 } while (i > 0);
10622 mResizingWindows.clear();
10623 }
Romain Guy06882f82009-06-10 13:36:04 -070010624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010625 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010626 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010627 i = mDestroySurface.size();
10628 if (i > 0) {
10629 do {
10630 i--;
10631 WindowState win = mDestroySurface.get(i);
10632 win.mDestroying = false;
10633 if (mInputMethodWindow == win) {
10634 mInputMethodWindow = null;
10635 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010636 if (win == mWallpaperTarget) {
10637 wallpaperDestroyed = true;
10638 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010639 win.destroySurfaceLocked();
10640 } while (i > 0);
10641 mDestroySurface.clear();
10642 }
10643
10644 // Time to remove any exiting tokens?
10645 for (i=mExitingTokens.size()-1; i>=0; i--) {
10646 WindowToken token = mExitingTokens.get(i);
10647 if (!token.hasVisible) {
10648 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010649 if (token.windowType == TYPE_WALLPAPER) {
10650 mWallpaperTokens.remove(token);
10651 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010652 }
10653 }
10654
10655 // Time to remove any exiting applications?
10656 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10657 AppWindowToken token = mExitingAppTokens.get(i);
10658 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010659 // Make sure there is no animation running on this token,
10660 // so any windows associated with it will be removed as
10661 // soon as their animations are complete
10662 token.animation = null;
10663 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010664 mAppTokens.remove(token);
10665 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010666 if (mLastEnterAnimToken == token) {
10667 mLastEnterAnimToken = null;
10668 mLastEnterAnimParams = null;
10669 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010670 }
10671 }
10672
Dianne Hackborna8f60182009-09-01 19:01:50 -070010673 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010674
Dianne Hackborna8f60182009-09-01 19:01:50 -070010675 if (!animating && mAppTransitionRunning) {
10676 // We have finished the animation of an app transition. To do
10677 // this, we have delayed a lot of operations like showing and
10678 // hiding apps, moving apps in Z-order, etc. The app token list
10679 // reflects the correct Z-order, but the window list may now
10680 // be out of sync with it. So here we will just rebuild the
10681 // entire app window list. Fun!
10682 mAppTransitionRunning = false;
10683 needRelayout = true;
10684 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010685 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010686 // Clear information about apps that were moving.
10687 mToBottomApps.clear();
10688 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010690 if (focusDisplayed) {
10691 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10692 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010693 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010694 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010695 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010696 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010697 requestAnimationLocked(0);
10698 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010699 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10700 }
Dianne Hackbornce73c1e2010-04-12 23:11:38 -070010701
10702 if (DEBUG_FREEZE) Slog.v(TAG, "Layout: mDisplayFrozen=" + mDisplayFrozen
10703 + " holdScreen=" + holdScreen);
10704 if (!mDisplayFrozen) {
10705 mQueue.setHoldScreenLocked(holdScreen != null);
10706 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10707 mPowerManager.setScreenBrightnessOverride(-1);
10708 } else {
10709 mPowerManager.setScreenBrightnessOverride((int)
10710 (screenBrightness * Power.BRIGHTNESS_ON));
10711 }
10712 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10713 mPowerManager.setButtonBrightnessOverride(-1);
10714 } else {
10715 mPowerManager.setButtonBrightnessOverride((int)
10716 (buttonBrightness * Power.BRIGHTNESS_ON));
10717 }
10718 if (holdScreen != mHoldingScreenOn) {
10719 mHoldingScreenOn = holdScreen;
10720 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10721 mH.sendMessage(m);
10722 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010723 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010724
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010725 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010726 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010727 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10728 LocalPowerManager.BUTTON_EVENT, true);
10729 mTurnOnScreen = false;
10730 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010731
10732 // Check to see if we are now in a state where the screen should
10733 // be enabled, because the window obscured flags have changed.
10734 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010735 }
10736
10737 void requestAnimationLocked(long delay) {
10738 if (!mAnimationPending) {
10739 mAnimationPending = true;
10740 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10741 }
10742 }
Romain Guy06882f82009-06-10 13:36:04 -070010743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010744 /**
10745 * Have the surface flinger show a surface, robustly dealing with
10746 * error conditions. In particular, if there is not enough memory
10747 * to show the surface, then we will try to get rid of other surfaces
10748 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010749 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010750 * @return Returns true if the surface was successfully shown.
10751 */
10752 boolean showSurfaceRobustlyLocked(WindowState win) {
10753 try {
10754 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010755 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010756 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010757 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010758 if (DEBUG_VISIBILITY) Slog.v(TAG,
10759 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010760 win.mTurnOnScreen = false;
10761 mTurnOnScreen = true;
10762 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010763 }
10764 return true;
10765 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010766 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010767 }
Romain Guy06882f82009-06-10 13:36:04 -070010768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010769 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010770
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010771 return false;
10772 }
Romain Guy06882f82009-06-10 13:36:04 -070010773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010774 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10775 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010776
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010777 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010778 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010780 if (mForceRemoves == null) {
10781 mForceRemoves = new ArrayList<WindowState>();
10782 }
Romain Guy06882f82009-06-10 13:36:04 -070010783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010784 long callingIdentity = Binder.clearCallingIdentity();
10785 try {
10786 // There was some problem... first, do a sanity check of the
10787 // window list to make sure we haven't left any dangling surfaces
10788 // around.
10789 int N = mWindows.size();
10790 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010791 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010792 for (int i=0; i<N; i++) {
10793 WindowState ws = (WindowState)mWindows.get(i);
10794 if (ws.mSurface != null) {
10795 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010796 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010797 + ws + " surface=" + ws.mSurface
10798 + " token=" + win.mToken
10799 + " pid=" + ws.mSession.mPid
10800 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010801 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010802 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010803 ws.mSurface = null;
10804 mForceRemoves.add(ws);
10805 i--;
10806 N--;
10807 leakedSurface = true;
10808 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010809 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010810 + ws + " surface=" + ws.mSurface
10811 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010812 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010813 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010814 ws.mSurface = null;
10815 leakedSurface = true;
10816 }
10817 }
10818 }
Romain Guy06882f82009-06-10 13:36:04 -070010819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010820 boolean killedApps = false;
10821 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010822 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010823 SparseIntArray pidCandidates = new SparseIntArray();
10824 for (int i=0; i<N; i++) {
10825 WindowState ws = (WindowState)mWindows.get(i);
10826 if (ws.mSurface != null) {
10827 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10828 }
10829 }
10830 if (pidCandidates.size() > 0) {
10831 int[] pids = new int[pidCandidates.size()];
10832 for (int i=0; i<pids.length; i++) {
10833 pids[i] = pidCandidates.keyAt(i);
10834 }
10835 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010836 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010837 killedApps = true;
10838 }
10839 } catch (RemoteException e) {
10840 }
10841 }
10842 }
Romain Guy06882f82009-06-10 13:36:04 -070010843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010844 if (leakedSurface || killedApps) {
10845 // We managed to reclaim some memory, so get rid of the trouble
10846 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010847 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010848 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010849 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010850 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010851 win.mSurface = null;
10852 }
Romain Guy06882f82009-06-10 13:36:04 -070010853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010854 try {
10855 win.mClient.dispatchGetNewSurface();
10856 } catch (RemoteException e) {
10857 }
10858 }
10859 } finally {
10860 Binder.restoreCallingIdentity(callingIdentity);
10861 }
10862 }
Romain Guy06882f82009-06-10 13:36:04 -070010863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010864 private boolean updateFocusedWindowLocked(int mode) {
10865 WindowState newFocus = computeFocusedWindowLocked();
10866 if (mCurrentFocus != newFocus) {
10867 // This check makes sure that we don't already have the focus
10868 // change message pending.
10869 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10870 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010871 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010872 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10873 final WindowState oldFocus = mCurrentFocus;
10874 mCurrentFocus = newFocus;
10875 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010877 final WindowState imWindow = mInputMethodWindow;
10878 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010879 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010880 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010881 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10882 mLayoutNeeded = true;
10883 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010884 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10885 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010886 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10887 // Client will do the layout, but we need to assign layers
10888 // for handleNewWindowLocked() below.
10889 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010890 }
10891 }
Romain Guy06882f82009-06-10 13:36:04 -070010892
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010893 if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10894 mKeyWaiter.handleNewWindowLocked(newFocus);
10895 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010896 return true;
10897 }
10898 return false;
10899 }
10900
10901 private WindowState computeFocusedWindowLocked() {
10902 WindowState result = null;
10903 WindowState win;
10904
10905 int i = mWindows.size() - 1;
10906 int nextAppIndex = mAppTokens.size()-1;
10907 WindowToken nextApp = nextAppIndex >= 0
10908 ? mAppTokens.get(nextAppIndex) : null;
10909
10910 while (i >= 0) {
10911 win = (WindowState)mWindows.get(i);
10912
Joe Onorato8a9b2202010-02-26 18:56:32 -080010913 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010914 TAG, "Looking for focus: " + i
10915 + " = " + win
10916 + ", flags=" + win.mAttrs.flags
10917 + ", canReceive=" + win.canReceiveKeys());
10918
10919 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010921 // If this window's application has been removed, just skip it.
10922 if (thisApp != null && thisApp.removed) {
10923 i--;
10924 continue;
10925 }
Romain Guy06882f82009-06-10 13:36:04 -070010926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010927 // If there is a focused app, don't allow focus to go to any
10928 // windows below it. If this is an application window, step
10929 // through the app tokens until we find its app.
10930 if (thisApp != null && nextApp != null && thisApp != nextApp
10931 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10932 int origAppIndex = nextAppIndex;
10933 while (nextAppIndex > 0) {
10934 if (nextApp == mFocusedApp) {
10935 // Whoops, we are below the focused app... no focus
10936 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010937 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010938 TAG, "Reached focused app: " + mFocusedApp);
10939 return null;
10940 }
10941 nextAppIndex--;
10942 nextApp = mAppTokens.get(nextAppIndex);
10943 if (nextApp == thisApp) {
10944 break;
10945 }
10946 }
10947 if (thisApp != nextApp) {
10948 // Uh oh, the app token doesn't exist! This shouldn't
10949 // happen, but if it does we can get totally hosed...
10950 // so restart at the original app.
10951 nextAppIndex = origAppIndex;
10952 nextApp = mAppTokens.get(nextAppIndex);
10953 }
10954 }
10955
10956 // Dispatch to this window if it is wants key events.
10957 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010958 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010959 TAG, "Found focus @ " + i + " = " + win);
10960 result = win;
10961 break;
10962 }
10963
10964 i--;
10965 }
10966
10967 return result;
10968 }
10969
10970 private void startFreezingDisplayLocked() {
10971 if (mDisplayFrozen) {
Chris Tate2ad63a92009-03-25 17:36:48 -070010972 // Freezing the display also suspends key event delivery, to
10973 // keep events from going astray while the display is reconfigured.
10974 // If someone has changed orientation again while the screen is
10975 // still frozen, the events will continue to be blocked while the
10976 // successive orientation change is processed. To prevent spurious
10977 // ANRs, we reset the event dispatch timeout in this case.
10978 synchronized (mKeyWaiter) {
10979 mKeyWaiter.mWasFrozen = true;
10980 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010981 return;
10982 }
Romain Guy06882f82009-06-10 13:36:04 -070010983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010984 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010986 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010987 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010988 if (mFreezeGcPending != 0) {
10989 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010990 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010991 mH.removeMessages(H.FORCE_GC);
10992 Runtime.getRuntime().gc();
10993 mFreezeGcPending = now;
10994 }
10995 } else {
10996 mFreezeGcPending = now;
10997 }
Romain Guy06882f82009-06-10 13:36:04 -070010998
Dianne Hackbornce73c1e2010-04-12 23:11:38 -070010999 if (DEBUG_FREEZE) Slog.v(TAG, "*** FREEZING DISPLAY", new RuntimeException());
11000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011001 mDisplayFrozen = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070011002 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
11003 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011004 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011005 mAppTransitionReady = true;
11006 }
Romain Guy06882f82009-06-10 13:36:04 -070011007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011008 if (PROFILE_ORIENTATION) {
11009 File file = new File("/data/system/frozen");
11010 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
11011 }
11012 Surface.freezeDisplay(0);
11013 }
Romain Guy06882f82009-06-10 13:36:04 -070011014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011015 private void stopFreezingDisplayLocked() {
11016 if (!mDisplayFrozen) {
11017 return;
11018 }
Romain Guy06882f82009-06-10 13:36:04 -070011019
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011020 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
11021 return;
11022 }
11023
Dianne Hackbornce73c1e2010-04-12 23:11:38 -070011024 if (DEBUG_FREEZE) Slog.v(TAG, "*** UNFREEZING DISPLAY", new RuntimeException());
11025
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011026 mDisplayFrozen = false;
11027 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
11028 if (PROFILE_ORIENTATION) {
11029 Debug.stopMethodTracing();
11030 }
11031 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070011032
Chris Tate2ad63a92009-03-25 17:36:48 -070011033 // Reset the key delivery timeout on unfreeze, too. We force a wakeup here
11034 // too because regular key delivery processing should resume immediately.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011035 synchronized (mKeyWaiter) {
11036 mKeyWaiter.mWasFrozen = true;
11037 mKeyWaiter.notifyAll();
11038 }
11039
Christopher Tateb696aee2010-04-02 19:08:30 -070011040 // While the display is frozen we don't re-compute the orientation
11041 // to avoid inconsistent states. However, something interesting
11042 // could have actually changed during that time so re-evaluate it
11043 // now to catch that.
11044 if (updateOrientationFromAppTokensLocked()) {
11045 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
11046 }
11047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011048 // A little kludge: a lot could have happened while the
11049 // display was frozen, so now that we are coming back we
11050 // do a gc so that any remote references the system
11051 // processes holds on others can be released if they are
11052 // no longer needed.
11053 mH.removeMessages(H.FORCE_GC);
11054 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11055 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011057 mScreenFrozenLock.release();
11058 }
Romain Guy06882f82009-06-10 13:36:04 -070011059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011060 @Override
11061 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11062 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11063 != PackageManager.PERMISSION_GRANTED) {
11064 pw.println("Permission Denial: can't dump WindowManager from from pid="
11065 + Binder.getCallingPid()
11066 + ", uid=" + Binder.getCallingUid());
11067 return;
11068 }
Romain Guy06882f82009-06-10 13:36:04 -070011069
Dianne Hackborna2e92262010-03-02 17:19:29 -080011070 pw.println("Input State:");
11071 mQueue.dump(pw, " ");
11072 pw.println(" ");
11073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011074 synchronized(mWindowMap) {
11075 pw.println("Current Window Manager state:");
11076 for (int i=mWindows.size()-1; i>=0; i--) {
11077 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011078 pw.print(" Window #"); pw.print(i); pw.print(' ');
11079 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011080 w.dump(pw, " ");
11081 }
11082 if (mInputMethodDialogs.size() > 0) {
11083 pw.println(" ");
11084 pw.println(" Input method dialogs:");
11085 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11086 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011087 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011088 }
11089 }
11090 if (mPendingRemove.size() > 0) {
11091 pw.println(" ");
11092 pw.println(" Remove pending for:");
11093 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11094 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011095 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11096 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011097 w.dump(pw, " ");
11098 }
11099 }
11100 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11101 pw.println(" ");
11102 pw.println(" Windows force removing:");
11103 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11104 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011105 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11106 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011107 w.dump(pw, " ");
11108 }
11109 }
11110 if (mDestroySurface.size() > 0) {
11111 pw.println(" ");
11112 pw.println(" Windows waiting to destroy their surface:");
11113 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11114 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011115 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11116 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011117 w.dump(pw, " ");
11118 }
11119 }
11120 if (mLosingFocus.size() > 0) {
11121 pw.println(" ");
11122 pw.println(" Windows losing focus:");
11123 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11124 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011125 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11126 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011127 w.dump(pw, " ");
11128 }
11129 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011130 if (mResizingWindows.size() > 0) {
11131 pw.println(" ");
11132 pw.println(" Windows waiting to resize:");
11133 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11134 WindowState w = mResizingWindows.get(i);
11135 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11136 pw.print(w); pw.println(":");
11137 w.dump(pw, " ");
11138 }
11139 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011140 if (mSessions.size() > 0) {
11141 pw.println(" ");
11142 pw.println(" All active sessions:");
11143 Iterator<Session> it = mSessions.iterator();
11144 while (it.hasNext()) {
11145 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011146 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011147 s.dump(pw, " ");
11148 }
11149 }
11150 if (mTokenMap.size() > 0) {
11151 pw.println(" ");
11152 pw.println(" All tokens:");
11153 Iterator<WindowToken> it = mTokenMap.values().iterator();
11154 while (it.hasNext()) {
11155 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011156 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011157 token.dump(pw, " ");
11158 }
11159 }
11160 if (mTokenList.size() > 0) {
11161 pw.println(" ");
11162 pw.println(" Window token list:");
11163 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011164 pw.print(" #"); pw.print(i); pw.print(": ");
11165 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011166 }
11167 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011168 if (mWallpaperTokens.size() > 0) {
11169 pw.println(" ");
11170 pw.println(" Wallpaper tokens:");
11171 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11172 WindowToken token = mWallpaperTokens.get(i);
11173 pw.print(" Wallpaper #"); pw.print(i);
11174 pw.print(' '); pw.print(token); pw.println(':');
11175 token.dump(pw, " ");
11176 }
11177 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011178 if (mAppTokens.size() > 0) {
11179 pw.println(" ");
11180 pw.println(" Application tokens in Z order:");
11181 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011182 pw.print(" App #"); pw.print(i); pw.print(": ");
11183 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011184 }
11185 }
11186 if (mFinishedStarting.size() > 0) {
11187 pw.println(" ");
11188 pw.println(" Finishing start of application tokens:");
11189 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11190 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011191 pw.print(" Finished Starting #"); pw.print(i);
11192 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011193 token.dump(pw, " ");
11194 }
11195 }
11196 if (mExitingTokens.size() > 0) {
11197 pw.println(" ");
11198 pw.println(" Exiting tokens:");
11199 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11200 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011201 pw.print(" Exiting #"); pw.print(i);
11202 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011203 token.dump(pw, " ");
11204 }
11205 }
11206 if (mExitingAppTokens.size() > 0) {
11207 pw.println(" ");
11208 pw.println(" Exiting application tokens:");
11209 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11210 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011211 pw.print(" Exiting App #"); pw.print(i);
11212 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011213 token.dump(pw, " ");
11214 }
11215 }
11216 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011217 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11218 pw.print(" mLastFocus="); pw.println(mLastFocus);
11219 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11220 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11221 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011222 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011223 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11224 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11225 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11226 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011227 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11228 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11229 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011230 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11231 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11232 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11233 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011234 if (mDimAnimator != null) {
11235 mDimAnimator.printTo(pw);
11236 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011237 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011238 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011239 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011240 pw.print(mInputMethodAnimLayerAdjustment);
11241 pw.print(" mWallpaperAnimLayerAdjustment=");
11242 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011243 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11244 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011245 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11246 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011247 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11248 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011249 pw.print(" mRotation="); pw.print(mRotation);
11250 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11251 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11252 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11253 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11254 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11255 pw.print(" mNextAppTransition=0x");
11256 pw.print(Integer.toHexString(mNextAppTransition));
11257 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011258 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011259 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011260 if (mNextAppTransitionPackage != null) {
11261 pw.print(" mNextAppTransitionPackage=");
11262 pw.print(mNextAppTransitionPackage);
11263 pw.print(", mNextAppTransitionEnter=0x");
11264 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11265 pw.print(", mNextAppTransitionExit=0x");
11266 pw.print(Integer.toHexString(mNextAppTransitionExit));
11267 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011268 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11269 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011270 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11271 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11272 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11273 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011274 if (mOpeningApps.size() > 0) {
11275 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11276 }
11277 if (mClosingApps.size() > 0) {
11278 pw.print(" mClosingApps="); pw.println(mClosingApps);
11279 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011280 if (mToTopApps.size() > 0) {
11281 pw.print(" mToTopApps="); pw.println(mToTopApps);
11282 }
11283 if (mToBottomApps.size() > 0) {
11284 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11285 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011286 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11287 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011288 pw.println(" KeyWaiter state:");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011289 pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin);
11290 pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder);
11291 pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished);
11292 pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow);
11293 pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching);
11294 pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011295 }
11296 }
11297
11298 public void monitor() {
11299 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011300 synchronized (mKeyguardTokenWatcher) { }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011301 synchronized (mKeyWaiter) { }
11302 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011303
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011304 public void virtualKeyFeedback(KeyEvent event) {
11305 mPolicy.keyFeedbackFromInput(event);
11306 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011307
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011308 /**
11309 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011310 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011311 */
11312 private static class DimAnimator {
11313 Surface mDimSurface;
11314 boolean mDimShown = false;
11315 float mDimCurrentAlpha;
11316 float mDimTargetAlpha;
11317 float mDimDeltaPerMs;
11318 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011319
11320 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011321
11322 DimAnimator (SurfaceSession session) {
11323 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011324 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011325 + mDimSurface + ": CREATE");
11326 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011327 mDimSurface = new Surface(session, 0,
11328 "DimSurface",
11329 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011330 Surface.FX_SURFACE_DIM);
11331 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011332 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011333 }
11334 }
11335 }
11336
11337 /**
11338 * Show the dim surface.
11339 */
11340 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011341 if (!mDimShown) {
11342 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11343 dw + "x" + dh + ")");
11344 mDimShown = true;
11345 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011346 mLastDimWidth = dw;
11347 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011348 mDimSurface.setPosition(0, 0);
11349 mDimSurface.setSize(dw, dh);
11350 mDimSurface.show();
11351 } catch (RuntimeException e) {
11352 Slog.w(TAG, "Failure showing dim surface", e);
11353 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011354 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11355 mLastDimWidth = dw;
11356 mLastDimHeight = dh;
11357 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011358 }
11359 }
11360
11361 /**
11362 * Set's the dim surface's layer and update dim parameters that will be used in
11363 * {@link updateSurface} after all windows are examined.
11364 */
11365 void updateParameters(WindowState w, long currentTime) {
11366 mDimSurface.setLayer(w.mAnimLayer-1);
11367
11368 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011369 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011370 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011371 if (mDimTargetAlpha != target) {
11372 // If the desired dim level has changed, then
11373 // start an animation to it.
11374 mLastDimAnimTime = currentTime;
11375 long duration = (w.mAnimating && w.mAnimation != null)
11376 ? w.mAnimation.computeDurationHint()
11377 : DEFAULT_DIM_DURATION;
11378 if (target > mDimTargetAlpha) {
11379 // This is happening behind the activity UI,
11380 // so we can make it run a little longer to
11381 // give a stronger impression without disrupting
11382 // the user.
11383 duration *= DIM_DURATION_MULTIPLIER;
11384 }
11385 if (duration < 1) {
11386 // Don't divide by zero
11387 duration = 1;
11388 }
11389 mDimTargetAlpha = target;
11390 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11391 }
11392 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011393
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011394 /**
11395 * Updating the surface's alpha. Returns true if the animation continues, or returns
11396 * false when the animation is finished and the dim surface is hidden.
11397 */
11398 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11399 if (!dimming) {
11400 if (mDimTargetAlpha != 0) {
11401 mLastDimAnimTime = currentTime;
11402 mDimTargetAlpha = 0;
11403 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11404 }
11405 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011406
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011407 boolean animating = false;
11408 if (mLastDimAnimTime != 0) {
11409 mDimCurrentAlpha += mDimDeltaPerMs
11410 * (currentTime-mLastDimAnimTime);
11411 boolean more = true;
11412 if (displayFrozen) {
11413 // If the display is frozen, there is no reason to animate.
11414 more = false;
11415 } else if (mDimDeltaPerMs > 0) {
11416 if (mDimCurrentAlpha > mDimTargetAlpha) {
11417 more = false;
11418 }
11419 } else if (mDimDeltaPerMs < 0) {
11420 if (mDimCurrentAlpha < mDimTargetAlpha) {
11421 more = false;
11422 }
11423 } else {
11424 more = false;
11425 }
11426
11427 // Do we need to continue animating?
11428 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011429 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011430 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11431 mLastDimAnimTime = currentTime;
11432 mDimSurface.setAlpha(mDimCurrentAlpha);
11433 animating = true;
11434 } else {
11435 mDimCurrentAlpha = mDimTargetAlpha;
11436 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011437 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011438 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11439 mDimSurface.setAlpha(mDimCurrentAlpha);
11440 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011441 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011442 + ": HIDE");
11443 try {
11444 mDimSurface.hide();
11445 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011446 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011447 }
11448 mDimShown = false;
11449 }
11450 }
11451 }
11452 return animating;
11453 }
11454
11455 public void printTo(PrintWriter pw) {
11456 pw.print(" mDimShown="); pw.print(mDimShown);
11457 pw.print(" current="); pw.print(mDimCurrentAlpha);
11458 pw.print(" target="); pw.print(mDimTargetAlpha);
11459 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11460 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11461 }
11462 }
11463
11464 /**
11465 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11466 * This is used for opening/closing transition for apps in compatible mode.
11467 */
11468 private static class FadeInOutAnimation extends Animation {
11469 int mWidth;
11470 boolean mFadeIn;
11471
11472 public FadeInOutAnimation(boolean fadeIn) {
11473 setInterpolator(new AccelerateInterpolator());
11474 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11475 mFadeIn = fadeIn;
11476 }
11477
11478 @Override
11479 protected void applyTransformation(float interpolatedTime, Transformation t) {
11480 float x = interpolatedTime;
11481 if (!mFadeIn) {
11482 x = 1.0f - x; // reverse the interpolation for fade out
11483 }
11484 if (x < 0.5) {
11485 // move the window out of the screen.
11486 t.getMatrix().setTranslate(mWidth, 0);
11487 } else {
11488 t.getMatrix().setTranslate(0, 0);// show
11489 t.setAlpha((x - 0.5f) * 2);
11490 }
11491 }
11492
11493 @Override
11494 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11495 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11496 mWidth = width;
11497 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011498
11499 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011500 public int getZAdjustment() {
11501 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011502 }
11503 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011504}