blob: be5cc7bbc592ce00a876561deb63965c95695e98 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
19import static android.os.LocalPowerManager.CHEEK_EVENT;
20import static android.os.LocalPowerManager.OTHER_EVENT;
21import static android.os.LocalPowerManager.TOUCH_EVENT;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -070022import static android.os.LocalPowerManager.LONG_TOUCH_EVENT;
23import static android.os.LocalPowerManager.TOUCH_UP_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
25import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
26import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070027import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
29import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070030import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
32import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
33import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070034import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
36import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
38import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
39import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
40import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
41import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070042import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
44import com.android.internal.app.IBatteryStats;
45import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080046import com.android.internal.policy.impl.PhoneWindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import com.android.internal.view.IInputContext;
48import com.android.internal.view.IInputMethodClient;
49import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080050import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import com.android.server.KeyInputQueue.QueuedEvent;
52import com.android.server.am.BatteryStatsService;
53
54import android.Manifest;
55import android.app.ActivityManagerNative;
56import android.app.IActivityManager;
57import android.content.Context;
58import android.content.pm.ActivityInfo;
59import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070060import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.content.res.Configuration;
62import android.graphics.Matrix;
63import android.graphics.PixelFormat;
64import android.graphics.Rect;
65import android.graphics.Region;
66import android.os.BatteryStats;
67import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070068import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069import android.os.Debug;
70import android.os.Handler;
71import android.os.IBinder;
Michael Chan53071d62009-05-13 17:29:48 -070072import android.os.LatencyTimer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073import android.os.LocalPowerManager;
74import android.os.Looper;
75import android.os.Message;
76import android.os.Parcel;
77import android.os.ParcelFileDescriptor;
78import android.os.Power;
79import android.os.PowerManager;
80import android.os.Process;
81import android.os.RemoteException;
82import android.os.ServiceManager;
83import android.os.SystemClock;
84import android.os.SystemProperties;
85import android.os.TokenWatcher;
86import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070087import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088import android.util.EventLog;
Joe Onorato8a9b2202010-02-26 18:56:32 -080089import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090import android.util.SparseIntArray;
91import android.view.Display;
92import android.view.Gravity;
93import android.view.IApplicationToken;
94import android.view.IOnKeyguardExitResult;
95import android.view.IRotationWatcher;
96import android.view.IWindow;
97import android.view.IWindowManager;
98import android.view.IWindowSession;
99import android.view.KeyEvent;
100import android.view.MotionEvent;
101import android.view.RawInputEvent;
102import android.view.Surface;
103import android.view.SurfaceSession;
104import android.view.View;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -0700105import android.view.ViewConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106import android.view.ViewTreeObserver;
107import android.view.WindowManager;
108import android.view.WindowManagerImpl;
109import android.view.WindowManagerPolicy;
110import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700111import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112import android.view.animation.Animation;
113import android.view.animation.AnimationUtils;
114import android.view.animation.Transformation;
115
116import java.io.BufferedWriter;
117import java.io.File;
118import java.io.FileDescriptor;
119import java.io.IOException;
120import java.io.OutputStream;
121import java.io.OutputStreamWriter;
122import java.io.PrintWriter;
123import java.io.StringWriter;
124import java.net.Socket;
125import java.util.ArrayList;
126import java.util.HashMap;
127import java.util.HashSet;
128import java.util.Iterator;
129import java.util.List;
130
131/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700132public class WindowManagerService extends IWindowManager.Stub
133 implements Watchdog.Monitor, KeyInputQueue.HapticFeedbackCallback {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 static final String TAG = "WindowManager";
135 static final boolean DEBUG = false;
136 static final boolean DEBUG_FOCUS = false;
137 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800138 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800139 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 static final boolean DEBUG_LAYERS = false;
141 static final boolean DEBUG_INPUT = false;
142 static final boolean DEBUG_INPUT_METHOD = false;
143 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700144 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700146 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 static final boolean DEBUG_APP_TRANSITIONS = false;
148 static final boolean DEBUG_STARTING_WINDOW = false;
149 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700150 static final boolean DEBUG_WALLPAPER = false;
Dianne Hackbornce73c1e2010-04-12 23:11:38 -0700151 static final boolean DEBUG_FREEZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700153 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700154 static final boolean MEASURE_LATENCY = false;
155 static private LatencyTimer lt;
156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 static final boolean PROFILE_ORIENTATION = false;
158 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700159 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 /** How long to wait for subsequent key repeats, in milliseconds */
162 static final int KEY_REPEAT_DELAY = 50;
163
164 /** How much to multiply the policy's type layer, to reserve room
165 * for multiple windows of the same type and Z-ordering adjustment
166 * with TYPE_LAYER_OFFSET. */
167 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
170 * or below others in the same layer. */
171 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 /** How much to increment the layer for each window, to reserve room
174 * for effect surfaces between them.
175 */
176 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 /** The maximum length we will accept for a loaded animation duration:
179 * this is 10 seconds.
180 */
181 static final int MAX_ANIMATION_DURATION = 10*1000;
182
183 /** Amount of time (in milliseconds) to animate the dim surface from one
184 * value to another, when no window animation is driving it.
185 */
186 static final int DEFAULT_DIM_DURATION = 200;
187
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700188 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
189 * compatible windows.
190 */
191 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 /** Adjustment to time to perform a dim, to make it more dramatic.
194 */
195 static final int DIM_DURATION_MULTIPLIER = 6;
Romain Guy06882f82009-06-10 13:36:04 -0700196
Dianne Hackborncfaef692009-06-15 14:24:44 -0700197 static final int INJECT_FAILED = 0;
198 static final int INJECT_SUCCEEDED = 1;
199 static final int INJECT_NO_PERMISSION = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201 static final int UPDATE_FOCUS_NORMAL = 0;
202 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
203 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
204 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700205
Michael Chane96440f2009-05-06 10:27:36 -0700206 /** The minimum time between dispatching touch events. */
207 int mMinWaitTimeBetweenTouchEvents = 1000 / 35;
208
209 // Last touch event time
210 long mLastTouchEventTime = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700211
Michael Chane96440f2009-05-06 10:27:36 -0700212 // Last touch event type
213 int mLastTouchEventType = OTHER_EVENT;
Romain Guy06882f82009-06-10 13:36:04 -0700214
Michael Chane96440f2009-05-06 10:27:36 -0700215 // Time to wait before calling useractivity again. This saves CPU usage
216 // when we get a flood of touch events.
217 static final int MIN_TIME_BETWEEN_USERACTIVITIES = 1000;
218
219 // Last time we call user activity
220 long mLastUserActivityCallTime = 0;
221
Romain Guy06882f82009-06-10 13:36:04 -0700222 // Last time we updated battery stats
Michael Chane96440f2009-05-06 10:27:36 -0700223 long mLastBatteryStatsCallTime = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700226 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227
228 /**
229 * Condition waited on by {@link #reenableKeyguard} to know the call to
230 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500231 * This is set to true only if mKeyguardTokenWatcher.acquired() has
232 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500234 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235
Mike Lockwood983ee092009-11-22 01:42:24 -0500236 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
237 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 public void acquired() {
239 mPolicy.enableKeyguard(false);
Mike Lockwood983ee092009-11-22 01:42:24 -0500240 mKeyguardDisabled = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 }
242 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700243 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500244 synchronized (mKeyguardTokenWatcher) {
245 mKeyguardDisabled = false;
246 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 }
248 }
249 };
250
251 final Context mContext;
252
253 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
258
259 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800263 /**
264 * All currently active sessions with clients.
265 */
266 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 /**
269 * Mapping from an IWindow IBinder to the server's Window object.
270 * This is also used as the lock for all of our state.
271 */
272 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
273
274 /**
275 * Mapping from a token IBinder to a WindowToken object.
276 */
277 final HashMap<IBinder, WindowToken> mTokenMap =
278 new HashMap<IBinder, WindowToken>();
279
280 /**
281 * The same tokens as mTokenMap, stored in a list for efficient iteration
282 * over them.
283 */
284 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 /**
287 * Window tokens that are in the process of exiting, but still
288 * on screen for animations.
289 */
290 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
291
292 /**
293 * Z-ordered (bottom-most first) list of all application tokens, for
294 * controlling the ordering of windows in different applications. This
295 * contains WindowToken objects.
296 */
297 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
298
299 /**
300 * Application tokens that are in the process of exiting, but still
301 * on screen for animations.
302 */
303 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
304
305 /**
306 * List of window tokens that have finished starting their application,
307 * and now need to have the policy remove their windows.
308 */
309 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
310
311 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700312 * This was the app token that was used to retrieve the last enter
313 * animation. It will be used for the next exit animation.
314 */
315 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800316
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700317 /**
318 * These were the layout params used to retrieve the last enter animation.
319 * They will be used for the next exit animation.
320 */
321 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800322
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700323 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800324 * Z-ordered (bottom-most first) list of all Window objects.
325 */
326 final ArrayList mWindows = new ArrayList();
327
328 /**
329 * Windows that are being resized. Used so we can tell the client about
330 * the resize after closing the transaction in which we resized the
331 * underlying surface.
332 */
333 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
334
335 /**
336 * Windows whose animations have ended and now must be removed.
337 */
338 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
339
340 /**
341 * Windows whose surface should be destroyed.
342 */
343 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
344
345 /**
346 * Windows that have lost input focus and are waiting for the new
347 * focus window to be displayed before they are told about this.
348 */
349 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
350
351 /**
352 * This is set when we have run out of memory, and will either be an empty
353 * list or contain windows that need to be force removed.
354 */
355 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700360 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 Surface mBlurSurface;
362 boolean mBlurShown;
Romain Guy06882f82009-06-10 13:36:04 -0700363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800364 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 final float[] mTmpFloats = new float[9];
367
368 boolean mSafeMode;
369 boolean mDisplayEnabled = false;
370 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700371 int mInitialDisplayWidth = 0;
372 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 int mRotation = 0;
374 int mRequestedRotation = 0;
375 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700376 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 ArrayList<IRotationWatcher> mRotationWatchers
378 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 boolean mLayoutNeeded = true;
381 boolean mAnimationPending = false;
382 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800383 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 boolean mWindowsFreezingScreen = false;
385 long mFreezeGcPending = 0;
386 int mAppsFreezingScreen = 0;
387
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800388 int mLayoutSeq = 0;
389
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800390 // State while inside of layoutAndPlaceSurfacesLocked().
391 boolean mFocusMayChange;
392
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800393 Configuration mCurConfiguration = new Configuration();
394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 // This is held as long as we have the screen frozen, to give us time to
396 // perform a rotation animation when turning off shows the lock screen which
397 // changes the orientation.
398 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 // State management of app transitions. When we are preparing for a
401 // transition, mNextAppTransition will be the kind of transition to
402 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
403 // mOpeningApps and mClosingApps are the lists of tokens that will be
404 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700405 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700406 String mNextAppTransitionPackage;
407 int mNextAppTransitionEnter;
408 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700410 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 boolean mAppTransitionTimeout = false;
412 boolean mStartingIconInTransition = false;
413 boolean mSkipAppTransitionAnimation = false;
414 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
415 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700416 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
417 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 //flag to detect fat touch events
420 boolean mFatTouch = false;
421 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 H mH = new H();
424
425 WindowState mCurrentFocus = null;
426 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 // This just indicates the window the input method is on top of, not
429 // necessarily the window its input is going to.
430 WindowState mInputMethodTarget = null;
431 WindowState mUpcomingInputMethodTarget = null;
432 boolean mInputMethodTargetWaitingAnim;
433 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 WindowState mInputMethodWindow = null;
436 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
437
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700438 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800439
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700440 // If non-null, this is the currently visible window that is associated
441 // with the wallpaper.
442 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700443 // If non-null, we are in the middle of animating from one wallpaper target
444 // to another, and this is the lower one in Z-order.
445 WindowState mLowerWallpaperTarget = null;
446 // If non-null, we are in the middle of animating from one wallpaper target
447 // to another, and this is the higher one in Z-order.
448 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700449 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700450 float mLastWallpaperX = -1;
451 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800452 float mLastWallpaperXStep = -1;
453 float mLastWallpaperYStep = -1;
Dianne Hackborn6adba242009-11-10 11:10:09 -0800454 boolean mSendingPointersToWallpaper = false;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700455 // This is set when we are waiting for a wallpaper to tell us it is done
456 // changing its scroll position.
457 WindowState mWaitingOnWallpaper;
458 // The last time we had a timeout when waiting for a wallpaper.
459 long mLastWallpaperTimeoutTime;
460 // We give a wallpaper up to 150ms to finish scrolling.
461 static final long WALLPAPER_TIMEOUT = 150;
462 // Time we wait after a timeout before trying to wait again.
463 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800465 AppWindowToken mFocusedApp = null;
466
467 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469 float mWindowAnimationScale = 1.0f;
470 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800472 final KeyWaiter mKeyWaiter = new KeyWaiter();
473 final KeyQ mQueue;
474 final InputDispatcherThread mInputThread;
475
476 // Who is holding the screen on.
477 Session mHoldingScreenOn;
Romain Guy06882f82009-06-10 13:36:04 -0700478
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700479 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481 /**
482 * Whether the UI is currently running in touch mode (not showing
483 * navigational focus because the user is directly pressing the screen).
484 */
485 boolean mInTouchMode = false;
486
487 private ViewServer mViewServer;
488
489 final Rect mTempRect = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -0700490
Dianne Hackbornc485a602009-03-24 22:39:49 -0700491 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700492 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700493
494 // The frame use to limit the size of the app running in compatibility mode.
495 Rect mCompatibleScreenFrame = new Rect();
496 // The surface used to fill the outer rim of the app running in compatibility mode.
497 Surface mBackgroundFillerSurface = null;
498 boolean mBackgroundFillerShown = false;
499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 public static WindowManagerService main(Context context,
501 PowerManagerService pm, boolean haveInputMethods) {
502 WMThread thr = new WMThread(context, pm, haveInputMethods);
503 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 synchronized (thr) {
506 while (thr.mService == null) {
507 try {
508 thr.wait();
509 } catch (InterruptedException e) {
510 }
511 }
512 }
Romain Guy06882f82009-06-10 13:36:04 -0700513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 return thr.mService;
515 }
Romain Guy06882f82009-06-10 13:36:04 -0700516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 static class WMThread extends Thread {
518 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 private final Context mContext;
521 private final PowerManagerService mPM;
522 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524 public WMThread(Context context, PowerManagerService pm,
525 boolean haveInputMethods) {
526 super("WindowManager");
527 mContext = context;
528 mPM = pm;
529 mHaveInputMethods = haveInputMethods;
530 }
Romain Guy06882f82009-06-10 13:36:04 -0700531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 public void run() {
533 Looper.prepare();
534 WindowManagerService s = new WindowManagerService(mContext, mPM,
535 mHaveInputMethods);
536 android.os.Process.setThreadPriority(
537 android.os.Process.THREAD_PRIORITY_DISPLAY);
Romain Guy06882f82009-06-10 13:36:04 -0700538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 synchronized (this) {
540 mService = s;
541 notifyAll();
542 }
Romain Guy06882f82009-06-10 13:36:04 -0700543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 Looper.loop();
545 }
546 }
547
548 static class PolicyThread extends Thread {
549 private final WindowManagerPolicy mPolicy;
550 private final WindowManagerService mService;
551 private final Context mContext;
552 private final PowerManagerService mPM;
553 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800555 public PolicyThread(WindowManagerPolicy policy,
556 WindowManagerService service, Context context,
557 PowerManagerService pm) {
558 super("WindowManagerPolicy");
559 mPolicy = policy;
560 mService = service;
561 mContext = context;
562 mPM = pm;
563 }
Romain Guy06882f82009-06-10 13:36:04 -0700564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 public void run() {
566 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800567 WindowManagerPolicyThread.set(this, Looper.myLooper());
568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800570 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 android.os.Process.setThreadPriority(
572 android.os.Process.THREAD_PRIORITY_FOREGROUND);
573 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 synchronized (this) {
576 mRunning = true;
577 notifyAll();
578 }
Romain Guy06882f82009-06-10 13:36:04 -0700579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580 Looper.loop();
581 }
582 }
583
584 private WindowManagerService(Context context, PowerManagerService pm,
585 boolean haveInputMethods) {
Michael Chan53071d62009-05-13 17:29:48 -0700586 if (MEASURE_LATENCY) {
587 lt = new LatencyTimer(100, 1000);
588 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 mContext = context;
591 mHaveInputMethods = haveInputMethods;
592 mLimitedAlphaCompositing = context.getResources().getBoolean(
593 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 mPowerManager = pm;
596 mPowerManager.setPolicy(mPolicy);
597 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
598 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
599 "SCREEN_FROZEN");
600 mScreenFrozenLock.setReferenceCounted(false);
601
602 mActivityManager = ActivityManagerNative.getDefault();
603 mBatteryStats = BatteryStatsService.getService();
604
605 // Get persisted window scale setting
606 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
607 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
608 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
609 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700610
Michael Chan9f028e62009-08-04 17:37:46 -0700611 int max_events_per_sec = 35;
612 try {
613 max_events_per_sec = Integer.parseInt(SystemProperties
614 .get("windowsmgr.max_events_per_sec"));
615 if (max_events_per_sec < 1) {
616 max_events_per_sec = 35;
617 }
618 } catch (NumberFormatException e) {
619 }
620 mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec;
621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 mQueue = new KeyQ();
623
624 mInputThread = new InputDispatcherThread();
Romain Guy06882f82009-06-10 13:36:04 -0700625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
627 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 synchronized (thr) {
630 while (!thr.mRunning) {
631 try {
632 thr.wait();
633 } catch (InterruptedException e) {
634 }
635 }
636 }
Romain Guy06882f82009-06-10 13:36:04 -0700637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 mInputThread.start();
Romain Guy06882f82009-06-10 13:36:04 -0700639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 // Add ourself to the Watchdog monitors.
641 Watchdog.getInstance().addMonitor(this);
642 }
643
644 @Override
645 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
646 throws RemoteException {
647 try {
648 return super.onTransact(code, data, reply, flags);
649 } catch (RuntimeException e) {
650 // The window manager only throws security exceptions, so let's
651 // log all others.
652 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800653 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654 }
655 throw e;
656 }
657 }
658
659 private void placeWindowAfter(Object pos, WindowState window) {
660 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800661 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 TAG, "Adding window " + window + " at "
663 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
664 mWindows.add(i+1, window);
665 }
666
667 private void placeWindowBefore(Object pos, WindowState window) {
668 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800669 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 TAG, "Adding window " + window + " at "
671 + i + " of " + mWindows.size() + " (before " + pos + ")");
672 mWindows.add(i, window);
673 }
674
675 //This method finds out the index of a window that has the same app token as
676 //win. used for z ordering the windows in mWindows
677 private int findIdxBasedOnAppTokens(WindowState win) {
678 //use a local variable to cache mWindows
679 ArrayList localmWindows = mWindows;
680 int jmax = localmWindows.size();
681 if(jmax == 0) {
682 return -1;
683 }
684 for(int j = (jmax-1); j >= 0; j--) {
685 WindowState wentry = (WindowState)localmWindows.get(j);
686 if(wentry.mAppToken == win.mAppToken) {
687 return j;
688 }
689 }
690 return -1;
691 }
Romain Guy06882f82009-06-10 13:36:04 -0700692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800693 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
694 final IWindow client = win.mClient;
695 final WindowToken token = win.mToken;
696 final ArrayList localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 final int N = localmWindows.size();
699 final WindowState attached = win.mAttachedWindow;
700 int i;
701 if (attached == null) {
702 int tokenWindowsPos = token.windows.size();
703 if (token.appWindowToken != null) {
704 int index = tokenWindowsPos-1;
705 if (index >= 0) {
706 // If this application has existing windows, we
707 // simply place the new window on top of them... but
708 // keep the starting window on top.
709 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
710 // Base windows go behind everything else.
711 placeWindowBefore(token.windows.get(0), win);
712 tokenWindowsPos = 0;
713 } else {
714 AppWindowToken atoken = win.mAppToken;
715 if (atoken != null &&
716 token.windows.get(index) == atoken.startingWindow) {
717 placeWindowBefore(token.windows.get(index), win);
718 tokenWindowsPos--;
719 } else {
720 int newIdx = findIdxBasedOnAppTokens(win);
721 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700722 //there is a window above this one associated with the same
723 //apptoken note that the window could be a floating window
724 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800726 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700727 TAG, "Adding window " + win + " at "
728 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800729 localmWindows.add(newIdx+1, win);
Romain Guy06882f82009-06-10 13:36:04 -0700730 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800731 }
732 }
733 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800734 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 TAG, "Figuring out where to add app window "
736 + client.asBinder() + " (token=" + token + ")");
737 // Figure out where the window should go, based on the
738 // order of applications.
739 final int NA = mAppTokens.size();
740 Object pos = null;
741 for (i=NA-1; i>=0; i--) {
742 AppWindowToken t = mAppTokens.get(i);
743 if (t == token) {
744 i--;
745 break;
746 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800747
Dianne Hackborna8f60182009-09-01 19:01:50 -0700748 // We haven't reached the token yet; if this token
749 // is not going to the bottom and has windows, we can
750 // use it as an anchor for when we do reach the token.
751 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800752 pos = t.windows.get(0);
753 }
754 }
755 // We now know the index into the apps. If we found
756 // an app window above, that gives us the position; else
757 // we need to look some more.
758 if (pos != null) {
759 // Move behind any windows attached to this one.
Romain Guy06882f82009-06-10 13:36:04 -0700760 WindowToken atoken =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 mTokenMap.get(((WindowState)pos).mClient.asBinder());
762 if (atoken != null) {
763 final int NC = atoken.windows.size();
764 if (NC > 0) {
765 WindowState bottom = atoken.windows.get(0);
766 if (bottom.mSubLayer < 0) {
767 pos = bottom;
768 }
769 }
770 }
771 placeWindowBefore(pos, win);
772 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700773 // Continue looking down until we find the first
774 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 while (i >= 0) {
776 AppWindowToken t = mAppTokens.get(i);
777 final int NW = t.windows.size();
778 if (NW > 0) {
779 pos = t.windows.get(NW-1);
780 break;
781 }
782 i--;
783 }
784 if (pos != null) {
785 // Move in front of any windows attached to this
786 // one.
787 WindowToken atoken =
788 mTokenMap.get(((WindowState)pos).mClient.asBinder());
789 if (atoken != null) {
790 final int NC = atoken.windows.size();
791 if (NC > 0) {
792 WindowState top = atoken.windows.get(NC-1);
793 if (top.mSubLayer >= 0) {
794 pos = top;
795 }
796 }
797 }
798 placeWindowAfter(pos, win);
799 } else {
800 // Just search for the start of this layer.
801 final int myLayer = win.mBaseLayer;
802 for (i=0; i<N; i++) {
803 WindowState w = (WindowState)localmWindows.get(i);
804 if (w.mBaseLayer > myLayer) {
805 break;
806 }
807 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800808 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700809 TAG, "Adding window " + win + " at "
810 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800811 localmWindows.add(i, win);
812 }
813 }
814 }
815 } else {
816 // Figure out where window should go, based on layer.
817 final int myLayer = win.mBaseLayer;
818 for (i=N-1; i>=0; i--) {
819 if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) {
820 i++;
821 break;
822 }
823 }
824 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800825 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700826 TAG, "Adding window " + win + " at "
827 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 localmWindows.add(i, win);
829 }
830 if (addToToken) {
831 token.windows.add(tokenWindowsPos, win);
832 }
833
834 } else {
835 // Figure out this window's ordering relative to the window
836 // it is attached to.
837 final int NA = token.windows.size();
838 final int sublayer = win.mSubLayer;
839 int largestSublayer = Integer.MIN_VALUE;
840 WindowState windowWithLargestSublayer = null;
841 for (i=0; i<NA; i++) {
842 WindowState w = token.windows.get(i);
843 final int wSublayer = w.mSubLayer;
844 if (wSublayer >= largestSublayer) {
845 largestSublayer = wSublayer;
846 windowWithLargestSublayer = w;
847 }
848 if (sublayer < 0) {
849 // For negative sublayers, we go below all windows
850 // in the same sublayer.
851 if (wSublayer >= sublayer) {
852 if (addToToken) {
853 token.windows.add(i, win);
854 }
855 placeWindowBefore(
856 wSublayer >= 0 ? attached : w, win);
857 break;
858 }
859 } else {
860 // For positive sublayers, we go above all windows
861 // in the same sublayer.
862 if (wSublayer > sublayer) {
863 if (addToToken) {
864 token.windows.add(i, win);
865 }
866 placeWindowBefore(w, win);
867 break;
868 }
869 }
870 }
871 if (i >= NA) {
872 if (addToToken) {
873 token.windows.add(win);
874 }
875 if (sublayer < 0) {
876 placeWindowBefore(attached, win);
877 } else {
878 placeWindowAfter(largestSublayer >= 0
879 ? windowWithLargestSublayer
880 : attached,
881 win);
882 }
883 }
884 }
Romain Guy06882f82009-06-10 13:36:04 -0700885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800886 if (win.mAppToken != null && addToToken) {
887 win.mAppToken.allAppWindows.add(win);
888 }
889 }
Romain Guy06882f82009-06-10 13:36:04 -0700890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891 static boolean canBeImeTarget(WindowState w) {
892 final int fl = w.mAttrs.flags
893 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
894 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
895 return w.isVisibleOrAdding();
896 }
897 return false;
898 }
Romain Guy06882f82009-06-10 13:36:04 -0700899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
901 final ArrayList localmWindows = mWindows;
902 final int N = localmWindows.size();
903 WindowState w = null;
904 int i = N;
905 while (i > 0) {
906 i--;
907 w = (WindowState)localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700908
Joe Onorato8a9b2202010-02-26 18:56:32 -0800909 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800910 // + Integer.toHexString(w.mAttrs.flags));
911 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800912 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800914 // Yet more tricksyness! If this window is a "starting"
915 // window, we do actually want to be on top of it, but
916 // it is not -really- where input will go. So if the caller
917 // is not actually looking to move the IME, look down below
918 // for a real window to target...
919 if (!willMove
920 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
921 && i > 0) {
922 WindowState wb = (WindowState)localmWindows.get(i-1);
923 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
924 i--;
925 w = wb;
926 }
927 }
928 break;
929 }
930 }
Romain Guy06882f82009-06-10 13:36:04 -0700931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700933
Joe Onorato8a9b2202010-02-26 18:56:32 -0800934 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 if (willMove && w != null) {
938 final WindowState curTarget = mInputMethodTarget;
939 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800941 // Now some fun for dealing with window animations that
942 // modify the Z order. We need to look at all windows below
943 // the current target that are in this app, finding the highest
944 // visible one in layering.
945 AppWindowToken token = curTarget.mAppToken;
946 WindowState highestTarget = null;
947 int highestPos = 0;
948 if (token.animating || token.animation != null) {
949 int pos = 0;
950 pos = localmWindows.indexOf(curTarget);
951 while (pos >= 0) {
952 WindowState win = (WindowState)localmWindows.get(pos);
953 if (win.mAppToken != token) {
954 break;
955 }
956 if (!win.mRemoved) {
957 if (highestTarget == null || win.mAnimLayer >
958 highestTarget.mAnimLayer) {
959 highestTarget = win;
960 highestPos = pos;
961 }
962 }
963 pos--;
964 }
965 }
Romain Guy06882f82009-06-10 13:36:04 -0700966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800967 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800968 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 + mNextAppTransition + " " + highestTarget
970 + " animating=" + highestTarget.isAnimating()
971 + " layer=" + highestTarget.mAnimLayer
972 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700973
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700974 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800975 // If we are currently setting up for an animation,
976 // hold everything until we can find out what will happen.
977 mInputMethodTargetWaitingAnim = true;
978 mInputMethodTarget = highestTarget;
979 return highestPos + 1;
980 } else if (highestTarget.isAnimating() &&
981 highestTarget.mAnimLayer > w.mAnimLayer) {
982 // If the window we are currently targeting is involved
983 // with an animation, and it is on top of the next target
984 // we will be over, then hold off on moving until
985 // that is done.
986 mInputMethodTarget = highestTarget;
987 return highestPos + 1;
988 }
989 }
990 }
991 }
Romain Guy06882f82009-06-10 13:36:04 -0700992
Joe Onorato8a9b2202010-02-26 18:56:32 -0800993 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800994 if (w != null) {
995 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -0800996 if (DEBUG_INPUT_METHOD) {
997 RuntimeException e = null;
998 if (!HIDE_STACK_CRAWLS) {
999 e = new RuntimeException();
1000 e.fillInStackTrace();
1001 }
1002 Slog.w(TAG, "Moving IM target from "
1003 + mInputMethodTarget + " to " + w, e);
1004 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005 mInputMethodTarget = w;
1006 if (w.mAppToken != null) {
1007 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1008 } else {
1009 setInputMethodAnimLayerAdjustment(0);
1010 }
1011 }
1012 return i+1;
1013 }
1014 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001015 if (DEBUG_INPUT_METHOD) {
1016 RuntimeException e = null;
1017 if (!HIDE_STACK_CRAWLS) {
1018 e = new RuntimeException();
1019 e.fillInStackTrace();
1020 }
1021 Slog.w(TAG, "Moving IM target from "
1022 + mInputMethodTarget + " to null", e);
1023 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001024 mInputMethodTarget = null;
1025 setInputMethodAnimLayerAdjustment(0);
1026 }
1027 return -1;
1028 }
Romain Guy06882f82009-06-10 13:36:04 -07001029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001030 void addInputMethodWindowToListLocked(WindowState win) {
1031 int pos = findDesiredInputMethodWindowIndexLocked(true);
1032 if (pos >= 0) {
1033 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001034 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001035 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 mWindows.add(pos, win);
1037 moveInputMethodDialogsLocked(pos+1);
1038 return;
1039 }
1040 win.mTargetAppToken = null;
1041 addWindowToListInOrderLocked(win, true);
1042 moveInputMethodDialogsLocked(pos);
1043 }
Romain Guy06882f82009-06-10 13:36:04 -07001044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001046 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 mInputMethodAnimLayerAdjustment = adj;
1048 WindowState imw = mInputMethodWindow;
1049 if (imw != null) {
1050 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001051 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001052 + " anim layer: " + imw.mAnimLayer);
1053 int wi = imw.mChildWindows.size();
1054 while (wi > 0) {
1055 wi--;
1056 WindowState cw = (WindowState)imw.mChildWindows.get(wi);
1057 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001058 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059 + " anim layer: " + cw.mAnimLayer);
1060 }
1061 }
1062 int di = mInputMethodDialogs.size();
1063 while (di > 0) {
1064 di --;
1065 imw = mInputMethodDialogs.get(di);
1066 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001067 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 + " anim layer: " + imw.mAnimLayer);
1069 }
1070 }
Romain Guy06882f82009-06-10 13:36:04 -07001071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1073 int wpos = mWindows.indexOf(win);
1074 if (wpos >= 0) {
1075 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001076 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077 mWindows.remove(wpos);
1078 int NC = win.mChildWindows.size();
1079 while (NC > 0) {
1080 NC--;
1081 WindowState cw = (WindowState)win.mChildWindows.get(NC);
1082 int cpos = mWindows.indexOf(cw);
1083 if (cpos >= 0) {
1084 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001085 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001086 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 mWindows.remove(cpos);
1088 }
1089 }
1090 }
1091 return interestingPos;
1092 }
Romain Guy06882f82009-06-10 13:36:04 -07001093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 private void reAddWindowToListInOrderLocked(WindowState win) {
1095 addWindowToListInOrderLocked(win, false);
1096 // This is a hack to get all of the child windows added as well
1097 // at the right position. Child windows should be rare and
1098 // this case should be rare, so it shouldn't be that big a deal.
1099 int wpos = mWindows.indexOf(win);
1100 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001101 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001102 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 mWindows.remove(wpos);
1104 reAddWindowLocked(wpos, win);
1105 }
1106 }
Romain Guy06882f82009-06-10 13:36:04 -07001107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001108 void logWindowList(String prefix) {
1109 int N = mWindows.size();
1110 while (N > 0) {
1111 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001112 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 }
1114 }
Romain Guy06882f82009-06-10 13:36:04 -07001115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 void moveInputMethodDialogsLocked(int pos) {
1117 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001120 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001121 for (int i=0; i<N; i++) {
1122 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1123 }
1124 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001125 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001126 logWindowList(" ");
1127 }
Romain Guy06882f82009-06-10 13:36:04 -07001128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001129 if (pos >= 0) {
1130 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1131 if (pos < mWindows.size()) {
1132 WindowState wp = (WindowState)mWindows.get(pos);
1133 if (wp == mInputMethodWindow) {
1134 pos++;
1135 }
1136 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001137 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001138 for (int i=0; i<N; i++) {
1139 WindowState win = dialogs.get(i);
1140 win.mTargetAppToken = targetAppToken;
1141 pos = reAddWindowLocked(pos, win);
1142 }
1143 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001144 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 logWindowList(" ");
1146 }
1147 return;
1148 }
1149 for (int i=0; i<N; i++) {
1150 WindowState win = dialogs.get(i);
1151 win.mTargetAppToken = null;
1152 reAddWindowToListInOrderLocked(win);
1153 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001154 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 logWindowList(" ");
1156 }
1157 }
1158 }
Romain Guy06882f82009-06-10 13:36:04 -07001159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1161 final WindowState imWin = mInputMethodWindow;
1162 final int DN = mInputMethodDialogs.size();
1163 if (imWin == null && DN == 0) {
1164 return false;
1165 }
Romain Guy06882f82009-06-10 13:36:04 -07001166
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001167 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1168 if (imPos >= 0) {
1169 // In this case, the input method windows are to be placed
1170 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001172 // First check to see if the input method windows are already
1173 // located here, and contiguous.
1174 final int N = mWindows.size();
1175 WindowState firstImWin = imPos < N
1176 ? (WindowState)mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001178 // Figure out the actual input method window that should be
1179 // at the bottom of their stack.
1180 WindowState baseImWin = imWin != null
1181 ? imWin : mInputMethodDialogs.get(0);
1182 if (baseImWin.mChildWindows.size() > 0) {
1183 WindowState cw = (WindowState)baseImWin.mChildWindows.get(0);
1184 if (cw.mSubLayer < 0) baseImWin = cw;
1185 }
Romain Guy06882f82009-06-10 13:36:04 -07001186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001187 if (firstImWin == baseImWin) {
1188 // The windows haven't moved... but are they still contiguous?
1189 // First find the top IM window.
1190 int pos = imPos+1;
1191 while (pos < N) {
1192 if (!((WindowState)mWindows.get(pos)).mIsImWindow) {
1193 break;
1194 }
1195 pos++;
1196 }
1197 pos++;
1198 // Now there should be no more input method windows above.
1199 while (pos < N) {
1200 if (((WindowState)mWindows.get(pos)).mIsImWindow) {
1201 break;
1202 }
1203 pos++;
1204 }
1205 if (pos >= N) {
1206 // All is good!
1207 return false;
1208 }
1209 }
Romain Guy06882f82009-06-10 13:36:04 -07001210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001211 if (imWin != null) {
1212 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001213 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001214 logWindowList(" ");
1215 }
1216 imPos = tmpRemoveWindowLocked(imPos, imWin);
1217 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001218 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001219 logWindowList(" ");
1220 }
1221 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1222 reAddWindowLocked(imPos, imWin);
1223 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001224 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001225 logWindowList(" ");
1226 }
1227 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1228 } else {
1229 moveInputMethodDialogsLocked(imPos);
1230 }
Romain Guy06882f82009-06-10 13:36:04 -07001231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 } else {
1233 // In this case, the input method windows go in a fixed layer,
1234 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001236 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001237 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001238 tmpRemoveWindowLocked(0, imWin);
1239 imWin.mTargetAppToken = null;
1240 reAddWindowToListInOrderLocked(imWin);
1241 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001242 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243 logWindowList(" ");
1244 }
1245 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1246 } else {
1247 moveInputMethodDialogsLocked(-1);;
1248 }
Romain Guy06882f82009-06-10 13:36:04 -07001249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001250 }
Romain Guy06882f82009-06-10 13:36:04 -07001251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 if (needAssignLayers) {
1253 assignLayersLocked();
1254 }
Romain Guy06882f82009-06-10 13:36:04 -07001255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 return true;
1257 }
Romain Guy06882f82009-06-10 13:36:04 -07001258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001259 void adjustInputMethodDialogsLocked() {
1260 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1261 }
Romain Guy06882f82009-06-10 13:36:04 -07001262
Dianne Hackborn25994b42009-09-04 14:21:19 -07001263 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001264 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001265 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1266 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1267 ? wallpaperTarget.mAppToken.animation : null)
1268 + " upper=" + mUpperWallpaperTarget
1269 + " lower=" + mLowerWallpaperTarget);
1270 return (wallpaperTarget != null
1271 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1272 && wallpaperTarget.mAppToken.animation != null)))
1273 || mUpperWallpaperTarget != null
1274 || mLowerWallpaperTarget != null;
1275 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001276
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001277 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1278 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001279
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001280 int adjustWallpaperWindowsLocked() {
1281 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001282
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001283 final int dw = mDisplay.getWidth();
1284 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001285
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001286 // First find top-most window that has asked to be on top of the
1287 // wallpaper; all wallpapers go behind it.
1288 final ArrayList localmWindows = mWindows;
1289 int N = localmWindows.size();
1290 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001291 WindowState foundW = null;
1292 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001293 WindowState topCurW = null;
1294 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001295 int i = N;
1296 while (i > 0) {
1297 i--;
1298 w = (WindowState)localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001299 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1300 if (topCurW == null) {
1301 topCurW = w;
1302 topCurI = i;
1303 }
1304 continue;
1305 }
1306 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001307 if (w.mAppToken != null) {
1308 // If this window's app token is hidden and not animating,
1309 // it is of no interest to us.
1310 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001311 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001312 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001313 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001314 continue;
1315 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001316 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001317 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001318 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1319 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001320 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001321 && (mWallpaperTarget == w
1322 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001323 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001324 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001325 foundW = w;
1326 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001327 if (w == mWallpaperTarget && ((w.mAppToken != null
1328 && w.mAppToken.animation != null)
1329 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001330 // The current wallpaper target is animating, so we'll
1331 // look behind it for another possible target and figure
1332 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001333 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001334 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001335 continue;
1336 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001337 break;
1338 }
1339 }
1340
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001341 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001342 // If we are currently waiting for an app transition, and either
1343 // the current target or the next target are involved with it,
1344 // then hold off on doing anything with the wallpaper.
1345 // Note that we are checking here for just whether the target
1346 // is part of an app token... which is potentially overly aggressive
1347 // (the app token may not be involved in the transition), but good
1348 // enough (we'll just wait until whatever transition is pending
1349 // executes).
1350 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001351 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001352 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001353 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001354 }
1355 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001356 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001357 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001358 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001359 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001360 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001361
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001362 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001363 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001364 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001365 + " oldTarget: " + mWallpaperTarget);
1366 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001367
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001368 mLowerWallpaperTarget = null;
1369 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001370
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001371 WindowState oldW = mWallpaperTarget;
1372 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001373
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001374 // Now what is happening... if the current and new targets are
1375 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001376 if (foundW != null && oldW != null) {
1377 boolean oldAnim = oldW.mAnimation != null
1378 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1379 boolean foundAnim = foundW.mAnimation != null
1380 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001381 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001382 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001383 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001384 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001385 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001386 int oldI = localmWindows.indexOf(oldW);
1387 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001388 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001389 }
1390 if (oldI >= 0) {
1391 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001392 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001393 + "=" + oldW + "; new#" + foundI
1394 + "=" + foundW);
1395 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001396
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001397 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001398 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001399 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001400 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001401 }
1402 mWallpaperTarget = oldW;
1403 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001404
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001405 // Now set the upper and lower wallpaper targets
1406 // correctly, and make sure that we are positioning
1407 // the wallpaper below the lower.
1408 if (foundI > oldI) {
1409 // The new target is on top of the old one.
1410 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001411 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001412 }
1413 mUpperWallpaperTarget = foundW;
1414 mLowerWallpaperTarget = oldW;
1415 foundW = oldW;
1416 foundI = oldI;
1417 } else {
1418 // The new target is below the old one.
1419 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001420 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001421 }
1422 mUpperWallpaperTarget = oldW;
1423 mLowerWallpaperTarget = foundW;
1424 }
1425 }
1426 }
1427 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001428
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001429 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001430 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001431 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1432 || (mLowerWallpaperTarget.mAppToken != null
1433 && mLowerWallpaperTarget.mAppToken.animation != null);
1434 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1435 || (mUpperWallpaperTarget.mAppToken != null
1436 && mUpperWallpaperTarget.mAppToken.animation != null);
1437 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001438 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001439 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001440 }
1441 mLowerWallpaperTarget = null;
1442 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001443 }
1444 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001445
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001446 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001447 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001448 // The window is visible to the compositor... but is it visible
1449 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001450 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001451 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001452
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001453 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001454 // its layer adjustment. Only do this if we are not transfering
1455 // between two wallpaper targets.
1456 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001457 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001458 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001459
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001460 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1461 * TYPE_LAYER_MULTIPLIER
1462 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001463
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001464 // Now w is the window we are supposed to be behind... but we
1465 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001466 // AND any starting window associated with it, AND below the
1467 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001468 while (foundI > 0) {
1469 WindowState wb = (WindowState)localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001470 if (wb.mBaseLayer < maxLayer &&
1471 wb.mAttachedWindow != foundW &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001472 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001473 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001474 // This window is not related to the previous one in any
1475 // interesting way, so stop here.
1476 break;
1477 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001478 foundW = wb;
1479 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001480 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001481 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001482 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001483 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001484
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001485 if (foundW == null && topCurW != null) {
1486 // There is no wallpaper target, so it goes at the bottom.
1487 // We will assume it is the same place as last time, if known.
1488 foundW = topCurW;
1489 foundI = topCurI+1;
1490 } else {
1491 // Okay i is the position immediately above the wallpaper. Look at
1492 // what is below it for later.
1493 foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null;
1494 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001495
Dianne Hackborn284ac932009-08-28 10:34:25 -07001496 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001497 if (mWallpaperTarget.mWallpaperX >= 0) {
1498 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001499 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001500 }
1501 if (mWallpaperTarget.mWallpaperY >= 0) {
1502 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001503 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001504 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001505 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001506
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001507 // Start stepping backwards from here, ensuring that our wallpaper windows
1508 // are correctly placed.
1509 int curTokenIndex = mWallpaperTokens.size();
1510 while (curTokenIndex > 0) {
1511 curTokenIndex--;
1512 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001513 if (token.hidden == visible) {
1514 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1515 token.hidden = !visible;
1516 // Need to do a layout to ensure the wallpaper now has the
1517 // correct size.
1518 mLayoutNeeded = true;
1519 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001520
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001521 int curWallpaperIndex = token.windows.size();
1522 while (curWallpaperIndex > 0) {
1523 curWallpaperIndex--;
1524 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001525
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001526 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001527 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001528 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001529
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001530 // First, make sure the client has the current visibility
1531 // state.
1532 if (wallpaper.mWallpaperVisible != visible) {
1533 wallpaper.mWallpaperVisible = visible;
1534 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001535 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001536 "Setting visibility of wallpaper " + wallpaper
1537 + ": " + visible);
1538 wallpaper.mClient.dispatchAppVisibility(visible);
1539 } catch (RemoteException e) {
1540 }
1541 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001542
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001543 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001544 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001545 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001546
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001547 // First, if this window is at the current index, then all
1548 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001549 if (wallpaper == foundW) {
1550 foundI--;
1551 foundW = foundI > 0
1552 ? (WindowState)localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001553 continue;
1554 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001555
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001556 // The window didn't match... the current wallpaper window,
1557 // wherever it is, is in the wrong place, so make sure it is
1558 // not in the list.
1559 int oldIndex = localmWindows.indexOf(wallpaper);
1560 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001561 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001562 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001563 localmWindows.remove(oldIndex);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001564 if (oldIndex < foundI) {
1565 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001566 }
1567 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001568
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001569 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001570 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001571 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001572 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001573
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001574 localmWindows.add(foundI, wallpaper);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001575 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001576 }
1577 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001578
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001579 return changed;
1580 }
1581
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001582 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001583 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001584 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001585 mWallpaperAnimLayerAdjustment = adj;
1586 int curTokenIndex = mWallpaperTokens.size();
1587 while (curTokenIndex > 0) {
1588 curTokenIndex--;
1589 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1590 int curWallpaperIndex = token.windows.size();
1591 while (curWallpaperIndex > 0) {
1592 curWallpaperIndex--;
1593 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1594 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001595 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001596 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001597 }
1598 }
1599 }
1600
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001601 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1602 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001603 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001604 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001605 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001606 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001607 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1608 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1609 changed = wallpaperWin.mXOffset != offset;
1610 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001611 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001612 + wallpaperWin + " x: " + offset);
1613 wallpaperWin.mXOffset = offset;
1614 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001615 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001616 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001617 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001618 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001619 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001620
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001621 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001622 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001623 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1624 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1625 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001626 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001627 + wallpaperWin + " y: " + offset);
1628 changed = true;
1629 wallpaperWin.mYOffset = offset;
1630 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001631 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001632 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001633 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001634 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001635 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001636
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001637 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001638 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001639 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001640 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1641 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001642 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001643 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001644 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001645 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001646 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1647 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001648 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001649 if (mWaitingOnWallpaper != null) {
1650 long start = SystemClock.uptimeMillis();
1651 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1652 < start) {
1653 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001654 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001655 "Waiting for offset complete...");
1656 mWindowMap.wait(WALLPAPER_TIMEOUT);
1657 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001658 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001659 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001660 if ((start+WALLPAPER_TIMEOUT)
1661 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001662 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001663 + wallpaperWin);
1664 mLastWallpaperTimeoutTime = start;
1665 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001666 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001667 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001668 }
1669 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001670 } catch (RemoteException e) {
1671 }
1672 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001673
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001674 return changed;
1675 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001676
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001677 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001678 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001679 if (mWaitingOnWallpaper != null &&
1680 mWaitingOnWallpaper.mClient.asBinder() == window) {
1681 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001682 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001683 }
1684 }
1685 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001686
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001687 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001688 final int dw = mDisplay.getWidth();
1689 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001690
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001691 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001692
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001693 WindowState target = mWallpaperTarget;
1694 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001695 if (target.mWallpaperX >= 0) {
1696 mLastWallpaperX = target.mWallpaperX;
1697 } else if (changingTarget.mWallpaperX >= 0) {
1698 mLastWallpaperX = changingTarget.mWallpaperX;
1699 }
1700 if (target.mWallpaperY >= 0) {
1701 mLastWallpaperY = target.mWallpaperY;
1702 } else if (changingTarget.mWallpaperY >= 0) {
1703 mLastWallpaperY = changingTarget.mWallpaperY;
1704 }
1705 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001706
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001707 int curTokenIndex = mWallpaperTokens.size();
1708 while (curTokenIndex > 0) {
1709 curTokenIndex--;
1710 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1711 int curWallpaperIndex = token.windows.size();
1712 while (curWallpaperIndex > 0) {
1713 curWallpaperIndex--;
1714 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1715 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1716 wallpaper.computeShownFrameLocked();
1717 changed = true;
1718 // We only want to be synchronous with one wallpaper.
1719 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001720 }
1721 }
1722 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001723
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001724 return changed;
1725 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001726
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001727 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001728 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001729 final int dw = mDisplay.getWidth();
1730 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001731
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001732 int curTokenIndex = mWallpaperTokens.size();
1733 while (curTokenIndex > 0) {
1734 curTokenIndex--;
1735 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001736 if (token.hidden == visible) {
1737 token.hidden = !visible;
1738 // Need to do a layout to ensure the wallpaper now has the
1739 // correct size.
1740 mLayoutNeeded = true;
1741 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001742
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001743 int curWallpaperIndex = token.windows.size();
1744 while (curWallpaperIndex > 0) {
1745 curWallpaperIndex--;
1746 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1747 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001748 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001749 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001750
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001751 if (wallpaper.mWallpaperVisible != visible) {
1752 wallpaper.mWallpaperVisible = visible;
1753 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001754 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001755 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001756 + ": " + visible);
1757 wallpaper.mClient.dispatchAppVisibility(visible);
1758 } catch (RemoteException e) {
1759 }
1760 }
1761 }
1762 }
1763 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001764
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001765 void sendPointerToWallpaperLocked(WindowState srcWin,
1766 MotionEvent pointer, long eventTime) {
1767 int curTokenIndex = mWallpaperTokens.size();
1768 while (curTokenIndex > 0) {
1769 curTokenIndex--;
1770 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1771 int curWallpaperIndex = token.windows.size();
1772 while (curWallpaperIndex > 0) {
1773 curWallpaperIndex--;
1774 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1775 if ((wallpaper.mAttrs.flags &
1776 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
1777 continue;
1778 }
1779 try {
1780 MotionEvent ev = MotionEvent.obtainNoHistory(pointer);
Dianne Hackborn6adba242009-11-10 11:10:09 -08001781 if (srcWin != null) {
1782 ev.offsetLocation(srcWin.mFrame.left-wallpaper.mFrame.left,
1783 srcWin.mFrame.top-wallpaper.mFrame.top);
1784 } else {
1785 ev.offsetLocation(-wallpaper.mFrame.left, -wallpaper.mFrame.top);
1786 }
1787 switch (pointer.getAction()) {
1788 case MotionEvent.ACTION_DOWN:
1789 mSendingPointersToWallpaper = true;
1790 break;
1791 case MotionEvent.ACTION_UP:
1792 mSendingPointersToWallpaper = false;
1793 break;
1794 }
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001795 wallpaper.mClient.dispatchPointer(ev, eventTime, false);
1796 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001797 Slog.w(TAG, "Failure sending pointer to wallpaper", e);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001798 }
1799 }
1800 }
1801 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001802
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001803 void dispatchPointerElsewhereLocked(WindowState srcWin, WindowState relWin,
1804 MotionEvent pointer, long eventTime, boolean skipped) {
1805 if (relWin != null) {
1806 mPolicy.dispatchedPointerEventLw(pointer, relWin.mFrame.left, relWin.mFrame.top);
1807 } else {
1808 mPolicy.dispatchedPointerEventLw(pointer, 0, 0);
1809 }
1810
1811 // If we sent an initial down to the wallpaper, then continue
1812 // sending events until the final up.
1813 if (mSendingPointersToWallpaper) {
1814 if (skipped) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001815 Slog.i(TAG, "Sending skipped pointer to wallpaper!");
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001816 }
1817 sendPointerToWallpaperLocked(relWin, pointer, eventTime);
1818
1819 // If we are on top of the wallpaper, then the wallpaper also
1820 // gets to see this movement.
1821 } else if (srcWin != null
1822 && pointer.getAction() == MotionEvent.ACTION_DOWN
1823 && mWallpaperTarget == srcWin
1824 && srcWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) {
1825 sendPointerToWallpaperLocked(relWin, pointer, eventTime);
1826 }
1827 }
1828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001829 public int addWindow(Session session, IWindow client,
1830 WindowManager.LayoutParams attrs, int viewVisibility,
1831 Rect outContentInsets) {
1832 int res = mPolicy.checkAddPermission(attrs);
1833 if (res != WindowManagerImpl.ADD_OKAY) {
1834 return res;
1835 }
Romain Guy06882f82009-06-10 13:36:04 -07001836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001837 boolean reportNewConfig = false;
1838 WindowState attachedWindow = null;
1839 WindowState win = null;
Romain Guy06882f82009-06-10 13:36:04 -07001840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001841 synchronized(mWindowMap) {
1842 // Instantiating a Display requires talking with the simulator,
1843 // so don't do it until we know the system is mostly up and
1844 // running.
1845 if (mDisplay == null) {
1846 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1847 mDisplay = wm.getDefaultDisplay();
Christopher Tateb696aee2010-04-02 19:08:30 -07001848 mInitialDisplayWidth = mDisplay.getWidth();
1849 mInitialDisplayHeight = mDisplay.getHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001850 mQueue.setDisplay(mDisplay);
1851 reportNewConfig = true;
1852 }
Romain Guy06882f82009-06-10 13:36:04 -07001853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001854 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001855 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001856 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1857 }
1858
1859 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001860 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001861 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001862 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001863 + attrs.token + ". Aborting.");
1864 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1865 }
1866 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1867 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001868 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001869 + attrs.token + ". Aborting.");
1870 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1871 }
1872 }
1873
1874 boolean addToken = false;
1875 WindowToken token = mTokenMap.get(attrs.token);
1876 if (token == null) {
1877 if (attrs.type >= FIRST_APPLICATION_WINDOW
1878 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001879 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001880 + attrs.token + ". Aborting.");
1881 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1882 }
1883 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001884 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001885 + attrs.token + ". Aborting.");
1886 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1887 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001888 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001889 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001890 + attrs.token + ". Aborting.");
1891 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1892 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001893 token = new WindowToken(attrs.token, -1, false);
1894 addToken = true;
1895 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1896 && attrs.type <= LAST_APPLICATION_WINDOW) {
1897 AppWindowToken atoken = token.appWindowToken;
1898 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001899 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001900 + token + ". Aborting.");
1901 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1902 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001903 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001904 + token + ". Aborting.");
1905 return WindowManagerImpl.ADD_APP_EXITING;
1906 }
1907 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1908 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001909 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001910 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1911 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1912 }
1913 } else if (attrs.type == TYPE_INPUT_METHOD) {
1914 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001915 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001916 + attrs.token + ". Aborting.");
1917 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1918 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001919 } else if (attrs.type == TYPE_WALLPAPER) {
1920 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001921 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001922 + attrs.token + ". Aborting.");
1923 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1924 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001925 }
1926
1927 win = new WindowState(session, client, token,
1928 attachedWindow, attrs, viewVisibility);
1929 if (win.mDeathRecipient == null) {
1930 // Client has apparently died, so there is no reason to
1931 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001932 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001933 + " that is dead, aborting.");
1934 return WindowManagerImpl.ADD_APP_EXITING;
1935 }
1936
1937 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001939 res = mPolicy.prepareAddWindowLw(win, attrs);
1940 if (res != WindowManagerImpl.ADD_OKAY) {
1941 return res;
1942 }
1943
1944 // From now on, no exceptions or errors allowed!
1945
1946 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001948 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001950 if (addToken) {
1951 mTokenMap.put(attrs.token, token);
1952 mTokenList.add(token);
1953 }
1954 win.attach();
1955 mWindowMap.put(client.asBinder(), win);
1956
1957 if (attrs.type == TYPE_APPLICATION_STARTING &&
1958 token.appWindowToken != null) {
1959 token.appWindowToken.startingWindow = win;
1960 }
1961
1962 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001964 if (attrs.type == TYPE_INPUT_METHOD) {
1965 mInputMethodWindow = win;
1966 addInputMethodWindowToListLocked(win);
1967 imMayMove = false;
1968 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1969 mInputMethodDialogs.add(win);
1970 addWindowToListInOrderLocked(win, true);
1971 adjustInputMethodDialogsLocked();
1972 imMayMove = false;
1973 } else {
1974 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001975 if (attrs.type == TYPE_WALLPAPER) {
1976 mLastWallpaperTimeoutTime = 0;
1977 adjustWallpaperWindowsLocked();
1978 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001979 adjustWallpaperWindowsLocked();
1980 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001981 }
Romain Guy06882f82009-06-10 13:36:04 -07001982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001983 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001985 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001987 if (mInTouchMode) {
1988 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1989 }
1990 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1991 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1992 }
Romain Guy06882f82009-06-10 13:36:04 -07001993
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001994 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001995 if (win.canReceiveKeys()) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001996 if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS))
1997 == true) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998 imMayMove = false;
1999 }
2000 }
Romain Guy06882f82009-06-10 13:36:04 -07002001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002002 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002003 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002004 }
Romain Guy06882f82009-06-10 13:36:04 -07002005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002006 assignLayersLocked();
2007 // Don't do layout here, the window must call
2008 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002010 //dump();
2011
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002012 if (focusChanged) {
2013 if (mCurrentFocus != null) {
2014 mKeyWaiter.handleNewWindowLocked(mCurrentFocus);
2015 }
2016 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002017 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002018 TAG, "New client " + client.asBinder()
2019 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002020
2021 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2022 reportNewConfig = true;
2023 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002024 }
2025
2026 // sendNewConfiguration() checks caller permissions so we must call it with
2027 // privilege. updateOrientationFromAppTokens() clears and resets the caller
2028 // identity anyway, so it's safe to just clear & restore around this whole
2029 // block.
2030 final long origId = Binder.clearCallingIdentity();
2031 if (reportNewConfig) {
2032 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002033 }
2034 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002036 return res;
2037 }
Romain Guy06882f82009-06-10 13:36:04 -07002038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002039 public void removeWindow(Session session, IWindow client) {
2040 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002041 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002042 if (win == null) {
2043 return;
2044 }
2045 removeWindowLocked(session, win);
2046 }
2047 }
Romain Guy06882f82009-06-10 13:36:04 -07002048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002049 public void removeWindowLocked(Session session, WindowState win) {
2050
Joe Onorato8a9b2202010-02-26 18:56:32 -08002051 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002052 TAG, "Remove " + win + " client="
2053 + Integer.toHexString(System.identityHashCode(
2054 win.mClient.asBinder()))
2055 + ", surface=" + win.mSurface);
2056
2057 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002058
Joe Onorato8a9b2202010-02-26 18:56:32 -08002059 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002060 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2061 + " mExiting=" + win.mExiting
2062 + " isAnimating=" + win.isAnimating()
2063 + " app-animation="
2064 + (win.mAppToken != null ? win.mAppToken.animation : null)
2065 + " inPendingTransaction="
2066 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2067 + " mDisplayFrozen=" + mDisplayFrozen);
2068 // Visibility of the removed window. Will be used later to update orientation later on.
2069 boolean wasVisible = false;
2070 // First, see if we need to run an animation. If we do, we have
2071 // to hold off on removing the window until the animation is done.
2072 // If the display is frozen, just remove immediately, since the
2073 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002074 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002075 // If we are not currently running the exit animation, we
2076 // need to see about starting one.
2077 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002079 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2080 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2081 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2082 }
2083 // Try starting an animation.
2084 if (applyAnimationLocked(win, transit, false)) {
2085 win.mExiting = true;
2086 }
2087 }
2088 if (win.mExiting || win.isAnimating()) {
2089 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002090 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002091 win.mExiting = true;
2092 win.mRemoveOnExit = true;
2093 mLayoutNeeded = true;
2094 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2095 performLayoutAndPlaceSurfacesLocked();
2096 if (win.mAppToken != null) {
2097 win.mAppToken.updateReportedVisibilityLocked();
2098 }
2099 //dump();
2100 Binder.restoreCallingIdentity(origId);
2101 return;
2102 }
2103 }
2104
2105 removeWindowInnerLocked(session, win);
2106 // Removing a visible window will effect the computed orientation
2107 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002108 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002109 != mForcedAppOrientation
2110 && updateOrientationFromAppTokensLocked()) {
2111 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002112 }
2113 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2114 Binder.restoreCallingIdentity(origId);
2115 }
Romain Guy06882f82009-06-10 13:36:04 -07002116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002117 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07002118 mKeyWaiter.finishedKey(session, win.mClient, true,
2119 KeyWaiter.RETURN_NOTHING);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002120 mKeyWaiter.releasePendingPointerLocked(win.mSession);
2121 mKeyWaiter.releasePendingTrackballLocked(win.mSession);
Romain Guy06882f82009-06-10 13:36:04 -07002122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002123 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002125 if (mInputMethodTarget == win) {
2126 moveInputMethodWindowsIfNeededLocked(false);
2127 }
Romain Guy06882f82009-06-10 13:36:04 -07002128
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002129 if (false) {
2130 RuntimeException e = new RuntimeException("here");
2131 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002132 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002133 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002135 mPolicy.removeWindowLw(win);
2136 win.removeLocked();
2137
2138 mWindowMap.remove(win.mClient.asBinder());
2139 mWindows.remove(win);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002140 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002141
2142 if (mInputMethodWindow == win) {
2143 mInputMethodWindow = null;
2144 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2145 mInputMethodDialogs.remove(win);
2146 }
Romain Guy06882f82009-06-10 13:36:04 -07002147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002148 final WindowToken token = win.mToken;
2149 final AppWindowToken atoken = win.mAppToken;
2150 token.windows.remove(win);
2151 if (atoken != null) {
2152 atoken.allAppWindows.remove(win);
2153 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002154 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002155 TAG, "**** Removing window " + win + ": count="
2156 + token.windows.size());
2157 if (token.windows.size() == 0) {
2158 if (!token.explicit) {
2159 mTokenMap.remove(token.token);
2160 mTokenList.remove(token);
2161 } else if (atoken != null) {
2162 atoken.firstWindowDrawn = false;
2163 }
2164 }
2165
2166 if (atoken != null) {
2167 if (atoken.startingWindow == win) {
2168 atoken.startingWindow = null;
2169 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2170 // If this is the last window and we had requested a starting
2171 // transition window, well there is no point now.
2172 atoken.startingData = null;
2173 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2174 // If this is the last window except for a starting transition
2175 // window, we need to get rid of the starting transition.
2176 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002177 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002178 + ": no more real windows");
2179 }
2180 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2181 mH.sendMessage(m);
2182 }
2183 }
Romain Guy06882f82009-06-10 13:36:04 -07002184
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002185 if (win.mAttrs.type == TYPE_WALLPAPER) {
2186 mLastWallpaperTimeoutTime = 0;
2187 adjustWallpaperWindowsLocked();
2188 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002189 adjustWallpaperWindowsLocked();
2190 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002192 if (!mInLayout) {
2193 assignLayersLocked();
2194 mLayoutNeeded = true;
2195 performLayoutAndPlaceSurfacesLocked();
2196 if (win.mAppToken != null) {
2197 win.mAppToken.updateReportedVisibilityLocked();
2198 }
2199 }
2200 }
2201
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002202 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2203 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2204 + ": " + msg + " / " + w.mAttrs.getTitle();
2205 if (where != null) {
2206 Slog.i(TAG, str, where);
2207 } else {
2208 Slog.i(TAG, str);
2209 }
2210 }
2211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002212 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2213 long origId = Binder.clearCallingIdentity();
2214 try {
2215 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002216 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002217 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002218 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002219 Surface.openTransaction();
2220 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002221 if (SHOW_TRANSACTIONS) logSurface(w,
2222 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002223 w.mSurface.setTransparentRegionHint(region);
2224 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002225 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002226 Surface.closeTransaction();
2227 }
2228 }
2229 }
2230 } finally {
2231 Binder.restoreCallingIdentity(origId);
2232 }
2233 }
2234
2235 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002236 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002237 Rect visibleInsets) {
2238 long origId = Binder.clearCallingIdentity();
2239 try {
2240 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002241 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002242 if (w != null) {
2243 w.mGivenInsetsPending = false;
2244 w.mGivenContentInsets.set(contentInsets);
2245 w.mGivenVisibleInsets.set(visibleInsets);
2246 w.mTouchableInsets = touchableInsets;
2247 mLayoutNeeded = true;
2248 performLayoutAndPlaceSurfacesLocked();
2249 }
2250 }
2251 } finally {
2252 Binder.restoreCallingIdentity(origId);
2253 }
2254 }
Romain Guy06882f82009-06-10 13:36:04 -07002255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002256 public void getWindowDisplayFrame(Session session, IWindow client,
2257 Rect outDisplayFrame) {
2258 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002259 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002260 if (win == null) {
2261 outDisplayFrame.setEmpty();
2262 return;
2263 }
2264 outDisplayFrame.set(win.mDisplayFrame);
2265 }
2266 }
2267
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002268 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2269 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002270 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2271 window.mWallpaperX = x;
2272 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002273 window.mWallpaperXStep = xStep;
2274 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002275 if (updateWallpaperOffsetLocked(window, true)) {
2276 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002277 }
2278 }
2279 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002280
Dianne Hackborn75804932009-10-20 20:15:20 -07002281 void wallpaperCommandComplete(IBinder window, Bundle result) {
2282 synchronized (mWindowMap) {
2283 if (mWaitingOnWallpaper != null &&
2284 mWaitingOnWallpaper.mClient.asBinder() == window) {
2285 mWaitingOnWallpaper = null;
2286 mWindowMap.notifyAll();
2287 }
2288 }
2289 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002290
Dianne Hackborn75804932009-10-20 20:15:20 -07002291 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2292 String action, int x, int y, int z, Bundle extras, boolean sync) {
2293 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2294 || window == mUpperWallpaperTarget) {
2295 boolean doWait = sync;
2296 int curTokenIndex = mWallpaperTokens.size();
2297 while (curTokenIndex > 0) {
2298 curTokenIndex--;
2299 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2300 int curWallpaperIndex = token.windows.size();
2301 while (curWallpaperIndex > 0) {
2302 curWallpaperIndex--;
2303 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2304 try {
2305 wallpaper.mClient.dispatchWallpaperCommand(action,
2306 x, y, z, extras, sync);
2307 // We only want to be synchronous with one wallpaper.
2308 sync = false;
2309 } catch (RemoteException e) {
2310 }
2311 }
2312 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002313
Dianne Hackborn75804932009-10-20 20:15:20 -07002314 if (doWait) {
2315 // XXX Need to wait for result.
2316 }
2317 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002318
Dianne Hackborn75804932009-10-20 20:15:20 -07002319 return null;
2320 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002322 public int relayoutWindow(Session session, IWindow client,
2323 WindowManager.LayoutParams attrs, int requestedWidth,
2324 int requestedHeight, int viewVisibility, boolean insetsPending,
2325 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002326 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002327 boolean displayed = false;
2328 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002329 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002330 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002332 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002333 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002334 if (win == null) {
2335 return 0;
2336 }
2337 win.mRequestedWidth = requestedWidth;
2338 win.mRequestedHeight = requestedHeight;
2339
2340 if (attrs != null) {
2341 mPolicy.adjustWindowParamsLw(attrs);
2342 }
Romain Guy06882f82009-06-10 13:36:04 -07002343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002344 int attrChanges = 0;
2345 int flagChanges = 0;
2346 if (attrs != null) {
2347 flagChanges = win.mAttrs.flags ^= attrs.flags;
2348 attrChanges = win.mAttrs.copyFrom(attrs);
2349 }
2350
Joe Onorato8a9b2202010-02-26 18:56:32 -08002351 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002352
2353 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2354 win.mAlpha = attrs.alpha;
2355 }
2356
2357 final boolean scaledWindow =
2358 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2359
2360 if (scaledWindow) {
2361 // requested{Width|Height} Surface's physical size
2362 // attrs.{width|height} Size on screen
2363 win.mHScale = (attrs.width != requestedWidth) ?
2364 (attrs.width / (float)requestedWidth) : 1.0f;
2365 win.mVScale = (attrs.height != requestedHeight) ?
2366 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002367 } else {
2368 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002369 }
2370
2371 boolean imMayMove = (flagChanges&(
2372 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2373 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002375 boolean focusMayChange = win.mViewVisibility != viewVisibility
2376 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2377 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002378
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002379 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2380 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002382 win.mRelayoutCalled = true;
2383 final int oldVisibility = win.mViewVisibility;
2384 win.mViewVisibility = viewVisibility;
2385 if (viewVisibility == View.VISIBLE &&
2386 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2387 displayed = !win.isVisibleLw();
2388 if (win.mExiting) {
2389 win.mExiting = false;
2390 win.mAnimation = null;
2391 }
2392 if (win.mDestroying) {
2393 win.mDestroying = false;
2394 mDestroySurface.remove(win);
2395 }
2396 if (oldVisibility == View.GONE) {
2397 win.mEnterAnimationPending = true;
2398 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002399 if (displayed) {
2400 if (win.mSurface != null && !win.mDrawPending
2401 && !win.mCommitDrawPending && !mDisplayFrozen
2402 && mPolicy.isScreenOn()) {
2403 applyEnterAnimationLocked(win);
2404 }
2405 if ((win.mAttrs.flags
2406 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2407 if (DEBUG_VISIBILITY) Slog.v(TAG,
2408 "Relayout window turning screen on: " + win);
2409 win.mTurnOnScreen = true;
2410 }
2411 int diff = 0;
2412 if (win.mConfiguration != mCurConfiguration
2413 && (win.mConfiguration == null
2414 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2415 win.mConfiguration = mCurConfiguration;
2416 if (DEBUG_CONFIGURATION) {
2417 Slog.i(TAG, "Window " + win + " visible with new config: "
2418 + win.mConfiguration + " / 0x"
2419 + Integer.toHexString(diff));
2420 }
2421 outConfig.setTo(mCurConfiguration);
2422 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002423 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002424 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2425 // To change the format, we need to re-build the surface.
2426 win.destroySurfaceLocked();
2427 displayed = true;
2428 }
2429 try {
2430 Surface surface = win.createSurfaceLocked();
2431 if (surface != null) {
2432 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002433 win.mReportDestroySurface = false;
2434 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002435 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002436 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002437 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002438 // For some reason there isn't a surface. Clear the
2439 // caller's object so they see the same state.
2440 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002441 }
2442 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002443 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002444 + client + " (" + win.mAttrs.getTitle() + ")",
2445 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002446 Binder.restoreCallingIdentity(origId);
2447 return 0;
2448 }
2449 if (displayed) {
2450 focusMayChange = true;
2451 }
2452 if (win.mAttrs.type == TYPE_INPUT_METHOD
2453 && mInputMethodWindow == null) {
2454 mInputMethodWindow = win;
2455 imMayMove = true;
2456 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002457 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2458 && win.mAppToken != null
2459 && win.mAppToken.startingWindow != null) {
2460 // Special handling of starting window over the base
2461 // window of the app: propagate lock screen flags to it,
2462 // to provide the correct semantics while starting.
2463 final int mask =
2464 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002465 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2466 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002467 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2468 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2469 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002470 } else {
2471 win.mEnterAnimationPending = false;
2472 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002473 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002474 + ": mExiting=" + win.mExiting
2475 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002476 // If we are not currently running the exit animation, we
2477 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002478 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002479 // Try starting an animation; if there isn't one, we
2480 // can destroy the surface right away.
2481 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2482 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2483 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2484 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002485 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002486 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002487 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002488 win.mExiting = true;
2489 mKeyWaiter.finishedKey(session, client, true,
2490 KeyWaiter.RETURN_NOTHING);
2491 } else if (win.isAnimating()) {
2492 // Currently in a hide animation... turn this into
2493 // an exit.
2494 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002495 } else if (win == mWallpaperTarget) {
2496 // If the wallpaper is currently behind this
2497 // window, we need to change both of them inside
2498 // of a transaction to avoid artifacts.
2499 win.mExiting = true;
2500 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002501 } else {
2502 if (mInputMethodWindow == win) {
2503 mInputMethodWindow = null;
2504 }
2505 win.destroySurfaceLocked();
2506 }
2507 }
2508 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002509
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002510 if (win.mSurface == null || (win.getAttrs().flags
2511 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2512 || win.mSurfacePendingDestroy) {
2513 // We are being called from a local process, which
2514 // means outSurface holds its current surface. Ensure the
2515 // surface object is cleared, but we don't want it actually
2516 // destroyed at this point.
2517 win.mSurfacePendingDestroy = false;
2518 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002519 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002520 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002521 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002522 "Keeping surface, will report destroy: " + win);
2523 win.mReportDestroySurface = true;
2524 outSurface.copyFrom(win.mSurface);
2525 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002526 }
2527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002528 if (focusMayChange) {
2529 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2530 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 imMayMove = false;
2532 }
2533 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2534 }
Romain Guy06882f82009-06-10 13:36:04 -07002535
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002536 // updateFocusedWindowLocked() already assigned layers so we only need to
2537 // reassign them at this point if the IM window state gets shuffled
2538 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002540 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002541 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2542 // Little hack here -- we -should- be able to rely on the
2543 // function to return true if the IME has moved and needs
2544 // its layer recomputed. However, if the IME was hidden
2545 // and isn't actually moved in the list, its layer may be
2546 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 assignLayers = true;
2548 }
2549 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002550 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002551 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002552 assignLayers = true;
2553 }
2554 }
Romain Guy06882f82009-06-10 13:36:04 -07002555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002556 mLayoutNeeded = true;
2557 win.mGivenInsetsPending = insetsPending;
2558 if (assignLayers) {
2559 assignLayersLocked();
2560 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002561 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002562 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002563 if (displayed && win.mIsWallpaper) {
2564 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002565 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002566 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002567 if (win.mAppToken != null) {
2568 win.mAppToken.updateReportedVisibilityLocked();
2569 }
2570 outFrame.set(win.mFrame);
2571 outContentInsets.set(win.mContentInsets);
2572 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002573 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002574 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002575 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002576 + ", requestedHeight=" + requestedHeight
2577 + ", viewVisibility=" + viewVisibility
2578 + "\nRelayout returning frame=" + outFrame
2579 + ", surface=" + outSurface);
2580
Joe Onorato8a9b2202010-02-26 18:56:32 -08002581 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002582 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2583
2584 inTouchMode = mInTouchMode;
2585 }
2586
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002587 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002588 sendNewConfiguration();
2589 }
Romain Guy06882f82009-06-10 13:36:04 -07002590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002591 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002593 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2594 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2595 }
2596
2597 public void finishDrawingWindow(Session session, IWindow client) {
2598 final long origId = Binder.clearCallingIdentity();
2599 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002600 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002601 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002602 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2603 adjustWallpaperWindowsLocked();
2604 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002605 mLayoutNeeded = true;
2606 performLayoutAndPlaceSurfacesLocked();
2607 }
2608 }
2609 Binder.restoreCallingIdentity(origId);
2610 }
2611
2612 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002613 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002614 + (lp != null ? lp.packageName : null)
2615 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2616 if (lp != null && lp.windowAnimations != 0) {
2617 // If this is a system resource, don't try to load it from the
2618 // application resources. It is nice to avoid loading application
2619 // resources if we can.
2620 String packageName = lp.packageName != null ? lp.packageName : "android";
2621 int resId = lp.windowAnimations;
2622 if ((resId&0xFF000000) == 0x01000000) {
2623 packageName = "android";
2624 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002625 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002626 + packageName);
2627 return AttributeCache.instance().get(packageName, resId,
2628 com.android.internal.R.styleable.WindowAnimation);
2629 }
2630 return null;
2631 }
Romain Guy06882f82009-06-10 13:36:04 -07002632
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002633 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002634 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002635 + packageName + " resId=0x" + Integer.toHexString(resId));
2636 if (packageName != null) {
2637 if ((resId&0xFF000000) == 0x01000000) {
2638 packageName = "android";
2639 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002640 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002641 + packageName);
2642 return AttributeCache.instance().get(packageName, resId,
2643 com.android.internal.R.styleable.WindowAnimation);
2644 }
2645 return null;
2646 }
2647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002648 private void applyEnterAnimationLocked(WindowState win) {
2649 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2650 if (win.mEnterAnimationPending) {
2651 win.mEnterAnimationPending = false;
2652 transit = WindowManagerPolicy.TRANSIT_ENTER;
2653 }
2654
2655 applyAnimationLocked(win, transit, true);
2656 }
2657
2658 private boolean applyAnimationLocked(WindowState win,
2659 int transit, boolean isEntrance) {
2660 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2661 // If we are trying to apply an animation, but already running
2662 // an animation of the same type, then just leave that one alone.
2663 return true;
2664 }
Romain Guy06882f82009-06-10 13:36:04 -07002665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002666 // Only apply an animation if the display isn't frozen. If it is
2667 // frozen, there is no reason to animate and it can cause strange
2668 // artifacts when we unfreeze the display if some different animation
2669 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002670 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002671 int anim = mPolicy.selectAnimationLw(win, transit);
2672 int attr = -1;
2673 Animation a = null;
2674 if (anim != 0) {
2675 a = AnimationUtils.loadAnimation(mContext, anim);
2676 } else {
2677 switch (transit) {
2678 case WindowManagerPolicy.TRANSIT_ENTER:
2679 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2680 break;
2681 case WindowManagerPolicy.TRANSIT_EXIT:
2682 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2683 break;
2684 case WindowManagerPolicy.TRANSIT_SHOW:
2685 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2686 break;
2687 case WindowManagerPolicy.TRANSIT_HIDE:
2688 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2689 break;
2690 }
2691 if (attr >= 0) {
2692 a = loadAnimation(win.mAttrs, attr);
2693 }
2694 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002695 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002696 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2697 + " mAnimation=" + win.mAnimation
2698 + " isEntrance=" + isEntrance);
2699 if (a != null) {
2700 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002701 RuntimeException e = null;
2702 if (!HIDE_STACK_CRAWLS) {
2703 e = new RuntimeException();
2704 e.fillInStackTrace();
2705 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002706 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002707 }
2708 win.setAnimation(a);
2709 win.mAnimationIsEntrance = isEntrance;
2710 }
2711 } else {
2712 win.clearAnimation();
2713 }
2714
2715 return win.mAnimation != null;
2716 }
2717
2718 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2719 int anim = 0;
2720 Context context = mContext;
2721 if (animAttr >= 0) {
2722 AttributeCache.Entry ent = getCachedAnimations(lp);
2723 if (ent != null) {
2724 context = ent.context;
2725 anim = ent.array.getResourceId(animAttr, 0);
2726 }
2727 }
2728 if (anim != 0) {
2729 return AnimationUtils.loadAnimation(context, anim);
2730 }
2731 return null;
2732 }
Romain Guy06882f82009-06-10 13:36:04 -07002733
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002734 private Animation loadAnimation(String packageName, int resId) {
2735 int anim = 0;
2736 Context context = mContext;
2737 if (resId >= 0) {
2738 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2739 if (ent != null) {
2740 context = ent.context;
2741 anim = resId;
2742 }
2743 }
2744 if (anim != 0) {
2745 return AnimationUtils.loadAnimation(context, anim);
2746 }
2747 return null;
2748 }
2749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002750 private boolean applyAnimationLocked(AppWindowToken wtoken,
2751 WindowManager.LayoutParams lp, int transit, boolean enter) {
2752 // Only apply an animation if the display isn't frozen. If it is
2753 // frozen, there is no reason to animate and it can cause strange
2754 // artifacts when we unfreeze the display if some different animation
2755 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002756 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002757 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002758 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002759 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002760 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002761 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002762 } else if (mNextAppTransitionPackage != null) {
2763 a = loadAnimation(mNextAppTransitionPackage, enter ?
2764 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002765 } else {
2766 int animAttr = 0;
2767 switch (transit) {
2768 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2769 animAttr = enter
2770 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2771 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2772 break;
2773 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2774 animAttr = enter
2775 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2776 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2777 break;
2778 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2779 animAttr = enter
2780 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2781 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2782 break;
2783 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2784 animAttr = enter
2785 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2786 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2787 break;
2788 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2789 animAttr = enter
2790 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2791 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2792 break;
2793 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2794 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002795 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002796 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2797 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002798 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002799 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002800 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2801 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002802 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002803 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002804 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002805 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2806 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2807 break;
2808 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2809 animAttr = enter
2810 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2811 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2812 break;
2813 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2814 animAttr = enter
2815 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2816 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002817 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002818 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002819 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002820 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002821 + " anim=" + a
2822 + " animAttr=0x" + Integer.toHexString(animAttr)
2823 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002824 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002825 if (a != null) {
2826 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002827 RuntimeException e = null;
2828 if (!HIDE_STACK_CRAWLS) {
2829 e = new RuntimeException();
2830 e.fillInStackTrace();
2831 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002832 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002833 }
2834 wtoken.setAnimation(a);
2835 }
2836 } else {
2837 wtoken.clearAnimation();
2838 }
2839
2840 return wtoken.animation != null;
2841 }
2842
2843 // -------------------------------------------------------------
2844 // Application Window Tokens
2845 // -------------------------------------------------------------
2846
2847 public void validateAppTokens(List tokens) {
2848 int v = tokens.size()-1;
2849 int m = mAppTokens.size()-1;
2850 while (v >= 0 && m >= 0) {
2851 AppWindowToken wtoken = mAppTokens.get(m);
2852 if (wtoken.removed) {
2853 m--;
2854 continue;
2855 }
2856 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002857 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002858 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2859 }
2860 v--;
2861 m--;
2862 }
2863 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002864 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002865 v--;
2866 }
2867 while (m >= 0) {
2868 AppWindowToken wtoken = mAppTokens.get(m);
2869 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002870 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002871 }
2872 m--;
2873 }
2874 }
2875
2876 boolean checkCallingPermission(String permission, String func) {
2877 // Quick check: if the calling permission is me, it's all okay.
2878 if (Binder.getCallingPid() == Process.myPid()) {
2879 return true;
2880 }
Romain Guy06882f82009-06-10 13:36:04 -07002881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002882 if (mContext.checkCallingPermission(permission)
2883 == PackageManager.PERMISSION_GRANTED) {
2884 return true;
2885 }
2886 String msg = "Permission Denial: " + func + " from pid="
2887 + Binder.getCallingPid()
2888 + ", uid=" + Binder.getCallingUid()
2889 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002890 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002891 return false;
2892 }
Romain Guy06882f82009-06-10 13:36:04 -07002893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002894 AppWindowToken findAppWindowToken(IBinder token) {
2895 WindowToken wtoken = mTokenMap.get(token);
2896 if (wtoken == null) {
2897 return null;
2898 }
2899 return wtoken.appWindowToken;
2900 }
Romain Guy06882f82009-06-10 13:36:04 -07002901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002902 public void addWindowToken(IBinder token, int type) {
2903 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2904 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002905 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002906 }
Romain Guy06882f82009-06-10 13:36:04 -07002907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002908 synchronized(mWindowMap) {
2909 WindowToken wtoken = mTokenMap.get(token);
2910 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002911 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 return;
2913 }
2914 wtoken = new WindowToken(token, type, true);
2915 mTokenMap.put(token, wtoken);
2916 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002917 if (type == TYPE_WALLPAPER) {
2918 mWallpaperTokens.add(wtoken);
2919 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920 }
2921 }
Romain Guy06882f82009-06-10 13:36:04 -07002922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002923 public void removeWindowToken(IBinder token) {
2924 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2925 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002926 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002927 }
2928
2929 final long origId = Binder.clearCallingIdentity();
2930 synchronized(mWindowMap) {
2931 WindowToken wtoken = mTokenMap.remove(token);
2932 mTokenList.remove(wtoken);
2933 if (wtoken != null) {
2934 boolean delayed = false;
2935 if (!wtoken.hidden) {
2936 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002938 final int N = wtoken.windows.size();
2939 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002941 for (int i=0; i<N; i++) {
2942 WindowState win = wtoken.windows.get(i);
2943
2944 if (win.isAnimating()) {
2945 delayed = true;
2946 }
Romain Guy06882f82009-06-10 13:36:04 -07002947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002948 if (win.isVisibleNow()) {
2949 applyAnimationLocked(win,
2950 WindowManagerPolicy.TRANSIT_EXIT, false);
2951 mKeyWaiter.finishedKey(win.mSession, win.mClient, true,
2952 KeyWaiter.RETURN_NOTHING);
2953 changed = true;
2954 }
2955 }
2956
2957 if (changed) {
2958 mLayoutNeeded = true;
2959 performLayoutAndPlaceSurfacesLocked();
2960 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2961 }
Romain Guy06882f82009-06-10 13:36:04 -07002962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002963 if (delayed) {
2964 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002965 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2966 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002967 }
2968 }
Romain Guy06882f82009-06-10 13:36:04 -07002969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002970 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002971 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002972 }
2973 }
2974 Binder.restoreCallingIdentity(origId);
2975 }
2976
2977 public void addAppToken(int addPos, IApplicationToken token,
2978 int groupId, int requestedOrientation, boolean fullscreen) {
2979 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2980 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002981 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002982 }
Romain Guy06882f82009-06-10 13:36:04 -07002983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002984 synchronized(mWindowMap) {
2985 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2986 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002987 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002988 return;
2989 }
2990 wtoken = new AppWindowToken(token);
2991 wtoken.groupId = groupId;
2992 wtoken.appFullscreen = fullscreen;
2993 wtoken.requestedOrientation = requestedOrientation;
2994 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002995 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002996 mTokenMap.put(token.asBinder(), wtoken);
2997 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999 // Application tokens start out hidden.
3000 wtoken.hidden = true;
3001 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003003 //dump();
3004 }
3005 }
Romain Guy06882f82009-06-10 13:36:04 -07003006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003007 public void setAppGroupId(IBinder token, int groupId) {
3008 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3009 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003010 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003011 }
3012
3013 synchronized(mWindowMap) {
3014 AppWindowToken wtoken = findAppWindowToken(token);
3015 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003016 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003017 return;
3018 }
3019 wtoken.groupId = groupId;
3020 }
3021 }
Romain Guy06882f82009-06-10 13:36:04 -07003022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003023 public int getOrientationFromWindowsLocked() {
3024 int pos = mWindows.size() - 1;
3025 while (pos >= 0) {
3026 WindowState wtoken = (WindowState) mWindows.get(pos);
3027 pos--;
3028 if (wtoken.mAppToken != null) {
3029 // We hit an application window. so the orientation will be determined by the
3030 // app window. No point in continuing further.
3031 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3032 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003033 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003034 continue;
3035 }
3036 int req = wtoken.mAttrs.screenOrientation;
3037 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3038 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3039 continue;
3040 } else {
3041 return req;
3042 }
3043 }
3044 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3045 }
Romain Guy06882f82009-06-10 13:36:04 -07003046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003047 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003048 int pos = mAppTokens.size() - 1;
3049 int curGroup = 0;
3050 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3051 boolean findingBehind = false;
3052 boolean haveGroup = false;
3053 boolean lastFullscreen = false;
3054 while (pos >= 0) {
3055 AppWindowToken wtoken = mAppTokens.get(pos);
3056 pos--;
3057 // if we're about to tear down this window and not seek for
3058 // the behind activity, don't use it for orientation
3059 if (!findingBehind
3060 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3061 continue;
3062 }
3063
3064 if (!haveGroup) {
3065 // We ignore any hidden applications on the top.
3066 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003067 continue;
3068 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003069 haveGroup = true;
3070 curGroup = wtoken.groupId;
3071 lastOrientation = wtoken.requestedOrientation;
3072 } else if (curGroup != wtoken.groupId) {
3073 // If we have hit a new application group, and the bottom
3074 // of the previous group didn't explicitly say to use
3075 // the orientation behind it, and the last app was
3076 // full screen, then we'll stick with the
3077 // user's orientation.
3078 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3079 && lastFullscreen) {
3080 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003081 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003082 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003083 int or = wtoken.requestedOrientation;
3084 // If this application is fullscreen, and didn't explicitly say
3085 // to use the orientation behind it, then just take whatever
3086 // orientation it has and ignores whatever is under it.
3087 lastFullscreen = wtoken.appFullscreen;
3088 if (lastFullscreen
3089 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3090 return or;
3091 }
3092 // If this application has requested an explicit orientation,
3093 // then use it.
3094 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3095 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3096 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3097 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3098 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3099 return or;
3100 }
3101 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3102 }
3103 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003104 }
Romain Guy06882f82009-06-10 13:36:04 -07003105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003106 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003107 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003108 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3109 "updateOrientationFromAppTokens()")) {
3110 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3111 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003112
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003113 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003114 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003115
3116 synchronized(mWindowMap) {
3117 if (updateOrientationFromAppTokensLocked()) {
3118 if (freezeThisOneIfNeeded != null) {
3119 AppWindowToken wtoken = findAppWindowToken(
3120 freezeThisOneIfNeeded);
3121 if (wtoken != null) {
3122 startAppFreezingScreenLocked(wtoken,
3123 ActivityInfo.CONFIG_ORIENTATION);
3124 }
3125 }
3126 config = computeNewConfigurationLocked();
3127
3128 } else if (currentConfig != null) {
3129 // No obvious action we need to take, but if our current
3130 // state mismatches the activity maanager's, update it
3131 mTempConfiguration.setToDefaults();
3132 if (computeNewConfigurationLocked(mTempConfiguration)) {
3133 if (currentConfig.diff(mTempConfiguration) != 0) {
3134 mWaitingForConfig = true;
3135 mLayoutNeeded = true;
3136 startFreezingDisplayLocked();
3137 config = new Configuration(mTempConfiguration);
3138 }
3139 }
3140 }
3141 }
3142
Dianne Hackborncfaef692009-06-15 14:24:44 -07003143 Binder.restoreCallingIdentity(ident);
3144 return config;
3145 }
3146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003147 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003148 * Determine the new desired orientation of the display, returning
3149 * a non-null new Configuration if it has changed from the current
3150 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3151 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3152 * SCREEN. This will typically be done for you if you call
3153 * sendNewConfiguration().
3154 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003155 * The orientation is computed from non-application windows first. If none of
3156 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003157 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003158 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3159 * android.os.IBinder)
3160 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003161 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003162 if (mDisplayFrozen) {
3163 // If the display is frozen, some activities may be in the middle
3164 // of restarting, and thus have removed their old window. If the
3165 // window has the flag to hide the lock screen, then the lock screen
3166 // can re-appear and inflict its own orientation on us. Keep the
3167 // orientation stable until this all settles down.
3168 return false;
3169 }
3170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003171 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003172 long ident = Binder.clearCallingIdentity();
3173 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003174 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003176 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003177 mForcedAppOrientation = req;
3178 //send a message to Policy indicating orientation change to take
3179 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003180 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003181 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3182 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3183 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003184 }
3185 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003186
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003187 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003188 } finally {
3189 Binder.restoreCallingIdentity(ident);
3190 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003191 }
Romain Guy06882f82009-06-10 13:36:04 -07003192
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003193 int computeForcedAppOrientationLocked() {
3194 int req = getOrientationFromWindowsLocked();
3195 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3196 req = getOrientationFromAppTokensLocked();
3197 }
3198 return req;
3199 }
Romain Guy06882f82009-06-10 13:36:04 -07003200
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003201 public void setNewConfiguration(Configuration config) {
3202 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3203 "setNewConfiguration()")) {
3204 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3205 }
3206
3207 synchronized(mWindowMap) {
3208 mCurConfiguration = new Configuration(config);
3209 mWaitingForConfig = false;
3210 performLayoutAndPlaceSurfacesLocked();
3211 }
3212 }
3213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003214 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3215 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3216 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003217 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003218 }
Romain Guy06882f82009-06-10 13:36:04 -07003219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003220 synchronized(mWindowMap) {
3221 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3222 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003223 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003224 return;
3225 }
Romain Guy06882f82009-06-10 13:36:04 -07003226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003227 wtoken.requestedOrientation = requestedOrientation;
3228 }
3229 }
Romain Guy06882f82009-06-10 13:36:04 -07003230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003231 public int getAppOrientation(IApplicationToken token) {
3232 synchronized(mWindowMap) {
3233 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3234 if (wtoken == null) {
3235 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3236 }
Romain Guy06882f82009-06-10 13:36:04 -07003237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003238 return wtoken.requestedOrientation;
3239 }
3240 }
Romain Guy06882f82009-06-10 13:36:04 -07003241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003242 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3243 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3244 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003245 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003246 }
3247
3248 synchronized(mWindowMap) {
3249 boolean changed = false;
3250 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003251 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003252 changed = mFocusedApp != null;
3253 mFocusedApp = null;
3254 mKeyWaiter.tickle();
3255 } else {
3256 AppWindowToken newFocus = findAppWindowToken(token);
3257 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003258 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003259 return;
3260 }
3261 changed = mFocusedApp != newFocus;
3262 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003263 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003264 mKeyWaiter.tickle();
3265 }
3266
3267 if (moveFocusNow && changed) {
3268 final long origId = Binder.clearCallingIdentity();
3269 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3270 Binder.restoreCallingIdentity(origId);
3271 }
3272 }
3273 }
3274
3275 public void prepareAppTransition(int transit) {
3276 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3277 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003278 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003279 }
Romain Guy06882f82009-06-10 13:36:04 -07003280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003281 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003282 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003283 TAG, "Prepare app transition: transit=" + transit
3284 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003285 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003286 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3287 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003288 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003289 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3290 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3291 // Opening a new task always supersedes a close for the anim.
3292 mNextAppTransition = transit;
3293 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3294 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3295 // Opening a new activity always supersedes a close for the anim.
3296 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003297 }
3298 mAppTransitionReady = false;
3299 mAppTransitionTimeout = false;
3300 mStartingIconInTransition = false;
3301 mSkipAppTransitionAnimation = false;
3302 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3303 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3304 5000);
3305 }
3306 }
3307 }
3308
3309 public int getPendingAppTransition() {
3310 return mNextAppTransition;
3311 }
Romain Guy06882f82009-06-10 13:36:04 -07003312
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003313 public void overridePendingAppTransition(String packageName,
3314 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003315 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003316 mNextAppTransitionPackage = packageName;
3317 mNextAppTransitionEnter = enterAnim;
3318 mNextAppTransitionExit = exitAnim;
3319 }
3320 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003322 public void executeAppTransition() {
3323 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3324 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003325 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003326 }
Romain Guy06882f82009-06-10 13:36:04 -07003327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003328 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003329 if (DEBUG_APP_TRANSITIONS) {
3330 RuntimeException e = new RuntimeException("here");
3331 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003332 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003333 + mNextAppTransition, e);
3334 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003335 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003336 mAppTransitionReady = true;
3337 final long origId = Binder.clearCallingIdentity();
3338 performLayoutAndPlaceSurfacesLocked();
3339 Binder.restoreCallingIdentity(origId);
3340 }
3341 }
3342 }
3343
3344 public void setAppStartingWindow(IBinder token, String pkg,
3345 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3346 IBinder transferFrom, boolean createIfNeeded) {
3347 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3348 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003349 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003350 }
3351
3352 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003353 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003354 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3355 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003357 AppWindowToken wtoken = findAppWindowToken(token);
3358 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003359 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003360 return;
3361 }
3362
3363 // If the display is frozen, we won't do anything until the
3364 // actual window is displayed so there is no reason to put in
3365 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003366 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003367 return;
3368 }
Romain Guy06882f82009-06-10 13:36:04 -07003369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003370 if (wtoken.startingData != null) {
3371 return;
3372 }
Romain Guy06882f82009-06-10 13:36:04 -07003373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003374 if (transferFrom != null) {
3375 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3376 if (ttoken != null) {
3377 WindowState startingWindow = ttoken.startingWindow;
3378 if (startingWindow != null) {
3379 if (mStartingIconInTransition) {
3380 // In this case, the starting icon has already
3381 // been displayed, so start letting windows get
3382 // shown immediately without any more transitions.
3383 mSkipAppTransitionAnimation = true;
3384 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003385 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003386 "Moving existing starting from " + ttoken
3387 + " to " + wtoken);
3388 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003390 // Transfer the starting window over to the new
3391 // token.
3392 wtoken.startingData = ttoken.startingData;
3393 wtoken.startingView = ttoken.startingView;
3394 wtoken.startingWindow = startingWindow;
3395 ttoken.startingData = null;
3396 ttoken.startingView = null;
3397 ttoken.startingWindow = null;
3398 ttoken.startingMoved = true;
3399 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003400 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003401 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003402 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003403 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003404 mWindows.remove(startingWindow);
3405 ttoken.windows.remove(startingWindow);
3406 ttoken.allAppWindows.remove(startingWindow);
3407 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003409 // Propagate other interesting state between the
3410 // tokens. If the old token is displayed, we should
3411 // immediately force the new one to be displayed. If
3412 // it is animating, we need to move that animation to
3413 // the new one.
3414 if (ttoken.allDrawn) {
3415 wtoken.allDrawn = true;
3416 }
3417 if (ttoken.firstWindowDrawn) {
3418 wtoken.firstWindowDrawn = true;
3419 }
3420 if (!ttoken.hidden) {
3421 wtoken.hidden = false;
3422 wtoken.hiddenRequested = false;
3423 wtoken.willBeHidden = false;
3424 }
3425 if (wtoken.clientHidden != ttoken.clientHidden) {
3426 wtoken.clientHidden = ttoken.clientHidden;
3427 wtoken.sendAppVisibilityToClients();
3428 }
3429 if (ttoken.animation != null) {
3430 wtoken.animation = ttoken.animation;
3431 wtoken.animating = ttoken.animating;
3432 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3433 ttoken.animation = null;
3434 ttoken.animLayerAdjustment = 0;
3435 wtoken.updateLayers();
3436 ttoken.updateLayers();
3437 }
Romain Guy06882f82009-06-10 13:36:04 -07003438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003439 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003440 mLayoutNeeded = true;
3441 performLayoutAndPlaceSurfacesLocked();
3442 Binder.restoreCallingIdentity(origId);
3443 return;
3444 } else if (ttoken.startingData != null) {
3445 // The previous app was getting ready to show a
3446 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003447 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003448 "Moving pending starting from " + ttoken
3449 + " to " + wtoken);
3450 wtoken.startingData = ttoken.startingData;
3451 ttoken.startingData = null;
3452 ttoken.startingMoved = true;
3453 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3454 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3455 // want to process the message ASAP, before any other queued
3456 // messages.
3457 mH.sendMessageAtFrontOfQueue(m);
3458 return;
3459 }
3460 }
3461 }
3462
3463 // There is no existing starting window, and the caller doesn't
3464 // want us to create one, so that's it!
3465 if (!createIfNeeded) {
3466 return;
3467 }
Romain Guy06882f82009-06-10 13:36:04 -07003468
Dianne Hackborn284ac932009-08-28 10:34:25 -07003469 // If this is a translucent or wallpaper window, then don't
3470 // show a starting window -- the current effect (a full-screen
3471 // opaque starting window that fades away to the real contents
3472 // when it is ready) does not work for this.
3473 if (theme != 0) {
3474 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3475 com.android.internal.R.styleable.Window);
3476 if (ent.array.getBoolean(
3477 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3478 return;
3479 }
3480 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003481 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3482 return;
3483 }
3484 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003485 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3486 return;
3487 }
3488 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003490 mStartingIconInTransition = true;
3491 wtoken.startingData = new StartingData(
3492 pkg, theme, nonLocalizedLabel,
3493 labelRes, icon);
3494 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3495 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3496 // want to process the message ASAP, before any other queued
3497 // messages.
3498 mH.sendMessageAtFrontOfQueue(m);
3499 }
3500 }
3501
3502 public void setAppWillBeHidden(IBinder token) {
3503 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3504 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003505 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003506 }
3507
3508 AppWindowToken wtoken;
3509
3510 synchronized(mWindowMap) {
3511 wtoken = findAppWindowToken(token);
3512 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003513 Slog.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003514 return;
3515 }
3516 wtoken.willBeHidden = true;
3517 }
3518 }
Romain Guy06882f82009-06-10 13:36:04 -07003519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003520 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3521 boolean visible, int transit, boolean performLayout) {
3522 boolean delayed = false;
3523
3524 if (wtoken.clientHidden == visible) {
3525 wtoken.clientHidden = !visible;
3526 wtoken.sendAppVisibilityToClients();
3527 }
Romain Guy06882f82009-06-10 13:36:04 -07003528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003529 wtoken.willBeHidden = false;
3530 if (wtoken.hidden == visible) {
3531 final int N = wtoken.allAppWindows.size();
3532 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003533 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003534 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3535 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003537 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003538
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003539 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003540 if (wtoken.animation == sDummyAnimation) {
3541 wtoken.animation = null;
3542 }
3543 applyAnimationLocked(wtoken, lp, transit, visible);
3544 changed = true;
3545 if (wtoken.animation != null) {
3546 delayed = runningAppAnimation = true;
3547 }
3548 }
Romain Guy06882f82009-06-10 13:36:04 -07003549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003550 for (int i=0; i<N; i++) {
3551 WindowState win = wtoken.allAppWindows.get(i);
3552 if (win == wtoken.startingWindow) {
3553 continue;
3554 }
3555
3556 if (win.isAnimating()) {
3557 delayed = true;
3558 }
Romain Guy06882f82009-06-10 13:36:04 -07003559
Joe Onorato8a9b2202010-02-26 18:56:32 -08003560 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003561 //win.dump(" ");
3562 if (visible) {
3563 if (!win.isVisibleNow()) {
3564 if (!runningAppAnimation) {
3565 applyAnimationLocked(win,
3566 WindowManagerPolicy.TRANSIT_ENTER, true);
3567 }
3568 changed = true;
3569 }
3570 } else if (win.isVisibleNow()) {
3571 if (!runningAppAnimation) {
3572 applyAnimationLocked(win,
3573 WindowManagerPolicy.TRANSIT_EXIT, false);
3574 }
3575 mKeyWaiter.finishedKey(win.mSession, win.mClient, true,
3576 KeyWaiter.RETURN_NOTHING);
3577 changed = true;
3578 }
3579 }
3580
3581 wtoken.hidden = wtoken.hiddenRequested = !visible;
3582 if (!visible) {
3583 unsetAppFreezingScreenLocked(wtoken, true, true);
3584 } else {
3585 // If we are being set visible, and the starting window is
3586 // not yet displayed, then make sure it doesn't get displayed.
3587 WindowState swin = wtoken.startingWindow;
3588 if (swin != null && (swin.mDrawPending
3589 || swin.mCommitDrawPending)) {
3590 swin.mPolicyVisibility = false;
3591 swin.mPolicyVisibilityAfterAnim = false;
3592 }
3593 }
Romain Guy06882f82009-06-10 13:36:04 -07003594
Joe Onorato8a9b2202010-02-26 18:56:32 -08003595 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003596 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3597 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003598
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003599 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003600 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003601 if (performLayout) {
3602 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3603 performLayoutAndPlaceSurfacesLocked();
3604 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003605 }
3606 }
3607
3608 if (wtoken.animation != null) {
3609 delayed = true;
3610 }
Romain Guy06882f82009-06-10 13:36:04 -07003611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003612 return delayed;
3613 }
3614
3615 public void setAppVisibility(IBinder token, boolean visible) {
3616 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3617 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003618 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003619 }
3620
3621 AppWindowToken wtoken;
3622
3623 synchronized(mWindowMap) {
3624 wtoken = findAppWindowToken(token);
3625 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003626 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003627 return;
3628 }
3629
3630 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003631 RuntimeException e = null;
3632 if (!HIDE_STACK_CRAWLS) {
3633 e = new RuntimeException();
3634 e.fillInStackTrace();
3635 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003636 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003637 + "): mNextAppTransition=" + mNextAppTransition
3638 + " hidden=" + wtoken.hidden
3639 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3640 }
Romain Guy06882f82009-06-10 13:36:04 -07003641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003642 // If we are preparing an app transition, then delay changing
3643 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003644 if (!mDisplayFrozen && mPolicy.isScreenOn()
3645 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003646 // Already in requested state, don't do anything more.
3647 if (wtoken.hiddenRequested != visible) {
3648 return;
3649 }
3650 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003651
Joe Onorato8a9b2202010-02-26 18:56:32 -08003652 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003653 TAG, "Setting dummy animation on: " + wtoken);
3654 wtoken.setDummyAnimation();
3655 mOpeningApps.remove(wtoken);
3656 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003657 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003658 wtoken.inPendingTransaction = true;
3659 if (visible) {
3660 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003661 wtoken.startingDisplayed = false;
3662 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003663
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003664 // If the token is currently hidden (should be the
3665 // common case), then we need to set up to wait for
3666 // its windows to be ready.
3667 if (wtoken.hidden) {
3668 wtoken.allDrawn = false;
3669 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003670
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003671 if (wtoken.clientHidden) {
3672 // In the case where we are making an app visible
3673 // but holding off for a transition, we still need
3674 // to tell the client to make its windows visible so
3675 // they get drawn. Otherwise, we will wait on
3676 // performing the transition until all windows have
3677 // been drawn, they never will be, and we are sad.
3678 wtoken.clientHidden = false;
3679 wtoken.sendAppVisibilityToClients();
3680 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003681 }
3682 } else {
3683 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003684
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003685 // If the token is currently visible (should be the
3686 // common case), then set up to wait for it to be hidden.
3687 if (!wtoken.hidden) {
3688 wtoken.waitingToHide = true;
3689 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003690 }
3691 return;
3692 }
Romain Guy06882f82009-06-10 13:36:04 -07003693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003694 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003695 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003696 wtoken.updateReportedVisibilityLocked();
3697 Binder.restoreCallingIdentity(origId);
3698 }
3699 }
3700
3701 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3702 boolean unfreezeSurfaceNow, boolean force) {
3703 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003704 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003705 + " force=" + force);
3706 final int N = wtoken.allAppWindows.size();
3707 boolean unfrozeWindows = false;
3708 for (int i=0; i<N; i++) {
3709 WindowState w = wtoken.allAppWindows.get(i);
3710 if (w.mAppFreezing) {
3711 w.mAppFreezing = false;
3712 if (w.mSurface != null && !w.mOrientationChanging) {
3713 w.mOrientationChanging = true;
3714 }
3715 unfrozeWindows = true;
3716 }
3717 }
3718 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003719 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003720 wtoken.freezingScreen = false;
3721 mAppsFreezingScreen--;
3722 }
3723 if (unfreezeSurfaceNow) {
3724 if (unfrozeWindows) {
3725 mLayoutNeeded = true;
3726 performLayoutAndPlaceSurfacesLocked();
3727 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003728 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003729 }
3730 }
3731 }
Romain Guy06882f82009-06-10 13:36:04 -07003732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003733 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3734 int configChanges) {
3735 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003736 RuntimeException e = null;
3737 if (!HIDE_STACK_CRAWLS) {
3738 e = new RuntimeException();
3739 e.fillInStackTrace();
3740 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003741 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003742 + ": hidden=" + wtoken.hidden + " freezing="
3743 + wtoken.freezingScreen, e);
3744 }
3745 if (!wtoken.hiddenRequested) {
3746 if (!wtoken.freezingScreen) {
3747 wtoken.freezingScreen = true;
3748 mAppsFreezingScreen++;
3749 if (mAppsFreezingScreen == 1) {
3750 startFreezingDisplayLocked();
3751 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3752 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3753 5000);
3754 }
3755 }
3756 final int N = wtoken.allAppWindows.size();
3757 for (int i=0; i<N; i++) {
3758 WindowState w = wtoken.allAppWindows.get(i);
3759 w.mAppFreezing = true;
3760 }
3761 }
3762 }
Romain Guy06882f82009-06-10 13:36:04 -07003763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003764 public void startAppFreezingScreen(IBinder token, int configChanges) {
3765 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3766 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003767 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003768 }
3769
3770 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003771 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003772 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003773 return;
3774 }
Romain Guy06882f82009-06-10 13:36:04 -07003775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003776 AppWindowToken wtoken = findAppWindowToken(token);
3777 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003778 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003779 return;
3780 }
3781 final long origId = Binder.clearCallingIdentity();
3782 startAppFreezingScreenLocked(wtoken, configChanges);
3783 Binder.restoreCallingIdentity(origId);
3784 }
3785 }
Romain Guy06882f82009-06-10 13:36:04 -07003786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003787 public void stopAppFreezingScreen(IBinder token, boolean force) {
3788 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3789 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003790 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003791 }
3792
3793 synchronized(mWindowMap) {
3794 AppWindowToken wtoken = findAppWindowToken(token);
3795 if (wtoken == null || wtoken.appToken == null) {
3796 return;
3797 }
3798 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003799 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003800 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3801 unsetAppFreezingScreenLocked(wtoken, true, force);
3802 Binder.restoreCallingIdentity(origId);
3803 }
3804 }
Romain Guy06882f82009-06-10 13:36:04 -07003805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 public void removeAppToken(IBinder token) {
3807 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3808 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003809 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003810 }
3811
3812 AppWindowToken wtoken = null;
3813 AppWindowToken startingToken = null;
3814 boolean delayed = false;
3815
3816 final long origId = Binder.clearCallingIdentity();
3817 synchronized(mWindowMap) {
3818 WindowToken basewtoken = mTokenMap.remove(token);
3819 mTokenList.remove(basewtoken);
3820 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003821 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003822 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003823 wtoken.inPendingTransaction = false;
3824 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003825 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 if (mClosingApps.contains(wtoken)) {
3827 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003828 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003829 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003830 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003831 delayed = true;
3832 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003833 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003834 TAG, "Removing app " + wtoken + " delayed=" + delayed
3835 + " animation=" + wtoken.animation
3836 + " animating=" + wtoken.animating);
3837 if (delayed) {
3838 // set the token aside because it has an active animation to be finished
3839 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003840 } else {
3841 // Make sure there is no animation running on this token,
3842 // so any windows associated with it will be removed as
3843 // soon as their animations are complete
3844 wtoken.animation = null;
3845 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003846 }
3847 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003848 if (mLastEnterAnimToken == wtoken) {
3849 mLastEnterAnimToken = null;
3850 mLastEnterAnimParams = null;
3851 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003852 wtoken.removed = true;
3853 if (wtoken.startingData != null) {
3854 startingToken = wtoken;
3855 }
3856 unsetAppFreezingScreenLocked(wtoken, true, true);
3857 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003858 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003859 mFocusedApp = null;
3860 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3861 mKeyWaiter.tickle();
3862 }
3863 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003864 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003865 }
Romain Guy06882f82009-06-10 13:36:04 -07003866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003867 if (!delayed && wtoken != null) {
3868 wtoken.updateReportedVisibilityLocked();
3869 }
3870 }
3871 Binder.restoreCallingIdentity(origId);
3872
3873 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003874 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003875 + startingToken + ": app token removed");
3876 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3877 mH.sendMessage(m);
3878 }
3879 }
3880
3881 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3882 final int NW = token.windows.size();
3883 for (int i=0; i<NW; i++) {
3884 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003885 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003886 mWindows.remove(win);
3887 int j = win.mChildWindows.size();
3888 while (j > 0) {
3889 j--;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003890 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003891 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003892 "Tmp removing child window " + cwin);
3893 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003894 }
3895 }
3896 return NW > 0;
3897 }
3898
3899 void dumpAppTokensLocked() {
3900 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003901 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003902 }
3903 }
Romain Guy06882f82009-06-10 13:36:04 -07003904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003905 void dumpWindowsLocked() {
3906 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003907 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003908 }
3909 }
Romain Guy06882f82009-06-10 13:36:04 -07003910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003911 private int findWindowOffsetLocked(int tokenPos) {
3912 final int NW = mWindows.size();
3913
3914 if (tokenPos >= mAppTokens.size()) {
3915 int i = NW;
3916 while (i > 0) {
3917 i--;
3918 WindowState win = (WindowState)mWindows.get(i);
3919 if (win.getAppToken() != null) {
3920 return i+1;
3921 }
3922 }
3923 }
3924
3925 while (tokenPos > 0) {
3926 // Find the first app token below the new position that has
3927 // a window displayed.
3928 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003929 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003930 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003931 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003932 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003933 "Skipping token -- currently sending to bottom");
3934 tokenPos--;
3935 continue;
3936 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003937 int i = wtoken.windows.size();
3938 while (i > 0) {
3939 i--;
3940 WindowState win = wtoken.windows.get(i);
3941 int j = win.mChildWindows.size();
3942 while (j > 0) {
3943 j--;
3944 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003945 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003946 for (int pos=NW-1; pos>=0; pos--) {
3947 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003948 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003949 "Found child win @" + (pos+1));
3950 return pos+1;
3951 }
3952 }
3953 }
3954 }
3955 for (int pos=NW-1; pos>=0; pos--) {
3956 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003957 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003958 return pos+1;
3959 }
3960 }
3961 }
3962 tokenPos--;
3963 }
3964
3965 return 0;
3966 }
3967
3968 private final int reAddWindowLocked(int index, WindowState win) {
3969 final int NCW = win.mChildWindows.size();
3970 boolean added = false;
3971 for (int j=0; j<NCW; j++) {
3972 WindowState cwin = (WindowState)win.mChildWindows.get(j);
3973 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003974 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003975 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003976 mWindows.add(index, win);
3977 index++;
3978 added = true;
3979 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003980 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003981 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003982 mWindows.add(index, cwin);
3983 index++;
3984 }
3985 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003986 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003987 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003988 mWindows.add(index, win);
3989 index++;
3990 }
3991 return index;
3992 }
Romain Guy06882f82009-06-10 13:36:04 -07003993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003994 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3995 final int NW = token.windows.size();
3996 for (int i=0; i<NW; i++) {
3997 index = reAddWindowLocked(index, token.windows.get(i));
3998 }
3999 return index;
4000 }
4001
4002 public void moveAppToken(int index, IBinder token) {
4003 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4004 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004005 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004006 }
4007
4008 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004009 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004010 if (DEBUG_REORDER) dumpAppTokensLocked();
4011 final AppWindowToken wtoken = findAppWindowToken(token);
4012 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004013 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004014 + token + " (" + wtoken + ")");
4015 return;
4016 }
4017 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004018 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004019 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004021 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004022 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004023 if (DEBUG_REORDER) dumpWindowsLocked();
4024 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004025 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004026 if (DEBUG_REORDER) dumpWindowsLocked();
4027 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004028 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004029 if (DEBUG_REORDER) dumpWindowsLocked();
4030 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004031 mLayoutNeeded = true;
4032 performLayoutAndPlaceSurfacesLocked();
4033 }
4034 Binder.restoreCallingIdentity(origId);
4035 }
4036 }
4037
4038 private void removeAppTokensLocked(List<IBinder> tokens) {
4039 // XXX This should be done more efficiently!
4040 // (take advantage of the fact that both lists should be
4041 // ordered in the same way.)
4042 int N = tokens.size();
4043 for (int i=0; i<N; i++) {
4044 IBinder token = tokens.get(i);
4045 final AppWindowToken wtoken = findAppWindowToken(token);
4046 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004047 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004048 + token + " (" + wtoken + ")");
4049 i--;
4050 N--;
4051 }
4052 }
4053 }
4054
Dianne Hackborna8f60182009-09-01 19:01:50 -07004055 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4056 boolean updateFocusAndLayout) {
4057 // First remove all of the windows from the list.
4058 tmpRemoveAppWindowsLocked(wtoken);
4059
4060 // Where to start adding?
4061 int pos = findWindowOffsetLocked(tokenPos);
4062
4063 // And now add them back at the correct place.
4064 pos = reAddAppWindowsLocked(pos, wtoken);
4065
4066 if (updateFocusAndLayout) {
4067 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4068 assignLayersLocked();
4069 }
4070 mLayoutNeeded = true;
4071 performLayoutAndPlaceSurfacesLocked();
4072 }
4073 }
4074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004075 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4076 // First remove all of the windows from the list.
4077 final int N = tokens.size();
4078 int i;
4079 for (i=0; i<N; i++) {
4080 WindowToken token = mTokenMap.get(tokens.get(i));
4081 if (token != null) {
4082 tmpRemoveAppWindowsLocked(token);
4083 }
4084 }
4085
4086 // Where to start adding?
4087 int pos = findWindowOffsetLocked(tokenPos);
4088
4089 // And now add them back at the correct place.
4090 for (i=0; i<N; i++) {
4091 WindowToken token = mTokenMap.get(tokens.get(i));
4092 if (token != null) {
4093 pos = reAddAppWindowsLocked(pos, token);
4094 }
4095 }
4096
Dianne Hackborna8f60182009-09-01 19:01:50 -07004097 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4098 assignLayersLocked();
4099 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004100 mLayoutNeeded = true;
4101 performLayoutAndPlaceSurfacesLocked();
4102
4103 //dump();
4104 }
4105
4106 public void moveAppTokensToTop(List<IBinder> tokens) {
4107 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4108 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004109 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004110 }
4111
4112 final long origId = Binder.clearCallingIdentity();
4113 synchronized(mWindowMap) {
4114 removeAppTokensLocked(tokens);
4115 final int N = tokens.size();
4116 for (int i=0; i<N; i++) {
4117 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4118 if (wt != null) {
4119 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004120 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004121 mToTopApps.remove(wt);
4122 mToBottomApps.remove(wt);
4123 mToTopApps.add(wt);
4124 wt.sendingToBottom = false;
4125 wt.sendingToTop = true;
4126 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004127 }
4128 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004129
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004130 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004131 moveAppWindowsLocked(tokens, mAppTokens.size());
4132 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004133 }
4134 Binder.restoreCallingIdentity(origId);
4135 }
4136
4137 public void moveAppTokensToBottom(List<IBinder> tokens) {
4138 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4139 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004140 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004141 }
4142
4143 final long origId = Binder.clearCallingIdentity();
4144 synchronized(mWindowMap) {
4145 removeAppTokensLocked(tokens);
4146 final int N = tokens.size();
4147 int pos = 0;
4148 for (int i=0; i<N; i++) {
4149 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4150 if (wt != null) {
4151 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004152 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004153 mToTopApps.remove(wt);
4154 mToBottomApps.remove(wt);
4155 mToBottomApps.add(i, wt);
4156 wt.sendingToTop = false;
4157 wt.sendingToBottom = true;
4158 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004159 pos++;
4160 }
4161 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004162
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004163 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004164 moveAppWindowsLocked(tokens, 0);
4165 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004166 }
4167 Binder.restoreCallingIdentity(origId);
4168 }
4169
4170 // -------------------------------------------------------------
4171 // Misc IWindowSession methods
4172 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004174 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004175 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004176 != PackageManager.PERMISSION_GRANTED) {
4177 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4178 }
Mike Lockwood983ee092009-11-22 01:42:24 -05004179 synchronized (mKeyguardTokenWatcher) {
4180 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004181 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004182 }
4183
4184 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004185 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004186 != PackageManager.PERMISSION_GRANTED) {
4187 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4188 }
Mike Lockwood983ee092009-11-22 01:42:24 -05004189 synchronized (mKeyguardTokenWatcher) {
4190 mKeyguardTokenWatcher.release(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004191
Mike Lockwood983ee092009-11-22 01:42:24 -05004192 if (!mKeyguardTokenWatcher.isAcquired()) {
4193 // If we are the last one to reenable the keyguard wait until
4194 // we have actaully finished reenabling until returning.
4195 // It is possible that reenableKeyguard() can be called before
4196 // the previous disableKeyguard() is handled, in which case
4197 // neither mKeyguardTokenWatcher.acquired() or released() would
4198 // be called. In that case mKeyguardDisabled will be false here
4199 // and we have nothing to wait for.
4200 while (mKeyguardDisabled) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004201 try {
Mike Lockwood983ee092009-11-22 01:42:24 -05004202 mKeyguardTokenWatcher.wait();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004203 } catch (InterruptedException e) {
4204 Thread.currentThread().interrupt();
4205 }
4206 }
4207 }
4208 }
4209 }
4210
4211 /**
4212 * @see android.app.KeyguardManager#exitKeyguardSecurely
4213 */
4214 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004215 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004216 != PackageManager.PERMISSION_GRANTED) {
4217 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4218 }
4219 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4220 public void onKeyguardExitResult(boolean success) {
4221 try {
4222 callback.onKeyguardExitResult(success);
4223 } catch (RemoteException e) {
4224 // Client has died, we don't care.
4225 }
4226 }
4227 });
4228 }
4229
4230 public boolean inKeyguardRestrictedInputMode() {
4231 return mPolicy.inKeyguardRestrictedKeyInputMode();
4232 }
Romain Guy06882f82009-06-10 13:36:04 -07004233
Dianne Hackbornffa42482009-09-23 22:20:11 -07004234 public void closeSystemDialogs(String reason) {
4235 synchronized(mWindowMap) {
4236 for (int i=mWindows.size()-1; i>=0; i--) {
4237 WindowState w = (WindowState)mWindows.get(i);
4238 if (w.mSurface != null) {
4239 try {
4240 w.mClient.closeSystemDialogs(reason);
4241 } catch (RemoteException e) {
4242 }
4243 }
4244 }
4245 }
4246 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004248 static float fixScale(float scale) {
4249 if (scale < 0) scale = 0;
4250 else if (scale > 20) scale = 20;
4251 return Math.abs(scale);
4252 }
Romain Guy06882f82009-06-10 13:36:04 -07004253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004254 public void setAnimationScale(int which, float scale) {
4255 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4256 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004257 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004258 }
4259
4260 if (scale < 0) scale = 0;
4261 else if (scale > 20) scale = 20;
4262 scale = Math.abs(scale);
4263 switch (which) {
4264 case 0: mWindowAnimationScale = fixScale(scale); break;
4265 case 1: mTransitionAnimationScale = fixScale(scale); break;
4266 }
Romain Guy06882f82009-06-10 13:36:04 -07004267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004268 // Persist setting
4269 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4270 }
Romain Guy06882f82009-06-10 13:36:04 -07004271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004272 public void setAnimationScales(float[] scales) {
4273 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4274 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004275 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004276 }
4277
4278 if (scales != null) {
4279 if (scales.length >= 1) {
4280 mWindowAnimationScale = fixScale(scales[0]);
4281 }
4282 if (scales.length >= 2) {
4283 mTransitionAnimationScale = fixScale(scales[1]);
4284 }
4285 }
Romain Guy06882f82009-06-10 13:36:04 -07004286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004287 // Persist setting
4288 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4289 }
Romain Guy06882f82009-06-10 13:36:04 -07004290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004291 public float getAnimationScale(int which) {
4292 switch (which) {
4293 case 0: return mWindowAnimationScale;
4294 case 1: return mTransitionAnimationScale;
4295 }
4296 return 0;
4297 }
Romain Guy06882f82009-06-10 13:36:04 -07004298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004299 public float[] getAnimationScales() {
4300 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4301 }
Romain Guy06882f82009-06-10 13:36:04 -07004302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004303 public int getSwitchState(int sw) {
4304 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4305 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004306 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004307 }
4308 return KeyInputQueue.getSwitchState(sw);
4309 }
Romain Guy06882f82009-06-10 13:36:04 -07004310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004311 public int getSwitchStateForDevice(int devid, int sw) {
4312 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4313 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004314 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004315 }
4316 return KeyInputQueue.getSwitchState(devid, sw);
4317 }
Romain Guy06882f82009-06-10 13:36:04 -07004318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004319 public int getScancodeState(int sw) {
4320 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4321 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004322 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004323 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004324 return mQueue.getScancodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004325 }
Romain Guy06882f82009-06-10 13:36:04 -07004326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004327 public int getScancodeStateForDevice(int devid, int sw) {
4328 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4329 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004330 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004331 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004332 return mQueue.getScancodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004333 }
Romain Guy06882f82009-06-10 13:36:04 -07004334
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004335 public int getTrackballScancodeState(int sw) {
4336 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4337 "getTrackballScancodeState()")) {
4338 throw new SecurityException("Requires READ_INPUT_STATE permission");
4339 }
4340 return mQueue.getTrackballScancodeState(sw);
4341 }
4342
4343 public int getDPadScancodeState(int sw) {
4344 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4345 "getDPadScancodeState()")) {
4346 throw new SecurityException("Requires READ_INPUT_STATE permission");
4347 }
4348 return mQueue.getDPadScancodeState(sw);
4349 }
4350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004351 public int getKeycodeState(int sw) {
4352 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4353 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004354 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004355 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004356 return mQueue.getKeycodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004357 }
Romain Guy06882f82009-06-10 13:36:04 -07004358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004359 public int getKeycodeStateForDevice(int devid, int sw) {
4360 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4361 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004362 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004363 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004364 return mQueue.getKeycodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004365 }
Romain Guy06882f82009-06-10 13:36:04 -07004366
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004367 public int getTrackballKeycodeState(int sw) {
4368 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4369 "getTrackballKeycodeState()")) {
4370 throw new SecurityException("Requires READ_INPUT_STATE permission");
4371 }
4372 return mQueue.getTrackballKeycodeState(sw);
4373 }
4374
4375 public int getDPadKeycodeState(int sw) {
4376 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4377 "getDPadKeycodeState()")) {
4378 throw new SecurityException("Requires READ_INPUT_STATE permission");
4379 }
4380 return mQueue.getDPadKeycodeState(sw);
4381 }
4382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004383 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
4384 return KeyInputQueue.hasKeys(keycodes, keyExists);
4385 }
Romain Guy06882f82009-06-10 13:36:04 -07004386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004387 public void enableScreenAfterBoot() {
4388 synchronized(mWindowMap) {
4389 if (mSystemBooted) {
4390 return;
4391 }
4392 mSystemBooted = true;
4393 }
Romain Guy06882f82009-06-10 13:36:04 -07004394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004395 performEnableScreen();
4396 }
Romain Guy06882f82009-06-10 13:36:04 -07004397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004398 public void enableScreenIfNeededLocked() {
4399 if (mDisplayEnabled) {
4400 return;
4401 }
4402 if (!mSystemBooted) {
4403 return;
4404 }
4405 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4406 }
Romain Guy06882f82009-06-10 13:36:04 -07004407
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004408 public void performEnableScreen() {
4409 synchronized(mWindowMap) {
4410 if (mDisplayEnabled) {
4411 return;
4412 }
4413 if (!mSystemBooted) {
4414 return;
4415 }
Romain Guy06882f82009-06-10 13:36:04 -07004416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004417 // Don't enable the screen until all existing windows
4418 // have been drawn.
4419 final int N = mWindows.size();
4420 for (int i=0; i<N; i++) {
4421 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn5943c202010-04-12 21:36:49 -07004422 if (w.isVisibleLw() && !w.mObscured
4423 && (w.mOrientationChanging || !w.isDrawnLw())) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004424 return;
4425 }
4426 }
Romain Guy06882f82009-06-10 13:36:04 -07004427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004428 mDisplayEnabled = true;
4429 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004430 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004431 StringWriter sw = new StringWriter();
4432 PrintWriter pw = new PrintWriter(sw);
4433 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004434 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004435 }
4436 try {
4437 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4438 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004439 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004440 Parcel data = Parcel.obtain();
4441 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4442 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4443 data, null, 0);
4444 data.recycle();
4445 }
4446 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004447 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004448 }
4449 }
Romain Guy06882f82009-06-10 13:36:04 -07004450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004451 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004453 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004454 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4455 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004456 }
Romain Guy06882f82009-06-10 13:36:04 -07004457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004458 public void setInTouchMode(boolean mode) {
4459 synchronized(mWindowMap) {
4460 mInTouchMode = mode;
4461 }
4462 }
4463
Romain Guy06882f82009-06-10 13:36:04 -07004464 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004465 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004466 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004467 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004468 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004469 }
4470
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004471 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004472 }
Romain Guy06882f82009-06-10 13:36:04 -07004473
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004474 public void setRotationUnchecked(int rotation,
4475 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004476 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004477 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004479 long origId = Binder.clearCallingIdentity();
4480 boolean changed;
4481 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004482 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004483 }
Romain Guy06882f82009-06-10 13:36:04 -07004484
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004485 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004486 sendNewConfiguration();
4487 }
Romain Guy06882f82009-06-10 13:36:04 -07004488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004489 Binder.restoreCallingIdentity(origId);
4490 }
Romain Guy06882f82009-06-10 13:36:04 -07004491
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004492 /**
4493 * Apply a new rotation to the screen, respecting the requests of
4494 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4495 * re-evaluate the desired rotation.
4496 *
4497 * Returns null if the rotation has been changed. In this case YOU
4498 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4499 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004500 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004501 boolean changed;
4502 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4503 rotation = mRequestedRotation;
4504 } else {
4505 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004506 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004507 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004508 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004509 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004510 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004511 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004512 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004514 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004515 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004516 "Rotation changed to " + rotation
4517 + " from " + mRotation
4518 + " (forceApp=" + mForcedAppOrientation
4519 + ", req=" + mRequestedRotation + ")");
4520 mRotation = rotation;
4521 mWindowsFreezingScreen = true;
4522 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4523 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4524 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004525 mWaitingForConfig = true;
4526 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004527 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004528 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004529 mQueue.setOrientation(rotation);
4530 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004531 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004532 }
4533 for (int i=mWindows.size()-1; i>=0; i--) {
4534 WindowState w = (WindowState)mWindows.get(i);
4535 if (w.mSurface != null) {
4536 w.mOrientationChanging = true;
4537 }
4538 }
4539 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4540 try {
4541 mRotationWatchers.get(i).onRotationChanged(rotation);
4542 } catch (RemoteException e) {
4543 }
4544 }
4545 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004547 return changed;
4548 }
Romain Guy06882f82009-06-10 13:36:04 -07004549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004550 public int getRotation() {
4551 return mRotation;
4552 }
4553
4554 public int watchRotation(IRotationWatcher watcher) {
4555 final IBinder watcherBinder = watcher.asBinder();
4556 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4557 public void binderDied() {
4558 synchronized (mWindowMap) {
4559 for (int i=0; i<mRotationWatchers.size(); i++) {
4560 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004561 IRotationWatcher removed = mRotationWatchers.remove(i);
4562 if (removed != null) {
4563 removed.asBinder().unlinkToDeath(this, 0);
4564 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004565 i--;
4566 }
4567 }
4568 }
4569 }
4570 };
Romain Guy06882f82009-06-10 13:36:04 -07004571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004572 synchronized (mWindowMap) {
4573 try {
4574 watcher.asBinder().linkToDeath(dr, 0);
4575 mRotationWatchers.add(watcher);
4576 } catch (RemoteException e) {
4577 // Client died, no cleanup needed.
4578 }
Romain Guy06882f82009-06-10 13:36:04 -07004579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004580 return mRotation;
4581 }
4582 }
4583
4584 /**
4585 * Starts the view server on the specified port.
4586 *
4587 * @param port The port to listener to.
4588 *
4589 * @return True if the server was successfully started, false otherwise.
4590 *
4591 * @see com.android.server.ViewServer
4592 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4593 */
4594 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004595 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004596 return false;
4597 }
4598
4599 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4600 return false;
4601 }
4602
4603 if (port < 1024) {
4604 return false;
4605 }
4606
4607 if (mViewServer != null) {
4608 if (!mViewServer.isRunning()) {
4609 try {
4610 return mViewServer.start();
4611 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004612 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004613 }
4614 }
4615 return false;
4616 }
4617
4618 try {
4619 mViewServer = new ViewServer(this, port);
4620 return mViewServer.start();
4621 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004622 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004623 }
4624 return false;
4625 }
4626
Romain Guy06882f82009-06-10 13:36:04 -07004627 private boolean isSystemSecure() {
4628 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4629 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4630 }
4631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004632 /**
4633 * Stops the view server if it exists.
4634 *
4635 * @return True if the server stopped, false if it wasn't started or
4636 * couldn't be stopped.
4637 *
4638 * @see com.android.server.ViewServer
4639 */
4640 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004641 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004642 return false;
4643 }
4644
4645 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4646 return false;
4647 }
4648
4649 if (mViewServer != null) {
4650 return mViewServer.stop();
4651 }
4652 return false;
4653 }
4654
4655 /**
4656 * Indicates whether the view server is running.
4657 *
4658 * @return True if the server is running, false otherwise.
4659 *
4660 * @see com.android.server.ViewServer
4661 */
4662 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004663 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004664 return false;
4665 }
4666
4667 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4668 return false;
4669 }
4670
4671 return mViewServer != null && mViewServer.isRunning();
4672 }
4673
4674 /**
4675 * Lists all availble windows in the system. The listing is written in the
4676 * specified Socket's output stream with the following syntax:
4677 * windowHashCodeInHexadecimal windowName
4678 * Each line of the ouput represents a different window.
4679 *
4680 * @param client The remote client to send the listing to.
4681 * @return False if an error occured, true otherwise.
4682 */
4683 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004684 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004685 return false;
4686 }
4687
4688 boolean result = true;
4689
4690 Object[] windows;
4691 synchronized (mWindowMap) {
4692 windows = new Object[mWindows.size()];
4693 //noinspection unchecked
4694 windows = mWindows.toArray(windows);
4695 }
4696
4697 BufferedWriter out = null;
4698
4699 // Any uncaught exception will crash the system process
4700 try {
4701 OutputStream clientStream = client.getOutputStream();
4702 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4703
4704 final int count = windows.length;
4705 for (int i = 0; i < count; i++) {
4706 final WindowState w = (WindowState) windows[i];
4707 out.write(Integer.toHexString(System.identityHashCode(w)));
4708 out.write(' ');
4709 out.append(w.mAttrs.getTitle());
4710 out.write('\n');
4711 }
4712
4713 out.write("DONE.\n");
4714 out.flush();
4715 } catch (Exception e) {
4716 result = false;
4717 } finally {
4718 if (out != null) {
4719 try {
4720 out.close();
4721 } catch (IOException e) {
4722 result = false;
4723 }
4724 }
4725 }
4726
4727 return result;
4728 }
4729
4730 /**
4731 * Sends a command to a target window. The result of the command, if any, will be
4732 * written in the output stream of the specified socket.
4733 *
4734 * The parameters must follow this syntax:
4735 * windowHashcode extra
4736 *
4737 * Where XX is the length in characeters of the windowTitle.
4738 *
4739 * The first parameter is the target window. The window with the specified hashcode
4740 * will be the target. If no target can be found, nothing happens. The extra parameters
4741 * will be delivered to the target window and as parameters to the command itself.
4742 *
4743 * @param client The remote client to sent the result, if any, to.
4744 * @param command The command to execute.
4745 * @param parameters The command parameters.
4746 *
4747 * @return True if the command was successfully delivered, false otherwise. This does
4748 * not indicate whether the command itself was successful.
4749 */
4750 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004751 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004752 return false;
4753 }
4754
4755 boolean success = true;
4756 Parcel data = null;
4757 Parcel reply = null;
4758
4759 // Any uncaught exception will crash the system process
4760 try {
4761 // Find the hashcode of the window
4762 int index = parameters.indexOf(' ');
4763 if (index == -1) {
4764 index = parameters.length();
4765 }
4766 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004767 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004768
4769 // Extract the command's parameter after the window description
4770 if (index < parameters.length()) {
4771 parameters = parameters.substring(index + 1);
4772 } else {
4773 parameters = "";
4774 }
4775
4776 final WindowManagerService.WindowState window = findWindow(hashCode);
4777 if (window == null) {
4778 return false;
4779 }
4780
4781 data = Parcel.obtain();
4782 data.writeInterfaceToken("android.view.IWindow");
4783 data.writeString(command);
4784 data.writeString(parameters);
4785 data.writeInt(1);
4786 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4787
4788 reply = Parcel.obtain();
4789
4790 final IBinder binder = window.mClient.asBinder();
4791 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4792 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4793
4794 reply.readException();
4795
4796 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004797 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004798 success = false;
4799 } finally {
4800 if (data != null) {
4801 data.recycle();
4802 }
4803 if (reply != null) {
4804 reply.recycle();
4805 }
4806 }
4807
4808 return success;
4809 }
4810
4811 private WindowState findWindow(int hashCode) {
4812 if (hashCode == -1) {
4813 return getFocusedWindow();
4814 }
4815
4816 synchronized (mWindowMap) {
4817 final ArrayList windows = mWindows;
4818 final int count = windows.size();
4819
4820 for (int i = 0; i < count; i++) {
4821 WindowState w = (WindowState) windows.get(i);
4822 if (System.identityHashCode(w) == hashCode) {
4823 return w;
4824 }
4825 }
4826 }
4827
4828 return null;
4829 }
4830
4831 /*
4832 * Instruct the Activity Manager to fetch the current configuration and broadcast
4833 * that to config-changed listeners if appropriate.
4834 */
4835 void sendNewConfiguration() {
4836 try {
4837 mActivityManager.updateConfiguration(null);
4838 } catch (RemoteException e) {
4839 }
4840 }
Romain Guy06882f82009-06-10 13:36:04 -07004841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004842 public Configuration computeNewConfiguration() {
4843 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004844 return computeNewConfigurationLocked();
4845 }
4846 }
Romain Guy06882f82009-06-10 13:36:04 -07004847
Dianne Hackbornc485a602009-03-24 22:39:49 -07004848 Configuration computeNewConfigurationLocked() {
4849 Configuration config = new Configuration();
4850 if (!computeNewConfigurationLocked(config)) {
4851 return null;
4852 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004853 return config;
4854 }
Romain Guy06882f82009-06-10 13:36:04 -07004855
Dianne Hackbornc485a602009-03-24 22:39:49 -07004856 boolean computeNewConfigurationLocked(Configuration config) {
4857 if (mDisplay == null) {
4858 return false;
4859 }
4860 mQueue.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07004861
4862 // Use the effective "visual" dimensions based on current rotation
4863 final boolean rotated = (mRotation == Surface.ROTATION_90
4864 || mRotation == Surface.ROTATION_270);
4865 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
4866 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
4867
Dianne Hackbornc485a602009-03-24 22:39:49 -07004868 int orientation = Configuration.ORIENTATION_SQUARE;
4869 if (dw < dh) {
4870 orientation = Configuration.ORIENTATION_PORTRAIT;
4871 } else if (dw > dh) {
4872 orientation = Configuration.ORIENTATION_LANDSCAPE;
4873 }
4874 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004875
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004876 DisplayMetrics dm = new DisplayMetrics();
4877 mDisplay.getMetrics(dm);
4878 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4879
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004880 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004881 // Note we only do this once because at this point we don't
4882 // expect the screen to change in this way at runtime, and want
4883 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004884 int longSize = dw;
4885 int shortSize = dh;
4886 if (longSize < shortSize) {
4887 int tmp = longSize;
4888 longSize = shortSize;
4889 shortSize = tmp;
4890 }
4891 longSize = (int)(longSize/dm.density);
4892 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004893
Dianne Hackborn723738c2009-06-25 19:48:04 -07004894 // These semi-magic numbers define our compatibility modes for
4895 // applications with different screens. Don't change unless you
4896 // make sure to test lots and lots of apps!
4897 if (longSize < 470) {
4898 // This is shorter than an HVGA normal density screen (which
4899 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004900 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
4901 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07004902 } else {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004903 // Is this a large screen?
4904 if (longSize > 640 && shortSize >= 480) {
4905 // VGA or larger screens at medium density are the point
4906 // at which we consider it to be a large screen.
4907 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
4908 } else {
4909 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004910
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004911 // If this screen is wider than normal HVGA, or taller
4912 // than FWVGA, then for old apps we want to run in size
4913 // compatibility mode.
4914 if (shortSize > 321 || longSize > 570) {
4915 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
4916 }
4917 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004918
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004919 // Is this a long screen?
4920 if (((longSize*3)/5) >= (shortSize-1)) {
4921 // Anything wider than WVGA (5:3) is considering to be long.
4922 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
4923 } else {
4924 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
4925 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07004926 }
4927 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004928 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004929
Dianne Hackbornc485a602009-03-24 22:39:49 -07004930 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
4931 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
4932 mPolicy.adjustConfigurationLw(config);
4933 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004934 }
Romain Guy06882f82009-06-10 13:36:04 -07004935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004936 // -------------------------------------------------------------
4937 // Input Events and Focus Management
4938 // -------------------------------------------------------------
4939
4940 private final void wakeupIfNeeded(WindowState targetWin, int eventType) {
Michael Chane96440f2009-05-06 10:27:36 -07004941 long curTime = SystemClock.uptimeMillis();
4942
Michael Chane10de972009-05-18 11:24:50 -07004943 if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) {
Michael Chane96440f2009-05-06 10:27:36 -07004944 if (mLastTouchEventType == eventType &&
4945 (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) {
4946 return;
4947 }
4948 mLastUserActivityCallTime = curTime;
4949 mLastTouchEventType = eventType;
4950 }
4951
4952 if (targetWin == null
4953 || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) {
4954 mPowerManager.userActivity(curTime, false, eventType, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004955 }
4956 }
4957
4958 // tells if it's a cheek event or not -- this function is stateful
4959 private static final int EVENT_NONE = 0;
4960 private static final int EVENT_UNKNOWN = 0;
4961 private static final int EVENT_CHEEK = 0;
4962 private static final int EVENT_IGNORE_DURATION = 300; // ms
4963 private static final float CHEEK_THRESHOLD = 0.6f;
4964 private int mEventState = EVENT_NONE;
4965 private float mEventSize;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004967 private int eventType(MotionEvent ev) {
4968 float size = ev.getSize();
4969 switch (ev.getAction()) {
4970 case MotionEvent.ACTION_DOWN:
4971 mEventSize = size;
4972 return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT;
4973 case MotionEvent.ACTION_UP:
4974 if (size > mEventSize) mEventSize = size;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004975 return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004976 case MotionEvent.ACTION_MOVE:
4977 final int N = ev.getHistorySize();
4978 if (size > mEventSize) mEventSize = size;
4979 if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT;
4980 for (int i=0; i<N; i++) {
4981 size = ev.getHistoricalSize(i);
4982 if (size > mEventSize) mEventSize = size;
4983 if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT;
4984 }
4985 if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) {
4986 return TOUCH_EVENT;
4987 } else {
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004988 return LONG_TOUCH_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004989 }
4990 default:
4991 // not good
4992 return OTHER_EVENT;
4993 }
4994 }
4995
4996 /**
4997 * @return Returns true if event was dispatched, false if it was dropped for any reason
4998 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07004999 private int dispatchPointer(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005000 if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005001 "dispatchPointer " + ev);
5002
Michael Chan53071d62009-05-13 17:29:48 -07005003 if (MEASURE_LATENCY) {
5004 lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano);
5005 }
5006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005007 Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005008 ev, true, false, pid, uid);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005009
Michael Chan53071d62009-05-13 17:29:48 -07005010 if (MEASURE_LATENCY) {
5011 lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano);
5012 }
5013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005014 int action = ev.getAction();
Romain Guy06882f82009-06-10 13:36:04 -07005015
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005016 if (action == MotionEvent.ACTION_UP) {
5017 // let go of our target
5018 mKeyWaiter.mMotionTarget = null;
5019 mPowerManager.logPointerUpEvent();
5020 } else if (action == MotionEvent.ACTION_DOWN) {
5021 mPowerManager.logPointerDownEvent();
5022 }
5023
5024 if (targetObj == null) {
5025 // In this case we are either dropping the event, or have received
5026 // a move or up without a down. It is common to receive move
5027 // events in such a way, since this means the user is moving the
5028 // pointer without actually pressing down. All other cases should
5029 // be atypical, so let's log them.
Michael Chane96440f2009-05-06 10:27:36 -07005030 if (action != MotionEvent.ACTION_MOVE) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005031 Slog.w(TAG, "No window to dispatch pointer action " + ev.getAction());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005032 }
Dianne Hackborn6adba242009-11-10 11:10:09 -08005033 synchronized (mWindowMap) {
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005034 dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true);
Dianne Hackborn6adba242009-11-10 11:10:09 -08005035 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005036 if (qev != null) {
5037 mQueue.recycleEvent(qev);
5038 }
5039 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005040 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005041 }
5042 if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
Dianne Hackborn6adba242009-11-10 11:10:09 -08005043 synchronized (mWindowMap) {
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005044 dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true);
Dianne Hackborn6adba242009-11-10 11:10:09 -08005045 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005046 if (qev != null) {
5047 mQueue.recycleEvent(qev);
5048 }
5049 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005050 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005051 }
Romain Guy06882f82009-06-10 13:36:04 -07005052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005053 WindowState target = (WindowState)targetObj;
Romain Guy06882f82009-06-10 13:36:04 -07005054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005055 final long eventTime = ev.getEventTime();
Michael Chan53071d62009-05-13 17:29:48 -07005056 final long eventTimeNano = ev.getEventTimeNano();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005057
Joe Onorato8a9b2202010-02-26 18:56:32 -08005058 //Slog.i(TAG, "Sending " + ev + " to " + target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005059
5060 if (uid != 0 && uid != target.mSession.mUid) {
5061 if (mContext.checkPermission(
5062 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5063 != PackageManager.PERMISSION_GRANTED) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005064 Slog.w(TAG, "Permission denied: injecting pointer event from pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005065 + pid + " uid " + uid + " to window " + target
5066 + " owned by uid " + target.mSession.mUid);
5067 if (qev != null) {
5068 mQueue.recycleEvent(qev);
5069 }
5070 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005071 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005072 }
5073 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005074
Michael Chan53071d62009-05-13 17:29:48 -07005075 if (MEASURE_LATENCY) {
5076 lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano);
5077 }
5078
Romain Guy06882f82009-06-10 13:36:04 -07005079 if ((target.mAttrs.flags &
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005080 WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) {
5081 //target wants to ignore fat touch events
5082 boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev);
5083 //explicit flag to return without processing event further
5084 boolean returnFlag = false;
5085 if((action == MotionEvent.ACTION_DOWN)) {
5086 mFatTouch = false;
5087 if(cheekPress) {
5088 mFatTouch = true;
5089 returnFlag = true;
5090 }
5091 } else {
5092 if(action == MotionEvent.ACTION_UP) {
5093 if(mFatTouch) {
5094 //earlier even was invalid doesnt matter if current up is cheekpress or not
5095 mFatTouch = false;
5096 returnFlag = true;
5097 } else if(cheekPress) {
5098 //cancel the earlier event
5099 ev.setAction(MotionEvent.ACTION_CANCEL);
5100 action = MotionEvent.ACTION_CANCEL;
5101 }
5102 } else if(action == MotionEvent.ACTION_MOVE) {
5103 if(mFatTouch) {
5104 //two cases here
5105 //an invalid down followed by 0 or moves(valid or invalid)
Romain Guy06882f82009-06-10 13:36:04 -07005106 //a valid down, invalid move, more moves. want to ignore till up
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005107 returnFlag = true;
5108 } else if(cheekPress) {
5109 //valid down followed by invalid moves
5110 //an invalid move have to cancel earlier action
5111 ev.setAction(MotionEvent.ACTION_CANCEL);
5112 action = MotionEvent.ACTION_CANCEL;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005113 if (DEBUG_INPUT) Slog.v(TAG, "Sending cancel for invalid ACTION_MOVE");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005114 //note that the subsequent invalid moves will not get here
5115 mFatTouch = true;
5116 }
5117 }
5118 } //else if action
5119 if(returnFlag) {
5120 //recycle que, ev
5121 if (qev != null) {
5122 mQueue.recycleEvent(qev);
5123 }
5124 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005125 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005126 }
5127 } //end if target
Michael Chane96440f2009-05-06 10:27:36 -07005128
Michael Chan9f028e62009-08-04 17:37:46 -07005129 // Enable this for testing the "right" value
5130 if (false && action == MotionEvent.ACTION_DOWN) {
Michael Chane96440f2009-05-06 10:27:36 -07005131 int max_events_per_sec = 35;
5132 try {
5133 max_events_per_sec = Integer.parseInt(SystemProperties
5134 .get("windowsmgr.max_events_per_sec"));
5135 if (max_events_per_sec < 1) {
5136 max_events_per_sec = 35;
5137 }
5138 } catch (NumberFormatException e) {
5139 }
5140 mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec;
5141 }
5142
5143 /*
5144 * Throttle events to minimize CPU usage when there's a flood of events
5145 * e.g. constant contact with the screen
5146 */
5147 if (action == MotionEvent.ACTION_MOVE) {
5148 long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents;
5149 long now = SystemClock.uptimeMillis();
5150 if (now < nextEventTime) {
5151 try {
5152 Thread.sleep(nextEventTime - now);
5153 } catch (InterruptedException e) {
5154 }
5155 mLastTouchEventTime = nextEventTime;
5156 } else {
5157 mLastTouchEventTime = now;
5158 }
5159 }
5160
Michael Chan53071d62009-05-13 17:29:48 -07005161 if (MEASURE_LATENCY) {
5162 lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano);
5163 }
5164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005165 synchronized(mWindowMap) {
Dianne Hackborn6adba242009-11-10 11:10:09 -08005166 if (!target.isVisibleLw()) {
5167 // During this motion dispatch, the target window has become
5168 // invisible.
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005169 dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), false);
Dianne Hackborn6adba242009-11-10 11:10:09 -08005170 if (qev != null) {
5171 mQueue.recycleEvent(qev);
5172 }
5173 ev.recycle();
5174 return INJECT_SUCCEEDED;
5175 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005177 if (qev != null && action == MotionEvent.ACTION_MOVE) {
5178 mKeyWaiter.bindTargetWindowLocked(target,
5179 KeyWaiter.RETURN_PENDING_POINTER, qev);
5180 ev = null;
5181 } else {
5182 if (action == MotionEvent.ACTION_DOWN) {
5183 WindowState out = mKeyWaiter.mOutsideTouchTargets;
5184 if (out != null) {
5185 MotionEvent oev = MotionEvent.obtain(ev);
5186 oev.setAction(MotionEvent.ACTION_OUTSIDE);
5187 do {
5188 final Rect frame = out.mFrame;
5189 oev.offsetLocation(-(float)frame.left, -(float)frame.top);
5190 try {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005191 out.mClient.dispatchPointer(oev, eventTime, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005192 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005193 Slog.i(TAG, "WINDOW DIED during outside motion dispatch: " + out);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005194 }
5195 oev.offsetLocation((float)frame.left, (float)frame.top);
5196 out = out.mNextOutsideTouch;
5197 } while (out != null);
5198 mKeyWaiter.mOutsideTouchTargets = null;
5199 }
5200 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005201
Dianne Hackborn90d2db32010-02-11 22:19:06 -08005202 dispatchPointerElsewhereLocked(target, null, ev, ev.getEventTime(), false);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005203
Dianne Hackborn6adba242009-11-10 11:10:09 -08005204 final Rect frame = target.mFrame;
5205 ev.offsetLocation(-(float)frame.left, -(float)frame.top);
5206 mKeyWaiter.bindTargetWindowLocked(target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005207 }
5208 }
Romain Guy06882f82009-06-10 13:36:04 -07005209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005210 // finally offset the event to the target's coordinate system and
5211 // dispatch the event.
5212 try {
5213 if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005214 Slog.v(TAG, "Delivering pointer " + qev + " to " + target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005215 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005216
Michael Chan53071d62009-05-13 17:29:48 -07005217 if (MEASURE_LATENCY) {
5218 lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano);
5219 }
5220
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005221 target.mClient.dispatchPointer(ev, eventTime, true);
Michael Chan53071d62009-05-13 17:29:48 -07005222
5223 if (MEASURE_LATENCY) {
5224 lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano);
5225 }
Dianne Hackborncfaef692009-06-15 14:24:44 -07005226 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005227 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005228 Slog.i(TAG, "WINDOW DIED during motion dispatch: " + target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005229 mKeyWaiter.mMotionTarget = null;
5230 try {
5231 removeWindow(target.mSession, target.mClient);
5232 } catch (java.util.NoSuchElementException ex) {
5233 // This will happen if the window has already been
5234 // removed.
5235 }
5236 }
Dianne Hackborncfaef692009-06-15 14:24:44 -07005237 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005238 }
Romain Guy06882f82009-06-10 13:36:04 -07005239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005240 /**
5241 * @return Returns true if event was dispatched, false if it was dropped for any reason
5242 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07005243 private int dispatchTrackball(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005244 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005245 TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">");
Romain Guy06882f82009-06-10 13:36:04 -07005246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005247 Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005248 ev, false, false, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005249 if (focusObj == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005250 Slog.w(TAG, "No focus window, dropping trackball: " + ev);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005251 if (qev != null) {
5252 mQueue.recycleEvent(qev);
5253 }
5254 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005255 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005256 }
5257 if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
5258 if (qev != null) {
5259 mQueue.recycleEvent(qev);
5260 }
5261 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005262 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005263 }
Romain Guy06882f82009-06-10 13:36:04 -07005264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005265 WindowState focus = (WindowState)focusObj;
Romain Guy06882f82009-06-10 13:36:04 -07005266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005267 if (uid != 0 && uid != focus.mSession.mUid) {
5268 if (mContext.checkPermission(
5269 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5270 != PackageManager.PERMISSION_GRANTED) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005271 Slog.w(TAG, "Permission denied: injecting key event from pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005272 + pid + " uid " + uid + " to window " + focus
5273 + " owned by uid " + focus.mSession.mUid);
5274 if (qev != null) {
5275 mQueue.recycleEvent(qev);
5276 }
5277 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005278 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005279 }
5280 }
Romain Guy06882f82009-06-10 13:36:04 -07005281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005282 final long eventTime = ev.getEventTime();
Romain Guy06882f82009-06-10 13:36:04 -07005283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005284 synchronized(mWindowMap) {
5285 if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) {
5286 mKeyWaiter.bindTargetWindowLocked(focus,
5287 KeyWaiter.RETURN_PENDING_TRACKBALL, qev);
5288 // We don't deliver movement events to the client, we hold
5289 // them and wait for them to call back.
5290 ev = null;
5291 } else {
5292 mKeyWaiter.bindTargetWindowLocked(focus);
5293 }
5294 }
Romain Guy06882f82009-06-10 13:36:04 -07005295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005296 try {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005297 focus.mClient.dispatchTrackball(ev, eventTime, true);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005298 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005299 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005300 Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005301 try {
5302 removeWindow(focus.mSession, focus.mClient);
5303 } catch (java.util.NoSuchElementException ex) {
5304 // This will happen if the window has already been
5305 // removed.
5306 }
5307 }
Romain Guy06882f82009-06-10 13:36:04 -07005308
Dianne Hackborncfaef692009-06-15 14:24:44 -07005309 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005310 }
Romain Guy06882f82009-06-10 13:36:04 -07005311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005312 /**
5313 * @return Returns true if event was dispatched, false if it was dropped for any reason
5314 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07005315 private int dispatchKey(KeyEvent event, int pid, int uid) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005316 if (DEBUG_INPUT) Slog.v(TAG, "Dispatch key: " + event);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005317
5318 Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005319 null, false, false, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005320 if (focusObj == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005321 Slog.w(TAG, "No focus window, dropping: " + event);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005322 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005323 }
5324 if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005325 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005326 }
Romain Guy06882f82009-06-10 13:36:04 -07005327
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07005328 // Okay we have finished waiting for the last event to be processed.
5329 // First off, if this is a repeat event, check to see if there is
5330 // a corresponding up event in the queue. If there is, we will
5331 // just drop the repeat, because it makes no sense to repeat after
5332 // the user has released a key. (This is especially important for
5333 // long presses.)
5334 if (event.getRepeatCount() > 0 && mQueue.hasKeyUpEvent(event)) {
5335 return INJECT_SUCCEEDED;
5336 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005338 WindowState focus = (WindowState)focusObj;
Romain Guy06882f82009-06-10 13:36:04 -07005339
Joe Onorato8a9b2202010-02-26 18:56:32 -08005340 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005341 TAG, "Dispatching to " + focus + ": " + event);
5342
5343 if (uid != 0 && uid != focus.mSession.mUid) {
5344 if (mContext.checkPermission(
5345 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5346 != PackageManager.PERMISSION_GRANTED) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005347 Slog.w(TAG, "Permission denied: injecting key event from pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005348 + pid + " uid " + uid + " to window " + focus
5349 + " owned by uid " + focus.mSession.mUid);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005350 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005351 }
5352 }
Romain Guy06882f82009-06-10 13:36:04 -07005353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005354 synchronized(mWindowMap) {
5355 mKeyWaiter.bindTargetWindowLocked(focus);
5356 }
5357
5358 // NOSHIP extra state logging
5359 mKeyWaiter.recordDispatchState(event, focus);
5360 // END NOSHIP
Romain Guy06882f82009-06-10 13:36:04 -07005361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005362 try {
5363 if (DEBUG_INPUT || DEBUG_FOCUS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005364 Slog.v(TAG, "Delivering key " + event.getKeyCode()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005365 + " to " + focus);
5366 }
5367 focus.mClient.dispatchKey(event);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005368 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005369 } catch (android.os.RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005370 Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005371 try {
5372 removeWindow(focus.mSession, focus.mClient);
5373 } catch (java.util.NoSuchElementException ex) {
5374 // This will happen if the window has already been
5375 // removed.
5376 }
5377 }
Romain Guy06882f82009-06-10 13:36:04 -07005378
Dianne Hackborncfaef692009-06-15 14:24:44 -07005379 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005380 }
Romain Guy06882f82009-06-10 13:36:04 -07005381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005382 public void pauseKeyDispatching(IBinder _token) {
5383 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5384 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005385 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005386 }
5387
5388 synchronized (mWindowMap) {
5389 WindowToken token = mTokenMap.get(_token);
5390 if (token != null) {
5391 mKeyWaiter.pauseDispatchingLocked(token);
5392 }
5393 }
5394 }
5395
5396 public void resumeKeyDispatching(IBinder _token) {
5397 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5398 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005399 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005400 }
5401
5402 synchronized (mWindowMap) {
5403 WindowToken token = mTokenMap.get(_token);
5404 if (token != null) {
5405 mKeyWaiter.resumeDispatchingLocked(token);
5406 }
5407 }
5408 }
5409
5410 public void setEventDispatching(boolean enabled) {
5411 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5412 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005413 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005414 }
5415
5416 synchronized (mWindowMap) {
5417 mKeyWaiter.setEventDispatchingLocked(enabled);
5418 }
5419 }
Romain Guy06882f82009-06-10 13:36:04 -07005420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005421 /**
5422 * Injects a keystroke event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005423 *
5424 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005425 * {@link SystemClock#uptimeMillis()} as the timebase.)
5426 * @param sync If true, wait for the event to be completed before returning to the caller.
5427 * @return Returns true if event was dispatched, false if it was dropped for any reason
5428 */
5429 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5430 long downTime = ev.getDownTime();
5431 long eventTime = ev.getEventTime();
5432
5433 int action = ev.getAction();
5434 int code = ev.getKeyCode();
5435 int repeatCount = ev.getRepeatCount();
5436 int metaState = ev.getMetaState();
5437 int deviceId = ev.getDeviceId();
5438 int scancode = ev.getScanCode();
5439
5440 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5441 if (downTime == 0) downTime = eventTime;
5442
5443 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
The Android Open Source Project10592532009-03-18 17:39:46 -07005444 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005445
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005446 final int pid = Binder.getCallingPid();
5447 final int uid = Binder.getCallingUid();
5448 final long ident = Binder.clearCallingIdentity();
5449 final int result = dispatchKey(newEvent, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005450 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005451 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005452 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005453 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005454 switch (result) {
5455 case INJECT_NO_PERMISSION:
5456 throw new SecurityException(
Chander S Pechetty27f3de62010-02-10 22:14:00 +05305457 "Injecting to another application requires INJECT_EVENTS permission");
Dianne Hackborncfaef692009-06-15 14:24:44 -07005458 case INJECT_SUCCEEDED:
5459 return true;
5460 }
5461 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005462 }
5463
5464 /**
5465 * Inject a pointer (touch) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005466 *
5467 * @param ev A motion event describing the pointer (touch) action. (As noted in
5468 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005469 * {@link SystemClock#uptimeMillis()} as the timebase.)
5470 * @param sync If true, wait for the event to be completed before returning to the caller.
5471 * @return Returns true if event was dispatched, false if it was dropped for any reason
5472 */
5473 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005474 final int pid = Binder.getCallingPid();
5475 final int uid = Binder.getCallingUid();
5476 final long ident = Binder.clearCallingIdentity();
5477 final int result = dispatchPointer(null, ev, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005478 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005479 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005480 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005481 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005482 switch (result) {
5483 case INJECT_NO_PERMISSION:
5484 throw new SecurityException(
Chander S Pechetty27f3de62010-02-10 22:14:00 +05305485 "Injecting to another application requires INJECT_EVENTS permission");
Dianne Hackborncfaef692009-06-15 14:24:44 -07005486 case INJECT_SUCCEEDED:
5487 return true;
5488 }
5489 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005490 }
Romain Guy06882f82009-06-10 13:36:04 -07005491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005492 /**
5493 * Inject a trackball (navigation device) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005494 *
5495 * @param ev A motion event describing the trackball action. (As noted in
5496 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005497 * {@link SystemClock#uptimeMillis()} as the timebase.)
5498 * @param sync If true, wait for the event to be completed before returning to the caller.
5499 * @return Returns true if event was dispatched, false if it was dropped for any reason
5500 */
5501 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005502 final int pid = Binder.getCallingPid();
5503 final int uid = Binder.getCallingUid();
5504 final long ident = Binder.clearCallingIdentity();
5505 final int result = dispatchTrackball(null, ev, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005506 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005507 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005508 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005509 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005510 switch (result) {
5511 case INJECT_NO_PERMISSION:
5512 throw new SecurityException(
Chander S Pechetty27f3de62010-02-10 22:14:00 +05305513 "Injecting to another application requires INJECT_EVENTS permission");
Dianne Hackborncfaef692009-06-15 14:24:44 -07005514 case INJECT_SUCCEEDED:
5515 return true;
5516 }
5517 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005518 }
Romain Guy06882f82009-06-10 13:36:04 -07005519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005520 private WindowState getFocusedWindow() {
5521 synchronized (mWindowMap) {
5522 return getFocusedWindowLocked();
5523 }
5524 }
5525
5526 private WindowState getFocusedWindowLocked() {
5527 return mCurrentFocus;
5528 }
Romain Guy06882f82009-06-10 13:36:04 -07005529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005530 /**
5531 * This class holds the state for dispatching key events. This state
5532 * is protected by the KeyWaiter instance, NOT by the window lock. You
5533 * can be holding the main window lock while acquire the KeyWaiter lock,
5534 * but not the other way around.
5535 */
5536 final class KeyWaiter {
5537 // NOSHIP debugging
5538 public class DispatchState {
5539 private KeyEvent event;
5540 private WindowState focus;
5541 private long time;
5542 private WindowState lastWin;
5543 private IBinder lastBinder;
5544 private boolean finished;
5545 private boolean gotFirstWindow;
5546 private boolean eventDispatching;
5547 private long timeToSwitch;
5548 private boolean wasFrozen;
5549 private boolean focusPaused;
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005550 private WindowState curFocus;
Romain Guy06882f82009-06-10 13:36:04 -07005551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005552 DispatchState(KeyEvent theEvent, WindowState theFocus) {
5553 focus = theFocus;
5554 event = theEvent;
5555 time = System.currentTimeMillis();
5556 // snapshot KeyWaiter state
5557 lastWin = mLastWin;
5558 lastBinder = mLastBinder;
5559 finished = mFinished;
5560 gotFirstWindow = mGotFirstWindow;
5561 eventDispatching = mEventDispatching;
5562 timeToSwitch = mTimeToSwitch;
5563 wasFrozen = mWasFrozen;
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005564 curFocus = mCurrentFocus;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005565 // cache the paused state at ctor time as well
5566 if (theFocus == null || theFocus.mToken == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005567 focusPaused = false;
5568 } else {
5569 focusPaused = theFocus.mToken.paused;
5570 }
5571 }
Romain Guy06882f82009-06-10 13:36:04 -07005572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005573 public String toString() {
5574 return "{{" + event + " to " + focus + " @ " + time
5575 + " lw=" + lastWin + " lb=" + lastBinder
5576 + " fin=" + finished + " gfw=" + gotFirstWindow
5577 + " ed=" + eventDispatching + " tts=" + timeToSwitch
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005578 + " wf=" + wasFrozen + " fp=" + focusPaused
Christopher Tate46d45252010-02-09 15:48:57 -08005579 + " mcf=" + curFocus + "}}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005580 }
5581 };
5582 private DispatchState mDispatchState = null;
5583 public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) {
5584 mDispatchState = new DispatchState(theEvent, theFocus);
5585 }
5586 // END NOSHIP
5587
5588 public static final int RETURN_NOTHING = 0;
5589 public static final int RETURN_PENDING_POINTER = 1;
5590 public static final int RETURN_PENDING_TRACKBALL = 2;
Romain Guy06882f82009-06-10 13:36:04 -07005591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005592 final Object SKIP_TARGET_TOKEN = new Object();
5593 final Object CONSUMED_EVENT_TOKEN = new Object();
Romain Guy06882f82009-06-10 13:36:04 -07005594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005595 private WindowState mLastWin = null;
5596 private IBinder mLastBinder = null;
5597 private boolean mFinished = true;
5598 private boolean mGotFirstWindow = false;
5599 private boolean mEventDispatching = true;
5600 private long mTimeToSwitch = 0;
5601 /* package */ boolean mWasFrozen = false;
Romain Guy06882f82009-06-10 13:36:04 -07005602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005603 // Target of Motion events
5604 WindowState mMotionTarget;
Romain Guy06882f82009-06-10 13:36:04 -07005605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005606 // Windows above the target who would like to receive an "outside"
5607 // touch event for any down events outside of them.
5608 WindowState mOutsideTouchTargets;
5609
5610 /**
5611 * Wait for the last event dispatch to complete, then find the next
5612 * target that should receive the given event and wait for that one
5613 * to be ready to receive it.
5614 */
5615 Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev,
5616 MotionEvent nextMotion, boolean isPointerEvent,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005617 boolean failIfTimeout, int callingPid, int callingUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005618 long startTime = SystemClock.uptimeMillis();
5619 long keyDispatchingTimeout = 5 * 1000;
5620 long waitedFor = 0;
5621
5622 while (true) {
5623 // Figure out which window we care about. It is either the
5624 // last window we are waiting to have process the event or,
5625 // if none, then the next window we think the event should go
5626 // to. Note: we retrieve mLastWin outside of the lock, so
5627 // it may change before we lock. Thus we must check it again.
5628 WindowState targetWin = mLastWin;
5629 boolean targetIsNew = targetWin == null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005630 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005631 TAG, "waitForLastKey: mFinished=" + mFinished +
5632 ", mLastWin=" + mLastWin);
5633 if (targetIsNew) {
5634 Object target = findTargetWindow(nextKey, qev, nextMotion,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005635 isPointerEvent, callingPid, callingUid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005636 if (target == SKIP_TARGET_TOKEN) {
5637 // The user has pressed a special key, and we are
5638 // dropping all pending events before it.
Joe Onorato8a9b2202010-02-26 18:56:32 -08005639 if (DEBUG_INPUT) Slog.v(TAG, "Skipping: " + nextKey
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005640 + " " + nextMotion);
5641 return null;
5642 }
5643 if (target == CONSUMED_EVENT_TOKEN) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005644 if (DEBUG_INPUT) Slog.v(TAG, "Consumed: " + nextKey
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005645 + " " + nextMotion);
5646 return target;
5647 }
5648 targetWin = (WindowState)target;
5649 }
Romain Guy06882f82009-06-10 13:36:04 -07005650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005651 AppWindowToken targetApp = null;
Romain Guy06882f82009-06-10 13:36:04 -07005652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005653 // Now: is it okay to send the next event to this window?
5654 synchronized (this) {
5655 // First: did we come here based on the last window not
5656 // being null, but it changed by the time we got here?
5657 // If so, try again.
5658 if (!targetIsNew && mLastWin == null) {
5659 continue;
5660 }
Romain Guy06882f82009-06-10 13:36:04 -07005661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005662 // We never dispatch events if not finished with the
5663 // last one, or the display is frozen.
5664 if (mFinished && !mDisplayFrozen) {
5665 // If event dispatching is disabled, then we
5666 // just consume the events.
5667 if (!mEventDispatching) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005668 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005669 "Skipping event; dispatching disabled: "
5670 + nextKey + " " + nextMotion);
5671 return null;
5672 }
5673 if (targetWin != null) {
5674 // If this is a new target, and that target is not
5675 // paused or unresponsive, then all looks good to
5676 // handle the event.
5677 if (targetIsNew && !targetWin.mToken.paused) {
5678 return targetWin;
5679 }
Romain Guy06882f82009-06-10 13:36:04 -07005680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005681 // If we didn't find a target window, and there is no
5682 // focused app window, then just eat the events.
5683 } else if (mFocusedApp == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005684 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005685 "Skipping event; no focused app: "
5686 + nextKey + " " + nextMotion);
5687 return null;
5688 }
5689 }
Romain Guy06882f82009-06-10 13:36:04 -07005690
Joe Onorato8a9b2202010-02-26 18:56:32 -08005691 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005692 TAG, "Waiting for last key in " + mLastBinder
5693 + " target=" + targetWin
5694 + " mFinished=" + mFinished
5695 + " mDisplayFrozen=" + mDisplayFrozen
5696 + " targetIsNew=" + targetIsNew
5697 + " paused="
5698 + (targetWin != null ? targetWin.mToken.paused : false)
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005699 + " mFocusedApp=" + mFocusedApp
5700 + " mCurrentFocus=" + mCurrentFocus);
Romain Guy06882f82009-06-10 13:36:04 -07005701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005702 targetApp = targetWin != null
5703 ? targetWin.mAppToken : mFocusedApp;
Romain Guy06882f82009-06-10 13:36:04 -07005704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005705 long curTimeout = keyDispatchingTimeout;
5706 if (mTimeToSwitch != 0) {
5707 long now = SystemClock.uptimeMillis();
5708 if (mTimeToSwitch <= now) {
5709 // If an app switch key has been pressed, and we have
5710 // waited too long for the current app to finish
5711 // processing keys, then wait no more!
Christopher Tate136b1f92010-02-11 17:51:24 -08005712 doFinishedKeyLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005713 continue;
5714 }
5715 long switchTimeout = mTimeToSwitch - now;
5716 if (curTimeout > switchTimeout) {
5717 curTimeout = switchTimeout;
5718 }
5719 }
Romain Guy06882f82009-06-10 13:36:04 -07005720
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005721 try {
5722 // after that continue
5723 // processing keys, so we don't get stuck.
Joe Onorato8a9b2202010-02-26 18:56:32 -08005724 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005725 TAG, "Waiting for key dispatch: " + curTimeout);
5726 wait(curTimeout);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005727 if (DEBUG_INPUT) Slog.v(TAG, "Finished waiting @"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005728 + SystemClock.uptimeMillis() + " startTime="
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005729 + startTime + " switchTime=" + mTimeToSwitch
5730 + " target=" + targetWin + " mLW=" + mLastWin
5731 + " mLB=" + mLastBinder + " fin=" + mFinished
5732 + " mCurrentFocus=" + mCurrentFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005733 } catch (InterruptedException e) {
5734 }
5735 }
5736
5737 // If we were frozen during configuration change, restart the
5738 // timeout checks from now; otherwise look at whether we timed
5739 // out before awakening.
5740 if (mWasFrozen) {
5741 waitedFor = 0;
5742 mWasFrozen = false;
5743 } else {
5744 waitedFor = SystemClock.uptimeMillis() - startTime;
5745 }
5746
5747 if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) {
5748 IApplicationToken at = null;
5749 synchronized (this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005750 Slog.w(TAG, "Key dispatching timed out sending to " +
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005751 (targetWin != null ? targetWin.mAttrs.getTitle()
Ken Shirriff8200b202010-02-04 13:34:37 -08005752 : "<null>: no window ready for key dispatch"));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005753 // NOSHIP debugging
Joe Onorato8a9b2202010-02-26 18:56:32 -08005754 Slog.w(TAG, "Previous dispatch state: " + mDispatchState);
5755 Slog.w(TAG, "Current dispatch state: " +
Ken Shirriff8200b202010-02-04 13:34:37 -08005756 new DispatchState(nextKey, targetWin));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005757 // END NOSHIP
5758 //dump();
5759 if (targetWin != null) {
5760 at = targetWin.getAppToken();
5761 } else if (targetApp != null) {
5762 at = targetApp.appToken;
5763 }
5764 }
5765
5766 boolean abort = true;
5767 if (at != null) {
5768 try {
5769 long timeout = at.getKeyDispatchingTimeout();
5770 if (timeout > waitedFor) {
5771 // we did not wait the proper amount of time for this application.
5772 // set the timeout to be the real timeout and wait again.
5773 keyDispatchingTimeout = timeout - waitedFor;
5774 continue;
5775 } else {
5776 abort = at.keyDispatchingTimedOut();
5777 }
5778 } catch (RemoteException ex) {
5779 }
5780 }
5781
5782 synchronized (this) {
5783 if (abort && (mLastWin == targetWin || targetWin == null)) {
5784 mFinished = true;
Romain Guy06882f82009-06-10 13:36:04 -07005785 if (mLastWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005786 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005787 "Window " + mLastWin +
5788 " timed out on key input");
5789 if (mLastWin.mToken.paused) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005790 Slog.w(TAG, "Un-pausing dispatching to this window");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005791 mLastWin.mToken.paused = false;
5792 }
5793 }
5794 if (mMotionTarget == targetWin) {
5795 mMotionTarget = null;
5796 }
5797 mLastWin = null;
5798 mLastBinder = null;
5799 if (failIfTimeout || targetWin == null) {
5800 return null;
5801 }
5802 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005803 Slog.w(TAG, "Continuing to wait for key to be dispatched");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005804 startTime = SystemClock.uptimeMillis();
5805 }
5806 }
5807 }
5808 }
5809 }
Romain Guy06882f82009-06-10 13:36:04 -07005810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005811 Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005812 MotionEvent nextMotion, boolean isPointerEvent,
5813 int callingPid, int callingUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005814 mOutsideTouchTargets = null;
Romain Guy06882f82009-06-10 13:36:04 -07005815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005816 if (nextKey != null) {
5817 // Find the target window for a normal key event.
5818 final int keycode = nextKey.getKeyCode();
5819 final int repeatCount = nextKey.getRepeatCount();
5820 final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP;
5821 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005823 if (!dispatch) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005824 if (callingUid == 0 ||
5825 mContext.checkPermission(
5826 android.Manifest.permission.INJECT_EVENTS,
5827 callingPid, callingUid)
5828 == PackageManager.PERMISSION_GRANTED) {
5829 mPolicy.interceptKeyTi(null, keycode,
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07005830 nextKey.getMetaState(), down, repeatCount,
5831 nextKey.getFlags());
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005832 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08005833 Slog.w(TAG, "Event timeout during app switch: dropping "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005834 + nextKey);
5835 return SKIP_TARGET_TOKEN;
5836 }
Romain Guy06882f82009-06-10 13:36:04 -07005837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005838 // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")");
Romain Guy06882f82009-06-10 13:36:04 -07005839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005840 WindowState focus = null;
5841 synchronized(mWindowMap) {
5842 focus = getFocusedWindowLocked();
5843 }
Romain Guy06882f82009-06-10 13:36:04 -07005844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005845 wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT);
Romain Guy06882f82009-06-10 13:36:04 -07005846
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005847 if (callingUid == 0 ||
5848 (focus != null && callingUid == focus.mSession.mUid) ||
5849 mContext.checkPermission(
5850 android.Manifest.permission.INJECT_EVENTS,
5851 callingPid, callingUid)
5852 == PackageManager.PERMISSION_GRANTED) {
5853 if (mPolicy.interceptKeyTi(focus,
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005854 keycode, nextKey.getMetaState(), down, repeatCount,
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07005855 nextKey.getFlags())) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005856 return CONSUMED_EVENT_TOKEN;
5857 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005858 }
Romain Guy06882f82009-06-10 13:36:04 -07005859
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005860 return focus;
Romain Guy06882f82009-06-10 13:36:04 -07005861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005862 } else if (!isPointerEvent) {
5863 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1);
5864 if (!dispatch) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005865 Slog.w(TAG, "Event timeout during app switch: dropping trackball "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005866 + nextMotion);
5867 return SKIP_TARGET_TOKEN;
5868 }
Romain Guy06882f82009-06-10 13:36:04 -07005869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005870 WindowState focus = null;
5871 synchronized(mWindowMap) {
5872 focus = getFocusedWindowLocked();
5873 }
Romain Guy06882f82009-06-10 13:36:04 -07005874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005875 wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT);
5876 return focus;
5877 }
Romain Guy06882f82009-06-10 13:36:04 -07005878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005879 if (nextMotion == null) {
5880 return SKIP_TARGET_TOKEN;
5881 }
Romain Guy06882f82009-06-10 13:36:04 -07005882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005883 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(
5884 KeyEvent.KEYCODE_UNKNOWN);
5885 if (!dispatch) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005886 Slog.w(TAG, "Event timeout during app switch: dropping pointer "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005887 + nextMotion);
5888 return SKIP_TARGET_TOKEN;
5889 }
Romain Guy06882f82009-06-10 13:36:04 -07005890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005891 // Find the target window for a pointer event.
5892 int action = nextMotion.getAction();
5893 final float xf = nextMotion.getX();
5894 final float yf = nextMotion.getY();
5895 final long eventTime = nextMotion.getEventTime();
Romain Guy06882f82009-06-10 13:36:04 -07005896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005897 final boolean screenWasOff = qev != null
5898 && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07005899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005900 WindowState target = null;
Romain Guy06882f82009-06-10 13:36:04 -07005901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005902 synchronized(mWindowMap) {
5903 synchronized (this) {
5904 if (action == MotionEvent.ACTION_DOWN) {
5905 if (mMotionTarget != null) {
5906 // this is weird, we got a pen down, but we thought it was
5907 // already down!
5908 // XXX: We should probably send an ACTION_UP to the current
5909 // target.
Joe Onorato8a9b2202010-02-26 18:56:32 -08005910 Slog.w(TAG, "Pointer down received while already down in: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005911 + mMotionTarget);
5912 mMotionTarget = null;
5913 }
Romain Guy06882f82009-06-10 13:36:04 -07005914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005915 // ACTION_DOWN is special, because we need to lock next events to
5916 // the window we'll land onto.
5917 final int x = (int)xf;
5918 final int y = (int)yf;
Romain Guy06882f82009-06-10 13:36:04 -07005919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005920 final ArrayList windows = mWindows;
5921 final int N = windows.size();
5922 WindowState topErrWindow = null;
5923 final Rect tmpRect = mTempRect;
5924 for (int i=N-1; i>=0; i--) {
5925 WindowState child = (WindowState)windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005926 //Slog.i(TAG, "Checking dispatch to: " + child);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005927 final int flags = child.mAttrs.flags;
5928 if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) {
5929 if (topErrWindow == null) {
5930 topErrWindow = child;
5931 }
5932 }
5933 if (!child.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005934 //Slog.i(TAG, "Not visible!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005935 continue;
5936 }
5937 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005938 //Slog.i(TAG, "Not touchable!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005939 if ((flags & WindowManager.LayoutParams
5940 .FLAG_WATCH_OUTSIDE_TOUCH) != 0) {
5941 child.mNextOutsideTouch = mOutsideTouchTargets;
5942 mOutsideTouchTargets = child;
5943 }
5944 continue;
5945 }
5946 tmpRect.set(child.mFrame);
5947 if (child.mTouchableInsets == ViewTreeObserver
5948 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
5949 // The touch is inside of the window if it is
5950 // inside the frame, AND the content part of that
5951 // frame that was given by the application.
5952 tmpRect.left += child.mGivenContentInsets.left;
5953 tmpRect.top += child.mGivenContentInsets.top;
5954 tmpRect.right -= child.mGivenContentInsets.right;
5955 tmpRect.bottom -= child.mGivenContentInsets.bottom;
5956 } else if (child.mTouchableInsets == ViewTreeObserver
5957 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
5958 // The touch is inside of the window if it is
5959 // inside the frame, AND the visible part of that
5960 // frame that was given by the application.
5961 tmpRect.left += child.mGivenVisibleInsets.left;
5962 tmpRect.top += child.mGivenVisibleInsets.top;
5963 tmpRect.right -= child.mGivenVisibleInsets.right;
5964 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
5965 }
5966 final int touchFlags = flags &
5967 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
5968 |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
5969 if (tmpRect.contains(x, y) || touchFlags == 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005970 //Slog.i(TAG, "Using this target!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005971 if (!screenWasOff || (flags &
5972 WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) {
5973 mMotionTarget = child;
5974 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005975 //Slog.i(TAG, "Waking, skip!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005976 mMotionTarget = null;
5977 }
5978 break;
5979 }
Romain Guy06882f82009-06-10 13:36:04 -07005980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005981 if ((flags & WindowManager.LayoutParams
5982 .FLAG_WATCH_OUTSIDE_TOUCH) != 0) {
5983 child.mNextOutsideTouch = mOutsideTouchTargets;
5984 mOutsideTouchTargets = child;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005985 //Slog.i(TAG, "Adding to outside target list: " + child);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005986 }
5987 }
5988
5989 // if there's an error window but it's not accepting
5990 // focus (typically because it is not yet visible) just
5991 // wait for it -- any other focused window may in fact
5992 // be in ANR state.
5993 if (topErrWindow != null && mMotionTarget != topErrWindow) {
5994 mMotionTarget = null;
5995 }
5996 }
Romain Guy06882f82009-06-10 13:36:04 -07005997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005998 target = mMotionTarget;
5999 }
6000 }
Romain Guy06882f82009-06-10 13:36:04 -07006001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006002 wakeupIfNeeded(target, eventType(nextMotion));
Romain Guy06882f82009-06-10 13:36:04 -07006003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006004 // Pointer events are a little different -- if there isn't a
6005 // target found for any event, then just drop it.
6006 return target != null ? target : SKIP_TARGET_TOKEN;
6007 }
Romain Guy06882f82009-06-10 13:36:04 -07006008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006009 boolean checkShouldDispatchKey(int keycode) {
6010 synchronized (this) {
6011 if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) {
6012 mTimeToSwitch = 0;
6013 return true;
6014 }
6015 if (mTimeToSwitch != 0
6016 && mTimeToSwitch < SystemClock.uptimeMillis()) {
6017 return false;
6018 }
6019 return true;
6020 }
6021 }
Romain Guy06882f82009-06-10 13:36:04 -07006022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006023 void bindTargetWindowLocked(WindowState win,
6024 int pendingWhat, QueuedEvent pendingMotion) {
6025 synchronized (this) {
6026 bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion);
6027 }
6028 }
Romain Guy06882f82009-06-10 13:36:04 -07006029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006030 void bindTargetWindowLocked(WindowState win) {
6031 synchronized (this) {
6032 bindTargetWindowLockedLocked(win, RETURN_NOTHING, null);
6033 }
6034 }
6035
6036 void bindTargetWindowLockedLocked(WindowState win,
6037 int pendingWhat, QueuedEvent pendingMotion) {
6038 mLastWin = win;
6039 mLastBinder = win.mClient.asBinder();
6040 mFinished = false;
6041 if (pendingMotion != null) {
6042 final Session s = win.mSession;
6043 if (pendingWhat == RETURN_PENDING_POINTER) {
6044 releasePendingPointerLocked(s);
6045 s.mPendingPointerMove = pendingMotion;
6046 s.mPendingPointerWindow = win;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006047 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006048 "bindTargetToWindow " + s.mPendingPointerMove);
6049 } else if (pendingWhat == RETURN_PENDING_TRACKBALL) {
6050 releasePendingTrackballLocked(s);
6051 s.mPendingTrackballMove = pendingMotion;
6052 s.mPendingTrackballWindow = win;
6053 }
6054 }
6055 }
Romain Guy06882f82009-06-10 13:36:04 -07006056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006057 void releasePendingPointerLocked(Session s) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006058 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006059 "releasePendingPointer " + s.mPendingPointerMove);
6060 if (s.mPendingPointerMove != null) {
6061 mQueue.recycleEvent(s.mPendingPointerMove);
6062 s.mPendingPointerMove = null;
6063 }
6064 }
Romain Guy06882f82009-06-10 13:36:04 -07006065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006066 void releasePendingTrackballLocked(Session s) {
6067 if (s.mPendingTrackballMove != null) {
6068 mQueue.recycleEvent(s.mPendingTrackballMove);
6069 s.mPendingTrackballMove = null;
6070 }
6071 }
Romain Guy06882f82009-06-10 13:36:04 -07006072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006073 MotionEvent finishedKey(Session session, IWindow client, boolean force,
6074 int returnWhat) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006075 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006076 TAG, "finishedKey: client=" + client + ", force=" + force);
6077
6078 if (client == null) {
6079 return null;
6080 }
6081
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006082 MotionEvent res = null;
6083 QueuedEvent qev = null;
6084 WindowState win = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006086 synchronized (this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006087 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006088 TAG, "finishedKey: client=" + client.asBinder()
6089 + ", force=" + force + ", last=" + mLastBinder
6090 + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")");
6091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006092 if (returnWhat == RETURN_PENDING_POINTER) {
6093 qev = session.mPendingPointerMove;
6094 win = session.mPendingPointerWindow;
6095 session.mPendingPointerMove = null;
6096 session.mPendingPointerWindow = null;
6097 } else if (returnWhat == RETURN_PENDING_TRACKBALL) {
6098 qev = session.mPendingTrackballMove;
6099 win = session.mPendingTrackballWindow;
6100 session.mPendingTrackballMove = null;
6101 session.mPendingTrackballWindow = null;
6102 }
Romain Guy06882f82009-06-10 13:36:04 -07006103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006104 if (mLastBinder == client.asBinder()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006105 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006106 TAG, "finishedKey: last paused="
6107 + ((mLastWin != null) ? mLastWin.mToken.paused : "null"));
6108 if (mLastWin != null && (!mLastWin.mToken.paused || force
6109 || !mEventDispatching)) {
Christopher Tate136b1f92010-02-11 17:51:24 -08006110 doFinishedKeyLocked(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006111 } else {
6112 // Make sure to wake up anyone currently waiting to
6113 // dispatch a key, so they can re-evaluate their
6114 // current situation.
6115 mFinished = true;
6116 notifyAll();
6117 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006118 }
Romain Guy06882f82009-06-10 13:36:04 -07006119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006120 if (qev != null) {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006121 res = (MotionEvent)qev.event;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006122 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006123 "Returning pending motion: " + res);
6124 mQueue.recycleEvent(qev);
6125 if (win != null && returnWhat == RETURN_PENDING_POINTER) {
6126 res.offsetLocation(-win.mFrame.left, -win.mFrame.top);
6127 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006128 }
Christopher Tate2624fbc2009-12-11 12:11:31 -08006129 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006130
Christopher Tate2624fbc2009-12-11 12:11:31 -08006131 if (res != null && returnWhat == RETURN_PENDING_POINTER) {
6132 synchronized (mWindowMap) {
Dianne Hackborn90d2db32010-02-11 22:19:06 -08006133 dispatchPointerElsewhereLocked(win, win, res, res.getEventTime(), false);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006134 }
6135 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006136
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006137 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006138 }
6139
6140 void tickle() {
6141 synchronized (this) {
6142 notifyAll();
6143 }
6144 }
Romain Guy06882f82009-06-10 13:36:04 -07006145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006146 void handleNewWindowLocked(WindowState newWindow) {
6147 if (!newWindow.canReceiveKeys()) {
6148 return;
6149 }
6150 synchronized (this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006151 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006152 TAG, "New key dispatch window: win="
6153 + newWindow.mClient.asBinder()
6154 + ", last=" + mLastBinder
6155 + " (token=" + (mLastWin != null ? mLastWin.mToken : null)
6156 + "), finished=" + mFinished + ", paused="
6157 + newWindow.mToken.paused);
6158
6159 // Displaying a window implicitly causes dispatching to
6160 // be unpaused. (This is to protect against bugs if someone
6161 // pauses dispatching but forgets to resume.)
6162 newWindow.mToken.paused = false;
6163
6164 mGotFirstWindow = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006165
6166 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006167 if (DEBUG_INPUT) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006168 "New SYSTEM_ERROR window; resetting state");
6169 mLastWin = null;
6170 mLastBinder = null;
6171 mMotionTarget = null;
6172 mFinished = true;
6173 } else if (mLastWin != null) {
6174 // If the new window is above the window we are
6175 // waiting on, then stop waiting and let key dispatching
6176 // start on the new guy.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006177 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006178 TAG, "Last win layer=" + mLastWin.mLayer
6179 + ", new win layer=" + newWindow.mLayer);
6180 if (newWindow.mLayer >= mLastWin.mLayer) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08006181 // The new window is above the old; finish pending input to the last
6182 // window and start directing it to the new one.
6183 mLastWin.mToken.paused = false;
Christopher Tate136b1f92010-02-11 17:51:24 -08006184 doFinishedKeyLocked(false); // does a notifyAll()
6185 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006186 }
6187 }
6188
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08006189 // Now that we've put a new window state in place, make the event waiter
6190 // take notice and retarget its attentions.
6191 notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006192 }
6193 }
6194
6195 void pauseDispatchingLocked(WindowToken token) {
6196 synchronized (this)
6197 {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006198 if (DEBUG_INPUT) Slog.v(TAG, "Pausing WindowToken " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006199 token.paused = true;
6200
6201 /*
6202 if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) {
6203 mPaused = true;
6204 } else {
6205 if (mLastWin == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006206 Slog.i(TAG, "Key dispatching not paused: no last window.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006207 } else if (mFinished) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006208 Slog.i(TAG, "Key dispatching not paused: finished last key.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006209 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006210 Slog.i(TAG, "Key dispatching not paused: window in higher layer.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006211 }
6212 }
6213 */
6214 }
6215 }
6216
6217 void resumeDispatchingLocked(WindowToken token) {
6218 synchronized (this) {
6219 if (token.paused) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006220 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006221 TAG, "Resuming WindowToken " + token
6222 + ", last=" + mLastBinder
6223 + " (token=" + (mLastWin != null ? mLastWin.mToken : null)
6224 + "), finished=" + mFinished + ", paused="
6225 + token.paused);
6226 token.paused = false;
6227 if (mLastWin != null && mLastWin.mToken == token && mFinished) {
Christopher Tate136b1f92010-02-11 17:51:24 -08006228 doFinishedKeyLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006229 } else {
6230 notifyAll();
6231 }
6232 }
6233 }
6234 }
6235
6236 void setEventDispatchingLocked(boolean enabled) {
6237 synchronized (this) {
6238 mEventDispatching = enabled;
6239 notifyAll();
6240 }
6241 }
Romain Guy06882f82009-06-10 13:36:04 -07006242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006243 void appSwitchComing() {
6244 synchronized (this) {
6245 // Don't wait for more than .5 seconds for app to finish
6246 // processing the pending events.
6247 long now = SystemClock.uptimeMillis() + 500;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006248 if (DEBUG_INPUT) Slog.v(TAG, "appSwitchComing: " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006249 if (mTimeToSwitch == 0 || now < mTimeToSwitch) {
6250 mTimeToSwitch = now;
6251 }
6252 notifyAll();
6253 }
6254 }
Romain Guy06882f82009-06-10 13:36:04 -07006255
Christopher Tate136b1f92010-02-11 17:51:24 -08006256 private final void doFinishedKeyLocked(boolean force) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006257 if (mLastWin != null) {
6258 releasePendingPointerLocked(mLastWin.mSession);
6259 releasePendingTrackballLocked(mLastWin.mSession);
6260 }
Romain Guy06882f82009-06-10 13:36:04 -07006261
Christopher Tate136b1f92010-02-11 17:51:24 -08006262 if (force || mLastWin == null || !mLastWin.mToken.paused
6263 || !mLastWin.isVisibleLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006264 // If the current window has been paused, we aren't -really-
6265 // finished... so let the waiters still wait.
6266 mLastWin = null;
6267 mLastBinder = null;
6268 }
6269 mFinished = true;
6270 notifyAll();
6271 }
6272 }
6273
6274 private class KeyQ extends KeyInputQueue
6275 implements KeyInputQueue.FilterCallback {
6276 PowerManager.WakeLock mHoldingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07006277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006278 KeyQ() {
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07006279 super(mContext, WindowManagerService.this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006280 PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
6281 mHoldingScreen = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
6282 "KEEP_SCREEN_ON_FLAG");
6283 mHoldingScreen.setReferenceCounted(false);
6284 }
6285
6286 @Override
6287 boolean preprocessEvent(InputDevice device, RawInputEvent event) {
6288 if (mPolicy.preprocessInputEventTq(event)) {
6289 return true;
6290 }
Romain Guy06882f82009-06-10 13:36:04 -07006291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006292 switch (event.type) {
6293 case RawInputEvent.EV_KEY: {
6294 // XXX begin hack
6295 if (DEBUG) {
6296 if (event.keycode == KeyEvent.KEYCODE_G) {
6297 if (event.value != 0) {
6298 // G down
6299 mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
6300 }
6301 return false;
6302 }
6303 if (event.keycode == KeyEvent.KEYCODE_D) {
6304 if (event.value != 0) {
6305 //dump();
6306 }
6307 return false;
6308 }
6309 }
6310 // XXX end hack
Romain Guy06882f82009-06-10 13:36:04 -07006311
Charles Mendis322591c2009-10-29 11:06:59 -07006312 boolean screenIsOff = !mPowerManager.isScreenOn();
6313 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006314 int actions = mPolicy.interceptKeyTq(event, !screenIsOff);
Romain Guy06882f82009-06-10 13:36:04 -07006315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006316 if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) {
6317 mPowerManager.goToSleep(event.when);
6318 }
6319
6320 if (screenIsOff) {
6321 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6322 }
6323 if (screenIsDim) {
6324 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6325 }
6326 if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) {
6327 mPowerManager.userActivity(event.when, false,
Michael Chane96440f2009-05-06 10:27:36 -07006328 LocalPowerManager.BUTTON_EVENT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006329 }
Romain Guy06882f82009-06-10 13:36:04 -07006330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006331 if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) {
6332 if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) {
6333 filterQueue(this);
6334 mKeyWaiter.appSwitchComing();
6335 }
6336 return true;
6337 } else {
6338 return false;
6339 }
6340 }
Romain Guy06882f82009-06-10 13:36:04 -07006341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006342 case RawInputEvent.EV_REL: {
Charles Mendis322591c2009-10-29 11:06:59 -07006343 boolean screenIsOff = !mPowerManager.isScreenOn();
6344 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006345 if (screenIsOff) {
6346 if (!mPolicy.isWakeRelMovementTq(event.deviceId,
6347 device.classes, event)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006348 //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006349 return false;
6350 }
6351 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6352 }
6353 if (screenIsDim) {
6354 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6355 }
6356 return true;
6357 }
Romain Guy06882f82009-06-10 13:36:04 -07006358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006359 case RawInputEvent.EV_ABS: {
Charles Mendis322591c2009-10-29 11:06:59 -07006360 boolean screenIsOff = !mPowerManager.isScreenOn();
6361 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006362 if (screenIsOff) {
6363 if (!mPolicy.isWakeAbsMovementTq(event.deviceId,
6364 device.classes, event)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006365 //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006366 return false;
6367 }
6368 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6369 }
6370 if (screenIsDim) {
6371 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6372 }
6373 return true;
6374 }
Romain Guy06882f82009-06-10 13:36:04 -07006375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006376 default:
6377 return true;
6378 }
6379 }
6380
6381 public int filterEvent(QueuedEvent ev) {
6382 switch (ev.classType) {
6383 case RawInputEvent.CLASS_KEYBOARD:
6384 KeyEvent ke = (KeyEvent)ev.event;
6385 if (mPolicy.isMovementKeyTi(ke.getKeyCode())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006386 Slog.w(TAG, "Dropping movement key during app switch: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006387 + ke.getKeyCode() + ", action=" + ke.getAction());
6388 return FILTER_REMOVE;
6389 }
6390 return FILTER_ABORT;
6391 default:
6392 return FILTER_KEEP;
6393 }
6394 }
Romain Guy06882f82009-06-10 13:36:04 -07006395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006396 /**
6397 * Must be called with the main window manager lock held.
6398 */
6399 void setHoldScreenLocked(boolean holding) {
6400 boolean state = mHoldingScreen.isHeld();
6401 if (holding != state) {
6402 if (holding) {
6403 mHoldingScreen.acquire();
6404 } else {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006405 mPolicy.screenOnStoppedLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006406 mHoldingScreen.release();
6407 }
6408 }
6409 }
Michael Chan53071d62009-05-13 17:29:48 -07006410 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006411
6412 public boolean detectSafeMode() {
6413 mSafeMode = mPolicy.detectSafeMode();
6414 return mSafeMode;
6415 }
Romain Guy06882f82009-06-10 13:36:04 -07006416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006417 public void systemReady() {
6418 mPolicy.systemReady();
6419 }
Romain Guy06882f82009-06-10 13:36:04 -07006420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006421 private final class InputDispatcherThread extends Thread {
6422 // Time to wait when there is nothing to do: 9999 seconds.
6423 static final int LONG_WAIT=9999*1000;
6424
6425 public InputDispatcherThread() {
6426 super("InputDispatcher");
6427 }
Romain Guy06882f82009-06-10 13:36:04 -07006428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006429 @Override
6430 public void run() {
6431 while (true) {
6432 try {
6433 process();
6434 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006435 Slog.e(TAG, "Exception in input dispatcher", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006436 }
6437 }
6438 }
Romain Guy06882f82009-06-10 13:36:04 -07006439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006440 private void process() {
6441 android.os.Process.setThreadPriority(
6442 android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);
Romain Guy06882f82009-06-10 13:36:04 -07006443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006444 // The last key event we saw
6445 KeyEvent lastKey = null;
6446
6447 // Last keydown time for auto-repeating keys
6448 long lastKeyTime = SystemClock.uptimeMillis();
6449 long nextKeyTime = lastKeyTime+LONG_WAIT;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006450 long downTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006451
Romain Guy06882f82009-06-10 13:36:04 -07006452 // How many successive repeats we generated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006453 int keyRepeatCount = 0;
6454
6455 // Need to report that configuration has changed?
6456 boolean configChanged = false;
Romain Guy06882f82009-06-10 13:36:04 -07006457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006458 while (true) {
6459 long curTime = SystemClock.uptimeMillis();
6460
Joe Onorato8a9b2202010-02-26 18:56:32 -08006461 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006462 TAG, "Waiting for next key: now=" + curTime
6463 + ", repeat @ " + nextKeyTime);
6464
6465 // Retrieve next event, waiting only as long as the next
6466 // repeat timeout. If the configuration has changed, then
6467 // don't wait at all -- we'll report the change as soon as
6468 // we have processed all events.
6469 QueuedEvent ev = mQueue.getEvent(
6470 (int)((!configChanged && curTime < nextKeyTime)
6471 ? (nextKeyTime-curTime) : 0));
6472
Joe Onorato8a9b2202010-02-26 18:56:32 -08006473 if (DEBUG_INPUT && ev != null) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006474 TAG, "Event: type=" + ev.classType + " data=" + ev.event);
6475
Michael Chan53071d62009-05-13 17:29:48 -07006476 if (MEASURE_LATENCY) {
6477 lt.sample("2 got event ", System.nanoTime() - ev.whenNano);
6478 }
6479
Mike Lockwood3d0ea722009-10-21 22:58:29 -04006480 if (lastKey != null && !mPolicy.allowKeyRepeat()) {
6481 // cancel key repeat at the request of the policy.
6482 lastKey = null;
6483 downTime = 0;
6484 lastKeyTime = curTime;
6485 nextKeyTime = curTime + LONG_WAIT;
6486 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006487 try {
6488 if (ev != null) {
Michael Chan53071d62009-05-13 17:29:48 -07006489 curTime = SystemClock.uptimeMillis();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006490 int eventType;
6491 if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) {
6492 eventType = eventType((MotionEvent)ev.event);
6493 } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD ||
6494 ev.classType == RawInputEvent.CLASS_TRACKBALL) {
6495 eventType = LocalPowerManager.BUTTON_EVENT;
6496 } else {
6497 eventType = LocalPowerManager.OTHER_EVENT;
6498 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07006499 try {
Michael Chan53071d62009-05-13 17:29:48 -07006500 if ((curTime - mLastBatteryStatsCallTime)
Michael Chane96440f2009-05-06 10:27:36 -07006501 >= MIN_TIME_BETWEEN_USERACTIVITIES) {
Michael Chan53071d62009-05-13 17:29:48 -07006502 mLastBatteryStatsCallTime = curTime;
Michael Chane96440f2009-05-06 10:27:36 -07006503 mBatteryStats.noteInputEvent();
6504 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07006505 } catch (RemoteException e) {
6506 // Ignore
6507 }
Michael Chane10de972009-05-18 11:24:50 -07006508
Mike Lockwood5db42402009-11-30 14:51:51 -05006509 if (ev.classType == RawInputEvent.CLASS_CONFIGURATION_CHANGED) {
6510 // do not wake screen in this case
6511 } else if (eventType != TOUCH_EVENT
Michael Chane10de972009-05-18 11:24:50 -07006512 && eventType != LONG_TOUCH_EVENT
6513 && eventType != CHEEK_EVENT) {
6514 mPowerManager.userActivity(curTime, false,
6515 eventType, false);
6516 } else if (mLastTouchEventType != eventType
6517 || (curTime - mLastUserActivityCallTime)
6518 >= MIN_TIME_BETWEEN_USERACTIVITIES) {
6519 mLastUserActivityCallTime = curTime;
6520 mLastTouchEventType = eventType;
6521 mPowerManager.userActivity(curTime, false,
6522 eventType, false);
6523 }
6524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006525 switch (ev.classType) {
6526 case RawInputEvent.CLASS_KEYBOARD:
6527 KeyEvent ke = (KeyEvent)ev.event;
6528 if (ke.isDown()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006529 lastKeyTime = curTime;
Kristian Dreher133bfdf2010-02-23 08:50:58 +01006530 if (lastKey != null &&
6531 ke.getKeyCode() == lastKey.getKeyCode()) {
6532 keyRepeatCount++;
6533 // Arbitrary long timeout to block
6534 // repeating here since we know that
6535 // the device driver takes care of it.
6536 nextKeyTime = lastKeyTime + LONG_WAIT;
The Android Open Source Project2a9ae012010-05-12 12:33:35 -07006537 if (DEBUG_INPUT) Slog.v(
Kristian Dreher133bfdf2010-02-23 08:50:58 +01006538 TAG, "Received repeated key down");
6539 } else {
6540 downTime = curTime;
6541 keyRepeatCount = 0;
6542 nextKeyTime = lastKeyTime
6543 + ViewConfiguration.getLongPressTimeout();
The Android Open Source Project2a9ae012010-05-12 12:33:35 -07006544 if (DEBUG_INPUT) Slog.v(
Kristian Dreher133bfdf2010-02-23 08:50:58 +01006545 TAG, "Received key down: first repeat @ "
6546 + nextKeyTime);
6547 }
6548 lastKey = ke;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006549 } else {
6550 lastKey = null;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006551 downTime = 0;
Kristian Dreher133bfdf2010-02-23 08:50:58 +01006552 keyRepeatCount = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006553 // Arbitrary long timeout.
6554 lastKeyTime = curTime;
6555 nextKeyTime = curTime + LONG_WAIT;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006556 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006557 TAG, "Received key up: ignore repeat @ "
6558 + nextKeyTime);
6559 }
Kristian Dreher133bfdf2010-02-23 08:50:58 +01006560 if (keyRepeatCount > 0) {
6561 dispatchKey(KeyEvent.changeTimeRepeat(ke,
6562 ke.getEventTime(), keyRepeatCount), 0, 0);
6563 } else {
6564 dispatchKey(ke, 0, 0);
6565 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006566 mQueue.recycleEvent(ev);
6567 break;
6568 case RawInputEvent.CLASS_TOUCHSCREEN:
Joe Onorato8a9b2202010-02-26 18:56:32 -08006569 //Slog.i(TAG, "Read next event " + ev);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006570 dispatchPointer(ev, (MotionEvent)ev.event, 0, 0);
6571 break;
6572 case RawInputEvent.CLASS_TRACKBALL:
6573 dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0);
6574 break;
6575 case RawInputEvent.CLASS_CONFIGURATION_CHANGED:
6576 configChanged = true;
6577 break;
6578 default:
6579 mQueue.recycleEvent(ev);
6580 break;
6581 }
Romain Guy06882f82009-06-10 13:36:04 -07006582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006583 } else if (configChanged) {
6584 configChanged = false;
6585 sendNewConfiguration();
Romain Guy06882f82009-06-10 13:36:04 -07006586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006587 } else if (lastKey != null) {
6588 curTime = SystemClock.uptimeMillis();
Romain Guy06882f82009-06-10 13:36:04 -07006589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006590 // Timeout occurred while key was down. If it is at or
6591 // past the key repeat time, dispatch the repeat.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006592 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006593 TAG, "Key timeout: repeat=" + nextKeyTime
6594 + ", now=" + curTime);
6595 if (curTime < nextKeyTime) {
6596 continue;
6597 }
Romain Guy06882f82009-06-10 13:36:04 -07006598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006599 lastKeyTime = nextKeyTime;
6600 nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY;
6601 keyRepeatCount++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006602 if (DEBUG_INPUT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006603 TAG, "Key repeat: count=" + keyRepeatCount
6604 + ", next @ " + nextKeyTime);
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006605 KeyEvent newEvent;
6606 if (downTime != 0 && (downTime
6607 + ViewConfiguration.getLongPressTimeout())
6608 <= curTime) {
6609 newEvent = KeyEvent.changeTimeRepeat(lastKey,
6610 curTime, keyRepeatCount,
6611 lastKey.getFlags() | KeyEvent.FLAG_LONG_PRESS);
6612 downTime = 0;
6613 } else {
6614 newEvent = KeyEvent.changeTimeRepeat(lastKey,
6615 curTime, keyRepeatCount);
6616 }
6617 dispatchKey(newEvent, 0, 0);
Romain Guy06882f82009-06-10 13:36:04 -07006618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006619 } else {
6620 curTime = SystemClock.uptimeMillis();
Romain Guy06882f82009-06-10 13:36:04 -07006621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006622 lastKeyTime = curTime;
6623 nextKeyTime = curTime + LONG_WAIT;
6624 }
Romain Guy06882f82009-06-10 13:36:04 -07006625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006626 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006627 Slog.e(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006628 "Input thread received uncaught exception: " + e, e);
6629 }
6630 }
6631 }
6632 }
6633
6634 // -------------------------------------------------------------
6635 // Client Session State
6636 // -------------------------------------------------------------
6637
6638 private final class Session extends IWindowSession.Stub
6639 implements IBinder.DeathRecipient {
6640 final IInputMethodClient mClient;
6641 final IInputContext mInputContext;
6642 final int mUid;
6643 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006644 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006645 SurfaceSession mSurfaceSession;
6646 int mNumWindow = 0;
6647 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006649 /**
6650 * Current pointer move event being dispatched to client window... must
6651 * hold key lock to access.
6652 */
6653 QueuedEvent mPendingPointerMove;
6654 WindowState mPendingPointerWindow;
Romain Guy06882f82009-06-10 13:36:04 -07006655
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006656 /**
6657 * Current trackball move event being dispatched to client window... must
6658 * hold key lock to access.
6659 */
6660 QueuedEvent mPendingTrackballMove;
6661 WindowState mPendingTrackballWindow;
6662
6663 public Session(IInputMethodClient client, IInputContext inputContext) {
6664 mClient = client;
6665 mInputContext = inputContext;
6666 mUid = Binder.getCallingUid();
6667 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006668 StringBuilder sb = new StringBuilder();
6669 sb.append("Session{");
6670 sb.append(Integer.toHexString(System.identityHashCode(this)));
6671 sb.append(" uid ");
6672 sb.append(mUid);
6673 sb.append("}");
6674 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006676 synchronized (mWindowMap) {
6677 if (mInputMethodManager == null && mHaveInputMethods) {
6678 IBinder b = ServiceManager.getService(
6679 Context.INPUT_METHOD_SERVICE);
6680 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6681 }
6682 }
6683 long ident = Binder.clearCallingIdentity();
6684 try {
6685 // Note: it is safe to call in to the input method manager
6686 // here because we are not holding our lock.
6687 if (mInputMethodManager != null) {
6688 mInputMethodManager.addClient(client, inputContext,
6689 mUid, mPid);
6690 } else {
6691 client.setUsingInputMethod(false);
6692 }
6693 client.asBinder().linkToDeath(this, 0);
6694 } catch (RemoteException e) {
6695 // The caller has died, so we can just forget about this.
6696 try {
6697 if (mInputMethodManager != null) {
6698 mInputMethodManager.removeClient(client);
6699 }
6700 } catch (RemoteException ee) {
6701 }
6702 } finally {
6703 Binder.restoreCallingIdentity(ident);
6704 }
6705 }
Romain Guy06882f82009-06-10 13:36:04 -07006706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006707 @Override
6708 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6709 throws RemoteException {
6710 try {
6711 return super.onTransact(code, data, reply, flags);
6712 } catch (RuntimeException e) {
6713 // Log all 'real' exceptions thrown to the caller
6714 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006715 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006716 }
6717 throw e;
6718 }
6719 }
6720
6721 public void binderDied() {
6722 // Note: it is safe to call in to the input method manager
6723 // here because we are not holding our lock.
6724 try {
6725 if (mInputMethodManager != null) {
6726 mInputMethodManager.removeClient(mClient);
6727 }
6728 } catch (RemoteException e) {
6729 }
6730 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006731 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006732 mClientDead = true;
6733 killSessionLocked();
6734 }
6735 }
6736
6737 public int add(IWindow window, WindowManager.LayoutParams attrs,
6738 int viewVisibility, Rect outContentInsets) {
6739 return addWindow(this, window, attrs, viewVisibility, outContentInsets);
6740 }
Romain Guy06882f82009-06-10 13:36:04 -07006741
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006742 public void remove(IWindow window) {
6743 removeWindow(this, window);
6744 }
Romain Guy06882f82009-06-10 13:36:04 -07006745
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006746 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6747 int requestedWidth, int requestedHeight, int viewFlags,
6748 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006749 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006750 return relayoutWindow(this, window, attrs,
6751 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006752 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006753 }
Romain Guy06882f82009-06-10 13:36:04 -07006754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006755 public void setTransparentRegion(IWindow window, Region region) {
6756 setTransparentRegionWindow(this, window, region);
6757 }
Romain Guy06882f82009-06-10 13:36:04 -07006758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006759 public void setInsets(IWindow window, int touchableInsets,
6760 Rect contentInsets, Rect visibleInsets) {
6761 setInsetsWindow(this, window, touchableInsets, contentInsets,
6762 visibleInsets);
6763 }
Romain Guy06882f82009-06-10 13:36:04 -07006764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006765 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6766 getWindowDisplayFrame(this, window, outDisplayFrame);
6767 }
Romain Guy06882f82009-06-10 13:36:04 -07006768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006769 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006770 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006771 TAG, "IWindow finishDrawing called for " + window);
6772 finishDrawingWindow(this, window);
6773 }
6774
6775 public void finishKey(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006776 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006777 TAG, "IWindow finishKey called for " + window);
6778 mKeyWaiter.finishedKey(this, window, false,
6779 KeyWaiter.RETURN_NOTHING);
6780 }
6781
6782 public MotionEvent getPendingPointerMove(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006783 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006784 TAG, "IWindow getPendingMotionEvent called for " + window);
6785 return mKeyWaiter.finishedKey(this, window, false,
6786 KeyWaiter.RETURN_PENDING_POINTER);
6787 }
Romain Guy06882f82009-06-10 13:36:04 -07006788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006789 public MotionEvent getPendingTrackballMove(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006790 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006791 TAG, "IWindow getPendingMotionEvent called for " + window);
6792 return mKeyWaiter.finishedKey(this, window, false,
6793 KeyWaiter.RETURN_PENDING_TRACKBALL);
6794 }
6795
6796 public void setInTouchMode(boolean mode) {
6797 synchronized(mWindowMap) {
6798 mInTouchMode = mode;
6799 }
6800 }
6801
6802 public boolean getInTouchMode() {
6803 synchronized(mWindowMap) {
6804 return mInTouchMode;
6805 }
6806 }
6807
6808 public boolean performHapticFeedback(IWindow window, int effectId,
6809 boolean always) {
6810 synchronized(mWindowMap) {
6811 long ident = Binder.clearCallingIdentity();
6812 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006813 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006814 windowForClientLocked(this, window, true),
6815 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006816 } finally {
6817 Binder.restoreCallingIdentity(ident);
6818 }
6819 }
6820 }
Romain Guy06882f82009-06-10 13:36:04 -07006821
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006822 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006823 synchronized(mWindowMap) {
6824 long ident = Binder.clearCallingIdentity();
6825 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006826 setWindowWallpaperPositionLocked(
6827 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006828 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006829 } finally {
6830 Binder.restoreCallingIdentity(ident);
6831 }
6832 }
6833 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006834
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006835 public void wallpaperOffsetsComplete(IBinder window) {
6836 WindowManagerService.this.wallpaperOffsetsComplete(window);
6837 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006838
Dianne Hackborn75804932009-10-20 20:15:20 -07006839 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6840 int z, Bundle extras, boolean sync) {
6841 synchronized(mWindowMap) {
6842 long ident = Binder.clearCallingIdentity();
6843 try {
6844 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006845 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006846 action, x, y, z, extras, sync);
6847 } finally {
6848 Binder.restoreCallingIdentity(ident);
6849 }
6850 }
6851 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006852
Dianne Hackborn75804932009-10-20 20:15:20 -07006853 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6854 WindowManagerService.this.wallpaperCommandComplete(window, result);
6855 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006857 void windowAddedLocked() {
6858 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006859 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006860 TAG, "First window added to " + this + ", creating SurfaceSession");
6861 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006862 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006863 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006864 mSessions.add(this);
6865 }
6866 mNumWindow++;
6867 }
6868
6869 void windowRemovedLocked() {
6870 mNumWindow--;
6871 killSessionLocked();
6872 }
Romain Guy06882f82009-06-10 13:36:04 -07006873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006874 void killSessionLocked() {
6875 if (mNumWindow <= 0 && mClientDead) {
6876 mSessions.remove(this);
6877 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006878 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006879 TAG, "Last window removed from " + this
6880 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006881 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006882 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006883 try {
6884 mSurfaceSession.kill();
6885 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006886 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006887 + mSurfaceSession + " in session " + this
6888 + ": " + e.toString());
6889 }
6890 mSurfaceSession = null;
6891 }
6892 }
6893 }
Romain Guy06882f82009-06-10 13:36:04 -07006894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006895 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006896 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6897 pw.print(" mClientDead="); pw.print(mClientDead);
6898 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
6899 if (mPendingPointerWindow != null || mPendingPointerMove != null) {
6900 pw.print(prefix);
6901 pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow);
6902 pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove);
6903 }
6904 if (mPendingTrackballWindow != null || mPendingTrackballMove != null) {
6905 pw.print(prefix);
6906 pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow);
6907 pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove);
6908 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006909 }
6910
6911 @Override
6912 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006913 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006914 }
6915 }
6916
6917 // -------------------------------------------------------------
6918 // Client Window State
6919 // -------------------------------------------------------------
6920
6921 private final class WindowState implements WindowManagerPolicy.WindowState {
6922 final Session mSession;
6923 final IWindow mClient;
6924 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006925 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006926 AppWindowToken mAppToken;
6927 AppWindowToken mTargetAppToken;
6928 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6929 final DeathRecipient mDeathRecipient;
6930 final WindowState mAttachedWindow;
6931 final ArrayList mChildWindows = new ArrayList();
6932 final int mBaseLayer;
6933 final int mSubLayer;
6934 final boolean mLayoutAttached;
6935 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006936 final boolean mIsWallpaper;
6937 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006938 int mViewVisibility;
6939 boolean mPolicyVisibility = true;
6940 boolean mPolicyVisibilityAfterAnim = true;
6941 boolean mAppFreezing;
6942 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006943 boolean mReportDestroySurface;
6944 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006945 boolean mAttachedHidden; // is our parent window hidden?
6946 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006947 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006948 int mRequestedWidth;
6949 int mRequestedHeight;
6950 int mLastRequestedWidth;
6951 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006952 int mLayer;
6953 int mAnimLayer;
6954 int mLastLayer;
6955 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006956 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006957 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006958
6959 WindowState mNextOutsideTouch;
Romain Guy06882f82009-06-10 13:36:04 -07006960
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006961 int mLayoutSeq = -1;
6962
6963 Configuration mConfiguration = null;
6964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006965 // Actual frame shown on-screen (may be modified by animation)
6966 final Rect mShownFrame = new Rect();
6967 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006969 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006970 * Set when we have changed the size of the surface, to know that
6971 * we must tell them application to resize (and thus redraw itself).
6972 */
6973 boolean mSurfaceResized;
6974
6975 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006976 * Insets that determine the actually visible area
6977 */
6978 final Rect mVisibleInsets = new Rect();
6979 final Rect mLastVisibleInsets = new Rect();
6980 boolean mVisibleInsetsChanged;
6981
6982 /**
6983 * Insets that are covered by system windows
6984 */
6985 final Rect mContentInsets = new Rect();
6986 final Rect mLastContentInsets = new Rect();
6987 boolean mContentInsetsChanged;
6988
6989 /**
6990 * Set to true if we are waiting for this window to receive its
6991 * given internal insets before laying out other windows based on it.
6992 */
6993 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006995 /**
6996 * These are the content insets that were given during layout for
6997 * this window, to be applied to windows behind it.
6998 */
6999 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07007000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007001 /**
7002 * These are the visible insets that were given during layout for
7003 * this window, to be applied to windows behind it.
7004 */
7005 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07007006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007007 /**
7008 * Flag indicating whether the touchable region should be adjusted by
7009 * the visible insets; if false the area outside the visible insets is
7010 * NOT touchable, so we must use those to adjust the frame during hit
7011 * tests.
7012 */
7013 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07007014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007015 // Current transformation being applied.
7016 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
7017 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
7018 float mHScale=1, mVScale=1;
7019 float mLastHScale=1, mLastVScale=1;
7020 final Matrix mTmpMatrix = new Matrix();
7021
7022 // "Real" frame that the application sees.
7023 final Rect mFrame = new Rect();
7024 final Rect mLastFrame = new Rect();
7025
7026 final Rect mContainingFrame = new Rect();
7027 final Rect mDisplayFrame = new Rect();
7028 final Rect mContentFrame = new Rect();
7029 final Rect mVisibleFrame = new Rect();
7030
7031 float mShownAlpha = 1;
7032 float mAlpha = 1;
7033 float mLastAlpha = 1;
7034
7035 // Set to true if, when the window gets displayed, it should perform
7036 // an enter animation.
7037 boolean mEnterAnimationPending;
7038
7039 // Currently running animation.
7040 boolean mAnimating;
7041 boolean mLocalAnimating;
7042 Animation mAnimation;
7043 boolean mAnimationIsEntrance;
7044 boolean mHasTransformation;
7045 boolean mHasLocalTransformation;
7046 final Transformation mTransformation = new Transformation();
7047
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007048 // If a window showing a wallpaper: the requested offset for the
7049 // wallpaper; if a wallpaper window: the currently applied offset.
7050 float mWallpaperX = -1;
7051 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007052
7053 // If a window showing a wallpaper: what fraction of the offset
7054 // range corresponds to a full virtual screen.
7055 float mWallpaperXStep = -1;
7056 float mWallpaperYStep = -1;
7057
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007058 // Wallpaper windows: pixels offset based on above variables.
7059 int mXOffset;
7060 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007061
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007062 // This is set after IWindowSession.relayout() has been called at
7063 // least once for the window. It allows us to detect the situation
7064 // where we don't yet have a surface, but should have one soon, so
7065 // we can give the window focus before waiting for the relayout.
7066 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07007067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007068 // This is set after the Surface has been created but before the
7069 // window has been drawn. During this time the surface is hidden.
7070 boolean mDrawPending;
7071
7072 // This is set after the window has finished drawing for the first
7073 // time but before its surface is shown. The surface will be
7074 // displayed when the next layout is run.
7075 boolean mCommitDrawPending;
7076
7077 // This is set during the time after the window's drawing has been
7078 // committed, and before its surface is actually shown. It is used
7079 // to delay showing the surface until all windows in a token are ready
7080 // to be shown.
7081 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07007082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007083 // Set when the window has been shown in the screen the first time.
7084 boolean mHasDrawn;
7085
7086 // Currently running an exit animation?
7087 boolean mExiting;
7088
7089 // Currently on the mDestroySurface list?
7090 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07007091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007092 // Completely remove from window manager after exit animation?
7093 boolean mRemoveOnExit;
7094
7095 // Set when the orientation is changing and this window has not yet
7096 // been updated for the new orientation.
7097 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07007098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007099 // Is this window now (or just being) removed?
7100 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07007101
Dianne Hackborn16064f92010-03-25 00:47:24 -07007102 // For debugging, this is the last information given to the surface flinger.
7103 boolean mSurfaceShown;
7104 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
7105 int mSurfaceLayer;
7106 float mSurfaceAlpha;
7107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007108 WindowState(Session s, IWindow c, WindowToken token,
7109 WindowState attachedWindow, WindowManager.LayoutParams a,
7110 int viewVisibility) {
7111 mSession = s;
7112 mClient = c;
7113 mToken = token;
7114 mAttrs.copyFrom(a);
7115 mViewVisibility = viewVisibility;
7116 DeathRecipient deathRecipient = new DeathRecipient();
7117 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007118 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007119 TAG, "Window " + this + " client=" + c.asBinder()
7120 + " token=" + token + " (" + mAttrs.token + ")");
7121 try {
7122 c.asBinder().linkToDeath(deathRecipient, 0);
7123 } catch (RemoteException e) {
7124 mDeathRecipient = null;
7125 mAttachedWindow = null;
7126 mLayoutAttached = false;
7127 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007128 mIsWallpaper = false;
7129 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007130 mBaseLayer = 0;
7131 mSubLayer = 0;
7132 return;
7133 }
7134 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07007135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007136 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
7137 mAttrs.type <= LAST_SUB_WINDOW)) {
7138 // The multiplier here is to reserve space for multiple
7139 // windows in the same type layer.
7140 mBaseLayer = mPolicy.windowTypeToLayerLw(
7141 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
7142 + TYPE_LAYER_OFFSET;
7143 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
7144 mAttachedWindow = attachedWindow;
7145 mAttachedWindow.mChildWindows.add(this);
7146 mLayoutAttached = mAttrs.type !=
7147 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
7148 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
7149 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007150 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
7151 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007152 } else {
7153 // The multiplier here is to reserve space for multiple
7154 // windows in the same type layer.
7155 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
7156 * TYPE_LAYER_MULTIPLIER
7157 + TYPE_LAYER_OFFSET;
7158 mSubLayer = 0;
7159 mAttachedWindow = null;
7160 mLayoutAttached = false;
7161 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
7162 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007163 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
7164 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007165 }
7166
7167 WindowState appWin = this;
7168 while (appWin.mAttachedWindow != null) {
7169 appWin = mAttachedWindow;
7170 }
7171 WindowToken appToken = appWin.mToken;
7172 while (appToken.appWindowToken == null) {
7173 WindowToken parent = mTokenMap.get(appToken.token);
7174 if (parent == null || appToken == parent) {
7175 break;
7176 }
7177 appToken = parent;
7178 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007179 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007180 mAppToken = appToken.appWindowToken;
7181
7182 mSurface = null;
7183 mRequestedWidth = 0;
7184 mRequestedHeight = 0;
7185 mLastRequestedWidth = 0;
7186 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007187 mXOffset = 0;
7188 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007189 mLayer = 0;
7190 mAnimLayer = 0;
7191 mLastLayer = 0;
7192 }
7193
7194 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007195 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007196 TAG, "Attaching " + this + " token=" + mToken
7197 + ", list=" + mToken.windows);
7198 mSession.windowAddedLocked();
7199 }
7200
7201 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7202 mHaveFrame = true;
7203
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007204 final Rect container = mContainingFrame;
7205 container.set(pf);
7206
7207 final Rect display = mDisplayFrame;
7208 display.set(df);
7209
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007210 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007211 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007212 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7213 display.intersect(mCompatibleScreenFrame);
7214 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007215 }
7216
7217 final int pw = container.right - container.left;
7218 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007219
7220 int w,h;
7221 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7222 w = mAttrs.width < 0 ? pw : mAttrs.width;
7223 h = mAttrs.height< 0 ? ph : mAttrs.height;
7224 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007225 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7226 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007227 }
Romain Guy06882f82009-06-10 13:36:04 -07007228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007229 final Rect content = mContentFrame;
7230 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007232 final Rect visible = mVisibleFrame;
7233 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007235 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007236 final int fw = frame.width();
7237 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007238
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007239 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7240 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7241
7242 Gravity.apply(mAttrs.gravity, w, h, container,
7243 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7244 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7245
7246 //System.out.println("Out: " + mFrame);
7247
7248 // Now make sure the window fits in the overall display.
7249 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007251 // Make sure the content and visible frames are inside of the
7252 // final window frame.
7253 if (content.left < frame.left) content.left = frame.left;
7254 if (content.top < frame.top) content.top = frame.top;
7255 if (content.right > frame.right) content.right = frame.right;
7256 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7257 if (visible.left < frame.left) visible.left = frame.left;
7258 if (visible.top < frame.top) visible.top = frame.top;
7259 if (visible.right > frame.right) visible.right = frame.right;
7260 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007262 final Rect contentInsets = mContentInsets;
7263 contentInsets.left = content.left-frame.left;
7264 contentInsets.top = content.top-frame.top;
7265 contentInsets.right = frame.right-content.right;
7266 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007268 final Rect visibleInsets = mVisibleInsets;
7269 visibleInsets.left = visible.left-frame.left;
7270 visibleInsets.top = visible.top-frame.top;
7271 visibleInsets.right = frame.right-visible.right;
7272 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007273
Dianne Hackborn284ac932009-08-28 10:34:25 -07007274 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7275 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007276 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007277 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007279 if (localLOGV) {
7280 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7281 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007282 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007283 + mRequestedWidth + ", mRequestedheight="
7284 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7285 + "): frame=" + mFrame.toShortString()
7286 + " ci=" + contentInsets.toShortString()
7287 + " vi=" + visibleInsets.toShortString());
7288 //}
7289 }
7290 }
Romain Guy06882f82009-06-10 13:36:04 -07007291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007292 public Rect getFrameLw() {
7293 return mFrame;
7294 }
7295
7296 public Rect getShownFrameLw() {
7297 return mShownFrame;
7298 }
7299
7300 public Rect getDisplayFrameLw() {
7301 return mDisplayFrame;
7302 }
7303
7304 public Rect getContentFrameLw() {
7305 return mContentFrame;
7306 }
7307
7308 public Rect getVisibleFrameLw() {
7309 return mVisibleFrame;
7310 }
7311
7312 public boolean getGivenInsetsPendingLw() {
7313 return mGivenInsetsPending;
7314 }
7315
7316 public Rect getGivenContentInsetsLw() {
7317 return mGivenContentInsets;
7318 }
Romain Guy06882f82009-06-10 13:36:04 -07007319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007320 public Rect getGivenVisibleInsetsLw() {
7321 return mGivenVisibleInsets;
7322 }
Romain Guy06882f82009-06-10 13:36:04 -07007323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007324 public WindowManager.LayoutParams getAttrs() {
7325 return mAttrs;
7326 }
7327
7328 public int getSurfaceLayer() {
7329 return mLayer;
7330 }
Romain Guy06882f82009-06-10 13:36:04 -07007331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007332 public IApplicationToken getAppToken() {
7333 return mAppToken != null ? mAppToken.appToken : null;
7334 }
7335
7336 public boolean hasAppShownWindows() {
7337 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7338 }
7339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007340 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007341 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007342 TAG, "Setting animation in " + this + ": " + anim);
7343 mAnimating = false;
7344 mLocalAnimating = false;
7345 mAnimation = anim;
7346 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7347 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7348 }
7349
7350 public void clearAnimation() {
7351 if (mAnimation != null) {
7352 mAnimating = true;
7353 mLocalAnimating = false;
7354 mAnimation = null;
7355 }
7356 }
Romain Guy06882f82009-06-10 13:36:04 -07007357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007358 Surface createSurfaceLocked() {
7359 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007360 mReportDestroySurface = false;
7361 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007362 mDrawPending = true;
7363 mCommitDrawPending = false;
7364 mReadyToShow = false;
7365 if (mAppToken != null) {
7366 mAppToken.allDrawn = false;
7367 }
7368
7369 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07007370 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007371 flags |= Surface.PUSH_BUFFERS;
7372 }
7373
7374 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7375 flags |= Surface.SECURE;
7376 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007377 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007378 TAG, "Creating surface in session "
7379 + mSession.mSurfaceSession + " window " + this
7380 + " w=" + mFrame.width()
7381 + " h=" + mFrame.height() + " format="
7382 + mAttrs.format + " flags=" + flags);
7383
7384 int w = mFrame.width();
7385 int h = mFrame.height();
7386 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7387 // for a scaled surface, we always want the requested
7388 // size.
7389 w = mRequestedWidth;
7390 h = mRequestedHeight;
7391 }
7392
Romain Guy9825ec62009-10-01 00:58:09 -07007393 // Something is wrong and SurfaceFlinger will not like this,
7394 // try to revert to sane values
7395 if (w <= 0) w = 1;
7396 if (h <= 0) h = 1;
7397
Dianne Hackborn16064f92010-03-25 00:47:24 -07007398 mSurfaceShown = false;
7399 mSurfaceLayer = 0;
7400 mSurfaceAlpha = 1;
7401 mSurfaceX = 0;
7402 mSurfaceY = 0;
7403 mSurfaceW = w;
7404 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007405 try {
7406 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007407 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007408 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007409 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007410 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007411 + mSurface + " IN SESSION "
7412 + mSession.mSurfaceSession
7413 + ": pid=" + mSession.mPid + " format="
7414 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007415 + Integer.toHexString(flags)
7416 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007417 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007418 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007419 reclaimSomeSurfaceMemoryLocked(this, "create");
7420 return null;
7421 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007422 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007423 return null;
7424 }
Romain Guy06882f82009-06-10 13:36:04 -07007425
Joe Onorato8a9b2202010-02-26 18:56:32 -08007426 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007427 TAG, "Got surface: " + mSurface
7428 + ", set left=" + mFrame.left + " top=" + mFrame.top
7429 + ", animLayer=" + mAnimLayer);
7430 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007431 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007432 if (SHOW_TRANSACTIONS) logSurface(this,
7433 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
7434 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7435 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007436 }
7437 Surface.openTransaction();
7438 try {
7439 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007440 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007441 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007442 mSurface.setPosition(mSurfaceX, mSurfaceY);
7443 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007444 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007445 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007446 mSurface.hide();
7447 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007448 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007449 mSurface.setFlags(Surface.SURFACE_DITHER,
7450 Surface.SURFACE_DITHER);
7451 }
7452 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007453 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007454 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7455 }
7456 mLastHidden = true;
7457 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007458 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007459 Surface.closeTransaction();
7460 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007461 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007462 TAG, "Created surface " + this);
7463 }
7464 return mSurface;
7465 }
Romain Guy06882f82009-06-10 13:36:04 -07007466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007467 void destroySurfaceLocked() {
7468 // Window is no longer on-screen, so can no longer receive
7469 // key events... if we were waiting for it to finish
7470 // handling a key event, the wait is over!
7471 mKeyWaiter.finishedKey(mSession, mClient, true,
7472 KeyWaiter.RETURN_NOTHING);
7473 mKeyWaiter.releasePendingPointerLocked(mSession);
7474 mKeyWaiter.releasePendingTrackballLocked(mSession);
7475
7476 if (mAppToken != null && this == mAppToken.startingWindow) {
7477 mAppToken.startingDisplayed = false;
7478 }
Romain Guy06882f82009-06-10 13:36:04 -07007479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007480 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007481 mDrawPending = false;
7482 mCommitDrawPending = false;
7483 mReadyToShow = false;
7484
7485 int i = mChildWindows.size();
7486 while (i > 0) {
7487 i--;
7488 WindowState c = (WindowState)mChildWindows.get(i);
7489 c.mAttachedHidden = true;
7490 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007491
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007492 if (mReportDestroySurface) {
7493 mReportDestroySurface = false;
7494 mSurfacePendingDestroy = true;
7495 try {
7496 mClient.dispatchGetNewSurface();
7497 // We'll really destroy on the next time around.
7498 return;
7499 } catch (RemoteException e) {
7500 }
7501 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007503 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007504 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007505 RuntimeException e = null;
7506 if (!HIDE_STACK_CRAWLS) {
7507 e = new RuntimeException();
7508 e.fillInStackTrace();
7509 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007510 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007511 + mSurface + ", session " + mSession, e);
7512 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007513 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007514 RuntimeException e = null;
7515 if (!HIDE_STACK_CRAWLS) {
7516 e = new RuntimeException();
7517 e.fillInStackTrace();
7518 }
7519 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007520 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007521 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007522 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007523 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007524 + " surface " + mSurface + " session " + mSession
7525 + ": " + e.toString());
7526 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007527
Dianne Hackborn16064f92010-03-25 00:47:24 -07007528 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007529 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007530 }
7531 }
7532
7533 boolean finishDrawingLocked() {
7534 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007535 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007536 TAG, "finishDrawingLocked: " + mSurface);
7537 mCommitDrawPending = true;
7538 mDrawPending = false;
7539 return true;
7540 }
7541 return false;
7542 }
7543
7544 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007545 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007546 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007547 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007548 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007549 }
7550 mCommitDrawPending = false;
7551 mReadyToShow = true;
7552 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7553 final AppWindowToken atoken = mAppToken;
7554 if (atoken == null || atoken.allDrawn || starting) {
7555 performShowLocked();
7556 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007557 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007558 }
7559
7560 // This must be called while inside a transaction.
7561 boolean performShowLocked() {
7562 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007563 RuntimeException e = null;
7564 if (!HIDE_STACK_CRAWLS) {
7565 e = new RuntimeException();
7566 e.fillInStackTrace();
7567 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007568 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007569 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7570 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7571 }
7572 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007573 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7574 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007575 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007576 + " during animation: policyVis=" + mPolicyVisibility
7577 + " attHidden=" + mAttachedHidden
7578 + " tok.hiddenRequested="
7579 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007580 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007581 + (mAppToken != null ? mAppToken.hidden : false)
7582 + " animating=" + mAnimating
7583 + " tok animating="
7584 + (mAppToken != null ? mAppToken.animating : false));
7585 if (!showSurfaceRobustlyLocked(this)) {
7586 return false;
7587 }
7588 mLastAlpha = -1;
7589 mHasDrawn = true;
7590 mLastHidden = false;
7591 mReadyToShow = false;
7592 enableScreenIfNeededLocked();
7593
7594 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007596 int i = mChildWindows.size();
7597 while (i > 0) {
7598 i--;
7599 WindowState c = (WindowState)mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007600 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007601 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007602 if (c.mSurface != null) {
7603 c.performShowLocked();
7604 // It hadn't been shown, which means layout not
7605 // performed on it, so now we want to make sure to
7606 // do a layout. If called from within the transaction
7607 // loop, this will cause it to restart with a new
7608 // layout.
7609 mLayoutNeeded = true;
7610 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007611 }
7612 }
Romain Guy06882f82009-06-10 13:36:04 -07007613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007614 if (mAttrs.type != TYPE_APPLICATION_STARTING
7615 && mAppToken != null) {
7616 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007617
Dianne Hackborn248b1882009-09-16 16:46:44 -07007618 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007619 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007620 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007621 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007622 // If this initial window is animating, stop it -- we
7623 // will do an animation to reveal it from behind the
7624 // starting window, so there is no need for it to also
7625 // be doing its own stuff.
7626 if (mAnimation != null) {
7627 mAnimation = null;
7628 // Make sure we clean up the animation.
7629 mAnimating = true;
7630 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007631 mFinishedStarting.add(mAppToken);
7632 mH.sendEmptyMessage(H.FINISHED_STARTING);
7633 }
7634 mAppToken.updateReportedVisibilityLocked();
7635 }
7636 }
7637 return true;
7638 }
Romain Guy06882f82009-06-10 13:36:04 -07007639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007640 // This must be called while inside a transaction. Returns true if
7641 // there is more animation to run.
7642 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007643 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007644 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007646 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7647 mHasTransformation = true;
7648 mHasLocalTransformation = true;
7649 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007650 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007651 TAG, "Starting animation in " + this +
7652 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7653 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7654 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7655 mAnimation.setStartTime(currentTime);
7656 mLocalAnimating = true;
7657 mAnimating = true;
7658 }
7659 mTransformation.clear();
7660 final boolean more = mAnimation.getTransformation(
7661 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007662 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007663 TAG, "Stepped animation in " + this +
7664 ": more=" + more + ", xform=" + mTransformation);
7665 if (more) {
7666 // we're not done!
7667 return true;
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, "Finished animation in " + this +
7671 " @ " + currentTime);
7672 mAnimation = null;
7673 //WindowManagerService.this.dump();
7674 }
7675 mHasLocalTransformation = false;
7676 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007677 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007678 // When our app token is animating, we kind-of pretend like
7679 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7680 // part of this check means that we will only do this if
7681 // our window is not currently exiting, or it is not
7682 // locally animating itself. The idea being that one that
7683 // is exiting and doing a local animation should be removed
7684 // once that animation is done.
7685 mAnimating = true;
7686 mHasTransformation = true;
7687 mTransformation.clear();
7688 return false;
7689 } else if (mHasTransformation) {
7690 // Little trick to get through the path below to act like
7691 // we have finished an animation.
7692 mAnimating = true;
7693 } else if (isAnimating()) {
7694 mAnimating = true;
7695 }
7696 } else if (mAnimation != null) {
7697 // If the display is frozen, and there is a pending animation,
7698 // clear it and make sure we run the cleanup code.
7699 mAnimating = true;
7700 mLocalAnimating = true;
7701 mAnimation = null;
7702 }
Romain Guy06882f82009-06-10 13:36:04 -07007703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007704 if (!mAnimating && !mLocalAnimating) {
7705 return false;
7706 }
7707
Joe Onorato8a9b2202010-02-26 18:56:32 -08007708 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007709 TAG, "Animation done in " + this + ": exiting=" + mExiting
7710 + ", reportedVisible="
7711 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007713 mAnimating = false;
7714 mLocalAnimating = false;
7715 mAnimation = null;
7716 mAnimLayer = mLayer;
7717 if (mIsImWindow) {
7718 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007719 } else if (mIsWallpaper) {
7720 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007721 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007722 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007723 + " anim layer: " + mAnimLayer);
7724 mHasTransformation = false;
7725 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007726 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7727 if (DEBUG_VISIBILITY) {
7728 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7729 + mPolicyVisibilityAfterAnim);
7730 }
7731 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7732 if (!mPolicyVisibility) {
7733 if (mCurrentFocus == this) {
7734 mFocusMayChange = true;
7735 }
7736 // Window is no longer visible -- make sure if we were waiting
7737 // for it to be displayed before enabling the display, that
7738 // we allow the display to be enabled now.
7739 enableScreenIfNeededLocked();
7740 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007741 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007742 mTransformation.clear();
7743 if (mHasDrawn
7744 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7745 && mAppToken != null
7746 && mAppToken.firstWindowDrawn
7747 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007748 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007749 + mToken + ": first real window done animating");
7750 mFinishedStarting.add(mAppToken);
7751 mH.sendEmptyMessage(H.FINISHED_STARTING);
7752 }
Romain Guy06882f82009-06-10 13:36:04 -07007753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007754 finishExit();
7755
7756 if (mAppToken != null) {
7757 mAppToken.updateReportedVisibilityLocked();
7758 }
7759
7760 return false;
7761 }
7762
7763 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007764 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007765 TAG, "finishExit in " + this
7766 + ": exiting=" + mExiting
7767 + " remove=" + mRemoveOnExit
7768 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007770 final int N = mChildWindows.size();
7771 for (int i=0; i<N; i++) {
7772 ((WindowState)mChildWindows.get(i)).finishExit();
7773 }
Romain Guy06882f82009-06-10 13:36:04 -07007774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007775 if (!mExiting) {
7776 return;
7777 }
Romain Guy06882f82009-06-10 13:36:04 -07007778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007779 if (isWindowAnimating()) {
7780 return;
7781 }
7782
Joe Onorato8a9b2202010-02-26 18:56:32 -08007783 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007784 TAG, "Exit animation finished in " + this
7785 + ": remove=" + mRemoveOnExit);
7786 if (mSurface != null) {
7787 mDestroySurface.add(this);
7788 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007789 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007790 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007791 try {
7792 mSurface.hide();
7793 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007794 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007795 }
7796 mLastHidden = true;
7797 mKeyWaiter.releasePendingPointerLocked(mSession);
7798 }
7799 mExiting = false;
7800 if (mRemoveOnExit) {
7801 mPendingRemove.add(this);
7802 mRemoveOnExit = false;
7803 }
7804 }
Romain Guy06882f82009-06-10 13:36:04 -07007805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007806 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7807 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7808 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7809 if (dtdx < -.000001f || dtdx > .000001f) return false;
7810 if (dsdy < -.000001f || dsdy > .000001f) return false;
7811 return true;
7812 }
Romain Guy06882f82009-06-10 13:36:04 -07007813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007814 void computeShownFrameLocked() {
7815 final boolean selfTransformation = mHasLocalTransformation;
7816 Transformation attachedTransformation =
7817 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7818 ? mAttachedWindow.mTransformation : null;
7819 Transformation appTransformation =
7820 (mAppToken != null && mAppToken.hasTransformation)
7821 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007822
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007823 // Wallpapers are animated based on the "real" window they
7824 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007825 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007826 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007827 if (mWallpaperTarget.mHasLocalTransformation &&
7828 mWallpaperTarget.mAnimation != null &&
7829 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007830 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007831 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007832 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007833 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007834 }
7835 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007836 mWallpaperTarget.mAppToken.hasTransformation &&
7837 mWallpaperTarget.mAppToken.animation != null &&
7838 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007839 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007840 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007841 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007842 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007843 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007844 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007846 if (selfTransformation || attachedTransformation != null
7847 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007848 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007849 final Rect frame = mFrame;
7850 final float tmpFloats[] = mTmpFloats;
7851 final Matrix tmpMatrix = mTmpMatrix;
7852
7853 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007854 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007855 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007856 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007857 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007858 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007859 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007860 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007861 }
7862 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007863 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007864 }
7865
7866 // "convert" it into SurfaceFlinger's format
7867 // (a 2x2 matrix + an offset)
7868 // Here we must not transform the position of the surface
7869 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007870 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007872 tmpMatrix.getValues(tmpFloats);
7873 mDsDx = tmpFloats[Matrix.MSCALE_X];
7874 mDtDx = tmpFloats[Matrix.MSKEW_X];
7875 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7876 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007877 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7878 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007879 int w = frame.width();
7880 int h = frame.height();
7881 mShownFrame.set(x, y, x+w, y+h);
7882
7883 // Now set the alpha... but because our current hardware
7884 // can't do alpha transformation on a non-opaque surface,
7885 // turn it off if we are running an animation that is also
7886 // transforming since it is more important to have that
7887 // animation be smooth.
7888 mShownAlpha = mAlpha;
7889 if (!mLimitedAlphaCompositing
7890 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7891 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7892 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007893 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007894 if (selfTransformation) {
7895 mShownAlpha *= mTransformation.getAlpha();
7896 }
7897 if (attachedTransformation != null) {
7898 mShownAlpha *= attachedTransformation.getAlpha();
7899 }
7900 if (appTransformation != null) {
7901 mShownAlpha *= appTransformation.getAlpha();
7902 }
7903 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007904 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007905 }
Romain Guy06882f82009-06-10 13:36:04 -07007906
Joe Onorato8a9b2202010-02-26 18:56:32 -08007907 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007908 TAG, "Continuing animation in " + this +
7909 ": " + mShownFrame +
7910 ", alpha=" + mTransformation.getAlpha());
7911 return;
7912 }
Romain Guy06882f82009-06-10 13:36:04 -07007913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007914 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007915 if (mXOffset != 0 || mYOffset != 0) {
7916 mShownFrame.offset(mXOffset, mYOffset);
7917 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007918 mShownAlpha = mAlpha;
7919 mDsDx = 1;
7920 mDtDx = 0;
7921 mDsDy = 0;
7922 mDtDy = 1;
7923 }
Romain Guy06882f82009-06-10 13:36:04 -07007924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007925 /**
7926 * Is this window visible? It is not visible if there is no
7927 * surface, or we are in the process of running an exit animation
7928 * that will remove the surface, or its app token has been hidden.
7929 */
7930 public boolean isVisibleLw() {
7931 final AppWindowToken atoken = mAppToken;
7932 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7933 && (atoken == null || !atoken.hiddenRequested)
7934 && !mExiting && !mDestroying;
7935 }
7936
7937 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007938 * Like {@link #isVisibleLw}, but also counts a window that is currently
7939 * "hidden" behind the keyguard as visible. This allows us to apply
7940 * things like window flags that impact the keyguard.
7941 * XXX I am starting to think we need to have ANOTHER visibility flag
7942 * for this "hidden behind keyguard" state rather than overloading
7943 * mPolicyVisibility. Ungh.
7944 */
7945 public boolean isVisibleOrBehindKeyguardLw() {
7946 final AppWindowToken atoken = mAppToken;
7947 return mSurface != null && !mAttachedHidden
7948 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackborn5943c202010-04-12 21:36:49 -07007949 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending))
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007950 && !mExiting && !mDestroying;
7951 }
7952
7953 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007954 * Is this window visible, ignoring its app token? It is not visible
7955 * if there is no surface, or we are in the process of running an exit animation
7956 * that will remove the surface.
7957 */
7958 public boolean isWinVisibleLw() {
7959 final AppWindowToken atoken = mAppToken;
7960 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7961 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7962 && !mExiting && !mDestroying;
7963 }
7964
7965 /**
7966 * The same as isVisible(), but follows the current hidden state of
7967 * the associated app token, not the pending requested hidden state.
7968 */
7969 boolean isVisibleNow() {
7970 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007971 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007972 }
7973
7974 /**
7975 * Same as isVisible(), but we also count it as visible between the
7976 * call to IWindowSession.add() and the first relayout().
7977 */
7978 boolean isVisibleOrAdding() {
7979 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007980 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007981 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7982 && mPolicyVisibility && !mAttachedHidden
7983 && (atoken == null || !atoken.hiddenRequested)
7984 && !mExiting && !mDestroying;
7985 }
7986
7987 /**
7988 * Is this window currently on-screen? It is on-screen either if it
7989 * is visible or it is currently running an animation before no longer
7990 * being visible.
7991 */
7992 boolean isOnScreen() {
7993 final AppWindowToken atoken = mAppToken;
7994 if (atoken != null) {
7995 return mSurface != null && mPolicyVisibility && !mDestroying
7996 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007997 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007998 } else {
7999 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008000 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008001 }
8002 }
Romain Guy06882f82009-06-10 13:36:04 -07008003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008004 /**
8005 * Like isOnScreen(), but we don't return true if the window is part
8006 * of a transition that has not yet been started.
8007 */
8008 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07008009 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008010 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07008011 return false;
8012 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008013 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008014 final boolean animating = atoken != null
8015 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008016 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008017 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
8018 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008019 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008020 }
8021
8022 /** Is the window or its container currently animating? */
8023 boolean isAnimating() {
8024 final WindowState attached = mAttachedWindow;
8025 final AppWindowToken atoken = mAppToken;
8026 return mAnimation != null
8027 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07008028 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008029 (atoken.animation != null
8030 || atoken.inPendingTransaction));
8031 }
8032
8033 /** Is this window currently animating? */
8034 boolean isWindowAnimating() {
8035 return mAnimation != null;
8036 }
8037
8038 /**
8039 * Like isOnScreen, but returns false if the surface hasn't yet
8040 * been drawn.
8041 */
8042 public boolean isDisplayedLw() {
8043 final AppWindowToken atoken = mAppToken;
8044 return mSurface != null && mPolicyVisibility && !mDestroying
8045 && !mDrawPending && !mCommitDrawPending
8046 && ((!mAttachedHidden &&
8047 (atoken == null || !atoken.hiddenRequested))
8048 || mAnimating);
8049 }
8050
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008051 /**
8052 * Returns true if the window has a surface that it has drawn a
Dianne Hackborn5943c202010-04-12 21:36:49 -07008053 * complete UI in to. Note that this returns true if the orientation
8054 * is changing even if the window hasn't redrawn because we don't want
8055 * to stop things from executing during that time.
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008056 */
8057 public boolean isDrawnLw() {
8058 final AppWindowToken atoken = mAppToken;
8059 return mSurface != null && !mDestroying
Dianne Hackborn5943c202010-04-12 21:36:49 -07008060 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending));
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008061 }
8062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008063 public boolean fillsScreenLw(int screenWidth, int screenHeight,
8064 boolean shownFrame, boolean onlyOpaque) {
8065 if (mSurface == null) {
8066 return false;
8067 }
8068 if (mAppToken != null && !mAppToken.appFullscreen) {
8069 return false;
8070 }
8071 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
8072 return false;
8073 }
8074 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008075
8076 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
8077 return frame.left <= mCompatibleScreenFrame.left &&
8078 frame.top <= mCompatibleScreenFrame.top &&
8079 frame.right >= mCompatibleScreenFrame.right &&
8080 frame.bottom >= mCompatibleScreenFrame.bottom;
8081 } else {
8082 return frame.left <= 0 && frame.top <= 0
8083 && frame.right >= screenWidth
8084 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008085 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008086 }
Romain Guy06882f82009-06-10 13:36:04 -07008087
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008088 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07008089 * Return true if the window is opaque and fully drawn. This indicates
8090 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008091 */
8092 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07008093 return (mAttrs.format == PixelFormat.OPAQUE
8094 || mAttrs.type == TYPE_WALLPAPER)
8095 && mSurface != null && mAnimation == null
8096 && (mAppToken == null || mAppToken.animation == null)
8097 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008098 }
8099
8100 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
8101 return
8102 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008103 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
8104 // only if it's visible
8105 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008106 // and only if the application fills the compatible screen
8107 mFrame.left <= mCompatibleScreenFrame.left &&
8108 mFrame.top <= mCompatibleScreenFrame.top &&
8109 mFrame.right >= mCompatibleScreenFrame.right &&
8110 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008111 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008112 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008113 }
8114
8115 boolean isFullscreen(int screenWidth, int screenHeight) {
8116 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008117 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008118 }
8119
8120 void removeLocked() {
8121 if (mAttachedWindow != null) {
8122 mAttachedWindow.mChildWindows.remove(this);
8123 }
8124 destroySurfaceLocked();
8125 mSession.windowRemovedLocked();
8126 try {
8127 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
8128 } catch (RuntimeException e) {
8129 // Ignore if it has already been removed (usually because
8130 // we are doing this as part of processing a death note.)
8131 }
8132 }
8133
8134 private class DeathRecipient implements IBinder.DeathRecipient {
8135 public void binderDied() {
8136 try {
8137 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008138 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008139 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008140 if (win != null) {
8141 removeWindowLocked(mSession, win);
8142 }
8143 }
8144 } catch (IllegalArgumentException ex) {
8145 // This will happen if the window has already been
8146 // removed.
8147 }
8148 }
8149 }
8150
8151 /** Returns true if this window desires key events. */
8152 public final boolean canReceiveKeys() {
8153 return isVisibleOrAdding()
8154 && (mViewVisibility == View.VISIBLE)
8155 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8156 }
8157
8158 public boolean hasDrawnLw() {
8159 return mHasDrawn;
8160 }
8161
8162 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008163 return showLw(doAnimation, true);
8164 }
8165
8166 boolean showLw(boolean doAnimation, boolean requestAnim) {
8167 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8168 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008169 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008170 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008171 if (doAnimation) {
8172 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8173 + mPolicyVisibility + " mAnimation=" + mAnimation);
8174 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8175 doAnimation = false;
8176 } else if (mPolicyVisibility && mAnimation == null) {
8177 // Check for the case where we are currently visible and
8178 // not animating; we do not want to do animation at such a
8179 // point to become visible when we already are.
8180 doAnimation = false;
8181 }
8182 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008183 mPolicyVisibility = true;
8184 mPolicyVisibilityAfterAnim = true;
8185 if (doAnimation) {
8186 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8187 }
8188 if (requestAnim) {
8189 requestAnimationLocked(0);
8190 }
8191 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008192 }
8193
8194 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008195 return hideLw(doAnimation, true);
8196 }
8197
8198 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008199 if (doAnimation) {
8200 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8201 doAnimation = false;
8202 }
8203 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008204 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8205 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008206 if (!current) {
8207 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008208 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008209 if (doAnimation) {
8210 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8211 if (mAnimation == null) {
8212 doAnimation = false;
8213 }
8214 }
8215 if (doAnimation) {
8216 mPolicyVisibilityAfterAnim = false;
8217 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008218 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008219 mPolicyVisibilityAfterAnim = false;
8220 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008221 // Window is no longer visible -- make sure if we were waiting
8222 // for it to be displayed before enabling the display, that
8223 // we allow the display to be enabled now.
8224 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008225 if (mCurrentFocus == this) {
8226 mFocusMayChange = true;
8227 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008228 }
8229 if (requestAnim) {
8230 requestAnimationLocked(0);
8231 }
8232 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008233 }
8234
8235 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008236 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8237 pw.print(" mClient="); pw.println(mClient.asBinder());
8238 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8239 if (mAttachedWindow != null || mLayoutAttached) {
8240 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8241 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8242 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008243 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8244 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8245 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008246 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8247 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008248 }
8249 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8250 pw.print(" mSubLayer="); pw.print(mSubLayer);
8251 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8252 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8253 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8254 pw.print("="); pw.print(mAnimLayer);
8255 pw.print(" mLastLayer="); pw.println(mLastLayer);
8256 if (mSurface != null) {
8257 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008258 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8259 pw.print(" layer="); pw.print(mSurfaceLayer);
8260 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8261 pw.print(" rect=("); pw.print(mSurfaceX);
8262 pw.print(","); pw.print(mSurfaceY);
8263 pw.print(") "); pw.print(mSurfaceW);
8264 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008265 }
8266 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8267 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8268 if (mAppToken != null) {
8269 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8270 }
8271 if (mTargetAppToken != null) {
8272 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8273 }
8274 pw.print(prefix); pw.print("mViewVisibility=0x");
8275 pw.print(Integer.toHexString(mViewVisibility));
8276 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008277 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8278 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008279 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8280 pw.print(prefix); pw.print("mPolicyVisibility=");
8281 pw.print(mPolicyVisibility);
8282 pw.print(" mPolicyVisibilityAfterAnim=");
8283 pw.print(mPolicyVisibilityAfterAnim);
8284 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8285 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008286 if (!mRelayoutCalled) {
8287 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8288 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008289 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008290 pw.print(" h="); pw.print(mRequestedHeight);
8291 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008292 if (mXOffset != 0 || mYOffset != 0) {
8293 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8294 pw.print(" y="); pw.println(mYOffset);
8295 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008296 pw.print(prefix); pw.print("mGivenContentInsets=");
8297 mGivenContentInsets.printShortString(pw);
8298 pw.print(" mGivenVisibleInsets=");
8299 mGivenVisibleInsets.printShortString(pw);
8300 pw.println();
8301 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8302 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8303 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8304 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008305 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008306 pw.print(prefix); pw.print("mShownFrame=");
8307 mShownFrame.printShortString(pw);
8308 pw.print(" last="); mLastShownFrame.printShortString(pw);
8309 pw.println();
8310 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8311 pw.print(" last="); mLastFrame.printShortString(pw);
8312 pw.println();
8313 pw.print(prefix); pw.print("mContainingFrame=");
8314 mContainingFrame.printShortString(pw);
8315 pw.print(" mDisplayFrame=");
8316 mDisplayFrame.printShortString(pw);
8317 pw.println();
8318 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8319 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8320 pw.println();
8321 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8322 pw.print(" last="); mLastContentInsets.printShortString(pw);
8323 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8324 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8325 pw.println();
8326 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8327 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8328 pw.print(" mAlpha="); pw.print(mAlpha);
8329 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8330 }
8331 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8332 || mAnimation != null) {
8333 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8334 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8335 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8336 pw.print(" mAnimation="); pw.println(mAnimation);
8337 }
8338 if (mHasTransformation || mHasLocalTransformation) {
8339 pw.print(prefix); pw.print("XForm: has=");
8340 pw.print(mHasTransformation);
8341 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8342 pw.print(" "); mTransformation.printShortString(pw);
8343 pw.println();
8344 }
8345 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8346 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8347 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8348 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8349 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8350 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8351 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8352 pw.print(" mDestroying="); pw.print(mDestroying);
8353 pw.print(" mRemoved="); pw.println(mRemoved);
8354 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008355 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008356 pw.print(prefix); pw.print("mOrientationChanging=");
8357 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008358 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8359 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008360 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008361 if (mHScale != 1 || mVScale != 1) {
8362 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8363 pw.print(" mVScale="); pw.println(mVScale);
8364 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008365 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008366 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8367 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8368 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008369 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8370 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8371 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8372 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008373 }
8374
8375 @Override
8376 public String toString() {
8377 return "Window{"
8378 + Integer.toHexString(System.identityHashCode(this))
8379 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
8380 }
8381 }
Romain Guy06882f82009-06-10 13:36:04 -07008382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008383 // -------------------------------------------------------------
8384 // Window Token State
8385 // -------------------------------------------------------------
8386
8387 class WindowToken {
8388 // The actual token.
8389 final IBinder token;
8390
8391 // The type of window this token is for, as per WindowManager.LayoutParams.
8392 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008394 // Set if this token was explicitly added by a client, so should
8395 // not be removed when all windows are removed.
8396 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008397
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008398 // For printing.
8399 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008401 // If this is an AppWindowToken, this is non-null.
8402 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008404 // All of the windows associated with this token.
8405 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8406
8407 // Is key dispatching paused for this token?
8408 boolean paused = false;
8409
8410 // Should this token's windows be hidden?
8411 boolean hidden;
8412
8413 // Temporary for finding which tokens no longer have visible windows.
8414 boolean hasVisible;
8415
Dianne Hackborna8f60182009-09-01 19:01:50 -07008416 // Set to true when this token is in a pending transaction where it
8417 // will be shown.
8418 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008419
Dianne Hackborna8f60182009-09-01 19:01:50 -07008420 // Set to true when this token is in a pending transaction where it
8421 // will be hidden.
8422 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008423
Dianne Hackborna8f60182009-09-01 19:01:50 -07008424 // Set to true when this token is in a pending transaction where its
8425 // windows will be put to the bottom of the list.
8426 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008427
Dianne Hackborna8f60182009-09-01 19:01:50 -07008428 // Set to true when this token is in a pending transaction where its
8429 // windows will be put to the top of the list.
8430 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008432 WindowToken(IBinder _token, int type, boolean _explicit) {
8433 token = _token;
8434 windowType = type;
8435 explicit = _explicit;
8436 }
8437
8438 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008439 pw.print(prefix); pw.print("token="); pw.println(token);
8440 pw.print(prefix); pw.print("windows="); pw.println(windows);
8441 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8442 pw.print(" hidden="); pw.print(hidden);
8443 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008444 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8445 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8446 pw.print(" waitingToHide="); pw.print(waitingToHide);
8447 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8448 pw.print(" sendingToTop="); pw.println(sendingToTop);
8449 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008450 }
8451
8452 @Override
8453 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008454 if (stringName == null) {
8455 StringBuilder sb = new StringBuilder();
8456 sb.append("WindowToken{");
8457 sb.append(Integer.toHexString(System.identityHashCode(this)));
8458 sb.append(" token="); sb.append(token); sb.append('}');
8459 stringName = sb.toString();
8460 }
8461 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008462 }
8463 };
8464
8465 class AppWindowToken extends WindowToken {
8466 // Non-null only for application tokens.
8467 final IApplicationToken appToken;
8468
8469 // All of the windows and child windows that are included in this
8470 // application token. Note this list is NOT sorted!
8471 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8472
8473 int groupId = -1;
8474 boolean appFullscreen;
8475 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Romain Guy06882f82009-06-10 13:36:04 -07008476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008477 // These are used for determining when all windows associated with
8478 // an activity have been drawn, so they can be made visible together
8479 // at the same time.
8480 int lastTransactionSequence = mTransactionSequence-1;
8481 int numInterestingWindows;
8482 int numDrawnWindows;
8483 boolean inPendingTransaction;
8484 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008486 // Is this token going to be hidden in a little while? If so, it
8487 // won't be taken into account for setting the screen orientation.
8488 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008490 // Is this window's surface needed? This is almost like hidden, except
8491 // it will sometimes be true a little earlier: when the token has
8492 // been shown, but is still waiting for its app transition to execute
8493 // before making its windows shown.
8494 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008496 // Have we told the window clients to hide themselves?
8497 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008499 // Last visibility state we reported to the app token.
8500 boolean reportedVisible;
8501
8502 // Set to true when the token has been removed from the window mgr.
8503 boolean removed;
8504
8505 // Have we been asked to have this token keep the screen frozen?
8506 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008508 boolean animating;
8509 Animation animation;
8510 boolean hasTransformation;
8511 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008513 // Offset to the window of all layers in the token, for use by
8514 // AppWindowToken animations.
8515 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008517 // Information about an application starting window if displayed.
8518 StartingData startingData;
8519 WindowState startingWindow;
8520 View startingView;
8521 boolean startingDisplayed;
8522 boolean startingMoved;
8523 boolean firstWindowDrawn;
8524
8525 AppWindowToken(IApplicationToken _token) {
8526 super(_token.asBinder(),
8527 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8528 appWindowToken = this;
8529 appToken = _token;
8530 }
Romain Guy06882f82009-06-10 13:36:04 -07008531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008532 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008533 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008534 TAG, "Setting animation in " + this + ": " + anim);
8535 animation = anim;
8536 animating = false;
8537 anim.restrictDuration(MAX_ANIMATION_DURATION);
8538 anim.scaleCurrentDuration(mTransitionAnimationScale);
8539 int zorder = anim.getZAdjustment();
8540 int adj = 0;
8541 if (zorder == Animation.ZORDER_TOP) {
8542 adj = TYPE_LAYER_OFFSET;
8543 } else if (zorder == Animation.ZORDER_BOTTOM) {
8544 adj = -TYPE_LAYER_OFFSET;
8545 }
Romain Guy06882f82009-06-10 13:36:04 -07008546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008547 if (animLayerAdjustment != adj) {
8548 animLayerAdjustment = adj;
8549 updateLayers();
8550 }
8551 }
Romain Guy06882f82009-06-10 13:36:04 -07008552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008553 public void setDummyAnimation() {
8554 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008555 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008556 TAG, "Setting dummy animation in " + this);
8557 animation = sDummyAnimation;
8558 }
8559 }
8560
8561 public void clearAnimation() {
8562 if (animation != null) {
8563 animation = null;
8564 animating = true;
8565 }
8566 }
Romain Guy06882f82009-06-10 13:36:04 -07008567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008568 void updateLayers() {
8569 final int N = allAppWindows.size();
8570 final int adj = animLayerAdjustment;
8571 for (int i=0; i<N; i++) {
8572 WindowState w = allAppWindows.get(i);
8573 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008574 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008575 + w.mAnimLayer);
8576 if (w == mInputMethodTarget) {
8577 setInputMethodAnimLayerAdjustment(adj);
8578 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008579 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008580 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008581 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008582 }
8583 }
Romain Guy06882f82009-06-10 13:36:04 -07008584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008585 void sendAppVisibilityToClients() {
8586 final int N = allAppWindows.size();
8587 for (int i=0; i<N; i++) {
8588 WindowState win = allAppWindows.get(i);
8589 if (win == startingWindow && clientHidden) {
8590 // Don't hide the starting window.
8591 continue;
8592 }
8593 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008594 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008595 "Setting visibility of " + win + ": " + (!clientHidden));
8596 win.mClient.dispatchAppVisibility(!clientHidden);
8597 } catch (RemoteException e) {
8598 }
8599 }
8600 }
Romain Guy06882f82009-06-10 13:36:04 -07008601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008602 void showAllWindowsLocked() {
8603 final int NW = allAppWindows.size();
8604 for (int i=0; i<NW; i++) {
8605 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008606 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008607 "performing show on: " + w);
8608 w.performShowLocked();
8609 }
8610 }
Romain Guy06882f82009-06-10 13:36:04 -07008611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008612 // This must be called while inside a transaction.
8613 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008614 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008615 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008617 if (animation == sDummyAnimation) {
8618 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008619 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008620 // when it is really time to animate, this will be set to
8621 // a real animation and the next call will execute normally.
8622 return false;
8623 }
Romain Guy06882f82009-06-10 13:36:04 -07008624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008625 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8626 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008627 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008628 TAG, "Starting animation in " + this +
8629 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8630 + " scale=" + mTransitionAnimationScale
8631 + " allDrawn=" + allDrawn + " animating=" + animating);
8632 animation.initialize(dw, dh, dw, dh);
8633 animation.setStartTime(currentTime);
8634 animating = true;
8635 }
8636 transformation.clear();
8637 final boolean more = animation.getTransformation(
8638 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008639 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008640 TAG, "Stepped animation in " + this +
8641 ": more=" + more + ", xform=" + transformation);
8642 if (more) {
8643 // we're done!
8644 hasTransformation = true;
8645 return true;
8646 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008647 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008648 TAG, "Finished animation in " + this +
8649 " @ " + currentTime);
8650 animation = null;
8651 }
8652 } else if (animation != null) {
8653 // If the display is frozen, and there is a pending animation,
8654 // clear it and make sure we run the cleanup code.
8655 animating = true;
8656 animation = null;
8657 }
8658
8659 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008661 if (!animating) {
8662 return false;
8663 }
8664
8665 clearAnimation();
8666 animating = false;
8667 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8668 moveInputMethodWindowsIfNeededLocked(true);
8669 }
Romain Guy06882f82009-06-10 13:36:04 -07008670
Joe Onorato8a9b2202010-02-26 18:56:32 -08008671 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008672 TAG, "Animation done in " + this
8673 + ": reportedVisible=" + reportedVisible);
8674
8675 transformation.clear();
8676 if (animLayerAdjustment != 0) {
8677 animLayerAdjustment = 0;
8678 updateLayers();
8679 }
Romain Guy06882f82009-06-10 13:36:04 -07008680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008681 final int N = windows.size();
8682 for (int i=0; i<N; i++) {
8683 ((WindowState)windows.get(i)).finishExit();
8684 }
8685 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008687 return false;
8688 }
8689
8690 void updateReportedVisibilityLocked() {
8691 if (appToken == null) {
8692 return;
8693 }
Romain Guy06882f82009-06-10 13:36:04 -07008694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008695 int numInteresting = 0;
8696 int numVisible = 0;
8697 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008698
Joe Onorato8a9b2202010-02-26 18:56:32 -08008699 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008700 final int N = allAppWindows.size();
8701 for (int i=0; i<N; i++) {
8702 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008703 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008704 || win.mViewVisibility != View.VISIBLE
8705 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008706 continue;
8707 }
8708 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008709 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008710 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008711 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008712 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008713 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008714 + " pv=" + win.mPolicyVisibility
8715 + " dp=" + win.mDrawPending
8716 + " cdp=" + win.mCommitDrawPending
8717 + " ah=" + win.mAttachedHidden
8718 + " th="
8719 + (win.mAppToken != null
8720 ? win.mAppToken.hiddenRequested : false)
8721 + " a=" + win.mAnimating);
8722 }
8723 }
8724 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008725 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008726 if (!win.isAnimating()) {
8727 numVisible++;
8728 }
8729 nowGone = false;
8730 } else if (win.isAnimating()) {
8731 nowGone = false;
8732 }
8733 }
Romain Guy06882f82009-06-10 13:36:04 -07008734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008735 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008736 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008737 + numInteresting + " visible=" + numVisible);
8738 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008739 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008740 TAG, "Visibility changed in " + this
8741 + ": vis=" + nowVisible);
8742 reportedVisible = nowVisible;
8743 Message m = mH.obtainMessage(
8744 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8745 nowVisible ? 1 : 0,
8746 nowGone ? 1 : 0,
8747 this);
8748 mH.sendMessage(m);
8749 }
8750 }
Romain Guy06882f82009-06-10 13:36:04 -07008751
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008752 WindowState findMainWindow() {
8753 int j = windows.size();
8754 while (j > 0) {
8755 j--;
8756 WindowState win = windows.get(j);
8757 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8758 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8759 return win;
8760 }
8761 }
8762 return null;
8763 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008765 void dump(PrintWriter pw, String prefix) {
8766 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008767 if (appToken != null) {
8768 pw.print(prefix); pw.println("app=true");
8769 }
8770 if (allAppWindows.size() > 0) {
8771 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8772 }
8773 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008774 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008775 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8776 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8777 pw.print(" clientHidden="); pw.print(clientHidden);
8778 pw.print(" willBeHidden="); pw.print(willBeHidden);
8779 pw.print(" reportedVisible="); pw.println(reportedVisible);
8780 if (paused || freezingScreen) {
8781 pw.print(prefix); pw.print("paused="); pw.print(paused);
8782 pw.print(" freezingScreen="); pw.println(freezingScreen);
8783 }
8784 if (numInterestingWindows != 0 || numDrawnWindows != 0
8785 || inPendingTransaction || allDrawn) {
8786 pw.print(prefix); pw.print("numInterestingWindows=");
8787 pw.print(numInterestingWindows);
8788 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8789 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8790 pw.print(" allDrawn="); pw.println(allDrawn);
8791 }
8792 if (animating || animation != null) {
8793 pw.print(prefix); pw.print("animating="); pw.print(animating);
8794 pw.print(" animation="); pw.println(animation);
8795 }
8796 if (animLayerAdjustment != 0) {
8797 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8798 }
8799 if (hasTransformation) {
8800 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8801 pw.print(" transformation="); transformation.printShortString(pw);
8802 pw.println();
8803 }
8804 if (startingData != null || removed || firstWindowDrawn) {
8805 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8806 pw.print(" removed="); pw.print(removed);
8807 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8808 }
8809 if (startingWindow != null || startingView != null
8810 || startingDisplayed || startingMoved) {
8811 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8812 pw.print(" startingView="); pw.print(startingView);
8813 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8814 pw.print(" startingMoved"); pw.println(startingMoved);
8815 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008816 }
8817
8818 @Override
8819 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008820 if (stringName == null) {
8821 StringBuilder sb = new StringBuilder();
8822 sb.append("AppWindowToken{");
8823 sb.append(Integer.toHexString(System.identityHashCode(this)));
8824 sb.append(" token="); sb.append(token); sb.append('}');
8825 stringName = sb.toString();
8826 }
8827 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008828 }
8829 }
Romain Guy06882f82009-06-10 13:36:04 -07008830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008831 // -------------------------------------------------------------
8832 // DummyAnimation
8833 // -------------------------------------------------------------
8834
8835 // This is an animation that does nothing: it just immediately finishes
8836 // itself every time it is called. It is used as a stub animation in cases
8837 // where we want to synchronize multiple things that may be animating.
8838 static final class DummyAnimation extends Animation {
8839 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8840 return false;
8841 }
8842 }
8843 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008845 // -------------------------------------------------------------
8846 // Async Handler
8847 // -------------------------------------------------------------
8848
8849 static final class StartingData {
8850 final String pkg;
8851 final int theme;
8852 final CharSequence nonLocalizedLabel;
8853 final int labelRes;
8854 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008856 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8857 int _labelRes, int _icon) {
8858 pkg = _pkg;
8859 theme = _theme;
8860 nonLocalizedLabel = _nonLocalizedLabel;
8861 labelRes = _labelRes;
8862 icon = _icon;
8863 }
8864 }
8865
8866 private final class H extends Handler {
8867 public static final int REPORT_FOCUS_CHANGE = 2;
8868 public static final int REPORT_LOSING_FOCUS = 3;
8869 public static final int ANIMATE = 4;
8870 public static final int ADD_STARTING = 5;
8871 public static final int REMOVE_STARTING = 6;
8872 public static final int FINISHED_STARTING = 7;
8873 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008874 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8875 public static final int HOLD_SCREEN_CHANGED = 12;
8876 public static final int APP_TRANSITION_TIMEOUT = 13;
8877 public static final int PERSIST_ANIMATION_SCALE = 14;
8878 public static final int FORCE_GC = 15;
8879 public static final int ENABLE_SCREEN = 16;
8880 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008881 public static final int SEND_NEW_CONFIGURATION = 18;
Romain Guy06882f82009-06-10 13:36:04 -07008882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008883 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008885 public H() {
8886 }
Romain Guy06882f82009-06-10 13:36:04 -07008887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008888 @Override
8889 public void handleMessage(Message msg) {
8890 switch (msg.what) {
8891 case REPORT_FOCUS_CHANGE: {
8892 WindowState lastFocus;
8893 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008895 synchronized(mWindowMap) {
8896 lastFocus = mLastFocus;
8897 newFocus = mCurrentFocus;
8898 if (lastFocus == newFocus) {
8899 // Focus is not changing, so nothing to do.
8900 return;
8901 }
8902 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008903 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008904 // + " to " + newFocus);
8905 if (newFocus != null && lastFocus != null
8906 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008907 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008908 mLosingFocus.add(lastFocus);
8909 lastFocus = null;
8910 }
8911 }
8912
8913 if (lastFocus != newFocus) {
8914 //System.out.println("Changing focus from " + lastFocus
8915 // + " to " + newFocus);
8916 if (newFocus != null) {
8917 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008918 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008919 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8920 } catch (RemoteException e) {
8921 // Ignore if process has died.
8922 }
8923 }
8924
8925 if (lastFocus != null) {
8926 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008927 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008928 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8929 } catch (RemoteException e) {
8930 // Ignore if process has died.
8931 }
8932 }
8933 }
8934 } break;
8935
8936 case REPORT_LOSING_FOCUS: {
8937 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008939 synchronized(mWindowMap) {
8940 losers = mLosingFocus;
8941 mLosingFocus = new ArrayList<WindowState>();
8942 }
8943
8944 final int N = losers.size();
8945 for (int i=0; i<N; i++) {
8946 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008947 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008948 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8949 } catch (RemoteException e) {
8950 // Ignore if process has died.
8951 }
8952 }
8953 } break;
8954
8955 case ANIMATE: {
8956 synchronized(mWindowMap) {
8957 mAnimationPending = false;
8958 performLayoutAndPlaceSurfacesLocked();
8959 }
8960 } break;
8961
8962 case ADD_STARTING: {
8963 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8964 final StartingData sd = wtoken.startingData;
8965
8966 if (sd == null) {
8967 // Animation has been canceled... do nothing.
8968 return;
8969 }
Romain Guy06882f82009-06-10 13:36:04 -07008970
Joe Onorato8a9b2202010-02-26 18:56:32 -08008971 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008972 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008974 View view = null;
8975 try {
8976 view = mPolicy.addStartingWindow(
8977 wtoken.token, sd.pkg,
8978 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8979 sd.icon);
8980 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008981 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008982 }
8983
8984 if (view != null) {
8985 boolean abort = false;
8986
8987 synchronized(mWindowMap) {
8988 if (wtoken.removed || wtoken.startingData == null) {
8989 // If the window was successfully added, then
8990 // we need to remove it.
8991 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008992 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008993 "Aborted starting " + wtoken
8994 + ": removed=" + wtoken.removed
8995 + " startingData=" + wtoken.startingData);
8996 wtoken.startingWindow = null;
8997 wtoken.startingData = null;
8998 abort = true;
8999 }
9000 } else {
9001 wtoken.startingView = view;
9002 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009003 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009004 "Added starting " + wtoken
9005 + ": startingWindow="
9006 + wtoken.startingWindow + " startingView="
9007 + wtoken.startingView);
9008 }
9009
9010 if (abort) {
9011 try {
9012 mPolicy.removeStartingWindow(wtoken.token, view);
9013 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009014 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009015 }
9016 }
9017 }
9018 } break;
9019
9020 case REMOVE_STARTING: {
9021 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9022 IBinder token = null;
9023 View view = null;
9024 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009025 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009026 + wtoken + ": startingWindow="
9027 + wtoken.startingWindow + " startingView="
9028 + wtoken.startingView);
9029 if (wtoken.startingWindow != null) {
9030 view = wtoken.startingView;
9031 token = wtoken.token;
9032 wtoken.startingData = null;
9033 wtoken.startingView = null;
9034 wtoken.startingWindow = null;
9035 }
9036 }
9037 if (view != null) {
9038 try {
9039 mPolicy.removeStartingWindow(token, view);
9040 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009041 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009042 }
9043 }
9044 } break;
9045
9046 case FINISHED_STARTING: {
9047 IBinder token = null;
9048 View view = null;
9049 while (true) {
9050 synchronized (mWindowMap) {
9051 final int N = mFinishedStarting.size();
9052 if (N <= 0) {
9053 break;
9054 }
9055 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
9056
Joe Onorato8a9b2202010-02-26 18:56:32 -08009057 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009058 "Finished starting " + wtoken
9059 + ": startingWindow=" + wtoken.startingWindow
9060 + " startingView=" + wtoken.startingView);
9061
9062 if (wtoken.startingWindow == null) {
9063 continue;
9064 }
9065
9066 view = wtoken.startingView;
9067 token = wtoken.token;
9068 wtoken.startingData = null;
9069 wtoken.startingView = null;
9070 wtoken.startingWindow = null;
9071 }
9072
9073 try {
9074 mPolicy.removeStartingWindow(token, view);
9075 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009076 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009077 }
9078 }
9079 } break;
9080
9081 case REPORT_APPLICATION_TOKEN_WINDOWS: {
9082 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9083
9084 boolean nowVisible = msg.arg1 != 0;
9085 boolean nowGone = msg.arg2 != 0;
9086
9087 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009088 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009089 TAG, "Reporting visible in " + wtoken
9090 + " visible=" + nowVisible
9091 + " gone=" + nowGone);
9092 if (nowVisible) {
9093 wtoken.appToken.windowsVisible();
9094 } else {
9095 wtoken.appToken.windowsGone();
9096 }
9097 } catch (RemoteException ex) {
9098 }
9099 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009101 case WINDOW_FREEZE_TIMEOUT: {
9102 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009103 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009104 int i = mWindows.size();
9105 while (i > 0) {
9106 i--;
9107 WindowState w = (WindowState)mWindows.get(i);
9108 if (w.mOrientationChanging) {
9109 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009110 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009111 }
9112 }
9113 performLayoutAndPlaceSurfacesLocked();
9114 }
9115 break;
9116 }
Romain Guy06882f82009-06-10 13:36:04 -07009117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009118 case HOLD_SCREEN_CHANGED: {
9119 Session oldHold;
9120 Session newHold;
9121 synchronized (mWindowMap) {
9122 oldHold = mLastReportedHold;
9123 newHold = (Session)msg.obj;
9124 mLastReportedHold = newHold;
9125 }
Romain Guy06882f82009-06-10 13:36:04 -07009126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009127 if (oldHold != newHold) {
9128 try {
9129 if (oldHold != null) {
9130 mBatteryStats.noteStopWakelock(oldHold.mUid,
9131 "window",
9132 BatteryStats.WAKE_TYPE_WINDOW);
9133 }
9134 if (newHold != null) {
9135 mBatteryStats.noteStartWakelock(newHold.mUid,
9136 "window",
9137 BatteryStats.WAKE_TYPE_WINDOW);
9138 }
9139 } catch (RemoteException e) {
9140 }
9141 }
9142 break;
9143 }
Romain Guy06882f82009-06-10 13:36:04 -07009144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009145 case APP_TRANSITION_TIMEOUT: {
9146 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009147 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009148 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009149 "*** APP TRANSITION TIMEOUT");
9150 mAppTransitionReady = true;
9151 mAppTransitionTimeout = true;
9152 performLayoutAndPlaceSurfacesLocked();
9153 }
9154 }
9155 break;
9156 }
Romain Guy06882f82009-06-10 13:36:04 -07009157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009158 case PERSIST_ANIMATION_SCALE: {
9159 Settings.System.putFloat(mContext.getContentResolver(),
9160 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9161 Settings.System.putFloat(mContext.getContentResolver(),
9162 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9163 break;
9164 }
Romain Guy06882f82009-06-10 13:36:04 -07009165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009166 case FORCE_GC: {
9167 synchronized(mWindowMap) {
9168 if (mAnimationPending) {
9169 // If we are animating, don't do the gc now but
9170 // delay a bit so we don't interrupt the animation.
9171 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9172 2000);
9173 return;
9174 }
9175 // If we are currently rotating the display, it will
9176 // schedule a new message when done.
9177 if (mDisplayFrozen) {
9178 return;
9179 }
9180 mFreezeGcPending = 0;
9181 }
9182 Runtime.getRuntime().gc();
9183 break;
9184 }
Romain Guy06882f82009-06-10 13:36:04 -07009185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009186 case ENABLE_SCREEN: {
9187 performEnableScreen();
9188 break;
9189 }
Romain Guy06882f82009-06-10 13:36:04 -07009190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009191 case APP_FREEZE_TIMEOUT: {
9192 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009193 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009194 int i = mAppTokens.size();
9195 while (i > 0) {
9196 i--;
9197 AppWindowToken tok = mAppTokens.get(i);
9198 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009199 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009200 unsetAppFreezingScreenLocked(tok, true, true);
9201 }
9202 }
9203 }
9204 break;
9205 }
Romain Guy06882f82009-06-10 13:36:04 -07009206
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009207 case SEND_NEW_CONFIGURATION: {
9208 removeMessages(SEND_NEW_CONFIGURATION);
9209 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009210 break;
9211 }
Romain Guy06882f82009-06-10 13:36:04 -07009212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009213 }
9214 }
9215 }
9216
9217 // -------------------------------------------------------------
9218 // IWindowManager API
9219 // -------------------------------------------------------------
9220
9221 public IWindowSession openSession(IInputMethodClient client,
9222 IInputContext inputContext) {
9223 if (client == null) throw new IllegalArgumentException("null client");
9224 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
9225 return new Session(client, inputContext);
9226 }
9227
9228 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9229 synchronized (mWindowMap) {
9230 // The focus for the client is the window immediately below
9231 // where we would place the input method window.
9232 int idx = findDesiredInputMethodWindowIndexLocked(false);
9233 WindowState imFocus;
9234 if (idx > 0) {
9235 imFocus = (WindowState)mWindows.get(idx-1);
9236 if (imFocus != null) {
9237 if (imFocus.mSession.mClient != null &&
9238 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9239 return true;
9240 }
9241 }
9242 }
9243 }
9244 return false;
9245 }
Romain Guy06882f82009-06-10 13:36:04 -07009246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009247 // -------------------------------------------------------------
9248 // Internals
9249 // -------------------------------------------------------------
9250
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009251 final WindowState windowForClientLocked(Session session, IWindow client,
9252 boolean throwOnError) {
9253 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009254 }
Romain Guy06882f82009-06-10 13:36:04 -07009255
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009256 final WindowState windowForClientLocked(Session session, IBinder client,
9257 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009258 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009259 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009260 TAG, "Looking up client " + client + ": " + win);
9261 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009262 RuntimeException ex = new IllegalArgumentException(
9263 "Requested window " + client + " does not exist");
9264 if (throwOnError) {
9265 throw ex;
9266 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009267 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009268 return null;
9269 }
9270 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009271 RuntimeException ex = new IllegalArgumentException(
9272 "Requested window " + client + " is in session " +
9273 win.mSession + ", not " + session);
9274 if (throwOnError) {
9275 throw ex;
9276 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009277 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009278 return null;
9279 }
9280
9281 return win;
9282 }
9283
Dianne Hackborna8f60182009-09-01 19:01:50 -07009284 final void rebuildAppWindowListLocked() {
9285 int NW = mWindows.size();
9286 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009287 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009288 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009289
Dianne Hackborna8f60182009-09-01 19:01:50 -07009290 // First remove all existing app windows.
9291 i=0;
9292 while (i < NW) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009293 WindowState w = (WindowState)mWindows.get(i);
9294 if (w.mAppToken != null) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009295 WindowState win = (WindowState)mWindows.remove(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009296 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009297 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009298 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009299 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009300 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009301 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9302 && lastWallpaper == i-1) {
9303 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009304 }
9305 i++;
9306 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009307
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009308 // The wallpaper window(s) typically live at the bottom of the stack,
9309 // so skip them before adding app tokens.
9310 lastWallpaper++;
9311 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009312
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009313 // First add all of the exiting app tokens... these are no longer
9314 // in the main app list, but still have windows shown. We put them
9315 // in the back because now that the animation is over we no longer
9316 // will care about them.
9317 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009318 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009319 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9320 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009321
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009322 // And add in the still active app tokens in Z order.
9323 NT = mAppTokens.size();
9324 for (int j=0; j<NT; j++) {
9325 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009326 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009327
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009328 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009329 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009330 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009331 + " windows but added " + i);
9332 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009333 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009335 private final void assignLayersLocked() {
9336 int N = mWindows.size();
9337 int curBaseLayer = 0;
9338 int curLayer = 0;
9339 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009341 for (i=0; i<N; i++) {
9342 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009343 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9344 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009345 curLayer += WINDOW_LAYER_MULTIPLIER;
9346 w.mLayer = curLayer;
9347 } else {
9348 curBaseLayer = curLayer = w.mBaseLayer;
9349 w.mLayer = curLayer;
9350 }
9351 if (w.mTargetAppToken != null) {
9352 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9353 } else if (w.mAppToken != null) {
9354 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9355 } else {
9356 w.mAnimLayer = w.mLayer;
9357 }
9358 if (w.mIsImWindow) {
9359 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009360 } else if (w.mIsWallpaper) {
9361 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009362 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009363 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009364 + w.mAnimLayer);
9365 //System.out.println(
9366 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9367 }
9368 }
9369
9370 private boolean mInLayout = false;
9371 private final void performLayoutAndPlaceSurfacesLocked() {
9372 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009373 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009374 throw new RuntimeException("Recursive call!");
9375 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009376 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009377 return;
9378 }
9379
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009380 if (mWaitingForConfig) {
9381 // Our configuration has changed (most likely rotation), but we
9382 // don't yet have the complete configuration to report to
9383 // applications. Don't do any window layout until we have it.
9384 return;
9385 }
9386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009387 boolean recoveringMemory = false;
9388 if (mForceRemoves != null) {
9389 recoveringMemory = true;
9390 // Wait a little it for things to settle down, and off we go.
9391 for (int i=0; i<mForceRemoves.size(); i++) {
9392 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009393 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009394 removeWindowInnerLocked(ws.mSession, ws);
9395 }
9396 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009397 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009398 Object tmp = new Object();
9399 synchronized (tmp) {
9400 try {
9401 tmp.wait(250);
9402 } catch (InterruptedException e) {
9403 }
9404 }
9405 }
Romain Guy06882f82009-06-10 13:36:04 -07009406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009407 mInLayout = true;
9408 try {
9409 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009411 int i = mPendingRemove.size()-1;
9412 if (i >= 0) {
9413 while (i >= 0) {
9414 WindowState w = mPendingRemove.get(i);
9415 removeWindowInnerLocked(w.mSession, w);
9416 i--;
9417 }
9418 mPendingRemove.clear();
9419
9420 mInLayout = false;
9421 assignLayersLocked();
9422 mLayoutNeeded = true;
9423 performLayoutAndPlaceSurfacesLocked();
9424
9425 } else {
9426 mInLayout = false;
9427 if (mLayoutNeeded) {
9428 requestAnimationLocked(0);
9429 }
9430 }
9431 } catch (RuntimeException e) {
9432 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009433 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009434 }
9435 }
9436
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009437 private final int performLayoutLockedInner() {
9438 if (!mLayoutNeeded) {
9439 return 0;
9440 }
9441
9442 mLayoutNeeded = false;
9443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009444 final int dw = mDisplay.getWidth();
9445 final int dh = mDisplay.getHeight();
9446
9447 final int N = mWindows.size();
9448 int i;
9449
Joe Onorato8a9b2202010-02-26 18:56:32 -08009450 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009451 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9452
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009453 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009454
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009455 int seq = mLayoutSeq+1;
9456 if (seq < 0) seq = 0;
9457 mLayoutSeq = seq;
9458
9459 // First perform layout of any root windows (not attached
9460 // to another window).
9461 int topAttached = -1;
9462 for (i = N-1; i >= 0; i--) {
9463 WindowState win = (WindowState) mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009464
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009465 // Don't do layout of a window if it is not visible, or
9466 // soon won't be visible, to avoid wasting time and funky
9467 // changes while a window is animating away.
9468 final AppWindowToken atoken = win.mAppToken;
9469 final boolean gone = win.mViewVisibility == View.GONE
9470 || !win.mRelayoutCalled
9471 || win.mRootToken.hidden
9472 || (atoken != null && atoken.hiddenRequested)
9473 || win.mAttachedHidden
9474 || win.mExiting || win.mDestroying;
9475
9476 if (!win.mLayoutAttached) {
9477 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
9478 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9479 + " mLayoutAttached=" + win.mLayoutAttached);
9480 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
9481 + win.mViewVisibility + " mRelayoutCalled="
9482 + win.mRelayoutCalled + " hidden="
9483 + win.mRootToken.hidden + " hiddenRequested="
9484 + (atoken != null && atoken.hiddenRequested)
9485 + " mAttachedHidden=" + win.mAttachedHidden);
9486 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009487
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009488 // If this view is GONE, then skip it -- keep the current
9489 // frame, and let the caller know so they can ignore it
9490 // if they want. (We do the normal layout for INVISIBLE
9491 // windows, since that means "perform layout as normal,
9492 // just don't display").
9493 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009494 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009495 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9496 win.mLayoutSeq = seq;
9497 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9498 + win.mFrame + " mContainingFrame="
9499 + win.mContainingFrame + " mDisplayFrame="
9500 + win.mDisplayFrame);
9501 } else {
9502 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009503 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009504 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009505 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009506
9507 // Now perform layout of attached windows, which usually
9508 // depend on the position of the window they are attached to.
9509 // XXX does not deal with windows that are attached to windows
9510 // that are themselves attached.
9511 for (i = topAttached; i >= 0; i--) {
9512 WindowState win = (WindowState) mWindows.get(i);
9513
9514 // If this view is GONE, then skip it -- keep the current
9515 // frame, and let the caller know so they can ignore it
9516 // if they want. (We do the normal layout for INVISIBLE
9517 // windows, since that means "perform layout as normal,
9518 // just don't display").
9519 if (win.mLayoutAttached) {
9520 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9521 + " mHaveFrame=" + win.mHaveFrame
9522 + " mViewVisibility=" + win.mViewVisibility
9523 + " mRelayoutCalled=" + win.mRelayoutCalled);
9524 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9525 || !win.mHaveFrame) {
9526 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9527 win.mLayoutSeq = seq;
9528 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9529 + win.mFrame + " mContainingFrame="
9530 + win.mContainingFrame + " mDisplayFrame="
9531 + win.mDisplayFrame);
9532 }
9533 }
9534 }
9535
9536 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009537 }
Romain Guy06882f82009-06-10 13:36:04 -07009538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009539 private final void performLayoutAndPlaceSurfacesLockedInner(
9540 boolean recoveringMemory) {
9541 final long currentTime = SystemClock.uptimeMillis();
9542 final int dw = mDisplay.getWidth();
9543 final int dh = mDisplay.getHeight();
9544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009545 int i;
9546
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009547 if (mFocusMayChange) {
9548 mFocusMayChange = false;
9549 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9550 }
9551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009552 if (mFxSession == null) {
9553 mFxSession = new SurfaceSession();
9554 }
Romain Guy06882f82009-06-10 13:36:04 -07009555
Joe Onorato8a9b2202010-02-26 18:56:32 -08009556 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009557
9558 // Initialize state of exiting tokens.
9559 for (i=mExitingTokens.size()-1; i>=0; i--) {
9560 mExitingTokens.get(i).hasVisible = false;
9561 }
9562
9563 // Initialize state of exiting applications.
9564 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9565 mExitingAppTokens.get(i).hasVisible = false;
9566 }
9567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009568 boolean orientationChangeComplete = true;
9569 Session holdScreen = null;
9570 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009571 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009572 boolean focusDisplayed = false;
9573 boolean animating = false;
9574
9575 Surface.openTransaction();
9576 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009577 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009578 int repeats = 0;
9579 int changes = 0;
9580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009581 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009582 repeats++;
9583 if (repeats > 6) {
9584 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9585 mLayoutNeeded = false;
9586 break;
9587 }
9588
9589 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9590 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9591 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9592 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9593 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9594 assignLayersLocked();
9595 mLayoutNeeded = true;
9596 }
9597 }
9598 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9599 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9600 if (updateOrientationFromAppTokensLocked()) {
9601 mLayoutNeeded = true;
9602 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9603 }
9604 }
9605 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9606 mLayoutNeeded = true;
9607 }
9608 }
9609
9610 // FIRST LOOP: Perform a layout, if needed.
9611 if (repeats < 4) {
9612 changes = performLayoutLockedInner();
9613 if (changes != 0) {
9614 continue;
9615 }
9616 } else {
9617 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9618 changes = 0;
9619 }
9620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009621 final int transactionSequence = ++mTransactionSequence;
9622
9623 // Update animations of all applications, including those
9624 // associated with exiting/removed apps
9625 boolean tokensAnimating = false;
9626 final int NAT = mAppTokens.size();
9627 for (i=0; i<NAT; i++) {
9628 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9629 tokensAnimating = true;
9630 }
9631 }
9632 final int NEAT = mExitingAppTokens.size();
9633 for (i=0; i<NEAT; i++) {
9634 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9635 tokensAnimating = true;
9636 }
9637 }
9638
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009639 // SECOND LOOP: Execute animations and update visibility of windows.
9640
Joe Onorato8a9b2202010-02-26 18:56:32 -08009641 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009642 + transactionSequence + " tokensAnimating="
9643 + tokensAnimating);
9644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009645 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009646
9647 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009648 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009649 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009650
9651 mPolicy.beginAnimationLw(dw, dh);
9652
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009653 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009655 for (i=N-1; i>=0; i--) {
9656 WindowState w = (WindowState)mWindows.get(i);
9657
9658 final WindowManager.LayoutParams attrs = w.mAttrs;
9659
9660 if (w.mSurface != null) {
9661 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009662 if (w.commitFinishDrawingLocked(currentTime)) {
9663 if ((w.mAttrs.flags
9664 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009665 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009666 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009667 wallpaperMayChange = true;
9668 }
9669 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009670
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009671 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009672 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9673 animating = true;
9674 //w.dump(" ");
9675 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009676 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9677 wallpaperMayChange = true;
9678 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009679
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009680 if (mPolicy.doesForceHide(w, attrs)) {
9681 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009682 if (DEBUG_VISIBILITY) Slog.v(TAG,
9683 "Animation done that could impact force hide: "
9684 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009685 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009686 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009687 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9688 forceHiding = true;
9689 }
9690 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9691 boolean changed;
9692 if (forceHiding) {
9693 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009694 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9695 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009696 } else {
9697 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009698 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9699 "Now policy shown: " + w);
9700 if (changed) {
9701 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009702 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009703 // Assume we will need to animate. If
9704 // we don't (because the wallpaper will
9705 // stay with the lock screen), then we will
9706 // clean up later.
9707 Animation a = mPolicy.createForceHideEnterAnimation();
9708 if (a != null) {
9709 w.setAnimation(a);
9710 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009711 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009712 if (mCurrentFocus == null ||
9713 mCurrentFocus.mLayer < w.mLayer) {
9714 // We are showing on to of the current
9715 // focus, so re-evaluate focus to make
9716 // sure it is correct.
9717 mFocusMayChange = true;
9718 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009719 }
9720 }
9721 if (changed && (attrs.flags
9722 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9723 wallpaperMayChange = true;
9724 }
9725 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009727 mPolicy.animatingWindowLw(w, attrs);
9728 }
9729
9730 final AppWindowToken atoken = w.mAppToken;
9731 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9732 if (atoken.lastTransactionSequence != transactionSequence) {
9733 atoken.lastTransactionSequence = transactionSequence;
9734 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9735 atoken.startingDisplayed = false;
9736 }
9737 if ((w.isOnScreen() || w.mAttrs.type
9738 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9739 && !w.mExiting && !w.mDestroying) {
9740 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009741 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009742 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009743 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009744 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009745 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009746 + " pv=" + w.mPolicyVisibility
9747 + " dp=" + w.mDrawPending
9748 + " cdp=" + w.mCommitDrawPending
9749 + " ah=" + w.mAttachedHidden
9750 + " th=" + atoken.hiddenRequested
9751 + " a=" + w.mAnimating);
9752 }
9753 }
9754 if (w != atoken.startingWindow) {
9755 if (!atoken.freezingScreen || !w.mAppFreezing) {
9756 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009757 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009758 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009759 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009760 "tokenMayBeDrawn: " + atoken
9761 + " freezingScreen=" + atoken.freezingScreen
9762 + " mAppFreezing=" + w.mAppFreezing);
9763 tokenMayBeDrawn = true;
9764 }
9765 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009766 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009767 atoken.startingDisplayed = true;
9768 }
9769 }
9770 } else if (w.mReadyToShow) {
9771 w.performShowLocked();
9772 }
9773 }
9774
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009775 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009776
9777 if (tokenMayBeDrawn) {
9778 // See if any windows have been drawn, so they (and others
9779 // associated with them) can now be shown.
9780 final int NT = mTokenList.size();
9781 for (i=0; i<NT; i++) {
9782 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9783 if (wtoken == null) {
9784 continue;
9785 }
9786 if (wtoken.freezingScreen) {
9787 int numInteresting = wtoken.numInterestingWindows;
9788 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009789 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009790 "allDrawn: " + wtoken
9791 + " interesting=" + numInteresting
9792 + " drawn=" + wtoken.numDrawnWindows);
9793 wtoken.showAllWindowsLocked();
9794 unsetAppFreezingScreenLocked(wtoken, false, true);
9795 orientationChangeComplete = true;
9796 }
9797 } else if (!wtoken.allDrawn) {
9798 int numInteresting = wtoken.numInterestingWindows;
9799 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009800 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009801 "allDrawn: " + wtoken
9802 + " interesting=" + numInteresting
9803 + " drawn=" + wtoken.numDrawnWindows);
9804 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009805 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009806
9807 // We can now show all of the drawn windows!
9808 if (!mOpeningApps.contains(wtoken)) {
9809 wtoken.showAllWindowsLocked();
9810 }
9811 }
9812 }
9813 }
9814 }
9815
9816 // If we are ready to perform an app transition, check through
9817 // all of the app tokens to be shown and see if they are ready
9818 // to go.
9819 if (mAppTransitionReady) {
9820 int NN = mOpeningApps.size();
9821 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009822 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009823 "Checking " + NN + " opening apps (frozen="
9824 + mDisplayFrozen + " timeout="
9825 + mAppTransitionTimeout + ")...");
9826 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9827 // If the display isn't frozen, wait to do anything until
9828 // all of the apps are ready. Otherwise just go because
9829 // we'll unfreeze the display when everyone is ready.
9830 for (i=0; i<NN && goodToGo; i++) {
9831 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009832 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009833 "Check opening app" + wtoken + ": allDrawn="
9834 + wtoken.allDrawn + " startingDisplayed="
9835 + wtoken.startingDisplayed);
9836 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9837 && !wtoken.startingMoved) {
9838 goodToGo = false;
9839 }
9840 }
9841 }
9842 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009843 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009844 int transit = mNextAppTransition;
9845 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009846 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009847 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009848 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009849 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009850 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009851 mAppTransitionTimeout = false;
9852 mStartingIconInTransition = false;
9853 mSkipAppTransitionAnimation = false;
9854
9855 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9856
Dianne Hackborna8f60182009-09-01 19:01:50 -07009857 // If there are applications waiting to come to the
9858 // top of the stack, now is the time to move their windows.
9859 // (Note that we don't do apps going to the bottom
9860 // here -- we want to keep their windows in the old
9861 // Z-order until the animation completes.)
9862 if (mToTopApps.size() > 0) {
9863 NN = mAppTokens.size();
9864 for (i=0; i<NN; i++) {
9865 AppWindowToken wtoken = mAppTokens.get(i);
9866 if (wtoken.sendingToTop) {
9867 wtoken.sendingToTop = false;
9868 moveAppWindowsLocked(wtoken, NN, false);
9869 }
9870 }
9871 mToTopApps.clear();
9872 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009873
Dianne Hackborn25994b42009-09-04 14:21:19 -07009874 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009875
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009876 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009877 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009878
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009879 // The top-most window will supply the layout params,
9880 // and we will determine it below.
9881 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009882 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009883 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009884
Joe Onorato8a9b2202010-02-26 18:56:32 -08009885 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009886 "New wallpaper target=" + mWallpaperTarget
9887 + ", lower target=" + mLowerWallpaperTarget
9888 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009889 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009890 // Do a first pass through the tokens for two
9891 // things:
9892 // (1) Determine if both the closing and opening
9893 // app token sets are wallpaper targets, in which
9894 // case special animations are needed
9895 // (since the wallpaper needs to stay static
9896 // behind them).
9897 // (2) Find the layout params of the top-most
9898 // application window in the tokens, which is
9899 // what will control the animation theme.
9900 final int NC = mClosingApps.size();
9901 NN = NC + mOpeningApps.size();
9902 for (i=0; i<NN; i++) {
9903 AppWindowToken wtoken;
9904 int mode;
9905 if (i < NC) {
9906 wtoken = mClosingApps.get(i);
9907 mode = 1;
9908 } else {
9909 wtoken = mOpeningApps.get(i-NC);
9910 mode = 2;
9911 }
9912 if (mLowerWallpaperTarget != null) {
9913 if (mLowerWallpaperTarget.mAppToken == wtoken
9914 || mUpperWallpaperTarget.mAppToken == wtoken) {
9915 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009916 }
9917 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009918 if (wtoken.appFullscreen) {
9919 WindowState ws = wtoken.findMainWindow();
9920 if (ws != null) {
9921 // If this is a compatibility mode
9922 // window, we will always use its anim.
9923 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9924 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009925 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009926 bestAnimLayer = Integer.MAX_VALUE;
9927 } else if (ws.mLayer > bestAnimLayer) {
9928 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009929 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009930 bestAnimLayer = ws.mLayer;
9931 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009932 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009933 }
9934 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009935
Dianne Hackborn25994b42009-09-04 14:21:19 -07009936 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009937 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009938 "Wallpaper animation!");
9939 switch (transit) {
9940 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9941 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9942 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9943 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9944 break;
9945 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9946 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9947 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9948 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9949 break;
9950 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009951 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009952 "New transit: " + transit);
9953 } else if (oldWallpaper != null) {
9954 // We are transitioning from an activity with
9955 // a wallpaper to one without.
9956 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009957 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009958 "New transit away from wallpaper: " + transit);
9959 } else if (mWallpaperTarget != null) {
9960 // We are transitioning from an activity without
9961 // a wallpaper to now showing the wallpaper
9962 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009963 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009964 "New transit into wallpaper: " + transit);
9965 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009966
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009967 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9968 mLastEnterAnimToken = animToken;
9969 mLastEnterAnimParams = animLp;
9970 } else if (mLastEnterAnimParams != null) {
9971 animLp = mLastEnterAnimParams;
9972 mLastEnterAnimToken = null;
9973 mLastEnterAnimParams = null;
9974 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009975
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009976 // If all closing windows are obscured, then there is
9977 // no need to do an animation. This is the case, for
9978 // example, when this transition is being done behind
9979 // the lock screen.
9980 if (!mPolicy.allowAppAnimationsLw()) {
9981 animLp = null;
9982 }
9983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009984 NN = mOpeningApps.size();
9985 for (i=0; i<NN; i++) {
9986 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009987 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009988 "Now opening app" + wtoken);
9989 wtoken.reportedVisible = false;
9990 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009991 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009992 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009993 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009994 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009995 wtoken.showAllWindowsLocked();
9996 }
9997 NN = mClosingApps.size();
9998 for (i=0; i<NN; i++) {
9999 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010000 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010001 "Now closing app" + wtoken);
10002 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010003 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010004 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010005 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010006 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010007 // Force the allDrawn flag, because we want to start
10008 // this guy's animations regardless of whether it's
10009 // gotten drawn.
10010 wtoken.allDrawn = true;
10011 }
10012
Dianne Hackborn8b571a82009-09-25 16:09:43 -070010013 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010015 mOpeningApps.clear();
10016 mClosingApps.clear();
10017
10018 // This has changed the visibility of windows, so perform
10019 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010020 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010021 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -070010022 if (!moveInputMethodWindowsIfNeededLocked(true)) {
10023 assignLayersLocked();
10024 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010025 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010026 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010027 }
10028 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010029
Dianne Hackborn16064f92010-03-25 00:47:24 -070010030 int adjResult = 0;
10031
Dianne Hackborna8f60182009-09-01 19:01:50 -070010032 if (!animating && mAppTransitionRunning) {
10033 // We have finished the animation of an app transition. To do
10034 // this, we have delayed a lot of operations like showing and
10035 // hiding apps, moving apps in Z-order, etc. The app token list
10036 // reflects the correct Z-order, but the window list may now
10037 // be out of sync with it. So here we will just rebuild the
10038 // entire app window list. Fun!
10039 mAppTransitionRunning = false;
10040 // Clear information about apps that were moving.
10041 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010042
Dianne Hackborna8f60182009-09-01 19:01:50 -070010043 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010044 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010045 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010046 moveInputMethodWindowsIfNeededLocked(false);
10047 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010048 // Since the window list has been rebuilt, focus might
10049 // have to be recomputed since the actual order of windows
10050 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010051 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010052 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010053
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010054 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010055 // At this point, there was a window with a wallpaper that
10056 // was force hiding other windows behind it, but now it
10057 // is going away. This may be simple -- just animate
10058 // away the wallpaper and its window -- or it may be
10059 // hard -- the wallpaper now needs to be shown behind
10060 // something that was hidden.
10061 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010062 if (mLowerWallpaperTarget != null
10063 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010064 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010065 "wallpaperForceHiding changed with lower="
10066 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010067 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010068 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10069 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10070 if (mLowerWallpaperTarget.mAppToken.hidden) {
10071 // The lower target has become hidden before we
10072 // actually started the animation... let's completely
10073 // re-evaluate everything.
10074 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010075 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010076 }
10077 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010078 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010079 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010080 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010081 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010082 + " NEW: " + mWallpaperTarget
10083 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010084 if (mLowerWallpaperTarget == null) {
10085 // Whoops, we don't need a special wallpaper animation.
10086 // Clear them out.
10087 forceHiding = false;
10088 for (i=N-1; i>=0; i--) {
10089 WindowState w = (WindowState)mWindows.get(i);
10090 if (w.mSurface != null) {
10091 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010092 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010093 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010094 forceHiding = true;
10095 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10096 if (!w.mAnimating) {
10097 // We set the animation above so it
10098 // is not yet running.
10099 w.clearAnimation();
10100 }
10101 }
10102 }
10103 }
10104 }
10105 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010106
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010107 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010108 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010109 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010110 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010111 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010112
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010113 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010114 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010115 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010116 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010117 assignLayersLocked();
10118 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010119 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010120 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010121 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010122 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010123
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010124 if (mFocusMayChange) {
10125 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010126 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010127 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010128 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010129 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010130 }
10131
10132 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010133 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010134 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010135
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010136 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10137 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010138
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010139 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010140
10141 // THIRD LOOP: Update the surfaces of all windows.
10142
10143 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10144
10145 boolean obscured = false;
10146 boolean blurring = false;
10147 boolean dimming = false;
10148 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010149 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010150 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010151
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010152 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010154 for (i=N-1; i>=0; i--) {
10155 WindowState w = (WindowState)mWindows.get(i);
10156
10157 boolean displayed = false;
10158 final WindowManager.LayoutParams attrs = w.mAttrs;
10159 final int attrFlags = attrs.flags;
10160
10161 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010162 // XXX NOTE: The logic here could be improved. We have
10163 // the decision about whether to resize a window separated
10164 // from whether to hide the surface. This can cause us to
10165 // resize a surface even if we are going to hide it. You
10166 // can see this by (1) holding device in landscape mode on
10167 // home screen; (2) tapping browser icon (device will rotate
10168 // to landscape; (3) tap home. The wallpaper will be resized
10169 // in step 2 but then immediately hidden, causing us to
10170 // have to resize and then redraw it again in step 3. It
10171 // would be nice to figure out how to avoid this, but it is
10172 // difficult because we do need to resize surfaces in some
10173 // cases while they are hidden such as when first showing a
10174 // window.
10175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010176 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010177 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010178 TAG, "Placing surface #" + i + " " + w.mSurface
10179 + ": new=" + w.mShownFrame + ", old="
10180 + w.mLastShownFrame);
10181
10182 boolean resize;
10183 int width, height;
10184 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
10185 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
10186 w.mLastRequestedHeight != w.mRequestedHeight;
10187 // for a scaled surface, we just want to use
10188 // the requested size.
10189 width = w.mRequestedWidth;
10190 height = w.mRequestedHeight;
10191 w.mLastRequestedWidth = width;
10192 w.mLastRequestedHeight = height;
10193 w.mLastShownFrame.set(w.mShownFrame);
10194 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010195 if (SHOW_TRANSACTIONS) logSurface(w,
10196 "POS " + w.mShownFrame.left
10197 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010198 w.mSurfaceX = w.mShownFrame.left;
10199 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010200 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10201 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010202 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010203 if (!recoveringMemory) {
10204 reclaimSomeSurfaceMemoryLocked(w, "position");
10205 }
10206 }
10207 } else {
10208 resize = !w.mLastShownFrame.equals(w.mShownFrame);
10209 width = w.mShownFrame.width();
10210 height = w.mShownFrame.height();
10211 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010212 }
10213
10214 if (resize) {
10215 if (width < 1) width = 1;
10216 if (height < 1) height = 1;
10217 if (w.mSurface != null) {
10218 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010219 if (SHOW_TRANSACTIONS) logSurface(w,
10220 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010221 + w.mShownFrame.top + " SIZE "
10222 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010223 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010224 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010225 w.mSurfaceW = width;
10226 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010227 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010228 w.mSurfaceX = w.mShownFrame.left;
10229 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010230 w.mSurface.setPosition(w.mShownFrame.left,
10231 w.mShownFrame.top);
10232 } catch (RuntimeException e) {
10233 // If something goes wrong with the surface (such
10234 // as running out of memory), don't take down the
10235 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010236 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010237 + "size=(" + width + "x" + height
10238 + "), pos=(" + w.mShownFrame.left
10239 + "," + w.mShownFrame.top + ")", e);
10240 if (!recoveringMemory) {
10241 reclaimSomeSurfaceMemoryLocked(w, "size");
10242 }
10243 }
10244 }
10245 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010246 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010247 w.mContentInsetsChanged =
10248 !w.mLastContentInsets.equals(w.mContentInsets);
10249 w.mVisibleInsetsChanged =
10250 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010251 boolean configChanged =
10252 w.mConfiguration != mCurConfiguration
10253 && (w.mConfiguration == null
10254 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010255 if (DEBUG_CONFIGURATION && configChanged) {
10256 Slog.v(TAG, "Win " + w + " config changed: "
10257 + mCurConfiguration);
10258 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010259 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010260 + ": configChanged=" + configChanged
10261 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -070010262 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010263 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010264 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010265 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010266 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010267 w.mLastFrame.set(w.mFrame);
10268 w.mLastContentInsets.set(w.mContentInsets);
10269 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010270 // If the screen is currently frozen, then keep
10271 // it frozen until this window draws at its new
10272 // orientation.
10273 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010274 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010275 "Resizing while display frozen: " + w);
10276 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010277 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010278 mWindowsFreezingScreen = true;
10279 // XXX should probably keep timeout from
10280 // when we first froze the display.
10281 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10282 mH.sendMessageDelayed(mH.obtainMessage(
10283 H.WINDOW_FREEZE_TIMEOUT), 2000);
10284 }
10285 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010286 // If the orientation is changing, then we need to
10287 // hold off on unfreezing the display until this
10288 // window has been redrawn; to do that, we need
10289 // to go through the process of getting informed
10290 // by the application when it has finished drawing.
10291 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010292 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010293 "Orientation start waiting for draw in "
10294 + w + ", surface " + w.mSurface);
10295 w.mDrawPending = true;
10296 w.mCommitDrawPending = false;
10297 w.mReadyToShow = false;
10298 if (w.mAppToken != null) {
10299 w.mAppToken.allDrawn = false;
10300 }
10301 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010302 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010303 "Resizing window " + w + " to " + w.mFrame);
10304 mResizingWindows.add(w);
10305 } else if (w.mOrientationChanging) {
10306 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010307 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010308 "Orientation not waiting for draw in "
10309 + w + ", surface " + w.mSurface);
10310 w.mOrientationChanging = false;
10311 }
10312 }
10313 }
10314
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010315 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010316 if (!w.mLastHidden) {
10317 //dump();
Dianne Hackborn5943c202010-04-12 21:36:49 -070010318 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Window hiding: waitingToShow="
10319 + w.mRootToken.waitingToShow + " polvis="
10320 + w.mPolicyVisibility + " atthid="
10321 + w.mAttachedHidden + " tokhid="
10322 + w.mRootToken.hidden + " vis="
10323 + w.mViewVisibility);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010324 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010325 if (SHOW_TRANSACTIONS) logSurface(w,
10326 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010327 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010328 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010329 try {
10330 w.mSurface.hide();
10331 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010332 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010333 }
10334 }
10335 mKeyWaiter.releasePendingPointerLocked(w.mSession);
10336 }
10337 // If we are waiting for this window to handle an
10338 // orientation change, well, it is hidden, so
10339 // doesn't really matter. Note that this does
10340 // introduce a potential glitch if the window
10341 // becomes unhidden before it has drawn for the
10342 // new orientation.
10343 if (w.mOrientationChanging) {
10344 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010345 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010346 "Orientation change skips hidden " + w);
10347 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010348 } else if (w.mLastLayer != w.mAnimLayer
10349 || w.mLastAlpha != w.mShownAlpha
10350 || w.mLastDsDx != w.mDsDx
10351 || w.mLastDtDx != w.mDtDx
10352 || w.mLastDsDy != w.mDsDy
10353 || w.mLastDtDy != w.mDtDy
10354 || w.mLastHScale != w.mHScale
10355 || w.mLastVScale != w.mVScale
10356 || w.mLastHidden) {
10357 displayed = true;
10358 w.mLastAlpha = w.mShownAlpha;
10359 w.mLastLayer = w.mAnimLayer;
10360 w.mLastDsDx = w.mDsDx;
10361 w.mLastDtDx = w.mDtDx;
10362 w.mLastDsDy = w.mDsDy;
10363 w.mLastDtDy = w.mDtDy;
10364 w.mLastHScale = w.mHScale;
10365 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010366 if (SHOW_TRANSACTIONS) logSurface(w,
10367 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010368 + " matrix=[" + (w.mDsDx*w.mHScale)
10369 + "," + (w.mDtDx*w.mVScale)
10370 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010371 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010372 if (w.mSurface != null) {
10373 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010374 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010375 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010376 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010377 w.mSurface.setLayer(w.mAnimLayer);
10378 w.mSurface.setMatrix(
10379 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10380 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10381 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010382 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010383 if (!recoveringMemory) {
10384 reclaimSomeSurfaceMemoryLocked(w, "update");
10385 }
10386 }
10387 }
10388
10389 if (w.mLastHidden && !w.mDrawPending
10390 && !w.mCommitDrawPending
10391 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010392 if (SHOW_TRANSACTIONS) logSurface(w,
10393 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010394 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010395 + " during relayout");
10396 if (showSurfaceRobustlyLocked(w)) {
10397 w.mHasDrawn = true;
10398 w.mLastHidden = false;
10399 } else {
10400 w.mOrientationChanging = false;
10401 }
10402 }
10403 if (w.mSurface != null) {
10404 w.mToken.hasVisible = true;
10405 }
10406 } else {
10407 displayed = true;
10408 }
10409
10410 if (displayed) {
10411 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010412 if (attrs.width == LayoutParams.MATCH_PARENT
10413 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010414 covered = true;
10415 }
10416 }
10417 if (w.mOrientationChanging) {
10418 if (w.mDrawPending || w.mCommitDrawPending) {
10419 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010420 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010421 "Orientation continue waiting for draw in " + w);
10422 } else {
10423 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010424 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010425 "Orientation change complete in " + w);
10426 }
10427 }
10428 w.mToken.hasVisible = true;
10429 }
10430 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010431 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010432 "Orientation change skips hidden " + w);
10433 w.mOrientationChanging = false;
10434 }
10435
10436 final boolean canBeSeen = w.isDisplayedLw();
10437
10438 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10439 focusDisplayed = true;
10440 }
10441
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010442 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010444 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010445 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010446 if (w.mSurface != null) {
10447 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10448 holdScreen = w.mSession;
10449 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010450 if (!syswin && w.mAttrs.screenBrightness >= 0
10451 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010452 screenBrightness = w.mAttrs.screenBrightness;
10453 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010454 if (!syswin && w.mAttrs.buttonBrightness >= 0
10455 && buttonBrightness < 0) {
10456 buttonBrightness = w.mAttrs.buttonBrightness;
10457 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010458 if (canBeSeen
10459 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10460 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10461 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010462 syswin = true;
10463 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010464 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010465
Dianne Hackborn25994b42009-09-04 14:21:19 -070010466 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10467 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010468 // This window completely covers everything behind it,
10469 // so we want to leave all of them as unblurred (for
10470 // performance reasons).
10471 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010472 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010473 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010474 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010475 obscured = true;
10476 if (mBackgroundFillerSurface == null) {
10477 try {
10478 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010479 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010480 0, dw, dh,
10481 PixelFormat.OPAQUE,
10482 Surface.FX_SURFACE_NORMAL);
10483 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010484 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010485 }
10486 }
10487 try {
10488 mBackgroundFillerSurface.setPosition(0, 0);
10489 mBackgroundFillerSurface.setSize(dw, dh);
10490 // Using the same layer as Dim because they will never be shown at the
10491 // same time.
10492 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10493 mBackgroundFillerSurface.show();
10494 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010495 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010496 }
10497 backgroundFillerShown = true;
10498 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010499 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010500 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010501 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010502 + ": blurring=" + blurring
10503 + " obscured=" + obscured
10504 + " displayed=" + displayed);
10505 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10506 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010507 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010508 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010509 if (mDimAnimator == null) {
10510 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010511 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010512 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010513 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010514 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010515 }
10516 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10517 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010518 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010519 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010520 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010521 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010522 + mBlurSurface + ": CREATE");
10523 try {
Romain Guy06882f82009-06-10 13:36:04 -070010524 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010525 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010526 -1, 16, 16,
10527 PixelFormat.OPAQUE,
10528 Surface.FX_SURFACE_BLUR);
10529 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010530 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010531 }
10532 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010533 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010534 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10535 + mBlurSurface + ": pos=(0,0) (" +
10536 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010537 mBlurSurface.setPosition(0, 0);
10538 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010539 mBlurSurface.setLayer(w.mAnimLayer-2);
10540 if (!mBlurShown) {
10541 try {
10542 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10543 + mBlurSurface + ": SHOW");
10544 mBlurSurface.show();
10545 } catch (RuntimeException e) {
10546 Slog.w(TAG, "Failure showing blur surface", e);
10547 }
10548 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010549 }
10550 }
10551 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010552 }
10553 }
10554 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010555
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010556 if (obscuredChanged && mWallpaperTarget == w) {
10557 // This is the wallpaper target and its obscured state
10558 // changed... make sure the current wallaper's visibility
10559 // has been updated accordingly.
10560 updateWallpaperVisibilityLocked();
10561 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010562 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010563
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010564 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10565 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010566 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010567 try {
10568 mBackgroundFillerSurface.hide();
10569 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010570 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010571 }
10572 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010573
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010574 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010575 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10576 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010577 }
Romain Guy06882f82009-06-10 13:36:04 -070010578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010579 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010580 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010581 + ": HIDE");
10582 try {
10583 mBlurSurface.hide();
10584 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010585 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010586 }
10587 mBlurShown = false;
10588 }
10589
Joe Onorato8a9b2202010-02-26 18:56:32 -080010590 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010591 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010592 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010593 }
10594
10595 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010596
Joe Onorato8a9b2202010-02-26 18:56:32 -080010597 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010598 "With display frozen, orientationChangeComplete="
10599 + orientationChangeComplete);
10600 if (orientationChangeComplete) {
10601 if (mWindowsFreezingScreen) {
10602 mWindowsFreezingScreen = false;
10603 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10604 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010605 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010606 }
Romain Guy06882f82009-06-10 13:36:04 -070010607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010608 i = mResizingWindows.size();
10609 if (i > 0) {
10610 do {
10611 i--;
10612 WindowState win = mResizingWindows.get(i);
10613 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010614 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10615 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010616 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010617 boolean configChanged =
10618 win.mConfiguration != mCurConfiguration
10619 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010620 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10621 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10622 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010623 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010624 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010625 + " / " + mCurConfiguration + " / 0x"
10626 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010627 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010628 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010629 win.mClient.resized(win.mFrame.width(),
10630 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010631 win.mLastVisibleInsets, win.mDrawPending,
10632 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010633 win.mContentInsetsChanged = false;
10634 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010635 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010636 } catch (RemoteException e) {
10637 win.mOrientationChanging = false;
10638 }
10639 } while (i > 0);
10640 mResizingWindows.clear();
10641 }
Romain Guy06882f82009-06-10 13:36:04 -070010642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010643 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010644 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010645 i = mDestroySurface.size();
10646 if (i > 0) {
10647 do {
10648 i--;
10649 WindowState win = mDestroySurface.get(i);
10650 win.mDestroying = false;
10651 if (mInputMethodWindow == win) {
10652 mInputMethodWindow = null;
10653 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010654 if (win == mWallpaperTarget) {
10655 wallpaperDestroyed = true;
10656 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010657 win.destroySurfaceLocked();
10658 } while (i > 0);
10659 mDestroySurface.clear();
10660 }
10661
10662 // Time to remove any exiting tokens?
10663 for (i=mExitingTokens.size()-1; i>=0; i--) {
10664 WindowToken token = mExitingTokens.get(i);
10665 if (!token.hasVisible) {
10666 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010667 if (token.windowType == TYPE_WALLPAPER) {
10668 mWallpaperTokens.remove(token);
10669 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010670 }
10671 }
10672
10673 // Time to remove any exiting applications?
10674 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10675 AppWindowToken token = mExitingAppTokens.get(i);
10676 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010677 // Make sure there is no animation running on this token,
10678 // so any windows associated with it will be removed as
10679 // soon as their animations are complete
10680 token.animation = null;
10681 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010682 mAppTokens.remove(token);
10683 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010684 if (mLastEnterAnimToken == token) {
10685 mLastEnterAnimToken = null;
10686 mLastEnterAnimParams = null;
10687 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010688 }
10689 }
10690
Dianne Hackborna8f60182009-09-01 19:01:50 -070010691 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010692
Dianne Hackborna8f60182009-09-01 19:01:50 -070010693 if (!animating && mAppTransitionRunning) {
10694 // We have finished the animation of an app transition. To do
10695 // this, we have delayed a lot of operations like showing and
10696 // hiding apps, moving apps in Z-order, etc. The app token list
10697 // reflects the correct Z-order, but the window list may now
10698 // be out of sync with it. So here we will just rebuild the
10699 // entire app window list. Fun!
10700 mAppTransitionRunning = false;
10701 needRelayout = true;
10702 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010703 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010704 // Clear information about apps that were moving.
10705 mToBottomApps.clear();
10706 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010708 if (focusDisplayed) {
10709 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10710 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010711 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010712 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010713 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010714 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010715 requestAnimationLocked(0);
10716 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010717 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10718 }
Dianne Hackbornce73c1e2010-04-12 23:11:38 -070010719
10720 if (DEBUG_FREEZE) Slog.v(TAG, "Layout: mDisplayFrozen=" + mDisplayFrozen
10721 + " holdScreen=" + holdScreen);
10722 if (!mDisplayFrozen) {
10723 mQueue.setHoldScreenLocked(holdScreen != null);
10724 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10725 mPowerManager.setScreenBrightnessOverride(-1);
10726 } else {
10727 mPowerManager.setScreenBrightnessOverride((int)
10728 (screenBrightness * Power.BRIGHTNESS_ON));
10729 }
10730 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10731 mPowerManager.setButtonBrightnessOverride(-1);
10732 } else {
10733 mPowerManager.setButtonBrightnessOverride((int)
10734 (buttonBrightness * Power.BRIGHTNESS_ON));
10735 }
10736 if (holdScreen != mHoldingScreenOn) {
10737 mHoldingScreenOn = holdScreen;
10738 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10739 mH.sendMessage(m);
10740 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010741 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010742
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010743 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010744 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010745 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10746 LocalPowerManager.BUTTON_EVENT, true);
10747 mTurnOnScreen = false;
10748 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010749
10750 // Check to see if we are now in a state where the screen should
10751 // be enabled, because the window obscured flags have changed.
10752 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010753 }
10754
10755 void requestAnimationLocked(long delay) {
10756 if (!mAnimationPending) {
10757 mAnimationPending = true;
10758 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10759 }
10760 }
Romain Guy06882f82009-06-10 13:36:04 -070010761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010762 /**
10763 * Have the surface flinger show a surface, robustly dealing with
10764 * error conditions. In particular, if there is not enough memory
10765 * to show the surface, then we will try to get rid of other surfaces
10766 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010767 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010768 * @return Returns true if the surface was successfully shown.
10769 */
10770 boolean showSurfaceRobustlyLocked(WindowState win) {
10771 try {
10772 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010773 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010774 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010775 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010776 if (DEBUG_VISIBILITY) Slog.v(TAG,
10777 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010778 win.mTurnOnScreen = false;
10779 mTurnOnScreen = true;
10780 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010781 }
10782 return true;
10783 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010784 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010785 }
Romain Guy06882f82009-06-10 13:36:04 -070010786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010787 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010789 return false;
10790 }
Romain Guy06882f82009-06-10 13:36:04 -070010791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010792 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10793 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010794
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010795 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010796 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010798 if (mForceRemoves == null) {
10799 mForceRemoves = new ArrayList<WindowState>();
10800 }
Romain Guy06882f82009-06-10 13:36:04 -070010801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010802 long callingIdentity = Binder.clearCallingIdentity();
10803 try {
10804 // There was some problem... first, do a sanity check of the
10805 // window list to make sure we haven't left any dangling surfaces
10806 // around.
10807 int N = mWindows.size();
10808 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010809 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010810 for (int i=0; i<N; i++) {
10811 WindowState ws = (WindowState)mWindows.get(i);
10812 if (ws.mSurface != null) {
10813 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010814 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010815 + ws + " surface=" + ws.mSurface
10816 + " token=" + win.mToken
10817 + " pid=" + ws.mSession.mPid
10818 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010819 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010820 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010821 ws.mSurface = null;
10822 mForceRemoves.add(ws);
10823 i--;
10824 N--;
10825 leakedSurface = true;
10826 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010827 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010828 + ws + " surface=" + ws.mSurface
10829 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010830 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010831 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010832 ws.mSurface = null;
10833 leakedSurface = true;
10834 }
10835 }
10836 }
Romain Guy06882f82009-06-10 13:36:04 -070010837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010838 boolean killedApps = false;
10839 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010840 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010841 SparseIntArray pidCandidates = new SparseIntArray();
10842 for (int i=0; i<N; i++) {
10843 WindowState ws = (WindowState)mWindows.get(i);
10844 if (ws.mSurface != null) {
10845 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10846 }
10847 }
10848 if (pidCandidates.size() > 0) {
10849 int[] pids = new int[pidCandidates.size()];
10850 for (int i=0; i<pids.length; i++) {
10851 pids[i] = pidCandidates.keyAt(i);
10852 }
10853 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010854 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010855 killedApps = true;
10856 }
10857 } catch (RemoteException e) {
10858 }
10859 }
10860 }
Romain Guy06882f82009-06-10 13:36:04 -070010861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010862 if (leakedSurface || killedApps) {
10863 // We managed to reclaim some memory, so get rid of the trouble
10864 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010865 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010866 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010867 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010868 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010869 win.mSurface = null;
10870 }
Romain Guy06882f82009-06-10 13:36:04 -070010871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010872 try {
10873 win.mClient.dispatchGetNewSurface();
10874 } catch (RemoteException e) {
10875 }
10876 }
10877 } finally {
10878 Binder.restoreCallingIdentity(callingIdentity);
10879 }
10880 }
Romain Guy06882f82009-06-10 13:36:04 -070010881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010882 private boolean updateFocusedWindowLocked(int mode) {
10883 WindowState newFocus = computeFocusedWindowLocked();
10884 if (mCurrentFocus != newFocus) {
10885 // This check makes sure that we don't already have the focus
10886 // change message pending.
10887 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10888 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010889 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010890 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10891 final WindowState oldFocus = mCurrentFocus;
10892 mCurrentFocus = newFocus;
10893 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010895 final WindowState imWindow = mInputMethodWindow;
10896 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010897 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010898 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010899 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10900 mLayoutNeeded = true;
10901 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010902 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10903 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010904 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10905 // Client will do the layout, but we need to assign layers
10906 // for handleNewWindowLocked() below.
10907 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010908 }
10909 }
Romain Guy06882f82009-06-10 13:36:04 -070010910
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010911 if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10912 mKeyWaiter.handleNewWindowLocked(newFocus);
10913 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010914 return true;
10915 }
10916 return false;
10917 }
10918
10919 private WindowState computeFocusedWindowLocked() {
10920 WindowState result = null;
10921 WindowState win;
10922
10923 int i = mWindows.size() - 1;
10924 int nextAppIndex = mAppTokens.size()-1;
10925 WindowToken nextApp = nextAppIndex >= 0
10926 ? mAppTokens.get(nextAppIndex) : null;
10927
10928 while (i >= 0) {
10929 win = (WindowState)mWindows.get(i);
10930
Joe Onorato8a9b2202010-02-26 18:56:32 -080010931 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010932 TAG, "Looking for focus: " + i
10933 + " = " + win
10934 + ", flags=" + win.mAttrs.flags
10935 + ", canReceive=" + win.canReceiveKeys());
10936
10937 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010939 // If this window's application has been removed, just skip it.
10940 if (thisApp != null && thisApp.removed) {
10941 i--;
10942 continue;
10943 }
Romain Guy06882f82009-06-10 13:36:04 -070010944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010945 // If there is a focused app, don't allow focus to go to any
10946 // windows below it. If this is an application window, step
10947 // through the app tokens until we find its app.
10948 if (thisApp != null && nextApp != null && thisApp != nextApp
10949 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10950 int origAppIndex = nextAppIndex;
10951 while (nextAppIndex > 0) {
10952 if (nextApp == mFocusedApp) {
10953 // Whoops, we are below the focused app... no focus
10954 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010955 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010956 TAG, "Reached focused app: " + mFocusedApp);
10957 return null;
10958 }
10959 nextAppIndex--;
10960 nextApp = mAppTokens.get(nextAppIndex);
10961 if (nextApp == thisApp) {
10962 break;
10963 }
10964 }
10965 if (thisApp != nextApp) {
10966 // Uh oh, the app token doesn't exist! This shouldn't
10967 // happen, but if it does we can get totally hosed...
10968 // so restart at the original app.
10969 nextAppIndex = origAppIndex;
10970 nextApp = mAppTokens.get(nextAppIndex);
10971 }
10972 }
10973
10974 // Dispatch to this window if it is wants key events.
10975 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010976 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010977 TAG, "Found focus @ " + i + " = " + win);
10978 result = win;
10979 break;
10980 }
10981
10982 i--;
10983 }
10984
10985 return result;
10986 }
10987
10988 private void startFreezingDisplayLocked() {
10989 if (mDisplayFrozen) {
Chris Tate2ad63a92009-03-25 17:36:48 -070010990 // Freezing the display also suspends key event delivery, to
10991 // keep events from going astray while the display is reconfigured.
10992 // If someone has changed orientation again while the screen is
10993 // still frozen, the events will continue to be blocked while the
10994 // successive orientation change is processed. To prevent spurious
10995 // ANRs, we reset the event dispatch timeout in this case.
10996 synchronized (mKeyWaiter) {
10997 mKeyWaiter.mWasFrozen = true;
10998 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010999 return;
11000 }
Romain Guy06882f82009-06-10 13:36:04 -070011001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011002 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070011003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011004 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080011005 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011006 if (mFreezeGcPending != 0) {
11007 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011008 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011009 mH.removeMessages(H.FORCE_GC);
11010 Runtime.getRuntime().gc();
11011 mFreezeGcPending = now;
11012 }
11013 } else {
11014 mFreezeGcPending = now;
11015 }
Romain Guy06882f82009-06-10 13:36:04 -070011016
Dianne Hackbornce73c1e2010-04-12 23:11:38 -070011017 if (DEBUG_FREEZE) Slog.v(TAG, "*** FREEZING DISPLAY", new RuntimeException());
11018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011019 mDisplayFrozen = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070011020 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
11021 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011022 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011023 mAppTransitionReady = true;
11024 }
Romain Guy06882f82009-06-10 13:36:04 -070011025
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011026 if (PROFILE_ORIENTATION) {
11027 File file = new File("/data/system/frozen");
11028 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
11029 }
11030 Surface.freezeDisplay(0);
11031 }
Romain Guy06882f82009-06-10 13:36:04 -070011032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011033 private void stopFreezingDisplayLocked() {
11034 if (!mDisplayFrozen) {
11035 return;
11036 }
Romain Guy06882f82009-06-10 13:36:04 -070011037
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011038 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
11039 return;
11040 }
11041
Dianne Hackbornce73c1e2010-04-12 23:11:38 -070011042 if (DEBUG_FREEZE) Slog.v(TAG, "*** UNFREEZING DISPLAY", new RuntimeException());
11043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011044 mDisplayFrozen = false;
11045 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
11046 if (PROFILE_ORIENTATION) {
11047 Debug.stopMethodTracing();
11048 }
11049 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070011050
Chris Tate2ad63a92009-03-25 17:36:48 -070011051 // Reset the key delivery timeout on unfreeze, too. We force a wakeup here
11052 // too because regular key delivery processing should resume immediately.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011053 synchronized (mKeyWaiter) {
11054 mKeyWaiter.mWasFrozen = true;
11055 mKeyWaiter.notifyAll();
11056 }
11057
Christopher Tateb696aee2010-04-02 19:08:30 -070011058 // While the display is frozen we don't re-compute the orientation
11059 // to avoid inconsistent states. However, something interesting
11060 // could have actually changed during that time so re-evaluate it
11061 // now to catch that.
11062 if (updateOrientationFromAppTokensLocked()) {
11063 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
11064 }
11065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011066 // A little kludge: a lot could have happened while the
11067 // display was frozen, so now that we are coming back we
11068 // do a gc so that any remote references the system
11069 // processes holds on others can be released if they are
11070 // no longer needed.
11071 mH.removeMessages(H.FORCE_GC);
11072 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11073 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011075 mScreenFrozenLock.release();
11076 }
Romain Guy06882f82009-06-10 13:36:04 -070011077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011078 @Override
11079 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11080 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11081 != PackageManager.PERMISSION_GRANTED) {
11082 pw.println("Permission Denial: can't dump WindowManager from from pid="
11083 + Binder.getCallingPid()
11084 + ", uid=" + Binder.getCallingUid());
11085 return;
11086 }
Romain Guy06882f82009-06-10 13:36:04 -070011087
Dianne Hackborna2e92262010-03-02 17:19:29 -080011088 pw.println("Input State:");
11089 mQueue.dump(pw, " ");
11090 pw.println(" ");
11091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011092 synchronized(mWindowMap) {
11093 pw.println("Current Window Manager state:");
11094 for (int i=mWindows.size()-1; i>=0; i--) {
11095 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011096 pw.print(" Window #"); pw.print(i); pw.print(' ');
11097 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011098 w.dump(pw, " ");
11099 }
11100 if (mInputMethodDialogs.size() > 0) {
11101 pw.println(" ");
11102 pw.println(" Input method dialogs:");
11103 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11104 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011105 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011106 }
11107 }
11108 if (mPendingRemove.size() > 0) {
11109 pw.println(" ");
11110 pw.println(" Remove pending for:");
11111 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11112 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011113 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11114 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011115 w.dump(pw, " ");
11116 }
11117 }
11118 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11119 pw.println(" ");
11120 pw.println(" Windows force removing:");
11121 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11122 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011123 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11124 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011125 w.dump(pw, " ");
11126 }
11127 }
11128 if (mDestroySurface.size() > 0) {
11129 pw.println(" ");
11130 pw.println(" Windows waiting to destroy their surface:");
11131 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11132 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011133 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11134 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011135 w.dump(pw, " ");
11136 }
11137 }
11138 if (mLosingFocus.size() > 0) {
11139 pw.println(" ");
11140 pw.println(" Windows losing focus:");
11141 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11142 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011143 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11144 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011145 w.dump(pw, " ");
11146 }
11147 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011148 if (mResizingWindows.size() > 0) {
11149 pw.println(" ");
11150 pw.println(" Windows waiting to resize:");
11151 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11152 WindowState w = mResizingWindows.get(i);
11153 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11154 pw.print(w); pw.println(":");
11155 w.dump(pw, " ");
11156 }
11157 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011158 if (mSessions.size() > 0) {
11159 pw.println(" ");
11160 pw.println(" All active sessions:");
11161 Iterator<Session> it = mSessions.iterator();
11162 while (it.hasNext()) {
11163 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011164 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011165 s.dump(pw, " ");
11166 }
11167 }
11168 if (mTokenMap.size() > 0) {
11169 pw.println(" ");
11170 pw.println(" All tokens:");
11171 Iterator<WindowToken> it = mTokenMap.values().iterator();
11172 while (it.hasNext()) {
11173 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011174 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011175 token.dump(pw, " ");
11176 }
11177 }
11178 if (mTokenList.size() > 0) {
11179 pw.println(" ");
11180 pw.println(" Window token list:");
11181 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011182 pw.print(" #"); pw.print(i); pw.print(": ");
11183 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011184 }
11185 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011186 if (mWallpaperTokens.size() > 0) {
11187 pw.println(" ");
11188 pw.println(" Wallpaper tokens:");
11189 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11190 WindowToken token = mWallpaperTokens.get(i);
11191 pw.print(" Wallpaper #"); pw.print(i);
11192 pw.print(' '); pw.print(token); pw.println(':');
11193 token.dump(pw, " ");
11194 }
11195 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011196 if (mAppTokens.size() > 0) {
11197 pw.println(" ");
11198 pw.println(" Application tokens in Z order:");
11199 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011200 pw.print(" App #"); pw.print(i); pw.print(": ");
11201 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011202 }
11203 }
11204 if (mFinishedStarting.size() > 0) {
11205 pw.println(" ");
11206 pw.println(" Finishing start of application tokens:");
11207 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11208 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011209 pw.print(" Finished Starting #"); pw.print(i);
11210 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011211 token.dump(pw, " ");
11212 }
11213 }
11214 if (mExitingTokens.size() > 0) {
11215 pw.println(" ");
11216 pw.println(" Exiting tokens:");
11217 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11218 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011219 pw.print(" Exiting #"); pw.print(i);
11220 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011221 token.dump(pw, " ");
11222 }
11223 }
11224 if (mExitingAppTokens.size() > 0) {
11225 pw.println(" ");
11226 pw.println(" Exiting application tokens:");
11227 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11228 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011229 pw.print(" Exiting App #"); pw.print(i);
11230 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011231 token.dump(pw, " ");
11232 }
11233 }
11234 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011235 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11236 pw.print(" mLastFocus="); pw.println(mLastFocus);
11237 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11238 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11239 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011240 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011241 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11242 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11243 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11244 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011245 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11246 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11247 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011248 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11249 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11250 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11251 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011252 if (mDimAnimator != null) {
11253 mDimAnimator.printTo(pw);
11254 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011255 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011256 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011257 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011258 pw.print(mInputMethodAnimLayerAdjustment);
11259 pw.print(" mWallpaperAnimLayerAdjustment=");
11260 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011261 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11262 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011263 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11264 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011265 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11266 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011267 pw.print(" mRotation="); pw.print(mRotation);
11268 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11269 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11270 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11271 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11272 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11273 pw.print(" mNextAppTransition=0x");
11274 pw.print(Integer.toHexString(mNextAppTransition));
11275 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011276 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011277 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011278 if (mNextAppTransitionPackage != null) {
11279 pw.print(" mNextAppTransitionPackage=");
11280 pw.print(mNextAppTransitionPackage);
11281 pw.print(", mNextAppTransitionEnter=0x");
11282 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11283 pw.print(", mNextAppTransitionExit=0x");
11284 pw.print(Integer.toHexString(mNextAppTransitionExit));
11285 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011286 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11287 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011288 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11289 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11290 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11291 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011292 if (mOpeningApps.size() > 0) {
11293 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11294 }
11295 if (mClosingApps.size() > 0) {
11296 pw.print(" mClosingApps="); pw.println(mClosingApps);
11297 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011298 if (mToTopApps.size() > 0) {
11299 pw.print(" mToTopApps="); pw.println(mToTopApps);
11300 }
11301 if (mToBottomApps.size() > 0) {
11302 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11303 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011304 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11305 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011306 pw.println(" KeyWaiter state:");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011307 pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin);
11308 pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder);
11309 pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished);
11310 pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow);
11311 pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching);
11312 pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011313 }
11314 }
11315
11316 public void monitor() {
11317 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011318 synchronized (mKeyguardTokenWatcher) { }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011319 synchronized (mKeyWaiter) { }
11320 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011321
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011322 public void virtualKeyFeedback(KeyEvent event) {
11323 mPolicy.keyFeedbackFromInput(event);
11324 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011325
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011326 /**
11327 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011328 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011329 */
11330 private static class DimAnimator {
11331 Surface mDimSurface;
11332 boolean mDimShown = false;
11333 float mDimCurrentAlpha;
11334 float mDimTargetAlpha;
11335 float mDimDeltaPerMs;
11336 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011337
11338 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011339
11340 DimAnimator (SurfaceSession session) {
11341 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011342 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011343 + mDimSurface + ": CREATE");
11344 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011345 mDimSurface = new Surface(session, 0,
11346 "DimSurface",
11347 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011348 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011349 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011350 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011351 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011352 }
11353 }
11354 }
11355
11356 /**
11357 * Show the dim surface.
11358 */
11359 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011360 if (!mDimShown) {
11361 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11362 dw + "x" + dh + ")");
11363 mDimShown = true;
11364 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011365 mLastDimWidth = dw;
11366 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011367 mDimSurface.setPosition(0, 0);
11368 mDimSurface.setSize(dw, dh);
11369 mDimSurface.show();
11370 } catch (RuntimeException e) {
11371 Slog.w(TAG, "Failure showing dim surface", e);
11372 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011373 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11374 mLastDimWidth = dw;
11375 mLastDimHeight = dh;
11376 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011377 }
11378 }
11379
11380 /**
11381 * Set's the dim surface's layer and update dim parameters that will be used in
11382 * {@link updateSurface} after all windows are examined.
11383 */
11384 void updateParameters(WindowState w, long currentTime) {
11385 mDimSurface.setLayer(w.mAnimLayer-1);
11386
11387 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011388 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011389 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011390 if (mDimTargetAlpha != target) {
11391 // If the desired dim level has changed, then
11392 // start an animation to it.
11393 mLastDimAnimTime = currentTime;
11394 long duration = (w.mAnimating && w.mAnimation != null)
11395 ? w.mAnimation.computeDurationHint()
11396 : DEFAULT_DIM_DURATION;
11397 if (target > mDimTargetAlpha) {
11398 // This is happening behind the activity UI,
11399 // so we can make it run a little longer to
11400 // give a stronger impression without disrupting
11401 // the user.
11402 duration *= DIM_DURATION_MULTIPLIER;
11403 }
11404 if (duration < 1) {
11405 // Don't divide by zero
11406 duration = 1;
11407 }
11408 mDimTargetAlpha = target;
11409 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11410 }
11411 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011412
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011413 /**
11414 * Updating the surface's alpha. Returns true if the animation continues, or returns
11415 * false when the animation is finished and the dim surface is hidden.
11416 */
11417 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11418 if (!dimming) {
11419 if (mDimTargetAlpha != 0) {
11420 mLastDimAnimTime = currentTime;
11421 mDimTargetAlpha = 0;
11422 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11423 }
11424 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011425
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011426 boolean animating = false;
11427 if (mLastDimAnimTime != 0) {
11428 mDimCurrentAlpha += mDimDeltaPerMs
11429 * (currentTime-mLastDimAnimTime);
11430 boolean more = true;
11431 if (displayFrozen) {
11432 // If the display is frozen, there is no reason to animate.
11433 more = false;
11434 } else if (mDimDeltaPerMs > 0) {
11435 if (mDimCurrentAlpha > mDimTargetAlpha) {
11436 more = false;
11437 }
11438 } else if (mDimDeltaPerMs < 0) {
11439 if (mDimCurrentAlpha < mDimTargetAlpha) {
11440 more = false;
11441 }
11442 } else {
11443 more = false;
11444 }
11445
11446 // Do we need to continue animating?
11447 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011448 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011449 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11450 mLastDimAnimTime = currentTime;
11451 mDimSurface.setAlpha(mDimCurrentAlpha);
11452 animating = true;
11453 } else {
11454 mDimCurrentAlpha = mDimTargetAlpha;
11455 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011456 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011457 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11458 mDimSurface.setAlpha(mDimCurrentAlpha);
11459 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011460 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011461 + ": HIDE");
11462 try {
11463 mDimSurface.hide();
11464 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011465 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011466 }
11467 mDimShown = false;
11468 }
11469 }
11470 }
11471 return animating;
11472 }
11473
11474 public void printTo(PrintWriter pw) {
11475 pw.print(" mDimShown="); pw.print(mDimShown);
11476 pw.print(" current="); pw.print(mDimCurrentAlpha);
11477 pw.print(" target="); pw.print(mDimTargetAlpha);
11478 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11479 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11480 }
11481 }
11482
11483 /**
11484 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11485 * This is used for opening/closing transition for apps in compatible mode.
11486 */
11487 private static class FadeInOutAnimation extends Animation {
11488 int mWidth;
11489 boolean mFadeIn;
11490
11491 public FadeInOutAnimation(boolean fadeIn) {
11492 setInterpolator(new AccelerateInterpolator());
11493 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11494 mFadeIn = fadeIn;
11495 }
11496
11497 @Override
11498 protected void applyTransformation(float interpolatedTime, Transformation t) {
11499 float x = interpolatedTime;
11500 if (!mFadeIn) {
11501 x = 1.0f - x; // reverse the interpolation for fade out
11502 }
11503 if (x < 0.5) {
11504 // move the window out of the screen.
11505 t.getMatrix().setTranslate(mWidth, 0);
11506 } else {
11507 t.getMatrix().setTranslate(0, 0);// show
11508 t.setAlpha((x - 0.5f) * 2);
11509 }
11510 }
11511
11512 @Override
11513 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11514 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11515 mWidth = width;
11516 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011517
11518 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011519 public int getZAdjustment() {
11520 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011521 }
11522 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011523}