blob: cdb86867350353285ec16ec2e5cf47eac8f1d764 [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;
46import com.android.internal.view.IInputContext;
47import com.android.internal.view.IInputMethodClient;
48import com.android.internal.view.IInputMethodManager;
49import com.android.server.KeyInputQueue.QueuedEvent;
50import com.android.server.am.BatteryStatsService;
51
52import android.Manifest;
53import android.app.ActivityManagerNative;
54import android.app.IActivityManager;
55import android.content.Context;
56import android.content.pm.ActivityInfo;
57import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070058import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import android.content.res.Configuration;
60import android.graphics.Matrix;
61import android.graphics.PixelFormat;
62import android.graphics.Rect;
63import android.graphics.Region;
64import android.os.BatteryStats;
65import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070066import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import android.os.Debug;
68import android.os.Handler;
69import android.os.IBinder;
Michael Chan53071d62009-05-13 17:29:48 -070070import android.os.LatencyTimer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071import android.os.LocalPowerManager;
72import android.os.Looper;
73import android.os.Message;
74import android.os.Parcel;
75import android.os.ParcelFileDescriptor;
76import android.os.Power;
77import android.os.PowerManager;
78import android.os.Process;
79import android.os.RemoteException;
80import android.os.ServiceManager;
81import android.os.SystemClock;
82import android.os.SystemProperties;
83import android.os.TokenWatcher;
84import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070085import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086import android.util.EventLog;
87import android.util.Log;
88import android.util.SparseIntArray;
89import android.view.Display;
90import android.view.Gravity;
91import android.view.IApplicationToken;
92import android.view.IOnKeyguardExitResult;
93import android.view.IRotationWatcher;
94import android.view.IWindow;
95import android.view.IWindowManager;
96import android.view.IWindowSession;
97import android.view.KeyEvent;
98import android.view.MotionEvent;
99import android.view.RawInputEvent;
100import android.view.Surface;
101import android.view.SurfaceSession;
102import android.view.View;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -0700103import android.view.ViewConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104import android.view.ViewTreeObserver;
105import android.view.WindowManager;
106import android.view.WindowManagerImpl;
107import android.view.WindowManagerPolicy;
108import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700109import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110import android.view.animation.Animation;
111import android.view.animation.AnimationUtils;
112import android.view.animation.Transformation;
113
114import java.io.BufferedWriter;
115import java.io.File;
116import java.io.FileDescriptor;
117import java.io.IOException;
118import java.io.OutputStream;
119import java.io.OutputStreamWriter;
120import java.io.PrintWriter;
121import java.io.StringWriter;
122import java.net.Socket;
123import java.util.ArrayList;
124import java.util.HashMap;
125import java.util.HashSet;
126import java.util.Iterator;
127import java.util.List;
128
129/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700130public class WindowManagerService extends IWindowManager.Stub
131 implements Watchdog.Monitor, KeyInputQueue.HapticFeedbackCallback {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 static final String TAG = "WindowManager";
133 static final boolean DEBUG = false;
134 static final boolean DEBUG_FOCUS = false;
135 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800136 static final boolean DEBUG_LAYOUT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 static final boolean DEBUG_LAYERS = false;
138 static final boolean DEBUG_INPUT = false;
139 static final boolean DEBUG_INPUT_METHOD = false;
140 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700141 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 static final boolean DEBUG_ORIENTATION = false;
143 static final boolean DEBUG_APP_TRANSITIONS = false;
144 static final boolean DEBUG_STARTING_WINDOW = false;
145 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700146 static final boolean DEBUG_WALLPAPER = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700148 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700149 static final boolean MEASURE_LATENCY = false;
150 static private LatencyTimer lt;
151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 static final boolean PROFILE_ORIENTATION = false;
153 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700154 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 /** How long to wait for subsequent key repeats, in milliseconds */
157 static final int KEY_REPEAT_DELAY = 50;
158
159 /** How much to multiply the policy's type layer, to reserve room
160 * for multiple windows of the same type and Z-ordering adjustment
161 * with TYPE_LAYER_OFFSET. */
162 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
165 * or below others in the same layer. */
166 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 /** How much to increment the layer for each window, to reserve room
169 * for effect surfaces between them.
170 */
171 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 /** The maximum length we will accept for a loaded animation duration:
174 * this is 10 seconds.
175 */
176 static final int MAX_ANIMATION_DURATION = 10*1000;
177
178 /** Amount of time (in milliseconds) to animate the dim surface from one
179 * value to another, when no window animation is driving it.
180 */
181 static final int DEFAULT_DIM_DURATION = 200;
182
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700183 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
184 * compatible windows.
185 */
186 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 /** Adjustment to time to perform a dim, to make it more dramatic.
189 */
190 static final int DIM_DURATION_MULTIPLIER = 6;
Romain Guy06882f82009-06-10 13:36:04 -0700191
Dianne Hackborncfaef692009-06-15 14:24:44 -0700192 static final int INJECT_FAILED = 0;
193 static final int INJECT_SUCCEEDED = 1;
194 static final int INJECT_NO_PERMISSION = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196 static final int UPDATE_FOCUS_NORMAL = 0;
197 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
198 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
199 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700200
Michael Chane96440f2009-05-06 10:27:36 -0700201 /** The minimum time between dispatching touch events. */
202 int mMinWaitTimeBetweenTouchEvents = 1000 / 35;
203
204 // Last touch event time
205 long mLastTouchEventTime = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700206
Michael Chane96440f2009-05-06 10:27:36 -0700207 // Last touch event type
208 int mLastTouchEventType = OTHER_EVENT;
Romain Guy06882f82009-06-10 13:36:04 -0700209
Michael Chane96440f2009-05-06 10:27:36 -0700210 // Time to wait before calling useractivity again. This saves CPU usage
211 // when we get a flood of touch events.
212 static final int MIN_TIME_BETWEEN_USERACTIVITIES = 1000;
213
214 // Last time we call user activity
215 long mLastUserActivityCallTime = 0;
216
Romain Guy06882f82009-06-10 13:36:04 -0700217 // Last time we updated battery stats
Michael Chane96440f2009-05-06 10:27:36 -0700218 long mLastBatteryStatsCallTime = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700221 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222
223 /**
224 * Condition waited on by {@link #reenableKeyguard} to know the call to
225 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500226 * This is set to true only if mKeyguardTokenWatcher.acquired() has
227 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500229 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230
Mike Lockwood983ee092009-11-22 01:42:24 -0500231 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
232 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 public void acquired() {
234 mPolicy.enableKeyguard(false);
Mike Lockwood983ee092009-11-22 01:42:24 -0500235 mKeyguardDisabled = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 }
237 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700238 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500239 synchronized (mKeyguardTokenWatcher) {
240 mKeyguardDisabled = false;
241 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 }
243 }
244 };
245
246 final Context mContext;
247
248 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
253
254 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258 /**
259 * All currently active sessions with clients.
260 */
261 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800263 /**
264 * Mapping from an IWindow IBinder to the server's Window object.
265 * This is also used as the lock for all of our state.
266 */
267 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
268
269 /**
270 * Mapping from a token IBinder to a WindowToken object.
271 */
272 final HashMap<IBinder, WindowToken> mTokenMap =
273 new HashMap<IBinder, WindowToken>();
274
275 /**
276 * The same tokens as mTokenMap, stored in a list for efficient iteration
277 * over them.
278 */
279 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 /**
282 * Window tokens that are in the process of exiting, but still
283 * on screen for animations.
284 */
285 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
286
287 /**
288 * Z-ordered (bottom-most first) list of all application tokens, for
289 * controlling the ordering of windows in different applications. This
290 * contains WindowToken objects.
291 */
292 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
293
294 /**
295 * Application tokens that are in the process of exiting, but still
296 * on screen for animations.
297 */
298 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
299
300 /**
301 * List of window tokens that have finished starting their application,
302 * and now need to have the policy remove their windows.
303 */
304 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
305
306 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700307 * This was the app token that was used to retrieve the last enter
308 * animation. It will be used for the next exit animation.
309 */
310 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800311
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700312 /**
313 * These were the layout params used to retrieve the last enter animation.
314 * They will be used for the next exit animation.
315 */
316 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800317
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700318 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 * Z-ordered (bottom-most first) list of all Window objects.
320 */
321 final ArrayList mWindows = new ArrayList();
322
323 /**
324 * Windows that are being resized. Used so we can tell the client about
325 * the resize after closing the transaction in which we resized the
326 * underlying surface.
327 */
328 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
329
330 /**
331 * Windows whose animations have ended and now must be removed.
332 */
333 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
334
335 /**
336 * Windows whose surface should be destroyed.
337 */
338 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
339
340 /**
341 * Windows that have lost input focus and are waiting for the new
342 * focus window to be displayed before they are told about this.
343 */
344 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
345
346 /**
347 * This is set when we have run out of memory, and will either be an empty
348 * list or contain windows that need to be force removed.
349 */
350 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700355 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 Surface mBlurSurface;
357 boolean mBlurShown;
Romain Guy06882f82009-06-10 13:36:04 -0700358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 final float[] mTmpFloats = new float[9];
362
363 boolean mSafeMode;
364 boolean mDisplayEnabled = false;
365 boolean mSystemBooted = false;
366 int mRotation = 0;
367 int mRequestedRotation = 0;
368 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700369 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 ArrayList<IRotationWatcher> mRotationWatchers
371 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 boolean mLayoutNeeded = true;
374 boolean mAnimationPending = false;
375 boolean mDisplayFrozen = false;
376 boolean mWindowsFreezingScreen = false;
377 long mFreezeGcPending = 0;
378 int mAppsFreezingScreen = 0;
379
380 // This is held as long as we have the screen frozen, to give us time to
381 // perform a rotation animation when turning off shows the lock screen which
382 // changes the orientation.
383 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 // State management of app transitions. When we are preparing for a
386 // transition, mNextAppTransition will be the kind of transition to
387 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
388 // mOpeningApps and mClosingApps are the lists of tokens that will be
389 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700390 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700391 String mNextAppTransitionPackage;
392 int mNextAppTransitionEnter;
393 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700395 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 boolean mAppTransitionTimeout = false;
397 boolean mStartingIconInTransition = false;
398 boolean mSkipAppTransitionAnimation = false;
399 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
400 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700401 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
402 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 //flag to detect fat touch events
405 boolean mFatTouch = false;
406 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700407
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800408 H mH = new H();
409
410 WindowState mCurrentFocus = null;
411 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 // This just indicates the window the input method is on top of, not
414 // necessarily the window its input is going to.
415 WindowState mInputMethodTarget = null;
416 WindowState mUpcomingInputMethodTarget = null;
417 boolean mInputMethodTargetWaitingAnim;
418 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 WindowState mInputMethodWindow = null;
421 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
422
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700423 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800424
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700425 // If non-null, this is the currently visible window that is associated
426 // with the wallpaper.
427 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700428 // If non-null, we are in the middle of animating from one wallpaper target
429 // to another, and this is the lower one in Z-order.
430 WindowState mLowerWallpaperTarget = null;
431 // If non-null, we are in the middle of animating from one wallpaper target
432 // to another, and this is the higher one in Z-order.
433 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700434 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700435 float mLastWallpaperX = -1;
436 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800437 float mLastWallpaperXStep = -1;
438 float mLastWallpaperYStep = -1;
Dianne Hackborn6adba242009-11-10 11:10:09 -0800439 boolean mSendingPointersToWallpaper = false;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700440 // This is set when we are waiting for a wallpaper to tell us it is done
441 // changing its scroll position.
442 WindowState mWaitingOnWallpaper;
443 // The last time we had a timeout when waiting for a wallpaper.
444 long mLastWallpaperTimeoutTime;
445 // We give a wallpaper up to 150ms to finish scrolling.
446 static final long WALLPAPER_TIMEOUT = 150;
447 // Time we wait after a timeout before trying to wait again.
448 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800450 AppWindowToken mFocusedApp = null;
451
452 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 float mWindowAnimationScale = 1.0f;
455 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800457 final KeyWaiter mKeyWaiter = new KeyWaiter();
458 final KeyQ mQueue;
459 final InputDispatcherThread mInputThread;
460
461 // Who is holding the screen on.
462 Session mHoldingScreenOn;
Romain Guy06882f82009-06-10 13:36:04 -0700463
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700464 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466 /**
467 * Whether the UI is currently running in touch mode (not showing
468 * navigational focus because the user is directly pressing the screen).
469 */
470 boolean mInTouchMode = false;
471
472 private ViewServer mViewServer;
473
474 final Rect mTempRect = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -0700475
Dianne Hackbornc485a602009-03-24 22:39:49 -0700476 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700477 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700478
479 // The frame use to limit the size of the app running in compatibility mode.
480 Rect mCompatibleScreenFrame = new Rect();
481 // The surface used to fill the outer rim of the app running in compatibility mode.
482 Surface mBackgroundFillerSurface = null;
483 boolean mBackgroundFillerShown = false;
484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800485 public static WindowManagerService main(Context context,
486 PowerManagerService pm, boolean haveInputMethods) {
487 WMThread thr = new WMThread(context, pm, haveInputMethods);
488 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 synchronized (thr) {
491 while (thr.mService == null) {
492 try {
493 thr.wait();
494 } catch (InterruptedException e) {
495 }
496 }
497 }
Romain Guy06882f82009-06-10 13:36:04 -0700498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800499 return thr.mService;
500 }
Romain Guy06882f82009-06-10 13:36:04 -0700501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 static class WMThread extends Thread {
503 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 private final Context mContext;
506 private final PowerManagerService mPM;
507 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 public WMThread(Context context, PowerManagerService pm,
510 boolean haveInputMethods) {
511 super("WindowManager");
512 mContext = context;
513 mPM = pm;
514 mHaveInputMethods = haveInputMethods;
515 }
Romain Guy06882f82009-06-10 13:36:04 -0700516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 public void run() {
518 Looper.prepare();
519 WindowManagerService s = new WindowManagerService(mContext, mPM,
520 mHaveInputMethods);
521 android.os.Process.setThreadPriority(
522 android.os.Process.THREAD_PRIORITY_DISPLAY);
Romain Guy06882f82009-06-10 13:36:04 -0700523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524 synchronized (this) {
525 mService = s;
526 notifyAll();
527 }
Romain Guy06882f82009-06-10 13:36:04 -0700528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 Looper.loop();
530 }
531 }
532
533 static class PolicyThread extends Thread {
534 private final WindowManagerPolicy mPolicy;
535 private final WindowManagerService mService;
536 private final Context mContext;
537 private final PowerManagerService mPM;
538 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 public PolicyThread(WindowManagerPolicy policy,
541 WindowManagerService service, Context context,
542 PowerManagerService pm) {
543 super("WindowManagerPolicy");
544 mPolicy = policy;
545 mService = service;
546 mContext = context;
547 mPM = pm;
548 }
Romain Guy06882f82009-06-10 13:36:04 -0700549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 public void run() {
551 Looper.prepare();
552 //Looper.myLooper().setMessageLogging(new LogPrinter(
553 // Log.VERBOSE, "WindowManagerPolicy"));
554 android.os.Process.setThreadPriority(
555 android.os.Process.THREAD_PRIORITY_FOREGROUND);
556 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 synchronized (this) {
559 mRunning = true;
560 notifyAll();
561 }
Romain Guy06882f82009-06-10 13:36:04 -0700562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 Looper.loop();
564 }
565 }
566
567 private WindowManagerService(Context context, PowerManagerService pm,
568 boolean haveInputMethods) {
Michael Chan53071d62009-05-13 17:29:48 -0700569 if (MEASURE_LATENCY) {
570 lt = new LatencyTimer(100, 1000);
571 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800573 mContext = context;
574 mHaveInputMethods = haveInputMethods;
575 mLimitedAlphaCompositing = context.getResources().getBoolean(
576 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 mPowerManager = pm;
579 mPowerManager.setPolicy(mPolicy);
580 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
581 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
582 "SCREEN_FROZEN");
583 mScreenFrozenLock.setReferenceCounted(false);
584
585 mActivityManager = ActivityManagerNative.getDefault();
586 mBatteryStats = BatteryStatsService.getService();
587
588 // Get persisted window scale setting
589 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
590 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
591 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
592 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700593
Michael Chan9f028e62009-08-04 17:37:46 -0700594 int max_events_per_sec = 35;
595 try {
596 max_events_per_sec = Integer.parseInt(SystemProperties
597 .get("windowsmgr.max_events_per_sec"));
598 if (max_events_per_sec < 1) {
599 max_events_per_sec = 35;
600 }
601 } catch (NumberFormatException e) {
602 }
603 mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec;
604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 mQueue = new KeyQ();
606
607 mInputThread = new InputDispatcherThread();
Romain Guy06882f82009-06-10 13:36:04 -0700608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
610 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 synchronized (thr) {
613 while (!thr.mRunning) {
614 try {
615 thr.wait();
616 } catch (InterruptedException e) {
617 }
618 }
619 }
Romain Guy06882f82009-06-10 13:36:04 -0700620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 mInputThread.start();
Romain Guy06882f82009-06-10 13:36:04 -0700622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623 // Add ourself to the Watchdog monitors.
624 Watchdog.getInstance().addMonitor(this);
625 }
626
627 @Override
628 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
629 throws RemoteException {
630 try {
631 return super.onTransact(code, data, reply, flags);
632 } catch (RuntimeException e) {
633 // The window manager only throws security exceptions, so let's
634 // log all others.
635 if (!(e instanceof SecurityException)) {
636 Log.e(TAG, "Window Manager Crash", e);
637 }
638 throw e;
639 }
640 }
641
642 private void placeWindowAfter(Object pos, WindowState window) {
643 final int i = mWindows.indexOf(pos);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700644 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Log.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 TAG, "Adding window " + window + " at "
646 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
647 mWindows.add(i+1, window);
648 }
649
650 private void placeWindowBefore(Object pos, WindowState window) {
651 final int i = mWindows.indexOf(pos);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700652 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Log.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653 TAG, "Adding window " + window + " at "
654 + i + " of " + mWindows.size() + " (before " + pos + ")");
655 mWindows.add(i, window);
656 }
657
658 //This method finds out the index of a window that has the same app token as
659 //win. used for z ordering the windows in mWindows
660 private int findIdxBasedOnAppTokens(WindowState win) {
661 //use a local variable to cache mWindows
662 ArrayList localmWindows = mWindows;
663 int jmax = localmWindows.size();
664 if(jmax == 0) {
665 return -1;
666 }
667 for(int j = (jmax-1); j >= 0; j--) {
668 WindowState wentry = (WindowState)localmWindows.get(j);
669 if(wentry.mAppToken == win.mAppToken) {
670 return j;
671 }
672 }
673 return -1;
674 }
Romain Guy06882f82009-06-10 13:36:04 -0700675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
677 final IWindow client = win.mClient;
678 final WindowToken token = win.mToken;
679 final ArrayList localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 final int N = localmWindows.size();
682 final WindowState attached = win.mAttachedWindow;
683 int i;
684 if (attached == null) {
685 int tokenWindowsPos = token.windows.size();
686 if (token.appWindowToken != null) {
687 int index = tokenWindowsPos-1;
688 if (index >= 0) {
689 // If this application has existing windows, we
690 // simply place the new window on top of them... but
691 // keep the starting window on top.
692 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
693 // Base windows go behind everything else.
694 placeWindowBefore(token.windows.get(0), win);
695 tokenWindowsPos = 0;
696 } else {
697 AppWindowToken atoken = win.mAppToken;
698 if (atoken != null &&
699 token.windows.get(index) == atoken.startingWindow) {
700 placeWindowBefore(token.windows.get(index), win);
701 tokenWindowsPos--;
702 } else {
703 int newIdx = findIdxBasedOnAppTokens(win);
704 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700705 //there is a window above this one associated with the same
706 //apptoken note that the window could be a floating window
707 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800708 //windows associated with this token.
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700709 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Log.v(
710 TAG, "Adding window " + win + " at "
711 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800712 localmWindows.add(newIdx+1, win);
Romain Guy06882f82009-06-10 13:36:04 -0700713 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800714 }
715 }
716 } else {
717 if (localLOGV) Log.v(
718 TAG, "Figuring out where to add app window "
719 + client.asBinder() + " (token=" + token + ")");
720 // Figure out where the window should go, based on the
721 // order of applications.
722 final int NA = mAppTokens.size();
723 Object pos = null;
724 for (i=NA-1; i>=0; i--) {
725 AppWindowToken t = mAppTokens.get(i);
726 if (t == token) {
727 i--;
728 break;
729 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800730
Dianne Hackborna8f60182009-09-01 19:01:50 -0700731 // We haven't reached the token yet; if this token
732 // is not going to the bottom and has windows, we can
733 // use it as an anchor for when we do reach the token.
734 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 pos = t.windows.get(0);
736 }
737 }
738 // We now know the index into the apps. If we found
739 // an app window above, that gives us the position; else
740 // we need to look some more.
741 if (pos != null) {
742 // Move behind any windows attached to this one.
Romain Guy06882f82009-06-10 13:36:04 -0700743 WindowToken atoken =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 mTokenMap.get(((WindowState)pos).mClient.asBinder());
745 if (atoken != null) {
746 final int NC = atoken.windows.size();
747 if (NC > 0) {
748 WindowState bottom = atoken.windows.get(0);
749 if (bottom.mSubLayer < 0) {
750 pos = bottom;
751 }
752 }
753 }
754 placeWindowBefore(pos, win);
755 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700756 // Continue looking down until we find the first
757 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800758 while (i >= 0) {
759 AppWindowToken t = mAppTokens.get(i);
760 final int NW = t.windows.size();
761 if (NW > 0) {
762 pos = t.windows.get(NW-1);
763 break;
764 }
765 i--;
766 }
767 if (pos != null) {
768 // Move in front of any windows attached to this
769 // one.
770 WindowToken atoken =
771 mTokenMap.get(((WindowState)pos).mClient.asBinder());
772 if (atoken != null) {
773 final int NC = atoken.windows.size();
774 if (NC > 0) {
775 WindowState top = atoken.windows.get(NC-1);
776 if (top.mSubLayer >= 0) {
777 pos = top;
778 }
779 }
780 }
781 placeWindowAfter(pos, win);
782 } else {
783 // Just search for the start of this layer.
784 final int myLayer = win.mBaseLayer;
785 for (i=0; i<N; i++) {
786 WindowState w = (WindowState)localmWindows.get(i);
787 if (w.mBaseLayer > myLayer) {
788 break;
789 }
790 }
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700791 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Log.v(
792 TAG, "Adding window " + win + " at "
793 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794 localmWindows.add(i, win);
795 }
796 }
797 }
798 } else {
799 // Figure out where window should go, based on layer.
800 final int myLayer = win.mBaseLayer;
801 for (i=N-1; i>=0; i--) {
802 if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) {
803 i++;
804 break;
805 }
806 }
807 if (i < 0) i = 0;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700808 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Log.v(
809 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 if (addToToken) {
814 token.windows.add(tokenWindowsPos, win);
815 }
816
817 } else {
818 // Figure out this window's ordering relative to the window
819 // it is attached to.
820 final int NA = token.windows.size();
821 final int sublayer = win.mSubLayer;
822 int largestSublayer = Integer.MIN_VALUE;
823 WindowState windowWithLargestSublayer = null;
824 for (i=0; i<NA; i++) {
825 WindowState w = token.windows.get(i);
826 final int wSublayer = w.mSubLayer;
827 if (wSublayer >= largestSublayer) {
828 largestSublayer = wSublayer;
829 windowWithLargestSublayer = w;
830 }
831 if (sublayer < 0) {
832 // For negative sublayers, we go below all windows
833 // in the same sublayer.
834 if (wSublayer >= sublayer) {
835 if (addToToken) {
836 token.windows.add(i, win);
837 }
838 placeWindowBefore(
839 wSublayer >= 0 ? attached : w, win);
840 break;
841 }
842 } else {
843 // For positive sublayers, we go above all windows
844 // in the same sublayer.
845 if (wSublayer > sublayer) {
846 if (addToToken) {
847 token.windows.add(i, win);
848 }
849 placeWindowBefore(w, win);
850 break;
851 }
852 }
853 }
854 if (i >= NA) {
855 if (addToToken) {
856 token.windows.add(win);
857 }
858 if (sublayer < 0) {
859 placeWindowBefore(attached, win);
860 } else {
861 placeWindowAfter(largestSublayer >= 0
862 ? windowWithLargestSublayer
863 : attached,
864 win);
865 }
866 }
867 }
Romain Guy06882f82009-06-10 13:36:04 -0700868
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869 if (win.mAppToken != null && addToToken) {
870 win.mAppToken.allAppWindows.add(win);
871 }
872 }
Romain Guy06882f82009-06-10 13:36:04 -0700873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800874 static boolean canBeImeTarget(WindowState w) {
875 final int fl = w.mAttrs.flags
876 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
877 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
878 return w.isVisibleOrAdding();
879 }
880 return false;
881 }
Romain Guy06882f82009-06-10 13:36:04 -0700882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
884 final ArrayList localmWindows = mWindows;
885 final int N = localmWindows.size();
886 WindowState w = null;
887 int i = N;
888 while (i > 0) {
889 i--;
890 w = (WindowState)localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800892 //Log.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
893 // + Integer.toHexString(w.mAttrs.flags));
894 if (canBeImeTarget(w)) {
895 //Log.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897 // Yet more tricksyness! If this window is a "starting"
898 // window, we do actually want to be on top of it, but
899 // it is not -really- where input will go. So if the caller
900 // is not actually looking to move the IME, look down below
901 // for a real window to target...
902 if (!willMove
903 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
904 && i > 0) {
905 WindowState wb = (WindowState)localmWindows.get(i-1);
906 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
907 i--;
908 w = wb;
909 }
910 }
911 break;
912 }
913 }
Romain Guy06882f82009-06-10 13:36:04 -0700914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800917 if (DEBUG_INPUT_METHOD) Log.v(TAG, "Desired input method target="
918 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800920 if (willMove && w != null) {
921 final WindowState curTarget = mInputMethodTarget;
922 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 // Now some fun for dealing with window animations that
925 // modify the Z order. We need to look at all windows below
926 // the current target that are in this app, finding the highest
927 // visible one in layering.
928 AppWindowToken token = curTarget.mAppToken;
929 WindowState highestTarget = null;
930 int highestPos = 0;
931 if (token.animating || token.animation != null) {
932 int pos = 0;
933 pos = localmWindows.indexOf(curTarget);
934 while (pos >= 0) {
935 WindowState win = (WindowState)localmWindows.get(pos);
936 if (win.mAppToken != token) {
937 break;
938 }
939 if (!win.mRemoved) {
940 if (highestTarget == null || win.mAnimLayer >
941 highestTarget.mAnimLayer) {
942 highestTarget = win;
943 highestPos = pos;
944 }
945 }
946 pos--;
947 }
948 }
Romain Guy06882f82009-06-10 13:36:04 -0700949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 if (highestTarget != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700951 if (DEBUG_INPUT_METHOD) Log.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800952 + mNextAppTransition + " " + highestTarget
953 + " animating=" + highestTarget.isAnimating()
954 + " layer=" + highestTarget.mAnimLayer
955 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700956
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700957 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800958 // If we are currently setting up for an animation,
959 // hold everything until we can find out what will happen.
960 mInputMethodTargetWaitingAnim = true;
961 mInputMethodTarget = highestTarget;
962 return highestPos + 1;
963 } else if (highestTarget.isAnimating() &&
964 highestTarget.mAnimLayer > w.mAnimLayer) {
965 // If the window we are currently targeting is involved
966 // with an animation, and it is on top of the next target
967 // we will be over, then hold off on moving until
968 // that is done.
969 mInputMethodTarget = highestTarget;
970 return highestPos + 1;
971 }
972 }
973 }
974 }
Romain Guy06882f82009-06-10 13:36:04 -0700975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800976 //Log.i(TAG, "Placing input method @" + (i+1));
977 if (w != null) {
978 if (willMove) {
979 RuntimeException e = new RuntimeException();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700980 if (!HIDE_STACK_CRAWLS) e.fillInStackTrace();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 if (DEBUG_INPUT_METHOD) Log.w(TAG, "Moving IM target from "
982 + mInputMethodTarget + " to " + w, e);
983 mInputMethodTarget = w;
984 if (w.mAppToken != null) {
985 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
986 } else {
987 setInputMethodAnimLayerAdjustment(0);
988 }
989 }
990 return i+1;
991 }
992 if (willMove) {
993 RuntimeException e = new RuntimeException();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700994 if (!HIDE_STACK_CRAWLS) e.fillInStackTrace();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995 if (DEBUG_INPUT_METHOD) Log.w(TAG, "Moving IM target from "
996 + mInputMethodTarget + " to null", e);
997 mInputMethodTarget = null;
998 setInputMethodAnimLayerAdjustment(0);
999 }
1000 return -1;
1001 }
Romain Guy06882f82009-06-10 13:36:04 -07001002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001003 void addInputMethodWindowToListLocked(WindowState win) {
1004 int pos = findDesiredInputMethodWindowIndexLocked(true);
1005 if (pos >= 0) {
1006 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001007 if (DEBUG_WINDOW_MOVEMENT) Log.v(
1008 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001009 mWindows.add(pos, win);
1010 moveInputMethodDialogsLocked(pos+1);
1011 return;
1012 }
1013 win.mTargetAppToken = null;
1014 addWindowToListInOrderLocked(win, true);
1015 moveInputMethodDialogsLocked(pos);
1016 }
Romain Guy06882f82009-06-10 13:36:04 -07001017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001018 void setInputMethodAnimLayerAdjustment(int adj) {
1019 if (DEBUG_LAYERS) Log.v(TAG, "Setting im layer adj to " + adj);
1020 mInputMethodAnimLayerAdjustment = adj;
1021 WindowState imw = mInputMethodWindow;
1022 if (imw != null) {
1023 imw.mAnimLayer = imw.mLayer + adj;
1024 if (DEBUG_LAYERS) Log.v(TAG, "IM win " + imw
1025 + " anim layer: " + imw.mAnimLayer);
1026 int wi = imw.mChildWindows.size();
1027 while (wi > 0) {
1028 wi--;
1029 WindowState cw = (WindowState)imw.mChildWindows.get(wi);
1030 cw.mAnimLayer = cw.mLayer + adj;
1031 if (DEBUG_LAYERS) Log.v(TAG, "IM win " + cw
1032 + " anim layer: " + cw.mAnimLayer);
1033 }
1034 }
1035 int di = mInputMethodDialogs.size();
1036 while (di > 0) {
1037 di --;
1038 imw = mInputMethodDialogs.get(di);
1039 imw.mAnimLayer = imw.mLayer + adj;
1040 if (DEBUG_LAYERS) Log.v(TAG, "IM win " + imw
1041 + " anim layer: " + imw.mAnimLayer);
1042 }
1043 }
Romain Guy06882f82009-06-10 13:36:04 -07001044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1046 int wpos = mWindows.indexOf(win);
1047 if (wpos >= 0) {
1048 if (wpos < interestingPos) interestingPos--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001049 if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001050 mWindows.remove(wpos);
1051 int NC = win.mChildWindows.size();
1052 while (NC > 0) {
1053 NC--;
1054 WindowState cw = (WindowState)win.mChildWindows.get(NC);
1055 int cpos = mWindows.indexOf(cw);
1056 if (cpos >= 0) {
1057 if (cpos < interestingPos) interestingPos--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001058 if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Temp removing child at "
1059 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001060 mWindows.remove(cpos);
1061 }
1062 }
1063 }
1064 return interestingPos;
1065 }
Romain Guy06882f82009-06-10 13:36:04 -07001066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 private void reAddWindowToListInOrderLocked(WindowState win) {
1068 addWindowToListInOrderLocked(win, false);
1069 // This is a hack to get all of the child windows added as well
1070 // at the right position. Child windows should be rare and
1071 // this case should be rare, so it shouldn't be that big a deal.
1072 int wpos = mWindows.indexOf(win);
1073 if (wpos >= 0) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001074 if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "ReAdd removing from " + wpos
1075 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001076 mWindows.remove(wpos);
1077 reAddWindowLocked(wpos, win);
1078 }
1079 }
Romain Guy06882f82009-06-10 13:36:04 -07001080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 void logWindowList(String prefix) {
1082 int N = mWindows.size();
1083 while (N > 0) {
1084 N--;
1085 Log.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
1086 }
1087 }
Romain Guy06882f82009-06-10 13:36:04 -07001088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 void moveInputMethodDialogsLocked(int pos) {
1090 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001092 final int N = dialogs.size();
1093 if (DEBUG_INPUT_METHOD) Log.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
1094 for (int i=0; i<N; i++) {
1095 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1096 }
1097 if (DEBUG_INPUT_METHOD) {
1098 Log.v(TAG, "Window list w/pos=" + pos);
1099 logWindowList(" ");
1100 }
Romain Guy06882f82009-06-10 13:36:04 -07001101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001102 if (pos >= 0) {
1103 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1104 if (pos < mWindows.size()) {
1105 WindowState wp = (WindowState)mWindows.get(pos);
1106 if (wp == mInputMethodWindow) {
1107 pos++;
1108 }
1109 }
1110 if (DEBUG_INPUT_METHOD) Log.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
1111 for (int i=0; i<N; i++) {
1112 WindowState win = dialogs.get(i);
1113 win.mTargetAppToken = targetAppToken;
1114 pos = reAddWindowLocked(pos, win);
1115 }
1116 if (DEBUG_INPUT_METHOD) {
1117 Log.v(TAG, "Final window list:");
1118 logWindowList(" ");
1119 }
1120 return;
1121 }
1122 for (int i=0; i<N; i++) {
1123 WindowState win = dialogs.get(i);
1124 win.mTargetAppToken = null;
1125 reAddWindowToListInOrderLocked(win);
1126 if (DEBUG_INPUT_METHOD) {
1127 Log.v(TAG, "No IM target, final list:");
1128 logWindowList(" ");
1129 }
1130 }
1131 }
Romain Guy06882f82009-06-10 13:36:04 -07001132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001133 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1134 final WindowState imWin = mInputMethodWindow;
1135 final int DN = mInputMethodDialogs.size();
1136 if (imWin == null && DN == 0) {
1137 return false;
1138 }
Romain Guy06882f82009-06-10 13:36:04 -07001139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001140 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1141 if (imPos >= 0) {
1142 // In this case, the input method windows are to be placed
1143 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 // First check to see if the input method windows are already
1146 // located here, and contiguous.
1147 final int N = mWindows.size();
1148 WindowState firstImWin = imPos < N
1149 ? (WindowState)mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 // Figure out the actual input method window that should be
1152 // at the bottom of their stack.
1153 WindowState baseImWin = imWin != null
1154 ? imWin : mInputMethodDialogs.get(0);
1155 if (baseImWin.mChildWindows.size() > 0) {
1156 WindowState cw = (WindowState)baseImWin.mChildWindows.get(0);
1157 if (cw.mSubLayer < 0) baseImWin = cw;
1158 }
Romain Guy06882f82009-06-10 13:36:04 -07001159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 if (firstImWin == baseImWin) {
1161 // The windows haven't moved... but are they still contiguous?
1162 // First find the top IM window.
1163 int pos = imPos+1;
1164 while (pos < N) {
1165 if (!((WindowState)mWindows.get(pos)).mIsImWindow) {
1166 break;
1167 }
1168 pos++;
1169 }
1170 pos++;
1171 // Now there should be no more input method windows above.
1172 while (pos < N) {
1173 if (((WindowState)mWindows.get(pos)).mIsImWindow) {
1174 break;
1175 }
1176 pos++;
1177 }
1178 if (pos >= N) {
1179 // All is good!
1180 return false;
1181 }
1182 }
Romain Guy06882f82009-06-10 13:36:04 -07001183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 if (imWin != null) {
1185 if (DEBUG_INPUT_METHOD) {
1186 Log.v(TAG, "Moving IM from " + imPos);
1187 logWindowList(" ");
1188 }
1189 imPos = tmpRemoveWindowLocked(imPos, imWin);
1190 if (DEBUG_INPUT_METHOD) {
1191 Log.v(TAG, "List after moving with new pos " + imPos + ":");
1192 logWindowList(" ");
1193 }
1194 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1195 reAddWindowLocked(imPos, imWin);
1196 if (DEBUG_INPUT_METHOD) {
1197 Log.v(TAG, "List after moving IM to " + imPos + ":");
1198 logWindowList(" ");
1199 }
1200 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1201 } else {
1202 moveInputMethodDialogsLocked(imPos);
1203 }
Romain Guy06882f82009-06-10 13:36:04 -07001204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001205 } else {
1206 // In this case, the input method windows go in a fixed layer,
1207 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001209 if (imWin != null) {
1210 if (DEBUG_INPUT_METHOD) Log.v(TAG, "Moving IM from " + imPos);
1211 tmpRemoveWindowLocked(0, imWin);
1212 imWin.mTargetAppToken = null;
1213 reAddWindowToListInOrderLocked(imWin);
1214 if (DEBUG_INPUT_METHOD) {
1215 Log.v(TAG, "List with no IM target:");
1216 logWindowList(" ");
1217 }
1218 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1219 } else {
1220 moveInputMethodDialogsLocked(-1);;
1221 }
Romain Guy06882f82009-06-10 13:36:04 -07001222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001223 }
Romain Guy06882f82009-06-10 13:36:04 -07001224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001225 if (needAssignLayers) {
1226 assignLayersLocked();
1227 }
Romain Guy06882f82009-06-10 13:36:04 -07001228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 return true;
1230 }
Romain Guy06882f82009-06-10 13:36:04 -07001231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 void adjustInputMethodDialogsLocked() {
1233 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1234 }
Romain Guy06882f82009-06-10 13:36:04 -07001235
Dianne Hackborn25994b42009-09-04 14:21:19 -07001236 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
1237 if (DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper vis: target obscured="
1238 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1239 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1240 ? wallpaperTarget.mAppToken.animation : null)
1241 + " upper=" + mUpperWallpaperTarget
1242 + " lower=" + mLowerWallpaperTarget);
1243 return (wallpaperTarget != null
1244 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1245 && wallpaperTarget.mAppToken.animation != null)))
1246 || mUpperWallpaperTarget != null
1247 || mLowerWallpaperTarget != null;
1248 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001249
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001250 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1251 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001252
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001253 int adjustWallpaperWindowsLocked() {
1254 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001255
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001256 final int dw = mDisplay.getWidth();
1257 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001258
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001259 // First find top-most window that has asked to be on top of the
1260 // wallpaper; all wallpapers go behind it.
1261 final ArrayList localmWindows = mWindows;
1262 int N = localmWindows.size();
1263 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001264 WindowState foundW = null;
1265 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001266 WindowState topCurW = null;
1267 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001268 int i = N;
1269 while (i > 0) {
1270 i--;
1271 w = (WindowState)localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001272 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1273 if (topCurW == null) {
1274 topCurW = w;
1275 topCurI = i;
1276 }
1277 continue;
1278 }
1279 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001280 if (w.mAppToken != null) {
1281 // If this window's app token is hidden and not animating,
1282 // it is of no interest to us.
1283 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
1284 if (DEBUG_WALLPAPER) Log.v(TAG,
1285 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001286 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001287 continue;
1288 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001289 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001290 if (DEBUG_WALLPAPER) Log.v(TAG, "Win " + w + ": readyfordisplay="
1291 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1292 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001293 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001294 && (mWallpaperTarget == w
1295 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001296 if (DEBUG_WALLPAPER) Log.v(TAG,
1297 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001298 foundW = w;
1299 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001300 if (w == mWallpaperTarget && ((w.mAppToken != null
1301 && w.mAppToken.animation != null)
1302 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001303 // The current wallpaper target is animating, so we'll
1304 // look behind it for another possible target and figure
1305 // out what is going on below.
1306 if (DEBUG_WALLPAPER) Log.v(TAG, "Win " + w
1307 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001308 continue;
1309 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001310 break;
1311 }
1312 }
1313
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001314 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001315 // If we are currently waiting for an app transition, and either
1316 // the current target or the next target are involved with it,
1317 // then hold off on doing anything with the wallpaper.
1318 // Note that we are checking here for just whether the target
1319 // is part of an app token... which is potentially overly aggressive
1320 // (the app token may not be involved in the transition), but good
1321 // enough (we'll just wait until whatever transition is pending
1322 // executes).
1323 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001324 if (DEBUG_WALLPAPER) Log.v(TAG,
1325 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001326 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001327 }
1328 if (foundW != null && foundW.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001329 if (DEBUG_WALLPAPER) Log.v(TAG,
1330 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001331 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001332 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001333 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001334
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001335 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001336 if (DEBUG_WALLPAPER) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001337 Log.v(TAG, "New wallpaper target: " + foundW
1338 + " oldTarget: " + mWallpaperTarget);
1339 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001340
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001341 mLowerWallpaperTarget = null;
1342 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001343
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001344 WindowState oldW = mWallpaperTarget;
1345 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001346
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001347 // Now what is happening... if the current and new targets are
1348 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001349 if (foundW != null && oldW != null) {
1350 boolean oldAnim = oldW.mAnimation != null
1351 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1352 boolean foundAnim = foundW.mAnimation != null
1353 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001354 if (DEBUG_WALLPAPER) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001355 Log.v(TAG, "New animation: " + foundAnim
1356 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001357 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001358 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001359 int oldI = localmWindows.indexOf(oldW);
1360 if (DEBUG_WALLPAPER) {
1361 Log.v(TAG, "New i: " + foundI + " old i: " + oldI);
1362 }
1363 if (oldI >= 0) {
1364 if (DEBUG_WALLPAPER) {
1365 Log.v(TAG, "Animating wallpapers: old#" + oldI
1366 + "=" + oldW + "; new#" + foundI
1367 + "=" + foundW);
1368 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001369
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001370 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001371 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001372 if (DEBUG_WALLPAPER) {
1373 Log.v(TAG, "Old wallpaper still the target.");
1374 }
1375 mWallpaperTarget = oldW;
1376 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001377
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001378 // Now set the upper and lower wallpaper targets
1379 // correctly, and make sure that we are positioning
1380 // the wallpaper below the lower.
1381 if (foundI > oldI) {
1382 // The new target is on top of the old one.
1383 if (DEBUG_WALLPAPER) {
1384 Log.v(TAG, "Found target above old target.");
1385 }
1386 mUpperWallpaperTarget = foundW;
1387 mLowerWallpaperTarget = oldW;
1388 foundW = oldW;
1389 foundI = oldI;
1390 } else {
1391 // The new target is below the old one.
1392 if (DEBUG_WALLPAPER) {
1393 Log.v(TAG, "Found target below old target.");
1394 }
1395 mUpperWallpaperTarget = oldW;
1396 mLowerWallpaperTarget = foundW;
1397 }
1398 }
1399 }
1400 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001401
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001402 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001403 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001404 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1405 || (mLowerWallpaperTarget.mAppToken != null
1406 && mLowerWallpaperTarget.mAppToken.animation != null);
1407 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1408 || (mUpperWallpaperTarget.mAppToken != null
1409 && mUpperWallpaperTarget.mAppToken.animation != null);
1410 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001411 if (DEBUG_WALLPAPER) {
1412 Log.v(TAG, "No longer animating wallpaper targets!");
1413 }
1414 mLowerWallpaperTarget = null;
1415 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001416 }
1417 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001418
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001419 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001420 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001421 // The window is visible to the compositor... but is it visible
1422 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001423 visible = isWallpaperVisible(foundW);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001424 if (DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001425
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001426 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001427 // its layer adjustment. Only do this if we are not transfering
1428 // between two wallpaper targets.
1429 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001430 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001431 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001432
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001433 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1434 * TYPE_LAYER_MULTIPLIER
1435 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001436
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001437 // Now w is the window we are supposed to be behind... but we
1438 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001439 // AND any starting window associated with it, AND below the
1440 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001441 while (foundI > 0) {
1442 WindowState wb = (WindowState)localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001443 if (wb.mBaseLayer < maxLayer &&
1444 wb.mAttachedWindow != foundW &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001445 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001446 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001447 // This window is not related to the previous one in any
1448 // interesting way, so stop here.
1449 break;
1450 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001451 foundW = wb;
1452 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001453 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001454 } else {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001455 if (DEBUG_WALLPAPER) Log.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001456 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001457
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001458 if (foundW == null && topCurW != null) {
1459 // There is no wallpaper target, so it goes at the bottom.
1460 // We will assume it is the same place as last time, if known.
1461 foundW = topCurW;
1462 foundI = topCurI+1;
1463 } else {
1464 // Okay i is the position immediately above the wallpaper. Look at
1465 // what is below it for later.
1466 foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null;
1467 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001468
Dianne Hackborn284ac932009-08-28 10:34:25 -07001469 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001470 if (mWallpaperTarget.mWallpaperX >= 0) {
1471 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001472 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001473 }
1474 if (mWallpaperTarget.mWallpaperY >= 0) {
1475 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001476 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001477 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001478 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001479
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001480 // Start stepping backwards from here, ensuring that our wallpaper windows
1481 // are correctly placed.
1482 int curTokenIndex = mWallpaperTokens.size();
1483 while (curTokenIndex > 0) {
1484 curTokenIndex--;
1485 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001486 if (token.hidden == visible) {
1487 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1488 token.hidden = !visible;
1489 // Need to do a layout to ensure the wallpaper now has the
1490 // correct size.
1491 mLayoutNeeded = true;
1492 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001493
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001494 int curWallpaperIndex = token.windows.size();
1495 while (curWallpaperIndex > 0) {
1496 curWallpaperIndex--;
1497 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001498
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001499 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001500 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001501 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001502
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001503 // First, make sure the client has the current visibility
1504 // state.
1505 if (wallpaper.mWallpaperVisible != visible) {
1506 wallpaper.mWallpaperVisible = visible;
1507 try {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001508 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Log.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001509 "Setting visibility of wallpaper " + wallpaper
1510 + ": " + visible);
1511 wallpaper.mClient.dispatchAppVisibility(visible);
1512 } catch (RemoteException e) {
1513 }
1514 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001515
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001516 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001517 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper win "
1518 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001519
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001520 // First, if this window is at the current index, then all
1521 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001522 if (wallpaper == foundW) {
1523 foundI--;
1524 foundW = foundI > 0
1525 ? (WindowState)localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001526 continue;
1527 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001528
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001529 // The window didn't match... the current wallpaper window,
1530 // wherever it is, is in the wrong place, so make sure it is
1531 // not in the list.
1532 int oldIndex = localmWindows.indexOf(wallpaper);
1533 if (oldIndex >= 0) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001534 if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Wallpaper removing at "
1535 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001536 localmWindows.remove(oldIndex);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001537 if (oldIndex < foundI) {
1538 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001539 }
1540 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001541
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001542 // Now stick it in.
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001543 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Log.v(TAG,
1544 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001545 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001546
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001547 localmWindows.add(foundI, wallpaper);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001548 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001549 }
1550 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001551
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001552 return changed;
1553 }
1554
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001555 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001556 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Log.v(TAG,
1557 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001558 mWallpaperAnimLayerAdjustment = adj;
1559 int curTokenIndex = mWallpaperTokens.size();
1560 while (curTokenIndex > 0) {
1561 curTokenIndex--;
1562 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1563 int curWallpaperIndex = token.windows.size();
1564 while (curWallpaperIndex > 0) {
1565 curWallpaperIndex--;
1566 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1567 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001568 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper win "
1569 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001570 }
1571 }
1572 }
1573
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001574 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1575 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001576 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001577 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001578 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001579 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001580 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1581 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1582 changed = wallpaperWin.mXOffset != offset;
1583 if (changed) {
1584 if (DEBUG_WALLPAPER) Log.v(TAG, "Update wallpaper "
1585 + wallpaperWin + " x: " + offset);
1586 wallpaperWin.mXOffset = offset;
1587 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001588 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001589 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001590 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001591 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001592 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001593
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001594 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001595 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001596 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1597 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1598 if (wallpaperWin.mYOffset != offset) {
1599 if (DEBUG_WALLPAPER) Log.v(TAG, "Update wallpaper "
1600 + wallpaperWin + " y: " + offset);
1601 changed = true;
1602 wallpaperWin.mYOffset = offset;
1603 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001604 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001605 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001606 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001607 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001608 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001609
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001610 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001611 try {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001612 if (DEBUG_WALLPAPER) Log.v(TAG, "Report new wp offset "
1613 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1614 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001615 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001616 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001617 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001618 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001619 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1620 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001621 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001622 if (mWaitingOnWallpaper != null) {
1623 long start = SystemClock.uptimeMillis();
1624 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1625 < start) {
1626 try {
1627 if (DEBUG_WALLPAPER) Log.v(TAG,
1628 "Waiting for offset complete...");
1629 mWindowMap.wait(WALLPAPER_TIMEOUT);
1630 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001631 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001632 if (DEBUG_WALLPAPER) Log.v(TAG, "Offset complete!");
1633 if ((start+WALLPAPER_TIMEOUT)
1634 < SystemClock.uptimeMillis()) {
1635 Log.i(TAG, "Timeout waiting for wallpaper to offset: "
1636 + wallpaperWin);
1637 mLastWallpaperTimeoutTime = start;
1638 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001639 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001640 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001641 }
1642 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001643 } catch (RemoteException e) {
1644 }
1645 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001646
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001647 return changed;
1648 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001649
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001650 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001651 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001652 if (mWaitingOnWallpaper != null &&
1653 mWaitingOnWallpaper.mClient.asBinder() == window) {
1654 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001655 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001656 }
1657 }
1658 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001659
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001660 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001661 final int dw = mDisplay.getWidth();
1662 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001663
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001664 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001665
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001666 WindowState target = mWallpaperTarget;
1667 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001668 if (target.mWallpaperX >= 0) {
1669 mLastWallpaperX = target.mWallpaperX;
1670 } else if (changingTarget.mWallpaperX >= 0) {
1671 mLastWallpaperX = changingTarget.mWallpaperX;
1672 }
1673 if (target.mWallpaperY >= 0) {
1674 mLastWallpaperY = target.mWallpaperY;
1675 } else if (changingTarget.mWallpaperY >= 0) {
1676 mLastWallpaperY = changingTarget.mWallpaperY;
1677 }
1678 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001679
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001680 int curTokenIndex = mWallpaperTokens.size();
1681 while (curTokenIndex > 0) {
1682 curTokenIndex--;
1683 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1684 int curWallpaperIndex = token.windows.size();
1685 while (curWallpaperIndex > 0) {
1686 curWallpaperIndex--;
1687 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1688 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1689 wallpaper.computeShownFrameLocked();
1690 changed = true;
1691 // We only want to be synchronous with one wallpaper.
1692 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001693 }
1694 }
1695 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001696
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001697 return changed;
1698 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001699
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001700 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001701 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001702 final int dw = mDisplay.getWidth();
1703 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001704
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001705 int curTokenIndex = mWallpaperTokens.size();
1706 while (curTokenIndex > 0) {
1707 curTokenIndex--;
1708 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001709 if (token.hidden == visible) {
1710 token.hidden = !visible;
1711 // Need to do a layout to ensure the wallpaper now has the
1712 // correct size.
1713 mLayoutNeeded = true;
1714 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001715
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001716 int curWallpaperIndex = token.windows.size();
1717 while (curWallpaperIndex > 0) {
1718 curWallpaperIndex--;
1719 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1720 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001721 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001722 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001723
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001724 if (wallpaper.mWallpaperVisible != visible) {
1725 wallpaper.mWallpaperVisible = visible;
1726 try {
1727 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Log.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001728 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001729 + ": " + visible);
1730 wallpaper.mClient.dispatchAppVisibility(visible);
1731 } catch (RemoteException e) {
1732 }
1733 }
1734 }
1735 }
1736 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001737
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001738 void sendPointerToWallpaperLocked(WindowState srcWin,
1739 MotionEvent pointer, long eventTime) {
1740 int curTokenIndex = mWallpaperTokens.size();
1741 while (curTokenIndex > 0) {
1742 curTokenIndex--;
1743 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1744 int curWallpaperIndex = token.windows.size();
1745 while (curWallpaperIndex > 0) {
1746 curWallpaperIndex--;
1747 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1748 if ((wallpaper.mAttrs.flags &
1749 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
1750 continue;
1751 }
1752 try {
1753 MotionEvent ev = MotionEvent.obtainNoHistory(pointer);
Dianne Hackborn6adba242009-11-10 11:10:09 -08001754 if (srcWin != null) {
1755 ev.offsetLocation(srcWin.mFrame.left-wallpaper.mFrame.left,
1756 srcWin.mFrame.top-wallpaper.mFrame.top);
1757 } else {
1758 ev.offsetLocation(-wallpaper.mFrame.left, -wallpaper.mFrame.top);
1759 }
1760 switch (pointer.getAction()) {
1761 case MotionEvent.ACTION_DOWN:
1762 mSendingPointersToWallpaper = true;
1763 break;
1764 case MotionEvent.ACTION_UP:
1765 mSendingPointersToWallpaper = false;
1766 break;
1767 }
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001768 wallpaper.mClient.dispatchPointer(ev, eventTime, false);
1769 } catch (RemoteException e) {
1770 Log.w(TAG, "Failure sending pointer to wallpaper", e);
1771 }
1772 }
1773 }
1774 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001776 public int addWindow(Session session, IWindow client,
1777 WindowManager.LayoutParams attrs, int viewVisibility,
1778 Rect outContentInsets) {
1779 int res = mPolicy.checkAddPermission(attrs);
1780 if (res != WindowManagerImpl.ADD_OKAY) {
1781 return res;
1782 }
Romain Guy06882f82009-06-10 13:36:04 -07001783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001784 boolean reportNewConfig = false;
1785 WindowState attachedWindow = null;
1786 WindowState win = null;
Romain Guy06882f82009-06-10 13:36:04 -07001787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001788 synchronized(mWindowMap) {
1789 // Instantiating a Display requires talking with the simulator,
1790 // so don't do it until we know the system is mostly up and
1791 // running.
1792 if (mDisplay == null) {
1793 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1794 mDisplay = wm.getDefaultDisplay();
1795 mQueue.setDisplay(mDisplay);
1796 reportNewConfig = true;
1797 }
Romain Guy06882f82009-06-10 13:36:04 -07001798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001799 if (mWindowMap.containsKey(client.asBinder())) {
1800 Log.w(TAG, "Window " + client + " is already added");
1801 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1802 }
1803
1804 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Romain Guy06882f82009-06-10 13:36:04 -07001805 attachedWindow = windowForClientLocked(null, attrs.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001806 if (attachedWindow == null) {
1807 Log.w(TAG, "Attempted to add window with token that is not a window: "
1808 + attrs.token + ". Aborting.");
1809 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1810 }
1811 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1812 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
1813 Log.w(TAG, "Attempted to add window with token that is a sub-window: "
1814 + attrs.token + ". Aborting.");
1815 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1816 }
1817 }
1818
1819 boolean addToken = false;
1820 WindowToken token = mTokenMap.get(attrs.token);
1821 if (token == null) {
1822 if (attrs.type >= FIRST_APPLICATION_WINDOW
1823 && attrs.type <= LAST_APPLICATION_WINDOW) {
1824 Log.w(TAG, "Attempted to add application window with unknown token "
1825 + attrs.token + ". Aborting.");
1826 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1827 }
1828 if (attrs.type == TYPE_INPUT_METHOD) {
1829 Log.w(TAG, "Attempted to add input method window with unknown token "
1830 + attrs.token + ". Aborting.");
1831 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1832 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001833 if (attrs.type == TYPE_WALLPAPER) {
1834 Log.w(TAG, "Attempted to add wallpaper window with unknown token "
1835 + attrs.token + ". Aborting.");
1836 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1837 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001838 token = new WindowToken(attrs.token, -1, false);
1839 addToken = true;
1840 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1841 && attrs.type <= LAST_APPLICATION_WINDOW) {
1842 AppWindowToken atoken = token.appWindowToken;
1843 if (atoken == null) {
1844 Log.w(TAG, "Attempted to add window with non-application token "
1845 + token + ". Aborting.");
1846 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1847 } else if (atoken.removed) {
1848 Log.w(TAG, "Attempted to add window with exiting application token "
1849 + token + ". Aborting.");
1850 return WindowManagerImpl.ADD_APP_EXITING;
1851 }
1852 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1853 // No need for this guy!
1854 if (localLOGV) Log.v(
1855 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1856 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1857 }
1858 } else if (attrs.type == TYPE_INPUT_METHOD) {
1859 if (token.windowType != TYPE_INPUT_METHOD) {
1860 Log.w(TAG, "Attempted to add input method window with bad token "
1861 + attrs.token + ". Aborting.");
1862 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1863 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001864 } else if (attrs.type == TYPE_WALLPAPER) {
1865 if (token.windowType != TYPE_WALLPAPER) {
1866 Log.w(TAG, "Attempted to add wallpaper window with bad token "
1867 + attrs.token + ". Aborting.");
1868 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1869 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001870 }
1871
1872 win = new WindowState(session, client, token,
1873 attachedWindow, attrs, viewVisibility);
1874 if (win.mDeathRecipient == null) {
1875 // Client has apparently died, so there is no reason to
1876 // continue.
1877 Log.w(TAG, "Adding window client " + client.asBinder()
1878 + " that is dead, aborting.");
1879 return WindowManagerImpl.ADD_APP_EXITING;
1880 }
1881
1882 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001884 res = mPolicy.prepareAddWindowLw(win, attrs);
1885 if (res != WindowManagerImpl.ADD_OKAY) {
1886 return res;
1887 }
1888
1889 // From now on, no exceptions or errors allowed!
1890
1891 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001893 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001895 if (addToken) {
1896 mTokenMap.put(attrs.token, token);
1897 mTokenList.add(token);
1898 }
1899 win.attach();
1900 mWindowMap.put(client.asBinder(), win);
1901
1902 if (attrs.type == TYPE_APPLICATION_STARTING &&
1903 token.appWindowToken != null) {
1904 token.appWindowToken.startingWindow = win;
1905 }
1906
1907 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001909 if (attrs.type == TYPE_INPUT_METHOD) {
1910 mInputMethodWindow = win;
1911 addInputMethodWindowToListLocked(win);
1912 imMayMove = false;
1913 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1914 mInputMethodDialogs.add(win);
1915 addWindowToListInOrderLocked(win, true);
1916 adjustInputMethodDialogsLocked();
1917 imMayMove = false;
1918 } else {
1919 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001920 if (attrs.type == TYPE_WALLPAPER) {
1921 mLastWallpaperTimeoutTime = 0;
1922 adjustWallpaperWindowsLocked();
1923 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001924 adjustWallpaperWindowsLocked();
1925 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001926 }
Romain Guy06882f82009-06-10 13:36:04 -07001927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001928 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001930 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001932 if (mInTouchMode) {
1933 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1934 }
1935 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1936 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1937 }
Romain Guy06882f82009-06-10 13:36:04 -07001938
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001939 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001940 if (win.canReceiveKeys()) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001941 if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS))
1942 == true) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001943 imMayMove = false;
1944 }
1945 }
Romain Guy06882f82009-06-10 13:36:04 -07001946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001947 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001948 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001949 }
Romain Guy06882f82009-06-10 13:36:04 -07001950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001951 assignLayersLocked();
1952 // Don't do layout here, the window must call
1953 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07001954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001955 //dump();
1956
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001957 if (focusChanged) {
1958 if (mCurrentFocus != null) {
1959 mKeyWaiter.handleNewWindowLocked(mCurrentFocus);
1960 }
1961 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001962 if (localLOGV) Log.v(
1963 TAG, "New client " + client.asBinder()
1964 + ": window=" + win);
1965 }
1966
1967 // sendNewConfiguration() checks caller permissions so we must call it with
1968 // privilege. updateOrientationFromAppTokens() clears and resets the caller
1969 // identity anyway, so it's safe to just clear & restore around this whole
1970 // block.
1971 final long origId = Binder.clearCallingIdentity();
1972 if (reportNewConfig) {
1973 sendNewConfiguration();
1974 } else {
1975 // Update Orientation after adding a window, only if the window needs to be
1976 // displayed right away
1977 if (win.isVisibleOrAdding()) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07001978 if (updateOrientationFromAppTokensUnchecked(null, null) != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001979 sendNewConfiguration();
1980 }
1981 }
1982 }
1983 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07001984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001985 return res;
1986 }
Romain Guy06882f82009-06-10 13:36:04 -07001987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001988 public void removeWindow(Session session, IWindow client) {
1989 synchronized(mWindowMap) {
1990 WindowState win = windowForClientLocked(session, client);
1991 if (win == null) {
1992 return;
1993 }
1994 removeWindowLocked(session, win);
1995 }
1996 }
Romain Guy06882f82009-06-10 13:36:04 -07001997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998 public void removeWindowLocked(Session session, WindowState win) {
1999
2000 if (localLOGV || DEBUG_FOCUS) Log.v(
2001 TAG, "Remove " + win + " client="
2002 + Integer.toHexString(System.identityHashCode(
2003 win.mClient.asBinder()))
2004 + ", surface=" + win.mSurface);
2005
2006 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002008 if (DEBUG_APP_TRANSITIONS) Log.v(
2009 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2010 + " mExiting=" + win.mExiting
2011 + " isAnimating=" + win.isAnimating()
2012 + " app-animation="
2013 + (win.mAppToken != null ? win.mAppToken.animation : null)
2014 + " inPendingTransaction="
2015 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2016 + " mDisplayFrozen=" + mDisplayFrozen);
2017 // Visibility of the removed window. Will be used later to update orientation later on.
2018 boolean wasVisible = false;
2019 // First, see if we need to run an animation. If we do, we have
2020 // to hold off on removing the window until the animation is done.
2021 // If the display is frozen, just remove immediately, since the
2022 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002023 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002024 // If we are not currently running the exit animation, we
2025 // need to see about starting one.
2026 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002027
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002028 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2029 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2030 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2031 }
2032 // Try starting an animation.
2033 if (applyAnimationLocked(win, transit, false)) {
2034 win.mExiting = true;
2035 }
2036 }
2037 if (win.mExiting || win.isAnimating()) {
2038 // The exit animation is running... wait for it!
2039 //Log.i(TAG, "*** Running exit animation...");
2040 win.mExiting = true;
2041 win.mRemoveOnExit = true;
2042 mLayoutNeeded = true;
2043 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2044 performLayoutAndPlaceSurfacesLocked();
2045 if (win.mAppToken != null) {
2046 win.mAppToken.updateReportedVisibilityLocked();
2047 }
2048 //dump();
2049 Binder.restoreCallingIdentity(origId);
2050 return;
2051 }
2052 }
2053
2054 removeWindowInnerLocked(session, win);
2055 // Removing a visible window will effect the computed orientation
2056 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002057 if (wasVisible && computeForcedAppOrientationLocked()
2058 != mForcedAppOrientation) {
2059 mH.sendMessage(mH.obtainMessage(H.COMPUTE_AND_SEND_NEW_CONFIGURATION));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002060 }
2061 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2062 Binder.restoreCallingIdentity(origId);
2063 }
Romain Guy06882f82009-06-10 13:36:04 -07002064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002065 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07002066 mKeyWaiter.finishedKey(session, win.mClient, true,
2067 KeyWaiter.RETURN_NOTHING);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002068 mKeyWaiter.releasePendingPointerLocked(win.mSession);
2069 mKeyWaiter.releasePendingTrackballLocked(win.mSession);
Romain Guy06882f82009-06-10 13:36:04 -07002070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002071 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002073 if (mInputMethodTarget == win) {
2074 moveInputMethodWindowsIfNeededLocked(false);
2075 }
Romain Guy06882f82009-06-10 13:36:04 -07002076
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002077 if (false) {
2078 RuntimeException e = new RuntimeException("here");
2079 e.fillInStackTrace();
2080 Log.w(TAG, "Removing window " + win, e);
2081 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002083 mPolicy.removeWindowLw(win);
2084 win.removeLocked();
2085
2086 mWindowMap.remove(win.mClient.asBinder());
2087 mWindows.remove(win);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002088 if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002089
2090 if (mInputMethodWindow == win) {
2091 mInputMethodWindow = null;
2092 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2093 mInputMethodDialogs.remove(win);
2094 }
Romain Guy06882f82009-06-10 13:36:04 -07002095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002096 final WindowToken token = win.mToken;
2097 final AppWindowToken atoken = win.mAppToken;
2098 token.windows.remove(win);
2099 if (atoken != null) {
2100 atoken.allAppWindows.remove(win);
2101 }
2102 if (localLOGV) Log.v(
2103 TAG, "**** Removing window " + win + ": count="
2104 + token.windows.size());
2105 if (token.windows.size() == 0) {
2106 if (!token.explicit) {
2107 mTokenMap.remove(token.token);
2108 mTokenList.remove(token);
2109 } else if (atoken != null) {
2110 atoken.firstWindowDrawn = false;
2111 }
2112 }
2113
2114 if (atoken != null) {
2115 if (atoken.startingWindow == win) {
2116 atoken.startingWindow = null;
2117 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2118 // If this is the last window and we had requested a starting
2119 // transition window, well there is no point now.
2120 atoken.startingData = null;
2121 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2122 // If this is the last window except for a starting transition
2123 // window, we need to get rid of the starting transition.
2124 if (DEBUG_STARTING_WINDOW) {
2125 Log.v(TAG, "Schedule remove starting " + token
2126 + ": no more real windows");
2127 }
2128 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2129 mH.sendMessage(m);
2130 }
2131 }
Romain Guy06882f82009-06-10 13:36:04 -07002132
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002133 if (win.mAttrs.type == TYPE_WALLPAPER) {
2134 mLastWallpaperTimeoutTime = 0;
2135 adjustWallpaperWindowsLocked();
2136 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002137 adjustWallpaperWindowsLocked();
2138 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002140 if (!mInLayout) {
2141 assignLayersLocked();
2142 mLayoutNeeded = true;
2143 performLayoutAndPlaceSurfacesLocked();
2144 if (win.mAppToken != null) {
2145 win.mAppToken.updateReportedVisibilityLocked();
2146 }
2147 }
2148 }
2149
2150 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2151 long origId = Binder.clearCallingIdentity();
2152 try {
2153 synchronized (mWindowMap) {
2154 WindowState w = windowForClientLocked(session, client);
2155 if ((w != null) && (w.mSurface != null)) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002156 if (SHOW_TRANSACTIONS) Log.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002157 Surface.openTransaction();
2158 try {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002159 if (SHOW_TRANSACTIONS) Log.i(
2160 TAG, " SURFACE " + w.mSurface
2161 + ": transparentRegionHint=" + region);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002162 w.mSurface.setTransparentRegionHint(region);
2163 } finally {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002164 if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002165 Surface.closeTransaction();
2166 }
2167 }
2168 }
2169 } finally {
2170 Binder.restoreCallingIdentity(origId);
2171 }
2172 }
2173
2174 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002175 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002176 Rect visibleInsets) {
2177 long origId = Binder.clearCallingIdentity();
2178 try {
2179 synchronized (mWindowMap) {
2180 WindowState w = windowForClientLocked(session, client);
2181 if (w != null) {
2182 w.mGivenInsetsPending = false;
2183 w.mGivenContentInsets.set(contentInsets);
2184 w.mGivenVisibleInsets.set(visibleInsets);
2185 w.mTouchableInsets = touchableInsets;
2186 mLayoutNeeded = true;
2187 performLayoutAndPlaceSurfacesLocked();
2188 }
2189 }
2190 } finally {
2191 Binder.restoreCallingIdentity(origId);
2192 }
2193 }
Romain Guy06882f82009-06-10 13:36:04 -07002194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002195 public void getWindowDisplayFrame(Session session, IWindow client,
2196 Rect outDisplayFrame) {
2197 synchronized(mWindowMap) {
2198 WindowState win = windowForClientLocked(session, client);
2199 if (win == null) {
2200 outDisplayFrame.setEmpty();
2201 return;
2202 }
2203 outDisplayFrame.set(win.mDisplayFrame);
2204 }
2205 }
2206
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002207 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2208 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002209 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2210 window.mWallpaperX = x;
2211 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002212 window.mWallpaperXStep = xStep;
2213 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002214 if (updateWallpaperOffsetLocked(window, true)) {
2215 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002216 }
2217 }
2218 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002219
Dianne Hackborn75804932009-10-20 20:15:20 -07002220 void wallpaperCommandComplete(IBinder window, Bundle result) {
2221 synchronized (mWindowMap) {
2222 if (mWaitingOnWallpaper != null &&
2223 mWaitingOnWallpaper.mClient.asBinder() == window) {
2224 mWaitingOnWallpaper = null;
2225 mWindowMap.notifyAll();
2226 }
2227 }
2228 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002229
Dianne Hackborn75804932009-10-20 20:15:20 -07002230 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2231 String action, int x, int y, int z, Bundle extras, boolean sync) {
2232 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2233 || window == mUpperWallpaperTarget) {
2234 boolean doWait = sync;
2235 int curTokenIndex = mWallpaperTokens.size();
2236 while (curTokenIndex > 0) {
2237 curTokenIndex--;
2238 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2239 int curWallpaperIndex = token.windows.size();
2240 while (curWallpaperIndex > 0) {
2241 curWallpaperIndex--;
2242 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2243 try {
2244 wallpaper.mClient.dispatchWallpaperCommand(action,
2245 x, y, z, extras, sync);
2246 // We only want to be synchronous with one wallpaper.
2247 sync = false;
2248 } catch (RemoteException e) {
2249 }
2250 }
2251 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002252
Dianne Hackborn75804932009-10-20 20:15:20 -07002253 if (doWait) {
2254 // XXX Need to wait for result.
2255 }
2256 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002257
Dianne Hackborn75804932009-10-20 20:15:20 -07002258 return null;
2259 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002261 public int relayoutWindow(Session session, IWindow client,
2262 WindowManager.LayoutParams attrs, int requestedWidth,
2263 int requestedHeight, int viewVisibility, boolean insetsPending,
2264 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
2265 Surface outSurface) {
2266 boolean displayed = false;
2267 boolean inTouchMode;
2268 Configuration newConfig = null;
2269 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002271 synchronized(mWindowMap) {
2272 WindowState win = windowForClientLocked(session, client);
2273 if (win == null) {
2274 return 0;
2275 }
2276 win.mRequestedWidth = requestedWidth;
2277 win.mRequestedHeight = requestedHeight;
2278
2279 if (attrs != null) {
2280 mPolicy.adjustWindowParamsLw(attrs);
2281 }
Romain Guy06882f82009-06-10 13:36:04 -07002282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 int attrChanges = 0;
2284 int flagChanges = 0;
2285 if (attrs != null) {
2286 flagChanges = win.mAttrs.flags ^= attrs.flags;
2287 attrChanges = win.mAttrs.copyFrom(attrs);
2288 }
2289
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002290 if (DEBUG_LAYOUT) Log.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002291
2292 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2293 win.mAlpha = attrs.alpha;
2294 }
2295
2296 final boolean scaledWindow =
2297 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2298
2299 if (scaledWindow) {
2300 // requested{Width|Height} Surface's physical size
2301 // attrs.{width|height} Size on screen
2302 win.mHScale = (attrs.width != requestedWidth) ?
2303 (attrs.width / (float)requestedWidth) : 1.0f;
2304 win.mVScale = (attrs.height != requestedHeight) ?
2305 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002306 } else {
2307 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002308 }
2309
2310 boolean imMayMove = (flagChanges&(
2311 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2312 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002314 boolean focusMayChange = win.mViewVisibility != viewVisibility
2315 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2316 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002317
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002318 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2319 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002321 win.mRelayoutCalled = true;
2322 final int oldVisibility = win.mViewVisibility;
2323 win.mViewVisibility = viewVisibility;
2324 if (viewVisibility == View.VISIBLE &&
2325 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2326 displayed = !win.isVisibleLw();
2327 if (win.mExiting) {
2328 win.mExiting = false;
2329 win.mAnimation = null;
2330 }
2331 if (win.mDestroying) {
2332 win.mDestroying = false;
2333 mDestroySurface.remove(win);
2334 }
2335 if (oldVisibility == View.GONE) {
2336 win.mEnterAnimationPending = true;
2337 }
2338 if (displayed && win.mSurface != null && !win.mDrawPending
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002339 && !win.mCommitDrawPending && !mDisplayFrozen
2340 && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002341 applyEnterAnimationLocked(win);
2342 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002343 if (displayed && (win.mAttrs.flags
2344 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2345 win.mTurnOnScreen = true;
2346 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002347 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2348 // To change the format, we need to re-build the surface.
2349 win.destroySurfaceLocked();
2350 displayed = true;
2351 }
2352 try {
2353 Surface surface = win.createSurfaceLocked();
2354 if (surface != null) {
2355 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002356 win.mReportDestroySurface = false;
2357 win.mSurfacePendingDestroy = false;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002358 if (SHOW_TRANSACTIONS) Log.i(TAG,
2359 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002360 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002361 // For some reason there isn't a surface. Clear the
2362 // caller's object so they see the same state.
2363 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002364 }
2365 } catch (Exception e) {
2366 Log.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002367 + client + " (" + win.mAttrs.getTitle() + ")",
2368 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002369 Binder.restoreCallingIdentity(origId);
2370 return 0;
2371 }
2372 if (displayed) {
2373 focusMayChange = true;
2374 }
2375 if (win.mAttrs.type == TYPE_INPUT_METHOD
2376 && mInputMethodWindow == null) {
2377 mInputMethodWindow = win;
2378 imMayMove = true;
2379 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002380 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2381 && win.mAppToken != null
2382 && win.mAppToken.startingWindow != null) {
2383 // Special handling of starting window over the base
2384 // window of the app: propagate lock screen flags to it,
2385 // to provide the correct semantics while starting.
2386 final int mask =
2387 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
2388 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
2389 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2390 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2391 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002392 } else {
2393 win.mEnterAnimationPending = false;
2394 if (win.mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002395 if (DEBUG_VISIBILITY) Log.i(TAG, "Relayout invis " + win
2396 + ": mExiting=" + win.mExiting
2397 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002398 // If we are not currently running the exit animation, we
2399 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002400 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002401 // Try starting an animation; if there isn't one, we
2402 // can destroy the surface right away.
2403 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2404 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2405 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2406 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002407 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002408 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002409 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002410 win.mExiting = true;
2411 mKeyWaiter.finishedKey(session, client, true,
2412 KeyWaiter.RETURN_NOTHING);
2413 } else if (win.isAnimating()) {
2414 // Currently in a hide animation... turn this into
2415 // an exit.
2416 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002417 } else if (win == mWallpaperTarget) {
2418 // If the wallpaper is currently behind this
2419 // window, we need to change both of them inside
2420 // of a transaction to avoid artifacts.
2421 win.mExiting = true;
2422 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002423 } else {
2424 if (mInputMethodWindow == win) {
2425 mInputMethodWindow = null;
2426 }
2427 win.destroySurfaceLocked();
2428 }
2429 }
2430 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002431
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002432 if (win.mSurface == null || (win.getAttrs().flags
2433 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2434 || win.mSurfacePendingDestroy) {
2435 // We are being called from a local process, which
2436 // means outSurface holds its current surface. Ensure the
2437 // surface object is cleared, but we don't want it actually
2438 // destroyed at this point.
2439 win.mSurfacePendingDestroy = false;
2440 outSurface.release();
2441 if (DEBUG_VISIBILITY) Log.i(TAG, "Releasing surface in: " + win);
2442 } else if (win.mSurface != null) {
2443 if (DEBUG_VISIBILITY) Log.i(TAG,
2444 "Keeping surface, will report destroy: " + win);
2445 win.mReportDestroySurface = true;
2446 outSurface.copyFrom(win.mSurface);
2447 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002448 }
2449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 if (focusMayChange) {
2451 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2452 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002453 imMayMove = false;
2454 }
2455 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2456 }
Romain Guy06882f82009-06-10 13:36:04 -07002457
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002458 // updateFocusedWindowLocked() already assigned layers so we only need to
2459 // reassign them at this point if the IM window state gets shuffled
2460 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002462 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002463 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2464 // Little hack here -- we -should- be able to rely on the
2465 // function to return true if the IME has moved and needs
2466 // its layer recomputed. However, if the IME was hidden
2467 // and isn't actually moved in the list, its layer may be
2468 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002469 assignLayers = true;
2470 }
2471 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002472 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002473 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002474 assignLayers = true;
2475 }
2476 }
Romain Guy06882f82009-06-10 13:36:04 -07002477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002478 mLayoutNeeded = true;
2479 win.mGivenInsetsPending = insetsPending;
2480 if (assignLayers) {
2481 assignLayersLocked();
2482 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002483 newConfig = updateOrientationFromAppTokensLocked(null, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002484 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002485 if (displayed && win.mIsWallpaper) {
2486 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002487 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002488 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002489 if (win.mAppToken != null) {
2490 win.mAppToken.updateReportedVisibilityLocked();
2491 }
2492 outFrame.set(win.mFrame);
2493 outContentInsets.set(win.mContentInsets);
2494 outVisibleInsets.set(win.mVisibleInsets);
2495 if (localLOGV) Log.v(
2496 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002497 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002498 + ", requestedHeight=" + requestedHeight
2499 + ", viewVisibility=" + viewVisibility
2500 + "\nRelayout returning frame=" + outFrame
2501 + ", surface=" + outSurface);
2502
2503 if (localLOGV || DEBUG_FOCUS) Log.v(
2504 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2505
2506 inTouchMode = mInTouchMode;
2507 }
2508
2509 if (newConfig != null) {
2510 sendNewConfiguration();
2511 }
Romain Guy06882f82009-06-10 13:36:04 -07002512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002513 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002515 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2516 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2517 }
2518
2519 public void finishDrawingWindow(Session session, IWindow client) {
2520 final long origId = Binder.clearCallingIdentity();
2521 synchronized(mWindowMap) {
2522 WindowState win = windowForClientLocked(session, client);
2523 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002524 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2525 adjustWallpaperWindowsLocked();
2526 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002527 mLayoutNeeded = true;
2528 performLayoutAndPlaceSurfacesLocked();
2529 }
2530 }
2531 Binder.restoreCallingIdentity(origId);
2532 }
2533
2534 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
2535 if (DEBUG_ANIM) Log.v(TAG, "Loading animations: params package="
2536 + (lp != null ? lp.packageName : null)
2537 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2538 if (lp != null && lp.windowAnimations != 0) {
2539 // If this is a system resource, don't try to load it from the
2540 // application resources. It is nice to avoid loading application
2541 // resources if we can.
2542 String packageName = lp.packageName != null ? lp.packageName : "android";
2543 int resId = lp.windowAnimations;
2544 if ((resId&0xFF000000) == 0x01000000) {
2545 packageName = "android";
2546 }
2547 if (DEBUG_ANIM) Log.v(TAG, "Loading animations: picked package="
2548 + packageName);
2549 return AttributeCache.instance().get(packageName, resId,
2550 com.android.internal.R.styleable.WindowAnimation);
2551 }
2552 return null;
2553 }
Romain Guy06882f82009-06-10 13:36:04 -07002554
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002555 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
2556 if (DEBUG_ANIM) Log.v(TAG, "Loading animations: params package="
2557 + packageName + " resId=0x" + Integer.toHexString(resId));
2558 if (packageName != null) {
2559 if ((resId&0xFF000000) == 0x01000000) {
2560 packageName = "android";
2561 }
2562 if (DEBUG_ANIM) Log.v(TAG, "Loading animations: picked package="
2563 + packageName);
2564 return AttributeCache.instance().get(packageName, resId,
2565 com.android.internal.R.styleable.WindowAnimation);
2566 }
2567 return null;
2568 }
2569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002570 private void applyEnterAnimationLocked(WindowState win) {
2571 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2572 if (win.mEnterAnimationPending) {
2573 win.mEnterAnimationPending = false;
2574 transit = WindowManagerPolicy.TRANSIT_ENTER;
2575 }
2576
2577 applyAnimationLocked(win, transit, true);
2578 }
2579
2580 private boolean applyAnimationLocked(WindowState win,
2581 int transit, boolean isEntrance) {
2582 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2583 // If we are trying to apply an animation, but already running
2584 // an animation of the same type, then just leave that one alone.
2585 return true;
2586 }
Romain Guy06882f82009-06-10 13:36:04 -07002587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002588 // Only apply an animation if the display isn't frozen. If it is
2589 // frozen, there is no reason to animate and it can cause strange
2590 // artifacts when we unfreeze the display if some different animation
2591 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002592 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002593 int anim = mPolicy.selectAnimationLw(win, transit);
2594 int attr = -1;
2595 Animation a = null;
2596 if (anim != 0) {
2597 a = AnimationUtils.loadAnimation(mContext, anim);
2598 } else {
2599 switch (transit) {
2600 case WindowManagerPolicy.TRANSIT_ENTER:
2601 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2602 break;
2603 case WindowManagerPolicy.TRANSIT_EXIT:
2604 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2605 break;
2606 case WindowManagerPolicy.TRANSIT_SHOW:
2607 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2608 break;
2609 case WindowManagerPolicy.TRANSIT_HIDE:
2610 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2611 break;
2612 }
2613 if (attr >= 0) {
2614 a = loadAnimation(win.mAttrs, attr);
2615 }
2616 }
2617 if (DEBUG_ANIM) Log.v(TAG, "applyAnimation: win=" + win
2618 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2619 + " mAnimation=" + win.mAnimation
2620 + " isEntrance=" + isEntrance);
2621 if (a != null) {
2622 if (DEBUG_ANIM) {
2623 RuntimeException e = new RuntimeException();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002624 if (!HIDE_STACK_CRAWLS) e.fillInStackTrace();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002625 Log.v(TAG, "Loaded animation " + a + " for " + win, e);
2626 }
2627 win.setAnimation(a);
2628 win.mAnimationIsEntrance = isEntrance;
2629 }
2630 } else {
2631 win.clearAnimation();
2632 }
2633
2634 return win.mAnimation != null;
2635 }
2636
2637 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2638 int anim = 0;
2639 Context context = mContext;
2640 if (animAttr >= 0) {
2641 AttributeCache.Entry ent = getCachedAnimations(lp);
2642 if (ent != null) {
2643 context = ent.context;
2644 anim = ent.array.getResourceId(animAttr, 0);
2645 }
2646 }
2647 if (anim != 0) {
2648 return AnimationUtils.loadAnimation(context, anim);
2649 }
2650 return null;
2651 }
Romain Guy06882f82009-06-10 13:36:04 -07002652
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002653 private Animation loadAnimation(String packageName, int resId) {
2654 int anim = 0;
2655 Context context = mContext;
2656 if (resId >= 0) {
2657 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2658 if (ent != null) {
2659 context = ent.context;
2660 anim = resId;
2661 }
2662 }
2663 if (anim != 0) {
2664 return AnimationUtils.loadAnimation(context, anim);
2665 }
2666 return null;
2667 }
2668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002669 private boolean applyAnimationLocked(AppWindowToken wtoken,
2670 WindowManager.LayoutParams lp, int transit, boolean enter) {
2671 // Only apply an animation if the display isn't frozen. If it is
2672 // frozen, there is no reason to animate and it can cause strange
2673 // artifacts when we unfreeze the display if some different animation
2674 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002675 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002676 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002677 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002678 a = new FadeInOutAnimation(enter);
2679 if (DEBUG_ANIM) Log.v(TAG,
2680 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002681 } else if (mNextAppTransitionPackage != null) {
2682 a = loadAnimation(mNextAppTransitionPackage, enter ?
2683 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002684 } else {
2685 int animAttr = 0;
2686 switch (transit) {
2687 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2688 animAttr = enter
2689 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2690 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2691 break;
2692 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2693 animAttr = enter
2694 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2695 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2696 break;
2697 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2698 animAttr = enter
2699 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2700 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2701 break;
2702 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2703 animAttr = enter
2704 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2705 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2706 break;
2707 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2708 animAttr = enter
2709 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2710 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2711 break;
2712 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2713 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002714 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002715 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2716 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002717 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002718 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002719 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2720 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002721 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002722 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002723 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002724 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2725 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2726 break;
2727 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2728 animAttr = enter
2729 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2730 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2731 break;
2732 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2733 animAttr = enter
2734 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2735 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002736 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002737 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002738 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002739 if (DEBUG_ANIM) Log.v(TAG, "applyAnimation: wtoken=" + wtoken
2740 + " anim=" + a
2741 + " animAttr=0x" + Integer.toHexString(animAttr)
2742 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002743 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002744 if (a != null) {
2745 if (DEBUG_ANIM) {
2746 RuntimeException e = new RuntimeException();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002747 if (!HIDE_STACK_CRAWLS) e.fillInStackTrace();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002748 Log.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
2749 }
2750 wtoken.setAnimation(a);
2751 }
2752 } else {
2753 wtoken.clearAnimation();
2754 }
2755
2756 return wtoken.animation != null;
2757 }
2758
2759 // -------------------------------------------------------------
2760 // Application Window Tokens
2761 // -------------------------------------------------------------
2762
2763 public void validateAppTokens(List tokens) {
2764 int v = tokens.size()-1;
2765 int m = mAppTokens.size()-1;
2766 while (v >= 0 && m >= 0) {
2767 AppWindowToken wtoken = mAppTokens.get(m);
2768 if (wtoken.removed) {
2769 m--;
2770 continue;
2771 }
2772 if (tokens.get(v) != wtoken.token) {
2773 Log.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
2774 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2775 }
2776 v--;
2777 m--;
2778 }
2779 while (v >= 0) {
2780 Log.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
2781 v--;
2782 }
2783 while (m >= 0) {
2784 AppWindowToken wtoken = mAppTokens.get(m);
2785 if (!wtoken.removed) {
2786 Log.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
2787 }
2788 m--;
2789 }
2790 }
2791
2792 boolean checkCallingPermission(String permission, String func) {
2793 // Quick check: if the calling permission is me, it's all okay.
2794 if (Binder.getCallingPid() == Process.myPid()) {
2795 return true;
2796 }
Romain Guy06882f82009-06-10 13:36:04 -07002797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002798 if (mContext.checkCallingPermission(permission)
2799 == PackageManager.PERMISSION_GRANTED) {
2800 return true;
2801 }
2802 String msg = "Permission Denial: " + func + " from pid="
2803 + Binder.getCallingPid()
2804 + ", uid=" + Binder.getCallingUid()
2805 + " requires " + permission;
2806 Log.w(TAG, msg);
2807 return false;
2808 }
Romain Guy06882f82009-06-10 13:36:04 -07002809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002810 AppWindowToken findAppWindowToken(IBinder token) {
2811 WindowToken wtoken = mTokenMap.get(token);
2812 if (wtoken == null) {
2813 return null;
2814 }
2815 return wtoken.appWindowToken;
2816 }
Romain Guy06882f82009-06-10 13:36:04 -07002817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002818 public void addWindowToken(IBinder token, int type) {
2819 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2820 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002821 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002822 }
Romain Guy06882f82009-06-10 13:36:04 -07002823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002824 synchronized(mWindowMap) {
2825 WindowToken wtoken = mTokenMap.get(token);
2826 if (wtoken != null) {
2827 Log.w(TAG, "Attempted to add existing input method token: " + token);
2828 return;
2829 }
2830 wtoken = new WindowToken(token, type, true);
2831 mTokenMap.put(token, wtoken);
2832 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002833 if (type == TYPE_WALLPAPER) {
2834 mWallpaperTokens.add(wtoken);
2835 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002836 }
2837 }
Romain Guy06882f82009-06-10 13:36:04 -07002838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002839 public void removeWindowToken(IBinder token) {
2840 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2841 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002842 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002843 }
2844
2845 final long origId = Binder.clearCallingIdentity();
2846 synchronized(mWindowMap) {
2847 WindowToken wtoken = mTokenMap.remove(token);
2848 mTokenList.remove(wtoken);
2849 if (wtoken != null) {
2850 boolean delayed = false;
2851 if (!wtoken.hidden) {
2852 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002854 final int N = wtoken.windows.size();
2855 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002857 for (int i=0; i<N; i++) {
2858 WindowState win = wtoken.windows.get(i);
2859
2860 if (win.isAnimating()) {
2861 delayed = true;
2862 }
Romain Guy06882f82009-06-10 13:36:04 -07002863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002864 if (win.isVisibleNow()) {
2865 applyAnimationLocked(win,
2866 WindowManagerPolicy.TRANSIT_EXIT, false);
2867 mKeyWaiter.finishedKey(win.mSession, win.mClient, true,
2868 KeyWaiter.RETURN_NOTHING);
2869 changed = true;
2870 }
2871 }
2872
2873 if (changed) {
2874 mLayoutNeeded = true;
2875 performLayoutAndPlaceSurfacesLocked();
2876 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2877 }
Romain Guy06882f82009-06-10 13:36:04 -07002878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002879 if (delayed) {
2880 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002881 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2882 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002883 }
2884 }
Romain Guy06882f82009-06-10 13:36:04 -07002885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002886 } else {
2887 Log.w(TAG, "Attempted to remove non-existing token: " + token);
2888 }
2889 }
2890 Binder.restoreCallingIdentity(origId);
2891 }
2892
2893 public void addAppToken(int addPos, IApplicationToken token,
2894 int groupId, int requestedOrientation, boolean fullscreen) {
2895 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2896 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002897 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002898 }
Romain Guy06882f82009-06-10 13:36:04 -07002899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002900 synchronized(mWindowMap) {
2901 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2902 if (wtoken != null) {
2903 Log.w(TAG, "Attempted to add existing app token: " + token);
2904 return;
2905 }
2906 wtoken = new AppWindowToken(token);
2907 wtoken.groupId = groupId;
2908 wtoken.appFullscreen = fullscreen;
2909 wtoken.requestedOrientation = requestedOrientation;
2910 mAppTokens.add(addPos, wtoken);
Dave Bortcfe65242009-04-09 14:51:04 -07002911 if (localLOGV) Log.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 mTokenMap.put(token.asBinder(), wtoken);
2913 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002915 // Application tokens start out hidden.
2916 wtoken.hidden = true;
2917 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002919 //dump();
2920 }
2921 }
Romain Guy06882f82009-06-10 13:36:04 -07002922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002923 public void setAppGroupId(IBinder token, int groupId) {
2924 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2925 "setAppStartingIcon()")) {
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 synchronized(mWindowMap) {
2930 AppWindowToken wtoken = findAppWindowToken(token);
2931 if (wtoken == null) {
2932 Log.w(TAG, "Attempted to set group id of non-existing app token: " + token);
2933 return;
2934 }
2935 wtoken.groupId = groupId;
2936 }
2937 }
Romain Guy06882f82009-06-10 13:36:04 -07002938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002939 public int getOrientationFromWindowsLocked() {
2940 int pos = mWindows.size() - 1;
2941 while (pos >= 0) {
2942 WindowState wtoken = (WindowState) mWindows.get(pos);
2943 pos--;
2944 if (wtoken.mAppToken != null) {
2945 // We hit an application window. so the orientation will be determined by the
2946 // app window. No point in continuing further.
2947 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
2948 }
2949 if (!wtoken.isVisibleLw()) {
2950 continue;
2951 }
2952 int req = wtoken.mAttrs.screenOrientation;
2953 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
2954 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
2955 continue;
2956 } else {
2957 return req;
2958 }
2959 }
2960 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
2961 }
Romain Guy06882f82009-06-10 13:36:04 -07002962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002963 public int getOrientationFromAppTokensLocked() {
2964 int pos = mAppTokens.size() - 1;
2965 int curGroup = 0;
2966 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Owen Lin3413b892009-05-01 17:12:32 -07002967 boolean findingBehind = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002968 boolean haveGroup = false;
The Android Open Source Project4df24232009-03-05 14:34:35 -08002969 boolean lastFullscreen = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002970 while (pos >= 0) {
2971 AppWindowToken wtoken = mAppTokens.get(pos);
2972 pos--;
Owen Lin3413b892009-05-01 17:12:32 -07002973 // if we're about to tear down this window and not seek for
2974 // the behind activity, don't use it for orientation
2975 if (!findingBehind
2976 && (!wtoken.hidden && wtoken.hiddenRequested)) {
The Android Open Source Project10592532009-03-18 17:39:46 -07002977 continue;
2978 }
2979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002980 if (!haveGroup) {
2981 // We ignore any hidden applications on the top.
2982 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
2983 continue;
2984 }
2985 haveGroup = true;
2986 curGroup = wtoken.groupId;
2987 lastOrientation = wtoken.requestedOrientation;
2988 } else if (curGroup != wtoken.groupId) {
2989 // If we have hit a new application group, and the bottom
2990 // of the previous group didn't explicitly say to use
The Android Open Source Project4df24232009-03-05 14:34:35 -08002991 // the orientation behind it, and the last app was
2992 // full screen, then we'll stick with the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002993 // user's orientation.
The Android Open Source Project4df24232009-03-05 14:34:35 -08002994 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
2995 && lastFullscreen) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002996 return lastOrientation;
2997 }
2998 }
2999 int or = wtoken.requestedOrientation;
Owen Lin3413b892009-05-01 17:12:32 -07003000 // If this application is fullscreen, and didn't explicitly say
3001 // to use the orientation behind it, then just take whatever
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003002 // orientation it has and ignores whatever is under it.
The Android Open Source Project4df24232009-03-05 14:34:35 -08003003 lastFullscreen = wtoken.appFullscreen;
Romain Guy06882f82009-06-10 13:36:04 -07003004 if (lastFullscreen
Owen Lin3413b892009-05-01 17:12:32 -07003005 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003006 return or;
3007 }
3008 // If this application has requested an explicit orientation,
3009 // then use it.
3010 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3011 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3012 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3013 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3014 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3015 return or;
3016 }
Owen Lin3413b892009-05-01 17:12:32 -07003017 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003018 }
3019 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3020 }
Romain Guy06882f82009-06-10 13:36:04 -07003021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003022 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003023 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003024 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3025 "updateOrientationFromAppTokens()")) {
3026 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3027 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003029 Configuration config;
3030 long ident = Binder.clearCallingIdentity();
Dianne Hackborncfaef692009-06-15 14:24:44 -07003031 config = updateOrientationFromAppTokensUnchecked(currentConfig,
3032 freezeThisOneIfNeeded);
3033 Binder.restoreCallingIdentity(ident);
3034 return config;
3035 }
3036
3037 Configuration updateOrientationFromAppTokensUnchecked(
3038 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
3039 Configuration config;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003040 synchronized(mWindowMap) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003041 config = updateOrientationFromAppTokensLocked(currentConfig, freezeThisOneIfNeeded);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003042 if (config != null) {
3043 mLayoutNeeded = true;
3044 performLayoutAndPlaceSurfacesLocked();
3045 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003046 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003047 return config;
3048 }
Romain Guy06882f82009-06-10 13:36:04 -07003049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003050 /*
3051 * The orientation is computed from non-application windows first. If none of
3052 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003053 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003054 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3055 * android.os.IBinder)
3056 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003057 Configuration updateOrientationFromAppTokensLocked(
The Android Open Source Project10592532009-03-18 17:39:46 -07003058 Configuration appConfig, IBinder freezeThisOneIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003059 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003060 long ident = Binder.clearCallingIdentity();
3061 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003062 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003064 if (req != mForcedAppOrientation) {
3065 changed = true;
3066 mForcedAppOrientation = req;
3067 //send a message to Policy indicating orientation change to take
3068 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003069 mPolicy.setCurrentOrientationLw(req);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003070 }
Romain Guy06882f82009-06-10 13:36:04 -07003071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003072 if (changed) {
3073 changed = setRotationUncheckedLocked(
Dianne Hackborn321ae682009-03-27 16:16:03 -07003074 WindowManagerPolicy.USE_LAST_ROTATION,
3075 mLastRotationFlags & (~Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003076 if (changed) {
3077 if (freezeThisOneIfNeeded != null) {
3078 AppWindowToken wtoken = findAppWindowToken(
3079 freezeThisOneIfNeeded);
3080 if (wtoken != null) {
3081 startAppFreezingScreenLocked(wtoken,
3082 ActivityInfo.CONFIG_ORIENTATION);
3083 }
3084 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07003085 return computeNewConfigurationLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003086 }
3087 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003088
3089 // No obvious action we need to take, but if our current
3090 // state mismatches the activity maanager's, update it
3091 if (appConfig != null) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07003092 mTempConfiguration.setToDefaults();
3093 if (computeNewConfigurationLocked(mTempConfiguration)) {
3094 if (appConfig.diff(mTempConfiguration) != 0) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07003095 return new Configuration(mTempConfiguration);
3096 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003097 }
3098 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003099 } finally {
3100 Binder.restoreCallingIdentity(ident);
3101 }
Romain Guy06882f82009-06-10 13:36:04 -07003102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003103 return null;
3104 }
Romain Guy06882f82009-06-10 13:36:04 -07003105
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003106 int computeForcedAppOrientationLocked() {
3107 int req = getOrientationFromWindowsLocked();
3108 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3109 req = getOrientationFromAppTokensLocked();
3110 }
3111 return req;
3112 }
Romain Guy06882f82009-06-10 13:36:04 -07003113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003114 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3115 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3116 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003117 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003118 }
Romain Guy06882f82009-06-10 13:36:04 -07003119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003120 synchronized(mWindowMap) {
3121 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3122 if (wtoken == null) {
3123 Log.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
3124 return;
3125 }
Romain Guy06882f82009-06-10 13:36:04 -07003126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003127 wtoken.requestedOrientation = requestedOrientation;
3128 }
3129 }
Romain Guy06882f82009-06-10 13:36:04 -07003130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003131 public int getAppOrientation(IApplicationToken token) {
3132 synchronized(mWindowMap) {
3133 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3134 if (wtoken == null) {
3135 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3136 }
Romain Guy06882f82009-06-10 13:36:04 -07003137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003138 return wtoken.requestedOrientation;
3139 }
3140 }
Romain Guy06882f82009-06-10 13:36:04 -07003141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003142 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3143 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3144 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003145 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003146 }
3147
3148 synchronized(mWindowMap) {
3149 boolean changed = false;
3150 if (token == null) {
3151 if (DEBUG_FOCUS) Log.v(TAG, "Clearing focused app, was " + mFocusedApp);
3152 changed = mFocusedApp != null;
3153 mFocusedApp = null;
3154 mKeyWaiter.tickle();
3155 } else {
3156 AppWindowToken newFocus = findAppWindowToken(token);
3157 if (newFocus == null) {
3158 Log.w(TAG, "Attempted to set focus to non-existing app token: " + token);
3159 return;
3160 }
3161 changed = mFocusedApp != newFocus;
3162 mFocusedApp = newFocus;
3163 if (DEBUG_FOCUS) Log.v(TAG, "Set focused app to: " + mFocusedApp);
3164 mKeyWaiter.tickle();
3165 }
3166
3167 if (moveFocusNow && changed) {
3168 final long origId = Binder.clearCallingIdentity();
3169 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3170 Binder.restoreCallingIdentity(origId);
3171 }
3172 }
3173 }
3174
3175 public void prepareAppTransition(int transit) {
3176 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3177 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003178 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003179 }
Romain Guy06882f82009-06-10 13:36:04 -07003180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003181 synchronized(mWindowMap) {
3182 if (DEBUG_APP_TRANSITIONS) Log.v(
3183 TAG, "Prepare app transition: transit=" + transit
3184 + " mNextAppTransition=" + mNextAppTransition);
3185 if (!mDisplayFrozen) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003186 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3187 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003188 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003189 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3190 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3191 // Opening a new task always supersedes a close for the anim.
3192 mNextAppTransition = transit;
3193 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3194 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3195 // Opening a new activity always supersedes a close for the anim.
3196 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003197 }
3198 mAppTransitionReady = false;
3199 mAppTransitionTimeout = false;
3200 mStartingIconInTransition = false;
3201 mSkipAppTransitionAnimation = false;
3202 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3203 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3204 5000);
3205 }
3206 }
3207 }
3208
3209 public int getPendingAppTransition() {
3210 return mNextAppTransition;
3211 }
Romain Guy06882f82009-06-10 13:36:04 -07003212
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003213 public void overridePendingAppTransition(String packageName,
3214 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003215 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003216 mNextAppTransitionPackage = packageName;
3217 mNextAppTransitionEnter = enterAnim;
3218 mNextAppTransitionExit = exitAnim;
3219 }
3220 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003222 public void executeAppTransition() {
3223 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3224 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003225 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003226 }
Romain Guy06882f82009-06-10 13:36:04 -07003227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003228 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003229 if (DEBUG_APP_TRANSITIONS) {
3230 RuntimeException e = new RuntimeException("here");
3231 e.fillInStackTrace();
3232 Log.w(TAG, "Execute app transition: mNextAppTransition="
3233 + mNextAppTransition, e);
3234 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003235 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003236 mAppTransitionReady = true;
3237 final long origId = Binder.clearCallingIdentity();
3238 performLayoutAndPlaceSurfacesLocked();
3239 Binder.restoreCallingIdentity(origId);
3240 }
3241 }
3242 }
3243
3244 public void setAppStartingWindow(IBinder token, String pkg,
3245 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3246 IBinder transferFrom, boolean createIfNeeded) {
3247 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3248 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003249 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003250 }
3251
3252 synchronized(mWindowMap) {
3253 if (DEBUG_STARTING_WINDOW) Log.v(
3254 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3255 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003257 AppWindowToken wtoken = findAppWindowToken(token);
3258 if (wtoken == null) {
3259 Log.w(TAG, "Attempted to set icon of non-existing app token: " + token);
3260 return;
3261 }
3262
3263 // If the display is frozen, we won't do anything until the
3264 // actual window is displayed so there is no reason to put in
3265 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003266 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003267 return;
3268 }
Romain Guy06882f82009-06-10 13:36:04 -07003269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003270 if (wtoken.startingData != null) {
3271 return;
3272 }
Romain Guy06882f82009-06-10 13:36:04 -07003273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003274 if (transferFrom != null) {
3275 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3276 if (ttoken != null) {
3277 WindowState startingWindow = ttoken.startingWindow;
3278 if (startingWindow != null) {
3279 if (mStartingIconInTransition) {
3280 // In this case, the starting icon has already
3281 // been displayed, so start letting windows get
3282 // shown immediately without any more transitions.
3283 mSkipAppTransitionAnimation = true;
3284 }
3285 if (DEBUG_STARTING_WINDOW) Log.v(TAG,
3286 "Moving existing starting from " + ttoken
3287 + " to " + wtoken);
3288 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003290 // Transfer the starting window over to the new
3291 // token.
3292 wtoken.startingData = ttoken.startingData;
3293 wtoken.startingView = ttoken.startingView;
3294 wtoken.startingWindow = startingWindow;
3295 ttoken.startingData = null;
3296 ttoken.startingView = null;
3297 ttoken.startingWindow = null;
3298 ttoken.startingMoved = true;
3299 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003300 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003301 startingWindow.mAppToken = wtoken;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003302 if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG,
3303 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003304 mWindows.remove(startingWindow);
3305 ttoken.windows.remove(startingWindow);
3306 ttoken.allAppWindows.remove(startingWindow);
3307 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003309 // Propagate other interesting state between the
3310 // tokens. If the old token is displayed, we should
3311 // immediately force the new one to be displayed. If
3312 // it is animating, we need to move that animation to
3313 // the new one.
3314 if (ttoken.allDrawn) {
3315 wtoken.allDrawn = true;
3316 }
3317 if (ttoken.firstWindowDrawn) {
3318 wtoken.firstWindowDrawn = true;
3319 }
3320 if (!ttoken.hidden) {
3321 wtoken.hidden = false;
3322 wtoken.hiddenRequested = false;
3323 wtoken.willBeHidden = false;
3324 }
3325 if (wtoken.clientHidden != ttoken.clientHidden) {
3326 wtoken.clientHidden = ttoken.clientHidden;
3327 wtoken.sendAppVisibilityToClients();
3328 }
3329 if (ttoken.animation != null) {
3330 wtoken.animation = ttoken.animation;
3331 wtoken.animating = ttoken.animating;
3332 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3333 ttoken.animation = null;
3334 ttoken.animLayerAdjustment = 0;
3335 wtoken.updateLayers();
3336 ttoken.updateLayers();
3337 }
Romain Guy06882f82009-06-10 13:36:04 -07003338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003339 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003340 mLayoutNeeded = true;
3341 performLayoutAndPlaceSurfacesLocked();
3342 Binder.restoreCallingIdentity(origId);
3343 return;
3344 } else if (ttoken.startingData != null) {
3345 // The previous app was getting ready to show a
3346 // starting window, but hasn't yet done so. Steal it!
3347 if (DEBUG_STARTING_WINDOW) Log.v(TAG,
3348 "Moving pending starting from " + ttoken
3349 + " to " + wtoken);
3350 wtoken.startingData = ttoken.startingData;
3351 ttoken.startingData = null;
3352 ttoken.startingMoved = true;
3353 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3354 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3355 // want to process the message ASAP, before any other queued
3356 // messages.
3357 mH.sendMessageAtFrontOfQueue(m);
3358 return;
3359 }
3360 }
3361 }
3362
3363 // There is no existing starting window, and the caller doesn't
3364 // want us to create one, so that's it!
3365 if (!createIfNeeded) {
3366 return;
3367 }
Romain Guy06882f82009-06-10 13:36:04 -07003368
Dianne Hackborn284ac932009-08-28 10:34:25 -07003369 // If this is a translucent or wallpaper window, then don't
3370 // show a starting window -- the current effect (a full-screen
3371 // opaque starting window that fades away to the real contents
3372 // when it is ready) does not work for this.
3373 if (theme != 0) {
3374 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3375 com.android.internal.R.styleable.Window);
3376 if (ent.array.getBoolean(
3377 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3378 return;
3379 }
3380 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003381 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3382 return;
3383 }
3384 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003385 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3386 return;
3387 }
3388 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003390 mStartingIconInTransition = true;
3391 wtoken.startingData = new StartingData(
3392 pkg, theme, nonLocalizedLabel,
3393 labelRes, icon);
3394 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3395 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3396 // want to process the message ASAP, before any other queued
3397 // messages.
3398 mH.sendMessageAtFrontOfQueue(m);
3399 }
3400 }
3401
3402 public void setAppWillBeHidden(IBinder token) {
3403 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3404 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003405 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003406 }
3407
3408 AppWindowToken wtoken;
3409
3410 synchronized(mWindowMap) {
3411 wtoken = findAppWindowToken(token);
3412 if (wtoken == null) {
3413 Log.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token);
3414 return;
3415 }
3416 wtoken.willBeHidden = true;
3417 }
3418 }
Romain Guy06882f82009-06-10 13:36:04 -07003419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003420 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3421 boolean visible, int transit, boolean performLayout) {
3422 boolean delayed = false;
3423
3424 if (wtoken.clientHidden == visible) {
3425 wtoken.clientHidden = !visible;
3426 wtoken.sendAppVisibilityToClients();
3427 }
Romain Guy06882f82009-06-10 13:36:04 -07003428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003429 wtoken.willBeHidden = false;
3430 if (wtoken.hidden == visible) {
3431 final int N = wtoken.allAppWindows.size();
3432 boolean changed = false;
3433 if (DEBUG_APP_TRANSITIONS) Log.v(
3434 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3435 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003437 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003438
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003439 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003440 if (wtoken.animation == sDummyAnimation) {
3441 wtoken.animation = null;
3442 }
3443 applyAnimationLocked(wtoken, lp, transit, visible);
3444 changed = true;
3445 if (wtoken.animation != null) {
3446 delayed = runningAppAnimation = true;
3447 }
3448 }
Romain Guy06882f82009-06-10 13:36:04 -07003449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003450 for (int i=0; i<N; i++) {
3451 WindowState win = wtoken.allAppWindows.get(i);
3452 if (win == wtoken.startingWindow) {
3453 continue;
3454 }
3455
3456 if (win.isAnimating()) {
3457 delayed = true;
3458 }
Romain Guy06882f82009-06-10 13:36:04 -07003459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003460 //Log.i(TAG, "Window " + win + ": vis=" + win.isVisible());
3461 //win.dump(" ");
3462 if (visible) {
3463 if (!win.isVisibleNow()) {
3464 if (!runningAppAnimation) {
3465 applyAnimationLocked(win,
3466 WindowManagerPolicy.TRANSIT_ENTER, true);
3467 }
3468 changed = true;
3469 }
3470 } else if (win.isVisibleNow()) {
3471 if (!runningAppAnimation) {
3472 applyAnimationLocked(win,
3473 WindowManagerPolicy.TRANSIT_EXIT, false);
3474 }
3475 mKeyWaiter.finishedKey(win.mSession, win.mClient, true,
3476 KeyWaiter.RETURN_NOTHING);
3477 changed = true;
3478 }
3479 }
3480
3481 wtoken.hidden = wtoken.hiddenRequested = !visible;
3482 if (!visible) {
3483 unsetAppFreezingScreenLocked(wtoken, true, true);
3484 } else {
3485 // If we are being set visible, and the starting window is
3486 // not yet displayed, then make sure it doesn't get displayed.
3487 WindowState swin = wtoken.startingWindow;
3488 if (swin != null && (swin.mDrawPending
3489 || swin.mCommitDrawPending)) {
3490 swin.mPolicyVisibility = false;
3491 swin.mPolicyVisibilityAfterAnim = false;
3492 }
3493 }
Romain Guy06882f82009-06-10 13:36:04 -07003494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003495 if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "setTokenVisibilityLocked: " + wtoken
3496 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3497 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003498
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003499 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003500 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003501 if (performLayout) {
3502 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3503 performLayoutAndPlaceSurfacesLocked();
3504 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003505 }
3506 }
3507
3508 if (wtoken.animation != null) {
3509 delayed = true;
3510 }
Romain Guy06882f82009-06-10 13:36:04 -07003511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003512 return delayed;
3513 }
3514
3515 public void setAppVisibility(IBinder token, boolean visible) {
3516 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3517 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003518 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003519 }
3520
3521 AppWindowToken wtoken;
3522
3523 synchronized(mWindowMap) {
3524 wtoken = findAppWindowToken(token);
3525 if (wtoken == null) {
3526 Log.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
3527 return;
3528 }
3529
3530 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
3531 RuntimeException e = new RuntimeException();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003532 if (!HIDE_STACK_CRAWLS) e.fillInStackTrace();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003533 Log.v(TAG, "setAppVisibility(" + token + ", " + visible
3534 + "): mNextAppTransition=" + mNextAppTransition
3535 + " hidden=" + wtoken.hidden
3536 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3537 }
Romain Guy06882f82009-06-10 13:36:04 -07003538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003539 // If we are preparing an app transition, then delay changing
3540 // the visibility of this token until we execute that transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003541 if (!mDisplayFrozen && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003542 // Already in requested state, don't do anything more.
3543 if (wtoken.hiddenRequested != visible) {
3544 return;
3545 }
3546 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003548 if (DEBUG_APP_TRANSITIONS) Log.v(
3549 TAG, "Setting dummy animation on: " + wtoken);
3550 wtoken.setDummyAnimation();
3551 mOpeningApps.remove(wtoken);
3552 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003553 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003554 wtoken.inPendingTransaction = true;
3555 if (visible) {
3556 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003557 wtoken.startingDisplayed = false;
3558 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003559
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003560 // If the token is currently hidden (should be the
3561 // common case), then we need to set up to wait for
3562 // its windows to be ready.
3563 if (wtoken.hidden) {
3564 wtoken.allDrawn = false;
3565 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003566
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003567 if (wtoken.clientHidden) {
3568 // In the case where we are making an app visible
3569 // but holding off for a transition, we still need
3570 // to tell the client to make its windows visible so
3571 // they get drawn. Otherwise, we will wait on
3572 // performing the transition until all windows have
3573 // been drawn, they never will be, and we are sad.
3574 wtoken.clientHidden = false;
3575 wtoken.sendAppVisibilityToClients();
3576 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003577 }
3578 } else {
3579 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003580
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003581 // If the token is currently visible (should be the
3582 // common case), then set up to wait for it to be hidden.
3583 if (!wtoken.hidden) {
3584 wtoken.waitingToHide = true;
3585 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003586 }
3587 return;
3588 }
Romain Guy06882f82009-06-10 13:36:04 -07003589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003590 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003591 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003592 wtoken.updateReportedVisibilityLocked();
3593 Binder.restoreCallingIdentity(origId);
3594 }
3595 }
3596
3597 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3598 boolean unfreezeSurfaceNow, boolean force) {
3599 if (wtoken.freezingScreen) {
3600 if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + wtoken
3601 + " force=" + force);
3602 final int N = wtoken.allAppWindows.size();
3603 boolean unfrozeWindows = false;
3604 for (int i=0; i<N; i++) {
3605 WindowState w = wtoken.allAppWindows.get(i);
3606 if (w.mAppFreezing) {
3607 w.mAppFreezing = false;
3608 if (w.mSurface != null && !w.mOrientationChanging) {
3609 w.mOrientationChanging = true;
3610 }
3611 unfrozeWindows = true;
3612 }
3613 }
3614 if (force || unfrozeWindows) {
3615 if (DEBUG_ORIENTATION) Log.v(TAG, "No longer freezing: " + wtoken);
3616 wtoken.freezingScreen = false;
3617 mAppsFreezingScreen--;
3618 }
3619 if (unfreezeSurfaceNow) {
3620 if (unfrozeWindows) {
3621 mLayoutNeeded = true;
3622 performLayoutAndPlaceSurfacesLocked();
3623 }
3624 if (mAppsFreezingScreen == 0 && !mWindowsFreezingScreen) {
3625 stopFreezingDisplayLocked();
3626 }
3627 }
3628 }
3629 }
Romain Guy06882f82009-06-10 13:36:04 -07003630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003631 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3632 int configChanges) {
3633 if (DEBUG_ORIENTATION) {
3634 RuntimeException e = new RuntimeException();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003635 if (!HIDE_STACK_CRAWLS) e.fillInStackTrace();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003636 Log.i(TAG, "Set freezing of " + wtoken.appToken
3637 + ": hidden=" + wtoken.hidden + " freezing="
3638 + wtoken.freezingScreen, e);
3639 }
3640 if (!wtoken.hiddenRequested) {
3641 if (!wtoken.freezingScreen) {
3642 wtoken.freezingScreen = true;
3643 mAppsFreezingScreen++;
3644 if (mAppsFreezingScreen == 1) {
3645 startFreezingDisplayLocked();
3646 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3647 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3648 5000);
3649 }
3650 }
3651 final int N = wtoken.allAppWindows.size();
3652 for (int i=0; i<N; i++) {
3653 WindowState w = wtoken.allAppWindows.get(i);
3654 w.mAppFreezing = true;
3655 }
3656 }
3657 }
Romain Guy06882f82009-06-10 13:36:04 -07003658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003659 public void startAppFreezingScreen(IBinder token, int configChanges) {
3660 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3661 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003662 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003663 }
3664
3665 synchronized(mWindowMap) {
3666 if (configChanges == 0 && !mDisplayFrozen) {
3667 if (DEBUG_ORIENTATION) Log.v(TAG, "Skipping set freeze of " + token);
3668 return;
3669 }
Romain Guy06882f82009-06-10 13:36:04 -07003670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003671 AppWindowToken wtoken = findAppWindowToken(token);
3672 if (wtoken == null || wtoken.appToken == null) {
3673 Log.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
3674 return;
3675 }
3676 final long origId = Binder.clearCallingIdentity();
3677 startAppFreezingScreenLocked(wtoken, configChanges);
3678 Binder.restoreCallingIdentity(origId);
3679 }
3680 }
Romain Guy06882f82009-06-10 13:36:04 -07003681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003682 public void stopAppFreezingScreen(IBinder token, boolean force) {
3683 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3684 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003685 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003686 }
3687
3688 synchronized(mWindowMap) {
3689 AppWindowToken wtoken = findAppWindowToken(token);
3690 if (wtoken == null || wtoken.appToken == null) {
3691 return;
3692 }
3693 final long origId = Binder.clearCallingIdentity();
3694 if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + token
3695 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3696 unsetAppFreezingScreenLocked(wtoken, true, force);
3697 Binder.restoreCallingIdentity(origId);
3698 }
3699 }
Romain Guy06882f82009-06-10 13:36:04 -07003700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003701 public void removeAppToken(IBinder token) {
3702 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3703 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003704 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003705 }
3706
3707 AppWindowToken wtoken = null;
3708 AppWindowToken startingToken = null;
3709 boolean delayed = false;
3710
3711 final long origId = Binder.clearCallingIdentity();
3712 synchronized(mWindowMap) {
3713 WindowToken basewtoken = mTokenMap.remove(token);
3714 mTokenList.remove(basewtoken);
3715 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
3716 if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003717 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003718 wtoken.inPendingTransaction = false;
3719 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003720 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003721 if (mClosingApps.contains(wtoken)) {
3722 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003723 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003724 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003725 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003726 delayed = true;
3727 }
3728 if (DEBUG_APP_TRANSITIONS) Log.v(
3729 TAG, "Removing app " + wtoken + " delayed=" + delayed
3730 + " animation=" + wtoken.animation
3731 + " animating=" + wtoken.animating);
3732 if (delayed) {
3733 // set the token aside because it has an active animation to be finished
3734 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003735 } else {
3736 // Make sure there is no animation running on this token,
3737 // so any windows associated with it will be removed as
3738 // soon as their animations are complete
3739 wtoken.animation = null;
3740 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003741 }
3742 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003743 if (mLastEnterAnimToken == wtoken) {
3744 mLastEnterAnimToken = null;
3745 mLastEnterAnimParams = null;
3746 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003747 wtoken.removed = true;
3748 if (wtoken.startingData != null) {
3749 startingToken = wtoken;
3750 }
3751 unsetAppFreezingScreenLocked(wtoken, true, true);
3752 if (mFocusedApp == wtoken) {
3753 if (DEBUG_FOCUS) Log.v(TAG, "Removing focused app token:" + wtoken);
3754 mFocusedApp = null;
3755 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3756 mKeyWaiter.tickle();
3757 }
3758 } else {
3759 Log.w(TAG, "Attempted to remove non-existing app token: " + token);
3760 }
Romain Guy06882f82009-06-10 13:36:04 -07003761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003762 if (!delayed && wtoken != null) {
3763 wtoken.updateReportedVisibilityLocked();
3764 }
3765 }
3766 Binder.restoreCallingIdentity(origId);
3767
3768 if (startingToken != null) {
3769 if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Schedule remove starting "
3770 + startingToken + ": app token removed");
3771 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3772 mH.sendMessage(m);
3773 }
3774 }
3775
3776 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3777 final int NW = token.windows.size();
3778 for (int i=0; i<NW; i++) {
3779 WindowState win = token.windows.get(i);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003780 if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003781 mWindows.remove(win);
3782 int j = win.mChildWindows.size();
3783 while (j > 0) {
3784 j--;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003785 WindowState cwin = (WindowState)win.mChildWindows.get(j);
3786 if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG,
3787 "Tmp removing child window " + cwin);
3788 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003789 }
3790 }
3791 return NW > 0;
3792 }
3793
3794 void dumpAppTokensLocked() {
3795 for (int i=mAppTokens.size()-1; i>=0; i--) {
3796 Log.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
3797 }
3798 }
Romain Guy06882f82009-06-10 13:36:04 -07003799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003800 void dumpWindowsLocked() {
3801 for (int i=mWindows.size()-1; i>=0; i--) {
3802 Log.v(TAG, " #" + i + ": " + mWindows.get(i));
3803 }
3804 }
Romain Guy06882f82009-06-10 13:36:04 -07003805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 private int findWindowOffsetLocked(int tokenPos) {
3807 final int NW = mWindows.size();
3808
3809 if (tokenPos >= mAppTokens.size()) {
3810 int i = NW;
3811 while (i > 0) {
3812 i--;
3813 WindowState win = (WindowState)mWindows.get(i);
3814 if (win.getAppToken() != null) {
3815 return i+1;
3816 }
3817 }
3818 }
3819
3820 while (tokenPos > 0) {
3821 // Find the first app token below the new position that has
3822 // a window displayed.
3823 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
3824 if (DEBUG_REORDER) Log.v(TAG, "Looking for lower windows @ "
3825 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003826 if (wtoken.sendingToBottom) {
3827 if (DEBUG_REORDER) Log.v(TAG,
3828 "Skipping token -- currently sending to bottom");
3829 tokenPos--;
3830 continue;
3831 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003832 int i = wtoken.windows.size();
3833 while (i > 0) {
3834 i--;
3835 WindowState win = wtoken.windows.get(i);
3836 int j = win.mChildWindows.size();
3837 while (j > 0) {
3838 j--;
3839 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003840 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003841 for (int pos=NW-1; pos>=0; pos--) {
3842 if (mWindows.get(pos) == cwin) {
3843 if (DEBUG_REORDER) Log.v(TAG,
3844 "Found child win @" + (pos+1));
3845 return pos+1;
3846 }
3847 }
3848 }
3849 }
3850 for (int pos=NW-1; pos>=0; pos--) {
3851 if (mWindows.get(pos) == win) {
3852 if (DEBUG_REORDER) Log.v(TAG, "Found win @" + (pos+1));
3853 return pos+1;
3854 }
3855 }
3856 }
3857 tokenPos--;
3858 }
3859
3860 return 0;
3861 }
3862
3863 private final int reAddWindowLocked(int index, WindowState win) {
3864 final int NCW = win.mChildWindows.size();
3865 boolean added = false;
3866 for (int j=0; j<NCW; j++) {
3867 WindowState cwin = (WindowState)win.mChildWindows.get(j);
3868 if (!added && cwin.mSubLayer >= 0) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003869 if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Re-adding child window at "
3870 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003871 mWindows.add(index, win);
3872 index++;
3873 added = true;
3874 }
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003875 if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Re-adding window at "
3876 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003877 mWindows.add(index, cwin);
3878 index++;
3879 }
3880 if (!added) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003881 if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Re-adding window at "
3882 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003883 mWindows.add(index, win);
3884 index++;
3885 }
3886 return index;
3887 }
Romain Guy06882f82009-06-10 13:36:04 -07003888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003889 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3890 final int NW = token.windows.size();
3891 for (int i=0; i<NW; i++) {
3892 index = reAddWindowLocked(index, token.windows.get(i));
3893 }
3894 return index;
3895 }
3896
3897 public void moveAppToken(int index, IBinder token) {
3898 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3899 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003900 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003901 }
3902
3903 synchronized(mWindowMap) {
3904 if (DEBUG_REORDER) Log.v(TAG, "Initial app tokens:");
3905 if (DEBUG_REORDER) dumpAppTokensLocked();
3906 final AppWindowToken wtoken = findAppWindowToken(token);
3907 if (wtoken == null || !mAppTokens.remove(wtoken)) {
3908 Log.w(TAG, "Attempting to reorder token that doesn't exist: "
3909 + token + " (" + wtoken + ")");
3910 return;
3911 }
3912 mAppTokens.add(index, wtoken);
3913 if (DEBUG_REORDER) Log.v(TAG, "Moved " + token + " to " + index + ":");
3914 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003916 final long origId = Binder.clearCallingIdentity();
3917 if (DEBUG_REORDER) Log.v(TAG, "Removing windows in " + token + ":");
3918 if (DEBUG_REORDER) dumpWindowsLocked();
3919 if (tmpRemoveAppWindowsLocked(wtoken)) {
3920 if (DEBUG_REORDER) Log.v(TAG, "Adding windows back in:");
3921 if (DEBUG_REORDER) dumpWindowsLocked();
3922 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
3923 if (DEBUG_REORDER) Log.v(TAG, "Final window list:");
3924 if (DEBUG_REORDER) dumpWindowsLocked();
3925 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003926 mLayoutNeeded = true;
3927 performLayoutAndPlaceSurfacesLocked();
3928 }
3929 Binder.restoreCallingIdentity(origId);
3930 }
3931 }
3932
3933 private void removeAppTokensLocked(List<IBinder> tokens) {
3934 // XXX This should be done more efficiently!
3935 // (take advantage of the fact that both lists should be
3936 // ordered in the same way.)
3937 int N = tokens.size();
3938 for (int i=0; i<N; i++) {
3939 IBinder token = tokens.get(i);
3940 final AppWindowToken wtoken = findAppWindowToken(token);
3941 if (!mAppTokens.remove(wtoken)) {
3942 Log.w(TAG, "Attempting to reorder token that doesn't exist: "
3943 + token + " (" + wtoken + ")");
3944 i--;
3945 N--;
3946 }
3947 }
3948 }
3949
Dianne Hackborna8f60182009-09-01 19:01:50 -07003950 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
3951 boolean updateFocusAndLayout) {
3952 // First remove all of the windows from the list.
3953 tmpRemoveAppWindowsLocked(wtoken);
3954
3955 // Where to start adding?
3956 int pos = findWindowOffsetLocked(tokenPos);
3957
3958 // And now add them back at the correct place.
3959 pos = reAddAppWindowsLocked(pos, wtoken);
3960
3961 if (updateFocusAndLayout) {
3962 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
3963 assignLayersLocked();
3964 }
3965 mLayoutNeeded = true;
3966 performLayoutAndPlaceSurfacesLocked();
3967 }
3968 }
3969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003970 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
3971 // First remove all of the windows from the list.
3972 final int N = tokens.size();
3973 int i;
3974 for (i=0; i<N; i++) {
3975 WindowToken token = mTokenMap.get(tokens.get(i));
3976 if (token != null) {
3977 tmpRemoveAppWindowsLocked(token);
3978 }
3979 }
3980
3981 // Where to start adding?
3982 int pos = findWindowOffsetLocked(tokenPos);
3983
3984 // And now add them back at the correct place.
3985 for (i=0; i<N; i++) {
3986 WindowToken token = mTokenMap.get(tokens.get(i));
3987 if (token != null) {
3988 pos = reAddAppWindowsLocked(pos, token);
3989 }
3990 }
3991
Dianne Hackborna8f60182009-09-01 19:01:50 -07003992 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
3993 assignLayersLocked();
3994 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003995 mLayoutNeeded = true;
3996 performLayoutAndPlaceSurfacesLocked();
3997
3998 //dump();
3999 }
4000
4001 public void moveAppTokensToTop(List<IBinder> tokens) {
4002 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4003 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004004 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004005 }
4006
4007 final long origId = Binder.clearCallingIdentity();
4008 synchronized(mWindowMap) {
4009 removeAppTokensLocked(tokens);
4010 final int N = tokens.size();
4011 for (int i=0; i<N; i++) {
4012 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4013 if (wt != null) {
4014 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004015 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004016 mToTopApps.remove(wt);
4017 mToBottomApps.remove(wt);
4018 mToTopApps.add(wt);
4019 wt.sendingToBottom = false;
4020 wt.sendingToTop = true;
4021 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004022 }
4023 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004024
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004025 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004026 moveAppWindowsLocked(tokens, mAppTokens.size());
4027 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004028 }
4029 Binder.restoreCallingIdentity(origId);
4030 }
4031
4032 public void moveAppTokensToBottom(List<IBinder> tokens) {
4033 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4034 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004035 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004036 }
4037
4038 final long origId = Binder.clearCallingIdentity();
4039 synchronized(mWindowMap) {
4040 removeAppTokensLocked(tokens);
4041 final int N = tokens.size();
4042 int pos = 0;
4043 for (int i=0; i<N; i++) {
4044 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4045 if (wt != null) {
4046 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004047 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004048 mToTopApps.remove(wt);
4049 mToBottomApps.remove(wt);
4050 mToBottomApps.add(i, wt);
4051 wt.sendingToTop = false;
4052 wt.sendingToBottom = true;
4053 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004054 pos++;
4055 }
4056 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004057
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004058 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004059 moveAppWindowsLocked(tokens, 0);
4060 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004061 }
4062 Binder.restoreCallingIdentity(origId);
4063 }
4064
4065 // -------------------------------------------------------------
4066 // Misc IWindowSession methods
4067 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004069 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004070 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004071 != PackageManager.PERMISSION_GRANTED) {
4072 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4073 }
Mike Lockwood983ee092009-11-22 01:42:24 -05004074 synchronized (mKeyguardTokenWatcher) {
4075 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004076 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004077 }
4078
4079 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004080 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004081 != PackageManager.PERMISSION_GRANTED) {
4082 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4083 }
Mike Lockwood983ee092009-11-22 01:42:24 -05004084 synchronized (mKeyguardTokenWatcher) {
4085 mKeyguardTokenWatcher.release(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004086
Mike Lockwood983ee092009-11-22 01:42:24 -05004087 if (!mKeyguardTokenWatcher.isAcquired()) {
4088 // If we are the last one to reenable the keyguard wait until
4089 // we have actaully finished reenabling until returning.
4090 // It is possible that reenableKeyguard() can be called before
4091 // the previous disableKeyguard() is handled, in which case
4092 // neither mKeyguardTokenWatcher.acquired() or released() would
4093 // be called. In that case mKeyguardDisabled will be false here
4094 // and we have nothing to wait for.
4095 while (mKeyguardDisabled) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004096 try {
Mike Lockwood983ee092009-11-22 01:42:24 -05004097 mKeyguardTokenWatcher.wait();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004098 } catch (InterruptedException e) {
4099 Thread.currentThread().interrupt();
4100 }
4101 }
4102 }
4103 }
4104 }
4105
4106 /**
4107 * @see android.app.KeyguardManager#exitKeyguardSecurely
4108 */
4109 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004110 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004111 != PackageManager.PERMISSION_GRANTED) {
4112 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4113 }
4114 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4115 public void onKeyguardExitResult(boolean success) {
4116 try {
4117 callback.onKeyguardExitResult(success);
4118 } catch (RemoteException e) {
4119 // Client has died, we don't care.
4120 }
4121 }
4122 });
4123 }
4124
4125 public boolean inKeyguardRestrictedInputMode() {
4126 return mPolicy.inKeyguardRestrictedKeyInputMode();
4127 }
Romain Guy06882f82009-06-10 13:36:04 -07004128
Dianne Hackbornffa42482009-09-23 22:20:11 -07004129 public void closeSystemDialogs(String reason) {
4130 synchronized(mWindowMap) {
4131 for (int i=mWindows.size()-1; i>=0; i--) {
4132 WindowState w = (WindowState)mWindows.get(i);
4133 if (w.mSurface != null) {
4134 try {
4135 w.mClient.closeSystemDialogs(reason);
4136 } catch (RemoteException e) {
4137 }
4138 }
4139 }
4140 }
4141 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004143 static float fixScale(float scale) {
4144 if (scale < 0) scale = 0;
4145 else if (scale > 20) scale = 20;
4146 return Math.abs(scale);
4147 }
Romain Guy06882f82009-06-10 13:36:04 -07004148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004149 public void setAnimationScale(int which, float scale) {
4150 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4151 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004152 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004153 }
4154
4155 if (scale < 0) scale = 0;
4156 else if (scale > 20) scale = 20;
4157 scale = Math.abs(scale);
4158 switch (which) {
4159 case 0: mWindowAnimationScale = fixScale(scale); break;
4160 case 1: mTransitionAnimationScale = fixScale(scale); break;
4161 }
Romain Guy06882f82009-06-10 13:36:04 -07004162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004163 // Persist setting
4164 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4165 }
Romain Guy06882f82009-06-10 13:36:04 -07004166
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004167 public void setAnimationScales(float[] scales) {
4168 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4169 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004170 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004171 }
4172
4173 if (scales != null) {
4174 if (scales.length >= 1) {
4175 mWindowAnimationScale = fixScale(scales[0]);
4176 }
4177 if (scales.length >= 2) {
4178 mTransitionAnimationScale = fixScale(scales[1]);
4179 }
4180 }
Romain Guy06882f82009-06-10 13:36:04 -07004181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004182 // Persist setting
4183 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4184 }
Romain Guy06882f82009-06-10 13:36:04 -07004185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004186 public float getAnimationScale(int which) {
4187 switch (which) {
4188 case 0: return mWindowAnimationScale;
4189 case 1: return mTransitionAnimationScale;
4190 }
4191 return 0;
4192 }
Romain Guy06882f82009-06-10 13:36:04 -07004193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004194 public float[] getAnimationScales() {
4195 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4196 }
Romain Guy06882f82009-06-10 13:36:04 -07004197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004198 public int getSwitchState(int sw) {
4199 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4200 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004201 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004202 }
4203 return KeyInputQueue.getSwitchState(sw);
4204 }
Romain Guy06882f82009-06-10 13:36:04 -07004205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004206 public int getSwitchStateForDevice(int devid, int sw) {
4207 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4208 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004209 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004210 }
4211 return KeyInputQueue.getSwitchState(devid, sw);
4212 }
Romain Guy06882f82009-06-10 13:36:04 -07004213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004214 public int getScancodeState(int sw) {
4215 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4216 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004217 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004218 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004219 return mQueue.getScancodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004220 }
Romain Guy06882f82009-06-10 13:36:04 -07004221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004222 public int getScancodeStateForDevice(int devid, int sw) {
4223 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4224 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004225 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004226 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004227 return mQueue.getScancodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004228 }
Romain Guy06882f82009-06-10 13:36:04 -07004229
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004230 public int getTrackballScancodeState(int sw) {
4231 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4232 "getTrackballScancodeState()")) {
4233 throw new SecurityException("Requires READ_INPUT_STATE permission");
4234 }
4235 return mQueue.getTrackballScancodeState(sw);
4236 }
4237
4238 public int getDPadScancodeState(int sw) {
4239 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4240 "getDPadScancodeState()")) {
4241 throw new SecurityException("Requires READ_INPUT_STATE permission");
4242 }
4243 return mQueue.getDPadScancodeState(sw);
4244 }
4245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004246 public int getKeycodeState(int sw) {
4247 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4248 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004249 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004250 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004251 return mQueue.getKeycodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004252 }
Romain Guy06882f82009-06-10 13:36:04 -07004253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004254 public int getKeycodeStateForDevice(int devid, int sw) {
4255 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4256 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004257 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004258 }
Dianne Hackborn6af0d502009-09-28 13:25:46 -07004259 return mQueue.getKeycodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004260 }
Romain Guy06882f82009-06-10 13:36:04 -07004261
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004262 public int getTrackballKeycodeState(int sw) {
4263 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4264 "getTrackballKeycodeState()")) {
4265 throw new SecurityException("Requires READ_INPUT_STATE permission");
4266 }
4267 return mQueue.getTrackballKeycodeState(sw);
4268 }
4269
4270 public int getDPadKeycodeState(int sw) {
4271 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4272 "getDPadKeycodeState()")) {
4273 throw new SecurityException("Requires READ_INPUT_STATE permission");
4274 }
4275 return mQueue.getDPadKeycodeState(sw);
4276 }
4277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004278 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
4279 return KeyInputQueue.hasKeys(keycodes, keyExists);
4280 }
Romain Guy06882f82009-06-10 13:36:04 -07004281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004282 public void enableScreenAfterBoot() {
4283 synchronized(mWindowMap) {
4284 if (mSystemBooted) {
4285 return;
4286 }
4287 mSystemBooted = true;
4288 }
Romain Guy06882f82009-06-10 13:36:04 -07004289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004290 performEnableScreen();
4291 }
Romain Guy06882f82009-06-10 13:36:04 -07004292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004293 public void enableScreenIfNeededLocked() {
4294 if (mDisplayEnabled) {
4295 return;
4296 }
4297 if (!mSystemBooted) {
4298 return;
4299 }
4300 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4301 }
Romain Guy06882f82009-06-10 13:36:04 -07004302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004303 public void performEnableScreen() {
4304 synchronized(mWindowMap) {
4305 if (mDisplayEnabled) {
4306 return;
4307 }
4308 if (!mSystemBooted) {
4309 return;
4310 }
Romain Guy06882f82009-06-10 13:36:04 -07004311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004312 // Don't enable the screen until all existing windows
4313 // have been drawn.
4314 final int N = mWindows.size();
4315 for (int i=0; i<N; i++) {
4316 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004317 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004318 return;
4319 }
4320 }
Romain Guy06882f82009-06-10 13:36:04 -07004321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004322 mDisplayEnabled = true;
4323 if (false) {
4324 Log.i(TAG, "ENABLING SCREEN!");
4325 StringWriter sw = new StringWriter();
4326 PrintWriter pw = new PrintWriter(sw);
4327 this.dump(null, pw, null);
4328 Log.i(TAG, sw.toString());
4329 }
4330 try {
4331 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4332 if (surfaceFlinger != null) {
4333 //Log.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
4334 Parcel data = Parcel.obtain();
4335 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4336 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4337 data, null, 0);
4338 data.recycle();
4339 }
4340 } catch (RemoteException ex) {
4341 Log.e(TAG, "Boot completed: SurfaceFlinger is dead!");
4342 }
4343 }
Romain Guy06882f82009-06-10 13:36:04 -07004344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004345 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004347 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004348 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4349 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004350 }
Romain Guy06882f82009-06-10 13:36:04 -07004351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004352 public void setInTouchMode(boolean mode) {
4353 synchronized(mWindowMap) {
4354 mInTouchMode = mode;
4355 }
4356 }
4357
Romain Guy06882f82009-06-10 13:36:04 -07004358 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004359 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004360 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004361 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004362 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004363 }
4364
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004365 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004366 }
Romain Guy06882f82009-06-10 13:36:04 -07004367
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004368 public void setRotationUnchecked(int rotation,
4369 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004370 if(DEBUG_ORIENTATION) Log.v(TAG,
4371 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004373 long origId = Binder.clearCallingIdentity();
4374 boolean changed;
4375 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004376 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004377 }
Romain Guy06882f82009-06-10 13:36:04 -07004378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004379 if (changed) {
4380 sendNewConfiguration();
4381 synchronized(mWindowMap) {
4382 mLayoutNeeded = true;
4383 performLayoutAndPlaceSurfacesLocked();
4384 }
4385 } else if (alwaysSendConfiguration) {
4386 //update configuration ignoring orientation change
4387 sendNewConfiguration();
4388 }
Romain Guy06882f82009-06-10 13:36:04 -07004389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004390 Binder.restoreCallingIdentity(origId);
4391 }
Romain Guy06882f82009-06-10 13:36:04 -07004392
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004393 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004394 boolean changed;
4395 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4396 rotation = mRequestedRotation;
4397 } else {
4398 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004399 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004400 }
4401 if (DEBUG_ORIENTATION) Log.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004402 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004403 mRotation, mDisplayEnabled);
4404 if (DEBUG_ORIENTATION) Log.v(TAG, "new rotation is set to " + rotation);
4405 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004407 if (changed) {
Romain Guy06882f82009-06-10 13:36:04 -07004408 if (DEBUG_ORIENTATION) Log.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004409 "Rotation changed to " + rotation
4410 + " from " + mRotation
4411 + " (forceApp=" + mForcedAppOrientation
4412 + ", req=" + mRequestedRotation + ")");
4413 mRotation = rotation;
4414 mWindowsFreezingScreen = true;
4415 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4416 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4417 2000);
4418 startFreezingDisplayLocked();
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004419 Log.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004420 mQueue.setOrientation(rotation);
4421 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004422 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004423 }
4424 for (int i=mWindows.size()-1; i>=0; i--) {
4425 WindowState w = (WindowState)mWindows.get(i);
4426 if (w.mSurface != null) {
4427 w.mOrientationChanging = true;
4428 }
4429 }
4430 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4431 try {
4432 mRotationWatchers.get(i).onRotationChanged(rotation);
4433 } catch (RemoteException e) {
4434 }
4435 }
4436 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004438 return changed;
4439 }
Romain Guy06882f82009-06-10 13:36:04 -07004440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004441 public int getRotation() {
4442 return mRotation;
4443 }
4444
4445 public int watchRotation(IRotationWatcher watcher) {
4446 final IBinder watcherBinder = watcher.asBinder();
4447 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4448 public void binderDied() {
4449 synchronized (mWindowMap) {
4450 for (int i=0; i<mRotationWatchers.size(); i++) {
4451 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004452 IRotationWatcher removed = mRotationWatchers.remove(i);
4453 if (removed != null) {
4454 removed.asBinder().unlinkToDeath(this, 0);
4455 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004456 i--;
4457 }
4458 }
4459 }
4460 }
4461 };
Romain Guy06882f82009-06-10 13:36:04 -07004462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004463 synchronized (mWindowMap) {
4464 try {
4465 watcher.asBinder().linkToDeath(dr, 0);
4466 mRotationWatchers.add(watcher);
4467 } catch (RemoteException e) {
4468 // Client died, no cleanup needed.
4469 }
Romain Guy06882f82009-06-10 13:36:04 -07004470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004471 return mRotation;
4472 }
4473 }
4474
4475 /**
4476 * Starts the view server on the specified port.
4477 *
4478 * @param port The port to listener to.
4479 *
4480 * @return True if the server was successfully started, false otherwise.
4481 *
4482 * @see com.android.server.ViewServer
4483 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4484 */
4485 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004486 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004487 return false;
4488 }
4489
4490 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4491 return false;
4492 }
4493
4494 if (port < 1024) {
4495 return false;
4496 }
4497
4498 if (mViewServer != null) {
4499 if (!mViewServer.isRunning()) {
4500 try {
4501 return mViewServer.start();
4502 } catch (IOException e) {
Romain Guy06882f82009-06-10 13:36:04 -07004503 Log.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004504 }
4505 }
4506 return false;
4507 }
4508
4509 try {
4510 mViewServer = new ViewServer(this, port);
4511 return mViewServer.start();
4512 } catch (IOException e) {
4513 Log.w(TAG, "View server did not start");
4514 }
4515 return false;
4516 }
4517
Romain Guy06882f82009-06-10 13:36:04 -07004518 private boolean isSystemSecure() {
4519 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4520 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4521 }
4522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004523 /**
4524 * Stops the view server if it exists.
4525 *
4526 * @return True if the server stopped, false if it wasn't started or
4527 * couldn't be stopped.
4528 *
4529 * @see com.android.server.ViewServer
4530 */
4531 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004532 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004533 return false;
4534 }
4535
4536 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4537 return false;
4538 }
4539
4540 if (mViewServer != null) {
4541 return mViewServer.stop();
4542 }
4543 return false;
4544 }
4545
4546 /**
4547 * Indicates whether the view server is running.
4548 *
4549 * @return True if the server is running, false otherwise.
4550 *
4551 * @see com.android.server.ViewServer
4552 */
4553 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004554 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004555 return false;
4556 }
4557
4558 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4559 return false;
4560 }
4561
4562 return mViewServer != null && mViewServer.isRunning();
4563 }
4564
4565 /**
4566 * Lists all availble windows in the system. The listing is written in the
4567 * specified Socket's output stream with the following syntax:
4568 * windowHashCodeInHexadecimal windowName
4569 * Each line of the ouput represents a different window.
4570 *
4571 * @param client The remote client to send the listing to.
4572 * @return False if an error occured, true otherwise.
4573 */
4574 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004575 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004576 return false;
4577 }
4578
4579 boolean result = true;
4580
4581 Object[] windows;
4582 synchronized (mWindowMap) {
4583 windows = new Object[mWindows.size()];
4584 //noinspection unchecked
4585 windows = mWindows.toArray(windows);
4586 }
4587
4588 BufferedWriter out = null;
4589
4590 // Any uncaught exception will crash the system process
4591 try {
4592 OutputStream clientStream = client.getOutputStream();
4593 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4594
4595 final int count = windows.length;
4596 for (int i = 0; i < count; i++) {
4597 final WindowState w = (WindowState) windows[i];
4598 out.write(Integer.toHexString(System.identityHashCode(w)));
4599 out.write(' ');
4600 out.append(w.mAttrs.getTitle());
4601 out.write('\n');
4602 }
4603
4604 out.write("DONE.\n");
4605 out.flush();
4606 } catch (Exception e) {
4607 result = false;
4608 } finally {
4609 if (out != null) {
4610 try {
4611 out.close();
4612 } catch (IOException e) {
4613 result = false;
4614 }
4615 }
4616 }
4617
4618 return result;
4619 }
4620
4621 /**
4622 * Sends a command to a target window. The result of the command, if any, will be
4623 * written in the output stream of the specified socket.
4624 *
4625 * The parameters must follow this syntax:
4626 * windowHashcode extra
4627 *
4628 * Where XX is the length in characeters of the windowTitle.
4629 *
4630 * The first parameter is the target window. The window with the specified hashcode
4631 * will be the target. If no target can be found, nothing happens. The extra parameters
4632 * will be delivered to the target window and as parameters to the command itself.
4633 *
4634 * @param client The remote client to sent the result, if any, to.
4635 * @param command The command to execute.
4636 * @param parameters The command parameters.
4637 *
4638 * @return True if the command was successfully delivered, false otherwise. This does
4639 * not indicate whether the command itself was successful.
4640 */
4641 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004642 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004643 return false;
4644 }
4645
4646 boolean success = true;
4647 Parcel data = null;
4648 Parcel reply = null;
4649
4650 // Any uncaught exception will crash the system process
4651 try {
4652 // Find the hashcode of the window
4653 int index = parameters.indexOf(' ');
4654 if (index == -1) {
4655 index = parameters.length();
4656 }
4657 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004658 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004659
4660 // Extract the command's parameter after the window description
4661 if (index < parameters.length()) {
4662 parameters = parameters.substring(index + 1);
4663 } else {
4664 parameters = "";
4665 }
4666
4667 final WindowManagerService.WindowState window = findWindow(hashCode);
4668 if (window == null) {
4669 return false;
4670 }
4671
4672 data = Parcel.obtain();
4673 data.writeInterfaceToken("android.view.IWindow");
4674 data.writeString(command);
4675 data.writeString(parameters);
4676 data.writeInt(1);
4677 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4678
4679 reply = Parcel.obtain();
4680
4681 final IBinder binder = window.mClient.asBinder();
4682 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4683 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4684
4685 reply.readException();
4686
4687 } catch (Exception e) {
4688 Log.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
4689 success = false;
4690 } finally {
4691 if (data != null) {
4692 data.recycle();
4693 }
4694 if (reply != null) {
4695 reply.recycle();
4696 }
4697 }
4698
4699 return success;
4700 }
4701
4702 private WindowState findWindow(int hashCode) {
4703 if (hashCode == -1) {
4704 return getFocusedWindow();
4705 }
4706
4707 synchronized (mWindowMap) {
4708 final ArrayList windows = mWindows;
4709 final int count = windows.size();
4710
4711 for (int i = 0; i < count; i++) {
4712 WindowState w = (WindowState) windows.get(i);
4713 if (System.identityHashCode(w) == hashCode) {
4714 return w;
4715 }
4716 }
4717 }
4718
4719 return null;
4720 }
4721
4722 /*
4723 * Instruct the Activity Manager to fetch the current configuration and broadcast
4724 * that to config-changed listeners if appropriate.
4725 */
4726 void sendNewConfiguration() {
4727 try {
4728 mActivityManager.updateConfiguration(null);
4729 } catch (RemoteException e) {
4730 }
4731 }
Romain Guy06882f82009-06-10 13:36:04 -07004732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004733 public Configuration computeNewConfiguration() {
4734 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004735 return computeNewConfigurationLocked();
4736 }
4737 }
Romain Guy06882f82009-06-10 13:36:04 -07004738
Dianne Hackbornc485a602009-03-24 22:39:49 -07004739 Configuration computeNewConfigurationLocked() {
4740 Configuration config = new Configuration();
4741 if (!computeNewConfigurationLocked(config)) {
4742 return null;
4743 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004744 return config;
4745 }
Romain Guy06882f82009-06-10 13:36:04 -07004746
Dianne Hackbornc485a602009-03-24 22:39:49 -07004747 boolean computeNewConfigurationLocked(Configuration config) {
4748 if (mDisplay == null) {
4749 return false;
4750 }
4751 mQueue.getInputConfiguration(config);
4752 final int dw = mDisplay.getWidth();
4753 final int dh = mDisplay.getHeight();
4754 int orientation = Configuration.ORIENTATION_SQUARE;
4755 if (dw < dh) {
4756 orientation = Configuration.ORIENTATION_PORTRAIT;
4757 } else if (dw > dh) {
4758 orientation = Configuration.ORIENTATION_LANDSCAPE;
4759 }
4760 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004761
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004762 DisplayMetrics dm = new DisplayMetrics();
4763 mDisplay.getMetrics(dm);
4764 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4765
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004766 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004767 // Note we only do this once because at this point we don't
4768 // expect the screen to change in this way at runtime, and want
4769 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004770 int longSize = dw;
4771 int shortSize = dh;
4772 if (longSize < shortSize) {
4773 int tmp = longSize;
4774 longSize = shortSize;
4775 shortSize = tmp;
4776 }
4777 longSize = (int)(longSize/dm.density);
4778 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004779
Dianne Hackborn723738c2009-06-25 19:48:04 -07004780 // These semi-magic numbers define our compatibility modes for
4781 // applications with different screens. Don't change unless you
4782 // make sure to test lots and lots of apps!
4783 if (longSize < 470) {
4784 // This is shorter than an HVGA normal density screen (which
4785 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004786 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
4787 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07004788 } else {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004789 // Is this a large screen?
4790 if (longSize > 640 && shortSize >= 480) {
4791 // VGA or larger screens at medium density are the point
4792 // at which we consider it to be a large screen.
4793 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
4794 } else {
4795 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004796
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004797 // If this screen is wider than normal HVGA, or taller
4798 // than FWVGA, then for old apps we want to run in size
4799 // compatibility mode.
4800 if (shortSize > 321 || longSize > 570) {
4801 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
4802 }
4803 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004804
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004805 // Is this a long screen?
4806 if (((longSize*3)/5) >= (shortSize-1)) {
4807 // Anything wider than WVGA (5:3) is considering to be long.
4808 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
4809 } else {
4810 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
4811 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07004812 }
4813 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004814 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004815
Dianne Hackbornc485a602009-03-24 22:39:49 -07004816 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
4817 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
4818 mPolicy.adjustConfigurationLw(config);
4819 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004820 }
Romain Guy06882f82009-06-10 13:36:04 -07004821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004822 // -------------------------------------------------------------
4823 // Input Events and Focus Management
4824 // -------------------------------------------------------------
4825
4826 private final void wakeupIfNeeded(WindowState targetWin, int eventType) {
Michael Chane96440f2009-05-06 10:27:36 -07004827 long curTime = SystemClock.uptimeMillis();
4828
Michael Chane10de972009-05-18 11:24:50 -07004829 if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) {
Michael Chane96440f2009-05-06 10:27:36 -07004830 if (mLastTouchEventType == eventType &&
4831 (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) {
4832 return;
4833 }
4834 mLastUserActivityCallTime = curTime;
4835 mLastTouchEventType = eventType;
4836 }
4837
4838 if (targetWin == null
4839 || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) {
4840 mPowerManager.userActivity(curTime, false, eventType, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004841 }
4842 }
4843
4844 // tells if it's a cheek event or not -- this function is stateful
4845 private static final int EVENT_NONE = 0;
4846 private static final int EVENT_UNKNOWN = 0;
4847 private static final int EVENT_CHEEK = 0;
4848 private static final int EVENT_IGNORE_DURATION = 300; // ms
4849 private static final float CHEEK_THRESHOLD = 0.6f;
4850 private int mEventState = EVENT_NONE;
4851 private float mEventSize;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004853 private int eventType(MotionEvent ev) {
4854 float size = ev.getSize();
4855 switch (ev.getAction()) {
4856 case MotionEvent.ACTION_DOWN:
4857 mEventSize = size;
4858 return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT;
4859 case MotionEvent.ACTION_UP:
4860 if (size > mEventSize) mEventSize = size;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004861 return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004862 case MotionEvent.ACTION_MOVE:
4863 final int N = ev.getHistorySize();
4864 if (size > mEventSize) mEventSize = size;
4865 if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT;
4866 for (int i=0; i<N; i++) {
4867 size = ev.getHistoricalSize(i);
4868 if (size > mEventSize) mEventSize = size;
4869 if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT;
4870 }
4871 if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) {
4872 return TOUCH_EVENT;
4873 } else {
Joe Onoratoe68ffcb2009-03-24 19:11:13 -07004874 return LONG_TOUCH_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004875 }
4876 default:
4877 // not good
4878 return OTHER_EVENT;
4879 }
4880 }
4881
4882 /**
4883 * @return Returns true if event was dispatched, false if it was dropped for any reason
4884 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07004885 private int dispatchPointer(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004886 if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Log.v(TAG,
4887 "dispatchPointer " + ev);
4888
Michael Chan53071d62009-05-13 17:29:48 -07004889 if (MEASURE_LATENCY) {
4890 lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano);
4891 }
4892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004893 Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07004894 ev, true, false, pid, uid);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004895
Michael Chan53071d62009-05-13 17:29:48 -07004896 if (MEASURE_LATENCY) {
4897 lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano);
4898 }
4899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004900 int action = ev.getAction();
Romain Guy06882f82009-06-10 13:36:04 -07004901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004902 if (action == MotionEvent.ACTION_UP) {
4903 // let go of our target
4904 mKeyWaiter.mMotionTarget = null;
4905 mPowerManager.logPointerUpEvent();
4906 } else if (action == MotionEvent.ACTION_DOWN) {
4907 mPowerManager.logPointerDownEvent();
4908 }
4909
4910 if (targetObj == null) {
4911 // In this case we are either dropping the event, or have received
4912 // a move or up without a down. It is common to receive move
4913 // events in such a way, since this means the user is moving the
4914 // pointer without actually pressing down. All other cases should
4915 // be atypical, so let's log them.
Michael Chane96440f2009-05-06 10:27:36 -07004916 if (action != MotionEvent.ACTION_MOVE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004917 Log.w(TAG, "No window to dispatch pointer action " + ev.getAction());
4918 }
Dianne Hackborn6adba242009-11-10 11:10:09 -08004919 synchronized (mWindowMap) {
4920 if (mSendingPointersToWallpaper) {
4921 Log.i(TAG, "Sending skipped pointer to wallpaper!");
4922 sendPointerToWallpaperLocked(null, ev, ev.getEventTime());
4923 }
4924 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004925 if (qev != null) {
4926 mQueue.recycleEvent(qev);
4927 }
4928 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07004929 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004930 }
4931 if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
Dianne Hackborn6adba242009-11-10 11:10:09 -08004932 synchronized (mWindowMap) {
4933 if (mSendingPointersToWallpaper) {
4934 Log.i(TAG, "Sending skipped pointer to wallpaper!");
4935 sendPointerToWallpaperLocked(null, ev, ev.getEventTime());
4936 }
4937 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004938 if (qev != null) {
4939 mQueue.recycleEvent(qev);
4940 }
4941 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07004942 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004943 }
Romain Guy06882f82009-06-10 13:36:04 -07004944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004945 WindowState target = (WindowState)targetObj;
Romain Guy06882f82009-06-10 13:36:04 -07004946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004947 final long eventTime = ev.getEventTime();
Michael Chan53071d62009-05-13 17:29:48 -07004948 final long eventTimeNano = ev.getEventTimeNano();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004950 //Log.i(TAG, "Sending " + ev + " to " + target);
4951
4952 if (uid != 0 && uid != target.mSession.mUid) {
4953 if (mContext.checkPermission(
4954 android.Manifest.permission.INJECT_EVENTS, pid, uid)
4955 != PackageManager.PERMISSION_GRANTED) {
4956 Log.w(TAG, "Permission denied: injecting pointer event from pid "
4957 + pid + " uid " + uid + " to window " + target
4958 + " owned by uid " + target.mSession.mUid);
4959 if (qev != null) {
4960 mQueue.recycleEvent(qev);
4961 }
4962 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07004963 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004964 }
4965 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004966
Michael Chan53071d62009-05-13 17:29:48 -07004967 if (MEASURE_LATENCY) {
4968 lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano);
4969 }
4970
Romain Guy06882f82009-06-10 13:36:04 -07004971 if ((target.mAttrs.flags &
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004972 WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) {
4973 //target wants to ignore fat touch events
4974 boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev);
4975 //explicit flag to return without processing event further
4976 boolean returnFlag = false;
4977 if((action == MotionEvent.ACTION_DOWN)) {
4978 mFatTouch = false;
4979 if(cheekPress) {
4980 mFatTouch = true;
4981 returnFlag = true;
4982 }
4983 } else {
4984 if(action == MotionEvent.ACTION_UP) {
4985 if(mFatTouch) {
4986 //earlier even was invalid doesnt matter if current up is cheekpress or not
4987 mFatTouch = false;
4988 returnFlag = true;
4989 } else if(cheekPress) {
4990 //cancel the earlier event
4991 ev.setAction(MotionEvent.ACTION_CANCEL);
4992 action = MotionEvent.ACTION_CANCEL;
4993 }
4994 } else if(action == MotionEvent.ACTION_MOVE) {
4995 if(mFatTouch) {
4996 //two cases here
4997 //an invalid down followed by 0 or moves(valid or invalid)
Romain Guy06882f82009-06-10 13:36:04 -07004998 //a valid down, invalid move, more moves. want to ignore till up
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004999 returnFlag = true;
5000 } else if(cheekPress) {
5001 //valid down followed by invalid moves
5002 //an invalid move have to cancel earlier action
5003 ev.setAction(MotionEvent.ACTION_CANCEL);
5004 action = MotionEvent.ACTION_CANCEL;
5005 if (DEBUG_INPUT) Log.v(TAG, "Sending cancel for invalid ACTION_MOVE");
5006 //note that the subsequent invalid moves will not get here
5007 mFatTouch = true;
5008 }
5009 }
5010 } //else if action
5011 if(returnFlag) {
5012 //recycle que, ev
5013 if (qev != null) {
5014 mQueue.recycleEvent(qev);
5015 }
5016 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005017 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005018 }
5019 } //end if target
Michael Chane96440f2009-05-06 10:27:36 -07005020
Michael Chan9f028e62009-08-04 17:37:46 -07005021 // Enable this for testing the "right" value
5022 if (false && action == MotionEvent.ACTION_DOWN) {
Michael Chane96440f2009-05-06 10:27:36 -07005023 int max_events_per_sec = 35;
5024 try {
5025 max_events_per_sec = Integer.parseInt(SystemProperties
5026 .get("windowsmgr.max_events_per_sec"));
5027 if (max_events_per_sec < 1) {
5028 max_events_per_sec = 35;
5029 }
5030 } catch (NumberFormatException e) {
5031 }
5032 mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec;
5033 }
5034
5035 /*
5036 * Throttle events to minimize CPU usage when there's a flood of events
5037 * e.g. constant contact with the screen
5038 */
5039 if (action == MotionEvent.ACTION_MOVE) {
5040 long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents;
5041 long now = SystemClock.uptimeMillis();
5042 if (now < nextEventTime) {
5043 try {
5044 Thread.sleep(nextEventTime - now);
5045 } catch (InterruptedException e) {
5046 }
5047 mLastTouchEventTime = nextEventTime;
5048 } else {
5049 mLastTouchEventTime = now;
5050 }
5051 }
5052
Michael Chan53071d62009-05-13 17:29:48 -07005053 if (MEASURE_LATENCY) {
5054 lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano);
5055 }
5056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005057 synchronized(mWindowMap) {
Dianne Hackborn6adba242009-11-10 11:10:09 -08005058 if (!target.isVisibleLw()) {
5059 // During this motion dispatch, the target window has become
5060 // invisible.
5061 if (mSendingPointersToWallpaper) {
5062 sendPointerToWallpaperLocked(null, ev, eventTime);
5063 }
5064 if (qev != null) {
5065 mQueue.recycleEvent(qev);
5066 }
5067 ev.recycle();
5068 return INJECT_SUCCEEDED;
5069 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005071 if (qev != null && action == MotionEvent.ACTION_MOVE) {
5072 mKeyWaiter.bindTargetWindowLocked(target,
5073 KeyWaiter.RETURN_PENDING_POINTER, qev);
5074 ev = null;
5075 } else {
5076 if (action == MotionEvent.ACTION_DOWN) {
5077 WindowState out = mKeyWaiter.mOutsideTouchTargets;
5078 if (out != null) {
5079 MotionEvent oev = MotionEvent.obtain(ev);
5080 oev.setAction(MotionEvent.ACTION_OUTSIDE);
5081 do {
5082 final Rect frame = out.mFrame;
5083 oev.offsetLocation(-(float)frame.left, -(float)frame.top);
5084 try {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005085 out.mClient.dispatchPointer(oev, eventTime, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005086 } catch (android.os.RemoteException e) {
5087 Log.i(TAG, "WINDOW DIED during outside motion dispatch: " + out);
5088 }
5089 oev.offsetLocation((float)frame.left, (float)frame.top);
5090 out = out.mNextOutsideTouch;
5091 } while (out != null);
5092 mKeyWaiter.mOutsideTouchTargets = null;
5093 }
5094 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005095
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005096 // If we are on top of the wallpaper, then the wallpaper also
5097 // gets to see this movement.
Dianne Hackborn9b52a212009-12-11 14:51:35 -08005098 if ((mWallpaperTarget == target &&
5099 target.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD)
5100 || mSendingPointersToWallpaper) {
Dianne Hackborn6adba242009-11-10 11:10:09 -08005101 sendPointerToWallpaperLocked(null, ev, eventTime);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005102 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005103
Dianne Hackborn6adba242009-11-10 11:10:09 -08005104 final Rect frame = target.mFrame;
5105 ev.offsetLocation(-(float)frame.left, -(float)frame.top);
5106 mKeyWaiter.bindTargetWindowLocked(target);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005107 }
5108 }
Romain Guy06882f82009-06-10 13:36:04 -07005109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005110 // finally offset the event to the target's coordinate system and
5111 // dispatch the event.
5112 try {
5113 if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) {
5114 Log.v(TAG, "Delivering pointer " + qev + " to " + target);
5115 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005116
Michael Chan53071d62009-05-13 17:29:48 -07005117 if (MEASURE_LATENCY) {
5118 lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano);
5119 }
5120
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005121 target.mClient.dispatchPointer(ev, eventTime, true);
Michael Chan53071d62009-05-13 17:29:48 -07005122
5123 if (MEASURE_LATENCY) {
5124 lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano);
5125 }
Dianne Hackborncfaef692009-06-15 14:24:44 -07005126 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005127 } catch (android.os.RemoteException e) {
5128 Log.i(TAG, "WINDOW DIED during motion dispatch: " + target);
5129 mKeyWaiter.mMotionTarget = null;
5130 try {
5131 removeWindow(target.mSession, target.mClient);
5132 } catch (java.util.NoSuchElementException ex) {
5133 // This will happen if the window has already been
5134 // removed.
5135 }
5136 }
Dianne Hackborncfaef692009-06-15 14:24:44 -07005137 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005138 }
Romain Guy06882f82009-06-10 13:36:04 -07005139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005140 /**
5141 * @return Returns true if event was dispatched, false if it was dropped for any reason
5142 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07005143 private int dispatchTrackball(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005144 if (DEBUG_INPUT) Log.v(
5145 TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">");
Romain Guy06882f82009-06-10 13:36:04 -07005146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005147 Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005148 ev, false, false, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005149 if (focusObj == null) {
5150 Log.w(TAG, "No focus window, dropping trackball: " + ev);
5151 if (qev != null) {
5152 mQueue.recycleEvent(qev);
5153 }
5154 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005155 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005156 }
5157 if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
5158 if (qev != null) {
5159 mQueue.recycleEvent(qev);
5160 }
5161 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005162 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005163 }
Romain Guy06882f82009-06-10 13:36:04 -07005164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005165 WindowState focus = (WindowState)focusObj;
Romain Guy06882f82009-06-10 13:36:04 -07005166
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005167 if (uid != 0 && uid != focus.mSession.mUid) {
5168 if (mContext.checkPermission(
5169 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5170 != PackageManager.PERMISSION_GRANTED) {
5171 Log.w(TAG, "Permission denied: injecting key event from pid "
5172 + pid + " uid " + uid + " to window " + focus
5173 + " owned by uid " + focus.mSession.mUid);
5174 if (qev != null) {
5175 mQueue.recycleEvent(qev);
5176 }
5177 ev.recycle();
Dianne Hackborncfaef692009-06-15 14:24:44 -07005178 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005179 }
5180 }
Romain Guy06882f82009-06-10 13:36:04 -07005181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005182 final long eventTime = ev.getEventTime();
Romain Guy06882f82009-06-10 13:36:04 -07005183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005184 synchronized(mWindowMap) {
5185 if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) {
5186 mKeyWaiter.bindTargetWindowLocked(focus,
5187 KeyWaiter.RETURN_PENDING_TRACKBALL, qev);
5188 // We don't deliver movement events to the client, we hold
5189 // them and wait for them to call back.
5190 ev = null;
5191 } else {
5192 mKeyWaiter.bindTargetWindowLocked(focus);
5193 }
5194 }
Romain Guy06882f82009-06-10 13:36:04 -07005195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005196 try {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005197 focus.mClient.dispatchTrackball(ev, eventTime, true);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005198 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005199 } catch (android.os.RemoteException e) {
5200 Log.i(TAG, "WINDOW DIED during key dispatch: " + focus);
5201 try {
5202 removeWindow(focus.mSession, focus.mClient);
5203 } catch (java.util.NoSuchElementException ex) {
5204 // This will happen if the window has already been
5205 // removed.
5206 }
5207 }
Romain Guy06882f82009-06-10 13:36:04 -07005208
Dianne Hackborncfaef692009-06-15 14:24:44 -07005209 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005210 }
Romain Guy06882f82009-06-10 13:36:04 -07005211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005212 /**
5213 * @return Returns true if event was dispatched, false if it was dropped for any reason
5214 */
Dianne Hackborncfaef692009-06-15 14:24:44 -07005215 private int dispatchKey(KeyEvent event, int pid, int uid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005216 if (DEBUG_INPUT) Log.v(TAG, "Dispatch key: " + event);
5217
5218 Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005219 null, false, false, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005220 if (focusObj == null) {
5221 Log.w(TAG, "No focus window, dropping: " + event);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005222 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005223 }
5224 if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005225 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005226 }
Romain Guy06882f82009-06-10 13:36:04 -07005227
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07005228 // Okay we have finished waiting for the last event to be processed.
5229 // First off, if this is a repeat event, check to see if there is
5230 // a corresponding up event in the queue. If there is, we will
5231 // just drop the repeat, because it makes no sense to repeat after
5232 // the user has released a key. (This is especially important for
5233 // long presses.)
5234 if (event.getRepeatCount() > 0 && mQueue.hasKeyUpEvent(event)) {
5235 return INJECT_SUCCEEDED;
5236 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005238 WindowState focus = (WindowState)focusObj;
Romain Guy06882f82009-06-10 13:36:04 -07005239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005240 if (DEBUG_INPUT) Log.v(
5241 TAG, "Dispatching to " + focus + ": " + event);
5242
5243 if (uid != 0 && uid != focus.mSession.mUid) {
5244 if (mContext.checkPermission(
5245 android.Manifest.permission.INJECT_EVENTS, pid, uid)
5246 != PackageManager.PERMISSION_GRANTED) {
5247 Log.w(TAG, "Permission denied: injecting key event from pid "
5248 + pid + " uid " + uid + " to window " + focus
5249 + " owned by uid " + focus.mSession.mUid);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005250 return INJECT_NO_PERMISSION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005251 }
5252 }
Romain Guy06882f82009-06-10 13:36:04 -07005253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005254 synchronized(mWindowMap) {
5255 mKeyWaiter.bindTargetWindowLocked(focus);
5256 }
5257
5258 // NOSHIP extra state logging
5259 mKeyWaiter.recordDispatchState(event, focus);
5260 // END NOSHIP
Romain Guy06882f82009-06-10 13:36:04 -07005261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005262 try {
5263 if (DEBUG_INPUT || DEBUG_FOCUS) {
5264 Log.v(TAG, "Delivering key " + event.getKeyCode()
5265 + " to " + focus);
5266 }
5267 focus.mClient.dispatchKey(event);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005268 return INJECT_SUCCEEDED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005269 } catch (android.os.RemoteException e) {
5270 Log.i(TAG, "WINDOW DIED during key dispatch: " + focus);
5271 try {
5272 removeWindow(focus.mSession, focus.mClient);
5273 } catch (java.util.NoSuchElementException ex) {
5274 // This will happen if the window has already been
5275 // removed.
5276 }
5277 }
Romain Guy06882f82009-06-10 13:36:04 -07005278
Dianne Hackborncfaef692009-06-15 14:24:44 -07005279 return INJECT_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005280 }
Romain Guy06882f82009-06-10 13:36:04 -07005281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005282 public void pauseKeyDispatching(IBinder _token) {
5283 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5284 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005285 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005286 }
5287
5288 synchronized (mWindowMap) {
5289 WindowToken token = mTokenMap.get(_token);
5290 if (token != null) {
5291 mKeyWaiter.pauseDispatchingLocked(token);
5292 }
5293 }
5294 }
5295
5296 public void resumeKeyDispatching(IBinder _token) {
5297 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5298 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005299 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005300 }
5301
5302 synchronized (mWindowMap) {
5303 WindowToken token = mTokenMap.get(_token);
5304 if (token != null) {
5305 mKeyWaiter.resumeDispatchingLocked(token);
5306 }
5307 }
5308 }
5309
5310 public void setEventDispatching(boolean enabled) {
5311 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5312 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005313 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005314 }
5315
5316 synchronized (mWindowMap) {
5317 mKeyWaiter.setEventDispatchingLocked(enabled);
5318 }
5319 }
Romain Guy06882f82009-06-10 13:36:04 -07005320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005321 /**
5322 * Injects a keystroke event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005323 *
5324 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005325 * {@link SystemClock#uptimeMillis()} as the timebase.)
5326 * @param sync If true, wait for the event to be completed before returning to the caller.
5327 * @return Returns true if event was dispatched, false if it was dropped for any reason
5328 */
5329 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5330 long downTime = ev.getDownTime();
5331 long eventTime = ev.getEventTime();
5332
5333 int action = ev.getAction();
5334 int code = ev.getKeyCode();
5335 int repeatCount = ev.getRepeatCount();
5336 int metaState = ev.getMetaState();
5337 int deviceId = ev.getDeviceId();
5338 int scancode = ev.getScanCode();
5339
5340 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5341 if (downTime == 0) downTime = eventTime;
5342
5343 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
The Android Open Source Project10592532009-03-18 17:39:46 -07005344 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005345
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005346 final int pid = Binder.getCallingPid();
5347 final int uid = Binder.getCallingUid();
5348 final long ident = Binder.clearCallingIdentity();
5349 final int result = dispatchKey(newEvent, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005350 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005351 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005352 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005353 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005354 switch (result) {
5355 case INJECT_NO_PERMISSION:
5356 throw new SecurityException(
5357 "Injecting to another application requires INJECT_EVENT permission");
5358 case INJECT_SUCCEEDED:
5359 return true;
5360 }
5361 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005362 }
5363
5364 /**
5365 * Inject a pointer (touch) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005366 *
5367 * @param ev A motion event describing the pointer (touch) action. (As noted in
5368 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005369 * {@link SystemClock#uptimeMillis()} as the timebase.)
5370 * @param sync If true, wait for the event to be completed before returning to the caller.
5371 * @return Returns true if event was dispatched, false if it was dropped for any reason
5372 */
5373 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005374 final int pid = Binder.getCallingPid();
5375 final int uid = Binder.getCallingUid();
5376 final long ident = Binder.clearCallingIdentity();
5377 final int result = dispatchPointer(null, ev, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005378 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005379 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005380 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005381 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005382 switch (result) {
5383 case INJECT_NO_PERMISSION:
5384 throw new SecurityException(
5385 "Injecting to another application requires INJECT_EVENT permission");
5386 case INJECT_SUCCEEDED:
5387 return true;
5388 }
5389 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005390 }
Romain Guy06882f82009-06-10 13:36:04 -07005391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005392 /**
5393 * Inject a trackball (navigation device) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005394 *
5395 * @param ev A motion event describing the trackball action. (As noted in
5396 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005397 * {@link SystemClock#uptimeMillis()} as the timebase.)
5398 * @param sync If true, wait for the event to be completed before returning to the caller.
5399 * @return Returns true if event was dispatched, false if it was dropped for any reason
5400 */
5401 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005402 final int pid = Binder.getCallingPid();
5403 final int uid = Binder.getCallingUid();
5404 final long ident = Binder.clearCallingIdentity();
5405 final int result = dispatchTrackball(null, ev, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005406 if (sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005407 mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005408 }
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005409 Binder.restoreCallingIdentity(ident);
Dianne Hackborncfaef692009-06-15 14:24:44 -07005410 switch (result) {
5411 case INJECT_NO_PERMISSION:
5412 throw new SecurityException(
5413 "Injecting to another application requires INJECT_EVENT permission");
5414 case INJECT_SUCCEEDED:
5415 return true;
5416 }
5417 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005418 }
Romain Guy06882f82009-06-10 13:36:04 -07005419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005420 private WindowState getFocusedWindow() {
5421 synchronized (mWindowMap) {
5422 return getFocusedWindowLocked();
5423 }
5424 }
5425
5426 private WindowState getFocusedWindowLocked() {
5427 return mCurrentFocus;
5428 }
Romain Guy06882f82009-06-10 13:36:04 -07005429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005430 /**
5431 * This class holds the state for dispatching key events. This state
5432 * is protected by the KeyWaiter instance, NOT by the window lock. You
5433 * can be holding the main window lock while acquire the KeyWaiter lock,
5434 * but not the other way around.
5435 */
5436 final class KeyWaiter {
5437 // NOSHIP debugging
5438 public class DispatchState {
5439 private KeyEvent event;
5440 private WindowState focus;
5441 private long time;
5442 private WindowState lastWin;
5443 private IBinder lastBinder;
5444 private boolean finished;
5445 private boolean gotFirstWindow;
5446 private boolean eventDispatching;
5447 private long timeToSwitch;
5448 private boolean wasFrozen;
5449 private boolean focusPaused;
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005450 private WindowState curFocus;
Romain Guy06882f82009-06-10 13:36:04 -07005451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005452 DispatchState(KeyEvent theEvent, WindowState theFocus) {
5453 focus = theFocus;
5454 event = theEvent;
5455 time = System.currentTimeMillis();
5456 // snapshot KeyWaiter state
5457 lastWin = mLastWin;
5458 lastBinder = mLastBinder;
5459 finished = mFinished;
5460 gotFirstWindow = mGotFirstWindow;
5461 eventDispatching = mEventDispatching;
5462 timeToSwitch = mTimeToSwitch;
5463 wasFrozen = mWasFrozen;
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005464 curFocus = mCurrentFocus;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005465 // cache the paused state at ctor time as well
5466 if (theFocus == null || theFocus.mToken == null) {
5467 Log.i(TAG, "focus " + theFocus + " mToken is null at event dispatch!");
5468 focusPaused = false;
5469 } else {
5470 focusPaused = theFocus.mToken.paused;
5471 }
5472 }
Romain Guy06882f82009-06-10 13:36:04 -07005473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005474 public String toString() {
5475 return "{{" + event + " to " + focus + " @ " + time
5476 + " lw=" + lastWin + " lb=" + lastBinder
5477 + " fin=" + finished + " gfw=" + gotFirstWindow
5478 + " ed=" + eventDispatching + " tts=" + timeToSwitch
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005479 + " wf=" + wasFrozen + " fp=" + focusPaused
5480 + " mcf=" + mCurrentFocus + "}}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005481 }
5482 };
5483 private DispatchState mDispatchState = null;
5484 public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) {
5485 mDispatchState = new DispatchState(theEvent, theFocus);
5486 }
5487 // END NOSHIP
5488
5489 public static final int RETURN_NOTHING = 0;
5490 public static final int RETURN_PENDING_POINTER = 1;
5491 public static final int RETURN_PENDING_TRACKBALL = 2;
Romain Guy06882f82009-06-10 13:36:04 -07005492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005493 final Object SKIP_TARGET_TOKEN = new Object();
5494 final Object CONSUMED_EVENT_TOKEN = new Object();
Romain Guy06882f82009-06-10 13:36:04 -07005495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005496 private WindowState mLastWin = null;
5497 private IBinder mLastBinder = null;
5498 private boolean mFinished = true;
5499 private boolean mGotFirstWindow = false;
5500 private boolean mEventDispatching = true;
5501 private long mTimeToSwitch = 0;
5502 /* package */ boolean mWasFrozen = false;
Romain Guy06882f82009-06-10 13:36:04 -07005503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005504 // Target of Motion events
5505 WindowState mMotionTarget;
Romain Guy06882f82009-06-10 13:36:04 -07005506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005507 // Windows above the target who would like to receive an "outside"
5508 // touch event for any down events outside of them.
5509 WindowState mOutsideTouchTargets;
5510
5511 /**
5512 * Wait for the last event dispatch to complete, then find the next
5513 * target that should receive the given event and wait for that one
5514 * to be ready to receive it.
5515 */
5516 Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev,
5517 MotionEvent nextMotion, boolean isPointerEvent,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005518 boolean failIfTimeout, int callingPid, int callingUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005519 long startTime = SystemClock.uptimeMillis();
5520 long keyDispatchingTimeout = 5 * 1000;
5521 long waitedFor = 0;
5522
5523 while (true) {
5524 // Figure out which window we care about. It is either the
5525 // last window we are waiting to have process the event or,
5526 // if none, then the next window we think the event should go
5527 // to. Note: we retrieve mLastWin outside of the lock, so
5528 // it may change before we lock. Thus we must check it again.
5529 WindowState targetWin = mLastWin;
5530 boolean targetIsNew = targetWin == null;
5531 if (DEBUG_INPUT) Log.v(
5532 TAG, "waitForLastKey: mFinished=" + mFinished +
5533 ", mLastWin=" + mLastWin);
5534 if (targetIsNew) {
5535 Object target = findTargetWindow(nextKey, qev, nextMotion,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005536 isPointerEvent, callingPid, callingUid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005537 if (target == SKIP_TARGET_TOKEN) {
5538 // The user has pressed a special key, and we are
5539 // dropping all pending events before it.
5540 if (DEBUG_INPUT) Log.v(TAG, "Skipping: " + nextKey
5541 + " " + nextMotion);
5542 return null;
5543 }
5544 if (target == CONSUMED_EVENT_TOKEN) {
5545 if (DEBUG_INPUT) Log.v(TAG, "Consumed: " + nextKey
5546 + " " + nextMotion);
5547 return target;
5548 }
5549 targetWin = (WindowState)target;
5550 }
Romain Guy06882f82009-06-10 13:36:04 -07005551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005552 AppWindowToken targetApp = null;
Romain Guy06882f82009-06-10 13:36:04 -07005553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005554 // Now: is it okay to send the next event to this window?
5555 synchronized (this) {
5556 // First: did we come here based on the last window not
5557 // being null, but it changed by the time we got here?
5558 // If so, try again.
5559 if (!targetIsNew && mLastWin == null) {
5560 continue;
5561 }
Romain Guy06882f82009-06-10 13:36:04 -07005562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005563 // We never dispatch events if not finished with the
5564 // last one, or the display is frozen.
5565 if (mFinished && !mDisplayFrozen) {
5566 // If event dispatching is disabled, then we
5567 // just consume the events.
5568 if (!mEventDispatching) {
5569 if (DEBUG_INPUT) Log.v(TAG,
5570 "Skipping event; dispatching disabled: "
5571 + nextKey + " " + nextMotion);
5572 return null;
5573 }
5574 if (targetWin != null) {
5575 // If this is a new target, and that target is not
5576 // paused or unresponsive, then all looks good to
5577 // handle the event.
5578 if (targetIsNew && !targetWin.mToken.paused) {
5579 return targetWin;
5580 }
Romain Guy06882f82009-06-10 13:36:04 -07005581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005582 // If we didn't find a target window, and there is no
5583 // focused app window, then just eat the events.
5584 } else if (mFocusedApp == null) {
5585 if (DEBUG_INPUT) Log.v(TAG,
5586 "Skipping event; no focused app: "
5587 + nextKey + " " + nextMotion);
5588 return null;
5589 }
5590 }
Romain Guy06882f82009-06-10 13:36:04 -07005591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005592 if (DEBUG_INPUT) Log.v(
5593 TAG, "Waiting for last key in " + mLastBinder
5594 + " target=" + targetWin
5595 + " mFinished=" + mFinished
5596 + " mDisplayFrozen=" + mDisplayFrozen
5597 + " targetIsNew=" + targetIsNew
5598 + " paused="
5599 + (targetWin != null ? targetWin.mToken.paused : false)
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005600 + " mFocusedApp=" + mFocusedApp
5601 + " mCurrentFocus=" + mCurrentFocus);
Romain Guy06882f82009-06-10 13:36:04 -07005602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005603 targetApp = targetWin != null
5604 ? targetWin.mAppToken : mFocusedApp;
Romain Guy06882f82009-06-10 13:36:04 -07005605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005606 long curTimeout = keyDispatchingTimeout;
5607 if (mTimeToSwitch != 0) {
5608 long now = SystemClock.uptimeMillis();
5609 if (mTimeToSwitch <= now) {
5610 // If an app switch key has been pressed, and we have
5611 // waited too long for the current app to finish
5612 // processing keys, then wait no more!
5613 doFinishedKeyLocked(true);
5614 continue;
5615 }
5616 long switchTimeout = mTimeToSwitch - now;
5617 if (curTimeout > switchTimeout) {
5618 curTimeout = switchTimeout;
5619 }
5620 }
Romain Guy06882f82009-06-10 13:36:04 -07005621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005622 try {
5623 // after that continue
5624 // processing keys, so we don't get stuck.
5625 if (DEBUG_INPUT) Log.v(
5626 TAG, "Waiting for key dispatch: " + curTimeout);
5627 wait(curTimeout);
5628 if (DEBUG_INPUT) Log.v(TAG, "Finished waiting @"
5629 + SystemClock.uptimeMillis() + " startTime="
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08005630 + startTime + " switchTime=" + mTimeToSwitch
5631 + " target=" + targetWin + " mLW=" + mLastWin
5632 + " mLB=" + mLastBinder + " fin=" + mFinished
5633 + " mCurrentFocus=" + mCurrentFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005634 } catch (InterruptedException e) {
5635 }
5636 }
5637
5638 // If we were frozen during configuration change, restart the
5639 // timeout checks from now; otherwise look at whether we timed
5640 // out before awakening.
5641 if (mWasFrozen) {
5642 waitedFor = 0;
5643 mWasFrozen = false;
5644 } else {
5645 waitedFor = SystemClock.uptimeMillis() - startTime;
5646 }
5647
5648 if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) {
5649 IApplicationToken at = null;
5650 synchronized (this) {
5651 Log.w(TAG, "Key dispatching timed out sending to " +
5652 (targetWin != null ? targetWin.mAttrs.getTitle()
5653 : "<null>"));
5654 // NOSHIP debugging
5655 Log.w(TAG, "Dispatch state: " + mDispatchState);
5656 Log.w(TAG, "Current state: " + new DispatchState(nextKey, targetWin));
5657 // END NOSHIP
5658 //dump();
5659 if (targetWin != null) {
5660 at = targetWin.getAppToken();
5661 } else if (targetApp != null) {
5662 at = targetApp.appToken;
5663 }
5664 }
5665
5666 boolean abort = true;
5667 if (at != null) {
5668 try {
5669 long timeout = at.getKeyDispatchingTimeout();
5670 if (timeout > waitedFor) {
5671 // we did not wait the proper amount of time for this application.
5672 // set the timeout to be the real timeout and wait again.
5673 keyDispatchingTimeout = timeout - waitedFor;
5674 continue;
5675 } else {
5676 abort = at.keyDispatchingTimedOut();
5677 }
5678 } catch (RemoteException ex) {
5679 }
5680 }
5681
5682 synchronized (this) {
5683 if (abort && (mLastWin == targetWin || targetWin == null)) {
5684 mFinished = true;
Romain Guy06882f82009-06-10 13:36:04 -07005685 if (mLastWin != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005686 if (DEBUG_INPUT) Log.v(TAG,
5687 "Window " + mLastWin +
5688 " timed out on key input");
5689 if (mLastWin.mToken.paused) {
5690 Log.w(TAG, "Un-pausing dispatching to this window");
5691 mLastWin.mToken.paused = false;
5692 }
5693 }
5694 if (mMotionTarget == targetWin) {
5695 mMotionTarget = null;
5696 }
5697 mLastWin = null;
5698 mLastBinder = null;
5699 if (failIfTimeout || targetWin == null) {
5700 return null;
5701 }
5702 } else {
5703 Log.w(TAG, "Continuing to wait for key to be dispatched");
5704 startTime = SystemClock.uptimeMillis();
5705 }
5706 }
5707 }
5708 }
5709 }
Romain Guy06882f82009-06-10 13:36:04 -07005710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005711 Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev,
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005712 MotionEvent nextMotion, boolean isPointerEvent,
5713 int callingPid, int callingUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005714 mOutsideTouchTargets = null;
Romain Guy06882f82009-06-10 13:36:04 -07005715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005716 if (nextKey != null) {
5717 // Find the target window for a normal key event.
5718 final int keycode = nextKey.getKeyCode();
5719 final int repeatCount = nextKey.getRepeatCount();
5720 final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP;
5721 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005722
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005723 if (!dispatch) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005724 if (callingUid == 0 ||
5725 mContext.checkPermission(
5726 android.Manifest.permission.INJECT_EVENTS,
5727 callingPid, callingUid)
5728 == PackageManager.PERMISSION_GRANTED) {
5729 mPolicy.interceptKeyTi(null, keycode,
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07005730 nextKey.getMetaState(), down, repeatCount,
5731 nextKey.getFlags());
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005732 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005733 Log.w(TAG, "Event timeout during app switch: dropping "
5734 + nextKey);
5735 return SKIP_TARGET_TOKEN;
5736 }
Romain Guy06882f82009-06-10 13:36:04 -07005737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005738 // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")");
Romain Guy06882f82009-06-10 13:36:04 -07005739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005740 WindowState focus = null;
5741 synchronized(mWindowMap) {
5742 focus = getFocusedWindowLocked();
5743 }
Romain Guy06882f82009-06-10 13:36:04 -07005744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005745 wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT);
Romain Guy06882f82009-06-10 13:36:04 -07005746
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005747 if (callingUid == 0 ||
5748 (focus != null && callingUid == focus.mSession.mUid) ||
5749 mContext.checkPermission(
5750 android.Manifest.permission.INJECT_EVENTS,
5751 callingPid, callingUid)
5752 == PackageManager.PERMISSION_GRANTED) {
5753 if (mPolicy.interceptKeyTi(focus,
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005754 keycode, nextKey.getMetaState(), down, repeatCount,
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07005755 nextKey.getFlags())) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005756 return CONSUMED_EVENT_TOKEN;
5757 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005758 }
Romain Guy06882f82009-06-10 13:36:04 -07005759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005760 return focus;
Romain Guy06882f82009-06-10 13:36:04 -07005761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005762 } else if (!isPointerEvent) {
5763 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1);
5764 if (!dispatch) {
5765 Log.w(TAG, "Event timeout during app switch: dropping trackball "
5766 + nextMotion);
5767 return SKIP_TARGET_TOKEN;
5768 }
Romain Guy06882f82009-06-10 13:36:04 -07005769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005770 WindowState focus = null;
5771 synchronized(mWindowMap) {
5772 focus = getFocusedWindowLocked();
5773 }
Romain Guy06882f82009-06-10 13:36:04 -07005774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005775 wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT);
5776 return focus;
5777 }
Romain Guy06882f82009-06-10 13:36:04 -07005778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005779 if (nextMotion == null) {
5780 return SKIP_TARGET_TOKEN;
5781 }
Romain Guy06882f82009-06-10 13:36:04 -07005782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005783 boolean dispatch = mKeyWaiter.checkShouldDispatchKey(
5784 KeyEvent.KEYCODE_UNKNOWN);
5785 if (!dispatch) {
5786 Log.w(TAG, "Event timeout during app switch: dropping pointer "
5787 + nextMotion);
5788 return SKIP_TARGET_TOKEN;
5789 }
Romain Guy06882f82009-06-10 13:36:04 -07005790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005791 // Find the target window for a pointer event.
5792 int action = nextMotion.getAction();
5793 final float xf = nextMotion.getX();
5794 final float yf = nextMotion.getY();
5795 final long eventTime = nextMotion.getEventTime();
Romain Guy06882f82009-06-10 13:36:04 -07005796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005797 final boolean screenWasOff = qev != null
5798 && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07005799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005800 WindowState target = null;
Romain Guy06882f82009-06-10 13:36:04 -07005801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005802 synchronized(mWindowMap) {
5803 synchronized (this) {
5804 if (action == MotionEvent.ACTION_DOWN) {
5805 if (mMotionTarget != null) {
5806 // this is weird, we got a pen down, but we thought it was
5807 // already down!
5808 // XXX: We should probably send an ACTION_UP to the current
5809 // target.
5810 Log.w(TAG, "Pointer down received while already down in: "
5811 + mMotionTarget);
5812 mMotionTarget = null;
5813 }
Romain Guy06882f82009-06-10 13:36:04 -07005814
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005815 // ACTION_DOWN is special, because we need to lock next events to
5816 // the window we'll land onto.
5817 final int x = (int)xf;
5818 final int y = (int)yf;
Romain Guy06882f82009-06-10 13:36:04 -07005819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005820 final ArrayList windows = mWindows;
5821 final int N = windows.size();
5822 WindowState topErrWindow = null;
5823 final Rect tmpRect = mTempRect;
5824 for (int i=N-1; i>=0; i--) {
5825 WindowState child = (WindowState)windows.get(i);
5826 //Log.i(TAG, "Checking dispatch to: " + child);
5827 final int flags = child.mAttrs.flags;
5828 if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) {
5829 if (topErrWindow == null) {
5830 topErrWindow = child;
5831 }
5832 }
5833 if (!child.isVisibleLw()) {
5834 //Log.i(TAG, "Not visible!");
5835 continue;
5836 }
5837 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
5838 //Log.i(TAG, "Not touchable!");
5839 if ((flags & WindowManager.LayoutParams
5840 .FLAG_WATCH_OUTSIDE_TOUCH) != 0) {
5841 child.mNextOutsideTouch = mOutsideTouchTargets;
5842 mOutsideTouchTargets = child;
5843 }
5844 continue;
5845 }
5846 tmpRect.set(child.mFrame);
5847 if (child.mTouchableInsets == ViewTreeObserver
5848 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
5849 // The touch is inside of the window if it is
5850 // inside the frame, AND the content part of that
5851 // frame that was given by the application.
5852 tmpRect.left += child.mGivenContentInsets.left;
5853 tmpRect.top += child.mGivenContentInsets.top;
5854 tmpRect.right -= child.mGivenContentInsets.right;
5855 tmpRect.bottom -= child.mGivenContentInsets.bottom;
5856 } else if (child.mTouchableInsets == ViewTreeObserver
5857 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
5858 // The touch is inside of the window if it is
5859 // inside the frame, AND the visible part of that
5860 // frame that was given by the application.
5861 tmpRect.left += child.mGivenVisibleInsets.left;
5862 tmpRect.top += child.mGivenVisibleInsets.top;
5863 tmpRect.right -= child.mGivenVisibleInsets.right;
5864 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
5865 }
5866 final int touchFlags = flags &
5867 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
5868 |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
5869 if (tmpRect.contains(x, y) || touchFlags == 0) {
5870 //Log.i(TAG, "Using this target!");
5871 if (!screenWasOff || (flags &
5872 WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) {
5873 mMotionTarget = child;
5874 } else {
5875 //Log.i(TAG, "Waking, skip!");
5876 mMotionTarget = null;
5877 }
5878 break;
5879 }
Romain Guy06882f82009-06-10 13:36:04 -07005880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005881 if ((flags & WindowManager.LayoutParams
5882 .FLAG_WATCH_OUTSIDE_TOUCH) != 0) {
5883 child.mNextOutsideTouch = mOutsideTouchTargets;
5884 mOutsideTouchTargets = child;
5885 //Log.i(TAG, "Adding to outside target list: " + child);
5886 }
5887 }
5888
5889 // if there's an error window but it's not accepting
5890 // focus (typically because it is not yet visible) just
5891 // wait for it -- any other focused window may in fact
5892 // be in ANR state.
5893 if (topErrWindow != null && mMotionTarget != topErrWindow) {
5894 mMotionTarget = null;
5895 }
5896 }
Romain Guy06882f82009-06-10 13:36:04 -07005897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005898 target = mMotionTarget;
5899 }
5900 }
Romain Guy06882f82009-06-10 13:36:04 -07005901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005902 wakeupIfNeeded(target, eventType(nextMotion));
Romain Guy06882f82009-06-10 13:36:04 -07005903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005904 // Pointer events are a little different -- if there isn't a
5905 // target found for any event, then just drop it.
5906 return target != null ? target : SKIP_TARGET_TOKEN;
5907 }
Romain Guy06882f82009-06-10 13:36:04 -07005908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005909 boolean checkShouldDispatchKey(int keycode) {
5910 synchronized (this) {
5911 if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) {
5912 mTimeToSwitch = 0;
5913 return true;
5914 }
5915 if (mTimeToSwitch != 0
5916 && mTimeToSwitch < SystemClock.uptimeMillis()) {
5917 return false;
5918 }
5919 return true;
5920 }
5921 }
Romain Guy06882f82009-06-10 13:36:04 -07005922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005923 void bindTargetWindowLocked(WindowState win,
5924 int pendingWhat, QueuedEvent pendingMotion) {
5925 synchronized (this) {
5926 bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion);
5927 }
5928 }
Romain Guy06882f82009-06-10 13:36:04 -07005929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005930 void bindTargetWindowLocked(WindowState win) {
5931 synchronized (this) {
5932 bindTargetWindowLockedLocked(win, RETURN_NOTHING, null);
5933 }
5934 }
5935
5936 void bindTargetWindowLockedLocked(WindowState win,
5937 int pendingWhat, QueuedEvent pendingMotion) {
5938 mLastWin = win;
5939 mLastBinder = win.mClient.asBinder();
5940 mFinished = false;
5941 if (pendingMotion != null) {
5942 final Session s = win.mSession;
5943 if (pendingWhat == RETURN_PENDING_POINTER) {
5944 releasePendingPointerLocked(s);
5945 s.mPendingPointerMove = pendingMotion;
5946 s.mPendingPointerWindow = win;
Romain Guy06882f82009-06-10 13:36:04 -07005947 if (DEBUG_INPUT) Log.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005948 "bindTargetToWindow " + s.mPendingPointerMove);
5949 } else if (pendingWhat == RETURN_PENDING_TRACKBALL) {
5950 releasePendingTrackballLocked(s);
5951 s.mPendingTrackballMove = pendingMotion;
5952 s.mPendingTrackballWindow = win;
5953 }
5954 }
5955 }
Romain Guy06882f82009-06-10 13:36:04 -07005956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005957 void releasePendingPointerLocked(Session s) {
5958 if (DEBUG_INPUT) Log.v(TAG,
5959 "releasePendingPointer " + s.mPendingPointerMove);
5960 if (s.mPendingPointerMove != null) {
5961 mQueue.recycleEvent(s.mPendingPointerMove);
5962 s.mPendingPointerMove = null;
5963 }
5964 }
Romain Guy06882f82009-06-10 13:36:04 -07005965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005966 void releasePendingTrackballLocked(Session s) {
5967 if (s.mPendingTrackballMove != null) {
5968 mQueue.recycleEvent(s.mPendingTrackballMove);
5969 s.mPendingTrackballMove = null;
5970 }
5971 }
Romain Guy06882f82009-06-10 13:36:04 -07005972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005973 MotionEvent finishedKey(Session session, IWindow client, boolean force,
5974 int returnWhat) {
5975 if (DEBUG_INPUT) Log.v(
5976 TAG, "finishedKey: client=" + client + ", force=" + force);
5977
5978 if (client == null) {
5979 return null;
5980 }
5981
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07005982 MotionEvent res = null;
5983 QueuedEvent qev = null;
5984 WindowState win = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005986 synchronized (this) {
5987 if (DEBUG_INPUT) Log.v(
5988 TAG, "finishedKey: client=" + client.asBinder()
5989 + ", force=" + force + ", last=" + mLastBinder
5990 + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")");
5991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005992 if (returnWhat == RETURN_PENDING_POINTER) {
5993 qev = session.mPendingPointerMove;
5994 win = session.mPendingPointerWindow;
5995 session.mPendingPointerMove = null;
5996 session.mPendingPointerWindow = null;
5997 } else if (returnWhat == RETURN_PENDING_TRACKBALL) {
5998 qev = session.mPendingTrackballMove;
5999 win = session.mPendingTrackballWindow;
6000 session.mPendingTrackballMove = null;
6001 session.mPendingTrackballWindow = null;
6002 }
Romain Guy06882f82009-06-10 13:36:04 -07006003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006004 if (mLastBinder == client.asBinder()) {
6005 if (DEBUG_INPUT) Log.v(
6006 TAG, "finishedKey: last paused="
6007 + ((mLastWin != null) ? mLastWin.mToken.paused : "null"));
6008 if (mLastWin != null && (!mLastWin.mToken.paused || force
6009 || !mEventDispatching)) {
6010 doFinishedKeyLocked(false);
6011 } else {
6012 // Make sure to wake up anyone currently waiting to
6013 // dispatch a key, so they can re-evaluate their
6014 // current situation.
6015 mFinished = true;
6016 notifyAll();
6017 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006018 }
Romain Guy06882f82009-06-10 13:36:04 -07006019
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006020 if (qev != null) {
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006021 res = (MotionEvent)qev.event;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006022 if (DEBUG_INPUT) Log.v(TAG,
6023 "Returning pending motion: " + res);
6024 mQueue.recycleEvent(qev);
6025 if (win != null && returnWhat == RETURN_PENDING_POINTER) {
6026 res.offsetLocation(-win.mFrame.left, -win.mFrame.top);
6027 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006028 }
Christopher Tate2624fbc2009-12-11 12:11:31 -08006029 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006030
Christopher Tate2624fbc2009-12-11 12:11:31 -08006031 if (res != null && returnWhat == RETURN_PENDING_POINTER) {
6032 synchronized (mWindowMap) {
6033 if ((mWallpaperTarget == win &&
6034 win.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD)
6035 || mSendingPointersToWallpaper) {
6036 sendPointerToWallpaperLocked(win, res, res.getEventTime());
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006037 }
6038 }
6039 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006040
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07006041 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006042 }
6043
6044 void tickle() {
6045 synchronized (this) {
6046 notifyAll();
6047 }
6048 }
Romain Guy06882f82009-06-10 13:36:04 -07006049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006050 void handleNewWindowLocked(WindowState newWindow) {
6051 if (!newWindow.canReceiveKeys()) {
6052 return;
6053 }
6054 synchronized (this) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08006055 if (DEBUG_INPUT) Log.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006056 TAG, "New key dispatch window: win="
6057 + newWindow.mClient.asBinder()
6058 + ", last=" + mLastBinder
6059 + " (token=" + (mLastWin != null ? mLastWin.mToken : null)
6060 + "), finished=" + mFinished + ", paused="
6061 + newWindow.mToken.paused);
6062
6063 // Displaying a window implicitly causes dispatching to
6064 // be unpaused. (This is to protect against bugs if someone
6065 // pauses dispatching but forgets to resume.)
6066 newWindow.mToken.paused = false;
6067
6068 mGotFirstWindow = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006069
6070 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
6071 if (DEBUG_INPUT) Log.v(TAG,
6072 "New SYSTEM_ERROR window; resetting state");
6073 mLastWin = null;
6074 mLastBinder = null;
6075 mMotionTarget = null;
6076 mFinished = true;
6077 } else if (mLastWin != null) {
6078 // If the new window is above the window we are
6079 // waiting on, then stop waiting and let key dispatching
6080 // start on the new guy.
6081 if (DEBUG_INPUT) Log.v(
6082 TAG, "Last win layer=" + mLastWin.mLayer
6083 + ", new win layer=" + newWindow.mLayer);
6084 if (newWindow.mLayer >= mLastWin.mLayer) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08006085 // The new window is above the old; finish pending input to the last
6086 // window and start directing it to the new one.
6087 mLastWin.mToken.paused = false;
6088 doFinishedKeyLocked(true); // does a notifyAll()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006089 }
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08006090 // Either the new window is lower, so there is no need to wake key waiters,
6091 // or we just finished key input to the previous window, which implicitly
6092 // notified the key waiters. In both cases, we don't need to issue the
6093 // notification here.
6094 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006095 }
6096
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08006097 // Now that we've put a new window state in place, make the event waiter
6098 // take notice and retarget its attentions.
6099 notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006100 }
6101 }
6102
6103 void pauseDispatchingLocked(WindowToken token) {
6104 synchronized (this)
6105 {
6106 if (DEBUG_INPUT) Log.v(TAG, "Pausing WindowToken " + token);
6107 token.paused = true;
6108
6109 /*
6110 if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) {
6111 mPaused = true;
6112 } else {
6113 if (mLastWin == null) {
Dave Bortcfe65242009-04-09 14:51:04 -07006114 Log.i(TAG, "Key dispatching not paused: no last window.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006115 } else if (mFinished) {
Dave Bortcfe65242009-04-09 14:51:04 -07006116 Log.i(TAG, "Key dispatching not paused: finished last key.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006117 } else {
Dave Bortcfe65242009-04-09 14:51:04 -07006118 Log.i(TAG, "Key dispatching not paused: window in higher layer.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006119 }
6120 }
6121 */
6122 }
6123 }
6124
6125 void resumeDispatchingLocked(WindowToken token) {
6126 synchronized (this) {
6127 if (token.paused) {
6128 if (DEBUG_INPUT) Log.v(
6129 TAG, "Resuming WindowToken " + token
6130 + ", last=" + mLastBinder
6131 + " (token=" + (mLastWin != null ? mLastWin.mToken : null)
6132 + "), finished=" + mFinished + ", paused="
6133 + token.paused);
6134 token.paused = false;
6135 if (mLastWin != null && mLastWin.mToken == token && mFinished) {
6136 doFinishedKeyLocked(true);
6137 } else {
6138 notifyAll();
6139 }
6140 }
6141 }
6142 }
6143
6144 void setEventDispatchingLocked(boolean enabled) {
6145 synchronized (this) {
6146 mEventDispatching = enabled;
6147 notifyAll();
6148 }
6149 }
Romain Guy06882f82009-06-10 13:36:04 -07006150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006151 void appSwitchComing() {
6152 synchronized (this) {
6153 // Don't wait for more than .5 seconds for app to finish
6154 // processing the pending events.
6155 long now = SystemClock.uptimeMillis() + 500;
6156 if (DEBUG_INPUT) Log.v(TAG, "appSwitchComing: " + now);
6157 if (mTimeToSwitch == 0 || now < mTimeToSwitch) {
6158 mTimeToSwitch = now;
6159 }
6160 notifyAll();
6161 }
6162 }
Romain Guy06882f82009-06-10 13:36:04 -07006163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006164 private final void doFinishedKeyLocked(boolean doRecycle) {
6165 if (mLastWin != null) {
6166 releasePendingPointerLocked(mLastWin.mSession);
6167 releasePendingTrackballLocked(mLastWin.mSession);
6168 }
Romain Guy06882f82009-06-10 13:36:04 -07006169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006170 if (mLastWin == null || !mLastWin.mToken.paused
6171 || !mLastWin.isVisibleLw()) {
6172 // If the current window has been paused, we aren't -really-
6173 // finished... so let the waiters still wait.
6174 mLastWin = null;
6175 mLastBinder = null;
6176 }
6177 mFinished = true;
6178 notifyAll();
6179 }
6180 }
6181
6182 private class KeyQ extends KeyInputQueue
6183 implements KeyInputQueue.FilterCallback {
6184 PowerManager.WakeLock mHoldingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07006185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006186 KeyQ() {
Dianne Hackbornddca3ee2009-07-23 19:01:31 -07006187 super(mContext, WindowManagerService.this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006188 PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
6189 mHoldingScreen = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
6190 "KEEP_SCREEN_ON_FLAG");
6191 mHoldingScreen.setReferenceCounted(false);
6192 }
6193
6194 @Override
6195 boolean preprocessEvent(InputDevice device, RawInputEvent event) {
6196 if (mPolicy.preprocessInputEventTq(event)) {
6197 return true;
6198 }
Romain Guy06882f82009-06-10 13:36:04 -07006199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006200 switch (event.type) {
6201 case RawInputEvent.EV_KEY: {
6202 // XXX begin hack
6203 if (DEBUG) {
6204 if (event.keycode == KeyEvent.KEYCODE_G) {
6205 if (event.value != 0) {
6206 // G down
6207 mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
6208 }
6209 return false;
6210 }
6211 if (event.keycode == KeyEvent.KEYCODE_D) {
6212 if (event.value != 0) {
6213 //dump();
6214 }
6215 return false;
6216 }
6217 }
6218 // XXX end hack
Romain Guy06882f82009-06-10 13:36:04 -07006219
Charles Mendis322591c2009-10-29 11:06:59 -07006220 boolean screenIsOff = !mPowerManager.isScreenOn();
6221 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006222 int actions = mPolicy.interceptKeyTq(event, !screenIsOff);
Romain Guy06882f82009-06-10 13:36:04 -07006223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006224 if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) {
6225 mPowerManager.goToSleep(event.when);
6226 }
6227
6228 if (screenIsOff) {
6229 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6230 }
6231 if (screenIsDim) {
6232 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6233 }
6234 if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) {
6235 mPowerManager.userActivity(event.when, false,
Michael Chane96440f2009-05-06 10:27:36 -07006236 LocalPowerManager.BUTTON_EVENT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006237 }
Romain Guy06882f82009-06-10 13:36:04 -07006238
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006239 if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) {
6240 if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) {
6241 filterQueue(this);
6242 mKeyWaiter.appSwitchComing();
6243 }
6244 return true;
6245 } else {
6246 return false;
6247 }
6248 }
Romain Guy06882f82009-06-10 13:36:04 -07006249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006250 case RawInputEvent.EV_REL: {
Charles Mendis322591c2009-10-29 11:06:59 -07006251 boolean screenIsOff = !mPowerManager.isScreenOn();
6252 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006253 if (screenIsOff) {
6254 if (!mPolicy.isWakeRelMovementTq(event.deviceId,
6255 device.classes, event)) {
6256 //Log.i(TAG, "dropping because screenIsOff and !isWakeKey");
6257 return false;
6258 }
6259 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6260 }
6261 if (screenIsDim) {
6262 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6263 }
6264 return true;
6265 }
Romain Guy06882f82009-06-10 13:36:04 -07006266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006267 case RawInputEvent.EV_ABS: {
Charles Mendis322591c2009-10-29 11:06:59 -07006268 boolean screenIsOff = !mPowerManager.isScreenOn();
6269 boolean screenIsDim = !mPowerManager.isScreenBright();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006270 if (screenIsOff) {
6271 if (!mPolicy.isWakeAbsMovementTq(event.deviceId,
6272 device.classes, event)) {
6273 //Log.i(TAG, "dropping because screenIsOff and !isWakeKey");
6274 return false;
6275 }
6276 event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE;
6277 }
6278 if (screenIsDim) {
6279 event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE;
6280 }
6281 return true;
6282 }
Romain Guy06882f82009-06-10 13:36:04 -07006283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006284 default:
6285 return true;
6286 }
6287 }
6288
6289 public int filterEvent(QueuedEvent ev) {
6290 switch (ev.classType) {
6291 case RawInputEvent.CLASS_KEYBOARD:
6292 KeyEvent ke = (KeyEvent)ev.event;
6293 if (mPolicy.isMovementKeyTi(ke.getKeyCode())) {
6294 Log.w(TAG, "Dropping movement key during app switch: "
6295 + ke.getKeyCode() + ", action=" + ke.getAction());
6296 return FILTER_REMOVE;
6297 }
6298 return FILTER_ABORT;
6299 default:
6300 return FILTER_KEEP;
6301 }
6302 }
Romain Guy06882f82009-06-10 13:36:04 -07006303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006304 /**
6305 * Must be called with the main window manager lock held.
6306 */
6307 void setHoldScreenLocked(boolean holding) {
6308 boolean state = mHoldingScreen.isHeld();
6309 if (holding != state) {
6310 if (holding) {
6311 mHoldingScreen.acquire();
6312 } else {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006313 mPolicy.screenOnStoppedLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006314 mHoldingScreen.release();
6315 }
6316 }
6317 }
Michael Chan53071d62009-05-13 17:29:48 -07006318 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006319
6320 public boolean detectSafeMode() {
6321 mSafeMode = mPolicy.detectSafeMode();
6322 return mSafeMode;
6323 }
Romain Guy06882f82009-06-10 13:36:04 -07006324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006325 public void systemReady() {
6326 mPolicy.systemReady();
6327 }
Romain Guy06882f82009-06-10 13:36:04 -07006328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006329 private final class InputDispatcherThread extends Thread {
6330 // Time to wait when there is nothing to do: 9999 seconds.
6331 static final int LONG_WAIT=9999*1000;
6332
6333 public InputDispatcherThread() {
6334 super("InputDispatcher");
6335 }
Romain Guy06882f82009-06-10 13:36:04 -07006336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006337 @Override
6338 public void run() {
6339 while (true) {
6340 try {
6341 process();
6342 } catch (Exception e) {
6343 Log.e(TAG, "Exception in input dispatcher", e);
6344 }
6345 }
6346 }
Romain Guy06882f82009-06-10 13:36:04 -07006347
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006348 private void process() {
6349 android.os.Process.setThreadPriority(
6350 android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);
Romain Guy06882f82009-06-10 13:36:04 -07006351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006352 // The last key event we saw
6353 KeyEvent lastKey = null;
6354
6355 // Last keydown time for auto-repeating keys
6356 long lastKeyTime = SystemClock.uptimeMillis();
6357 long nextKeyTime = lastKeyTime+LONG_WAIT;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006358 long downTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006359
Romain Guy06882f82009-06-10 13:36:04 -07006360 // How many successive repeats we generated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006361 int keyRepeatCount = 0;
6362
6363 // Need to report that configuration has changed?
6364 boolean configChanged = false;
Romain Guy06882f82009-06-10 13:36:04 -07006365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006366 while (true) {
6367 long curTime = SystemClock.uptimeMillis();
6368
6369 if (DEBUG_INPUT) Log.v(
6370 TAG, "Waiting for next key: now=" + curTime
6371 + ", repeat @ " + nextKeyTime);
6372
6373 // Retrieve next event, waiting only as long as the next
6374 // repeat timeout. If the configuration has changed, then
6375 // don't wait at all -- we'll report the change as soon as
6376 // we have processed all events.
6377 QueuedEvent ev = mQueue.getEvent(
6378 (int)((!configChanged && curTime < nextKeyTime)
6379 ? (nextKeyTime-curTime) : 0));
6380
6381 if (DEBUG_INPUT && ev != null) Log.v(
6382 TAG, "Event: type=" + ev.classType + " data=" + ev.event);
6383
Michael Chan53071d62009-05-13 17:29:48 -07006384 if (MEASURE_LATENCY) {
6385 lt.sample("2 got event ", System.nanoTime() - ev.whenNano);
6386 }
6387
Mike Lockwood3d0ea722009-10-21 22:58:29 -04006388 if (lastKey != null && !mPolicy.allowKeyRepeat()) {
6389 // cancel key repeat at the request of the policy.
6390 lastKey = null;
6391 downTime = 0;
6392 lastKeyTime = curTime;
6393 nextKeyTime = curTime + LONG_WAIT;
6394 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006395 try {
6396 if (ev != null) {
Michael Chan53071d62009-05-13 17:29:48 -07006397 curTime = SystemClock.uptimeMillis();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006398 int eventType;
6399 if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) {
6400 eventType = eventType((MotionEvent)ev.event);
6401 } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD ||
6402 ev.classType == RawInputEvent.CLASS_TRACKBALL) {
6403 eventType = LocalPowerManager.BUTTON_EVENT;
6404 } else {
6405 eventType = LocalPowerManager.OTHER_EVENT;
6406 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07006407 try {
Michael Chan53071d62009-05-13 17:29:48 -07006408 if ((curTime - mLastBatteryStatsCallTime)
Michael Chane96440f2009-05-06 10:27:36 -07006409 >= MIN_TIME_BETWEEN_USERACTIVITIES) {
Michael Chan53071d62009-05-13 17:29:48 -07006410 mLastBatteryStatsCallTime = curTime;
Michael Chane96440f2009-05-06 10:27:36 -07006411 mBatteryStats.noteInputEvent();
6412 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07006413 } catch (RemoteException e) {
6414 // Ignore
6415 }
Michael Chane10de972009-05-18 11:24:50 -07006416
Mike Lockwood5db42402009-11-30 14:51:51 -05006417 if (ev.classType == RawInputEvent.CLASS_CONFIGURATION_CHANGED) {
6418 // do not wake screen in this case
6419 } else if (eventType != TOUCH_EVENT
Michael Chane10de972009-05-18 11:24:50 -07006420 && eventType != LONG_TOUCH_EVENT
6421 && eventType != CHEEK_EVENT) {
6422 mPowerManager.userActivity(curTime, false,
6423 eventType, false);
6424 } else if (mLastTouchEventType != eventType
6425 || (curTime - mLastUserActivityCallTime)
6426 >= MIN_TIME_BETWEEN_USERACTIVITIES) {
6427 mLastUserActivityCallTime = curTime;
6428 mLastTouchEventType = eventType;
6429 mPowerManager.userActivity(curTime, false,
6430 eventType, false);
6431 }
6432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006433 switch (ev.classType) {
6434 case RawInputEvent.CLASS_KEYBOARD:
6435 KeyEvent ke = (KeyEvent)ev.event;
6436 if (ke.isDown()) {
6437 lastKey = ke;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006438 downTime = curTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006439 keyRepeatCount = 0;
6440 lastKeyTime = curTime;
6441 nextKeyTime = lastKeyTime
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006442 + ViewConfiguration.getLongPressTimeout();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006443 if (DEBUG_INPUT) Log.v(
6444 TAG, "Received key down: first repeat @ "
6445 + nextKeyTime);
6446 } else {
6447 lastKey = null;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006448 downTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006449 // Arbitrary long timeout.
6450 lastKeyTime = curTime;
6451 nextKeyTime = curTime + LONG_WAIT;
6452 if (DEBUG_INPUT) Log.v(
6453 TAG, "Received key up: ignore repeat @ "
6454 + nextKeyTime);
6455 }
6456 dispatchKey((KeyEvent)ev.event, 0, 0);
6457 mQueue.recycleEvent(ev);
6458 break;
6459 case RawInputEvent.CLASS_TOUCHSCREEN:
6460 //Log.i(TAG, "Read next event " + ev);
6461 dispatchPointer(ev, (MotionEvent)ev.event, 0, 0);
6462 break;
6463 case RawInputEvent.CLASS_TRACKBALL:
6464 dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0);
6465 break;
6466 case RawInputEvent.CLASS_CONFIGURATION_CHANGED:
6467 configChanged = true;
6468 break;
6469 default:
6470 mQueue.recycleEvent(ev);
6471 break;
6472 }
Romain Guy06882f82009-06-10 13:36:04 -07006473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006474 } else if (configChanged) {
6475 configChanged = false;
6476 sendNewConfiguration();
Romain Guy06882f82009-06-10 13:36:04 -07006477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006478 } else if (lastKey != null) {
6479 curTime = SystemClock.uptimeMillis();
Romain Guy06882f82009-06-10 13:36:04 -07006480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006481 // Timeout occurred while key was down. If it is at or
6482 // past the key repeat time, dispatch the repeat.
6483 if (DEBUG_INPUT) Log.v(
6484 TAG, "Key timeout: repeat=" + nextKeyTime
6485 + ", now=" + curTime);
6486 if (curTime < nextKeyTime) {
6487 continue;
6488 }
Romain Guy06882f82009-06-10 13:36:04 -07006489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006490 lastKeyTime = nextKeyTime;
6491 nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY;
6492 keyRepeatCount++;
6493 if (DEBUG_INPUT) Log.v(
6494 TAG, "Key repeat: count=" + keyRepeatCount
6495 + ", next @ " + nextKeyTime);
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07006496 KeyEvent newEvent;
6497 if (downTime != 0 && (downTime
6498 + ViewConfiguration.getLongPressTimeout())
6499 <= curTime) {
6500 newEvent = KeyEvent.changeTimeRepeat(lastKey,
6501 curTime, keyRepeatCount,
6502 lastKey.getFlags() | KeyEvent.FLAG_LONG_PRESS);
6503 downTime = 0;
6504 } else {
6505 newEvent = KeyEvent.changeTimeRepeat(lastKey,
6506 curTime, keyRepeatCount);
6507 }
6508 dispatchKey(newEvent, 0, 0);
Romain Guy06882f82009-06-10 13:36:04 -07006509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006510 } else {
6511 curTime = SystemClock.uptimeMillis();
Romain Guy06882f82009-06-10 13:36:04 -07006512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006513 lastKeyTime = curTime;
6514 nextKeyTime = curTime + LONG_WAIT;
6515 }
Romain Guy06882f82009-06-10 13:36:04 -07006516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006517 } catch (Exception e) {
6518 Log.e(TAG,
6519 "Input thread received uncaught exception: " + e, e);
6520 }
6521 }
6522 }
6523 }
6524
6525 // -------------------------------------------------------------
6526 // Client Session State
6527 // -------------------------------------------------------------
6528
6529 private final class Session extends IWindowSession.Stub
6530 implements IBinder.DeathRecipient {
6531 final IInputMethodClient mClient;
6532 final IInputContext mInputContext;
6533 final int mUid;
6534 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006535 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006536 SurfaceSession mSurfaceSession;
6537 int mNumWindow = 0;
6538 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006540 /**
6541 * Current pointer move event being dispatched to client window... must
6542 * hold key lock to access.
6543 */
6544 QueuedEvent mPendingPointerMove;
6545 WindowState mPendingPointerWindow;
Romain Guy06882f82009-06-10 13:36:04 -07006546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006547 /**
6548 * Current trackball move event being dispatched to client window... must
6549 * hold key lock to access.
6550 */
6551 QueuedEvent mPendingTrackballMove;
6552 WindowState mPendingTrackballWindow;
6553
6554 public Session(IInputMethodClient client, IInputContext inputContext) {
6555 mClient = client;
6556 mInputContext = inputContext;
6557 mUid = Binder.getCallingUid();
6558 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006559 StringBuilder sb = new StringBuilder();
6560 sb.append("Session{");
6561 sb.append(Integer.toHexString(System.identityHashCode(this)));
6562 sb.append(" uid ");
6563 sb.append(mUid);
6564 sb.append("}");
6565 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006567 synchronized (mWindowMap) {
6568 if (mInputMethodManager == null && mHaveInputMethods) {
6569 IBinder b = ServiceManager.getService(
6570 Context.INPUT_METHOD_SERVICE);
6571 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6572 }
6573 }
6574 long ident = Binder.clearCallingIdentity();
6575 try {
6576 // Note: it is safe to call in to the input method manager
6577 // here because we are not holding our lock.
6578 if (mInputMethodManager != null) {
6579 mInputMethodManager.addClient(client, inputContext,
6580 mUid, mPid);
6581 } else {
6582 client.setUsingInputMethod(false);
6583 }
6584 client.asBinder().linkToDeath(this, 0);
6585 } catch (RemoteException e) {
6586 // The caller has died, so we can just forget about this.
6587 try {
6588 if (mInputMethodManager != null) {
6589 mInputMethodManager.removeClient(client);
6590 }
6591 } catch (RemoteException ee) {
6592 }
6593 } finally {
6594 Binder.restoreCallingIdentity(ident);
6595 }
6596 }
Romain Guy06882f82009-06-10 13:36:04 -07006597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006598 @Override
6599 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6600 throws RemoteException {
6601 try {
6602 return super.onTransact(code, data, reply, flags);
6603 } catch (RuntimeException e) {
6604 // Log all 'real' exceptions thrown to the caller
6605 if (!(e instanceof SecurityException)) {
6606 Log.e(TAG, "Window Session Crash", e);
6607 }
6608 throw e;
6609 }
6610 }
6611
6612 public void binderDied() {
6613 // Note: it is safe to call in to the input method manager
6614 // here because we are not holding our lock.
6615 try {
6616 if (mInputMethodManager != null) {
6617 mInputMethodManager.removeClient(mClient);
6618 }
6619 } catch (RemoteException e) {
6620 }
6621 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006622 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006623 mClientDead = true;
6624 killSessionLocked();
6625 }
6626 }
6627
6628 public int add(IWindow window, WindowManager.LayoutParams attrs,
6629 int viewVisibility, Rect outContentInsets) {
6630 return addWindow(this, window, attrs, viewVisibility, outContentInsets);
6631 }
Romain Guy06882f82009-06-10 13:36:04 -07006632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006633 public void remove(IWindow window) {
6634 removeWindow(this, window);
6635 }
Romain Guy06882f82009-06-10 13:36:04 -07006636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006637 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6638 int requestedWidth, int requestedHeight, int viewFlags,
6639 boolean insetsPending, Rect outFrame, Rect outContentInsets,
6640 Rect outVisibleInsets, Surface outSurface) {
6641 return relayoutWindow(this, window, attrs,
6642 requestedWidth, requestedHeight, viewFlags, insetsPending,
6643 outFrame, outContentInsets, outVisibleInsets, outSurface);
6644 }
Romain Guy06882f82009-06-10 13:36:04 -07006645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006646 public void setTransparentRegion(IWindow window, Region region) {
6647 setTransparentRegionWindow(this, window, region);
6648 }
Romain Guy06882f82009-06-10 13:36:04 -07006649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006650 public void setInsets(IWindow window, int touchableInsets,
6651 Rect contentInsets, Rect visibleInsets) {
6652 setInsetsWindow(this, window, touchableInsets, contentInsets,
6653 visibleInsets);
6654 }
Romain Guy06882f82009-06-10 13:36:04 -07006655
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006656 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6657 getWindowDisplayFrame(this, window, outDisplayFrame);
6658 }
Romain Guy06882f82009-06-10 13:36:04 -07006659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006660 public void finishDrawing(IWindow window) {
6661 if (localLOGV) Log.v(
6662 TAG, "IWindow finishDrawing called for " + window);
6663 finishDrawingWindow(this, window);
6664 }
6665
6666 public void finishKey(IWindow window) {
6667 if (localLOGV) Log.v(
6668 TAG, "IWindow finishKey called for " + window);
6669 mKeyWaiter.finishedKey(this, window, false,
6670 KeyWaiter.RETURN_NOTHING);
6671 }
6672
6673 public MotionEvent getPendingPointerMove(IWindow window) {
6674 if (localLOGV) Log.v(
6675 TAG, "IWindow getPendingMotionEvent called for " + window);
6676 return mKeyWaiter.finishedKey(this, window, false,
6677 KeyWaiter.RETURN_PENDING_POINTER);
6678 }
Romain Guy06882f82009-06-10 13:36:04 -07006679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006680 public MotionEvent getPendingTrackballMove(IWindow window) {
6681 if (localLOGV) Log.v(
6682 TAG, "IWindow getPendingMotionEvent called for " + window);
6683 return mKeyWaiter.finishedKey(this, window, false,
6684 KeyWaiter.RETURN_PENDING_TRACKBALL);
6685 }
6686
6687 public void setInTouchMode(boolean mode) {
6688 synchronized(mWindowMap) {
6689 mInTouchMode = mode;
6690 }
6691 }
6692
6693 public boolean getInTouchMode() {
6694 synchronized(mWindowMap) {
6695 return mInTouchMode;
6696 }
6697 }
6698
6699 public boolean performHapticFeedback(IWindow window, int effectId,
6700 boolean always) {
6701 synchronized(mWindowMap) {
6702 long ident = Binder.clearCallingIdentity();
6703 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006704 return mPolicy.performHapticFeedbackLw(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006705 windowForClientLocked(this, window), effectId, always);
6706 } finally {
6707 Binder.restoreCallingIdentity(ident);
6708 }
6709 }
6710 }
Romain Guy06882f82009-06-10 13:36:04 -07006711
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006712 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006713 synchronized(mWindowMap) {
6714 long ident = Binder.clearCallingIdentity();
6715 try {
6716 setWindowWallpaperPositionLocked(windowForClientLocked(this, window),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006717 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006718 } finally {
6719 Binder.restoreCallingIdentity(ident);
6720 }
6721 }
6722 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006723
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006724 public void wallpaperOffsetsComplete(IBinder window) {
6725 WindowManagerService.this.wallpaperOffsetsComplete(window);
6726 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006727
Dianne Hackborn75804932009-10-20 20:15:20 -07006728 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6729 int z, Bundle extras, boolean sync) {
6730 synchronized(mWindowMap) {
6731 long ident = Binder.clearCallingIdentity();
6732 try {
6733 return sendWindowWallpaperCommandLocked(
6734 windowForClientLocked(this, window),
6735 action, x, y, z, extras, sync);
6736 } finally {
6737 Binder.restoreCallingIdentity(ident);
6738 }
6739 }
6740 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006741
Dianne Hackborn75804932009-10-20 20:15:20 -07006742 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6743 WindowManagerService.this.wallpaperCommandComplete(window, result);
6744 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006745
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006746 void windowAddedLocked() {
6747 if (mSurfaceSession == null) {
6748 if (localLOGV) Log.v(
6749 TAG, "First window added to " + this + ", creating SurfaceSession");
6750 mSurfaceSession = new SurfaceSession();
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006751 if (SHOW_TRANSACTIONS) Log.i(
6752 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006753 mSessions.add(this);
6754 }
6755 mNumWindow++;
6756 }
6757
6758 void windowRemovedLocked() {
6759 mNumWindow--;
6760 killSessionLocked();
6761 }
Romain Guy06882f82009-06-10 13:36:04 -07006762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006763 void killSessionLocked() {
6764 if (mNumWindow <= 0 && mClientDead) {
6765 mSessions.remove(this);
6766 if (mSurfaceSession != null) {
6767 if (localLOGV) Log.v(
6768 TAG, "Last window removed from " + this
6769 + ", destroying " + mSurfaceSession);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006770 if (SHOW_TRANSACTIONS) Log.i(
6771 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006772 try {
6773 mSurfaceSession.kill();
6774 } catch (Exception e) {
6775 Log.w(TAG, "Exception thrown when killing surface session "
6776 + mSurfaceSession + " in session " + this
6777 + ": " + e.toString());
6778 }
6779 mSurfaceSession = null;
6780 }
6781 }
6782 }
Romain Guy06882f82009-06-10 13:36:04 -07006783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006784 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006785 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6786 pw.print(" mClientDead="); pw.print(mClientDead);
6787 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
6788 if (mPendingPointerWindow != null || mPendingPointerMove != null) {
6789 pw.print(prefix);
6790 pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow);
6791 pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove);
6792 }
6793 if (mPendingTrackballWindow != null || mPendingTrackballMove != null) {
6794 pw.print(prefix);
6795 pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow);
6796 pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove);
6797 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006798 }
6799
6800 @Override
6801 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006802 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006803 }
6804 }
6805
6806 // -------------------------------------------------------------
6807 // Client Window State
6808 // -------------------------------------------------------------
6809
6810 private final class WindowState implements WindowManagerPolicy.WindowState {
6811 final Session mSession;
6812 final IWindow mClient;
6813 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006814 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006815 AppWindowToken mAppToken;
6816 AppWindowToken mTargetAppToken;
6817 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6818 final DeathRecipient mDeathRecipient;
6819 final WindowState mAttachedWindow;
6820 final ArrayList mChildWindows = new ArrayList();
6821 final int mBaseLayer;
6822 final int mSubLayer;
6823 final boolean mLayoutAttached;
6824 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006825 final boolean mIsWallpaper;
6826 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006827 int mViewVisibility;
6828 boolean mPolicyVisibility = true;
6829 boolean mPolicyVisibilityAfterAnim = true;
6830 boolean mAppFreezing;
6831 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006832 boolean mReportDestroySurface;
6833 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006834 boolean mAttachedHidden; // is our parent window hidden?
6835 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006836 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006837 int mRequestedWidth;
6838 int mRequestedHeight;
6839 int mLastRequestedWidth;
6840 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006841 int mLayer;
6842 int mAnimLayer;
6843 int mLastLayer;
6844 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006845 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006846 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006847
6848 WindowState mNextOutsideTouch;
Romain Guy06882f82009-06-10 13:36:04 -07006849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006850 // Actual frame shown on-screen (may be modified by animation)
6851 final Rect mShownFrame = new Rect();
6852 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006854 /**
6855 * Insets that determine the actually visible area
6856 */
6857 final Rect mVisibleInsets = new Rect();
6858 final Rect mLastVisibleInsets = new Rect();
6859 boolean mVisibleInsetsChanged;
6860
6861 /**
6862 * Insets that are covered by system windows
6863 */
6864 final Rect mContentInsets = new Rect();
6865 final Rect mLastContentInsets = new Rect();
6866 boolean mContentInsetsChanged;
6867
6868 /**
6869 * Set to true if we are waiting for this window to receive its
6870 * given internal insets before laying out other windows based on it.
6871 */
6872 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006874 /**
6875 * These are the content insets that were given during layout for
6876 * this window, to be applied to windows behind it.
6877 */
6878 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006880 /**
6881 * These are the visible insets that were given during layout for
6882 * this window, to be applied to windows behind it.
6883 */
6884 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006886 /**
6887 * Flag indicating whether the touchable region should be adjusted by
6888 * the visible insets; if false the area outside the visible insets is
6889 * NOT touchable, so we must use those to adjust the frame during hit
6890 * tests.
6891 */
6892 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006894 // Current transformation being applied.
6895 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6896 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6897 float mHScale=1, mVScale=1;
6898 float mLastHScale=1, mLastVScale=1;
6899 final Matrix mTmpMatrix = new Matrix();
6900
6901 // "Real" frame that the application sees.
6902 final Rect mFrame = new Rect();
6903 final Rect mLastFrame = new Rect();
6904
6905 final Rect mContainingFrame = new Rect();
6906 final Rect mDisplayFrame = new Rect();
6907 final Rect mContentFrame = new Rect();
6908 final Rect mVisibleFrame = new Rect();
6909
6910 float mShownAlpha = 1;
6911 float mAlpha = 1;
6912 float mLastAlpha = 1;
6913
6914 // Set to true if, when the window gets displayed, it should perform
6915 // an enter animation.
6916 boolean mEnterAnimationPending;
6917
6918 // Currently running animation.
6919 boolean mAnimating;
6920 boolean mLocalAnimating;
6921 Animation mAnimation;
6922 boolean mAnimationIsEntrance;
6923 boolean mHasTransformation;
6924 boolean mHasLocalTransformation;
6925 final Transformation mTransformation = new Transformation();
6926
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006927 // If a window showing a wallpaper: the requested offset for the
6928 // wallpaper; if a wallpaper window: the currently applied offset.
6929 float mWallpaperX = -1;
6930 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006931
6932 // If a window showing a wallpaper: what fraction of the offset
6933 // range corresponds to a full virtual screen.
6934 float mWallpaperXStep = -1;
6935 float mWallpaperYStep = -1;
6936
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006937 // Wallpaper windows: pixels offset based on above variables.
6938 int mXOffset;
6939 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006941 // This is set after IWindowSession.relayout() has been called at
6942 // least once for the window. It allows us to detect the situation
6943 // where we don't yet have a surface, but should have one soon, so
6944 // we can give the window focus before waiting for the relayout.
6945 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006947 // This is set after the Surface has been created but before the
6948 // window has been drawn. During this time the surface is hidden.
6949 boolean mDrawPending;
6950
6951 // This is set after the window has finished drawing for the first
6952 // time but before its surface is shown. The surface will be
6953 // displayed when the next layout is run.
6954 boolean mCommitDrawPending;
6955
6956 // This is set during the time after the window's drawing has been
6957 // committed, and before its surface is actually shown. It is used
6958 // to delay showing the surface until all windows in a token are ready
6959 // to be shown.
6960 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006961
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006962 // Set when the window has been shown in the screen the first time.
6963 boolean mHasDrawn;
6964
6965 // Currently running an exit animation?
6966 boolean mExiting;
6967
6968 // Currently on the mDestroySurface list?
6969 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006971 // Completely remove from window manager after exit animation?
6972 boolean mRemoveOnExit;
6973
6974 // Set when the orientation is changing and this window has not yet
6975 // been updated for the new orientation.
6976 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006978 // Is this window now (or just being) removed?
6979 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006981 WindowState(Session s, IWindow c, WindowToken token,
6982 WindowState attachedWindow, WindowManager.LayoutParams a,
6983 int viewVisibility) {
6984 mSession = s;
6985 mClient = c;
6986 mToken = token;
6987 mAttrs.copyFrom(a);
6988 mViewVisibility = viewVisibility;
6989 DeathRecipient deathRecipient = new DeathRecipient();
6990 mAlpha = a.alpha;
6991 if (localLOGV) Log.v(
6992 TAG, "Window " + this + " client=" + c.asBinder()
6993 + " token=" + token + " (" + mAttrs.token + ")");
6994 try {
6995 c.asBinder().linkToDeath(deathRecipient, 0);
6996 } catch (RemoteException e) {
6997 mDeathRecipient = null;
6998 mAttachedWindow = null;
6999 mLayoutAttached = false;
7000 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007001 mIsWallpaper = false;
7002 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007003 mBaseLayer = 0;
7004 mSubLayer = 0;
7005 return;
7006 }
7007 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07007008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007009 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
7010 mAttrs.type <= LAST_SUB_WINDOW)) {
7011 // The multiplier here is to reserve space for multiple
7012 // windows in the same type layer.
7013 mBaseLayer = mPolicy.windowTypeToLayerLw(
7014 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
7015 + TYPE_LAYER_OFFSET;
7016 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
7017 mAttachedWindow = attachedWindow;
7018 mAttachedWindow.mChildWindows.add(this);
7019 mLayoutAttached = mAttrs.type !=
7020 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
7021 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
7022 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007023 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
7024 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007025 } else {
7026 // The multiplier here is to reserve space for multiple
7027 // windows in the same type layer.
7028 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
7029 * TYPE_LAYER_MULTIPLIER
7030 + TYPE_LAYER_OFFSET;
7031 mSubLayer = 0;
7032 mAttachedWindow = null;
7033 mLayoutAttached = false;
7034 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
7035 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007036 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
7037 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007038 }
7039
7040 WindowState appWin = this;
7041 while (appWin.mAttachedWindow != null) {
7042 appWin = mAttachedWindow;
7043 }
7044 WindowToken appToken = appWin.mToken;
7045 while (appToken.appWindowToken == null) {
7046 WindowToken parent = mTokenMap.get(appToken.token);
7047 if (parent == null || appToken == parent) {
7048 break;
7049 }
7050 appToken = parent;
7051 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007052 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007053 mAppToken = appToken.appWindowToken;
7054
7055 mSurface = null;
7056 mRequestedWidth = 0;
7057 mRequestedHeight = 0;
7058 mLastRequestedWidth = 0;
7059 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007060 mXOffset = 0;
7061 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007062 mLayer = 0;
7063 mAnimLayer = 0;
7064 mLastLayer = 0;
7065 }
7066
7067 void attach() {
7068 if (localLOGV) Log.v(
7069 TAG, "Attaching " + this + " token=" + mToken
7070 + ", list=" + mToken.windows);
7071 mSession.windowAddedLocked();
7072 }
7073
7074 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7075 mHaveFrame = true;
7076
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007077 final Rect container = mContainingFrame;
7078 container.set(pf);
7079
7080 final Rect display = mDisplayFrame;
7081 display.set(df);
7082
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007083 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007084 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007085 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7086 display.intersect(mCompatibleScreenFrame);
7087 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007088 }
7089
7090 final int pw = container.right - container.left;
7091 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007092
7093 int w,h;
7094 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7095 w = mAttrs.width < 0 ? pw : mAttrs.width;
7096 h = mAttrs.height< 0 ? ph : mAttrs.height;
7097 } else {
7098 w = mAttrs.width == mAttrs.FILL_PARENT ? pw : mRequestedWidth;
7099 h = mAttrs.height== mAttrs.FILL_PARENT ? ph : mRequestedHeight;
7100 }
Romain Guy06882f82009-06-10 13:36:04 -07007101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007102 final Rect content = mContentFrame;
7103 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007105 final Rect visible = mVisibleFrame;
7106 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007108 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007109 final int fw = frame.width();
7110 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007112 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7113 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7114
7115 Gravity.apply(mAttrs.gravity, w, h, container,
7116 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7117 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7118
7119 //System.out.println("Out: " + mFrame);
7120
7121 // Now make sure the window fits in the overall display.
7122 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007124 // Make sure the content and visible frames are inside of the
7125 // final window frame.
7126 if (content.left < frame.left) content.left = frame.left;
7127 if (content.top < frame.top) content.top = frame.top;
7128 if (content.right > frame.right) content.right = frame.right;
7129 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7130 if (visible.left < frame.left) visible.left = frame.left;
7131 if (visible.top < frame.top) visible.top = frame.top;
7132 if (visible.right > frame.right) visible.right = frame.right;
7133 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007135 final Rect contentInsets = mContentInsets;
7136 contentInsets.left = content.left-frame.left;
7137 contentInsets.top = content.top-frame.top;
7138 contentInsets.right = frame.right-content.right;
7139 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007141 final Rect visibleInsets = mVisibleInsets;
7142 visibleInsets.left = visible.left-frame.left;
7143 visibleInsets.top = visible.top-frame.top;
7144 visibleInsets.right = frame.right-visible.right;
7145 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007146
Dianne Hackborn284ac932009-08-28 10:34:25 -07007147 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7148 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007149 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007150 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007152 if (localLOGV) {
7153 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7154 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
7155 Log.v(TAG, "Resolving (mRequestedWidth="
7156 + mRequestedWidth + ", mRequestedheight="
7157 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7158 + "): frame=" + mFrame.toShortString()
7159 + " ci=" + contentInsets.toShortString()
7160 + " vi=" + visibleInsets.toShortString());
7161 //}
7162 }
7163 }
Romain Guy06882f82009-06-10 13:36:04 -07007164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007165 public Rect getFrameLw() {
7166 return mFrame;
7167 }
7168
7169 public Rect getShownFrameLw() {
7170 return mShownFrame;
7171 }
7172
7173 public Rect getDisplayFrameLw() {
7174 return mDisplayFrame;
7175 }
7176
7177 public Rect getContentFrameLw() {
7178 return mContentFrame;
7179 }
7180
7181 public Rect getVisibleFrameLw() {
7182 return mVisibleFrame;
7183 }
7184
7185 public boolean getGivenInsetsPendingLw() {
7186 return mGivenInsetsPending;
7187 }
7188
7189 public Rect getGivenContentInsetsLw() {
7190 return mGivenContentInsets;
7191 }
Romain Guy06882f82009-06-10 13:36:04 -07007192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007193 public Rect getGivenVisibleInsetsLw() {
7194 return mGivenVisibleInsets;
7195 }
Romain Guy06882f82009-06-10 13:36:04 -07007196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007197 public WindowManager.LayoutParams getAttrs() {
7198 return mAttrs;
7199 }
7200
7201 public int getSurfaceLayer() {
7202 return mLayer;
7203 }
Romain Guy06882f82009-06-10 13:36:04 -07007204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007205 public IApplicationToken getAppToken() {
7206 return mAppToken != null ? mAppToken.appToken : null;
7207 }
7208
7209 public boolean hasAppShownWindows() {
7210 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7211 }
7212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007213 public void setAnimation(Animation anim) {
7214 if (localLOGV) Log.v(
7215 TAG, "Setting animation in " + this + ": " + anim);
7216 mAnimating = false;
7217 mLocalAnimating = false;
7218 mAnimation = anim;
7219 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7220 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7221 }
7222
7223 public void clearAnimation() {
7224 if (mAnimation != null) {
7225 mAnimating = true;
7226 mLocalAnimating = false;
7227 mAnimation = null;
7228 }
7229 }
Romain Guy06882f82009-06-10 13:36:04 -07007230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007231 Surface createSurfaceLocked() {
7232 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007233 mReportDestroySurface = false;
7234 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007235 mDrawPending = true;
7236 mCommitDrawPending = false;
7237 mReadyToShow = false;
7238 if (mAppToken != null) {
7239 mAppToken.allDrawn = false;
7240 }
7241
7242 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07007243 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007244 flags |= Surface.PUSH_BUFFERS;
7245 }
7246
7247 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7248 flags |= Surface.SECURE;
7249 }
7250 if (DEBUG_VISIBILITY) Log.v(
7251 TAG, "Creating surface in session "
7252 + mSession.mSurfaceSession + " window " + this
7253 + " w=" + mFrame.width()
7254 + " h=" + mFrame.height() + " format="
7255 + mAttrs.format + " flags=" + flags);
7256
7257 int w = mFrame.width();
7258 int h = mFrame.height();
7259 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7260 // for a scaled surface, we always want the requested
7261 // size.
7262 w = mRequestedWidth;
7263 h = mRequestedHeight;
7264 }
7265
Romain Guy9825ec62009-10-01 00:58:09 -07007266 // Something is wrong and SurfaceFlinger will not like this,
7267 // try to revert to sane values
7268 if (w <= 0) w = 1;
7269 if (h <= 0) h = 1;
7270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007271 try {
7272 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007273 mSession.mSurfaceSession, mSession.mPid,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007274 0, w, h, mAttrs.format, flags);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007275 if (SHOW_TRANSACTIONS) Log.i(TAG, " CREATE SURFACE "
7276 + mSurface + " IN SESSION "
7277 + mSession.mSurfaceSession
7278 + ": pid=" + mSession.mPid + " format="
7279 + mAttrs.format + " flags=0x"
7280 + Integer.toHexString(flags));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007281 } catch (Surface.OutOfResourcesException e) {
7282 Log.w(TAG, "OutOfResourcesException creating surface");
7283 reclaimSomeSurfaceMemoryLocked(this, "create");
7284 return null;
7285 } catch (Exception e) {
7286 Log.e(TAG, "Exception creating surface", e);
7287 return null;
7288 }
Romain Guy06882f82009-06-10 13:36:04 -07007289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007290 if (localLOGV) Log.v(
7291 TAG, "Got surface: " + mSurface
7292 + ", set left=" + mFrame.left + " top=" + mFrame.top
7293 + ", animLayer=" + mAnimLayer);
7294 if (SHOW_TRANSACTIONS) {
7295 Log.i(TAG, ">>> OPEN TRANSACTION");
7296 Log.i(TAG, " SURFACE " + mSurface + ": CREATE ("
7297 + mAttrs.getTitle() + ") pos=(" +
7298 mFrame.left + "," + mFrame.top + ") (" +
7299 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7300 mAnimLayer + " HIDE");
7301 }
7302 Surface.openTransaction();
7303 try {
7304 try {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007305 mSurface.setPosition(mFrame.left + mXOffset,
7306 mFrame.top + mYOffset);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007307 mSurface.setLayer(mAnimLayer);
7308 mSurface.hide();
7309 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007310 if (SHOW_TRANSACTIONS) Log.i(TAG, " SURFACE "
7311 + mSurface + ": DITHER");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007312 mSurface.setFlags(Surface.SURFACE_DITHER,
7313 Surface.SURFACE_DITHER);
7314 }
7315 } catch (RuntimeException e) {
7316 Log.w(TAG, "Error creating surface in " + w, e);
7317 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7318 }
7319 mLastHidden = true;
7320 } finally {
7321 if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION");
7322 Surface.closeTransaction();
7323 }
7324 if (localLOGV) Log.v(
7325 TAG, "Created surface " + this);
7326 }
7327 return mSurface;
7328 }
Romain Guy06882f82009-06-10 13:36:04 -07007329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007330 void destroySurfaceLocked() {
7331 // Window is no longer on-screen, so can no longer receive
7332 // key events... if we were waiting for it to finish
7333 // handling a key event, the wait is over!
7334 mKeyWaiter.finishedKey(mSession, mClient, true,
7335 KeyWaiter.RETURN_NOTHING);
7336 mKeyWaiter.releasePendingPointerLocked(mSession);
7337 mKeyWaiter.releasePendingTrackballLocked(mSession);
7338
7339 if (mAppToken != null && this == mAppToken.startingWindow) {
7340 mAppToken.startingDisplayed = false;
7341 }
Romain Guy06882f82009-06-10 13:36:04 -07007342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007343 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007344 mDrawPending = false;
7345 mCommitDrawPending = false;
7346 mReadyToShow = false;
7347
7348 int i = mChildWindows.size();
7349 while (i > 0) {
7350 i--;
7351 WindowState c = (WindowState)mChildWindows.get(i);
7352 c.mAttachedHidden = true;
7353 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007354
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007355 if (mReportDestroySurface) {
7356 mReportDestroySurface = false;
7357 mSurfacePendingDestroy = true;
7358 try {
7359 mClient.dispatchGetNewSurface();
7360 // We'll really destroy on the next time around.
7361 return;
7362 } catch (RemoteException e) {
7363 }
7364 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007366 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007367 if (DEBUG_VISIBILITY) {
7368 RuntimeException e = new RuntimeException();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07007369 if (!HIDE_STACK_CRAWLS) e.fillInStackTrace();
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007370 Log.w(TAG, "Window " + this + " destroying surface "
7371 + mSurface + ", session " + mSession, e);
7372 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007373 if (SHOW_TRANSACTIONS) {
7374 RuntimeException ex = new RuntimeException();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07007375 if (!HIDE_STACK_CRAWLS) ex.fillInStackTrace();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007376 Log.i(TAG, " SURFACE " + mSurface + ": DESTROY ("
7377 + mAttrs.getTitle() + ")", ex);
7378 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007379 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007380 } catch (RuntimeException e) {
7381 Log.w(TAG, "Exception thrown when destroying Window " + this
7382 + " surface " + mSurface + " session " + mSession
7383 + ": " + e.toString());
7384 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007386 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007387 }
7388 }
7389
7390 boolean finishDrawingLocked() {
7391 if (mDrawPending) {
7392 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.v(
7393 TAG, "finishDrawingLocked: " + mSurface);
7394 mCommitDrawPending = true;
7395 mDrawPending = false;
7396 return true;
7397 }
7398 return false;
7399 }
7400
7401 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007402 boolean commitFinishDrawingLocked(long currentTime) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007403 //Log.i(TAG, "commitFinishDrawingLocked: " + mSurface);
7404 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007405 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007406 }
7407 mCommitDrawPending = false;
7408 mReadyToShow = true;
7409 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7410 final AppWindowToken atoken = mAppToken;
7411 if (atoken == null || atoken.allDrawn || starting) {
7412 performShowLocked();
7413 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007414 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007415 }
7416
7417 // This must be called while inside a transaction.
7418 boolean performShowLocked() {
7419 if (DEBUG_VISIBILITY) {
7420 RuntimeException e = new RuntimeException();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07007421 if (!HIDE_STACK_CRAWLS) e.fillInStackTrace();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007422 Log.v(TAG, "performShow on " + this
7423 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7424 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7425 }
7426 if (mReadyToShow && isReadyForDisplay()) {
7427 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.i(
7428 TAG, " SURFACE " + mSurface + ": SHOW (performShowLocked)");
7429 if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + this
7430 + " during animation: policyVis=" + mPolicyVisibility
7431 + " attHidden=" + mAttachedHidden
7432 + " tok.hiddenRequested="
7433 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007434 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007435 + (mAppToken != null ? mAppToken.hidden : false)
7436 + " animating=" + mAnimating
7437 + " tok animating="
7438 + (mAppToken != null ? mAppToken.animating : false));
7439 if (!showSurfaceRobustlyLocked(this)) {
7440 return false;
7441 }
7442 mLastAlpha = -1;
7443 mHasDrawn = true;
7444 mLastHidden = false;
7445 mReadyToShow = false;
7446 enableScreenIfNeededLocked();
7447
7448 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007450 int i = mChildWindows.size();
7451 while (i > 0) {
7452 i--;
7453 WindowState c = (WindowState)mChildWindows.get(i);
7454 if (c.mSurface != null && c.mAttachedHidden) {
7455 c.mAttachedHidden = false;
7456 c.performShowLocked();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007457 // It hadn't been shown, which means layout not
7458 // performed on it, so now we want to make sure to
7459 // do a layout. If called from within the transaction
7460 // loop, this will cause it to restart with a new
7461 // layout.
7462 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007463 }
7464 }
Romain Guy06882f82009-06-10 13:36:04 -07007465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007466 if (mAttrs.type != TYPE_APPLICATION_STARTING
7467 && mAppToken != null) {
7468 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007469
Dianne Hackborn248b1882009-09-16 16:46:44 -07007470 if (mAppToken.startingData != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007471 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Log.v(TAG,
7472 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007473 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007474 // If this initial window is animating, stop it -- we
7475 // will do an animation to reveal it from behind the
7476 // starting window, so there is no need for it to also
7477 // be doing its own stuff.
7478 if (mAnimation != null) {
7479 mAnimation = null;
7480 // Make sure we clean up the animation.
7481 mAnimating = true;
7482 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007483 mFinishedStarting.add(mAppToken);
7484 mH.sendEmptyMessage(H.FINISHED_STARTING);
7485 }
7486 mAppToken.updateReportedVisibilityLocked();
7487 }
7488 }
7489 return true;
7490 }
Romain Guy06882f82009-06-10 13:36:04 -07007491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007492 // This must be called while inside a transaction. Returns true if
7493 // there is more animation to run.
7494 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007495 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007496 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007498 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7499 mHasTransformation = true;
7500 mHasLocalTransformation = true;
7501 if (!mLocalAnimating) {
7502 if (DEBUG_ANIM) Log.v(
7503 TAG, "Starting animation in " + this +
7504 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7505 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7506 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7507 mAnimation.setStartTime(currentTime);
7508 mLocalAnimating = true;
7509 mAnimating = true;
7510 }
7511 mTransformation.clear();
7512 final boolean more = mAnimation.getTransformation(
7513 currentTime, mTransformation);
7514 if (DEBUG_ANIM) Log.v(
7515 TAG, "Stepped animation in " + this +
7516 ": more=" + more + ", xform=" + mTransformation);
7517 if (more) {
7518 // we're not done!
7519 return true;
7520 }
7521 if (DEBUG_ANIM) Log.v(
7522 TAG, "Finished animation in " + this +
7523 " @ " + currentTime);
7524 mAnimation = null;
7525 //WindowManagerService.this.dump();
7526 }
7527 mHasLocalTransformation = false;
7528 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007529 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007530 // When our app token is animating, we kind-of pretend like
7531 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7532 // part of this check means that we will only do this if
7533 // our window is not currently exiting, or it is not
7534 // locally animating itself. The idea being that one that
7535 // is exiting and doing a local animation should be removed
7536 // once that animation is done.
7537 mAnimating = true;
7538 mHasTransformation = true;
7539 mTransformation.clear();
7540 return false;
7541 } else if (mHasTransformation) {
7542 // Little trick to get through the path below to act like
7543 // we have finished an animation.
7544 mAnimating = true;
7545 } else if (isAnimating()) {
7546 mAnimating = true;
7547 }
7548 } else if (mAnimation != null) {
7549 // If the display is frozen, and there is a pending animation,
7550 // clear it and make sure we run the cleanup code.
7551 mAnimating = true;
7552 mLocalAnimating = true;
7553 mAnimation = null;
7554 }
Romain Guy06882f82009-06-10 13:36:04 -07007555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007556 if (!mAnimating && !mLocalAnimating) {
7557 return false;
7558 }
7559
7560 if (DEBUG_ANIM) Log.v(
7561 TAG, "Animation done in " + this + ": exiting=" + mExiting
7562 + ", reportedVisible="
7563 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007565 mAnimating = false;
7566 mLocalAnimating = false;
7567 mAnimation = null;
7568 mAnimLayer = mLayer;
7569 if (mIsImWindow) {
7570 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007571 } else if (mIsWallpaper) {
7572 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007573 }
7574 if (DEBUG_LAYERS) Log.v(TAG, "Stepping win " + this
7575 + " anim layer: " + mAnimLayer);
7576 mHasTransformation = false;
7577 mHasLocalTransformation = false;
7578 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007579 if (!mPolicyVisibility) {
7580 // Window is no longer visible -- make sure if we were waiting
7581 // for it to be displayed before enabling the display, that
7582 // we allow the display to be enabled now.
7583 enableScreenIfNeededLocked();
7584 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007585 mTransformation.clear();
7586 if (mHasDrawn
7587 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7588 && mAppToken != null
7589 && mAppToken.firstWindowDrawn
7590 && mAppToken.startingData != null) {
7591 if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Finish starting "
7592 + mToken + ": first real window done animating");
7593 mFinishedStarting.add(mAppToken);
7594 mH.sendEmptyMessage(H.FINISHED_STARTING);
7595 }
Romain Guy06882f82009-06-10 13:36:04 -07007596
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007597 finishExit();
7598
7599 if (mAppToken != null) {
7600 mAppToken.updateReportedVisibilityLocked();
7601 }
7602
7603 return false;
7604 }
7605
7606 void finishExit() {
7607 if (DEBUG_ANIM) Log.v(
7608 TAG, "finishExit in " + this
7609 + ": exiting=" + mExiting
7610 + " remove=" + mRemoveOnExit
7611 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007613 final int N = mChildWindows.size();
7614 for (int i=0; i<N; i++) {
7615 ((WindowState)mChildWindows.get(i)).finishExit();
7616 }
Romain Guy06882f82009-06-10 13:36:04 -07007617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007618 if (!mExiting) {
7619 return;
7620 }
Romain Guy06882f82009-06-10 13:36:04 -07007621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007622 if (isWindowAnimating()) {
7623 return;
7624 }
7625
7626 if (localLOGV) Log.v(
7627 TAG, "Exit animation finished in " + this
7628 + ": remove=" + mRemoveOnExit);
7629 if (mSurface != null) {
7630 mDestroySurface.add(this);
7631 mDestroying = true;
7632 if (SHOW_TRANSACTIONS) Log.i(
7633 TAG, " SURFACE " + mSurface + ": HIDE (finishExit)");
7634 try {
7635 mSurface.hide();
7636 } catch (RuntimeException e) {
7637 Log.w(TAG, "Error hiding surface in " + this, e);
7638 }
7639 mLastHidden = true;
7640 mKeyWaiter.releasePendingPointerLocked(mSession);
7641 }
7642 mExiting = false;
7643 if (mRemoveOnExit) {
7644 mPendingRemove.add(this);
7645 mRemoveOnExit = false;
7646 }
7647 }
Romain Guy06882f82009-06-10 13:36:04 -07007648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007649 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7650 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7651 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7652 if (dtdx < -.000001f || dtdx > .000001f) return false;
7653 if (dsdy < -.000001f || dsdy > .000001f) return false;
7654 return true;
7655 }
Romain Guy06882f82009-06-10 13:36:04 -07007656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007657 void computeShownFrameLocked() {
7658 final boolean selfTransformation = mHasLocalTransformation;
7659 Transformation attachedTransformation =
7660 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7661 ? mAttachedWindow.mTransformation : null;
7662 Transformation appTransformation =
7663 (mAppToken != null && mAppToken.hasTransformation)
7664 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007665
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007666 // Wallpapers are animated based on the "real" window they
7667 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007668 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007669 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007670 if (mWallpaperTarget.mHasLocalTransformation &&
7671 mWallpaperTarget.mAnimation != null &&
7672 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007673 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007674 if (DEBUG_WALLPAPER && attachedTransformation != null) {
7675 Log.v(TAG, "WP target attached xform: " + attachedTransformation);
7676 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007677 }
7678 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007679 mWallpaperTarget.mAppToken.hasTransformation &&
7680 mWallpaperTarget.mAppToken.animation != null &&
7681 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007682 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007683 if (DEBUG_WALLPAPER && appTransformation != null) {
7684 Log.v(TAG, "WP target app xform: " + appTransformation);
7685 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007686 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007687 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007689 if (selfTransformation || attachedTransformation != null
7690 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007691 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007692 final Rect frame = mFrame;
7693 final float tmpFloats[] = mTmpFloats;
7694 final Matrix tmpMatrix = mTmpMatrix;
7695
7696 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007697 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007698 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007699 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007700 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007701 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007702 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007703 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007704 }
7705 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007706 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007707 }
7708
7709 // "convert" it into SurfaceFlinger's format
7710 // (a 2x2 matrix + an offset)
7711 // Here we must not transform the position of the surface
7712 // since it is already included in the transformation.
7713 //Log.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007715 tmpMatrix.getValues(tmpFloats);
7716 mDsDx = tmpFloats[Matrix.MSCALE_X];
7717 mDtDx = tmpFloats[Matrix.MSKEW_X];
7718 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7719 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007720 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7721 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007722 int w = frame.width();
7723 int h = frame.height();
7724 mShownFrame.set(x, y, x+w, y+h);
7725
7726 // Now set the alpha... but because our current hardware
7727 // can't do alpha transformation on a non-opaque surface,
7728 // turn it off if we are running an animation that is also
7729 // transforming since it is more important to have that
7730 // animation be smooth.
7731 mShownAlpha = mAlpha;
7732 if (!mLimitedAlphaCompositing
7733 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7734 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7735 && x == frame.left && y == frame.top))) {
7736 //Log.i(TAG, "Applying alpha transform");
7737 if (selfTransformation) {
7738 mShownAlpha *= mTransformation.getAlpha();
7739 }
7740 if (attachedTransformation != null) {
7741 mShownAlpha *= attachedTransformation.getAlpha();
7742 }
7743 if (appTransformation != null) {
7744 mShownAlpha *= appTransformation.getAlpha();
7745 }
7746 } else {
7747 //Log.i(TAG, "Not applying alpha transform");
7748 }
Romain Guy06882f82009-06-10 13:36:04 -07007749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007750 if (localLOGV) Log.v(
7751 TAG, "Continuing animation in " + this +
7752 ": " + mShownFrame +
7753 ", alpha=" + mTransformation.getAlpha());
7754 return;
7755 }
Romain Guy06882f82009-06-10 13:36:04 -07007756
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007757 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007758 if (mXOffset != 0 || mYOffset != 0) {
7759 mShownFrame.offset(mXOffset, mYOffset);
7760 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007761 mShownAlpha = mAlpha;
7762 mDsDx = 1;
7763 mDtDx = 0;
7764 mDsDy = 0;
7765 mDtDy = 1;
7766 }
Romain Guy06882f82009-06-10 13:36:04 -07007767
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007768 /**
7769 * Is this window visible? It is not visible if there is no
7770 * surface, or we are in the process of running an exit animation
7771 * that will remove the surface, or its app token has been hidden.
7772 */
7773 public boolean isVisibleLw() {
7774 final AppWindowToken atoken = mAppToken;
7775 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7776 && (atoken == null || !atoken.hiddenRequested)
7777 && !mExiting && !mDestroying;
7778 }
7779
7780 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007781 * Like {@link #isVisibleLw}, but also counts a window that is currently
7782 * "hidden" behind the keyguard as visible. This allows us to apply
7783 * things like window flags that impact the keyguard.
7784 * XXX I am starting to think we need to have ANOTHER visibility flag
7785 * for this "hidden behind keyguard" state rather than overloading
7786 * mPolicyVisibility. Ungh.
7787 */
7788 public boolean isVisibleOrBehindKeyguardLw() {
7789 final AppWindowToken atoken = mAppToken;
7790 return mSurface != null && !mAttachedHidden
7791 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
7792 && !mExiting && !mDestroying;
7793 }
7794
7795 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007796 * Is this window visible, ignoring its app token? It is not visible
7797 * if there is no surface, or we are in the process of running an exit animation
7798 * that will remove the surface.
7799 */
7800 public boolean isWinVisibleLw() {
7801 final AppWindowToken atoken = mAppToken;
7802 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7803 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7804 && !mExiting && !mDestroying;
7805 }
7806
7807 /**
7808 * The same as isVisible(), but follows the current hidden state of
7809 * the associated app token, not the pending requested hidden state.
7810 */
7811 boolean isVisibleNow() {
7812 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007813 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007814 }
7815
7816 /**
7817 * Same as isVisible(), but we also count it as visible between the
7818 * call to IWindowSession.add() and the first relayout().
7819 */
7820 boolean isVisibleOrAdding() {
7821 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007822 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007823 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7824 && mPolicyVisibility && !mAttachedHidden
7825 && (atoken == null || !atoken.hiddenRequested)
7826 && !mExiting && !mDestroying;
7827 }
7828
7829 /**
7830 * Is this window currently on-screen? It is on-screen either if it
7831 * is visible or it is currently running an animation before no longer
7832 * being visible.
7833 */
7834 boolean isOnScreen() {
7835 final AppWindowToken atoken = mAppToken;
7836 if (atoken != null) {
7837 return mSurface != null && mPolicyVisibility && !mDestroying
7838 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007839 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007840 } else {
7841 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007842 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007843 }
7844 }
Romain Guy06882f82009-06-10 13:36:04 -07007845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007846 /**
7847 * Like isOnScreen(), but we don't return true if the window is part
7848 * of a transition that has not yet been started.
7849 */
7850 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007851 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007852 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007853 return false;
7854 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007855 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007856 final boolean animating = atoken != null
7857 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007858 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007859 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7860 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007861 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007862 }
7863
7864 /** Is the window or its container currently animating? */
7865 boolean isAnimating() {
7866 final WindowState attached = mAttachedWindow;
7867 final AppWindowToken atoken = mAppToken;
7868 return mAnimation != null
7869 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007870 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007871 (atoken.animation != null
7872 || atoken.inPendingTransaction));
7873 }
7874
7875 /** Is this window currently animating? */
7876 boolean isWindowAnimating() {
7877 return mAnimation != null;
7878 }
7879
7880 /**
7881 * Like isOnScreen, but returns false if the surface hasn't yet
7882 * been drawn.
7883 */
7884 public boolean isDisplayedLw() {
7885 final AppWindowToken atoken = mAppToken;
7886 return mSurface != null && mPolicyVisibility && !mDestroying
7887 && !mDrawPending && !mCommitDrawPending
7888 && ((!mAttachedHidden &&
7889 (atoken == null || !atoken.hiddenRequested))
7890 || mAnimating);
7891 }
7892
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007893 /**
7894 * Returns true if the window has a surface that it has drawn a
7895 * complete UI in to.
7896 */
7897 public boolean isDrawnLw() {
7898 final AppWindowToken atoken = mAppToken;
7899 return mSurface != null && !mDestroying
7900 && !mDrawPending && !mCommitDrawPending;
7901 }
7902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007903 public boolean fillsScreenLw(int screenWidth, int screenHeight,
7904 boolean shownFrame, boolean onlyOpaque) {
7905 if (mSurface == null) {
7906 return false;
7907 }
7908 if (mAppToken != null && !mAppToken.appFullscreen) {
7909 return false;
7910 }
7911 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
7912 return false;
7913 }
7914 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007915
7916 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
7917 return frame.left <= mCompatibleScreenFrame.left &&
7918 frame.top <= mCompatibleScreenFrame.top &&
7919 frame.right >= mCompatibleScreenFrame.right &&
7920 frame.bottom >= mCompatibleScreenFrame.bottom;
7921 } else {
7922 return frame.left <= 0 && frame.top <= 0
7923 && frame.right >= screenWidth
7924 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007925 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007926 }
Romain Guy06882f82009-06-10 13:36:04 -07007927
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007928 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007929 * Return true if the window is opaque and fully drawn. This indicates
7930 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007931 */
7932 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007933 return (mAttrs.format == PixelFormat.OPAQUE
7934 || mAttrs.type == TYPE_WALLPAPER)
7935 && mSurface != null && mAnimation == null
7936 && (mAppToken == null || mAppToken.animation == null)
7937 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007938 }
7939
7940 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7941 return
7942 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007943 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7944 // only if it's visible
7945 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007946 // and only if the application fills the compatible screen
7947 mFrame.left <= mCompatibleScreenFrame.left &&
7948 mFrame.top <= mCompatibleScreenFrame.top &&
7949 mFrame.right >= mCompatibleScreenFrame.right &&
7950 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007951 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007952 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007953 }
7954
7955 boolean isFullscreen(int screenWidth, int screenHeight) {
7956 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007957 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007958 }
7959
7960 void removeLocked() {
7961 if (mAttachedWindow != null) {
7962 mAttachedWindow.mChildWindows.remove(this);
7963 }
7964 destroySurfaceLocked();
7965 mSession.windowRemovedLocked();
7966 try {
7967 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7968 } catch (RuntimeException e) {
7969 // Ignore if it has already been removed (usually because
7970 // we are doing this as part of processing a death note.)
7971 }
7972 }
7973
7974 private class DeathRecipient implements IBinder.DeathRecipient {
7975 public void binderDied() {
7976 try {
7977 synchronized(mWindowMap) {
7978 WindowState win = windowForClientLocked(mSession, mClient);
7979 Log.i(TAG, "WIN DEATH: " + win);
7980 if (win != null) {
7981 removeWindowLocked(mSession, win);
7982 }
7983 }
7984 } catch (IllegalArgumentException ex) {
7985 // This will happen if the window has already been
7986 // removed.
7987 }
7988 }
7989 }
7990
7991 /** Returns true if this window desires key events. */
7992 public final boolean canReceiveKeys() {
7993 return isVisibleOrAdding()
7994 && (mViewVisibility == View.VISIBLE)
7995 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7996 }
7997
7998 public boolean hasDrawnLw() {
7999 return mHasDrawn;
8000 }
8001
8002 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008003 return showLw(doAnimation, true);
8004 }
8005
8006 boolean showLw(boolean doAnimation, boolean requestAnim) {
8007 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8008 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008009 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008010 mPolicyVisibility = true;
8011 mPolicyVisibilityAfterAnim = true;
8012 if (doAnimation) {
8013 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8014 }
8015 if (requestAnim) {
8016 requestAnimationLocked(0);
8017 }
8018 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008019 }
8020
8021 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008022 return hideLw(doAnimation, true);
8023 }
8024
8025 boolean hideLw(boolean doAnimation, boolean requestAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008026 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8027 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008028 if (!current) {
8029 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008030 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008031 if (doAnimation) {
8032 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8033 if (mAnimation == null) {
8034 doAnimation = false;
8035 }
8036 }
8037 if (doAnimation) {
8038 mPolicyVisibilityAfterAnim = false;
8039 } else {
8040 mPolicyVisibilityAfterAnim = false;
8041 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008042 // Window is no longer visible -- make sure if we were waiting
8043 // for it to be displayed before enabling the display, that
8044 // we allow the display to be enabled now.
8045 enableScreenIfNeededLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008046 }
8047 if (requestAnim) {
8048 requestAnimationLocked(0);
8049 }
8050 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008051 }
8052
8053 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008054 StringBuilder sb = new StringBuilder(64);
Romain Guy06882f82009-06-10 13:36:04 -07008055
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008056 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8057 pw.print(" mClient="); pw.println(mClient.asBinder());
8058 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8059 if (mAttachedWindow != null || mLayoutAttached) {
8060 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8061 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8062 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008063 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8064 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8065 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008066 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8067 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008068 }
8069 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8070 pw.print(" mSubLayer="); pw.print(mSubLayer);
8071 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8072 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8073 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8074 pw.print("="); pw.print(mAnimLayer);
8075 pw.print(" mLastLayer="); pw.println(mLastLayer);
8076 if (mSurface != null) {
8077 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
8078 }
8079 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8080 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8081 if (mAppToken != null) {
8082 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8083 }
8084 if (mTargetAppToken != null) {
8085 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8086 }
8087 pw.print(prefix); pw.print("mViewVisibility=0x");
8088 pw.print(Integer.toHexString(mViewVisibility));
8089 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008090 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8091 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008092 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8093 pw.print(prefix); pw.print("mPolicyVisibility=");
8094 pw.print(mPolicyVisibility);
8095 pw.print(" mPolicyVisibilityAfterAnim=");
8096 pw.print(mPolicyVisibilityAfterAnim);
8097 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8098 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008099 if (!mRelayoutCalled) {
8100 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8101 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008102 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008103 pw.print(" h="); pw.println(mRequestedHeight);
8104 if (mXOffset != 0 || mYOffset != 0) {
8105 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8106 pw.print(" y="); pw.println(mYOffset);
8107 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008108 pw.print(prefix); pw.print("mGivenContentInsets=");
8109 mGivenContentInsets.printShortString(pw);
8110 pw.print(" mGivenVisibleInsets=");
8111 mGivenVisibleInsets.printShortString(pw);
8112 pw.println();
8113 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8114 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8115 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8116 }
8117 pw.print(prefix); pw.print("mShownFrame=");
8118 mShownFrame.printShortString(pw);
8119 pw.print(" last="); mLastShownFrame.printShortString(pw);
8120 pw.println();
8121 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8122 pw.print(" last="); mLastFrame.printShortString(pw);
8123 pw.println();
8124 pw.print(prefix); pw.print("mContainingFrame=");
8125 mContainingFrame.printShortString(pw);
8126 pw.print(" mDisplayFrame=");
8127 mDisplayFrame.printShortString(pw);
8128 pw.println();
8129 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8130 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8131 pw.println();
8132 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8133 pw.print(" last="); mLastContentInsets.printShortString(pw);
8134 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8135 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8136 pw.println();
8137 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8138 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8139 pw.print(" mAlpha="); pw.print(mAlpha);
8140 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8141 }
8142 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8143 || mAnimation != null) {
8144 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8145 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8146 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8147 pw.print(" mAnimation="); pw.println(mAnimation);
8148 }
8149 if (mHasTransformation || mHasLocalTransformation) {
8150 pw.print(prefix); pw.print("XForm: has=");
8151 pw.print(mHasTransformation);
8152 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8153 pw.print(" "); mTransformation.printShortString(pw);
8154 pw.println();
8155 }
8156 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8157 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8158 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8159 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8160 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8161 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8162 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8163 pw.print(" mDestroying="); pw.print(mDestroying);
8164 pw.print(" mRemoved="); pw.println(mRemoved);
8165 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008166 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008167 pw.print(prefix); pw.print("mOrientationChanging=");
8168 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008169 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8170 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008171 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008172 if (mHScale != 1 || mVScale != 1) {
8173 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8174 pw.print(" mVScale="); pw.println(mVScale);
8175 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008176 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008177 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8178 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8179 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008180 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8181 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8182 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8183 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008184 }
8185
8186 @Override
8187 public String toString() {
8188 return "Window{"
8189 + Integer.toHexString(System.identityHashCode(this))
8190 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
8191 }
8192 }
Romain Guy06882f82009-06-10 13:36:04 -07008193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008194 // -------------------------------------------------------------
8195 // Window Token State
8196 // -------------------------------------------------------------
8197
8198 class WindowToken {
8199 // The actual token.
8200 final IBinder token;
8201
8202 // The type of window this token is for, as per WindowManager.LayoutParams.
8203 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008205 // Set if this token was explicitly added by a client, so should
8206 // not be removed when all windows are removed.
8207 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008208
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008209 // For printing.
8210 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008212 // If this is an AppWindowToken, this is non-null.
8213 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008215 // All of the windows associated with this token.
8216 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8217
8218 // Is key dispatching paused for this token?
8219 boolean paused = false;
8220
8221 // Should this token's windows be hidden?
8222 boolean hidden;
8223
8224 // Temporary for finding which tokens no longer have visible windows.
8225 boolean hasVisible;
8226
Dianne Hackborna8f60182009-09-01 19:01:50 -07008227 // Set to true when this token is in a pending transaction where it
8228 // will be shown.
8229 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008230
Dianne Hackborna8f60182009-09-01 19:01:50 -07008231 // Set to true when this token is in a pending transaction where it
8232 // will be hidden.
8233 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008234
Dianne Hackborna8f60182009-09-01 19:01:50 -07008235 // Set to true when this token is in a pending transaction where its
8236 // windows will be put to the bottom of the list.
8237 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008238
Dianne Hackborna8f60182009-09-01 19:01:50 -07008239 // Set to true when this token is in a pending transaction where its
8240 // windows will be put to the top of the list.
8241 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008243 WindowToken(IBinder _token, int type, boolean _explicit) {
8244 token = _token;
8245 windowType = type;
8246 explicit = _explicit;
8247 }
8248
8249 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008250 pw.print(prefix); pw.print("token="); pw.println(token);
8251 pw.print(prefix); pw.print("windows="); pw.println(windows);
8252 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8253 pw.print(" hidden="); pw.print(hidden);
8254 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008255 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8256 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8257 pw.print(" waitingToHide="); pw.print(waitingToHide);
8258 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8259 pw.print(" sendingToTop="); pw.println(sendingToTop);
8260 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008261 }
8262
8263 @Override
8264 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008265 if (stringName == null) {
8266 StringBuilder sb = new StringBuilder();
8267 sb.append("WindowToken{");
8268 sb.append(Integer.toHexString(System.identityHashCode(this)));
8269 sb.append(" token="); sb.append(token); sb.append('}');
8270 stringName = sb.toString();
8271 }
8272 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008273 }
8274 };
8275
8276 class AppWindowToken extends WindowToken {
8277 // Non-null only for application tokens.
8278 final IApplicationToken appToken;
8279
8280 // All of the windows and child windows that are included in this
8281 // application token. Note this list is NOT sorted!
8282 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8283
8284 int groupId = -1;
8285 boolean appFullscreen;
8286 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Romain Guy06882f82009-06-10 13:36:04 -07008287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008288 // These are used for determining when all windows associated with
8289 // an activity have been drawn, so they can be made visible together
8290 // at the same time.
8291 int lastTransactionSequence = mTransactionSequence-1;
8292 int numInterestingWindows;
8293 int numDrawnWindows;
8294 boolean inPendingTransaction;
8295 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008297 // Is this token going to be hidden in a little while? If so, it
8298 // won't be taken into account for setting the screen orientation.
8299 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008301 // Is this window's surface needed? This is almost like hidden, except
8302 // it will sometimes be true a little earlier: when the token has
8303 // been shown, but is still waiting for its app transition to execute
8304 // before making its windows shown.
8305 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008307 // Have we told the window clients to hide themselves?
8308 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008310 // Last visibility state we reported to the app token.
8311 boolean reportedVisible;
8312
8313 // Set to true when the token has been removed from the window mgr.
8314 boolean removed;
8315
8316 // Have we been asked to have this token keep the screen frozen?
8317 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008319 boolean animating;
8320 Animation animation;
8321 boolean hasTransformation;
8322 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008324 // Offset to the window of all layers in the token, for use by
8325 // AppWindowToken animations.
8326 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008328 // Information about an application starting window if displayed.
8329 StartingData startingData;
8330 WindowState startingWindow;
8331 View startingView;
8332 boolean startingDisplayed;
8333 boolean startingMoved;
8334 boolean firstWindowDrawn;
8335
8336 AppWindowToken(IApplicationToken _token) {
8337 super(_token.asBinder(),
8338 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8339 appWindowToken = this;
8340 appToken = _token;
8341 }
Romain Guy06882f82009-06-10 13:36:04 -07008342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008343 public void setAnimation(Animation anim) {
8344 if (localLOGV) Log.v(
8345 TAG, "Setting animation in " + this + ": " + anim);
8346 animation = anim;
8347 animating = false;
8348 anim.restrictDuration(MAX_ANIMATION_DURATION);
8349 anim.scaleCurrentDuration(mTransitionAnimationScale);
8350 int zorder = anim.getZAdjustment();
8351 int adj = 0;
8352 if (zorder == Animation.ZORDER_TOP) {
8353 adj = TYPE_LAYER_OFFSET;
8354 } else if (zorder == Animation.ZORDER_BOTTOM) {
8355 adj = -TYPE_LAYER_OFFSET;
8356 }
Romain Guy06882f82009-06-10 13:36:04 -07008357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008358 if (animLayerAdjustment != adj) {
8359 animLayerAdjustment = adj;
8360 updateLayers();
8361 }
8362 }
Romain Guy06882f82009-06-10 13:36:04 -07008363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008364 public void setDummyAnimation() {
8365 if (animation == null) {
8366 if (localLOGV) Log.v(
8367 TAG, "Setting dummy animation in " + this);
8368 animation = sDummyAnimation;
8369 }
8370 }
8371
8372 public void clearAnimation() {
8373 if (animation != null) {
8374 animation = null;
8375 animating = true;
8376 }
8377 }
Romain Guy06882f82009-06-10 13:36:04 -07008378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008379 void updateLayers() {
8380 final int N = allAppWindows.size();
8381 final int adj = animLayerAdjustment;
8382 for (int i=0; i<N; i++) {
8383 WindowState w = allAppWindows.get(i);
8384 w.mAnimLayer = w.mLayer + adj;
8385 if (DEBUG_LAYERS) Log.v(TAG, "Updating layer " + w + ": "
8386 + w.mAnimLayer);
8387 if (w == mInputMethodTarget) {
8388 setInputMethodAnimLayerAdjustment(adj);
8389 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008390 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008391 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008392 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008393 }
8394 }
Romain Guy06882f82009-06-10 13:36:04 -07008395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008396 void sendAppVisibilityToClients() {
8397 final int N = allAppWindows.size();
8398 for (int i=0; i<N; i++) {
8399 WindowState win = allAppWindows.get(i);
8400 if (win == startingWindow && clientHidden) {
8401 // Don't hide the starting window.
8402 continue;
8403 }
8404 try {
8405 if (DEBUG_VISIBILITY) Log.v(TAG,
8406 "Setting visibility of " + win + ": " + (!clientHidden));
8407 win.mClient.dispatchAppVisibility(!clientHidden);
8408 } catch (RemoteException e) {
8409 }
8410 }
8411 }
Romain Guy06882f82009-06-10 13:36:04 -07008412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008413 void showAllWindowsLocked() {
8414 final int NW = allAppWindows.size();
8415 for (int i=0; i<NW; i++) {
8416 WindowState w = allAppWindows.get(i);
8417 if (DEBUG_VISIBILITY) Log.v(TAG,
8418 "performing show on: " + w);
8419 w.performShowLocked();
8420 }
8421 }
Romain Guy06882f82009-06-10 13:36:04 -07008422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008423 // This must be called while inside a transaction.
8424 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008425 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008426 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008428 if (animation == sDummyAnimation) {
8429 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008430 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008431 // when it is really time to animate, this will be set to
8432 // a real animation and the next call will execute normally.
8433 return false;
8434 }
Romain Guy06882f82009-06-10 13:36:04 -07008435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008436 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8437 if (!animating) {
8438 if (DEBUG_ANIM) Log.v(
8439 TAG, "Starting animation in " + this +
8440 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8441 + " scale=" + mTransitionAnimationScale
8442 + " allDrawn=" + allDrawn + " animating=" + animating);
8443 animation.initialize(dw, dh, dw, dh);
8444 animation.setStartTime(currentTime);
8445 animating = true;
8446 }
8447 transformation.clear();
8448 final boolean more = animation.getTransformation(
8449 currentTime, transformation);
8450 if (DEBUG_ANIM) Log.v(
8451 TAG, "Stepped animation in " + this +
8452 ": more=" + more + ", xform=" + transformation);
8453 if (more) {
8454 // we're done!
8455 hasTransformation = true;
8456 return true;
8457 }
8458 if (DEBUG_ANIM) Log.v(
8459 TAG, "Finished animation in " + this +
8460 " @ " + currentTime);
8461 animation = null;
8462 }
8463 } else if (animation != null) {
8464 // If the display is frozen, and there is a pending animation,
8465 // clear it and make sure we run the cleanup code.
8466 animating = true;
8467 animation = null;
8468 }
8469
8470 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008472 if (!animating) {
8473 return false;
8474 }
8475
8476 clearAnimation();
8477 animating = false;
8478 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8479 moveInputMethodWindowsIfNeededLocked(true);
8480 }
Romain Guy06882f82009-06-10 13:36:04 -07008481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008482 if (DEBUG_ANIM) Log.v(
8483 TAG, "Animation done in " + this
8484 + ": reportedVisible=" + reportedVisible);
8485
8486 transformation.clear();
8487 if (animLayerAdjustment != 0) {
8488 animLayerAdjustment = 0;
8489 updateLayers();
8490 }
Romain Guy06882f82009-06-10 13:36:04 -07008491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008492 final int N = windows.size();
8493 for (int i=0; i<N; i++) {
8494 ((WindowState)windows.get(i)).finishExit();
8495 }
8496 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008498 return false;
8499 }
8500
8501 void updateReportedVisibilityLocked() {
8502 if (appToken == null) {
8503 return;
8504 }
Romain Guy06882f82009-06-10 13:36:04 -07008505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008506 int numInteresting = 0;
8507 int numVisible = 0;
8508 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008510 if (DEBUG_VISIBILITY) Log.v(TAG, "Update reported visibility: " + this);
8511 final int N = allAppWindows.size();
8512 for (int i=0; i<N; i++) {
8513 WindowState win = allAppWindows.get(i);
8514 if (win == startingWindow || win.mAppFreezing) {
8515 continue;
8516 }
8517 if (DEBUG_VISIBILITY) {
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008518 Log.v(TAG, "Win " + win + ": isDrawn="
8519 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008520 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008521 if (!win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008522 Log.v(TAG, "Not displayed: s=" + win.mSurface
8523 + " pv=" + win.mPolicyVisibility
8524 + " dp=" + win.mDrawPending
8525 + " cdp=" + win.mCommitDrawPending
8526 + " ah=" + win.mAttachedHidden
8527 + " th="
8528 + (win.mAppToken != null
8529 ? win.mAppToken.hiddenRequested : false)
8530 + " a=" + win.mAnimating);
8531 }
8532 }
8533 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008534 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008535 if (!win.isAnimating()) {
8536 numVisible++;
8537 }
8538 nowGone = false;
8539 } else if (win.isAnimating()) {
8540 nowGone = false;
8541 }
8542 }
Romain Guy06882f82009-06-10 13:36:04 -07008543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008544 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
8545 if (DEBUG_VISIBILITY) Log.v(TAG, "VIS " + this + ": interesting="
8546 + numInteresting + " visible=" + numVisible);
8547 if (nowVisible != reportedVisible) {
8548 if (DEBUG_VISIBILITY) Log.v(
8549 TAG, "Visibility changed in " + this
8550 + ": vis=" + nowVisible);
8551 reportedVisible = nowVisible;
8552 Message m = mH.obtainMessage(
8553 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8554 nowVisible ? 1 : 0,
8555 nowGone ? 1 : 0,
8556 this);
8557 mH.sendMessage(m);
8558 }
8559 }
Romain Guy06882f82009-06-10 13:36:04 -07008560
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008561 WindowState findMainWindow() {
8562 int j = windows.size();
8563 while (j > 0) {
8564 j--;
8565 WindowState win = windows.get(j);
8566 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8567 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8568 return win;
8569 }
8570 }
8571 return null;
8572 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008574 void dump(PrintWriter pw, String prefix) {
8575 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008576 if (appToken != null) {
8577 pw.print(prefix); pw.println("app=true");
8578 }
8579 if (allAppWindows.size() > 0) {
8580 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8581 }
8582 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008583 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008584 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8585 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8586 pw.print(" clientHidden="); pw.print(clientHidden);
8587 pw.print(" willBeHidden="); pw.print(willBeHidden);
8588 pw.print(" reportedVisible="); pw.println(reportedVisible);
8589 if (paused || freezingScreen) {
8590 pw.print(prefix); pw.print("paused="); pw.print(paused);
8591 pw.print(" freezingScreen="); pw.println(freezingScreen);
8592 }
8593 if (numInterestingWindows != 0 || numDrawnWindows != 0
8594 || inPendingTransaction || allDrawn) {
8595 pw.print(prefix); pw.print("numInterestingWindows=");
8596 pw.print(numInterestingWindows);
8597 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8598 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8599 pw.print(" allDrawn="); pw.println(allDrawn);
8600 }
8601 if (animating || animation != null) {
8602 pw.print(prefix); pw.print("animating="); pw.print(animating);
8603 pw.print(" animation="); pw.println(animation);
8604 }
8605 if (animLayerAdjustment != 0) {
8606 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8607 }
8608 if (hasTransformation) {
8609 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8610 pw.print(" transformation="); transformation.printShortString(pw);
8611 pw.println();
8612 }
8613 if (startingData != null || removed || firstWindowDrawn) {
8614 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8615 pw.print(" removed="); pw.print(removed);
8616 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8617 }
8618 if (startingWindow != null || startingView != null
8619 || startingDisplayed || startingMoved) {
8620 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8621 pw.print(" startingView="); pw.print(startingView);
8622 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8623 pw.print(" startingMoved"); pw.println(startingMoved);
8624 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008625 }
8626
8627 @Override
8628 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008629 if (stringName == null) {
8630 StringBuilder sb = new StringBuilder();
8631 sb.append("AppWindowToken{");
8632 sb.append(Integer.toHexString(System.identityHashCode(this)));
8633 sb.append(" token="); sb.append(token); sb.append('}');
8634 stringName = sb.toString();
8635 }
8636 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008637 }
8638 }
Romain Guy06882f82009-06-10 13:36:04 -07008639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008640 // -------------------------------------------------------------
8641 // DummyAnimation
8642 // -------------------------------------------------------------
8643
8644 // This is an animation that does nothing: it just immediately finishes
8645 // itself every time it is called. It is used as a stub animation in cases
8646 // where we want to synchronize multiple things that may be animating.
8647 static final class DummyAnimation extends Animation {
8648 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8649 return false;
8650 }
8651 }
8652 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008654 // -------------------------------------------------------------
8655 // Async Handler
8656 // -------------------------------------------------------------
8657
8658 static final class StartingData {
8659 final String pkg;
8660 final int theme;
8661 final CharSequence nonLocalizedLabel;
8662 final int labelRes;
8663 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008665 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8666 int _labelRes, int _icon) {
8667 pkg = _pkg;
8668 theme = _theme;
8669 nonLocalizedLabel = _nonLocalizedLabel;
8670 labelRes = _labelRes;
8671 icon = _icon;
8672 }
8673 }
8674
8675 private final class H extends Handler {
8676 public static final int REPORT_FOCUS_CHANGE = 2;
8677 public static final int REPORT_LOSING_FOCUS = 3;
8678 public static final int ANIMATE = 4;
8679 public static final int ADD_STARTING = 5;
8680 public static final int REMOVE_STARTING = 6;
8681 public static final int FINISHED_STARTING = 7;
8682 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008683 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8684 public static final int HOLD_SCREEN_CHANGED = 12;
8685 public static final int APP_TRANSITION_TIMEOUT = 13;
8686 public static final int PERSIST_ANIMATION_SCALE = 14;
8687 public static final int FORCE_GC = 15;
8688 public static final int ENABLE_SCREEN = 16;
8689 public static final int APP_FREEZE_TIMEOUT = 17;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008690 public static final int COMPUTE_AND_SEND_NEW_CONFIGURATION = 18;
Romain Guy06882f82009-06-10 13:36:04 -07008691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008692 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008694 public H() {
8695 }
Romain Guy06882f82009-06-10 13:36:04 -07008696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008697 @Override
8698 public void handleMessage(Message msg) {
8699 switch (msg.what) {
8700 case REPORT_FOCUS_CHANGE: {
8701 WindowState lastFocus;
8702 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008704 synchronized(mWindowMap) {
8705 lastFocus = mLastFocus;
8706 newFocus = mCurrentFocus;
8707 if (lastFocus == newFocus) {
8708 // Focus is not changing, so nothing to do.
8709 return;
8710 }
8711 mLastFocus = newFocus;
8712 //Log.i(TAG, "Focus moving from " + lastFocus
8713 // + " to " + newFocus);
8714 if (newFocus != null && lastFocus != null
8715 && !newFocus.isDisplayedLw()) {
8716 //Log.i(TAG, "Delaying loss of focus...");
8717 mLosingFocus.add(lastFocus);
8718 lastFocus = null;
8719 }
8720 }
8721
8722 if (lastFocus != newFocus) {
8723 //System.out.println("Changing focus from " + lastFocus
8724 // + " to " + newFocus);
8725 if (newFocus != null) {
8726 try {
8727 //Log.i(TAG, "Gaining focus: " + newFocus);
8728 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8729 } catch (RemoteException e) {
8730 // Ignore if process has died.
8731 }
8732 }
8733
8734 if (lastFocus != null) {
8735 try {
8736 //Log.i(TAG, "Losing focus: " + lastFocus);
8737 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8738 } catch (RemoteException e) {
8739 // Ignore if process has died.
8740 }
8741 }
8742 }
8743 } break;
8744
8745 case REPORT_LOSING_FOCUS: {
8746 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008748 synchronized(mWindowMap) {
8749 losers = mLosingFocus;
8750 mLosingFocus = new ArrayList<WindowState>();
8751 }
8752
8753 final int N = losers.size();
8754 for (int i=0; i<N; i++) {
8755 try {
8756 //Log.i(TAG, "Losing delayed focus: " + losers.get(i));
8757 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8758 } catch (RemoteException e) {
8759 // Ignore if process has died.
8760 }
8761 }
8762 } break;
8763
8764 case ANIMATE: {
8765 synchronized(mWindowMap) {
8766 mAnimationPending = false;
8767 performLayoutAndPlaceSurfacesLocked();
8768 }
8769 } break;
8770
8771 case ADD_STARTING: {
8772 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8773 final StartingData sd = wtoken.startingData;
8774
8775 if (sd == null) {
8776 // Animation has been canceled... do nothing.
8777 return;
8778 }
Romain Guy06882f82009-06-10 13:36:04 -07008779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008780 if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Add starting "
8781 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008783 View view = null;
8784 try {
8785 view = mPolicy.addStartingWindow(
8786 wtoken.token, sd.pkg,
8787 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8788 sd.icon);
8789 } catch (Exception e) {
8790 Log.w(TAG, "Exception when adding starting window", e);
8791 }
8792
8793 if (view != null) {
8794 boolean abort = false;
8795
8796 synchronized(mWindowMap) {
8797 if (wtoken.removed || wtoken.startingData == null) {
8798 // If the window was successfully added, then
8799 // we need to remove it.
8800 if (wtoken.startingWindow != null) {
8801 if (DEBUG_STARTING_WINDOW) Log.v(TAG,
8802 "Aborted starting " + wtoken
8803 + ": removed=" + wtoken.removed
8804 + " startingData=" + wtoken.startingData);
8805 wtoken.startingWindow = null;
8806 wtoken.startingData = null;
8807 abort = true;
8808 }
8809 } else {
8810 wtoken.startingView = view;
8811 }
8812 if (DEBUG_STARTING_WINDOW && !abort) Log.v(TAG,
8813 "Added starting " + wtoken
8814 + ": startingWindow="
8815 + wtoken.startingWindow + " startingView="
8816 + wtoken.startingView);
8817 }
8818
8819 if (abort) {
8820 try {
8821 mPolicy.removeStartingWindow(wtoken.token, view);
8822 } catch (Exception e) {
8823 Log.w(TAG, "Exception when removing starting window", e);
8824 }
8825 }
8826 }
8827 } break;
8828
8829 case REMOVE_STARTING: {
8830 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8831 IBinder token = null;
8832 View view = null;
8833 synchronized (mWindowMap) {
8834 if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Remove starting "
8835 + wtoken + ": startingWindow="
8836 + wtoken.startingWindow + " startingView="
8837 + wtoken.startingView);
8838 if (wtoken.startingWindow != null) {
8839 view = wtoken.startingView;
8840 token = wtoken.token;
8841 wtoken.startingData = null;
8842 wtoken.startingView = null;
8843 wtoken.startingWindow = null;
8844 }
8845 }
8846 if (view != null) {
8847 try {
8848 mPolicy.removeStartingWindow(token, view);
8849 } catch (Exception e) {
8850 Log.w(TAG, "Exception when removing starting window", e);
8851 }
8852 }
8853 } break;
8854
8855 case FINISHED_STARTING: {
8856 IBinder token = null;
8857 View view = null;
8858 while (true) {
8859 synchronized (mWindowMap) {
8860 final int N = mFinishedStarting.size();
8861 if (N <= 0) {
8862 break;
8863 }
8864 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8865
8866 if (DEBUG_STARTING_WINDOW) Log.v(TAG,
8867 "Finished starting " + wtoken
8868 + ": startingWindow=" + wtoken.startingWindow
8869 + " startingView=" + wtoken.startingView);
8870
8871 if (wtoken.startingWindow == null) {
8872 continue;
8873 }
8874
8875 view = wtoken.startingView;
8876 token = wtoken.token;
8877 wtoken.startingData = null;
8878 wtoken.startingView = null;
8879 wtoken.startingWindow = null;
8880 }
8881
8882 try {
8883 mPolicy.removeStartingWindow(token, view);
8884 } catch (Exception e) {
8885 Log.w(TAG, "Exception when removing starting window", e);
8886 }
8887 }
8888 } break;
8889
8890 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8891 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8892
8893 boolean nowVisible = msg.arg1 != 0;
8894 boolean nowGone = msg.arg2 != 0;
8895
8896 try {
8897 if (DEBUG_VISIBILITY) Log.v(
8898 TAG, "Reporting visible in " + wtoken
8899 + " visible=" + nowVisible
8900 + " gone=" + nowGone);
8901 if (nowVisible) {
8902 wtoken.appToken.windowsVisible();
8903 } else {
8904 wtoken.appToken.windowsGone();
8905 }
8906 } catch (RemoteException ex) {
8907 }
8908 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008910 case WINDOW_FREEZE_TIMEOUT: {
8911 synchronized (mWindowMap) {
8912 Log.w(TAG, "Window freeze timeout expired.");
8913 int i = mWindows.size();
8914 while (i > 0) {
8915 i--;
8916 WindowState w = (WindowState)mWindows.get(i);
8917 if (w.mOrientationChanging) {
8918 w.mOrientationChanging = false;
8919 Log.w(TAG, "Force clearing orientation change: " + w);
8920 }
8921 }
8922 performLayoutAndPlaceSurfacesLocked();
8923 }
8924 break;
8925 }
Romain Guy06882f82009-06-10 13:36:04 -07008926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008927 case HOLD_SCREEN_CHANGED: {
8928 Session oldHold;
8929 Session newHold;
8930 synchronized (mWindowMap) {
8931 oldHold = mLastReportedHold;
8932 newHold = (Session)msg.obj;
8933 mLastReportedHold = newHold;
8934 }
Romain Guy06882f82009-06-10 13:36:04 -07008935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008936 if (oldHold != newHold) {
8937 try {
8938 if (oldHold != null) {
8939 mBatteryStats.noteStopWakelock(oldHold.mUid,
8940 "window",
8941 BatteryStats.WAKE_TYPE_WINDOW);
8942 }
8943 if (newHold != null) {
8944 mBatteryStats.noteStartWakelock(newHold.mUid,
8945 "window",
8946 BatteryStats.WAKE_TYPE_WINDOW);
8947 }
8948 } catch (RemoteException e) {
8949 }
8950 }
8951 break;
8952 }
Romain Guy06882f82009-06-10 13:36:04 -07008953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008954 case APP_TRANSITION_TIMEOUT: {
8955 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008956 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008957 if (DEBUG_APP_TRANSITIONS) Log.v(TAG,
8958 "*** APP TRANSITION TIMEOUT");
8959 mAppTransitionReady = true;
8960 mAppTransitionTimeout = true;
8961 performLayoutAndPlaceSurfacesLocked();
8962 }
8963 }
8964 break;
8965 }
Romain Guy06882f82009-06-10 13:36:04 -07008966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008967 case PERSIST_ANIMATION_SCALE: {
8968 Settings.System.putFloat(mContext.getContentResolver(),
8969 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8970 Settings.System.putFloat(mContext.getContentResolver(),
8971 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8972 break;
8973 }
Romain Guy06882f82009-06-10 13:36:04 -07008974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008975 case FORCE_GC: {
8976 synchronized(mWindowMap) {
8977 if (mAnimationPending) {
8978 // If we are animating, don't do the gc now but
8979 // delay a bit so we don't interrupt the animation.
8980 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8981 2000);
8982 return;
8983 }
8984 // If we are currently rotating the display, it will
8985 // schedule a new message when done.
8986 if (mDisplayFrozen) {
8987 return;
8988 }
8989 mFreezeGcPending = 0;
8990 }
8991 Runtime.getRuntime().gc();
8992 break;
8993 }
Romain Guy06882f82009-06-10 13:36:04 -07008994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008995 case ENABLE_SCREEN: {
8996 performEnableScreen();
8997 break;
8998 }
Romain Guy06882f82009-06-10 13:36:04 -07008999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009000 case APP_FREEZE_TIMEOUT: {
9001 synchronized (mWindowMap) {
9002 Log.w(TAG, "App freeze timeout expired.");
9003 int i = mAppTokens.size();
9004 while (i > 0) {
9005 i--;
9006 AppWindowToken tok = mAppTokens.get(i);
9007 if (tok.freezingScreen) {
9008 Log.w(TAG, "Force clearing freeze: " + tok);
9009 unsetAppFreezingScreenLocked(tok, true, true);
9010 }
9011 }
9012 }
9013 break;
9014 }
Romain Guy06882f82009-06-10 13:36:04 -07009015
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009016 case COMPUTE_AND_SEND_NEW_CONFIGURATION: {
Dianne Hackborncfaef692009-06-15 14:24:44 -07009017 if (updateOrientationFromAppTokensUnchecked(null, null) != null) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009018 sendNewConfiguration();
9019 }
9020 break;
9021 }
Romain Guy06882f82009-06-10 13:36:04 -07009022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009023 }
9024 }
9025 }
9026
9027 // -------------------------------------------------------------
9028 // IWindowManager API
9029 // -------------------------------------------------------------
9030
9031 public IWindowSession openSession(IInputMethodClient client,
9032 IInputContext inputContext) {
9033 if (client == null) throw new IllegalArgumentException("null client");
9034 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
9035 return new Session(client, inputContext);
9036 }
9037
9038 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9039 synchronized (mWindowMap) {
9040 // The focus for the client is the window immediately below
9041 // where we would place the input method window.
9042 int idx = findDesiredInputMethodWindowIndexLocked(false);
9043 WindowState imFocus;
9044 if (idx > 0) {
9045 imFocus = (WindowState)mWindows.get(idx-1);
9046 if (imFocus != null) {
9047 if (imFocus.mSession.mClient != null &&
9048 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9049 return true;
9050 }
9051 }
9052 }
9053 }
9054 return false;
9055 }
Romain Guy06882f82009-06-10 13:36:04 -07009056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009057 // -------------------------------------------------------------
9058 // Internals
9059 // -------------------------------------------------------------
9060
9061 final WindowState windowForClientLocked(Session session, IWindow client) {
9062 return windowForClientLocked(session, client.asBinder());
9063 }
Romain Guy06882f82009-06-10 13:36:04 -07009064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009065 final WindowState windowForClientLocked(Session session, IBinder client) {
9066 WindowState win = mWindowMap.get(client);
9067 if (localLOGV) Log.v(
9068 TAG, "Looking up client " + client + ": " + win);
9069 if (win == null) {
9070 RuntimeException ex = new RuntimeException();
9071 Log.w(TAG, "Requested window " + client + " does not exist", ex);
9072 return null;
9073 }
9074 if (session != null && win.mSession != session) {
9075 RuntimeException ex = new RuntimeException();
9076 Log.w(TAG, "Requested window " + client + " is in session " +
9077 win.mSession + ", not " + session, ex);
9078 return null;
9079 }
9080
9081 return win;
9082 }
9083
Dianne Hackborna8f60182009-09-01 19:01:50 -07009084 final void rebuildAppWindowListLocked() {
9085 int NW = mWindows.size();
9086 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009087 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009088 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009089
Dianne Hackborna8f60182009-09-01 19:01:50 -07009090 // First remove all existing app windows.
9091 i=0;
9092 while (i < NW) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009093 WindowState w = (WindowState)mWindows.get(i);
9094 if (w.mAppToken != null) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009095 WindowState win = (WindowState)mWindows.remove(i);
9096 if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG,
9097 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009098 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009099 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009100 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009101 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9102 && lastWallpaper == i-1) {
9103 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009104 }
9105 i++;
9106 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009107
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009108 // The wallpaper window(s) typically live at the bottom of the stack,
9109 // so skip them before adding app tokens.
9110 lastWallpaper++;
9111 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009112
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009113 // First add all of the exiting app tokens... these are no longer
9114 // in the main app list, but still have windows shown. We put them
9115 // in the back because now that the animation is over we no longer
9116 // will care about them.
9117 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009118 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009119 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9120 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009121
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009122 // And add in the still active app tokens in Z order.
9123 NT = mAppTokens.size();
9124 for (int j=0; j<NT; j++) {
9125 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009126 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009127
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009128 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009129 if (i != numRemoved) {
9130 Log.w(TAG, "Rebuild removed " + numRemoved
9131 + " windows but added " + i);
9132 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009133 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009135 private final void assignLayersLocked() {
9136 int N = mWindows.size();
9137 int curBaseLayer = 0;
9138 int curLayer = 0;
9139 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009141 for (i=0; i<N; i++) {
9142 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009143 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9144 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009145 curLayer += WINDOW_LAYER_MULTIPLIER;
9146 w.mLayer = curLayer;
9147 } else {
9148 curBaseLayer = curLayer = w.mBaseLayer;
9149 w.mLayer = curLayer;
9150 }
9151 if (w.mTargetAppToken != null) {
9152 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9153 } else if (w.mAppToken != null) {
9154 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9155 } else {
9156 w.mAnimLayer = w.mLayer;
9157 }
9158 if (w.mIsImWindow) {
9159 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009160 } else if (w.mIsWallpaper) {
9161 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009162 }
9163 if (DEBUG_LAYERS) Log.v(TAG, "Assign layer " + w + ": "
9164 + w.mAnimLayer);
9165 //System.out.println(
9166 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9167 }
9168 }
9169
9170 private boolean mInLayout = false;
9171 private final void performLayoutAndPlaceSurfacesLocked() {
9172 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009173 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009174 throw new RuntimeException("Recursive call!");
9175 }
9176 Log.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
9177 return;
9178 }
9179
9180 boolean recoveringMemory = false;
9181 if (mForceRemoves != null) {
9182 recoveringMemory = true;
9183 // Wait a little it for things to settle down, and off we go.
9184 for (int i=0; i<mForceRemoves.size(); i++) {
9185 WindowState ws = mForceRemoves.get(i);
9186 Log.i(TAG, "Force removing: " + ws);
9187 removeWindowInnerLocked(ws.mSession, ws);
9188 }
9189 mForceRemoves = null;
9190 Log.w(TAG, "Due to memory failure, waiting a bit for next layout");
9191 Object tmp = new Object();
9192 synchronized (tmp) {
9193 try {
9194 tmp.wait(250);
9195 } catch (InterruptedException e) {
9196 }
9197 }
9198 }
Romain Guy06882f82009-06-10 13:36:04 -07009199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009200 mInLayout = true;
9201 try {
9202 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009204 int i = mPendingRemove.size()-1;
9205 if (i >= 0) {
9206 while (i >= 0) {
9207 WindowState w = mPendingRemove.get(i);
9208 removeWindowInnerLocked(w.mSession, w);
9209 i--;
9210 }
9211 mPendingRemove.clear();
9212
9213 mInLayout = false;
9214 assignLayersLocked();
9215 mLayoutNeeded = true;
9216 performLayoutAndPlaceSurfacesLocked();
9217
9218 } else {
9219 mInLayout = false;
9220 if (mLayoutNeeded) {
9221 requestAnimationLocked(0);
9222 }
9223 }
9224 } catch (RuntimeException e) {
9225 mInLayout = false;
9226 Log.e(TAG, "Unhandled exception while layout out windows", e);
9227 }
9228 }
9229
9230 private final void performLayoutLockedInner() {
9231 final int dw = mDisplay.getWidth();
9232 final int dh = mDisplay.getHeight();
9233
9234 final int N = mWindows.size();
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009235 int repeats = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009236 int i;
9237
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009238 if (DEBUG_LAYOUT) Log.v(TAG, "performLayout: needed="
9239 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009241 // FIRST LOOP: Perform a layout, if needed.
Romain Guy06882f82009-06-10 13:36:04 -07009242
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009243 while (mLayoutNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009244 mPolicy.beginLayoutLw(dw, dh);
9245
9246 // First perform layout of any root windows (not attached
9247 // to another window).
9248 int topAttached = -1;
9249 for (i = N-1; i >= 0; i--) {
9250 WindowState win = (WindowState) mWindows.get(i);
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009251
9252 // Don't do layout of a window if it is not visible, or
9253 // soon won't be visible, to avoid wasting time and funky
9254 // changes while a window is animating away.
9255 final AppWindowToken atoken = win.mAppToken;
9256 final boolean gone = win.mViewVisibility == View.GONE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009257 || !win.mRelayoutCalled
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009258 || win.mRootToken.hidden
9259 || (atoken != null && atoken.hiddenRequested)
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009260 || win.mAttachedHidden
9261 || win.mExiting || win.mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009262
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009263 if (win.mLayoutAttached) {
9264 if (DEBUG_LAYOUT) Log.v(TAG, "First pass " + win
9265 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9266 + " mLayoutAttached=" + win.mLayoutAttached);
9267 if (DEBUG_LAYOUT && gone) Log.v(TAG, " (mViewVisibility="
9268 + win.mViewVisibility + " mRelayoutCalled="
9269 + win.mRelayoutCalled + " hidden="
9270 + win.mRootToken.hidden + " hiddenRequested="
9271 + (atoken != null && atoken.hiddenRequested)
9272 + " mAttachedHidden=" + win.mAttachedHidden);
9273 }
9274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009275 // If this view is GONE, then skip it -- keep the current
9276 // frame, and let the caller know so they can ignore it
9277 // if they want. (We do the normal layout for INVISIBLE
9278 // windows, since that means "perform layout as normal,
9279 // just don't display").
9280 if (!gone || !win.mHaveFrame) {
9281 if (!win.mLayoutAttached) {
9282 mPolicy.layoutWindowLw(win, win.mAttrs, null);
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009283 if (DEBUG_LAYOUT) Log.v(TAG, "-> mFrame="
9284 + win.mFrame + " mContainingFrame="
9285 + win.mContainingFrame + " mDisplayFrame="
9286 + win.mDisplayFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009287 } else {
9288 if (topAttached < 0) topAttached = i;
9289 }
9290 }
9291 }
Romain Guy06882f82009-06-10 13:36:04 -07009292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009293 // Now perform layout of attached windows, which usually
9294 // depend on the position of the window they are attached to.
9295 // XXX does not deal with windows that are attached to windows
9296 // that are themselves attached.
9297 for (i = topAttached; i >= 0; i--) {
9298 WindowState win = (WindowState) mWindows.get(i);
9299
9300 // If this view is GONE, then skip it -- keep the current
9301 // frame, and let the caller know so they can ignore it
9302 // if they want. (We do the normal layout for INVISIBLE
9303 // windows, since that means "perform layout as normal,
9304 // just don't display").
9305 if (win.mLayoutAttached) {
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009306 if (DEBUG_LAYOUT) Log.v(TAG, "Second pass " + win
9307 + " mHaveFrame=" + win.mHaveFrame
9308 + " mViewVisibility=" + win.mViewVisibility
9309 + " mRelayoutCalled=" + win.mRelayoutCalled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009310 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9311 || !win.mHaveFrame) {
9312 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009313 if (DEBUG_LAYOUT) Log.v(TAG, "-> mFrame="
9314 + win.mFrame + " mContainingFrame="
9315 + win.mContainingFrame + " mDisplayFrame="
9316 + win.mDisplayFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009317 }
9318 }
9319 }
9320
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009321 int changes = mPolicy.finishLayoutLw();
9322 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9323 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9324 assignLayersLocked();
9325 }
9326 }
9327 if (changes == 0) {
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009328 mLayoutNeeded = false;
9329 } else if (repeats > 2) {
9330 Log.w(TAG, "Layout repeat aborted after too many iterations");
9331 mLayoutNeeded = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009332 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9333 Configuration newConfig = updateOrientationFromAppTokensLocked(
9334 null, null);
9335 if (newConfig != null) {
9336 mLayoutNeeded = true;
9337 mH.sendEmptyMessage(H.COMPUTE_AND_SEND_NEW_CONFIGURATION);
9338 }
9339 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009340 } else {
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009341 if (DEBUG_LAYOUT) Log.v(TAG, "Repeating layout because changes=0x"
9342 + Integer.toHexString(changes));
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009343 repeats++;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009344 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009345 if (DEBUG_LAYOUT) Log.v(TAG, "Computing new config from layout");
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009346 Configuration newConfig = updateOrientationFromAppTokensLocked(
9347 null, null);
9348 if (newConfig != null) {
9349 mH.sendEmptyMessage(H.COMPUTE_AND_SEND_NEW_CONFIGURATION);
9350 }
9351 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009352 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009353 }
9354 }
Romain Guy06882f82009-06-10 13:36:04 -07009355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009356 private final void performLayoutAndPlaceSurfacesLockedInner(
9357 boolean recoveringMemory) {
9358 final long currentTime = SystemClock.uptimeMillis();
9359 final int dw = mDisplay.getWidth();
9360 final int dh = mDisplay.getHeight();
9361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009362 int i;
9363
9364 // FIRST LOOP: Perform a layout, if needed.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009365 performLayoutLockedInner();
Romain Guy06882f82009-06-10 13:36:04 -07009366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009367 if (mFxSession == null) {
9368 mFxSession = new SurfaceSession();
9369 }
Romain Guy06882f82009-06-10 13:36:04 -07009370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009371 if (SHOW_TRANSACTIONS) Log.i(TAG, ">>> OPEN TRANSACTION");
9372
9373 // Initialize state of exiting tokens.
9374 for (i=mExitingTokens.size()-1; i>=0; i--) {
9375 mExitingTokens.get(i).hasVisible = false;
9376 }
9377
9378 // Initialize state of exiting applications.
9379 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9380 mExitingAppTokens.get(i).hasVisible = false;
9381 }
9382
9383 // SECOND LOOP: Execute animations and update visibility of windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009384 boolean orientationChangeComplete = true;
9385 Session holdScreen = null;
9386 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009387 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009388 boolean focusDisplayed = false;
9389 boolean animating = false;
9390
9391 Surface.openTransaction();
9392 try {
9393 boolean restart;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009394 boolean forceHiding = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009395 boolean wallpaperForceHidingChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009396
9397 do {
9398 final int transactionSequence = ++mTransactionSequence;
9399
9400 // Update animations of all applications, including those
9401 // associated with exiting/removed apps
9402 boolean tokensAnimating = false;
9403 final int NAT = mAppTokens.size();
9404 for (i=0; i<NAT; i++) {
9405 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9406 tokensAnimating = true;
9407 }
9408 }
9409 final int NEAT = mExitingAppTokens.size();
9410 for (i=0; i<NEAT; i++) {
9411 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9412 tokensAnimating = true;
9413 }
9414 }
9415
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009416 if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "*** ANIM STEP: seq="
9417 + transactionSequence + " tokensAnimating="
9418 + tokensAnimating);
9419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009420 animating = tokensAnimating;
9421 restart = false;
9422
9423 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009424 boolean wallpaperMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009425 boolean focusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009426
9427 mPolicy.beginAnimationLw(dw, dh);
9428
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009429 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009431 for (i=N-1; i>=0; i--) {
9432 WindowState w = (WindowState)mWindows.get(i);
9433
9434 final WindowManager.LayoutParams attrs = w.mAttrs;
9435
9436 if (w.mSurface != null) {
9437 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009438 if (w.commitFinishDrawingLocked(currentTime)) {
9439 if ((w.mAttrs.flags
9440 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009441 if (DEBUG_WALLPAPER) Log.v(TAG,
9442 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009443 wallpaperMayChange = true;
9444 }
9445 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009446
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009447 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009448 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9449 animating = true;
9450 //w.dump(" ");
9451 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009452 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9453 wallpaperMayChange = true;
9454 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009455
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009456 if (mPolicy.doesForceHide(w, attrs)) {
9457 if (!wasAnimating && animating) {
9458 wallpaperForceHidingChanged = true;
9459 focusMayChange = true;
9460 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9461 forceHiding = true;
9462 }
9463 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9464 boolean changed;
9465 if (forceHiding) {
9466 changed = w.hideLw(false, false);
9467 } else {
9468 changed = w.showLw(false, false);
9469 if (changed && wallpaperForceHidingChanged
9470 && w.isReadyForDisplay()) {
9471 // Assume we will need to animate. If
9472 // we don't (because the wallpaper will
9473 // stay with the lock screen), then we will
9474 // clean up later.
9475 Animation a = mPolicy.createForceHideEnterAnimation();
9476 if (a != null) {
9477 w.setAnimation(a);
9478 }
9479 }
9480 }
9481 if (changed && (attrs.flags
9482 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9483 wallpaperMayChange = true;
9484 }
9485 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009487 mPolicy.animatingWindowLw(w, attrs);
9488 }
9489
9490 final AppWindowToken atoken = w.mAppToken;
9491 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9492 if (atoken.lastTransactionSequence != transactionSequence) {
9493 atoken.lastTransactionSequence = transactionSequence;
9494 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9495 atoken.startingDisplayed = false;
9496 }
9497 if ((w.isOnScreen() || w.mAttrs.type
9498 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9499 && !w.mExiting && !w.mDestroying) {
9500 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009501 Log.v(TAG, "Eval win " + w + ": isDrawn="
9502 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009503 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009504 if (!w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009505 Log.v(TAG, "Not displayed: s=" + w.mSurface
9506 + " pv=" + w.mPolicyVisibility
9507 + " dp=" + w.mDrawPending
9508 + " cdp=" + w.mCommitDrawPending
9509 + " ah=" + w.mAttachedHidden
9510 + " th=" + atoken.hiddenRequested
9511 + " a=" + w.mAnimating);
9512 }
9513 }
9514 if (w != atoken.startingWindow) {
9515 if (!atoken.freezingScreen || !w.mAppFreezing) {
9516 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009517 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009518 atoken.numDrawnWindows++;
9519 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Log.v(TAG,
9520 "tokenMayBeDrawn: " + atoken
9521 + " freezingScreen=" + atoken.freezingScreen
9522 + " mAppFreezing=" + w.mAppFreezing);
9523 tokenMayBeDrawn = true;
9524 }
9525 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009526 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009527 atoken.startingDisplayed = true;
9528 }
9529 }
9530 } else if (w.mReadyToShow) {
9531 w.performShowLocked();
9532 }
9533 }
9534
9535 if (mPolicy.finishAnimationLw()) {
9536 restart = true;
9537 }
9538
9539 if (tokenMayBeDrawn) {
9540 // See if any windows have been drawn, so they (and others
9541 // associated with them) can now be shown.
9542 final int NT = mTokenList.size();
9543 for (i=0; i<NT; i++) {
9544 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9545 if (wtoken == null) {
9546 continue;
9547 }
9548 if (wtoken.freezingScreen) {
9549 int numInteresting = wtoken.numInterestingWindows;
9550 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
9551 if (DEBUG_VISIBILITY) Log.v(TAG,
9552 "allDrawn: " + wtoken
9553 + " interesting=" + numInteresting
9554 + " drawn=" + wtoken.numDrawnWindows);
9555 wtoken.showAllWindowsLocked();
9556 unsetAppFreezingScreenLocked(wtoken, false, true);
9557 orientationChangeComplete = true;
9558 }
9559 } else if (!wtoken.allDrawn) {
9560 int numInteresting = wtoken.numInterestingWindows;
9561 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
9562 if (DEBUG_VISIBILITY) Log.v(TAG,
9563 "allDrawn: " + wtoken
9564 + " interesting=" + numInteresting
9565 + " drawn=" + wtoken.numDrawnWindows);
9566 wtoken.allDrawn = true;
9567 restart = true;
9568
9569 // We can now show all of the drawn windows!
9570 if (!mOpeningApps.contains(wtoken)) {
9571 wtoken.showAllWindowsLocked();
9572 }
9573 }
9574 }
9575 }
9576 }
9577
9578 // If we are ready to perform an app transition, check through
9579 // all of the app tokens to be shown and see if they are ready
9580 // to go.
9581 if (mAppTransitionReady) {
9582 int NN = mOpeningApps.size();
9583 boolean goodToGo = true;
9584 if (DEBUG_APP_TRANSITIONS) Log.v(TAG,
9585 "Checking " + NN + " opening apps (frozen="
9586 + mDisplayFrozen + " timeout="
9587 + mAppTransitionTimeout + ")...");
9588 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9589 // If the display isn't frozen, wait to do anything until
9590 // all of the apps are ready. Otherwise just go because
9591 // we'll unfreeze the display when everyone is ready.
9592 for (i=0; i<NN && goodToGo; i++) {
9593 AppWindowToken wtoken = mOpeningApps.get(i);
9594 if (DEBUG_APP_TRANSITIONS) Log.v(TAG,
9595 "Check opening app" + wtoken + ": allDrawn="
9596 + wtoken.allDrawn + " startingDisplayed="
9597 + wtoken.startingDisplayed);
9598 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9599 && !wtoken.startingMoved) {
9600 goodToGo = false;
9601 }
9602 }
9603 }
9604 if (goodToGo) {
9605 if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "**** GOOD TO GO");
9606 int transit = mNextAppTransition;
9607 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009608 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009609 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009610 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009611 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009612 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009613 mAppTransitionTimeout = false;
9614 mStartingIconInTransition = false;
9615 mSkipAppTransitionAnimation = false;
9616
9617 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9618
Dianne Hackborna8f60182009-09-01 19:01:50 -07009619 // If there are applications waiting to come to the
9620 // top of the stack, now is the time to move their windows.
9621 // (Note that we don't do apps going to the bottom
9622 // here -- we want to keep their windows in the old
9623 // Z-order until the animation completes.)
9624 if (mToTopApps.size() > 0) {
9625 NN = mAppTokens.size();
9626 for (i=0; i<NN; i++) {
9627 AppWindowToken wtoken = mAppTokens.get(i);
9628 if (wtoken.sendingToTop) {
9629 wtoken.sendingToTop = false;
9630 moveAppWindowsLocked(wtoken, NN, false);
9631 }
9632 }
9633 mToTopApps.clear();
9634 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009635
Dianne Hackborn25994b42009-09-04 14:21:19 -07009636 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009637
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009638 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009639 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009640
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009641 // The top-most window will supply the layout params,
9642 // and we will determine it below.
9643 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009644 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009645 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009646
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009647 if (DEBUG_APP_TRANSITIONS) Log.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009648 "New wallpaper target=" + mWallpaperTarget
9649 + ", lower target=" + mLowerWallpaperTarget
9650 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009651 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009652 // Do a first pass through the tokens for two
9653 // things:
9654 // (1) Determine if both the closing and opening
9655 // app token sets are wallpaper targets, in which
9656 // case special animations are needed
9657 // (since the wallpaper needs to stay static
9658 // behind them).
9659 // (2) Find the layout params of the top-most
9660 // application window in the tokens, which is
9661 // what will control the animation theme.
9662 final int NC = mClosingApps.size();
9663 NN = NC + mOpeningApps.size();
9664 for (i=0; i<NN; i++) {
9665 AppWindowToken wtoken;
9666 int mode;
9667 if (i < NC) {
9668 wtoken = mClosingApps.get(i);
9669 mode = 1;
9670 } else {
9671 wtoken = mOpeningApps.get(i-NC);
9672 mode = 2;
9673 }
9674 if (mLowerWallpaperTarget != null) {
9675 if (mLowerWallpaperTarget.mAppToken == wtoken
9676 || mUpperWallpaperTarget.mAppToken == wtoken) {
9677 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009678 }
9679 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009680 if (wtoken.appFullscreen) {
9681 WindowState ws = wtoken.findMainWindow();
9682 if (ws != null) {
9683 // If this is a compatibility mode
9684 // window, we will always use its anim.
9685 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9686 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009687 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009688 bestAnimLayer = Integer.MAX_VALUE;
9689 } else if (ws.mLayer > bestAnimLayer) {
9690 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009691 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009692 bestAnimLayer = ws.mLayer;
9693 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009694 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009695 }
9696 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009697
Dianne Hackborn25994b42009-09-04 14:21:19 -07009698 if (foundWallpapers == 3) {
9699 if (DEBUG_APP_TRANSITIONS) Log.v(TAG,
9700 "Wallpaper animation!");
9701 switch (transit) {
9702 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9703 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9704 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9705 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9706 break;
9707 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9708 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9709 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9710 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9711 break;
9712 }
9713 if (DEBUG_APP_TRANSITIONS) Log.v(TAG,
9714 "New transit: " + transit);
9715 } else if (oldWallpaper != null) {
9716 // We are transitioning from an activity with
9717 // a wallpaper to one without.
9718 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
9719 if (DEBUG_APP_TRANSITIONS) Log.v(TAG,
9720 "New transit away from wallpaper: " + transit);
9721 } else if (mWallpaperTarget != null) {
9722 // We are transitioning from an activity without
9723 // a wallpaper to now showing the wallpaper
9724 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
9725 if (DEBUG_APP_TRANSITIONS) Log.v(TAG,
9726 "New transit into wallpaper: " + transit);
9727 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009728
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009729 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9730 mLastEnterAnimToken = animToken;
9731 mLastEnterAnimParams = animLp;
9732 } else if (mLastEnterAnimParams != null) {
9733 animLp = mLastEnterAnimParams;
9734 mLastEnterAnimToken = null;
9735 mLastEnterAnimParams = null;
9736 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009737
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009738 // If all closing windows are obscured, then there is
9739 // no need to do an animation. This is the case, for
9740 // example, when this transition is being done behind
9741 // the lock screen.
9742 if (!mPolicy.allowAppAnimationsLw()) {
9743 animLp = null;
9744 }
9745
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009746 NN = mOpeningApps.size();
9747 for (i=0; i<NN; i++) {
9748 AppWindowToken wtoken = mOpeningApps.get(i);
9749 if (DEBUG_APP_TRANSITIONS) Log.v(TAG,
9750 "Now opening app" + wtoken);
9751 wtoken.reportedVisible = false;
9752 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009753 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009754 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009755 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009756 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009757 wtoken.showAllWindowsLocked();
9758 }
9759 NN = mClosingApps.size();
9760 for (i=0; i<NN; i++) {
9761 AppWindowToken wtoken = mClosingApps.get(i);
9762 if (DEBUG_APP_TRANSITIONS) Log.v(TAG,
9763 "Now closing app" + wtoken);
9764 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009765 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009766 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009767 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009768 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009769 // Force the allDrawn flag, because we want to start
9770 // this guy's animations regardless of whether it's
9771 // gotten drawn.
9772 wtoken.allDrawn = true;
9773 }
9774
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009775 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009777 mOpeningApps.clear();
9778 mClosingApps.clear();
9779
9780 // This has changed the visibility of windows, so perform
9781 // a new layout to get them all up-to-date.
9782 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009783 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9784 assignLayersLocked();
9785 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009786 performLayoutLockedInner();
9787 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009788 focusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009789
9790 restart = true;
9791 }
9792 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009793
Dianne Hackborna8f60182009-09-01 19:01:50 -07009794 if (!animating && mAppTransitionRunning) {
9795 // We have finished the animation of an app transition. To do
9796 // this, we have delayed a lot of operations like showing and
9797 // hiding apps, moving apps in Z-order, etc. The app token list
9798 // reflects the correct Z-order, but the window list may now
9799 // be out of sync with it. So here we will just rebuild the
9800 // entire app window list. Fun!
9801 mAppTransitionRunning = false;
9802 // Clear information about apps that were moving.
9803 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009804
Dianne Hackborna8f60182009-09-01 19:01:50 -07009805 rebuildAppWindowListLocked();
9806 restart = true;
9807 moveInputMethodWindowsIfNeededLocked(false);
9808 wallpaperMayChange = true;
9809 mLayoutNeeded = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009810 // Since the window list has been rebuilt, focus might
9811 // have to be recomputed since the actual order of windows
9812 // might have changed again.
9813 focusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009814 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009815
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009816 int adjResult = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009817
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009818 if (wallpaperForceHidingChanged && !restart && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009819 // At this point, there was a window with a wallpaper that
9820 // was force hiding other windows behind it, but now it
9821 // is going away. This may be simple -- just animate
9822 // away the wallpaper and its window -- or it may be
9823 // hard -- the wallpaper now needs to be shown behind
9824 // something that was hidden.
9825 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009826 if (mLowerWallpaperTarget != null
9827 && mLowerWallpaperTarget.mAppToken != null) {
9828 if (DEBUG_WALLPAPER) Log.v(TAG,
9829 "wallpaperForceHiding changed with lower="
9830 + mLowerWallpaperTarget);
9831 if (DEBUG_WALLPAPER) Log.v(TAG,
9832 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9833 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9834 if (mLowerWallpaperTarget.mAppToken.hidden) {
9835 // The lower target has become hidden before we
9836 // actually started the animation... let's completely
9837 // re-evaluate everything.
9838 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
9839 restart = true;
9840 }
9841 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009842 adjResult = adjustWallpaperWindowsLocked();
9843 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009844 wallpaperForceHidingChanged = false;
9845 if (DEBUG_WALLPAPER) Log.v(TAG, "****** OLD: " + oldWallpaper
9846 + " NEW: " + mWallpaperTarget
9847 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009848 if (mLowerWallpaperTarget == null) {
9849 // Whoops, we don't need a special wallpaper animation.
9850 // Clear them out.
9851 forceHiding = false;
9852 for (i=N-1; i>=0; i--) {
9853 WindowState w = (WindowState)mWindows.get(i);
9854 if (w.mSurface != null) {
9855 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009856 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
9857 if (DEBUG_FOCUS) Log.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009858 forceHiding = true;
9859 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9860 if (!w.mAnimating) {
9861 // We set the animation above so it
9862 // is not yet running.
9863 w.clearAnimation();
9864 }
9865 }
9866 }
9867 }
9868 }
9869 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009870
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009871 if (wallpaperMayChange) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009872 if (DEBUG_WALLPAPER) Log.v(TAG,
9873 "Wallpaper may change! Adjusting");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009874 adjResult = adjustWallpaperWindowsLocked();
9875 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009876
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009877 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9878 if (DEBUG_WALLPAPER) Log.v(TAG,
9879 "Wallpaper layer changed: assigning layers + relayout");
9880 restart = true;
9881 mLayoutNeeded = true;
9882 assignLayersLocked();
9883 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
9884 if (DEBUG_WALLPAPER) Log.v(TAG,
9885 "Wallpaper visibility changed: relayout");
9886 restart = true;
9887 mLayoutNeeded = true;
9888 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009889
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009890 if (focusMayChange) {
9891 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009892 restart = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009893 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009894 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009895 }
9896
9897 if (mLayoutNeeded) {
9898 restart = true;
9899 performLayoutLockedInner();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009900 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009901
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009902 if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "*** ANIM STEP: restart="
9903 + restart);
9904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009905 } while (restart);
9906
9907 // THIRD LOOP: Update the surfaces of all windows.
9908
9909 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9910
9911 boolean obscured = false;
9912 boolean blurring = false;
9913 boolean dimming = false;
9914 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009915 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009916 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009917
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009918 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009920 for (i=N-1; i>=0; i--) {
9921 WindowState w = (WindowState)mWindows.get(i);
9922
9923 boolean displayed = false;
9924 final WindowManager.LayoutParams attrs = w.mAttrs;
9925 final int attrFlags = attrs.flags;
9926
9927 if (w.mSurface != null) {
9928 w.computeShownFrameLocked();
9929 if (localLOGV) Log.v(
9930 TAG, "Placing surface #" + i + " " + w.mSurface
9931 + ": new=" + w.mShownFrame + ", old="
9932 + w.mLastShownFrame);
9933
9934 boolean resize;
9935 int width, height;
9936 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9937 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9938 w.mLastRequestedHeight != w.mRequestedHeight;
9939 // for a scaled surface, we just want to use
9940 // the requested size.
9941 width = w.mRequestedWidth;
9942 height = w.mRequestedHeight;
9943 w.mLastRequestedWidth = width;
9944 w.mLastRequestedHeight = height;
9945 w.mLastShownFrame.set(w.mShownFrame);
9946 try {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009947 if (SHOW_TRANSACTIONS) Log.i(
9948 TAG, " SURFACE " + w.mSurface
9949 + ": POS " + w.mShownFrame.left
9950 + ", " + w.mShownFrame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009951 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9952 } catch (RuntimeException e) {
9953 Log.w(TAG, "Error positioning surface in " + w, e);
9954 if (!recoveringMemory) {
9955 reclaimSomeSurfaceMemoryLocked(w, "position");
9956 }
9957 }
9958 } else {
9959 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9960 width = w.mShownFrame.width();
9961 height = w.mShownFrame.height();
9962 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009963 }
9964
9965 if (resize) {
9966 if (width < 1) width = 1;
9967 if (height < 1) height = 1;
9968 if (w.mSurface != null) {
9969 try {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009970 if (SHOW_TRANSACTIONS) Log.i(
9971 TAG, " SURFACE " + w.mSurface + ": POS "
9972 + w.mShownFrame.left + ","
9973 + w.mShownFrame.top + " SIZE "
9974 + w.mShownFrame.width() + "x"
9975 + w.mShownFrame.height());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009976 w.mSurface.setSize(width, height);
9977 w.mSurface.setPosition(w.mShownFrame.left,
9978 w.mShownFrame.top);
9979 } catch (RuntimeException e) {
9980 // If something goes wrong with the surface (such
9981 // as running out of memory), don't take down the
9982 // entire system.
9983 Log.e(TAG, "Failure updating surface of " + w
9984 + "size=(" + width + "x" + height
9985 + "), pos=(" + w.mShownFrame.left
9986 + "," + w.mShownFrame.top + ")", e);
9987 if (!recoveringMemory) {
9988 reclaimSomeSurfaceMemoryLocked(w, "size");
9989 }
9990 }
9991 }
9992 }
9993 if (!w.mAppFreezing) {
9994 w.mContentInsetsChanged =
9995 !w.mLastContentInsets.equals(w.mContentInsets);
9996 w.mVisibleInsetsChanged =
9997 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Romain Guy06882f82009-06-10 13:36:04 -07009998 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009999 || w.mContentInsetsChanged
10000 || w.mVisibleInsetsChanged) {
10001 w.mLastFrame.set(w.mFrame);
10002 w.mLastContentInsets.set(w.mContentInsets);
10003 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010004 // If the screen is currently frozen, then keep
10005 // it frozen until this window draws at its new
10006 // orientation.
10007 if (mDisplayFrozen) {
10008 if (DEBUG_ORIENTATION) Log.v(TAG,
10009 "Resizing while display frozen: " + w);
10010 w.mOrientationChanging = true;
10011 if (mWindowsFreezingScreen) {
10012 mWindowsFreezingScreen = true;
10013 // XXX should probably keep timeout from
10014 // when we first froze the display.
10015 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10016 mH.sendMessageDelayed(mH.obtainMessage(
10017 H.WINDOW_FREEZE_TIMEOUT), 2000);
10018 }
10019 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010020 // If the orientation is changing, then we need to
10021 // hold off on unfreezing the display until this
10022 // window has been redrawn; to do that, we need
10023 // to go through the process of getting informed
10024 // by the application when it has finished drawing.
10025 if (w.mOrientationChanging) {
10026 if (DEBUG_ORIENTATION) Log.v(TAG,
10027 "Orientation start waiting for draw in "
10028 + w + ", surface " + w.mSurface);
10029 w.mDrawPending = true;
10030 w.mCommitDrawPending = false;
10031 w.mReadyToShow = false;
10032 if (w.mAppToken != null) {
10033 w.mAppToken.allDrawn = false;
10034 }
10035 }
Romain Guy06882f82009-06-10 13:36:04 -070010036 if (DEBUG_ORIENTATION) Log.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010037 "Resizing window " + w + " to " + w.mFrame);
10038 mResizingWindows.add(w);
10039 } else if (w.mOrientationChanging) {
10040 if (!w.mDrawPending && !w.mCommitDrawPending) {
10041 if (DEBUG_ORIENTATION) Log.v(TAG,
10042 "Orientation not waiting for draw in "
10043 + w + ", surface " + w.mSurface);
10044 w.mOrientationChanging = false;
10045 }
10046 }
10047 }
10048
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010049 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010050 if (!w.mLastHidden) {
10051 //dump();
10052 w.mLastHidden = true;
10053 if (SHOW_TRANSACTIONS) Log.i(
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010054 TAG, " SURFACE " + w.mSurface + ": HIDE (performLayout)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010055 if (w.mSurface != null) {
10056 try {
10057 w.mSurface.hide();
10058 } catch (RuntimeException e) {
10059 Log.w(TAG, "Exception hiding surface in " + w);
10060 }
10061 }
10062 mKeyWaiter.releasePendingPointerLocked(w.mSession);
10063 }
10064 // If we are waiting for this window to handle an
10065 // orientation change, well, it is hidden, so
10066 // doesn't really matter. Note that this does
10067 // introduce a potential glitch if the window
10068 // becomes unhidden before it has drawn for the
10069 // new orientation.
10070 if (w.mOrientationChanging) {
10071 w.mOrientationChanging = false;
10072 if (DEBUG_ORIENTATION) Log.v(TAG,
10073 "Orientation change skips hidden " + w);
10074 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010075 } else if (w.mLastLayer != w.mAnimLayer
10076 || w.mLastAlpha != w.mShownAlpha
10077 || w.mLastDsDx != w.mDsDx
10078 || w.mLastDtDx != w.mDtDx
10079 || w.mLastDsDy != w.mDsDy
10080 || w.mLastDtDy != w.mDtDy
10081 || w.mLastHScale != w.mHScale
10082 || w.mLastVScale != w.mVScale
10083 || w.mLastHidden) {
10084 displayed = true;
10085 w.mLastAlpha = w.mShownAlpha;
10086 w.mLastLayer = w.mAnimLayer;
10087 w.mLastDsDx = w.mDsDx;
10088 w.mLastDtDx = w.mDtDx;
10089 w.mLastDsDy = w.mDsDy;
10090 w.mLastDtDy = w.mDtDy;
10091 w.mLastHScale = w.mHScale;
10092 w.mLastVScale = w.mVScale;
10093 if (SHOW_TRANSACTIONS) Log.i(
10094 TAG, " SURFACE " + w.mSurface + ": alpha="
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010095 + w.mShownAlpha + " layer=" + w.mAnimLayer
10096 + " matrix=[" + (w.mDsDx*w.mHScale)
10097 + "," + (w.mDtDx*w.mVScale)
10098 + "][" + (w.mDsDy*w.mHScale)
10099 + "," + (w.mDtDy*w.mVScale) + "]");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010100 if (w.mSurface != null) {
10101 try {
10102 w.mSurface.setAlpha(w.mShownAlpha);
10103 w.mSurface.setLayer(w.mAnimLayer);
10104 w.mSurface.setMatrix(
10105 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10106 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10107 } catch (RuntimeException e) {
10108 Log.w(TAG, "Error updating surface in " + w, e);
10109 if (!recoveringMemory) {
10110 reclaimSomeSurfaceMemoryLocked(w, "update");
10111 }
10112 }
10113 }
10114
10115 if (w.mLastHidden && !w.mDrawPending
10116 && !w.mCommitDrawPending
10117 && !w.mReadyToShow) {
10118 if (SHOW_TRANSACTIONS) Log.i(
10119 TAG, " SURFACE " + w.mSurface + ": SHOW (performLayout)");
10120 if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + w
10121 + " during relayout");
10122 if (showSurfaceRobustlyLocked(w)) {
10123 w.mHasDrawn = true;
10124 w.mLastHidden = false;
10125 } else {
10126 w.mOrientationChanging = false;
10127 }
10128 }
10129 if (w.mSurface != null) {
10130 w.mToken.hasVisible = true;
10131 }
10132 } else {
10133 displayed = true;
10134 }
10135
10136 if (displayed) {
10137 if (!covered) {
10138 if (attrs.width == LayoutParams.FILL_PARENT
10139 && attrs.height == LayoutParams.FILL_PARENT) {
10140 covered = true;
10141 }
10142 }
10143 if (w.mOrientationChanging) {
10144 if (w.mDrawPending || w.mCommitDrawPending) {
10145 orientationChangeComplete = false;
10146 if (DEBUG_ORIENTATION) Log.v(TAG,
10147 "Orientation continue waiting for draw in " + w);
10148 } else {
10149 w.mOrientationChanging = false;
10150 if (DEBUG_ORIENTATION) Log.v(TAG,
10151 "Orientation change complete in " + w);
10152 }
10153 }
10154 w.mToken.hasVisible = true;
10155 }
10156 } else if (w.mOrientationChanging) {
10157 if (DEBUG_ORIENTATION) Log.v(TAG,
10158 "Orientation change skips hidden " + w);
10159 w.mOrientationChanging = false;
10160 }
10161
10162 final boolean canBeSeen = w.isDisplayedLw();
10163
10164 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10165 focusDisplayed = true;
10166 }
10167
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010168 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010170 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010171 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010172 if (w.mSurface != null) {
10173 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10174 holdScreen = w.mSession;
10175 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010176 if (!syswin && w.mAttrs.screenBrightness >= 0
10177 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010178 screenBrightness = w.mAttrs.screenBrightness;
10179 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010180 if (!syswin && w.mAttrs.buttonBrightness >= 0
10181 && buttonBrightness < 0) {
10182 buttonBrightness = w.mAttrs.buttonBrightness;
10183 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010184 if (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10185 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10186 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR) {
10187 syswin = true;
10188 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010189 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010190
Dianne Hackborn25994b42009-09-04 14:21:19 -070010191 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10192 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010193 // This window completely covers everything behind it,
10194 // so we want to leave all of them as unblurred (for
10195 // performance reasons).
10196 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010197 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
10198 if (SHOW_TRANSACTIONS) Log.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010199 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010200 obscured = true;
10201 if (mBackgroundFillerSurface == null) {
10202 try {
10203 mBackgroundFillerSurface = new Surface(mFxSession, 0,
10204 0, dw, dh,
10205 PixelFormat.OPAQUE,
10206 Surface.FX_SURFACE_NORMAL);
10207 } catch (Exception e) {
10208 Log.e(TAG, "Exception creating filler surface", e);
10209 }
10210 }
10211 try {
10212 mBackgroundFillerSurface.setPosition(0, 0);
10213 mBackgroundFillerSurface.setSize(dw, dh);
10214 // Using the same layer as Dim because they will never be shown at the
10215 // same time.
10216 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10217 mBackgroundFillerSurface.show();
10218 } catch (RuntimeException e) {
10219 Log.e(TAG, "Exception showing filler surface");
10220 }
10221 backgroundFillerShown = true;
10222 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010223 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010224 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
10225 if (localLOGV) Log.v(TAG, "Win " + w
10226 + ": blurring=" + blurring
10227 + " obscured=" + obscured
10228 + " displayed=" + displayed);
10229 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10230 if (!dimming) {
10231 //Log.i(TAG, "DIM BEHIND: " + w);
10232 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010233 if (mDimAnimator == null) {
10234 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010235 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010236 mDimAnimator.show(dw, dh);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010237 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010238 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010239 }
10240 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10241 if (!blurring) {
10242 //Log.i(TAG, "BLUR BEHIND: " + w);
10243 blurring = true;
10244 mBlurShown = true;
10245 if (mBlurSurface == null) {
10246 if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR "
10247 + mBlurSurface + ": CREATE");
10248 try {
Romain Guy06882f82009-06-10 13:36:04 -070010249 mBlurSurface = new Surface(mFxSession, 0,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010250 -1, 16, 16,
10251 PixelFormat.OPAQUE,
10252 Surface.FX_SURFACE_BLUR);
10253 } catch (Exception e) {
10254 Log.e(TAG, "Exception creating Blur surface", e);
10255 }
10256 }
10257 if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR "
10258 + mBlurSurface + ": SHOW pos=(0,0) (" +
10259 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
10260 if (mBlurSurface != null) {
10261 mBlurSurface.setPosition(0, 0);
10262 mBlurSurface.setSize(dw, dh);
10263 try {
10264 mBlurSurface.show();
10265 } catch (RuntimeException e) {
10266 Log.w(TAG, "Failure showing blur surface", e);
10267 }
10268 }
10269 }
10270 mBlurSurface.setLayer(w.mAnimLayer-2);
10271 }
10272 }
10273 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010274
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010275 if (obscuredChanged && mWallpaperTarget == w) {
10276 // This is the wallpaper target and its obscured state
10277 // changed... make sure the current wallaper's visibility
10278 // has been updated accordingly.
10279 updateWallpaperVisibilityLocked();
10280 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010281 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010282
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010283 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10284 mBackgroundFillerShown = false;
10285 if (SHOW_TRANSACTIONS) Log.d(TAG, "hiding background filler");
10286 try {
10287 mBackgroundFillerSurface.hide();
10288 } catch (RuntimeException e) {
10289 Log.e(TAG, "Exception hiding filler surface", e);
10290 }
10291 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010292
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010293 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010294 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10295 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010296 }
Romain Guy06882f82009-06-10 13:36:04 -070010297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010298 if (!blurring && mBlurShown) {
10299 if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " + mBlurSurface
10300 + ": HIDE");
10301 try {
10302 mBlurSurface.hide();
10303 } catch (IllegalArgumentException e) {
10304 Log.w(TAG, "Illegal argument exception hiding blur surface");
10305 }
10306 mBlurShown = false;
10307 }
10308
10309 if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION");
10310 } catch (RuntimeException e) {
10311 Log.e(TAG, "Unhandled exception in Window Manager", e);
10312 }
10313
10314 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010316 if (DEBUG_ORIENTATION && mDisplayFrozen) Log.v(TAG,
10317 "With display frozen, orientationChangeComplete="
10318 + orientationChangeComplete);
10319 if (orientationChangeComplete) {
10320 if (mWindowsFreezingScreen) {
10321 mWindowsFreezingScreen = false;
10322 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10323 }
10324 if (mAppsFreezingScreen == 0) {
10325 stopFreezingDisplayLocked();
10326 }
10327 }
Romain Guy06882f82009-06-10 13:36:04 -070010328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010329 i = mResizingWindows.size();
10330 if (i > 0) {
10331 do {
10332 i--;
10333 WindowState win = mResizingWindows.get(i);
10334 try {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010335 if (DEBUG_ORIENTATION) Log.v(TAG, "Reporting new frame to "
10336 + win + ": " + win.mFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010337 win.mClient.resized(win.mFrame.width(),
10338 win.mFrame.height(), win.mLastContentInsets,
10339 win.mLastVisibleInsets, win.mDrawPending);
10340 win.mContentInsetsChanged = false;
10341 win.mVisibleInsetsChanged = false;
10342 } catch (RemoteException e) {
10343 win.mOrientationChanging = false;
10344 }
10345 } while (i > 0);
10346 mResizingWindows.clear();
10347 }
Romain Guy06882f82009-06-10 13:36:04 -070010348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010349 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010350 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010351 i = mDestroySurface.size();
10352 if (i > 0) {
10353 do {
10354 i--;
10355 WindowState win = mDestroySurface.get(i);
10356 win.mDestroying = false;
10357 if (mInputMethodWindow == win) {
10358 mInputMethodWindow = null;
10359 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010360 if (win == mWallpaperTarget) {
10361 wallpaperDestroyed = true;
10362 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010363 win.destroySurfaceLocked();
10364 } while (i > 0);
10365 mDestroySurface.clear();
10366 }
10367
10368 // Time to remove any exiting tokens?
10369 for (i=mExitingTokens.size()-1; i>=0; i--) {
10370 WindowToken token = mExitingTokens.get(i);
10371 if (!token.hasVisible) {
10372 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010373 if (token.windowType == TYPE_WALLPAPER) {
10374 mWallpaperTokens.remove(token);
10375 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010376 }
10377 }
10378
10379 // Time to remove any exiting applications?
10380 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10381 AppWindowToken token = mExitingAppTokens.get(i);
10382 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010383 // Make sure there is no animation running on this token,
10384 // so any windows associated with it will be removed as
10385 // soon as their animations are complete
10386 token.animation = null;
10387 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010388 mAppTokens.remove(token);
10389 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010390 if (mLastEnterAnimToken == token) {
10391 mLastEnterAnimToken = null;
10392 mLastEnterAnimParams = null;
10393 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010394 }
10395 }
10396
Dianne Hackborna8f60182009-09-01 19:01:50 -070010397 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010398
Dianne Hackborna8f60182009-09-01 19:01:50 -070010399 if (!animating && mAppTransitionRunning) {
10400 // We have finished the animation of an app transition. To do
10401 // this, we have delayed a lot of operations like showing and
10402 // hiding apps, moving apps in Z-order, etc. The app token list
10403 // reflects the correct Z-order, but the window list may now
10404 // be out of sync with it. So here we will just rebuild the
10405 // entire app window list. Fun!
10406 mAppTransitionRunning = false;
10407 needRelayout = true;
10408 rebuildAppWindowListLocked();
10409 // Clear information about apps that were moving.
10410 mToBottomApps.clear();
10411 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010413 if (focusDisplayed) {
10414 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10415 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010416 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010417 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010418 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010419 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010420 requestAnimationLocked(0);
10421 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010422 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10423 }
10424 mQueue.setHoldScreenLocked(holdScreen != null);
10425 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10426 mPowerManager.setScreenBrightnessOverride(-1);
10427 } else {
10428 mPowerManager.setScreenBrightnessOverride((int)
10429 (screenBrightness * Power.BRIGHTNESS_ON));
10430 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010431 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10432 mPowerManager.setButtonBrightnessOverride(-1);
10433 } else {
10434 mPowerManager.setButtonBrightnessOverride((int)
10435 (buttonBrightness * Power.BRIGHTNESS_ON));
10436 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010437 if (holdScreen != mHoldingScreenOn) {
10438 mHoldingScreenOn = holdScreen;
10439 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10440 mH.sendMessage(m);
10441 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010442
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010443 if (mTurnOnScreen) {
10444 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10445 LocalPowerManager.BUTTON_EVENT, true);
10446 mTurnOnScreen = false;
10447 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010448
10449 // Check to see if we are now in a state where the screen should
10450 // be enabled, because the window obscured flags have changed.
10451 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010452 }
10453
10454 void requestAnimationLocked(long delay) {
10455 if (!mAnimationPending) {
10456 mAnimationPending = true;
10457 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10458 }
10459 }
Romain Guy06882f82009-06-10 13:36:04 -070010460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010461 /**
10462 * Have the surface flinger show a surface, robustly dealing with
10463 * error conditions. In particular, if there is not enough memory
10464 * to show the surface, then we will try to get rid of other surfaces
10465 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010466 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010467 * @return Returns true if the surface was successfully shown.
10468 */
10469 boolean showSurfaceRobustlyLocked(WindowState win) {
10470 try {
10471 if (win.mSurface != null) {
10472 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010473 if (win.mTurnOnScreen) {
10474 win.mTurnOnScreen = false;
10475 mTurnOnScreen = true;
10476 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010477 }
10478 return true;
10479 } catch (RuntimeException e) {
10480 Log.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
10481 }
Romain Guy06882f82009-06-10 13:36:04 -070010482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010483 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010485 return false;
10486 }
Romain Guy06882f82009-06-10 13:36:04 -070010487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010488 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10489 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010490
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010491 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010492 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010494 if (mForceRemoves == null) {
10495 mForceRemoves = new ArrayList<WindowState>();
10496 }
Romain Guy06882f82009-06-10 13:36:04 -070010497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010498 long callingIdentity = Binder.clearCallingIdentity();
10499 try {
10500 // There was some problem... first, do a sanity check of the
10501 // window list to make sure we haven't left any dangling surfaces
10502 // around.
10503 int N = mWindows.size();
10504 boolean leakedSurface = false;
10505 Log.i(TAG, "Out of memory for surface! Looking for leaks...");
10506 for (int i=0; i<N; i++) {
10507 WindowState ws = (WindowState)mWindows.get(i);
10508 if (ws.mSurface != null) {
10509 if (!mSessions.contains(ws.mSession)) {
10510 Log.w(TAG, "LEAKED SURFACE (session doesn't exist): "
10511 + ws + " surface=" + ws.mSurface
10512 + " token=" + win.mToken
10513 + " pid=" + ws.mSession.mPid
10514 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010515 ws.mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010516 ws.mSurface = null;
10517 mForceRemoves.add(ws);
10518 i--;
10519 N--;
10520 leakedSurface = true;
10521 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
10522 Log.w(TAG, "LEAKED SURFACE (app token hidden): "
10523 + ws + " surface=" + ws.mSurface
10524 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010525 ws.mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010526 ws.mSurface = null;
10527 leakedSurface = true;
10528 }
10529 }
10530 }
Romain Guy06882f82009-06-10 13:36:04 -070010531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010532 boolean killedApps = false;
10533 if (!leakedSurface) {
10534 Log.w(TAG, "No leaked surfaces; killing applicatons!");
10535 SparseIntArray pidCandidates = new SparseIntArray();
10536 for (int i=0; i<N; i++) {
10537 WindowState ws = (WindowState)mWindows.get(i);
10538 if (ws.mSurface != null) {
10539 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10540 }
10541 }
10542 if (pidCandidates.size() > 0) {
10543 int[] pids = new int[pidCandidates.size()];
10544 for (int i=0; i<pids.length; i++) {
10545 pids[i] = pidCandidates.keyAt(i);
10546 }
10547 try {
10548 if (mActivityManager.killPidsForMemory(pids)) {
10549 killedApps = true;
10550 }
10551 } catch (RemoteException e) {
10552 }
10553 }
10554 }
Romain Guy06882f82009-06-10 13:36:04 -070010555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010556 if (leakedSurface || killedApps) {
10557 // We managed to reclaim some memory, so get rid of the trouble
10558 // surface and ask the app to request another one.
10559 Log.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
10560 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010561 surface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010562 win.mSurface = null;
10563 }
Romain Guy06882f82009-06-10 13:36:04 -070010564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010565 try {
10566 win.mClient.dispatchGetNewSurface();
10567 } catch (RemoteException e) {
10568 }
10569 }
10570 } finally {
10571 Binder.restoreCallingIdentity(callingIdentity);
10572 }
10573 }
Romain Guy06882f82009-06-10 13:36:04 -070010574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010575 private boolean updateFocusedWindowLocked(int mode) {
10576 WindowState newFocus = computeFocusedWindowLocked();
10577 if (mCurrentFocus != newFocus) {
10578 // This check makes sure that we don't already have the focus
10579 // change message pending.
10580 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10581 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
10582 if (localLOGV) Log.v(
10583 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10584 final WindowState oldFocus = mCurrentFocus;
10585 mCurrentFocus = newFocus;
10586 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010588 final WindowState imWindow = mInputMethodWindow;
10589 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010590 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010591 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010592 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10593 mLayoutNeeded = true;
10594 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010595 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10596 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010597 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10598 // Client will do the layout, but we need to assign layers
10599 // for handleNewWindowLocked() below.
10600 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010601 }
10602 }
Romain Guy06882f82009-06-10 13:36:04 -070010603
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010604 if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10605 mKeyWaiter.handleNewWindowLocked(newFocus);
10606 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010607 return true;
10608 }
10609 return false;
10610 }
10611
10612 private WindowState computeFocusedWindowLocked() {
10613 WindowState result = null;
10614 WindowState win;
10615
10616 int i = mWindows.size() - 1;
10617 int nextAppIndex = mAppTokens.size()-1;
10618 WindowToken nextApp = nextAppIndex >= 0
10619 ? mAppTokens.get(nextAppIndex) : null;
10620
10621 while (i >= 0) {
10622 win = (WindowState)mWindows.get(i);
10623
10624 if (localLOGV || DEBUG_FOCUS) Log.v(
10625 TAG, "Looking for focus: " + i
10626 + " = " + win
10627 + ", flags=" + win.mAttrs.flags
10628 + ", canReceive=" + win.canReceiveKeys());
10629
10630 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010632 // If this window's application has been removed, just skip it.
10633 if (thisApp != null && thisApp.removed) {
10634 i--;
10635 continue;
10636 }
Romain Guy06882f82009-06-10 13:36:04 -070010637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010638 // If there is a focused app, don't allow focus to go to any
10639 // windows below it. If this is an application window, step
10640 // through the app tokens until we find its app.
10641 if (thisApp != null && nextApp != null && thisApp != nextApp
10642 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10643 int origAppIndex = nextAppIndex;
10644 while (nextAppIndex > 0) {
10645 if (nextApp == mFocusedApp) {
10646 // Whoops, we are below the focused app... no focus
10647 // for you!
10648 if (localLOGV || DEBUG_FOCUS) Log.v(
10649 TAG, "Reached focused app: " + mFocusedApp);
10650 return null;
10651 }
10652 nextAppIndex--;
10653 nextApp = mAppTokens.get(nextAppIndex);
10654 if (nextApp == thisApp) {
10655 break;
10656 }
10657 }
10658 if (thisApp != nextApp) {
10659 // Uh oh, the app token doesn't exist! This shouldn't
10660 // happen, but if it does we can get totally hosed...
10661 // so restart at the original app.
10662 nextAppIndex = origAppIndex;
10663 nextApp = mAppTokens.get(nextAppIndex);
10664 }
10665 }
10666
10667 // Dispatch to this window if it is wants key events.
10668 if (win.canReceiveKeys()) {
10669 if (DEBUG_FOCUS) Log.v(
10670 TAG, "Found focus @ " + i + " = " + win);
10671 result = win;
10672 break;
10673 }
10674
10675 i--;
10676 }
10677
10678 return result;
10679 }
10680
10681 private void startFreezingDisplayLocked() {
10682 if (mDisplayFrozen) {
Chris Tate2ad63a92009-03-25 17:36:48 -070010683 // Freezing the display also suspends key event delivery, to
10684 // keep events from going astray while the display is reconfigured.
10685 // If someone has changed orientation again while the screen is
10686 // still frozen, the events will continue to be blocked while the
10687 // successive orientation change is processed. To prevent spurious
10688 // ANRs, we reset the event dispatch timeout in this case.
10689 synchronized (mKeyWaiter) {
10690 mKeyWaiter.mWasFrozen = true;
10691 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010692 return;
10693 }
Romain Guy06882f82009-06-10 13:36:04 -070010694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010695 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010697 long now = SystemClock.uptimeMillis();
10698 //Log.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
10699 if (mFreezeGcPending != 0) {
10700 if (now > (mFreezeGcPending+1000)) {
10701 //Log.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
10702 mH.removeMessages(H.FORCE_GC);
10703 Runtime.getRuntime().gc();
10704 mFreezeGcPending = now;
10705 }
10706 } else {
10707 mFreezeGcPending = now;
10708 }
Romain Guy06882f82009-06-10 13:36:04 -070010709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010710 mDisplayFrozen = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010711 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10712 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010713 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010714 mAppTransitionReady = true;
10715 }
Romain Guy06882f82009-06-10 13:36:04 -070010716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010717 if (PROFILE_ORIENTATION) {
10718 File file = new File("/data/system/frozen");
10719 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10720 }
10721 Surface.freezeDisplay(0);
10722 }
Romain Guy06882f82009-06-10 13:36:04 -070010723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010724 private void stopFreezingDisplayLocked() {
10725 if (!mDisplayFrozen) {
10726 return;
10727 }
Romain Guy06882f82009-06-10 13:36:04 -070010728
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010729 mDisplayFrozen = false;
10730 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10731 if (PROFILE_ORIENTATION) {
10732 Debug.stopMethodTracing();
10733 }
10734 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010735
Chris Tate2ad63a92009-03-25 17:36:48 -070010736 // Reset the key delivery timeout on unfreeze, too. We force a wakeup here
10737 // too because regular key delivery processing should resume immediately.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010738 synchronized (mKeyWaiter) {
10739 mKeyWaiter.mWasFrozen = true;
10740 mKeyWaiter.notifyAll();
10741 }
10742
10743 // A little kludge: a lot could have happened while the
10744 // display was frozen, so now that we are coming back we
10745 // do a gc so that any remote references the system
10746 // processes holds on others can be released if they are
10747 // no longer needed.
10748 mH.removeMessages(H.FORCE_GC);
10749 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10750 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010752 mScreenFrozenLock.release();
10753 }
Romain Guy06882f82009-06-10 13:36:04 -070010754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010755 @Override
10756 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10757 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10758 != PackageManager.PERMISSION_GRANTED) {
10759 pw.println("Permission Denial: can't dump WindowManager from from pid="
10760 + Binder.getCallingPid()
10761 + ", uid=" + Binder.getCallingUid());
10762 return;
10763 }
Romain Guy06882f82009-06-10 13:36:04 -070010764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010765 synchronized(mWindowMap) {
10766 pw.println("Current Window Manager state:");
10767 for (int i=mWindows.size()-1; i>=0; i--) {
10768 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010769 pw.print(" Window #"); pw.print(i); pw.print(' ');
10770 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010771 w.dump(pw, " ");
10772 }
10773 if (mInputMethodDialogs.size() > 0) {
10774 pw.println(" ");
10775 pw.println(" Input method dialogs:");
10776 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10777 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010778 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010779 }
10780 }
10781 if (mPendingRemove.size() > 0) {
10782 pw.println(" ");
10783 pw.println(" Remove pending for:");
10784 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10785 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010786 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10787 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010788 w.dump(pw, " ");
10789 }
10790 }
10791 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10792 pw.println(" ");
10793 pw.println(" Windows force removing:");
10794 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10795 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010796 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10797 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010798 w.dump(pw, " ");
10799 }
10800 }
10801 if (mDestroySurface.size() > 0) {
10802 pw.println(" ");
10803 pw.println(" Windows waiting to destroy their surface:");
10804 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10805 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010806 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10807 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010808 w.dump(pw, " ");
10809 }
10810 }
10811 if (mLosingFocus.size() > 0) {
10812 pw.println(" ");
10813 pw.println(" Windows losing focus:");
10814 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10815 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010816 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10817 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010818 w.dump(pw, " ");
10819 }
10820 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010821 if (mResizingWindows.size() > 0) {
10822 pw.println(" ");
10823 pw.println(" Windows waiting to resize:");
10824 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10825 WindowState w = mResizingWindows.get(i);
10826 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10827 pw.print(w); pw.println(":");
10828 w.dump(pw, " ");
10829 }
10830 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010831 if (mSessions.size() > 0) {
10832 pw.println(" ");
10833 pw.println(" All active sessions:");
10834 Iterator<Session> it = mSessions.iterator();
10835 while (it.hasNext()) {
10836 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010837 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010838 s.dump(pw, " ");
10839 }
10840 }
10841 if (mTokenMap.size() > 0) {
10842 pw.println(" ");
10843 pw.println(" All tokens:");
10844 Iterator<WindowToken> it = mTokenMap.values().iterator();
10845 while (it.hasNext()) {
10846 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010847 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010848 token.dump(pw, " ");
10849 }
10850 }
10851 if (mTokenList.size() > 0) {
10852 pw.println(" ");
10853 pw.println(" Window token list:");
10854 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010855 pw.print(" #"); pw.print(i); pw.print(": ");
10856 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010857 }
10858 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010859 if (mWallpaperTokens.size() > 0) {
10860 pw.println(" ");
10861 pw.println(" Wallpaper tokens:");
10862 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10863 WindowToken token = mWallpaperTokens.get(i);
10864 pw.print(" Wallpaper #"); pw.print(i);
10865 pw.print(' '); pw.print(token); pw.println(':');
10866 token.dump(pw, " ");
10867 }
10868 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010869 if (mAppTokens.size() > 0) {
10870 pw.println(" ");
10871 pw.println(" Application tokens in Z order:");
10872 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010873 pw.print(" App #"); pw.print(i); pw.print(": ");
10874 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010875 }
10876 }
10877 if (mFinishedStarting.size() > 0) {
10878 pw.println(" ");
10879 pw.println(" Finishing start of application tokens:");
10880 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10881 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010882 pw.print(" Finished Starting #"); pw.print(i);
10883 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010884 token.dump(pw, " ");
10885 }
10886 }
10887 if (mExitingTokens.size() > 0) {
10888 pw.println(" ");
10889 pw.println(" Exiting tokens:");
10890 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10891 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010892 pw.print(" Exiting #"); pw.print(i);
10893 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010894 token.dump(pw, " ");
10895 }
10896 }
10897 if (mExitingAppTokens.size() > 0) {
10898 pw.println(" ");
10899 pw.println(" Exiting application tokens:");
10900 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10901 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010902 pw.print(" Exiting App #"); pw.print(i);
10903 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010904 token.dump(pw, " ");
10905 }
10906 }
10907 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010908 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10909 pw.print(" mLastFocus="); pw.println(mLastFocus);
10910 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10911 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10912 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010913 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010914 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10915 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10916 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10917 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010918 pw.print(" mInTouchMode="); pw.println(mInTouchMode);
10919 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10920 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10921 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10922 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010923 if (mDimAnimator != null) {
10924 mDimAnimator.printTo(pw);
10925 } else {
10926 pw.print( " no DimAnimator ");
10927 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010928 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010929 pw.print(mInputMethodAnimLayerAdjustment);
10930 pw.print(" mWallpaperAnimLayerAdjustment=");
10931 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010932 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10933 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010934 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10935 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
10936 pw.print(" mAppsFreezingScreen="); pw.println(mAppsFreezingScreen);
10937 pw.print(" mRotation="); pw.print(mRotation);
10938 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10939 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10940 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10941 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10942 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10943 pw.print(" mNextAppTransition=0x");
10944 pw.print(Integer.toHexString(mNextAppTransition));
10945 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010946 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010947 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010948 if (mNextAppTransitionPackage != null) {
10949 pw.print(" mNextAppTransitionPackage=");
10950 pw.print(mNextAppTransitionPackage);
10951 pw.print(", mNextAppTransitionEnter=0x");
10952 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10953 pw.print(", mNextAppTransitionExit=0x");
10954 pw.print(Integer.toHexString(mNextAppTransitionExit));
10955 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010956 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10957 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010958 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10959 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10960 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10961 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010962 if (mOpeningApps.size() > 0) {
10963 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10964 }
10965 if (mClosingApps.size() > 0) {
10966 pw.print(" mClosingApps="); pw.println(mClosingApps);
10967 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010968 if (mToTopApps.size() > 0) {
10969 pw.print(" mToTopApps="); pw.println(mToTopApps);
10970 }
10971 if (mToBottomApps.size() > 0) {
10972 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10973 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010974 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10975 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010976 pw.println(" KeyWaiter state:");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010977 pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin);
10978 pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder);
10979 pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished);
10980 pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow);
10981 pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching);
10982 pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010983 }
10984 }
10985
10986 public void monitor() {
10987 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010988 synchronized (mKeyguardTokenWatcher) { }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010989 synchronized (mKeyWaiter) { }
10990 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010991
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010992 public void virtualKeyFeedback(KeyEvent event) {
10993 mPolicy.keyFeedbackFromInput(event);
10994 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010995
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010996 /**
10997 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010998 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010999 */
11000 private static class DimAnimator {
11001 Surface mDimSurface;
11002 boolean mDimShown = false;
11003 float mDimCurrentAlpha;
11004 float mDimTargetAlpha;
11005 float mDimDeltaPerMs;
11006 long mLastDimAnimTime;
11007
11008 DimAnimator (SurfaceSession session) {
11009 if (mDimSurface == null) {
11010 if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM "
11011 + mDimSurface + ": CREATE");
11012 try {
11013 mDimSurface = new Surface(session, 0, -1, 16, 16, PixelFormat.OPAQUE,
11014 Surface.FX_SURFACE_DIM);
11015 } catch (Exception e) {
11016 Log.e(TAG, "Exception creating Dim surface", e);
11017 }
11018 }
11019 }
11020
11021 /**
11022 * Show the dim surface.
11023 */
11024 void show(int dw, int dh) {
11025 if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11026 dw + "x" + dh + ")");
11027 mDimShown = true;
11028 try {
11029 mDimSurface.setPosition(0, 0);
11030 mDimSurface.setSize(dw, dh);
11031 mDimSurface.show();
11032 } catch (RuntimeException e) {
11033 Log.w(TAG, "Failure showing dim surface", e);
11034 }
11035 }
11036
11037 /**
11038 * Set's the dim surface's layer and update dim parameters that will be used in
11039 * {@link updateSurface} after all windows are examined.
11040 */
11041 void updateParameters(WindowState w, long currentTime) {
11042 mDimSurface.setLayer(w.mAnimLayer-1);
11043
11044 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011045 if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface
11046 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011047 if (mDimTargetAlpha != target) {
11048 // If the desired dim level has changed, then
11049 // start an animation to it.
11050 mLastDimAnimTime = currentTime;
11051 long duration = (w.mAnimating && w.mAnimation != null)
11052 ? w.mAnimation.computeDurationHint()
11053 : DEFAULT_DIM_DURATION;
11054 if (target > mDimTargetAlpha) {
11055 // This is happening behind the activity UI,
11056 // so we can make it run a little longer to
11057 // give a stronger impression without disrupting
11058 // the user.
11059 duration *= DIM_DURATION_MULTIPLIER;
11060 }
11061 if (duration < 1) {
11062 // Don't divide by zero
11063 duration = 1;
11064 }
11065 mDimTargetAlpha = target;
11066 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11067 }
11068 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011069
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011070 /**
11071 * Updating the surface's alpha. Returns true if the animation continues, or returns
11072 * false when the animation is finished and the dim surface is hidden.
11073 */
11074 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11075 if (!dimming) {
11076 if (mDimTargetAlpha != 0) {
11077 mLastDimAnimTime = currentTime;
11078 mDimTargetAlpha = 0;
11079 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11080 }
11081 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011082
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011083 boolean animating = false;
11084 if (mLastDimAnimTime != 0) {
11085 mDimCurrentAlpha += mDimDeltaPerMs
11086 * (currentTime-mLastDimAnimTime);
11087 boolean more = true;
11088 if (displayFrozen) {
11089 // If the display is frozen, there is no reason to animate.
11090 more = false;
11091 } else if (mDimDeltaPerMs > 0) {
11092 if (mDimCurrentAlpha > mDimTargetAlpha) {
11093 more = false;
11094 }
11095 } else if (mDimDeltaPerMs < 0) {
11096 if (mDimCurrentAlpha < mDimTargetAlpha) {
11097 more = false;
11098 }
11099 } else {
11100 more = false;
11101 }
11102
11103 // Do we need to continue animating?
11104 if (more) {
11105 if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM "
11106 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11107 mLastDimAnimTime = currentTime;
11108 mDimSurface.setAlpha(mDimCurrentAlpha);
11109 animating = true;
11110 } else {
11111 mDimCurrentAlpha = mDimTargetAlpha;
11112 mLastDimAnimTime = 0;
11113 if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM "
11114 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11115 mDimSurface.setAlpha(mDimCurrentAlpha);
11116 if (!dimming) {
11117 if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface
11118 + ": HIDE");
11119 try {
11120 mDimSurface.hide();
11121 } catch (RuntimeException e) {
11122 Log.w(TAG, "Illegal argument exception hiding dim surface");
11123 }
11124 mDimShown = false;
11125 }
11126 }
11127 }
11128 return animating;
11129 }
11130
11131 public void printTo(PrintWriter pw) {
11132 pw.print(" mDimShown="); pw.print(mDimShown);
11133 pw.print(" current="); pw.print(mDimCurrentAlpha);
11134 pw.print(" target="); pw.print(mDimTargetAlpha);
11135 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11136 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11137 }
11138 }
11139
11140 /**
11141 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11142 * This is used for opening/closing transition for apps in compatible mode.
11143 */
11144 private static class FadeInOutAnimation extends Animation {
11145 int mWidth;
11146 boolean mFadeIn;
11147
11148 public FadeInOutAnimation(boolean fadeIn) {
11149 setInterpolator(new AccelerateInterpolator());
11150 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11151 mFadeIn = fadeIn;
11152 }
11153
11154 @Override
11155 protected void applyTransformation(float interpolatedTime, Transformation t) {
11156 float x = interpolatedTime;
11157 if (!mFadeIn) {
11158 x = 1.0f - x; // reverse the interpolation for fade out
11159 }
11160 if (x < 0.5) {
11161 // move the window out of the screen.
11162 t.getMatrix().setTranslate(mWidth, 0);
11163 } else {
11164 t.getMatrix().setTranslate(0, 0);// show
11165 t.setAlpha((x - 0.5f) * 2);
11166 }
11167 }
11168
11169 @Override
11170 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11171 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11172 mWidth = width;
11173 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011174
11175 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011176 public int getZAdjustment() {
11177 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011178 }
11179 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011180}