blob: 657b6af0b43808535aaa6666daffb81ba68ac51b [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);
7583 if (c.mSurface != null && c.mAttachedHidden) {
7584 c.mAttachedHidden = false;
7585 c.performShowLocked();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007586 // It hadn't been shown, which means layout not
7587 // performed on it, so now we want to make sure to
7588 // do a layout. If called from within the transaction
7589 // loop, this will cause it to restart with a new
7590 // layout.
7591 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007592 }
7593 }
Romain Guy06882f82009-06-10 13:36:04 -07007594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007595 if (mAttrs.type != TYPE_APPLICATION_STARTING
7596 && mAppToken != null) {
7597 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007598
Dianne Hackborn248b1882009-09-16 16:46:44 -07007599 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007600 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007601 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007602 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007603 // If this initial window is animating, stop it -- we
7604 // will do an animation to reveal it from behind the
7605 // starting window, so there is no need for it to also
7606 // be doing its own stuff.
7607 if (mAnimation != null) {
7608 mAnimation = null;
7609 // Make sure we clean up the animation.
7610 mAnimating = true;
7611 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007612 mFinishedStarting.add(mAppToken);
7613 mH.sendEmptyMessage(H.FINISHED_STARTING);
7614 }
7615 mAppToken.updateReportedVisibilityLocked();
7616 }
7617 }
7618 return true;
7619 }
Romain Guy06882f82009-06-10 13:36:04 -07007620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007621 // This must be called while inside a transaction. Returns true if
7622 // there is more animation to run.
7623 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007624 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007625 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007627 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7628 mHasTransformation = true;
7629 mHasLocalTransformation = true;
7630 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007631 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007632 TAG, "Starting animation in " + this +
7633 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7634 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7635 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7636 mAnimation.setStartTime(currentTime);
7637 mLocalAnimating = true;
7638 mAnimating = true;
7639 }
7640 mTransformation.clear();
7641 final boolean more = mAnimation.getTransformation(
7642 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007643 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007644 TAG, "Stepped animation in " + this +
7645 ": more=" + more + ", xform=" + mTransformation);
7646 if (more) {
7647 // we're not done!
7648 return true;
7649 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007650 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007651 TAG, "Finished animation in " + this +
7652 " @ " + currentTime);
7653 mAnimation = null;
7654 //WindowManagerService.this.dump();
7655 }
7656 mHasLocalTransformation = false;
7657 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007658 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007659 // When our app token is animating, we kind-of pretend like
7660 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7661 // part of this check means that we will only do this if
7662 // our window is not currently exiting, or it is not
7663 // locally animating itself. The idea being that one that
7664 // is exiting and doing a local animation should be removed
7665 // once that animation is done.
7666 mAnimating = true;
7667 mHasTransformation = true;
7668 mTransformation.clear();
7669 return false;
7670 } else if (mHasTransformation) {
7671 // Little trick to get through the path below to act like
7672 // we have finished an animation.
7673 mAnimating = true;
7674 } else if (isAnimating()) {
7675 mAnimating = true;
7676 }
7677 } else if (mAnimation != null) {
7678 // If the display is frozen, and there is a pending animation,
7679 // clear it and make sure we run the cleanup code.
7680 mAnimating = true;
7681 mLocalAnimating = true;
7682 mAnimation = null;
7683 }
Romain Guy06882f82009-06-10 13:36:04 -07007684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007685 if (!mAnimating && !mLocalAnimating) {
7686 return false;
7687 }
7688
Joe Onorato8a9b2202010-02-26 18:56:32 -08007689 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007690 TAG, "Animation done in " + this + ": exiting=" + mExiting
7691 + ", reportedVisible="
7692 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007694 mAnimating = false;
7695 mLocalAnimating = false;
7696 mAnimation = null;
7697 mAnimLayer = mLayer;
7698 if (mIsImWindow) {
7699 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007700 } else if (mIsWallpaper) {
7701 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007702 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007703 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007704 + " anim layer: " + mAnimLayer);
7705 mHasTransformation = false;
7706 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007707 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7708 if (DEBUG_VISIBILITY) {
7709 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7710 + mPolicyVisibilityAfterAnim);
7711 }
7712 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7713 if (!mPolicyVisibility) {
7714 if (mCurrentFocus == this) {
7715 mFocusMayChange = true;
7716 }
7717 // Window is no longer visible -- make sure if we were waiting
7718 // for it to be displayed before enabling the display, that
7719 // we allow the display to be enabled now.
7720 enableScreenIfNeededLocked();
7721 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007722 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007723 mTransformation.clear();
7724 if (mHasDrawn
7725 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7726 && mAppToken != null
7727 && mAppToken.firstWindowDrawn
7728 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007729 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007730 + mToken + ": first real window done animating");
7731 mFinishedStarting.add(mAppToken);
7732 mH.sendEmptyMessage(H.FINISHED_STARTING);
7733 }
Romain Guy06882f82009-06-10 13:36:04 -07007734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007735 finishExit();
7736
7737 if (mAppToken != null) {
7738 mAppToken.updateReportedVisibilityLocked();
7739 }
7740
7741 return false;
7742 }
7743
7744 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007745 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007746 TAG, "finishExit in " + this
7747 + ": exiting=" + mExiting
7748 + " remove=" + mRemoveOnExit
7749 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007751 final int N = mChildWindows.size();
7752 for (int i=0; i<N; i++) {
7753 ((WindowState)mChildWindows.get(i)).finishExit();
7754 }
Romain Guy06882f82009-06-10 13:36:04 -07007755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007756 if (!mExiting) {
7757 return;
7758 }
Romain Guy06882f82009-06-10 13:36:04 -07007759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007760 if (isWindowAnimating()) {
7761 return;
7762 }
7763
Joe Onorato8a9b2202010-02-26 18:56:32 -08007764 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007765 TAG, "Exit animation finished in " + this
7766 + ": remove=" + mRemoveOnExit);
7767 if (mSurface != null) {
7768 mDestroySurface.add(this);
7769 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007770 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007771 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007772 try {
7773 mSurface.hide();
7774 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007775 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007776 }
7777 mLastHidden = true;
7778 mKeyWaiter.releasePendingPointerLocked(mSession);
7779 }
7780 mExiting = false;
7781 if (mRemoveOnExit) {
7782 mPendingRemove.add(this);
7783 mRemoveOnExit = false;
7784 }
7785 }
Romain Guy06882f82009-06-10 13:36:04 -07007786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007787 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7788 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7789 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7790 if (dtdx < -.000001f || dtdx > .000001f) return false;
7791 if (dsdy < -.000001f || dsdy > .000001f) return false;
7792 return true;
7793 }
Romain Guy06882f82009-06-10 13:36:04 -07007794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007795 void computeShownFrameLocked() {
7796 final boolean selfTransformation = mHasLocalTransformation;
7797 Transformation attachedTransformation =
7798 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7799 ? mAttachedWindow.mTransformation : null;
7800 Transformation appTransformation =
7801 (mAppToken != null && mAppToken.hasTransformation)
7802 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007803
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007804 // Wallpapers are animated based on the "real" window they
7805 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007806 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007807 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007808 if (mWallpaperTarget.mHasLocalTransformation &&
7809 mWallpaperTarget.mAnimation != null &&
7810 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007811 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007812 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007813 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007814 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007815 }
7816 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007817 mWallpaperTarget.mAppToken.hasTransformation &&
7818 mWallpaperTarget.mAppToken.animation != null &&
7819 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007820 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007821 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007822 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007823 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007824 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007825 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007827 if (selfTransformation || attachedTransformation != null
7828 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007829 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007830 final Rect frame = mFrame;
7831 final float tmpFloats[] = mTmpFloats;
7832 final Matrix tmpMatrix = mTmpMatrix;
7833
7834 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007835 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007836 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007837 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007838 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007839 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007840 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007841 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007842 }
7843 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007844 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007845 }
7846
7847 // "convert" it into SurfaceFlinger's format
7848 // (a 2x2 matrix + an offset)
7849 // Here we must not transform the position of the surface
7850 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007851 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007853 tmpMatrix.getValues(tmpFloats);
7854 mDsDx = tmpFloats[Matrix.MSCALE_X];
7855 mDtDx = tmpFloats[Matrix.MSKEW_X];
7856 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7857 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007858 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7859 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007860 int w = frame.width();
7861 int h = frame.height();
7862 mShownFrame.set(x, y, x+w, y+h);
7863
7864 // Now set the alpha... but because our current hardware
7865 // can't do alpha transformation on a non-opaque surface,
7866 // turn it off if we are running an animation that is also
7867 // transforming since it is more important to have that
7868 // animation be smooth.
7869 mShownAlpha = mAlpha;
7870 if (!mLimitedAlphaCompositing
7871 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7872 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7873 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007874 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007875 if (selfTransformation) {
7876 mShownAlpha *= mTransformation.getAlpha();
7877 }
7878 if (attachedTransformation != null) {
7879 mShownAlpha *= attachedTransformation.getAlpha();
7880 }
7881 if (appTransformation != null) {
7882 mShownAlpha *= appTransformation.getAlpha();
7883 }
7884 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007885 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007886 }
Romain Guy06882f82009-06-10 13:36:04 -07007887
Joe Onorato8a9b2202010-02-26 18:56:32 -08007888 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007889 TAG, "Continuing animation in " + this +
7890 ": " + mShownFrame +
7891 ", alpha=" + mTransformation.getAlpha());
7892 return;
7893 }
Romain Guy06882f82009-06-10 13:36:04 -07007894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007895 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007896 if (mXOffset != 0 || mYOffset != 0) {
7897 mShownFrame.offset(mXOffset, mYOffset);
7898 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007899 mShownAlpha = mAlpha;
7900 mDsDx = 1;
7901 mDtDx = 0;
7902 mDsDy = 0;
7903 mDtDy = 1;
7904 }
Romain Guy06882f82009-06-10 13:36:04 -07007905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007906 /**
7907 * Is this window visible? It is not visible if there is no
7908 * surface, or we are in the process of running an exit animation
7909 * that will remove the surface, or its app token has been hidden.
7910 */
7911 public boolean isVisibleLw() {
7912 final AppWindowToken atoken = mAppToken;
7913 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7914 && (atoken == null || !atoken.hiddenRequested)
7915 && !mExiting && !mDestroying;
7916 }
7917
7918 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007919 * Like {@link #isVisibleLw}, but also counts a window that is currently
7920 * "hidden" behind the keyguard as visible. This allows us to apply
7921 * things like window flags that impact the keyguard.
7922 * XXX I am starting to think we need to have ANOTHER visibility flag
7923 * for this "hidden behind keyguard" state rather than overloading
7924 * mPolicyVisibility. Ungh.
7925 */
7926 public boolean isVisibleOrBehindKeyguardLw() {
7927 final AppWindowToken atoken = mAppToken;
7928 return mSurface != null && !mAttachedHidden
7929 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackborn5943c202010-04-12 21:36:49 -07007930 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending))
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007931 && !mExiting && !mDestroying;
7932 }
7933
7934 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007935 * Is this window visible, ignoring its app token? It is not visible
7936 * if there is no surface, or we are in the process of running an exit animation
7937 * that will remove the surface.
7938 */
7939 public boolean isWinVisibleLw() {
7940 final AppWindowToken atoken = mAppToken;
7941 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7942 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7943 && !mExiting && !mDestroying;
7944 }
7945
7946 /**
7947 * The same as isVisible(), but follows the current hidden state of
7948 * the associated app token, not the pending requested hidden state.
7949 */
7950 boolean isVisibleNow() {
7951 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007952 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007953 }
7954
7955 /**
7956 * Same as isVisible(), but we also count it as visible between the
7957 * call to IWindowSession.add() and the first relayout().
7958 */
7959 boolean isVisibleOrAdding() {
7960 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007961 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007962 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7963 && mPolicyVisibility && !mAttachedHidden
7964 && (atoken == null || !atoken.hiddenRequested)
7965 && !mExiting && !mDestroying;
7966 }
7967
7968 /**
7969 * Is this window currently on-screen? It is on-screen either if it
7970 * is visible or it is currently running an animation before no longer
7971 * being visible.
7972 */
7973 boolean isOnScreen() {
7974 final AppWindowToken atoken = mAppToken;
7975 if (atoken != null) {
7976 return mSurface != null && mPolicyVisibility && !mDestroying
7977 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007978 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007979 } else {
7980 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007981 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007982 }
7983 }
Romain Guy06882f82009-06-10 13:36:04 -07007984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007985 /**
7986 * Like isOnScreen(), but we don't return true if the window is part
7987 * of a transition that has not yet been started.
7988 */
7989 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007990 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007991 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007992 return false;
7993 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007994 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007995 final boolean animating = atoken != null
7996 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007997 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007998 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7999 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008000 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008001 }
8002
8003 /** Is the window or its container currently animating? */
8004 boolean isAnimating() {
8005 final WindowState attached = mAttachedWindow;
8006 final AppWindowToken atoken = mAppToken;
8007 return mAnimation != null
8008 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07008009 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008010 (atoken.animation != null
8011 || atoken.inPendingTransaction));
8012 }
8013
8014 /** Is this window currently animating? */
8015 boolean isWindowAnimating() {
8016 return mAnimation != null;
8017 }
8018
8019 /**
8020 * Like isOnScreen, but returns false if the surface hasn't yet
8021 * been drawn.
8022 */
8023 public boolean isDisplayedLw() {
8024 final AppWindowToken atoken = mAppToken;
8025 return mSurface != null && mPolicyVisibility && !mDestroying
8026 && !mDrawPending && !mCommitDrawPending
8027 && ((!mAttachedHidden &&
8028 (atoken == null || !atoken.hiddenRequested))
8029 || mAnimating);
8030 }
8031
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008032 /**
8033 * Returns true if the window has a surface that it has drawn a
Dianne Hackborn5943c202010-04-12 21:36:49 -07008034 * complete UI in to. Note that this returns true if the orientation
8035 * is changing even if the window hasn't redrawn because we don't want
8036 * to stop things from executing during that time.
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008037 */
8038 public boolean isDrawnLw() {
8039 final AppWindowToken atoken = mAppToken;
8040 return mSurface != null && !mDestroying
Dianne Hackborn5943c202010-04-12 21:36:49 -07008041 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending));
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008042 }
8043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008044 public boolean fillsScreenLw(int screenWidth, int screenHeight,
8045 boolean shownFrame, boolean onlyOpaque) {
8046 if (mSurface == null) {
8047 return false;
8048 }
8049 if (mAppToken != null && !mAppToken.appFullscreen) {
8050 return false;
8051 }
8052 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
8053 return false;
8054 }
8055 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008056
8057 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
8058 return frame.left <= mCompatibleScreenFrame.left &&
8059 frame.top <= mCompatibleScreenFrame.top &&
8060 frame.right >= mCompatibleScreenFrame.right &&
8061 frame.bottom >= mCompatibleScreenFrame.bottom;
8062 } else {
8063 return frame.left <= 0 && frame.top <= 0
8064 && frame.right >= screenWidth
8065 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008066 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008067 }
Romain Guy06882f82009-06-10 13:36:04 -07008068
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008069 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07008070 * Return true if the window is opaque and fully drawn. This indicates
8071 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008072 */
8073 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07008074 return (mAttrs.format == PixelFormat.OPAQUE
8075 || mAttrs.type == TYPE_WALLPAPER)
8076 && mSurface != null && mAnimation == null
8077 && (mAppToken == null || mAppToken.animation == null)
8078 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008079 }
8080
8081 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
8082 return
8083 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008084 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
8085 // only if it's visible
8086 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008087 // and only if the application fills the compatible screen
8088 mFrame.left <= mCompatibleScreenFrame.left &&
8089 mFrame.top <= mCompatibleScreenFrame.top &&
8090 mFrame.right >= mCompatibleScreenFrame.right &&
8091 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008092 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008093 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008094 }
8095
8096 boolean isFullscreen(int screenWidth, int screenHeight) {
8097 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008098 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008099 }
8100
8101 void removeLocked() {
8102 if (mAttachedWindow != null) {
8103 mAttachedWindow.mChildWindows.remove(this);
8104 }
8105 destroySurfaceLocked();
8106 mSession.windowRemovedLocked();
8107 try {
8108 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
8109 } catch (RuntimeException e) {
8110 // Ignore if it has already been removed (usually because
8111 // we are doing this as part of processing a death note.)
8112 }
8113 }
8114
8115 private class DeathRecipient implements IBinder.DeathRecipient {
8116 public void binderDied() {
8117 try {
8118 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008119 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008120 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008121 if (win != null) {
8122 removeWindowLocked(mSession, win);
8123 }
8124 }
8125 } catch (IllegalArgumentException ex) {
8126 // This will happen if the window has already been
8127 // removed.
8128 }
8129 }
8130 }
8131
8132 /** Returns true if this window desires key events. */
8133 public final boolean canReceiveKeys() {
8134 return isVisibleOrAdding()
8135 && (mViewVisibility == View.VISIBLE)
8136 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8137 }
8138
8139 public boolean hasDrawnLw() {
8140 return mHasDrawn;
8141 }
8142
8143 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008144 return showLw(doAnimation, true);
8145 }
8146
8147 boolean showLw(boolean doAnimation, boolean requestAnim) {
8148 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8149 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008150 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008151 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008152 if (doAnimation) {
8153 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8154 + mPolicyVisibility + " mAnimation=" + mAnimation);
8155 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8156 doAnimation = false;
8157 } else if (mPolicyVisibility && mAnimation == null) {
8158 // Check for the case where we are currently visible and
8159 // not animating; we do not want to do animation at such a
8160 // point to become visible when we already are.
8161 doAnimation = false;
8162 }
8163 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008164 mPolicyVisibility = true;
8165 mPolicyVisibilityAfterAnim = true;
8166 if (doAnimation) {
8167 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8168 }
8169 if (requestAnim) {
8170 requestAnimationLocked(0);
8171 }
8172 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008173 }
8174
8175 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008176 return hideLw(doAnimation, true);
8177 }
8178
8179 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008180 if (doAnimation) {
8181 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8182 doAnimation = false;
8183 }
8184 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008185 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8186 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008187 if (!current) {
8188 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008189 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008190 if (doAnimation) {
8191 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8192 if (mAnimation == null) {
8193 doAnimation = false;
8194 }
8195 }
8196 if (doAnimation) {
8197 mPolicyVisibilityAfterAnim = false;
8198 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008199 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008200 mPolicyVisibilityAfterAnim = false;
8201 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008202 // Window is no longer visible -- make sure if we were waiting
8203 // for it to be displayed before enabling the display, that
8204 // we allow the display to be enabled now.
8205 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008206 if (mCurrentFocus == this) {
8207 mFocusMayChange = true;
8208 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008209 }
8210 if (requestAnim) {
8211 requestAnimationLocked(0);
8212 }
8213 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008214 }
8215
8216 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008217 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8218 pw.print(" mClient="); pw.println(mClient.asBinder());
8219 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8220 if (mAttachedWindow != null || mLayoutAttached) {
8221 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8222 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8223 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008224 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8225 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8226 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008227 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8228 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008229 }
8230 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8231 pw.print(" mSubLayer="); pw.print(mSubLayer);
8232 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8233 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8234 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8235 pw.print("="); pw.print(mAnimLayer);
8236 pw.print(" mLastLayer="); pw.println(mLastLayer);
8237 if (mSurface != null) {
8238 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008239 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8240 pw.print(" layer="); pw.print(mSurfaceLayer);
8241 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8242 pw.print(" rect=("); pw.print(mSurfaceX);
8243 pw.print(","); pw.print(mSurfaceY);
8244 pw.print(") "); pw.print(mSurfaceW);
8245 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008246 }
8247 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8248 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8249 if (mAppToken != null) {
8250 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8251 }
8252 if (mTargetAppToken != null) {
8253 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8254 }
8255 pw.print(prefix); pw.print("mViewVisibility=0x");
8256 pw.print(Integer.toHexString(mViewVisibility));
8257 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008258 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8259 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008260 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8261 pw.print(prefix); pw.print("mPolicyVisibility=");
8262 pw.print(mPolicyVisibility);
8263 pw.print(" mPolicyVisibilityAfterAnim=");
8264 pw.print(mPolicyVisibilityAfterAnim);
8265 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8266 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008267 if (!mRelayoutCalled) {
8268 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8269 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008270 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008271 pw.print(" h="); pw.print(mRequestedHeight);
8272 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008273 if (mXOffset != 0 || mYOffset != 0) {
8274 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8275 pw.print(" y="); pw.println(mYOffset);
8276 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008277 pw.print(prefix); pw.print("mGivenContentInsets=");
8278 mGivenContentInsets.printShortString(pw);
8279 pw.print(" mGivenVisibleInsets=");
8280 mGivenVisibleInsets.printShortString(pw);
8281 pw.println();
8282 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8283 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8284 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8285 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008286 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008287 pw.print(prefix); pw.print("mShownFrame=");
8288 mShownFrame.printShortString(pw);
8289 pw.print(" last="); mLastShownFrame.printShortString(pw);
8290 pw.println();
8291 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8292 pw.print(" last="); mLastFrame.printShortString(pw);
8293 pw.println();
8294 pw.print(prefix); pw.print("mContainingFrame=");
8295 mContainingFrame.printShortString(pw);
8296 pw.print(" mDisplayFrame=");
8297 mDisplayFrame.printShortString(pw);
8298 pw.println();
8299 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8300 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8301 pw.println();
8302 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8303 pw.print(" last="); mLastContentInsets.printShortString(pw);
8304 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8305 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8306 pw.println();
8307 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8308 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8309 pw.print(" mAlpha="); pw.print(mAlpha);
8310 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8311 }
8312 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8313 || mAnimation != null) {
8314 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8315 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8316 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8317 pw.print(" mAnimation="); pw.println(mAnimation);
8318 }
8319 if (mHasTransformation || mHasLocalTransformation) {
8320 pw.print(prefix); pw.print("XForm: has=");
8321 pw.print(mHasTransformation);
8322 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8323 pw.print(" "); mTransformation.printShortString(pw);
8324 pw.println();
8325 }
8326 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8327 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8328 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8329 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8330 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8331 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8332 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8333 pw.print(" mDestroying="); pw.print(mDestroying);
8334 pw.print(" mRemoved="); pw.println(mRemoved);
8335 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008336 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008337 pw.print(prefix); pw.print("mOrientationChanging=");
8338 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008339 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8340 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008341 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008342 if (mHScale != 1 || mVScale != 1) {
8343 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8344 pw.print(" mVScale="); pw.println(mVScale);
8345 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008346 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008347 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8348 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8349 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008350 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8351 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8352 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8353 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008354 }
8355
8356 @Override
8357 public String toString() {
8358 return "Window{"
8359 + Integer.toHexString(System.identityHashCode(this))
8360 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
8361 }
8362 }
Romain Guy06882f82009-06-10 13:36:04 -07008363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008364 // -------------------------------------------------------------
8365 // Window Token State
8366 // -------------------------------------------------------------
8367
8368 class WindowToken {
8369 // The actual token.
8370 final IBinder token;
8371
8372 // The type of window this token is for, as per WindowManager.LayoutParams.
8373 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008375 // Set if this token was explicitly added by a client, so should
8376 // not be removed when all windows are removed.
8377 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008378
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008379 // For printing.
8380 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008382 // If this is an AppWindowToken, this is non-null.
8383 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008385 // All of the windows associated with this token.
8386 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8387
8388 // Is key dispatching paused for this token?
8389 boolean paused = false;
8390
8391 // Should this token's windows be hidden?
8392 boolean hidden;
8393
8394 // Temporary for finding which tokens no longer have visible windows.
8395 boolean hasVisible;
8396
Dianne Hackborna8f60182009-09-01 19:01:50 -07008397 // Set to true when this token is in a pending transaction where it
8398 // will be shown.
8399 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008400
Dianne Hackborna8f60182009-09-01 19:01:50 -07008401 // Set to true when this token is in a pending transaction where it
8402 // will be hidden.
8403 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008404
Dianne Hackborna8f60182009-09-01 19:01:50 -07008405 // Set to true when this token is in a pending transaction where its
8406 // windows will be put to the bottom of the list.
8407 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008408
Dianne Hackborna8f60182009-09-01 19:01:50 -07008409 // Set to true when this token is in a pending transaction where its
8410 // windows will be put to the top of the list.
8411 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008413 WindowToken(IBinder _token, int type, boolean _explicit) {
8414 token = _token;
8415 windowType = type;
8416 explicit = _explicit;
8417 }
8418
8419 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008420 pw.print(prefix); pw.print("token="); pw.println(token);
8421 pw.print(prefix); pw.print("windows="); pw.println(windows);
8422 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8423 pw.print(" hidden="); pw.print(hidden);
8424 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008425 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8426 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8427 pw.print(" waitingToHide="); pw.print(waitingToHide);
8428 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8429 pw.print(" sendingToTop="); pw.println(sendingToTop);
8430 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008431 }
8432
8433 @Override
8434 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008435 if (stringName == null) {
8436 StringBuilder sb = new StringBuilder();
8437 sb.append("WindowToken{");
8438 sb.append(Integer.toHexString(System.identityHashCode(this)));
8439 sb.append(" token="); sb.append(token); sb.append('}');
8440 stringName = sb.toString();
8441 }
8442 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008443 }
8444 };
8445
8446 class AppWindowToken extends WindowToken {
8447 // Non-null only for application tokens.
8448 final IApplicationToken appToken;
8449
8450 // All of the windows and child windows that are included in this
8451 // application token. Note this list is NOT sorted!
8452 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8453
8454 int groupId = -1;
8455 boolean appFullscreen;
8456 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Romain Guy06882f82009-06-10 13:36:04 -07008457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008458 // These are used for determining when all windows associated with
8459 // an activity have been drawn, so they can be made visible together
8460 // at the same time.
8461 int lastTransactionSequence = mTransactionSequence-1;
8462 int numInterestingWindows;
8463 int numDrawnWindows;
8464 boolean inPendingTransaction;
8465 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008467 // Is this token going to be hidden in a little while? If so, it
8468 // won't be taken into account for setting the screen orientation.
8469 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008471 // Is this window's surface needed? This is almost like hidden, except
8472 // it will sometimes be true a little earlier: when the token has
8473 // been shown, but is still waiting for its app transition to execute
8474 // before making its windows shown.
8475 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008477 // Have we told the window clients to hide themselves?
8478 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008480 // Last visibility state we reported to the app token.
8481 boolean reportedVisible;
8482
8483 // Set to true when the token has been removed from the window mgr.
8484 boolean removed;
8485
8486 // Have we been asked to have this token keep the screen frozen?
8487 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008489 boolean animating;
8490 Animation animation;
8491 boolean hasTransformation;
8492 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008494 // Offset to the window of all layers in the token, for use by
8495 // AppWindowToken animations.
8496 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008498 // Information about an application starting window if displayed.
8499 StartingData startingData;
8500 WindowState startingWindow;
8501 View startingView;
8502 boolean startingDisplayed;
8503 boolean startingMoved;
8504 boolean firstWindowDrawn;
8505
8506 AppWindowToken(IApplicationToken _token) {
8507 super(_token.asBinder(),
8508 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8509 appWindowToken = this;
8510 appToken = _token;
8511 }
Romain Guy06882f82009-06-10 13:36:04 -07008512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008513 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008514 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008515 TAG, "Setting animation in " + this + ": " + anim);
8516 animation = anim;
8517 animating = false;
8518 anim.restrictDuration(MAX_ANIMATION_DURATION);
8519 anim.scaleCurrentDuration(mTransitionAnimationScale);
8520 int zorder = anim.getZAdjustment();
8521 int adj = 0;
8522 if (zorder == Animation.ZORDER_TOP) {
8523 adj = TYPE_LAYER_OFFSET;
8524 } else if (zorder == Animation.ZORDER_BOTTOM) {
8525 adj = -TYPE_LAYER_OFFSET;
8526 }
Romain Guy06882f82009-06-10 13:36:04 -07008527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008528 if (animLayerAdjustment != adj) {
8529 animLayerAdjustment = adj;
8530 updateLayers();
8531 }
8532 }
Romain Guy06882f82009-06-10 13:36:04 -07008533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008534 public void setDummyAnimation() {
8535 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008536 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008537 TAG, "Setting dummy animation in " + this);
8538 animation = sDummyAnimation;
8539 }
8540 }
8541
8542 public void clearAnimation() {
8543 if (animation != null) {
8544 animation = null;
8545 animating = true;
8546 }
8547 }
Romain Guy06882f82009-06-10 13:36:04 -07008548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008549 void updateLayers() {
8550 final int N = allAppWindows.size();
8551 final int adj = animLayerAdjustment;
8552 for (int i=0; i<N; i++) {
8553 WindowState w = allAppWindows.get(i);
8554 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008555 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008556 + w.mAnimLayer);
8557 if (w == mInputMethodTarget) {
8558 setInputMethodAnimLayerAdjustment(adj);
8559 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008560 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008561 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008562 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008563 }
8564 }
Romain Guy06882f82009-06-10 13:36:04 -07008565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008566 void sendAppVisibilityToClients() {
8567 final int N = allAppWindows.size();
8568 for (int i=0; i<N; i++) {
8569 WindowState win = allAppWindows.get(i);
8570 if (win == startingWindow && clientHidden) {
8571 // Don't hide the starting window.
8572 continue;
8573 }
8574 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008575 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008576 "Setting visibility of " + win + ": " + (!clientHidden));
8577 win.mClient.dispatchAppVisibility(!clientHidden);
8578 } catch (RemoteException e) {
8579 }
8580 }
8581 }
Romain Guy06882f82009-06-10 13:36:04 -07008582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008583 void showAllWindowsLocked() {
8584 final int NW = allAppWindows.size();
8585 for (int i=0; i<NW; i++) {
8586 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008587 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008588 "performing show on: " + w);
8589 w.performShowLocked();
8590 }
8591 }
Romain Guy06882f82009-06-10 13:36:04 -07008592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008593 // This must be called while inside a transaction.
8594 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008595 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008596 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008598 if (animation == sDummyAnimation) {
8599 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008600 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008601 // when it is really time to animate, this will be set to
8602 // a real animation and the next call will execute normally.
8603 return false;
8604 }
Romain Guy06882f82009-06-10 13:36:04 -07008605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008606 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8607 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008608 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008609 TAG, "Starting animation in " + this +
8610 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8611 + " scale=" + mTransitionAnimationScale
8612 + " allDrawn=" + allDrawn + " animating=" + animating);
8613 animation.initialize(dw, dh, dw, dh);
8614 animation.setStartTime(currentTime);
8615 animating = true;
8616 }
8617 transformation.clear();
8618 final boolean more = animation.getTransformation(
8619 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008620 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008621 TAG, "Stepped animation in " + this +
8622 ": more=" + more + ", xform=" + transformation);
8623 if (more) {
8624 // we're done!
8625 hasTransformation = true;
8626 return true;
8627 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008628 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008629 TAG, "Finished animation in " + this +
8630 " @ " + currentTime);
8631 animation = null;
8632 }
8633 } else if (animation != null) {
8634 // If the display is frozen, and there is a pending animation,
8635 // clear it and make sure we run the cleanup code.
8636 animating = true;
8637 animation = null;
8638 }
8639
8640 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008642 if (!animating) {
8643 return false;
8644 }
8645
8646 clearAnimation();
8647 animating = false;
8648 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8649 moveInputMethodWindowsIfNeededLocked(true);
8650 }
Romain Guy06882f82009-06-10 13:36:04 -07008651
Joe Onorato8a9b2202010-02-26 18:56:32 -08008652 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008653 TAG, "Animation done in " + this
8654 + ": reportedVisible=" + reportedVisible);
8655
8656 transformation.clear();
8657 if (animLayerAdjustment != 0) {
8658 animLayerAdjustment = 0;
8659 updateLayers();
8660 }
Romain Guy06882f82009-06-10 13:36:04 -07008661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008662 final int N = windows.size();
8663 for (int i=0; i<N; i++) {
8664 ((WindowState)windows.get(i)).finishExit();
8665 }
8666 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008668 return false;
8669 }
8670
8671 void updateReportedVisibilityLocked() {
8672 if (appToken == null) {
8673 return;
8674 }
Romain Guy06882f82009-06-10 13:36:04 -07008675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008676 int numInteresting = 0;
8677 int numVisible = 0;
8678 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008679
Joe Onorato8a9b2202010-02-26 18:56:32 -08008680 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008681 final int N = allAppWindows.size();
8682 for (int i=0; i<N; i++) {
8683 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008684 if (win == startingWindow || win.mAppFreezing
8685 || win.mViewVisibility != View.VISIBLE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008686 continue;
8687 }
8688 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008689 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008690 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008691 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008692 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008693 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008694 + " pv=" + win.mPolicyVisibility
8695 + " dp=" + win.mDrawPending
8696 + " cdp=" + win.mCommitDrawPending
8697 + " ah=" + win.mAttachedHidden
8698 + " th="
8699 + (win.mAppToken != null
8700 ? win.mAppToken.hiddenRequested : false)
8701 + " a=" + win.mAnimating);
8702 }
8703 }
8704 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008705 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008706 if (!win.isAnimating()) {
8707 numVisible++;
8708 }
8709 nowGone = false;
8710 } else if (win.isAnimating()) {
8711 nowGone = false;
8712 }
8713 }
Romain Guy06882f82009-06-10 13:36:04 -07008714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008715 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008716 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008717 + numInteresting + " visible=" + numVisible);
8718 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008719 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008720 TAG, "Visibility changed in " + this
8721 + ": vis=" + nowVisible);
8722 reportedVisible = nowVisible;
8723 Message m = mH.obtainMessage(
8724 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8725 nowVisible ? 1 : 0,
8726 nowGone ? 1 : 0,
8727 this);
8728 mH.sendMessage(m);
8729 }
8730 }
Romain Guy06882f82009-06-10 13:36:04 -07008731
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008732 WindowState findMainWindow() {
8733 int j = windows.size();
8734 while (j > 0) {
8735 j--;
8736 WindowState win = windows.get(j);
8737 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8738 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8739 return win;
8740 }
8741 }
8742 return null;
8743 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008745 void dump(PrintWriter pw, String prefix) {
8746 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008747 if (appToken != null) {
8748 pw.print(prefix); pw.println("app=true");
8749 }
8750 if (allAppWindows.size() > 0) {
8751 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8752 }
8753 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008754 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008755 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8756 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8757 pw.print(" clientHidden="); pw.print(clientHidden);
8758 pw.print(" willBeHidden="); pw.print(willBeHidden);
8759 pw.print(" reportedVisible="); pw.println(reportedVisible);
8760 if (paused || freezingScreen) {
8761 pw.print(prefix); pw.print("paused="); pw.print(paused);
8762 pw.print(" freezingScreen="); pw.println(freezingScreen);
8763 }
8764 if (numInterestingWindows != 0 || numDrawnWindows != 0
8765 || inPendingTransaction || allDrawn) {
8766 pw.print(prefix); pw.print("numInterestingWindows=");
8767 pw.print(numInterestingWindows);
8768 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8769 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8770 pw.print(" allDrawn="); pw.println(allDrawn);
8771 }
8772 if (animating || animation != null) {
8773 pw.print(prefix); pw.print("animating="); pw.print(animating);
8774 pw.print(" animation="); pw.println(animation);
8775 }
8776 if (animLayerAdjustment != 0) {
8777 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8778 }
8779 if (hasTransformation) {
8780 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8781 pw.print(" transformation="); transformation.printShortString(pw);
8782 pw.println();
8783 }
8784 if (startingData != null || removed || firstWindowDrawn) {
8785 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8786 pw.print(" removed="); pw.print(removed);
8787 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8788 }
8789 if (startingWindow != null || startingView != null
8790 || startingDisplayed || startingMoved) {
8791 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8792 pw.print(" startingView="); pw.print(startingView);
8793 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8794 pw.print(" startingMoved"); pw.println(startingMoved);
8795 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008796 }
8797
8798 @Override
8799 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008800 if (stringName == null) {
8801 StringBuilder sb = new StringBuilder();
8802 sb.append("AppWindowToken{");
8803 sb.append(Integer.toHexString(System.identityHashCode(this)));
8804 sb.append(" token="); sb.append(token); sb.append('}');
8805 stringName = sb.toString();
8806 }
8807 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008808 }
8809 }
Romain Guy06882f82009-06-10 13:36:04 -07008810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008811 // -------------------------------------------------------------
8812 // DummyAnimation
8813 // -------------------------------------------------------------
8814
8815 // This is an animation that does nothing: it just immediately finishes
8816 // itself every time it is called. It is used as a stub animation in cases
8817 // where we want to synchronize multiple things that may be animating.
8818 static final class DummyAnimation extends Animation {
8819 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8820 return false;
8821 }
8822 }
8823 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008825 // -------------------------------------------------------------
8826 // Async Handler
8827 // -------------------------------------------------------------
8828
8829 static final class StartingData {
8830 final String pkg;
8831 final int theme;
8832 final CharSequence nonLocalizedLabel;
8833 final int labelRes;
8834 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008836 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8837 int _labelRes, int _icon) {
8838 pkg = _pkg;
8839 theme = _theme;
8840 nonLocalizedLabel = _nonLocalizedLabel;
8841 labelRes = _labelRes;
8842 icon = _icon;
8843 }
8844 }
8845
8846 private final class H extends Handler {
8847 public static final int REPORT_FOCUS_CHANGE = 2;
8848 public static final int REPORT_LOSING_FOCUS = 3;
8849 public static final int ANIMATE = 4;
8850 public static final int ADD_STARTING = 5;
8851 public static final int REMOVE_STARTING = 6;
8852 public static final int FINISHED_STARTING = 7;
8853 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008854 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8855 public static final int HOLD_SCREEN_CHANGED = 12;
8856 public static final int APP_TRANSITION_TIMEOUT = 13;
8857 public static final int PERSIST_ANIMATION_SCALE = 14;
8858 public static final int FORCE_GC = 15;
8859 public static final int ENABLE_SCREEN = 16;
8860 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008861 public static final int SEND_NEW_CONFIGURATION = 18;
Romain Guy06882f82009-06-10 13:36:04 -07008862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008863 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008865 public H() {
8866 }
Romain Guy06882f82009-06-10 13:36:04 -07008867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008868 @Override
8869 public void handleMessage(Message msg) {
8870 switch (msg.what) {
8871 case REPORT_FOCUS_CHANGE: {
8872 WindowState lastFocus;
8873 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008875 synchronized(mWindowMap) {
8876 lastFocus = mLastFocus;
8877 newFocus = mCurrentFocus;
8878 if (lastFocus == newFocus) {
8879 // Focus is not changing, so nothing to do.
8880 return;
8881 }
8882 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008883 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008884 // + " to " + newFocus);
8885 if (newFocus != null && lastFocus != null
8886 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008887 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008888 mLosingFocus.add(lastFocus);
8889 lastFocus = null;
8890 }
8891 }
8892
8893 if (lastFocus != newFocus) {
8894 //System.out.println("Changing focus from " + lastFocus
8895 // + " to " + newFocus);
8896 if (newFocus != null) {
8897 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008898 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008899 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8900 } catch (RemoteException e) {
8901 // Ignore if process has died.
8902 }
8903 }
8904
8905 if (lastFocus != null) {
8906 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008907 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008908 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8909 } catch (RemoteException e) {
8910 // Ignore if process has died.
8911 }
8912 }
8913 }
8914 } break;
8915
8916 case REPORT_LOSING_FOCUS: {
8917 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008919 synchronized(mWindowMap) {
8920 losers = mLosingFocus;
8921 mLosingFocus = new ArrayList<WindowState>();
8922 }
8923
8924 final int N = losers.size();
8925 for (int i=0; i<N; i++) {
8926 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008927 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008928 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8929 } catch (RemoteException e) {
8930 // Ignore if process has died.
8931 }
8932 }
8933 } break;
8934
8935 case ANIMATE: {
8936 synchronized(mWindowMap) {
8937 mAnimationPending = false;
8938 performLayoutAndPlaceSurfacesLocked();
8939 }
8940 } break;
8941
8942 case ADD_STARTING: {
8943 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8944 final StartingData sd = wtoken.startingData;
8945
8946 if (sd == null) {
8947 // Animation has been canceled... do nothing.
8948 return;
8949 }
Romain Guy06882f82009-06-10 13:36:04 -07008950
Joe Onorato8a9b2202010-02-26 18:56:32 -08008951 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008952 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008954 View view = null;
8955 try {
8956 view = mPolicy.addStartingWindow(
8957 wtoken.token, sd.pkg,
8958 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8959 sd.icon);
8960 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008961 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008962 }
8963
8964 if (view != null) {
8965 boolean abort = false;
8966
8967 synchronized(mWindowMap) {
8968 if (wtoken.removed || wtoken.startingData == null) {
8969 // If the window was successfully added, then
8970 // we need to remove it.
8971 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008972 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008973 "Aborted starting " + wtoken
8974 + ": removed=" + wtoken.removed
8975 + " startingData=" + wtoken.startingData);
8976 wtoken.startingWindow = null;
8977 wtoken.startingData = null;
8978 abort = true;
8979 }
8980 } else {
8981 wtoken.startingView = view;
8982 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008983 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008984 "Added starting " + wtoken
8985 + ": startingWindow="
8986 + wtoken.startingWindow + " startingView="
8987 + wtoken.startingView);
8988 }
8989
8990 if (abort) {
8991 try {
8992 mPolicy.removeStartingWindow(wtoken.token, view);
8993 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008994 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008995 }
8996 }
8997 }
8998 } break;
8999
9000 case REMOVE_STARTING: {
9001 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9002 IBinder token = null;
9003 View view = null;
9004 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009005 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009006 + wtoken + ": startingWindow="
9007 + wtoken.startingWindow + " startingView="
9008 + wtoken.startingView);
9009 if (wtoken.startingWindow != null) {
9010 view = wtoken.startingView;
9011 token = wtoken.token;
9012 wtoken.startingData = null;
9013 wtoken.startingView = null;
9014 wtoken.startingWindow = null;
9015 }
9016 }
9017 if (view != null) {
9018 try {
9019 mPolicy.removeStartingWindow(token, view);
9020 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009021 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009022 }
9023 }
9024 } break;
9025
9026 case FINISHED_STARTING: {
9027 IBinder token = null;
9028 View view = null;
9029 while (true) {
9030 synchronized (mWindowMap) {
9031 final int N = mFinishedStarting.size();
9032 if (N <= 0) {
9033 break;
9034 }
9035 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
9036
Joe Onorato8a9b2202010-02-26 18:56:32 -08009037 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009038 "Finished starting " + wtoken
9039 + ": startingWindow=" + wtoken.startingWindow
9040 + " startingView=" + wtoken.startingView);
9041
9042 if (wtoken.startingWindow == null) {
9043 continue;
9044 }
9045
9046 view = wtoken.startingView;
9047 token = wtoken.token;
9048 wtoken.startingData = null;
9049 wtoken.startingView = null;
9050 wtoken.startingWindow = null;
9051 }
9052
9053 try {
9054 mPolicy.removeStartingWindow(token, view);
9055 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009056 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009057 }
9058 }
9059 } break;
9060
9061 case REPORT_APPLICATION_TOKEN_WINDOWS: {
9062 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9063
9064 boolean nowVisible = msg.arg1 != 0;
9065 boolean nowGone = msg.arg2 != 0;
9066
9067 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009068 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009069 TAG, "Reporting visible in " + wtoken
9070 + " visible=" + nowVisible
9071 + " gone=" + nowGone);
9072 if (nowVisible) {
9073 wtoken.appToken.windowsVisible();
9074 } else {
9075 wtoken.appToken.windowsGone();
9076 }
9077 } catch (RemoteException ex) {
9078 }
9079 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009081 case WINDOW_FREEZE_TIMEOUT: {
9082 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009083 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009084 int i = mWindows.size();
9085 while (i > 0) {
9086 i--;
9087 WindowState w = (WindowState)mWindows.get(i);
9088 if (w.mOrientationChanging) {
9089 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009090 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009091 }
9092 }
9093 performLayoutAndPlaceSurfacesLocked();
9094 }
9095 break;
9096 }
Romain Guy06882f82009-06-10 13:36:04 -07009097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009098 case HOLD_SCREEN_CHANGED: {
9099 Session oldHold;
9100 Session newHold;
9101 synchronized (mWindowMap) {
9102 oldHold = mLastReportedHold;
9103 newHold = (Session)msg.obj;
9104 mLastReportedHold = newHold;
9105 }
Romain Guy06882f82009-06-10 13:36:04 -07009106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009107 if (oldHold != newHold) {
9108 try {
9109 if (oldHold != null) {
9110 mBatteryStats.noteStopWakelock(oldHold.mUid,
9111 "window",
9112 BatteryStats.WAKE_TYPE_WINDOW);
9113 }
9114 if (newHold != null) {
9115 mBatteryStats.noteStartWakelock(newHold.mUid,
9116 "window",
9117 BatteryStats.WAKE_TYPE_WINDOW);
9118 }
9119 } catch (RemoteException e) {
9120 }
9121 }
9122 break;
9123 }
Romain Guy06882f82009-06-10 13:36:04 -07009124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009125 case APP_TRANSITION_TIMEOUT: {
9126 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009127 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009128 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009129 "*** APP TRANSITION TIMEOUT");
9130 mAppTransitionReady = true;
9131 mAppTransitionTimeout = true;
9132 performLayoutAndPlaceSurfacesLocked();
9133 }
9134 }
9135 break;
9136 }
Romain Guy06882f82009-06-10 13:36:04 -07009137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009138 case PERSIST_ANIMATION_SCALE: {
9139 Settings.System.putFloat(mContext.getContentResolver(),
9140 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9141 Settings.System.putFloat(mContext.getContentResolver(),
9142 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9143 break;
9144 }
Romain Guy06882f82009-06-10 13:36:04 -07009145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009146 case FORCE_GC: {
9147 synchronized(mWindowMap) {
9148 if (mAnimationPending) {
9149 // If we are animating, don't do the gc now but
9150 // delay a bit so we don't interrupt the animation.
9151 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9152 2000);
9153 return;
9154 }
9155 // If we are currently rotating the display, it will
9156 // schedule a new message when done.
9157 if (mDisplayFrozen) {
9158 return;
9159 }
9160 mFreezeGcPending = 0;
9161 }
9162 Runtime.getRuntime().gc();
9163 break;
9164 }
Romain Guy06882f82009-06-10 13:36:04 -07009165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009166 case ENABLE_SCREEN: {
9167 performEnableScreen();
9168 break;
9169 }
Romain Guy06882f82009-06-10 13:36:04 -07009170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009171 case APP_FREEZE_TIMEOUT: {
9172 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009173 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009174 int i = mAppTokens.size();
9175 while (i > 0) {
9176 i--;
9177 AppWindowToken tok = mAppTokens.get(i);
9178 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009179 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009180 unsetAppFreezingScreenLocked(tok, true, true);
9181 }
9182 }
9183 }
9184 break;
9185 }
Romain Guy06882f82009-06-10 13:36:04 -07009186
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009187 case SEND_NEW_CONFIGURATION: {
9188 removeMessages(SEND_NEW_CONFIGURATION);
9189 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009190 break;
9191 }
Romain Guy06882f82009-06-10 13:36:04 -07009192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009193 }
9194 }
9195 }
9196
9197 // -------------------------------------------------------------
9198 // IWindowManager API
9199 // -------------------------------------------------------------
9200
9201 public IWindowSession openSession(IInputMethodClient client,
9202 IInputContext inputContext) {
9203 if (client == null) throw new IllegalArgumentException("null client");
9204 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
9205 return new Session(client, inputContext);
9206 }
9207
9208 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9209 synchronized (mWindowMap) {
9210 // The focus for the client is the window immediately below
9211 // where we would place the input method window.
9212 int idx = findDesiredInputMethodWindowIndexLocked(false);
9213 WindowState imFocus;
9214 if (idx > 0) {
9215 imFocus = (WindowState)mWindows.get(idx-1);
9216 if (imFocus != null) {
9217 if (imFocus.mSession.mClient != null &&
9218 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9219 return true;
9220 }
9221 }
9222 }
9223 }
9224 return false;
9225 }
Romain Guy06882f82009-06-10 13:36:04 -07009226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009227 // -------------------------------------------------------------
9228 // Internals
9229 // -------------------------------------------------------------
9230
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009231 final WindowState windowForClientLocked(Session session, IWindow client,
9232 boolean throwOnError) {
9233 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009234 }
Romain Guy06882f82009-06-10 13:36:04 -07009235
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009236 final WindowState windowForClientLocked(Session session, IBinder client,
9237 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009238 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009239 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009240 TAG, "Looking up client " + client + ": " + win);
9241 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009242 RuntimeException ex = new IllegalArgumentException(
9243 "Requested window " + client + " does not exist");
9244 if (throwOnError) {
9245 throw ex;
9246 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009247 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009248 return null;
9249 }
9250 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009251 RuntimeException ex = new IllegalArgumentException(
9252 "Requested window " + client + " is in session " +
9253 win.mSession + ", not " + session);
9254 if (throwOnError) {
9255 throw ex;
9256 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009257 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009258 return null;
9259 }
9260
9261 return win;
9262 }
9263
Dianne Hackborna8f60182009-09-01 19:01:50 -07009264 final void rebuildAppWindowListLocked() {
9265 int NW = mWindows.size();
9266 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009267 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009268 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009269
Dianne Hackborna8f60182009-09-01 19:01:50 -07009270 // First remove all existing app windows.
9271 i=0;
9272 while (i < NW) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009273 WindowState w = (WindowState)mWindows.get(i);
9274 if (w.mAppToken != null) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009275 WindowState win = (WindowState)mWindows.remove(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009276 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009277 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009278 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009279 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009280 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009281 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9282 && lastWallpaper == i-1) {
9283 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009284 }
9285 i++;
9286 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009287
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009288 // The wallpaper window(s) typically live at the bottom of the stack,
9289 // so skip them before adding app tokens.
9290 lastWallpaper++;
9291 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009292
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009293 // First add all of the exiting app tokens... these are no longer
9294 // in the main app list, but still have windows shown. We put them
9295 // in the back because now that the animation is over we no longer
9296 // will care about them.
9297 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009298 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009299 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9300 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009301
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009302 // And add in the still active app tokens in Z order.
9303 NT = mAppTokens.size();
9304 for (int j=0; j<NT; j++) {
9305 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009306 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009307
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009308 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009309 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009310 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009311 + " windows but added " + i);
9312 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009313 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009315 private final void assignLayersLocked() {
9316 int N = mWindows.size();
9317 int curBaseLayer = 0;
9318 int curLayer = 0;
9319 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009321 for (i=0; i<N; i++) {
9322 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009323 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9324 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009325 curLayer += WINDOW_LAYER_MULTIPLIER;
9326 w.mLayer = curLayer;
9327 } else {
9328 curBaseLayer = curLayer = w.mBaseLayer;
9329 w.mLayer = curLayer;
9330 }
9331 if (w.mTargetAppToken != null) {
9332 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9333 } else if (w.mAppToken != null) {
9334 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9335 } else {
9336 w.mAnimLayer = w.mLayer;
9337 }
9338 if (w.mIsImWindow) {
9339 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009340 } else if (w.mIsWallpaper) {
9341 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009342 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009343 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009344 + w.mAnimLayer);
9345 //System.out.println(
9346 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9347 }
9348 }
9349
9350 private boolean mInLayout = false;
9351 private final void performLayoutAndPlaceSurfacesLocked() {
9352 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009353 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009354 throw new RuntimeException("Recursive call!");
9355 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009356 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009357 return;
9358 }
9359
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009360 if (mWaitingForConfig) {
9361 // Our configuration has changed (most likely rotation), but we
9362 // don't yet have the complete configuration to report to
9363 // applications. Don't do any window layout until we have it.
9364 return;
9365 }
9366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009367 boolean recoveringMemory = false;
9368 if (mForceRemoves != null) {
9369 recoveringMemory = true;
9370 // Wait a little it for things to settle down, and off we go.
9371 for (int i=0; i<mForceRemoves.size(); i++) {
9372 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009373 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009374 removeWindowInnerLocked(ws.mSession, ws);
9375 }
9376 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009377 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009378 Object tmp = new Object();
9379 synchronized (tmp) {
9380 try {
9381 tmp.wait(250);
9382 } catch (InterruptedException e) {
9383 }
9384 }
9385 }
Romain Guy06882f82009-06-10 13:36:04 -07009386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009387 mInLayout = true;
9388 try {
9389 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009391 int i = mPendingRemove.size()-1;
9392 if (i >= 0) {
9393 while (i >= 0) {
9394 WindowState w = mPendingRemove.get(i);
9395 removeWindowInnerLocked(w.mSession, w);
9396 i--;
9397 }
9398 mPendingRemove.clear();
9399
9400 mInLayout = false;
9401 assignLayersLocked();
9402 mLayoutNeeded = true;
9403 performLayoutAndPlaceSurfacesLocked();
9404
9405 } else {
9406 mInLayout = false;
9407 if (mLayoutNeeded) {
9408 requestAnimationLocked(0);
9409 }
9410 }
9411 } catch (RuntimeException e) {
9412 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009413 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009414 }
9415 }
9416
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009417 private final int performLayoutLockedInner() {
9418 if (!mLayoutNeeded) {
9419 return 0;
9420 }
9421
9422 mLayoutNeeded = false;
9423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009424 final int dw = mDisplay.getWidth();
9425 final int dh = mDisplay.getHeight();
9426
9427 final int N = mWindows.size();
9428 int i;
9429
Joe Onorato8a9b2202010-02-26 18:56:32 -08009430 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009431 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9432
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009433 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009434
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009435 int seq = mLayoutSeq+1;
9436 if (seq < 0) seq = 0;
9437 mLayoutSeq = seq;
9438
9439 // First perform layout of any root windows (not attached
9440 // to another window).
9441 int topAttached = -1;
9442 for (i = N-1; i >= 0; i--) {
9443 WindowState win = (WindowState) mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009444
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009445 // Don't do layout of a window if it is not visible, or
9446 // soon won't be visible, to avoid wasting time and funky
9447 // changes while a window is animating away.
9448 final AppWindowToken atoken = win.mAppToken;
9449 final boolean gone = win.mViewVisibility == View.GONE
9450 || !win.mRelayoutCalled
9451 || win.mRootToken.hidden
9452 || (atoken != null && atoken.hiddenRequested)
9453 || win.mAttachedHidden
9454 || win.mExiting || win.mDestroying;
9455
9456 if (!win.mLayoutAttached) {
9457 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
9458 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9459 + " mLayoutAttached=" + win.mLayoutAttached);
9460 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
9461 + win.mViewVisibility + " mRelayoutCalled="
9462 + win.mRelayoutCalled + " hidden="
9463 + win.mRootToken.hidden + " hiddenRequested="
9464 + (atoken != null && atoken.hiddenRequested)
9465 + " mAttachedHidden=" + win.mAttachedHidden);
9466 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009467
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009468 // If this view is GONE, then skip it -- keep the current
9469 // frame, and let the caller know so they can ignore it
9470 // if they want. (We do the normal layout for INVISIBLE
9471 // windows, since that means "perform layout as normal,
9472 // just don't display").
9473 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009474 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009475 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9476 win.mLayoutSeq = seq;
9477 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9478 + win.mFrame + " mContainingFrame="
9479 + win.mContainingFrame + " mDisplayFrame="
9480 + win.mDisplayFrame);
9481 } else {
9482 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009483 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009484 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009485 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009486
9487 // Now perform layout of attached windows, which usually
9488 // depend on the position of the window they are attached to.
9489 // XXX does not deal with windows that are attached to windows
9490 // that are themselves attached.
9491 for (i = topAttached; i >= 0; i--) {
9492 WindowState win = (WindowState) mWindows.get(i);
9493
9494 // If this view is GONE, then skip it -- keep the current
9495 // frame, and let the caller know so they can ignore it
9496 // if they want. (We do the normal layout for INVISIBLE
9497 // windows, since that means "perform layout as normal,
9498 // just don't display").
9499 if (win.mLayoutAttached) {
9500 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9501 + " mHaveFrame=" + win.mHaveFrame
9502 + " mViewVisibility=" + win.mViewVisibility
9503 + " mRelayoutCalled=" + win.mRelayoutCalled);
9504 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9505 || !win.mHaveFrame) {
9506 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9507 win.mLayoutSeq = seq;
9508 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9509 + win.mFrame + " mContainingFrame="
9510 + win.mContainingFrame + " mDisplayFrame="
9511 + win.mDisplayFrame);
9512 }
9513 }
9514 }
9515
9516 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009517 }
Romain Guy06882f82009-06-10 13:36:04 -07009518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009519 private final void performLayoutAndPlaceSurfacesLockedInner(
9520 boolean recoveringMemory) {
9521 final long currentTime = SystemClock.uptimeMillis();
9522 final int dw = mDisplay.getWidth();
9523 final int dh = mDisplay.getHeight();
9524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009525 int i;
9526
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009527 if (mFocusMayChange) {
9528 mFocusMayChange = false;
9529 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9530 }
9531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009532 if (mFxSession == null) {
9533 mFxSession = new SurfaceSession();
9534 }
Romain Guy06882f82009-06-10 13:36:04 -07009535
Joe Onorato8a9b2202010-02-26 18:56:32 -08009536 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009537
9538 // Initialize state of exiting tokens.
9539 for (i=mExitingTokens.size()-1; i>=0; i--) {
9540 mExitingTokens.get(i).hasVisible = false;
9541 }
9542
9543 // Initialize state of exiting applications.
9544 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9545 mExitingAppTokens.get(i).hasVisible = false;
9546 }
9547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009548 boolean orientationChangeComplete = true;
9549 Session holdScreen = null;
9550 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009551 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009552 boolean focusDisplayed = false;
9553 boolean animating = false;
9554
9555 Surface.openTransaction();
9556 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009557 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009558 int repeats = 0;
9559 int changes = 0;
9560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009561 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009562 repeats++;
9563 if (repeats > 6) {
9564 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9565 mLayoutNeeded = false;
9566 break;
9567 }
9568
9569 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9570 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9571 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9572 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9573 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9574 assignLayersLocked();
9575 mLayoutNeeded = true;
9576 }
9577 }
9578 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9579 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9580 if (updateOrientationFromAppTokensLocked()) {
9581 mLayoutNeeded = true;
9582 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9583 }
9584 }
9585 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9586 mLayoutNeeded = true;
9587 }
9588 }
9589
9590 // FIRST LOOP: Perform a layout, if needed.
9591 if (repeats < 4) {
9592 changes = performLayoutLockedInner();
9593 if (changes != 0) {
9594 continue;
9595 }
9596 } else {
9597 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9598 changes = 0;
9599 }
9600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009601 final int transactionSequence = ++mTransactionSequence;
9602
9603 // Update animations of all applications, including those
9604 // associated with exiting/removed apps
9605 boolean tokensAnimating = false;
9606 final int NAT = mAppTokens.size();
9607 for (i=0; i<NAT; i++) {
9608 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9609 tokensAnimating = true;
9610 }
9611 }
9612 final int NEAT = mExitingAppTokens.size();
9613 for (i=0; i<NEAT; i++) {
9614 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9615 tokensAnimating = true;
9616 }
9617 }
9618
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009619 // SECOND LOOP: Execute animations and update visibility of windows.
9620
Joe Onorato8a9b2202010-02-26 18:56:32 -08009621 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009622 + transactionSequence + " tokensAnimating="
9623 + tokensAnimating);
9624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009625 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009626
9627 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009628 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009629 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009630
9631 mPolicy.beginAnimationLw(dw, dh);
9632
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009633 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009635 for (i=N-1; i>=0; i--) {
9636 WindowState w = (WindowState)mWindows.get(i);
9637
9638 final WindowManager.LayoutParams attrs = w.mAttrs;
9639
9640 if (w.mSurface != null) {
9641 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009642 if (w.commitFinishDrawingLocked(currentTime)) {
9643 if ((w.mAttrs.flags
9644 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009645 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009646 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009647 wallpaperMayChange = true;
9648 }
9649 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009650
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009651 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009652 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9653 animating = true;
9654 //w.dump(" ");
9655 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009656 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9657 wallpaperMayChange = true;
9658 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009659
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009660 if (mPolicy.doesForceHide(w, attrs)) {
9661 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009662 if (DEBUG_VISIBILITY) Slog.v(TAG,
9663 "Animation done that could impact force hide: "
9664 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009665 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009666 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009667 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9668 forceHiding = true;
9669 }
9670 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9671 boolean changed;
9672 if (forceHiding) {
9673 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009674 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9675 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009676 } else {
9677 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009678 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9679 "Now policy shown: " + w);
9680 if (changed) {
9681 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009682 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009683 // Assume we will need to animate. If
9684 // we don't (because the wallpaper will
9685 // stay with the lock screen), then we will
9686 // clean up later.
9687 Animation a = mPolicy.createForceHideEnterAnimation();
9688 if (a != null) {
9689 w.setAnimation(a);
9690 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009691 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009692 if (mCurrentFocus == null ||
9693 mCurrentFocus.mLayer < w.mLayer) {
9694 // We are showing on to of the current
9695 // focus, so re-evaluate focus to make
9696 // sure it is correct.
9697 mFocusMayChange = true;
9698 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009699 }
9700 }
9701 if (changed && (attrs.flags
9702 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9703 wallpaperMayChange = true;
9704 }
9705 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009707 mPolicy.animatingWindowLw(w, attrs);
9708 }
9709
9710 final AppWindowToken atoken = w.mAppToken;
9711 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9712 if (atoken.lastTransactionSequence != transactionSequence) {
9713 atoken.lastTransactionSequence = transactionSequence;
9714 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9715 atoken.startingDisplayed = false;
9716 }
9717 if ((w.isOnScreen() || w.mAttrs.type
9718 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9719 && !w.mExiting && !w.mDestroying) {
9720 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009721 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009722 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009723 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009724 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009725 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009726 + " pv=" + w.mPolicyVisibility
9727 + " dp=" + w.mDrawPending
9728 + " cdp=" + w.mCommitDrawPending
9729 + " ah=" + w.mAttachedHidden
9730 + " th=" + atoken.hiddenRequested
9731 + " a=" + w.mAnimating);
9732 }
9733 }
9734 if (w != atoken.startingWindow) {
9735 if (!atoken.freezingScreen || !w.mAppFreezing) {
9736 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009737 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009738 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009739 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009740 "tokenMayBeDrawn: " + atoken
9741 + " freezingScreen=" + atoken.freezingScreen
9742 + " mAppFreezing=" + w.mAppFreezing);
9743 tokenMayBeDrawn = true;
9744 }
9745 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009746 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009747 atoken.startingDisplayed = true;
9748 }
9749 }
9750 } else if (w.mReadyToShow) {
9751 w.performShowLocked();
9752 }
9753 }
9754
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009755 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009756
9757 if (tokenMayBeDrawn) {
9758 // See if any windows have been drawn, so they (and others
9759 // associated with them) can now be shown.
9760 final int NT = mTokenList.size();
9761 for (i=0; i<NT; i++) {
9762 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9763 if (wtoken == null) {
9764 continue;
9765 }
9766 if (wtoken.freezingScreen) {
9767 int numInteresting = wtoken.numInterestingWindows;
9768 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009769 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009770 "allDrawn: " + wtoken
9771 + " interesting=" + numInteresting
9772 + " drawn=" + wtoken.numDrawnWindows);
9773 wtoken.showAllWindowsLocked();
9774 unsetAppFreezingScreenLocked(wtoken, false, true);
9775 orientationChangeComplete = true;
9776 }
9777 } else if (!wtoken.allDrawn) {
9778 int numInteresting = wtoken.numInterestingWindows;
9779 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009780 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009781 "allDrawn: " + wtoken
9782 + " interesting=" + numInteresting
9783 + " drawn=" + wtoken.numDrawnWindows);
9784 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009785 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009786
9787 // We can now show all of the drawn windows!
9788 if (!mOpeningApps.contains(wtoken)) {
9789 wtoken.showAllWindowsLocked();
9790 }
9791 }
9792 }
9793 }
9794 }
9795
9796 // If we are ready to perform an app transition, check through
9797 // all of the app tokens to be shown and see if they are ready
9798 // to go.
9799 if (mAppTransitionReady) {
9800 int NN = mOpeningApps.size();
9801 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009802 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009803 "Checking " + NN + " opening apps (frozen="
9804 + mDisplayFrozen + " timeout="
9805 + mAppTransitionTimeout + ")...");
9806 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9807 // If the display isn't frozen, wait to do anything until
9808 // all of the apps are ready. Otherwise just go because
9809 // we'll unfreeze the display when everyone is ready.
9810 for (i=0; i<NN && goodToGo; i++) {
9811 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009812 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009813 "Check opening app" + wtoken + ": allDrawn="
9814 + wtoken.allDrawn + " startingDisplayed="
9815 + wtoken.startingDisplayed);
9816 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9817 && !wtoken.startingMoved) {
9818 goodToGo = false;
9819 }
9820 }
9821 }
9822 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009823 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009824 int transit = mNextAppTransition;
9825 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009826 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009827 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009828 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009829 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009830 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009831 mAppTransitionTimeout = false;
9832 mStartingIconInTransition = false;
9833 mSkipAppTransitionAnimation = false;
9834
9835 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9836
Dianne Hackborna8f60182009-09-01 19:01:50 -07009837 // If there are applications waiting to come to the
9838 // top of the stack, now is the time to move their windows.
9839 // (Note that we don't do apps going to the bottom
9840 // here -- we want to keep their windows in the old
9841 // Z-order until the animation completes.)
9842 if (mToTopApps.size() > 0) {
9843 NN = mAppTokens.size();
9844 for (i=0; i<NN; i++) {
9845 AppWindowToken wtoken = mAppTokens.get(i);
9846 if (wtoken.sendingToTop) {
9847 wtoken.sendingToTop = false;
9848 moveAppWindowsLocked(wtoken, NN, false);
9849 }
9850 }
9851 mToTopApps.clear();
9852 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009853
Dianne Hackborn25994b42009-09-04 14:21:19 -07009854 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009855
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009856 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009857 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009858
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009859 // The top-most window will supply the layout params,
9860 // and we will determine it below.
9861 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009862 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009863 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009864
Joe Onorato8a9b2202010-02-26 18:56:32 -08009865 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009866 "New wallpaper target=" + mWallpaperTarget
9867 + ", lower target=" + mLowerWallpaperTarget
9868 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009869 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009870 // Do a first pass through the tokens for two
9871 // things:
9872 // (1) Determine if both the closing and opening
9873 // app token sets are wallpaper targets, in which
9874 // case special animations are needed
9875 // (since the wallpaper needs to stay static
9876 // behind them).
9877 // (2) Find the layout params of the top-most
9878 // application window in the tokens, which is
9879 // what will control the animation theme.
9880 final int NC = mClosingApps.size();
9881 NN = NC + mOpeningApps.size();
9882 for (i=0; i<NN; i++) {
9883 AppWindowToken wtoken;
9884 int mode;
9885 if (i < NC) {
9886 wtoken = mClosingApps.get(i);
9887 mode = 1;
9888 } else {
9889 wtoken = mOpeningApps.get(i-NC);
9890 mode = 2;
9891 }
9892 if (mLowerWallpaperTarget != null) {
9893 if (mLowerWallpaperTarget.mAppToken == wtoken
9894 || mUpperWallpaperTarget.mAppToken == wtoken) {
9895 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009896 }
9897 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009898 if (wtoken.appFullscreen) {
9899 WindowState ws = wtoken.findMainWindow();
9900 if (ws != null) {
9901 // If this is a compatibility mode
9902 // window, we will always use its anim.
9903 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9904 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009905 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009906 bestAnimLayer = Integer.MAX_VALUE;
9907 } else if (ws.mLayer > bestAnimLayer) {
9908 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009909 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009910 bestAnimLayer = ws.mLayer;
9911 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009912 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009913 }
9914 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009915
Dianne Hackborn25994b42009-09-04 14:21:19 -07009916 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009917 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009918 "Wallpaper animation!");
9919 switch (transit) {
9920 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9921 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9922 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9923 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9924 break;
9925 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9926 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9927 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9928 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9929 break;
9930 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009931 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009932 "New transit: " + transit);
9933 } else if (oldWallpaper != null) {
9934 // We are transitioning from an activity with
9935 // a wallpaper to one without.
9936 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009937 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009938 "New transit away from wallpaper: " + transit);
9939 } else if (mWallpaperTarget != null) {
9940 // We are transitioning from an activity without
9941 // a wallpaper to now showing the wallpaper
9942 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009943 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009944 "New transit into wallpaper: " + transit);
9945 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009946
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009947 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9948 mLastEnterAnimToken = animToken;
9949 mLastEnterAnimParams = animLp;
9950 } else if (mLastEnterAnimParams != null) {
9951 animLp = mLastEnterAnimParams;
9952 mLastEnterAnimToken = null;
9953 mLastEnterAnimParams = null;
9954 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009955
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009956 // If all closing windows are obscured, then there is
9957 // no need to do an animation. This is the case, for
9958 // example, when this transition is being done behind
9959 // the lock screen.
9960 if (!mPolicy.allowAppAnimationsLw()) {
9961 animLp = null;
9962 }
9963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009964 NN = mOpeningApps.size();
9965 for (i=0; i<NN; i++) {
9966 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009967 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009968 "Now opening app" + wtoken);
9969 wtoken.reportedVisible = false;
9970 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009971 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009972 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009973 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009974 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009975 wtoken.showAllWindowsLocked();
9976 }
9977 NN = mClosingApps.size();
9978 for (i=0; i<NN; i++) {
9979 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009980 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009981 "Now closing app" + wtoken);
9982 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009983 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009984 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009985 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009986 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009987 // Force the allDrawn flag, because we want to start
9988 // this guy's animations regardless of whether it's
9989 // gotten drawn.
9990 wtoken.allDrawn = true;
9991 }
9992
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009993 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009995 mOpeningApps.clear();
9996 mClosingApps.clear();
9997
9998 // This has changed the visibility of windows, so perform
9999 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010000 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010001 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -070010002 if (!moveInputMethodWindowsIfNeededLocked(true)) {
10003 assignLayersLocked();
10004 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010005 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010006 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010007 }
10008 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010009
Dianne Hackborn16064f92010-03-25 00:47:24 -070010010 int adjResult = 0;
10011
Dianne Hackborna8f60182009-09-01 19:01:50 -070010012 if (!animating && mAppTransitionRunning) {
10013 // We have finished the animation of an app transition. To do
10014 // this, we have delayed a lot of operations like showing and
10015 // hiding apps, moving apps in Z-order, etc. The app token list
10016 // reflects the correct Z-order, but the window list may now
10017 // be out of sync with it. So here we will just rebuild the
10018 // entire app window list. Fun!
10019 mAppTransitionRunning = false;
10020 // Clear information about apps that were moving.
10021 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010022
Dianne Hackborna8f60182009-09-01 19:01:50 -070010023 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010024 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010025 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010026 moveInputMethodWindowsIfNeededLocked(false);
10027 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010028 // Since the window list has been rebuilt, focus might
10029 // have to be recomputed since the actual order of windows
10030 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010031 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010032 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010033
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010034 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010035 // At this point, there was a window with a wallpaper that
10036 // was force hiding other windows behind it, but now it
10037 // is going away. This may be simple -- just animate
10038 // away the wallpaper and its window -- or it may be
10039 // hard -- the wallpaper now needs to be shown behind
10040 // something that was hidden.
10041 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010042 if (mLowerWallpaperTarget != null
10043 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010044 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010045 "wallpaperForceHiding changed with lower="
10046 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010047 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010048 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10049 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10050 if (mLowerWallpaperTarget.mAppToken.hidden) {
10051 // The lower target has become hidden before we
10052 // actually started the animation... let's completely
10053 // re-evaluate everything.
10054 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010055 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010056 }
10057 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010058 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010059 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010060 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010061 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010062 + " NEW: " + mWallpaperTarget
10063 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010064 if (mLowerWallpaperTarget == null) {
10065 // Whoops, we don't need a special wallpaper animation.
10066 // Clear them out.
10067 forceHiding = false;
10068 for (i=N-1; i>=0; i--) {
10069 WindowState w = (WindowState)mWindows.get(i);
10070 if (w.mSurface != null) {
10071 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010072 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010073 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010074 forceHiding = true;
10075 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10076 if (!w.mAnimating) {
10077 // We set the animation above so it
10078 // is not yet running.
10079 w.clearAnimation();
10080 }
10081 }
10082 }
10083 }
10084 }
10085 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010086
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010087 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010088 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010089 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010090 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010091 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010092
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010093 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010094 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010095 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010096 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010097 assignLayersLocked();
10098 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010099 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010100 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010101 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010102 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010103
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010104 if (mFocusMayChange) {
10105 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010106 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010107 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010108 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010109 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010110 }
10111
10112 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010113 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010114 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010115
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010116 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10117 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010118
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010119 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010120
10121 // THIRD LOOP: Update the surfaces of all windows.
10122
10123 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10124
10125 boolean obscured = false;
10126 boolean blurring = false;
10127 boolean dimming = false;
10128 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010129 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010130 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010131
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010132 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010134 for (i=N-1; i>=0; i--) {
10135 WindowState w = (WindowState)mWindows.get(i);
10136
10137 boolean displayed = false;
10138 final WindowManager.LayoutParams attrs = w.mAttrs;
10139 final int attrFlags = attrs.flags;
10140
10141 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010142 // XXX NOTE: The logic here could be improved. We have
10143 // the decision about whether to resize a window separated
10144 // from whether to hide the surface. This can cause us to
10145 // resize a surface even if we are going to hide it. You
10146 // can see this by (1) holding device in landscape mode on
10147 // home screen; (2) tapping browser icon (device will rotate
10148 // to landscape; (3) tap home. The wallpaper will be resized
10149 // in step 2 but then immediately hidden, causing us to
10150 // have to resize and then redraw it again in step 3. It
10151 // would be nice to figure out how to avoid this, but it is
10152 // difficult because we do need to resize surfaces in some
10153 // cases while they are hidden such as when first showing a
10154 // window.
10155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010156 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010157 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010158 TAG, "Placing surface #" + i + " " + w.mSurface
10159 + ": new=" + w.mShownFrame + ", old="
10160 + w.mLastShownFrame);
10161
10162 boolean resize;
10163 int width, height;
10164 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
10165 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
10166 w.mLastRequestedHeight != w.mRequestedHeight;
10167 // for a scaled surface, we just want to use
10168 // the requested size.
10169 width = w.mRequestedWidth;
10170 height = w.mRequestedHeight;
10171 w.mLastRequestedWidth = width;
10172 w.mLastRequestedHeight = height;
10173 w.mLastShownFrame.set(w.mShownFrame);
10174 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010175 if (SHOW_TRANSACTIONS) logSurface(w,
10176 "POS " + w.mShownFrame.left
10177 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010178 w.mSurfaceX = w.mShownFrame.left;
10179 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010180 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10181 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010182 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010183 if (!recoveringMemory) {
10184 reclaimSomeSurfaceMemoryLocked(w, "position");
10185 }
10186 }
10187 } else {
10188 resize = !w.mLastShownFrame.equals(w.mShownFrame);
10189 width = w.mShownFrame.width();
10190 height = w.mShownFrame.height();
10191 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010192 }
10193
10194 if (resize) {
10195 if (width < 1) width = 1;
10196 if (height < 1) height = 1;
10197 if (w.mSurface != null) {
10198 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010199 if (SHOW_TRANSACTIONS) logSurface(w,
10200 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010201 + w.mShownFrame.top + " SIZE "
10202 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010203 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010204 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010205 w.mSurfaceW = width;
10206 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010207 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010208 w.mSurfaceX = w.mShownFrame.left;
10209 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010210 w.mSurface.setPosition(w.mShownFrame.left,
10211 w.mShownFrame.top);
10212 } catch (RuntimeException e) {
10213 // If something goes wrong with the surface (such
10214 // as running out of memory), don't take down the
10215 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010216 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010217 + "size=(" + width + "x" + height
10218 + "), pos=(" + w.mShownFrame.left
10219 + "," + w.mShownFrame.top + ")", e);
10220 if (!recoveringMemory) {
10221 reclaimSomeSurfaceMemoryLocked(w, "size");
10222 }
10223 }
10224 }
10225 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010226 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010227 w.mContentInsetsChanged =
10228 !w.mLastContentInsets.equals(w.mContentInsets);
10229 w.mVisibleInsetsChanged =
10230 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010231 boolean configChanged =
10232 w.mConfiguration != mCurConfiguration
10233 && (w.mConfiguration == null
10234 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010235 if (DEBUG_CONFIGURATION && configChanged) {
10236 Slog.v(TAG, "Win " + w + " config changed: "
10237 + mCurConfiguration);
10238 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010239 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010240 + ": configChanged=" + configChanged
10241 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -070010242 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010243 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010244 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010245 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010246 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010247 w.mLastFrame.set(w.mFrame);
10248 w.mLastContentInsets.set(w.mContentInsets);
10249 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010250 // If the screen is currently frozen, then keep
10251 // it frozen until this window draws at its new
10252 // orientation.
10253 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010254 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010255 "Resizing while display frozen: " + w);
10256 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010257 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010258 mWindowsFreezingScreen = true;
10259 // XXX should probably keep timeout from
10260 // when we first froze the display.
10261 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10262 mH.sendMessageDelayed(mH.obtainMessage(
10263 H.WINDOW_FREEZE_TIMEOUT), 2000);
10264 }
10265 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010266 // If the orientation is changing, then we need to
10267 // hold off on unfreezing the display until this
10268 // window has been redrawn; to do that, we need
10269 // to go through the process of getting informed
10270 // by the application when it has finished drawing.
10271 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010272 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010273 "Orientation start waiting for draw in "
10274 + w + ", surface " + w.mSurface);
10275 w.mDrawPending = true;
10276 w.mCommitDrawPending = false;
10277 w.mReadyToShow = false;
10278 if (w.mAppToken != null) {
10279 w.mAppToken.allDrawn = false;
10280 }
10281 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010282 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010283 "Resizing window " + w + " to " + w.mFrame);
10284 mResizingWindows.add(w);
10285 } else if (w.mOrientationChanging) {
10286 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010287 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010288 "Orientation not waiting for draw in "
10289 + w + ", surface " + w.mSurface);
10290 w.mOrientationChanging = false;
10291 }
10292 }
10293 }
10294
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010295 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010296 if (!w.mLastHidden) {
10297 //dump();
Dianne Hackborn5943c202010-04-12 21:36:49 -070010298 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Window hiding: waitingToShow="
10299 + w.mRootToken.waitingToShow + " polvis="
10300 + w.mPolicyVisibility + " atthid="
10301 + w.mAttachedHidden + " tokhid="
10302 + w.mRootToken.hidden + " vis="
10303 + w.mViewVisibility);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010304 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010305 if (SHOW_TRANSACTIONS) logSurface(w,
10306 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010307 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010308 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010309 try {
10310 w.mSurface.hide();
10311 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010312 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010313 }
10314 }
10315 mKeyWaiter.releasePendingPointerLocked(w.mSession);
10316 }
10317 // If we are waiting for this window to handle an
10318 // orientation change, well, it is hidden, so
10319 // doesn't really matter. Note that this does
10320 // introduce a potential glitch if the window
10321 // becomes unhidden before it has drawn for the
10322 // new orientation.
10323 if (w.mOrientationChanging) {
10324 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010325 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010326 "Orientation change skips hidden " + w);
10327 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010328 } else if (w.mLastLayer != w.mAnimLayer
10329 || w.mLastAlpha != w.mShownAlpha
10330 || w.mLastDsDx != w.mDsDx
10331 || w.mLastDtDx != w.mDtDx
10332 || w.mLastDsDy != w.mDsDy
10333 || w.mLastDtDy != w.mDtDy
10334 || w.mLastHScale != w.mHScale
10335 || w.mLastVScale != w.mVScale
10336 || w.mLastHidden) {
10337 displayed = true;
10338 w.mLastAlpha = w.mShownAlpha;
10339 w.mLastLayer = w.mAnimLayer;
10340 w.mLastDsDx = w.mDsDx;
10341 w.mLastDtDx = w.mDtDx;
10342 w.mLastDsDy = w.mDsDy;
10343 w.mLastDtDy = w.mDtDy;
10344 w.mLastHScale = w.mHScale;
10345 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010346 if (SHOW_TRANSACTIONS) logSurface(w,
10347 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010348 + " matrix=[" + (w.mDsDx*w.mHScale)
10349 + "," + (w.mDtDx*w.mVScale)
10350 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010351 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010352 if (w.mSurface != null) {
10353 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010354 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010355 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010356 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010357 w.mSurface.setLayer(w.mAnimLayer);
10358 w.mSurface.setMatrix(
10359 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10360 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10361 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010362 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010363 if (!recoveringMemory) {
10364 reclaimSomeSurfaceMemoryLocked(w, "update");
10365 }
10366 }
10367 }
10368
10369 if (w.mLastHidden && !w.mDrawPending
10370 && !w.mCommitDrawPending
10371 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010372 if (SHOW_TRANSACTIONS) logSurface(w,
10373 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010374 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010375 + " during relayout");
10376 if (showSurfaceRobustlyLocked(w)) {
10377 w.mHasDrawn = true;
10378 w.mLastHidden = false;
10379 } else {
10380 w.mOrientationChanging = false;
10381 }
10382 }
10383 if (w.mSurface != null) {
10384 w.mToken.hasVisible = true;
10385 }
10386 } else {
10387 displayed = true;
10388 }
10389
10390 if (displayed) {
10391 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010392 if (attrs.width == LayoutParams.MATCH_PARENT
10393 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010394 covered = true;
10395 }
10396 }
10397 if (w.mOrientationChanging) {
10398 if (w.mDrawPending || w.mCommitDrawPending) {
10399 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010400 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010401 "Orientation continue waiting for draw in " + w);
10402 } else {
10403 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010404 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010405 "Orientation change complete in " + w);
10406 }
10407 }
10408 w.mToken.hasVisible = true;
10409 }
10410 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010411 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010412 "Orientation change skips hidden " + w);
10413 w.mOrientationChanging = false;
10414 }
10415
10416 final boolean canBeSeen = w.isDisplayedLw();
10417
10418 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10419 focusDisplayed = true;
10420 }
10421
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010422 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010424 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010425 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010426 if (w.mSurface != null) {
10427 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10428 holdScreen = w.mSession;
10429 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010430 if (!syswin && w.mAttrs.screenBrightness >= 0
10431 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010432 screenBrightness = w.mAttrs.screenBrightness;
10433 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010434 if (!syswin && w.mAttrs.buttonBrightness >= 0
10435 && buttonBrightness < 0) {
10436 buttonBrightness = w.mAttrs.buttonBrightness;
10437 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010438 if (canBeSeen
10439 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10440 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10441 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010442 syswin = true;
10443 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010444 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010445
Dianne Hackborn25994b42009-09-04 14:21:19 -070010446 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10447 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010448 // This window completely covers everything behind it,
10449 // so we want to leave all of them as unblurred (for
10450 // performance reasons).
10451 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010452 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010453 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010454 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010455 obscured = true;
10456 if (mBackgroundFillerSurface == null) {
10457 try {
10458 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010459 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010460 0, dw, dh,
10461 PixelFormat.OPAQUE,
10462 Surface.FX_SURFACE_NORMAL);
10463 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010464 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010465 }
10466 }
10467 try {
10468 mBackgroundFillerSurface.setPosition(0, 0);
10469 mBackgroundFillerSurface.setSize(dw, dh);
10470 // Using the same layer as Dim because they will never be shown at the
10471 // same time.
10472 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10473 mBackgroundFillerSurface.show();
10474 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010475 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010476 }
10477 backgroundFillerShown = true;
10478 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010479 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010480 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010481 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010482 + ": blurring=" + blurring
10483 + " obscured=" + obscured
10484 + " displayed=" + displayed);
10485 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10486 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010487 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010488 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010489 if (mDimAnimator == null) {
10490 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010491 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010492 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010493 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010494 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010495 }
10496 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10497 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010498 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010499 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010500 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010501 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010502 + mBlurSurface + ": CREATE");
10503 try {
Romain Guy06882f82009-06-10 13:36:04 -070010504 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010505 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010506 -1, 16, 16,
10507 PixelFormat.OPAQUE,
10508 Surface.FX_SURFACE_BLUR);
10509 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010510 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010511 }
10512 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010513 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010514 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10515 + mBlurSurface + ": pos=(0,0) (" +
10516 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010517 mBlurSurface.setPosition(0, 0);
10518 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010519 mBlurSurface.setLayer(w.mAnimLayer-2);
10520 if (!mBlurShown) {
10521 try {
10522 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10523 + mBlurSurface + ": SHOW");
10524 mBlurSurface.show();
10525 } catch (RuntimeException e) {
10526 Slog.w(TAG, "Failure showing blur surface", e);
10527 }
10528 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010529 }
10530 }
10531 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010532 }
10533 }
10534 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010535
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010536 if (obscuredChanged && mWallpaperTarget == w) {
10537 // This is the wallpaper target and its obscured state
10538 // changed... make sure the current wallaper's visibility
10539 // has been updated accordingly.
10540 updateWallpaperVisibilityLocked();
10541 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010542 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010543
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010544 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10545 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010546 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010547 try {
10548 mBackgroundFillerSurface.hide();
10549 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010550 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010551 }
10552 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010553
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010554 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010555 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10556 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010557 }
Romain Guy06882f82009-06-10 13:36:04 -070010558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010559 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010560 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010561 + ": HIDE");
10562 try {
10563 mBlurSurface.hide();
10564 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010565 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010566 }
10567 mBlurShown = false;
10568 }
10569
Joe Onorato8a9b2202010-02-26 18:56:32 -080010570 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010571 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010572 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010573 }
10574
10575 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010576
Joe Onorato8a9b2202010-02-26 18:56:32 -080010577 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010578 "With display frozen, orientationChangeComplete="
10579 + orientationChangeComplete);
10580 if (orientationChangeComplete) {
10581 if (mWindowsFreezingScreen) {
10582 mWindowsFreezingScreen = false;
10583 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10584 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010585 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010586 }
Romain Guy06882f82009-06-10 13:36:04 -070010587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010588 i = mResizingWindows.size();
10589 if (i > 0) {
10590 do {
10591 i--;
10592 WindowState win = mResizingWindows.get(i);
10593 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010594 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10595 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010596 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010597 boolean configChanged =
10598 win.mConfiguration != mCurConfiguration
10599 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010600 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10601 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10602 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010603 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010604 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010605 + " / " + mCurConfiguration + " / 0x"
10606 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010607 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010608 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010609 win.mClient.resized(win.mFrame.width(),
10610 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010611 win.mLastVisibleInsets, win.mDrawPending,
10612 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010613 win.mContentInsetsChanged = false;
10614 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010615 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010616 } catch (RemoteException e) {
10617 win.mOrientationChanging = false;
10618 }
10619 } while (i > 0);
10620 mResizingWindows.clear();
10621 }
Romain Guy06882f82009-06-10 13:36:04 -070010622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010623 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010624 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010625 i = mDestroySurface.size();
10626 if (i > 0) {
10627 do {
10628 i--;
10629 WindowState win = mDestroySurface.get(i);
10630 win.mDestroying = false;
10631 if (mInputMethodWindow == win) {
10632 mInputMethodWindow = null;
10633 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010634 if (win == mWallpaperTarget) {
10635 wallpaperDestroyed = true;
10636 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010637 win.destroySurfaceLocked();
10638 } while (i > 0);
10639 mDestroySurface.clear();
10640 }
10641
10642 // Time to remove any exiting tokens?
10643 for (i=mExitingTokens.size()-1; i>=0; i--) {
10644 WindowToken token = mExitingTokens.get(i);
10645 if (!token.hasVisible) {
10646 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010647 if (token.windowType == TYPE_WALLPAPER) {
10648 mWallpaperTokens.remove(token);
10649 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010650 }
10651 }
10652
10653 // Time to remove any exiting applications?
10654 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10655 AppWindowToken token = mExitingAppTokens.get(i);
10656 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010657 // Make sure there is no animation running on this token,
10658 // so any windows associated with it will be removed as
10659 // soon as their animations are complete
10660 token.animation = null;
10661 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010662 mAppTokens.remove(token);
10663 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010664 if (mLastEnterAnimToken == token) {
10665 mLastEnterAnimToken = null;
10666 mLastEnterAnimParams = null;
10667 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010668 }
10669 }
10670
Dianne Hackborna8f60182009-09-01 19:01:50 -070010671 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010672
Dianne Hackborna8f60182009-09-01 19:01:50 -070010673 if (!animating && mAppTransitionRunning) {
10674 // We have finished the animation of an app transition. To do
10675 // this, we have delayed a lot of operations like showing and
10676 // hiding apps, moving apps in Z-order, etc. The app token list
10677 // reflects the correct Z-order, but the window list may now
10678 // be out of sync with it. So here we will just rebuild the
10679 // entire app window list. Fun!
10680 mAppTransitionRunning = false;
10681 needRelayout = true;
10682 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010683 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010684 // Clear information about apps that were moving.
10685 mToBottomApps.clear();
10686 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010688 if (focusDisplayed) {
10689 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10690 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010691 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010692 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010693 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010694 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010695 requestAnimationLocked(0);
10696 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010697 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10698 }
Dianne Hackbornce73c1e2010-04-12 23:11:38 -070010699
10700 if (DEBUG_FREEZE) Slog.v(TAG, "Layout: mDisplayFrozen=" + mDisplayFrozen
10701 + " holdScreen=" + holdScreen);
10702 if (!mDisplayFrozen) {
10703 mQueue.setHoldScreenLocked(holdScreen != null);
10704 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10705 mPowerManager.setScreenBrightnessOverride(-1);
10706 } else {
10707 mPowerManager.setScreenBrightnessOverride((int)
10708 (screenBrightness * Power.BRIGHTNESS_ON));
10709 }
10710 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10711 mPowerManager.setButtonBrightnessOverride(-1);
10712 } else {
10713 mPowerManager.setButtonBrightnessOverride((int)
10714 (buttonBrightness * Power.BRIGHTNESS_ON));
10715 }
10716 if (holdScreen != mHoldingScreenOn) {
10717 mHoldingScreenOn = holdScreen;
10718 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10719 mH.sendMessage(m);
10720 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010721 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010722
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010723 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010724 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010725 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10726 LocalPowerManager.BUTTON_EVENT, true);
10727 mTurnOnScreen = false;
10728 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010729
10730 // Check to see if we are now in a state where the screen should
10731 // be enabled, because the window obscured flags have changed.
10732 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010733 }
10734
10735 void requestAnimationLocked(long delay) {
10736 if (!mAnimationPending) {
10737 mAnimationPending = true;
10738 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10739 }
10740 }
Romain Guy06882f82009-06-10 13:36:04 -070010741
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010742 /**
10743 * Have the surface flinger show a surface, robustly dealing with
10744 * error conditions. In particular, if there is not enough memory
10745 * to show the surface, then we will try to get rid of other surfaces
10746 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010747 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010748 * @return Returns true if the surface was successfully shown.
10749 */
10750 boolean showSurfaceRobustlyLocked(WindowState win) {
10751 try {
10752 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010753 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010754 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010755 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010756 if (DEBUG_VISIBILITY) Slog.v(TAG,
10757 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010758 win.mTurnOnScreen = false;
10759 mTurnOnScreen = true;
10760 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010761 }
10762 return true;
10763 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010764 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010765 }
Romain Guy06882f82009-06-10 13:36:04 -070010766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010767 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010769 return false;
10770 }
Romain Guy06882f82009-06-10 13:36:04 -070010771
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010772 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10773 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010774
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010775 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010776 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010778 if (mForceRemoves == null) {
10779 mForceRemoves = new ArrayList<WindowState>();
10780 }
Romain Guy06882f82009-06-10 13:36:04 -070010781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010782 long callingIdentity = Binder.clearCallingIdentity();
10783 try {
10784 // There was some problem... first, do a sanity check of the
10785 // window list to make sure we haven't left any dangling surfaces
10786 // around.
10787 int N = mWindows.size();
10788 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010789 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010790 for (int i=0; i<N; i++) {
10791 WindowState ws = (WindowState)mWindows.get(i);
10792 if (ws.mSurface != null) {
10793 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010794 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010795 + ws + " surface=" + ws.mSurface
10796 + " token=" + win.mToken
10797 + " pid=" + ws.mSession.mPid
10798 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010799 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010800 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010801 ws.mSurface = null;
10802 mForceRemoves.add(ws);
10803 i--;
10804 N--;
10805 leakedSurface = true;
10806 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010807 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010808 + ws + " surface=" + ws.mSurface
10809 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010810 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010811 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010812 ws.mSurface = null;
10813 leakedSurface = true;
10814 }
10815 }
10816 }
Romain Guy06882f82009-06-10 13:36:04 -070010817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010818 boolean killedApps = false;
10819 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010820 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010821 SparseIntArray pidCandidates = new SparseIntArray();
10822 for (int i=0; i<N; i++) {
10823 WindowState ws = (WindowState)mWindows.get(i);
10824 if (ws.mSurface != null) {
10825 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10826 }
10827 }
10828 if (pidCandidates.size() > 0) {
10829 int[] pids = new int[pidCandidates.size()];
10830 for (int i=0; i<pids.length; i++) {
10831 pids[i] = pidCandidates.keyAt(i);
10832 }
10833 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010834 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010835 killedApps = true;
10836 }
10837 } catch (RemoteException e) {
10838 }
10839 }
10840 }
Romain Guy06882f82009-06-10 13:36:04 -070010841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010842 if (leakedSurface || killedApps) {
10843 // We managed to reclaim some memory, so get rid of the trouble
10844 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010845 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010846 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010847 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010848 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010849 win.mSurface = null;
10850 }
Romain Guy06882f82009-06-10 13:36:04 -070010851
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010852 try {
10853 win.mClient.dispatchGetNewSurface();
10854 } catch (RemoteException e) {
10855 }
10856 }
10857 } finally {
10858 Binder.restoreCallingIdentity(callingIdentity);
10859 }
10860 }
Romain Guy06882f82009-06-10 13:36:04 -070010861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010862 private boolean updateFocusedWindowLocked(int mode) {
10863 WindowState newFocus = computeFocusedWindowLocked();
10864 if (mCurrentFocus != newFocus) {
10865 // This check makes sure that we don't already have the focus
10866 // change message pending.
10867 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10868 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010869 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010870 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10871 final WindowState oldFocus = mCurrentFocus;
10872 mCurrentFocus = newFocus;
10873 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010875 final WindowState imWindow = mInputMethodWindow;
10876 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010877 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010878 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010879 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10880 mLayoutNeeded = true;
10881 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010882 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10883 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010884 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10885 // Client will do the layout, but we need to assign layers
10886 // for handleNewWindowLocked() below.
10887 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010888 }
10889 }
Romain Guy06882f82009-06-10 13:36:04 -070010890
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010891 if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10892 mKeyWaiter.handleNewWindowLocked(newFocus);
10893 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010894 return true;
10895 }
10896 return false;
10897 }
10898
10899 private WindowState computeFocusedWindowLocked() {
10900 WindowState result = null;
10901 WindowState win;
10902
10903 int i = mWindows.size() - 1;
10904 int nextAppIndex = mAppTokens.size()-1;
10905 WindowToken nextApp = nextAppIndex >= 0
10906 ? mAppTokens.get(nextAppIndex) : null;
10907
10908 while (i >= 0) {
10909 win = (WindowState)mWindows.get(i);
10910
Joe Onorato8a9b2202010-02-26 18:56:32 -080010911 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010912 TAG, "Looking for focus: " + i
10913 + " = " + win
10914 + ", flags=" + win.mAttrs.flags
10915 + ", canReceive=" + win.canReceiveKeys());
10916
10917 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010919 // If this window's application has been removed, just skip it.
10920 if (thisApp != null && thisApp.removed) {
10921 i--;
10922 continue;
10923 }
Romain Guy06882f82009-06-10 13:36:04 -070010924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010925 // If there is a focused app, don't allow focus to go to any
10926 // windows below it. If this is an application window, step
10927 // through the app tokens until we find its app.
10928 if (thisApp != null && nextApp != null && thisApp != nextApp
10929 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10930 int origAppIndex = nextAppIndex;
10931 while (nextAppIndex > 0) {
10932 if (nextApp == mFocusedApp) {
10933 // Whoops, we are below the focused app... no focus
10934 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010935 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010936 TAG, "Reached focused app: " + mFocusedApp);
10937 return null;
10938 }
10939 nextAppIndex--;
10940 nextApp = mAppTokens.get(nextAppIndex);
10941 if (nextApp == thisApp) {
10942 break;
10943 }
10944 }
10945 if (thisApp != nextApp) {
10946 // Uh oh, the app token doesn't exist! This shouldn't
10947 // happen, but if it does we can get totally hosed...
10948 // so restart at the original app.
10949 nextAppIndex = origAppIndex;
10950 nextApp = mAppTokens.get(nextAppIndex);
10951 }
10952 }
10953
10954 // Dispatch to this window if it is wants key events.
10955 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010956 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010957 TAG, "Found focus @ " + i + " = " + win);
10958 result = win;
10959 break;
10960 }
10961
10962 i--;
10963 }
10964
10965 return result;
10966 }
10967
10968 private void startFreezingDisplayLocked() {
10969 if (mDisplayFrozen) {
Chris Tate2ad63a92009-03-25 17:36:48 -070010970 // Freezing the display also suspends key event delivery, to
10971 // keep events from going astray while the display is reconfigured.
10972 // If someone has changed orientation again while the screen is
10973 // still frozen, the events will continue to be blocked while the
10974 // successive orientation change is processed. To prevent spurious
10975 // ANRs, we reset the event dispatch timeout in this case.
10976 synchronized (mKeyWaiter) {
10977 mKeyWaiter.mWasFrozen = true;
10978 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010979 return;
10980 }
Romain Guy06882f82009-06-10 13:36:04 -070010981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010982 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010984 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010985 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010986 if (mFreezeGcPending != 0) {
10987 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010988 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010989 mH.removeMessages(H.FORCE_GC);
10990 Runtime.getRuntime().gc();
10991 mFreezeGcPending = now;
10992 }
10993 } else {
10994 mFreezeGcPending = now;
10995 }
Romain Guy06882f82009-06-10 13:36:04 -070010996
Dianne Hackbornce73c1e2010-04-12 23:11:38 -070010997 if (DEBUG_FREEZE) Slog.v(TAG, "*** FREEZING DISPLAY", new RuntimeException());
10998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010999 mDisplayFrozen = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070011000 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
11001 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011002 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011003 mAppTransitionReady = true;
11004 }
Romain Guy06882f82009-06-10 13:36:04 -070011005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011006 if (PROFILE_ORIENTATION) {
11007 File file = new File("/data/system/frozen");
11008 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
11009 }
11010 Surface.freezeDisplay(0);
11011 }
Romain Guy06882f82009-06-10 13:36:04 -070011012
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011013 private void stopFreezingDisplayLocked() {
11014 if (!mDisplayFrozen) {
11015 return;
11016 }
Romain Guy06882f82009-06-10 13:36:04 -070011017
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011018 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
11019 return;
11020 }
11021
Dianne Hackbornce73c1e2010-04-12 23:11:38 -070011022 if (DEBUG_FREEZE) Slog.v(TAG, "*** UNFREEZING DISPLAY", new RuntimeException());
11023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011024 mDisplayFrozen = false;
11025 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
11026 if (PROFILE_ORIENTATION) {
11027 Debug.stopMethodTracing();
11028 }
11029 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070011030
Chris Tate2ad63a92009-03-25 17:36:48 -070011031 // Reset the key delivery timeout on unfreeze, too. We force a wakeup here
11032 // too because regular key delivery processing should resume immediately.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011033 synchronized (mKeyWaiter) {
11034 mKeyWaiter.mWasFrozen = true;
11035 mKeyWaiter.notifyAll();
11036 }
11037
Christopher Tateb696aee2010-04-02 19:08:30 -070011038 // While the display is frozen we don't re-compute the orientation
11039 // to avoid inconsistent states. However, something interesting
11040 // could have actually changed during that time so re-evaluate it
11041 // now to catch that.
11042 if (updateOrientationFromAppTokensLocked()) {
11043 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
11044 }
11045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011046 // A little kludge: a lot could have happened while the
11047 // display was frozen, so now that we are coming back we
11048 // do a gc so that any remote references the system
11049 // processes holds on others can be released if they are
11050 // no longer needed.
11051 mH.removeMessages(H.FORCE_GC);
11052 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11053 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011055 mScreenFrozenLock.release();
11056 }
Romain Guy06882f82009-06-10 13:36:04 -070011057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011058 @Override
11059 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11060 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11061 != PackageManager.PERMISSION_GRANTED) {
11062 pw.println("Permission Denial: can't dump WindowManager from from pid="
11063 + Binder.getCallingPid()
11064 + ", uid=" + Binder.getCallingUid());
11065 return;
11066 }
Romain Guy06882f82009-06-10 13:36:04 -070011067
Dianne Hackborna2e92262010-03-02 17:19:29 -080011068 pw.println("Input State:");
11069 mQueue.dump(pw, " ");
11070 pw.println(" ");
11071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011072 synchronized(mWindowMap) {
11073 pw.println("Current Window Manager state:");
11074 for (int i=mWindows.size()-1; i>=0; i--) {
11075 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011076 pw.print(" Window #"); pw.print(i); pw.print(' ');
11077 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011078 w.dump(pw, " ");
11079 }
11080 if (mInputMethodDialogs.size() > 0) {
11081 pw.println(" ");
11082 pw.println(" Input method dialogs:");
11083 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11084 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011085 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011086 }
11087 }
11088 if (mPendingRemove.size() > 0) {
11089 pw.println(" ");
11090 pw.println(" Remove pending for:");
11091 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11092 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011093 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11094 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011095 w.dump(pw, " ");
11096 }
11097 }
11098 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11099 pw.println(" ");
11100 pw.println(" Windows force removing:");
11101 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11102 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011103 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11104 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011105 w.dump(pw, " ");
11106 }
11107 }
11108 if (mDestroySurface.size() > 0) {
11109 pw.println(" ");
11110 pw.println(" Windows waiting to destroy their surface:");
11111 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11112 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011113 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11114 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011115 w.dump(pw, " ");
11116 }
11117 }
11118 if (mLosingFocus.size() > 0) {
11119 pw.println(" ");
11120 pw.println(" Windows losing focus:");
11121 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11122 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011123 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11124 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011125 w.dump(pw, " ");
11126 }
11127 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011128 if (mResizingWindows.size() > 0) {
11129 pw.println(" ");
11130 pw.println(" Windows waiting to resize:");
11131 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11132 WindowState w = mResizingWindows.get(i);
11133 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11134 pw.print(w); pw.println(":");
11135 w.dump(pw, " ");
11136 }
11137 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011138 if (mSessions.size() > 0) {
11139 pw.println(" ");
11140 pw.println(" All active sessions:");
11141 Iterator<Session> it = mSessions.iterator();
11142 while (it.hasNext()) {
11143 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011144 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011145 s.dump(pw, " ");
11146 }
11147 }
11148 if (mTokenMap.size() > 0) {
11149 pw.println(" ");
11150 pw.println(" All tokens:");
11151 Iterator<WindowToken> it = mTokenMap.values().iterator();
11152 while (it.hasNext()) {
11153 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011154 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011155 token.dump(pw, " ");
11156 }
11157 }
11158 if (mTokenList.size() > 0) {
11159 pw.println(" ");
11160 pw.println(" Window token list:");
11161 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011162 pw.print(" #"); pw.print(i); pw.print(": ");
11163 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011164 }
11165 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011166 if (mWallpaperTokens.size() > 0) {
11167 pw.println(" ");
11168 pw.println(" Wallpaper tokens:");
11169 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11170 WindowToken token = mWallpaperTokens.get(i);
11171 pw.print(" Wallpaper #"); pw.print(i);
11172 pw.print(' '); pw.print(token); pw.println(':');
11173 token.dump(pw, " ");
11174 }
11175 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011176 if (mAppTokens.size() > 0) {
11177 pw.println(" ");
11178 pw.println(" Application tokens in Z order:");
11179 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011180 pw.print(" App #"); pw.print(i); pw.print(": ");
11181 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011182 }
11183 }
11184 if (mFinishedStarting.size() > 0) {
11185 pw.println(" ");
11186 pw.println(" Finishing start of application tokens:");
11187 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11188 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011189 pw.print(" Finished Starting #"); pw.print(i);
11190 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011191 token.dump(pw, " ");
11192 }
11193 }
11194 if (mExitingTokens.size() > 0) {
11195 pw.println(" ");
11196 pw.println(" Exiting tokens:");
11197 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11198 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011199 pw.print(" Exiting #"); pw.print(i);
11200 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011201 token.dump(pw, " ");
11202 }
11203 }
11204 if (mExitingAppTokens.size() > 0) {
11205 pw.println(" ");
11206 pw.println(" Exiting application tokens:");
11207 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11208 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011209 pw.print(" Exiting App #"); pw.print(i);
11210 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011211 token.dump(pw, " ");
11212 }
11213 }
11214 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011215 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11216 pw.print(" mLastFocus="); pw.println(mLastFocus);
11217 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11218 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11219 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011220 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011221 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11222 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11223 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11224 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011225 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11226 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11227 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011228 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11229 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11230 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11231 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011232 if (mDimAnimator != null) {
11233 mDimAnimator.printTo(pw);
11234 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011235 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011236 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011237 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011238 pw.print(mInputMethodAnimLayerAdjustment);
11239 pw.print(" mWallpaperAnimLayerAdjustment=");
11240 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011241 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11242 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011243 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11244 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011245 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11246 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011247 pw.print(" mRotation="); pw.print(mRotation);
11248 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11249 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11250 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11251 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11252 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11253 pw.print(" mNextAppTransition=0x");
11254 pw.print(Integer.toHexString(mNextAppTransition));
11255 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011256 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011257 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011258 if (mNextAppTransitionPackage != null) {
11259 pw.print(" mNextAppTransitionPackage=");
11260 pw.print(mNextAppTransitionPackage);
11261 pw.print(", mNextAppTransitionEnter=0x");
11262 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11263 pw.print(", mNextAppTransitionExit=0x");
11264 pw.print(Integer.toHexString(mNextAppTransitionExit));
11265 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011266 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11267 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011268 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11269 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11270 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11271 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011272 if (mOpeningApps.size() > 0) {
11273 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11274 }
11275 if (mClosingApps.size() > 0) {
11276 pw.print(" mClosingApps="); pw.println(mClosingApps);
11277 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011278 if (mToTopApps.size() > 0) {
11279 pw.print(" mToTopApps="); pw.println(mToTopApps);
11280 }
11281 if (mToBottomApps.size() > 0) {
11282 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11283 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011284 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11285 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011286 pw.println(" KeyWaiter state:");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011287 pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin);
11288 pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder);
11289 pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished);
11290 pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow);
11291 pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching);
11292 pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011293 }
11294 }
11295
11296 public void monitor() {
11297 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011298 synchronized (mKeyguardTokenWatcher) { }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011299 synchronized (mKeyWaiter) { }
11300 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011301
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011302 public void virtualKeyFeedback(KeyEvent event) {
11303 mPolicy.keyFeedbackFromInput(event);
11304 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011305
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011306 /**
11307 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011308 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011309 */
11310 private static class DimAnimator {
11311 Surface mDimSurface;
11312 boolean mDimShown = false;
11313 float mDimCurrentAlpha;
11314 float mDimTargetAlpha;
11315 float mDimDeltaPerMs;
11316 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011317
11318 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011319
11320 DimAnimator (SurfaceSession session) {
11321 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011322 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011323 + mDimSurface + ": CREATE");
11324 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011325 mDimSurface = new Surface(session, 0,
11326 "DimSurface",
11327 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011328 Surface.FX_SURFACE_DIM);
11329 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011330 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011331 }
11332 }
11333 }
11334
11335 /**
11336 * Show the dim surface.
11337 */
11338 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011339 if (!mDimShown) {
11340 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11341 dw + "x" + dh + ")");
11342 mDimShown = true;
11343 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011344 mLastDimWidth = dw;
11345 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011346 mDimSurface.setPosition(0, 0);
11347 mDimSurface.setSize(dw, dh);
11348 mDimSurface.show();
11349 } catch (RuntimeException e) {
11350 Slog.w(TAG, "Failure showing dim surface", e);
11351 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011352 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11353 mLastDimWidth = dw;
11354 mLastDimHeight = dh;
11355 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011356 }
11357 }
11358
11359 /**
11360 * Set's the dim surface's layer and update dim parameters that will be used in
11361 * {@link updateSurface} after all windows are examined.
11362 */
11363 void updateParameters(WindowState w, long currentTime) {
11364 mDimSurface.setLayer(w.mAnimLayer-1);
11365
11366 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011367 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011368 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011369 if (mDimTargetAlpha != target) {
11370 // If the desired dim level has changed, then
11371 // start an animation to it.
11372 mLastDimAnimTime = currentTime;
11373 long duration = (w.mAnimating && w.mAnimation != null)
11374 ? w.mAnimation.computeDurationHint()
11375 : DEFAULT_DIM_DURATION;
11376 if (target > mDimTargetAlpha) {
11377 // This is happening behind the activity UI,
11378 // so we can make it run a little longer to
11379 // give a stronger impression without disrupting
11380 // the user.
11381 duration *= DIM_DURATION_MULTIPLIER;
11382 }
11383 if (duration < 1) {
11384 // Don't divide by zero
11385 duration = 1;
11386 }
11387 mDimTargetAlpha = target;
11388 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11389 }
11390 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011391
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011392 /**
11393 * Updating the surface's alpha. Returns true if the animation continues, or returns
11394 * false when the animation is finished and the dim surface is hidden.
11395 */
11396 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11397 if (!dimming) {
11398 if (mDimTargetAlpha != 0) {
11399 mLastDimAnimTime = currentTime;
11400 mDimTargetAlpha = 0;
11401 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11402 }
11403 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011404
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011405 boolean animating = false;
11406 if (mLastDimAnimTime != 0) {
11407 mDimCurrentAlpha += mDimDeltaPerMs
11408 * (currentTime-mLastDimAnimTime);
11409 boolean more = true;
11410 if (displayFrozen) {
11411 // If the display is frozen, there is no reason to animate.
11412 more = false;
11413 } else if (mDimDeltaPerMs > 0) {
11414 if (mDimCurrentAlpha > mDimTargetAlpha) {
11415 more = false;
11416 }
11417 } else if (mDimDeltaPerMs < 0) {
11418 if (mDimCurrentAlpha < mDimTargetAlpha) {
11419 more = false;
11420 }
11421 } else {
11422 more = false;
11423 }
11424
11425 // Do we need to continue animating?
11426 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011427 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011428 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11429 mLastDimAnimTime = currentTime;
11430 mDimSurface.setAlpha(mDimCurrentAlpha);
11431 animating = true;
11432 } else {
11433 mDimCurrentAlpha = mDimTargetAlpha;
11434 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011435 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011436 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11437 mDimSurface.setAlpha(mDimCurrentAlpha);
11438 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011439 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011440 + ": HIDE");
11441 try {
11442 mDimSurface.hide();
11443 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011444 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011445 }
11446 mDimShown = false;
11447 }
11448 }
11449 }
11450 return animating;
11451 }
11452
11453 public void printTo(PrintWriter pw) {
11454 pw.print(" mDimShown="); pw.print(mDimShown);
11455 pw.print(" current="); pw.print(mDimCurrentAlpha);
11456 pw.print(" target="); pw.print(mDimTargetAlpha);
11457 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11458 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11459 }
11460 }
11461
11462 /**
11463 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11464 * This is used for opening/closing transition for apps in compatible mode.
11465 */
11466 private static class FadeInOutAnimation extends Animation {
11467 int mWidth;
11468 boolean mFadeIn;
11469
11470 public FadeInOutAnimation(boolean fadeIn) {
11471 setInterpolator(new AccelerateInterpolator());
11472 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11473 mFadeIn = fadeIn;
11474 }
11475
11476 @Override
11477 protected void applyTransformation(float interpolatedTime, Transformation t) {
11478 float x = interpolatedTime;
11479 if (!mFadeIn) {
11480 x = 1.0f - x; // reverse the interpolation for fade out
11481 }
11482 if (x < 0.5) {
11483 // move the window out of the screen.
11484 t.getMatrix().setTranslate(mWidth, 0);
11485 } else {
11486 t.getMatrix().setTranslate(0, 0);// show
11487 t.setAlpha((x - 0.5f) * 2);
11488 }
11489 }
11490
11491 @Override
11492 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11493 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11494 mWidth = width;
11495 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011496
11497 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011498 public int getZAdjustment() {
11499 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011500 }
11501 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011502}