blob: 0e4b38d6d58485c6499eeb627f6fde036d92b27f [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;
370 int mRotation = 0;
371 int mRequestedRotation = 0;
372 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700373 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 ArrayList<IRotationWatcher> mRotationWatchers
375 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 boolean mLayoutNeeded = true;
378 boolean mAnimationPending = false;
379 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800380 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 boolean mWindowsFreezingScreen = false;
382 long mFreezeGcPending = 0;
383 int mAppsFreezingScreen = 0;
384
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800385 int mLayoutSeq = 0;
386
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800387 // State while inside of layoutAndPlaceSurfacesLocked().
388 boolean mFocusMayChange;
389
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800390 Configuration mCurConfiguration = new Configuration();
391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 // This is held as long as we have the screen frozen, to give us time to
393 // perform a rotation animation when turning off shows the lock screen which
394 // changes the orientation.
395 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800397 // State management of app transitions. When we are preparing for a
398 // transition, mNextAppTransition will be the kind of transition to
399 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
400 // mOpeningApps and mClosingApps are the lists of tokens that will be
401 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700402 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700403 String mNextAppTransitionPackage;
404 int mNextAppTransitionEnter;
405 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700407 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800408 boolean mAppTransitionTimeout = false;
409 boolean mStartingIconInTransition = false;
410 boolean mSkipAppTransitionAnimation = false;
411 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
412 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700413 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
414 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416 //flag to detect fat touch events
417 boolean mFatTouch = false;
418 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 H mH = new H();
421
422 WindowState mCurrentFocus = null;
423 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 // This just indicates the window the input method is on top of, not
426 // necessarily the window its input is going to.
427 WindowState mInputMethodTarget = null;
428 WindowState mUpcomingInputMethodTarget = null;
429 boolean mInputMethodTargetWaitingAnim;
430 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 WindowState mInputMethodWindow = null;
433 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
434
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700435 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800436
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700437 // If non-null, this is the currently visible window that is associated
438 // with the wallpaper.
439 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700440 // If non-null, we are in the middle of animating from one wallpaper target
441 // to another, and this is the lower one in Z-order.
442 WindowState mLowerWallpaperTarget = null;
443 // If non-null, we are in the middle of animating from one wallpaper target
444 // to another, and this is the higher one in Z-order.
445 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700446 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700447 float mLastWallpaperX = -1;
448 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800449 float mLastWallpaperXStep = -1;
450 float mLastWallpaperYStep = -1;
Dianne Hackborn6adba242009-11-10 11:10:09 -0800451 boolean mSendingPointersToWallpaper = false;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700452 // This is set when we are waiting for a wallpaper to tell us it is done
453 // changing its scroll position.
454 WindowState mWaitingOnWallpaper;
455 // The last time we had a timeout when waiting for a wallpaper.
456 long mLastWallpaperTimeoutTime;
457 // We give a wallpaper up to 150ms to finish scrolling.
458 static final long WALLPAPER_TIMEOUT = 150;
459 // Time we wait after a timeout before trying to wait again.
460 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 AppWindowToken mFocusedApp = null;
463
464 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466 float mWindowAnimationScale = 1.0f;
467 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469 final KeyWaiter mKeyWaiter = new KeyWaiter();
470 final KeyQ mQueue;
471 final InputDispatcherThread mInputThread;
472
473 // Who is holding the screen on.
474 Session mHoldingScreenOn;
Romain Guy06882f82009-06-10 13:36:04 -0700475
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700476 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478 /**
479 * Whether the UI is currently running in touch mode (not showing
480 * navigational focus because the user is directly pressing the screen).
481 */
482 boolean mInTouchMode = false;
483
484 private ViewServer mViewServer;
485
486 final Rect mTempRect = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -0700487
Dianne Hackbornc485a602009-03-24 22:39:49 -0700488 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700489 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700490
491 // The frame use to limit the size of the app running in compatibility mode.
492 Rect mCompatibleScreenFrame = new Rect();
493 // The surface used to fill the outer rim of the app running in compatibility mode.
494 Surface mBackgroundFillerSurface = null;
495 boolean mBackgroundFillerShown = false;
496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 public static WindowManagerService main(Context context,
498 PowerManagerService pm, boolean haveInputMethods) {
499 WMThread thr = new WMThread(context, pm, haveInputMethods);
500 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 synchronized (thr) {
503 while (thr.mService == null) {
504 try {
505 thr.wait();
506 } catch (InterruptedException e) {
507 }
508 }
509 }
Romain Guy06882f82009-06-10 13:36:04 -0700510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 return thr.mService;
512 }
Romain Guy06882f82009-06-10 13:36:04 -0700513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 static class WMThread extends Thread {
515 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 private final Context mContext;
518 private final PowerManagerService mPM;
519 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800521 public WMThread(Context context, PowerManagerService pm,
522 boolean haveInputMethods) {
523 super("WindowManager");
524 mContext = context;
525 mPM = pm;
526 mHaveInputMethods = haveInputMethods;
527 }
Romain Guy06882f82009-06-10 13:36:04 -0700528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 public void run() {
530 Looper.prepare();
531 WindowManagerService s = new WindowManagerService(mContext, mPM,
532 mHaveInputMethods);
533 android.os.Process.setThreadPriority(
534 android.os.Process.THREAD_PRIORITY_DISPLAY);
Romain Guy06882f82009-06-10 13:36:04 -0700535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 synchronized (this) {
537 mService = s;
538 notifyAll();
539 }
Romain Guy06882f82009-06-10 13:36:04 -0700540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 Looper.loop();
542 }
543 }
544
545 static class PolicyThread extends Thread {
546 private final WindowManagerPolicy mPolicy;
547 private final WindowManagerService mService;
548 private final Context mContext;
549 private final PowerManagerService mPM;
550 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552 public PolicyThread(WindowManagerPolicy policy,
553 WindowManagerService service, Context context,
554 PowerManagerService pm) {
555 super("WindowManagerPolicy");
556 mPolicy = policy;
557 mService = service;
558 mContext = context;
559 mPM = pm;
560 }
Romain Guy06882f82009-06-10 13:36:04 -0700561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 public void run() {
563 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800564 WindowManagerPolicyThread.set(this, Looper.myLooper());
565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800567 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 android.os.Process.setThreadPriority(
569 android.os.Process.THREAD_PRIORITY_FOREGROUND);
570 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 synchronized (this) {
573 mRunning = true;
574 notifyAll();
575 }
Romain Guy06882f82009-06-10 13:36:04 -0700576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 Looper.loop();
578 }
579 }
580
581 private WindowManagerService(Context context, PowerManagerService pm,
582 boolean haveInputMethods) {
Michael Chan53071d62009-05-13 17:29:48 -0700583 if (MEASURE_LATENCY) {
584 lt = new LatencyTimer(100, 1000);
585 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 mContext = context;
588 mHaveInputMethods = haveInputMethods;
589 mLimitedAlphaCompositing = context.getResources().getBoolean(
590 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 mPowerManager = pm;
593 mPowerManager.setPolicy(mPolicy);
594 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
595 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
596 "SCREEN_FROZEN");
597 mScreenFrozenLock.setReferenceCounted(false);
598
599 mActivityManager = ActivityManagerNative.getDefault();
600 mBatteryStats = BatteryStatsService.getService();
601
602 // Get persisted window scale setting
603 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
604 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
605 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
606 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700607
Michael Chan9f028e62009-08-04 17:37:46 -0700608 int max_events_per_sec = 35;
609 try {
610 max_events_per_sec = Integer.parseInt(SystemProperties
611 .get("windowsmgr.max_events_per_sec"));
612 if (max_events_per_sec < 1) {
613 max_events_per_sec = 35;
614 }
615 } catch (NumberFormatException e) {
616 }
617 mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec;
618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800619 mQueue = new KeyQ();
620
621 mInputThread = new InputDispatcherThread();
Romain Guy06882f82009-06-10 13:36:04 -0700622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
624 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 synchronized (thr) {
627 while (!thr.mRunning) {
628 try {
629 thr.wait();
630 } catch (InterruptedException e) {
631 }
632 }
633 }
Romain Guy06882f82009-06-10 13:36:04 -0700634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 mInputThread.start();
Romain Guy06882f82009-06-10 13:36:04 -0700636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637 // Add ourself to the Watchdog monitors.
638 Watchdog.getInstance().addMonitor(this);
639 }
640
641 @Override
642 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
643 throws RemoteException {
644 try {
645 return super.onTransact(code, data, reply, flags);
646 } catch (RuntimeException e) {
647 // The window manager only throws security exceptions, so let's
648 // log all others.
649 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800650 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651 }
652 throw e;
653 }
654 }
655
656 private void placeWindowAfter(Object pos, WindowState window) {
657 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800658 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659 TAG, "Adding window " + window + " at "
660 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
661 mWindows.add(i+1, window);
662 }
663
664 private void placeWindowBefore(Object pos, WindowState window) {
665 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800666 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 TAG, "Adding window " + window + " at "
668 + i + " of " + mWindows.size() + " (before " + pos + ")");
669 mWindows.add(i, window);
670 }
671
672 //This method finds out the index of a window that has the same app token as
673 //win. used for z ordering the windows in mWindows
674 private int findIdxBasedOnAppTokens(WindowState win) {
675 //use a local variable to cache mWindows
676 ArrayList localmWindows = mWindows;
677 int jmax = localmWindows.size();
678 if(jmax == 0) {
679 return -1;
680 }
681 for(int j = (jmax-1); j >= 0; j--) {
682 WindowState wentry = (WindowState)localmWindows.get(j);
683 if(wentry.mAppToken == win.mAppToken) {
684 return j;
685 }
686 }
687 return -1;
688 }
Romain Guy06882f82009-06-10 13:36:04 -0700689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800690 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
691 final IWindow client = win.mClient;
692 final WindowToken token = win.mToken;
693 final ArrayList localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800695 final int N = localmWindows.size();
696 final WindowState attached = win.mAttachedWindow;
697 int i;
698 if (attached == null) {
699 int tokenWindowsPos = token.windows.size();
700 if (token.appWindowToken != null) {
701 int index = tokenWindowsPos-1;
702 if (index >= 0) {
703 // If this application has existing windows, we
704 // simply place the new window on top of them... but
705 // keep the starting window on top.
706 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
707 // Base windows go behind everything else.
708 placeWindowBefore(token.windows.get(0), win);
709 tokenWindowsPos = 0;
710 } else {
711 AppWindowToken atoken = win.mAppToken;
712 if (atoken != null &&
713 token.windows.get(index) == atoken.startingWindow) {
714 placeWindowBefore(token.windows.get(index), win);
715 tokenWindowsPos--;
716 } else {
717 int newIdx = findIdxBasedOnAppTokens(win);
718 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700719 //there is a window above this one associated with the same
720 //apptoken note that the window could be a floating window
721 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800723 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700724 TAG, "Adding window " + win + " at "
725 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800726 localmWindows.add(newIdx+1, win);
Romain Guy06882f82009-06-10 13:36:04 -0700727 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800728 }
729 }
730 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800731 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732 TAG, "Figuring out where to add app window "
733 + client.asBinder() + " (token=" + token + ")");
734 // Figure out where the window should go, based on the
735 // order of applications.
736 final int NA = mAppTokens.size();
737 Object pos = null;
738 for (i=NA-1; i>=0; i--) {
739 AppWindowToken t = mAppTokens.get(i);
740 if (t == token) {
741 i--;
742 break;
743 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800744
Dianne Hackborna8f60182009-09-01 19:01:50 -0700745 // We haven't reached the token yet; if this token
746 // is not going to the bottom and has windows, we can
747 // use it as an anchor for when we do reach the token.
748 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800749 pos = t.windows.get(0);
750 }
751 }
752 // We now know the index into the apps. If we found
753 // an app window above, that gives us the position; else
754 // we need to look some more.
755 if (pos != null) {
756 // Move behind any windows attached to this one.
Romain Guy06882f82009-06-10 13:36:04 -0700757 WindowToken atoken =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800758 mTokenMap.get(((WindowState)pos).mClient.asBinder());
759 if (atoken != null) {
760 final int NC = atoken.windows.size();
761 if (NC > 0) {
762 WindowState bottom = atoken.windows.get(0);
763 if (bottom.mSubLayer < 0) {
764 pos = bottom;
765 }
766 }
767 }
768 placeWindowBefore(pos, win);
769 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700770 // Continue looking down until we find the first
771 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800772 while (i >= 0) {
773 AppWindowToken t = mAppTokens.get(i);
774 final int NW = t.windows.size();
775 if (NW > 0) {
776 pos = t.windows.get(NW-1);
777 break;
778 }
779 i--;
780 }
781 if (pos != null) {
782 // Move in front of any windows attached to this
783 // one.
784 WindowToken atoken =
785 mTokenMap.get(((WindowState)pos).mClient.asBinder());
786 if (atoken != null) {
787 final int NC = atoken.windows.size();
788 if (NC > 0) {
789 WindowState top = atoken.windows.get(NC-1);
790 if (top.mSubLayer >= 0) {
791 pos = top;
792 }
793 }
794 }
795 placeWindowAfter(pos, win);
796 } else {
797 // Just search for the start of this layer.
798 final int myLayer = win.mBaseLayer;
799 for (i=0; i<N; i++) {
800 WindowState w = (WindowState)localmWindows.get(i);
801 if (w.mBaseLayer > myLayer) {
802 break;
803 }
804 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800805 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700806 TAG, "Adding window " + win + " at "
807 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800808 localmWindows.add(i, win);
809 }
810 }
811 }
812 } else {
813 // Figure out where window should go, based on layer.
814 final int myLayer = win.mBaseLayer;
815 for (i=N-1; i>=0; i--) {
816 if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) {
817 i++;
818 break;
819 }
820 }
821 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800822 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700823 TAG, "Adding window " + win + " at "
824 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800825 localmWindows.add(i, win);
826 }
827 if (addToToken) {
828 token.windows.add(tokenWindowsPos, win);
829 }
830
831 } else {
832 // Figure out this window's ordering relative to the window
833 // it is attached to.
834 final int NA = token.windows.size();
835 final int sublayer = win.mSubLayer;
836 int largestSublayer = Integer.MIN_VALUE;
837 WindowState windowWithLargestSublayer = null;
838 for (i=0; i<NA; i++) {
839 WindowState w = token.windows.get(i);
840 final int wSublayer = w.mSubLayer;
841 if (wSublayer >= largestSublayer) {
842 largestSublayer = wSublayer;
843 windowWithLargestSublayer = w;
844 }
845 if (sublayer < 0) {
846 // For negative sublayers, we go below all windows
847 // in the same sublayer.
848 if (wSublayer >= sublayer) {
849 if (addToToken) {
850 token.windows.add(i, win);
851 }
852 placeWindowBefore(
853 wSublayer >= 0 ? attached : w, win);
854 break;
855 }
856 } else {
857 // For positive sublayers, we go above all windows
858 // in the same sublayer.
859 if (wSublayer > sublayer) {
860 if (addToToken) {
861 token.windows.add(i, win);
862 }
863 placeWindowBefore(w, win);
864 break;
865 }
866 }
867 }
868 if (i >= NA) {
869 if (addToToken) {
870 token.windows.add(win);
871 }
872 if (sublayer < 0) {
873 placeWindowBefore(attached, win);
874 } else {
875 placeWindowAfter(largestSublayer >= 0
876 ? windowWithLargestSublayer
877 : attached,
878 win);
879 }
880 }
881 }
Romain Guy06882f82009-06-10 13:36:04 -0700882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 if (win.mAppToken != null && addToToken) {
884 win.mAppToken.allAppWindows.add(win);
885 }
886 }
Romain Guy06882f82009-06-10 13:36:04 -0700887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800888 static boolean canBeImeTarget(WindowState w) {
889 final int fl = w.mAttrs.flags
890 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
891 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
892 return w.isVisibleOrAdding();
893 }
894 return false;
895 }
Romain Guy06882f82009-06-10 13:36:04 -0700896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
898 final ArrayList localmWindows = mWindows;
899 final int N = localmWindows.size();
900 WindowState w = null;
901 int i = N;
902 while (i > 0) {
903 i--;
904 w = (WindowState)localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700905
Joe Onorato8a9b2202010-02-26 18:56:32 -0800906 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800907 // + Integer.toHexString(w.mAttrs.flags));
908 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800909 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800911 // Yet more tricksyness! If this window is a "starting"
912 // window, we do actually want to be on top of it, but
913 // it is not -really- where input will go. So if the caller
914 // is not actually looking to move the IME, look down below
915 // for a real window to target...
916 if (!willMove
917 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
918 && i > 0) {
919 WindowState wb = (WindowState)localmWindows.get(i-1);
920 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
921 i--;
922 w = wb;
923 }
924 }
925 break;
926 }
927 }
Romain Guy06882f82009-06-10 13:36:04 -0700928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700930
Joe Onorato8a9b2202010-02-26 18:56:32 -0800931 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 if (willMove && w != null) {
935 final WindowState curTarget = mInputMethodTarget;
936 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 // Now some fun for dealing with window animations that
939 // modify the Z order. We need to look at all windows below
940 // the current target that are in this app, finding the highest
941 // visible one in layering.
942 AppWindowToken token = curTarget.mAppToken;
943 WindowState highestTarget = null;
944 int highestPos = 0;
945 if (token.animating || token.animation != null) {
946 int pos = 0;
947 pos = localmWindows.indexOf(curTarget);
948 while (pos >= 0) {
949 WindowState win = (WindowState)localmWindows.get(pos);
950 if (win.mAppToken != token) {
951 break;
952 }
953 if (!win.mRemoved) {
954 if (highestTarget == null || win.mAnimLayer >
955 highestTarget.mAnimLayer) {
956 highestTarget = win;
957 highestPos = pos;
958 }
959 }
960 pos--;
961 }
962 }
Romain Guy06882f82009-06-10 13:36:04 -0700963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800964 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800965 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966 + mNextAppTransition + " " + highestTarget
967 + " animating=" + highestTarget.isAnimating()
968 + " layer=" + highestTarget.mAnimLayer
969 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700970
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700971 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 // If we are currently setting up for an animation,
973 // hold everything until we can find out what will happen.
974 mInputMethodTargetWaitingAnim = true;
975 mInputMethodTarget = highestTarget;
976 return highestPos + 1;
977 } else if (highestTarget.isAnimating() &&
978 highestTarget.mAnimLayer > w.mAnimLayer) {
979 // If the window we are currently targeting is involved
980 // with an animation, and it is on top of the next target
981 // we will be over, then hold off on moving until
982 // that is done.
983 mInputMethodTarget = highestTarget;
984 return highestPos + 1;
985 }
986 }
987 }
988 }
Romain Guy06882f82009-06-10 13:36:04 -0700989
Joe Onorato8a9b2202010-02-26 18:56:32 -0800990 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800991 if (w != null) {
992 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -0800993 if (DEBUG_INPUT_METHOD) {
994 RuntimeException e = null;
995 if (!HIDE_STACK_CRAWLS) {
996 e = new RuntimeException();
997 e.fillInStackTrace();
998 }
999 Slog.w(TAG, "Moving IM target from "
1000 + mInputMethodTarget + " to " + w, e);
1001 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001002 mInputMethodTarget = w;
1003 if (w.mAppToken != null) {
1004 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1005 } else {
1006 setInputMethodAnimLayerAdjustment(0);
1007 }
1008 }
1009 return i+1;
1010 }
1011 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001012 if (DEBUG_INPUT_METHOD) {
1013 RuntimeException e = null;
1014 if (!HIDE_STACK_CRAWLS) {
1015 e = new RuntimeException();
1016 e.fillInStackTrace();
1017 }
1018 Slog.w(TAG, "Moving IM target from "
1019 + mInputMethodTarget + " to null", e);
1020 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001021 mInputMethodTarget = null;
1022 setInputMethodAnimLayerAdjustment(0);
1023 }
1024 return -1;
1025 }
Romain Guy06882f82009-06-10 13:36:04 -07001026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001027 void addInputMethodWindowToListLocked(WindowState win) {
1028 int pos = findDesiredInputMethodWindowIndexLocked(true);
1029 if (pos >= 0) {
1030 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001031 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001032 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001033 mWindows.add(pos, win);
1034 moveInputMethodDialogsLocked(pos+1);
1035 return;
1036 }
1037 win.mTargetAppToken = null;
1038 addWindowToListInOrderLocked(win, true);
1039 moveInputMethodDialogsLocked(pos);
1040 }
Romain Guy06882f82009-06-10 13:36:04 -07001041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001042 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001043 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 mInputMethodAnimLayerAdjustment = adj;
1045 WindowState imw = mInputMethodWindow;
1046 if (imw != null) {
1047 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001048 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 + " anim layer: " + imw.mAnimLayer);
1050 int wi = imw.mChildWindows.size();
1051 while (wi > 0) {
1052 wi--;
1053 WindowState cw = (WindowState)imw.mChildWindows.get(wi);
1054 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001055 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001056 + " anim layer: " + cw.mAnimLayer);
1057 }
1058 }
1059 int di = mInputMethodDialogs.size();
1060 while (di > 0) {
1061 di --;
1062 imw = mInputMethodDialogs.get(di);
1063 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001064 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065 + " anim layer: " + imw.mAnimLayer);
1066 }
1067 }
Romain Guy06882f82009-06-10 13:36:04 -07001068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1070 int wpos = mWindows.indexOf(win);
1071 if (wpos >= 0) {
1072 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001073 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001074 mWindows.remove(wpos);
1075 int NC = win.mChildWindows.size();
1076 while (NC > 0) {
1077 NC--;
1078 WindowState cw = (WindowState)win.mChildWindows.get(NC);
1079 int cpos = mWindows.indexOf(cw);
1080 if (cpos >= 0) {
1081 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001082 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001083 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084 mWindows.remove(cpos);
1085 }
1086 }
1087 }
1088 return interestingPos;
1089 }
Romain Guy06882f82009-06-10 13:36:04 -07001090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 private void reAddWindowToListInOrderLocked(WindowState win) {
1092 addWindowToListInOrderLocked(win, false);
1093 // This is a hack to get all of the child windows added as well
1094 // at the right position. Child windows should be rare and
1095 // this case should be rare, so it shouldn't be that big a deal.
1096 int wpos = mWindows.indexOf(win);
1097 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001098 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001099 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 mWindows.remove(wpos);
1101 reAddWindowLocked(wpos, win);
1102 }
1103 }
Romain Guy06882f82009-06-10 13:36:04 -07001104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 void logWindowList(String prefix) {
1106 int N = mWindows.size();
1107 while (N > 0) {
1108 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001109 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001110 }
1111 }
Romain Guy06882f82009-06-10 13:36:04 -07001112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 void moveInputMethodDialogsLocked(int pos) {
1114 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001117 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001118 for (int i=0; i<N; i++) {
1119 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1120 }
1121 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001122 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001123 logWindowList(" ");
1124 }
Romain Guy06882f82009-06-10 13:36:04 -07001125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001126 if (pos >= 0) {
1127 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1128 if (pos < mWindows.size()) {
1129 WindowState wp = (WindowState)mWindows.get(pos);
1130 if (wp == mInputMethodWindow) {
1131 pos++;
1132 }
1133 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001134 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 for (int i=0; i<N; i++) {
1136 WindowState win = dialogs.get(i);
1137 win.mTargetAppToken = targetAppToken;
1138 pos = reAddWindowLocked(pos, win);
1139 }
1140 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001141 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 logWindowList(" ");
1143 }
1144 return;
1145 }
1146 for (int i=0; i<N; i++) {
1147 WindowState win = dialogs.get(i);
1148 win.mTargetAppToken = null;
1149 reAddWindowToListInOrderLocked(win);
1150 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001151 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 logWindowList(" ");
1153 }
1154 }
1155 }
Romain Guy06882f82009-06-10 13:36:04 -07001156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001157 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1158 final WindowState imWin = mInputMethodWindow;
1159 final int DN = mInputMethodDialogs.size();
1160 if (imWin == null && DN == 0) {
1161 return false;
1162 }
Romain Guy06882f82009-06-10 13:36:04 -07001163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001164 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1165 if (imPos >= 0) {
1166 // In this case, the input method windows are to be placed
1167 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001169 // First check to see if the input method windows are already
1170 // located here, and contiguous.
1171 final int N = mWindows.size();
1172 WindowState firstImWin = imPos < N
1173 ? (WindowState)mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 // Figure out the actual input method window that should be
1176 // at the bottom of their stack.
1177 WindowState baseImWin = imWin != null
1178 ? imWin : mInputMethodDialogs.get(0);
1179 if (baseImWin.mChildWindows.size() > 0) {
1180 WindowState cw = (WindowState)baseImWin.mChildWindows.get(0);
1181 if (cw.mSubLayer < 0) baseImWin = cw;
1182 }
Romain Guy06882f82009-06-10 13:36:04 -07001183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 if (firstImWin == baseImWin) {
1185 // The windows haven't moved... but are they still contiguous?
1186 // First find the top IM window.
1187 int pos = imPos+1;
1188 while (pos < N) {
1189 if (!((WindowState)mWindows.get(pos)).mIsImWindow) {
1190 break;
1191 }
1192 pos++;
1193 }
1194 pos++;
1195 // Now there should be no more input method windows above.
1196 while (pos < N) {
1197 if (((WindowState)mWindows.get(pos)).mIsImWindow) {
1198 break;
1199 }
1200 pos++;
1201 }
1202 if (pos >= N) {
1203 // All is good!
1204 return false;
1205 }
1206 }
Romain Guy06882f82009-06-10 13:36:04 -07001207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208 if (imWin != null) {
1209 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001210 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001211 logWindowList(" ");
1212 }
1213 imPos = tmpRemoveWindowLocked(imPos, imWin);
1214 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001215 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001216 logWindowList(" ");
1217 }
1218 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1219 reAddWindowLocked(imPos, imWin);
1220 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001221 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001222 logWindowList(" ");
1223 }
1224 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1225 } else {
1226 moveInputMethodDialogsLocked(imPos);
1227 }
Romain Guy06882f82009-06-10 13:36:04 -07001228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 } else {
1230 // In this case, the input method windows go in a fixed layer,
1231 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001233 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001234 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235 tmpRemoveWindowLocked(0, imWin);
1236 imWin.mTargetAppToken = null;
1237 reAddWindowToListInOrderLocked(imWin);
1238 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001239 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001240 logWindowList(" ");
1241 }
1242 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1243 } else {
1244 moveInputMethodDialogsLocked(-1);;
1245 }
Romain Guy06882f82009-06-10 13:36:04 -07001246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 }
Romain Guy06882f82009-06-10 13:36:04 -07001248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249 if (needAssignLayers) {
1250 assignLayersLocked();
1251 }
Romain Guy06882f82009-06-10 13:36:04 -07001252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253 return true;
1254 }
Romain Guy06882f82009-06-10 13:36:04 -07001255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 void adjustInputMethodDialogsLocked() {
1257 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1258 }
Romain Guy06882f82009-06-10 13:36:04 -07001259
Dianne Hackborn25994b42009-09-04 14:21:19 -07001260 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001261 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001262 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1263 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1264 ? wallpaperTarget.mAppToken.animation : null)
1265 + " upper=" + mUpperWallpaperTarget
1266 + " lower=" + mLowerWallpaperTarget);
1267 return (wallpaperTarget != null
1268 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1269 && wallpaperTarget.mAppToken.animation != null)))
1270 || mUpperWallpaperTarget != null
1271 || mLowerWallpaperTarget != null;
1272 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001273
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001274 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1275 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001276
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001277 int adjustWallpaperWindowsLocked() {
1278 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001279
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001280 final int dw = mDisplay.getWidth();
1281 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001282
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001283 // First find top-most window that has asked to be on top of the
1284 // wallpaper; all wallpapers go behind it.
1285 final ArrayList localmWindows = mWindows;
1286 int N = localmWindows.size();
1287 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001288 WindowState foundW = null;
1289 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001290 WindowState topCurW = null;
1291 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001292 int i = N;
1293 while (i > 0) {
1294 i--;
1295 w = (WindowState)localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001296 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1297 if (topCurW == null) {
1298 topCurW = w;
1299 topCurI = i;
1300 }
1301 continue;
1302 }
1303 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001304 if (w.mAppToken != null) {
1305 // If this window's app token is hidden and not animating,
1306 // it is of no interest to us.
1307 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001308 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001309 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001310 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001311 continue;
1312 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001313 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001314 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001315 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1316 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001317 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001318 && (mWallpaperTarget == w
1319 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001320 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001321 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001322 foundW = w;
1323 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001324 if (w == mWallpaperTarget && ((w.mAppToken != null
1325 && w.mAppToken.animation != null)
1326 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001327 // The current wallpaper target is animating, so we'll
1328 // look behind it for another possible target and figure
1329 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001330 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001331 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001332 continue;
1333 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001334 break;
1335 }
1336 }
1337
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001338 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001339 // If we are currently waiting for an app transition, and either
1340 // the current target or the next target are involved with it,
1341 // then hold off on doing anything with the wallpaper.
1342 // Note that we are checking here for just whether the target
1343 // is part of an app token... which is potentially overly aggressive
1344 // (the app token may not be involved in the transition), but good
1345 // enough (we'll just wait until whatever transition is pending
1346 // executes).
1347 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001348 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001349 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001350 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001351 }
1352 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001353 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001354 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001355 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001356 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001357 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001358
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001359 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001360 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001361 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001362 + " oldTarget: " + mWallpaperTarget);
1363 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001364
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001365 mLowerWallpaperTarget = null;
1366 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001367
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001368 WindowState oldW = mWallpaperTarget;
1369 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001370
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001371 // Now what is happening... if the current and new targets are
1372 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001373 if (foundW != null && oldW != null) {
1374 boolean oldAnim = oldW.mAnimation != null
1375 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1376 boolean foundAnim = foundW.mAnimation != null
1377 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001378 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001379 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001380 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001381 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001382 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001383 int oldI = localmWindows.indexOf(oldW);
1384 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001385 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001386 }
1387 if (oldI >= 0) {
1388 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001389 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001390 + "=" + oldW + "; new#" + foundI
1391 + "=" + foundW);
1392 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001393
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001394 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001395 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001396 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001397 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001398 }
1399 mWallpaperTarget = oldW;
1400 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001401
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001402 // Now set the upper and lower wallpaper targets
1403 // correctly, and make sure that we are positioning
1404 // the wallpaper below the lower.
1405 if (foundI > oldI) {
1406 // The new target is on top of the old one.
1407 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001408 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001409 }
1410 mUpperWallpaperTarget = foundW;
1411 mLowerWallpaperTarget = oldW;
1412 foundW = oldW;
1413 foundI = oldI;
1414 } else {
1415 // The new target is below the old one.
1416 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001417 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001418 }
1419 mUpperWallpaperTarget = oldW;
1420 mLowerWallpaperTarget = foundW;
1421 }
1422 }
1423 }
1424 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001425
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001426 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001427 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001428 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1429 || (mLowerWallpaperTarget.mAppToken != null
1430 && mLowerWallpaperTarget.mAppToken.animation != null);
1431 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1432 || (mUpperWallpaperTarget.mAppToken != null
1433 && mUpperWallpaperTarget.mAppToken.animation != null);
1434 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001435 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001436 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001437 }
1438 mLowerWallpaperTarget = null;
1439 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001440 }
1441 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001442
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001443 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001444 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001445 // The window is visible to the compositor... but is it visible
1446 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001447 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001448 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001449
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001450 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001451 // its layer adjustment. Only do this if we are not transfering
1452 // between two wallpaper targets.
1453 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001454 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001455 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001456
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001457 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1458 * TYPE_LAYER_MULTIPLIER
1459 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001460
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001461 // Now w is the window we are supposed to be behind... but we
1462 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001463 // AND any starting window associated with it, AND below the
1464 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001465 while (foundI > 0) {
1466 WindowState wb = (WindowState)localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001467 if (wb.mBaseLayer < maxLayer &&
1468 wb.mAttachedWindow != foundW &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001469 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001470 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001471 // This window is not related to the previous one in any
1472 // interesting way, so stop here.
1473 break;
1474 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001475 foundW = wb;
1476 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001477 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001478 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001479 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001480 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001481
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001482 if (foundW == null && topCurW != null) {
1483 // There is no wallpaper target, so it goes at the bottom.
1484 // We will assume it is the same place as last time, if known.
1485 foundW = topCurW;
1486 foundI = topCurI+1;
1487 } else {
1488 // Okay i is the position immediately above the wallpaper. Look at
1489 // what is below it for later.
1490 foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null;
1491 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001492
Dianne Hackborn284ac932009-08-28 10:34:25 -07001493 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001494 if (mWallpaperTarget.mWallpaperX >= 0) {
1495 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001496 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001497 }
1498 if (mWallpaperTarget.mWallpaperY >= 0) {
1499 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001500 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001501 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001502 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001503
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001504 // Start stepping backwards from here, ensuring that our wallpaper windows
1505 // are correctly placed.
1506 int curTokenIndex = mWallpaperTokens.size();
1507 while (curTokenIndex > 0) {
1508 curTokenIndex--;
1509 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001510 if (token.hidden == visible) {
1511 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1512 token.hidden = !visible;
1513 // Need to do a layout to ensure the wallpaper now has the
1514 // correct size.
1515 mLayoutNeeded = true;
1516 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001517
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001518 int curWallpaperIndex = token.windows.size();
1519 while (curWallpaperIndex > 0) {
1520 curWallpaperIndex--;
1521 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001522
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001523 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001524 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001525 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001526
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001527 // First, make sure the client has the current visibility
1528 // state.
1529 if (wallpaper.mWallpaperVisible != visible) {
1530 wallpaper.mWallpaperVisible = visible;
1531 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001532 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001533 "Setting visibility of wallpaper " + wallpaper
1534 + ": " + visible);
1535 wallpaper.mClient.dispatchAppVisibility(visible);
1536 } catch (RemoteException e) {
1537 }
1538 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001539
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001540 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001541 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001542 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001543
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001544 // First, if this window is at the current index, then all
1545 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001546 if (wallpaper == foundW) {
1547 foundI--;
1548 foundW = foundI > 0
1549 ? (WindowState)localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001550 continue;
1551 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001552
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001553 // The window didn't match... the current wallpaper window,
1554 // wherever it is, is in the wrong place, so make sure it is
1555 // not in the list.
1556 int oldIndex = localmWindows.indexOf(wallpaper);
1557 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001558 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001559 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001560 localmWindows.remove(oldIndex);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001561 if (oldIndex < foundI) {
1562 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001563 }
1564 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001565
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001566 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001567 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001568 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001569 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001570
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001571 localmWindows.add(foundI, wallpaper);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001572 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001573 }
1574 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001575
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001576 return changed;
1577 }
1578
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001579 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001580 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001581 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001582 mWallpaperAnimLayerAdjustment = adj;
1583 int curTokenIndex = mWallpaperTokens.size();
1584 while (curTokenIndex > 0) {
1585 curTokenIndex--;
1586 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1587 int curWallpaperIndex = token.windows.size();
1588 while (curWallpaperIndex > 0) {
1589 curWallpaperIndex--;
1590 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1591 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001592 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001593 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001594 }
1595 }
1596 }
1597
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001598 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1599 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001600 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001601 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001602 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001603 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001604 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1605 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1606 changed = wallpaperWin.mXOffset != offset;
1607 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001608 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001609 + wallpaperWin + " x: " + offset);
1610 wallpaperWin.mXOffset = offset;
1611 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001612 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001613 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001614 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001615 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001616 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001617
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001618 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001619 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001620 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1621 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1622 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001623 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001624 + wallpaperWin + " y: " + offset);
1625 changed = true;
1626 wallpaperWin.mYOffset = offset;
1627 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001628 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001629 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001630 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001631 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001632 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001633
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001634 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001635 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001636 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001637 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1638 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001639 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001640 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001641 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001642 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001643 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1644 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001645 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001646 if (mWaitingOnWallpaper != null) {
1647 long start = SystemClock.uptimeMillis();
1648 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1649 < start) {
1650 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001651 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001652 "Waiting for offset complete...");
1653 mWindowMap.wait(WALLPAPER_TIMEOUT);
1654 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001655 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001656 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001657 if ((start+WALLPAPER_TIMEOUT)
1658 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001659 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001660 + wallpaperWin);
1661 mLastWallpaperTimeoutTime = start;
1662 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001663 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001664 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001665 }
1666 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001667 } catch (RemoteException e) {
1668 }
1669 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001670
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001671 return changed;
1672 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001673
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001674 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001675 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001676 if (mWaitingOnWallpaper != null &&
1677 mWaitingOnWallpaper.mClient.asBinder() == window) {
1678 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001679 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001680 }
1681 }
1682 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001683
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001684 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001685 final int dw = mDisplay.getWidth();
1686 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001687
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001688 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001689
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001690 WindowState target = mWallpaperTarget;
1691 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001692 if (target.mWallpaperX >= 0) {
1693 mLastWallpaperX = target.mWallpaperX;
1694 } else if (changingTarget.mWallpaperX >= 0) {
1695 mLastWallpaperX = changingTarget.mWallpaperX;
1696 }
1697 if (target.mWallpaperY >= 0) {
1698 mLastWallpaperY = target.mWallpaperY;
1699 } else if (changingTarget.mWallpaperY >= 0) {
1700 mLastWallpaperY = changingTarget.mWallpaperY;
1701 }
1702 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001703
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001704 int curTokenIndex = mWallpaperTokens.size();
1705 while (curTokenIndex > 0) {
1706 curTokenIndex--;
1707 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1708 int curWallpaperIndex = token.windows.size();
1709 while (curWallpaperIndex > 0) {
1710 curWallpaperIndex--;
1711 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1712 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1713 wallpaper.computeShownFrameLocked();
1714 changed = true;
1715 // We only want to be synchronous with one wallpaper.
1716 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001717 }
1718 }
1719 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001720
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001721 return changed;
1722 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001723
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001724 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001725 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001726 final int dw = mDisplay.getWidth();
1727 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001728
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001729 int curTokenIndex = mWallpaperTokens.size();
1730 while (curTokenIndex > 0) {
1731 curTokenIndex--;
1732 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001733 if (token.hidden == visible) {
1734 token.hidden = !visible;
1735 // Need to do a layout to ensure the wallpaper now has the
1736 // correct size.
1737 mLayoutNeeded = true;
1738 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001739
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001740 int curWallpaperIndex = token.windows.size();
1741 while (curWallpaperIndex > 0) {
1742 curWallpaperIndex--;
1743 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1744 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001745 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001746 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001747
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001748 if (wallpaper.mWallpaperVisible != visible) {
1749 wallpaper.mWallpaperVisible = visible;
1750 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001751 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001752 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001753 + ": " + visible);
1754 wallpaper.mClient.dispatchAppVisibility(visible);
1755 } catch (RemoteException e) {
1756 }
1757 }
1758 }
1759 }
1760 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001761
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001762 void sendPointerToWallpaperLocked(WindowState srcWin,
1763 MotionEvent pointer, long eventTime) {
1764 int curTokenIndex = mWallpaperTokens.size();
1765 while (curTokenIndex > 0) {
1766 curTokenIndex--;
1767 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1768 int curWallpaperIndex = token.windows.size();
1769 while (curWallpaperIndex > 0) {
1770 curWallpaperIndex--;
1771 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1772 if ((wallpaper.mAttrs.flags &
1773 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
1774 continue;
1775 }
1776 try {
1777 MotionEvent ev = MotionEvent.obtainNoHistory(pointer);
Dianne Hackborn6adba242009-11-10 11:10:09 -08001778 if (srcWin != null) {
1779 ev.offsetLocation(srcWin.mFrame.left-wallpaper.mFrame.left,
1780 srcWin.mFrame.top-wallpaper.mFrame.top);
1781 } else {
1782 ev.offsetLocation(-wallpaper.mFrame.left, -wallpaper.mFrame.top);
1783 }
1784 switch (pointer.getAction()) {
1785 case MotionEvent.ACTION_DOWN:
1786 mSendingPointersToWallpaper = true;
1787 break;
1788 case MotionEvent.ACTION_UP:
1789 mSendingPointersToWallpaper = false;
1790 break;
1791 }
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001792 wallpaper.mClient.dispatchPointer(ev, eventTime, false);
1793 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001794 Slog.w(TAG, "Failure sending pointer to wallpaper", e);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001795 }
1796 }
1797 }
1798 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001799
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001800 void dispatchPointerElsewhereLocked(WindowState srcWin, WindowState relWin,
1801 MotionEvent pointer, long eventTime, boolean skipped) {
1802 if (relWin != null) {
1803 mPolicy.dispatchedPointerEventLw(pointer, relWin.mFrame.left, relWin.mFrame.top);
1804 } else {
1805 mPolicy.dispatchedPointerEventLw(pointer, 0, 0);
1806 }
1807
1808 // If we sent an initial down to the wallpaper, then continue
1809 // sending events until the final up.
1810 if (mSendingPointersToWallpaper) {
1811 if (skipped) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001812 Slog.i(TAG, "Sending skipped pointer to wallpaper!");
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001813 }
1814 sendPointerToWallpaperLocked(relWin, pointer, eventTime);
1815
1816 // If we are on top of the wallpaper, then the wallpaper also
1817 // gets to see this movement.
1818 } else if (srcWin != null
1819 && pointer.getAction() == MotionEvent.ACTION_DOWN
1820 && mWallpaperTarget == srcWin
1821 && srcWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) {
1822 sendPointerToWallpaperLocked(relWin, pointer, eventTime);
1823 }
1824 }
1825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001826 public int addWindow(Session session, IWindow client,
1827 WindowManager.LayoutParams attrs, int viewVisibility,
1828 Rect outContentInsets) {
1829 int res = mPolicy.checkAddPermission(attrs);
1830 if (res != WindowManagerImpl.ADD_OKAY) {
1831 return res;
1832 }
Romain Guy06882f82009-06-10 13:36:04 -07001833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001834 boolean reportNewConfig = false;
1835 WindowState attachedWindow = null;
1836 WindowState win = null;
Romain Guy06882f82009-06-10 13:36:04 -07001837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001838 synchronized(mWindowMap) {
1839 // Instantiating a Display requires talking with the simulator,
1840 // so don't do it until we know the system is mostly up and
1841 // running.
1842 if (mDisplay == null) {
1843 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1844 mDisplay = wm.getDefaultDisplay();
1845 mQueue.setDisplay(mDisplay);
1846 reportNewConfig = true;
1847 }
Romain Guy06882f82009-06-10 13:36:04 -07001848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001849 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001850 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001851 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1852 }
1853
1854 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001855 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001856 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001857 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001858 + attrs.token + ". Aborting.");
1859 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1860 }
1861 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1862 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001863 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001864 + attrs.token + ". Aborting.");
1865 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1866 }
1867 }
1868
1869 boolean addToken = false;
1870 WindowToken token = mTokenMap.get(attrs.token);
1871 if (token == null) {
1872 if (attrs.type >= FIRST_APPLICATION_WINDOW
1873 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001874 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001875 + attrs.token + ". Aborting.");
1876 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1877 }
1878 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001879 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001880 + attrs.token + ". Aborting.");
1881 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1882 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001883 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001884 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001885 + attrs.token + ". Aborting.");
1886 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1887 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001888 token = new WindowToken(attrs.token, -1, false);
1889 addToken = true;
1890 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1891 && attrs.type <= LAST_APPLICATION_WINDOW) {
1892 AppWindowToken atoken = token.appWindowToken;
1893 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001894 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001895 + token + ". Aborting.");
1896 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1897 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001898 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001899 + token + ". Aborting.");
1900 return WindowManagerImpl.ADD_APP_EXITING;
1901 }
1902 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1903 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001904 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001905 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1906 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1907 }
1908 } else if (attrs.type == TYPE_INPUT_METHOD) {
1909 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001910 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001911 + attrs.token + ". Aborting.");
1912 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1913 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001914 } else if (attrs.type == TYPE_WALLPAPER) {
1915 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001916 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001917 + attrs.token + ". Aborting.");
1918 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1919 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001920 }
1921
1922 win = new WindowState(session, client, token,
1923 attachedWindow, attrs, viewVisibility);
1924 if (win.mDeathRecipient == null) {
1925 // Client has apparently died, so there is no reason to
1926 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001927 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001928 + " that is dead, aborting.");
1929 return WindowManagerImpl.ADD_APP_EXITING;
1930 }
1931
1932 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001934 res = mPolicy.prepareAddWindowLw(win, attrs);
1935 if (res != WindowManagerImpl.ADD_OKAY) {
1936 return res;
1937 }
1938
1939 // From now on, no exceptions or errors allowed!
1940
1941 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001943 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001945 if (addToken) {
1946 mTokenMap.put(attrs.token, token);
1947 mTokenList.add(token);
1948 }
1949 win.attach();
1950 mWindowMap.put(client.asBinder(), win);
1951
1952 if (attrs.type == TYPE_APPLICATION_STARTING &&
1953 token.appWindowToken != null) {
1954 token.appWindowToken.startingWindow = win;
1955 }
1956
1957 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001959 if (attrs.type == TYPE_INPUT_METHOD) {
1960 mInputMethodWindow = win;
1961 addInputMethodWindowToListLocked(win);
1962 imMayMove = false;
1963 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1964 mInputMethodDialogs.add(win);
1965 addWindowToListInOrderLocked(win, true);
1966 adjustInputMethodDialogsLocked();
1967 imMayMove = false;
1968 } else {
1969 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001970 if (attrs.type == TYPE_WALLPAPER) {
1971 mLastWallpaperTimeoutTime = 0;
1972 adjustWallpaperWindowsLocked();
1973 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001974 adjustWallpaperWindowsLocked();
1975 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001976 }
Romain Guy06882f82009-06-10 13:36:04 -07001977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001978 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001980 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001982 if (mInTouchMode) {
1983 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1984 }
1985 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1986 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1987 }
Romain Guy06882f82009-06-10 13:36:04 -07001988
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001989 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001990 if (win.canReceiveKeys()) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001991 if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS))
1992 == true) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001993 imMayMove = false;
1994 }
1995 }
Romain Guy06882f82009-06-10 13:36:04 -07001996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001997 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001998 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001999 }
Romain Guy06882f82009-06-10 13:36:04 -07002000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001 assignLayersLocked();
2002 // Don't do layout here, the window must call
2003 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002005 //dump();
2006
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002007 if (focusChanged) {
2008 if (mCurrentFocus != null) {
2009 mKeyWaiter.handleNewWindowLocked(mCurrentFocus);
2010 }
2011 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002012 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002013 TAG, "New client " + client.asBinder()
2014 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002015
2016 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2017 reportNewConfig = true;
2018 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002019 }
2020
2021 // sendNewConfiguration() checks caller permissions so we must call it with
2022 // privilege. updateOrientationFromAppTokens() clears and resets the caller
2023 // identity anyway, so it's safe to just clear & restore around this whole
2024 // block.
2025 final long origId = Binder.clearCallingIdentity();
2026 if (reportNewConfig) {
2027 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002028 }
2029 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002031 return res;
2032 }
Romain Guy06882f82009-06-10 13:36:04 -07002033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002034 public void removeWindow(Session session, IWindow client) {
2035 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002036 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002037 if (win == null) {
2038 return;
2039 }
2040 removeWindowLocked(session, win);
2041 }
2042 }
Romain Guy06882f82009-06-10 13:36:04 -07002043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002044 public void removeWindowLocked(Session session, WindowState win) {
2045
Joe Onorato8a9b2202010-02-26 18:56:32 -08002046 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002047 TAG, "Remove " + win + " client="
2048 + Integer.toHexString(System.identityHashCode(
2049 win.mClient.asBinder()))
2050 + ", surface=" + win.mSurface);
2051
2052 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002053
Joe Onorato8a9b2202010-02-26 18:56:32 -08002054 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002055 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2056 + " mExiting=" + win.mExiting
2057 + " isAnimating=" + win.isAnimating()
2058 + " app-animation="
2059 + (win.mAppToken != null ? win.mAppToken.animation : null)
2060 + " inPendingTransaction="
2061 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2062 + " mDisplayFrozen=" + mDisplayFrozen);
2063 // Visibility of the removed window. Will be used later to update orientation later on.
2064 boolean wasVisible = false;
2065 // First, see if we need to run an animation. If we do, we have
2066 // to hold off on removing the window until the animation is done.
2067 // If the display is frozen, just remove immediately, since the
2068 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002069 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002070 // If we are not currently running the exit animation, we
2071 // need to see about starting one.
2072 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002074 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2075 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2076 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2077 }
2078 // Try starting an animation.
2079 if (applyAnimationLocked(win, transit, false)) {
2080 win.mExiting = true;
2081 }
2082 }
2083 if (win.mExiting || win.isAnimating()) {
2084 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002085 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002086 win.mExiting = true;
2087 win.mRemoveOnExit = true;
2088 mLayoutNeeded = true;
2089 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2090 performLayoutAndPlaceSurfacesLocked();
2091 if (win.mAppToken != null) {
2092 win.mAppToken.updateReportedVisibilityLocked();
2093 }
2094 //dump();
2095 Binder.restoreCallingIdentity(origId);
2096 return;
2097 }
2098 }
2099
2100 removeWindowInnerLocked(session, win);
2101 // Removing a visible window will effect the computed orientation
2102 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002103 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002104 != mForcedAppOrientation
2105 && updateOrientationFromAppTokensLocked()) {
2106 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002107 }
2108 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2109 Binder.restoreCallingIdentity(origId);
2110 }
Romain Guy06882f82009-06-10 13:36:04 -07002111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002112 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07002113 mKeyWaiter.finishedKey(session, win.mClient, true,
2114 KeyWaiter.RETURN_NOTHING);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002115 mKeyWaiter.releasePendingPointerLocked(win.mSession);
2116 mKeyWaiter.releasePendingTrackballLocked(win.mSession);
Romain Guy06882f82009-06-10 13:36:04 -07002117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002118 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002120 if (mInputMethodTarget == win) {
2121 moveInputMethodWindowsIfNeededLocked(false);
2122 }
Romain Guy06882f82009-06-10 13:36:04 -07002123
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002124 if (false) {
2125 RuntimeException e = new RuntimeException("here");
2126 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002127 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002128 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002130 mPolicy.removeWindowLw(win);
2131 win.removeLocked();
2132
2133 mWindowMap.remove(win.mClient.asBinder());
2134 mWindows.remove(win);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002135 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002136
2137 if (mInputMethodWindow == win) {
2138 mInputMethodWindow = null;
2139 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2140 mInputMethodDialogs.remove(win);
2141 }
Romain Guy06882f82009-06-10 13:36:04 -07002142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002143 final WindowToken token = win.mToken;
2144 final AppWindowToken atoken = win.mAppToken;
2145 token.windows.remove(win);
2146 if (atoken != null) {
2147 atoken.allAppWindows.remove(win);
2148 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002149 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002150 TAG, "**** Removing window " + win + ": count="
2151 + token.windows.size());
2152 if (token.windows.size() == 0) {
2153 if (!token.explicit) {
2154 mTokenMap.remove(token.token);
2155 mTokenList.remove(token);
2156 } else if (atoken != null) {
2157 atoken.firstWindowDrawn = false;
2158 }
2159 }
2160
2161 if (atoken != null) {
2162 if (atoken.startingWindow == win) {
2163 atoken.startingWindow = null;
2164 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2165 // If this is the last window and we had requested a starting
2166 // transition window, well there is no point now.
2167 atoken.startingData = null;
2168 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2169 // If this is the last window except for a starting transition
2170 // window, we need to get rid of the starting transition.
2171 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002172 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002173 + ": no more real windows");
2174 }
2175 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2176 mH.sendMessage(m);
2177 }
2178 }
Romain Guy06882f82009-06-10 13:36:04 -07002179
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002180 if (win.mAttrs.type == TYPE_WALLPAPER) {
2181 mLastWallpaperTimeoutTime = 0;
2182 adjustWallpaperWindowsLocked();
2183 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002184 adjustWallpaperWindowsLocked();
2185 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002187 if (!mInLayout) {
2188 assignLayersLocked();
2189 mLayoutNeeded = true;
2190 performLayoutAndPlaceSurfacesLocked();
2191 if (win.mAppToken != null) {
2192 win.mAppToken.updateReportedVisibilityLocked();
2193 }
2194 }
2195 }
2196
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002197 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2198 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2199 + ": " + msg + " / " + w.mAttrs.getTitle();
2200 if (where != null) {
2201 Slog.i(TAG, str, where);
2202 } else {
2203 Slog.i(TAG, str);
2204 }
2205 }
2206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002207 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2208 long origId = Binder.clearCallingIdentity();
2209 try {
2210 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002211 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002212 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002213 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002214 Surface.openTransaction();
2215 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002216 if (SHOW_TRANSACTIONS) logSurface(w,
2217 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002218 w.mSurface.setTransparentRegionHint(region);
2219 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002220 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002221 Surface.closeTransaction();
2222 }
2223 }
2224 }
2225 } finally {
2226 Binder.restoreCallingIdentity(origId);
2227 }
2228 }
2229
2230 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002231 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002232 Rect visibleInsets) {
2233 long origId = Binder.clearCallingIdentity();
2234 try {
2235 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002236 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002237 if (w != null) {
2238 w.mGivenInsetsPending = false;
2239 w.mGivenContentInsets.set(contentInsets);
2240 w.mGivenVisibleInsets.set(visibleInsets);
2241 w.mTouchableInsets = touchableInsets;
2242 mLayoutNeeded = true;
2243 performLayoutAndPlaceSurfacesLocked();
2244 }
2245 }
2246 } finally {
2247 Binder.restoreCallingIdentity(origId);
2248 }
2249 }
Romain Guy06882f82009-06-10 13:36:04 -07002250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002251 public void getWindowDisplayFrame(Session session, IWindow client,
2252 Rect outDisplayFrame) {
2253 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002254 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002255 if (win == null) {
2256 outDisplayFrame.setEmpty();
2257 return;
2258 }
2259 outDisplayFrame.set(win.mDisplayFrame);
2260 }
2261 }
2262
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002263 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2264 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002265 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2266 window.mWallpaperX = x;
2267 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002268 window.mWallpaperXStep = xStep;
2269 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002270 if (updateWallpaperOffsetLocked(window, true)) {
2271 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002272 }
2273 }
2274 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002275
Dianne Hackborn75804932009-10-20 20:15:20 -07002276 void wallpaperCommandComplete(IBinder window, Bundle result) {
2277 synchronized (mWindowMap) {
2278 if (mWaitingOnWallpaper != null &&
2279 mWaitingOnWallpaper.mClient.asBinder() == window) {
2280 mWaitingOnWallpaper = null;
2281 mWindowMap.notifyAll();
2282 }
2283 }
2284 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002285
Dianne Hackborn75804932009-10-20 20:15:20 -07002286 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2287 String action, int x, int y, int z, Bundle extras, boolean sync) {
2288 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2289 || window == mUpperWallpaperTarget) {
2290 boolean doWait = sync;
2291 int curTokenIndex = mWallpaperTokens.size();
2292 while (curTokenIndex > 0) {
2293 curTokenIndex--;
2294 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2295 int curWallpaperIndex = token.windows.size();
2296 while (curWallpaperIndex > 0) {
2297 curWallpaperIndex--;
2298 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2299 try {
2300 wallpaper.mClient.dispatchWallpaperCommand(action,
2301 x, y, z, extras, sync);
2302 // We only want to be synchronous with one wallpaper.
2303 sync = false;
2304 } catch (RemoteException e) {
2305 }
2306 }
2307 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002308
Dianne Hackborn75804932009-10-20 20:15:20 -07002309 if (doWait) {
2310 // XXX Need to wait for result.
2311 }
2312 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002313
Dianne Hackborn75804932009-10-20 20:15:20 -07002314 return null;
2315 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002317 public int relayoutWindow(Session session, IWindow client,
2318 WindowManager.LayoutParams attrs, int requestedWidth,
2319 int requestedHeight, int viewVisibility, boolean insetsPending,
2320 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002321 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002322 boolean displayed = false;
2323 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002324 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002325 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002327 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002328 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002329 if (win == null) {
2330 return 0;
2331 }
2332 win.mRequestedWidth = requestedWidth;
2333 win.mRequestedHeight = requestedHeight;
2334
2335 if (attrs != null) {
2336 mPolicy.adjustWindowParamsLw(attrs);
2337 }
Romain Guy06882f82009-06-10 13:36:04 -07002338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002339 int attrChanges = 0;
2340 int flagChanges = 0;
2341 if (attrs != null) {
2342 flagChanges = win.mAttrs.flags ^= attrs.flags;
2343 attrChanges = win.mAttrs.copyFrom(attrs);
2344 }
2345
Joe Onorato8a9b2202010-02-26 18:56:32 -08002346 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002347
2348 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2349 win.mAlpha = attrs.alpha;
2350 }
2351
2352 final boolean scaledWindow =
2353 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2354
2355 if (scaledWindow) {
2356 // requested{Width|Height} Surface's physical size
2357 // attrs.{width|height} Size on screen
2358 win.mHScale = (attrs.width != requestedWidth) ?
2359 (attrs.width / (float)requestedWidth) : 1.0f;
2360 win.mVScale = (attrs.height != requestedHeight) ?
2361 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002362 } else {
2363 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002364 }
2365
2366 boolean imMayMove = (flagChanges&(
2367 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2368 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002370 boolean focusMayChange = win.mViewVisibility != viewVisibility
2371 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2372 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002373
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002374 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2375 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002377 win.mRelayoutCalled = true;
2378 final int oldVisibility = win.mViewVisibility;
2379 win.mViewVisibility = viewVisibility;
2380 if (viewVisibility == View.VISIBLE &&
2381 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2382 displayed = !win.isVisibleLw();
2383 if (win.mExiting) {
2384 win.mExiting = false;
2385 win.mAnimation = null;
2386 }
2387 if (win.mDestroying) {
2388 win.mDestroying = false;
2389 mDestroySurface.remove(win);
2390 }
2391 if (oldVisibility == View.GONE) {
2392 win.mEnterAnimationPending = true;
2393 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002394 if (displayed) {
2395 if (win.mSurface != null && !win.mDrawPending
2396 && !win.mCommitDrawPending && !mDisplayFrozen
2397 && mPolicy.isScreenOn()) {
2398 applyEnterAnimationLocked(win);
2399 }
2400 if ((win.mAttrs.flags
2401 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2402 if (DEBUG_VISIBILITY) Slog.v(TAG,
2403 "Relayout window turning screen on: " + win);
2404 win.mTurnOnScreen = true;
2405 }
2406 int diff = 0;
2407 if (win.mConfiguration != mCurConfiguration
2408 && (win.mConfiguration == null
2409 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2410 win.mConfiguration = mCurConfiguration;
2411 if (DEBUG_CONFIGURATION) {
2412 Slog.i(TAG, "Window " + win + " visible with new config: "
2413 + win.mConfiguration + " / 0x"
2414 + Integer.toHexString(diff));
2415 }
2416 outConfig.setTo(mCurConfiguration);
2417 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002418 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002419 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2420 // To change the format, we need to re-build the surface.
2421 win.destroySurfaceLocked();
2422 displayed = true;
2423 }
2424 try {
2425 Surface surface = win.createSurfaceLocked();
2426 if (surface != null) {
2427 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002428 win.mReportDestroySurface = false;
2429 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002430 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002431 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002432 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002433 // For some reason there isn't a surface. Clear the
2434 // caller's object so they see the same state.
2435 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002436 }
2437 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002438 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002439 + client + " (" + win.mAttrs.getTitle() + ")",
2440 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002441 Binder.restoreCallingIdentity(origId);
2442 return 0;
2443 }
2444 if (displayed) {
2445 focusMayChange = true;
2446 }
2447 if (win.mAttrs.type == TYPE_INPUT_METHOD
2448 && mInputMethodWindow == null) {
2449 mInputMethodWindow = win;
2450 imMayMove = true;
2451 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002452 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2453 && win.mAppToken != null
2454 && win.mAppToken.startingWindow != null) {
2455 // Special handling of starting window over the base
2456 // window of the app: propagate lock screen flags to it,
2457 // to provide the correct semantics while starting.
2458 final int mask =
2459 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002460 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2461 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002462 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2463 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2464 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002465 } else {
2466 win.mEnterAnimationPending = false;
2467 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002468 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002469 + ": mExiting=" + win.mExiting
2470 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002471 // If we are not currently running the exit animation, we
2472 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002473 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002474 // Try starting an animation; if there isn't one, we
2475 // can destroy the surface right away.
2476 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2477 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2478 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2479 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002480 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002481 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002482 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002483 win.mExiting = true;
2484 mKeyWaiter.finishedKey(session, client, true,
2485 KeyWaiter.RETURN_NOTHING);
2486 } else if (win.isAnimating()) {
2487 // Currently in a hide animation... turn this into
2488 // an exit.
2489 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002490 } else if (win == mWallpaperTarget) {
2491 // If the wallpaper is currently behind this
2492 // window, we need to change both of them inside
2493 // of a transaction to avoid artifacts.
2494 win.mExiting = true;
2495 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002496 } else {
2497 if (mInputMethodWindow == win) {
2498 mInputMethodWindow = null;
2499 }
2500 win.destroySurfaceLocked();
2501 }
2502 }
2503 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002504
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002505 if (win.mSurface == null || (win.getAttrs().flags
2506 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2507 || win.mSurfacePendingDestroy) {
2508 // We are being called from a local process, which
2509 // means outSurface holds its current surface. Ensure the
2510 // surface object is cleared, but we don't want it actually
2511 // destroyed at this point.
2512 win.mSurfacePendingDestroy = false;
2513 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002514 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002515 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002516 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002517 "Keeping surface, will report destroy: " + win);
2518 win.mReportDestroySurface = true;
2519 outSurface.copyFrom(win.mSurface);
2520 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002521 }
2522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002523 if (focusMayChange) {
2524 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2525 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002526 imMayMove = false;
2527 }
2528 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2529 }
Romain Guy06882f82009-06-10 13:36:04 -07002530
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002531 // updateFocusedWindowLocked() already assigned layers so we only need to
2532 // reassign them at this point if the IM window state gets shuffled
2533 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002535 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002536 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2537 // Little hack here -- we -should- be able to rely on the
2538 // function to return true if the IME has moved and needs
2539 // its layer recomputed. However, if the IME was hidden
2540 // and isn't actually moved in the list, its layer may be
2541 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002542 assignLayers = true;
2543 }
2544 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002545 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002546 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002547 assignLayers = true;
2548 }
2549 }
Romain Guy06882f82009-06-10 13:36:04 -07002550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002551 mLayoutNeeded = true;
2552 win.mGivenInsetsPending = insetsPending;
2553 if (assignLayers) {
2554 assignLayersLocked();
2555 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002556 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002557 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002558 if (displayed && win.mIsWallpaper) {
2559 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002560 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002561 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002562 if (win.mAppToken != null) {
2563 win.mAppToken.updateReportedVisibilityLocked();
2564 }
2565 outFrame.set(win.mFrame);
2566 outContentInsets.set(win.mContentInsets);
2567 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002568 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002569 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002570 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002571 + ", requestedHeight=" + requestedHeight
2572 + ", viewVisibility=" + viewVisibility
2573 + "\nRelayout returning frame=" + outFrame
2574 + ", surface=" + outSurface);
2575
Joe Onorato8a9b2202010-02-26 18:56:32 -08002576 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002577 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2578
2579 inTouchMode = mInTouchMode;
2580 }
2581
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002582 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002583 sendNewConfiguration();
2584 }
Romain Guy06882f82009-06-10 13:36:04 -07002585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002586 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002588 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2589 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2590 }
2591
2592 public void finishDrawingWindow(Session session, IWindow client) {
2593 final long origId = Binder.clearCallingIdentity();
2594 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002595 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002596 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002597 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2598 adjustWallpaperWindowsLocked();
2599 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002600 mLayoutNeeded = true;
2601 performLayoutAndPlaceSurfacesLocked();
2602 }
2603 }
2604 Binder.restoreCallingIdentity(origId);
2605 }
2606
2607 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002608 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002609 + (lp != null ? lp.packageName : null)
2610 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2611 if (lp != null && lp.windowAnimations != 0) {
2612 // If this is a system resource, don't try to load it from the
2613 // application resources. It is nice to avoid loading application
2614 // resources if we can.
2615 String packageName = lp.packageName != null ? lp.packageName : "android";
2616 int resId = lp.windowAnimations;
2617 if ((resId&0xFF000000) == 0x01000000) {
2618 packageName = "android";
2619 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002620 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002621 + packageName);
2622 return AttributeCache.instance().get(packageName, resId,
2623 com.android.internal.R.styleable.WindowAnimation);
2624 }
2625 return null;
2626 }
Romain Guy06882f82009-06-10 13:36:04 -07002627
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002628 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002629 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002630 + packageName + " resId=0x" + Integer.toHexString(resId));
2631 if (packageName != null) {
2632 if ((resId&0xFF000000) == 0x01000000) {
2633 packageName = "android";
2634 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002635 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002636 + packageName);
2637 return AttributeCache.instance().get(packageName, resId,
2638 com.android.internal.R.styleable.WindowAnimation);
2639 }
2640 return null;
2641 }
2642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002643 private void applyEnterAnimationLocked(WindowState win) {
2644 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2645 if (win.mEnterAnimationPending) {
2646 win.mEnterAnimationPending = false;
2647 transit = WindowManagerPolicy.TRANSIT_ENTER;
2648 }
2649
2650 applyAnimationLocked(win, transit, true);
2651 }
2652
2653 private boolean applyAnimationLocked(WindowState win,
2654 int transit, boolean isEntrance) {
2655 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2656 // If we are trying to apply an animation, but already running
2657 // an animation of the same type, then just leave that one alone.
2658 return true;
2659 }
Romain Guy06882f82009-06-10 13:36:04 -07002660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002661 // Only apply an animation if the display isn't frozen. If it is
2662 // frozen, there is no reason to animate and it can cause strange
2663 // artifacts when we unfreeze the display if some different animation
2664 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002665 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002666 int anim = mPolicy.selectAnimationLw(win, transit);
2667 int attr = -1;
2668 Animation a = null;
2669 if (anim != 0) {
2670 a = AnimationUtils.loadAnimation(mContext, anim);
2671 } else {
2672 switch (transit) {
2673 case WindowManagerPolicy.TRANSIT_ENTER:
2674 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2675 break;
2676 case WindowManagerPolicy.TRANSIT_EXIT:
2677 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2678 break;
2679 case WindowManagerPolicy.TRANSIT_SHOW:
2680 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2681 break;
2682 case WindowManagerPolicy.TRANSIT_HIDE:
2683 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2684 break;
2685 }
2686 if (attr >= 0) {
2687 a = loadAnimation(win.mAttrs, attr);
2688 }
2689 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002690 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002691 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2692 + " mAnimation=" + win.mAnimation
2693 + " isEntrance=" + isEntrance);
2694 if (a != null) {
2695 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002696 RuntimeException e = null;
2697 if (!HIDE_STACK_CRAWLS) {
2698 e = new RuntimeException();
2699 e.fillInStackTrace();
2700 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002701 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002702 }
2703 win.setAnimation(a);
2704 win.mAnimationIsEntrance = isEntrance;
2705 }
2706 } else {
2707 win.clearAnimation();
2708 }
2709
2710 return win.mAnimation != null;
2711 }
2712
2713 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2714 int anim = 0;
2715 Context context = mContext;
2716 if (animAttr >= 0) {
2717 AttributeCache.Entry ent = getCachedAnimations(lp);
2718 if (ent != null) {
2719 context = ent.context;
2720 anim = ent.array.getResourceId(animAttr, 0);
2721 }
2722 }
2723 if (anim != 0) {
2724 return AnimationUtils.loadAnimation(context, anim);
2725 }
2726 return null;
2727 }
Romain Guy06882f82009-06-10 13:36:04 -07002728
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002729 private Animation loadAnimation(String packageName, int resId) {
2730 int anim = 0;
2731 Context context = mContext;
2732 if (resId >= 0) {
2733 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2734 if (ent != null) {
2735 context = ent.context;
2736 anim = resId;
2737 }
2738 }
2739 if (anim != 0) {
2740 return AnimationUtils.loadAnimation(context, anim);
2741 }
2742 return null;
2743 }
2744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002745 private boolean applyAnimationLocked(AppWindowToken wtoken,
2746 WindowManager.LayoutParams lp, int transit, boolean enter) {
2747 // Only apply an animation if the display isn't frozen. If it is
2748 // frozen, there is no reason to animate and it can cause strange
2749 // artifacts when we unfreeze the display if some different animation
2750 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002751 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002752 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002753 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002754 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002755 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002756 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002757 } else if (mNextAppTransitionPackage != null) {
2758 a = loadAnimation(mNextAppTransitionPackage, enter ?
2759 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002760 } else {
2761 int animAttr = 0;
2762 switch (transit) {
2763 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2764 animAttr = enter
2765 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2766 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2767 break;
2768 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2769 animAttr = enter
2770 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2771 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2772 break;
2773 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2774 animAttr = enter
2775 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2776 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2777 break;
2778 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2779 animAttr = enter
2780 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2781 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2782 break;
2783 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2784 animAttr = enter
2785 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2786 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2787 break;
2788 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2789 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002790 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002791 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2792 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002793 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002794 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002795 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2796 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002797 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002798 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002799 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002800 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2801 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2802 break;
2803 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2804 animAttr = enter
2805 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2806 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2807 break;
2808 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2809 animAttr = enter
2810 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2811 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002812 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002813 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002814 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002815 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002816 + " anim=" + a
2817 + " animAttr=0x" + Integer.toHexString(animAttr)
2818 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002819 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002820 if (a != null) {
2821 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002822 RuntimeException e = null;
2823 if (!HIDE_STACK_CRAWLS) {
2824 e = new RuntimeException();
2825 e.fillInStackTrace();
2826 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002827 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002828 }
2829 wtoken.setAnimation(a);
2830 }
2831 } else {
2832 wtoken.clearAnimation();
2833 }
2834
2835 return wtoken.animation != null;
2836 }
2837
2838 // -------------------------------------------------------------
2839 // Application Window Tokens
2840 // -------------------------------------------------------------
2841
2842 public void validateAppTokens(List tokens) {
2843 int v = tokens.size()-1;
2844 int m = mAppTokens.size()-1;
2845 while (v >= 0 && m >= 0) {
2846 AppWindowToken wtoken = mAppTokens.get(m);
2847 if (wtoken.removed) {
2848 m--;
2849 continue;
2850 }
2851 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002852 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002853 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2854 }
2855 v--;
2856 m--;
2857 }
2858 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002859 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 v--;
2861 }
2862 while (m >= 0) {
2863 AppWindowToken wtoken = mAppTokens.get(m);
2864 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002865 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002866 }
2867 m--;
2868 }
2869 }
2870
2871 boolean checkCallingPermission(String permission, String func) {
2872 // Quick check: if the calling permission is me, it's all okay.
2873 if (Binder.getCallingPid() == Process.myPid()) {
2874 return true;
2875 }
Romain Guy06882f82009-06-10 13:36:04 -07002876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002877 if (mContext.checkCallingPermission(permission)
2878 == PackageManager.PERMISSION_GRANTED) {
2879 return true;
2880 }
2881 String msg = "Permission Denial: " + func + " from pid="
2882 + Binder.getCallingPid()
2883 + ", uid=" + Binder.getCallingUid()
2884 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002885 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002886 return false;
2887 }
Romain Guy06882f82009-06-10 13:36:04 -07002888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002889 AppWindowToken findAppWindowToken(IBinder token) {
2890 WindowToken wtoken = mTokenMap.get(token);
2891 if (wtoken == null) {
2892 return null;
2893 }
2894 return wtoken.appWindowToken;
2895 }
Romain Guy06882f82009-06-10 13:36:04 -07002896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002897 public void addWindowToken(IBinder token, int type) {
2898 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2899 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002900 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002901 }
Romain Guy06882f82009-06-10 13:36:04 -07002902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002903 synchronized(mWindowMap) {
2904 WindowToken wtoken = mTokenMap.get(token);
2905 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002906 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002907 return;
2908 }
2909 wtoken = new WindowToken(token, type, true);
2910 mTokenMap.put(token, wtoken);
2911 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002912 if (type == TYPE_WALLPAPER) {
2913 mWallpaperTokens.add(wtoken);
2914 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002915 }
2916 }
Romain Guy06882f82009-06-10 13:36:04 -07002917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002918 public void removeWindowToken(IBinder token) {
2919 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2920 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002921 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002922 }
2923
2924 final long origId = Binder.clearCallingIdentity();
2925 synchronized(mWindowMap) {
2926 WindowToken wtoken = mTokenMap.remove(token);
2927 mTokenList.remove(wtoken);
2928 if (wtoken != null) {
2929 boolean delayed = false;
2930 if (!wtoken.hidden) {
2931 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002933 final int N = wtoken.windows.size();
2934 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002936 for (int i=0; i<N; i++) {
2937 WindowState win = wtoken.windows.get(i);
2938
2939 if (win.isAnimating()) {
2940 delayed = true;
2941 }
Romain Guy06882f82009-06-10 13:36:04 -07002942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002943 if (win.isVisibleNow()) {
2944 applyAnimationLocked(win,
2945 WindowManagerPolicy.TRANSIT_EXIT, false);
2946 mKeyWaiter.finishedKey(win.mSession, win.mClient, true,
2947 KeyWaiter.RETURN_NOTHING);
2948 changed = true;
2949 }
2950 }
2951
2952 if (changed) {
2953 mLayoutNeeded = true;
2954 performLayoutAndPlaceSurfacesLocked();
2955 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2956 }
Romain Guy06882f82009-06-10 13:36:04 -07002957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002958 if (delayed) {
2959 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002960 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2961 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002962 }
2963 }
Romain Guy06882f82009-06-10 13:36:04 -07002964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002965 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002966 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002967 }
2968 }
2969 Binder.restoreCallingIdentity(origId);
2970 }
2971
2972 public void addAppToken(int addPos, IApplicationToken token,
2973 int groupId, int requestedOrientation, boolean fullscreen) {
2974 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2975 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002976 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002977 }
Romain Guy06882f82009-06-10 13:36:04 -07002978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002979 synchronized(mWindowMap) {
2980 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2981 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002982 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002983 return;
2984 }
2985 wtoken = new AppWindowToken(token);
2986 wtoken.groupId = groupId;
2987 wtoken.appFullscreen = fullscreen;
2988 wtoken.requestedOrientation = requestedOrientation;
2989 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002990 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002991 mTokenMap.put(token.asBinder(), wtoken);
2992 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002994 // Application tokens start out hidden.
2995 wtoken.hidden = true;
2996 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002998 //dump();
2999 }
3000 }
Romain Guy06882f82009-06-10 13:36:04 -07003001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003002 public void setAppGroupId(IBinder token, int groupId) {
3003 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3004 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003005 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003006 }
3007
3008 synchronized(mWindowMap) {
3009 AppWindowToken wtoken = findAppWindowToken(token);
3010 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003011 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003012 return;
3013 }
3014 wtoken.groupId = groupId;
3015 }
3016 }
Romain Guy06882f82009-06-10 13:36:04 -07003017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003018 public int getOrientationFromWindowsLocked() {
3019 int pos = mWindows.size() - 1;
3020 while (pos >= 0) {
3021 WindowState wtoken = (WindowState) mWindows.get(pos);
3022 pos--;
3023 if (wtoken.mAppToken != null) {
3024 // We hit an application window. so the orientation will be determined by the
3025 // app window. No point in continuing further.
3026 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3027 }
3028 if (!wtoken.isVisibleLw()) {
3029 continue;
3030 }
3031 int req = wtoken.mAttrs.screenOrientation;
3032 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3033 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3034 continue;
3035 } else {
3036 return req;
3037 }
3038 }
3039 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3040 }
Romain Guy06882f82009-06-10 13:36:04 -07003041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003042 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003043 int pos = mAppTokens.size() - 1;
3044 int curGroup = 0;
3045 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3046 boolean findingBehind = false;
3047 boolean haveGroup = false;
3048 boolean lastFullscreen = false;
3049 while (pos >= 0) {
3050 AppWindowToken wtoken = mAppTokens.get(pos);
3051 pos--;
3052 // if we're about to tear down this window and not seek for
3053 // the behind activity, don't use it for orientation
3054 if (!findingBehind
3055 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3056 continue;
3057 }
3058
3059 if (!haveGroup) {
3060 // We ignore any hidden applications on the top.
3061 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003062 continue;
3063 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003064 haveGroup = true;
3065 curGroup = wtoken.groupId;
3066 lastOrientation = wtoken.requestedOrientation;
3067 } else if (curGroup != wtoken.groupId) {
3068 // If we have hit a new application group, and the bottom
3069 // of the previous group didn't explicitly say to use
3070 // the orientation behind it, and the last app was
3071 // full screen, then we'll stick with the
3072 // user's orientation.
3073 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3074 && lastFullscreen) {
3075 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003076 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003077 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003078 int or = wtoken.requestedOrientation;
3079 // If this application is fullscreen, and didn't explicitly say
3080 // to use the orientation behind it, then just take whatever
3081 // orientation it has and ignores whatever is under it.
3082 lastFullscreen = wtoken.appFullscreen;
3083 if (lastFullscreen
3084 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3085 return or;
3086 }
3087 // If this application has requested an explicit orientation,
3088 // then use it.
3089 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3090 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3091 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3092 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3093 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3094 return or;
3095 }
3096 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3097 }
3098 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003099 }
Romain Guy06882f82009-06-10 13:36:04 -07003100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003101 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003102 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003103 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3104 "updateOrientationFromAppTokens()")) {
3105 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3106 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003107
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003108 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003109 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003110
3111 synchronized(mWindowMap) {
3112 if (updateOrientationFromAppTokensLocked()) {
3113 if (freezeThisOneIfNeeded != null) {
3114 AppWindowToken wtoken = findAppWindowToken(
3115 freezeThisOneIfNeeded);
3116 if (wtoken != null) {
3117 startAppFreezingScreenLocked(wtoken,
3118 ActivityInfo.CONFIG_ORIENTATION);
3119 }
3120 }
3121 config = computeNewConfigurationLocked();
3122
3123 } else if (currentConfig != null) {
3124 // No obvious action we need to take, but if our current
3125 // state mismatches the activity maanager's, update it
3126 mTempConfiguration.setToDefaults();
3127 if (computeNewConfigurationLocked(mTempConfiguration)) {
3128 if (currentConfig.diff(mTempConfiguration) != 0) {
3129 mWaitingForConfig = true;
3130 mLayoutNeeded = true;
3131 startFreezingDisplayLocked();
3132 config = new Configuration(mTempConfiguration);
3133 }
3134 }
3135 }
3136 }
3137
Dianne Hackborncfaef692009-06-15 14:24:44 -07003138 Binder.restoreCallingIdentity(ident);
3139 return config;
3140 }
3141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003142 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003143 * Determine the new desired orientation of the display, returning
3144 * a non-null new Configuration if it has changed from the current
3145 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3146 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3147 * SCREEN. This will typically be done for you if you call
3148 * sendNewConfiguration().
3149 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003150 * The orientation is computed from non-application windows first. If none of
3151 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003152 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003153 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3154 * android.os.IBinder)
3155 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003156 boolean updateOrientationFromAppTokensLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003157 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003158 long ident = Binder.clearCallingIdentity();
3159 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003160 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003162 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003163 mForcedAppOrientation = req;
3164 //send a message to Policy indicating orientation change to take
3165 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003166 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003167 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3168 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3169 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003170 }
3171 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003172
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003173 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003174 } finally {
3175 Binder.restoreCallingIdentity(ident);
3176 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003177 }
Romain Guy06882f82009-06-10 13:36:04 -07003178
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003179 int computeForcedAppOrientationLocked() {
3180 int req = getOrientationFromWindowsLocked();
3181 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3182 req = getOrientationFromAppTokensLocked();
3183 }
3184 return req;
3185 }
Romain Guy06882f82009-06-10 13:36:04 -07003186
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003187 public void setNewConfiguration(Configuration config) {
3188 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3189 "setNewConfiguration()")) {
3190 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3191 }
3192
3193 synchronized(mWindowMap) {
3194 mCurConfiguration = new Configuration(config);
3195 mWaitingForConfig = false;
3196 performLayoutAndPlaceSurfacesLocked();
3197 }
3198 }
3199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003200 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3201 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3202 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003203 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003204 }
Romain Guy06882f82009-06-10 13:36:04 -07003205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003206 synchronized(mWindowMap) {
3207 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3208 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003209 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003210 return;
3211 }
Romain Guy06882f82009-06-10 13:36:04 -07003212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003213 wtoken.requestedOrientation = requestedOrientation;
3214 }
3215 }
Romain Guy06882f82009-06-10 13:36:04 -07003216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003217 public int getAppOrientation(IApplicationToken token) {
3218 synchronized(mWindowMap) {
3219 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3220 if (wtoken == null) {
3221 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3222 }
Romain Guy06882f82009-06-10 13:36:04 -07003223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003224 return wtoken.requestedOrientation;
3225 }
3226 }
Romain Guy06882f82009-06-10 13:36:04 -07003227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003228 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3229 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3230 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003231 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003232 }
3233
3234 synchronized(mWindowMap) {
3235 boolean changed = false;
3236 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003237 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003238 changed = mFocusedApp != null;
3239 mFocusedApp = null;
3240 mKeyWaiter.tickle();
3241 } else {
3242 AppWindowToken newFocus = findAppWindowToken(token);
3243 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003244 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003245 return;
3246 }
3247 changed = mFocusedApp != newFocus;
3248 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003249 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003250 mKeyWaiter.tickle();
3251 }
3252
3253 if (moveFocusNow && changed) {
3254 final long origId = Binder.clearCallingIdentity();
3255 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3256 Binder.restoreCallingIdentity(origId);
3257 }
3258 }
3259 }
3260
3261 public void prepareAppTransition(int transit) {
3262 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3263 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003264 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003265 }
Romain Guy06882f82009-06-10 13:36:04 -07003266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003267 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003268 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003269 TAG, "Prepare app transition: transit=" + transit
3270 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003271 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003272 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3273 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003274 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003275 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3276 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3277 // Opening a new task always supersedes a close for the anim.
3278 mNextAppTransition = transit;
3279 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3280 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3281 // Opening a new activity always supersedes a close for the anim.
3282 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003283 }
3284 mAppTransitionReady = false;
3285 mAppTransitionTimeout = false;
3286 mStartingIconInTransition = false;
3287 mSkipAppTransitionAnimation = false;
3288 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3289 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3290 5000);
3291 }
3292 }
3293 }
3294
3295 public int getPendingAppTransition() {
3296 return mNextAppTransition;
3297 }
Romain Guy06882f82009-06-10 13:36:04 -07003298
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003299 public void overridePendingAppTransition(String packageName,
3300 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003301 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003302 mNextAppTransitionPackage = packageName;
3303 mNextAppTransitionEnter = enterAnim;
3304 mNextAppTransitionExit = exitAnim;
3305 }
3306 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 public void executeAppTransition() {
3309 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3310 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003311 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003312 }
Romain Guy06882f82009-06-10 13:36:04 -07003313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003314 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003315 if (DEBUG_APP_TRANSITIONS) {
3316 RuntimeException e = new RuntimeException("here");
3317 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003318 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003319 + mNextAppTransition, e);
3320 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003321 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003322 mAppTransitionReady = true;
3323 final long origId = Binder.clearCallingIdentity();
3324 performLayoutAndPlaceSurfacesLocked();
3325 Binder.restoreCallingIdentity(origId);
3326 }
3327 }
3328 }
3329
3330 public void setAppStartingWindow(IBinder token, String pkg,
3331 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3332 IBinder transferFrom, boolean createIfNeeded) {
3333 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3334 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003335 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003336 }
3337
3338 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003339 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003340 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3341 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003343 AppWindowToken wtoken = findAppWindowToken(token);
3344 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003345 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003346 return;
3347 }
3348
3349 // If the display is frozen, we won't do anything until the
3350 // actual window is displayed so there is no reason to put in
3351 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003352 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003353 return;
3354 }
Romain Guy06882f82009-06-10 13:36:04 -07003355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003356 if (wtoken.startingData != null) {
3357 return;
3358 }
Romain Guy06882f82009-06-10 13:36:04 -07003359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003360 if (transferFrom != null) {
3361 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3362 if (ttoken != null) {
3363 WindowState startingWindow = ttoken.startingWindow;
3364 if (startingWindow != null) {
3365 if (mStartingIconInTransition) {
3366 // In this case, the starting icon has already
3367 // been displayed, so start letting windows get
3368 // shown immediately without any more transitions.
3369 mSkipAppTransitionAnimation = true;
3370 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003371 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003372 "Moving existing starting from " + ttoken
3373 + " to " + wtoken);
3374 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003376 // Transfer the starting window over to the new
3377 // token.
3378 wtoken.startingData = ttoken.startingData;
3379 wtoken.startingView = ttoken.startingView;
3380 wtoken.startingWindow = startingWindow;
3381 ttoken.startingData = null;
3382 ttoken.startingView = null;
3383 ttoken.startingWindow = null;
3384 ttoken.startingMoved = true;
3385 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003386 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003387 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003388 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003389 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003390 mWindows.remove(startingWindow);
3391 ttoken.windows.remove(startingWindow);
3392 ttoken.allAppWindows.remove(startingWindow);
3393 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003395 // Propagate other interesting state between the
3396 // tokens. If the old token is displayed, we should
3397 // immediately force the new one to be displayed. If
3398 // it is animating, we need to move that animation to
3399 // the new one.
3400 if (ttoken.allDrawn) {
3401 wtoken.allDrawn = true;
3402 }
3403 if (ttoken.firstWindowDrawn) {
3404 wtoken.firstWindowDrawn = true;
3405 }
3406 if (!ttoken.hidden) {
3407 wtoken.hidden = false;
3408 wtoken.hiddenRequested = false;
3409 wtoken.willBeHidden = false;
3410 }
3411 if (wtoken.clientHidden != ttoken.clientHidden) {
3412 wtoken.clientHidden = ttoken.clientHidden;
3413 wtoken.sendAppVisibilityToClients();
3414 }
3415 if (ttoken.animation != null) {
3416 wtoken.animation = ttoken.animation;
3417 wtoken.animating = ttoken.animating;
3418 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3419 ttoken.animation = null;
3420 ttoken.animLayerAdjustment = 0;
3421 wtoken.updateLayers();
3422 ttoken.updateLayers();
3423 }
Romain Guy06882f82009-06-10 13:36:04 -07003424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003425 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003426 mLayoutNeeded = true;
3427 performLayoutAndPlaceSurfacesLocked();
3428 Binder.restoreCallingIdentity(origId);
3429 return;
3430 } else if (ttoken.startingData != null) {
3431 // The previous app was getting ready to show a
3432 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003433 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003434 "Moving pending starting from " + ttoken
3435 + " to " + wtoken);
3436 wtoken.startingData = ttoken.startingData;
3437 ttoken.startingData = null;
3438 ttoken.startingMoved = true;
3439 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3440 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3441 // want to process the message ASAP, before any other queued
3442 // messages.
3443 mH.sendMessageAtFrontOfQueue(m);
3444 return;
3445 }
3446 }
3447 }
3448
3449 // There is no existing starting window, and the caller doesn't
3450 // want us to create one, so that's it!
3451 if (!createIfNeeded) {
3452 return;
3453 }
Romain Guy06882f82009-06-10 13:36:04 -07003454
Dianne Hackborn284ac932009-08-28 10:34:25 -07003455 // If this is a translucent or wallpaper window, then don't
3456 // show a starting window -- the current effect (a full-screen
3457 // opaque starting window that fades away to the real contents
3458 // when it is ready) does not work for this.
3459 if (theme != 0) {
3460 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3461 com.android.internal.R.styleable.Window);
3462 if (ent.array.getBoolean(
3463 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3464 return;
3465 }
3466 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003467 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3468 return;
3469 }
3470 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003471 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3472 return;
3473 }
3474 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003476 mStartingIconInTransition = true;
3477 wtoken.startingData = new StartingData(
3478 pkg, theme, nonLocalizedLabel,
3479 labelRes, icon);
3480 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3481 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3482 // want to process the message ASAP, before any other queued
3483 // messages.
3484 mH.sendMessageAtFrontOfQueue(m);
3485 }
3486 }
3487
3488 public void setAppWillBeHidden(IBinder token) {
3489 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3490 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003491 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003492 }
3493
3494 AppWindowToken wtoken;
3495
3496 synchronized(mWindowMap) {
3497 wtoken = findAppWindowToken(token);
3498 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003499 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 -08003500 return;
3501 }
3502 wtoken.willBeHidden = true;
3503 }
3504 }
Romain Guy06882f82009-06-10 13:36:04 -07003505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003506 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3507 boolean visible, int transit, boolean performLayout) {
3508 boolean delayed = false;
3509
3510 if (wtoken.clientHidden == visible) {
3511 wtoken.clientHidden = !visible;
3512 wtoken.sendAppVisibilityToClients();
3513 }
Romain Guy06882f82009-06-10 13:36:04 -07003514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003515 wtoken.willBeHidden = false;
3516 if (wtoken.hidden == visible) {
3517 final int N = wtoken.allAppWindows.size();
3518 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003519 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003520 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3521 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003523 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003524
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003525 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003526 if (wtoken.animation == sDummyAnimation) {
3527 wtoken.animation = null;
3528 }
3529 applyAnimationLocked(wtoken, lp, transit, visible);
3530 changed = true;
3531 if (wtoken.animation != null) {
3532 delayed = runningAppAnimation = true;
3533 }
3534 }
Romain Guy06882f82009-06-10 13:36:04 -07003535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003536 for (int i=0; i<N; i++) {
3537 WindowState win = wtoken.allAppWindows.get(i);
3538 if (win == wtoken.startingWindow) {
3539 continue;
3540 }
3541
3542 if (win.isAnimating()) {
3543 delayed = true;
3544 }
Romain Guy06882f82009-06-10 13:36:04 -07003545
Joe Onorato8a9b2202010-02-26 18:56:32 -08003546 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003547 //win.dump(" ");
3548 if (visible) {
3549 if (!win.isVisibleNow()) {
3550 if (!runningAppAnimation) {
3551 applyAnimationLocked(win,
3552 WindowManagerPolicy.TRANSIT_ENTER, true);
3553 }
3554 changed = true;
3555 }
3556 } else if (win.isVisibleNow()) {
3557 if (!runningAppAnimation) {
3558 applyAnimationLocked(win,
3559 WindowManagerPolicy.TRANSIT_EXIT, false);
3560 }
3561 mKeyWaiter.finishedKey(win.mSession, win.mClient, true,
3562 KeyWaiter.RETURN_NOTHING);
3563 changed = true;
3564 }
3565 }
3566
3567 wtoken.hidden = wtoken.hiddenRequested = !visible;
3568 if (!visible) {
3569 unsetAppFreezingScreenLocked(wtoken, true, true);
3570 } else {
3571 // If we are being set visible, and the starting window is
3572 // not yet displayed, then make sure it doesn't get displayed.
3573 WindowState swin = wtoken.startingWindow;
3574 if (swin != null && (swin.mDrawPending
3575 || swin.mCommitDrawPending)) {
3576 swin.mPolicyVisibility = false;
3577 swin.mPolicyVisibilityAfterAnim = false;
3578 }
3579 }
Romain Guy06882f82009-06-10 13:36:04 -07003580
Joe Onorato8a9b2202010-02-26 18:56:32 -08003581 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003582 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3583 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003584
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003585 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003586 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003587 if (performLayout) {
3588 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3589 performLayoutAndPlaceSurfacesLocked();
3590 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003591 }
3592 }
3593
3594 if (wtoken.animation != null) {
3595 delayed = true;
3596 }
Romain Guy06882f82009-06-10 13:36:04 -07003597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003598 return delayed;
3599 }
3600
3601 public void setAppVisibility(IBinder token, boolean visible) {
3602 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3603 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003604 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003605 }
3606
3607 AppWindowToken wtoken;
3608
3609 synchronized(mWindowMap) {
3610 wtoken = findAppWindowToken(token);
3611 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003612 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003613 return;
3614 }
3615
3616 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003617 RuntimeException e = null;
3618 if (!HIDE_STACK_CRAWLS) {
3619 e = new RuntimeException();
3620 e.fillInStackTrace();
3621 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003622 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003623 + "): mNextAppTransition=" + mNextAppTransition
3624 + " hidden=" + wtoken.hidden
3625 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3626 }
Romain Guy06882f82009-06-10 13:36:04 -07003627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003628 // If we are preparing an app transition, then delay changing
3629 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003630 if (!mDisplayFrozen && mPolicy.isScreenOn()
3631 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003632 // Already in requested state, don't do anything more.
3633 if (wtoken.hiddenRequested != visible) {
3634 return;
3635 }
3636 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003637
Joe Onorato8a9b2202010-02-26 18:56:32 -08003638 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003639 TAG, "Setting dummy animation on: " + wtoken);
3640 wtoken.setDummyAnimation();
3641 mOpeningApps.remove(wtoken);
3642 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003643 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003644 wtoken.inPendingTransaction = true;
3645 if (visible) {
3646 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003647 wtoken.startingDisplayed = false;
3648 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003649
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003650 // If the token is currently hidden (should be the
3651 // common case), then we need to set up to wait for
3652 // its windows to be ready.
3653 if (wtoken.hidden) {
3654 wtoken.allDrawn = false;
3655 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003656
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003657 if (wtoken.clientHidden) {
3658 // In the case where we are making an app visible
3659 // but holding off for a transition, we still need
3660 // to tell the client to make its windows visible so
3661 // they get drawn. Otherwise, we will wait on
3662 // performing the transition until all windows have
3663 // been drawn, they never will be, and we are sad.
3664 wtoken.clientHidden = false;
3665 wtoken.sendAppVisibilityToClients();
3666 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003667 }
3668 } else {
3669 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003670
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003671 // If the token is currently visible (should be the
3672 // common case), then set up to wait for it to be hidden.
3673 if (!wtoken.hidden) {
3674 wtoken.waitingToHide = true;
3675 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003676 }
3677 return;
3678 }
Romain Guy06882f82009-06-10 13:36:04 -07003679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003680 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003681 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003682 wtoken.updateReportedVisibilityLocked();
3683 Binder.restoreCallingIdentity(origId);
3684 }
3685 }
3686
3687 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3688 boolean unfreezeSurfaceNow, boolean force) {
3689 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003690 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003691 + " force=" + force);
3692 final int N = wtoken.allAppWindows.size();
3693 boolean unfrozeWindows = false;
3694 for (int i=0; i<N; i++) {
3695 WindowState w = wtoken.allAppWindows.get(i);
3696 if (w.mAppFreezing) {
3697 w.mAppFreezing = false;
3698 if (w.mSurface != null && !w.mOrientationChanging) {
3699 w.mOrientationChanging = true;
3700 }
3701 unfrozeWindows = true;
3702 }
3703 }
3704 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003705 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003706 wtoken.freezingScreen = false;
3707 mAppsFreezingScreen--;
3708 }
3709 if (unfreezeSurfaceNow) {
3710 if (unfrozeWindows) {
3711 mLayoutNeeded = true;
3712 performLayoutAndPlaceSurfacesLocked();
3713 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003714 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003715 }
3716 }
3717 }
Romain Guy06882f82009-06-10 13:36:04 -07003718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003719 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3720 int configChanges) {
3721 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003722 RuntimeException e = null;
3723 if (!HIDE_STACK_CRAWLS) {
3724 e = new RuntimeException();
3725 e.fillInStackTrace();
3726 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003727 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003728 + ": hidden=" + wtoken.hidden + " freezing="
3729 + wtoken.freezingScreen, e);
3730 }
3731 if (!wtoken.hiddenRequested) {
3732 if (!wtoken.freezingScreen) {
3733 wtoken.freezingScreen = true;
3734 mAppsFreezingScreen++;
3735 if (mAppsFreezingScreen == 1) {
3736 startFreezingDisplayLocked();
3737 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3738 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3739 5000);
3740 }
3741 }
3742 final int N = wtoken.allAppWindows.size();
3743 for (int i=0; i<N; i++) {
3744 WindowState w = wtoken.allAppWindows.get(i);
3745 w.mAppFreezing = true;
3746 }
3747 }
3748 }
Romain Guy06882f82009-06-10 13:36:04 -07003749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003750 public void startAppFreezingScreen(IBinder token, int configChanges) {
3751 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3752 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003753 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003754 }
3755
3756 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003757 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003758 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003759 return;
3760 }
Romain Guy06882f82009-06-10 13:36:04 -07003761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003762 AppWindowToken wtoken = findAppWindowToken(token);
3763 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003764 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003765 return;
3766 }
3767 final long origId = Binder.clearCallingIdentity();
3768 startAppFreezingScreenLocked(wtoken, configChanges);
3769 Binder.restoreCallingIdentity(origId);
3770 }
3771 }
Romain Guy06882f82009-06-10 13:36:04 -07003772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003773 public void stopAppFreezingScreen(IBinder token, boolean force) {
3774 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3775 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003776 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003777 }
3778
3779 synchronized(mWindowMap) {
3780 AppWindowToken wtoken = findAppWindowToken(token);
3781 if (wtoken == null || wtoken.appToken == null) {
3782 return;
3783 }
3784 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003785 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003786 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3787 unsetAppFreezingScreenLocked(wtoken, true, force);
3788 Binder.restoreCallingIdentity(origId);
3789 }
3790 }
Romain Guy06882f82009-06-10 13:36:04 -07003791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003792 public void removeAppToken(IBinder token) {
3793 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3794 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003795 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003796 }
3797
3798 AppWindowToken wtoken = null;
3799 AppWindowToken startingToken = null;
3800 boolean delayed = false;
3801
3802 final long origId = Binder.clearCallingIdentity();
3803 synchronized(mWindowMap) {
3804 WindowToken basewtoken = mTokenMap.remove(token);
3805 mTokenList.remove(basewtoken);
3806 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003807 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003808 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003809 wtoken.inPendingTransaction = false;
3810 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003811 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003812 if (mClosingApps.contains(wtoken)) {
3813 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003814 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003815 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003816 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003817 delayed = true;
3818 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003819 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003820 TAG, "Removing app " + wtoken + " delayed=" + delayed
3821 + " animation=" + wtoken.animation
3822 + " animating=" + wtoken.animating);
3823 if (delayed) {
3824 // set the token aside because it has an active animation to be finished
3825 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003826 } else {
3827 // Make sure there is no animation running on this token,
3828 // so any windows associated with it will be removed as
3829 // soon as their animations are complete
3830 wtoken.animation = null;
3831 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003832 }
3833 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003834 if (mLastEnterAnimToken == wtoken) {
3835 mLastEnterAnimToken = null;
3836 mLastEnterAnimParams = null;
3837 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003838 wtoken.removed = true;
3839 if (wtoken.startingData != null) {
3840 startingToken = wtoken;
3841 }
3842 unsetAppFreezingScreenLocked(wtoken, true, true);
3843 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003844 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003845 mFocusedApp = null;
3846 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3847 mKeyWaiter.tickle();
3848 }
3849 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003850 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003851 }
Romain Guy06882f82009-06-10 13:36:04 -07003852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003853 if (!delayed && wtoken != null) {
3854 wtoken.updateReportedVisibilityLocked();
3855 }
3856 }
3857 Binder.restoreCallingIdentity(origId);
3858
3859 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003860 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003861 + startingToken + ": app token removed");
3862 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3863 mH.sendMessage(m);
3864 }
3865 }
3866
3867 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3868 final int NW = token.windows.size();
3869 for (int i=0; i<NW; i++) {
3870 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003871 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003872 mWindows.remove(win);
3873 int j = win.mChildWindows.size();
3874 while (j > 0) {
3875 j--;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003876 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003877 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003878 "Tmp removing child window " + cwin);
3879 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003880 }
3881 }
3882 return NW > 0;
3883 }
3884
3885 void dumpAppTokensLocked() {
3886 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003887 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003888 }
3889 }
Romain Guy06882f82009-06-10 13:36:04 -07003890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003891 void dumpWindowsLocked() {
3892 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003893 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003894 }
3895 }
Romain Guy06882f82009-06-10 13:36:04 -07003896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003897 private int findWindowOffsetLocked(int tokenPos) {
3898 final int NW = mWindows.size();
3899
3900 if (tokenPos >= mAppTokens.size()) {
3901 int i = NW;
3902 while (i > 0) {
3903 i--;
3904 WindowState win = (WindowState)mWindows.get(i);
3905 if (win.getAppToken() != null) {
3906 return i+1;
3907 }
3908 }
3909 }
3910
3911 while (tokenPos > 0) {
3912 // Find the first app token below the new position that has
3913 // a window displayed.
3914 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003915 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003916 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003917 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003918 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003919 "Skipping token -- currently sending to bottom");
3920 tokenPos--;
3921 continue;
3922 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003923 int i = wtoken.windows.size();
3924 while (i > 0) {
3925 i--;
3926 WindowState win = wtoken.windows.get(i);
3927 int j = win.mChildWindows.size();
3928 while (j > 0) {
3929 j--;
3930 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003931 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003932 for (int pos=NW-1; pos>=0; pos--) {
3933 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003934 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003935 "Found child win @" + (pos+1));
3936 return pos+1;
3937 }
3938 }
3939 }
3940 }
3941 for (int pos=NW-1; pos>=0; pos--) {
3942 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003943 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003944 return pos+1;
3945 }
3946 }
3947 }
3948 tokenPos--;
3949 }
3950
3951 return 0;
3952 }
3953
3954 private final int reAddWindowLocked(int index, WindowState win) {
3955 final int NCW = win.mChildWindows.size();
3956 boolean added = false;
3957 for (int j=0; j<NCW; j++) {
3958 WindowState cwin = (WindowState)win.mChildWindows.get(j);
3959 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003960 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003961 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003962 mWindows.add(index, win);
3963 index++;
3964 added = true;
3965 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003966 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003967 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003968 mWindows.add(index, cwin);
3969 index++;
3970 }
3971 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003972 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003973 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003974 mWindows.add(index, win);
3975 index++;
3976 }
3977 return index;
3978 }
Romain Guy06882f82009-06-10 13:36:04 -07003979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003980 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3981 final int NW = token.windows.size();
3982 for (int i=0; i<NW; i++) {
3983 index = reAddWindowLocked(index, token.windows.get(i));
3984 }
3985 return index;
3986 }
3987
3988 public void moveAppToken(int index, IBinder token) {
3989 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3990 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003991 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003992 }
3993
3994 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003995 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003996 if (DEBUG_REORDER) dumpAppTokensLocked();
3997 final AppWindowToken wtoken = findAppWindowToken(token);
3998 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003999 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004000 + token + " (" + wtoken + ")");
4001 return;
4002 }
4003 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004004 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004005 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004007 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004008 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004009 if (DEBUG_REORDER) dumpWindowsLocked();
4010 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004011 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004012 if (DEBUG_REORDER) dumpWindowsLocked();
4013 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004014 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004015 if (DEBUG_REORDER) dumpWindowsLocked();
4016 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004017 mLayoutNeeded = true;
4018 performLayoutAndPlaceSurfacesLocked();
4019 }
4020 Binder.restoreCallingIdentity(origId);
4021 }
4022 }
4023
4024 private void removeAppTokensLocked(List<IBinder> tokens) {
4025 // XXX This should be done more efficiently!
4026 // (take advantage of the fact that both lists should be
4027 // ordered in the same way.)
4028 int N = tokens.size();
4029 for (int i=0; i<N; i++) {
4030 IBinder token = tokens.get(i);
4031 final AppWindowToken wtoken = findAppWindowToken(token);
4032 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004033 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004034 + token + " (" + wtoken + ")");
4035 i--;
4036 N--;
4037 }
4038 }
4039 }
4040
Dianne Hackborna8f60182009-09-01 19:01:50 -07004041 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4042 boolean updateFocusAndLayout) {
4043 // First remove all of the windows from the list.
4044 tmpRemoveAppWindowsLocked(wtoken);
4045
4046 // Where to start adding?
4047 int pos = findWindowOffsetLocked(tokenPos);
4048
4049 // And now add them back at the correct place.
4050 pos = reAddAppWindowsLocked(pos, wtoken);
4051
4052 if (updateFocusAndLayout) {
4053 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4054 assignLayersLocked();
4055 }
4056 mLayoutNeeded = true;
4057 performLayoutAndPlaceSurfacesLocked();
4058 }
4059 }
4060
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004061 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4062 // First remove all of the windows from the list.
4063 final int N = tokens.size();
4064 int i;
4065 for (i=0; i<N; i++) {
4066 WindowToken token = mTokenMap.get(tokens.get(i));
4067 if (token != null) {
4068 tmpRemoveAppWindowsLocked(token);
4069 }
4070 }
4071
4072 // Where to start adding?
4073 int pos = findWindowOffsetLocked(tokenPos);
4074
4075 // And now add them back at the correct place.
4076 for (i=0; i<N; i++) {
4077 WindowToken token = mTokenMap.get(tokens.get(i));
4078 if (token != null) {
4079 pos = reAddAppWindowsLocked(pos, token);
4080 }
4081 }
4082
Dianne Hackborna8f60182009-09-01 19:01:50 -07004083 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4084 assignLayersLocked();
4085 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004086 mLayoutNeeded = true;
4087 performLayoutAndPlaceSurfacesLocked();
4088
4089 //dump();
4090 }
4091
4092 public void moveAppTokensToTop(List<IBinder> tokens) {
4093 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4094 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004095 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004096 }
4097
4098 final long origId = Binder.clearCallingIdentity();
4099 synchronized(mWindowMap) {
4100 removeAppTokensLocked(tokens);
4101 final int N = tokens.size();
4102 for (int i=0; i<N; i++) {
4103 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4104 if (wt != null) {
4105 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004106 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004107 mToTopApps.remove(wt);
4108 mToBottomApps.remove(wt);
4109 mToTopApps.add(wt);
4110 wt.sendingToBottom = false;
4111 wt.sendingToTop = true;
4112 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004113 }
4114 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004115
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004116 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004117 moveAppWindowsLocked(tokens, mAppTokens.size());
4118 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004119 }
4120 Binder.restoreCallingIdentity(origId);
4121 }
4122
4123 public void moveAppTokensToBottom(List<IBinder> tokens) {
4124 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4125 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004126 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004127 }
4128
4129 final long origId = Binder.clearCallingIdentity();
4130 synchronized(mWindowMap) {
4131 removeAppTokensLocked(tokens);
4132 final int N = tokens.size();
4133 int pos = 0;
4134 for (int i=0; i<N; i++) {
4135 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4136 if (wt != null) {
4137 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004138 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004139 mToTopApps.remove(wt);
4140 mToBottomApps.remove(wt);
4141 mToBottomApps.add(i, wt);
4142 wt.sendingToTop = false;
4143 wt.sendingToBottom = true;
4144 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004145 pos++;
4146 }
4147 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004148
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004149 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004150 moveAppWindowsLocked(tokens, 0);
4151 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004152 }
4153 Binder.restoreCallingIdentity(origId);
4154 }
4155
4156 // -------------------------------------------------------------
4157 // Misc IWindowSession methods
4158 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004160 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004161 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004162 != PackageManager.PERMISSION_GRANTED) {
4163 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4164 }
Mike Lockwood983ee092009-11-22 01:42:24 -05004165 synchronized (mKeyguardTokenWatcher) {
4166 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004167 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004168 }
4169
4170 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004171 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004172 != PackageManager.PERMISSION_GRANTED) {
4173 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4174 }
Mike Lockwood983ee092009-11-22 01:42:24 -05004175 synchronized (mKeyguardTokenWatcher) {
4176 mKeyguardTokenWatcher.release(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004177
Mike Lockwood983ee092009-11-22 01:42:24 -05004178 if (!mKeyguardTokenWatcher.isAcquired()) {
4179 // If we are the last one to reenable the keyguard wait until
4180 // we have actaully finished reenabling until returning.
4181 // It is possible that reenableKeyguard() can be called before
4182 // the previous disableKeyguard() is handled, in which case
4183 // neither mKeyguardTokenWatcher.acquired() or released() would
4184 // be called. In that case mKeyguardDisabled will be false here
4185 // and we have nothing to wait for.
4186 while (mKeyguardDisabled) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004187 try {
Mike Lockwood983ee092009-11-22 01:42:24 -05004188 mKeyguardTokenWatcher.wait();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004189 } catch (InterruptedException e) {
4190 Thread.currentThread().interrupt();
4191 }
4192 }
4193 }
4194 }
4195 }
4196
4197 /**
4198 * @see android.app.KeyguardManager#exitKeyguardSecurely
4199 */
4200 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004201 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004202 != PackageManager.PERMISSION_GRANTED) {
4203 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4204 }
4205 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4206 public void onKeyguardExitResult(boolean success) {
4207 try {
4208 callback.onKeyguardExitResult(success);
4209 } catch (RemoteException e) {
4210 // Client has died, we don't care.
4211 }
4212 }
4213 });
4214 }
4215
4216 public boolean inKeyguardRestrictedInputMode() {
4217 return mPolicy.inKeyguardRestrictedKeyInputMode();
4218 }
Romain Guy06882f82009-06-10 13:36:04 -07004219
Dianne Hackbornffa42482009-09-23 22:20:11 -07004220 public void closeSystemDialogs(String reason) {
4221 synchronized(mWindowMap) {
4222 for (int i=mWindows.size()-1; i>=0; i--) {
4223 WindowState w = (WindowState)mWindows.get(i);
4224 if (w.mSurface != null) {
4225 try {
4226 w.mClient.closeSystemDialogs(reason);
4227 } catch (RemoteException e) {
4228 }
4229 }
4230 }
4231 }
4232 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004233
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004234 static float fixScale(float scale) {
4235 if (scale < 0) scale = 0;
4236 else if (scale > 20) scale = 20;
4237 return Math.abs(scale);
4238 }
Romain Guy06882f82009-06-10 13:36:04 -07004239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004240 public void setAnimationScale(int which, float scale) {
4241 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4242 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004243 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004244 }
4245
4246 if (scale < 0) scale = 0;
4247 else if (scale > 20) scale = 20;
4248 scale = Math.abs(scale);
4249 switch (which) {
4250 case 0: mWindowAnimationScale = fixScale(scale); break;
4251 case 1: mTransitionAnimationScale = fixScale(scale); break;
4252 }
Romain Guy06882f82009-06-10 13:36:04 -07004253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004254 // Persist setting
4255 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4256 }
Romain Guy06882f82009-06-10 13:36:04 -07004257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004258 public void setAnimationScales(float[] scales) {
4259 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4260 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004261 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004262 }
4263
4264 if (scales != null) {
4265 if (scales.length >= 1) {
4266 mWindowAnimationScale = fixScale(scales[0]);
4267 }
4268 if (scales.length >= 2) {
4269 mTransitionAnimationScale = fixScale(scales[1]);
4270 }
4271 }
Romain Guy06882f82009-06-10 13:36:04 -07004272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004273 // Persist setting
4274 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4275 }
Romain Guy06882f82009-06-10 13:36:04 -07004276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004277 public float getAnimationScale(int which) {
4278 switch (which) {
4279 case 0: return mWindowAnimationScale;
4280 case 1: return mTransitionAnimationScale;
4281 }
4282 return 0;
4283 }
Romain Guy06882f82009-06-10 13:36:04 -07004284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004285 public float[] getAnimationScales() {
4286 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4287 }
Romain Guy06882f82009-06-10 13:36:04 -07004288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004289 public int getSwitchState(int sw) {
4290 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4291 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004292 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004293 }
4294 return KeyInputQueue.getSwitchState(sw);
4295 }
Romain Guy06882f82009-06-10 13:36:04 -07004296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004297 public int getSwitchStateForDevice(int devid, int sw) {
4298 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4299 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004300 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004301 }
4302 return KeyInputQueue.getSwitchState(devid, sw);
4303 }
Romain Guy06882f82009-06-10 13:36:04 -07004304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004305 public int getScancodeState(int sw) {
4306 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4307 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004308 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004309 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004310 return mQueue.getScancodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004311 }
Romain Guy06882f82009-06-10 13:36:04 -07004312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004313 public int getScancodeStateForDevice(int devid, int sw) {
4314 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4315 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004316 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004317 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004318 return mQueue.getScancodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004319 }
Romain Guy06882f82009-06-10 13:36:04 -07004320
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004321 public int getTrackballScancodeState(int sw) {
4322 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4323 "getTrackballScancodeState()")) {
4324 throw new SecurityException("Requires READ_INPUT_STATE permission");
4325 }
4326 return mQueue.getTrackballScancodeState(sw);
4327 }
4328
4329 public int getDPadScancodeState(int sw) {
4330 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4331 "getDPadScancodeState()")) {
4332 throw new SecurityException("Requires READ_INPUT_STATE permission");
4333 }
4334 return mQueue.getDPadScancodeState(sw);
4335 }
4336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004337 public int getKeycodeState(int sw) {
4338 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4339 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004340 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004341 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004342 return mQueue.getKeycodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004343 }
Romain Guy06882f82009-06-10 13:36:04 -07004344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004345 public int getKeycodeStateForDevice(int devid, int sw) {
4346 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4347 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004348 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004349 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004350 return mQueue.getKeycodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004351 }
Romain Guy06882f82009-06-10 13:36:04 -07004352
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004353 public int getTrackballKeycodeState(int sw) {
4354 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4355 "getTrackballKeycodeState()")) {
4356 throw new SecurityException("Requires READ_INPUT_STATE permission");
4357 }
4358 return mQueue.getTrackballKeycodeState(sw);
4359 }
4360
4361 public int getDPadKeycodeState(int sw) {
4362 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4363 "getDPadKeycodeState()")) {
4364 throw new SecurityException("Requires READ_INPUT_STATE permission");
4365 }
4366 return mQueue.getDPadKeycodeState(sw);
4367 }
4368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004369 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
4370 return KeyInputQueue.hasKeys(keycodes, keyExists);
4371 }
Romain Guy06882f82009-06-10 13:36:04 -07004372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004373 public void enableScreenAfterBoot() {
4374 synchronized(mWindowMap) {
4375 if (mSystemBooted) {
4376 return;
4377 }
4378 mSystemBooted = true;
4379 }
Romain Guy06882f82009-06-10 13:36:04 -07004380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004381 performEnableScreen();
4382 }
Romain Guy06882f82009-06-10 13:36:04 -07004383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004384 public void enableScreenIfNeededLocked() {
4385 if (mDisplayEnabled) {
4386 return;
4387 }
4388 if (!mSystemBooted) {
4389 return;
4390 }
4391 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4392 }
Romain Guy06882f82009-06-10 13:36:04 -07004393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004394 public void performEnableScreen() {
4395 synchronized(mWindowMap) {
4396 if (mDisplayEnabled) {
4397 return;
4398 }
4399 if (!mSystemBooted) {
4400 return;
4401 }
Romain Guy06882f82009-06-10 13:36:04 -07004402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004403 // Don't enable the screen until all existing windows
4404 // have been drawn.
4405 final int N = mWindows.size();
4406 for (int i=0; i<N; i++) {
4407 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004408 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004409 return;
4410 }
4411 }
Romain Guy06882f82009-06-10 13:36:04 -07004412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004413 mDisplayEnabled = true;
4414 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004415 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004416 StringWriter sw = new StringWriter();
4417 PrintWriter pw = new PrintWriter(sw);
4418 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004419 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004420 }
4421 try {
4422 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4423 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004424 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004425 Parcel data = Parcel.obtain();
4426 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4427 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4428 data, null, 0);
4429 data.recycle();
4430 }
4431 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004432 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004433 }
4434 }
Romain Guy06882f82009-06-10 13:36:04 -07004435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004436 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004438 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004439 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4440 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004441 }
Romain Guy06882f82009-06-10 13:36:04 -07004442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004443 public void setInTouchMode(boolean mode) {
4444 synchronized(mWindowMap) {
4445 mInTouchMode = mode;
4446 }
4447 }
4448
Romain Guy06882f82009-06-10 13:36:04 -07004449 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004450 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004451 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004452 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004453 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004454 }
4455
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004456 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004457 }
Romain Guy06882f82009-06-10 13:36:04 -07004458
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004459 public void setRotationUnchecked(int rotation,
4460 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004461 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004462 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004464 long origId = Binder.clearCallingIdentity();
4465 boolean changed;
4466 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004467 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004468 }
Romain Guy06882f82009-06-10 13:36:04 -07004469
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004470 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004471 sendNewConfiguration();
4472 }
Romain Guy06882f82009-06-10 13:36:04 -07004473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004474 Binder.restoreCallingIdentity(origId);
4475 }
Romain Guy06882f82009-06-10 13:36:04 -07004476
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004477 /**
4478 * Apply a new rotation to the screen, respecting the requests of
4479 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4480 * re-evaluate the desired rotation.
4481 *
4482 * Returns null if the rotation has been changed. In this case YOU
4483 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4484 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004485 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004486 boolean changed;
4487 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4488 rotation = mRequestedRotation;
4489 } else {
4490 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004491 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004492 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004493 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004494 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004495 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004496 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004497 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004499 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004500 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004501 "Rotation changed to " + rotation
4502 + " from " + mRotation
4503 + " (forceApp=" + mForcedAppOrientation
4504 + ", req=" + mRequestedRotation + ")");
4505 mRotation = rotation;
4506 mWindowsFreezingScreen = true;
4507 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4508 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4509 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004510 mWaitingForConfig = true;
4511 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004512 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004513 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004514 mQueue.setOrientation(rotation);
4515 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004516 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004517 }
4518 for (int i=mWindows.size()-1; i>=0; i--) {
4519 WindowState w = (WindowState)mWindows.get(i);
4520 if (w.mSurface != null) {
4521 w.mOrientationChanging = true;
4522 }
4523 }
4524 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4525 try {
4526 mRotationWatchers.get(i).onRotationChanged(rotation);
4527 } catch (RemoteException e) {
4528 }
4529 }
4530 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004532 return changed;
4533 }
Romain Guy06882f82009-06-10 13:36:04 -07004534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004535 public int getRotation() {
4536 return mRotation;
4537 }
4538
4539 public int watchRotation(IRotationWatcher watcher) {
4540 final IBinder watcherBinder = watcher.asBinder();
4541 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4542 public void binderDied() {
4543 synchronized (mWindowMap) {
4544 for (int i=0; i<mRotationWatchers.size(); i++) {
4545 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004546 IRotationWatcher removed = mRotationWatchers.remove(i);
4547 if (removed != null) {
4548 removed.asBinder().unlinkToDeath(this, 0);
4549 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004550 i--;
4551 }
4552 }
4553 }
4554 }
4555 };
Romain Guy06882f82009-06-10 13:36:04 -07004556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004557 synchronized (mWindowMap) {
4558 try {
4559 watcher.asBinder().linkToDeath(dr, 0);
4560 mRotationWatchers.add(watcher);
4561 } catch (RemoteException e) {
4562 // Client died, no cleanup needed.
4563 }
Romain Guy06882f82009-06-10 13:36:04 -07004564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004565 return mRotation;
4566 }
4567 }
4568
4569 /**
4570 * Starts the view server on the specified port.
4571 *
4572 * @param port The port to listener to.
4573 *
4574 * @return True if the server was successfully started, false otherwise.
4575 *
4576 * @see com.android.server.ViewServer
4577 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4578 */
4579 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004580 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004581 return false;
4582 }
4583
4584 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4585 return false;
4586 }
4587
4588 if (port < 1024) {
4589 return false;
4590 }
4591
4592 if (mViewServer != null) {
4593 if (!mViewServer.isRunning()) {
4594 try {
4595 return mViewServer.start();
4596 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004597 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004598 }
4599 }
4600 return false;
4601 }
4602
4603 try {
4604 mViewServer = new ViewServer(this, port);
4605 return mViewServer.start();
4606 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004607 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004608 }
4609 return false;
4610 }
4611
Romain Guy06882f82009-06-10 13:36:04 -07004612 private boolean isSystemSecure() {
4613 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4614 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4615 }
4616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004617 /**
4618 * Stops the view server if it exists.
4619 *
4620 * @return True if the server stopped, false if it wasn't started or
4621 * couldn't be stopped.
4622 *
4623 * @see com.android.server.ViewServer
4624 */
4625 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004626 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004627 return false;
4628 }
4629
4630 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4631 return false;
4632 }
4633
4634 if (mViewServer != null) {
4635 return mViewServer.stop();
4636 }
4637 return false;
4638 }
4639
4640 /**
4641 * Indicates whether the view server is running.
4642 *
4643 * @return True if the server is running, false otherwise.
4644 *
4645 * @see com.android.server.ViewServer
4646 */
4647 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004648 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004649 return false;
4650 }
4651
4652 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4653 return false;
4654 }
4655
4656 return mViewServer != null && mViewServer.isRunning();
4657 }
4658
4659 /**
4660 * Lists all availble windows in the system. The listing is written in the
4661 * specified Socket's output stream with the following syntax:
4662 * windowHashCodeInHexadecimal windowName
4663 * Each line of the ouput represents a different window.
4664 *
4665 * @param client The remote client to send the listing to.
4666 * @return False if an error occured, true otherwise.
4667 */
4668 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004669 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004670 return false;
4671 }
4672
4673 boolean result = true;
4674
4675 Object[] windows;
4676 synchronized (mWindowMap) {
4677 windows = new Object[mWindows.size()];
4678 //noinspection unchecked
4679 windows = mWindows.toArray(windows);
4680 }
4681
4682 BufferedWriter out = null;
4683
4684 // Any uncaught exception will crash the system process
4685 try {
4686 OutputStream clientStream = client.getOutputStream();
4687 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4688
4689 final int count = windows.length;
4690 for (int i = 0; i < count; i++) {
4691 final WindowState w = (WindowState) windows[i];
4692 out.write(Integer.toHexString(System.identityHashCode(w)));
4693 out.write(' ');
4694 out.append(w.mAttrs.getTitle());
4695 out.write('\n');
4696 }
4697
4698 out.write("DONE.\n");
4699 out.flush();
4700 } catch (Exception e) {
4701 result = false;
4702 } finally {
4703 if (out != null) {
4704 try {
4705 out.close();
4706 } catch (IOException e) {
4707 result = false;
4708 }
4709 }
4710 }
4711
4712 return result;
4713 }
4714
4715 /**
4716 * Sends a command to a target window. The result of the command, if any, will be
4717 * written in the output stream of the specified socket.
4718 *
4719 * The parameters must follow this syntax:
4720 * windowHashcode extra
4721 *
4722 * Where XX is the length in characeters of the windowTitle.
4723 *
4724 * The first parameter is the target window. The window with the specified hashcode
4725 * will be the target. If no target can be found, nothing happens. The extra parameters
4726 * will be delivered to the target window and as parameters to the command itself.
4727 *
4728 * @param client The remote client to sent the result, if any, to.
4729 * @param command The command to execute.
4730 * @param parameters The command parameters.
4731 *
4732 * @return True if the command was successfully delivered, false otherwise. This does
4733 * not indicate whether the command itself was successful.
4734 */
4735 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004736 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004737 return false;
4738 }
4739
4740 boolean success = true;
4741 Parcel data = null;
4742 Parcel reply = null;
4743
4744 // Any uncaught exception will crash the system process
4745 try {
4746 // Find the hashcode of the window
4747 int index = parameters.indexOf(' ');
4748 if (index == -1) {
4749 index = parameters.length();
4750 }
4751 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004752 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004753
4754 // Extract the command's parameter after the window description
4755 if (index < parameters.length()) {
4756 parameters = parameters.substring(index + 1);
4757 } else {
4758 parameters = "";
4759 }
4760
4761 final WindowManagerService.WindowState window = findWindow(hashCode);
4762 if (window == null) {
4763 return false;
4764 }
4765
4766 data = Parcel.obtain();
4767 data.writeInterfaceToken("android.view.IWindow");
4768 data.writeString(command);
4769 data.writeString(parameters);
4770 data.writeInt(1);
4771 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4772
4773 reply = Parcel.obtain();
4774
4775 final IBinder binder = window.mClient.asBinder();
4776 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4777 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4778
4779 reply.readException();
4780
4781 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004782 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004783 success = false;
4784 } finally {
4785 if (data != null) {
4786 data.recycle();
4787 }
4788 if (reply != null) {
4789 reply.recycle();
4790 }
4791 }
4792
4793 return success;
4794 }
4795
4796 private WindowState findWindow(int hashCode) {
4797 if (hashCode == -1) {
4798 return getFocusedWindow();
4799 }
4800
4801 synchronized (mWindowMap) {
4802 final ArrayList windows = mWindows;
4803 final int count = windows.size();
4804
4805 for (int i = 0; i < count; i++) {
4806 WindowState w = (WindowState) windows.get(i);
4807 if (System.identityHashCode(w) == hashCode) {
4808 return w;
4809 }
4810 }
4811 }
4812
4813 return null;
4814 }
4815
4816 /*
4817 * Instruct the Activity Manager to fetch the current configuration and broadcast
4818 * that to config-changed listeners if appropriate.
4819 */
4820 void sendNewConfiguration() {
4821 try {
4822 mActivityManager.updateConfiguration(null);
4823 } catch (RemoteException e) {
4824 }
4825 }
Romain Guy06882f82009-06-10 13:36:04 -07004826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004827 public Configuration computeNewConfiguration() {
4828 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004829 return computeNewConfigurationLocked();
4830 }
4831 }
Romain Guy06882f82009-06-10 13:36:04 -07004832
Dianne Hackbornc485a602009-03-24 22:39:49 -07004833 Configuration computeNewConfigurationLocked() {
4834 Configuration config = new Configuration();
4835 if (!computeNewConfigurationLocked(config)) {
4836 return null;
4837 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004838 return config;
4839 }
Romain Guy06882f82009-06-10 13:36:04 -07004840
Dianne Hackbornc485a602009-03-24 22:39:49 -07004841 boolean computeNewConfigurationLocked(Configuration config) {
4842 if (mDisplay == null) {
4843 return false;
4844 }
4845 mQueue.getInputConfiguration(config);
4846 final int dw = mDisplay.getWidth();
4847 final int dh = mDisplay.getHeight();
4848 int orientation = Configuration.ORIENTATION_SQUARE;
4849 if (dw < dh) {
4850 orientation = Configuration.ORIENTATION_PORTRAIT;
4851 } else if (dw > dh) {
4852 orientation = Configuration.ORIENTATION_LANDSCAPE;
4853 }
4854 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004855
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004856 DisplayMetrics dm = new DisplayMetrics();
4857 mDisplay.getMetrics(dm);
4858 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4859
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004860 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004861 // Note we only do this once because at this point we don't
4862 // expect the screen to change in this way at runtime, and want
4863 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004864 int longSize = dw;
4865 int shortSize = dh;
4866 if (longSize < shortSize) {
4867 int tmp = longSize;
4868 longSize = shortSize;
4869 shortSize = tmp;
4870 }
4871 longSize = (int)(longSize/dm.density);
4872 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004873
Dianne Hackborn723738c2009-06-25 19:48:04 -07004874 // These semi-magic numbers define our compatibility modes for
4875 // applications with different screens. Don't change unless you
4876 // make sure to test lots and lots of apps!
4877 if (longSize < 470) {
4878 // This is shorter than an HVGA normal density screen (which
4879 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004880 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
4881 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07004882 } else {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004883 // Is this a large screen?
4884 if (longSize > 640 && shortSize >= 480) {
4885 // VGA or larger screens at medium density are the point
4886 // at which we consider it to be a large screen.
4887 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
4888 } else {
4889 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004890
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004891 // If this screen is wider than normal HVGA, or taller
4892 // than FWVGA, then for old apps we want to run in size
4893 // compatibility mode.
4894 if (shortSize > 321 || longSize > 570) {
4895 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
4896 }
4897 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004898
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004899 // Is this a long screen?
4900 if (((longSize*3)/5) >= (shortSize-1)) {
4901 // Anything wider than WVGA (5:3) is considering to be long.
4902 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
4903 } else {
4904 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
4905 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07004906 }
4907 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004908 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004909
Dianne Hackbornc485a602009-03-24 22:39:49 -07004910 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
4911 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
4912 mPolicy.adjustConfigurationLw(config);
4913 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004914 }
Romain Guy06882f82009-06-10 13:36:04 -07004915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004916 // -------------------------------------------------------------
4917 // Input Events and Focus Management
4918 // -------------------------------------------------------------
4919
4920 private final void wakeupIfNeeded(WindowState targetWin, int eventType) {
Michael Chane96440f2009-05-06 10:27:36 -07004921 long curTime = SystemClock.uptimeMillis();
4922
Michael Chane10de972009-05-18 11:24:50 -07004923 if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) {
Michael Chane96440f2009-05-06 10:27:36 -07004924 if (mLastTouchEventType == eventType &&
4925 (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) {
4926 return;
4927 }
4928 mLastUserActivityCallTime = curTime;
4929 mLastTouchEventType = eventType;
4930 }
4931
4932 if (targetWin == null
4933 || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) {
4934 mPowerManager.userActivity(curTime, false, eventType, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004935 }
4936 }
4937
4938 // tells if it's a cheek event or not -- this function is stateful
4939 private static final int EVENT_NONE = 0;
4940 private static final int EVENT_UNKNOWN = 0;
4941 private static final int EVENT_CHEEK = 0;
4942 private static final int EVENT_IGNORE_DURATION = 300; // ms
4943 private static final float CHEEK_THRESHOLD = 0.6f;
4944 private int mEventState = EVENT_NONE;
4945 private float mEventSize;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004947 private int eventType(MotionEvent ev) {
4948 float size = ev.getSize();
4949 switch (ev.getAction()) {
4950 case MotionEvent.ACTION_DOWN:
4951 mEventSize = size;
4952 return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT;
4953 case MotionEvent.ACTION_UP:
4954 if (size > mEventSize) mEventSize = size;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004955 return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004956 case MotionEvent.ACTION_MOVE:
4957 final int N = ev.getHistorySize();
4958 if (size > mEventSize) mEventSize = size;
4959 if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT;
4960 for (int i=0; i<N; i++) {
4961 size = ev.getHistoricalSize(i);
4962 if (size > mEventSize) mEventSize = size;
4963 if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT;
4964 }
4965 if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) {
4966 return TOUCH_EVENT;
4967 } else {
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004968 return LONG_TOUCH_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004969 }
4970 default:
4971 // not good
4972 return OTHER_EVENT;
4973 }
4974 }
4975
4976 /**
4977 * @return Returns true if event was dispatched, false if it was dropped for any reason
4978 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07004979 private int dispatchPointer(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004980 if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004981 "dispatchPointer " + ev);
4982
Michael Chan53071d62009-05-13 17:29:48 -07004983 if (MEASURE_LATENCY) {
4984 lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano);
4985 }
4986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004987 Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07004988 ev, true, false, pid, uid);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004989
Michael Chan53071d62009-05-13 17:29:48 -07004990 if (MEASURE_LATENCY) {
4991 lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano);
4992 }
4993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004994 int action = ev.getAction();
Romain Guy06882f82009-06-10 13:36:04 -07004995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004996 if (action == MotionEvent.ACTION_UP) {
4997 // let go of our target
4998 mKeyWaiter.mMotionTarget = null;
4999 mPowerManager.logPointerUpEvent();
5000 } else if (action == MotionEvent.ACTION_DOWN) {
5001 mPowerManager.logPointerDownEvent();
5002 }
5003
5004 if (targetObj == null) {
5005 // In this case we are either dropping the event, or have received
5006 // a move or up without a down. It is common to receive move
5007 // events in such a way, since this means the user is moving the
5008 // pointer without actually pressing down. All other cases should
5009 // be atypical, so let's log them.
Michael Chane96440f2009-05-06 10:27:36 -07005010 if (action != MotionEvent.ACTION_MOVE) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005011 Slog.w(TAG, "No window to dispatch pointer action " + ev.getAction());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005012 }
Dianne Hackborn6adba242009-11-10 11:10:09 -08005013 synchronized (mWindowMap) {
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005014 dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true);
Dianne Hackborn6adba242009-11-10 11:10:09 -08005015 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005016 if (qev != null) {
5017 mQueue.recycleEvent(qev);
5018 }
5019 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005020 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005021 }
5022 if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
Dianne Hackborn6adba242009-11-10 11:10:09 -08005023 synchronized (mWindowMap) {
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005024 dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true);
Dianne Hackborn6adba242009-11-10 11:10:09 -08005025 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005026 if (qev != null) {
5027 mQueue.recycleEvent(qev);
5028 }
5029 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005030 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005031 }
Romain Guy06882f82009-06-10 13:36:04 -07005032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005033 WindowState target = (WindowState)targetObj;
Romain Guy06882f82009-06-10 13:36:04 -07005034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005035 final long eventTime = ev.getEventTime();
Michael Chan53071d62009-05-13 17:29:48 -07005036 final long eventTimeNano = ev.getEventTimeNano();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005037
Joe Onorato8a9b2202010-02-26 18:56:32 -08005038 //Slog.i(TAG, "Sending " + ev + " to " + target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005039
5040 if (uid != 0 && uid != target.mSession.mUid) {
5041 if (mContext.checkPermission(
5042 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5043 != PackageManager.PERMISSION_GRANTED) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005044 Slog.w(TAG, "Permission denied: injecting pointer event from pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005045 + pid + " uid " + uid + " to window " + target
5046 + " owned by uid " + target.mSession.mUid);
5047 if (qev != null) {
5048 mQueue.recycleEvent(qev);
5049 }
5050 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005051 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005052 }
5053 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005054
Michael Chan53071d62009-05-13 17:29:48 -07005055 if (MEASURE_LATENCY) {
5056 lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano);
5057 }
5058
Romain Guy06882f82009-06-10 13:36:04 -07005059 if ((target.mAttrs.flags &
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005060 WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) {
5061 //target wants to ignore fat touch events
5062 boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev);
5063 //explicit flag to return without processing event further
5064 boolean returnFlag = false;
5065 if((action == MotionEvent.ACTION_DOWN)) {
5066 mFatTouch = false;
5067 if(cheekPress) {
5068 mFatTouch = true;
5069 returnFlag = true;
5070 }
5071 } else {
5072 if(action == MotionEvent.ACTION_UP) {
5073 if(mFatTouch) {
5074 //earlier even was invalid doesnt matter if current up is cheekpress or not
5075 mFatTouch = false;
5076 returnFlag = true;
5077 } else if(cheekPress) {
5078 //cancel the earlier event
5079 ev.setAction(MotionEvent.ACTION_CANCEL);
5080 action = MotionEvent.ACTION_CANCEL;
5081 }
5082 } else if(action == MotionEvent.ACTION_MOVE) {
5083 if(mFatTouch) {
5084 //two cases here
5085 //an invalid down followed by 0 or moves(valid or invalid)
Romain Guy06882f82009-06-10 13:36:04 -07005086 //a valid down, invalid move, more moves. want to ignore till up
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005087 returnFlag = true;
5088 } else if(cheekPress) {
5089 //valid down followed by invalid moves
5090 //an invalid move have to cancel earlier action
5091 ev.setAction(MotionEvent.ACTION_CANCEL);
5092 action = MotionEvent.ACTION_CANCEL;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005093 if (DEBUG_INPUT) Slog.v(TAG, "Sending cancel for invalid ACTION_MOVE");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005094 //note that the subsequent invalid moves will not get here
5095 mFatTouch = true;
5096 }
5097 }
5098 } //else if action
5099 if(returnFlag) {
5100 //recycle que, ev
5101 if (qev != null) {
5102 mQueue.recycleEvent(qev);
5103 }
5104 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005105 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005106 }
5107 } //end if target
Michael Chane96440f2009-05-06 10:27:36 -07005108
Michael Chan9f028e62009-08-04 17:37:46 -07005109 // Enable this for testing the "right" value
5110 if (false && action == MotionEvent.ACTION_DOWN) {
Michael Chane96440f2009-05-06 10:27:36 -07005111 int max_events_per_sec = 35;
5112 try {
5113 max_events_per_sec = Integer.parseInt(SystemProperties
5114 .get("windowsmgr.max_events_per_sec"));
5115 if (max_events_per_sec < 1) {
5116 max_events_per_sec = 35;
5117 }
5118 } catch (NumberFormatException e) {
5119 }
5120 mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec;
5121 }
5122
5123 /*
5124 * Throttle events to minimize CPU usage when there's a flood of events
5125 * e.g. constant contact with the screen
5126 */
5127 if (action == MotionEvent.ACTION_MOVE) {
5128 long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents;
5129 long now = SystemClock.uptimeMillis();
5130 if (now < nextEventTime) {
5131 try {
5132 Thread.sleep(nextEventTime - now);
5133 } catch (InterruptedException e) {
5134 }
5135 mLastTouchEventTime = nextEventTime;
5136 } else {
5137 mLastTouchEventTime = now;
5138 }
5139 }
5140
Michael Chan53071d62009-05-13 17:29:48 -07005141 if (MEASURE_LATENCY) {
5142 lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano);
5143 }
5144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005145 synchronized(mWindowMap) {
Dianne Hackborn6adba242009-11-10 11:10:09 -08005146 if (!target.isVisibleLw()) {
5147 // During this motion dispatch, the target window has become
5148 // invisible.
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005149 dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), false);
Dianne Hackborn6adba242009-11-10 11:10:09 -08005150 if (qev != null) {
5151 mQueue.recycleEvent(qev);
5152 }
5153 ev.recycle();
5154 return INJECT_SUCCEEDED;
5155 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005157 if (qev != null && action == MotionEvent.ACTION_MOVE) {
5158 mKeyWaiter.bindTargetWindowLocked(target,
5159 KeyWaiter.RETURN_PENDING_POINTER, qev);
5160 ev = null;
5161 } else {
5162 if (action == MotionEvent.ACTION_DOWN) {
5163 WindowState out = mKeyWaiter.mOutsideTouchTargets;
5164 if (out != null) {
5165 MotionEvent oev = MotionEvent.obtain(ev);
5166 oev.setAction(MotionEvent.ACTION_OUTSIDE);
5167 do {
5168 final Rect frame = out.mFrame;
5169 oev.offsetLocation(-(float)frame.left, -(float)frame.top);
5170 try {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005171 out.mClient.dispatchPointer(oev, eventTime, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005172 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005173 Slog.i(TAG, "WINDOW DIED during outside motion dispatch: " + out);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005174 }
5175 oev.offsetLocation((float)frame.left, (float)frame.top);
5176 out = out.mNextOutsideTouch;
5177 } while (out != null);
5178 mKeyWaiter.mOutsideTouchTargets = null;
5179 }
5180 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005181
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005182 dispatchPointerElsewhereLocked(target, null, ev, ev.getEventTime(), false);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005183
Dianne Hackborn6adba242009-11-10 11:10:09 -08005184 final Rect frame = target.mFrame;
5185 ev.offsetLocation(-(float)frame.left, -(float)frame.top);
5186 mKeyWaiter.bindTargetWindowLocked(target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005187 }
5188 }
Romain Guy06882f82009-06-10 13:36:04 -07005189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005190 // finally offset the event to the target's coordinate system and
5191 // dispatch the event.
5192 try {
5193 if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005194 Slog.v(TAG, "Delivering pointer " + qev + " to " + target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005195 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005196
Michael Chan53071d62009-05-13 17:29:48 -07005197 if (MEASURE_LATENCY) {
5198 lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano);
5199 }
5200
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005201 target.mClient.dispatchPointer(ev, eventTime, true);
Michael Chan53071d62009-05-13 17:29:48 -07005202
5203 if (MEASURE_LATENCY) {
5204 lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano);
5205 }
Dianne Hackborncfaef692009-06-15 14:24:44 -07005206 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005207 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005208 Slog.i(TAG, "WINDOW DIED during motion dispatch: " + target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005209 mKeyWaiter.mMotionTarget = null;
5210 try {
5211 removeWindow(target.mSession, target.mClient);
5212 } catch (java.util.NoSuchElementException ex) {
5213 // This will happen if the window has already been
5214 // removed.
5215 }
5216 }
Dianne Hackborncfaef692009-06-15 14:24:44 -07005217 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005218 }
Romain Guy06882f82009-06-10 13:36:04 -07005219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005220 /**
5221 * @return Returns true if event was dispatched, false if it was dropped for any reason
5222 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07005223 private int dispatchTrackball(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005224 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005225 TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">");
Romain Guy06882f82009-06-10 13:36:04 -07005226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005227 Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005228 ev, false, false, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005229 if (focusObj == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005230 Slog.w(TAG, "No focus window, dropping trackball: " + ev);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005231 if (qev != null) {
5232 mQueue.recycleEvent(qev);
5233 }
5234 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005235 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005236 }
5237 if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
5238 if (qev != null) {
5239 mQueue.recycleEvent(qev);
5240 }
5241 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005242 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005243 }
Romain Guy06882f82009-06-10 13:36:04 -07005244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005245 WindowState focus = (WindowState)focusObj;
Romain Guy06882f82009-06-10 13:36:04 -07005246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005247 if (uid != 0 && uid != focus.mSession.mUid) {
5248 if (mContext.checkPermission(
5249 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5250 != PackageManager.PERMISSION_GRANTED) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005251 Slog.w(TAG, "Permission denied: injecting key event from pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005252 + pid + " uid " + uid + " to window " + focus
5253 + " owned by uid " + focus.mSession.mUid);
5254 if (qev != null) {
5255 mQueue.recycleEvent(qev);
5256 }
5257 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005258 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005259 }
5260 }
Romain Guy06882f82009-06-10 13:36:04 -07005261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005262 final long eventTime = ev.getEventTime();
Romain Guy06882f82009-06-10 13:36:04 -07005263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005264 synchronized(mWindowMap) {
5265 if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) {
5266 mKeyWaiter.bindTargetWindowLocked(focus,
5267 KeyWaiter.RETURN_PENDING_TRACKBALL, qev);
5268 // We don't deliver movement events to the client, we hold
5269 // them and wait for them to call back.
5270 ev = null;
5271 } else {
5272 mKeyWaiter.bindTargetWindowLocked(focus);
5273 }
5274 }
Romain Guy06882f82009-06-10 13:36:04 -07005275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005276 try {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005277 focus.mClient.dispatchTrackball(ev, eventTime, true);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005278 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005279 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005280 Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005281 try {
5282 removeWindow(focus.mSession, focus.mClient);
5283 } catch (java.util.NoSuchElementException ex) {
5284 // This will happen if the window has already been
5285 // removed.
5286 }
5287 }
Romain Guy06882f82009-06-10 13:36:04 -07005288
Dianne Hackborncfaef692009-06-15 14:24:44 -07005289 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005290 }
Romain Guy06882f82009-06-10 13:36:04 -07005291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005292 /**
5293 * @return Returns true if event was dispatched, false if it was dropped for any reason
5294 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07005295 private int dispatchKey(KeyEvent event, int pid, int uid) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005296 if (DEBUG_INPUT) Slog.v(TAG, "Dispatch key: " + event);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005297
5298 Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005299 null, false, false, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005300 if (focusObj == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005301 Slog.w(TAG, "No focus window, dropping: " + event);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005302 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005303 }
5304 if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005305 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005306 }
Romain Guy06882f82009-06-10 13:36:04 -07005307
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07005308 // Okay we have finished waiting for the last event to be processed.
5309 // First off, if this is a repeat event, check to see if there is
5310 // a corresponding up event in the queue. If there is, we will
5311 // just drop the repeat, because it makes no sense to repeat after
5312 // the user has released a key. (This is especially important for
5313 // long presses.)
5314 if (event.getRepeatCount() > 0 && mQueue.hasKeyUpEvent(event)) {
5315 return INJECT_SUCCEEDED;
5316 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005318 WindowState focus = (WindowState)focusObj;
Romain Guy06882f82009-06-10 13:36:04 -07005319
Joe Onorato8a9b2202010-02-26 18:56:32 -08005320 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005321 TAG, "Dispatching to " + focus + ": " + event);
5322
5323 if (uid != 0 && uid != focus.mSession.mUid) {
5324 if (mContext.checkPermission(
5325 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5326 != PackageManager.PERMISSION_GRANTED) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005327 Slog.w(TAG, "Permission denied: injecting key event from pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005328 + pid + " uid " + uid + " to window " + focus
5329 + " owned by uid " + focus.mSession.mUid);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005330 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005331 }
5332 }
Romain Guy06882f82009-06-10 13:36:04 -07005333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005334 synchronized(mWindowMap) {
5335 mKeyWaiter.bindTargetWindowLocked(focus);
5336 }
5337
5338 // NOSHIP extra state logging
5339 mKeyWaiter.recordDispatchState(event, focus);
5340 // END NOSHIP
Romain Guy06882f82009-06-10 13:36:04 -07005341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005342 try {
5343 if (DEBUG_INPUT || DEBUG_FOCUS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005344 Slog.v(TAG, "Delivering key " + event.getKeyCode()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005345 + " to " + focus);
5346 }
5347 focus.mClient.dispatchKey(event);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005348 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005349 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005350 Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005351 try {
5352 removeWindow(focus.mSession, focus.mClient);
5353 } catch (java.util.NoSuchElementException ex) {
5354 // This will happen if the window has already been
5355 // removed.
5356 }
5357 }
Romain Guy06882f82009-06-10 13:36:04 -07005358
Dianne Hackborncfaef692009-06-15 14:24:44 -07005359 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005360 }
Romain Guy06882f82009-06-10 13:36:04 -07005361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005362 public void pauseKeyDispatching(IBinder _token) {
5363 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5364 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005365 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005366 }
5367
5368 synchronized (mWindowMap) {
5369 WindowToken token = mTokenMap.get(_token);
5370 if (token != null) {
5371 mKeyWaiter.pauseDispatchingLocked(token);
5372 }
5373 }
5374 }
5375
5376 public void resumeKeyDispatching(IBinder _token) {
5377 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5378 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005379 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005380 }
5381
5382 synchronized (mWindowMap) {
5383 WindowToken token = mTokenMap.get(_token);
5384 if (token != null) {
5385 mKeyWaiter.resumeDispatchingLocked(token);
5386 }
5387 }
5388 }
5389
5390 public void setEventDispatching(boolean enabled) {
5391 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5392 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005393 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005394 }
5395
5396 synchronized (mWindowMap) {
5397 mKeyWaiter.setEventDispatchingLocked(enabled);
5398 }
5399 }
Romain Guy06882f82009-06-10 13:36:04 -07005400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005401 /**
5402 * Injects a keystroke event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005403 *
5404 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005405 * {@link SystemClock#uptimeMillis()} as the timebase.)
5406 * @param sync If true, wait for the event to be completed before returning to the caller.
5407 * @return Returns true if event was dispatched, false if it was dropped for any reason
5408 */
5409 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5410 long downTime = ev.getDownTime();
5411 long eventTime = ev.getEventTime();
5412
5413 int action = ev.getAction();
5414 int code = ev.getKeyCode();
5415 int repeatCount = ev.getRepeatCount();
5416 int metaState = ev.getMetaState();
5417 int deviceId = ev.getDeviceId();
5418 int scancode = ev.getScanCode();
5419
5420 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5421 if (downTime == 0) downTime = eventTime;
5422
5423 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
The Android Open Source Project10592532009-03-18 17:39:46 -07005424 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005425
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005426 final int pid = Binder.getCallingPid();
5427 final int uid = Binder.getCallingUid();
5428 final long ident = Binder.clearCallingIdentity();
5429 final int result = dispatchKey(newEvent, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005430 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005431 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005432 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005433 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005434 switch (result) {
5435 case INJECT_NO_PERMISSION:
5436 throw new SecurityException(
Chander S Pechetty27f3de62010-02-10 22:14:00 +05305437 "Injecting to another application requires INJECT_EVENTS permission");
Dianne Hackborncfaef692009-06-15 14:24:44 -07005438 case INJECT_SUCCEEDED:
5439 return true;
5440 }
5441 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005442 }
5443
5444 /**
5445 * Inject a pointer (touch) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005446 *
5447 * @param ev A motion event describing the pointer (touch) action. (As noted in
5448 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005449 * {@link SystemClock#uptimeMillis()} as the timebase.)
5450 * @param sync If true, wait for the event to be completed before returning to the caller.
5451 * @return Returns true if event was dispatched, false if it was dropped for any reason
5452 */
5453 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005454 final int pid = Binder.getCallingPid();
5455 final int uid = Binder.getCallingUid();
5456 final long ident = Binder.clearCallingIdentity();
5457 final int result = dispatchPointer(null, ev, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005458 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005459 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005460 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005461 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005462 switch (result) {
5463 case INJECT_NO_PERMISSION:
5464 throw new SecurityException(
Chander S Pechetty27f3de62010-02-10 22:14:00 +05305465 "Injecting to another application requires INJECT_EVENTS permission");
Dianne Hackborncfaef692009-06-15 14:24:44 -07005466 case INJECT_SUCCEEDED:
5467 return true;
5468 }
5469 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005470 }
Romain Guy06882f82009-06-10 13:36:04 -07005471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005472 /**
5473 * Inject a trackball (navigation device) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005474 *
5475 * @param ev A motion event describing the trackball action. (As noted in
5476 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005477 * {@link SystemClock#uptimeMillis()} as the timebase.)
5478 * @param sync If true, wait for the event to be completed before returning to the caller.
5479 * @return Returns true if event was dispatched, false if it was dropped for any reason
5480 */
5481 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005482 final int pid = Binder.getCallingPid();
5483 final int uid = Binder.getCallingUid();
5484 final long ident = Binder.clearCallingIdentity();
5485 final int result = dispatchTrackball(null, ev, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005486 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005487 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005488 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005489 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005490 switch (result) {
5491 case INJECT_NO_PERMISSION:
5492 throw new SecurityException(
Chander S Pechetty27f3de62010-02-10 22:14:00 +05305493 "Injecting to another application requires INJECT_EVENTS permission");
Dianne Hackborncfaef692009-06-15 14:24:44 -07005494 case INJECT_SUCCEEDED:
5495 return true;
5496 }
5497 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005498 }
Romain Guy06882f82009-06-10 13:36:04 -07005499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005500 private WindowState getFocusedWindow() {
5501 synchronized (mWindowMap) {
5502 return getFocusedWindowLocked();
5503 }
5504 }
5505
5506 private WindowState getFocusedWindowLocked() {
5507 return mCurrentFocus;
5508 }
Romain Guy06882f82009-06-10 13:36:04 -07005509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005510 /**
5511 * This class holds the state for dispatching key events. This state
5512 * is protected by the KeyWaiter instance, NOT by the window lock. You
5513 * can be holding the main window lock while acquire the KeyWaiter lock,
5514 * but not the other way around.
5515 */
5516 final class KeyWaiter {
5517 // NOSHIP debugging
5518 public class DispatchState {
5519 private KeyEvent event;
5520 private WindowState focus;
5521 private long time;
5522 private WindowState lastWin;
5523 private IBinder lastBinder;
5524 private boolean finished;
5525 private boolean gotFirstWindow;
5526 private boolean eventDispatching;
5527 private long timeToSwitch;
5528 private boolean wasFrozen;
5529 private boolean focusPaused;
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005530 private WindowState curFocus;
Romain Guy06882f82009-06-10 13:36:04 -07005531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005532 DispatchState(KeyEvent theEvent, WindowState theFocus) {
5533 focus = theFocus;
5534 event = theEvent;
5535 time = System.currentTimeMillis();
5536 // snapshot KeyWaiter state
5537 lastWin = mLastWin;
5538 lastBinder = mLastBinder;
5539 finished = mFinished;
5540 gotFirstWindow = mGotFirstWindow;
5541 eventDispatching = mEventDispatching;
5542 timeToSwitch = mTimeToSwitch;
5543 wasFrozen = mWasFrozen;
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005544 curFocus = mCurrentFocus;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005545 // cache the paused state at ctor time as well
5546 if (theFocus == null || theFocus.mToken == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005547 focusPaused = false;
5548 } else {
5549 focusPaused = theFocus.mToken.paused;
5550 }
5551 }
Romain Guy06882f82009-06-10 13:36:04 -07005552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005553 public String toString() {
5554 return "{{" + event + " to " + focus + " @ " + time
5555 + " lw=" + lastWin + " lb=" + lastBinder
5556 + " fin=" + finished + " gfw=" + gotFirstWindow
5557 + " ed=" + eventDispatching + " tts=" + timeToSwitch
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005558 + " wf=" + wasFrozen + " fp=" + focusPaused
Christopher Tate46d45252010-02-09 15:48:57 -08005559 + " mcf=" + curFocus + "}}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005560 }
5561 };
5562 private DispatchState mDispatchState = null;
5563 public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) {
5564 mDispatchState = new DispatchState(theEvent, theFocus);
5565 }
5566 // END NOSHIP
5567
5568 public static final int RETURN_NOTHING = 0;
5569 public static final int RETURN_PENDING_POINTER = 1;
5570 public static final int RETURN_PENDING_TRACKBALL = 2;
Romain Guy06882f82009-06-10 13:36:04 -07005571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005572 final Object SKIP_TARGET_TOKEN = new Object();
5573 final Object CONSUMED_EVENT_TOKEN = new Object();
Romain Guy06882f82009-06-10 13:36:04 -07005574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005575 private WindowState mLastWin = null;
5576 private IBinder mLastBinder = null;
5577 private boolean mFinished = true;
5578 private boolean mGotFirstWindow = false;
5579 private boolean mEventDispatching = true;
5580 private long mTimeToSwitch = 0;
5581 /* package */ boolean mWasFrozen = false;
Romain Guy06882f82009-06-10 13:36:04 -07005582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005583 // Target of Motion events
5584 WindowState mMotionTarget;
Romain Guy06882f82009-06-10 13:36:04 -07005585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005586 // Windows above the target who would like to receive an "outside"
5587 // touch event for any down events outside of them.
5588 WindowState mOutsideTouchTargets;
5589
5590 /**
5591 * Wait for the last event dispatch to complete, then find the next
5592 * target that should receive the given event and wait for that one
5593 * to be ready to receive it.
5594 */
5595 Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev,
5596 MotionEvent nextMotion, boolean isPointerEvent,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005597 boolean failIfTimeout, int callingPid, int callingUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005598 long startTime = SystemClock.uptimeMillis();
5599 long keyDispatchingTimeout = 5 * 1000;
5600 long waitedFor = 0;
5601
5602 while (true) {
5603 // Figure out which window we care about. It is either the
5604 // last window we are waiting to have process the event or,
5605 // if none, then the next window we think the event should go
5606 // to. Note: we retrieve mLastWin outside of the lock, so
5607 // it may change before we lock. Thus we must check it again.
5608 WindowState targetWin = mLastWin;
5609 boolean targetIsNew = targetWin == null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005610 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005611 TAG, "waitForLastKey: mFinished=" + mFinished +
5612 ", mLastWin=" + mLastWin);
5613 if (targetIsNew) {
5614 Object target = findTargetWindow(nextKey, qev, nextMotion,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005615 isPointerEvent, callingPid, callingUid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005616 if (target == SKIP_TARGET_TOKEN) {
5617 // The user has pressed a special key, and we are
5618 // dropping all pending events before it.
Joe Onorato8a9b2202010-02-26 18:56:32 -08005619 if (DEBUG_INPUT) Slog.v(TAG, "Skipping: " + nextKey
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005620 + " " + nextMotion);
5621 return null;
5622 }
5623 if (target == CONSUMED_EVENT_TOKEN) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005624 if (DEBUG_INPUT) Slog.v(TAG, "Consumed: " + nextKey
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005625 + " " + nextMotion);
5626 return target;
5627 }
5628 targetWin = (WindowState)target;
5629 }
Romain Guy06882f82009-06-10 13:36:04 -07005630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005631 AppWindowToken targetApp = null;
Romain Guy06882f82009-06-10 13:36:04 -07005632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005633 // Now: is it okay to send the next event to this window?
5634 synchronized (this) {
5635 // First: did we come here based on the last window not
5636 // being null, but it changed by the time we got here?
5637 // If so, try again.
5638 if (!targetIsNew && mLastWin == null) {
5639 continue;
5640 }
Romain Guy06882f82009-06-10 13:36:04 -07005641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005642 // We never dispatch events if not finished with the
5643 // last one, or the display is frozen.
5644 if (mFinished && !mDisplayFrozen) {
5645 // If event dispatching is disabled, then we
5646 // just consume the events.
5647 if (!mEventDispatching) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005648 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005649 "Skipping event; dispatching disabled: "
5650 + nextKey + " " + nextMotion);
5651 return null;
5652 }
5653 if (targetWin != null) {
5654 // If this is a new target, and that target is not
5655 // paused or unresponsive, then all looks good to
5656 // handle the event.
5657 if (targetIsNew && !targetWin.mToken.paused) {
5658 return targetWin;
5659 }
Romain Guy06882f82009-06-10 13:36:04 -07005660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005661 // If we didn't find a target window, and there is no
5662 // focused app window, then just eat the events.
5663 } else if (mFocusedApp == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005664 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005665 "Skipping event; no focused app: "
5666 + nextKey + " " + nextMotion);
5667 return null;
5668 }
5669 }
Romain Guy06882f82009-06-10 13:36:04 -07005670
Joe Onorato8a9b2202010-02-26 18:56:32 -08005671 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005672 TAG, "Waiting for last key in " + mLastBinder
5673 + " target=" + targetWin
5674 + " mFinished=" + mFinished
5675 + " mDisplayFrozen=" + mDisplayFrozen
5676 + " targetIsNew=" + targetIsNew
5677 + " paused="
5678 + (targetWin != null ? targetWin.mToken.paused : false)
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005679 + " mFocusedApp=" + mFocusedApp
5680 + " mCurrentFocus=" + mCurrentFocus);
Romain Guy06882f82009-06-10 13:36:04 -07005681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005682 targetApp = targetWin != null
5683 ? targetWin.mAppToken : mFocusedApp;
Romain Guy06882f82009-06-10 13:36:04 -07005684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005685 long curTimeout = keyDispatchingTimeout;
5686 if (mTimeToSwitch != 0) {
5687 long now = SystemClock.uptimeMillis();
5688 if (mTimeToSwitch <= now) {
5689 // If an app switch key has been pressed, and we have
5690 // waited too long for the current app to finish
5691 // processing keys, then wait no more!
Christopher Tate136b1f92010-02-11 17:51:24 -08005692 doFinishedKeyLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005693 continue;
5694 }
5695 long switchTimeout = mTimeToSwitch - now;
5696 if (curTimeout > switchTimeout) {
5697 curTimeout = switchTimeout;
5698 }
5699 }
Romain Guy06882f82009-06-10 13:36:04 -07005700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005701 try {
5702 // after that continue
5703 // processing keys, so we don't get stuck.
Joe Onorato8a9b2202010-02-26 18:56:32 -08005704 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005705 TAG, "Waiting for key dispatch: " + curTimeout);
5706 wait(curTimeout);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005707 if (DEBUG_INPUT) Slog.v(TAG, "Finished waiting @"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005708 + SystemClock.uptimeMillis() + " startTime="
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005709 + startTime + " switchTime=" + mTimeToSwitch
5710 + " target=" + targetWin + " mLW=" + mLastWin
5711 + " mLB=" + mLastBinder + " fin=" + mFinished
5712 + " mCurrentFocus=" + mCurrentFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005713 } catch (InterruptedException e) {
5714 }
5715 }
5716
5717 // If we were frozen during configuration change, restart the
5718 // timeout checks from now; otherwise look at whether we timed
5719 // out before awakening.
5720 if (mWasFrozen) {
5721 waitedFor = 0;
5722 mWasFrozen = false;
5723 } else {
5724 waitedFor = SystemClock.uptimeMillis() - startTime;
5725 }
5726
5727 if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) {
5728 IApplicationToken at = null;
5729 synchronized (this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005730 Slog.w(TAG, "Key dispatching timed out sending to " +
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005731 (targetWin != null ? targetWin.mAttrs.getTitle()
Ken Shirriff8200b202010-02-04 13:34:37 -08005732 : "<null>: no window ready for key dispatch"));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005733 // NOSHIP debugging
Joe Onorato8a9b2202010-02-26 18:56:32 -08005734 Slog.w(TAG, "Previous dispatch state: " + mDispatchState);
5735 Slog.w(TAG, "Current dispatch state: " +
Ken Shirriff8200b202010-02-04 13:34:37 -08005736 new DispatchState(nextKey, targetWin));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005737 // END NOSHIP
5738 //dump();
5739 if (targetWin != null) {
5740 at = targetWin.getAppToken();
5741 } else if (targetApp != null) {
5742 at = targetApp.appToken;
5743 }
5744 }
5745
5746 boolean abort = true;
5747 if (at != null) {
5748 try {
5749 long timeout = at.getKeyDispatchingTimeout();
5750 if (timeout > waitedFor) {
5751 // we did not wait the proper amount of time for this application.
5752 // set the timeout to be the real timeout and wait again.
5753 keyDispatchingTimeout = timeout - waitedFor;
5754 continue;
5755 } else {
5756 abort = at.keyDispatchingTimedOut();
5757 }
5758 } catch (RemoteException ex) {
5759 }
5760 }
5761
5762 synchronized (this) {
5763 if (abort && (mLastWin == targetWin || targetWin == null)) {
5764 mFinished = true;
Romain Guy06882f82009-06-10 13:36:04 -07005765 if (mLastWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005766 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005767 "Window " + mLastWin +
5768 " timed out on key input");
5769 if (mLastWin.mToken.paused) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005770 Slog.w(TAG, "Un-pausing dispatching to this window");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005771 mLastWin.mToken.paused = false;
5772 }
5773 }
5774 if (mMotionTarget == targetWin) {
5775 mMotionTarget = null;
5776 }
5777 mLastWin = null;
5778 mLastBinder = null;
5779 if (failIfTimeout || targetWin == null) {
5780 return null;
5781 }
5782 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005783 Slog.w(TAG, "Continuing to wait for key to be dispatched");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005784 startTime = SystemClock.uptimeMillis();
5785 }
5786 }
5787 }
5788 }
5789 }
Romain Guy06882f82009-06-10 13:36:04 -07005790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005791 Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005792 MotionEvent nextMotion, boolean isPointerEvent,
5793 int callingPid, int callingUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005794 mOutsideTouchTargets = null;
Romain Guy06882f82009-06-10 13:36:04 -07005795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005796 if (nextKey != null) {
5797 // Find the target window for a normal key event.
5798 final int keycode = nextKey.getKeyCode();
5799 final int repeatCount = nextKey.getRepeatCount();
5800 final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP;
5801 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005803 if (!dispatch) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005804 if (callingUid == 0 ||
5805 mContext.checkPermission(
5806 android.Manifest.permission.INJECT_EVENTS,
5807 callingPid, callingUid)
5808 == PackageManager.PERMISSION_GRANTED) {
5809 mPolicy.interceptKeyTi(null, keycode,
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07005810 nextKey.getMetaState(), down, repeatCount,
5811 nextKey.getFlags());
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005812 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08005813 Slog.w(TAG, "Event timeout during app switch: dropping "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005814 + nextKey);
5815 return SKIP_TARGET_TOKEN;
5816 }
Romain Guy06882f82009-06-10 13:36:04 -07005817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005818 // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")");
Romain Guy06882f82009-06-10 13:36:04 -07005819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005820 WindowState focus = null;
5821 synchronized(mWindowMap) {
5822 focus = getFocusedWindowLocked();
5823 }
Romain Guy06882f82009-06-10 13:36:04 -07005824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005825 wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT);
Romain Guy06882f82009-06-10 13:36:04 -07005826
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005827 if (callingUid == 0 ||
5828 (focus != null && callingUid == focus.mSession.mUid) ||
5829 mContext.checkPermission(
5830 android.Manifest.permission.INJECT_EVENTS,
5831 callingPid, callingUid)
5832 == PackageManager.PERMISSION_GRANTED) {
5833 if (mPolicy.interceptKeyTi(focus,
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005834 keycode, nextKey.getMetaState(), down, repeatCount,
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07005835 nextKey.getFlags())) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005836 return CONSUMED_EVENT_TOKEN;
5837 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005838 }
Romain Guy06882f82009-06-10 13:36:04 -07005839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005840 return focus;
Romain Guy06882f82009-06-10 13:36:04 -07005841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005842 } else if (!isPointerEvent) {
5843 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1);
5844 if (!dispatch) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005845 Slog.w(TAG, "Event timeout during app switch: dropping trackball "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005846 + nextMotion);
5847 return SKIP_TARGET_TOKEN;
5848 }
Romain Guy06882f82009-06-10 13:36:04 -07005849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005850 WindowState focus = null;
5851 synchronized(mWindowMap) {
5852 focus = getFocusedWindowLocked();
5853 }
Romain Guy06882f82009-06-10 13:36:04 -07005854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005855 wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT);
5856 return focus;
5857 }
Romain Guy06882f82009-06-10 13:36:04 -07005858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005859 if (nextMotion == null) {
5860 return SKIP_TARGET_TOKEN;
5861 }
Romain Guy06882f82009-06-10 13:36:04 -07005862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005863 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(
5864 KeyEvent.KEYCODE_UNKNOWN);
5865 if (!dispatch) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005866 Slog.w(TAG, "Event timeout during app switch: dropping pointer "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005867 + nextMotion);
5868 return SKIP_TARGET_TOKEN;
5869 }
Romain Guy06882f82009-06-10 13:36:04 -07005870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005871 // Find the target window for a pointer event.
5872 int action = nextMotion.getAction();
5873 final float xf = nextMotion.getX();
5874 final float yf = nextMotion.getY();
5875 final long eventTime = nextMotion.getEventTime();
Romain Guy06882f82009-06-10 13:36:04 -07005876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005877 final boolean screenWasOff = qev != null
5878 && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07005879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005880 WindowState target = null;
Romain Guy06882f82009-06-10 13:36:04 -07005881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005882 synchronized(mWindowMap) {
5883 synchronized (this) {
5884 if (action == MotionEvent.ACTION_DOWN) {
5885 if (mMotionTarget != null) {
5886 // this is weird, we got a pen down, but we thought it was
5887 // already down!
5888 // XXX: We should probably send an ACTION_UP to the current
5889 // target.
Joe Onorato8a9b2202010-02-26 18:56:32 -08005890 Slog.w(TAG, "Pointer down received while already down in: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005891 + mMotionTarget);
5892 mMotionTarget = null;
5893 }
Romain Guy06882f82009-06-10 13:36:04 -07005894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005895 // ACTION_DOWN is special, because we need to lock next events to
5896 // the window we'll land onto.
5897 final int x = (int)xf;
5898 final int y = (int)yf;
Romain Guy06882f82009-06-10 13:36:04 -07005899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005900 final ArrayList windows = mWindows;
5901 final int N = windows.size();
5902 WindowState topErrWindow = null;
5903 final Rect tmpRect = mTempRect;
5904 for (int i=N-1; i>=0; i--) {
5905 WindowState child = (WindowState)windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005906 //Slog.i(TAG, "Checking dispatch to: " + child);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005907 final int flags = child.mAttrs.flags;
5908 if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) {
5909 if (topErrWindow == null) {
5910 topErrWindow = child;
5911 }
5912 }
5913 if (!child.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005914 //Slog.i(TAG, "Not visible!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005915 continue;
5916 }
5917 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005918 //Slog.i(TAG, "Not touchable!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005919 if ((flags & WindowManager.LayoutParams
5920 .FLAG_WATCH_OUTSIDE_TOUCH) != 0) {
5921 child.mNextOutsideTouch = mOutsideTouchTargets;
5922 mOutsideTouchTargets = child;
5923 }
5924 continue;
5925 }
5926 tmpRect.set(child.mFrame);
5927 if (child.mTouchableInsets == ViewTreeObserver
5928 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
5929 // The touch is inside of the window if it is
5930 // inside the frame, AND the content part of that
5931 // frame that was given by the application.
5932 tmpRect.left += child.mGivenContentInsets.left;
5933 tmpRect.top += child.mGivenContentInsets.top;
5934 tmpRect.right -= child.mGivenContentInsets.right;
5935 tmpRect.bottom -= child.mGivenContentInsets.bottom;
5936 } else if (child.mTouchableInsets == ViewTreeObserver
5937 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
5938 // The touch is inside of the window if it is
5939 // inside the frame, AND the visible part of that
5940 // frame that was given by the application.
5941 tmpRect.left += child.mGivenVisibleInsets.left;
5942 tmpRect.top += child.mGivenVisibleInsets.top;
5943 tmpRect.right -= child.mGivenVisibleInsets.right;
5944 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
5945 }
5946 final int touchFlags = flags &
5947 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
5948 |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
5949 if (tmpRect.contains(x, y) || touchFlags == 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005950 //Slog.i(TAG, "Using this target!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005951 if (!screenWasOff || (flags &
5952 WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) {
5953 mMotionTarget = child;
5954 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005955 //Slog.i(TAG, "Waking, skip!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005956 mMotionTarget = null;
5957 }
5958 break;
5959 }
Romain Guy06882f82009-06-10 13:36:04 -07005960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005961 if ((flags & WindowManager.LayoutParams
5962 .FLAG_WATCH_OUTSIDE_TOUCH) != 0) {
5963 child.mNextOutsideTouch = mOutsideTouchTargets;
5964 mOutsideTouchTargets = child;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005965 //Slog.i(TAG, "Adding to outside target list: " + child);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005966 }
5967 }
5968
5969 // if there's an error window but it's not accepting
5970 // focus (typically because it is not yet visible) just
5971 // wait for it -- any other focused window may in fact
5972 // be in ANR state.
5973 if (topErrWindow != null && mMotionTarget != topErrWindow) {
5974 mMotionTarget = null;
5975 }
5976 }
Romain Guy06882f82009-06-10 13:36:04 -07005977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005978 target = mMotionTarget;
5979 }
5980 }
Romain Guy06882f82009-06-10 13:36:04 -07005981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005982 wakeupIfNeeded(target, eventType(nextMotion));
Romain Guy06882f82009-06-10 13:36:04 -07005983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005984 // Pointer events are a little different -- if there isn't a
5985 // target found for any event, then just drop it.
5986 return target != null ? target : SKIP_TARGET_TOKEN;
5987 }
Romain Guy06882f82009-06-10 13:36:04 -07005988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005989 boolean checkShouldDispatchKey(int keycode) {
5990 synchronized (this) {
5991 if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) {
5992 mTimeToSwitch = 0;
5993 return true;
5994 }
5995 if (mTimeToSwitch != 0
5996 && mTimeToSwitch < SystemClock.uptimeMillis()) {
5997 return false;
5998 }
5999 return true;
6000 }
6001 }
Romain Guy06882f82009-06-10 13:36:04 -07006002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006003 void bindTargetWindowLocked(WindowState win,
6004 int pendingWhat, QueuedEvent pendingMotion) {
6005 synchronized (this) {
6006 bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion);
6007 }
6008 }
Romain Guy06882f82009-06-10 13:36:04 -07006009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006010 void bindTargetWindowLocked(WindowState win) {
6011 synchronized (this) {
6012 bindTargetWindowLockedLocked(win, RETURN_NOTHING, null);
6013 }
6014 }
6015
6016 void bindTargetWindowLockedLocked(WindowState win,
6017 int pendingWhat, QueuedEvent pendingMotion) {
6018 mLastWin = win;
6019 mLastBinder = win.mClient.asBinder();
6020 mFinished = false;
6021 if (pendingMotion != null) {
6022 final Session s = win.mSession;
6023 if (pendingWhat == RETURN_PENDING_POINTER) {
6024 releasePendingPointerLocked(s);
6025 s.mPendingPointerMove = pendingMotion;
6026 s.mPendingPointerWindow = win;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006027 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006028 "bindTargetToWindow " + s.mPendingPointerMove);
6029 } else if (pendingWhat == RETURN_PENDING_TRACKBALL) {
6030 releasePendingTrackballLocked(s);
6031 s.mPendingTrackballMove = pendingMotion;
6032 s.mPendingTrackballWindow = win;
6033 }
6034 }
6035 }
Romain Guy06882f82009-06-10 13:36:04 -07006036
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006037 void releasePendingPointerLocked(Session s) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006038 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006039 "releasePendingPointer " + s.mPendingPointerMove);
6040 if (s.mPendingPointerMove != null) {
6041 mQueue.recycleEvent(s.mPendingPointerMove);
6042 s.mPendingPointerMove = null;
6043 }
6044 }
Romain Guy06882f82009-06-10 13:36:04 -07006045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006046 void releasePendingTrackballLocked(Session s) {
6047 if (s.mPendingTrackballMove != null) {
6048 mQueue.recycleEvent(s.mPendingTrackballMove);
6049 s.mPendingTrackballMove = null;
6050 }
6051 }
Romain Guy06882f82009-06-10 13:36:04 -07006052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006053 MotionEvent finishedKey(Session session, IWindow client, boolean force,
6054 int returnWhat) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006055 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006056 TAG, "finishedKey: client=" + client + ", force=" + force);
6057
6058 if (client == null) {
6059 return null;
6060 }
6061
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006062 MotionEvent res = null;
6063 QueuedEvent qev = null;
6064 WindowState win = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006066 synchronized (this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006067 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006068 TAG, "finishedKey: client=" + client.asBinder()
6069 + ", force=" + force + ", last=" + mLastBinder
6070 + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")");
6071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006072 if (returnWhat == RETURN_PENDING_POINTER) {
6073 qev = session.mPendingPointerMove;
6074 win = session.mPendingPointerWindow;
6075 session.mPendingPointerMove = null;
6076 session.mPendingPointerWindow = null;
6077 } else if (returnWhat == RETURN_PENDING_TRACKBALL) {
6078 qev = session.mPendingTrackballMove;
6079 win = session.mPendingTrackballWindow;
6080 session.mPendingTrackballMove = null;
6081 session.mPendingTrackballWindow = null;
6082 }
Romain Guy06882f82009-06-10 13:36:04 -07006083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006084 if (mLastBinder == client.asBinder()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006085 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006086 TAG, "finishedKey: last paused="
6087 + ((mLastWin != null) ? mLastWin.mToken.paused : "null"));
6088 if (mLastWin != null && (!mLastWin.mToken.paused || force
6089 || !mEventDispatching)) {
Christopher Tate136b1f92010-02-11 17:51:24 -08006090 doFinishedKeyLocked(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006091 } else {
6092 // Make sure to wake up anyone currently waiting to
6093 // dispatch a key, so they can re-evaluate their
6094 // current situation.
6095 mFinished = true;
6096 notifyAll();
6097 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006098 }
Romain Guy06882f82009-06-10 13:36:04 -07006099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006100 if (qev != null) {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006101 res = (MotionEvent)qev.event;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006102 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006103 "Returning pending motion: " + res);
6104 mQueue.recycleEvent(qev);
6105 if (win != null && returnWhat == RETURN_PENDING_POINTER) {
6106 res.offsetLocation(-win.mFrame.left, -win.mFrame.top);
6107 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006108 }
Christopher Tate2624fbc2009-12-11 12:11:31 -08006109 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006110
Christopher Tate2624fbc2009-12-11 12:11:31 -08006111 if (res != null && returnWhat == RETURN_PENDING_POINTER) {
6112 synchronized (mWindowMap) {
Dianne Hackborn90d2db32010-02-11 22:19:06 -08006113 dispatchPointerElsewhereLocked(win, win, res, res.getEventTime(), false);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006114 }
6115 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006116
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006117 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006118 }
6119
6120 void tickle() {
6121 synchronized (this) {
6122 notifyAll();
6123 }
6124 }
Romain Guy06882f82009-06-10 13:36:04 -07006125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006126 void handleNewWindowLocked(WindowState newWindow) {
6127 if (!newWindow.canReceiveKeys()) {
6128 return;
6129 }
6130 synchronized (this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006131 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006132 TAG, "New key dispatch window: win="
6133 + newWindow.mClient.asBinder()
6134 + ", last=" + mLastBinder
6135 + " (token=" + (mLastWin != null ? mLastWin.mToken : null)
6136 + "), finished=" + mFinished + ", paused="
6137 + newWindow.mToken.paused);
6138
6139 // Displaying a window implicitly causes dispatching to
6140 // be unpaused. (This is to protect against bugs if someone
6141 // pauses dispatching but forgets to resume.)
6142 newWindow.mToken.paused = false;
6143
6144 mGotFirstWindow = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006145
6146 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006147 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006148 "New SYSTEM_ERROR window; resetting state");
6149 mLastWin = null;
6150 mLastBinder = null;
6151 mMotionTarget = null;
6152 mFinished = true;
6153 } else if (mLastWin != null) {
6154 // If the new window is above the window we are
6155 // waiting on, then stop waiting and let key dispatching
6156 // start on the new guy.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006157 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006158 TAG, "Last win layer=" + mLastWin.mLayer
6159 + ", new win layer=" + newWindow.mLayer);
6160 if (newWindow.mLayer >= mLastWin.mLayer) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08006161 // The new window is above the old; finish pending input to the last
6162 // window and start directing it to the new one.
6163 mLastWin.mToken.paused = false;
Christopher Tate136b1f92010-02-11 17:51:24 -08006164 doFinishedKeyLocked(false); // does a notifyAll()
6165 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006166 }
6167 }
6168
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08006169 // Now that we've put a new window state in place, make the event waiter
6170 // take notice and retarget its attentions.
6171 notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006172 }
6173 }
6174
6175 void pauseDispatchingLocked(WindowToken token) {
6176 synchronized (this)
6177 {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006178 if (DEBUG_INPUT) Slog.v(TAG, "Pausing WindowToken " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006179 token.paused = true;
6180
6181 /*
6182 if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) {
6183 mPaused = true;
6184 } else {
6185 if (mLastWin == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006186 Slog.i(TAG, "Key dispatching not paused: no last window.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006187 } else if (mFinished) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006188 Slog.i(TAG, "Key dispatching not paused: finished last key.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006189 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006190 Slog.i(TAG, "Key dispatching not paused: window in higher layer.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006191 }
6192 }
6193 */
6194 }
6195 }
6196
6197 void resumeDispatchingLocked(WindowToken token) {
6198 synchronized (this) {
6199 if (token.paused) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006200 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006201 TAG, "Resuming WindowToken " + token
6202 + ", last=" + mLastBinder
6203 + " (token=" + (mLastWin != null ? mLastWin.mToken : null)
6204 + "), finished=" + mFinished + ", paused="
6205 + token.paused);
6206 token.paused = false;
6207 if (mLastWin != null && mLastWin.mToken == token && mFinished) {
Christopher Tate136b1f92010-02-11 17:51:24 -08006208 doFinishedKeyLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006209 } else {
6210 notifyAll();
6211 }
6212 }
6213 }
6214 }
6215
6216 void setEventDispatchingLocked(boolean enabled) {
6217 synchronized (this) {
6218 mEventDispatching = enabled;
6219 notifyAll();
6220 }
6221 }
Romain Guy06882f82009-06-10 13:36:04 -07006222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006223 void appSwitchComing() {
6224 synchronized (this) {
6225 // Don't wait for more than .5 seconds for app to finish
6226 // processing the pending events.
6227 long now = SystemClock.uptimeMillis() + 500;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006228 if (DEBUG_INPUT) Slog.v(TAG, "appSwitchComing: " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006229 if (mTimeToSwitch == 0 || now < mTimeToSwitch) {
6230 mTimeToSwitch = now;
6231 }
6232 notifyAll();
6233 }
6234 }
Romain Guy06882f82009-06-10 13:36:04 -07006235
Christopher Tate136b1f92010-02-11 17:51:24 -08006236 private final void doFinishedKeyLocked(boolean force) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006237 if (mLastWin != null) {
6238 releasePendingPointerLocked(mLastWin.mSession);
6239 releasePendingTrackballLocked(mLastWin.mSession);
6240 }
Romain Guy06882f82009-06-10 13:36:04 -07006241
Christopher Tate136b1f92010-02-11 17:51:24 -08006242 if (force || mLastWin == null || !mLastWin.mToken.paused
6243 || !mLastWin.isVisibleLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006244 // If the current window has been paused, we aren't -really-
6245 // finished... so let the waiters still wait.
6246 mLastWin = null;
6247 mLastBinder = null;
6248 }
6249 mFinished = true;
6250 notifyAll();
6251 }
6252 }
6253
6254 private class KeyQ extends KeyInputQueue
6255 implements KeyInputQueue.FilterCallback {
6256 PowerManager.WakeLock mHoldingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07006257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006258 KeyQ() {
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07006259 super(mContext, WindowManagerService.this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006260 PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
6261 mHoldingScreen = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
6262 "KEEP_SCREEN_ON_FLAG");
6263 mHoldingScreen.setReferenceCounted(false);
6264 }
6265
6266 @Override
6267 boolean preprocessEvent(InputDevice device, RawInputEvent event) {
6268 if (mPolicy.preprocessInputEventTq(event)) {
6269 return true;
6270 }
Romain Guy06882f82009-06-10 13:36:04 -07006271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006272 switch (event.type) {
6273 case RawInputEvent.EV_KEY: {
6274 // XXX begin hack
6275 if (DEBUG) {
6276 if (event.keycode == KeyEvent.KEYCODE_G) {
6277 if (event.value != 0) {
6278 // G down
6279 mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
6280 }
6281 return false;
6282 }
6283 if (event.keycode == KeyEvent.KEYCODE_D) {
6284 if (event.value != 0) {
6285 //dump();
6286 }
6287 return false;
6288 }
6289 }
6290 // XXX end hack
Romain Guy06882f82009-06-10 13:36:04 -07006291
Charles Mendis322591c2009-10-29 11:06:59 -07006292 boolean screenIsOff = !mPowerManager.isScreenOn();
6293 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006294 int actions = mPolicy.interceptKeyTq(event, !screenIsOff);
Romain Guy06882f82009-06-10 13:36:04 -07006295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006296 if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) {
6297 mPowerManager.goToSleep(event.when);
6298 }
6299
6300 if (screenIsOff) {
6301 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6302 }
6303 if (screenIsDim) {
6304 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6305 }
6306 if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) {
6307 mPowerManager.userActivity(event.when, false,
Michael Chane96440f2009-05-06 10:27:36 -07006308 LocalPowerManager.BUTTON_EVENT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006309 }
Romain Guy06882f82009-06-10 13:36:04 -07006310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006311 if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) {
6312 if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) {
6313 filterQueue(this);
6314 mKeyWaiter.appSwitchComing();
6315 }
6316 return true;
6317 } else {
6318 return false;
6319 }
6320 }
Romain Guy06882f82009-06-10 13:36:04 -07006321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006322 case RawInputEvent.EV_REL: {
Charles Mendis322591c2009-10-29 11:06:59 -07006323 boolean screenIsOff = !mPowerManager.isScreenOn();
6324 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006325 if (screenIsOff) {
6326 if (!mPolicy.isWakeRelMovementTq(event.deviceId,
6327 device.classes, event)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006328 //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006329 return false;
6330 }
6331 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6332 }
6333 if (screenIsDim) {
6334 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6335 }
6336 return true;
6337 }
Romain Guy06882f82009-06-10 13:36:04 -07006338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006339 case RawInputEvent.EV_ABS: {
Charles Mendis322591c2009-10-29 11:06:59 -07006340 boolean screenIsOff = !mPowerManager.isScreenOn();
6341 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006342 if (screenIsOff) {
6343 if (!mPolicy.isWakeAbsMovementTq(event.deviceId,
6344 device.classes, event)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006345 //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006346 return false;
6347 }
6348 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6349 }
6350 if (screenIsDim) {
6351 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6352 }
6353 return true;
6354 }
Romain Guy06882f82009-06-10 13:36:04 -07006355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006356 default:
6357 return true;
6358 }
6359 }
6360
6361 public int filterEvent(QueuedEvent ev) {
6362 switch (ev.classType) {
6363 case RawInputEvent.CLASS_KEYBOARD:
6364 KeyEvent ke = (KeyEvent)ev.event;
6365 if (mPolicy.isMovementKeyTi(ke.getKeyCode())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006366 Slog.w(TAG, "Dropping movement key during app switch: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006367 + ke.getKeyCode() + ", action=" + ke.getAction());
6368 return FILTER_REMOVE;
6369 }
6370 return FILTER_ABORT;
6371 default:
6372 return FILTER_KEEP;
6373 }
6374 }
Romain Guy06882f82009-06-10 13:36:04 -07006375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006376 /**
6377 * Must be called with the main window manager lock held.
6378 */
6379 void setHoldScreenLocked(boolean holding) {
6380 boolean state = mHoldingScreen.isHeld();
6381 if (holding != state) {
6382 if (holding) {
6383 mHoldingScreen.acquire();
6384 } else {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006385 mPolicy.screenOnStoppedLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006386 mHoldingScreen.release();
6387 }
6388 }
6389 }
Michael Chan53071d62009-05-13 17:29:48 -07006390 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006391
6392 public boolean detectSafeMode() {
6393 mSafeMode = mPolicy.detectSafeMode();
6394 return mSafeMode;
6395 }
Romain Guy06882f82009-06-10 13:36:04 -07006396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006397 public void systemReady() {
6398 mPolicy.systemReady();
6399 }
Romain Guy06882f82009-06-10 13:36:04 -07006400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006401 private final class InputDispatcherThread extends Thread {
6402 // Time to wait when there is nothing to do: 9999 seconds.
6403 static final int LONG_WAIT=9999*1000;
6404
6405 public InputDispatcherThread() {
6406 super("InputDispatcher");
6407 }
Romain Guy06882f82009-06-10 13:36:04 -07006408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006409 @Override
6410 public void run() {
6411 while (true) {
6412 try {
6413 process();
6414 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006415 Slog.e(TAG, "Exception in input dispatcher", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006416 }
6417 }
6418 }
Romain Guy06882f82009-06-10 13:36:04 -07006419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006420 private void process() {
6421 android.os.Process.setThreadPriority(
6422 android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);
Romain Guy06882f82009-06-10 13:36:04 -07006423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006424 // The last key event we saw
6425 KeyEvent lastKey = null;
6426
6427 // Last keydown time for auto-repeating keys
6428 long lastKeyTime = SystemClock.uptimeMillis();
6429 long nextKeyTime = lastKeyTime+LONG_WAIT;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006430 long downTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006431
Romain Guy06882f82009-06-10 13:36:04 -07006432 // How many successive repeats we generated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006433 int keyRepeatCount = 0;
6434
6435 // Need to report that configuration has changed?
6436 boolean configChanged = false;
Romain Guy06882f82009-06-10 13:36:04 -07006437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006438 while (true) {
6439 long curTime = SystemClock.uptimeMillis();
6440
Joe Onorato8a9b2202010-02-26 18:56:32 -08006441 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006442 TAG, "Waiting for next key: now=" + curTime
6443 + ", repeat @ " + nextKeyTime);
6444
6445 // Retrieve next event, waiting only as long as the next
6446 // repeat timeout. If the configuration has changed, then
6447 // don't wait at all -- we'll report the change as soon as
6448 // we have processed all events.
6449 QueuedEvent ev = mQueue.getEvent(
6450 (int)((!configChanged && curTime < nextKeyTime)
6451 ? (nextKeyTime-curTime) : 0));
6452
Joe Onorato8a9b2202010-02-26 18:56:32 -08006453 if (DEBUG_INPUT && ev != null) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006454 TAG, "Event: type=" + ev.classType + " data=" + ev.event);
6455
Michael Chan53071d62009-05-13 17:29:48 -07006456 if (MEASURE_LATENCY) {
6457 lt.sample("2 got event ", System.nanoTime() - ev.whenNano);
6458 }
6459
Mike Lockwood3d0ea722009-10-21 22:58:29 -04006460 if (lastKey != null && !mPolicy.allowKeyRepeat()) {
6461 // cancel key repeat at the request of the policy.
6462 lastKey = null;
6463 downTime = 0;
6464 lastKeyTime = curTime;
6465 nextKeyTime = curTime + LONG_WAIT;
6466 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006467 try {
6468 if (ev != null) {
Michael Chan53071d62009-05-13 17:29:48 -07006469 curTime = SystemClock.uptimeMillis();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006470 int eventType;
6471 if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) {
6472 eventType = eventType((MotionEvent)ev.event);
6473 } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD ||
6474 ev.classType == RawInputEvent.CLASS_TRACKBALL) {
6475 eventType = LocalPowerManager.BUTTON_EVENT;
6476 } else {
6477 eventType = LocalPowerManager.OTHER_EVENT;
6478 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07006479 try {
Michael Chan53071d62009-05-13 17:29:48 -07006480 if ((curTime - mLastBatteryStatsCallTime)
Michael Chane96440f2009-05-06 10:27:36 -07006481 >= MIN_TIME_BETWEEN_USERACTIVITIES) {
Michael Chan53071d62009-05-13 17:29:48 -07006482 mLastBatteryStatsCallTime = curTime;
Michael Chane96440f2009-05-06 10:27:36 -07006483 mBatteryStats.noteInputEvent();
6484 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07006485 } catch (RemoteException e) {
6486 // Ignore
6487 }
Michael Chane10de972009-05-18 11:24:50 -07006488
Mike Lockwood5db42402009-11-30 14:51:51 -05006489 if (ev.classType == RawInputEvent.CLASS_CONFIGURATION_CHANGED) {
6490 // do not wake screen in this case
6491 } else if (eventType != TOUCH_EVENT
Michael Chane10de972009-05-18 11:24:50 -07006492 && eventType != LONG_TOUCH_EVENT
6493 && eventType != CHEEK_EVENT) {
6494 mPowerManager.userActivity(curTime, false,
6495 eventType, false);
6496 } else if (mLastTouchEventType != eventType
6497 || (curTime - mLastUserActivityCallTime)
6498 >= MIN_TIME_BETWEEN_USERACTIVITIES) {
6499 mLastUserActivityCallTime = curTime;
6500 mLastTouchEventType = eventType;
6501 mPowerManager.userActivity(curTime, false,
6502 eventType, false);
6503 }
6504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006505 switch (ev.classType) {
6506 case RawInputEvent.CLASS_KEYBOARD:
6507 KeyEvent ke = (KeyEvent)ev.event;
6508 if (ke.isDown()) {
6509 lastKey = ke;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006510 downTime = curTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006511 keyRepeatCount = 0;
6512 lastKeyTime = curTime;
6513 nextKeyTime = lastKeyTime
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006514 + ViewConfiguration.getLongPressTimeout();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006515 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006516 TAG, "Received key down: first repeat @ "
6517 + nextKeyTime);
6518 } else {
6519 lastKey = null;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006520 downTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006521 // Arbitrary long timeout.
6522 lastKeyTime = curTime;
6523 nextKeyTime = curTime + LONG_WAIT;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006524 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006525 TAG, "Received key up: ignore repeat @ "
6526 + nextKeyTime);
6527 }
6528 dispatchKey((KeyEvent)ev.event, 0, 0);
6529 mQueue.recycleEvent(ev);
6530 break;
6531 case RawInputEvent.CLASS_TOUCHSCREEN:
Joe Onorato8a9b2202010-02-26 18:56:32 -08006532 //Slog.i(TAG, "Read next event " + ev);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006533 dispatchPointer(ev, (MotionEvent)ev.event, 0, 0);
6534 break;
6535 case RawInputEvent.CLASS_TRACKBALL:
6536 dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0);
6537 break;
6538 case RawInputEvent.CLASS_CONFIGURATION_CHANGED:
6539 configChanged = true;
6540 break;
6541 default:
6542 mQueue.recycleEvent(ev);
6543 break;
6544 }
Romain Guy06882f82009-06-10 13:36:04 -07006545
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006546 } else if (configChanged) {
6547 configChanged = false;
6548 sendNewConfiguration();
Romain Guy06882f82009-06-10 13:36:04 -07006549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006550 } else if (lastKey != null) {
6551 curTime = SystemClock.uptimeMillis();
Romain Guy06882f82009-06-10 13:36:04 -07006552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006553 // Timeout occurred while key was down. If it is at or
6554 // past the key repeat time, dispatch the repeat.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006555 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006556 TAG, "Key timeout: repeat=" + nextKeyTime
6557 + ", now=" + curTime);
6558 if (curTime < nextKeyTime) {
6559 continue;
6560 }
Romain Guy06882f82009-06-10 13:36:04 -07006561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006562 lastKeyTime = nextKeyTime;
6563 nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY;
6564 keyRepeatCount++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006565 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006566 TAG, "Key repeat: count=" + keyRepeatCount
6567 + ", next @ " + nextKeyTime);
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006568 KeyEvent newEvent;
6569 if (downTime != 0 && (downTime
6570 + ViewConfiguration.getLongPressTimeout())
6571 <= curTime) {
6572 newEvent = KeyEvent.changeTimeRepeat(lastKey,
6573 curTime, keyRepeatCount,
6574 lastKey.getFlags() | KeyEvent.FLAG_LONG_PRESS);
6575 downTime = 0;
6576 } else {
6577 newEvent = KeyEvent.changeTimeRepeat(lastKey,
6578 curTime, keyRepeatCount);
6579 }
6580 dispatchKey(newEvent, 0, 0);
Romain Guy06882f82009-06-10 13:36:04 -07006581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006582 } else {
6583 curTime = SystemClock.uptimeMillis();
Romain Guy06882f82009-06-10 13:36:04 -07006584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006585 lastKeyTime = curTime;
6586 nextKeyTime = curTime + LONG_WAIT;
6587 }
Romain Guy06882f82009-06-10 13:36:04 -07006588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006589 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006590 Slog.e(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006591 "Input thread received uncaught exception: " + e, e);
6592 }
6593 }
6594 }
6595 }
6596
6597 // -------------------------------------------------------------
6598 // Client Session State
6599 // -------------------------------------------------------------
6600
6601 private final class Session extends IWindowSession.Stub
6602 implements IBinder.DeathRecipient {
6603 final IInputMethodClient mClient;
6604 final IInputContext mInputContext;
6605 final int mUid;
6606 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006607 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006608 SurfaceSession mSurfaceSession;
6609 int mNumWindow = 0;
6610 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006612 /**
6613 * Current pointer move event being dispatched to client window... must
6614 * hold key lock to access.
6615 */
6616 QueuedEvent mPendingPointerMove;
6617 WindowState mPendingPointerWindow;
Romain Guy06882f82009-06-10 13:36:04 -07006618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006619 /**
6620 * Current trackball move event being dispatched to client window... must
6621 * hold key lock to access.
6622 */
6623 QueuedEvent mPendingTrackballMove;
6624 WindowState mPendingTrackballWindow;
6625
6626 public Session(IInputMethodClient client, IInputContext inputContext) {
6627 mClient = client;
6628 mInputContext = inputContext;
6629 mUid = Binder.getCallingUid();
6630 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006631 StringBuilder sb = new StringBuilder();
6632 sb.append("Session{");
6633 sb.append(Integer.toHexString(System.identityHashCode(this)));
6634 sb.append(" uid ");
6635 sb.append(mUid);
6636 sb.append("}");
6637 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006639 synchronized (mWindowMap) {
6640 if (mInputMethodManager == null && mHaveInputMethods) {
6641 IBinder b = ServiceManager.getService(
6642 Context.INPUT_METHOD_SERVICE);
6643 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6644 }
6645 }
6646 long ident = Binder.clearCallingIdentity();
6647 try {
6648 // Note: it is safe to call in to the input method manager
6649 // here because we are not holding our lock.
6650 if (mInputMethodManager != null) {
6651 mInputMethodManager.addClient(client, inputContext,
6652 mUid, mPid);
6653 } else {
6654 client.setUsingInputMethod(false);
6655 }
6656 client.asBinder().linkToDeath(this, 0);
6657 } catch (RemoteException e) {
6658 // The caller has died, so we can just forget about this.
6659 try {
6660 if (mInputMethodManager != null) {
6661 mInputMethodManager.removeClient(client);
6662 }
6663 } catch (RemoteException ee) {
6664 }
6665 } finally {
6666 Binder.restoreCallingIdentity(ident);
6667 }
6668 }
Romain Guy06882f82009-06-10 13:36:04 -07006669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006670 @Override
6671 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6672 throws RemoteException {
6673 try {
6674 return super.onTransact(code, data, reply, flags);
6675 } catch (RuntimeException e) {
6676 // Log all 'real' exceptions thrown to the caller
6677 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006678 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006679 }
6680 throw e;
6681 }
6682 }
6683
6684 public void binderDied() {
6685 // Note: it is safe to call in to the input method manager
6686 // here because we are not holding our lock.
6687 try {
6688 if (mInputMethodManager != null) {
6689 mInputMethodManager.removeClient(mClient);
6690 }
6691 } catch (RemoteException e) {
6692 }
6693 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006694 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006695 mClientDead = true;
6696 killSessionLocked();
6697 }
6698 }
6699
6700 public int add(IWindow window, WindowManager.LayoutParams attrs,
6701 int viewVisibility, Rect outContentInsets) {
6702 return addWindow(this, window, attrs, viewVisibility, outContentInsets);
6703 }
Romain Guy06882f82009-06-10 13:36:04 -07006704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006705 public void remove(IWindow window) {
6706 removeWindow(this, window);
6707 }
Romain Guy06882f82009-06-10 13:36:04 -07006708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006709 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6710 int requestedWidth, int requestedHeight, int viewFlags,
6711 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006712 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006713 return relayoutWindow(this, window, attrs,
6714 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006715 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006716 }
Romain Guy06882f82009-06-10 13:36:04 -07006717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006718 public void setTransparentRegion(IWindow window, Region region) {
6719 setTransparentRegionWindow(this, window, region);
6720 }
Romain Guy06882f82009-06-10 13:36:04 -07006721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006722 public void setInsets(IWindow window, int touchableInsets,
6723 Rect contentInsets, Rect visibleInsets) {
6724 setInsetsWindow(this, window, touchableInsets, contentInsets,
6725 visibleInsets);
6726 }
Romain Guy06882f82009-06-10 13:36:04 -07006727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006728 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6729 getWindowDisplayFrame(this, window, outDisplayFrame);
6730 }
Romain Guy06882f82009-06-10 13:36:04 -07006731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006732 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006733 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006734 TAG, "IWindow finishDrawing called for " + window);
6735 finishDrawingWindow(this, window);
6736 }
6737
6738 public void finishKey(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006739 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006740 TAG, "IWindow finishKey called for " + window);
6741 mKeyWaiter.finishedKey(this, window, false,
6742 KeyWaiter.RETURN_NOTHING);
6743 }
6744
6745 public MotionEvent getPendingPointerMove(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006746 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006747 TAG, "IWindow getPendingMotionEvent called for " + window);
6748 return mKeyWaiter.finishedKey(this, window, false,
6749 KeyWaiter.RETURN_PENDING_POINTER);
6750 }
Romain Guy06882f82009-06-10 13:36:04 -07006751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006752 public MotionEvent getPendingTrackballMove(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006753 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006754 TAG, "IWindow getPendingMotionEvent called for " + window);
6755 return mKeyWaiter.finishedKey(this, window, false,
6756 KeyWaiter.RETURN_PENDING_TRACKBALL);
6757 }
6758
6759 public void setInTouchMode(boolean mode) {
6760 synchronized(mWindowMap) {
6761 mInTouchMode = mode;
6762 }
6763 }
6764
6765 public boolean getInTouchMode() {
6766 synchronized(mWindowMap) {
6767 return mInTouchMode;
6768 }
6769 }
6770
6771 public boolean performHapticFeedback(IWindow window, int effectId,
6772 boolean always) {
6773 synchronized(mWindowMap) {
6774 long ident = Binder.clearCallingIdentity();
6775 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006776 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006777 windowForClientLocked(this, window, true),
6778 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006779 } finally {
6780 Binder.restoreCallingIdentity(ident);
6781 }
6782 }
6783 }
Romain Guy06882f82009-06-10 13:36:04 -07006784
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006785 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006786 synchronized(mWindowMap) {
6787 long ident = Binder.clearCallingIdentity();
6788 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006789 setWindowWallpaperPositionLocked(
6790 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006791 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006792 } finally {
6793 Binder.restoreCallingIdentity(ident);
6794 }
6795 }
6796 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006797
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006798 public void wallpaperOffsetsComplete(IBinder window) {
6799 WindowManagerService.this.wallpaperOffsetsComplete(window);
6800 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006801
Dianne Hackborn75804932009-10-20 20:15:20 -07006802 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6803 int z, Bundle extras, boolean sync) {
6804 synchronized(mWindowMap) {
6805 long ident = Binder.clearCallingIdentity();
6806 try {
6807 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006808 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006809 action, x, y, z, extras, sync);
6810 } finally {
6811 Binder.restoreCallingIdentity(ident);
6812 }
6813 }
6814 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006815
Dianne Hackborn75804932009-10-20 20:15:20 -07006816 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6817 WindowManagerService.this.wallpaperCommandComplete(window, result);
6818 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006820 void windowAddedLocked() {
6821 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006822 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006823 TAG, "First window added to " + this + ", creating SurfaceSession");
6824 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006825 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006826 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006827 mSessions.add(this);
6828 }
6829 mNumWindow++;
6830 }
6831
6832 void windowRemovedLocked() {
6833 mNumWindow--;
6834 killSessionLocked();
6835 }
Romain Guy06882f82009-06-10 13:36:04 -07006836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006837 void killSessionLocked() {
6838 if (mNumWindow <= 0 && mClientDead) {
6839 mSessions.remove(this);
6840 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006841 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006842 TAG, "Last window removed from " + this
6843 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006844 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006845 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006846 try {
6847 mSurfaceSession.kill();
6848 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006849 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006850 + mSurfaceSession + " in session " + this
6851 + ": " + e.toString());
6852 }
6853 mSurfaceSession = null;
6854 }
6855 }
6856 }
Romain Guy06882f82009-06-10 13:36:04 -07006857
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006858 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006859 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6860 pw.print(" mClientDead="); pw.print(mClientDead);
6861 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
6862 if (mPendingPointerWindow != null || mPendingPointerMove != null) {
6863 pw.print(prefix);
6864 pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow);
6865 pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove);
6866 }
6867 if (mPendingTrackballWindow != null || mPendingTrackballMove != null) {
6868 pw.print(prefix);
6869 pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow);
6870 pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove);
6871 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006872 }
6873
6874 @Override
6875 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006876 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006877 }
6878 }
6879
6880 // -------------------------------------------------------------
6881 // Client Window State
6882 // -------------------------------------------------------------
6883
6884 private final class WindowState implements WindowManagerPolicy.WindowState {
6885 final Session mSession;
6886 final IWindow mClient;
6887 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006888 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006889 AppWindowToken mAppToken;
6890 AppWindowToken mTargetAppToken;
6891 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6892 final DeathRecipient mDeathRecipient;
6893 final WindowState mAttachedWindow;
6894 final ArrayList mChildWindows = new ArrayList();
6895 final int mBaseLayer;
6896 final int mSubLayer;
6897 final boolean mLayoutAttached;
6898 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006899 final boolean mIsWallpaper;
6900 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006901 int mViewVisibility;
6902 boolean mPolicyVisibility = true;
6903 boolean mPolicyVisibilityAfterAnim = true;
6904 boolean mAppFreezing;
6905 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006906 boolean mReportDestroySurface;
6907 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006908 boolean mAttachedHidden; // is our parent window hidden?
6909 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006910 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006911 int mRequestedWidth;
6912 int mRequestedHeight;
6913 int mLastRequestedWidth;
6914 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006915 int mLayer;
6916 int mAnimLayer;
6917 int mLastLayer;
6918 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006919 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006920 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006921
6922 WindowState mNextOutsideTouch;
Romain Guy06882f82009-06-10 13:36:04 -07006923
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006924 int mLayoutSeq = -1;
6925
6926 Configuration mConfiguration = null;
6927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006928 // Actual frame shown on-screen (may be modified by animation)
6929 final Rect mShownFrame = new Rect();
6930 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006932 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006933 * Set when we have changed the size of the surface, to know that
6934 * we must tell them application to resize (and thus redraw itself).
6935 */
6936 boolean mSurfaceResized;
6937
6938 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006939 * Insets that determine the actually visible area
6940 */
6941 final Rect mVisibleInsets = new Rect();
6942 final Rect mLastVisibleInsets = new Rect();
6943 boolean mVisibleInsetsChanged;
6944
6945 /**
6946 * Insets that are covered by system windows
6947 */
6948 final Rect mContentInsets = new Rect();
6949 final Rect mLastContentInsets = new Rect();
6950 boolean mContentInsetsChanged;
6951
6952 /**
6953 * Set to true if we are waiting for this window to receive its
6954 * given internal insets before laying out other windows based on it.
6955 */
6956 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006958 /**
6959 * These are the content insets that were given during layout for
6960 * this window, to be applied to windows behind it.
6961 */
6962 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006964 /**
6965 * These are the visible insets that were given during layout for
6966 * this window, to be applied to windows behind it.
6967 */
6968 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006970 /**
6971 * Flag indicating whether the touchable region should be adjusted by
6972 * the visible insets; if false the area outside the visible insets is
6973 * NOT touchable, so we must use those to adjust the frame during hit
6974 * tests.
6975 */
6976 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006978 // Current transformation being applied.
6979 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6980 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6981 float mHScale=1, mVScale=1;
6982 float mLastHScale=1, mLastVScale=1;
6983 final Matrix mTmpMatrix = new Matrix();
6984
6985 // "Real" frame that the application sees.
6986 final Rect mFrame = new Rect();
6987 final Rect mLastFrame = new Rect();
6988
6989 final Rect mContainingFrame = new Rect();
6990 final Rect mDisplayFrame = new Rect();
6991 final Rect mContentFrame = new Rect();
6992 final Rect mVisibleFrame = new Rect();
6993
6994 float mShownAlpha = 1;
6995 float mAlpha = 1;
6996 float mLastAlpha = 1;
6997
6998 // Set to true if, when the window gets displayed, it should perform
6999 // an enter animation.
7000 boolean mEnterAnimationPending;
7001
7002 // Currently running animation.
7003 boolean mAnimating;
7004 boolean mLocalAnimating;
7005 Animation mAnimation;
7006 boolean mAnimationIsEntrance;
7007 boolean mHasTransformation;
7008 boolean mHasLocalTransformation;
7009 final Transformation mTransformation = new Transformation();
7010
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007011 // If a window showing a wallpaper: the requested offset for the
7012 // wallpaper; if a wallpaper window: the currently applied offset.
7013 float mWallpaperX = -1;
7014 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007015
7016 // If a window showing a wallpaper: what fraction of the offset
7017 // range corresponds to a full virtual screen.
7018 float mWallpaperXStep = -1;
7019 float mWallpaperYStep = -1;
7020
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007021 // Wallpaper windows: pixels offset based on above variables.
7022 int mXOffset;
7023 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007025 // This is set after IWindowSession.relayout() has been called at
7026 // least once for the window. It allows us to detect the situation
7027 // where we don't yet have a surface, but should have one soon, so
7028 // we can give the window focus before waiting for the relayout.
7029 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07007030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007031 // This is set after the Surface has been created but before the
7032 // window has been drawn. During this time the surface is hidden.
7033 boolean mDrawPending;
7034
7035 // This is set after the window has finished drawing for the first
7036 // time but before its surface is shown. The surface will be
7037 // displayed when the next layout is run.
7038 boolean mCommitDrawPending;
7039
7040 // This is set during the time after the window's drawing has been
7041 // committed, and before its surface is actually shown. It is used
7042 // to delay showing the surface until all windows in a token are ready
7043 // to be shown.
7044 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07007045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007046 // Set when the window has been shown in the screen the first time.
7047 boolean mHasDrawn;
7048
7049 // Currently running an exit animation?
7050 boolean mExiting;
7051
7052 // Currently on the mDestroySurface list?
7053 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07007054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007055 // Completely remove from window manager after exit animation?
7056 boolean mRemoveOnExit;
7057
7058 // Set when the orientation is changing and this window has not yet
7059 // been updated for the new orientation.
7060 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07007061
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007062 // Is this window now (or just being) removed?
7063 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07007064
Dianne Hackborn16064f92010-03-25 00:47:24 -07007065 // For debugging, this is the last information given to the surface flinger.
7066 boolean mSurfaceShown;
7067 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
7068 int mSurfaceLayer;
7069 float mSurfaceAlpha;
7070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007071 WindowState(Session s, IWindow c, WindowToken token,
7072 WindowState attachedWindow, WindowManager.LayoutParams a,
7073 int viewVisibility) {
7074 mSession = s;
7075 mClient = c;
7076 mToken = token;
7077 mAttrs.copyFrom(a);
7078 mViewVisibility = viewVisibility;
7079 DeathRecipient deathRecipient = new DeathRecipient();
7080 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007081 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007082 TAG, "Window " + this + " client=" + c.asBinder()
7083 + " token=" + token + " (" + mAttrs.token + ")");
7084 try {
7085 c.asBinder().linkToDeath(deathRecipient, 0);
7086 } catch (RemoteException e) {
7087 mDeathRecipient = null;
7088 mAttachedWindow = null;
7089 mLayoutAttached = false;
7090 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007091 mIsWallpaper = false;
7092 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007093 mBaseLayer = 0;
7094 mSubLayer = 0;
7095 return;
7096 }
7097 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07007098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007099 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
7100 mAttrs.type <= LAST_SUB_WINDOW)) {
7101 // The multiplier here is to reserve space for multiple
7102 // windows in the same type layer.
7103 mBaseLayer = mPolicy.windowTypeToLayerLw(
7104 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
7105 + TYPE_LAYER_OFFSET;
7106 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
7107 mAttachedWindow = attachedWindow;
7108 mAttachedWindow.mChildWindows.add(this);
7109 mLayoutAttached = mAttrs.type !=
7110 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
7111 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
7112 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007113 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
7114 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007115 } else {
7116 // The multiplier here is to reserve space for multiple
7117 // windows in the same type layer.
7118 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
7119 * TYPE_LAYER_MULTIPLIER
7120 + TYPE_LAYER_OFFSET;
7121 mSubLayer = 0;
7122 mAttachedWindow = null;
7123 mLayoutAttached = false;
7124 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
7125 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007126 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
7127 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007128 }
7129
7130 WindowState appWin = this;
7131 while (appWin.mAttachedWindow != null) {
7132 appWin = mAttachedWindow;
7133 }
7134 WindowToken appToken = appWin.mToken;
7135 while (appToken.appWindowToken == null) {
7136 WindowToken parent = mTokenMap.get(appToken.token);
7137 if (parent == null || appToken == parent) {
7138 break;
7139 }
7140 appToken = parent;
7141 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007142 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007143 mAppToken = appToken.appWindowToken;
7144
7145 mSurface = null;
7146 mRequestedWidth = 0;
7147 mRequestedHeight = 0;
7148 mLastRequestedWidth = 0;
7149 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007150 mXOffset = 0;
7151 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007152 mLayer = 0;
7153 mAnimLayer = 0;
7154 mLastLayer = 0;
7155 }
7156
7157 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007158 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007159 TAG, "Attaching " + this + " token=" + mToken
7160 + ", list=" + mToken.windows);
7161 mSession.windowAddedLocked();
7162 }
7163
7164 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7165 mHaveFrame = true;
7166
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007167 final Rect container = mContainingFrame;
7168 container.set(pf);
7169
7170 final Rect display = mDisplayFrame;
7171 display.set(df);
7172
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007173 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007174 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007175 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7176 display.intersect(mCompatibleScreenFrame);
7177 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007178 }
7179
7180 final int pw = container.right - container.left;
7181 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007182
7183 int w,h;
7184 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7185 w = mAttrs.width < 0 ? pw : mAttrs.width;
7186 h = mAttrs.height< 0 ? ph : mAttrs.height;
7187 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007188 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7189 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007190 }
Romain Guy06882f82009-06-10 13:36:04 -07007191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007192 final Rect content = mContentFrame;
7193 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007195 final Rect visible = mVisibleFrame;
7196 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007198 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007199 final int fw = frame.width();
7200 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007202 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7203 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7204
7205 Gravity.apply(mAttrs.gravity, w, h, container,
7206 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7207 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7208
7209 //System.out.println("Out: " + mFrame);
7210
7211 // Now make sure the window fits in the overall display.
7212 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007214 // Make sure the content and visible frames are inside of the
7215 // final window frame.
7216 if (content.left < frame.left) content.left = frame.left;
7217 if (content.top < frame.top) content.top = frame.top;
7218 if (content.right > frame.right) content.right = frame.right;
7219 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7220 if (visible.left < frame.left) visible.left = frame.left;
7221 if (visible.top < frame.top) visible.top = frame.top;
7222 if (visible.right > frame.right) visible.right = frame.right;
7223 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007225 final Rect contentInsets = mContentInsets;
7226 contentInsets.left = content.left-frame.left;
7227 contentInsets.top = content.top-frame.top;
7228 contentInsets.right = frame.right-content.right;
7229 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007231 final Rect visibleInsets = mVisibleInsets;
7232 visibleInsets.left = visible.left-frame.left;
7233 visibleInsets.top = visible.top-frame.top;
7234 visibleInsets.right = frame.right-visible.right;
7235 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007236
Dianne Hackborn284ac932009-08-28 10:34:25 -07007237 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7238 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007239 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007240 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007242 if (localLOGV) {
7243 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7244 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007245 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007246 + mRequestedWidth + ", mRequestedheight="
7247 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7248 + "): frame=" + mFrame.toShortString()
7249 + " ci=" + contentInsets.toShortString()
7250 + " vi=" + visibleInsets.toShortString());
7251 //}
7252 }
7253 }
Romain Guy06882f82009-06-10 13:36:04 -07007254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007255 public Rect getFrameLw() {
7256 return mFrame;
7257 }
7258
7259 public Rect getShownFrameLw() {
7260 return mShownFrame;
7261 }
7262
7263 public Rect getDisplayFrameLw() {
7264 return mDisplayFrame;
7265 }
7266
7267 public Rect getContentFrameLw() {
7268 return mContentFrame;
7269 }
7270
7271 public Rect getVisibleFrameLw() {
7272 return mVisibleFrame;
7273 }
7274
7275 public boolean getGivenInsetsPendingLw() {
7276 return mGivenInsetsPending;
7277 }
7278
7279 public Rect getGivenContentInsetsLw() {
7280 return mGivenContentInsets;
7281 }
Romain Guy06882f82009-06-10 13:36:04 -07007282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007283 public Rect getGivenVisibleInsetsLw() {
7284 return mGivenVisibleInsets;
7285 }
Romain Guy06882f82009-06-10 13:36:04 -07007286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007287 public WindowManager.LayoutParams getAttrs() {
7288 return mAttrs;
7289 }
7290
7291 public int getSurfaceLayer() {
7292 return mLayer;
7293 }
Romain Guy06882f82009-06-10 13:36:04 -07007294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007295 public IApplicationToken getAppToken() {
7296 return mAppToken != null ? mAppToken.appToken : null;
7297 }
7298
7299 public boolean hasAppShownWindows() {
7300 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7301 }
7302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007303 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007304 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007305 TAG, "Setting animation in " + this + ": " + anim);
7306 mAnimating = false;
7307 mLocalAnimating = false;
7308 mAnimation = anim;
7309 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7310 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7311 }
7312
7313 public void clearAnimation() {
7314 if (mAnimation != null) {
7315 mAnimating = true;
7316 mLocalAnimating = false;
7317 mAnimation = null;
7318 }
7319 }
Romain Guy06882f82009-06-10 13:36:04 -07007320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007321 Surface createSurfaceLocked() {
7322 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007323 mReportDestroySurface = false;
7324 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007325 mDrawPending = true;
7326 mCommitDrawPending = false;
7327 mReadyToShow = false;
7328 if (mAppToken != null) {
7329 mAppToken.allDrawn = false;
7330 }
7331
7332 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07007333 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007334 flags |= Surface.PUSH_BUFFERS;
7335 }
7336
7337 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7338 flags |= Surface.SECURE;
7339 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007340 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007341 TAG, "Creating surface in session "
7342 + mSession.mSurfaceSession + " window " + this
7343 + " w=" + mFrame.width()
7344 + " h=" + mFrame.height() + " format="
7345 + mAttrs.format + " flags=" + flags);
7346
7347 int w = mFrame.width();
7348 int h = mFrame.height();
7349 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7350 // for a scaled surface, we always want the requested
7351 // size.
7352 w = mRequestedWidth;
7353 h = mRequestedHeight;
7354 }
7355
Romain Guy9825ec62009-10-01 00:58:09 -07007356 // Something is wrong and SurfaceFlinger will not like this,
7357 // try to revert to sane values
7358 if (w <= 0) w = 1;
7359 if (h <= 0) h = 1;
7360
Dianne Hackborn16064f92010-03-25 00:47:24 -07007361 mSurfaceShown = false;
7362 mSurfaceLayer = 0;
7363 mSurfaceAlpha = 1;
7364 mSurfaceX = 0;
7365 mSurfaceY = 0;
7366 mSurfaceW = w;
7367 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007368 try {
7369 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007370 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007371 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007372 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007373 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007374 + mSurface + " IN SESSION "
7375 + mSession.mSurfaceSession
7376 + ": pid=" + mSession.mPid + " format="
7377 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007378 + Integer.toHexString(flags)
7379 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007380 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007381 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007382 reclaimSomeSurfaceMemoryLocked(this, "create");
7383 return null;
7384 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007385 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007386 return null;
7387 }
Romain Guy06882f82009-06-10 13:36:04 -07007388
Joe Onorato8a9b2202010-02-26 18:56:32 -08007389 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007390 TAG, "Got surface: " + mSurface
7391 + ", set left=" + mFrame.left + " top=" + mFrame.top
7392 + ", animLayer=" + mAnimLayer);
7393 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007394 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007395 if (SHOW_TRANSACTIONS) logSurface(this,
7396 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
7397 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7398 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007399 }
7400 Surface.openTransaction();
7401 try {
7402 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007403 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007404 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007405 mSurface.setPosition(mSurfaceX, mSurfaceY);
7406 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007407 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007408 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007409 mSurface.hide();
7410 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007411 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007412 mSurface.setFlags(Surface.SURFACE_DITHER,
7413 Surface.SURFACE_DITHER);
7414 }
7415 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007416 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007417 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7418 }
7419 mLastHidden = true;
7420 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007421 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007422 Surface.closeTransaction();
7423 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007424 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007425 TAG, "Created surface " + this);
7426 }
7427 return mSurface;
7428 }
Romain Guy06882f82009-06-10 13:36:04 -07007429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007430 void destroySurfaceLocked() {
7431 // Window is no longer on-screen, so can no longer receive
7432 // key events... if we were waiting for it to finish
7433 // handling a key event, the wait is over!
7434 mKeyWaiter.finishedKey(mSession, mClient, true,
7435 KeyWaiter.RETURN_NOTHING);
7436 mKeyWaiter.releasePendingPointerLocked(mSession);
7437 mKeyWaiter.releasePendingTrackballLocked(mSession);
7438
7439 if (mAppToken != null && this == mAppToken.startingWindow) {
7440 mAppToken.startingDisplayed = false;
7441 }
Romain Guy06882f82009-06-10 13:36:04 -07007442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007443 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007444 mDrawPending = false;
7445 mCommitDrawPending = false;
7446 mReadyToShow = false;
7447
7448 int i = mChildWindows.size();
7449 while (i > 0) {
7450 i--;
7451 WindowState c = (WindowState)mChildWindows.get(i);
7452 c.mAttachedHidden = true;
7453 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007454
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007455 if (mReportDestroySurface) {
7456 mReportDestroySurface = false;
7457 mSurfacePendingDestroy = true;
7458 try {
7459 mClient.dispatchGetNewSurface();
7460 // We'll really destroy on the next time around.
7461 return;
7462 } catch (RemoteException e) {
7463 }
7464 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007466 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007467 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007468 RuntimeException e = null;
7469 if (!HIDE_STACK_CRAWLS) {
7470 e = new RuntimeException();
7471 e.fillInStackTrace();
7472 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007473 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007474 + mSurface + ", session " + mSession, e);
7475 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007476 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007477 RuntimeException e = null;
7478 if (!HIDE_STACK_CRAWLS) {
7479 e = new RuntimeException();
7480 e.fillInStackTrace();
7481 }
7482 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007483 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007484 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007485 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007486 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007487 + " surface " + mSurface + " session " + mSession
7488 + ": " + e.toString());
7489 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007490
Dianne Hackborn16064f92010-03-25 00:47:24 -07007491 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007492 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007493 }
7494 }
7495
7496 boolean finishDrawingLocked() {
7497 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007498 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007499 TAG, "finishDrawingLocked: " + mSurface);
7500 mCommitDrawPending = true;
7501 mDrawPending = false;
7502 return true;
7503 }
7504 return false;
7505 }
7506
7507 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007508 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007509 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007510 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007511 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007512 }
7513 mCommitDrawPending = false;
7514 mReadyToShow = true;
7515 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7516 final AppWindowToken atoken = mAppToken;
7517 if (atoken == null || atoken.allDrawn || starting) {
7518 performShowLocked();
7519 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007520 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007521 }
7522
7523 // This must be called while inside a transaction.
7524 boolean performShowLocked() {
7525 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007526 RuntimeException e = null;
7527 if (!HIDE_STACK_CRAWLS) {
7528 e = new RuntimeException();
7529 e.fillInStackTrace();
7530 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007531 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007532 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7533 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7534 }
7535 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007536 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7537 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007538 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007539 + " during animation: policyVis=" + mPolicyVisibility
7540 + " attHidden=" + mAttachedHidden
7541 + " tok.hiddenRequested="
7542 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007543 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007544 + (mAppToken != null ? mAppToken.hidden : false)
7545 + " animating=" + mAnimating
7546 + " tok animating="
7547 + (mAppToken != null ? mAppToken.animating : false));
7548 if (!showSurfaceRobustlyLocked(this)) {
7549 return false;
7550 }
7551 mLastAlpha = -1;
7552 mHasDrawn = true;
7553 mLastHidden = false;
7554 mReadyToShow = false;
7555 enableScreenIfNeededLocked();
7556
7557 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007559 int i = mChildWindows.size();
7560 while (i > 0) {
7561 i--;
7562 WindowState c = (WindowState)mChildWindows.get(i);
7563 if (c.mSurface != null && c.mAttachedHidden) {
7564 c.mAttachedHidden = false;
7565 c.performShowLocked();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007566 // It hadn't been shown, which means layout not
7567 // performed on it, so now we want to make sure to
7568 // do a layout. If called from within the transaction
7569 // loop, this will cause it to restart with a new
7570 // layout.
7571 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007572 }
7573 }
Romain Guy06882f82009-06-10 13:36:04 -07007574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007575 if (mAttrs.type != TYPE_APPLICATION_STARTING
7576 && mAppToken != null) {
7577 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007578
Dianne Hackborn248b1882009-09-16 16:46:44 -07007579 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007580 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007581 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007582 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007583 // If this initial window is animating, stop it -- we
7584 // will do an animation to reveal it from behind the
7585 // starting window, so there is no need for it to also
7586 // be doing its own stuff.
7587 if (mAnimation != null) {
7588 mAnimation = null;
7589 // Make sure we clean up the animation.
7590 mAnimating = true;
7591 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007592 mFinishedStarting.add(mAppToken);
7593 mH.sendEmptyMessage(H.FINISHED_STARTING);
7594 }
7595 mAppToken.updateReportedVisibilityLocked();
7596 }
7597 }
7598 return true;
7599 }
Romain Guy06882f82009-06-10 13:36:04 -07007600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007601 // This must be called while inside a transaction. Returns true if
7602 // there is more animation to run.
7603 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007604 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007605 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007607 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7608 mHasTransformation = true;
7609 mHasLocalTransformation = true;
7610 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007611 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007612 TAG, "Starting animation in " + this +
7613 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7614 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7615 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7616 mAnimation.setStartTime(currentTime);
7617 mLocalAnimating = true;
7618 mAnimating = true;
7619 }
7620 mTransformation.clear();
7621 final boolean more = mAnimation.getTransformation(
7622 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007623 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007624 TAG, "Stepped animation in " + this +
7625 ": more=" + more + ", xform=" + mTransformation);
7626 if (more) {
7627 // we're not done!
7628 return true;
7629 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007630 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007631 TAG, "Finished animation in " + this +
7632 " @ " + currentTime);
7633 mAnimation = null;
7634 //WindowManagerService.this.dump();
7635 }
7636 mHasLocalTransformation = false;
7637 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007638 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007639 // When our app token is animating, we kind-of pretend like
7640 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7641 // part of this check means that we will only do this if
7642 // our window is not currently exiting, or it is not
7643 // locally animating itself. The idea being that one that
7644 // is exiting and doing a local animation should be removed
7645 // once that animation is done.
7646 mAnimating = true;
7647 mHasTransformation = true;
7648 mTransformation.clear();
7649 return false;
7650 } else if (mHasTransformation) {
7651 // Little trick to get through the path below to act like
7652 // we have finished an animation.
7653 mAnimating = true;
7654 } else if (isAnimating()) {
7655 mAnimating = true;
7656 }
7657 } else if (mAnimation != null) {
7658 // If the display is frozen, and there is a pending animation,
7659 // clear it and make sure we run the cleanup code.
7660 mAnimating = true;
7661 mLocalAnimating = true;
7662 mAnimation = null;
7663 }
Romain Guy06882f82009-06-10 13:36:04 -07007664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007665 if (!mAnimating && !mLocalAnimating) {
7666 return false;
7667 }
7668
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, "Animation done in " + this + ": exiting=" + mExiting
7671 + ", reportedVisible="
7672 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007674 mAnimating = false;
7675 mLocalAnimating = false;
7676 mAnimation = null;
7677 mAnimLayer = mLayer;
7678 if (mIsImWindow) {
7679 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007680 } else if (mIsWallpaper) {
7681 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007682 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007683 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007684 + " anim layer: " + mAnimLayer);
7685 mHasTransformation = false;
7686 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007687 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7688 if (DEBUG_VISIBILITY) {
7689 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7690 + mPolicyVisibilityAfterAnim);
7691 }
7692 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7693 if (!mPolicyVisibility) {
7694 if (mCurrentFocus == this) {
7695 mFocusMayChange = true;
7696 }
7697 // Window is no longer visible -- make sure if we were waiting
7698 // for it to be displayed before enabling the display, that
7699 // we allow the display to be enabled now.
7700 enableScreenIfNeededLocked();
7701 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007702 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007703 mTransformation.clear();
7704 if (mHasDrawn
7705 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7706 && mAppToken != null
7707 && mAppToken.firstWindowDrawn
7708 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007709 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007710 + mToken + ": first real window done animating");
7711 mFinishedStarting.add(mAppToken);
7712 mH.sendEmptyMessage(H.FINISHED_STARTING);
7713 }
Romain Guy06882f82009-06-10 13:36:04 -07007714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007715 finishExit();
7716
7717 if (mAppToken != null) {
7718 mAppToken.updateReportedVisibilityLocked();
7719 }
7720
7721 return false;
7722 }
7723
7724 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007725 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007726 TAG, "finishExit in " + this
7727 + ": exiting=" + mExiting
7728 + " remove=" + mRemoveOnExit
7729 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007730
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007731 final int N = mChildWindows.size();
7732 for (int i=0; i<N; i++) {
7733 ((WindowState)mChildWindows.get(i)).finishExit();
7734 }
Romain Guy06882f82009-06-10 13:36:04 -07007735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007736 if (!mExiting) {
7737 return;
7738 }
Romain Guy06882f82009-06-10 13:36:04 -07007739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007740 if (isWindowAnimating()) {
7741 return;
7742 }
7743
Joe Onorato8a9b2202010-02-26 18:56:32 -08007744 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007745 TAG, "Exit animation finished in " + this
7746 + ": remove=" + mRemoveOnExit);
7747 if (mSurface != null) {
7748 mDestroySurface.add(this);
7749 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007750 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007751 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007752 try {
7753 mSurface.hide();
7754 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007755 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007756 }
7757 mLastHidden = true;
7758 mKeyWaiter.releasePendingPointerLocked(mSession);
7759 }
7760 mExiting = false;
7761 if (mRemoveOnExit) {
7762 mPendingRemove.add(this);
7763 mRemoveOnExit = false;
7764 }
7765 }
Romain Guy06882f82009-06-10 13:36:04 -07007766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007767 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7768 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7769 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7770 if (dtdx < -.000001f || dtdx > .000001f) return false;
7771 if (dsdy < -.000001f || dsdy > .000001f) return false;
7772 return true;
7773 }
Romain Guy06882f82009-06-10 13:36:04 -07007774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007775 void computeShownFrameLocked() {
7776 final boolean selfTransformation = mHasLocalTransformation;
7777 Transformation attachedTransformation =
7778 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7779 ? mAttachedWindow.mTransformation : null;
7780 Transformation appTransformation =
7781 (mAppToken != null && mAppToken.hasTransformation)
7782 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007783
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007784 // Wallpapers are animated based on the "real" window they
7785 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007786 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007787 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007788 if (mWallpaperTarget.mHasLocalTransformation &&
7789 mWallpaperTarget.mAnimation != null &&
7790 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007791 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007792 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007793 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007794 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007795 }
7796 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007797 mWallpaperTarget.mAppToken.hasTransformation &&
7798 mWallpaperTarget.mAppToken.animation != null &&
7799 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007800 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007801 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007802 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007803 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007804 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007805 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007807 if (selfTransformation || attachedTransformation != null
7808 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007809 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007810 final Rect frame = mFrame;
7811 final float tmpFloats[] = mTmpFloats;
7812 final Matrix tmpMatrix = mTmpMatrix;
7813
7814 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007815 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007816 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007817 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007818 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007819 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007820 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007821 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007822 }
7823 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007824 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007825 }
7826
7827 // "convert" it into SurfaceFlinger's format
7828 // (a 2x2 matrix + an offset)
7829 // Here we must not transform the position of the surface
7830 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007831 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007833 tmpMatrix.getValues(tmpFloats);
7834 mDsDx = tmpFloats[Matrix.MSCALE_X];
7835 mDtDx = tmpFloats[Matrix.MSKEW_X];
7836 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7837 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007838 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7839 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007840 int w = frame.width();
7841 int h = frame.height();
7842 mShownFrame.set(x, y, x+w, y+h);
7843
7844 // Now set the alpha... but because our current hardware
7845 // can't do alpha transformation on a non-opaque surface,
7846 // turn it off if we are running an animation that is also
7847 // transforming since it is more important to have that
7848 // animation be smooth.
7849 mShownAlpha = mAlpha;
7850 if (!mLimitedAlphaCompositing
7851 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7852 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7853 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007854 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007855 if (selfTransformation) {
7856 mShownAlpha *= mTransformation.getAlpha();
7857 }
7858 if (attachedTransformation != null) {
7859 mShownAlpha *= attachedTransformation.getAlpha();
7860 }
7861 if (appTransformation != null) {
7862 mShownAlpha *= appTransformation.getAlpha();
7863 }
7864 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007865 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007866 }
Romain Guy06882f82009-06-10 13:36:04 -07007867
Joe Onorato8a9b2202010-02-26 18:56:32 -08007868 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007869 TAG, "Continuing animation in " + this +
7870 ": " + mShownFrame +
7871 ", alpha=" + mTransformation.getAlpha());
7872 return;
7873 }
Romain Guy06882f82009-06-10 13:36:04 -07007874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007875 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007876 if (mXOffset != 0 || mYOffset != 0) {
7877 mShownFrame.offset(mXOffset, mYOffset);
7878 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007879 mShownAlpha = mAlpha;
7880 mDsDx = 1;
7881 mDtDx = 0;
7882 mDsDy = 0;
7883 mDtDy = 1;
7884 }
Romain Guy06882f82009-06-10 13:36:04 -07007885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007886 /**
7887 * Is this window visible? It is not visible if there is no
7888 * surface, or we are in the process of running an exit animation
7889 * that will remove the surface, or its app token has been hidden.
7890 */
7891 public boolean isVisibleLw() {
7892 final AppWindowToken atoken = mAppToken;
7893 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7894 && (atoken == null || !atoken.hiddenRequested)
7895 && !mExiting && !mDestroying;
7896 }
7897
7898 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007899 * Like {@link #isVisibleLw}, but also counts a window that is currently
7900 * "hidden" behind the keyguard as visible. This allows us to apply
7901 * things like window flags that impact the keyguard.
7902 * XXX I am starting to think we need to have ANOTHER visibility flag
7903 * for this "hidden behind keyguard" state rather than overloading
7904 * mPolicyVisibility. Ungh.
7905 */
7906 public boolean isVisibleOrBehindKeyguardLw() {
7907 final AppWindowToken atoken = mAppToken;
7908 return mSurface != null && !mAttachedHidden
7909 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007910 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007911 && !mExiting && !mDestroying;
7912 }
7913
7914 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007915 * Is this window visible, ignoring its app token? It is not visible
7916 * if there is no surface, or we are in the process of running an exit animation
7917 * that will remove the surface.
7918 */
7919 public boolean isWinVisibleLw() {
7920 final AppWindowToken atoken = mAppToken;
7921 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7922 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7923 && !mExiting && !mDestroying;
7924 }
7925
7926 /**
7927 * The same as isVisible(), but follows the current hidden state of
7928 * the associated app token, not the pending requested hidden state.
7929 */
7930 boolean isVisibleNow() {
7931 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007932 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007933 }
7934
7935 /**
7936 * Same as isVisible(), but we also count it as visible between the
7937 * call to IWindowSession.add() and the first relayout().
7938 */
7939 boolean isVisibleOrAdding() {
7940 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007941 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007942 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7943 && mPolicyVisibility && !mAttachedHidden
7944 && (atoken == null || !atoken.hiddenRequested)
7945 && !mExiting && !mDestroying;
7946 }
7947
7948 /**
7949 * Is this window currently on-screen? It is on-screen either if it
7950 * is visible or it is currently running an animation before no longer
7951 * being visible.
7952 */
7953 boolean isOnScreen() {
7954 final AppWindowToken atoken = mAppToken;
7955 if (atoken != null) {
7956 return mSurface != null && mPolicyVisibility && !mDestroying
7957 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007958 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007959 } else {
7960 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007961 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007962 }
7963 }
Romain Guy06882f82009-06-10 13:36:04 -07007964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007965 /**
7966 * Like isOnScreen(), but we don't return true if the window is part
7967 * of a transition that has not yet been started.
7968 */
7969 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007970 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007971 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007972 return false;
7973 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007974 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007975 final boolean animating = atoken != null
7976 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007977 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007978 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7979 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007980 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007981 }
7982
7983 /** Is the window or its container currently animating? */
7984 boolean isAnimating() {
7985 final WindowState attached = mAttachedWindow;
7986 final AppWindowToken atoken = mAppToken;
7987 return mAnimation != null
7988 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007989 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007990 (atoken.animation != null
7991 || atoken.inPendingTransaction));
7992 }
7993
7994 /** Is this window currently animating? */
7995 boolean isWindowAnimating() {
7996 return mAnimation != null;
7997 }
7998
7999 /**
8000 * Like isOnScreen, but returns false if the surface hasn't yet
8001 * been drawn.
8002 */
8003 public boolean isDisplayedLw() {
8004 final AppWindowToken atoken = mAppToken;
8005 return mSurface != null && mPolicyVisibility && !mDestroying
8006 && !mDrawPending && !mCommitDrawPending
8007 && ((!mAttachedHidden &&
8008 (atoken == null || !atoken.hiddenRequested))
8009 || mAnimating);
8010 }
8011
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008012 /**
8013 * Returns true if the window has a surface that it has drawn a
8014 * complete UI in to.
8015 */
8016 public boolean isDrawnLw() {
8017 final AppWindowToken atoken = mAppToken;
8018 return mSurface != null && !mDestroying
8019 && !mDrawPending && !mCommitDrawPending;
8020 }
8021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008022 public boolean fillsScreenLw(int screenWidth, int screenHeight,
8023 boolean shownFrame, boolean onlyOpaque) {
8024 if (mSurface == null) {
8025 return false;
8026 }
8027 if (mAppToken != null && !mAppToken.appFullscreen) {
8028 return false;
8029 }
8030 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
8031 return false;
8032 }
8033 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008034
8035 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
8036 return frame.left <= mCompatibleScreenFrame.left &&
8037 frame.top <= mCompatibleScreenFrame.top &&
8038 frame.right >= mCompatibleScreenFrame.right &&
8039 frame.bottom >= mCompatibleScreenFrame.bottom;
8040 } else {
8041 return frame.left <= 0 && frame.top <= 0
8042 && frame.right >= screenWidth
8043 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008044 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008045 }
Romain Guy06882f82009-06-10 13:36:04 -07008046
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008047 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07008048 * Return true if the window is opaque and fully drawn. This indicates
8049 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008050 */
8051 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07008052 return (mAttrs.format == PixelFormat.OPAQUE
8053 || mAttrs.type == TYPE_WALLPAPER)
8054 && mSurface != null && mAnimation == null
8055 && (mAppToken == null || mAppToken.animation == null)
8056 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008057 }
8058
8059 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
8060 return
8061 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008062 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
8063 // only if it's visible
8064 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008065 // and only if the application fills the compatible screen
8066 mFrame.left <= mCompatibleScreenFrame.left &&
8067 mFrame.top <= mCompatibleScreenFrame.top &&
8068 mFrame.right >= mCompatibleScreenFrame.right &&
8069 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008070 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008071 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008072 }
8073
8074 boolean isFullscreen(int screenWidth, int screenHeight) {
8075 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008076 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008077 }
8078
8079 void removeLocked() {
8080 if (mAttachedWindow != null) {
8081 mAttachedWindow.mChildWindows.remove(this);
8082 }
8083 destroySurfaceLocked();
8084 mSession.windowRemovedLocked();
8085 try {
8086 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
8087 } catch (RuntimeException e) {
8088 // Ignore if it has already been removed (usually because
8089 // we are doing this as part of processing a death note.)
8090 }
8091 }
8092
8093 private class DeathRecipient implements IBinder.DeathRecipient {
8094 public void binderDied() {
8095 try {
8096 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008097 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008098 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008099 if (win != null) {
8100 removeWindowLocked(mSession, win);
8101 }
8102 }
8103 } catch (IllegalArgumentException ex) {
8104 // This will happen if the window has already been
8105 // removed.
8106 }
8107 }
8108 }
8109
8110 /** Returns true if this window desires key events. */
8111 public final boolean canReceiveKeys() {
8112 return isVisibleOrAdding()
8113 && (mViewVisibility == View.VISIBLE)
8114 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8115 }
8116
8117 public boolean hasDrawnLw() {
8118 return mHasDrawn;
8119 }
8120
8121 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008122 return showLw(doAnimation, true);
8123 }
8124
8125 boolean showLw(boolean doAnimation, boolean requestAnim) {
8126 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8127 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008128 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008129 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008130 if (doAnimation) {
8131 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8132 + mPolicyVisibility + " mAnimation=" + mAnimation);
8133 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8134 doAnimation = false;
8135 } else if (mPolicyVisibility && mAnimation == null) {
8136 // Check for the case where we are currently visible and
8137 // not animating; we do not want to do animation at such a
8138 // point to become visible when we already are.
8139 doAnimation = false;
8140 }
8141 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008142 mPolicyVisibility = true;
8143 mPolicyVisibilityAfterAnim = true;
8144 if (doAnimation) {
8145 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8146 }
8147 if (requestAnim) {
8148 requestAnimationLocked(0);
8149 }
8150 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008151 }
8152
8153 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008154 return hideLw(doAnimation, true);
8155 }
8156
8157 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008158 if (doAnimation) {
8159 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8160 doAnimation = false;
8161 }
8162 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008163 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8164 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008165 if (!current) {
8166 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008167 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008168 if (doAnimation) {
8169 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8170 if (mAnimation == null) {
8171 doAnimation = false;
8172 }
8173 }
8174 if (doAnimation) {
8175 mPolicyVisibilityAfterAnim = false;
8176 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008177 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008178 mPolicyVisibilityAfterAnim = false;
8179 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008180 // Window is no longer visible -- make sure if we were waiting
8181 // for it to be displayed before enabling the display, that
8182 // we allow the display to be enabled now.
8183 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008184 if (mCurrentFocus == this) {
8185 mFocusMayChange = true;
8186 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008187 }
8188 if (requestAnim) {
8189 requestAnimationLocked(0);
8190 }
8191 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008192 }
8193
8194 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008195 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8196 pw.print(" mClient="); pw.println(mClient.asBinder());
8197 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8198 if (mAttachedWindow != null || mLayoutAttached) {
8199 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8200 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8201 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008202 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8203 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8204 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008205 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8206 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008207 }
8208 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8209 pw.print(" mSubLayer="); pw.print(mSubLayer);
8210 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8211 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8212 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8213 pw.print("="); pw.print(mAnimLayer);
8214 pw.print(" mLastLayer="); pw.println(mLastLayer);
8215 if (mSurface != null) {
8216 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008217 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8218 pw.print(" layer="); pw.print(mSurfaceLayer);
8219 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8220 pw.print(" rect=("); pw.print(mSurfaceX);
8221 pw.print(","); pw.print(mSurfaceY);
8222 pw.print(") "); pw.print(mSurfaceW);
8223 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008224 }
8225 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8226 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8227 if (mAppToken != null) {
8228 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8229 }
8230 if (mTargetAppToken != null) {
8231 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8232 }
8233 pw.print(prefix); pw.print("mViewVisibility=0x");
8234 pw.print(Integer.toHexString(mViewVisibility));
8235 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008236 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8237 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008238 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8239 pw.print(prefix); pw.print("mPolicyVisibility=");
8240 pw.print(mPolicyVisibility);
8241 pw.print(" mPolicyVisibilityAfterAnim=");
8242 pw.print(mPolicyVisibilityAfterAnim);
8243 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8244 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008245 if (!mRelayoutCalled) {
8246 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8247 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008248 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008249 pw.print(" h="); pw.print(mRequestedHeight);
8250 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008251 if (mXOffset != 0 || mYOffset != 0) {
8252 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8253 pw.print(" y="); pw.println(mYOffset);
8254 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008255 pw.print(prefix); pw.print("mGivenContentInsets=");
8256 mGivenContentInsets.printShortString(pw);
8257 pw.print(" mGivenVisibleInsets=");
8258 mGivenVisibleInsets.printShortString(pw);
8259 pw.println();
8260 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8261 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8262 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8263 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008264 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008265 pw.print(prefix); pw.print("mShownFrame=");
8266 mShownFrame.printShortString(pw);
8267 pw.print(" last="); mLastShownFrame.printShortString(pw);
8268 pw.println();
8269 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8270 pw.print(" last="); mLastFrame.printShortString(pw);
8271 pw.println();
8272 pw.print(prefix); pw.print("mContainingFrame=");
8273 mContainingFrame.printShortString(pw);
8274 pw.print(" mDisplayFrame=");
8275 mDisplayFrame.printShortString(pw);
8276 pw.println();
8277 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8278 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8279 pw.println();
8280 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8281 pw.print(" last="); mLastContentInsets.printShortString(pw);
8282 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8283 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8284 pw.println();
8285 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8286 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8287 pw.print(" mAlpha="); pw.print(mAlpha);
8288 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8289 }
8290 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8291 || mAnimation != null) {
8292 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8293 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8294 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8295 pw.print(" mAnimation="); pw.println(mAnimation);
8296 }
8297 if (mHasTransformation || mHasLocalTransformation) {
8298 pw.print(prefix); pw.print("XForm: has=");
8299 pw.print(mHasTransformation);
8300 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8301 pw.print(" "); mTransformation.printShortString(pw);
8302 pw.println();
8303 }
8304 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8305 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8306 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8307 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8308 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8309 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8310 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8311 pw.print(" mDestroying="); pw.print(mDestroying);
8312 pw.print(" mRemoved="); pw.println(mRemoved);
8313 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008314 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008315 pw.print(prefix); pw.print("mOrientationChanging=");
8316 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008317 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8318 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008319 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008320 if (mHScale != 1 || mVScale != 1) {
8321 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8322 pw.print(" mVScale="); pw.println(mVScale);
8323 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008324 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008325 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8326 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8327 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008328 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8329 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8330 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8331 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008332 }
8333
8334 @Override
8335 public String toString() {
8336 return "Window{"
8337 + Integer.toHexString(System.identityHashCode(this))
8338 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
8339 }
8340 }
Romain Guy06882f82009-06-10 13:36:04 -07008341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008342 // -------------------------------------------------------------
8343 // Window Token State
8344 // -------------------------------------------------------------
8345
8346 class WindowToken {
8347 // The actual token.
8348 final IBinder token;
8349
8350 // The type of window this token is for, as per WindowManager.LayoutParams.
8351 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008353 // Set if this token was explicitly added by a client, so should
8354 // not be removed when all windows are removed.
8355 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008356
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008357 // For printing.
8358 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008360 // If this is an AppWindowToken, this is non-null.
8361 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008363 // All of the windows associated with this token.
8364 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8365
8366 // Is key dispatching paused for this token?
8367 boolean paused = false;
8368
8369 // Should this token's windows be hidden?
8370 boolean hidden;
8371
8372 // Temporary for finding which tokens no longer have visible windows.
8373 boolean hasVisible;
8374
Dianne Hackborna8f60182009-09-01 19:01:50 -07008375 // Set to true when this token is in a pending transaction where it
8376 // will be shown.
8377 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008378
Dianne Hackborna8f60182009-09-01 19:01:50 -07008379 // Set to true when this token is in a pending transaction where it
8380 // will be hidden.
8381 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008382
Dianne Hackborna8f60182009-09-01 19:01:50 -07008383 // Set to true when this token is in a pending transaction where its
8384 // windows will be put to the bottom of the list.
8385 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008386
Dianne Hackborna8f60182009-09-01 19:01:50 -07008387 // Set to true when this token is in a pending transaction where its
8388 // windows will be put to the top of the list.
8389 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008391 WindowToken(IBinder _token, int type, boolean _explicit) {
8392 token = _token;
8393 windowType = type;
8394 explicit = _explicit;
8395 }
8396
8397 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008398 pw.print(prefix); pw.print("token="); pw.println(token);
8399 pw.print(prefix); pw.print("windows="); pw.println(windows);
8400 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8401 pw.print(" hidden="); pw.print(hidden);
8402 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008403 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8404 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8405 pw.print(" waitingToHide="); pw.print(waitingToHide);
8406 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8407 pw.print(" sendingToTop="); pw.println(sendingToTop);
8408 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008409 }
8410
8411 @Override
8412 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008413 if (stringName == null) {
8414 StringBuilder sb = new StringBuilder();
8415 sb.append("WindowToken{");
8416 sb.append(Integer.toHexString(System.identityHashCode(this)));
8417 sb.append(" token="); sb.append(token); sb.append('}');
8418 stringName = sb.toString();
8419 }
8420 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008421 }
8422 };
8423
8424 class AppWindowToken extends WindowToken {
8425 // Non-null only for application tokens.
8426 final IApplicationToken appToken;
8427
8428 // All of the windows and child windows that are included in this
8429 // application token. Note this list is NOT sorted!
8430 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8431
8432 int groupId = -1;
8433 boolean appFullscreen;
8434 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Romain Guy06882f82009-06-10 13:36:04 -07008435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008436 // These are used for determining when all windows associated with
8437 // an activity have been drawn, so they can be made visible together
8438 // at the same time.
8439 int lastTransactionSequence = mTransactionSequence-1;
8440 int numInterestingWindows;
8441 int numDrawnWindows;
8442 boolean inPendingTransaction;
8443 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008445 // Is this token going to be hidden in a little while? If so, it
8446 // won't be taken into account for setting the screen orientation.
8447 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008449 // Is this window's surface needed? This is almost like hidden, except
8450 // it will sometimes be true a little earlier: when the token has
8451 // been shown, but is still waiting for its app transition to execute
8452 // before making its windows shown.
8453 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008455 // Have we told the window clients to hide themselves?
8456 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008458 // Last visibility state we reported to the app token.
8459 boolean reportedVisible;
8460
8461 // Set to true when the token has been removed from the window mgr.
8462 boolean removed;
8463
8464 // Have we been asked to have this token keep the screen frozen?
8465 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008467 boolean animating;
8468 Animation animation;
8469 boolean hasTransformation;
8470 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008472 // Offset to the window of all layers in the token, for use by
8473 // AppWindowToken animations.
8474 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008476 // Information about an application starting window if displayed.
8477 StartingData startingData;
8478 WindowState startingWindow;
8479 View startingView;
8480 boolean startingDisplayed;
8481 boolean startingMoved;
8482 boolean firstWindowDrawn;
8483
8484 AppWindowToken(IApplicationToken _token) {
8485 super(_token.asBinder(),
8486 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8487 appWindowToken = this;
8488 appToken = _token;
8489 }
Romain Guy06882f82009-06-10 13:36:04 -07008490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008491 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008492 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008493 TAG, "Setting animation in " + this + ": " + anim);
8494 animation = anim;
8495 animating = false;
8496 anim.restrictDuration(MAX_ANIMATION_DURATION);
8497 anim.scaleCurrentDuration(mTransitionAnimationScale);
8498 int zorder = anim.getZAdjustment();
8499 int adj = 0;
8500 if (zorder == Animation.ZORDER_TOP) {
8501 adj = TYPE_LAYER_OFFSET;
8502 } else if (zorder == Animation.ZORDER_BOTTOM) {
8503 adj = -TYPE_LAYER_OFFSET;
8504 }
Romain Guy06882f82009-06-10 13:36:04 -07008505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008506 if (animLayerAdjustment != adj) {
8507 animLayerAdjustment = adj;
8508 updateLayers();
8509 }
8510 }
Romain Guy06882f82009-06-10 13:36:04 -07008511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008512 public void setDummyAnimation() {
8513 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008514 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008515 TAG, "Setting dummy animation in " + this);
8516 animation = sDummyAnimation;
8517 }
8518 }
8519
8520 public void clearAnimation() {
8521 if (animation != null) {
8522 animation = null;
8523 animating = true;
8524 }
8525 }
Romain Guy06882f82009-06-10 13:36:04 -07008526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008527 void updateLayers() {
8528 final int N = allAppWindows.size();
8529 final int adj = animLayerAdjustment;
8530 for (int i=0; i<N; i++) {
8531 WindowState w = allAppWindows.get(i);
8532 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008533 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008534 + w.mAnimLayer);
8535 if (w == mInputMethodTarget) {
8536 setInputMethodAnimLayerAdjustment(adj);
8537 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008538 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008539 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008540 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008541 }
8542 }
Romain Guy06882f82009-06-10 13:36:04 -07008543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008544 void sendAppVisibilityToClients() {
8545 final int N = allAppWindows.size();
8546 for (int i=0; i<N; i++) {
8547 WindowState win = allAppWindows.get(i);
8548 if (win == startingWindow && clientHidden) {
8549 // Don't hide the starting window.
8550 continue;
8551 }
8552 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008553 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008554 "Setting visibility of " + win + ": " + (!clientHidden));
8555 win.mClient.dispatchAppVisibility(!clientHidden);
8556 } catch (RemoteException e) {
8557 }
8558 }
8559 }
Romain Guy06882f82009-06-10 13:36:04 -07008560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008561 void showAllWindowsLocked() {
8562 final int NW = allAppWindows.size();
8563 for (int i=0; i<NW; i++) {
8564 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008565 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008566 "performing show on: " + w);
8567 w.performShowLocked();
8568 }
8569 }
Romain Guy06882f82009-06-10 13:36:04 -07008570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008571 // This must be called while inside a transaction.
8572 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008573 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008574 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008576 if (animation == sDummyAnimation) {
8577 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008578 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008579 // when it is really time to animate, this will be set to
8580 // a real animation and the next call will execute normally.
8581 return false;
8582 }
Romain Guy06882f82009-06-10 13:36:04 -07008583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008584 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8585 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008586 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008587 TAG, "Starting animation in " + this +
8588 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8589 + " scale=" + mTransitionAnimationScale
8590 + " allDrawn=" + allDrawn + " animating=" + animating);
8591 animation.initialize(dw, dh, dw, dh);
8592 animation.setStartTime(currentTime);
8593 animating = true;
8594 }
8595 transformation.clear();
8596 final boolean more = animation.getTransformation(
8597 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008598 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008599 TAG, "Stepped animation in " + this +
8600 ": more=" + more + ", xform=" + transformation);
8601 if (more) {
8602 // we're done!
8603 hasTransformation = true;
8604 return true;
8605 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008606 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008607 TAG, "Finished animation in " + this +
8608 " @ " + currentTime);
8609 animation = null;
8610 }
8611 } else if (animation != null) {
8612 // If the display is frozen, and there is a pending animation,
8613 // clear it and make sure we run the cleanup code.
8614 animating = true;
8615 animation = null;
8616 }
8617
8618 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008620 if (!animating) {
8621 return false;
8622 }
8623
8624 clearAnimation();
8625 animating = false;
8626 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8627 moveInputMethodWindowsIfNeededLocked(true);
8628 }
Romain Guy06882f82009-06-10 13:36:04 -07008629
Joe Onorato8a9b2202010-02-26 18:56:32 -08008630 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008631 TAG, "Animation done in " + this
8632 + ": reportedVisible=" + reportedVisible);
8633
8634 transformation.clear();
8635 if (animLayerAdjustment != 0) {
8636 animLayerAdjustment = 0;
8637 updateLayers();
8638 }
Romain Guy06882f82009-06-10 13:36:04 -07008639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008640 final int N = windows.size();
8641 for (int i=0; i<N; i++) {
8642 ((WindowState)windows.get(i)).finishExit();
8643 }
8644 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008646 return false;
8647 }
8648
8649 void updateReportedVisibilityLocked() {
8650 if (appToken == null) {
8651 return;
8652 }
Romain Guy06882f82009-06-10 13:36:04 -07008653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008654 int numInteresting = 0;
8655 int numVisible = 0;
8656 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008657
Joe Onorato8a9b2202010-02-26 18:56:32 -08008658 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008659 final int N = allAppWindows.size();
8660 for (int i=0; i<N; i++) {
8661 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008662 if (win == startingWindow || win.mAppFreezing
8663 || win.mViewVisibility != View.VISIBLE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008664 continue;
8665 }
8666 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008667 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008668 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008669 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008670 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008671 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008672 + " pv=" + win.mPolicyVisibility
8673 + " dp=" + win.mDrawPending
8674 + " cdp=" + win.mCommitDrawPending
8675 + " ah=" + win.mAttachedHidden
8676 + " th="
8677 + (win.mAppToken != null
8678 ? win.mAppToken.hiddenRequested : false)
8679 + " a=" + win.mAnimating);
8680 }
8681 }
8682 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008683 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008684 if (!win.isAnimating()) {
8685 numVisible++;
8686 }
8687 nowGone = false;
8688 } else if (win.isAnimating()) {
8689 nowGone = false;
8690 }
8691 }
Romain Guy06882f82009-06-10 13:36:04 -07008692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008693 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008694 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008695 + numInteresting + " visible=" + numVisible);
8696 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008697 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008698 TAG, "Visibility changed in " + this
8699 + ": vis=" + nowVisible);
8700 reportedVisible = nowVisible;
8701 Message m = mH.obtainMessage(
8702 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8703 nowVisible ? 1 : 0,
8704 nowGone ? 1 : 0,
8705 this);
8706 mH.sendMessage(m);
8707 }
8708 }
Romain Guy06882f82009-06-10 13:36:04 -07008709
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008710 WindowState findMainWindow() {
8711 int j = windows.size();
8712 while (j > 0) {
8713 j--;
8714 WindowState win = windows.get(j);
8715 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8716 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8717 return win;
8718 }
8719 }
8720 return null;
8721 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008722
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008723 void dump(PrintWriter pw, String prefix) {
8724 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008725 if (appToken != null) {
8726 pw.print(prefix); pw.println("app=true");
8727 }
8728 if (allAppWindows.size() > 0) {
8729 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8730 }
8731 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008732 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008733 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8734 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8735 pw.print(" clientHidden="); pw.print(clientHidden);
8736 pw.print(" willBeHidden="); pw.print(willBeHidden);
8737 pw.print(" reportedVisible="); pw.println(reportedVisible);
8738 if (paused || freezingScreen) {
8739 pw.print(prefix); pw.print("paused="); pw.print(paused);
8740 pw.print(" freezingScreen="); pw.println(freezingScreen);
8741 }
8742 if (numInterestingWindows != 0 || numDrawnWindows != 0
8743 || inPendingTransaction || allDrawn) {
8744 pw.print(prefix); pw.print("numInterestingWindows=");
8745 pw.print(numInterestingWindows);
8746 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8747 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8748 pw.print(" allDrawn="); pw.println(allDrawn);
8749 }
8750 if (animating || animation != null) {
8751 pw.print(prefix); pw.print("animating="); pw.print(animating);
8752 pw.print(" animation="); pw.println(animation);
8753 }
8754 if (animLayerAdjustment != 0) {
8755 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8756 }
8757 if (hasTransformation) {
8758 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8759 pw.print(" transformation="); transformation.printShortString(pw);
8760 pw.println();
8761 }
8762 if (startingData != null || removed || firstWindowDrawn) {
8763 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8764 pw.print(" removed="); pw.print(removed);
8765 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8766 }
8767 if (startingWindow != null || startingView != null
8768 || startingDisplayed || startingMoved) {
8769 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8770 pw.print(" startingView="); pw.print(startingView);
8771 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8772 pw.print(" startingMoved"); pw.println(startingMoved);
8773 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008774 }
8775
8776 @Override
8777 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008778 if (stringName == null) {
8779 StringBuilder sb = new StringBuilder();
8780 sb.append("AppWindowToken{");
8781 sb.append(Integer.toHexString(System.identityHashCode(this)));
8782 sb.append(" token="); sb.append(token); sb.append('}');
8783 stringName = sb.toString();
8784 }
8785 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008786 }
8787 }
Romain Guy06882f82009-06-10 13:36:04 -07008788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008789 // -------------------------------------------------------------
8790 // DummyAnimation
8791 // -------------------------------------------------------------
8792
8793 // This is an animation that does nothing: it just immediately finishes
8794 // itself every time it is called. It is used as a stub animation in cases
8795 // where we want to synchronize multiple things that may be animating.
8796 static final class DummyAnimation extends Animation {
8797 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8798 return false;
8799 }
8800 }
8801 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008803 // -------------------------------------------------------------
8804 // Async Handler
8805 // -------------------------------------------------------------
8806
8807 static final class StartingData {
8808 final String pkg;
8809 final int theme;
8810 final CharSequence nonLocalizedLabel;
8811 final int labelRes;
8812 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008814 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8815 int _labelRes, int _icon) {
8816 pkg = _pkg;
8817 theme = _theme;
8818 nonLocalizedLabel = _nonLocalizedLabel;
8819 labelRes = _labelRes;
8820 icon = _icon;
8821 }
8822 }
8823
8824 private final class H extends Handler {
8825 public static final int REPORT_FOCUS_CHANGE = 2;
8826 public static final int REPORT_LOSING_FOCUS = 3;
8827 public static final int ANIMATE = 4;
8828 public static final int ADD_STARTING = 5;
8829 public static final int REMOVE_STARTING = 6;
8830 public static final int FINISHED_STARTING = 7;
8831 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008832 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8833 public static final int HOLD_SCREEN_CHANGED = 12;
8834 public static final int APP_TRANSITION_TIMEOUT = 13;
8835 public static final int PERSIST_ANIMATION_SCALE = 14;
8836 public static final int FORCE_GC = 15;
8837 public static final int ENABLE_SCREEN = 16;
8838 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008839 public static final int SEND_NEW_CONFIGURATION = 18;
Romain Guy06882f82009-06-10 13:36:04 -07008840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008841 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008843 public H() {
8844 }
Romain Guy06882f82009-06-10 13:36:04 -07008845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008846 @Override
8847 public void handleMessage(Message msg) {
8848 switch (msg.what) {
8849 case REPORT_FOCUS_CHANGE: {
8850 WindowState lastFocus;
8851 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008853 synchronized(mWindowMap) {
8854 lastFocus = mLastFocus;
8855 newFocus = mCurrentFocus;
8856 if (lastFocus == newFocus) {
8857 // Focus is not changing, so nothing to do.
8858 return;
8859 }
8860 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008861 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008862 // + " to " + newFocus);
8863 if (newFocus != null && lastFocus != null
8864 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008865 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008866 mLosingFocus.add(lastFocus);
8867 lastFocus = null;
8868 }
8869 }
8870
8871 if (lastFocus != newFocus) {
8872 //System.out.println("Changing focus from " + lastFocus
8873 // + " to " + newFocus);
8874 if (newFocus != null) {
8875 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008876 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008877 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8878 } catch (RemoteException e) {
8879 // Ignore if process has died.
8880 }
8881 }
8882
8883 if (lastFocus != null) {
8884 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008885 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008886 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8887 } catch (RemoteException e) {
8888 // Ignore if process has died.
8889 }
8890 }
8891 }
8892 } break;
8893
8894 case REPORT_LOSING_FOCUS: {
8895 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008897 synchronized(mWindowMap) {
8898 losers = mLosingFocus;
8899 mLosingFocus = new ArrayList<WindowState>();
8900 }
8901
8902 final int N = losers.size();
8903 for (int i=0; i<N; i++) {
8904 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008905 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008906 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8907 } catch (RemoteException e) {
8908 // Ignore if process has died.
8909 }
8910 }
8911 } break;
8912
8913 case ANIMATE: {
8914 synchronized(mWindowMap) {
8915 mAnimationPending = false;
8916 performLayoutAndPlaceSurfacesLocked();
8917 }
8918 } break;
8919
8920 case ADD_STARTING: {
8921 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8922 final StartingData sd = wtoken.startingData;
8923
8924 if (sd == null) {
8925 // Animation has been canceled... do nothing.
8926 return;
8927 }
Romain Guy06882f82009-06-10 13:36:04 -07008928
Joe Onorato8a9b2202010-02-26 18:56:32 -08008929 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008930 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008932 View view = null;
8933 try {
8934 view = mPolicy.addStartingWindow(
8935 wtoken.token, sd.pkg,
8936 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8937 sd.icon);
8938 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008939 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008940 }
8941
8942 if (view != null) {
8943 boolean abort = false;
8944
8945 synchronized(mWindowMap) {
8946 if (wtoken.removed || wtoken.startingData == null) {
8947 // If the window was successfully added, then
8948 // we need to remove it.
8949 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008950 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008951 "Aborted starting " + wtoken
8952 + ": removed=" + wtoken.removed
8953 + " startingData=" + wtoken.startingData);
8954 wtoken.startingWindow = null;
8955 wtoken.startingData = null;
8956 abort = true;
8957 }
8958 } else {
8959 wtoken.startingView = view;
8960 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008961 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008962 "Added starting " + wtoken
8963 + ": startingWindow="
8964 + wtoken.startingWindow + " startingView="
8965 + wtoken.startingView);
8966 }
8967
8968 if (abort) {
8969 try {
8970 mPolicy.removeStartingWindow(wtoken.token, view);
8971 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008972 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008973 }
8974 }
8975 }
8976 } break;
8977
8978 case REMOVE_STARTING: {
8979 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8980 IBinder token = null;
8981 View view = null;
8982 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008983 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008984 + wtoken + ": startingWindow="
8985 + wtoken.startingWindow + " startingView="
8986 + wtoken.startingView);
8987 if (wtoken.startingWindow != null) {
8988 view = wtoken.startingView;
8989 token = wtoken.token;
8990 wtoken.startingData = null;
8991 wtoken.startingView = null;
8992 wtoken.startingWindow = null;
8993 }
8994 }
8995 if (view != null) {
8996 try {
8997 mPolicy.removeStartingWindow(token, view);
8998 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008999 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009000 }
9001 }
9002 } break;
9003
9004 case FINISHED_STARTING: {
9005 IBinder token = null;
9006 View view = null;
9007 while (true) {
9008 synchronized (mWindowMap) {
9009 final int N = mFinishedStarting.size();
9010 if (N <= 0) {
9011 break;
9012 }
9013 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
9014
Joe Onorato8a9b2202010-02-26 18:56:32 -08009015 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009016 "Finished starting " + wtoken
9017 + ": startingWindow=" + wtoken.startingWindow
9018 + " startingView=" + wtoken.startingView);
9019
9020 if (wtoken.startingWindow == null) {
9021 continue;
9022 }
9023
9024 view = wtoken.startingView;
9025 token = wtoken.token;
9026 wtoken.startingData = null;
9027 wtoken.startingView = null;
9028 wtoken.startingWindow = null;
9029 }
9030
9031 try {
9032 mPolicy.removeStartingWindow(token, view);
9033 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009034 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009035 }
9036 }
9037 } break;
9038
9039 case REPORT_APPLICATION_TOKEN_WINDOWS: {
9040 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9041
9042 boolean nowVisible = msg.arg1 != 0;
9043 boolean nowGone = msg.arg2 != 0;
9044
9045 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009046 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009047 TAG, "Reporting visible in " + wtoken
9048 + " visible=" + nowVisible
9049 + " gone=" + nowGone);
9050 if (nowVisible) {
9051 wtoken.appToken.windowsVisible();
9052 } else {
9053 wtoken.appToken.windowsGone();
9054 }
9055 } catch (RemoteException ex) {
9056 }
9057 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009059 case WINDOW_FREEZE_TIMEOUT: {
9060 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009061 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009062 int i = mWindows.size();
9063 while (i > 0) {
9064 i--;
9065 WindowState w = (WindowState)mWindows.get(i);
9066 if (w.mOrientationChanging) {
9067 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009068 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009069 }
9070 }
9071 performLayoutAndPlaceSurfacesLocked();
9072 }
9073 break;
9074 }
Romain Guy06882f82009-06-10 13:36:04 -07009075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009076 case HOLD_SCREEN_CHANGED: {
9077 Session oldHold;
9078 Session newHold;
9079 synchronized (mWindowMap) {
9080 oldHold = mLastReportedHold;
9081 newHold = (Session)msg.obj;
9082 mLastReportedHold = newHold;
9083 }
Romain Guy06882f82009-06-10 13:36:04 -07009084
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009085 if (oldHold != newHold) {
9086 try {
9087 if (oldHold != null) {
9088 mBatteryStats.noteStopWakelock(oldHold.mUid,
9089 "window",
9090 BatteryStats.WAKE_TYPE_WINDOW);
9091 }
9092 if (newHold != null) {
9093 mBatteryStats.noteStartWakelock(newHold.mUid,
9094 "window",
9095 BatteryStats.WAKE_TYPE_WINDOW);
9096 }
9097 } catch (RemoteException e) {
9098 }
9099 }
9100 break;
9101 }
Romain Guy06882f82009-06-10 13:36:04 -07009102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009103 case APP_TRANSITION_TIMEOUT: {
9104 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009105 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009106 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009107 "*** APP TRANSITION TIMEOUT");
9108 mAppTransitionReady = true;
9109 mAppTransitionTimeout = true;
9110 performLayoutAndPlaceSurfacesLocked();
9111 }
9112 }
9113 break;
9114 }
Romain Guy06882f82009-06-10 13:36:04 -07009115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009116 case PERSIST_ANIMATION_SCALE: {
9117 Settings.System.putFloat(mContext.getContentResolver(),
9118 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9119 Settings.System.putFloat(mContext.getContentResolver(),
9120 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9121 break;
9122 }
Romain Guy06882f82009-06-10 13:36:04 -07009123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009124 case FORCE_GC: {
9125 synchronized(mWindowMap) {
9126 if (mAnimationPending) {
9127 // If we are animating, don't do the gc now but
9128 // delay a bit so we don't interrupt the animation.
9129 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9130 2000);
9131 return;
9132 }
9133 // If we are currently rotating the display, it will
9134 // schedule a new message when done.
9135 if (mDisplayFrozen) {
9136 return;
9137 }
9138 mFreezeGcPending = 0;
9139 }
9140 Runtime.getRuntime().gc();
9141 break;
9142 }
Romain Guy06882f82009-06-10 13:36:04 -07009143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009144 case ENABLE_SCREEN: {
9145 performEnableScreen();
9146 break;
9147 }
Romain Guy06882f82009-06-10 13:36:04 -07009148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009149 case APP_FREEZE_TIMEOUT: {
9150 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009151 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009152 int i = mAppTokens.size();
9153 while (i > 0) {
9154 i--;
9155 AppWindowToken tok = mAppTokens.get(i);
9156 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009157 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009158 unsetAppFreezingScreenLocked(tok, true, true);
9159 }
9160 }
9161 }
9162 break;
9163 }
Romain Guy06882f82009-06-10 13:36:04 -07009164
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009165 case SEND_NEW_CONFIGURATION: {
9166 removeMessages(SEND_NEW_CONFIGURATION);
9167 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009168 break;
9169 }
Romain Guy06882f82009-06-10 13:36:04 -07009170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009171 }
9172 }
9173 }
9174
9175 // -------------------------------------------------------------
9176 // IWindowManager API
9177 // -------------------------------------------------------------
9178
9179 public IWindowSession openSession(IInputMethodClient client,
9180 IInputContext inputContext) {
9181 if (client == null) throw new IllegalArgumentException("null client");
9182 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
9183 return new Session(client, inputContext);
9184 }
9185
9186 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9187 synchronized (mWindowMap) {
9188 // The focus for the client is the window immediately below
9189 // where we would place the input method window.
9190 int idx = findDesiredInputMethodWindowIndexLocked(false);
9191 WindowState imFocus;
9192 if (idx > 0) {
9193 imFocus = (WindowState)mWindows.get(idx-1);
9194 if (imFocus != null) {
9195 if (imFocus.mSession.mClient != null &&
9196 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9197 return true;
9198 }
9199 }
9200 }
9201 }
9202 return false;
9203 }
Romain Guy06882f82009-06-10 13:36:04 -07009204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009205 // -------------------------------------------------------------
9206 // Internals
9207 // -------------------------------------------------------------
9208
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009209 final WindowState windowForClientLocked(Session session, IWindow client,
9210 boolean throwOnError) {
9211 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009212 }
Romain Guy06882f82009-06-10 13:36:04 -07009213
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009214 final WindowState windowForClientLocked(Session session, IBinder client,
9215 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009216 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009217 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009218 TAG, "Looking up client " + client + ": " + win);
9219 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009220 RuntimeException ex = new IllegalArgumentException(
9221 "Requested window " + client + " does not exist");
9222 if (throwOnError) {
9223 throw ex;
9224 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009225 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009226 return null;
9227 }
9228 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009229 RuntimeException ex = new IllegalArgumentException(
9230 "Requested window " + client + " is in session " +
9231 win.mSession + ", not " + session);
9232 if (throwOnError) {
9233 throw ex;
9234 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009235 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009236 return null;
9237 }
9238
9239 return win;
9240 }
9241
Dianne Hackborna8f60182009-09-01 19:01:50 -07009242 final void rebuildAppWindowListLocked() {
9243 int NW = mWindows.size();
9244 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009245 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009246 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009247
Dianne Hackborna8f60182009-09-01 19:01:50 -07009248 // First remove all existing app windows.
9249 i=0;
9250 while (i < NW) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009251 WindowState w = (WindowState)mWindows.get(i);
9252 if (w.mAppToken != null) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009253 WindowState win = (WindowState)mWindows.remove(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009254 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009255 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009256 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009257 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009258 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009259 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9260 && lastWallpaper == i-1) {
9261 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009262 }
9263 i++;
9264 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009265
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009266 // The wallpaper window(s) typically live at the bottom of the stack,
9267 // so skip them before adding app tokens.
9268 lastWallpaper++;
9269 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009270
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009271 // First add all of the exiting app tokens... these are no longer
9272 // in the main app list, but still have windows shown. We put them
9273 // in the back because now that the animation is over we no longer
9274 // will care about them.
9275 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009276 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009277 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9278 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009279
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009280 // And add in the still active app tokens in Z order.
9281 NT = mAppTokens.size();
9282 for (int j=0; j<NT; j++) {
9283 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009284 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009285
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009286 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009287 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009288 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009289 + " windows but added " + i);
9290 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009291 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009293 private final void assignLayersLocked() {
9294 int N = mWindows.size();
9295 int curBaseLayer = 0;
9296 int curLayer = 0;
9297 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009299 for (i=0; i<N; i++) {
9300 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009301 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9302 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009303 curLayer += WINDOW_LAYER_MULTIPLIER;
9304 w.mLayer = curLayer;
9305 } else {
9306 curBaseLayer = curLayer = w.mBaseLayer;
9307 w.mLayer = curLayer;
9308 }
9309 if (w.mTargetAppToken != null) {
9310 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9311 } else if (w.mAppToken != null) {
9312 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9313 } else {
9314 w.mAnimLayer = w.mLayer;
9315 }
9316 if (w.mIsImWindow) {
9317 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009318 } else if (w.mIsWallpaper) {
9319 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009320 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009321 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009322 + w.mAnimLayer);
9323 //System.out.println(
9324 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9325 }
9326 }
9327
9328 private boolean mInLayout = false;
9329 private final void performLayoutAndPlaceSurfacesLocked() {
9330 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009331 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009332 throw new RuntimeException("Recursive call!");
9333 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009334 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009335 return;
9336 }
9337
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009338 if (mWaitingForConfig) {
9339 // Our configuration has changed (most likely rotation), but we
9340 // don't yet have the complete configuration to report to
9341 // applications. Don't do any window layout until we have it.
9342 return;
9343 }
9344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009345 boolean recoveringMemory = false;
9346 if (mForceRemoves != null) {
9347 recoveringMemory = true;
9348 // Wait a little it for things to settle down, and off we go.
9349 for (int i=0; i<mForceRemoves.size(); i++) {
9350 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009351 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009352 removeWindowInnerLocked(ws.mSession, ws);
9353 }
9354 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009355 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009356 Object tmp = new Object();
9357 synchronized (tmp) {
9358 try {
9359 tmp.wait(250);
9360 } catch (InterruptedException e) {
9361 }
9362 }
9363 }
Romain Guy06882f82009-06-10 13:36:04 -07009364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009365 mInLayout = true;
9366 try {
9367 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009369 int i = mPendingRemove.size()-1;
9370 if (i >= 0) {
9371 while (i >= 0) {
9372 WindowState w = mPendingRemove.get(i);
9373 removeWindowInnerLocked(w.mSession, w);
9374 i--;
9375 }
9376 mPendingRemove.clear();
9377
9378 mInLayout = false;
9379 assignLayersLocked();
9380 mLayoutNeeded = true;
9381 performLayoutAndPlaceSurfacesLocked();
9382
9383 } else {
9384 mInLayout = false;
9385 if (mLayoutNeeded) {
9386 requestAnimationLocked(0);
9387 }
9388 }
9389 } catch (RuntimeException e) {
9390 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009391 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009392 }
9393 }
9394
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009395 private final int performLayoutLockedInner() {
9396 if (!mLayoutNeeded) {
9397 return 0;
9398 }
9399
9400 mLayoutNeeded = false;
9401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009402 final int dw = mDisplay.getWidth();
9403 final int dh = mDisplay.getHeight();
9404
9405 final int N = mWindows.size();
9406 int i;
9407
Joe Onorato8a9b2202010-02-26 18:56:32 -08009408 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009409 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9410
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009411 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009412
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009413 int seq = mLayoutSeq+1;
9414 if (seq < 0) seq = 0;
9415 mLayoutSeq = seq;
9416
9417 // First perform layout of any root windows (not attached
9418 // to another window).
9419 int topAttached = -1;
9420 for (i = N-1; i >= 0; i--) {
9421 WindowState win = (WindowState) mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009422
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009423 // Don't do layout of a window if it is not visible, or
9424 // soon won't be visible, to avoid wasting time and funky
9425 // changes while a window is animating away.
9426 final AppWindowToken atoken = win.mAppToken;
9427 final boolean gone = win.mViewVisibility == View.GONE
9428 || !win.mRelayoutCalled
9429 || win.mRootToken.hidden
9430 || (atoken != null && atoken.hiddenRequested)
9431 || win.mAttachedHidden
9432 || win.mExiting || win.mDestroying;
9433
9434 if (!win.mLayoutAttached) {
9435 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
9436 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9437 + " mLayoutAttached=" + win.mLayoutAttached);
9438 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
9439 + win.mViewVisibility + " mRelayoutCalled="
9440 + win.mRelayoutCalled + " hidden="
9441 + win.mRootToken.hidden + " hiddenRequested="
9442 + (atoken != null && atoken.hiddenRequested)
9443 + " mAttachedHidden=" + win.mAttachedHidden);
9444 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009445
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009446 // If this view is GONE, then skip it -- keep the current
9447 // frame, and let the caller know so they can ignore it
9448 // if they want. (We do the normal layout for INVISIBLE
9449 // windows, since that means "perform layout as normal,
9450 // just don't display").
9451 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009452 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009453 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9454 win.mLayoutSeq = seq;
9455 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9456 + win.mFrame + " mContainingFrame="
9457 + win.mContainingFrame + " mDisplayFrame="
9458 + win.mDisplayFrame);
9459 } else {
9460 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009461 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009462 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009463 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009464
9465 // Now perform layout of attached windows, which usually
9466 // depend on the position of the window they are attached to.
9467 // XXX does not deal with windows that are attached to windows
9468 // that are themselves attached.
9469 for (i = topAttached; i >= 0; i--) {
9470 WindowState win = (WindowState) mWindows.get(i);
9471
9472 // If this view is GONE, then skip it -- keep the current
9473 // frame, and let the caller know so they can ignore it
9474 // if they want. (We do the normal layout for INVISIBLE
9475 // windows, since that means "perform layout as normal,
9476 // just don't display").
9477 if (win.mLayoutAttached) {
9478 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9479 + " mHaveFrame=" + win.mHaveFrame
9480 + " mViewVisibility=" + win.mViewVisibility
9481 + " mRelayoutCalled=" + win.mRelayoutCalled);
9482 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9483 || !win.mHaveFrame) {
9484 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9485 win.mLayoutSeq = seq;
9486 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9487 + win.mFrame + " mContainingFrame="
9488 + win.mContainingFrame + " mDisplayFrame="
9489 + win.mDisplayFrame);
9490 }
9491 }
9492 }
9493
9494 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009495 }
Romain Guy06882f82009-06-10 13:36:04 -07009496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009497 private final void performLayoutAndPlaceSurfacesLockedInner(
9498 boolean recoveringMemory) {
9499 final long currentTime = SystemClock.uptimeMillis();
9500 final int dw = mDisplay.getWidth();
9501 final int dh = mDisplay.getHeight();
9502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009503 int i;
9504
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009505 if (mFocusMayChange) {
9506 mFocusMayChange = false;
9507 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9508 }
9509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009510 if (mFxSession == null) {
9511 mFxSession = new SurfaceSession();
9512 }
Romain Guy06882f82009-06-10 13:36:04 -07009513
Joe Onorato8a9b2202010-02-26 18:56:32 -08009514 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009515
9516 // Initialize state of exiting tokens.
9517 for (i=mExitingTokens.size()-1; i>=0; i--) {
9518 mExitingTokens.get(i).hasVisible = false;
9519 }
9520
9521 // Initialize state of exiting applications.
9522 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9523 mExitingAppTokens.get(i).hasVisible = false;
9524 }
9525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009526 boolean orientationChangeComplete = true;
9527 Session holdScreen = null;
9528 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009529 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009530 boolean focusDisplayed = false;
9531 boolean animating = false;
9532
9533 Surface.openTransaction();
9534 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009535 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009536 int repeats = 0;
9537 int changes = 0;
9538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009539 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009540 repeats++;
9541 if (repeats > 6) {
9542 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9543 mLayoutNeeded = false;
9544 break;
9545 }
9546
9547 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9548 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9549 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9550 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9551 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9552 assignLayersLocked();
9553 mLayoutNeeded = true;
9554 }
9555 }
9556 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9557 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9558 if (updateOrientationFromAppTokensLocked()) {
9559 mLayoutNeeded = true;
9560 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9561 }
9562 }
9563 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9564 mLayoutNeeded = true;
9565 }
9566 }
9567
9568 // FIRST LOOP: Perform a layout, if needed.
9569 if (repeats < 4) {
9570 changes = performLayoutLockedInner();
9571 if (changes != 0) {
9572 continue;
9573 }
9574 } else {
9575 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9576 changes = 0;
9577 }
9578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009579 final int transactionSequence = ++mTransactionSequence;
9580
9581 // Update animations of all applications, including those
9582 // associated with exiting/removed apps
9583 boolean tokensAnimating = false;
9584 final int NAT = mAppTokens.size();
9585 for (i=0; i<NAT; i++) {
9586 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9587 tokensAnimating = true;
9588 }
9589 }
9590 final int NEAT = mExitingAppTokens.size();
9591 for (i=0; i<NEAT; i++) {
9592 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9593 tokensAnimating = true;
9594 }
9595 }
9596
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009597 // SECOND LOOP: Execute animations and update visibility of windows.
9598
Joe Onorato8a9b2202010-02-26 18:56:32 -08009599 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009600 + transactionSequence + " tokensAnimating="
9601 + tokensAnimating);
9602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009603 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009604
9605 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009606 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009607 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009608
9609 mPolicy.beginAnimationLw(dw, dh);
9610
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009611 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009613 for (i=N-1; i>=0; i--) {
9614 WindowState w = (WindowState)mWindows.get(i);
9615
9616 final WindowManager.LayoutParams attrs = w.mAttrs;
9617
9618 if (w.mSurface != null) {
9619 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009620 if (w.commitFinishDrawingLocked(currentTime)) {
9621 if ((w.mAttrs.flags
9622 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009623 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009624 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009625 wallpaperMayChange = true;
9626 }
9627 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009628
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009629 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009630 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9631 animating = true;
9632 //w.dump(" ");
9633 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009634 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9635 wallpaperMayChange = true;
9636 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009637
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009638 if (mPolicy.doesForceHide(w, attrs)) {
9639 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009640 if (DEBUG_VISIBILITY) Slog.v(TAG,
9641 "Animation done that could impact force hide: "
9642 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009643 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009644 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009645 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9646 forceHiding = true;
9647 }
9648 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9649 boolean changed;
9650 if (forceHiding) {
9651 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009652 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9653 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009654 } else {
9655 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009656 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9657 "Now policy shown: " + w);
9658 if (changed) {
9659 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009660 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009661 // Assume we will need to animate. If
9662 // we don't (because the wallpaper will
9663 // stay with the lock screen), then we will
9664 // clean up later.
9665 Animation a = mPolicy.createForceHideEnterAnimation();
9666 if (a != null) {
9667 w.setAnimation(a);
9668 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009669 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009670 if (mCurrentFocus == null ||
9671 mCurrentFocus.mLayer < w.mLayer) {
9672 // We are showing on to of the current
9673 // focus, so re-evaluate focus to make
9674 // sure it is correct.
9675 mFocusMayChange = true;
9676 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009677 }
9678 }
9679 if (changed && (attrs.flags
9680 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9681 wallpaperMayChange = true;
9682 }
9683 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009685 mPolicy.animatingWindowLw(w, attrs);
9686 }
9687
9688 final AppWindowToken atoken = w.mAppToken;
9689 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9690 if (atoken.lastTransactionSequence != transactionSequence) {
9691 atoken.lastTransactionSequence = transactionSequence;
9692 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9693 atoken.startingDisplayed = false;
9694 }
9695 if ((w.isOnScreen() || w.mAttrs.type
9696 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9697 && !w.mExiting && !w.mDestroying) {
9698 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009699 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009700 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009701 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009702 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009703 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009704 + " pv=" + w.mPolicyVisibility
9705 + " dp=" + w.mDrawPending
9706 + " cdp=" + w.mCommitDrawPending
9707 + " ah=" + w.mAttachedHidden
9708 + " th=" + atoken.hiddenRequested
9709 + " a=" + w.mAnimating);
9710 }
9711 }
9712 if (w != atoken.startingWindow) {
9713 if (!atoken.freezingScreen || !w.mAppFreezing) {
9714 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009715 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009716 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009717 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009718 "tokenMayBeDrawn: " + atoken
9719 + " freezingScreen=" + atoken.freezingScreen
9720 + " mAppFreezing=" + w.mAppFreezing);
9721 tokenMayBeDrawn = true;
9722 }
9723 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009724 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009725 atoken.startingDisplayed = true;
9726 }
9727 }
9728 } else if (w.mReadyToShow) {
9729 w.performShowLocked();
9730 }
9731 }
9732
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009733 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009734
9735 if (tokenMayBeDrawn) {
9736 // See if any windows have been drawn, so they (and others
9737 // associated with them) can now be shown.
9738 final int NT = mTokenList.size();
9739 for (i=0; i<NT; i++) {
9740 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9741 if (wtoken == null) {
9742 continue;
9743 }
9744 if (wtoken.freezingScreen) {
9745 int numInteresting = wtoken.numInterestingWindows;
9746 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009747 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009748 "allDrawn: " + wtoken
9749 + " interesting=" + numInteresting
9750 + " drawn=" + wtoken.numDrawnWindows);
9751 wtoken.showAllWindowsLocked();
9752 unsetAppFreezingScreenLocked(wtoken, false, true);
9753 orientationChangeComplete = true;
9754 }
9755 } else if (!wtoken.allDrawn) {
9756 int numInteresting = wtoken.numInterestingWindows;
9757 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009758 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009759 "allDrawn: " + wtoken
9760 + " interesting=" + numInteresting
9761 + " drawn=" + wtoken.numDrawnWindows);
9762 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009763 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009764
9765 // We can now show all of the drawn windows!
9766 if (!mOpeningApps.contains(wtoken)) {
9767 wtoken.showAllWindowsLocked();
9768 }
9769 }
9770 }
9771 }
9772 }
9773
9774 // If we are ready to perform an app transition, check through
9775 // all of the app tokens to be shown and see if they are ready
9776 // to go.
9777 if (mAppTransitionReady) {
9778 int NN = mOpeningApps.size();
9779 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009780 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009781 "Checking " + NN + " opening apps (frozen="
9782 + mDisplayFrozen + " timeout="
9783 + mAppTransitionTimeout + ")...");
9784 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9785 // If the display isn't frozen, wait to do anything until
9786 // all of the apps are ready. Otherwise just go because
9787 // we'll unfreeze the display when everyone is ready.
9788 for (i=0; i<NN && goodToGo; i++) {
9789 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009790 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009791 "Check opening app" + wtoken + ": allDrawn="
9792 + wtoken.allDrawn + " startingDisplayed="
9793 + wtoken.startingDisplayed);
9794 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9795 && !wtoken.startingMoved) {
9796 goodToGo = false;
9797 }
9798 }
9799 }
9800 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009801 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009802 int transit = mNextAppTransition;
9803 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009804 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009805 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009806 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009807 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009808 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009809 mAppTransitionTimeout = false;
9810 mStartingIconInTransition = false;
9811 mSkipAppTransitionAnimation = false;
9812
9813 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9814
Dianne Hackborna8f60182009-09-01 19:01:50 -07009815 // If there are applications waiting to come to the
9816 // top of the stack, now is the time to move their windows.
9817 // (Note that we don't do apps going to the bottom
9818 // here -- we want to keep their windows in the old
9819 // Z-order until the animation completes.)
9820 if (mToTopApps.size() > 0) {
9821 NN = mAppTokens.size();
9822 for (i=0; i<NN; i++) {
9823 AppWindowToken wtoken = mAppTokens.get(i);
9824 if (wtoken.sendingToTop) {
9825 wtoken.sendingToTop = false;
9826 moveAppWindowsLocked(wtoken, NN, false);
9827 }
9828 }
9829 mToTopApps.clear();
9830 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009831
Dianne Hackborn25994b42009-09-04 14:21:19 -07009832 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009833
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009834 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009835 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009836
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009837 // The top-most window will supply the layout params,
9838 // and we will determine it below.
9839 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009840 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009841 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009842
Joe Onorato8a9b2202010-02-26 18:56:32 -08009843 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009844 "New wallpaper target=" + mWallpaperTarget
9845 + ", lower target=" + mLowerWallpaperTarget
9846 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009847 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009848 // Do a first pass through the tokens for two
9849 // things:
9850 // (1) Determine if both the closing and opening
9851 // app token sets are wallpaper targets, in which
9852 // case special animations are needed
9853 // (since the wallpaper needs to stay static
9854 // behind them).
9855 // (2) Find the layout params of the top-most
9856 // application window in the tokens, which is
9857 // what will control the animation theme.
9858 final int NC = mClosingApps.size();
9859 NN = NC + mOpeningApps.size();
9860 for (i=0; i<NN; i++) {
9861 AppWindowToken wtoken;
9862 int mode;
9863 if (i < NC) {
9864 wtoken = mClosingApps.get(i);
9865 mode = 1;
9866 } else {
9867 wtoken = mOpeningApps.get(i-NC);
9868 mode = 2;
9869 }
9870 if (mLowerWallpaperTarget != null) {
9871 if (mLowerWallpaperTarget.mAppToken == wtoken
9872 || mUpperWallpaperTarget.mAppToken == wtoken) {
9873 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009874 }
9875 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009876 if (wtoken.appFullscreen) {
9877 WindowState ws = wtoken.findMainWindow();
9878 if (ws != null) {
9879 // If this is a compatibility mode
9880 // window, we will always use its anim.
9881 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9882 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009883 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009884 bestAnimLayer = Integer.MAX_VALUE;
9885 } else if (ws.mLayer > bestAnimLayer) {
9886 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009887 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009888 bestAnimLayer = ws.mLayer;
9889 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009890 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009891 }
9892 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009893
Dianne Hackborn25994b42009-09-04 14:21:19 -07009894 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009895 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009896 "Wallpaper animation!");
9897 switch (transit) {
9898 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9899 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9900 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9901 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9902 break;
9903 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9904 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9905 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9906 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9907 break;
9908 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009909 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009910 "New transit: " + transit);
9911 } else if (oldWallpaper != null) {
9912 // We are transitioning from an activity with
9913 // a wallpaper to one without.
9914 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009915 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009916 "New transit away from wallpaper: " + transit);
9917 } else if (mWallpaperTarget != null) {
9918 // We are transitioning from an activity without
9919 // a wallpaper to now showing the wallpaper
9920 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009921 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009922 "New transit into wallpaper: " + transit);
9923 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009924
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009925 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9926 mLastEnterAnimToken = animToken;
9927 mLastEnterAnimParams = animLp;
9928 } else if (mLastEnterAnimParams != null) {
9929 animLp = mLastEnterAnimParams;
9930 mLastEnterAnimToken = null;
9931 mLastEnterAnimParams = null;
9932 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009933
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009934 // If all closing windows are obscured, then there is
9935 // no need to do an animation. This is the case, for
9936 // example, when this transition is being done behind
9937 // the lock screen.
9938 if (!mPolicy.allowAppAnimationsLw()) {
9939 animLp = null;
9940 }
9941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009942 NN = mOpeningApps.size();
9943 for (i=0; i<NN; i++) {
9944 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009945 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009946 "Now opening app" + wtoken);
9947 wtoken.reportedVisible = false;
9948 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009949 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009950 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009951 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009952 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009953 wtoken.showAllWindowsLocked();
9954 }
9955 NN = mClosingApps.size();
9956 for (i=0; i<NN; i++) {
9957 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009958 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009959 "Now closing app" + wtoken);
9960 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009961 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009962 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009963 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009964 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009965 // Force the allDrawn flag, because we want to start
9966 // this guy's animations regardless of whether it's
9967 // gotten drawn.
9968 wtoken.allDrawn = true;
9969 }
9970
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009971 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009973 mOpeningApps.clear();
9974 mClosingApps.clear();
9975
9976 // This has changed the visibility of windows, so perform
9977 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009978 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009979 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009980 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9981 assignLayersLocked();
9982 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009983 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009984 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009985 }
9986 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009987
Dianne Hackborn16064f92010-03-25 00:47:24 -07009988 int adjResult = 0;
9989
Dianne Hackborna8f60182009-09-01 19:01:50 -07009990 if (!animating && mAppTransitionRunning) {
9991 // We have finished the animation of an app transition. To do
9992 // this, we have delayed a lot of operations like showing and
9993 // hiding apps, moving apps in Z-order, etc. The app token list
9994 // reflects the correct Z-order, but the window list may now
9995 // be out of sync with it. So here we will just rebuild the
9996 // entire app window list. Fun!
9997 mAppTransitionRunning = false;
9998 // Clear information about apps that were moving.
9999 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010000
Dianne Hackborna8f60182009-09-01 19:01:50 -070010001 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010002 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010003 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010004 moveInputMethodWindowsIfNeededLocked(false);
10005 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010006 // Since the window list has been rebuilt, focus might
10007 // have to be recomputed since the actual order of windows
10008 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010009 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010010 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010011
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010012 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010013 // At this point, there was a window with a wallpaper that
10014 // was force hiding other windows behind it, but now it
10015 // is going away. This may be simple -- just animate
10016 // away the wallpaper and its window -- or it may be
10017 // hard -- the wallpaper now needs to be shown behind
10018 // something that was hidden.
10019 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010020 if (mLowerWallpaperTarget != null
10021 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010022 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010023 "wallpaperForceHiding changed with lower="
10024 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010025 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010026 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10027 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10028 if (mLowerWallpaperTarget.mAppToken.hidden) {
10029 // The lower target has become hidden before we
10030 // actually started the animation... let's completely
10031 // re-evaluate everything.
10032 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010033 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010034 }
10035 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010036 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010037 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010038 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010039 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010040 + " NEW: " + mWallpaperTarget
10041 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010042 if (mLowerWallpaperTarget == null) {
10043 // Whoops, we don't need a special wallpaper animation.
10044 // Clear them out.
10045 forceHiding = false;
10046 for (i=N-1; i>=0; i--) {
10047 WindowState w = (WindowState)mWindows.get(i);
10048 if (w.mSurface != null) {
10049 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010050 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010051 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010052 forceHiding = true;
10053 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10054 if (!w.mAnimating) {
10055 // We set the animation above so it
10056 // is not yet running.
10057 w.clearAnimation();
10058 }
10059 }
10060 }
10061 }
10062 }
10063 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010064
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010065 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010066 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010067 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010068 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010069 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010070
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010071 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010072 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010073 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010074 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010075 assignLayersLocked();
10076 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010077 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010078 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010079 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010080 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010081
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010082 if (mFocusMayChange) {
10083 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010084 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010085 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010086 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010087 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010088 }
10089
10090 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010091 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010092 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010093
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010094 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10095 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010096
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010097 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010098
10099 // THIRD LOOP: Update the surfaces of all windows.
10100
10101 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10102
10103 boolean obscured = false;
10104 boolean blurring = false;
10105 boolean dimming = false;
10106 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010107 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010108 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010109
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010110 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010112 for (i=N-1; i>=0; i--) {
10113 WindowState w = (WindowState)mWindows.get(i);
10114
10115 boolean displayed = false;
10116 final WindowManager.LayoutParams attrs = w.mAttrs;
10117 final int attrFlags = attrs.flags;
10118
10119 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010120 // XXX NOTE: The logic here could be improved. We have
10121 // the decision about whether to resize a window separated
10122 // from whether to hide the surface. This can cause us to
10123 // resize a surface even if we are going to hide it. You
10124 // can see this by (1) holding device in landscape mode on
10125 // home screen; (2) tapping browser icon (device will rotate
10126 // to landscape; (3) tap home. The wallpaper will be resized
10127 // in step 2 but then immediately hidden, causing us to
10128 // have to resize and then redraw it again in step 3. It
10129 // would be nice to figure out how to avoid this, but it is
10130 // difficult because we do need to resize surfaces in some
10131 // cases while they are hidden such as when first showing a
10132 // window.
10133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010134 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010135 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010136 TAG, "Placing surface #" + i + " " + w.mSurface
10137 + ": new=" + w.mShownFrame + ", old="
10138 + w.mLastShownFrame);
10139
10140 boolean resize;
10141 int width, height;
10142 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
10143 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
10144 w.mLastRequestedHeight != w.mRequestedHeight;
10145 // for a scaled surface, we just want to use
10146 // the requested size.
10147 width = w.mRequestedWidth;
10148 height = w.mRequestedHeight;
10149 w.mLastRequestedWidth = width;
10150 w.mLastRequestedHeight = height;
10151 w.mLastShownFrame.set(w.mShownFrame);
10152 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010153 if (SHOW_TRANSACTIONS) logSurface(w,
10154 "POS " + w.mShownFrame.left
10155 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010156 w.mSurfaceX = w.mShownFrame.left;
10157 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010158 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10159 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010160 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010161 if (!recoveringMemory) {
10162 reclaimSomeSurfaceMemoryLocked(w, "position");
10163 }
10164 }
10165 } else {
10166 resize = !w.mLastShownFrame.equals(w.mShownFrame);
10167 width = w.mShownFrame.width();
10168 height = w.mShownFrame.height();
10169 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010170 }
10171
10172 if (resize) {
10173 if (width < 1) width = 1;
10174 if (height < 1) height = 1;
10175 if (w.mSurface != null) {
10176 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010177 if (SHOW_TRANSACTIONS) logSurface(w,
10178 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010179 + w.mShownFrame.top + " SIZE "
10180 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010181 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010182 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010183 w.mSurfaceW = width;
10184 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010185 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010186 w.mSurfaceX = w.mShownFrame.left;
10187 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010188 w.mSurface.setPosition(w.mShownFrame.left,
10189 w.mShownFrame.top);
10190 } catch (RuntimeException e) {
10191 // If something goes wrong with the surface (such
10192 // as running out of memory), don't take down the
10193 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010194 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010195 + "size=(" + width + "x" + height
10196 + "), pos=(" + w.mShownFrame.left
10197 + "," + w.mShownFrame.top + ")", e);
10198 if (!recoveringMemory) {
10199 reclaimSomeSurfaceMemoryLocked(w, "size");
10200 }
10201 }
10202 }
10203 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010204 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010205 w.mContentInsetsChanged =
10206 !w.mLastContentInsets.equals(w.mContentInsets);
10207 w.mVisibleInsetsChanged =
10208 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010209 boolean configChanged =
10210 w.mConfiguration != mCurConfiguration
10211 && (w.mConfiguration == null
10212 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010213 if (DEBUG_CONFIGURATION && configChanged) {
10214 Slog.v(TAG, "Win " + w + " config changed: "
10215 + mCurConfiguration);
10216 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010217 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010218 + ": configChanged=" + configChanged
10219 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -070010220 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010221 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010222 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010223 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010224 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010225 w.mLastFrame.set(w.mFrame);
10226 w.mLastContentInsets.set(w.mContentInsets);
10227 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010228 // If the screen is currently frozen, then keep
10229 // it frozen until this window draws at its new
10230 // orientation.
10231 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010232 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010233 "Resizing while display frozen: " + w);
10234 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010235 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010236 mWindowsFreezingScreen = true;
10237 // XXX should probably keep timeout from
10238 // when we first froze the display.
10239 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10240 mH.sendMessageDelayed(mH.obtainMessage(
10241 H.WINDOW_FREEZE_TIMEOUT), 2000);
10242 }
10243 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010244 // If the orientation is changing, then we need to
10245 // hold off on unfreezing the display until this
10246 // window has been redrawn; to do that, we need
10247 // to go through the process of getting informed
10248 // by the application when it has finished drawing.
10249 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010250 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010251 "Orientation start waiting for draw in "
10252 + w + ", surface " + w.mSurface);
10253 w.mDrawPending = true;
10254 w.mCommitDrawPending = false;
10255 w.mReadyToShow = false;
10256 if (w.mAppToken != null) {
10257 w.mAppToken.allDrawn = false;
10258 }
10259 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010260 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010261 "Resizing window " + w + " to " + w.mFrame);
10262 mResizingWindows.add(w);
10263 } else if (w.mOrientationChanging) {
10264 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010265 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010266 "Orientation not waiting for draw in "
10267 + w + ", surface " + w.mSurface);
10268 w.mOrientationChanging = false;
10269 }
10270 }
10271 }
10272
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010273 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010274 if (!w.mLastHidden) {
10275 //dump();
10276 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010277 if (SHOW_TRANSACTIONS) logSurface(w,
10278 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010279 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010280 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010281 try {
10282 w.mSurface.hide();
10283 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010284 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010285 }
10286 }
10287 mKeyWaiter.releasePendingPointerLocked(w.mSession);
10288 }
10289 // If we are waiting for this window to handle an
10290 // orientation change, well, it is hidden, so
10291 // doesn't really matter. Note that this does
10292 // introduce a potential glitch if the window
10293 // becomes unhidden before it has drawn for the
10294 // new orientation.
10295 if (w.mOrientationChanging) {
10296 w.mOrientationChanging = false;
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 change skips hidden " + w);
10299 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010300 } else if (w.mLastLayer != w.mAnimLayer
10301 || w.mLastAlpha != w.mShownAlpha
10302 || w.mLastDsDx != w.mDsDx
10303 || w.mLastDtDx != w.mDtDx
10304 || w.mLastDsDy != w.mDsDy
10305 || w.mLastDtDy != w.mDtDy
10306 || w.mLastHScale != w.mHScale
10307 || w.mLastVScale != w.mVScale
10308 || w.mLastHidden) {
10309 displayed = true;
10310 w.mLastAlpha = w.mShownAlpha;
10311 w.mLastLayer = w.mAnimLayer;
10312 w.mLastDsDx = w.mDsDx;
10313 w.mLastDtDx = w.mDtDx;
10314 w.mLastDsDy = w.mDsDy;
10315 w.mLastDtDy = w.mDtDy;
10316 w.mLastHScale = w.mHScale;
10317 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010318 if (SHOW_TRANSACTIONS) logSurface(w,
10319 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010320 + " matrix=[" + (w.mDsDx*w.mHScale)
10321 + "," + (w.mDtDx*w.mVScale)
10322 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010323 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010324 if (w.mSurface != null) {
10325 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010326 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010327 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010328 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010329 w.mSurface.setLayer(w.mAnimLayer);
10330 w.mSurface.setMatrix(
10331 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10332 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10333 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010334 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010335 if (!recoveringMemory) {
10336 reclaimSomeSurfaceMemoryLocked(w, "update");
10337 }
10338 }
10339 }
10340
10341 if (w.mLastHidden && !w.mDrawPending
10342 && !w.mCommitDrawPending
10343 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010344 if (SHOW_TRANSACTIONS) logSurface(w,
10345 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010346 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010347 + " during relayout");
10348 if (showSurfaceRobustlyLocked(w)) {
10349 w.mHasDrawn = true;
10350 w.mLastHidden = false;
10351 } else {
10352 w.mOrientationChanging = false;
10353 }
10354 }
10355 if (w.mSurface != null) {
10356 w.mToken.hasVisible = true;
10357 }
10358 } else {
10359 displayed = true;
10360 }
10361
10362 if (displayed) {
10363 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010364 if (attrs.width == LayoutParams.MATCH_PARENT
10365 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010366 covered = true;
10367 }
10368 }
10369 if (w.mOrientationChanging) {
10370 if (w.mDrawPending || w.mCommitDrawPending) {
10371 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010372 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010373 "Orientation continue waiting for draw in " + w);
10374 } else {
10375 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010376 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010377 "Orientation change complete in " + w);
10378 }
10379 }
10380 w.mToken.hasVisible = true;
10381 }
10382 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010383 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010384 "Orientation change skips hidden " + w);
10385 w.mOrientationChanging = false;
10386 }
10387
10388 final boolean canBeSeen = w.isDisplayedLw();
10389
10390 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10391 focusDisplayed = true;
10392 }
10393
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010394 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010396 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010397 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010398 if (w.mSurface != null) {
10399 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10400 holdScreen = w.mSession;
10401 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010402 if (!syswin && w.mAttrs.screenBrightness >= 0
10403 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010404 screenBrightness = w.mAttrs.screenBrightness;
10405 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010406 if (!syswin && w.mAttrs.buttonBrightness >= 0
10407 && buttonBrightness < 0) {
10408 buttonBrightness = w.mAttrs.buttonBrightness;
10409 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010410 if (canBeSeen
10411 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10412 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10413 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010414 syswin = true;
10415 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010416 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010417
Dianne Hackborn25994b42009-09-04 14:21:19 -070010418 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10419 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010420 // This window completely covers everything behind it,
10421 // so we want to leave all of them as unblurred (for
10422 // performance reasons).
10423 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010424 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010425 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010426 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010427 obscured = true;
10428 if (mBackgroundFillerSurface == null) {
10429 try {
10430 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010431 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010432 0, dw, dh,
10433 PixelFormat.OPAQUE,
10434 Surface.FX_SURFACE_NORMAL);
10435 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010436 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010437 }
10438 }
10439 try {
10440 mBackgroundFillerSurface.setPosition(0, 0);
10441 mBackgroundFillerSurface.setSize(dw, dh);
10442 // Using the same layer as Dim because they will never be shown at the
10443 // same time.
10444 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10445 mBackgroundFillerSurface.show();
10446 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010447 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010448 }
10449 backgroundFillerShown = true;
10450 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010451 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010452 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010453 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010454 + ": blurring=" + blurring
10455 + " obscured=" + obscured
10456 + " displayed=" + displayed);
10457 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10458 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010459 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010460 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010461 if (mDimAnimator == null) {
10462 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010463 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010464 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010465 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010466 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010467 }
10468 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10469 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010470 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010471 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010472 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010473 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010474 + mBlurSurface + ": CREATE");
10475 try {
Romain Guy06882f82009-06-10 13:36:04 -070010476 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010477 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010478 -1, 16, 16,
10479 PixelFormat.OPAQUE,
10480 Surface.FX_SURFACE_BLUR);
10481 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010482 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010483 }
10484 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010485 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010486 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10487 + mBlurSurface + ": pos=(0,0) (" +
10488 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010489 mBlurSurface.setPosition(0, 0);
10490 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010491 mBlurSurface.setLayer(w.mAnimLayer-2);
10492 if (!mBlurShown) {
10493 try {
10494 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10495 + mBlurSurface + ": SHOW");
10496 mBlurSurface.show();
10497 } catch (RuntimeException e) {
10498 Slog.w(TAG, "Failure showing blur surface", e);
10499 }
10500 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010501 }
10502 }
10503 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010504 }
10505 }
10506 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010507
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010508 if (obscuredChanged && mWallpaperTarget == w) {
10509 // This is the wallpaper target and its obscured state
10510 // changed... make sure the current wallaper's visibility
10511 // has been updated accordingly.
10512 updateWallpaperVisibilityLocked();
10513 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010514 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010515
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010516 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10517 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010518 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010519 try {
10520 mBackgroundFillerSurface.hide();
10521 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010522 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010523 }
10524 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010525
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010526 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010527 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10528 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010529 }
Romain Guy06882f82009-06-10 13:36:04 -070010530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010531 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010532 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010533 + ": HIDE");
10534 try {
10535 mBlurSurface.hide();
10536 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010537 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010538 }
10539 mBlurShown = false;
10540 }
10541
Joe Onorato8a9b2202010-02-26 18:56:32 -080010542 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010543 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010544 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010545 }
10546
10547 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010548
Joe Onorato8a9b2202010-02-26 18:56:32 -080010549 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010550 "With display frozen, orientationChangeComplete="
10551 + orientationChangeComplete);
10552 if (orientationChangeComplete) {
10553 if (mWindowsFreezingScreen) {
10554 mWindowsFreezingScreen = false;
10555 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10556 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010557 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010558 }
Romain Guy06882f82009-06-10 13:36:04 -070010559
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010560 i = mResizingWindows.size();
10561 if (i > 0) {
10562 do {
10563 i--;
10564 WindowState win = mResizingWindows.get(i);
10565 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010566 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10567 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010568 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010569 boolean configChanged =
10570 win.mConfiguration != mCurConfiguration
10571 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010572 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10573 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10574 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010575 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010576 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010577 + " / " + mCurConfiguration + " / 0x"
10578 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010579 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010580 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010581 win.mClient.resized(win.mFrame.width(),
10582 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010583 win.mLastVisibleInsets, win.mDrawPending,
10584 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010585 win.mContentInsetsChanged = false;
10586 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010587 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010588 } catch (RemoteException e) {
10589 win.mOrientationChanging = false;
10590 }
10591 } while (i > 0);
10592 mResizingWindows.clear();
10593 }
Romain Guy06882f82009-06-10 13:36:04 -070010594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010595 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010596 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010597 i = mDestroySurface.size();
10598 if (i > 0) {
10599 do {
10600 i--;
10601 WindowState win = mDestroySurface.get(i);
10602 win.mDestroying = false;
10603 if (mInputMethodWindow == win) {
10604 mInputMethodWindow = null;
10605 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010606 if (win == mWallpaperTarget) {
10607 wallpaperDestroyed = true;
10608 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010609 win.destroySurfaceLocked();
10610 } while (i > 0);
10611 mDestroySurface.clear();
10612 }
10613
10614 // Time to remove any exiting tokens?
10615 for (i=mExitingTokens.size()-1; i>=0; i--) {
10616 WindowToken token = mExitingTokens.get(i);
10617 if (!token.hasVisible) {
10618 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010619 if (token.windowType == TYPE_WALLPAPER) {
10620 mWallpaperTokens.remove(token);
10621 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010622 }
10623 }
10624
10625 // Time to remove any exiting applications?
10626 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10627 AppWindowToken token = mExitingAppTokens.get(i);
10628 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010629 // Make sure there is no animation running on this token,
10630 // so any windows associated with it will be removed as
10631 // soon as their animations are complete
10632 token.animation = null;
10633 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010634 mAppTokens.remove(token);
10635 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010636 if (mLastEnterAnimToken == token) {
10637 mLastEnterAnimToken = null;
10638 mLastEnterAnimParams = null;
10639 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010640 }
10641 }
10642
Dianne Hackborna8f60182009-09-01 19:01:50 -070010643 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010644
Dianne Hackborna8f60182009-09-01 19:01:50 -070010645 if (!animating && mAppTransitionRunning) {
10646 // We have finished the animation of an app transition. To do
10647 // this, we have delayed a lot of operations like showing and
10648 // hiding apps, moving apps in Z-order, etc. The app token list
10649 // reflects the correct Z-order, but the window list may now
10650 // be out of sync with it. So here we will just rebuild the
10651 // entire app window list. Fun!
10652 mAppTransitionRunning = false;
10653 needRelayout = true;
10654 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010655 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010656 // Clear information about apps that were moving.
10657 mToBottomApps.clear();
10658 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010660 if (focusDisplayed) {
10661 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10662 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010663 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010664 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010665 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010666 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010667 requestAnimationLocked(0);
10668 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010669 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10670 }
10671 mQueue.setHoldScreenLocked(holdScreen != null);
10672 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10673 mPowerManager.setScreenBrightnessOverride(-1);
10674 } else {
10675 mPowerManager.setScreenBrightnessOverride((int)
10676 (screenBrightness * Power.BRIGHTNESS_ON));
10677 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010678 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10679 mPowerManager.setButtonBrightnessOverride(-1);
10680 } else {
10681 mPowerManager.setButtonBrightnessOverride((int)
10682 (buttonBrightness * Power.BRIGHTNESS_ON));
10683 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010684 if (holdScreen != mHoldingScreenOn) {
10685 mHoldingScreenOn = holdScreen;
10686 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10687 mH.sendMessage(m);
10688 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010689
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010690 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010691 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010692 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10693 LocalPowerManager.BUTTON_EVENT, true);
10694 mTurnOnScreen = false;
10695 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010696
10697 // Check to see if we are now in a state where the screen should
10698 // be enabled, because the window obscured flags have changed.
10699 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010700 }
10701
10702 void requestAnimationLocked(long delay) {
10703 if (!mAnimationPending) {
10704 mAnimationPending = true;
10705 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10706 }
10707 }
Romain Guy06882f82009-06-10 13:36:04 -070010708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010709 /**
10710 * Have the surface flinger show a surface, robustly dealing with
10711 * error conditions. In particular, if there is not enough memory
10712 * to show the surface, then we will try to get rid of other surfaces
10713 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010714 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010715 * @return Returns true if the surface was successfully shown.
10716 */
10717 boolean showSurfaceRobustlyLocked(WindowState win) {
10718 try {
10719 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010720 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010721 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010722 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010723 if (DEBUG_VISIBILITY) Slog.v(TAG,
10724 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010725 win.mTurnOnScreen = false;
10726 mTurnOnScreen = true;
10727 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010728 }
10729 return true;
10730 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010731 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010732 }
Romain Guy06882f82009-06-10 13:36:04 -070010733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010734 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010736 return false;
10737 }
Romain Guy06882f82009-06-10 13:36:04 -070010738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010739 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10740 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010741
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010742 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010743 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010745 if (mForceRemoves == null) {
10746 mForceRemoves = new ArrayList<WindowState>();
10747 }
Romain Guy06882f82009-06-10 13:36:04 -070010748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010749 long callingIdentity = Binder.clearCallingIdentity();
10750 try {
10751 // There was some problem... first, do a sanity check of the
10752 // window list to make sure we haven't left any dangling surfaces
10753 // around.
10754 int N = mWindows.size();
10755 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010756 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010757 for (int i=0; i<N; i++) {
10758 WindowState ws = (WindowState)mWindows.get(i);
10759 if (ws.mSurface != null) {
10760 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010761 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010762 + ws + " surface=" + ws.mSurface
10763 + " token=" + win.mToken
10764 + " pid=" + ws.mSession.mPid
10765 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010766 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010767 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010768 ws.mSurface = null;
10769 mForceRemoves.add(ws);
10770 i--;
10771 N--;
10772 leakedSurface = true;
10773 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010774 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010775 + ws + " surface=" + ws.mSurface
10776 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010777 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010778 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010779 ws.mSurface = null;
10780 leakedSurface = true;
10781 }
10782 }
10783 }
Romain Guy06882f82009-06-10 13:36:04 -070010784
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010785 boolean killedApps = false;
10786 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010787 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010788 SparseIntArray pidCandidates = new SparseIntArray();
10789 for (int i=0; i<N; i++) {
10790 WindowState ws = (WindowState)mWindows.get(i);
10791 if (ws.mSurface != null) {
10792 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10793 }
10794 }
10795 if (pidCandidates.size() > 0) {
10796 int[] pids = new int[pidCandidates.size()];
10797 for (int i=0; i<pids.length; i++) {
10798 pids[i] = pidCandidates.keyAt(i);
10799 }
10800 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010801 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010802 killedApps = true;
10803 }
10804 } catch (RemoteException e) {
10805 }
10806 }
10807 }
Romain Guy06882f82009-06-10 13:36:04 -070010808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010809 if (leakedSurface || killedApps) {
10810 // We managed to reclaim some memory, so get rid of the trouble
10811 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010812 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010813 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010814 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010815 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010816 win.mSurface = null;
10817 }
Romain Guy06882f82009-06-10 13:36:04 -070010818
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010819 try {
10820 win.mClient.dispatchGetNewSurface();
10821 } catch (RemoteException e) {
10822 }
10823 }
10824 } finally {
10825 Binder.restoreCallingIdentity(callingIdentity);
10826 }
10827 }
Romain Guy06882f82009-06-10 13:36:04 -070010828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010829 private boolean updateFocusedWindowLocked(int mode) {
10830 WindowState newFocus = computeFocusedWindowLocked();
10831 if (mCurrentFocus != newFocus) {
10832 // This check makes sure that we don't already have the focus
10833 // change message pending.
10834 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10835 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010836 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010837 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10838 final WindowState oldFocus = mCurrentFocus;
10839 mCurrentFocus = newFocus;
10840 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010842 final WindowState imWindow = mInputMethodWindow;
10843 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010844 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010845 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010846 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10847 mLayoutNeeded = true;
10848 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010849 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10850 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010851 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10852 // Client will do the layout, but we need to assign layers
10853 // for handleNewWindowLocked() below.
10854 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010855 }
10856 }
Romain Guy06882f82009-06-10 13:36:04 -070010857
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010858 if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10859 mKeyWaiter.handleNewWindowLocked(newFocus);
10860 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010861 return true;
10862 }
10863 return false;
10864 }
10865
10866 private WindowState computeFocusedWindowLocked() {
10867 WindowState result = null;
10868 WindowState win;
10869
10870 int i = mWindows.size() - 1;
10871 int nextAppIndex = mAppTokens.size()-1;
10872 WindowToken nextApp = nextAppIndex >= 0
10873 ? mAppTokens.get(nextAppIndex) : null;
10874
10875 while (i >= 0) {
10876 win = (WindowState)mWindows.get(i);
10877
Joe Onorato8a9b2202010-02-26 18:56:32 -080010878 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010879 TAG, "Looking for focus: " + i
10880 + " = " + win
10881 + ", flags=" + win.mAttrs.flags
10882 + ", canReceive=" + win.canReceiveKeys());
10883
10884 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010886 // If this window's application has been removed, just skip it.
10887 if (thisApp != null && thisApp.removed) {
10888 i--;
10889 continue;
10890 }
Romain Guy06882f82009-06-10 13:36:04 -070010891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010892 // If there is a focused app, don't allow focus to go to any
10893 // windows below it. If this is an application window, step
10894 // through the app tokens until we find its app.
10895 if (thisApp != null && nextApp != null && thisApp != nextApp
10896 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10897 int origAppIndex = nextAppIndex;
10898 while (nextAppIndex > 0) {
10899 if (nextApp == mFocusedApp) {
10900 // Whoops, we are below the focused app... no focus
10901 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010902 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010903 TAG, "Reached focused app: " + mFocusedApp);
10904 return null;
10905 }
10906 nextAppIndex--;
10907 nextApp = mAppTokens.get(nextAppIndex);
10908 if (nextApp == thisApp) {
10909 break;
10910 }
10911 }
10912 if (thisApp != nextApp) {
10913 // Uh oh, the app token doesn't exist! This shouldn't
10914 // happen, but if it does we can get totally hosed...
10915 // so restart at the original app.
10916 nextAppIndex = origAppIndex;
10917 nextApp = mAppTokens.get(nextAppIndex);
10918 }
10919 }
10920
10921 // Dispatch to this window if it is wants key events.
10922 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010923 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010924 TAG, "Found focus @ " + i + " = " + win);
10925 result = win;
10926 break;
10927 }
10928
10929 i--;
10930 }
10931
10932 return result;
10933 }
10934
10935 private void startFreezingDisplayLocked() {
10936 if (mDisplayFrozen) {
Chris Tate2ad63a92009-03-25 17:36:48 -070010937 // Freezing the display also suspends key event delivery, to
10938 // keep events from going astray while the display is reconfigured.
10939 // If someone has changed orientation again while the screen is
10940 // still frozen, the events will continue to be blocked while the
10941 // successive orientation change is processed. To prevent spurious
10942 // ANRs, we reset the event dispatch timeout in this case.
10943 synchronized (mKeyWaiter) {
10944 mKeyWaiter.mWasFrozen = true;
10945 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010946 return;
10947 }
Romain Guy06882f82009-06-10 13:36:04 -070010948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010949 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010951 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010952 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010953 if (mFreezeGcPending != 0) {
10954 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010955 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010956 mH.removeMessages(H.FORCE_GC);
10957 Runtime.getRuntime().gc();
10958 mFreezeGcPending = now;
10959 }
10960 } else {
10961 mFreezeGcPending = now;
10962 }
Romain Guy06882f82009-06-10 13:36:04 -070010963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010964 mDisplayFrozen = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010965 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10966 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010967 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010968 mAppTransitionReady = true;
10969 }
Romain Guy06882f82009-06-10 13:36:04 -070010970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010971 if (PROFILE_ORIENTATION) {
10972 File file = new File("/data/system/frozen");
10973 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10974 }
10975 Surface.freezeDisplay(0);
10976 }
Romain Guy06882f82009-06-10 13:36:04 -070010977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010978 private void stopFreezingDisplayLocked() {
10979 if (!mDisplayFrozen) {
10980 return;
10981 }
Romain Guy06882f82009-06-10 13:36:04 -070010982
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010983 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10984 return;
10985 }
10986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010987 mDisplayFrozen = false;
10988 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10989 if (PROFILE_ORIENTATION) {
10990 Debug.stopMethodTracing();
10991 }
10992 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010993
Chris Tate2ad63a92009-03-25 17:36:48 -070010994 // Reset the key delivery timeout on unfreeze, too. We force a wakeup here
10995 // too because regular key delivery processing should resume immediately.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010996 synchronized (mKeyWaiter) {
10997 mKeyWaiter.mWasFrozen = true;
10998 mKeyWaiter.notifyAll();
10999 }
11000
11001 // A little kludge: a lot could have happened while the
11002 // display was frozen, so now that we are coming back we
11003 // do a gc so that any remote references the system
11004 // processes holds on others can be released if they are
11005 // no longer needed.
11006 mH.removeMessages(H.FORCE_GC);
11007 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11008 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011010 mScreenFrozenLock.release();
11011 }
Romain Guy06882f82009-06-10 13:36:04 -070011012
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011013 @Override
11014 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11015 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11016 != PackageManager.PERMISSION_GRANTED) {
11017 pw.println("Permission Denial: can't dump WindowManager from from pid="
11018 + Binder.getCallingPid()
11019 + ", uid=" + Binder.getCallingUid());
11020 return;
11021 }
Romain Guy06882f82009-06-10 13:36:04 -070011022
Dianne Hackborna2e92262010-03-02 17:19:29 -080011023 pw.println("Input State:");
11024 mQueue.dump(pw, " ");
11025 pw.println(" ");
11026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011027 synchronized(mWindowMap) {
11028 pw.println("Current Window Manager state:");
11029 for (int i=mWindows.size()-1; i>=0; i--) {
11030 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011031 pw.print(" Window #"); pw.print(i); pw.print(' ');
11032 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011033 w.dump(pw, " ");
11034 }
11035 if (mInputMethodDialogs.size() > 0) {
11036 pw.println(" ");
11037 pw.println(" Input method dialogs:");
11038 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11039 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011040 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011041 }
11042 }
11043 if (mPendingRemove.size() > 0) {
11044 pw.println(" ");
11045 pw.println(" Remove pending for:");
11046 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11047 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011048 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11049 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011050 w.dump(pw, " ");
11051 }
11052 }
11053 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11054 pw.println(" ");
11055 pw.println(" Windows force removing:");
11056 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11057 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011058 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11059 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011060 w.dump(pw, " ");
11061 }
11062 }
11063 if (mDestroySurface.size() > 0) {
11064 pw.println(" ");
11065 pw.println(" Windows waiting to destroy their surface:");
11066 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11067 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011068 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11069 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011070 w.dump(pw, " ");
11071 }
11072 }
11073 if (mLosingFocus.size() > 0) {
11074 pw.println(" ");
11075 pw.println(" Windows losing focus:");
11076 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11077 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011078 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11079 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011080 w.dump(pw, " ");
11081 }
11082 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011083 if (mResizingWindows.size() > 0) {
11084 pw.println(" ");
11085 pw.println(" Windows waiting to resize:");
11086 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11087 WindowState w = mResizingWindows.get(i);
11088 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11089 pw.print(w); pw.println(":");
11090 w.dump(pw, " ");
11091 }
11092 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011093 if (mSessions.size() > 0) {
11094 pw.println(" ");
11095 pw.println(" All active sessions:");
11096 Iterator<Session> it = mSessions.iterator();
11097 while (it.hasNext()) {
11098 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011099 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011100 s.dump(pw, " ");
11101 }
11102 }
11103 if (mTokenMap.size() > 0) {
11104 pw.println(" ");
11105 pw.println(" All tokens:");
11106 Iterator<WindowToken> it = mTokenMap.values().iterator();
11107 while (it.hasNext()) {
11108 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011109 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011110 token.dump(pw, " ");
11111 }
11112 }
11113 if (mTokenList.size() > 0) {
11114 pw.println(" ");
11115 pw.println(" Window token list:");
11116 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011117 pw.print(" #"); pw.print(i); pw.print(": ");
11118 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011119 }
11120 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011121 if (mWallpaperTokens.size() > 0) {
11122 pw.println(" ");
11123 pw.println(" Wallpaper tokens:");
11124 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11125 WindowToken token = mWallpaperTokens.get(i);
11126 pw.print(" Wallpaper #"); pw.print(i);
11127 pw.print(' '); pw.print(token); pw.println(':');
11128 token.dump(pw, " ");
11129 }
11130 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011131 if (mAppTokens.size() > 0) {
11132 pw.println(" ");
11133 pw.println(" Application tokens in Z order:");
11134 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011135 pw.print(" App #"); pw.print(i); pw.print(": ");
11136 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011137 }
11138 }
11139 if (mFinishedStarting.size() > 0) {
11140 pw.println(" ");
11141 pw.println(" Finishing start of application tokens:");
11142 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11143 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011144 pw.print(" Finished Starting #"); pw.print(i);
11145 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011146 token.dump(pw, " ");
11147 }
11148 }
11149 if (mExitingTokens.size() > 0) {
11150 pw.println(" ");
11151 pw.println(" Exiting tokens:");
11152 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11153 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011154 pw.print(" Exiting #"); pw.print(i);
11155 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011156 token.dump(pw, " ");
11157 }
11158 }
11159 if (mExitingAppTokens.size() > 0) {
11160 pw.println(" ");
11161 pw.println(" Exiting application tokens:");
11162 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11163 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011164 pw.print(" Exiting App #"); pw.print(i);
11165 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011166 token.dump(pw, " ");
11167 }
11168 }
11169 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011170 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11171 pw.print(" mLastFocus="); pw.println(mLastFocus);
11172 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11173 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11174 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011175 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011176 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11177 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11178 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11179 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011180 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11181 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11182 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011183 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11184 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11185 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11186 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011187 if (mDimAnimator != null) {
11188 mDimAnimator.printTo(pw);
11189 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011190 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011191 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011192 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011193 pw.print(mInputMethodAnimLayerAdjustment);
11194 pw.print(" mWallpaperAnimLayerAdjustment=");
11195 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011196 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11197 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011198 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11199 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011200 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11201 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011202 pw.print(" mRotation="); pw.print(mRotation);
11203 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11204 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11205 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11206 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11207 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11208 pw.print(" mNextAppTransition=0x");
11209 pw.print(Integer.toHexString(mNextAppTransition));
11210 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011211 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011212 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011213 if (mNextAppTransitionPackage != null) {
11214 pw.print(" mNextAppTransitionPackage=");
11215 pw.print(mNextAppTransitionPackage);
11216 pw.print(", mNextAppTransitionEnter=0x");
11217 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11218 pw.print(", mNextAppTransitionExit=0x");
11219 pw.print(Integer.toHexString(mNextAppTransitionExit));
11220 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011221 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11222 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011223 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11224 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11225 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11226 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011227 if (mOpeningApps.size() > 0) {
11228 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11229 }
11230 if (mClosingApps.size() > 0) {
11231 pw.print(" mClosingApps="); pw.println(mClosingApps);
11232 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011233 if (mToTopApps.size() > 0) {
11234 pw.print(" mToTopApps="); pw.println(mToTopApps);
11235 }
11236 if (mToBottomApps.size() > 0) {
11237 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11238 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011239 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11240 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011241 pw.println(" KeyWaiter state:");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011242 pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin);
11243 pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder);
11244 pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished);
11245 pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow);
11246 pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching);
11247 pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011248 }
11249 }
11250
11251 public void monitor() {
11252 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011253 synchronized (mKeyguardTokenWatcher) { }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011254 synchronized (mKeyWaiter) { }
11255 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011256
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011257 public void virtualKeyFeedback(KeyEvent event) {
11258 mPolicy.keyFeedbackFromInput(event);
11259 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011260
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011261 /**
11262 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011263 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011264 */
11265 private static class DimAnimator {
11266 Surface mDimSurface;
11267 boolean mDimShown = false;
11268 float mDimCurrentAlpha;
11269 float mDimTargetAlpha;
11270 float mDimDeltaPerMs;
11271 long mLastDimAnimTime;
11272
11273 DimAnimator (SurfaceSession session) {
11274 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011275 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011276 + mDimSurface + ": CREATE");
11277 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011278 mDimSurface = new Surface(session, 0,
11279 "DimSurface",
11280 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011281 Surface.FX_SURFACE_DIM);
11282 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011283 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011284 }
11285 }
11286 }
11287
11288 /**
11289 * Show the dim surface.
11290 */
11291 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011292 if (!mDimShown) {
11293 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11294 dw + "x" + dh + ")");
11295 mDimShown = true;
11296 try {
11297 mDimSurface.setPosition(0, 0);
11298 mDimSurface.setSize(dw, dh);
11299 mDimSurface.show();
11300 } catch (RuntimeException e) {
11301 Slog.w(TAG, "Failure showing dim surface", e);
11302 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011303 }
11304 }
11305
11306 /**
11307 * Set's the dim surface's layer and update dim parameters that will be used in
11308 * {@link updateSurface} after all windows are examined.
11309 */
11310 void updateParameters(WindowState w, long currentTime) {
11311 mDimSurface.setLayer(w.mAnimLayer-1);
11312
11313 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011314 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011315 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011316 if (mDimTargetAlpha != target) {
11317 // If the desired dim level has changed, then
11318 // start an animation to it.
11319 mLastDimAnimTime = currentTime;
11320 long duration = (w.mAnimating && w.mAnimation != null)
11321 ? w.mAnimation.computeDurationHint()
11322 : DEFAULT_DIM_DURATION;
11323 if (target > mDimTargetAlpha) {
11324 // This is happening behind the activity UI,
11325 // so we can make it run a little longer to
11326 // give a stronger impression without disrupting
11327 // the user.
11328 duration *= DIM_DURATION_MULTIPLIER;
11329 }
11330 if (duration < 1) {
11331 // Don't divide by zero
11332 duration = 1;
11333 }
11334 mDimTargetAlpha = target;
11335 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11336 }
11337 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011338
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011339 /**
11340 * Updating the surface's alpha. Returns true if the animation continues, or returns
11341 * false when the animation is finished and the dim surface is hidden.
11342 */
11343 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11344 if (!dimming) {
11345 if (mDimTargetAlpha != 0) {
11346 mLastDimAnimTime = currentTime;
11347 mDimTargetAlpha = 0;
11348 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11349 }
11350 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011351
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011352 boolean animating = false;
11353 if (mLastDimAnimTime != 0) {
11354 mDimCurrentAlpha += mDimDeltaPerMs
11355 * (currentTime-mLastDimAnimTime);
11356 boolean more = true;
11357 if (displayFrozen) {
11358 // If the display is frozen, there is no reason to animate.
11359 more = false;
11360 } else if (mDimDeltaPerMs > 0) {
11361 if (mDimCurrentAlpha > mDimTargetAlpha) {
11362 more = false;
11363 }
11364 } else if (mDimDeltaPerMs < 0) {
11365 if (mDimCurrentAlpha < mDimTargetAlpha) {
11366 more = false;
11367 }
11368 } else {
11369 more = false;
11370 }
11371
11372 // Do we need to continue animating?
11373 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011374 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011375 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11376 mLastDimAnimTime = currentTime;
11377 mDimSurface.setAlpha(mDimCurrentAlpha);
11378 animating = true;
11379 } else {
11380 mDimCurrentAlpha = mDimTargetAlpha;
11381 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011382 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011383 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11384 mDimSurface.setAlpha(mDimCurrentAlpha);
11385 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011386 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011387 + ": HIDE");
11388 try {
11389 mDimSurface.hide();
11390 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011391 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011392 }
11393 mDimShown = false;
11394 }
11395 }
11396 }
11397 return animating;
11398 }
11399
11400 public void printTo(PrintWriter pw) {
11401 pw.print(" mDimShown="); pw.print(mDimShown);
11402 pw.print(" current="); pw.print(mDimCurrentAlpha);
11403 pw.print(" target="); pw.print(mDimTargetAlpha);
11404 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11405 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11406 }
11407 }
11408
11409 /**
11410 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11411 * This is used for opening/closing transition for apps in compatible mode.
11412 */
11413 private static class FadeInOutAnimation extends Animation {
11414 int mWidth;
11415 boolean mFadeIn;
11416
11417 public FadeInOutAnimation(boolean fadeIn) {
11418 setInterpolator(new AccelerateInterpolator());
11419 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11420 mFadeIn = fadeIn;
11421 }
11422
11423 @Override
11424 protected void applyTransformation(float interpolatedTime, Transformation t) {
11425 float x = interpolatedTime;
11426 if (!mFadeIn) {
11427 x = 1.0f - x; // reverse the interpolation for fade out
11428 }
11429 if (x < 0.5) {
11430 // move the window out of the screen.
11431 t.getMatrix().setTranslate(mWidth, 0);
11432 } else {
11433 t.getMatrix().setTranslate(0, 0);// show
11434 t.setAlpha((x - 0.5f) * 2);
11435 }
11436 }
11437
11438 @Override
11439 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11440 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11441 mWidth = width;
11442 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011443
11444 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011445 public int getZAdjustment() {
11446 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011447 }
11448 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011449}