blob: 9cc73aaea1d00b607fb99f0e362ce181d7eb1947 [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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700152 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700153 static final boolean MEASURE_LATENCY = false;
154 static private LatencyTimer lt;
155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 static final boolean PROFILE_ORIENTATION = false;
157 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700158 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 /** How long to wait for subsequent key repeats, in milliseconds */
161 static final int KEY_REPEAT_DELAY = 50;
162
163 /** How much to multiply the policy's type layer, to reserve room
164 * for multiple windows of the same type and Z-ordering adjustment
165 * with TYPE_LAYER_OFFSET. */
166 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
169 * or below others in the same layer. */
170 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 /** How much to increment the layer for each window, to reserve room
173 * for effect surfaces between them.
174 */
175 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 /** The maximum length we will accept for a loaded animation duration:
178 * this is 10 seconds.
179 */
180 static final int MAX_ANIMATION_DURATION = 10*1000;
181
182 /** Amount of time (in milliseconds) to animate the dim surface from one
183 * value to another, when no window animation is driving it.
184 */
185 static final int DEFAULT_DIM_DURATION = 200;
186
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700187 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
188 * compatible windows.
189 */
190 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192 /** Adjustment to time to perform a dim, to make it more dramatic.
193 */
194 static final int DIM_DURATION_MULTIPLIER = 6;
Romain Guy06882f82009-06-10 13:36:04 -0700195
Dianne Hackborncfaef692009-06-15 14:24:44 -0700196 static final int INJECT_FAILED = 0;
197 static final int INJECT_SUCCEEDED = 1;
198 static final int INJECT_NO_PERMISSION = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 static final int UPDATE_FOCUS_NORMAL = 0;
201 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
202 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
203 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700204
Michael Chane96440f2009-05-06 10:27:36 -0700205 /** The minimum time between dispatching touch events. */
206 int mMinWaitTimeBetweenTouchEvents = 1000 / 35;
207
208 // Last touch event time
209 long mLastTouchEventTime = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700210
Michael Chane96440f2009-05-06 10:27:36 -0700211 // Last touch event type
212 int mLastTouchEventType = OTHER_EVENT;
Romain Guy06882f82009-06-10 13:36:04 -0700213
Michael Chane96440f2009-05-06 10:27:36 -0700214 // Time to wait before calling useractivity again. This saves CPU usage
215 // when we get a flood of touch events.
216 static final int MIN_TIME_BETWEEN_USERACTIVITIES = 1000;
217
218 // Last time we call user activity
219 long mLastUserActivityCallTime = 0;
220
Romain Guy06882f82009-06-10 13:36:04 -0700221 // Last time we updated battery stats
Michael Chane96440f2009-05-06 10:27:36 -0700222 long mLastBatteryStatsCallTime = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700225 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226
227 /**
228 * Condition waited on by {@link #reenableKeyguard} to know the call to
229 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500230 * This is set to true only if mKeyguardTokenWatcher.acquired() has
231 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500233 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800234
Mike Lockwood983ee092009-11-22 01:42:24 -0500235 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
236 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 public void acquired() {
238 mPolicy.enableKeyguard(false);
Mike Lockwood983ee092009-11-22 01:42:24 -0500239 mKeyguardDisabled = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240 }
241 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700242 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500243 synchronized (mKeyguardTokenWatcher) {
244 mKeyguardDisabled = false;
245 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 }
247 }
248 };
249
250 final Context mContext;
251
252 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
257
258 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 /**
263 * All currently active sessions with clients.
264 */
265 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 /**
268 * Mapping from an IWindow IBinder to the server's Window object.
269 * This is also used as the lock for all of our state.
270 */
271 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
272
273 /**
274 * Mapping from a token IBinder to a WindowToken object.
275 */
276 final HashMap<IBinder, WindowToken> mTokenMap =
277 new HashMap<IBinder, WindowToken>();
278
279 /**
280 * The same tokens as mTokenMap, stored in a list for efficient iteration
281 * over them.
282 */
283 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 /**
286 * Window tokens that are in the process of exiting, but still
287 * on screen for animations.
288 */
289 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
290
291 /**
292 * Z-ordered (bottom-most first) list of all application tokens, for
293 * controlling the ordering of windows in different applications. This
294 * contains WindowToken objects.
295 */
296 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
297
298 /**
299 * Application tokens that are in the process of exiting, but still
300 * on screen for animations.
301 */
302 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
303
304 /**
305 * List of window tokens that have finished starting their application,
306 * and now need to have the policy remove their windows.
307 */
308 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
309
310 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700311 * This was the app token that was used to retrieve the last enter
312 * animation. It will be used for the next exit animation.
313 */
314 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800315
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700316 /**
317 * These were the layout params used to retrieve the last enter animation.
318 * They will be used for the next exit animation.
319 */
320 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800321
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700322 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 * Z-ordered (bottom-most first) list of all Window objects.
324 */
325 final ArrayList mWindows = new ArrayList();
326
327 /**
328 * Windows that are being resized. Used so we can tell the client about
329 * the resize after closing the transaction in which we resized the
330 * underlying surface.
331 */
332 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
333
334 /**
335 * Windows whose animations have ended and now must be removed.
336 */
337 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
338
339 /**
340 * Windows whose surface should be destroyed.
341 */
342 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
343
344 /**
345 * Windows that have lost input focus and are waiting for the new
346 * focus window to be displayed before they are told about this.
347 */
348 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
349
350 /**
351 * This is set when we have run out of memory, and will either be an empty
352 * list or contain windows that need to be force removed.
353 */
354 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700359 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 Surface mBlurSurface;
361 boolean mBlurShown;
Romain Guy06882f82009-06-10 13:36:04 -0700362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 final float[] mTmpFloats = new float[9];
366
367 boolean mSafeMode;
368 boolean mDisplayEnabled = false;
369 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700370 int mInitialDisplayWidth = 0;
371 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 int mRotation = 0;
373 int mRequestedRotation = 0;
374 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700375 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 ArrayList<IRotationWatcher> mRotationWatchers
377 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 boolean mLayoutNeeded = true;
380 boolean mAnimationPending = false;
381 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800382 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 boolean mWindowsFreezingScreen = false;
384 long mFreezeGcPending = 0;
385 int mAppsFreezingScreen = 0;
386
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800387 int mLayoutSeq = 0;
388
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800389 // State while inside of layoutAndPlaceSurfacesLocked().
390 boolean mFocusMayChange;
391
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800392 Configuration mCurConfiguration = new Configuration();
393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 // This is held as long as we have the screen frozen, to give us time to
395 // perform a rotation animation when turning off shows the lock screen which
396 // changes the orientation.
397 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 // State management of app transitions. When we are preparing for a
400 // transition, mNextAppTransition will be the kind of transition to
401 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
402 // mOpeningApps and mClosingApps are the lists of tokens that will be
403 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700404 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700405 String mNextAppTransitionPackage;
406 int mNextAppTransitionEnter;
407 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800408 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700409 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 boolean mAppTransitionTimeout = false;
411 boolean mStartingIconInTransition = false;
412 boolean mSkipAppTransitionAnimation = false;
413 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
414 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700415 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
416 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 //flag to detect fat touch events
419 boolean mFatTouch = false;
420 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 H mH = new H();
423
424 WindowState mCurrentFocus = null;
425 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 // This just indicates the window the input method is on top of, not
428 // necessarily the window its input is going to.
429 WindowState mInputMethodTarget = null;
430 WindowState mUpcomingInputMethodTarget = null;
431 boolean mInputMethodTargetWaitingAnim;
432 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 WindowState mInputMethodWindow = null;
435 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
436
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700437 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800438
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700439 // If non-null, this is the currently visible window that is associated
440 // with the wallpaper.
441 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700442 // If non-null, we are in the middle of animating from one wallpaper target
443 // to another, and this is the lower one in Z-order.
444 WindowState mLowerWallpaperTarget = null;
445 // If non-null, we are in the middle of animating from one wallpaper target
446 // to another, and this is the higher one in Z-order.
447 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700448 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700449 float mLastWallpaperX = -1;
450 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800451 float mLastWallpaperXStep = -1;
452 float mLastWallpaperYStep = -1;
Dianne Hackborn6adba242009-11-10 11:10:09 -0800453 boolean mSendingPointersToWallpaper = false;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700454 // This is set when we are waiting for a wallpaper to tell us it is done
455 // changing its scroll position.
456 WindowState mWaitingOnWallpaper;
457 // The last time we had a timeout when waiting for a wallpaper.
458 long mLastWallpaperTimeoutTime;
459 // We give a wallpaper up to 150ms to finish scrolling.
460 static final long WALLPAPER_TIMEOUT = 150;
461 // Time we wait after a timeout before trying to wait again.
462 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800464 AppWindowToken mFocusedApp = null;
465
466 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468 float mWindowAnimationScale = 1.0f;
469 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 final KeyWaiter mKeyWaiter = new KeyWaiter();
472 final KeyQ mQueue;
473 final InputDispatcherThread mInputThread;
474
475 // Who is holding the screen on.
476 Session mHoldingScreenOn;
Romain Guy06882f82009-06-10 13:36:04 -0700477
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700478 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480 /**
481 * Whether the UI is currently running in touch mode (not showing
482 * navigational focus because the user is directly pressing the screen).
483 */
484 boolean mInTouchMode = false;
485
486 private ViewServer mViewServer;
487
488 final Rect mTempRect = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -0700489
Dianne Hackbornc485a602009-03-24 22:39:49 -0700490 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700491 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700492
493 // The frame use to limit the size of the app running in compatibility mode.
494 Rect mCompatibleScreenFrame = new Rect();
495 // The surface used to fill the outer rim of the app running in compatibility mode.
496 Surface mBackgroundFillerSurface = null;
497 boolean mBackgroundFillerShown = false;
498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800499 public static WindowManagerService main(Context context,
500 PowerManagerService pm, boolean haveInputMethods) {
501 WMThread thr = new WMThread(context, pm, haveInputMethods);
502 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 synchronized (thr) {
505 while (thr.mService == null) {
506 try {
507 thr.wait();
508 } catch (InterruptedException e) {
509 }
510 }
511 }
Romain Guy06882f82009-06-10 13:36:04 -0700512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 return thr.mService;
514 }
Romain Guy06882f82009-06-10 13:36:04 -0700515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 static class WMThread extends Thread {
517 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519 private final Context mContext;
520 private final PowerManagerService mPM;
521 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523 public WMThread(Context context, PowerManagerService pm,
524 boolean haveInputMethods) {
525 super("WindowManager");
526 mContext = context;
527 mPM = pm;
528 mHaveInputMethods = haveInputMethods;
529 }
Romain Guy06882f82009-06-10 13:36:04 -0700530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 public void run() {
532 Looper.prepare();
533 WindowManagerService s = new WindowManagerService(mContext, mPM,
534 mHaveInputMethods);
535 android.os.Process.setThreadPriority(
536 android.os.Process.THREAD_PRIORITY_DISPLAY);
Romain Guy06882f82009-06-10 13:36:04 -0700537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538 synchronized (this) {
539 mService = s;
540 notifyAll();
541 }
Romain Guy06882f82009-06-10 13:36:04 -0700542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 Looper.loop();
544 }
545 }
546
547 static class PolicyThread extends Thread {
548 private final WindowManagerPolicy mPolicy;
549 private final WindowManagerService mService;
550 private final Context mContext;
551 private final PowerManagerService mPM;
552 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 public PolicyThread(WindowManagerPolicy policy,
555 WindowManagerService service, Context context,
556 PowerManagerService pm) {
557 super("WindowManagerPolicy");
558 mPolicy = policy;
559 mService = service;
560 mContext = context;
561 mPM = pm;
562 }
Romain Guy06882f82009-06-10 13:36:04 -0700563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 public void run() {
565 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800566 WindowManagerPolicyThread.set(this, Looper.myLooper());
567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800569 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 android.os.Process.setThreadPriority(
571 android.os.Process.THREAD_PRIORITY_FOREGROUND);
572 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 synchronized (this) {
575 mRunning = true;
576 notifyAll();
577 }
Romain Guy06882f82009-06-10 13:36:04 -0700578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 Looper.loop();
580 }
581 }
582
583 private WindowManagerService(Context context, PowerManagerService pm,
584 boolean haveInputMethods) {
Michael Chan53071d62009-05-13 17:29:48 -0700585 if (MEASURE_LATENCY) {
586 lt = new LatencyTimer(100, 1000);
587 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 mContext = context;
590 mHaveInputMethods = haveInputMethods;
591 mLimitedAlphaCompositing = context.getResources().getBoolean(
592 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 mPowerManager = pm;
595 mPowerManager.setPolicy(mPolicy);
596 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
597 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
598 "SCREEN_FROZEN");
599 mScreenFrozenLock.setReferenceCounted(false);
600
601 mActivityManager = ActivityManagerNative.getDefault();
602 mBatteryStats = BatteryStatsService.getService();
603
604 // Get persisted window scale setting
605 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
606 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
607 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
608 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700609
Michael Chan9f028e62009-08-04 17:37:46 -0700610 int max_events_per_sec = 35;
611 try {
612 max_events_per_sec = Integer.parseInt(SystemProperties
613 .get("windowsmgr.max_events_per_sec"));
614 if (max_events_per_sec < 1) {
615 max_events_per_sec = 35;
616 }
617 } catch (NumberFormatException e) {
618 }
619 mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec;
620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 mQueue = new KeyQ();
622
623 mInputThread = new InputDispatcherThread();
Romain Guy06882f82009-06-10 13:36:04 -0700624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
626 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800628 synchronized (thr) {
629 while (!thr.mRunning) {
630 try {
631 thr.wait();
632 } catch (InterruptedException e) {
633 }
634 }
635 }
Romain Guy06882f82009-06-10 13:36:04 -0700636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637 mInputThread.start();
Romain Guy06882f82009-06-10 13:36:04 -0700638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 // Add ourself to the Watchdog monitors.
640 Watchdog.getInstance().addMonitor(this);
641 }
642
643 @Override
644 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
645 throws RemoteException {
646 try {
647 return super.onTransact(code, data, reply, flags);
648 } catch (RuntimeException e) {
649 // The window manager only throws security exceptions, so let's
650 // log all others.
651 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800652 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653 }
654 throw e;
655 }
656 }
657
658 private void placeWindowAfter(Object pos, WindowState window) {
659 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800660 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800661 TAG, "Adding window " + window + " at "
662 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
663 mWindows.add(i+1, window);
664 }
665
666 private void placeWindowBefore(Object pos, WindowState window) {
667 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800668 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669 TAG, "Adding window " + window + " at "
670 + i + " of " + mWindows.size() + " (before " + pos + ")");
671 mWindows.add(i, window);
672 }
673
674 //This method finds out the index of a window that has the same app token as
675 //win. used for z ordering the windows in mWindows
676 private int findIdxBasedOnAppTokens(WindowState win) {
677 //use a local variable to cache mWindows
678 ArrayList localmWindows = mWindows;
679 int jmax = localmWindows.size();
680 if(jmax == 0) {
681 return -1;
682 }
683 for(int j = (jmax-1); j >= 0; j--) {
684 WindowState wentry = (WindowState)localmWindows.get(j);
685 if(wentry.mAppToken == win.mAppToken) {
686 return j;
687 }
688 }
689 return -1;
690 }
Romain Guy06882f82009-06-10 13:36:04 -0700691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
693 final IWindow client = win.mClient;
694 final WindowToken token = win.mToken;
695 final ArrayList localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800697 final int N = localmWindows.size();
698 final WindowState attached = win.mAttachedWindow;
699 int i;
700 if (attached == null) {
701 int tokenWindowsPos = token.windows.size();
702 if (token.appWindowToken != null) {
703 int index = tokenWindowsPos-1;
704 if (index >= 0) {
705 // If this application has existing windows, we
706 // simply place the new window on top of them... but
707 // keep the starting window on top.
708 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
709 // Base windows go behind everything else.
710 placeWindowBefore(token.windows.get(0), win);
711 tokenWindowsPos = 0;
712 } else {
713 AppWindowToken atoken = win.mAppToken;
714 if (atoken != null &&
715 token.windows.get(index) == atoken.startingWindow) {
716 placeWindowBefore(token.windows.get(index), win);
717 tokenWindowsPos--;
718 } else {
719 int newIdx = findIdxBasedOnAppTokens(win);
720 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700721 //there is a window above this one associated with the same
722 //apptoken note that the window could be a floating window
723 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800724 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800725 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700726 TAG, "Adding window " + win + " at "
727 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800728 localmWindows.add(newIdx+1, win);
Romain Guy06882f82009-06-10 13:36:04 -0700729 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800730 }
731 }
732 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800733 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800734 TAG, "Figuring out where to add app window "
735 + client.asBinder() + " (token=" + token + ")");
736 // Figure out where the window should go, based on the
737 // order of applications.
738 final int NA = mAppTokens.size();
739 Object pos = null;
740 for (i=NA-1; i>=0; i--) {
741 AppWindowToken t = mAppTokens.get(i);
742 if (t == token) {
743 i--;
744 break;
745 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800746
Dianne Hackborna8f60182009-09-01 19:01:50 -0700747 // We haven't reached the token yet; if this token
748 // is not going to the bottom and has windows, we can
749 // use it as an anchor for when we do reach the token.
750 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 pos = t.windows.get(0);
752 }
753 }
754 // We now know the index into the apps. If we found
755 // an app window above, that gives us the position; else
756 // we need to look some more.
757 if (pos != null) {
758 // Move behind any windows attached to this one.
Romain Guy06882f82009-06-10 13:36:04 -0700759 WindowToken atoken =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800760 mTokenMap.get(((WindowState)pos).mClient.asBinder());
761 if (atoken != null) {
762 final int NC = atoken.windows.size();
763 if (NC > 0) {
764 WindowState bottom = atoken.windows.get(0);
765 if (bottom.mSubLayer < 0) {
766 pos = bottom;
767 }
768 }
769 }
770 placeWindowBefore(pos, win);
771 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700772 // Continue looking down until we find the first
773 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 while (i >= 0) {
775 AppWindowToken t = mAppTokens.get(i);
776 final int NW = t.windows.size();
777 if (NW > 0) {
778 pos = t.windows.get(NW-1);
779 break;
780 }
781 i--;
782 }
783 if (pos != null) {
784 // Move in front of any windows attached to this
785 // one.
786 WindowToken atoken =
787 mTokenMap.get(((WindowState)pos).mClient.asBinder());
788 if (atoken != null) {
789 final int NC = atoken.windows.size();
790 if (NC > 0) {
791 WindowState top = atoken.windows.get(NC-1);
792 if (top.mSubLayer >= 0) {
793 pos = top;
794 }
795 }
796 }
797 placeWindowAfter(pos, win);
798 } else {
799 // Just search for the start of this layer.
800 final int myLayer = win.mBaseLayer;
801 for (i=0; i<N; i++) {
802 WindowState w = (WindowState)localmWindows.get(i);
803 if (w.mBaseLayer > myLayer) {
804 break;
805 }
806 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800807 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700808 TAG, "Adding window " + win + " at "
809 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800810 localmWindows.add(i, win);
811 }
812 }
813 }
814 } else {
815 // Figure out where window should go, based on layer.
816 final int myLayer = win.mBaseLayer;
817 for (i=N-1; i>=0; i--) {
818 if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) {
819 i++;
820 break;
821 }
822 }
823 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800824 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700825 TAG, "Adding window " + win + " at "
826 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800827 localmWindows.add(i, win);
828 }
829 if (addToToken) {
830 token.windows.add(tokenWindowsPos, win);
831 }
832
833 } else {
834 // Figure out this window's ordering relative to the window
835 // it is attached to.
836 final int NA = token.windows.size();
837 final int sublayer = win.mSubLayer;
838 int largestSublayer = Integer.MIN_VALUE;
839 WindowState windowWithLargestSublayer = null;
840 for (i=0; i<NA; i++) {
841 WindowState w = token.windows.get(i);
842 final int wSublayer = w.mSubLayer;
843 if (wSublayer >= largestSublayer) {
844 largestSublayer = wSublayer;
845 windowWithLargestSublayer = w;
846 }
847 if (sublayer < 0) {
848 // For negative sublayers, we go below all windows
849 // in the same sublayer.
850 if (wSublayer >= sublayer) {
851 if (addToToken) {
852 token.windows.add(i, win);
853 }
854 placeWindowBefore(
855 wSublayer >= 0 ? attached : w, win);
856 break;
857 }
858 } else {
859 // For positive sublayers, we go above all windows
860 // in the same sublayer.
861 if (wSublayer > sublayer) {
862 if (addToToken) {
863 token.windows.add(i, win);
864 }
865 placeWindowBefore(w, win);
866 break;
867 }
868 }
869 }
870 if (i >= NA) {
871 if (addToToken) {
872 token.windows.add(win);
873 }
874 if (sublayer < 0) {
875 placeWindowBefore(attached, win);
876 } else {
877 placeWindowAfter(largestSublayer >= 0
878 ? windowWithLargestSublayer
879 : attached,
880 win);
881 }
882 }
883 }
Romain Guy06882f82009-06-10 13:36:04 -0700884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800885 if (win.mAppToken != null && addToToken) {
886 win.mAppToken.allAppWindows.add(win);
887 }
888 }
Romain Guy06882f82009-06-10 13:36:04 -0700889
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800890 static boolean canBeImeTarget(WindowState w) {
891 final int fl = w.mAttrs.flags
892 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
893 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
894 return w.isVisibleOrAdding();
895 }
896 return false;
897 }
Romain Guy06882f82009-06-10 13:36:04 -0700898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800899 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
900 final ArrayList localmWindows = mWindows;
901 final int N = localmWindows.size();
902 WindowState w = null;
903 int i = N;
904 while (i > 0) {
905 i--;
906 w = (WindowState)localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700907
Joe Onorato8a9b2202010-02-26 18:56:32 -0800908 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800909 // + Integer.toHexString(w.mAttrs.flags));
910 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800911 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 // Yet more tricksyness! If this window is a "starting"
914 // window, we do actually want to be on top of it, but
915 // it is not -really- where input will go. So if the caller
916 // is not actually looking to move the IME, look down below
917 // for a real window to target...
918 if (!willMove
919 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
920 && i > 0) {
921 WindowState wb = (WindowState)localmWindows.get(i-1);
922 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
923 i--;
924 w = wb;
925 }
926 }
927 break;
928 }
929 }
Romain Guy06882f82009-06-10 13:36:04 -0700930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700932
Joe Onorato8a9b2202010-02-26 18:56:32 -0800933 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 if (willMove && w != null) {
937 final WindowState curTarget = mInputMethodTarget;
938 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 // Now some fun for dealing with window animations that
941 // modify the Z order. We need to look at all windows below
942 // the current target that are in this app, finding the highest
943 // visible one in layering.
944 AppWindowToken token = curTarget.mAppToken;
945 WindowState highestTarget = null;
946 int highestPos = 0;
947 if (token.animating || token.animation != null) {
948 int pos = 0;
949 pos = localmWindows.indexOf(curTarget);
950 while (pos >= 0) {
951 WindowState win = (WindowState)localmWindows.get(pos);
952 if (win.mAppToken != token) {
953 break;
954 }
955 if (!win.mRemoved) {
956 if (highestTarget == null || win.mAnimLayer >
957 highestTarget.mAnimLayer) {
958 highestTarget = win;
959 highestPos = pos;
960 }
961 }
962 pos--;
963 }
964 }
Romain Guy06882f82009-06-10 13:36:04 -0700965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800967 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800968 + mNextAppTransition + " " + highestTarget
969 + " animating=" + highestTarget.isAnimating()
970 + " layer=" + highestTarget.mAnimLayer
971 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700972
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700973 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800974 // If we are currently setting up for an animation,
975 // hold everything until we can find out what will happen.
976 mInputMethodTargetWaitingAnim = true;
977 mInputMethodTarget = highestTarget;
978 return highestPos + 1;
979 } else if (highestTarget.isAnimating() &&
980 highestTarget.mAnimLayer > w.mAnimLayer) {
981 // If the window we are currently targeting is involved
982 // with an animation, and it is on top of the next target
983 // we will be over, then hold off on moving until
984 // that is done.
985 mInputMethodTarget = highestTarget;
986 return highestPos + 1;
987 }
988 }
989 }
990 }
Romain Guy06882f82009-06-10 13:36:04 -0700991
Joe Onorato8a9b2202010-02-26 18:56:32 -0800992 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800993 if (w != null) {
994 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -0800995 if (DEBUG_INPUT_METHOD) {
996 RuntimeException e = null;
997 if (!HIDE_STACK_CRAWLS) {
998 e = new RuntimeException();
999 e.fillInStackTrace();
1000 }
1001 Slog.w(TAG, "Moving IM target from "
1002 + mInputMethodTarget + " to " + w, e);
1003 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001004 mInputMethodTarget = w;
1005 if (w.mAppToken != null) {
1006 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1007 } else {
1008 setInputMethodAnimLayerAdjustment(0);
1009 }
1010 }
1011 return i+1;
1012 }
1013 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001014 if (DEBUG_INPUT_METHOD) {
1015 RuntimeException e = null;
1016 if (!HIDE_STACK_CRAWLS) {
1017 e = new RuntimeException();
1018 e.fillInStackTrace();
1019 }
1020 Slog.w(TAG, "Moving IM target from "
1021 + mInputMethodTarget + " to null", e);
1022 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001023 mInputMethodTarget = null;
1024 setInputMethodAnimLayerAdjustment(0);
1025 }
1026 return -1;
1027 }
Romain Guy06882f82009-06-10 13:36:04 -07001028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001029 void addInputMethodWindowToListLocked(WindowState win) {
1030 int pos = findDesiredInputMethodWindowIndexLocked(true);
1031 if (pos >= 0) {
1032 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001033 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001034 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035 mWindows.add(pos, win);
1036 moveInputMethodDialogsLocked(pos+1);
1037 return;
1038 }
1039 win.mTargetAppToken = null;
1040 addWindowToListInOrderLocked(win, true);
1041 moveInputMethodDialogsLocked(pos);
1042 }
Romain Guy06882f82009-06-10 13:36:04 -07001043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001045 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 mInputMethodAnimLayerAdjustment = adj;
1047 WindowState imw = mInputMethodWindow;
1048 if (imw != null) {
1049 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001050 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 + " anim layer: " + imw.mAnimLayer);
1052 int wi = imw.mChildWindows.size();
1053 while (wi > 0) {
1054 wi--;
1055 WindowState cw = (WindowState)imw.mChildWindows.get(wi);
1056 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001057 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 + " anim layer: " + cw.mAnimLayer);
1059 }
1060 }
1061 int di = mInputMethodDialogs.size();
1062 while (di > 0) {
1063 di --;
1064 imw = mInputMethodDialogs.get(di);
1065 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001066 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 + " anim layer: " + imw.mAnimLayer);
1068 }
1069 }
Romain Guy06882f82009-06-10 13:36:04 -07001070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1072 int wpos = mWindows.indexOf(win);
1073 if (wpos >= 0) {
1074 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001075 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001076 mWindows.remove(wpos);
1077 int NC = win.mChildWindows.size();
1078 while (NC > 0) {
1079 NC--;
1080 WindowState cw = (WindowState)win.mChildWindows.get(NC);
1081 int cpos = mWindows.indexOf(cw);
1082 if (cpos >= 0) {
1083 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001084 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001085 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 mWindows.remove(cpos);
1087 }
1088 }
1089 }
1090 return interestingPos;
1091 }
Romain Guy06882f82009-06-10 13:36:04 -07001092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 private void reAddWindowToListInOrderLocked(WindowState win) {
1094 addWindowToListInOrderLocked(win, false);
1095 // This is a hack to get all of the child windows added as well
1096 // at the right position. Child windows should be rare and
1097 // this case should be rare, so it shouldn't be that big a deal.
1098 int wpos = mWindows.indexOf(win);
1099 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001100 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001101 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001102 mWindows.remove(wpos);
1103 reAddWindowLocked(wpos, win);
1104 }
1105 }
Romain Guy06882f82009-06-10 13:36:04 -07001106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 void logWindowList(String prefix) {
1108 int N = mWindows.size();
1109 while (N > 0) {
1110 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001111 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001112 }
1113 }
Romain Guy06882f82009-06-10 13:36:04 -07001114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 void moveInputMethodDialogsLocked(int pos) {
1116 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001118 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001119 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 for (int i=0; i<N; i++) {
1121 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1122 }
1123 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001124 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001125 logWindowList(" ");
1126 }
Romain Guy06882f82009-06-10 13:36:04 -07001127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128 if (pos >= 0) {
1129 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1130 if (pos < mWindows.size()) {
1131 WindowState wp = (WindowState)mWindows.get(pos);
1132 if (wp == mInputMethodWindow) {
1133 pos++;
1134 }
1135 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001136 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001137 for (int i=0; i<N; i++) {
1138 WindowState win = dialogs.get(i);
1139 win.mTargetAppToken = targetAppToken;
1140 pos = reAddWindowLocked(pos, win);
1141 }
1142 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001143 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001144 logWindowList(" ");
1145 }
1146 return;
1147 }
1148 for (int i=0; i<N; i++) {
1149 WindowState win = dialogs.get(i);
1150 win.mTargetAppToken = null;
1151 reAddWindowToListInOrderLocked(win);
1152 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001153 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154 logWindowList(" ");
1155 }
1156 }
1157 }
Romain Guy06882f82009-06-10 13:36:04 -07001158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1160 final WindowState imWin = mInputMethodWindow;
1161 final int DN = mInputMethodDialogs.size();
1162 if (imWin == null && DN == 0) {
1163 return false;
1164 }
Romain Guy06882f82009-06-10 13:36:04 -07001165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1167 if (imPos >= 0) {
1168 // In this case, the input method windows are to be placed
1169 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001171 // First check to see if the input method windows are already
1172 // located here, and contiguous.
1173 final int N = mWindows.size();
1174 WindowState firstImWin = imPos < N
1175 ? (WindowState)mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001177 // Figure out the actual input method window that should be
1178 // at the bottom of their stack.
1179 WindowState baseImWin = imWin != null
1180 ? imWin : mInputMethodDialogs.get(0);
1181 if (baseImWin.mChildWindows.size() > 0) {
1182 WindowState cw = (WindowState)baseImWin.mChildWindows.get(0);
1183 if (cw.mSubLayer < 0) baseImWin = cw;
1184 }
Romain Guy06882f82009-06-10 13:36:04 -07001185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186 if (firstImWin == baseImWin) {
1187 // The windows haven't moved... but are they still contiguous?
1188 // First find the top IM window.
1189 int pos = imPos+1;
1190 while (pos < N) {
1191 if (!((WindowState)mWindows.get(pos)).mIsImWindow) {
1192 break;
1193 }
1194 pos++;
1195 }
1196 pos++;
1197 // Now there should be no more input method windows above.
1198 while (pos < N) {
1199 if (((WindowState)mWindows.get(pos)).mIsImWindow) {
1200 break;
1201 }
1202 pos++;
1203 }
1204 if (pos >= N) {
1205 // All is good!
1206 return false;
1207 }
1208 }
Romain Guy06882f82009-06-10 13:36:04 -07001209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001210 if (imWin != null) {
1211 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001212 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001213 logWindowList(" ");
1214 }
1215 imPos = tmpRemoveWindowLocked(imPos, imWin);
1216 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001217 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001218 logWindowList(" ");
1219 }
1220 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1221 reAddWindowLocked(imPos, imWin);
1222 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001223 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 logWindowList(" ");
1225 }
1226 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1227 } else {
1228 moveInputMethodDialogsLocked(imPos);
1229 }
Romain Guy06882f82009-06-10 13:36:04 -07001230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001231 } else {
1232 // In this case, the input method windows go in a fixed layer,
1233 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001236 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001237 tmpRemoveWindowLocked(0, imWin);
1238 imWin.mTargetAppToken = null;
1239 reAddWindowToListInOrderLocked(imWin);
1240 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001241 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001242 logWindowList(" ");
1243 }
1244 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1245 } else {
1246 moveInputMethodDialogsLocked(-1);;
1247 }
Romain Guy06882f82009-06-10 13:36:04 -07001248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249 }
Romain Guy06882f82009-06-10 13:36:04 -07001250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001251 if (needAssignLayers) {
1252 assignLayersLocked();
1253 }
Romain Guy06882f82009-06-10 13:36:04 -07001254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001255 return true;
1256 }
Romain Guy06882f82009-06-10 13:36:04 -07001257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001258 void adjustInputMethodDialogsLocked() {
1259 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1260 }
Romain Guy06882f82009-06-10 13:36:04 -07001261
Dianne Hackborn25994b42009-09-04 14:21:19 -07001262 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001263 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001264 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1265 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1266 ? wallpaperTarget.mAppToken.animation : null)
1267 + " upper=" + mUpperWallpaperTarget
1268 + " lower=" + mLowerWallpaperTarget);
1269 return (wallpaperTarget != null
1270 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1271 && wallpaperTarget.mAppToken.animation != null)))
1272 || mUpperWallpaperTarget != null
1273 || mLowerWallpaperTarget != null;
1274 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001275
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001276 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1277 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001278
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001279 int adjustWallpaperWindowsLocked() {
1280 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001281
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001282 final int dw = mDisplay.getWidth();
1283 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001284
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001285 // First find top-most window that has asked to be on top of the
1286 // wallpaper; all wallpapers go behind it.
1287 final ArrayList localmWindows = mWindows;
1288 int N = localmWindows.size();
1289 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001290 WindowState foundW = null;
1291 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001292 WindowState topCurW = null;
1293 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001294 int i = N;
1295 while (i > 0) {
1296 i--;
1297 w = (WindowState)localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001298 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1299 if (topCurW == null) {
1300 topCurW = w;
1301 topCurI = i;
1302 }
1303 continue;
1304 }
1305 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001306 if (w.mAppToken != null) {
1307 // If this window's app token is hidden and not animating,
1308 // it is of no interest to us.
1309 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001310 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001311 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001312 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001313 continue;
1314 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001315 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001316 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001317 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1318 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001319 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001320 && (mWallpaperTarget == w
1321 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001322 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001323 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001324 foundW = w;
1325 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001326 if (w == mWallpaperTarget && ((w.mAppToken != null
1327 && w.mAppToken.animation != null)
1328 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001329 // The current wallpaper target is animating, so we'll
1330 // look behind it for another possible target and figure
1331 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001332 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001333 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001334 continue;
1335 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001336 break;
1337 }
1338 }
1339
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001340 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001341 // If we are currently waiting for an app transition, and either
1342 // the current target or the next target are involved with it,
1343 // then hold off on doing anything with the wallpaper.
1344 // Note that we are checking here for just whether the target
1345 // is part of an app token... which is potentially overly aggressive
1346 // (the app token may not be involved in the transition), but good
1347 // enough (we'll just wait until whatever transition is pending
1348 // executes).
1349 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001350 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001351 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001352 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001353 }
1354 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001355 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001356 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001357 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001358 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001359 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001360
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001361 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001362 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001363 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001364 + " oldTarget: " + mWallpaperTarget);
1365 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001366
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001367 mLowerWallpaperTarget = null;
1368 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001369
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001370 WindowState oldW = mWallpaperTarget;
1371 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001372
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001373 // Now what is happening... if the current and new targets are
1374 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001375 if (foundW != null && oldW != null) {
1376 boolean oldAnim = oldW.mAnimation != null
1377 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1378 boolean foundAnim = foundW.mAnimation != null
1379 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001380 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001381 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001382 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001383 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001384 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001385 int oldI = localmWindows.indexOf(oldW);
1386 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001387 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001388 }
1389 if (oldI >= 0) {
1390 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001391 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001392 + "=" + oldW + "; new#" + foundI
1393 + "=" + foundW);
1394 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001395
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001396 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001397 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001398 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001399 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001400 }
1401 mWallpaperTarget = oldW;
1402 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001403
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001404 // Now set the upper and lower wallpaper targets
1405 // correctly, and make sure that we are positioning
1406 // the wallpaper below the lower.
1407 if (foundI > oldI) {
1408 // The new target is on top of the old one.
1409 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001410 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001411 }
1412 mUpperWallpaperTarget = foundW;
1413 mLowerWallpaperTarget = oldW;
1414 foundW = oldW;
1415 foundI = oldI;
1416 } else {
1417 // The new target is below the old one.
1418 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001419 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001420 }
1421 mUpperWallpaperTarget = oldW;
1422 mLowerWallpaperTarget = foundW;
1423 }
1424 }
1425 }
1426 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001427
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001428 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001429 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001430 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1431 || (mLowerWallpaperTarget.mAppToken != null
1432 && mLowerWallpaperTarget.mAppToken.animation != null);
1433 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1434 || (mUpperWallpaperTarget.mAppToken != null
1435 && mUpperWallpaperTarget.mAppToken.animation != null);
1436 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001437 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001438 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001439 }
1440 mLowerWallpaperTarget = null;
1441 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001442 }
1443 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001444
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001445 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001446 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001447 // The window is visible to the compositor... but is it visible
1448 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001449 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001450 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001451
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001452 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001453 // its layer adjustment. Only do this if we are not transfering
1454 // between two wallpaper targets.
1455 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001456 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001457 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001458
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001459 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1460 * TYPE_LAYER_MULTIPLIER
1461 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001462
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001463 // Now w is the window we are supposed to be behind... but we
1464 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001465 // AND any starting window associated with it, AND below the
1466 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001467 while (foundI > 0) {
1468 WindowState wb = (WindowState)localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001469 if (wb.mBaseLayer < maxLayer &&
1470 wb.mAttachedWindow != foundW &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001471 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001472 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001473 // This window is not related to the previous one in any
1474 // interesting way, so stop here.
1475 break;
1476 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001477 foundW = wb;
1478 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001479 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001480 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001481 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001482 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001483
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001484 if (foundW == null && topCurW != null) {
1485 // There is no wallpaper target, so it goes at the bottom.
1486 // We will assume it is the same place as last time, if known.
1487 foundW = topCurW;
1488 foundI = topCurI+1;
1489 } else {
1490 // Okay i is the position immediately above the wallpaper. Look at
1491 // what is below it for later.
1492 foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null;
1493 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001494
Dianne Hackborn284ac932009-08-28 10:34:25 -07001495 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001496 if (mWallpaperTarget.mWallpaperX >= 0) {
1497 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001498 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001499 }
1500 if (mWallpaperTarget.mWallpaperY >= 0) {
1501 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001502 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001503 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001504 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001505
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001506 // Start stepping backwards from here, ensuring that our wallpaper windows
1507 // are correctly placed.
1508 int curTokenIndex = mWallpaperTokens.size();
1509 while (curTokenIndex > 0) {
1510 curTokenIndex--;
1511 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001512 if (token.hidden == visible) {
1513 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1514 token.hidden = !visible;
1515 // Need to do a layout to ensure the wallpaper now has the
1516 // correct size.
1517 mLayoutNeeded = true;
1518 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001519
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001520 int curWallpaperIndex = token.windows.size();
1521 while (curWallpaperIndex > 0) {
1522 curWallpaperIndex--;
1523 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001524
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001525 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001526 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001527 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001528
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001529 // First, make sure the client has the current visibility
1530 // state.
1531 if (wallpaper.mWallpaperVisible != visible) {
1532 wallpaper.mWallpaperVisible = visible;
1533 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001534 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001535 "Setting visibility of wallpaper " + wallpaper
1536 + ": " + visible);
1537 wallpaper.mClient.dispatchAppVisibility(visible);
1538 } catch (RemoteException e) {
1539 }
1540 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001541
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001542 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001543 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001544 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001545
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001546 // First, if this window is at the current index, then all
1547 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001548 if (wallpaper == foundW) {
1549 foundI--;
1550 foundW = foundI > 0
1551 ? (WindowState)localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001552 continue;
1553 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001554
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001555 // The window didn't match... the current wallpaper window,
1556 // wherever it is, is in the wrong place, so make sure it is
1557 // not in the list.
1558 int oldIndex = localmWindows.indexOf(wallpaper);
1559 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001560 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001561 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001562 localmWindows.remove(oldIndex);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001563 if (oldIndex < foundI) {
1564 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001565 }
1566 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001567
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001568 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001569 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001570 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001571 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001572
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001573 localmWindows.add(foundI, wallpaper);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001574 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001575 }
1576 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001577
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001578 return changed;
1579 }
1580
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001581 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001582 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001583 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001584 mWallpaperAnimLayerAdjustment = adj;
1585 int curTokenIndex = mWallpaperTokens.size();
1586 while (curTokenIndex > 0) {
1587 curTokenIndex--;
1588 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1589 int curWallpaperIndex = token.windows.size();
1590 while (curWallpaperIndex > 0) {
1591 curWallpaperIndex--;
1592 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1593 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001594 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001595 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001596 }
1597 }
1598 }
1599
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001600 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1601 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001602 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001603 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001604 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001605 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001606 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1607 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1608 changed = wallpaperWin.mXOffset != offset;
1609 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001610 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001611 + wallpaperWin + " x: " + offset);
1612 wallpaperWin.mXOffset = offset;
1613 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001614 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001615 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001616 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001617 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001618 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001619
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001620 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001621 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001622 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1623 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1624 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001625 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001626 + wallpaperWin + " y: " + offset);
1627 changed = true;
1628 wallpaperWin.mYOffset = offset;
1629 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001630 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001631 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001632 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001633 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001634 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001635
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001636 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001637 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001638 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001639 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1640 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001641 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001642 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001643 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001644 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001645 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1646 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001647 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001648 if (mWaitingOnWallpaper != null) {
1649 long start = SystemClock.uptimeMillis();
1650 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1651 < start) {
1652 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001653 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001654 "Waiting for offset complete...");
1655 mWindowMap.wait(WALLPAPER_TIMEOUT);
1656 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001657 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001658 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001659 if ((start+WALLPAPER_TIMEOUT)
1660 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001661 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001662 + wallpaperWin);
1663 mLastWallpaperTimeoutTime = start;
1664 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001665 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001666 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001667 }
1668 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001669 } catch (RemoteException e) {
1670 }
1671 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001672
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001673 return changed;
1674 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001675
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001676 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001677 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001678 if (mWaitingOnWallpaper != null &&
1679 mWaitingOnWallpaper.mClient.asBinder() == window) {
1680 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001681 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001682 }
1683 }
1684 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001685
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001686 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001687 final int dw = mDisplay.getWidth();
1688 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001689
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001690 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001691
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001692 WindowState target = mWallpaperTarget;
1693 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001694 if (target.mWallpaperX >= 0) {
1695 mLastWallpaperX = target.mWallpaperX;
1696 } else if (changingTarget.mWallpaperX >= 0) {
1697 mLastWallpaperX = changingTarget.mWallpaperX;
1698 }
1699 if (target.mWallpaperY >= 0) {
1700 mLastWallpaperY = target.mWallpaperY;
1701 } else if (changingTarget.mWallpaperY >= 0) {
1702 mLastWallpaperY = changingTarget.mWallpaperY;
1703 }
1704 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001705
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001706 int curTokenIndex = mWallpaperTokens.size();
1707 while (curTokenIndex > 0) {
1708 curTokenIndex--;
1709 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1710 int curWallpaperIndex = token.windows.size();
1711 while (curWallpaperIndex > 0) {
1712 curWallpaperIndex--;
1713 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1714 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1715 wallpaper.computeShownFrameLocked();
1716 changed = true;
1717 // We only want to be synchronous with one wallpaper.
1718 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001719 }
1720 }
1721 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001722
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001723 return changed;
1724 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001725
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001726 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001727 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001728 final int dw = mDisplay.getWidth();
1729 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001730
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001731 int curTokenIndex = mWallpaperTokens.size();
1732 while (curTokenIndex > 0) {
1733 curTokenIndex--;
1734 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001735 if (token.hidden == visible) {
1736 token.hidden = !visible;
1737 // Need to do a layout to ensure the wallpaper now has the
1738 // correct size.
1739 mLayoutNeeded = true;
1740 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001741
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001742 int curWallpaperIndex = token.windows.size();
1743 while (curWallpaperIndex > 0) {
1744 curWallpaperIndex--;
1745 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1746 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001747 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001748 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001749
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001750 if (wallpaper.mWallpaperVisible != visible) {
1751 wallpaper.mWallpaperVisible = visible;
1752 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001753 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001754 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001755 + ": " + visible);
1756 wallpaper.mClient.dispatchAppVisibility(visible);
1757 } catch (RemoteException e) {
1758 }
1759 }
1760 }
1761 }
1762 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001763
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001764 void sendPointerToWallpaperLocked(WindowState srcWin,
1765 MotionEvent pointer, long eventTime) {
1766 int curTokenIndex = mWallpaperTokens.size();
1767 while (curTokenIndex > 0) {
1768 curTokenIndex--;
1769 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1770 int curWallpaperIndex = token.windows.size();
1771 while (curWallpaperIndex > 0) {
1772 curWallpaperIndex--;
1773 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1774 if ((wallpaper.mAttrs.flags &
1775 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
1776 continue;
1777 }
1778 try {
1779 MotionEvent ev = MotionEvent.obtainNoHistory(pointer);
Dianne Hackborn6adba242009-11-10 11:10:09 -08001780 if (srcWin != null) {
1781 ev.offsetLocation(srcWin.mFrame.left-wallpaper.mFrame.left,
1782 srcWin.mFrame.top-wallpaper.mFrame.top);
1783 } else {
1784 ev.offsetLocation(-wallpaper.mFrame.left, -wallpaper.mFrame.top);
1785 }
1786 switch (pointer.getAction()) {
1787 case MotionEvent.ACTION_DOWN:
1788 mSendingPointersToWallpaper = true;
1789 break;
1790 case MotionEvent.ACTION_UP:
1791 mSendingPointersToWallpaper = false;
1792 break;
1793 }
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001794 wallpaper.mClient.dispatchPointer(ev, eventTime, false);
1795 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001796 Slog.w(TAG, "Failure sending pointer to wallpaper", e);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001797 }
1798 }
1799 }
1800 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001801
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001802 void dispatchPointerElsewhereLocked(WindowState srcWin, WindowState relWin,
1803 MotionEvent pointer, long eventTime, boolean skipped) {
1804 if (relWin != null) {
1805 mPolicy.dispatchedPointerEventLw(pointer, relWin.mFrame.left, relWin.mFrame.top);
1806 } else {
1807 mPolicy.dispatchedPointerEventLw(pointer, 0, 0);
1808 }
1809
1810 // If we sent an initial down to the wallpaper, then continue
1811 // sending events until the final up.
1812 if (mSendingPointersToWallpaper) {
1813 if (skipped) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001814 Slog.i(TAG, "Sending skipped pointer to wallpaper!");
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001815 }
1816 sendPointerToWallpaperLocked(relWin, pointer, eventTime);
1817
1818 // If we are on top of the wallpaper, then the wallpaper also
1819 // gets to see this movement.
1820 } else if (srcWin != null
1821 && pointer.getAction() == MotionEvent.ACTION_DOWN
1822 && mWallpaperTarget == srcWin
1823 && srcWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) {
1824 sendPointerToWallpaperLocked(relWin, pointer, eventTime);
1825 }
1826 }
1827
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001828 public int addWindow(Session session, IWindow client,
1829 WindowManager.LayoutParams attrs, int viewVisibility,
1830 Rect outContentInsets) {
1831 int res = mPolicy.checkAddPermission(attrs);
1832 if (res != WindowManagerImpl.ADD_OKAY) {
1833 return res;
1834 }
Romain Guy06882f82009-06-10 13:36:04 -07001835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001836 boolean reportNewConfig = false;
1837 WindowState attachedWindow = null;
1838 WindowState win = null;
Romain Guy06882f82009-06-10 13:36:04 -07001839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001840 synchronized(mWindowMap) {
1841 // Instantiating a Display requires talking with the simulator,
1842 // so don't do it until we know the system is mostly up and
1843 // running.
1844 if (mDisplay == null) {
1845 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1846 mDisplay = wm.getDefaultDisplay();
Christopher Tateb696aee2010-04-02 19:08:30 -07001847 mInitialDisplayWidth = mDisplay.getWidth();
1848 mInitialDisplayHeight = mDisplay.getHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001849 mQueue.setDisplay(mDisplay);
1850 reportNewConfig = true;
1851 }
Romain Guy06882f82009-06-10 13:36:04 -07001852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001853 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001854 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001855 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1856 }
1857
1858 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001859 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001860 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001861 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001862 + attrs.token + ". Aborting.");
1863 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1864 }
1865 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1866 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001867 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001868 + attrs.token + ". Aborting.");
1869 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1870 }
1871 }
1872
1873 boolean addToken = false;
1874 WindowToken token = mTokenMap.get(attrs.token);
1875 if (token == null) {
1876 if (attrs.type >= FIRST_APPLICATION_WINDOW
1877 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001878 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001879 + attrs.token + ". Aborting.");
1880 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1881 }
1882 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001883 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001884 + attrs.token + ". Aborting.");
1885 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1886 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001887 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001888 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001889 + attrs.token + ". Aborting.");
1890 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1891 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001892 token = new WindowToken(attrs.token, -1, false);
1893 addToken = true;
1894 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1895 && attrs.type <= LAST_APPLICATION_WINDOW) {
1896 AppWindowToken atoken = token.appWindowToken;
1897 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001898 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001899 + token + ". Aborting.");
1900 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1901 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001902 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001903 + token + ". Aborting.");
1904 return WindowManagerImpl.ADD_APP_EXITING;
1905 }
1906 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1907 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001908 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001909 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1910 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1911 }
1912 } else if (attrs.type == TYPE_INPUT_METHOD) {
1913 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001914 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001915 + attrs.token + ". Aborting.");
1916 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1917 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001918 } else if (attrs.type == TYPE_WALLPAPER) {
1919 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001920 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001921 + attrs.token + ". Aborting.");
1922 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1923 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001924 }
1925
1926 win = new WindowState(session, client, token,
1927 attachedWindow, attrs, viewVisibility);
1928 if (win.mDeathRecipient == null) {
1929 // Client has apparently died, so there is no reason to
1930 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001931 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001932 + " that is dead, aborting.");
1933 return WindowManagerImpl.ADD_APP_EXITING;
1934 }
1935
1936 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001938 res = mPolicy.prepareAddWindowLw(win, attrs);
1939 if (res != WindowManagerImpl.ADD_OKAY) {
1940 return res;
1941 }
1942
1943 // From now on, no exceptions or errors allowed!
1944
1945 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001947 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001949 if (addToken) {
1950 mTokenMap.put(attrs.token, token);
1951 mTokenList.add(token);
1952 }
1953 win.attach();
1954 mWindowMap.put(client.asBinder(), win);
1955
1956 if (attrs.type == TYPE_APPLICATION_STARTING &&
1957 token.appWindowToken != null) {
1958 token.appWindowToken.startingWindow = win;
1959 }
1960
1961 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001963 if (attrs.type == TYPE_INPUT_METHOD) {
1964 mInputMethodWindow = win;
1965 addInputMethodWindowToListLocked(win);
1966 imMayMove = false;
1967 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1968 mInputMethodDialogs.add(win);
1969 addWindowToListInOrderLocked(win, true);
1970 adjustInputMethodDialogsLocked();
1971 imMayMove = false;
1972 } else {
1973 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001974 if (attrs.type == TYPE_WALLPAPER) {
1975 mLastWallpaperTimeoutTime = 0;
1976 adjustWallpaperWindowsLocked();
1977 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001978 adjustWallpaperWindowsLocked();
1979 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001980 }
Romain Guy06882f82009-06-10 13:36:04 -07001981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001982 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001984 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001986 if (mInTouchMode) {
1987 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1988 }
1989 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1990 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1991 }
Romain Guy06882f82009-06-10 13:36:04 -07001992
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001993 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001994 if (win.canReceiveKeys()) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001995 if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS))
1996 == true) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001997 imMayMove = false;
1998 }
1999 }
Romain Guy06882f82009-06-10 13:36:04 -07002000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002002 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002003 }
Romain Guy06882f82009-06-10 13:36:04 -07002004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002005 assignLayersLocked();
2006 // Don't do layout here, the window must call
2007 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002009 //dump();
2010
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002011 if (focusChanged) {
2012 if (mCurrentFocus != null) {
2013 mKeyWaiter.handleNewWindowLocked(mCurrentFocus);
2014 }
2015 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002016 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002017 TAG, "New client " + client.asBinder()
2018 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002019
2020 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2021 reportNewConfig = true;
2022 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002023 }
2024
2025 // sendNewConfiguration() checks caller permissions so we must call it with
2026 // privilege. updateOrientationFromAppTokens() clears and resets the caller
2027 // identity anyway, so it's safe to just clear & restore around this whole
2028 // block.
2029 final long origId = Binder.clearCallingIdentity();
2030 if (reportNewConfig) {
2031 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002032 }
2033 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002035 return res;
2036 }
Romain Guy06882f82009-06-10 13:36:04 -07002037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002038 public void removeWindow(Session session, IWindow client) {
2039 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002040 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002041 if (win == null) {
2042 return;
2043 }
2044 removeWindowLocked(session, win);
2045 }
2046 }
Romain Guy06882f82009-06-10 13:36:04 -07002047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002048 public void removeWindowLocked(Session session, WindowState win) {
2049
Joe Onorato8a9b2202010-02-26 18:56:32 -08002050 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002051 TAG, "Remove " + win + " client="
2052 + Integer.toHexString(System.identityHashCode(
2053 win.mClient.asBinder()))
2054 + ", surface=" + win.mSurface);
2055
2056 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002057
Joe Onorato8a9b2202010-02-26 18:56:32 -08002058 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002059 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2060 + " mExiting=" + win.mExiting
2061 + " isAnimating=" + win.isAnimating()
2062 + " app-animation="
2063 + (win.mAppToken != null ? win.mAppToken.animation : null)
2064 + " inPendingTransaction="
2065 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2066 + " mDisplayFrozen=" + mDisplayFrozen);
2067 // Visibility of the removed window. Will be used later to update orientation later on.
2068 boolean wasVisible = false;
2069 // First, see if we need to run an animation. If we do, we have
2070 // to hold off on removing the window until the animation is done.
2071 // If the display is frozen, just remove immediately, since the
2072 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002073 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002074 // If we are not currently running the exit animation, we
2075 // need to see about starting one.
2076 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002078 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2079 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2080 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2081 }
2082 // Try starting an animation.
2083 if (applyAnimationLocked(win, transit, false)) {
2084 win.mExiting = true;
2085 }
2086 }
2087 if (win.mExiting || win.isAnimating()) {
2088 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002089 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002090 win.mExiting = true;
2091 win.mRemoveOnExit = true;
2092 mLayoutNeeded = true;
2093 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2094 performLayoutAndPlaceSurfacesLocked();
2095 if (win.mAppToken != null) {
2096 win.mAppToken.updateReportedVisibilityLocked();
2097 }
2098 //dump();
2099 Binder.restoreCallingIdentity(origId);
2100 return;
2101 }
2102 }
2103
2104 removeWindowInnerLocked(session, win);
2105 // Removing a visible window will effect the computed orientation
2106 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002107 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002108 != mForcedAppOrientation
2109 && updateOrientationFromAppTokensLocked()) {
2110 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002111 }
2112 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2113 Binder.restoreCallingIdentity(origId);
2114 }
Romain Guy06882f82009-06-10 13:36:04 -07002115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002116 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07002117 mKeyWaiter.finishedKey(session, win.mClient, true,
2118 KeyWaiter.RETURN_NOTHING);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002119 mKeyWaiter.releasePendingPointerLocked(win.mSession);
2120 mKeyWaiter.releasePendingTrackballLocked(win.mSession);
Romain Guy06882f82009-06-10 13:36:04 -07002121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002122 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002124 if (mInputMethodTarget == win) {
2125 moveInputMethodWindowsIfNeededLocked(false);
2126 }
Romain Guy06882f82009-06-10 13:36:04 -07002127
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002128 if (false) {
2129 RuntimeException e = new RuntimeException("here");
2130 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002131 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002132 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002134 mPolicy.removeWindowLw(win);
2135 win.removeLocked();
2136
2137 mWindowMap.remove(win.mClient.asBinder());
2138 mWindows.remove(win);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002139 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002140
2141 if (mInputMethodWindow == win) {
2142 mInputMethodWindow = null;
2143 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2144 mInputMethodDialogs.remove(win);
2145 }
Romain Guy06882f82009-06-10 13:36:04 -07002146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002147 final WindowToken token = win.mToken;
2148 final AppWindowToken atoken = win.mAppToken;
2149 token.windows.remove(win);
2150 if (atoken != null) {
2151 atoken.allAppWindows.remove(win);
2152 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002153 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002154 TAG, "**** Removing window " + win + ": count="
2155 + token.windows.size());
2156 if (token.windows.size() == 0) {
2157 if (!token.explicit) {
2158 mTokenMap.remove(token.token);
2159 mTokenList.remove(token);
2160 } else if (atoken != null) {
2161 atoken.firstWindowDrawn = false;
2162 }
2163 }
2164
2165 if (atoken != null) {
2166 if (atoken.startingWindow == win) {
2167 atoken.startingWindow = null;
2168 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2169 // If this is the last window and we had requested a starting
2170 // transition window, well there is no point now.
2171 atoken.startingData = null;
2172 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2173 // If this is the last window except for a starting transition
2174 // window, we need to get rid of the starting transition.
2175 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002176 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002177 + ": no more real windows");
2178 }
2179 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2180 mH.sendMessage(m);
2181 }
2182 }
Romain Guy06882f82009-06-10 13:36:04 -07002183
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002184 if (win.mAttrs.type == TYPE_WALLPAPER) {
2185 mLastWallpaperTimeoutTime = 0;
2186 adjustWallpaperWindowsLocked();
2187 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002188 adjustWallpaperWindowsLocked();
2189 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002191 if (!mInLayout) {
2192 assignLayersLocked();
2193 mLayoutNeeded = true;
2194 performLayoutAndPlaceSurfacesLocked();
2195 if (win.mAppToken != null) {
2196 win.mAppToken.updateReportedVisibilityLocked();
2197 }
2198 }
2199 }
2200
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002201 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2202 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2203 + ": " + msg + " / " + w.mAttrs.getTitle();
2204 if (where != null) {
2205 Slog.i(TAG, str, where);
2206 } else {
2207 Slog.i(TAG, str);
2208 }
2209 }
2210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002211 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2212 long origId = Binder.clearCallingIdentity();
2213 try {
2214 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002215 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002216 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002217 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002218 Surface.openTransaction();
2219 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002220 if (SHOW_TRANSACTIONS) logSurface(w,
2221 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002222 w.mSurface.setTransparentRegionHint(region);
2223 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002224 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002225 Surface.closeTransaction();
2226 }
2227 }
2228 }
2229 } finally {
2230 Binder.restoreCallingIdentity(origId);
2231 }
2232 }
2233
2234 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002235 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002236 Rect visibleInsets) {
2237 long origId = Binder.clearCallingIdentity();
2238 try {
2239 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002240 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002241 if (w != null) {
2242 w.mGivenInsetsPending = false;
2243 w.mGivenContentInsets.set(contentInsets);
2244 w.mGivenVisibleInsets.set(visibleInsets);
2245 w.mTouchableInsets = touchableInsets;
2246 mLayoutNeeded = true;
2247 performLayoutAndPlaceSurfacesLocked();
2248 }
2249 }
2250 } finally {
2251 Binder.restoreCallingIdentity(origId);
2252 }
2253 }
Romain Guy06882f82009-06-10 13:36:04 -07002254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002255 public void getWindowDisplayFrame(Session session, IWindow client,
2256 Rect outDisplayFrame) {
2257 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002258 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002259 if (win == null) {
2260 outDisplayFrame.setEmpty();
2261 return;
2262 }
2263 outDisplayFrame.set(win.mDisplayFrame);
2264 }
2265 }
2266
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002267 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2268 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002269 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2270 window.mWallpaperX = x;
2271 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002272 window.mWallpaperXStep = xStep;
2273 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002274 if (updateWallpaperOffsetLocked(window, true)) {
2275 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002276 }
2277 }
2278 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002279
Dianne Hackborn75804932009-10-20 20:15:20 -07002280 void wallpaperCommandComplete(IBinder window, Bundle result) {
2281 synchronized (mWindowMap) {
2282 if (mWaitingOnWallpaper != null &&
2283 mWaitingOnWallpaper.mClient.asBinder() == window) {
2284 mWaitingOnWallpaper = null;
2285 mWindowMap.notifyAll();
2286 }
2287 }
2288 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002289
Dianne Hackborn75804932009-10-20 20:15:20 -07002290 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2291 String action, int x, int y, int z, Bundle extras, boolean sync) {
2292 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2293 || window == mUpperWallpaperTarget) {
2294 boolean doWait = sync;
2295 int curTokenIndex = mWallpaperTokens.size();
2296 while (curTokenIndex > 0) {
2297 curTokenIndex--;
2298 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2299 int curWallpaperIndex = token.windows.size();
2300 while (curWallpaperIndex > 0) {
2301 curWallpaperIndex--;
2302 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2303 try {
2304 wallpaper.mClient.dispatchWallpaperCommand(action,
2305 x, y, z, extras, sync);
2306 // We only want to be synchronous with one wallpaper.
2307 sync = false;
2308 } catch (RemoteException e) {
2309 }
2310 }
2311 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002312
Dianne Hackborn75804932009-10-20 20:15:20 -07002313 if (doWait) {
2314 // XXX Need to wait for result.
2315 }
2316 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002317
Dianne Hackborn75804932009-10-20 20:15:20 -07002318 return null;
2319 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002321 public int relayoutWindow(Session session, IWindow client,
2322 WindowManager.LayoutParams attrs, int requestedWidth,
2323 int requestedHeight, int viewVisibility, boolean insetsPending,
2324 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002325 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002326 boolean displayed = false;
2327 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002328 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002329 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002331 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002332 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002333 if (win == null) {
2334 return 0;
2335 }
2336 win.mRequestedWidth = requestedWidth;
2337 win.mRequestedHeight = requestedHeight;
2338
2339 if (attrs != null) {
2340 mPolicy.adjustWindowParamsLw(attrs);
2341 }
Romain Guy06882f82009-06-10 13:36:04 -07002342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002343 int attrChanges = 0;
2344 int flagChanges = 0;
2345 if (attrs != null) {
2346 flagChanges = win.mAttrs.flags ^= attrs.flags;
2347 attrChanges = win.mAttrs.copyFrom(attrs);
2348 }
2349
Joe Onorato8a9b2202010-02-26 18:56:32 -08002350 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002351
2352 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2353 win.mAlpha = attrs.alpha;
2354 }
2355
2356 final boolean scaledWindow =
2357 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2358
2359 if (scaledWindow) {
2360 // requested{Width|Height} Surface's physical size
2361 // attrs.{width|height} Size on screen
2362 win.mHScale = (attrs.width != requestedWidth) ?
2363 (attrs.width / (float)requestedWidth) : 1.0f;
2364 win.mVScale = (attrs.height != requestedHeight) ?
2365 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002366 } else {
2367 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002368 }
2369
2370 boolean imMayMove = (flagChanges&(
2371 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2372 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002374 boolean focusMayChange = win.mViewVisibility != viewVisibility
2375 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2376 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002377
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002378 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2379 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002381 win.mRelayoutCalled = true;
2382 final int oldVisibility = win.mViewVisibility;
2383 win.mViewVisibility = viewVisibility;
2384 if (viewVisibility == View.VISIBLE &&
2385 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2386 displayed = !win.isVisibleLw();
2387 if (win.mExiting) {
2388 win.mExiting = false;
2389 win.mAnimation = null;
2390 }
2391 if (win.mDestroying) {
2392 win.mDestroying = false;
2393 mDestroySurface.remove(win);
2394 }
2395 if (oldVisibility == View.GONE) {
2396 win.mEnterAnimationPending = true;
2397 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002398 if (displayed) {
2399 if (win.mSurface != null && !win.mDrawPending
2400 && !win.mCommitDrawPending && !mDisplayFrozen
2401 && mPolicy.isScreenOn()) {
2402 applyEnterAnimationLocked(win);
2403 }
2404 if ((win.mAttrs.flags
2405 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2406 if (DEBUG_VISIBILITY) Slog.v(TAG,
2407 "Relayout window turning screen on: " + win);
2408 win.mTurnOnScreen = true;
2409 }
2410 int diff = 0;
2411 if (win.mConfiguration != mCurConfiguration
2412 && (win.mConfiguration == null
2413 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2414 win.mConfiguration = mCurConfiguration;
2415 if (DEBUG_CONFIGURATION) {
2416 Slog.i(TAG, "Window " + win + " visible with new config: "
2417 + win.mConfiguration + " / 0x"
2418 + Integer.toHexString(diff));
2419 }
2420 outConfig.setTo(mCurConfiguration);
2421 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002422 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002423 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2424 // To change the format, we need to re-build the surface.
2425 win.destroySurfaceLocked();
2426 displayed = true;
2427 }
2428 try {
2429 Surface surface = win.createSurfaceLocked();
2430 if (surface != null) {
2431 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002432 win.mReportDestroySurface = false;
2433 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002434 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002435 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002436 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002437 // For some reason there isn't a surface. Clear the
2438 // caller's object so they see the same state.
2439 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002440 }
2441 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002442 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002443 + client + " (" + win.mAttrs.getTitle() + ")",
2444 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002445 Binder.restoreCallingIdentity(origId);
2446 return 0;
2447 }
2448 if (displayed) {
2449 focusMayChange = true;
2450 }
2451 if (win.mAttrs.type == TYPE_INPUT_METHOD
2452 && mInputMethodWindow == null) {
2453 mInputMethodWindow = win;
2454 imMayMove = true;
2455 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002456 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2457 && win.mAppToken != null
2458 && win.mAppToken.startingWindow != null) {
2459 // Special handling of starting window over the base
2460 // window of the app: propagate lock screen flags to it,
2461 // to provide the correct semantics while starting.
2462 final int mask =
2463 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002464 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2465 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002466 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2467 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2468 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002469 } else {
2470 win.mEnterAnimationPending = false;
2471 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002472 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002473 + ": mExiting=" + win.mExiting
2474 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002475 // If we are not currently running the exit animation, we
2476 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002477 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002478 // Try starting an animation; if there isn't one, we
2479 // can destroy the surface right away.
2480 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2481 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2482 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2483 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002484 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002485 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002486 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 win.mExiting = true;
2488 mKeyWaiter.finishedKey(session, client, true,
2489 KeyWaiter.RETURN_NOTHING);
2490 } else if (win.isAnimating()) {
2491 // Currently in a hide animation... turn this into
2492 // an exit.
2493 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002494 } else if (win == mWallpaperTarget) {
2495 // If the wallpaper is currently behind this
2496 // window, we need to change both of them inside
2497 // of a transaction to avoid artifacts.
2498 win.mExiting = true;
2499 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002500 } else {
2501 if (mInputMethodWindow == win) {
2502 mInputMethodWindow = null;
2503 }
2504 win.destroySurfaceLocked();
2505 }
2506 }
2507 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002508
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002509 if (win.mSurface == null || (win.getAttrs().flags
2510 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2511 || win.mSurfacePendingDestroy) {
2512 // We are being called from a local process, which
2513 // means outSurface holds its current surface. Ensure the
2514 // surface object is cleared, but we don't want it actually
2515 // destroyed at this point.
2516 win.mSurfacePendingDestroy = false;
2517 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002518 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002519 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002520 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002521 "Keeping surface, will report destroy: " + win);
2522 win.mReportDestroySurface = true;
2523 outSurface.copyFrom(win.mSurface);
2524 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002525 }
2526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002527 if (focusMayChange) {
2528 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2529 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002530 imMayMove = false;
2531 }
2532 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2533 }
Romain Guy06882f82009-06-10 13:36:04 -07002534
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002535 // updateFocusedWindowLocked() already assigned layers so we only need to
2536 // reassign them at this point if the IM window state gets shuffled
2537 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002539 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002540 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2541 // Little hack here -- we -should- be able to rely on the
2542 // function to return true if the IME has moved and needs
2543 // its layer recomputed. However, if the IME was hidden
2544 // and isn't actually moved in the list, its layer may be
2545 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002546 assignLayers = true;
2547 }
2548 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002549 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002550 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002551 assignLayers = true;
2552 }
2553 }
Romain Guy06882f82009-06-10 13:36:04 -07002554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002555 mLayoutNeeded = true;
2556 win.mGivenInsetsPending = insetsPending;
2557 if (assignLayers) {
2558 assignLayersLocked();
2559 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002560 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002561 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002562 if (displayed && win.mIsWallpaper) {
2563 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002564 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002565 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002566 if (win.mAppToken != null) {
2567 win.mAppToken.updateReportedVisibilityLocked();
2568 }
2569 outFrame.set(win.mFrame);
2570 outContentInsets.set(win.mContentInsets);
2571 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002572 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002573 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002574 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002575 + ", requestedHeight=" + requestedHeight
2576 + ", viewVisibility=" + viewVisibility
2577 + "\nRelayout returning frame=" + outFrame
2578 + ", surface=" + outSurface);
2579
Joe Onorato8a9b2202010-02-26 18:56:32 -08002580 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002581 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2582
2583 inTouchMode = mInTouchMode;
2584 }
2585
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002586 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002587 sendNewConfiguration();
2588 }
Romain Guy06882f82009-06-10 13:36:04 -07002589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002590 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002592 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2593 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2594 }
2595
2596 public void finishDrawingWindow(Session session, IWindow client) {
2597 final long origId = Binder.clearCallingIdentity();
2598 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002599 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002600 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002601 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2602 adjustWallpaperWindowsLocked();
2603 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002604 mLayoutNeeded = true;
2605 performLayoutAndPlaceSurfacesLocked();
2606 }
2607 }
2608 Binder.restoreCallingIdentity(origId);
2609 }
2610
2611 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002612 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002613 + (lp != null ? lp.packageName : null)
2614 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2615 if (lp != null && lp.windowAnimations != 0) {
2616 // If this is a system resource, don't try to load it from the
2617 // application resources. It is nice to avoid loading application
2618 // resources if we can.
2619 String packageName = lp.packageName != null ? lp.packageName : "android";
2620 int resId = lp.windowAnimations;
2621 if ((resId&0xFF000000) == 0x01000000) {
2622 packageName = "android";
2623 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002624 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002625 + packageName);
2626 return AttributeCache.instance().get(packageName, resId,
2627 com.android.internal.R.styleable.WindowAnimation);
2628 }
2629 return null;
2630 }
Romain Guy06882f82009-06-10 13:36:04 -07002631
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002632 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002633 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002634 + packageName + " resId=0x" + Integer.toHexString(resId));
2635 if (packageName != null) {
2636 if ((resId&0xFF000000) == 0x01000000) {
2637 packageName = "android";
2638 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002639 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002640 + packageName);
2641 return AttributeCache.instance().get(packageName, resId,
2642 com.android.internal.R.styleable.WindowAnimation);
2643 }
2644 return null;
2645 }
2646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002647 private void applyEnterAnimationLocked(WindowState win) {
2648 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2649 if (win.mEnterAnimationPending) {
2650 win.mEnterAnimationPending = false;
2651 transit = WindowManagerPolicy.TRANSIT_ENTER;
2652 }
2653
2654 applyAnimationLocked(win, transit, true);
2655 }
2656
2657 private boolean applyAnimationLocked(WindowState win,
2658 int transit, boolean isEntrance) {
2659 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2660 // If we are trying to apply an animation, but already running
2661 // an animation of the same type, then just leave that one alone.
2662 return true;
2663 }
Romain Guy06882f82009-06-10 13:36:04 -07002664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002665 // Only apply an animation if the display isn't frozen. If it is
2666 // frozen, there is no reason to animate and it can cause strange
2667 // artifacts when we unfreeze the display if some different animation
2668 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002669 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002670 int anim = mPolicy.selectAnimationLw(win, transit);
2671 int attr = -1;
2672 Animation a = null;
2673 if (anim != 0) {
2674 a = AnimationUtils.loadAnimation(mContext, anim);
2675 } else {
2676 switch (transit) {
2677 case WindowManagerPolicy.TRANSIT_ENTER:
2678 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2679 break;
2680 case WindowManagerPolicy.TRANSIT_EXIT:
2681 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2682 break;
2683 case WindowManagerPolicy.TRANSIT_SHOW:
2684 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2685 break;
2686 case WindowManagerPolicy.TRANSIT_HIDE:
2687 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2688 break;
2689 }
2690 if (attr >= 0) {
2691 a = loadAnimation(win.mAttrs, attr);
2692 }
2693 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002694 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002695 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2696 + " mAnimation=" + win.mAnimation
2697 + " isEntrance=" + isEntrance);
2698 if (a != null) {
2699 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002700 RuntimeException e = null;
2701 if (!HIDE_STACK_CRAWLS) {
2702 e = new RuntimeException();
2703 e.fillInStackTrace();
2704 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002705 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002706 }
2707 win.setAnimation(a);
2708 win.mAnimationIsEntrance = isEntrance;
2709 }
2710 } else {
2711 win.clearAnimation();
2712 }
2713
2714 return win.mAnimation != null;
2715 }
2716
2717 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2718 int anim = 0;
2719 Context context = mContext;
2720 if (animAttr >= 0) {
2721 AttributeCache.Entry ent = getCachedAnimations(lp);
2722 if (ent != null) {
2723 context = ent.context;
2724 anim = ent.array.getResourceId(animAttr, 0);
2725 }
2726 }
2727 if (anim != 0) {
2728 return AnimationUtils.loadAnimation(context, anim);
2729 }
2730 return null;
2731 }
Romain Guy06882f82009-06-10 13:36:04 -07002732
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002733 private Animation loadAnimation(String packageName, int resId) {
2734 int anim = 0;
2735 Context context = mContext;
2736 if (resId >= 0) {
2737 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2738 if (ent != null) {
2739 context = ent.context;
2740 anim = resId;
2741 }
2742 }
2743 if (anim != 0) {
2744 return AnimationUtils.loadAnimation(context, anim);
2745 }
2746 return null;
2747 }
2748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002749 private boolean applyAnimationLocked(AppWindowToken wtoken,
2750 WindowManager.LayoutParams lp, int transit, boolean enter) {
2751 // Only apply an animation if the display isn't frozen. If it is
2752 // frozen, there is no reason to animate and it can cause strange
2753 // artifacts when we unfreeze the display if some different animation
2754 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002755 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002756 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002757 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002758 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002759 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002760 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002761 } else if (mNextAppTransitionPackage != null) {
2762 a = loadAnimation(mNextAppTransitionPackage, enter ?
2763 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002764 } else {
2765 int animAttr = 0;
2766 switch (transit) {
2767 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2768 animAttr = enter
2769 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2770 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2771 break;
2772 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2773 animAttr = enter
2774 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2775 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2776 break;
2777 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2778 animAttr = enter
2779 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2780 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2781 break;
2782 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2783 animAttr = enter
2784 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2785 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2786 break;
2787 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2788 animAttr = enter
2789 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2790 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2791 break;
2792 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2793 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002794 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002795 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2796 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002797 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002798 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002799 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2800 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002801 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002802 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002803 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002804 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2805 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2806 break;
2807 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2808 animAttr = enter
2809 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2810 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2811 break;
2812 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2813 animAttr = enter
2814 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2815 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002816 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002817 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002818 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002819 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002820 + " anim=" + a
2821 + " animAttr=0x" + Integer.toHexString(animAttr)
2822 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002823 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002824 if (a != null) {
2825 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002826 RuntimeException e = null;
2827 if (!HIDE_STACK_CRAWLS) {
2828 e = new RuntimeException();
2829 e.fillInStackTrace();
2830 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002831 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002832 }
2833 wtoken.setAnimation(a);
2834 }
2835 } else {
2836 wtoken.clearAnimation();
2837 }
2838
2839 return wtoken.animation != null;
2840 }
2841
2842 // -------------------------------------------------------------
2843 // Application Window Tokens
2844 // -------------------------------------------------------------
2845
2846 public void validateAppTokens(List tokens) {
2847 int v = tokens.size()-1;
2848 int m = mAppTokens.size()-1;
2849 while (v >= 0 && m >= 0) {
2850 AppWindowToken wtoken = mAppTokens.get(m);
2851 if (wtoken.removed) {
2852 m--;
2853 continue;
2854 }
2855 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002856 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002857 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2858 }
2859 v--;
2860 m--;
2861 }
2862 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002863 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002864 v--;
2865 }
2866 while (m >= 0) {
2867 AppWindowToken wtoken = mAppTokens.get(m);
2868 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002869 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002870 }
2871 m--;
2872 }
2873 }
2874
2875 boolean checkCallingPermission(String permission, String func) {
2876 // Quick check: if the calling permission is me, it's all okay.
2877 if (Binder.getCallingPid() == Process.myPid()) {
2878 return true;
2879 }
Romain Guy06882f82009-06-10 13:36:04 -07002880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002881 if (mContext.checkCallingPermission(permission)
2882 == PackageManager.PERMISSION_GRANTED) {
2883 return true;
2884 }
2885 String msg = "Permission Denial: " + func + " from pid="
2886 + Binder.getCallingPid()
2887 + ", uid=" + Binder.getCallingUid()
2888 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002889 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002890 return false;
2891 }
Romain Guy06882f82009-06-10 13:36:04 -07002892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002893 AppWindowToken findAppWindowToken(IBinder token) {
2894 WindowToken wtoken = mTokenMap.get(token);
2895 if (wtoken == null) {
2896 return null;
2897 }
2898 return wtoken.appWindowToken;
2899 }
Romain Guy06882f82009-06-10 13:36:04 -07002900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002901 public void addWindowToken(IBinder token, int type) {
2902 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2903 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002904 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002905 }
Romain Guy06882f82009-06-10 13:36:04 -07002906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002907 synchronized(mWindowMap) {
2908 WindowToken wtoken = mTokenMap.get(token);
2909 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002910 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002911 return;
2912 }
2913 wtoken = new WindowToken(token, type, true);
2914 mTokenMap.put(token, wtoken);
2915 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002916 if (type == TYPE_WALLPAPER) {
2917 mWallpaperTokens.add(wtoken);
2918 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002919 }
2920 }
Romain Guy06882f82009-06-10 13:36:04 -07002921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002922 public void removeWindowToken(IBinder token) {
2923 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2924 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002925 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002926 }
2927
2928 final long origId = Binder.clearCallingIdentity();
2929 synchronized(mWindowMap) {
2930 WindowToken wtoken = mTokenMap.remove(token);
2931 mTokenList.remove(wtoken);
2932 if (wtoken != null) {
2933 boolean delayed = false;
2934 if (!wtoken.hidden) {
2935 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002937 final int N = wtoken.windows.size();
2938 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002940 for (int i=0; i<N; i++) {
2941 WindowState win = wtoken.windows.get(i);
2942
2943 if (win.isAnimating()) {
2944 delayed = true;
2945 }
Romain Guy06882f82009-06-10 13:36:04 -07002946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002947 if (win.isVisibleNow()) {
2948 applyAnimationLocked(win,
2949 WindowManagerPolicy.TRANSIT_EXIT, false);
2950 mKeyWaiter.finishedKey(win.mSession, win.mClient, true,
2951 KeyWaiter.RETURN_NOTHING);
2952 changed = true;
2953 }
2954 }
2955
2956 if (changed) {
2957 mLayoutNeeded = true;
2958 performLayoutAndPlaceSurfacesLocked();
2959 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2960 }
Romain Guy06882f82009-06-10 13:36:04 -07002961
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002962 if (delayed) {
2963 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002964 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2965 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002966 }
2967 }
Romain Guy06882f82009-06-10 13:36:04 -07002968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002969 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002970 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002971 }
2972 }
2973 Binder.restoreCallingIdentity(origId);
2974 }
2975
2976 public void addAppToken(int addPos, IApplicationToken token,
2977 int groupId, int requestedOrientation, boolean fullscreen) {
2978 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2979 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002980 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002981 }
Romain Guy06882f82009-06-10 13:36:04 -07002982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002983 synchronized(mWindowMap) {
2984 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2985 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002986 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987 return;
2988 }
2989 wtoken = new AppWindowToken(token);
2990 wtoken.groupId = groupId;
2991 wtoken.appFullscreen = fullscreen;
2992 wtoken.requestedOrientation = requestedOrientation;
2993 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002994 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002995 mTokenMap.put(token.asBinder(), wtoken);
2996 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002998 // Application tokens start out hidden.
2999 wtoken.hidden = true;
3000 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003002 //dump();
3003 }
3004 }
Romain Guy06882f82009-06-10 13:36:04 -07003005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003006 public void setAppGroupId(IBinder token, int groupId) {
3007 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3008 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003009 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003010 }
3011
3012 synchronized(mWindowMap) {
3013 AppWindowToken wtoken = findAppWindowToken(token);
3014 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003015 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003016 return;
3017 }
3018 wtoken.groupId = groupId;
3019 }
3020 }
Romain Guy06882f82009-06-10 13:36:04 -07003021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003022 public int getOrientationFromWindowsLocked() {
3023 int pos = mWindows.size() - 1;
3024 while (pos >= 0) {
3025 WindowState wtoken = (WindowState) mWindows.get(pos);
3026 pos--;
3027 if (wtoken.mAppToken != null) {
3028 // We hit an application window. so the orientation will be determined by the
3029 // app window. No point in continuing further.
3030 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3031 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003032 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003033 continue;
3034 }
3035 int req = wtoken.mAttrs.screenOrientation;
3036 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3037 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3038 continue;
3039 } else {
3040 return req;
3041 }
3042 }
3043 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3044 }
Romain Guy06882f82009-06-10 13:36:04 -07003045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003046 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003047 int pos = mAppTokens.size() - 1;
3048 int curGroup = 0;
3049 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3050 boolean findingBehind = false;
3051 boolean haveGroup = false;
3052 boolean lastFullscreen = false;
3053 while (pos >= 0) {
3054 AppWindowToken wtoken = mAppTokens.get(pos);
3055 pos--;
3056 // if we're about to tear down this window and not seek for
3057 // the behind activity, don't use it for orientation
3058 if (!findingBehind
3059 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3060 continue;
3061 }
3062
3063 if (!haveGroup) {
3064 // We ignore any hidden applications on the top.
3065 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003066 continue;
3067 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003068 haveGroup = true;
3069 curGroup = wtoken.groupId;
3070 lastOrientation = wtoken.requestedOrientation;
3071 } else if (curGroup != wtoken.groupId) {
3072 // If we have hit a new application group, and the bottom
3073 // of the previous group didn't explicitly say to use
3074 // the orientation behind it, and the last app was
3075 // full screen, then we'll stick with the
3076 // user's orientation.
3077 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3078 && lastFullscreen) {
3079 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003080 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003081 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003082 int or = wtoken.requestedOrientation;
3083 // If this application is fullscreen, and didn't explicitly say
3084 // to use the orientation behind it, then just take whatever
3085 // orientation it has and ignores whatever is under it.
3086 lastFullscreen = wtoken.appFullscreen;
3087 if (lastFullscreen
3088 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3089 return or;
3090 }
3091 // If this application has requested an explicit orientation,
3092 // then use it.
3093 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3094 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3095 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3096 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3097 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3098 return or;
3099 }
3100 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3101 }
3102 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003103 }
Romain Guy06882f82009-06-10 13:36:04 -07003104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003105 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003106 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003107 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3108 "updateOrientationFromAppTokens()")) {
3109 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3110 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003111
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003112 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003113 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003114
3115 synchronized(mWindowMap) {
3116 if (updateOrientationFromAppTokensLocked()) {
3117 if (freezeThisOneIfNeeded != null) {
3118 AppWindowToken wtoken = findAppWindowToken(
3119 freezeThisOneIfNeeded);
3120 if (wtoken != null) {
3121 startAppFreezingScreenLocked(wtoken,
3122 ActivityInfo.CONFIG_ORIENTATION);
3123 }
3124 }
3125 config = computeNewConfigurationLocked();
3126
3127 } else if (currentConfig != null) {
3128 // No obvious action we need to take, but if our current
3129 // state mismatches the activity maanager's, update it
3130 mTempConfiguration.setToDefaults();
3131 if (computeNewConfigurationLocked(mTempConfiguration)) {
3132 if (currentConfig.diff(mTempConfiguration) != 0) {
3133 mWaitingForConfig = true;
3134 mLayoutNeeded = true;
3135 startFreezingDisplayLocked();
3136 config = new Configuration(mTempConfiguration);
3137 }
3138 }
3139 }
3140 }
3141
Dianne Hackborncfaef692009-06-15 14:24:44 -07003142 Binder.restoreCallingIdentity(ident);
3143 return config;
3144 }
3145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003146 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003147 * Determine the new desired orientation of the display, returning
3148 * a non-null new Configuration if it has changed from the current
3149 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3150 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3151 * SCREEN. This will typically be done for you if you call
3152 * sendNewConfiguration().
3153 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003154 * The orientation is computed from non-application windows first. If none of
3155 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003156 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003157 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3158 * android.os.IBinder)
3159 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003160 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003161 if (mDisplayFrozen) {
3162 // If the display is frozen, some activities may be in the middle
3163 // of restarting, and thus have removed their old window. If the
3164 // window has the flag to hide the lock screen, then the lock screen
3165 // can re-appear and inflict its own orientation on us. Keep the
3166 // orientation stable until this all settles down.
3167 return false;
3168 }
3169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003170 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003171 long ident = Binder.clearCallingIdentity();
3172 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003173 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003175 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003176 mForcedAppOrientation = req;
3177 //send a message to Policy indicating orientation change to take
3178 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003179 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003180 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3181 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3182 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003183 }
3184 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003185
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003186 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 } finally {
3188 Binder.restoreCallingIdentity(ident);
3189 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003190 }
Romain Guy06882f82009-06-10 13:36:04 -07003191
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003192 int computeForcedAppOrientationLocked() {
3193 int req = getOrientationFromWindowsLocked();
3194 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3195 req = getOrientationFromAppTokensLocked();
3196 }
3197 return req;
3198 }
Romain Guy06882f82009-06-10 13:36:04 -07003199
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003200 public void setNewConfiguration(Configuration config) {
3201 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3202 "setNewConfiguration()")) {
3203 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3204 }
3205
3206 synchronized(mWindowMap) {
3207 mCurConfiguration = new Configuration(config);
3208 mWaitingForConfig = false;
3209 performLayoutAndPlaceSurfacesLocked();
3210 }
3211 }
3212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003213 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3214 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3215 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003216 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003217 }
Romain Guy06882f82009-06-10 13:36:04 -07003218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003219 synchronized(mWindowMap) {
3220 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3221 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003222 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003223 return;
3224 }
Romain Guy06882f82009-06-10 13:36:04 -07003225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003226 wtoken.requestedOrientation = requestedOrientation;
3227 }
3228 }
Romain Guy06882f82009-06-10 13:36:04 -07003229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003230 public int getAppOrientation(IApplicationToken token) {
3231 synchronized(mWindowMap) {
3232 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3233 if (wtoken == null) {
3234 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3235 }
Romain Guy06882f82009-06-10 13:36:04 -07003236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003237 return wtoken.requestedOrientation;
3238 }
3239 }
Romain Guy06882f82009-06-10 13:36:04 -07003240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003241 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3242 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3243 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003244 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003245 }
3246
3247 synchronized(mWindowMap) {
3248 boolean changed = false;
3249 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003250 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003251 changed = mFocusedApp != null;
3252 mFocusedApp = null;
3253 mKeyWaiter.tickle();
3254 } else {
3255 AppWindowToken newFocus = findAppWindowToken(token);
3256 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003257 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003258 return;
3259 }
3260 changed = mFocusedApp != newFocus;
3261 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003262 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003263 mKeyWaiter.tickle();
3264 }
3265
3266 if (moveFocusNow && changed) {
3267 final long origId = Binder.clearCallingIdentity();
3268 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3269 Binder.restoreCallingIdentity(origId);
3270 }
3271 }
3272 }
3273
3274 public void prepareAppTransition(int transit) {
3275 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3276 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003277 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003278 }
Romain Guy06882f82009-06-10 13:36:04 -07003279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003280 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003281 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003282 TAG, "Prepare app transition: transit=" + transit
3283 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003284 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003285 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3286 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003287 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003288 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3289 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3290 // Opening a new task always supersedes a close for the anim.
3291 mNextAppTransition = transit;
3292 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3293 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3294 // Opening a new activity always supersedes a close for the anim.
3295 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003296 }
3297 mAppTransitionReady = false;
3298 mAppTransitionTimeout = false;
3299 mStartingIconInTransition = false;
3300 mSkipAppTransitionAnimation = false;
3301 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3302 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3303 5000);
3304 }
3305 }
3306 }
3307
3308 public int getPendingAppTransition() {
3309 return mNextAppTransition;
3310 }
Romain Guy06882f82009-06-10 13:36:04 -07003311
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003312 public void overridePendingAppTransition(String packageName,
3313 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003314 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003315 mNextAppTransitionPackage = packageName;
3316 mNextAppTransitionEnter = enterAnim;
3317 mNextAppTransitionExit = exitAnim;
3318 }
3319 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003321 public void executeAppTransition() {
3322 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3323 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003324 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003325 }
Romain Guy06882f82009-06-10 13:36:04 -07003326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003327 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003328 if (DEBUG_APP_TRANSITIONS) {
3329 RuntimeException e = new RuntimeException("here");
3330 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003331 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003332 + mNextAppTransition, e);
3333 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003334 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003335 mAppTransitionReady = true;
3336 final long origId = Binder.clearCallingIdentity();
3337 performLayoutAndPlaceSurfacesLocked();
3338 Binder.restoreCallingIdentity(origId);
3339 }
3340 }
3341 }
3342
3343 public void setAppStartingWindow(IBinder token, String pkg,
3344 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3345 IBinder transferFrom, boolean createIfNeeded) {
3346 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3347 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003348 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003349 }
3350
3351 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003352 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003353 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3354 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003356 AppWindowToken wtoken = findAppWindowToken(token);
3357 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003358 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003359 return;
3360 }
3361
3362 // If the display is frozen, we won't do anything until the
3363 // actual window is displayed so there is no reason to put in
3364 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003365 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003366 return;
3367 }
Romain Guy06882f82009-06-10 13:36:04 -07003368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003369 if (wtoken.startingData != null) {
3370 return;
3371 }
Romain Guy06882f82009-06-10 13:36:04 -07003372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003373 if (transferFrom != null) {
3374 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3375 if (ttoken != null) {
3376 WindowState startingWindow = ttoken.startingWindow;
3377 if (startingWindow != null) {
3378 if (mStartingIconInTransition) {
3379 // In this case, the starting icon has already
3380 // been displayed, so start letting windows get
3381 // shown immediately without any more transitions.
3382 mSkipAppTransitionAnimation = true;
3383 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003384 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003385 "Moving existing starting from " + ttoken
3386 + " to " + wtoken);
3387 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003389 // Transfer the starting window over to the new
3390 // token.
3391 wtoken.startingData = ttoken.startingData;
3392 wtoken.startingView = ttoken.startingView;
3393 wtoken.startingWindow = startingWindow;
3394 ttoken.startingData = null;
3395 ttoken.startingView = null;
3396 ttoken.startingWindow = null;
3397 ttoken.startingMoved = true;
3398 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003399 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003400 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003401 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003402 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003403 mWindows.remove(startingWindow);
3404 ttoken.windows.remove(startingWindow);
3405 ttoken.allAppWindows.remove(startingWindow);
3406 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003407
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003408 // Propagate other interesting state between the
3409 // tokens. If the old token is displayed, we should
3410 // immediately force the new one to be displayed. If
3411 // it is animating, we need to move that animation to
3412 // the new one.
3413 if (ttoken.allDrawn) {
3414 wtoken.allDrawn = true;
3415 }
3416 if (ttoken.firstWindowDrawn) {
3417 wtoken.firstWindowDrawn = true;
3418 }
3419 if (!ttoken.hidden) {
3420 wtoken.hidden = false;
3421 wtoken.hiddenRequested = false;
3422 wtoken.willBeHidden = false;
3423 }
3424 if (wtoken.clientHidden != ttoken.clientHidden) {
3425 wtoken.clientHidden = ttoken.clientHidden;
3426 wtoken.sendAppVisibilityToClients();
3427 }
3428 if (ttoken.animation != null) {
3429 wtoken.animation = ttoken.animation;
3430 wtoken.animating = ttoken.animating;
3431 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3432 ttoken.animation = null;
3433 ttoken.animLayerAdjustment = 0;
3434 wtoken.updateLayers();
3435 ttoken.updateLayers();
3436 }
Romain Guy06882f82009-06-10 13:36:04 -07003437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003438 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003439 mLayoutNeeded = true;
3440 performLayoutAndPlaceSurfacesLocked();
3441 Binder.restoreCallingIdentity(origId);
3442 return;
3443 } else if (ttoken.startingData != null) {
3444 // The previous app was getting ready to show a
3445 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003446 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003447 "Moving pending starting from " + ttoken
3448 + " to " + wtoken);
3449 wtoken.startingData = ttoken.startingData;
3450 ttoken.startingData = null;
3451 ttoken.startingMoved = true;
3452 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3453 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3454 // want to process the message ASAP, before any other queued
3455 // messages.
3456 mH.sendMessageAtFrontOfQueue(m);
3457 return;
3458 }
3459 }
3460 }
3461
3462 // There is no existing starting window, and the caller doesn't
3463 // want us to create one, so that's it!
3464 if (!createIfNeeded) {
3465 return;
3466 }
Romain Guy06882f82009-06-10 13:36:04 -07003467
Dianne Hackborn284ac932009-08-28 10:34:25 -07003468 // If this is a translucent or wallpaper window, then don't
3469 // show a starting window -- the current effect (a full-screen
3470 // opaque starting window that fades away to the real contents
3471 // when it is ready) does not work for this.
3472 if (theme != 0) {
3473 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3474 com.android.internal.R.styleable.Window);
3475 if (ent.array.getBoolean(
3476 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3477 return;
3478 }
3479 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003480 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3481 return;
3482 }
3483 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003484 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3485 return;
3486 }
3487 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003489 mStartingIconInTransition = true;
3490 wtoken.startingData = new StartingData(
3491 pkg, theme, nonLocalizedLabel,
3492 labelRes, icon);
3493 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3494 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3495 // want to process the message ASAP, before any other queued
3496 // messages.
3497 mH.sendMessageAtFrontOfQueue(m);
3498 }
3499 }
3500
3501 public void setAppWillBeHidden(IBinder token) {
3502 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3503 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003504 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003505 }
3506
3507 AppWindowToken wtoken;
3508
3509 synchronized(mWindowMap) {
3510 wtoken = findAppWindowToken(token);
3511 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003512 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 -08003513 return;
3514 }
3515 wtoken.willBeHidden = true;
3516 }
3517 }
Romain Guy06882f82009-06-10 13:36:04 -07003518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003519 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3520 boolean visible, int transit, boolean performLayout) {
3521 boolean delayed = false;
3522
3523 if (wtoken.clientHidden == visible) {
3524 wtoken.clientHidden = !visible;
3525 wtoken.sendAppVisibilityToClients();
3526 }
Romain Guy06882f82009-06-10 13:36:04 -07003527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003528 wtoken.willBeHidden = false;
3529 if (wtoken.hidden == visible) {
3530 final int N = wtoken.allAppWindows.size();
3531 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003532 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003533 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3534 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003536 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003537
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003538 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003539 if (wtoken.animation == sDummyAnimation) {
3540 wtoken.animation = null;
3541 }
3542 applyAnimationLocked(wtoken, lp, transit, visible);
3543 changed = true;
3544 if (wtoken.animation != null) {
3545 delayed = runningAppAnimation = true;
3546 }
3547 }
Romain Guy06882f82009-06-10 13:36:04 -07003548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003549 for (int i=0; i<N; i++) {
3550 WindowState win = wtoken.allAppWindows.get(i);
3551 if (win == wtoken.startingWindow) {
3552 continue;
3553 }
3554
3555 if (win.isAnimating()) {
3556 delayed = true;
3557 }
Romain Guy06882f82009-06-10 13:36:04 -07003558
Joe Onorato8a9b2202010-02-26 18:56:32 -08003559 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003560 //win.dump(" ");
3561 if (visible) {
3562 if (!win.isVisibleNow()) {
3563 if (!runningAppAnimation) {
3564 applyAnimationLocked(win,
3565 WindowManagerPolicy.TRANSIT_ENTER, true);
3566 }
3567 changed = true;
3568 }
3569 } else if (win.isVisibleNow()) {
3570 if (!runningAppAnimation) {
3571 applyAnimationLocked(win,
3572 WindowManagerPolicy.TRANSIT_EXIT, false);
3573 }
3574 mKeyWaiter.finishedKey(win.mSession, win.mClient, true,
3575 KeyWaiter.RETURN_NOTHING);
3576 changed = true;
3577 }
3578 }
3579
3580 wtoken.hidden = wtoken.hiddenRequested = !visible;
3581 if (!visible) {
3582 unsetAppFreezingScreenLocked(wtoken, true, true);
3583 } else {
3584 // If we are being set visible, and the starting window is
3585 // not yet displayed, then make sure it doesn't get displayed.
3586 WindowState swin = wtoken.startingWindow;
3587 if (swin != null && (swin.mDrawPending
3588 || swin.mCommitDrawPending)) {
3589 swin.mPolicyVisibility = false;
3590 swin.mPolicyVisibilityAfterAnim = false;
3591 }
3592 }
Romain Guy06882f82009-06-10 13:36:04 -07003593
Joe Onorato8a9b2202010-02-26 18:56:32 -08003594 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003595 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3596 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003597
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003598 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003599 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003600 if (performLayout) {
3601 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3602 performLayoutAndPlaceSurfacesLocked();
3603 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003604 }
3605 }
3606
3607 if (wtoken.animation != null) {
3608 delayed = true;
3609 }
Romain Guy06882f82009-06-10 13:36:04 -07003610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003611 return delayed;
3612 }
3613
3614 public void setAppVisibility(IBinder token, boolean visible) {
3615 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3616 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003617 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003618 }
3619
3620 AppWindowToken wtoken;
3621
3622 synchronized(mWindowMap) {
3623 wtoken = findAppWindowToken(token);
3624 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003625 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003626 return;
3627 }
3628
3629 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003630 RuntimeException e = null;
3631 if (!HIDE_STACK_CRAWLS) {
3632 e = new RuntimeException();
3633 e.fillInStackTrace();
3634 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003635 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003636 + "): mNextAppTransition=" + mNextAppTransition
3637 + " hidden=" + wtoken.hidden
3638 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3639 }
Romain Guy06882f82009-06-10 13:36:04 -07003640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003641 // If we are preparing an app transition, then delay changing
3642 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003643 if (!mDisplayFrozen && mPolicy.isScreenOn()
3644 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003645 // Already in requested state, don't do anything more.
3646 if (wtoken.hiddenRequested != visible) {
3647 return;
3648 }
3649 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003650
Joe Onorato8a9b2202010-02-26 18:56:32 -08003651 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003652 TAG, "Setting dummy animation on: " + wtoken);
3653 wtoken.setDummyAnimation();
3654 mOpeningApps.remove(wtoken);
3655 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003656 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003657 wtoken.inPendingTransaction = true;
3658 if (visible) {
3659 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003660 wtoken.startingDisplayed = false;
3661 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003662
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003663 // If the token is currently hidden (should be the
3664 // common case), then we need to set up to wait for
3665 // its windows to be ready.
3666 if (wtoken.hidden) {
3667 wtoken.allDrawn = false;
3668 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003669
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003670 if (wtoken.clientHidden) {
3671 // In the case where we are making an app visible
3672 // but holding off for a transition, we still need
3673 // to tell the client to make its windows visible so
3674 // they get drawn. Otherwise, we will wait on
3675 // performing the transition until all windows have
3676 // been drawn, they never will be, and we are sad.
3677 wtoken.clientHidden = false;
3678 wtoken.sendAppVisibilityToClients();
3679 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003680 }
3681 } else {
3682 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003683
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003684 // If the token is currently visible (should be the
3685 // common case), then set up to wait for it to be hidden.
3686 if (!wtoken.hidden) {
3687 wtoken.waitingToHide = true;
3688 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003689 }
3690 return;
3691 }
Romain Guy06882f82009-06-10 13:36:04 -07003692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003693 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003694 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003695 wtoken.updateReportedVisibilityLocked();
3696 Binder.restoreCallingIdentity(origId);
3697 }
3698 }
3699
3700 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3701 boolean unfreezeSurfaceNow, boolean force) {
3702 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003703 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003704 + " force=" + force);
3705 final int N = wtoken.allAppWindows.size();
3706 boolean unfrozeWindows = false;
3707 for (int i=0; i<N; i++) {
3708 WindowState w = wtoken.allAppWindows.get(i);
3709 if (w.mAppFreezing) {
3710 w.mAppFreezing = false;
3711 if (w.mSurface != null && !w.mOrientationChanging) {
3712 w.mOrientationChanging = true;
3713 }
3714 unfrozeWindows = true;
3715 }
3716 }
3717 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003718 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003719 wtoken.freezingScreen = false;
3720 mAppsFreezingScreen--;
3721 }
3722 if (unfreezeSurfaceNow) {
3723 if (unfrozeWindows) {
3724 mLayoutNeeded = true;
3725 performLayoutAndPlaceSurfacesLocked();
3726 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003727 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003728 }
3729 }
3730 }
Romain Guy06882f82009-06-10 13:36:04 -07003731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003732 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3733 int configChanges) {
3734 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003735 RuntimeException e = null;
3736 if (!HIDE_STACK_CRAWLS) {
3737 e = new RuntimeException();
3738 e.fillInStackTrace();
3739 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003740 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003741 + ": hidden=" + wtoken.hidden + " freezing="
3742 + wtoken.freezingScreen, e);
3743 }
3744 if (!wtoken.hiddenRequested) {
3745 if (!wtoken.freezingScreen) {
3746 wtoken.freezingScreen = true;
3747 mAppsFreezingScreen++;
3748 if (mAppsFreezingScreen == 1) {
3749 startFreezingDisplayLocked();
3750 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3751 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3752 5000);
3753 }
3754 }
3755 final int N = wtoken.allAppWindows.size();
3756 for (int i=0; i<N; i++) {
3757 WindowState w = wtoken.allAppWindows.get(i);
3758 w.mAppFreezing = true;
3759 }
3760 }
3761 }
Romain Guy06882f82009-06-10 13:36:04 -07003762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003763 public void startAppFreezingScreen(IBinder token, int configChanges) {
3764 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3765 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003766 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003767 }
3768
3769 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003770 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003771 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003772 return;
3773 }
Romain Guy06882f82009-06-10 13:36:04 -07003774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003775 AppWindowToken wtoken = findAppWindowToken(token);
3776 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003777 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003778 return;
3779 }
3780 final long origId = Binder.clearCallingIdentity();
3781 startAppFreezingScreenLocked(wtoken, configChanges);
3782 Binder.restoreCallingIdentity(origId);
3783 }
3784 }
Romain Guy06882f82009-06-10 13:36:04 -07003785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003786 public void stopAppFreezingScreen(IBinder token, boolean force) {
3787 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3788 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003789 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003790 }
3791
3792 synchronized(mWindowMap) {
3793 AppWindowToken wtoken = findAppWindowToken(token);
3794 if (wtoken == null || wtoken.appToken == null) {
3795 return;
3796 }
3797 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003798 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003799 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3800 unsetAppFreezingScreenLocked(wtoken, true, force);
3801 Binder.restoreCallingIdentity(origId);
3802 }
3803 }
Romain Guy06882f82009-06-10 13:36:04 -07003804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003805 public void removeAppToken(IBinder token) {
3806 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3807 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003808 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003809 }
3810
3811 AppWindowToken wtoken = null;
3812 AppWindowToken startingToken = null;
3813 boolean delayed = false;
3814
3815 final long origId = Binder.clearCallingIdentity();
3816 synchronized(mWindowMap) {
3817 WindowToken basewtoken = mTokenMap.remove(token);
3818 mTokenList.remove(basewtoken);
3819 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003820 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003821 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003822 wtoken.inPendingTransaction = false;
3823 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003824 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003825 if (mClosingApps.contains(wtoken)) {
3826 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003827 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003828 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003829 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003830 delayed = true;
3831 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003832 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003833 TAG, "Removing app " + wtoken + " delayed=" + delayed
3834 + " animation=" + wtoken.animation
3835 + " animating=" + wtoken.animating);
3836 if (delayed) {
3837 // set the token aside because it has an active animation to be finished
3838 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003839 } else {
3840 // Make sure there is no animation running on this token,
3841 // so any windows associated with it will be removed as
3842 // soon as their animations are complete
3843 wtoken.animation = null;
3844 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003845 }
3846 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003847 if (mLastEnterAnimToken == wtoken) {
3848 mLastEnterAnimToken = null;
3849 mLastEnterAnimParams = null;
3850 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003851 wtoken.removed = true;
3852 if (wtoken.startingData != null) {
3853 startingToken = wtoken;
3854 }
3855 unsetAppFreezingScreenLocked(wtoken, true, true);
3856 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003857 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003858 mFocusedApp = null;
3859 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3860 mKeyWaiter.tickle();
3861 }
3862 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003863 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003864 }
Romain Guy06882f82009-06-10 13:36:04 -07003865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003866 if (!delayed && wtoken != null) {
3867 wtoken.updateReportedVisibilityLocked();
3868 }
3869 }
3870 Binder.restoreCallingIdentity(origId);
3871
3872 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003873 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003874 + startingToken + ": app token removed");
3875 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3876 mH.sendMessage(m);
3877 }
3878 }
3879
3880 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3881 final int NW = token.windows.size();
3882 for (int i=0; i<NW; i++) {
3883 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003884 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003885 mWindows.remove(win);
3886 int j = win.mChildWindows.size();
3887 while (j > 0) {
3888 j--;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003889 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003890 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003891 "Tmp removing child window " + cwin);
3892 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003893 }
3894 }
3895 return NW > 0;
3896 }
3897
3898 void dumpAppTokensLocked() {
3899 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003900 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003901 }
3902 }
Romain Guy06882f82009-06-10 13:36:04 -07003903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003904 void dumpWindowsLocked() {
3905 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003906 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003907 }
3908 }
Romain Guy06882f82009-06-10 13:36:04 -07003909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003910 private int findWindowOffsetLocked(int tokenPos) {
3911 final int NW = mWindows.size();
3912
3913 if (tokenPos >= mAppTokens.size()) {
3914 int i = NW;
3915 while (i > 0) {
3916 i--;
3917 WindowState win = (WindowState)mWindows.get(i);
3918 if (win.getAppToken() != null) {
3919 return i+1;
3920 }
3921 }
3922 }
3923
3924 while (tokenPos > 0) {
3925 // Find the first app token below the new position that has
3926 // a window displayed.
3927 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003928 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003929 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003930 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003931 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003932 "Skipping token -- currently sending to bottom");
3933 tokenPos--;
3934 continue;
3935 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003936 int i = wtoken.windows.size();
3937 while (i > 0) {
3938 i--;
3939 WindowState win = wtoken.windows.get(i);
3940 int j = win.mChildWindows.size();
3941 while (j > 0) {
3942 j--;
3943 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003944 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003945 for (int pos=NW-1; pos>=0; pos--) {
3946 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003947 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003948 "Found child win @" + (pos+1));
3949 return pos+1;
3950 }
3951 }
3952 }
3953 }
3954 for (int pos=NW-1; pos>=0; pos--) {
3955 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003956 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003957 return pos+1;
3958 }
3959 }
3960 }
3961 tokenPos--;
3962 }
3963
3964 return 0;
3965 }
3966
3967 private final int reAddWindowLocked(int index, WindowState win) {
3968 final int NCW = win.mChildWindows.size();
3969 boolean added = false;
3970 for (int j=0; j<NCW; j++) {
3971 WindowState cwin = (WindowState)win.mChildWindows.get(j);
3972 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003973 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003974 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003975 mWindows.add(index, win);
3976 index++;
3977 added = true;
3978 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003979 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003980 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003981 mWindows.add(index, cwin);
3982 index++;
3983 }
3984 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003985 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003986 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003987 mWindows.add(index, win);
3988 index++;
3989 }
3990 return index;
3991 }
Romain Guy06882f82009-06-10 13:36:04 -07003992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003993 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3994 final int NW = token.windows.size();
3995 for (int i=0; i<NW; i++) {
3996 index = reAddWindowLocked(index, token.windows.get(i));
3997 }
3998 return index;
3999 }
4000
4001 public void moveAppToken(int index, IBinder token) {
4002 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4003 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004004 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004005 }
4006
4007 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004008 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004009 if (DEBUG_REORDER) dumpAppTokensLocked();
4010 final AppWindowToken wtoken = findAppWindowToken(token);
4011 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004012 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004013 + token + " (" + wtoken + ")");
4014 return;
4015 }
4016 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004017 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004018 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004019
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004020 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004021 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004022 if (DEBUG_REORDER) dumpWindowsLocked();
4023 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004024 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004025 if (DEBUG_REORDER) dumpWindowsLocked();
4026 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004027 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004028 if (DEBUG_REORDER) dumpWindowsLocked();
4029 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004030 mLayoutNeeded = true;
4031 performLayoutAndPlaceSurfacesLocked();
4032 }
4033 Binder.restoreCallingIdentity(origId);
4034 }
4035 }
4036
4037 private void removeAppTokensLocked(List<IBinder> tokens) {
4038 // XXX This should be done more efficiently!
4039 // (take advantage of the fact that both lists should be
4040 // ordered in the same way.)
4041 int N = tokens.size();
4042 for (int i=0; i<N; i++) {
4043 IBinder token = tokens.get(i);
4044 final AppWindowToken wtoken = findAppWindowToken(token);
4045 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004046 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004047 + token + " (" + wtoken + ")");
4048 i--;
4049 N--;
4050 }
4051 }
4052 }
4053
Dianne Hackborna8f60182009-09-01 19:01:50 -07004054 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4055 boolean updateFocusAndLayout) {
4056 // First remove all of the windows from the list.
4057 tmpRemoveAppWindowsLocked(wtoken);
4058
4059 // Where to start adding?
4060 int pos = findWindowOffsetLocked(tokenPos);
4061
4062 // And now add them back at the correct place.
4063 pos = reAddAppWindowsLocked(pos, wtoken);
4064
4065 if (updateFocusAndLayout) {
4066 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4067 assignLayersLocked();
4068 }
4069 mLayoutNeeded = true;
4070 performLayoutAndPlaceSurfacesLocked();
4071 }
4072 }
4073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004074 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4075 // First remove all of the windows from the list.
4076 final int N = tokens.size();
4077 int i;
4078 for (i=0; i<N; i++) {
4079 WindowToken token = mTokenMap.get(tokens.get(i));
4080 if (token != null) {
4081 tmpRemoveAppWindowsLocked(token);
4082 }
4083 }
4084
4085 // Where to start adding?
4086 int pos = findWindowOffsetLocked(tokenPos);
4087
4088 // And now add them back at the correct place.
4089 for (i=0; i<N; i++) {
4090 WindowToken token = mTokenMap.get(tokens.get(i));
4091 if (token != null) {
4092 pos = reAddAppWindowsLocked(pos, token);
4093 }
4094 }
4095
Dianne Hackborna8f60182009-09-01 19:01:50 -07004096 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4097 assignLayersLocked();
4098 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004099 mLayoutNeeded = true;
4100 performLayoutAndPlaceSurfacesLocked();
4101
4102 //dump();
4103 }
4104
4105 public void moveAppTokensToTop(List<IBinder> tokens) {
4106 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4107 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004108 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004109 }
4110
4111 final long origId = Binder.clearCallingIdentity();
4112 synchronized(mWindowMap) {
4113 removeAppTokensLocked(tokens);
4114 final int N = tokens.size();
4115 for (int i=0; i<N; i++) {
4116 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4117 if (wt != null) {
4118 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004119 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004120 mToTopApps.remove(wt);
4121 mToBottomApps.remove(wt);
4122 mToTopApps.add(wt);
4123 wt.sendingToBottom = false;
4124 wt.sendingToTop = true;
4125 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004126 }
4127 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004128
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004129 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004130 moveAppWindowsLocked(tokens, mAppTokens.size());
4131 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004132 }
4133 Binder.restoreCallingIdentity(origId);
4134 }
4135
4136 public void moveAppTokensToBottom(List<IBinder> tokens) {
4137 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4138 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004139 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004140 }
4141
4142 final long origId = Binder.clearCallingIdentity();
4143 synchronized(mWindowMap) {
4144 removeAppTokensLocked(tokens);
4145 final int N = tokens.size();
4146 int pos = 0;
4147 for (int i=0; i<N; i++) {
4148 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4149 if (wt != null) {
4150 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004151 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004152 mToTopApps.remove(wt);
4153 mToBottomApps.remove(wt);
4154 mToBottomApps.add(i, wt);
4155 wt.sendingToTop = false;
4156 wt.sendingToBottom = true;
4157 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004158 pos++;
4159 }
4160 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004161
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004162 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004163 moveAppWindowsLocked(tokens, 0);
4164 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004165 }
4166 Binder.restoreCallingIdentity(origId);
4167 }
4168
4169 // -------------------------------------------------------------
4170 // Misc IWindowSession methods
4171 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004173 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004174 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004175 != PackageManager.PERMISSION_GRANTED) {
4176 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4177 }
Mike Lockwood983ee092009-11-22 01:42:24 -05004178 synchronized (mKeyguardTokenWatcher) {
4179 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004180 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004181 }
4182
4183 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004184 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004185 != PackageManager.PERMISSION_GRANTED) {
4186 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4187 }
Mike Lockwood983ee092009-11-22 01:42:24 -05004188 synchronized (mKeyguardTokenWatcher) {
4189 mKeyguardTokenWatcher.release(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004190
Mike Lockwood983ee092009-11-22 01:42:24 -05004191 if (!mKeyguardTokenWatcher.isAcquired()) {
4192 // If we are the last one to reenable the keyguard wait until
4193 // we have actaully finished reenabling until returning.
4194 // It is possible that reenableKeyguard() can be called before
4195 // the previous disableKeyguard() is handled, in which case
4196 // neither mKeyguardTokenWatcher.acquired() or released() would
4197 // be called. In that case mKeyguardDisabled will be false here
4198 // and we have nothing to wait for.
4199 while (mKeyguardDisabled) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004200 try {
Mike Lockwood983ee092009-11-22 01:42:24 -05004201 mKeyguardTokenWatcher.wait();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004202 } catch (InterruptedException e) {
4203 Thread.currentThread().interrupt();
4204 }
4205 }
4206 }
4207 }
4208 }
4209
4210 /**
4211 * @see android.app.KeyguardManager#exitKeyguardSecurely
4212 */
4213 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004214 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004215 != PackageManager.PERMISSION_GRANTED) {
4216 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4217 }
4218 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4219 public void onKeyguardExitResult(boolean success) {
4220 try {
4221 callback.onKeyguardExitResult(success);
4222 } catch (RemoteException e) {
4223 // Client has died, we don't care.
4224 }
4225 }
4226 });
4227 }
4228
4229 public boolean inKeyguardRestrictedInputMode() {
4230 return mPolicy.inKeyguardRestrictedKeyInputMode();
4231 }
Romain Guy06882f82009-06-10 13:36:04 -07004232
Dianne Hackbornffa42482009-09-23 22:20:11 -07004233 public void closeSystemDialogs(String reason) {
4234 synchronized(mWindowMap) {
4235 for (int i=mWindows.size()-1; i>=0; i--) {
4236 WindowState w = (WindowState)mWindows.get(i);
4237 if (w.mSurface != null) {
4238 try {
4239 w.mClient.closeSystemDialogs(reason);
4240 } catch (RemoteException e) {
4241 }
4242 }
4243 }
4244 }
4245 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004247 static float fixScale(float scale) {
4248 if (scale < 0) scale = 0;
4249 else if (scale > 20) scale = 20;
4250 return Math.abs(scale);
4251 }
Romain Guy06882f82009-06-10 13:36:04 -07004252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004253 public void setAnimationScale(int which, float scale) {
4254 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4255 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004256 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004257 }
4258
4259 if (scale < 0) scale = 0;
4260 else if (scale > 20) scale = 20;
4261 scale = Math.abs(scale);
4262 switch (which) {
4263 case 0: mWindowAnimationScale = fixScale(scale); break;
4264 case 1: mTransitionAnimationScale = fixScale(scale); break;
4265 }
Romain Guy06882f82009-06-10 13:36:04 -07004266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004267 // Persist setting
4268 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4269 }
Romain Guy06882f82009-06-10 13:36:04 -07004270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004271 public void setAnimationScales(float[] scales) {
4272 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4273 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004274 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004275 }
4276
4277 if (scales != null) {
4278 if (scales.length >= 1) {
4279 mWindowAnimationScale = fixScale(scales[0]);
4280 }
4281 if (scales.length >= 2) {
4282 mTransitionAnimationScale = fixScale(scales[1]);
4283 }
4284 }
Romain Guy06882f82009-06-10 13:36:04 -07004285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004286 // Persist setting
4287 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4288 }
Romain Guy06882f82009-06-10 13:36:04 -07004289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004290 public float getAnimationScale(int which) {
4291 switch (which) {
4292 case 0: return mWindowAnimationScale;
4293 case 1: return mTransitionAnimationScale;
4294 }
4295 return 0;
4296 }
Romain Guy06882f82009-06-10 13:36:04 -07004297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004298 public float[] getAnimationScales() {
4299 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4300 }
Romain Guy06882f82009-06-10 13:36:04 -07004301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004302 public int getSwitchState(int sw) {
4303 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4304 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004305 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004306 }
4307 return KeyInputQueue.getSwitchState(sw);
4308 }
Romain Guy06882f82009-06-10 13:36:04 -07004309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004310 public int getSwitchStateForDevice(int devid, int sw) {
4311 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4312 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004313 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004314 }
4315 return KeyInputQueue.getSwitchState(devid, sw);
4316 }
Romain Guy06882f82009-06-10 13:36:04 -07004317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004318 public int getScancodeState(int sw) {
4319 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4320 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004321 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004322 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004323 return mQueue.getScancodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004324 }
Romain Guy06882f82009-06-10 13:36:04 -07004325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004326 public int getScancodeStateForDevice(int devid, int sw) {
4327 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4328 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004329 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004330 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004331 return mQueue.getScancodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004332 }
Romain Guy06882f82009-06-10 13:36:04 -07004333
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004334 public int getTrackballScancodeState(int sw) {
4335 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4336 "getTrackballScancodeState()")) {
4337 throw new SecurityException("Requires READ_INPUT_STATE permission");
4338 }
4339 return mQueue.getTrackballScancodeState(sw);
4340 }
4341
4342 public int getDPadScancodeState(int sw) {
4343 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4344 "getDPadScancodeState()")) {
4345 throw new SecurityException("Requires READ_INPUT_STATE permission");
4346 }
4347 return mQueue.getDPadScancodeState(sw);
4348 }
4349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004350 public int getKeycodeState(int sw) {
4351 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4352 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004353 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004354 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004355 return mQueue.getKeycodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004356 }
Romain Guy06882f82009-06-10 13:36:04 -07004357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004358 public int getKeycodeStateForDevice(int devid, int sw) {
4359 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4360 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004361 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004362 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004363 return mQueue.getKeycodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004364 }
Romain Guy06882f82009-06-10 13:36:04 -07004365
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004366 public int getTrackballKeycodeState(int sw) {
4367 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4368 "getTrackballKeycodeState()")) {
4369 throw new SecurityException("Requires READ_INPUT_STATE permission");
4370 }
4371 return mQueue.getTrackballKeycodeState(sw);
4372 }
4373
4374 public int getDPadKeycodeState(int sw) {
4375 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4376 "getDPadKeycodeState()")) {
4377 throw new SecurityException("Requires READ_INPUT_STATE permission");
4378 }
4379 return mQueue.getDPadKeycodeState(sw);
4380 }
4381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004382 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
4383 return KeyInputQueue.hasKeys(keycodes, keyExists);
4384 }
Romain Guy06882f82009-06-10 13:36:04 -07004385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004386 public void enableScreenAfterBoot() {
4387 synchronized(mWindowMap) {
4388 if (mSystemBooted) {
4389 return;
4390 }
4391 mSystemBooted = true;
4392 }
Romain Guy06882f82009-06-10 13:36:04 -07004393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004394 performEnableScreen();
4395 }
Romain Guy06882f82009-06-10 13:36:04 -07004396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004397 public void enableScreenIfNeededLocked() {
4398 if (mDisplayEnabled) {
4399 return;
4400 }
4401 if (!mSystemBooted) {
4402 return;
4403 }
4404 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4405 }
Romain Guy06882f82009-06-10 13:36:04 -07004406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004407 public void performEnableScreen() {
4408 synchronized(mWindowMap) {
4409 if (mDisplayEnabled) {
4410 return;
4411 }
4412 if (!mSystemBooted) {
4413 return;
4414 }
Romain Guy06882f82009-06-10 13:36:04 -07004415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004416 // Don't enable the screen until all existing windows
4417 // have been drawn.
4418 final int N = mWindows.size();
4419 for (int i=0; i<N; i++) {
4420 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004421 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004422 return;
4423 }
4424 }
Romain Guy06882f82009-06-10 13:36:04 -07004425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004426 mDisplayEnabled = true;
4427 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004428 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004429 StringWriter sw = new StringWriter();
4430 PrintWriter pw = new PrintWriter(sw);
4431 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004432 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004433 }
4434 try {
4435 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4436 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004437 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004438 Parcel data = Parcel.obtain();
4439 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4440 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4441 data, null, 0);
4442 data.recycle();
4443 }
4444 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004445 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004446 }
4447 }
Romain Guy06882f82009-06-10 13:36:04 -07004448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004449 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004451 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004452 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4453 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004454 }
Romain Guy06882f82009-06-10 13:36:04 -07004455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004456 public void setInTouchMode(boolean mode) {
4457 synchronized(mWindowMap) {
4458 mInTouchMode = mode;
4459 }
4460 }
4461
Romain Guy06882f82009-06-10 13:36:04 -07004462 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004463 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004464 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004465 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004466 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004467 }
4468
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004469 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004470 }
Romain Guy06882f82009-06-10 13:36:04 -07004471
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004472 public void setRotationUnchecked(int rotation,
4473 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004474 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004475 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004477 long origId = Binder.clearCallingIdentity();
4478 boolean changed;
4479 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004480 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004481 }
Romain Guy06882f82009-06-10 13:36:04 -07004482
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004483 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004484 sendNewConfiguration();
4485 }
Romain Guy06882f82009-06-10 13:36:04 -07004486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004487 Binder.restoreCallingIdentity(origId);
4488 }
Romain Guy06882f82009-06-10 13:36:04 -07004489
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004490 /**
4491 * Apply a new rotation to the screen, respecting the requests of
4492 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4493 * re-evaluate the desired rotation.
4494 *
4495 * Returns null if the rotation has been changed. In this case YOU
4496 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4497 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004498 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004499 boolean changed;
4500 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4501 rotation = mRequestedRotation;
4502 } else {
4503 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004504 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004505 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004506 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004507 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004508 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004509 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004510 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004512 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004513 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004514 "Rotation changed to " + rotation
4515 + " from " + mRotation
4516 + " (forceApp=" + mForcedAppOrientation
4517 + ", req=" + mRequestedRotation + ")");
4518 mRotation = rotation;
4519 mWindowsFreezingScreen = true;
4520 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4521 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4522 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004523 mWaitingForConfig = true;
4524 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004525 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004526 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004527 mQueue.setOrientation(rotation);
4528 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004529 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004530 }
4531 for (int i=mWindows.size()-1; i>=0; i--) {
4532 WindowState w = (WindowState)mWindows.get(i);
4533 if (w.mSurface != null) {
4534 w.mOrientationChanging = true;
4535 }
4536 }
4537 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4538 try {
4539 mRotationWatchers.get(i).onRotationChanged(rotation);
4540 } catch (RemoteException e) {
4541 }
4542 }
4543 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004545 return changed;
4546 }
Romain Guy06882f82009-06-10 13:36:04 -07004547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004548 public int getRotation() {
4549 return mRotation;
4550 }
4551
4552 public int watchRotation(IRotationWatcher watcher) {
4553 final IBinder watcherBinder = watcher.asBinder();
4554 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4555 public void binderDied() {
4556 synchronized (mWindowMap) {
4557 for (int i=0; i<mRotationWatchers.size(); i++) {
4558 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004559 IRotationWatcher removed = mRotationWatchers.remove(i);
4560 if (removed != null) {
4561 removed.asBinder().unlinkToDeath(this, 0);
4562 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004563 i--;
4564 }
4565 }
4566 }
4567 }
4568 };
Romain Guy06882f82009-06-10 13:36:04 -07004569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004570 synchronized (mWindowMap) {
4571 try {
4572 watcher.asBinder().linkToDeath(dr, 0);
4573 mRotationWatchers.add(watcher);
4574 } catch (RemoteException e) {
4575 // Client died, no cleanup needed.
4576 }
Romain Guy06882f82009-06-10 13:36:04 -07004577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004578 return mRotation;
4579 }
4580 }
4581
4582 /**
4583 * Starts the view server on the specified port.
4584 *
4585 * @param port The port to listener to.
4586 *
4587 * @return True if the server was successfully started, false otherwise.
4588 *
4589 * @see com.android.server.ViewServer
4590 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4591 */
4592 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004593 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004594 return false;
4595 }
4596
4597 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4598 return false;
4599 }
4600
4601 if (port < 1024) {
4602 return false;
4603 }
4604
4605 if (mViewServer != null) {
4606 if (!mViewServer.isRunning()) {
4607 try {
4608 return mViewServer.start();
4609 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004610 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004611 }
4612 }
4613 return false;
4614 }
4615
4616 try {
4617 mViewServer = new ViewServer(this, port);
4618 return mViewServer.start();
4619 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004620 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004621 }
4622 return false;
4623 }
4624
Romain Guy06882f82009-06-10 13:36:04 -07004625 private boolean isSystemSecure() {
4626 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4627 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4628 }
4629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004630 /**
4631 * Stops the view server if it exists.
4632 *
4633 * @return True if the server stopped, false if it wasn't started or
4634 * couldn't be stopped.
4635 *
4636 * @see com.android.server.ViewServer
4637 */
4638 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004639 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004640 return false;
4641 }
4642
4643 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4644 return false;
4645 }
4646
4647 if (mViewServer != null) {
4648 return mViewServer.stop();
4649 }
4650 return false;
4651 }
4652
4653 /**
4654 * Indicates whether the view server is running.
4655 *
4656 * @return True if the server is running, false otherwise.
4657 *
4658 * @see com.android.server.ViewServer
4659 */
4660 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004661 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004662 return false;
4663 }
4664
4665 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4666 return false;
4667 }
4668
4669 return mViewServer != null && mViewServer.isRunning();
4670 }
4671
4672 /**
4673 * Lists all availble windows in the system. The listing is written in the
4674 * specified Socket's output stream with the following syntax:
4675 * windowHashCodeInHexadecimal windowName
4676 * Each line of the ouput represents a different window.
4677 *
4678 * @param client The remote client to send the listing to.
4679 * @return False if an error occured, true otherwise.
4680 */
4681 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004682 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004683 return false;
4684 }
4685
4686 boolean result = true;
4687
4688 Object[] windows;
4689 synchronized (mWindowMap) {
4690 windows = new Object[mWindows.size()];
4691 //noinspection unchecked
4692 windows = mWindows.toArray(windows);
4693 }
4694
4695 BufferedWriter out = null;
4696
4697 // Any uncaught exception will crash the system process
4698 try {
4699 OutputStream clientStream = client.getOutputStream();
4700 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4701
4702 final int count = windows.length;
4703 for (int i = 0; i < count; i++) {
4704 final WindowState w = (WindowState) windows[i];
4705 out.write(Integer.toHexString(System.identityHashCode(w)));
4706 out.write(' ');
4707 out.append(w.mAttrs.getTitle());
4708 out.write('\n');
4709 }
4710
4711 out.write("DONE.\n");
4712 out.flush();
4713 } catch (Exception e) {
4714 result = false;
4715 } finally {
4716 if (out != null) {
4717 try {
4718 out.close();
4719 } catch (IOException e) {
4720 result = false;
4721 }
4722 }
4723 }
4724
4725 return result;
4726 }
4727
4728 /**
4729 * Sends a command to a target window. The result of the command, if any, will be
4730 * written in the output stream of the specified socket.
4731 *
4732 * The parameters must follow this syntax:
4733 * windowHashcode extra
4734 *
4735 * Where XX is the length in characeters of the windowTitle.
4736 *
4737 * The first parameter is the target window. The window with the specified hashcode
4738 * will be the target. If no target can be found, nothing happens. The extra parameters
4739 * will be delivered to the target window and as parameters to the command itself.
4740 *
4741 * @param client The remote client to sent the result, if any, to.
4742 * @param command The command to execute.
4743 * @param parameters The command parameters.
4744 *
4745 * @return True if the command was successfully delivered, false otherwise. This does
4746 * not indicate whether the command itself was successful.
4747 */
4748 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004749 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004750 return false;
4751 }
4752
4753 boolean success = true;
4754 Parcel data = null;
4755 Parcel reply = null;
4756
4757 // Any uncaught exception will crash the system process
4758 try {
4759 // Find the hashcode of the window
4760 int index = parameters.indexOf(' ');
4761 if (index == -1) {
4762 index = parameters.length();
4763 }
4764 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004765 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004766
4767 // Extract the command's parameter after the window description
4768 if (index < parameters.length()) {
4769 parameters = parameters.substring(index + 1);
4770 } else {
4771 parameters = "";
4772 }
4773
4774 final WindowManagerService.WindowState window = findWindow(hashCode);
4775 if (window == null) {
4776 return false;
4777 }
4778
4779 data = Parcel.obtain();
4780 data.writeInterfaceToken("android.view.IWindow");
4781 data.writeString(command);
4782 data.writeString(parameters);
4783 data.writeInt(1);
4784 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4785
4786 reply = Parcel.obtain();
4787
4788 final IBinder binder = window.mClient.asBinder();
4789 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4790 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4791
4792 reply.readException();
4793
4794 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004795 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004796 success = false;
4797 } finally {
4798 if (data != null) {
4799 data.recycle();
4800 }
4801 if (reply != null) {
4802 reply.recycle();
4803 }
4804 }
4805
4806 return success;
4807 }
4808
4809 private WindowState findWindow(int hashCode) {
4810 if (hashCode == -1) {
4811 return getFocusedWindow();
4812 }
4813
4814 synchronized (mWindowMap) {
4815 final ArrayList windows = mWindows;
4816 final int count = windows.size();
4817
4818 for (int i = 0; i < count; i++) {
4819 WindowState w = (WindowState) windows.get(i);
4820 if (System.identityHashCode(w) == hashCode) {
4821 return w;
4822 }
4823 }
4824 }
4825
4826 return null;
4827 }
4828
4829 /*
4830 * Instruct the Activity Manager to fetch the current configuration and broadcast
4831 * that to config-changed listeners if appropriate.
4832 */
4833 void sendNewConfiguration() {
4834 try {
4835 mActivityManager.updateConfiguration(null);
4836 } catch (RemoteException e) {
4837 }
4838 }
Romain Guy06882f82009-06-10 13:36:04 -07004839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004840 public Configuration computeNewConfiguration() {
4841 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004842 return computeNewConfigurationLocked();
4843 }
4844 }
Romain Guy06882f82009-06-10 13:36:04 -07004845
Dianne Hackbornc485a602009-03-24 22:39:49 -07004846 Configuration computeNewConfigurationLocked() {
4847 Configuration config = new Configuration();
4848 if (!computeNewConfigurationLocked(config)) {
4849 return null;
4850 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004851 return config;
4852 }
Romain Guy06882f82009-06-10 13:36:04 -07004853
Dianne Hackbornc485a602009-03-24 22:39:49 -07004854 boolean computeNewConfigurationLocked(Configuration config) {
4855 if (mDisplay == null) {
4856 return false;
4857 }
4858 mQueue.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07004859
4860 // Use the effective "visual" dimensions based on current rotation
4861 final boolean rotated = (mRotation == Surface.ROTATION_90
4862 || mRotation == Surface.ROTATION_270);
4863 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
4864 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
4865
Dianne Hackbornc485a602009-03-24 22:39:49 -07004866 int orientation = Configuration.ORIENTATION_SQUARE;
4867 if (dw < dh) {
4868 orientation = Configuration.ORIENTATION_PORTRAIT;
4869 } else if (dw > dh) {
4870 orientation = Configuration.ORIENTATION_LANDSCAPE;
4871 }
4872 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004873
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004874 DisplayMetrics dm = new DisplayMetrics();
4875 mDisplay.getMetrics(dm);
4876 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4877
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004878 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004879 // Note we only do this once because at this point we don't
4880 // expect the screen to change in this way at runtime, and want
4881 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004882 int longSize = dw;
4883 int shortSize = dh;
4884 if (longSize < shortSize) {
4885 int tmp = longSize;
4886 longSize = shortSize;
4887 shortSize = tmp;
4888 }
4889 longSize = (int)(longSize/dm.density);
4890 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004891
Dianne Hackborn723738c2009-06-25 19:48:04 -07004892 // These semi-magic numbers define our compatibility modes for
4893 // applications with different screens. Don't change unless you
4894 // make sure to test lots and lots of apps!
4895 if (longSize < 470) {
4896 // This is shorter than an HVGA normal density screen (which
4897 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004898 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
4899 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07004900 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07004901 // What size is this screen screen?
4902 if (longSize >= 800 && shortSize >= 600) {
4903 // SVGA or larger screens at medium density are the point
4904 // at which we consider it to be an extra large screen.
4905 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
4906 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004907 // VGA or larger screens at medium density are the point
4908 // at which we consider it to be a large screen.
4909 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
4910 } else {
4911 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004912
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004913 // If this screen is wider than normal HVGA, or taller
4914 // than FWVGA, then for old apps we want to run in size
4915 // compatibility mode.
4916 if (shortSize > 321 || longSize > 570) {
4917 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
4918 }
4919 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004920
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004921 // Is this a long screen?
4922 if (((longSize*3)/5) >= (shortSize-1)) {
4923 // Anything wider than WVGA (5:3) is considering to be long.
4924 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
4925 } else {
4926 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
4927 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07004928 }
4929 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004930 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004931
Dianne Hackbornc485a602009-03-24 22:39:49 -07004932 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
4933 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
4934 mPolicy.adjustConfigurationLw(config);
4935 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004936 }
Romain Guy06882f82009-06-10 13:36:04 -07004937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004938 // -------------------------------------------------------------
4939 // Input Events and Focus Management
4940 // -------------------------------------------------------------
4941
4942 private final void wakeupIfNeeded(WindowState targetWin, int eventType) {
Michael Chane96440f2009-05-06 10:27:36 -07004943 long curTime = SystemClock.uptimeMillis();
4944
Michael Chane10de972009-05-18 11:24:50 -07004945 if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) {
Michael Chane96440f2009-05-06 10:27:36 -07004946 if (mLastTouchEventType == eventType &&
4947 (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) {
4948 return;
4949 }
4950 mLastUserActivityCallTime = curTime;
4951 mLastTouchEventType = eventType;
4952 }
4953
4954 if (targetWin == null
4955 || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) {
4956 mPowerManager.userActivity(curTime, false, eventType, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004957 }
4958 }
4959
4960 // tells if it's a cheek event or not -- this function is stateful
4961 private static final int EVENT_NONE = 0;
4962 private static final int EVENT_UNKNOWN = 0;
4963 private static final int EVENT_CHEEK = 0;
4964 private static final int EVENT_IGNORE_DURATION = 300; // ms
4965 private static final float CHEEK_THRESHOLD = 0.6f;
4966 private int mEventState = EVENT_NONE;
4967 private float mEventSize;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004969 private int eventType(MotionEvent ev) {
4970 float size = ev.getSize();
4971 switch (ev.getAction()) {
4972 case MotionEvent.ACTION_DOWN:
4973 mEventSize = size;
4974 return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT;
4975 case MotionEvent.ACTION_UP:
4976 if (size > mEventSize) mEventSize = size;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004977 return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004978 case MotionEvent.ACTION_MOVE:
4979 final int N = ev.getHistorySize();
4980 if (size > mEventSize) mEventSize = size;
4981 if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT;
4982 for (int i=0; i<N; i++) {
4983 size = ev.getHistoricalSize(i);
4984 if (size > mEventSize) mEventSize = size;
4985 if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT;
4986 }
4987 if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) {
4988 return TOUCH_EVENT;
4989 } else {
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004990 return LONG_TOUCH_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004991 }
4992 default:
4993 // not good
4994 return OTHER_EVENT;
4995 }
4996 }
4997
4998 /**
4999 * @return Returns true if event was dispatched, false if it was dropped for any reason
5000 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07005001 private int dispatchPointer(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005002 if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005003 "dispatchPointer " + ev);
5004
Michael Chan53071d62009-05-13 17:29:48 -07005005 if (MEASURE_LATENCY) {
5006 lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano);
5007 }
5008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005009 Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005010 ev, true, false, pid, uid);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005011
Michael Chan53071d62009-05-13 17:29:48 -07005012 if (MEASURE_LATENCY) {
5013 lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano);
5014 }
5015
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005016 int action = ev.getAction();
Romain Guy06882f82009-06-10 13:36:04 -07005017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005018 if (action == MotionEvent.ACTION_UP) {
5019 // let go of our target
5020 mKeyWaiter.mMotionTarget = null;
5021 mPowerManager.logPointerUpEvent();
5022 } else if (action == MotionEvent.ACTION_DOWN) {
5023 mPowerManager.logPointerDownEvent();
5024 }
5025
5026 if (targetObj == null) {
5027 // In this case we are either dropping the event, or have received
5028 // a move or up without a down. It is common to receive move
5029 // events in such a way, since this means the user is moving the
5030 // pointer without actually pressing down. All other cases should
5031 // be atypical, so let's log them.
Michael Chane96440f2009-05-06 10:27:36 -07005032 if (action != MotionEvent.ACTION_MOVE) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005033 Slog.w(TAG, "No window to dispatch pointer action " + ev.getAction());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005034 }
Dianne Hackborn6adba242009-11-10 11:10:09 -08005035 synchronized (mWindowMap) {
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005036 dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true);
Dianne Hackborn6adba242009-11-10 11:10:09 -08005037 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005038 if (qev != null) {
5039 mQueue.recycleEvent(qev);
5040 }
5041 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005042 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005043 }
5044 if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
Dianne Hackborn6adba242009-11-10 11:10:09 -08005045 synchronized (mWindowMap) {
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005046 dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true);
Dianne Hackborn6adba242009-11-10 11:10:09 -08005047 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005048 if (qev != null) {
5049 mQueue.recycleEvent(qev);
5050 }
5051 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005052 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005053 }
Romain Guy06882f82009-06-10 13:36:04 -07005054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005055 WindowState target = (WindowState)targetObj;
Romain Guy06882f82009-06-10 13:36:04 -07005056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005057 final long eventTime = ev.getEventTime();
Michael Chan53071d62009-05-13 17:29:48 -07005058 final long eventTimeNano = ev.getEventTimeNano();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005059
Joe Onorato8a9b2202010-02-26 18:56:32 -08005060 //Slog.i(TAG, "Sending " + ev + " to " + target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005061
5062 if (uid != 0 && uid != target.mSession.mUid) {
5063 if (mContext.checkPermission(
5064 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5065 != PackageManager.PERMISSION_GRANTED) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005066 Slog.w(TAG, "Permission denied: injecting pointer event from pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005067 + pid + " uid " + uid + " to window " + target
5068 + " owned by uid " + target.mSession.mUid);
5069 if (qev != null) {
5070 mQueue.recycleEvent(qev);
5071 }
5072 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005073 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005074 }
5075 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005076
Michael Chan53071d62009-05-13 17:29:48 -07005077 if (MEASURE_LATENCY) {
5078 lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano);
5079 }
5080
Romain Guy06882f82009-06-10 13:36:04 -07005081 if ((target.mAttrs.flags &
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005082 WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) {
5083 //target wants to ignore fat touch events
5084 boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev);
5085 //explicit flag to return without processing event further
5086 boolean returnFlag = false;
5087 if((action == MotionEvent.ACTION_DOWN)) {
5088 mFatTouch = false;
5089 if(cheekPress) {
5090 mFatTouch = true;
5091 returnFlag = true;
5092 }
5093 } else {
5094 if(action == MotionEvent.ACTION_UP) {
5095 if(mFatTouch) {
5096 //earlier even was invalid doesnt matter if current up is cheekpress or not
5097 mFatTouch = false;
5098 returnFlag = true;
5099 } else if(cheekPress) {
5100 //cancel the earlier event
5101 ev.setAction(MotionEvent.ACTION_CANCEL);
5102 action = MotionEvent.ACTION_CANCEL;
5103 }
5104 } else if(action == MotionEvent.ACTION_MOVE) {
5105 if(mFatTouch) {
5106 //two cases here
5107 //an invalid down followed by 0 or moves(valid or invalid)
Romain Guy06882f82009-06-10 13:36:04 -07005108 //a valid down, invalid move, more moves. want to ignore till up
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005109 returnFlag = true;
5110 } else if(cheekPress) {
5111 //valid down followed by invalid moves
5112 //an invalid move have to cancel earlier action
5113 ev.setAction(MotionEvent.ACTION_CANCEL);
5114 action = MotionEvent.ACTION_CANCEL;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005115 if (DEBUG_INPUT) Slog.v(TAG, "Sending cancel for invalid ACTION_MOVE");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005116 //note that the subsequent invalid moves will not get here
5117 mFatTouch = true;
5118 }
5119 }
5120 } //else if action
5121 if(returnFlag) {
5122 //recycle que, ev
5123 if (qev != null) {
5124 mQueue.recycleEvent(qev);
5125 }
5126 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005127 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005128 }
5129 } //end if target
Michael Chane96440f2009-05-06 10:27:36 -07005130
Michael Chan9f028e62009-08-04 17:37:46 -07005131 // Enable this for testing the "right" value
5132 if (false && action == MotionEvent.ACTION_DOWN) {
Michael Chane96440f2009-05-06 10:27:36 -07005133 int max_events_per_sec = 35;
5134 try {
5135 max_events_per_sec = Integer.parseInt(SystemProperties
5136 .get("windowsmgr.max_events_per_sec"));
5137 if (max_events_per_sec < 1) {
5138 max_events_per_sec = 35;
5139 }
5140 } catch (NumberFormatException e) {
5141 }
5142 mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec;
5143 }
5144
5145 /*
5146 * Throttle events to minimize CPU usage when there's a flood of events
5147 * e.g. constant contact with the screen
5148 */
5149 if (action == MotionEvent.ACTION_MOVE) {
5150 long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents;
5151 long now = SystemClock.uptimeMillis();
5152 if (now < nextEventTime) {
5153 try {
5154 Thread.sleep(nextEventTime - now);
5155 } catch (InterruptedException e) {
5156 }
5157 mLastTouchEventTime = nextEventTime;
5158 } else {
5159 mLastTouchEventTime = now;
5160 }
5161 }
5162
Michael Chan53071d62009-05-13 17:29:48 -07005163 if (MEASURE_LATENCY) {
5164 lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano);
5165 }
5166
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005167 synchronized(mWindowMap) {
Dianne Hackborn6adba242009-11-10 11:10:09 -08005168 if (!target.isVisibleLw()) {
5169 // During this motion dispatch, the target window has become
5170 // invisible.
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005171 dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), false);
Dianne Hackborn6adba242009-11-10 11:10:09 -08005172 if (qev != null) {
5173 mQueue.recycleEvent(qev);
5174 }
5175 ev.recycle();
5176 return INJECT_SUCCEEDED;
5177 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005179 if (qev != null && action == MotionEvent.ACTION_MOVE) {
5180 mKeyWaiter.bindTargetWindowLocked(target,
5181 KeyWaiter.RETURN_PENDING_POINTER, qev);
5182 ev = null;
5183 } else {
5184 if (action == MotionEvent.ACTION_DOWN) {
5185 WindowState out = mKeyWaiter.mOutsideTouchTargets;
5186 if (out != null) {
5187 MotionEvent oev = MotionEvent.obtain(ev);
Adam Powell47482962010-05-27 15:19:58 -07005188 try {
5189 oev.setAction(MotionEvent.ACTION_OUTSIDE);
5190 do {
5191 final Rect frame = out.mFrame;
5192 oev.offsetLocation(-(float)frame.left, -(float)frame.top);
5193 try {
5194 out.mClient.dispatchPointer(oev, eventTime, false);
5195 } catch (android.os.RemoteException e) {
5196 Slog.i(TAG,
5197 "WINDOW DIED during outside motion dispatch: " + out);
5198 }
5199 oev.offsetLocation((float)frame.left, (float)frame.top);
5200 out = out.mNextOutsideTouch;
5201 } while (out != null);
5202 mKeyWaiter.mOutsideTouchTargets = null;
5203 } finally {
5204 oev.recycle();
5205 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005206 }
5207 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005208
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005209 dispatchPointerElsewhereLocked(target, null, ev, ev.getEventTime(), false);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005210
Dianne Hackborn6adba242009-11-10 11:10:09 -08005211 final Rect frame = target.mFrame;
5212 ev.offsetLocation(-(float)frame.left, -(float)frame.top);
5213 mKeyWaiter.bindTargetWindowLocked(target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005214 }
5215 }
Romain Guy06882f82009-06-10 13:36:04 -07005216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005217 // finally offset the event to the target's coordinate system and
5218 // dispatch the event.
5219 try {
5220 if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005221 Slog.v(TAG, "Delivering pointer " + qev + " to " + target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005222 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005223
Michael Chan53071d62009-05-13 17:29:48 -07005224 if (MEASURE_LATENCY) {
5225 lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano);
5226 }
5227
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005228 target.mClient.dispatchPointer(ev, eventTime, true);
Michael Chan53071d62009-05-13 17:29:48 -07005229
5230 if (MEASURE_LATENCY) {
5231 lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano);
5232 }
Dianne Hackborncfaef692009-06-15 14:24:44 -07005233 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005234 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005235 Slog.i(TAG, "WINDOW DIED during motion dispatch: " + target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005236 mKeyWaiter.mMotionTarget = null;
5237 try {
5238 removeWindow(target.mSession, target.mClient);
5239 } catch (java.util.NoSuchElementException ex) {
5240 // This will happen if the window has already been
5241 // removed.
5242 }
5243 }
Dianne Hackborncfaef692009-06-15 14:24:44 -07005244 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005245 }
Romain Guy06882f82009-06-10 13:36:04 -07005246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005247 /**
5248 * @return Returns true if event was dispatched, false if it was dropped for any reason
5249 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07005250 private int dispatchTrackball(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005251 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005252 TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">");
Romain Guy06882f82009-06-10 13:36:04 -07005253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005254 Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005255 ev, false, false, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005256 if (focusObj == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005257 Slog.w(TAG, "No focus window, dropping trackball: " + ev);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005258 if (qev != null) {
5259 mQueue.recycleEvent(qev);
5260 }
5261 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005262 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005263 }
5264 if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
5265 if (qev != null) {
5266 mQueue.recycleEvent(qev);
5267 }
5268 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005269 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005270 }
Romain Guy06882f82009-06-10 13:36:04 -07005271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005272 WindowState focus = (WindowState)focusObj;
Romain Guy06882f82009-06-10 13:36:04 -07005273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005274 if (uid != 0 && uid != focus.mSession.mUid) {
5275 if (mContext.checkPermission(
5276 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5277 != PackageManager.PERMISSION_GRANTED) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005278 Slog.w(TAG, "Permission denied: injecting key event from pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005279 + pid + " uid " + uid + " to window " + focus
5280 + " owned by uid " + focus.mSession.mUid);
5281 if (qev != null) {
5282 mQueue.recycleEvent(qev);
5283 }
5284 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005285 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005286 }
5287 }
Romain Guy06882f82009-06-10 13:36:04 -07005288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005289 final long eventTime = ev.getEventTime();
Romain Guy06882f82009-06-10 13:36:04 -07005290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005291 synchronized(mWindowMap) {
5292 if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) {
5293 mKeyWaiter.bindTargetWindowLocked(focus,
5294 KeyWaiter.RETURN_PENDING_TRACKBALL, qev);
5295 // We don't deliver movement events to the client, we hold
5296 // them and wait for them to call back.
5297 ev = null;
5298 } else {
5299 mKeyWaiter.bindTargetWindowLocked(focus);
5300 }
5301 }
Romain Guy06882f82009-06-10 13:36:04 -07005302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005303 try {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005304 focus.mClient.dispatchTrackball(ev, eventTime, true);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005305 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005306 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005307 Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005308 try {
5309 removeWindow(focus.mSession, focus.mClient);
5310 } catch (java.util.NoSuchElementException ex) {
5311 // This will happen if the window has already been
5312 // removed.
5313 }
5314 }
Romain Guy06882f82009-06-10 13:36:04 -07005315
Dianne Hackborncfaef692009-06-15 14:24:44 -07005316 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005317 }
Romain Guy06882f82009-06-10 13:36:04 -07005318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005319 /**
5320 * @return Returns true if event was dispatched, false if it was dropped for any reason
5321 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07005322 private int dispatchKey(KeyEvent event, int pid, int uid) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005323 if (DEBUG_INPUT) Slog.v(TAG, "Dispatch key: " + event);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005324
5325 Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005326 null, false, false, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005327 if (focusObj == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005328 Slog.w(TAG, "No focus window, dropping: " + event);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005329 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005330 }
5331 if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005332 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005333 }
Romain Guy06882f82009-06-10 13:36:04 -07005334
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07005335 // Okay we have finished waiting for the last event to be processed.
5336 // First off, if this is a repeat event, check to see if there is
5337 // a corresponding up event in the queue. If there is, we will
5338 // just drop the repeat, because it makes no sense to repeat after
5339 // the user has released a key. (This is especially important for
5340 // long presses.)
5341 if (event.getRepeatCount() > 0 && mQueue.hasKeyUpEvent(event)) {
5342 return INJECT_SUCCEEDED;
5343 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005345 WindowState focus = (WindowState)focusObj;
Romain Guy06882f82009-06-10 13:36:04 -07005346
Joe Onorato8a9b2202010-02-26 18:56:32 -08005347 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005348 TAG, "Dispatching to " + focus + ": " + event);
5349
5350 if (uid != 0 && uid != focus.mSession.mUid) {
5351 if (mContext.checkPermission(
5352 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5353 != PackageManager.PERMISSION_GRANTED) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005354 Slog.w(TAG, "Permission denied: injecting key event from pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005355 + pid + " uid " + uid + " to window " + focus
5356 + " owned by uid " + focus.mSession.mUid);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005357 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005358 }
5359 }
Romain Guy06882f82009-06-10 13:36:04 -07005360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005361 synchronized(mWindowMap) {
5362 mKeyWaiter.bindTargetWindowLocked(focus);
5363 }
5364
5365 // NOSHIP extra state logging
5366 mKeyWaiter.recordDispatchState(event, focus);
5367 // END NOSHIP
Romain Guy06882f82009-06-10 13:36:04 -07005368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005369 try {
5370 if (DEBUG_INPUT || DEBUG_FOCUS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005371 Slog.v(TAG, "Delivering key " + event.getKeyCode()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005372 + " to " + focus);
5373 }
5374 focus.mClient.dispatchKey(event);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005375 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005376 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005377 Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005378 try {
5379 removeWindow(focus.mSession, focus.mClient);
5380 } catch (java.util.NoSuchElementException ex) {
5381 // This will happen if the window has already been
5382 // removed.
5383 }
5384 }
Romain Guy06882f82009-06-10 13:36:04 -07005385
Dianne Hackborncfaef692009-06-15 14:24:44 -07005386 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005387 }
Romain Guy06882f82009-06-10 13:36:04 -07005388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005389 public void pauseKeyDispatching(IBinder _token) {
5390 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5391 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005392 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005393 }
5394
5395 synchronized (mWindowMap) {
5396 WindowToken token = mTokenMap.get(_token);
5397 if (token != null) {
5398 mKeyWaiter.pauseDispatchingLocked(token);
5399 }
5400 }
5401 }
5402
5403 public void resumeKeyDispatching(IBinder _token) {
5404 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5405 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005406 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005407 }
5408
5409 synchronized (mWindowMap) {
5410 WindowToken token = mTokenMap.get(_token);
5411 if (token != null) {
5412 mKeyWaiter.resumeDispatchingLocked(token);
5413 }
5414 }
5415 }
5416
5417 public void setEventDispatching(boolean enabled) {
5418 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5419 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005420 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005421 }
5422
5423 synchronized (mWindowMap) {
5424 mKeyWaiter.setEventDispatchingLocked(enabled);
5425 }
5426 }
Romain Guy06882f82009-06-10 13:36:04 -07005427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005428 /**
5429 * Injects a keystroke event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005430 *
5431 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005432 * {@link SystemClock#uptimeMillis()} as the timebase.)
5433 * @param sync If true, wait for the event to be completed before returning to the caller.
5434 * @return Returns true if event was dispatched, false if it was dropped for any reason
5435 */
5436 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5437 long downTime = ev.getDownTime();
5438 long eventTime = ev.getEventTime();
5439
5440 int action = ev.getAction();
5441 int code = ev.getKeyCode();
5442 int repeatCount = ev.getRepeatCount();
5443 int metaState = ev.getMetaState();
5444 int deviceId = ev.getDeviceId();
5445 int scancode = ev.getScanCode();
5446
5447 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5448 if (downTime == 0) downTime = eventTime;
5449
5450 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
The Android Open Source Project10592532009-03-18 17:39:46 -07005451 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005452
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005453 final int pid = Binder.getCallingPid();
5454 final int uid = Binder.getCallingUid();
5455 final long ident = Binder.clearCallingIdentity();
5456 final int result = dispatchKey(newEvent, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005457 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005458 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005459 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005460 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005461 switch (result) {
5462 case INJECT_NO_PERMISSION:
5463 throw new SecurityException(
Chander S Pechetty27f3de62010-02-10 22:14:00 +05305464 "Injecting to another application requires INJECT_EVENTS permission");
Dianne Hackborncfaef692009-06-15 14:24:44 -07005465 case INJECT_SUCCEEDED:
5466 return true;
5467 }
5468 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005469 }
5470
5471 /**
5472 * Inject a pointer (touch) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005473 *
5474 * @param ev A motion event describing the pointer (touch) action. (As noted in
5475 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005476 * {@link SystemClock#uptimeMillis()} as the timebase.)
5477 * @param sync If true, wait for the event to be completed before returning to the caller.
5478 * @return Returns true if event was dispatched, false if it was dropped for any reason
5479 */
5480 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005481 final int pid = Binder.getCallingPid();
5482 final int uid = Binder.getCallingUid();
5483 final long ident = Binder.clearCallingIdentity();
5484 final int result = dispatchPointer(null, ev, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005485 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005486 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005487 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005488 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005489 switch (result) {
5490 case INJECT_NO_PERMISSION:
5491 throw new SecurityException(
Chander S Pechetty27f3de62010-02-10 22:14:00 +05305492 "Injecting to another application requires INJECT_EVENTS permission");
Dianne Hackborncfaef692009-06-15 14:24:44 -07005493 case INJECT_SUCCEEDED:
5494 return true;
5495 }
5496 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005497 }
Romain Guy06882f82009-06-10 13:36:04 -07005498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005499 /**
5500 * Inject a trackball (navigation device) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005501 *
5502 * @param ev A motion event describing the trackball action. (As noted in
5503 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005504 * {@link SystemClock#uptimeMillis()} as the timebase.)
5505 * @param sync If true, wait for the event to be completed before returning to the caller.
5506 * @return Returns true if event was dispatched, false if it was dropped for any reason
5507 */
5508 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005509 final int pid = Binder.getCallingPid();
5510 final int uid = Binder.getCallingUid();
5511 final long ident = Binder.clearCallingIdentity();
5512 final int result = dispatchTrackball(null, ev, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005513 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005514 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005515 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005516 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005517 switch (result) {
5518 case INJECT_NO_PERMISSION:
5519 throw new SecurityException(
Chander S Pechetty27f3de62010-02-10 22:14:00 +05305520 "Injecting to another application requires INJECT_EVENTS permission");
Dianne Hackborncfaef692009-06-15 14:24:44 -07005521 case INJECT_SUCCEEDED:
5522 return true;
5523 }
5524 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005525 }
Romain Guy06882f82009-06-10 13:36:04 -07005526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005527 private WindowState getFocusedWindow() {
5528 synchronized (mWindowMap) {
5529 return getFocusedWindowLocked();
5530 }
5531 }
5532
5533 private WindowState getFocusedWindowLocked() {
5534 return mCurrentFocus;
5535 }
Romain Guy06882f82009-06-10 13:36:04 -07005536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005537 /**
5538 * This class holds the state for dispatching key events. This state
5539 * is protected by the KeyWaiter instance, NOT by the window lock. You
5540 * can be holding the main window lock while acquire the KeyWaiter lock,
5541 * but not the other way around.
5542 */
5543 final class KeyWaiter {
5544 // NOSHIP debugging
5545 public class DispatchState {
5546 private KeyEvent event;
5547 private WindowState focus;
5548 private long time;
5549 private WindowState lastWin;
5550 private IBinder lastBinder;
5551 private boolean finished;
5552 private boolean gotFirstWindow;
5553 private boolean eventDispatching;
5554 private long timeToSwitch;
5555 private boolean wasFrozen;
5556 private boolean focusPaused;
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005557 private WindowState curFocus;
Romain Guy06882f82009-06-10 13:36:04 -07005558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005559 DispatchState(KeyEvent theEvent, WindowState theFocus) {
5560 focus = theFocus;
5561 event = theEvent;
5562 time = System.currentTimeMillis();
5563 // snapshot KeyWaiter state
5564 lastWin = mLastWin;
5565 lastBinder = mLastBinder;
5566 finished = mFinished;
5567 gotFirstWindow = mGotFirstWindow;
5568 eventDispatching = mEventDispatching;
5569 timeToSwitch = mTimeToSwitch;
5570 wasFrozen = mWasFrozen;
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005571 curFocus = mCurrentFocus;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005572 // cache the paused state at ctor time as well
5573 if (theFocus == null || theFocus.mToken == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005574 focusPaused = false;
5575 } else {
5576 focusPaused = theFocus.mToken.paused;
5577 }
5578 }
Romain Guy06882f82009-06-10 13:36:04 -07005579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005580 public String toString() {
5581 return "{{" + event + " to " + focus + " @ " + time
5582 + " lw=" + lastWin + " lb=" + lastBinder
5583 + " fin=" + finished + " gfw=" + gotFirstWindow
5584 + " ed=" + eventDispatching + " tts=" + timeToSwitch
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005585 + " wf=" + wasFrozen + " fp=" + focusPaused
Christopher Tate46d45252010-02-09 15:48:57 -08005586 + " mcf=" + curFocus + "}}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005587 }
5588 };
5589 private DispatchState mDispatchState = null;
5590 public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) {
5591 mDispatchState = new DispatchState(theEvent, theFocus);
5592 }
5593 // END NOSHIP
5594
5595 public static final int RETURN_NOTHING = 0;
5596 public static final int RETURN_PENDING_POINTER = 1;
5597 public static final int RETURN_PENDING_TRACKBALL = 2;
Romain Guy06882f82009-06-10 13:36:04 -07005598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005599 final Object SKIP_TARGET_TOKEN = new Object();
5600 final Object CONSUMED_EVENT_TOKEN = new Object();
Romain Guy06882f82009-06-10 13:36:04 -07005601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005602 private WindowState mLastWin = null;
5603 private IBinder mLastBinder = null;
5604 private boolean mFinished = true;
5605 private boolean mGotFirstWindow = false;
5606 private boolean mEventDispatching = true;
5607 private long mTimeToSwitch = 0;
5608 /* package */ boolean mWasFrozen = false;
Romain Guy06882f82009-06-10 13:36:04 -07005609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005610 // Target of Motion events
5611 WindowState mMotionTarget;
Romain Guy06882f82009-06-10 13:36:04 -07005612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005613 // Windows above the target who would like to receive an "outside"
5614 // touch event for any down events outside of them.
5615 WindowState mOutsideTouchTargets;
5616
5617 /**
5618 * Wait for the last event dispatch to complete, then find the next
5619 * target that should receive the given event and wait for that one
5620 * to be ready to receive it.
5621 */
5622 Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev,
5623 MotionEvent nextMotion, boolean isPointerEvent,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005624 boolean failIfTimeout, int callingPid, int callingUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005625 long startTime = SystemClock.uptimeMillis();
5626 long keyDispatchingTimeout = 5 * 1000;
5627 long waitedFor = 0;
5628
5629 while (true) {
5630 // Figure out which window we care about. It is either the
5631 // last window we are waiting to have process the event or,
5632 // if none, then the next window we think the event should go
5633 // to. Note: we retrieve mLastWin outside of the lock, so
5634 // it may change before we lock. Thus we must check it again.
5635 WindowState targetWin = mLastWin;
5636 boolean targetIsNew = targetWin == null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005637 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005638 TAG, "waitForLastKey: mFinished=" + mFinished +
5639 ", mLastWin=" + mLastWin);
5640 if (targetIsNew) {
5641 Object target = findTargetWindow(nextKey, qev, nextMotion,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005642 isPointerEvent, callingPid, callingUid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005643 if (target == SKIP_TARGET_TOKEN) {
5644 // The user has pressed a special key, and we are
5645 // dropping all pending events before it.
Joe Onorato8a9b2202010-02-26 18:56:32 -08005646 if (DEBUG_INPUT) Slog.v(TAG, "Skipping: " + nextKey
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005647 + " " + nextMotion);
5648 return null;
5649 }
5650 if (target == CONSUMED_EVENT_TOKEN) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005651 if (DEBUG_INPUT) Slog.v(TAG, "Consumed: " + nextKey
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005652 + " " + nextMotion);
5653 return target;
5654 }
5655 targetWin = (WindowState)target;
5656 }
Romain Guy06882f82009-06-10 13:36:04 -07005657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005658 AppWindowToken targetApp = null;
Romain Guy06882f82009-06-10 13:36:04 -07005659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005660 // Now: is it okay to send the next event to this window?
5661 synchronized (this) {
5662 // First: did we come here based on the last window not
5663 // being null, but it changed by the time we got here?
5664 // If so, try again.
5665 if (!targetIsNew && mLastWin == null) {
5666 continue;
5667 }
Romain Guy06882f82009-06-10 13:36:04 -07005668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005669 // We never dispatch events if not finished with the
5670 // last one, or the display is frozen.
5671 if (mFinished && !mDisplayFrozen) {
5672 // If event dispatching is disabled, then we
5673 // just consume the events.
5674 if (!mEventDispatching) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005675 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005676 "Skipping event; dispatching disabled: "
5677 + nextKey + " " + nextMotion);
5678 return null;
5679 }
5680 if (targetWin != null) {
5681 // If this is a new target, and that target is not
5682 // paused or unresponsive, then all looks good to
5683 // handle the event.
5684 if (targetIsNew && !targetWin.mToken.paused) {
5685 return targetWin;
5686 }
Romain Guy06882f82009-06-10 13:36:04 -07005687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005688 // If we didn't find a target window, and there is no
5689 // focused app window, then just eat the events.
5690 } else if (mFocusedApp == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005691 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005692 "Skipping event; no focused app: "
5693 + nextKey + " " + nextMotion);
5694 return null;
5695 }
5696 }
Romain Guy06882f82009-06-10 13:36:04 -07005697
Joe Onorato8a9b2202010-02-26 18:56:32 -08005698 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005699 TAG, "Waiting for last key in " + mLastBinder
5700 + " target=" + targetWin
5701 + " mFinished=" + mFinished
5702 + " mDisplayFrozen=" + mDisplayFrozen
5703 + " targetIsNew=" + targetIsNew
5704 + " paused="
5705 + (targetWin != null ? targetWin.mToken.paused : false)
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005706 + " mFocusedApp=" + mFocusedApp
5707 + " mCurrentFocus=" + mCurrentFocus);
Romain Guy06882f82009-06-10 13:36:04 -07005708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005709 targetApp = targetWin != null
5710 ? targetWin.mAppToken : mFocusedApp;
Romain Guy06882f82009-06-10 13:36:04 -07005711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005712 long curTimeout = keyDispatchingTimeout;
5713 if (mTimeToSwitch != 0) {
5714 long now = SystemClock.uptimeMillis();
5715 if (mTimeToSwitch <= now) {
5716 // If an app switch key has been pressed, and we have
5717 // waited too long for the current app to finish
5718 // processing keys, then wait no more!
Christopher Tate136b1f92010-02-11 17:51:24 -08005719 doFinishedKeyLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005720 continue;
5721 }
5722 long switchTimeout = mTimeToSwitch - now;
5723 if (curTimeout > switchTimeout) {
5724 curTimeout = switchTimeout;
5725 }
5726 }
Romain Guy06882f82009-06-10 13:36:04 -07005727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005728 try {
5729 // after that continue
5730 // processing keys, so we don't get stuck.
Joe Onorato8a9b2202010-02-26 18:56:32 -08005731 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005732 TAG, "Waiting for key dispatch: " + curTimeout);
5733 wait(curTimeout);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005734 if (DEBUG_INPUT) Slog.v(TAG, "Finished waiting @"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005735 + SystemClock.uptimeMillis() + " startTime="
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005736 + startTime + " switchTime=" + mTimeToSwitch
5737 + " target=" + targetWin + " mLW=" + mLastWin
5738 + " mLB=" + mLastBinder + " fin=" + mFinished
5739 + " mCurrentFocus=" + mCurrentFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005740 } catch (InterruptedException e) {
5741 }
5742 }
5743
5744 // If we were frozen during configuration change, restart the
5745 // timeout checks from now; otherwise look at whether we timed
5746 // out before awakening.
5747 if (mWasFrozen) {
5748 waitedFor = 0;
5749 mWasFrozen = false;
5750 } else {
5751 waitedFor = SystemClock.uptimeMillis() - startTime;
5752 }
5753
5754 if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) {
5755 IApplicationToken at = null;
5756 synchronized (this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005757 Slog.w(TAG, "Key dispatching timed out sending to " +
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005758 (targetWin != null ? targetWin.mAttrs.getTitle()
Ken Shirriff8200b202010-02-04 13:34:37 -08005759 : "<null>: no window ready for key dispatch"));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005760 // NOSHIP debugging
Joe Onorato8a9b2202010-02-26 18:56:32 -08005761 Slog.w(TAG, "Previous dispatch state: " + mDispatchState);
5762 Slog.w(TAG, "Current dispatch state: " +
Ken Shirriff8200b202010-02-04 13:34:37 -08005763 new DispatchState(nextKey, targetWin));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005764 // END NOSHIP
5765 //dump();
5766 if (targetWin != null) {
5767 at = targetWin.getAppToken();
5768 } else if (targetApp != null) {
5769 at = targetApp.appToken;
5770 }
5771 }
5772
5773 boolean abort = true;
5774 if (at != null) {
5775 try {
5776 long timeout = at.getKeyDispatchingTimeout();
5777 if (timeout > waitedFor) {
5778 // we did not wait the proper amount of time for this application.
5779 // set the timeout to be the real timeout and wait again.
5780 keyDispatchingTimeout = timeout - waitedFor;
5781 continue;
5782 } else {
5783 abort = at.keyDispatchingTimedOut();
5784 }
5785 } catch (RemoteException ex) {
5786 }
5787 }
5788
5789 synchronized (this) {
5790 if (abort && (mLastWin == targetWin || targetWin == null)) {
5791 mFinished = true;
Romain Guy06882f82009-06-10 13:36:04 -07005792 if (mLastWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005793 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005794 "Window " + mLastWin +
5795 " timed out on key input");
5796 if (mLastWin.mToken.paused) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005797 Slog.w(TAG, "Un-pausing dispatching to this window");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005798 mLastWin.mToken.paused = false;
5799 }
5800 }
5801 if (mMotionTarget == targetWin) {
5802 mMotionTarget = null;
5803 }
5804 mLastWin = null;
5805 mLastBinder = null;
5806 if (failIfTimeout || targetWin == null) {
5807 return null;
5808 }
5809 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005810 Slog.w(TAG, "Continuing to wait for key to be dispatched");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005811 startTime = SystemClock.uptimeMillis();
5812 }
5813 }
5814 }
5815 }
5816 }
Romain Guy06882f82009-06-10 13:36:04 -07005817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005818 Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005819 MotionEvent nextMotion, boolean isPointerEvent,
5820 int callingPid, int callingUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005821 mOutsideTouchTargets = null;
Romain Guy06882f82009-06-10 13:36:04 -07005822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005823 if (nextKey != null) {
5824 // Find the target window for a normal key event.
5825 final int keycode = nextKey.getKeyCode();
5826 final int repeatCount = nextKey.getRepeatCount();
5827 final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP;
5828 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005830 if (!dispatch) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005831 if (callingUid == 0 ||
5832 mContext.checkPermission(
5833 android.Manifest.permission.INJECT_EVENTS,
5834 callingPid, callingUid)
5835 == PackageManager.PERMISSION_GRANTED) {
5836 mPolicy.interceptKeyTi(null, keycode,
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07005837 nextKey.getMetaState(), down, repeatCount,
5838 nextKey.getFlags());
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005839 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08005840 Slog.w(TAG, "Event timeout during app switch: dropping "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005841 + nextKey);
5842 return SKIP_TARGET_TOKEN;
5843 }
Romain Guy06882f82009-06-10 13:36:04 -07005844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005845 // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")");
Romain Guy06882f82009-06-10 13:36:04 -07005846
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005847 WindowState focus = null;
5848 synchronized(mWindowMap) {
5849 focus = getFocusedWindowLocked();
5850 }
Romain Guy06882f82009-06-10 13:36:04 -07005851
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005852 wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT);
Romain Guy06882f82009-06-10 13:36:04 -07005853
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005854 if (callingUid == 0 ||
5855 (focus != null && callingUid == focus.mSession.mUid) ||
5856 mContext.checkPermission(
5857 android.Manifest.permission.INJECT_EVENTS,
5858 callingPid, callingUid)
5859 == PackageManager.PERMISSION_GRANTED) {
5860 if (mPolicy.interceptKeyTi(focus,
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005861 keycode, nextKey.getMetaState(), down, repeatCount,
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07005862 nextKey.getFlags())) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005863 return CONSUMED_EVENT_TOKEN;
5864 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005865 }
Romain Guy06882f82009-06-10 13:36:04 -07005866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005867 return focus;
Romain Guy06882f82009-06-10 13:36:04 -07005868
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005869 } else if (!isPointerEvent) {
5870 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1);
5871 if (!dispatch) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005872 Slog.w(TAG, "Event timeout during app switch: dropping trackball "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005873 + nextMotion);
5874 return SKIP_TARGET_TOKEN;
5875 }
Romain Guy06882f82009-06-10 13:36:04 -07005876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005877 WindowState focus = null;
5878 synchronized(mWindowMap) {
5879 focus = getFocusedWindowLocked();
5880 }
Romain Guy06882f82009-06-10 13:36:04 -07005881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005882 wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT);
5883 return focus;
5884 }
Romain Guy06882f82009-06-10 13:36:04 -07005885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005886 if (nextMotion == null) {
5887 return SKIP_TARGET_TOKEN;
5888 }
Romain Guy06882f82009-06-10 13:36:04 -07005889
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005890 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(
5891 KeyEvent.KEYCODE_UNKNOWN);
5892 if (!dispatch) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005893 Slog.w(TAG, "Event timeout during app switch: dropping pointer "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005894 + nextMotion);
5895 return SKIP_TARGET_TOKEN;
5896 }
Romain Guy06882f82009-06-10 13:36:04 -07005897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005898 // Find the target window for a pointer event.
5899 int action = nextMotion.getAction();
5900 final float xf = nextMotion.getX();
5901 final float yf = nextMotion.getY();
5902 final long eventTime = nextMotion.getEventTime();
Romain Guy06882f82009-06-10 13:36:04 -07005903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005904 final boolean screenWasOff = qev != null
5905 && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07005906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005907 WindowState target = null;
Romain Guy06882f82009-06-10 13:36:04 -07005908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005909 synchronized(mWindowMap) {
5910 synchronized (this) {
5911 if (action == MotionEvent.ACTION_DOWN) {
5912 if (mMotionTarget != null) {
5913 // this is weird, we got a pen down, but we thought it was
5914 // already down!
5915 // XXX: We should probably send an ACTION_UP to the current
5916 // target.
Joe Onorato8a9b2202010-02-26 18:56:32 -08005917 Slog.w(TAG, "Pointer down received while already down in: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005918 + mMotionTarget);
5919 mMotionTarget = null;
5920 }
Romain Guy06882f82009-06-10 13:36:04 -07005921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005922 // ACTION_DOWN is special, because we need to lock next events to
5923 // the window we'll land onto.
5924 final int x = (int)xf;
5925 final int y = (int)yf;
Romain Guy06882f82009-06-10 13:36:04 -07005926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005927 final ArrayList windows = mWindows;
5928 final int N = windows.size();
5929 WindowState topErrWindow = null;
5930 final Rect tmpRect = mTempRect;
5931 for (int i=N-1; i>=0; i--) {
5932 WindowState child = (WindowState)windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005933 //Slog.i(TAG, "Checking dispatch to: " + child);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005934 final int flags = child.mAttrs.flags;
5935 if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) {
5936 if (topErrWindow == null) {
5937 topErrWindow = child;
5938 }
5939 }
5940 if (!child.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005941 //Slog.i(TAG, "Not visible!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005942 continue;
5943 }
5944 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005945 //Slog.i(TAG, "Not touchable!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005946 if ((flags & WindowManager.LayoutParams
5947 .FLAG_WATCH_OUTSIDE_TOUCH) != 0) {
5948 child.mNextOutsideTouch = mOutsideTouchTargets;
5949 mOutsideTouchTargets = child;
5950 }
5951 continue;
5952 }
5953 tmpRect.set(child.mFrame);
5954 if (child.mTouchableInsets == ViewTreeObserver
5955 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
5956 // The touch is inside of the window if it is
5957 // inside the frame, AND the content part of that
5958 // frame that was given by the application.
5959 tmpRect.left += child.mGivenContentInsets.left;
5960 tmpRect.top += child.mGivenContentInsets.top;
5961 tmpRect.right -= child.mGivenContentInsets.right;
5962 tmpRect.bottom -= child.mGivenContentInsets.bottom;
5963 } else if (child.mTouchableInsets == ViewTreeObserver
5964 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
5965 // The touch is inside of the window if it is
5966 // inside the frame, AND the visible part of that
5967 // frame that was given by the application.
5968 tmpRect.left += child.mGivenVisibleInsets.left;
5969 tmpRect.top += child.mGivenVisibleInsets.top;
5970 tmpRect.right -= child.mGivenVisibleInsets.right;
5971 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
5972 }
5973 final int touchFlags = flags &
5974 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
5975 |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
5976 if (tmpRect.contains(x, y) || touchFlags == 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005977 //Slog.i(TAG, "Using this target!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005978 if (!screenWasOff || (flags &
5979 WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) {
5980 mMotionTarget = child;
5981 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005982 //Slog.i(TAG, "Waking, skip!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005983 mMotionTarget = null;
5984 }
5985 break;
5986 }
Romain Guy06882f82009-06-10 13:36:04 -07005987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005988 if ((flags & WindowManager.LayoutParams
5989 .FLAG_WATCH_OUTSIDE_TOUCH) != 0) {
5990 child.mNextOutsideTouch = mOutsideTouchTargets;
5991 mOutsideTouchTargets = child;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005992 //Slog.i(TAG, "Adding to outside target list: " + child);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005993 }
5994 }
5995
5996 // if there's an error window but it's not accepting
5997 // focus (typically because it is not yet visible) just
5998 // wait for it -- any other focused window may in fact
5999 // be in ANR state.
6000 if (topErrWindow != null && mMotionTarget != topErrWindow) {
6001 mMotionTarget = null;
6002 }
6003 }
Romain Guy06882f82009-06-10 13:36:04 -07006004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006005 target = mMotionTarget;
6006 }
6007 }
Romain Guy06882f82009-06-10 13:36:04 -07006008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006009 wakeupIfNeeded(target, eventType(nextMotion));
Romain Guy06882f82009-06-10 13:36:04 -07006010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006011 // Pointer events are a little different -- if there isn't a
6012 // target found for any event, then just drop it.
6013 return target != null ? target : SKIP_TARGET_TOKEN;
6014 }
Romain Guy06882f82009-06-10 13:36:04 -07006015
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006016 boolean checkShouldDispatchKey(int keycode) {
6017 synchronized (this) {
6018 if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) {
6019 mTimeToSwitch = 0;
6020 return true;
6021 }
6022 if (mTimeToSwitch != 0
6023 && mTimeToSwitch < SystemClock.uptimeMillis()) {
6024 return false;
6025 }
6026 return true;
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 int pendingWhat, QueuedEvent pendingMotion) {
6032 synchronized (this) {
6033 bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion);
6034 }
6035 }
Romain Guy06882f82009-06-10 13:36:04 -07006036
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006037 void bindTargetWindowLocked(WindowState win) {
6038 synchronized (this) {
6039 bindTargetWindowLockedLocked(win, RETURN_NOTHING, null);
6040 }
6041 }
6042
6043 void bindTargetWindowLockedLocked(WindowState win,
6044 int pendingWhat, QueuedEvent pendingMotion) {
6045 mLastWin = win;
6046 mLastBinder = win.mClient.asBinder();
6047 mFinished = false;
6048 if (pendingMotion != null) {
6049 final Session s = win.mSession;
6050 if (pendingWhat == RETURN_PENDING_POINTER) {
6051 releasePendingPointerLocked(s);
6052 s.mPendingPointerMove = pendingMotion;
6053 s.mPendingPointerWindow = win;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006054 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006055 "bindTargetToWindow " + s.mPendingPointerMove);
6056 } else if (pendingWhat == RETURN_PENDING_TRACKBALL) {
6057 releasePendingTrackballLocked(s);
6058 s.mPendingTrackballMove = pendingMotion;
6059 s.mPendingTrackballWindow = win;
6060 }
6061 }
6062 }
Romain Guy06882f82009-06-10 13:36:04 -07006063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006064 void releasePendingPointerLocked(Session s) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006065 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006066 "releasePendingPointer " + s.mPendingPointerMove);
6067 if (s.mPendingPointerMove != null) {
6068 mQueue.recycleEvent(s.mPendingPointerMove);
6069 s.mPendingPointerMove = null;
6070 }
6071 }
Romain Guy06882f82009-06-10 13:36:04 -07006072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006073 void releasePendingTrackballLocked(Session s) {
6074 if (s.mPendingTrackballMove != null) {
6075 mQueue.recycleEvent(s.mPendingTrackballMove);
6076 s.mPendingTrackballMove = null;
6077 }
6078 }
Romain Guy06882f82009-06-10 13:36:04 -07006079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006080 MotionEvent finishedKey(Session session, IWindow client, boolean force,
6081 int returnWhat) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006082 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006083 TAG, "finishedKey: client=" + client + ", force=" + force);
6084
6085 if (client == null) {
6086 return null;
6087 }
6088
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006089 MotionEvent res = null;
6090 QueuedEvent qev = null;
6091 WindowState win = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006093 synchronized (this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006094 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006095 TAG, "finishedKey: client=" + client.asBinder()
6096 + ", force=" + force + ", last=" + mLastBinder
6097 + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")");
6098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006099 if (returnWhat == RETURN_PENDING_POINTER) {
6100 qev = session.mPendingPointerMove;
6101 win = session.mPendingPointerWindow;
6102 session.mPendingPointerMove = null;
6103 session.mPendingPointerWindow = null;
6104 } else if (returnWhat == RETURN_PENDING_TRACKBALL) {
6105 qev = session.mPendingTrackballMove;
6106 win = session.mPendingTrackballWindow;
6107 session.mPendingTrackballMove = null;
6108 session.mPendingTrackballWindow = null;
6109 }
Romain Guy06882f82009-06-10 13:36:04 -07006110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006111 if (mLastBinder == client.asBinder()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006112 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006113 TAG, "finishedKey: last paused="
6114 + ((mLastWin != null) ? mLastWin.mToken.paused : "null"));
6115 if (mLastWin != null && (!mLastWin.mToken.paused || force
6116 || !mEventDispatching)) {
Christopher Tate136b1f92010-02-11 17:51:24 -08006117 doFinishedKeyLocked(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006118 } else {
6119 // Make sure to wake up anyone currently waiting to
6120 // dispatch a key, so they can re-evaluate their
6121 // current situation.
6122 mFinished = true;
6123 notifyAll();
6124 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006125 }
Romain Guy06882f82009-06-10 13:36:04 -07006126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006127 if (qev != null) {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006128 res = (MotionEvent)qev.event;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006129 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006130 "Returning pending motion: " + res);
6131 mQueue.recycleEvent(qev);
6132 if (win != null && returnWhat == RETURN_PENDING_POINTER) {
6133 res.offsetLocation(-win.mFrame.left, -win.mFrame.top);
6134 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006135 }
Christopher Tate2624fbc2009-12-11 12:11:31 -08006136 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006137
Christopher Tate2624fbc2009-12-11 12:11:31 -08006138 if (res != null && returnWhat == RETURN_PENDING_POINTER) {
6139 synchronized (mWindowMap) {
Dianne Hackborn90d2db32010-02-11 22:19:06 -08006140 dispatchPointerElsewhereLocked(win, win, res, res.getEventTime(), false);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006141 }
6142 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006143
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006144 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006145 }
6146
6147 void tickle() {
6148 synchronized (this) {
6149 notifyAll();
6150 }
6151 }
Romain Guy06882f82009-06-10 13:36:04 -07006152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006153 void handleNewWindowLocked(WindowState newWindow) {
6154 if (!newWindow.canReceiveKeys()) {
6155 return;
6156 }
6157 synchronized (this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006158 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006159 TAG, "New key dispatch window: win="
6160 + newWindow.mClient.asBinder()
6161 + ", last=" + mLastBinder
6162 + " (token=" + (mLastWin != null ? mLastWin.mToken : null)
6163 + "), finished=" + mFinished + ", paused="
6164 + newWindow.mToken.paused);
6165
6166 // Displaying a window implicitly causes dispatching to
6167 // be unpaused. (This is to protect against bugs if someone
6168 // pauses dispatching but forgets to resume.)
6169 newWindow.mToken.paused = false;
6170
6171 mGotFirstWindow = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006172
6173 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006174 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006175 "New SYSTEM_ERROR window; resetting state");
6176 mLastWin = null;
6177 mLastBinder = null;
6178 mMotionTarget = null;
6179 mFinished = true;
6180 } else if (mLastWin != null) {
6181 // If the new window is above the window we are
6182 // waiting on, then stop waiting and let key dispatching
6183 // start on the new guy.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006184 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006185 TAG, "Last win layer=" + mLastWin.mLayer
6186 + ", new win layer=" + newWindow.mLayer);
6187 if (newWindow.mLayer >= mLastWin.mLayer) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08006188 // The new window is above the old; finish pending input to the last
6189 // window and start directing it to the new one.
6190 mLastWin.mToken.paused = false;
Christopher Tate136b1f92010-02-11 17:51:24 -08006191 doFinishedKeyLocked(false); // does a notifyAll()
6192 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006193 }
6194 }
6195
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08006196 // Now that we've put a new window state in place, make the event waiter
6197 // take notice and retarget its attentions.
6198 notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006199 }
6200 }
6201
6202 void pauseDispatchingLocked(WindowToken token) {
6203 synchronized (this)
6204 {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006205 if (DEBUG_INPUT) Slog.v(TAG, "Pausing WindowToken " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006206 token.paused = true;
6207
6208 /*
6209 if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) {
6210 mPaused = true;
6211 } else {
6212 if (mLastWin == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006213 Slog.i(TAG, "Key dispatching not paused: no last window.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006214 } else if (mFinished) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006215 Slog.i(TAG, "Key dispatching not paused: finished last key.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006216 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006217 Slog.i(TAG, "Key dispatching not paused: window in higher layer.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006218 }
6219 }
6220 */
6221 }
6222 }
6223
6224 void resumeDispatchingLocked(WindowToken token) {
6225 synchronized (this) {
6226 if (token.paused) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006227 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006228 TAG, "Resuming WindowToken " + token
6229 + ", last=" + mLastBinder
6230 + " (token=" + (mLastWin != null ? mLastWin.mToken : null)
6231 + "), finished=" + mFinished + ", paused="
6232 + token.paused);
6233 token.paused = false;
6234 if (mLastWin != null && mLastWin.mToken == token && mFinished) {
Christopher Tate136b1f92010-02-11 17:51:24 -08006235 doFinishedKeyLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006236 } else {
6237 notifyAll();
6238 }
6239 }
6240 }
6241 }
6242
6243 void setEventDispatchingLocked(boolean enabled) {
6244 synchronized (this) {
6245 mEventDispatching = enabled;
6246 notifyAll();
6247 }
6248 }
Romain Guy06882f82009-06-10 13:36:04 -07006249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006250 void appSwitchComing() {
6251 synchronized (this) {
6252 // Don't wait for more than .5 seconds for app to finish
6253 // processing the pending events.
6254 long now = SystemClock.uptimeMillis() + 500;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006255 if (DEBUG_INPUT) Slog.v(TAG, "appSwitchComing: " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006256 if (mTimeToSwitch == 0 || now < mTimeToSwitch) {
6257 mTimeToSwitch = now;
6258 }
6259 notifyAll();
6260 }
6261 }
Romain Guy06882f82009-06-10 13:36:04 -07006262
Christopher Tate136b1f92010-02-11 17:51:24 -08006263 private final void doFinishedKeyLocked(boolean force) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006264 if (mLastWin != null) {
6265 releasePendingPointerLocked(mLastWin.mSession);
6266 releasePendingTrackballLocked(mLastWin.mSession);
6267 }
Romain Guy06882f82009-06-10 13:36:04 -07006268
Christopher Tate136b1f92010-02-11 17:51:24 -08006269 if (force || mLastWin == null || !mLastWin.mToken.paused
6270 || !mLastWin.isVisibleLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006271 // If the current window has been paused, we aren't -really-
6272 // finished... so let the waiters still wait.
6273 mLastWin = null;
6274 mLastBinder = null;
6275 }
6276 mFinished = true;
6277 notifyAll();
6278 }
6279 }
6280
6281 private class KeyQ extends KeyInputQueue
6282 implements KeyInputQueue.FilterCallback {
6283 PowerManager.WakeLock mHoldingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07006284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006285 KeyQ() {
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07006286 super(mContext, WindowManagerService.this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006287 PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
6288 mHoldingScreen = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
6289 "KEEP_SCREEN_ON_FLAG");
6290 mHoldingScreen.setReferenceCounted(false);
6291 }
6292
6293 @Override
6294 boolean preprocessEvent(InputDevice device, RawInputEvent event) {
6295 if (mPolicy.preprocessInputEventTq(event)) {
6296 return true;
6297 }
Romain Guy06882f82009-06-10 13:36:04 -07006298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006299 switch (event.type) {
6300 case RawInputEvent.EV_KEY: {
6301 // XXX begin hack
6302 if (DEBUG) {
6303 if (event.keycode == KeyEvent.KEYCODE_G) {
6304 if (event.value != 0) {
6305 // G down
6306 mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
6307 }
6308 return false;
6309 }
6310 if (event.keycode == KeyEvent.KEYCODE_D) {
6311 if (event.value != 0) {
6312 //dump();
6313 }
6314 return false;
6315 }
6316 }
6317 // XXX end hack
Romain Guy06882f82009-06-10 13:36:04 -07006318
Charles Mendis322591c2009-10-29 11:06:59 -07006319 boolean screenIsOff = !mPowerManager.isScreenOn();
6320 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006321 int actions = mPolicy.interceptKeyTq(event, !screenIsOff);
Romain Guy06882f82009-06-10 13:36:04 -07006322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006323 if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) {
6324 mPowerManager.goToSleep(event.when);
6325 }
6326
6327 if (screenIsOff) {
6328 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6329 }
6330 if (screenIsDim) {
6331 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6332 }
6333 if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) {
6334 mPowerManager.userActivity(event.when, false,
Michael Chane96440f2009-05-06 10:27:36 -07006335 LocalPowerManager.BUTTON_EVENT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006336 }
Romain Guy06882f82009-06-10 13:36:04 -07006337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006338 if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) {
6339 if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) {
6340 filterQueue(this);
6341 mKeyWaiter.appSwitchComing();
6342 }
6343 return true;
6344 } else {
6345 return false;
6346 }
6347 }
Romain Guy06882f82009-06-10 13:36:04 -07006348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006349 case RawInputEvent.EV_REL: {
Charles Mendis322591c2009-10-29 11:06:59 -07006350 boolean screenIsOff = !mPowerManager.isScreenOn();
6351 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006352 if (screenIsOff) {
6353 if (!mPolicy.isWakeRelMovementTq(event.deviceId,
6354 device.classes, event)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006355 //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006356 return false;
6357 }
6358 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6359 }
6360 if (screenIsDim) {
6361 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6362 }
6363 return true;
6364 }
Romain Guy06882f82009-06-10 13:36:04 -07006365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006366 case RawInputEvent.EV_ABS: {
Charles Mendis322591c2009-10-29 11:06:59 -07006367 boolean screenIsOff = !mPowerManager.isScreenOn();
6368 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006369 if (screenIsOff) {
6370 if (!mPolicy.isWakeAbsMovementTq(event.deviceId,
6371 device.classes, event)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006372 //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006373 return false;
6374 }
6375 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6376 }
6377 if (screenIsDim) {
6378 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6379 }
6380 return true;
6381 }
Romain Guy06882f82009-06-10 13:36:04 -07006382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006383 default:
6384 return true;
6385 }
6386 }
6387
6388 public int filterEvent(QueuedEvent ev) {
6389 switch (ev.classType) {
6390 case RawInputEvent.CLASS_KEYBOARD:
6391 KeyEvent ke = (KeyEvent)ev.event;
6392 if (mPolicy.isMovementKeyTi(ke.getKeyCode())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006393 Slog.w(TAG, "Dropping movement key during app switch: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006394 + ke.getKeyCode() + ", action=" + ke.getAction());
6395 return FILTER_REMOVE;
6396 }
6397 return FILTER_ABORT;
6398 default:
6399 return FILTER_KEEP;
6400 }
6401 }
Romain Guy06882f82009-06-10 13:36:04 -07006402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006403 /**
6404 * Must be called with the main window manager lock held.
6405 */
6406 void setHoldScreenLocked(boolean holding) {
6407 boolean state = mHoldingScreen.isHeld();
6408 if (holding != state) {
6409 if (holding) {
6410 mHoldingScreen.acquire();
6411 } else {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006412 mPolicy.screenOnStoppedLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006413 mHoldingScreen.release();
6414 }
6415 }
6416 }
Michael Chan53071d62009-05-13 17:29:48 -07006417 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006418
6419 public boolean detectSafeMode() {
6420 mSafeMode = mPolicy.detectSafeMode();
6421 return mSafeMode;
6422 }
Romain Guy06882f82009-06-10 13:36:04 -07006423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006424 public void systemReady() {
6425 mPolicy.systemReady();
6426 }
Romain Guy06882f82009-06-10 13:36:04 -07006427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006428 private final class InputDispatcherThread extends Thread {
6429 // Time to wait when there is nothing to do: 9999 seconds.
6430 static final int LONG_WAIT=9999*1000;
6431
6432 public InputDispatcherThread() {
6433 super("InputDispatcher");
6434 }
Romain Guy06882f82009-06-10 13:36:04 -07006435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006436 @Override
6437 public void run() {
6438 while (true) {
6439 try {
6440 process();
6441 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006442 Slog.e(TAG, "Exception in input dispatcher", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006443 }
6444 }
6445 }
Romain Guy06882f82009-06-10 13:36:04 -07006446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006447 private void process() {
6448 android.os.Process.setThreadPriority(
6449 android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);
Romain Guy06882f82009-06-10 13:36:04 -07006450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006451 // The last key event we saw
6452 KeyEvent lastKey = null;
6453
6454 // Last keydown time for auto-repeating keys
6455 long lastKeyTime = SystemClock.uptimeMillis();
6456 long nextKeyTime = lastKeyTime+LONG_WAIT;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006457 long downTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006458
Romain Guy06882f82009-06-10 13:36:04 -07006459 // How many successive repeats we generated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006460 int keyRepeatCount = 0;
6461
6462 // Need to report that configuration has changed?
6463 boolean configChanged = false;
Romain Guy06882f82009-06-10 13:36:04 -07006464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006465 while (true) {
6466 long curTime = SystemClock.uptimeMillis();
6467
Joe Onorato8a9b2202010-02-26 18:56:32 -08006468 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006469 TAG, "Waiting for next key: now=" + curTime
6470 + ", repeat @ " + nextKeyTime);
6471
6472 // Retrieve next event, waiting only as long as the next
6473 // repeat timeout. If the configuration has changed, then
6474 // don't wait at all -- we'll report the change as soon as
6475 // we have processed all events.
6476 QueuedEvent ev = mQueue.getEvent(
6477 (int)((!configChanged && curTime < nextKeyTime)
6478 ? (nextKeyTime-curTime) : 0));
6479
Joe Onorato8a9b2202010-02-26 18:56:32 -08006480 if (DEBUG_INPUT && ev != null) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006481 TAG, "Event: type=" + ev.classType + " data=" + ev.event);
6482
Michael Chan53071d62009-05-13 17:29:48 -07006483 if (MEASURE_LATENCY) {
6484 lt.sample("2 got event ", System.nanoTime() - ev.whenNano);
6485 }
6486
Mike Lockwood3d0ea722009-10-21 22:58:29 -04006487 if (lastKey != null && !mPolicy.allowKeyRepeat()) {
6488 // cancel key repeat at the request of the policy.
6489 lastKey = null;
6490 downTime = 0;
6491 lastKeyTime = curTime;
6492 nextKeyTime = curTime + LONG_WAIT;
6493 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006494 try {
6495 if (ev != null) {
Michael Chan53071d62009-05-13 17:29:48 -07006496 curTime = SystemClock.uptimeMillis();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006497 int eventType;
6498 if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) {
6499 eventType = eventType((MotionEvent)ev.event);
6500 } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD ||
6501 ev.classType == RawInputEvent.CLASS_TRACKBALL) {
6502 eventType = LocalPowerManager.BUTTON_EVENT;
6503 } else {
6504 eventType = LocalPowerManager.OTHER_EVENT;
6505 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07006506 try {
Michael Chan53071d62009-05-13 17:29:48 -07006507 if ((curTime - mLastBatteryStatsCallTime)
Michael Chane96440f2009-05-06 10:27:36 -07006508 >= MIN_TIME_BETWEEN_USERACTIVITIES) {
Michael Chan53071d62009-05-13 17:29:48 -07006509 mLastBatteryStatsCallTime = curTime;
Michael Chane96440f2009-05-06 10:27:36 -07006510 mBatteryStats.noteInputEvent();
6511 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07006512 } catch (RemoteException e) {
6513 // Ignore
6514 }
Michael Chane10de972009-05-18 11:24:50 -07006515
Mike Lockwood5db42402009-11-30 14:51:51 -05006516 if (ev.classType == RawInputEvent.CLASS_CONFIGURATION_CHANGED) {
6517 // do not wake screen in this case
6518 } else if (eventType != TOUCH_EVENT
Michael Chane10de972009-05-18 11:24:50 -07006519 && eventType != LONG_TOUCH_EVENT
6520 && eventType != CHEEK_EVENT) {
6521 mPowerManager.userActivity(curTime, false,
6522 eventType, false);
6523 } else if (mLastTouchEventType != eventType
6524 || (curTime - mLastUserActivityCallTime)
6525 >= MIN_TIME_BETWEEN_USERACTIVITIES) {
6526 mLastUserActivityCallTime = curTime;
6527 mLastTouchEventType = eventType;
6528 mPowerManager.userActivity(curTime, false,
6529 eventType, false);
6530 }
6531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006532 switch (ev.classType) {
6533 case RawInputEvent.CLASS_KEYBOARD:
6534 KeyEvent ke = (KeyEvent)ev.event;
6535 if (ke.isDown()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006536 lastKeyTime = curTime;
Kristian Dreher133bfdf2010-02-23 08:50:58 +01006537 if (lastKey != null &&
6538 ke.getKeyCode() == lastKey.getKeyCode()) {
6539 keyRepeatCount++;
6540 // Arbitrary long timeout to block
6541 // repeating here since we know that
6542 // the device driver takes care of it.
6543 nextKeyTime = lastKeyTime + LONG_WAIT;
The Android Open Source Project2a9ae012010-05-12 12:33:35 -07006544 if (DEBUG_INPUT) Slog.v(
Kristian Dreher133bfdf2010-02-23 08:50:58 +01006545 TAG, "Received repeated key down");
6546 } else {
6547 downTime = curTime;
6548 keyRepeatCount = 0;
6549 nextKeyTime = lastKeyTime
6550 + ViewConfiguration.getLongPressTimeout();
The Android Open Source Project2a9ae012010-05-12 12:33:35 -07006551 if (DEBUG_INPUT) Slog.v(
Kristian Dreher133bfdf2010-02-23 08:50:58 +01006552 TAG, "Received key down: first repeat @ "
6553 + nextKeyTime);
6554 }
6555 lastKey = ke;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006556 } else {
6557 lastKey = null;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006558 downTime = 0;
Kristian Dreher133bfdf2010-02-23 08:50:58 +01006559 keyRepeatCount = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006560 // Arbitrary long timeout.
6561 lastKeyTime = curTime;
6562 nextKeyTime = curTime + LONG_WAIT;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006563 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006564 TAG, "Received key up: ignore repeat @ "
6565 + nextKeyTime);
6566 }
Kristian Dreher133bfdf2010-02-23 08:50:58 +01006567 if (keyRepeatCount > 0) {
6568 dispatchKey(KeyEvent.changeTimeRepeat(ke,
6569 ke.getEventTime(), keyRepeatCount), 0, 0);
6570 } else {
6571 dispatchKey(ke, 0, 0);
6572 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006573 mQueue.recycleEvent(ev);
6574 break;
6575 case RawInputEvent.CLASS_TOUCHSCREEN:
Joe Onorato8a9b2202010-02-26 18:56:32 -08006576 //Slog.i(TAG, "Read next event " + ev);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006577 dispatchPointer(ev, (MotionEvent)ev.event, 0, 0);
6578 break;
6579 case RawInputEvent.CLASS_TRACKBALL:
6580 dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0);
6581 break;
6582 case RawInputEvent.CLASS_CONFIGURATION_CHANGED:
6583 configChanged = true;
6584 break;
6585 default:
6586 mQueue.recycleEvent(ev);
6587 break;
6588 }
Romain Guy06882f82009-06-10 13:36:04 -07006589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006590 } else if (configChanged) {
6591 configChanged = false;
6592 sendNewConfiguration();
Romain Guy06882f82009-06-10 13:36:04 -07006593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006594 } else if (lastKey != null) {
6595 curTime = SystemClock.uptimeMillis();
Romain Guy06882f82009-06-10 13:36:04 -07006596
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006597 // Timeout occurred while key was down. If it is at or
6598 // past the key repeat time, dispatch the repeat.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006599 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006600 TAG, "Key timeout: repeat=" + nextKeyTime
6601 + ", now=" + curTime);
6602 if (curTime < nextKeyTime) {
6603 continue;
6604 }
Romain Guy06882f82009-06-10 13:36:04 -07006605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006606 lastKeyTime = nextKeyTime;
6607 nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY;
6608 keyRepeatCount++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006609 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006610 TAG, "Key repeat: count=" + keyRepeatCount
6611 + ", next @ " + nextKeyTime);
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006612 KeyEvent newEvent;
6613 if (downTime != 0 && (downTime
6614 + ViewConfiguration.getLongPressTimeout())
6615 <= curTime) {
6616 newEvent = KeyEvent.changeTimeRepeat(lastKey,
6617 curTime, keyRepeatCount,
6618 lastKey.getFlags() | KeyEvent.FLAG_LONG_PRESS);
6619 downTime = 0;
6620 } else {
6621 newEvent = KeyEvent.changeTimeRepeat(lastKey,
6622 curTime, keyRepeatCount);
6623 }
6624 dispatchKey(newEvent, 0, 0);
Romain Guy06882f82009-06-10 13:36:04 -07006625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006626 } else {
6627 curTime = SystemClock.uptimeMillis();
Romain Guy06882f82009-06-10 13:36:04 -07006628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006629 lastKeyTime = curTime;
6630 nextKeyTime = curTime + LONG_WAIT;
6631 }
Romain Guy06882f82009-06-10 13:36:04 -07006632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006633 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006634 Slog.e(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006635 "Input thread received uncaught exception: " + e, e);
6636 }
6637 }
6638 }
6639 }
6640
6641 // -------------------------------------------------------------
6642 // Client Session State
6643 // -------------------------------------------------------------
6644
6645 private final class Session extends IWindowSession.Stub
6646 implements IBinder.DeathRecipient {
6647 final IInputMethodClient mClient;
6648 final IInputContext mInputContext;
6649 final int mUid;
6650 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006651 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006652 SurfaceSession mSurfaceSession;
6653 int mNumWindow = 0;
6654 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006655
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006656 /**
6657 * Current pointer move event being dispatched to client window... must
6658 * hold key lock to access.
6659 */
6660 QueuedEvent mPendingPointerMove;
6661 WindowState mPendingPointerWindow;
Romain Guy06882f82009-06-10 13:36:04 -07006662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006663 /**
6664 * Current trackball move event being dispatched to client window... must
6665 * hold key lock to access.
6666 */
6667 QueuedEvent mPendingTrackballMove;
6668 WindowState mPendingTrackballWindow;
6669
6670 public Session(IInputMethodClient client, IInputContext inputContext) {
6671 mClient = client;
6672 mInputContext = inputContext;
6673 mUid = Binder.getCallingUid();
6674 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006675 StringBuilder sb = new StringBuilder();
6676 sb.append("Session{");
6677 sb.append(Integer.toHexString(System.identityHashCode(this)));
6678 sb.append(" uid ");
6679 sb.append(mUid);
6680 sb.append("}");
6681 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006682
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006683 synchronized (mWindowMap) {
6684 if (mInputMethodManager == null && mHaveInputMethods) {
6685 IBinder b = ServiceManager.getService(
6686 Context.INPUT_METHOD_SERVICE);
6687 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6688 }
6689 }
6690 long ident = Binder.clearCallingIdentity();
6691 try {
6692 // Note: it is safe to call in to the input method manager
6693 // here because we are not holding our lock.
6694 if (mInputMethodManager != null) {
6695 mInputMethodManager.addClient(client, inputContext,
6696 mUid, mPid);
6697 } else {
6698 client.setUsingInputMethod(false);
6699 }
6700 client.asBinder().linkToDeath(this, 0);
6701 } catch (RemoteException e) {
6702 // The caller has died, so we can just forget about this.
6703 try {
6704 if (mInputMethodManager != null) {
6705 mInputMethodManager.removeClient(client);
6706 }
6707 } catch (RemoteException ee) {
6708 }
6709 } finally {
6710 Binder.restoreCallingIdentity(ident);
6711 }
6712 }
Romain Guy06882f82009-06-10 13:36:04 -07006713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006714 @Override
6715 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6716 throws RemoteException {
6717 try {
6718 return super.onTransact(code, data, reply, flags);
6719 } catch (RuntimeException e) {
6720 // Log all 'real' exceptions thrown to the caller
6721 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006722 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006723 }
6724 throw e;
6725 }
6726 }
6727
6728 public void binderDied() {
6729 // Note: it is safe to call in to the input method manager
6730 // here because we are not holding our lock.
6731 try {
6732 if (mInputMethodManager != null) {
6733 mInputMethodManager.removeClient(mClient);
6734 }
6735 } catch (RemoteException e) {
6736 }
6737 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006738 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006739 mClientDead = true;
6740 killSessionLocked();
6741 }
6742 }
6743
6744 public int add(IWindow window, WindowManager.LayoutParams attrs,
6745 int viewVisibility, Rect outContentInsets) {
6746 return addWindow(this, window, attrs, viewVisibility, outContentInsets);
6747 }
Romain Guy06882f82009-06-10 13:36:04 -07006748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006749 public void remove(IWindow window) {
6750 removeWindow(this, window);
6751 }
Romain Guy06882f82009-06-10 13:36:04 -07006752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006753 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6754 int requestedWidth, int requestedHeight, int viewFlags,
6755 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006756 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006757 return relayoutWindow(this, window, attrs,
6758 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006759 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006760 }
Romain Guy06882f82009-06-10 13:36:04 -07006761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006762 public void setTransparentRegion(IWindow window, Region region) {
6763 setTransparentRegionWindow(this, window, region);
6764 }
Romain Guy06882f82009-06-10 13:36:04 -07006765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006766 public void setInsets(IWindow window, int touchableInsets,
6767 Rect contentInsets, Rect visibleInsets) {
6768 setInsetsWindow(this, window, touchableInsets, contentInsets,
6769 visibleInsets);
6770 }
Romain Guy06882f82009-06-10 13:36:04 -07006771
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006772 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6773 getWindowDisplayFrame(this, window, outDisplayFrame);
6774 }
Romain Guy06882f82009-06-10 13:36:04 -07006775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006776 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006777 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006778 TAG, "IWindow finishDrawing called for " + window);
6779 finishDrawingWindow(this, window);
6780 }
6781
6782 public void finishKey(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006783 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006784 TAG, "IWindow finishKey called for " + window);
6785 mKeyWaiter.finishedKey(this, window, false,
6786 KeyWaiter.RETURN_NOTHING);
6787 }
6788
6789 public MotionEvent getPendingPointerMove(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006790 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006791 TAG, "IWindow getPendingMotionEvent called for " + window);
6792 return mKeyWaiter.finishedKey(this, window, false,
6793 KeyWaiter.RETURN_PENDING_POINTER);
6794 }
Romain Guy06882f82009-06-10 13:36:04 -07006795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006796 public MotionEvent getPendingTrackballMove(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006797 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006798 TAG, "IWindow getPendingMotionEvent called for " + window);
6799 return mKeyWaiter.finishedKey(this, window, false,
6800 KeyWaiter.RETURN_PENDING_TRACKBALL);
6801 }
6802
6803 public void setInTouchMode(boolean mode) {
6804 synchronized(mWindowMap) {
6805 mInTouchMode = mode;
6806 }
6807 }
6808
6809 public boolean getInTouchMode() {
6810 synchronized(mWindowMap) {
6811 return mInTouchMode;
6812 }
6813 }
6814
6815 public boolean performHapticFeedback(IWindow window, int effectId,
6816 boolean always) {
6817 synchronized(mWindowMap) {
6818 long ident = Binder.clearCallingIdentity();
6819 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006820 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006821 windowForClientLocked(this, window, true),
6822 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006823 } finally {
6824 Binder.restoreCallingIdentity(ident);
6825 }
6826 }
6827 }
Romain Guy06882f82009-06-10 13:36:04 -07006828
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006829 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006830 synchronized(mWindowMap) {
6831 long ident = Binder.clearCallingIdentity();
6832 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006833 setWindowWallpaperPositionLocked(
6834 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006835 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006836 } finally {
6837 Binder.restoreCallingIdentity(ident);
6838 }
6839 }
6840 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006841
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006842 public void wallpaperOffsetsComplete(IBinder window) {
6843 WindowManagerService.this.wallpaperOffsetsComplete(window);
6844 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006845
Dianne Hackborn75804932009-10-20 20:15:20 -07006846 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6847 int z, Bundle extras, boolean sync) {
6848 synchronized(mWindowMap) {
6849 long ident = Binder.clearCallingIdentity();
6850 try {
6851 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006852 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006853 action, x, y, z, extras, sync);
6854 } finally {
6855 Binder.restoreCallingIdentity(ident);
6856 }
6857 }
6858 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006859
Dianne Hackborn75804932009-10-20 20:15:20 -07006860 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6861 WindowManagerService.this.wallpaperCommandComplete(window, result);
6862 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006864 void windowAddedLocked() {
6865 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006866 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006867 TAG, "First window added to " + this + ", creating SurfaceSession");
6868 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006869 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006870 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006871 mSessions.add(this);
6872 }
6873 mNumWindow++;
6874 }
6875
6876 void windowRemovedLocked() {
6877 mNumWindow--;
6878 killSessionLocked();
6879 }
Romain Guy06882f82009-06-10 13:36:04 -07006880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006881 void killSessionLocked() {
6882 if (mNumWindow <= 0 && mClientDead) {
6883 mSessions.remove(this);
6884 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006885 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006886 TAG, "Last window removed from " + this
6887 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006888 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006889 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006890 try {
6891 mSurfaceSession.kill();
6892 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006893 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006894 + mSurfaceSession + " in session " + this
6895 + ": " + e.toString());
6896 }
6897 mSurfaceSession = null;
6898 }
6899 }
6900 }
Romain Guy06882f82009-06-10 13:36:04 -07006901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006902 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006903 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6904 pw.print(" mClientDead="); pw.print(mClientDead);
6905 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
6906 if (mPendingPointerWindow != null || mPendingPointerMove != null) {
6907 pw.print(prefix);
6908 pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow);
6909 pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove);
6910 }
6911 if (mPendingTrackballWindow != null || mPendingTrackballMove != null) {
6912 pw.print(prefix);
6913 pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow);
6914 pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove);
6915 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006916 }
6917
6918 @Override
6919 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006920 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006921 }
6922 }
6923
6924 // -------------------------------------------------------------
6925 // Client Window State
6926 // -------------------------------------------------------------
6927
6928 private final class WindowState implements WindowManagerPolicy.WindowState {
6929 final Session mSession;
6930 final IWindow mClient;
6931 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006932 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006933 AppWindowToken mAppToken;
6934 AppWindowToken mTargetAppToken;
6935 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6936 final DeathRecipient mDeathRecipient;
6937 final WindowState mAttachedWindow;
6938 final ArrayList mChildWindows = new ArrayList();
6939 final int mBaseLayer;
6940 final int mSubLayer;
6941 final boolean mLayoutAttached;
6942 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006943 final boolean mIsWallpaper;
6944 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006945 int mViewVisibility;
6946 boolean mPolicyVisibility = true;
6947 boolean mPolicyVisibilityAfterAnim = true;
6948 boolean mAppFreezing;
6949 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006950 boolean mReportDestroySurface;
6951 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006952 boolean mAttachedHidden; // is our parent window hidden?
6953 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006954 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006955 int mRequestedWidth;
6956 int mRequestedHeight;
6957 int mLastRequestedWidth;
6958 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006959 int mLayer;
6960 int mAnimLayer;
6961 int mLastLayer;
6962 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006963 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006964 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006965
6966 WindowState mNextOutsideTouch;
Romain Guy06882f82009-06-10 13:36:04 -07006967
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006968 int mLayoutSeq = -1;
6969
6970 Configuration mConfiguration = null;
6971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006972 // Actual frame shown on-screen (may be modified by animation)
6973 final Rect mShownFrame = new Rect();
6974 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006976 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006977 * Set when we have changed the size of the surface, to know that
6978 * we must tell them application to resize (and thus redraw itself).
6979 */
6980 boolean mSurfaceResized;
6981
6982 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006983 * Insets that determine the actually visible area
6984 */
6985 final Rect mVisibleInsets = new Rect();
6986 final Rect mLastVisibleInsets = new Rect();
6987 boolean mVisibleInsetsChanged;
6988
6989 /**
6990 * Insets that are covered by system windows
6991 */
6992 final Rect mContentInsets = new Rect();
6993 final Rect mLastContentInsets = new Rect();
6994 boolean mContentInsetsChanged;
6995
6996 /**
6997 * Set to true if we are waiting for this window to receive its
6998 * given internal insets before laying out other windows based on it.
6999 */
7000 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07007001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007002 /**
7003 * These are the content insets that were given during layout for
7004 * this window, to be applied to windows behind it.
7005 */
7006 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07007007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007008 /**
7009 * These are the visible insets that were given during layout for
7010 * this window, to be applied to windows behind it.
7011 */
7012 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07007013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007014 /**
7015 * Flag indicating whether the touchable region should be adjusted by
7016 * the visible insets; if false the area outside the visible insets is
7017 * NOT touchable, so we must use those to adjust the frame during hit
7018 * tests.
7019 */
7020 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07007021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007022 // Current transformation being applied.
7023 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
7024 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
7025 float mHScale=1, mVScale=1;
7026 float mLastHScale=1, mLastVScale=1;
7027 final Matrix mTmpMatrix = new Matrix();
7028
7029 // "Real" frame that the application sees.
7030 final Rect mFrame = new Rect();
7031 final Rect mLastFrame = new Rect();
7032
7033 final Rect mContainingFrame = new Rect();
7034 final Rect mDisplayFrame = new Rect();
7035 final Rect mContentFrame = new Rect();
7036 final Rect mVisibleFrame = new Rect();
7037
7038 float mShownAlpha = 1;
7039 float mAlpha = 1;
7040 float mLastAlpha = 1;
7041
7042 // Set to true if, when the window gets displayed, it should perform
7043 // an enter animation.
7044 boolean mEnterAnimationPending;
7045
7046 // Currently running animation.
7047 boolean mAnimating;
7048 boolean mLocalAnimating;
7049 Animation mAnimation;
7050 boolean mAnimationIsEntrance;
7051 boolean mHasTransformation;
7052 boolean mHasLocalTransformation;
7053 final Transformation mTransformation = new Transformation();
7054
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007055 // If a window showing a wallpaper: the requested offset for the
7056 // wallpaper; if a wallpaper window: the currently applied offset.
7057 float mWallpaperX = -1;
7058 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007059
7060 // If a window showing a wallpaper: what fraction of the offset
7061 // range corresponds to a full virtual screen.
7062 float mWallpaperXStep = -1;
7063 float mWallpaperYStep = -1;
7064
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007065 // Wallpaper windows: pixels offset based on above variables.
7066 int mXOffset;
7067 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007069 // This is set after IWindowSession.relayout() has been called at
7070 // least once for the window. It allows us to detect the situation
7071 // where we don't yet have a surface, but should have one soon, so
7072 // we can give the window focus before waiting for the relayout.
7073 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07007074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007075 // This is set after the Surface has been created but before the
7076 // window has been drawn. During this time the surface is hidden.
7077 boolean mDrawPending;
7078
7079 // This is set after the window has finished drawing for the first
7080 // time but before its surface is shown. The surface will be
7081 // displayed when the next layout is run.
7082 boolean mCommitDrawPending;
7083
7084 // This is set during the time after the window's drawing has been
7085 // committed, and before its surface is actually shown. It is used
7086 // to delay showing the surface until all windows in a token are ready
7087 // to be shown.
7088 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07007089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007090 // Set when the window has been shown in the screen the first time.
7091 boolean mHasDrawn;
7092
7093 // Currently running an exit animation?
7094 boolean mExiting;
7095
7096 // Currently on the mDestroySurface list?
7097 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07007098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007099 // Completely remove from window manager after exit animation?
7100 boolean mRemoveOnExit;
7101
7102 // Set when the orientation is changing and this window has not yet
7103 // been updated for the new orientation.
7104 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07007105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007106 // Is this window now (or just being) removed?
7107 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07007108
Dianne Hackborn16064f92010-03-25 00:47:24 -07007109 // For debugging, this is the last information given to the surface flinger.
7110 boolean mSurfaceShown;
7111 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
7112 int mSurfaceLayer;
7113 float mSurfaceAlpha;
7114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007115 WindowState(Session s, IWindow c, WindowToken token,
7116 WindowState attachedWindow, WindowManager.LayoutParams a,
7117 int viewVisibility) {
7118 mSession = s;
7119 mClient = c;
7120 mToken = token;
7121 mAttrs.copyFrom(a);
7122 mViewVisibility = viewVisibility;
7123 DeathRecipient deathRecipient = new DeathRecipient();
7124 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007125 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007126 TAG, "Window " + this + " client=" + c.asBinder()
7127 + " token=" + token + " (" + mAttrs.token + ")");
7128 try {
7129 c.asBinder().linkToDeath(deathRecipient, 0);
7130 } catch (RemoteException e) {
7131 mDeathRecipient = null;
7132 mAttachedWindow = null;
7133 mLayoutAttached = false;
7134 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007135 mIsWallpaper = false;
7136 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007137 mBaseLayer = 0;
7138 mSubLayer = 0;
7139 return;
7140 }
7141 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07007142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007143 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
7144 mAttrs.type <= LAST_SUB_WINDOW)) {
7145 // The multiplier here is to reserve space for multiple
7146 // windows in the same type layer.
7147 mBaseLayer = mPolicy.windowTypeToLayerLw(
7148 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
7149 + TYPE_LAYER_OFFSET;
7150 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
7151 mAttachedWindow = attachedWindow;
7152 mAttachedWindow.mChildWindows.add(this);
7153 mLayoutAttached = mAttrs.type !=
7154 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
7155 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
7156 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007157 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
7158 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007159 } else {
7160 // The multiplier here is to reserve space for multiple
7161 // windows in the same type layer.
7162 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
7163 * TYPE_LAYER_MULTIPLIER
7164 + TYPE_LAYER_OFFSET;
7165 mSubLayer = 0;
7166 mAttachedWindow = null;
7167 mLayoutAttached = false;
7168 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
7169 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007170 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
7171 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007172 }
7173
7174 WindowState appWin = this;
7175 while (appWin.mAttachedWindow != null) {
7176 appWin = mAttachedWindow;
7177 }
7178 WindowToken appToken = appWin.mToken;
7179 while (appToken.appWindowToken == null) {
7180 WindowToken parent = mTokenMap.get(appToken.token);
7181 if (parent == null || appToken == parent) {
7182 break;
7183 }
7184 appToken = parent;
7185 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007186 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007187 mAppToken = appToken.appWindowToken;
7188
7189 mSurface = null;
7190 mRequestedWidth = 0;
7191 mRequestedHeight = 0;
7192 mLastRequestedWidth = 0;
7193 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007194 mXOffset = 0;
7195 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007196 mLayer = 0;
7197 mAnimLayer = 0;
7198 mLastLayer = 0;
7199 }
7200
7201 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007202 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007203 TAG, "Attaching " + this + " token=" + mToken
7204 + ", list=" + mToken.windows);
7205 mSession.windowAddedLocked();
7206 }
7207
7208 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7209 mHaveFrame = true;
7210
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007211 final Rect container = mContainingFrame;
7212 container.set(pf);
7213
7214 final Rect display = mDisplayFrame;
7215 display.set(df);
7216
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007217 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007218 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007219 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7220 display.intersect(mCompatibleScreenFrame);
7221 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007222 }
7223
7224 final int pw = container.right - container.left;
7225 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007226
7227 int w,h;
7228 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7229 w = mAttrs.width < 0 ? pw : mAttrs.width;
7230 h = mAttrs.height< 0 ? ph : mAttrs.height;
7231 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007232 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7233 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007234 }
Romain Guy06882f82009-06-10 13:36:04 -07007235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007236 final Rect content = mContentFrame;
7237 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007238
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007239 final Rect visible = mVisibleFrame;
7240 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007242 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007243 final int fw = frame.width();
7244 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007246 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7247 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7248
7249 Gravity.apply(mAttrs.gravity, w, h, container,
7250 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7251 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7252
7253 //System.out.println("Out: " + mFrame);
7254
7255 // Now make sure the window fits in the overall display.
7256 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007258 // Make sure the content and visible frames are inside of the
7259 // final window frame.
7260 if (content.left < frame.left) content.left = frame.left;
7261 if (content.top < frame.top) content.top = frame.top;
7262 if (content.right > frame.right) content.right = frame.right;
7263 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7264 if (visible.left < frame.left) visible.left = frame.left;
7265 if (visible.top < frame.top) visible.top = frame.top;
7266 if (visible.right > frame.right) visible.right = frame.right;
7267 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007269 final Rect contentInsets = mContentInsets;
7270 contentInsets.left = content.left-frame.left;
7271 contentInsets.top = content.top-frame.top;
7272 contentInsets.right = frame.right-content.right;
7273 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007275 final Rect visibleInsets = mVisibleInsets;
7276 visibleInsets.left = visible.left-frame.left;
7277 visibleInsets.top = visible.top-frame.top;
7278 visibleInsets.right = frame.right-visible.right;
7279 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007280
Dianne Hackborn284ac932009-08-28 10:34:25 -07007281 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7282 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007283 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007284 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007286 if (localLOGV) {
7287 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7288 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007289 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007290 + mRequestedWidth + ", mRequestedheight="
7291 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7292 + "): frame=" + mFrame.toShortString()
7293 + " ci=" + contentInsets.toShortString()
7294 + " vi=" + visibleInsets.toShortString());
7295 //}
7296 }
7297 }
Romain Guy06882f82009-06-10 13:36:04 -07007298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007299 public Rect getFrameLw() {
7300 return mFrame;
7301 }
7302
7303 public Rect getShownFrameLw() {
7304 return mShownFrame;
7305 }
7306
7307 public Rect getDisplayFrameLw() {
7308 return mDisplayFrame;
7309 }
7310
7311 public Rect getContentFrameLw() {
7312 return mContentFrame;
7313 }
7314
7315 public Rect getVisibleFrameLw() {
7316 return mVisibleFrame;
7317 }
7318
7319 public boolean getGivenInsetsPendingLw() {
7320 return mGivenInsetsPending;
7321 }
7322
7323 public Rect getGivenContentInsetsLw() {
7324 return mGivenContentInsets;
7325 }
Romain Guy06882f82009-06-10 13:36:04 -07007326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007327 public Rect getGivenVisibleInsetsLw() {
7328 return mGivenVisibleInsets;
7329 }
Romain Guy06882f82009-06-10 13:36:04 -07007330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007331 public WindowManager.LayoutParams getAttrs() {
7332 return mAttrs;
7333 }
7334
7335 public int getSurfaceLayer() {
7336 return mLayer;
7337 }
Romain Guy06882f82009-06-10 13:36:04 -07007338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007339 public IApplicationToken getAppToken() {
7340 return mAppToken != null ? mAppToken.appToken : null;
7341 }
7342
7343 public boolean hasAppShownWindows() {
7344 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7345 }
7346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007347 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007348 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007349 TAG, "Setting animation in " + this + ": " + anim);
7350 mAnimating = false;
7351 mLocalAnimating = false;
7352 mAnimation = anim;
7353 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7354 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7355 }
7356
7357 public void clearAnimation() {
7358 if (mAnimation != null) {
7359 mAnimating = true;
7360 mLocalAnimating = false;
7361 mAnimation = null;
7362 }
7363 }
Romain Guy06882f82009-06-10 13:36:04 -07007364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007365 Surface createSurfaceLocked() {
7366 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007367 mReportDestroySurface = false;
7368 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007369 mDrawPending = true;
7370 mCommitDrawPending = false;
7371 mReadyToShow = false;
7372 if (mAppToken != null) {
7373 mAppToken.allDrawn = false;
7374 }
7375
7376 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07007377 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007378 flags |= Surface.PUSH_BUFFERS;
7379 }
7380
7381 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7382 flags |= Surface.SECURE;
7383 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007384 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007385 TAG, "Creating surface in session "
7386 + mSession.mSurfaceSession + " window " + this
7387 + " w=" + mFrame.width()
7388 + " h=" + mFrame.height() + " format="
7389 + mAttrs.format + " flags=" + flags);
7390
7391 int w = mFrame.width();
7392 int h = mFrame.height();
7393 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7394 // for a scaled surface, we always want the requested
7395 // size.
7396 w = mRequestedWidth;
7397 h = mRequestedHeight;
7398 }
7399
Romain Guy9825ec62009-10-01 00:58:09 -07007400 // Something is wrong and SurfaceFlinger will not like this,
7401 // try to revert to sane values
7402 if (w <= 0) w = 1;
7403 if (h <= 0) h = 1;
7404
Dianne Hackborn16064f92010-03-25 00:47:24 -07007405 mSurfaceShown = false;
7406 mSurfaceLayer = 0;
7407 mSurfaceAlpha = 1;
7408 mSurfaceX = 0;
7409 mSurfaceY = 0;
7410 mSurfaceW = w;
7411 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007412 try {
7413 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007414 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007415 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007416 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007417 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007418 + mSurface + " IN SESSION "
7419 + mSession.mSurfaceSession
7420 + ": pid=" + mSession.mPid + " format="
7421 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007422 + Integer.toHexString(flags)
7423 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007424 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007425 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007426 reclaimSomeSurfaceMemoryLocked(this, "create");
7427 return null;
7428 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007429 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007430 return null;
7431 }
Romain Guy06882f82009-06-10 13:36:04 -07007432
Joe Onorato8a9b2202010-02-26 18:56:32 -08007433 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007434 TAG, "Got surface: " + mSurface
7435 + ", set left=" + mFrame.left + " top=" + mFrame.top
7436 + ", animLayer=" + mAnimLayer);
7437 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007438 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007439 if (SHOW_TRANSACTIONS) logSurface(this,
7440 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
7441 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7442 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007443 }
7444 Surface.openTransaction();
7445 try {
7446 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007447 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007448 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007449 mSurface.setPosition(mSurfaceX, mSurfaceY);
7450 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007451 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007452 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007453 mSurface.hide();
7454 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007455 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007456 mSurface.setFlags(Surface.SURFACE_DITHER,
7457 Surface.SURFACE_DITHER);
7458 }
7459 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007460 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007461 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7462 }
7463 mLastHidden = true;
7464 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007465 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007466 Surface.closeTransaction();
7467 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007468 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007469 TAG, "Created surface " + this);
7470 }
7471 return mSurface;
7472 }
Romain Guy06882f82009-06-10 13:36:04 -07007473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007474 void destroySurfaceLocked() {
7475 // Window is no longer on-screen, so can no longer receive
7476 // key events... if we were waiting for it to finish
7477 // handling a key event, the wait is over!
7478 mKeyWaiter.finishedKey(mSession, mClient, true,
7479 KeyWaiter.RETURN_NOTHING);
7480 mKeyWaiter.releasePendingPointerLocked(mSession);
7481 mKeyWaiter.releasePendingTrackballLocked(mSession);
7482
7483 if (mAppToken != null && this == mAppToken.startingWindow) {
7484 mAppToken.startingDisplayed = false;
7485 }
Romain Guy06882f82009-06-10 13:36:04 -07007486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007487 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007488 mDrawPending = false;
7489 mCommitDrawPending = false;
7490 mReadyToShow = false;
7491
7492 int i = mChildWindows.size();
7493 while (i > 0) {
7494 i--;
7495 WindowState c = (WindowState)mChildWindows.get(i);
7496 c.mAttachedHidden = true;
7497 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007498
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007499 if (mReportDestroySurface) {
7500 mReportDestroySurface = false;
7501 mSurfacePendingDestroy = true;
7502 try {
7503 mClient.dispatchGetNewSurface();
7504 // We'll really destroy on the next time around.
7505 return;
7506 } catch (RemoteException e) {
7507 }
7508 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007510 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007511 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007512 RuntimeException e = null;
7513 if (!HIDE_STACK_CRAWLS) {
7514 e = new RuntimeException();
7515 e.fillInStackTrace();
7516 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007517 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007518 + mSurface + ", session " + mSession, e);
7519 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007520 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007521 RuntimeException e = null;
7522 if (!HIDE_STACK_CRAWLS) {
7523 e = new RuntimeException();
7524 e.fillInStackTrace();
7525 }
7526 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007527 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007528 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007529 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007530 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007531 + " surface " + mSurface + " session " + mSession
7532 + ": " + e.toString());
7533 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007534
Dianne Hackborn16064f92010-03-25 00:47:24 -07007535 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007536 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007537 }
7538 }
7539
7540 boolean finishDrawingLocked() {
7541 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007542 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007543 TAG, "finishDrawingLocked: " + mSurface);
7544 mCommitDrawPending = true;
7545 mDrawPending = false;
7546 return true;
7547 }
7548 return false;
7549 }
7550
7551 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007552 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007553 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007554 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007555 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007556 }
7557 mCommitDrawPending = false;
7558 mReadyToShow = true;
7559 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7560 final AppWindowToken atoken = mAppToken;
7561 if (atoken == null || atoken.allDrawn || starting) {
7562 performShowLocked();
7563 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007564 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007565 }
7566
7567 // This must be called while inside a transaction.
7568 boolean performShowLocked() {
7569 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007570 RuntimeException e = null;
7571 if (!HIDE_STACK_CRAWLS) {
7572 e = new RuntimeException();
7573 e.fillInStackTrace();
7574 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007575 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007576 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7577 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7578 }
7579 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007580 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7581 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007582 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007583 + " during animation: policyVis=" + mPolicyVisibility
7584 + " attHidden=" + mAttachedHidden
7585 + " tok.hiddenRequested="
7586 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007587 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007588 + (mAppToken != null ? mAppToken.hidden : false)
7589 + " animating=" + mAnimating
7590 + " tok animating="
7591 + (mAppToken != null ? mAppToken.animating : false));
7592 if (!showSurfaceRobustlyLocked(this)) {
7593 return false;
7594 }
7595 mLastAlpha = -1;
7596 mHasDrawn = true;
7597 mLastHidden = false;
7598 mReadyToShow = false;
7599 enableScreenIfNeededLocked();
7600
7601 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007603 int i = mChildWindows.size();
7604 while (i > 0) {
7605 i--;
7606 WindowState c = (WindowState)mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007607 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007608 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007609 if (c.mSurface != null) {
7610 c.performShowLocked();
7611 // It hadn't been shown, which means layout not
7612 // performed on it, so now we want to make sure to
7613 // do a layout. If called from within the transaction
7614 // loop, this will cause it to restart with a new
7615 // layout.
7616 mLayoutNeeded = true;
7617 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007618 }
7619 }
Romain Guy06882f82009-06-10 13:36:04 -07007620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007621 if (mAttrs.type != TYPE_APPLICATION_STARTING
7622 && mAppToken != null) {
7623 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007624
Dianne Hackborn248b1882009-09-16 16:46:44 -07007625 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007626 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007627 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007628 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007629 // If this initial window is animating, stop it -- we
7630 // will do an animation to reveal it from behind the
7631 // starting window, so there is no need for it to also
7632 // be doing its own stuff.
7633 if (mAnimation != null) {
7634 mAnimation = null;
7635 // Make sure we clean up the animation.
7636 mAnimating = true;
7637 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007638 mFinishedStarting.add(mAppToken);
7639 mH.sendEmptyMessage(H.FINISHED_STARTING);
7640 }
7641 mAppToken.updateReportedVisibilityLocked();
7642 }
7643 }
7644 return true;
7645 }
Romain Guy06882f82009-06-10 13:36:04 -07007646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007647 // This must be called while inside a transaction. Returns true if
7648 // there is more animation to run.
7649 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007650 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007651 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007653 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7654 mHasTransformation = true;
7655 mHasLocalTransformation = true;
7656 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007657 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007658 TAG, "Starting animation in " + this +
7659 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7660 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7661 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7662 mAnimation.setStartTime(currentTime);
7663 mLocalAnimating = true;
7664 mAnimating = true;
7665 }
7666 mTransformation.clear();
7667 final boolean more = mAnimation.getTransformation(
7668 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007669 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007670 TAG, "Stepped animation in " + this +
7671 ": more=" + more + ", xform=" + mTransformation);
7672 if (more) {
7673 // we're not done!
7674 return true;
7675 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007676 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007677 TAG, "Finished animation in " + this +
7678 " @ " + currentTime);
7679 mAnimation = null;
7680 //WindowManagerService.this.dump();
7681 }
7682 mHasLocalTransformation = false;
7683 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007684 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007685 // When our app token is animating, we kind-of pretend like
7686 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7687 // part of this check means that we will only do this if
7688 // our window is not currently exiting, or it is not
7689 // locally animating itself. The idea being that one that
7690 // is exiting and doing a local animation should be removed
7691 // once that animation is done.
7692 mAnimating = true;
7693 mHasTransformation = true;
7694 mTransformation.clear();
7695 return false;
7696 } else if (mHasTransformation) {
7697 // Little trick to get through the path below to act like
7698 // we have finished an animation.
7699 mAnimating = true;
7700 } else if (isAnimating()) {
7701 mAnimating = true;
7702 }
7703 } else if (mAnimation != null) {
7704 // If the display is frozen, and there is a pending animation,
7705 // clear it and make sure we run the cleanup code.
7706 mAnimating = true;
7707 mLocalAnimating = true;
7708 mAnimation = null;
7709 }
Romain Guy06882f82009-06-10 13:36:04 -07007710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007711 if (!mAnimating && !mLocalAnimating) {
7712 return false;
7713 }
7714
Joe Onorato8a9b2202010-02-26 18:56:32 -08007715 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007716 TAG, "Animation done in " + this + ": exiting=" + mExiting
7717 + ", reportedVisible="
7718 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007720 mAnimating = false;
7721 mLocalAnimating = false;
7722 mAnimation = null;
7723 mAnimLayer = mLayer;
7724 if (mIsImWindow) {
7725 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007726 } else if (mIsWallpaper) {
7727 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007728 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007729 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007730 + " anim layer: " + mAnimLayer);
7731 mHasTransformation = false;
7732 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007733 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7734 if (DEBUG_VISIBILITY) {
7735 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7736 + mPolicyVisibilityAfterAnim);
7737 }
7738 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7739 if (!mPolicyVisibility) {
7740 if (mCurrentFocus == this) {
7741 mFocusMayChange = true;
7742 }
7743 // Window is no longer visible -- make sure if we were waiting
7744 // for it to be displayed before enabling the display, that
7745 // we allow the display to be enabled now.
7746 enableScreenIfNeededLocked();
7747 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007748 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007749 mTransformation.clear();
7750 if (mHasDrawn
7751 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7752 && mAppToken != null
7753 && mAppToken.firstWindowDrawn
7754 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007755 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007756 + mToken + ": first real window done animating");
7757 mFinishedStarting.add(mAppToken);
7758 mH.sendEmptyMessage(H.FINISHED_STARTING);
7759 }
Romain Guy06882f82009-06-10 13:36:04 -07007760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007761 finishExit();
7762
7763 if (mAppToken != null) {
7764 mAppToken.updateReportedVisibilityLocked();
7765 }
7766
7767 return false;
7768 }
7769
7770 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007771 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007772 TAG, "finishExit in " + this
7773 + ": exiting=" + mExiting
7774 + " remove=" + mRemoveOnExit
7775 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007777 final int N = mChildWindows.size();
7778 for (int i=0; i<N; i++) {
7779 ((WindowState)mChildWindows.get(i)).finishExit();
7780 }
Romain Guy06882f82009-06-10 13:36:04 -07007781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007782 if (!mExiting) {
7783 return;
7784 }
Romain Guy06882f82009-06-10 13:36:04 -07007785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007786 if (isWindowAnimating()) {
7787 return;
7788 }
7789
Joe Onorato8a9b2202010-02-26 18:56:32 -08007790 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007791 TAG, "Exit animation finished in " + this
7792 + ": remove=" + mRemoveOnExit);
7793 if (mSurface != null) {
7794 mDestroySurface.add(this);
7795 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007796 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007797 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007798 try {
7799 mSurface.hide();
7800 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007801 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007802 }
7803 mLastHidden = true;
7804 mKeyWaiter.releasePendingPointerLocked(mSession);
7805 }
7806 mExiting = false;
7807 if (mRemoveOnExit) {
7808 mPendingRemove.add(this);
7809 mRemoveOnExit = false;
7810 }
7811 }
Romain Guy06882f82009-06-10 13:36:04 -07007812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007813 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7814 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7815 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7816 if (dtdx < -.000001f || dtdx > .000001f) return false;
7817 if (dsdy < -.000001f || dsdy > .000001f) return false;
7818 return true;
7819 }
Romain Guy06882f82009-06-10 13:36:04 -07007820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007821 void computeShownFrameLocked() {
7822 final boolean selfTransformation = mHasLocalTransformation;
7823 Transformation attachedTransformation =
7824 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7825 ? mAttachedWindow.mTransformation : null;
7826 Transformation appTransformation =
7827 (mAppToken != null && mAppToken.hasTransformation)
7828 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007829
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007830 // Wallpapers are animated based on the "real" window they
7831 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007832 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007833 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007834 if (mWallpaperTarget.mHasLocalTransformation &&
7835 mWallpaperTarget.mAnimation != null &&
7836 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007837 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007838 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007839 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007840 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007841 }
7842 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007843 mWallpaperTarget.mAppToken.hasTransformation &&
7844 mWallpaperTarget.mAppToken.animation != null &&
7845 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007846 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007847 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007848 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007849 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007850 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007851 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007853 if (selfTransformation || attachedTransformation != null
7854 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007855 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007856 final Rect frame = mFrame;
7857 final float tmpFloats[] = mTmpFloats;
7858 final Matrix tmpMatrix = mTmpMatrix;
7859
7860 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007861 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007862 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007863 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007864 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007865 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007866 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007867 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007868 }
7869 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007870 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007871 }
7872
7873 // "convert" it into SurfaceFlinger's format
7874 // (a 2x2 matrix + an offset)
7875 // Here we must not transform the position of the surface
7876 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007877 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007879 tmpMatrix.getValues(tmpFloats);
7880 mDsDx = tmpFloats[Matrix.MSCALE_X];
7881 mDtDx = tmpFloats[Matrix.MSKEW_X];
7882 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7883 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007884 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7885 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007886 int w = frame.width();
7887 int h = frame.height();
7888 mShownFrame.set(x, y, x+w, y+h);
7889
7890 // Now set the alpha... but because our current hardware
7891 // can't do alpha transformation on a non-opaque surface,
7892 // turn it off if we are running an animation that is also
7893 // transforming since it is more important to have that
7894 // animation be smooth.
7895 mShownAlpha = mAlpha;
7896 if (!mLimitedAlphaCompositing
7897 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7898 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7899 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007900 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007901 if (selfTransformation) {
7902 mShownAlpha *= mTransformation.getAlpha();
7903 }
7904 if (attachedTransformation != null) {
7905 mShownAlpha *= attachedTransformation.getAlpha();
7906 }
7907 if (appTransformation != null) {
7908 mShownAlpha *= appTransformation.getAlpha();
7909 }
7910 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007911 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007912 }
Romain Guy06882f82009-06-10 13:36:04 -07007913
Joe Onorato8a9b2202010-02-26 18:56:32 -08007914 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007915 TAG, "Continuing animation in " + this +
7916 ": " + mShownFrame +
7917 ", alpha=" + mTransformation.getAlpha());
7918 return;
7919 }
Romain Guy06882f82009-06-10 13:36:04 -07007920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007921 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007922 if (mXOffset != 0 || mYOffset != 0) {
7923 mShownFrame.offset(mXOffset, mYOffset);
7924 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007925 mShownAlpha = mAlpha;
7926 mDsDx = 1;
7927 mDtDx = 0;
7928 mDsDy = 0;
7929 mDtDy = 1;
7930 }
Romain Guy06882f82009-06-10 13:36:04 -07007931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007932 /**
7933 * Is this window visible? It is not visible if there is no
7934 * surface, or we are in the process of running an exit animation
7935 * that will remove the surface, or its app token has been hidden.
7936 */
7937 public boolean isVisibleLw() {
7938 final AppWindowToken atoken = mAppToken;
7939 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7940 && (atoken == null || !atoken.hiddenRequested)
7941 && !mExiting && !mDestroying;
7942 }
7943
7944 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007945 * Like {@link #isVisibleLw}, but also counts a window that is currently
7946 * "hidden" behind the keyguard as visible. This allows us to apply
7947 * things like window flags that impact the keyguard.
7948 * XXX I am starting to think we need to have ANOTHER visibility flag
7949 * for this "hidden behind keyguard" state rather than overloading
7950 * mPolicyVisibility. Ungh.
7951 */
7952 public boolean isVisibleOrBehindKeyguardLw() {
7953 final AppWindowToken atoken = mAppToken;
7954 return mSurface != null && !mAttachedHidden
7955 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007956 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007957 && !mExiting && !mDestroying;
7958 }
7959
7960 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007961 * Is this window visible, ignoring its app token? It is not visible
7962 * if there is no surface, or we are in the process of running an exit animation
7963 * that will remove the surface.
7964 */
7965 public boolean isWinVisibleLw() {
7966 final AppWindowToken atoken = mAppToken;
7967 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7968 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7969 && !mExiting && !mDestroying;
7970 }
7971
7972 /**
7973 * The same as isVisible(), but follows the current hidden state of
7974 * the associated app token, not the pending requested hidden state.
7975 */
7976 boolean isVisibleNow() {
7977 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007978 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007979 }
7980
7981 /**
7982 * Same as isVisible(), but we also count it as visible between the
7983 * call to IWindowSession.add() and the first relayout().
7984 */
7985 boolean isVisibleOrAdding() {
7986 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007987 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007988 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7989 && mPolicyVisibility && !mAttachedHidden
7990 && (atoken == null || !atoken.hiddenRequested)
7991 && !mExiting && !mDestroying;
7992 }
7993
7994 /**
7995 * Is this window currently on-screen? It is on-screen either if it
7996 * is visible or it is currently running an animation before no longer
7997 * being visible.
7998 */
7999 boolean isOnScreen() {
8000 final AppWindowToken atoken = mAppToken;
8001 if (atoken != null) {
8002 return mSurface != null && mPolicyVisibility && !mDestroying
8003 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008004 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008005 } else {
8006 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008007 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008008 }
8009 }
Romain Guy06882f82009-06-10 13:36:04 -07008010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008011 /**
8012 * Like isOnScreen(), but we don't return true if the window is part
8013 * of a transition that has not yet been started.
8014 */
8015 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07008016 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008017 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07008018 return false;
8019 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008020 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008021 final boolean animating = atoken != null
8022 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008023 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008024 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
8025 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008026 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008027 }
8028
8029 /** Is the window or its container currently animating? */
8030 boolean isAnimating() {
8031 final WindowState attached = mAttachedWindow;
8032 final AppWindowToken atoken = mAppToken;
8033 return mAnimation != null
8034 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07008035 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008036 (atoken.animation != null
8037 || atoken.inPendingTransaction));
8038 }
8039
8040 /** Is this window currently animating? */
8041 boolean isWindowAnimating() {
8042 return mAnimation != null;
8043 }
8044
8045 /**
8046 * Like isOnScreen, but returns false if the surface hasn't yet
8047 * been drawn.
8048 */
8049 public boolean isDisplayedLw() {
8050 final AppWindowToken atoken = mAppToken;
8051 return mSurface != null && mPolicyVisibility && !mDestroying
8052 && !mDrawPending && !mCommitDrawPending
8053 && ((!mAttachedHidden &&
8054 (atoken == null || !atoken.hiddenRequested))
8055 || mAnimating);
8056 }
8057
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008058 /**
8059 * Returns true if the window has a surface that it has drawn a
8060 * complete UI in to.
8061 */
8062 public boolean isDrawnLw() {
8063 final AppWindowToken atoken = mAppToken;
8064 return mSurface != null && !mDestroying
8065 && !mDrawPending && !mCommitDrawPending;
8066 }
8067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008068 public boolean fillsScreenLw(int screenWidth, int screenHeight,
8069 boolean shownFrame, boolean onlyOpaque) {
8070 if (mSurface == null) {
8071 return false;
8072 }
8073 if (mAppToken != null && !mAppToken.appFullscreen) {
8074 return false;
8075 }
8076 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
8077 return false;
8078 }
8079 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008080
8081 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
8082 return frame.left <= mCompatibleScreenFrame.left &&
8083 frame.top <= mCompatibleScreenFrame.top &&
8084 frame.right >= mCompatibleScreenFrame.right &&
8085 frame.bottom >= mCompatibleScreenFrame.bottom;
8086 } else {
8087 return frame.left <= 0 && frame.top <= 0
8088 && frame.right >= screenWidth
8089 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008090 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008091 }
Romain Guy06882f82009-06-10 13:36:04 -07008092
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008093 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07008094 * Return true if the window is opaque and fully drawn. This indicates
8095 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008096 */
8097 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07008098 return (mAttrs.format == PixelFormat.OPAQUE
8099 || mAttrs.type == TYPE_WALLPAPER)
8100 && mSurface != null && mAnimation == null
8101 && (mAppToken == null || mAppToken.animation == null)
8102 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008103 }
8104
8105 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
8106 return
8107 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008108 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
8109 // only if it's visible
8110 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008111 // and only if the application fills the compatible screen
8112 mFrame.left <= mCompatibleScreenFrame.left &&
8113 mFrame.top <= mCompatibleScreenFrame.top &&
8114 mFrame.right >= mCompatibleScreenFrame.right &&
8115 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008116 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008117 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008118 }
8119
8120 boolean isFullscreen(int screenWidth, int screenHeight) {
8121 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008122 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008123 }
8124
8125 void removeLocked() {
8126 if (mAttachedWindow != null) {
8127 mAttachedWindow.mChildWindows.remove(this);
8128 }
8129 destroySurfaceLocked();
8130 mSession.windowRemovedLocked();
8131 try {
8132 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
8133 } catch (RuntimeException e) {
8134 // Ignore if it has already been removed (usually because
8135 // we are doing this as part of processing a death note.)
8136 }
8137 }
8138
8139 private class DeathRecipient implements IBinder.DeathRecipient {
8140 public void binderDied() {
8141 try {
8142 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008143 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008144 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008145 if (win != null) {
8146 removeWindowLocked(mSession, win);
8147 }
8148 }
8149 } catch (IllegalArgumentException ex) {
8150 // This will happen if the window has already been
8151 // removed.
8152 }
8153 }
8154 }
8155
8156 /** Returns true if this window desires key events. */
8157 public final boolean canReceiveKeys() {
8158 return isVisibleOrAdding()
8159 && (mViewVisibility == View.VISIBLE)
8160 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8161 }
8162
8163 public boolean hasDrawnLw() {
8164 return mHasDrawn;
8165 }
8166
8167 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008168 return showLw(doAnimation, true);
8169 }
8170
8171 boolean showLw(boolean doAnimation, boolean requestAnim) {
8172 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8173 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008174 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008175 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008176 if (doAnimation) {
8177 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8178 + mPolicyVisibility + " mAnimation=" + mAnimation);
8179 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8180 doAnimation = false;
8181 } else if (mPolicyVisibility && mAnimation == null) {
8182 // Check for the case where we are currently visible and
8183 // not animating; we do not want to do animation at such a
8184 // point to become visible when we already are.
8185 doAnimation = false;
8186 }
8187 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008188 mPolicyVisibility = true;
8189 mPolicyVisibilityAfterAnim = true;
8190 if (doAnimation) {
8191 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8192 }
8193 if (requestAnim) {
8194 requestAnimationLocked(0);
8195 }
8196 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008197 }
8198
8199 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008200 return hideLw(doAnimation, true);
8201 }
8202
8203 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008204 if (doAnimation) {
8205 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8206 doAnimation = false;
8207 }
8208 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008209 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8210 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008211 if (!current) {
8212 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008213 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008214 if (doAnimation) {
8215 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8216 if (mAnimation == null) {
8217 doAnimation = false;
8218 }
8219 }
8220 if (doAnimation) {
8221 mPolicyVisibilityAfterAnim = false;
8222 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008223 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008224 mPolicyVisibilityAfterAnim = false;
8225 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008226 // Window is no longer visible -- make sure if we were waiting
8227 // for it to be displayed before enabling the display, that
8228 // we allow the display to be enabled now.
8229 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008230 if (mCurrentFocus == this) {
8231 mFocusMayChange = true;
8232 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008233 }
8234 if (requestAnim) {
8235 requestAnimationLocked(0);
8236 }
8237 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008238 }
8239
8240 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008241 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8242 pw.print(" mClient="); pw.println(mClient.asBinder());
8243 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8244 if (mAttachedWindow != null || mLayoutAttached) {
8245 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8246 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8247 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008248 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8249 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8250 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008251 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8252 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008253 }
8254 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8255 pw.print(" mSubLayer="); pw.print(mSubLayer);
8256 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8257 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8258 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8259 pw.print("="); pw.print(mAnimLayer);
8260 pw.print(" mLastLayer="); pw.println(mLastLayer);
8261 if (mSurface != null) {
8262 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008263 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8264 pw.print(" layer="); pw.print(mSurfaceLayer);
8265 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8266 pw.print(" rect=("); pw.print(mSurfaceX);
8267 pw.print(","); pw.print(mSurfaceY);
8268 pw.print(") "); pw.print(mSurfaceW);
8269 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008270 }
8271 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8272 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8273 if (mAppToken != null) {
8274 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8275 }
8276 if (mTargetAppToken != null) {
8277 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8278 }
8279 pw.print(prefix); pw.print("mViewVisibility=0x");
8280 pw.print(Integer.toHexString(mViewVisibility));
8281 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008282 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8283 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008284 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8285 pw.print(prefix); pw.print("mPolicyVisibility=");
8286 pw.print(mPolicyVisibility);
8287 pw.print(" mPolicyVisibilityAfterAnim=");
8288 pw.print(mPolicyVisibilityAfterAnim);
8289 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8290 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008291 if (!mRelayoutCalled) {
8292 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8293 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008294 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008295 pw.print(" h="); pw.print(mRequestedHeight);
8296 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008297 if (mXOffset != 0 || mYOffset != 0) {
8298 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8299 pw.print(" y="); pw.println(mYOffset);
8300 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008301 pw.print(prefix); pw.print("mGivenContentInsets=");
8302 mGivenContentInsets.printShortString(pw);
8303 pw.print(" mGivenVisibleInsets=");
8304 mGivenVisibleInsets.printShortString(pw);
8305 pw.println();
8306 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8307 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8308 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8309 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008310 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008311 pw.print(prefix); pw.print("mShownFrame=");
8312 mShownFrame.printShortString(pw);
8313 pw.print(" last="); mLastShownFrame.printShortString(pw);
8314 pw.println();
8315 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8316 pw.print(" last="); mLastFrame.printShortString(pw);
8317 pw.println();
8318 pw.print(prefix); pw.print("mContainingFrame=");
8319 mContainingFrame.printShortString(pw);
8320 pw.print(" mDisplayFrame=");
8321 mDisplayFrame.printShortString(pw);
8322 pw.println();
8323 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8324 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8325 pw.println();
8326 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8327 pw.print(" last="); mLastContentInsets.printShortString(pw);
8328 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8329 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8330 pw.println();
8331 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8332 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8333 pw.print(" mAlpha="); pw.print(mAlpha);
8334 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8335 }
8336 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8337 || mAnimation != null) {
8338 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8339 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8340 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8341 pw.print(" mAnimation="); pw.println(mAnimation);
8342 }
8343 if (mHasTransformation || mHasLocalTransformation) {
8344 pw.print(prefix); pw.print("XForm: has=");
8345 pw.print(mHasTransformation);
8346 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8347 pw.print(" "); mTransformation.printShortString(pw);
8348 pw.println();
8349 }
8350 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8351 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8352 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8353 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8354 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8355 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8356 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8357 pw.print(" mDestroying="); pw.print(mDestroying);
8358 pw.print(" mRemoved="); pw.println(mRemoved);
8359 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008360 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008361 pw.print(prefix); pw.print("mOrientationChanging=");
8362 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008363 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8364 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008365 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008366 if (mHScale != 1 || mVScale != 1) {
8367 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8368 pw.print(" mVScale="); pw.println(mVScale);
8369 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008370 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008371 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8372 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8373 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008374 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8375 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8376 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8377 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008378 }
8379
8380 @Override
8381 public String toString() {
8382 return "Window{"
8383 + Integer.toHexString(System.identityHashCode(this))
8384 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
8385 }
8386 }
Romain Guy06882f82009-06-10 13:36:04 -07008387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008388 // -------------------------------------------------------------
8389 // Window Token State
8390 // -------------------------------------------------------------
8391
8392 class WindowToken {
8393 // The actual token.
8394 final IBinder token;
8395
8396 // The type of window this token is for, as per WindowManager.LayoutParams.
8397 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008399 // Set if this token was explicitly added by a client, so should
8400 // not be removed when all windows are removed.
8401 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008402
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008403 // For printing.
8404 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008406 // If this is an AppWindowToken, this is non-null.
8407 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008409 // All of the windows associated with this token.
8410 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8411
8412 // Is key dispatching paused for this token?
8413 boolean paused = false;
8414
8415 // Should this token's windows be hidden?
8416 boolean hidden;
8417
8418 // Temporary for finding which tokens no longer have visible windows.
8419 boolean hasVisible;
8420
Dianne Hackborna8f60182009-09-01 19:01:50 -07008421 // Set to true when this token is in a pending transaction where it
8422 // will be shown.
8423 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008424
Dianne Hackborna8f60182009-09-01 19:01:50 -07008425 // Set to true when this token is in a pending transaction where it
8426 // will be hidden.
8427 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008428
Dianne Hackborna8f60182009-09-01 19:01:50 -07008429 // Set to true when this token is in a pending transaction where its
8430 // windows will be put to the bottom of the list.
8431 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008432
Dianne Hackborna8f60182009-09-01 19:01:50 -07008433 // Set to true when this token is in a pending transaction where its
8434 // windows will be put to the top of the list.
8435 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008437 WindowToken(IBinder _token, int type, boolean _explicit) {
8438 token = _token;
8439 windowType = type;
8440 explicit = _explicit;
8441 }
8442
8443 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008444 pw.print(prefix); pw.print("token="); pw.println(token);
8445 pw.print(prefix); pw.print("windows="); pw.println(windows);
8446 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8447 pw.print(" hidden="); pw.print(hidden);
8448 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008449 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8450 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8451 pw.print(" waitingToHide="); pw.print(waitingToHide);
8452 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8453 pw.print(" sendingToTop="); pw.println(sendingToTop);
8454 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008455 }
8456
8457 @Override
8458 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008459 if (stringName == null) {
8460 StringBuilder sb = new StringBuilder();
8461 sb.append("WindowToken{");
8462 sb.append(Integer.toHexString(System.identityHashCode(this)));
8463 sb.append(" token="); sb.append(token); sb.append('}');
8464 stringName = sb.toString();
8465 }
8466 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008467 }
8468 };
8469
8470 class AppWindowToken extends WindowToken {
8471 // Non-null only for application tokens.
8472 final IApplicationToken appToken;
8473
8474 // All of the windows and child windows that are included in this
8475 // application token. Note this list is NOT sorted!
8476 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8477
8478 int groupId = -1;
8479 boolean appFullscreen;
8480 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Romain Guy06882f82009-06-10 13:36:04 -07008481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008482 // These are used for determining when all windows associated with
8483 // an activity have been drawn, so they can be made visible together
8484 // at the same time.
8485 int lastTransactionSequence = mTransactionSequence-1;
8486 int numInterestingWindows;
8487 int numDrawnWindows;
8488 boolean inPendingTransaction;
8489 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008491 // Is this token going to be hidden in a little while? If so, it
8492 // won't be taken into account for setting the screen orientation.
8493 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008495 // Is this window's surface needed? This is almost like hidden, except
8496 // it will sometimes be true a little earlier: when the token has
8497 // been shown, but is still waiting for its app transition to execute
8498 // before making its windows shown.
8499 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008501 // Have we told the window clients to hide themselves?
8502 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008504 // Last visibility state we reported to the app token.
8505 boolean reportedVisible;
8506
8507 // Set to true when the token has been removed from the window mgr.
8508 boolean removed;
8509
8510 // Have we been asked to have this token keep the screen frozen?
8511 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008513 boolean animating;
8514 Animation animation;
8515 boolean hasTransformation;
8516 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008518 // Offset to the window of all layers in the token, for use by
8519 // AppWindowToken animations.
8520 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008522 // Information about an application starting window if displayed.
8523 StartingData startingData;
8524 WindowState startingWindow;
8525 View startingView;
8526 boolean startingDisplayed;
8527 boolean startingMoved;
8528 boolean firstWindowDrawn;
8529
8530 AppWindowToken(IApplicationToken _token) {
8531 super(_token.asBinder(),
8532 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8533 appWindowToken = this;
8534 appToken = _token;
8535 }
Romain Guy06882f82009-06-10 13:36:04 -07008536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008537 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008538 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008539 TAG, "Setting animation in " + this + ": " + anim);
8540 animation = anim;
8541 animating = false;
8542 anim.restrictDuration(MAX_ANIMATION_DURATION);
8543 anim.scaleCurrentDuration(mTransitionAnimationScale);
8544 int zorder = anim.getZAdjustment();
8545 int adj = 0;
8546 if (zorder == Animation.ZORDER_TOP) {
8547 adj = TYPE_LAYER_OFFSET;
8548 } else if (zorder == Animation.ZORDER_BOTTOM) {
8549 adj = -TYPE_LAYER_OFFSET;
8550 }
Romain Guy06882f82009-06-10 13:36:04 -07008551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008552 if (animLayerAdjustment != adj) {
8553 animLayerAdjustment = adj;
8554 updateLayers();
8555 }
8556 }
Romain Guy06882f82009-06-10 13:36:04 -07008557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008558 public void setDummyAnimation() {
8559 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008560 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008561 TAG, "Setting dummy animation in " + this);
8562 animation = sDummyAnimation;
8563 }
8564 }
8565
8566 public void clearAnimation() {
8567 if (animation != null) {
8568 animation = null;
8569 animating = true;
8570 }
8571 }
Romain Guy06882f82009-06-10 13:36:04 -07008572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008573 void updateLayers() {
8574 final int N = allAppWindows.size();
8575 final int adj = animLayerAdjustment;
8576 for (int i=0; i<N; i++) {
8577 WindowState w = allAppWindows.get(i);
8578 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008579 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008580 + w.mAnimLayer);
8581 if (w == mInputMethodTarget) {
8582 setInputMethodAnimLayerAdjustment(adj);
8583 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008584 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008585 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008586 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008587 }
8588 }
Romain Guy06882f82009-06-10 13:36:04 -07008589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008590 void sendAppVisibilityToClients() {
8591 final int N = allAppWindows.size();
8592 for (int i=0; i<N; i++) {
8593 WindowState win = allAppWindows.get(i);
8594 if (win == startingWindow && clientHidden) {
8595 // Don't hide the starting window.
8596 continue;
8597 }
8598 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008599 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008600 "Setting visibility of " + win + ": " + (!clientHidden));
8601 win.mClient.dispatchAppVisibility(!clientHidden);
8602 } catch (RemoteException e) {
8603 }
8604 }
8605 }
Romain Guy06882f82009-06-10 13:36:04 -07008606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008607 void showAllWindowsLocked() {
8608 final int NW = allAppWindows.size();
8609 for (int i=0; i<NW; i++) {
8610 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008611 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008612 "performing show on: " + w);
8613 w.performShowLocked();
8614 }
8615 }
Romain Guy06882f82009-06-10 13:36:04 -07008616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008617 // This must be called while inside a transaction.
8618 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008619 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008620 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008622 if (animation == sDummyAnimation) {
8623 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008624 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008625 // when it is really time to animate, this will be set to
8626 // a real animation and the next call will execute normally.
8627 return false;
8628 }
Romain Guy06882f82009-06-10 13:36:04 -07008629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008630 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8631 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008632 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008633 TAG, "Starting animation in " + this +
8634 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8635 + " scale=" + mTransitionAnimationScale
8636 + " allDrawn=" + allDrawn + " animating=" + animating);
8637 animation.initialize(dw, dh, dw, dh);
8638 animation.setStartTime(currentTime);
8639 animating = true;
8640 }
8641 transformation.clear();
8642 final boolean more = animation.getTransformation(
8643 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008644 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008645 TAG, "Stepped animation in " + this +
8646 ": more=" + more + ", xform=" + transformation);
8647 if (more) {
8648 // we're done!
8649 hasTransformation = true;
8650 return true;
8651 }
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, "Finished animation in " + this +
8654 " @ " + currentTime);
8655 animation = null;
8656 }
8657 } else if (animation != null) {
8658 // If the display is frozen, and there is a pending animation,
8659 // clear it and make sure we run the cleanup code.
8660 animating = true;
8661 animation = null;
8662 }
8663
8664 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008666 if (!animating) {
8667 return false;
8668 }
8669
8670 clearAnimation();
8671 animating = false;
8672 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8673 moveInputMethodWindowsIfNeededLocked(true);
8674 }
Romain Guy06882f82009-06-10 13:36:04 -07008675
Joe Onorato8a9b2202010-02-26 18:56:32 -08008676 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008677 TAG, "Animation done in " + this
8678 + ": reportedVisible=" + reportedVisible);
8679
8680 transformation.clear();
8681 if (animLayerAdjustment != 0) {
8682 animLayerAdjustment = 0;
8683 updateLayers();
8684 }
Romain Guy06882f82009-06-10 13:36:04 -07008685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008686 final int N = windows.size();
8687 for (int i=0; i<N; i++) {
8688 ((WindowState)windows.get(i)).finishExit();
8689 }
8690 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008692 return false;
8693 }
8694
8695 void updateReportedVisibilityLocked() {
8696 if (appToken == null) {
8697 return;
8698 }
Romain Guy06882f82009-06-10 13:36:04 -07008699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008700 int numInteresting = 0;
8701 int numVisible = 0;
8702 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008703
Joe Onorato8a9b2202010-02-26 18:56:32 -08008704 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008705 final int N = allAppWindows.size();
8706 for (int i=0; i<N; i++) {
8707 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008708 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008709 || win.mViewVisibility != View.VISIBLE
8710 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008711 continue;
8712 }
8713 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008714 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008715 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008716 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008717 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008718 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008719 + " pv=" + win.mPolicyVisibility
8720 + " dp=" + win.mDrawPending
8721 + " cdp=" + win.mCommitDrawPending
8722 + " ah=" + win.mAttachedHidden
8723 + " th="
8724 + (win.mAppToken != null
8725 ? win.mAppToken.hiddenRequested : false)
8726 + " a=" + win.mAnimating);
8727 }
8728 }
8729 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008730 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008731 if (!win.isAnimating()) {
8732 numVisible++;
8733 }
8734 nowGone = false;
8735 } else if (win.isAnimating()) {
8736 nowGone = false;
8737 }
8738 }
Romain Guy06882f82009-06-10 13:36:04 -07008739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008740 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008741 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008742 + numInteresting + " visible=" + numVisible);
8743 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008744 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008745 TAG, "Visibility changed in " + this
8746 + ": vis=" + nowVisible);
8747 reportedVisible = nowVisible;
8748 Message m = mH.obtainMessage(
8749 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8750 nowVisible ? 1 : 0,
8751 nowGone ? 1 : 0,
8752 this);
8753 mH.sendMessage(m);
8754 }
8755 }
Romain Guy06882f82009-06-10 13:36:04 -07008756
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008757 WindowState findMainWindow() {
8758 int j = windows.size();
8759 while (j > 0) {
8760 j--;
8761 WindowState win = windows.get(j);
8762 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8763 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8764 return win;
8765 }
8766 }
8767 return null;
8768 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008770 void dump(PrintWriter pw, String prefix) {
8771 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008772 if (appToken != null) {
8773 pw.print(prefix); pw.println("app=true");
8774 }
8775 if (allAppWindows.size() > 0) {
8776 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8777 }
8778 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008779 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008780 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8781 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8782 pw.print(" clientHidden="); pw.print(clientHidden);
8783 pw.print(" willBeHidden="); pw.print(willBeHidden);
8784 pw.print(" reportedVisible="); pw.println(reportedVisible);
8785 if (paused || freezingScreen) {
8786 pw.print(prefix); pw.print("paused="); pw.print(paused);
8787 pw.print(" freezingScreen="); pw.println(freezingScreen);
8788 }
8789 if (numInterestingWindows != 0 || numDrawnWindows != 0
8790 || inPendingTransaction || allDrawn) {
8791 pw.print(prefix); pw.print("numInterestingWindows=");
8792 pw.print(numInterestingWindows);
8793 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8794 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8795 pw.print(" allDrawn="); pw.println(allDrawn);
8796 }
8797 if (animating || animation != null) {
8798 pw.print(prefix); pw.print("animating="); pw.print(animating);
8799 pw.print(" animation="); pw.println(animation);
8800 }
8801 if (animLayerAdjustment != 0) {
8802 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8803 }
8804 if (hasTransformation) {
8805 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8806 pw.print(" transformation="); transformation.printShortString(pw);
8807 pw.println();
8808 }
8809 if (startingData != null || removed || firstWindowDrawn) {
8810 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8811 pw.print(" removed="); pw.print(removed);
8812 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8813 }
8814 if (startingWindow != null || startingView != null
8815 || startingDisplayed || startingMoved) {
8816 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8817 pw.print(" startingView="); pw.print(startingView);
8818 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8819 pw.print(" startingMoved"); pw.println(startingMoved);
8820 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008821 }
8822
8823 @Override
8824 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008825 if (stringName == null) {
8826 StringBuilder sb = new StringBuilder();
8827 sb.append("AppWindowToken{");
8828 sb.append(Integer.toHexString(System.identityHashCode(this)));
8829 sb.append(" token="); sb.append(token); sb.append('}');
8830 stringName = sb.toString();
8831 }
8832 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008833 }
8834 }
Romain Guy06882f82009-06-10 13:36:04 -07008835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008836 // -------------------------------------------------------------
8837 // DummyAnimation
8838 // -------------------------------------------------------------
8839
8840 // This is an animation that does nothing: it just immediately finishes
8841 // itself every time it is called. It is used as a stub animation in cases
8842 // where we want to synchronize multiple things that may be animating.
8843 static final class DummyAnimation extends Animation {
8844 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8845 return false;
8846 }
8847 }
8848 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008850 // -------------------------------------------------------------
8851 // Async Handler
8852 // -------------------------------------------------------------
8853
8854 static final class StartingData {
8855 final String pkg;
8856 final int theme;
8857 final CharSequence nonLocalizedLabel;
8858 final int labelRes;
8859 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008860
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008861 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8862 int _labelRes, int _icon) {
8863 pkg = _pkg;
8864 theme = _theme;
8865 nonLocalizedLabel = _nonLocalizedLabel;
8866 labelRes = _labelRes;
8867 icon = _icon;
8868 }
8869 }
8870
8871 private final class H extends Handler {
8872 public static final int REPORT_FOCUS_CHANGE = 2;
8873 public static final int REPORT_LOSING_FOCUS = 3;
8874 public static final int ANIMATE = 4;
8875 public static final int ADD_STARTING = 5;
8876 public static final int REMOVE_STARTING = 6;
8877 public static final int FINISHED_STARTING = 7;
8878 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008879 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8880 public static final int HOLD_SCREEN_CHANGED = 12;
8881 public static final int APP_TRANSITION_TIMEOUT = 13;
8882 public static final int PERSIST_ANIMATION_SCALE = 14;
8883 public static final int FORCE_GC = 15;
8884 public static final int ENABLE_SCREEN = 16;
8885 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008886 public static final int SEND_NEW_CONFIGURATION = 18;
Romain Guy06882f82009-06-10 13:36:04 -07008887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008888 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008889
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008890 public H() {
8891 }
Romain Guy06882f82009-06-10 13:36:04 -07008892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008893 @Override
8894 public void handleMessage(Message msg) {
8895 switch (msg.what) {
8896 case REPORT_FOCUS_CHANGE: {
8897 WindowState lastFocus;
8898 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008900 synchronized(mWindowMap) {
8901 lastFocus = mLastFocus;
8902 newFocus = mCurrentFocus;
8903 if (lastFocus == newFocus) {
8904 // Focus is not changing, so nothing to do.
8905 return;
8906 }
8907 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008908 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008909 // + " to " + newFocus);
8910 if (newFocus != null && lastFocus != null
8911 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008912 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008913 mLosingFocus.add(lastFocus);
8914 lastFocus = null;
8915 }
8916 }
8917
8918 if (lastFocus != newFocus) {
8919 //System.out.println("Changing focus from " + lastFocus
8920 // + " to " + newFocus);
8921 if (newFocus != null) {
8922 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008923 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008924 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8925 } catch (RemoteException e) {
8926 // Ignore if process has died.
8927 }
8928 }
8929
8930 if (lastFocus != null) {
8931 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008932 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008933 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8934 } catch (RemoteException e) {
8935 // Ignore if process has died.
8936 }
8937 }
8938 }
8939 } break;
8940
8941 case REPORT_LOSING_FOCUS: {
8942 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008944 synchronized(mWindowMap) {
8945 losers = mLosingFocus;
8946 mLosingFocus = new ArrayList<WindowState>();
8947 }
8948
8949 final int N = losers.size();
8950 for (int i=0; i<N; i++) {
8951 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008952 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008953 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8954 } catch (RemoteException e) {
8955 // Ignore if process has died.
8956 }
8957 }
8958 } break;
8959
8960 case ANIMATE: {
8961 synchronized(mWindowMap) {
8962 mAnimationPending = false;
8963 performLayoutAndPlaceSurfacesLocked();
8964 }
8965 } break;
8966
8967 case ADD_STARTING: {
8968 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8969 final StartingData sd = wtoken.startingData;
8970
8971 if (sd == null) {
8972 // Animation has been canceled... do nothing.
8973 return;
8974 }
Romain Guy06882f82009-06-10 13:36:04 -07008975
Joe Onorato8a9b2202010-02-26 18:56:32 -08008976 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008977 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008979 View view = null;
8980 try {
8981 view = mPolicy.addStartingWindow(
8982 wtoken.token, sd.pkg,
8983 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8984 sd.icon);
8985 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008986 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008987 }
8988
8989 if (view != null) {
8990 boolean abort = false;
8991
8992 synchronized(mWindowMap) {
8993 if (wtoken.removed || wtoken.startingData == null) {
8994 // If the window was successfully added, then
8995 // we need to remove it.
8996 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008997 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008998 "Aborted starting " + wtoken
8999 + ": removed=" + wtoken.removed
9000 + " startingData=" + wtoken.startingData);
9001 wtoken.startingWindow = null;
9002 wtoken.startingData = null;
9003 abort = true;
9004 }
9005 } else {
9006 wtoken.startingView = view;
9007 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009008 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009009 "Added starting " + wtoken
9010 + ": startingWindow="
9011 + wtoken.startingWindow + " startingView="
9012 + wtoken.startingView);
9013 }
9014
9015 if (abort) {
9016 try {
9017 mPolicy.removeStartingWindow(wtoken.token, view);
9018 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009019 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009020 }
9021 }
9022 }
9023 } break;
9024
9025 case REMOVE_STARTING: {
9026 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9027 IBinder token = null;
9028 View view = null;
9029 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009030 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009031 + wtoken + ": startingWindow="
9032 + wtoken.startingWindow + " startingView="
9033 + wtoken.startingView);
9034 if (wtoken.startingWindow != null) {
9035 view = wtoken.startingView;
9036 token = wtoken.token;
9037 wtoken.startingData = null;
9038 wtoken.startingView = null;
9039 wtoken.startingWindow = null;
9040 }
9041 }
9042 if (view != null) {
9043 try {
9044 mPolicy.removeStartingWindow(token, view);
9045 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009046 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009047 }
9048 }
9049 } break;
9050
9051 case FINISHED_STARTING: {
9052 IBinder token = null;
9053 View view = null;
9054 while (true) {
9055 synchronized (mWindowMap) {
9056 final int N = mFinishedStarting.size();
9057 if (N <= 0) {
9058 break;
9059 }
9060 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
9061
Joe Onorato8a9b2202010-02-26 18:56:32 -08009062 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009063 "Finished starting " + wtoken
9064 + ": startingWindow=" + wtoken.startingWindow
9065 + " startingView=" + wtoken.startingView);
9066
9067 if (wtoken.startingWindow == null) {
9068 continue;
9069 }
9070
9071 view = wtoken.startingView;
9072 token = wtoken.token;
9073 wtoken.startingData = null;
9074 wtoken.startingView = null;
9075 wtoken.startingWindow = null;
9076 }
9077
9078 try {
9079 mPolicy.removeStartingWindow(token, view);
9080 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009081 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009082 }
9083 }
9084 } break;
9085
9086 case REPORT_APPLICATION_TOKEN_WINDOWS: {
9087 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9088
9089 boolean nowVisible = msg.arg1 != 0;
9090 boolean nowGone = msg.arg2 != 0;
9091
9092 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009093 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009094 TAG, "Reporting visible in " + wtoken
9095 + " visible=" + nowVisible
9096 + " gone=" + nowGone);
9097 if (nowVisible) {
9098 wtoken.appToken.windowsVisible();
9099 } else {
9100 wtoken.appToken.windowsGone();
9101 }
9102 } catch (RemoteException ex) {
9103 }
9104 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009106 case WINDOW_FREEZE_TIMEOUT: {
9107 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009108 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009109 int i = mWindows.size();
9110 while (i > 0) {
9111 i--;
9112 WindowState w = (WindowState)mWindows.get(i);
9113 if (w.mOrientationChanging) {
9114 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009115 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009116 }
9117 }
9118 performLayoutAndPlaceSurfacesLocked();
9119 }
9120 break;
9121 }
Romain Guy06882f82009-06-10 13:36:04 -07009122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009123 case HOLD_SCREEN_CHANGED: {
9124 Session oldHold;
9125 Session newHold;
9126 synchronized (mWindowMap) {
9127 oldHold = mLastReportedHold;
9128 newHold = (Session)msg.obj;
9129 mLastReportedHold = newHold;
9130 }
Romain Guy06882f82009-06-10 13:36:04 -07009131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009132 if (oldHold != newHold) {
9133 try {
9134 if (oldHold != null) {
9135 mBatteryStats.noteStopWakelock(oldHold.mUid,
9136 "window",
9137 BatteryStats.WAKE_TYPE_WINDOW);
9138 }
9139 if (newHold != null) {
9140 mBatteryStats.noteStartWakelock(newHold.mUid,
9141 "window",
9142 BatteryStats.WAKE_TYPE_WINDOW);
9143 }
9144 } catch (RemoteException e) {
9145 }
9146 }
9147 break;
9148 }
Romain Guy06882f82009-06-10 13:36:04 -07009149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009150 case APP_TRANSITION_TIMEOUT: {
9151 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009152 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009153 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009154 "*** APP TRANSITION TIMEOUT");
9155 mAppTransitionReady = true;
9156 mAppTransitionTimeout = true;
9157 performLayoutAndPlaceSurfacesLocked();
9158 }
9159 }
9160 break;
9161 }
Romain Guy06882f82009-06-10 13:36:04 -07009162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009163 case PERSIST_ANIMATION_SCALE: {
9164 Settings.System.putFloat(mContext.getContentResolver(),
9165 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9166 Settings.System.putFloat(mContext.getContentResolver(),
9167 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9168 break;
9169 }
Romain Guy06882f82009-06-10 13:36:04 -07009170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009171 case FORCE_GC: {
9172 synchronized(mWindowMap) {
9173 if (mAnimationPending) {
9174 // If we are animating, don't do the gc now but
9175 // delay a bit so we don't interrupt the animation.
9176 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9177 2000);
9178 return;
9179 }
9180 // If we are currently rotating the display, it will
9181 // schedule a new message when done.
9182 if (mDisplayFrozen) {
9183 return;
9184 }
9185 mFreezeGcPending = 0;
9186 }
9187 Runtime.getRuntime().gc();
9188 break;
9189 }
Romain Guy06882f82009-06-10 13:36:04 -07009190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009191 case ENABLE_SCREEN: {
9192 performEnableScreen();
9193 break;
9194 }
Romain Guy06882f82009-06-10 13:36:04 -07009195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009196 case APP_FREEZE_TIMEOUT: {
9197 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009198 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009199 int i = mAppTokens.size();
9200 while (i > 0) {
9201 i--;
9202 AppWindowToken tok = mAppTokens.get(i);
9203 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009204 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009205 unsetAppFreezingScreenLocked(tok, true, true);
9206 }
9207 }
9208 }
9209 break;
9210 }
Romain Guy06882f82009-06-10 13:36:04 -07009211
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009212 case SEND_NEW_CONFIGURATION: {
9213 removeMessages(SEND_NEW_CONFIGURATION);
9214 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009215 break;
9216 }
Romain Guy06882f82009-06-10 13:36:04 -07009217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009218 }
9219 }
9220 }
9221
9222 // -------------------------------------------------------------
9223 // IWindowManager API
9224 // -------------------------------------------------------------
9225
9226 public IWindowSession openSession(IInputMethodClient client,
9227 IInputContext inputContext) {
9228 if (client == null) throw new IllegalArgumentException("null client");
9229 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
9230 return new Session(client, inputContext);
9231 }
9232
9233 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9234 synchronized (mWindowMap) {
9235 // The focus for the client is the window immediately below
9236 // where we would place the input method window.
9237 int idx = findDesiredInputMethodWindowIndexLocked(false);
9238 WindowState imFocus;
9239 if (idx > 0) {
9240 imFocus = (WindowState)mWindows.get(idx-1);
9241 if (imFocus != null) {
9242 if (imFocus.mSession.mClient != null &&
9243 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9244 return true;
9245 }
9246 }
9247 }
9248 }
9249 return false;
9250 }
Romain Guy06882f82009-06-10 13:36:04 -07009251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009252 // -------------------------------------------------------------
9253 // Internals
9254 // -------------------------------------------------------------
9255
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009256 final WindowState windowForClientLocked(Session session, IWindow client,
9257 boolean throwOnError) {
9258 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009259 }
Romain Guy06882f82009-06-10 13:36:04 -07009260
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009261 final WindowState windowForClientLocked(Session session, IBinder client,
9262 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009263 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009264 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009265 TAG, "Looking up client " + client + ": " + win);
9266 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009267 RuntimeException ex = new IllegalArgumentException(
9268 "Requested window " + client + " does not exist");
9269 if (throwOnError) {
9270 throw ex;
9271 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009272 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009273 return null;
9274 }
9275 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009276 RuntimeException ex = new IllegalArgumentException(
9277 "Requested window " + client + " is in session " +
9278 win.mSession + ", not " + session);
9279 if (throwOnError) {
9280 throw ex;
9281 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009282 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009283 return null;
9284 }
9285
9286 return win;
9287 }
9288
Dianne Hackborna8f60182009-09-01 19:01:50 -07009289 final void rebuildAppWindowListLocked() {
9290 int NW = mWindows.size();
9291 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009292 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009293 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009294
Dianne Hackborna8f60182009-09-01 19:01:50 -07009295 // First remove all existing app windows.
9296 i=0;
9297 while (i < NW) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009298 WindowState w = (WindowState)mWindows.get(i);
9299 if (w.mAppToken != null) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009300 WindowState win = (WindowState)mWindows.remove(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009301 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009302 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009303 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009304 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009305 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009306 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9307 && lastWallpaper == i-1) {
9308 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009309 }
9310 i++;
9311 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009312
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009313 // The wallpaper window(s) typically live at the bottom of the stack,
9314 // so skip them before adding app tokens.
9315 lastWallpaper++;
9316 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009317
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009318 // First add all of the exiting app tokens... these are no longer
9319 // in the main app list, but still have windows shown. We put them
9320 // in the back because now that the animation is over we no longer
9321 // will care about them.
9322 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009323 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009324 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9325 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009326
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009327 // And add in the still active app tokens in Z order.
9328 NT = mAppTokens.size();
9329 for (int j=0; j<NT; j++) {
9330 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009331 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009332
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009333 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009334 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009335 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009336 + " windows but added " + i);
9337 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009338 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009340 private final void assignLayersLocked() {
9341 int N = mWindows.size();
9342 int curBaseLayer = 0;
9343 int curLayer = 0;
9344 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009346 for (i=0; i<N; i++) {
9347 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009348 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9349 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009350 curLayer += WINDOW_LAYER_MULTIPLIER;
9351 w.mLayer = curLayer;
9352 } else {
9353 curBaseLayer = curLayer = w.mBaseLayer;
9354 w.mLayer = curLayer;
9355 }
9356 if (w.mTargetAppToken != null) {
9357 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9358 } else if (w.mAppToken != null) {
9359 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9360 } else {
9361 w.mAnimLayer = w.mLayer;
9362 }
9363 if (w.mIsImWindow) {
9364 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009365 } else if (w.mIsWallpaper) {
9366 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009367 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009368 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009369 + w.mAnimLayer);
9370 //System.out.println(
9371 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9372 }
9373 }
9374
9375 private boolean mInLayout = false;
9376 private final void performLayoutAndPlaceSurfacesLocked() {
9377 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009378 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009379 throw new RuntimeException("Recursive call!");
9380 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009381 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009382 return;
9383 }
9384
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009385 if (mWaitingForConfig) {
9386 // Our configuration has changed (most likely rotation), but we
9387 // don't yet have the complete configuration to report to
9388 // applications. Don't do any window layout until we have it.
9389 return;
9390 }
9391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009392 boolean recoveringMemory = false;
9393 if (mForceRemoves != null) {
9394 recoveringMemory = true;
9395 // Wait a little it for things to settle down, and off we go.
9396 for (int i=0; i<mForceRemoves.size(); i++) {
9397 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009398 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009399 removeWindowInnerLocked(ws.mSession, ws);
9400 }
9401 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009402 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009403 Object tmp = new Object();
9404 synchronized (tmp) {
9405 try {
9406 tmp.wait(250);
9407 } catch (InterruptedException e) {
9408 }
9409 }
9410 }
Romain Guy06882f82009-06-10 13:36:04 -07009411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009412 mInLayout = true;
9413 try {
9414 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009416 int i = mPendingRemove.size()-1;
9417 if (i >= 0) {
9418 while (i >= 0) {
9419 WindowState w = mPendingRemove.get(i);
9420 removeWindowInnerLocked(w.mSession, w);
9421 i--;
9422 }
9423 mPendingRemove.clear();
9424
9425 mInLayout = false;
9426 assignLayersLocked();
9427 mLayoutNeeded = true;
9428 performLayoutAndPlaceSurfacesLocked();
9429
9430 } else {
9431 mInLayout = false;
9432 if (mLayoutNeeded) {
9433 requestAnimationLocked(0);
9434 }
9435 }
9436 } catch (RuntimeException e) {
9437 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009438 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009439 }
9440 }
9441
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009442 private final int performLayoutLockedInner() {
9443 if (!mLayoutNeeded) {
9444 return 0;
9445 }
9446
9447 mLayoutNeeded = false;
9448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009449 final int dw = mDisplay.getWidth();
9450 final int dh = mDisplay.getHeight();
9451
9452 final int N = mWindows.size();
9453 int i;
9454
Joe Onorato8a9b2202010-02-26 18:56:32 -08009455 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009456 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9457
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009458 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009459
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009460 int seq = mLayoutSeq+1;
9461 if (seq < 0) seq = 0;
9462 mLayoutSeq = seq;
9463
9464 // First perform layout of any root windows (not attached
9465 // to another window).
9466 int topAttached = -1;
9467 for (i = N-1; i >= 0; i--) {
9468 WindowState win = (WindowState) mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009469
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009470 // Don't do layout of a window if it is not visible, or
9471 // soon won't be visible, to avoid wasting time and funky
9472 // changes while a window is animating away.
9473 final AppWindowToken atoken = win.mAppToken;
9474 final boolean gone = win.mViewVisibility == View.GONE
9475 || !win.mRelayoutCalled
9476 || win.mRootToken.hidden
9477 || (atoken != null && atoken.hiddenRequested)
9478 || win.mAttachedHidden
9479 || win.mExiting || win.mDestroying;
9480
9481 if (!win.mLayoutAttached) {
9482 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
9483 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9484 + " mLayoutAttached=" + win.mLayoutAttached);
9485 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
9486 + win.mViewVisibility + " mRelayoutCalled="
9487 + win.mRelayoutCalled + " hidden="
9488 + win.mRootToken.hidden + " hiddenRequested="
9489 + (atoken != null && atoken.hiddenRequested)
9490 + " mAttachedHidden=" + win.mAttachedHidden);
9491 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009492
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009493 // If this view is GONE, then skip it -- keep the current
9494 // frame, and let the caller know so they can ignore it
9495 // if they want. (We do the normal layout for INVISIBLE
9496 // windows, since that means "perform layout as normal,
9497 // just don't display").
9498 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009499 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009500 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9501 win.mLayoutSeq = seq;
9502 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9503 + win.mFrame + " mContainingFrame="
9504 + win.mContainingFrame + " mDisplayFrame="
9505 + win.mDisplayFrame);
9506 } else {
9507 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009508 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009509 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009510 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009511
9512 // Now perform layout of attached windows, which usually
9513 // depend on the position of the window they are attached to.
9514 // XXX does not deal with windows that are attached to windows
9515 // that are themselves attached.
9516 for (i = topAttached; i >= 0; i--) {
9517 WindowState win = (WindowState) mWindows.get(i);
9518
9519 // If this view is GONE, then skip it -- keep the current
9520 // frame, and let the caller know so they can ignore it
9521 // if they want. (We do the normal layout for INVISIBLE
9522 // windows, since that means "perform layout as normal,
9523 // just don't display").
9524 if (win.mLayoutAttached) {
9525 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9526 + " mHaveFrame=" + win.mHaveFrame
9527 + " mViewVisibility=" + win.mViewVisibility
9528 + " mRelayoutCalled=" + win.mRelayoutCalled);
9529 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9530 || !win.mHaveFrame) {
9531 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9532 win.mLayoutSeq = seq;
9533 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9534 + win.mFrame + " mContainingFrame="
9535 + win.mContainingFrame + " mDisplayFrame="
9536 + win.mDisplayFrame);
9537 }
9538 }
9539 }
9540
9541 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009542 }
Romain Guy06882f82009-06-10 13:36:04 -07009543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009544 private final void performLayoutAndPlaceSurfacesLockedInner(
9545 boolean recoveringMemory) {
9546 final long currentTime = SystemClock.uptimeMillis();
9547 final int dw = mDisplay.getWidth();
9548 final int dh = mDisplay.getHeight();
9549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009550 int i;
9551
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009552 if (mFocusMayChange) {
9553 mFocusMayChange = false;
9554 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9555 }
9556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009557 if (mFxSession == null) {
9558 mFxSession = new SurfaceSession();
9559 }
Romain Guy06882f82009-06-10 13:36:04 -07009560
Joe Onorato8a9b2202010-02-26 18:56:32 -08009561 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009562
9563 // Initialize state of exiting tokens.
9564 for (i=mExitingTokens.size()-1; i>=0; i--) {
9565 mExitingTokens.get(i).hasVisible = false;
9566 }
9567
9568 // Initialize state of exiting applications.
9569 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9570 mExitingAppTokens.get(i).hasVisible = false;
9571 }
9572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009573 boolean orientationChangeComplete = true;
9574 Session holdScreen = null;
9575 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009576 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009577 boolean focusDisplayed = false;
9578 boolean animating = false;
9579
9580 Surface.openTransaction();
9581 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009582 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009583 int repeats = 0;
9584 int changes = 0;
9585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009586 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009587 repeats++;
9588 if (repeats > 6) {
9589 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9590 mLayoutNeeded = false;
9591 break;
9592 }
9593
9594 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9595 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9596 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9597 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9598 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9599 assignLayersLocked();
9600 mLayoutNeeded = true;
9601 }
9602 }
9603 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9604 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9605 if (updateOrientationFromAppTokensLocked()) {
9606 mLayoutNeeded = true;
9607 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9608 }
9609 }
9610 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9611 mLayoutNeeded = true;
9612 }
9613 }
9614
9615 // FIRST LOOP: Perform a layout, if needed.
9616 if (repeats < 4) {
9617 changes = performLayoutLockedInner();
9618 if (changes != 0) {
9619 continue;
9620 }
9621 } else {
9622 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9623 changes = 0;
9624 }
9625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009626 final int transactionSequence = ++mTransactionSequence;
9627
9628 // Update animations of all applications, including those
9629 // associated with exiting/removed apps
9630 boolean tokensAnimating = false;
9631 final int NAT = mAppTokens.size();
9632 for (i=0; i<NAT; i++) {
9633 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9634 tokensAnimating = true;
9635 }
9636 }
9637 final int NEAT = mExitingAppTokens.size();
9638 for (i=0; i<NEAT; i++) {
9639 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9640 tokensAnimating = true;
9641 }
9642 }
9643
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009644 // SECOND LOOP: Execute animations and update visibility of windows.
9645
Joe Onorato8a9b2202010-02-26 18:56:32 -08009646 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009647 + transactionSequence + " tokensAnimating="
9648 + tokensAnimating);
9649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009650 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009651
9652 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009653 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009654 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009655
9656 mPolicy.beginAnimationLw(dw, dh);
9657
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009658 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009660 for (i=N-1; i>=0; i--) {
9661 WindowState w = (WindowState)mWindows.get(i);
9662
9663 final WindowManager.LayoutParams attrs = w.mAttrs;
9664
9665 if (w.mSurface != null) {
9666 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009667 if (w.commitFinishDrawingLocked(currentTime)) {
9668 if ((w.mAttrs.flags
9669 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009670 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009671 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009672 wallpaperMayChange = true;
9673 }
9674 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009675
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009676 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009677 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9678 animating = true;
9679 //w.dump(" ");
9680 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009681 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9682 wallpaperMayChange = true;
9683 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009684
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009685 if (mPolicy.doesForceHide(w, attrs)) {
9686 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009687 if (DEBUG_VISIBILITY) Slog.v(TAG,
9688 "Animation done that could impact force hide: "
9689 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009690 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009691 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009692 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9693 forceHiding = true;
9694 }
9695 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9696 boolean changed;
9697 if (forceHiding) {
9698 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009699 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9700 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009701 } else {
9702 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009703 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9704 "Now policy shown: " + w);
9705 if (changed) {
9706 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009707 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009708 // Assume we will need to animate. If
9709 // we don't (because the wallpaper will
9710 // stay with the lock screen), then we will
9711 // clean up later.
9712 Animation a = mPolicy.createForceHideEnterAnimation();
9713 if (a != null) {
9714 w.setAnimation(a);
9715 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009716 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009717 if (mCurrentFocus == null ||
9718 mCurrentFocus.mLayer < w.mLayer) {
9719 // We are showing on to of the current
9720 // focus, so re-evaluate focus to make
9721 // sure it is correct.
9722 mFocusMayChange = true;
9723 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009724 }
9725 }
9726 if (changed && (attrs.flags
9727 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9728 wallpaperMayChange = true;
9729 }
9730 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009732 mPolicy.animatingWindowLw(w, attrs);
9733 }
9734
9735 final AppWindowToken atoken = w.mAppToken;
9736 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9737 if (atoken.lastTransactionSequence != transactionSequence) {
9738 atoken.lastTransactionSequence = transactionSequence;
9739 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9740 atoken.startingDisplayed = false;
9741 }
9742 if ((w.isOnScreen() || w.mAttrs.type
9743 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9744 && !w.mExiting && !w.mDestroying) {
9745 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009746 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009747 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009748 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009749 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009750 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009751 + " pv=" + w.mPolicyVisibility
9752 + " dp=" + w.mDrawPending
9753 + " cdp=" + w.mCommitDrawPending
9754 + " ah=" + w.mAttachedHidden
9755 + " th=" + atoken.hiddenRequested
9756 + " a=" + w.mAnimating);
9757 }
9758 }
9759 if (w != atoken.startingWindow) {
9760 if (!atoken.freezingScreen || !w.mAppFreezing) {
9761 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009762 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009763 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009764 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009765 "tokenMayBeDrawn: " + atoken
9766 + " freezingScreen=" + atoken.freezingScreen
9767 + " mAppFreezing=" + w.mAppFreezing);
9768 tokenMayBeDrawn = true;
9769 }
9770 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009771 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009772 atoken.startingDisplayed = true;
9773 }
9774 }
9775 } else if (w.mReadyToShow) {
9776 w.performShowLocked();
9777 }
9778 }
9779
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009780 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009781
9782 if (tokenMayBeDrawn) {
9783 // See if any windows have been drawn, so they (and others
9784 // associated with them) can now be shown.
9785 final int NT = mTokenList.size();
9786 for (i=0; i<NT; i++) {
9787 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9788 if (wtoken == null) {
9789 continue;
9790 }
9791 if (wtoken.freezingScreen) {
9792 int numInteresting = wtoken.numInterestingWindows;
9793 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009794 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009795 "allDrawn: " + wtoken
9796 + " interesting=" + numInteresting
9797 + " drawn=" + wtoken.numDrawnWindows);
9798 wtoken.showAllWindowsLocked();
9799 unsetAppFreezingScreenLocked(wtoken, false, true);
9800 orientationChangeComplete = true;
9801 }
9802 } else if (!wtoken.allDrawn) {
9803 int numInteresting = wtoken.numInterestingWindows;
9804 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009805 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009806 "allDrawn: " + wtoken
9807 + " interesting=" + numInteresting
9808 + " drawn=" + wtoken.numDrawnWindows);
9809 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009810 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009811
9812 // We can now show all of the drawn windows!
9813 if (!mOpeningApps.contains(wtoken)) {
9814 wtoken.showAllWindowsLocked();
9815 }
9816 }
9817 }
9818 }
9819 }
9820
9821 // If we are ready to perform an app transition, check through
9822 // all of the app tokens to be shown and see if they are ready
9823 // to go.
9824 if (mAppTransitionReady) {
9825 int NN = mOpeningApps.size();
9826 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009827 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009828 "Checking " + NN + " opening apps (frozen="
9829 + mDisplayFrozen + " timeout="
9830 + mAppTransitionTimeout + ")...");
9831 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9832 // If the display isn't frozen, wait to do anything until
9833 // all of the apps are ready. Otherwise just go because
9834 // we'll unfreeze the display when everyone is ready.
9835 for (i=0; i<NN && goodToGo; i++) {
9836 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009837 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009838 "Check opening app" + wtoken + ": allDrawn="
9839 + wtoken.allDrawn + " startingDisplayed="
9840 + wtoken.startingDisplayed);
9841 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9842 && !wtoken.startingMoved) {
9843 goodToGo = false;
9844 }
9845 }
9846 }
9847 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009848 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009849 int transit = mNextAppTransition;
9850 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009851 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009852 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009853 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009854 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009855 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009856 mAppTransitionTimeout = false;
9857 mStartingIconInTransition = false;
9858 mSkipAppTransitionAnimation = false;
9859
9860 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9861
Dianne Hackborna8f60182009-09-01 19:01:50 -07009862 // If there are applications waiting to come to the
9863 // top of the stack, now is the time to move their windows.
9864 // (Note that we don't do apps going to the bottom
9865 // here -- we want to keep their windows in the old
9866 // Z-order until the animation completes.)
9867 if (mToTopApps.size() > 0) {
9868 NN = mAppTokens.size();
9869 for (i=0; i<NN; i++) {
9870 AppWindowToken wtoken = mAppTokens.get(i);
9871 if (wtoken.sendingToTop) {
9872 wtoken.sendingToTop = false;
9873 moveAppWindowsLocked(wtoken, NN, false);
9874 }
9875 }
9876 mToTopApps.clear();
9877 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009878
Dianne Hackborn25994b42009-09-04 14:21:19 -07009879 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009880
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009881 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009882 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009883
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009884 // The top-most window will supply the layout params,
9885 // and we will determine it below.
9886 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009887 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009888 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009889
Joe Onorato8a9b2202010-02-26 18:56:32 -08009890 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009891 "New wallpaper target=" + mWallpaperTarget
9892 + ", lower target=" + mLowerWallpaperTarget
9893 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009894 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009895 // Do a first pass through the tokens for two
9896 // things:
9897 // (1) Determine if both the closing and opening
9898 // app token sets are wallpaper targets, in which
9899 // case special animations are needed
9900 // (since the wallpaper needs to stay static
9901 // behind them).
9902 // (2) Find the layout params of the top-most
9903 // application window in the tokens, which is
9904 // what will control the animation theme.
9905 final int NC = mClosingApps.size();
9906 NN = NC + mOpeningApps.size();
9907 for (i=0; i<NN; i++) {
9908 AppWindowToken wtoken;
9909 int mode;
9910 if (i < NC) {
9911 wtoken = mClosingApps.get(i);
9912 mode = 1;
9913 } else {
9914 wtoken = mOpeningApps.get(i-NC);
9915 mode = 2;
9916 }
9917 if (mLowerWallpaperTarget != null) {
9918 if (mLowerWallpaperTarget.mAppToken == wtoken
9919 || mUpperWallpaperTarget.mAppToken == wtoken) {
9920 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009921 }
9922 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009923 if (wtoken.appFullscreen) {
9924 WindowState ws = wtoken.findMainWindow();
9925 if (ws != null) {
9926 // If this is a compatibility mode
9927 // window, we will always use its anim.
9928 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9929 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009930 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009931 bestAnimLayer = Integer.MAX_VALUE;
9932 } else if (ws.mLayer > bestAnimLayer) {
9933 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009934 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009935 bestAnimLayer = ws.mLayer;
9936 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009937 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009938 }
9939 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009940
Dianne Hackborn25994b42009-09-04 14:21:19 -07009941 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009942 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009943 "Wallpaper animation!");
9944 switch (transit) {
9945 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9946 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9947 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9948 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9949 break;
9950 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9951 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9952 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9953 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9954 break;
9955 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009956 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009957 "New transit: " + transit);
9958 } else if (oldWallpaper != null) {
9959 // We are transitioning from an activity with
9960 // a wallpaper to one without.
9961 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009962 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009963 "New transit away from wallpaper: " + transit);
9964 } else if (mWallpaperTarget != null) {
9965 // We are transitioning from an activity without
9966 // a wallpaper to now showing the wallpaper
9967 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009968 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009969 "New transit into wallpaper: " + transit);
9970 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009971
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009972 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9973 mLastEnterAnimToken = animToken;
9974 mLastEnterAnimParams = animLp;
9975 } else if (mLastEnterAnimParams != null) {
9976 animLp = mLastEnterAnimParams;
9977 mLastEnterAnimToken = null;
9978 mLastEnterAnimParams = null;
9979 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009980
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009981 // If all closing windows are obscured, then there is
9982 // no need to do an animation. This is the case, for
9983 // example, when this transition is being done behind
9984 // the lock screen.
9985 if (!mPolicy.allowAppAnimationsLw()) {
9986 animLp = null;
9987 }
9988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009989 NN = mOpeningApps.size();
9990 for (i=0; i<NN; i++) {
9991 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009992 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009993 "Now opening app" + wtoken);
9994 wtoken.reportedVisible = false;
9995 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009996 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009997 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009998 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009999 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010000 wtoken.showAllWindowsLocked();
10001 }
10002 NN = mClosingApps.size();
10003 for (i=0; i<NN; i++) {
10004 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010005 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010006 "Now closing app" + wtoken);
10007 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010008 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010009 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010010 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010011 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010012 // Force the allDrawn flag, because we want to start
10013 // this guy's animations regardless of whether it's
10014 // gotten drawn.
10015 wtoken.allDrawn = true;
10016 }
10017
Dianne Hackborn8b571a82009-09-25 16:09:43 -070010018 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010019
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010020 mOpeningApps.clear();
10021 mClosingApps.clear();
10022
10023 // This has changed the visibility of windows, so perform
10024 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010025 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010026 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -070010027 if (!moveInputMethodWindowsIfNeededLocked(true)) {
10028 assignLayersLocked();
10029 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010030 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010031 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010032 }
10033 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010034
Dianne Hackborn16064f92010-03-25 00:47:24 -070010035 int adjResult = 0;
10036
Dianne Hackborna8f60182009-09-01 19:01:50 -070010037 if (!animating && mAppTransitionRunning) {
10038 // We have finished the animation of an app transition. To do
10039 // this, we have delayed a lot of operations like showing and
10040 // hiding apps, moving apps in Z-order, etc. The app token list
10041 // reflects the correct Z-order, but the window list may now
10042 // be out of sync with it. So here we will just rebuild the
10043 // entire app window list. Fun!
10044 mAppTransitionRunning = false;
10045 // Clear information about apps that were moving.
10046 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010047
Dianne Hackborna8f60182009-09-01 19:01:50 -070010048 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010049 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010050 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010051 moveInputMethodWindowsIfNeededLocked(false);
10052 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010053 // Since the window list has been rebuilt, focus might
10054 // have to be recomputed since the actual order of windows
10055 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010056 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010057 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010058
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010059 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010060 // At this point, there was a window with a wallpaper that
10061 // was force hiding other windows behind it, but now it
10062 // is going away. This may be simple -- just animate
10063 // away the wallpaper and its window -- or it may be
10064 // hard -- the wallpaper now needs to be shown behind
10065 // something that was hidden.
10066 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010067 if (mLowerWallpaperTarget != null
10068 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010069 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010070 "wallpaperForceHiding changed with lower="
10071 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010072 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010073 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10074 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10075 if (mLowerWallpaperTarget.mAppToken.hidden) {
10076 // The lower target has become hidden before we
10077 // actually started the animation... let's completely
10078 // re-evaluate everything.
10079 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010080 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010081 }
10082 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010083 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010084 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010085 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010086 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010087 + " NEW: " + mWallpaperTarget
10088 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010089 if (mLowerWallpaperTarget == null) {
10090 // Whoops, we don't need a special wallpaper animation.
10091 // Clear them out.
10092 forceHiding = false;
10093 for (i=N-1; i>=0; i--) {
10094 WindowState w = (WindowState)mWindows.get(i);
10095 if (w.mSurface != null) {
10096 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010097 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010098 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010099 forceHiding = true;
10100 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10101 if (!w.mAnimating) {
10102 // We set the animation above so it
10103 // is not yet running.
10104 w.clearAnimation();
10105 }
10106 }
10107 }
10108 }
10109 }
10110 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010111
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010112 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010113 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010114 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010115 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010116 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010117
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010118 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010119 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010120 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010121 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010122 assignLayersLocked();
10123 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010124 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010125 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010126 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010127 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010128
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010129 if (mFocusMayChange) {
10130 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010131 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010132 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010133 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010134 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010135 }
10136
10137 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010138 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010139 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010140
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010141 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10142 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010143
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010144 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010145
10146 // THIRD LOOP: Update the surfaces of all windows.
10147
10148 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10149
10150 boolean obscured = false;
10151 boolean blurring = false;
10152 boolean dimming = false;
10153 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010154 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010155 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010156
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010157 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010159 for (i=N-1; i>=0; i--) {
10160 WindowState w = (WindowState)mWindows.get(i);
10161
10162 boolean displayed = false;
10163 final WindowManager.LayoutParams attrs = w.mAttrs;
10164 final int attrFlags = attrs.flags;
10165
10166 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010167 // XXX NOTE: The logic here could be improved. We have
10168 // the decision about whether to resize a window separated
10169 // from whether to hide the surface. This can cause us to
10170 // resize a surface even if we are going to hide it. You
10171 // can see this by (1) holding device in landscape mode on
10172 // home screen; (2) tapping browser icon (device will rotate
10173 // to landscape; (3) tap home. The wallpaper will be resized
10174 // in step 2 but then immediately hidden, causing us to
10175 // have to resize and then redraw it again in step 3. It
10176 // would be nice to figure out how to avoid this, but it is
10177 // difficult because we do need to resize surfaces in some
10178 // cases while they are hidden such as when first showing a
10179 // window.
10180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010181 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010182 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010183 TAG, "Placing surface #" + i + " " + w.mSurface
10184 + ": new=" + w.mShownFrame + ", old="
10185 + w.mLastShownFrame);
10186
10187 boolean resize;
10188 int width, height;
10189 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
10190 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
10191 w.mLastRequestedHeight != w.mRequestedHeight;
10192 // for a scaled surface, we just want to use
10193 // the requested size.
10194 width = w.mRequestedWidth;
10195 height = w.mRequestedHeight;
10196 w.mLastRequestedWidth = width;
10197 w.mLastRequestedHeight = height;
10198 w.mLastShownFrame.set(w.mShownFrame);
10199 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010200 if (SHOW_TRANSACTIONS) logSurface(w,
10201 "POS " + w.mShownFrame.left
10202 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010203 w.mSurfaceX = w.mShownFrame.left;
10204 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010205 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10206 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010207 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010208 if (!recoveringMemory) {
10209 reclaimSomeSurfaceMemoryLocked(w, "position");
10210 }
10211 }
10212 } else {
10213 resize = !w.mLastShownFrame.equals(w.mShownFrame);
10214 width = w.mShownFrame.width();
10215 height = w.mShownFrame.height();
10216 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010217 }
10218
10219 if (resize) {
10220 if (width < 1) width = 1;
10221 if (height < 1) height = 1;
10222 if (w.mSurface != null) {
10223 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010224 if (SHOW_TRANSACTIONS) logSurface(w,
10225 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010226 + w.mShownFrame.top + " SIZE "
10227 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010228 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010229 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010230 w.mSurfaceW = width;
10231 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010232 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010233 w.mSurfaceX = w.mShownFrame.left;
10234 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010235 w.mSurface.setPosition(w.mShownFrame.left,
10236 w.mShownFrame.top);
10237 } catch (RuntimeException e) {
10238 // If something goes wrong with the surface (such
10239 // as running out of memory), don't take down the
10240 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010241 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010242 + "size=(" + width + "x" + height
10243 + "), pos=(" + w.mShownFrame.left
10244 + "," + w.mShownFrame.top + ")", e);
10245 if (!recoveringMemory) {
10246 reclaimSomeSurfaceMemoryLocked(w, "size");
10247 }
10248 }
10249 }
10250 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010251 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010252 w.mContentInsetsChanged =
10253 !w.mLastContentInsets.equals(w.mContentInsets);
10254 w.mVisibleInsetsChanged =
10255 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010256 boolean configChanged =
10257 w.mConfiguration != mCurConfiguration
10258 && (w.mConfiguration == null
10259 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010260 if (DEBUG_CONFIGURATION && configChanged) {
10261 Slog.v(TAG, "Win " + w + " config changed: "
10262 + mCurConfiguration);
10263 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010264 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010265 + ": configChanged=" + configChanged
10266 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -070010267 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010268 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010269 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010270 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010271 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010272 w.mLastFrame.set(w.mFrame);
10273 w.mLastContentInsets.set(w.mContentInsets);
10274 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010275 // If the screen is currently frozen, then keep
10276 // it frozen until this window draws at its new
10277 // orientation.
10278 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010279 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010280 "Resizing while display frozen: " + w);
10281 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010282 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010283 mWindowsFreezingScreen = true;
10284 // XXX should probably keep timeout from
10285 // when we first froze the display.
10286 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10287 mH.sendMessageDelayed(mH.obtainMessage(
10288 H.WINDOW_FREEZE_TIMEOUT), 2000);
10289 }
10290 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010291 // If the orientation is changing, then we need to
10292 // hold off on unfreezing the display until this
10293 // window has been redrawn; to do that, we need
10294 // to go through the process of getting informed
10295 // by the application when it has finished drawing.
10296 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010297 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010298 "Orientation start waiting for draw in "
10299 + w + ", surface " + w.mSurface);
10300 w.mDrawPending = true;
10301 w.mCommitDrawPending = false;
10302 w.mReadyToShow = false;
10303 if (w.mAppToken != null) {
10304 w.mAppToken.allDrawn = false;
10305 }
10306 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010307 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010308 "Resizing window " + w + " to " + w.mFrame);
10309 mResizingWindows.add(w);
10310 } else if (w.mOrientationChanging) {
10311 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010312 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010313 "Orientation not waiting for draw in "
10314 + w + ", surface " + w.mSurface);
10315 w.mOrientationChanging = false;
10316 }
10317 }
10318 }
10319
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010320 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010321 if (!w.mLastHidden) {
10322 //dump();
10323 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010324 if (SHOW_TRANSACTIONS) logSurface(w,
10325 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010326 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010327 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010328 try {
10329 w.mSurface.hide();
10330 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010331 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010332 }
10333 }
10334 mKeyWaiter.releasePendingPointerLocked(w.mSession);
10335 }
10336 // If we are waiting for this window to handle an
10337 // orientation change, well, it is hidden, so
10338 // doesn't really matter. Note that this does
10339 // introduce a potential glitch if the window
10340 // becomes unhidden before it has drawn for the
10341 // new orientation.
10342 if (w.mOrientationChanging) {
10343 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010344 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010345 "Orientation change skips hidden " + w);
10346 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010347 } else if (w.mLastLayer != w.mAnimLayer
10348 || w.mLastAlpha != w.mShownAlpha
10349 || w.mLastDsDx != w.mDsDx
10350 || w.mLastDtDx != w.mDtDx
10351 || w.mLastDsDy != w.mDsDy
10352 || w.mLastDtDy != w.mDtDy
10353 || w.mLastHScale != w.mHScale
10354 || w.mLastVScale != w.mVScale
10355 || w.mLastHidden) {
10356 displayed = true;
10357 w.mLastAlpha = w.mShownAlpha;
10358 w.mLastLayer = w.mAnimLayer;
10359 w.mLastDsDx = w.mDsDx;
10360 w.mLastDtDx = w.mDtDx;
10361 w.mLastDsDy = w.mDsDy;
10362 w.mLastDtDy = w.mDtDy;
10363 w.mLastHScale = w.mHScale;
10364 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010365 if (SHOW_TRANSACTIONS) logSurface(w,
10366 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010367 + " matrix=[" + (w.mDsDx*w.mHScale)
10368 + "," + (w.mDtDx*w.mVScale)
10369 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010370 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010371 if (w.mSurface != null) {
10372 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010373 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010374 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010375 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010376 w.mSurface.setLayer(w.mAnimLayer);
10377 w.mSurface.setMatrix(
10378 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10379 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10380 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010381 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010382 if (!recoveringMemory) {
10383 reclaimSomeSurfaceMemoryLocked(w, "update");
10384 }
10385 }
10386 }
10387
10388 if (w.mLastHidden && !w.mDrawPending
10389 && !w.mCommitDrawPending
10390 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010391 if (SHOW_TRANSACTIONS) logSurface(w,
10392 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010393 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010394 + " during relayout");
10395 if (showSurfaceRobustlyLocked(w)) {
10396 w.mHasDrawn = true;
10397 w.mLastHidden = false;
10398 } else {
10399 w.mOrientationChanging = false;
10400 }
10401 }
10402 if (w.mSurface != null) {
10403 w.mToken.hasVisible = true;
10404 }
10405 } else {
10406 displayed = true;
10407 }
10408
10409 if (displayed) {
10410 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010411 if (attrs.width == LayoutParams.MATCH_PARENT
10412 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010413 covered = true;
10414 }
10415 }
10416 if (w.mOrientationChanging) {
10417 if (w.mDrawPending || w.mCommitDrawPending) {
10418 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010419 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010420 "Orientation continue waiting for draw in " + w);
10421 } else {
10422 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010423 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010424 "Orientation change complete in " + w);
10425 }
10426 }
10427 w.mToken.hasVisible = true;
10428 }
10429 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010430 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010431 "Orientation change skips hidden " + w);
10432 w.mOrientationChanging = false;
10433 }
10434
10435 final boolean canBeSeen = w.isDisplayedLw();
10436
10437 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10438 focusDisplayed = true;
10439 }
10440
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010441 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010443 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010444 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010445 if (w.mSurface != null) {
10446 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10447 holdScreen = w.mSession;
10448 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010449 if (!syswin && w.mAttrs.screenBrightness >= 0
10450 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010451 screenBrightness = w.mAttrs.screenBrightness;
10452 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010453 if (!syswin && w.mAttrs.buttonBrightness >= 0
10454 && buttonBrightness < 0) {
10455 buttonBrightness = w.mAttrs.buttonBrightness;
10456 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010457 if (canBeSeen
10458 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10459 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10460 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010461 syswin = true;
10462 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010463 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010464
Dianne Hackborn25994b42009-09-04 14:21:19 -070010465 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10466 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010467 // This window completely covers everything behind it,
10468 // so we want to leave all of them as unblurred (for
10469 // performance reasons).
10470 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010471 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010472 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010473 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010474 obscured = true;
10475 if (mBackgroundFillerSurface == null) {
10476 try {
10477 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010478 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010479 0, dw, dh,
10480 PixelFormat.OPAQUE,
10481 Surface.FX_SURFACE_NORMAL);
10482 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010483 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010484 }
10485 }
10486 try {
10487 mBackgroundFillerSurface.setPosition(0, 0);
10488 mBackgroundFillerSurface.setSize(dw, dh);
10489 // Using the same layer as Dim because they will never be shown at the
10490 // same time.
10491 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10492 mBackgroundFillerSurface.show();
10493 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010494 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010495 }
10496 backgroundFillerShown = true;
10497 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010498 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010499 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010500 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010501 + ": blurring=" + blurring
10502 + " obscured=" + obscured
10503 + " displayed=" + displayed);
10504 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10505 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010506 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010507 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010508 if (mDimAnimator == null) {
10509 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010510 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010511 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010512 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010513 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010514 }
10515 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10516 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010517 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010518 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010519 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010520 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010521 + mBlurSurface + ": CREATE");
10522 try {
Romain Guy06882f82009-06-10 13:36:04 -070010523 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010524 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010525 -1, 16, 16,
10526 PixelFormat.OPAQUE,
10527 Surface.FX_SURFACE_BLUR);
10528 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010529 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010530 }
10531 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010532 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010533 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10534 + mBlurSurface + ": pos=(0,0) (" +
10535 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010536 mBlurSurface.setPosition(0, 0);
10537 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010538 mBlurSurface.setLayer(w.mAnimLayer-2);
10539 if (!mBlurShown) {
10540 try {
10541 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10542 + mBlurSurface + ": SHOW");
10543 mBlurSurface.show();
10544 } catch (RuntimeException e) {
10545 Slog.w(TAG, "Failure showing blur surface", e);
10546 }
10547 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010548 }
10549 }
10550 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010551 }
10552 }
10553 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010554
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010555 if (obscuredChanged && mWallpaperTarget == w) {
10556 // This is the wallpaper target and its obscured state
10557 // changed... make sure the current wallaper's visibility
10558 // has been updated accordingly.
10559 updateWallpaperVisibilityLocked();
10560 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010561 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010562
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010563 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10564 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010565 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010566 try {
10567 mBackgroundFillerSurface.hide();
10568 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010569 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010570 }
10571 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010572
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010573 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010574 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10575 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010576 }
Romain Guy06882f82009-06-10 13:36:04 -070010577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010578 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010579 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010580 + ": HIDE");
10581 try {
10582 mBlurSurface.hide();
10583 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010584 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010585 }
10586 mBlurShown = false;
10587 }
10588
Joe Onorato8a9b2202010-02-26 18:56:32 -080010589 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010590 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010591 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010592 }
10593
10594 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010595
Joe Onorato8a9b2202010-02-26 18:56:32 -080010596 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010597 "With display frozen, orientationChangeComplete="
10598 + orientationChangeComplete);
10599 if (orientationChangeComplete) {
10600 if (mWindowsFreezingScreen) {
10601 mWindowsFreezingScreen = false;
10602 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10603 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010604 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010605 }
Romain Guy06882f82009-06-10 13:36:04 -070010606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010607 i = mResizingWindows.size();
10608 if (i > 0) {
10609 do {
10610 i--;
10611 WindowState win = mResizingWindows.get(i);
10612 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010613 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10614 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010615 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010616 boolean configChanged =
10617 win.mConfiguration != mCurConfiguration
10618 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010619 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10620 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10621 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010622 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010623 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010624 + " / " + mCurConfiguration + " / 0x"
10625 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010626 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010627 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010628 win.mClient.resized(win.mFrame.width(),
10629 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010630 win.mLastVisibleInsets, win.mDrawPending,
10631 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010632 win.mContentInsetsChanged = false;
10633 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010634 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010635 } catch (RemoteException e) {
10636 win.mOrientationChanging = false;
10637 }
10638 } while (i > 0);
10639 mResizingWindows.clear();
10640 }
Romain Guy06882f82009-06-10 13:36:04 -070010641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010642 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010643 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010644 i = mDestroySurface.size();
10645 if (i > 0) {
10646 do {
10647 i--;
10648 WindowState win = mDestroySurface.get(i);
10649 win.mDestroying = false;
10650 if (mInputMethodWindow == win) {
10651 mInputMethodWindow = null;
10652 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010653 if (win == mWallpaperTarget) {
10654 wallpaperDestroyed = true;
10655 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010656 win.destroySurfaceLocked();
10657 } while (i > 0);
10658 mDestroySurface.clear();
10659 }
10660
10661 // Time to remove any exiting tokens?
10662 for (i=mExitingTokens.size()-1; i>=0; i--) {
10663 WindowToken token = mExitingTokens.get(i);
10664 if (!token.hasVisible) {
10665 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010666 if (token.windowType == TYPE_WALLPAPER) {
10667 mWallpaperTokens.remove(token);
10668 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010669 }
10670 }
10671
10672 // Time to remove any exiting applications?
10673 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10674 AppWindowToken token = mExitingAppTokens.get(i);
10675 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010676 // Make sure there is no animation running on this token,
10677 // so any windows associated with it will be removed as
10678 // soon as their animations are complete
10679 token.animation = null;
10680 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010681 mAppTokens.remove(token);
10682 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010683 if (mLastEnterAnimToken == token) {
10684 mLastEnterAnimToken = null;
10685 mLastEnterAnimParams = null;
10686 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010687 }
10688 }
10689
Dianne Hackborna8f60182009-09-01 19:01:50 -070010690 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010691
Dianne Hackborna8f60182009-09-01 19:01:50 -070010692 if (!animating && mAppTransitionRunning) {
10693 // We have finished the animation of an app transition. To do
10694 // this, we have delayed a lot of operations like showing and
10695 // hiding apps, moving apps in Z-order, etc. The app token list
10696 // reflects the correct Z-order, but the window list may now
10697 // be out of sync with it. So here we will just rebuild the
10698 // entire app window list. Fun!
10699 mAppTransitionRunning = false;
10700 needRelayout = true;
10701 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010702 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010703 // Clear information about apps that were moving.
10704 mToBottomApps.clear();
10705 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010707 if (focusDisplayed) {
10708 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10709 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010710 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010711 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010712 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010713 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010714 requestAnimationLocked(0);
10715 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010716 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10717 }
10718 mQueue.setHoldScreenLocked(holdScreen != null);
10719 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10720 mPowerManager.setScreenBrightnessOverride(-1);
10721 } else {
10722 mPowerManager.setScreenBrightnessOverride((int)
10723 (screenBrightness * Power.BRIGHTNESS_ON));
10724 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010725 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10726 mPowerManager.setButtonBrightnessOverride(-1);
10727 } else {
10728 mPowerManager.setButtonBrightnessOverride((int)
10729 (buttonBrightness * Power.BRIGHTNESS_ON));
10730 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010731 if (holdScreen != mHoldingScreenOn) {
10732 mHoldingScreenOn = holdScreen;
10733 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10734 mH.sendMessage(m);
10735 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010736
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010737 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010738 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010739 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10740 LocalPowerManager.BUTTON_EVENT, true);
10741 mTurnOnScreen = false;
10742 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010743
10744 // Check to see if we are now in a state where the screen should
10745 // be enabled, because the window obscured flags have changed.
10746 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010747 }
10748
10749 void requestAnimationLocked(long delay) {
10750 if (!mAnimationPending) {
10751 mAnimationPending = true;
10752 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10753 }
10754 }
Romain Guy06882f82009-06-10 13:36:04 -070010755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010756 /**
10757 * Have the surface flinger show a surface, robustly dealing with
10758 * error conditions. In particular, if there is not enough memory
10759 * to show the surface, then we will try to get rid of other surfaces
10760 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010761 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010762 * @return Returns true if the surface was successfully shown.
10763 */
10764 boolean showSurfaceRobustlyLocked(WindowState win) {
10765 try {
10766 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010767 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010768 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010769 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010770 if (DEBUG_VISIBILITY) Slog.v(TAG,
10771 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010772 win.mTurnOnScreen = false;
10773 mTurnOnScreen = true;
10774 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010775 }
10776 return true;
10777 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010778 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010779 }
Romain Guy06882f82009-06-10 13:36:04 -070010780
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010781 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010783 return false;
10784 }
Romain Guy06882f82009-06-10 13:36:04 -070010785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010786 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10787 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010788
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010789 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010790 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010792 if (mForceRemoves == null) {
10793 mForceRemoves = new ArrayList<WindowState>();
10794 }
Romain Guy06882f82009-06-10 13:36:04 -070010795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010796 long callingIdentity = Binder.clearCallingIdentity();
10797 try {
10798 // There was some problem... first, do a sanity check of the
10799 // window list to make sure we haven't left any dangling surfaces
10800 // around.
10801 int N = mWindows.size();
10802 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010803 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010804 for (int i=0; i<N; i++) {
10805 WindowState ws = (WindowState)mWindows.get(i);
10806 if (ws.mSurface != null) {
10807 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010808 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010809 + ws + " surface=" + ws.mSurface
10810 + " token=" + win.mToken
10811 + " pid=" + ws.mSession.mPid
10812 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010813 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010814 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010815 ws.mSurface = null;
10816 mForceRemoves.add(ws);
10817 i--;
10818 N--;
10819 leakedSurface = true;
10820 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010821 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010822 + ws + " surface=" + ws.mSurface
10823 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010824 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010825 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010826 ws.mSurface = null;
10827 leakedSurface = true;
10828 }
10829 }
10830 }
Romain Guy06882f82009-06-10 13:36:04 -070010831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010832 boolean killedApps = false;
10833 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010834 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010835 SparseIntArray pidCandidates = new SparseIntArray();
10836 for (int i=0; i<N; i++) {
10837 WindowState ws = (WindowState)mWindows.get(i);
10838 if (ws.mSurface != null) {
10839 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10840 }
10841 }
10842 if (pidCandidates.size() > 0) {
10843 int[] pids = new int[pidCandidates.size()];
10844 for (int i=0; i<pids.length; i++) {
10845 pids[i] = pidCandidates.keyAt(i);
10846 }
10847 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010848 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010849 killedApps = true;
10850 }
10851 } catch (RemoteException e) {
10852 }
10853 }
10854 }
Romain Guy06882f82009-06-10 13:36:04 -070010855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010856 if (leakedSurface || killedApps) {
10857 // We managed to reclaim some memory, so get rid of the trouble
10858 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010859 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010860 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010861 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010862 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010863 win.mSurface = null;
10864 }
Romain Guy06882f82009-06-10 13:36:04 -070010865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010866 try {
10867 win.mClient.dispatchGetNewSurface();
10868 } catch (RemoteException e) {
10869 }
10870 }
10871 } finally {
10872 Binder.restoreCallingIdentity(callingIdentity);
10873 }
10874 }
Romain Guy06882f82009-06-10 13:36:04 -070010875
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010876 private boolean updateFocusedWindowLocked(int mode) {
10877 WindowState newFocus = computeFocusedWindowLocked();
10878 if (mCurrentFocus != newFocus) {
10879 // This check makes sure that we don't already have the focus
10880 // change message pending.
10881 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10882 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010883 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010884 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10885 final WindowState oldFocus = mCurrentFocus;
10886 mCurrentFocus = newFocus;
10887 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010889 final WindowState imWindow = mInputMethodWindow;
10890 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010891 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010892 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010893 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10894 mLayoutNeeded = true;
10895 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010896 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10897 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010898 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10899 // Client will do the layout, but we need to assign layers
10900 // for handleNewWindowLocked() below.
10901 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010902 }
10903 }
Romain Guy06882f82009-06-10 13:36:04 -070010904
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010905 if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10906 mKeyWaiter.handleNewWindowLocked(newFocus);
10907 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010908 return true;
10909 }
10910 return false;
10911 }
10912
10913 private WindowState computeFocusedWindowLocked() {
10914 WindowState result = null;
10915 WindowState win;
10916
10917 int i = mWindows.size() - 1;
10918 int nextAppIndex = mAppTokens.size()-1;
10919 WindowToken nextApp = nextAppIndex >= 0
10920 ? mAppTokens.get(nextAppIndex) : null;
10921
10922 while (i >= 0) {
10923 win = (WindowState)mWindows.get(i);
10924
Joe Onorato8a9b2202010-02-26 18:56:32 -080010925 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010926 TAG, "Looking for focus: " + i
10927 + " = " + win
10928 + ", flags=" + win.mAttrs.flags
10929 + ", canReceive=" + win.canReceiveKeys());
10930
10931 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010933 // If this window's application has been removed, just skip it.
10934 if (thisApp != null && thisApp.removed) {
10935 i--;
10936 continue;
10937 }
Romain Guy06882f82009-06-10 13:36:04 -070010938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010939 // If there is a focused app, don't allow focus to go to any
10940 // windows below it. If this is an application window, step
10941 // through the app tokens until we find its app.
10942 if (thisApp != null && nextApp != null && thisApp != nextApp
10943 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10944 int origAppIndex = nextAppIndex;
10945 while (nextAppIndex > 0) {
10946 if (nextApp == mFocusedApp) {
10947 // Whoops, we are below the focused app... no focus
10948 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010949 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010950 TAG, "Reached focused app: " + mFocusedApp);
10951 return null;
10952 }
10953 nextAppIndex--;
10954 nextApp = mAppTokens.get(nextAppIndex);
10955 if (nextApp == thisApp) {
10956 break;
10957 }
10958 }
10959 if (thisApp != nextApp) {
10960 // Uh oh, the app token doesn't exist! This shouldn't
10961 // happen, but if it does we can get totally hosed...
10962 // so restart at the original app.
10963 nextAppIndex = origAppIndex;
10964 nextApp = mAppTokens.get(nextAppIndex);
10965 }
10966 }
10967
10968 // Dispatch to this window if it is wants key events.
10969 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010970 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010971 TAG, "Found focus @ " + i + " = " + win);
10972 result = win;
10973 break;
10974 }
10975
10976 i--;
10977 }
10978
10979 return result;
10980 }
10981
10982 private void startFreezingDisplayLocked() {
10983 if (mDisplayFrozen) {
Chris Tate2ad63a92009-03-25 17:36:48 -070010984 // Freezing the display also suspends key event delivery, to
10985 // keep events from going astray while the display is reconfigured.
10986 // If someone has changed orientation again while the screen is
10987 // still frozen, the events will continue to be blocked while the
10988 // successive orientation change is processed. To prevent spurious
10989 // ANRs, we reset the event dispatch timeout in this case.
10990 synchronized (mKeyWaiter) {
10991 mKeyWaiter.mWasFrozen = true;
10992 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010993 return;
10994 }
Romain Guy06882f82009-06-10 13:36:04 -070010995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010996 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010998 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010999 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011000 if (mFreezeGcPending != 0) {
11001 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011002 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011003 mH.removeMessages(H.FORCE_GC);
11004 Runtime.getRuntime().gc();
11005 mFreezeGcPending = now;
11006 }
11007 } else {
11008 mFreezeGcPending = now;
11009 }
Romain Guy06882f82009-06-10 13:36:04 -070011010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011011 mDisplayFrozen = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070011012 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
11013 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011014 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011015 mAppTransitionReady = true;
11016 }
Romain Guy06882f82009-06-10 13:36:04 -070011017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011018 if (PROFILE_ORIENTATION) {
11019 File file = new File("/data/system/frozen");
11020 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
11021 }
11022 Surface.freezeDisplay(0);
11023 }
Romain Guy06882f82009-06-10 13:36:04 -070011024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011025 private void stopFreezingDisplayLocked() {
11026 if (!mDisplayFrozen) {
11027 return;
11028 }
Romain Guy06882f82009-06-10 13:36:04 -070011029
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011030 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
11031 return;
11032 }
11033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011034 mDisplayFrozen = false;
11035 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
11036 if (PROFILE_ORIENTATION) {
11037 Debug.stopMethodTracing();
11038 }
11039 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070011040
Chris Tate2ad63a92009-03-25 17:36:48 -070011041 // Reset the key delivery timeout on unfreeze, too. We force a wakeup here
11042 // too because regular key delivery processing should resume immediately.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011043 synchronized (mKeyWaiter) {
11044 mKeyWaiter.mWasFrozen = true;
11045 mKeyWaiter.notifyAll();
11046 }
11047
Christopher Tateb696aee2010-04-02 19:08:30 -070011048 // While the display is frozen we don't re-compute the orientation
11049 // to avoid inconsistent states. However, something interesting
11050 // could have actually changed during that time so re-evaluate it
11051 // now to catch that.
11052 if (updateOrientationFromAppTokensLocked()) {
11053 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
11054 }
11055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011056 // A little kludge: a lot could have happened while the
11057 // display was frozen, so now that we are coming back we
11058 // do a gc so that any remote references the system
11059 // processes holds on others can be released if they are
11060 // no longer needed.
11061 mH.removeMessages(H.FORCE_GC);
11062 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11063 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011065 mScreenFrozenLock.release();
11066 }
Romain Guy06882f82009-06-10 13:36:04 -070011067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011068 @Override
11069 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11070 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11071 != PackageManager.PERMISSION_GRANTED) {
11072 pw.println("Permission Denial: can't dump WindowManager from from pid="
11073 + Binder.getCallingPid()
11074 + ", uid=" + Binder.getCallingUid());
11075 return;
11076 }
Romain Guy06882f82009-06-10 13:36:04 -070011077
Dianne Hackborna2e92262010-03-02 17:19:29 -080011078 pw.println("Input State:");
11079 mQueue.dump(pw, " ");
11080 pw.println(" ");
11081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011082 synchronized(mWindowMap) {
11083 pw.println("Current Window Manager state:");
11084 for (int i=mWindows.size()-1; i>=0; i--) {
11085 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011086 pw.print(" Window #"); pw.print(i); pw.print(' ');
11087 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011088 w.dump(pw, " ");
11089 }
11090 if (mInputMethodDialogs.size() > 0) {
11091 pw.println(" ");
11092 pw.println(" Input method dialogs:");
11093 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11094 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011095 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011096 }
11097 }
11098 if (mPendingRemove.size() > 0) {
11099 pw.println(" ");
11100 pw.println(" Remove pending for:");
11101 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11102 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011103 pw.print(" Remove #"); 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 (mForceRemoves != null && mForceRemoves.size() > 0) {
11109 pw.println(" ");
11110 pw.println(" Windows force removing:");
11111 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11112 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011113 pw.print(" Removing #"); 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 (mDestroySurface.size() > 0) {
11119 pw.println(" ");
11120 pw.println(" Windows waiting to destroy their surface:");
11121 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11122 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011123 pw.print(" Destroy #"); 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 }
11128 if (mLosingFocus.size() > 0) {
11129 pw.println(" ");
11130 pw.println(" Windows losing focus:");
11131 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11132 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011133 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11134 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011135 w.dump(pw, " ");
11136 }
11137 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011138 if (mResizingWindows.size() > 0) {
11139 pw.println(" ");
11140 pw.println(" Windows waiting to resize:");
11141 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11142 WindowState w = mResizingWindows.get(i);
11143 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11144 pw.print(w); pw.println(":");
11145 w.dump(pw, " ");
11146 }
11147 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011148 if (mSessions.size() > 0) {
11149 pw.println(" ");
11150 pw.println(" All active sessions:");
11151 Iterator<Session> it = mSessions.iterator();
11152 while (it.hasNext()) {
11153 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011154 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011155 s.dump(pw, " ");
11156 }
11157 }
11158 if (mTokenMap.size() > 0) {
11159 pw.println(" ");
11160 pw.println(" All tokens:");
11161 Iterator<WindowToken> it = mTokenMap.values().iterator();
11162 while (it.hasNext()) {
11163 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011164 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011165 token.dump(pw, " ");
11166 }
11167 }
11168 if (mTokenList.size() > 0) {
11169 pw.println(" ");
11170 pw.println(" Window token list:");
11171 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011172 pw.print(" #"); pw.print(i); pw.print(": ");
11173 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011174 }
11175 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011176 if (mWallpaperTokens.size() > 0) {
11177 pw.println(" ");
11178 pw.println(" Wallpaper tokens:");
11179 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11180 WindowToken token = mWallpaperTokens.get(i);
11181 pw.print(" Wallpaper #"); pw.print(i);
11182 pw.print(' '); pw.print(token); pw.println(':');
11183 token.dump(pw, " ");
11184 }
11185 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011186 if (mAppTokens.size() > 0) {
11187 pw.println(" ");
11188 pw.println(" Application tokens in Z order:");
11189 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011190 pw.print(" App #"); pw.print(i); pw.print(": ");
11191 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011192 }
11193 }
11194 if (mFinishedStarting.size() > 0) {
11195 pw.println(" ");
11196 pw.println(" Finishing start of application tokens:");
11197 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11198 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011199 pw.print(" Finished Starting #"); 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 (mExitingTokens.size() > 0) {
11205 pw.println(" ");
11206 pw.println(" Exiting tokens:");
11207 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11208 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011209 pw.print(" Exiting #"); 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 if (mExitingAppTokens.size() > 0) {
11215 pw.println(" ");
11216 pw.println(" Exiting application tokens:");
11217 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11218 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011219 pw.print(" Exiting App #"); pw.print(i);
11220 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011221 token.dump(pw, " ");
11222 }
11223 }
11224 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011225 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11226 pw.print(" mLastFocus="); pw.println(mLastFocus);
11227 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11228 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11229 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011230 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011231 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11232 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11233 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11234 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011235 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11236 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11237 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011238 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11239 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11240 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11241 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011242 if (mDimAnimator != null) {
11243 mDimAnimator.printTo(pw);
11244 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011245 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011246 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011247 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011248 pw.print(mInputMethodAnimLayerAdjustment);
11249 pw.print(" mWallpaperAnimLayerAdjustment=");
11250 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011251 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11252 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011253 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11254 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011255 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11256 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011257 pw.print(" mRotation="); pw.print(mRotation);
11258 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11259 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11260 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11261 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11262 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11263 pw.print(" mNextAppTransition=0x");
11264 pw.print(Integer.toHexString(mNextAppTransition));
11265 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011266 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011267 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011268 if (mNextAppTransitionPackage != null) {
11269 pw.print(" mNextAppTransitionPackage=");
11270 pw.print(mNextAppTransitionPackage);
11271 pw.print(", mNextAppTransitionEnter=0x");
11272 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11273 pw.print(", mNextAppTransitionExit=0x");
11274 pw.print(Integer.toHexString(mNextAppTransitionExit));
11275 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011276 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11277 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011278 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11279 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11280 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11281 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011282 if (mOpeningApps.size() > 0) {
11283 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11284 }
11285 if (mClosingApps.size() > 0) {
11286 pw.print(" mClosingApps="); pw.println(mClosingApps);
11287 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011288 if (mToTopApps.size() > 0) {
11289 pw.print(" mToTopApps="); pw.println(mToTopApps);
11290 }
11291 if (mToBottomApps.size() > 0) {
11292 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11293 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011294 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11295 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011296 pw.println(" KeyWaiter state:");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011297 pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin);
11298 pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder);
11299 pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished);
11300 pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow);
11301 pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching);
11302 pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011303 }
11304 }
11305
11306 public void monitor() {
11307 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011308 synchronized (mKeyguardTokenWatcher) { }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011309 synchronized (mKeyWaiter) { }
11310 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011311
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011312 public void virtualKeyFeedback(KeyEvent event) {
11313 mPolicy.keyFeedbackFromInput(event);
11314 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011315
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011316 /**
11317 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011318 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011319 */
11320 private static class DimAnimator {
11321 Surface mDimSurface;
11322 boolean mDimShown = false;
11323 float mDimCurrentAlpha;
11324 float mDimTargetAlpha;
11325 float mDimDeltaPerMs;
11326 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011327
11328 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011329
11330 DimAnimator (SurfaceSession session) {
11331 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011332 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011333 + mDimSurface + ": CREATE");
11334 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011335 mDimSurface = new Surface(session, 0,
11336 "DimSurface",
11337 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011338 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011339 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011340 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011341 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011342 }
11343 }
11344 }
11345
11346 /**
11347 * Show the dim surface.
11348 */
11349 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011350 if (!mDimShown) {
11351 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11352 dw + "x" + dh + ")");
11353 mDimShown = true;
11354 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011355 mLastDimWidth = dw;
11356 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011357 mDimSurface.setPosition(0, 0);
11358 mDimSurface.setSize(dw, dh);
11359 mDimSurface.show();
11360 } catch (RuntimeException e) {
11361 Slog.w(TAG, "Failure showing dim surface", e);
11362 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011363 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11364 mLastDimWidth = dw;
11365 mLastDimHeight = dh;
11366 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011367 }
11368 }
11369
11370 /**
11371 * Set's the dim surface's layer and update dim parameters that will be used in
11372 * {@link updateSurface} after all windows are examined.
11373 */
11374 void updateParameters(WindowState w, long currentTime) {
11375 mDimSurface.setLayer(w.mAnimLayer-1);
11376
11377 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011378 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011379 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011380 if (mDimTargetAlpha != target) {
11381 // If the desired dim level has changed, then
11382 // start an animation to it.
11383 mLastDimAnimTime = currentTime;
11384 long duration = (w.mAnimating && w.mAnimation != null)
11385 ? w.mAnimation.computeDurationHint()
11386 : DEFAULT_DIM_DURATION;
11387 if (target > mDimTargetAlpha) {
11388 // This is happening behind the activity UI,
11389 // so we can make it run a little longer to
11390 // give a stronger impression without disrupting
11391 // the user.
11392 duration *= DIM_DURATION_MULTIPLIER;
11393 }
11394 if (duration < 1) {
11395 // Don't divide by zero
11396 duration = 1;
11397 }
11398 mDimTargetAlpha = target;
11399 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11400 }
11401 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011402
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011403 /**
11404 * Updating the surface's alpha. Returns true if the animation continues, or returns
11405 * false when the animation is finished and the dim surface is hidden.
11406 */
11407 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11408 if (!dimming) {
11409 if (mDimTargetAlpha != 0) {
11410 mLastDimAnimTime = currentTime;
11411 mDimTargetAlpha = 0;
11412 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11413 }
11414 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011415
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011416 boolean animating = false;
11417 if (mLastDimAnimTime != 0) {
11418 mDimCurrentAlpha += mDimDeltaPerMs
11419 * (currentTime-mLastDimAnimTime);
11420 boolean more = true;
11421 if (displayFrozen) {
11422 // If the display is frozen, there is no reason to animate.
11423 more = false;
11424 } else if (mDimDeltaPerMs > 0) {
11425 if (mDimCurrentAlpha > mDimTargetAlpha) {
11426 more = false;
11427 }
11428 } else if (mDimDeltaPerMs < 0) {
11429 if (mDimCurrentAlpha < mDimTargetAlpha) {
11430 more = false;
11431 }
11432 } else {
11433 more = false;
11434 }
11435
11436 // Do we need to continue animating?
11437 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011438 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011439 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11440 mLastDimAnimTime = currentTime;
11441 mDimSurface.setAlpha(mDimCurrentAlpha);
11442 animating = true;
11443 } else {
11444 mDimCurrentAlpha = mDimTargetAlpha;
11445 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011446 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011447 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11448 mDimSurface.setAlpha(mDimCurrentAlpha);
11449 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011450 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011451 + ": HIDE");
11452 try {
11453 mDimSurface.hide();
11454 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011455 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011456 }
11457 mDimShown = false;
11458 }
11459 }
11460 }
11461 return animating;
11462 }
11463
11464 public void printTo(PrintWriter pw) {
11465 pw.print(" mDimShown="); pw.print(mDimShown);
11466 pw.print(" current="); pw.print(mDimCurrentAlpha);
11467 pw.print(" target="); pw.print(mDimTargetAlpha);
11468 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11469 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11470 }
11471 }
11472
11473 /**
11474 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11475 * This is used for opening/closing transition for apps in compatible mode.
11476 */
11477 private static class FadeInOutAnimation extends Animation {
11478 int mWidth;
11479 boolean mFadeIn;
11480
11481 public FadeInOutAnimation(boolean fadeIn) {
11482 setInterpolator(new AccelerateInterpolator());
11483 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11484 mFadeIn = fadeIn;
11485 }
11486
11487 @Override
11488 protected void applyTransformation(float interpolatedTime, Transformation t) {
11489 float x = interpolatedTime;
11490 if (!mFadeIn) {
11491 x = 1.0f - x; // reverse the interpolation for fade out
11492 }
11493 if (x < 0.5) {
11494 // move the window out of the screen.
11495 t.getMatrix().setTranslate(mWidth, 0);
11496 } else {
11497 t.getMatrix().setTranslate(0, 0);// show
11498 t.setAlpha((x - 0.5f) * 2);
11499 }
11500 }
11501
11502 @Override
11503 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11504 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11505 mWidth = width;
11506 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011507
11508 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011509 public int getZAdjustment() {
11510 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011511 }
11512 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011513}