blob: 1fdceefa40fef78f6cc51841f7c61c63c2f5a568 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
19import static android.os.LocalPowerManager.CHEEK_EVENT;
20import static android.os.LocalPowerManager.OTHER_EVENT;
21import static android.os.LocalPowerManager.TOUCH_EVENT;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -070022import static android.os.LocalPowerManager.LONG_TOUCH_EVENT;
23import static android.os.LocalPowerManager.TOUCH_UP_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
25import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
26import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070027import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
29import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070030import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
32import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
33import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070034import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
36import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
38import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
39import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
40import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
41import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070042import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
44import com.android.internal.app.IBatteryStats;
45import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080046import com.android.internal.policy.impl.PhoneWindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import com.android.internal.view.IInputContext;
48import com.android.internal.view.IInputMethodClient;
49import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080050import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import com.android.server.am.BatteryStatsService;
52
53import android.Manifest;
54import android.app.ActivityManagerNative;
55import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070056import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070057import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070059import android.content.Intent;
60import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.content.pm.ActivityInfo;
62import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070063import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.content.res.Configuration;
65import android.graphics.Matrix;
66import android.graphics.PixelFormat;
67import android.graphics.Rect;
68import android.graphics.Region;
69import android.os.BatteryStats;
70import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070071import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.Debug;
73import android.os.Handler;
74import android.os.IBinder;
Michael Chan53071d62009-05-13 17:29:48 -070075import android.os.LatencyTimer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076import android.os.LocalPowerManager;
77import android.os.Looper;
78import android.os.Message;
79import android.os.Parcel;
80import android.os.ParcelFileDescriptor;
81import android.os.Power;
82import android.os.PowerManager;
83import android.os.Process;
84import android.os.RemoteException;
85import android.os.ServiceManager;
86import android.os.SystemClock;
87import android.os.SystemProperties;
88import android.os.TokenWatcher;
89import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070090import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070092import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080093import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094import android.util.SparseIntArray;
95import android.view.Display;
96import android.view.Gravity;
Jeff Brown00fa7bd2010-07-02 15:37:36 -070097import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.view.IApplicationToken;
99import android.view.IOnKeyguardExitResult;
100import android.view.IRotationWatcher;
101import android.view.IWindow;
102import android.view.IWindowManager;
103import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700104import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700105import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700106import android.view.InputEvent;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700107import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108import android.view.KeyEvent;
109import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110import android.view.Surface;
111import android.view.SurfaceSession;
112import android.view.View;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -0700113import android.view.ViewConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114import android.view.ViewTreeObserver;
115import android.view.WindowManager;
116import android.view.WindowManagerImpl;
117import android.view.WindowManagerPolicy;
118import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700119import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120import android.view.animation.Animation;
121import android.view.animation.AnimationUtils;
122import android.view.animation.Transformation;
123
124import java.io.BufferedWriter;
125import java.io.File;
126import java.io.FileDescriptor;
127import java.io.IOException;
128import java.io.OutputStream;
129import java.io.OutputStreamWriter;
130import java.io.PrintWriter;
131import java.io.StringWriter;
132import java.net.Socket;
133import java.util.ArrayList;
134import java.util.HashMap;
135import java.util.HashSet;
136import java.util.Iterator;
137import java.util.List;
138
139/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700140public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700141 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 static final String TAG = "WindowManager";
143 static final boolean DEBUG = false;
144 static final boolean DEBUG_FOCUS = false;
145 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800146 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800147 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 static final boolean DEBUG_LAYERS = false;
149 static final boolean DEBUG_INPUT = false;
150 static final boolean DEBUG_INPUT_METHOD = false;
151 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700152 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700154 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 static final boolean DEBUG_APP_TRANSITIONS = false;
156 static final boolean DEBUG_STARTING_WINDOW = false;
157 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700158 static final boolean DEBUG_WALLPAPER = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700160 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700161 static final boolean MEASURE_LATENCY = false;
162 static private LatencyTimer lt;
163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 static final boolean PROFILE_ORIENTATION = false;
165 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700166 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 /** How much to multiply the policy's type layer, to reserve room
169 * for multiple windows of the same type and Z-ordering adjustment
170 * with TYPE_LAYER_OFFSET. */
171 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
174 * or below others in the same layer. */
175 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 /** How much to increment the layer for each window, to reserve room
178 * for effect surfaces between them.
179 */
180 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 /** The maximum length we will accept for a loaded animation duration:
183 * this is 10 seconds.
184 */
185 static final int MAX_ANIMATION_DURATION = 10*1000;
186
187 /** Amount of time (in milliseconds) to animate the dim surface from one
188 * value to another, when no window animation is driving it.
189 */
190 static final int DEFAULT_DIM_DURATION = 200;
191
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700192 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
193 * compatible windows.
194 */
195 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 /** Adjustment to time to perform a dim, to make it more dramatic.
198 */
199 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700200
201 // Maximum number of milliseconds to wait for input event injection.
202 // FIXME is this value reasonable?
203 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700204
205 // Default input dispatching timeout in nanoseconds.
206 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208 static final int UPDATE_FOCUS_NORMAL = 0;
209 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
210 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
211 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700214 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215
216 /**
217 * Condition waited on by {@link #reenableKeyguard} to know the call to
218 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500219 * This is set to true only if mKeyguardTokenWatcher.acquired() has
220 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500222 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223
Jim Miller284b62e2010-06-08 14:27:42 -0700224 private static final int ALLOW_DISABLE_YES = 1;
225 private static final int ALLOW_DISABLE_NO = 0;
226 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
227 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
228
Mike Lockwood983ee092009-11-22 01:42:24 -0500229 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
230 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700232 if (shouldAllowDisableKeyguard()) {
233 mPolicy.enableKeyguard(false);
234 mKeyguardDisabled = true;
235 } else {
236 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
237 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 }
239 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700240 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500241 synchronized (mKeyguardTokenWatcher) {
242 mKeyguardDisabled = false;
243 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 }
245 }
246 };
247
Jim Miller284b62e2010-06-08 14:27:42 -0700248 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
249 @Override
250 public void onReceive(Context context, Intent intent) {
251 mPolicy.enableKeyguard(true);
252 synchronized(mKeyguardTokenWatcher) {
253 // lazily evaluate this next time we're asked to disable keyguard
254 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
255 mKeyguardDisabled = false;
256 }
257 }
258 };
259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 final Context mContext;
261
262 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800266 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
267
268 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 /**
273 * All currently active sessions with clients.
274 */
275 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 /**
278 * Mapping from an IWindow IBinder to the server's Window object.
279 * This is also used as the lock for all of our state.
280 */
281 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
282
283 /**
284 * Mapping from a token IBinder to a WindowToken object.
285 */
286 final HashMap<IBinder, WindowToken> mTokenMap =
287 new HashMap<IBinder, WindowToken>();
288
289 /**
290 * The same tokens as mTokenMap, stored in a list for efficient iteration
291 * over them.
292 */
293 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 /**
296 * Window tokens that are in the process of exiting, but still
297 * on screen for animations.
298 */
299 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
300
301 /**
302 * Z-ordered (bottom-most first) list of all application tokens, for
303 * controlling the ordering of windows in different applications. This
304 * contains WindowToken objects.
305 */
306 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
307
308 /**
309 * Application tokens that are in the process of exiting, but still
310 * on screen for animations.
311 */
312 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
313
314 /**
315 * List of window tokens that have finished starting their application,
316 * and now need to have the policy remove their windows.
317 */
318 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
319
320 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700321 * This was the app token that was used to retrieve the last enter
322 * animation. It will be used for the next exit animation.
323 */
324 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800325
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700326 /**
327 * These were the layout params used to retrieve the last enter animation.
328 * They will be used for the next exit animation.
329 */
330 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800331
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700332 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333 * Z-ordered (bottom-most first) list of all Window objects.
334 */
Jeff Browne33348b2010-07-15 23:54:05 -0700335 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336
337 /**
338 * Windows that are being resized. Used so we can tell the client about
339 * the resize after closing the transaction in which we resized the
340 * underlying surface.
341 */
342 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
343
344 /**
345 * Windows whose animations have ended and now must be removed.
346 */
347 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
348
349 /**
350 * Windows whose surface should be destroyed.
351 */
352 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
353
354 /**
355 * Windows that have lost input focus and are waiting for the new
356 * focus window to be displayed before they are told about this.
357 */
358 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
359
360 /**
361 * This is set when we have run out of memory, and will either be an empty
362 * list or contain windows that need to be force removed.
363 */
364 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700369 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 Surface mBlurSurface;
371 boolean mBlurShown;
Romain Guy06882f82009-06-10 13:36:04 -0700372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 final float[] mTmpFloats = new float[9];
376
377 boolean mSafeMode;
378 boolean mDisplayEnabled = false;
379 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700380 int mInitialDisplayWidth = 0;
381 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 int mRotation = 0;
383 int mRequestedRotation = 0;
384 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700385 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 ArrayList<IRotationWatcher> mRotationWatchers
387 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 boolean mLayoutNeeded = true;
390 boolean mAnimationPending = false;
391 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800392 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 boolean mWindowsFreezingScreen = false;
394 long mFreezeGcPending = 0;
395 int mAppsFreezingScreen = 0;
396
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800397 int mLayoutSeq = 0;
398
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800399 // State while inside of layoutAndPlaceSurfacesLocked().
400 boolean mFocusMayChange;
401
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800402 Configuration mCurConfiguration = new Configuration();
403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 // This is held as long as we have the screen frozen, to give us time to
405 // perform a rotation animation when turning off shows the lock screen which
406 // changes the orientation.
407 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 // State management of app transitions. When we are preparing for a
410 // transition, mNextAppTransition will be the kind of transition to
411 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
412 // mOpeningApps and mClosingApps are the lists of tokens that will be
413 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700414 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700415 String mNextAppTransitionPackage;
416 int mNextAppTransitionEnter;
417 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700419 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 boolean mAppTransitionTimeout = false;
421 boolean mStartingIconInTransition = false;
422 boolean mSkipAppTransitionAnimation = false;
423 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
424 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700425 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
426 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800430 H mH = new H();
431
432 WindowState mCurrentFocus = null;
433 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 // This just indicates the window the input method is on top of, not
436 // necessarily the window its input is going to.
437 WindowState mInputMethodTarget = null;
438 WindowState mUpcomingInputMethodTarget = null;
439 boolean mInputMethodTargetWaitingAnim;
440 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 WindowState mInputMethodWindow = null;
443 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
444
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700445 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800446
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700447 // If non-null, this is the currently visible window that is associated
448 // with the wallpaper.
449 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700450 // If non-null, we are in the middle of animating from one wallpaper target
451 // to another, and this is the lower one in Z-order.
452 WindowState mLowerWallpaperTarget = null;
453 // If non-null, we are in the middle of animating from one wallpaper target
454 // to another, and this is the higher one in Z-order.
455 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700456 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700457 float mLastWallpaperX = -1;
458 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800459 float mLastWallpaperXStep = -1;
460 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700461 // This is set when we are waiting for a wallpaper to tell us it is done
462 // changing its scroll position.
463 WindowState mWaitingOnWallpaper;
464 // The last time we had a timeout when waiting for a wallpaper.
465 long mLastWallpaperTimeoutTime;
466 // We give a wallpaper up to 150ms to finish scrolling.
467 static final long WALLPAPER_TIMEOUT = 150;
468 // Time we wait after a timeout before trying to wait again.
469 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 AppWindowToken mFocusedApp = null;
472
473 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 float mWindowAnimationScale = 1.0f;
476 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700477
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700478 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479
480 // Who is holding the screen on.
481 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700482 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700483
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700484 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 /**
487 * Whether the UI is currently running in touch mode (not showing
488 * navigational focus because the user is directly pressing the screen).
489 */
490 boolean mInTouchMode = false;
491
492 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700493 private ArrayList<WindowChangeListener> mWindowChangeListeners =
494 new ArrayList<WindowChangeListener>();
495 private boolean mWindowsChanged = false;
496
497 public interface WindowChangeListener {
498 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700499 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700500 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501
Dianne Hackbornc485a602009-03-24 22:39:49 -0700502 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700503 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700504
505 // The frame use to limit the size of the app running in compatibility mode.
506 Rect mCompatibleScreenFrame = new Rect();
507 // The surface used to fill the outer rim of the app running in compatibility mode.
508 Surface mBackgroundFillerSurface = null;
509 boolean mBackgroundFillerShown = false;
510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 public static WindowManagerService main(Context context,
512 PowerManagerService pm, boolean haveInputMethods) {
513 WMThread thr = new WMThread(context, pm, haveInputMethods);
514 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 synchronized (thr) {
517 while (thr.mService == null) {
518 try {
519 thr.wait();
520 } catch (InterruptedException e) {
521 }
522 }
523 }
Romain Guy06882f82009-06-10 13:36:04 -0700524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800525 return thr.mService;
526 }
Romain Guy06882f82009-06-10 13:36:04 -0700527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 static class WMThread extends Thread {
529 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 private final Context mContext;
532 private final PowerManagerService mPM;
533 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535 public WMThread(Context context, PowerManagerService pm,
536 boolean haveInputMethods) {
537 super("WindowManager");
538 mContext = context;
539 mPM = pm;
540 mHaveInputMethods = haveInputMethods;
541 }
Romain Guy06882f82009-06-10 13:36:04 -0700542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 public void run() {
544 Looper.prepare();
545 WindowManagerService s = new WindowManagerService(mContext, mPM,
546 mHaveInputMethods);
547 android.os.Process.setThreadPriority(
548 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700549 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 synchronized (this) {
552 mService = s;
553 notifyAll();
554 }
Romain Guy06882f82009-06-10 13:36:04 -0700555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 Looper.loop();
557 }
558 }
559
560 static class PolicyThread extends Thread {
561 private final WindowManagerPolicy mPolicy;
562 private final WindowManagerService mService;
563 private final Context mContext;
564 private final PowerManagerService mPM;
565 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 public PolicyThread(WindowManagerPolicy policy,
568 WindowManagerService service, Context context,
569 PowerManagerService pm) {
570 super("WindowManagerPolicy");
571 mPolicy = policy;
572 mService = service;
573 mContext = context;
574 mPM = pm;
575 }
Romain Guy06882f82009-06-10 13:36:04 -0700576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 public void run() {
578 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800579 WindowManagerPolicyThread.set(this, Looper.myLooper());
580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800582 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 android.os.Process.setThreadPriority(
584 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700585 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 synchronized (this) {
589 mRunning = true;
590 notifyAll();
591 }
Romain Guy06882f82009-06-10 13:36:04 -0700592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 Looper.loop();
594 }
595 }
596
597 private WindowManagerService(Context context, PowerManagerService pm,
598 boolean haveInputMethods) {
Michael Chan53071d62009-05-13 17:29:48 -0700599 if (MEASURE_LATENCY) {
600 lt = new LatencyTimer(100, 1000);
601 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 mContext = context;
604 mHaveInputMethods = haveInputMethods;
605 mLimitedAlphaCompositing = context.getResources().getBoolean(
606 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 mPowerManager = pm;
609 mPowerManager.setPolicy(mPolicy);
610 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
611 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
612 "SCREEN_FROZEN");
613 mScreenFrozenLock.setReferenceCounted(false);
614
615 mActivityManager = ActivityManagerNative.getDefault();
616 mBatteryStats = BatteryStatsService.getService();
617
618 // Get persisted window scale setting
619 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
620 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
621 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
622 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700623
Jim Miller284b62e2010-06-08 14:27:42 -0700624 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
625 IntentFilter filter = new IntentFilter();
626 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
627 mContext.registerReceiver(mBroadcastReceiver, filter);
628
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700629 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
630 "KEEP_SCREEN_ON_FLAG");
631 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632
Jeff Browne33348b2010-07-15 23:54:05 -0700633 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
636 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 synchronized (thr) {
639 while (!thr.mRunning) {
640 try {
641 thr.wait();
642 } catch (InterruptedException e) {
643 }
644 }
645 }
Romain Guy06882f82009-06-10 13:36:04 -0700646
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700647 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -0700648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800649 // Add ourself to the Watchdog monitors.
650 Watchdog.getInstance().addMonitor(this);
651 }
652
653 @Override
654 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
655 throws RemoteException {
656 try {
657 return super.onTransact(code, data, reply, flags);
658 } catch (RuntimeException e) {
659 // The window manager only throws security exceptions, so let's
660 // log all others.
661 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800662 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 }
664 throw e;
665 }
666 }
667
Jeff Browne33348b2010-07-15 23:54:05 -0700668 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800670 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800671 TAG, "Adding window " + window + " at "
672 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
673 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700674 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 }
676
Jeff Browne33348b2010-07-15 23:54:05 -0700677 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800679 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800680 TAG, "Adding window " + window + " at "
681 + i + " of " + mWindows.size() + " (before " + pos + ")");
682 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700683 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 }
685
686 //This method finds out the index of a window that has the same app token as
687 //win. used for z ordering the windows in mWindows
688 private int findIdxBasedOnAppTokens(WindowState win) {
689 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -0700690 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800691 int jmax = localmWindows.size();
692 if(jmax == 0) {
693 return -1;
694 }
695 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700696 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800697 if(wentry.mAppToken == win.mAppToken) {
698 return j;
699 }
700 }
701 return -1;
702 }
Romain Guy06882f82009-06-10 13:36:04 -0700703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800704 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
705 final IWindow client = win.mClient;
706 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -0700707 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800709 final int N = localmWindows.size();
710 final WindowState attached = win.mAttachedWindow;
711 int i;
712 if (attached == null) {
713 int tokenWindowsPos = token.windows.size();
714 if (token.appWindowToken != null) {
715 int index = tokenWindowsPos-1;
716 if (index >= 0) {
717 // If this application has existing windows, we
718 // simply place the new window on top of them... but
719 // keep the starting window on top.
720 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
721 // Base windows go behind everything else.
722 placeWindowBefore(token.windows.get(0), win);
723 tokenWindowsPos = 0;
724 } else {
725 AppWindowToken atoken = win.mAppToken;
726 if (atoken != null &&
727 token.windows.get(index) == atoken.startingWindow) {
728 placeWindowBefore(token.windows.get(index), win);
729 tokenWindowsPos--;
730 } else {
731 int newIdx = findIdxBasedOnAppTokens(win);
732 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700733 //there is a window above this one associated with the same
734 //apptoken note that the window could be a floating window
735 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800737 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700738 TAG, "Adding window " + win + " at "
739 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800740 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700741 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -0700742 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 }
744 }
745 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800746 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747 TAG, "Figuring out where to add app window "
748 + client.asBinder() + " (token=" + token + ")");
749 // Figure out where the window should go, based on the
750 // order of applications.
751 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -0700752 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753 for (i=NA-1; i>=0; i--) {
754 AppWindowToken t = mAppTokens.get(i);
755 if (t == token) {
756 i--;
757 break;
758 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800759
Dianne Hackborna8f60182009-09-01 19:01:50 -0700760 // We haven't reached the token yet; if this token
761 // is not going to the bottom and has windows, we can
762 // use it as an anchor for when we do reach the token.
763 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800764 pos = t.windows.get(0);
765 }
766 }
767 // We now know the index into the apps. If we found
768 // an app window above, that gives us the position; else
769 // we need to look some more.
770 if (pos != null) {
771 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -0700772 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 if (atoken != null) {
774 final int NC = atoken.windows.size();
775 if (NC > 0) {
776 WindowState bottom = atoken.windows.get(0);
777 if (bottom.mSubLayer < 0) {
778 pos = bottom;
779 }
780 }
781 }
782 placeWindowBefore(pos, win);
783 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700784 // Continue looking down until we find the first
785 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800786 while (i >= 0) {
787 AppWindowToken t = mAppTokens.get(i);
788 final int NW = t.windows.size();
789 if (NW > 0) {
790 pos = t.windows.get(NW-1);
791 break;
792 }
793 i--;
794 }
795 if (pos != null) {
796 // Move in front of any windows attached to this
797 // one.
Jeff Browne33348b2010-07-15 23:54:05 -0700798 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 if (atoken != null) {
800 final int NC = atoken.windows.size();
801 if (NC > 0) {
802 WindowState top = atoken.windows.get(NC-1);
803 if (top.mSubLayer >= 0) {
804 pos = top;
805 }
806 }
807 }
808 placeWindowAfter(pos, win);
809 } else {
810 // Just search for the start of this layer.
811 final int myLayer = win.mBaseLayer;
812 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -0700813 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800814 if (w.mBaseLayer > myLayer) {
815 break;
816 }
817 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800818 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700819 TAG, "Adding window " + win + " at "
820 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700822 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800823 }
824 }
825 }
826 } else {
827 // Figure out where window should go, based on layer.
828 final int myLayer = win.mBaseLayer;
829 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700830 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831 i++;
832 break;
833 }
834 }
835 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800836 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700837 TAG, "Adding window " + win + " at "
838 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700840 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841 }
842 if (addToToken) {
843 token.windows.add(tokenWindowsPos, win);
844 }
845
846 } else {
847 // Figure out this window's ordering relative to the window
848 // it is attached to.
849 final int NA = token.windows.size();
850 final int sublayer = win.mSubLayer;
851 int largestSublayer = Integer.MIN_VALUE;
852 WindowState windowWithLargestSublayer = null;
853 for (i=0; i<NA; i++) {
854 WindowState w = token.windows.get(i);
855 final int wSublayer = w.mSubLayer;
856 if (wSublayer >= largestSublayer) {
857 largestSublayer = wSublayer;
858 windowWithLargestSublayer = w;
859 }
860 if (sublayer < 0) {
861 // For negative sublayers, we go below all windows
862 // in the same sublayer.
863 if (wSublayer >= sublayer) {
864 if (addToToken) {
865 token.windows.add(i, win);
866 }
867 placeWindowBefore(
868 wSublayer >= 0 ? attached : w, win);
869 break;
870 }
871 } else {
872 // For positive sublayers, we go above all windows
873 // in the same sublayer.
874 if (wSublayer > sublayer) {
875 if (addToToken) {
876 token.windows.add(i, win);
877 }
878 placeWindowBefore(w, win);
879 break;
880 }
881 }
882 }
883 if (i >= NA) {
884 if (addToToken) {
885 token.windows.add(win);
886 }
887 if (sublayer < 0) {
888 placeWindowBefore(attached, win);
889 } else {
890 placeWindowAfter(largestSublayer >= 0
891 ? windowWithLargestSublayer
892 : attached,
893 win);
894 }
895 }
896 }
Romain Guy06882f82009-06-10 13:36:04 -0700897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800898 if (win.mAppToken != null && addToToken) {
899 win.mAppToken.allAppWindows.add(win);
900 }
901 }
Romain Guy06882f82009-06-10 13:36:04 -0700902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800903 static boolean canBeImeTarget(WindowState w) {
904 final int fl = w.mAttrs.flags
905 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
906 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
907 return w.isVisibleOrAdding();
908 }
909 return false;
910 }
Romain Guy06882f82009-06-10 13:36:04 -0700911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -0700913 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800914 final int N = localmWindows.size();
915 WindowState w = null;
916 int i = N;
917 while (i > 0) {
918 i--;
Jeff Browne33348b2010-07-15 23:54:05 -0700919 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700920
Joe Onorato8a9b2202010-02-26 18:56:32 -0800921 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800922 // + Integer.toHexString(w.mAttrs.flags));
923 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800924 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 // Yet more tricksyness! If this window is a "starting"
927 // window, we do actually want to be on top of it, but
928 // it is not -really- where input will go. So if the caller
929 // is not actually looking to move the IME, look down below
930 // for a real window to target...
931 if (!willMove
932 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
933 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -0700934 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
936 i--;
937 w = wb;
938 }
939 }
940 break;
941 }
942 }
Romain Guy06882f82009-06-10 13:36:04 -0700943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700945
Joe Onorato8a9b2202010-02-26 18:56:32 -0800946 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800947 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800949 if (willMove && w != null) {
950 final WindowState curTarget = mInputMethodTarget;
951 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953 // Now some fun for dealing with window animations that
954 // modify the Z order. We need to look at all windows below
955 // the current target that are in this app, finding the highest
956 // visible one in layering.
957 AppWindowToken token = curTarget.mAppToken;
958 WindowState highestTarget = null;
959 int highestPos = 0;
960 if (token.animating || token.animation != null) {
961 int pos = 0;
962 pos = localmWindows.indexOf(curTarget);
963 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -0700964 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800965 if (win.mAppToken != token) {
966 break;
967 }
968 if (!win.mRemoved) {
969 if (highestTarget == null || win.mAnimLayer >
970 highestTarget.mAnimLayer) {
971 highestTarget = win;
972 highestPos = pos;
973 }
974 }
975 pos--;
976 }
977 }
Romain Guy06882f82009-06-10 13:36:04 -0700978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800979 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800980 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 + mNextAppTransition + " " + highestTarget
982 + " animating=" + highestTarget.isAnimating()
983 + " layer=" + highestTarget.mAnimLayer
984 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700985
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700986 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800987 // If we are currently setting up for an animation,
988 // hold everything until we can find out what will happen.
989 mInputMethodTargetWaitingAnim = true;
990 mInputMethodTarget = highestTarget;
991 return highestPos + 1;
992 } else if (highestTarget.isAnimating() &&
993 highestTarget.mAnimLayer > w.mAnimLayer) {
994 // If the window we are currently targeting is involved
995 // with an animation, and it is on top of the next target
996 // we will be over, then hold off on moving until
997 // that is done.
998 mInputMethodTarget = highestTarget;
999 return highestPos + 1;
1000 }
1001 }
1002 }
1003 }
Romain Guy06882f82009-06-10 13:36:04 -07001004
Joe Onorato8a9b2202010-02-26 18:56:32 -08001005 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001006 if (w != null) {
1007 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001008 if (DEBUG_INPUT_METHOD) {
1009 RuntimeException e = null;
1010 if (!HIDE_STACK_CRAWLS) {
1011 e = new RuntimeException();
1012 e.fillInStackTrace();
1013 }
1014 Slog.w(TAG, "Moving IM target from "
1015 + mInputMethodTarget + " to " + w, e);
1016 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001017 mInputMethodTarget = w;
1018 if (w.mAppToken != null) {
1019 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1020 } else {
1021 setInputMethodAnimLayerAdjustment(0);
1022 }
1023 }
1024 return i+1;
1025 }
1026 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001027 if (DEBUG_INPUT_METHOD) {
1028 RuntimeException e = null;
1029 if (!HIDE_STACK_CRAWLS) {
1030 e = new RuntimeException();
1031 e.fillInStackTrace();
1032 }
1033 Slog.w(TAG, "Moving IM target from "
1034 + mInputMethodTarget + " to null", e);
1035 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 mInputMethodTarget = null;
1037 setInputMethodAnimLayerAdjustment(0);
1038 }
1039 return -1;
1040 }
Romain Guy06882f82009-06-10 13:36:04 -07001041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001042 void addInputMethodWindowToListLocked(WindowState win) {
1043 int pos = findDesiredInputMethodWindowIndexLocked(true);
1044 if (pos >= 0) {
1045 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001046 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001047 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001048 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001049 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001050 moveInputMethodDialogsLocked(pos+1);
1051 return;
1052 }
1053 win.mTargetAppToken = null;
1054 addWindowToListInOrderLocked(win, true);
1055 moveInputMethodDialogsLocked(pos);
1056 }
Romain Guy06882f82009-06-10 13:36:04 -07001057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001059 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001060 mInputMethodAnimLayerAdjustment = adj;
1061 WindowState imw = mInputMethodWindow;
1062 if (imw != null) {
1063 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001064 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065 + " anim layer: " + imw.mAnimLayer);
1066 int wi = imw.mChildWindows.size();
1067 while (wi > 0) {
1068 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001069 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001070 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001071 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 + " anim layer: " + cw.mAnimLayer);
1073 }
1074 }
1075 int di = mInputMethodDialogs.size();
1076 while (di > 0) {
1077 di --;
1078 imw = mInputMethodDialogs.get(di);
1079 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001080 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 + " anim layer: " + imw.mAnimLayer);
1082 }
1083 }
Romain Guy06882f82009-06-10 13:36:04 -07001084
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001085 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1086 int wpos = mWindows.indexOf(win);
1087 if (wpos >= 0) {
1088 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001089 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001090 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001091 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001092 int NC = win.mChildWindows.size();
1093 while (NC > 0) {
1094 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001095 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001096 int cpos = mWindows.indexOf(cw);
1097 if (cpos >= 0) {
1098 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001099 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001100 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 mWindows.remove(cpos);
1102 }
1103 }
1104 }
1105 return interestingPos;
1106 }
Romain Guy06882f82009-06-10 13:36:04 -07001107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001108 private void reAddWindowToListInOrderLocked(WindowState win) {
1109 addWindowToListInOrderLocked(win, false);
1110 // This is a hack to get all of the child windows added as well
1111 // at the right position. Child windows should be rare and
1112 // this case should be rare, so it shouldn't be that big a deal.
1113 int wpos = mWindows.indexOf(win);
1114 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001115 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001116 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001117 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001118 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119 reAddWindowLocked(wpos, win);
1120 }
1121 }
Romain Guy06882f82009-06-10 13:36:04 -07001122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001123 void logWindowList(String prefix) {
1124 int N = mWindows.size();
1125 while (N > 0) {
1126 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001127 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128 }
1129 }
Romain Guy06882f82009-06-10 13:36:04 -07001130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131 void moveInputMethodDialogsLocked(int pos) {
1132 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001135 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 for (int i=0; i<N; i++) {
1137 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1138 }
1139 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001140 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 logWindowList(" ");
1142 }
Romain Guy06882f82009-06-10 13:36:04 -07001143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001144 if (pos >= 0) {
1145 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1146 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001147 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 if (wp == mInputMethodWindow) {
1149 pos++;
1150 }
1151 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001152 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001153 for (int i=0; i<N; i++) {
1154 WindowState win = dialogs.get(i);
1155 win.mTargetAppToken = targetAppToken;
1156 pos = reAddWindowLocked(pos, win);
1157 }
1158 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001159 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 logWindowList(" ");
1161 }
1162 return;
1163 }
1164 for (int i=0; i<N; i++) {
1165 WindowState win = dialogs.get(i);
1166 win.mTargetAppToken = null;
1167 reAddWindowToListInOrderLocked(win);
1168 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001169 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001170 logWindowList(" ");
1171 }
1172 }
1173 }
Romain Guy06882f82009-06-10 13:36:04 -07001174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1176 final WindowState imWin = mInputMethodWindow;
1177 final int DN = mInputMethodDialogs.size();
1178 if (imWin == null && DN == 0) {
1179 return false;
1180 }
Romain Guy06882f82009-06-10 13:36:04 -07001181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1183 if (imPos >= 0) {
1184 // In this case, the input method windows are to be placed
1185 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001187 // First check to see if the input method windows are already
1188 // located here, and contiguous.
1189 final int N = mWindows.size();
1190 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001191 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001193 // Figure out the actual input method window that should be
1194 // at the bottom of their stack.
1195 WindowState baseImWin = imWin != null
1196 ? imWin : mInputMethodDialogs.get(0);
1197 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001198 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001199 if (cw.mSubLayer < 0) baseImWin = cw;
1200 }
Romain Guy06882f82009-06-10 13:36:04 -07001201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001202 if (firstImWin == baseImWin) {
1203 // The windows haven't moved... but are they still contiguous?
1204 // First find the top IM window.
1205 int pos = imPos+1;
1206 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001207 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208 break;
1209 }
1210 pos++;
1211 }
1212 pos++;
1213 // Now there should be no more input method windows above.
1214 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001215 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001216 break;
1217 }
1218 pos++;
1219 }
1220 if (pos >= N) {
1221 // All is good!
1222 return false;
1223 }
1224 }
Romain Guy06882f82009-06-10 13:36:04 -07001225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 if (imWin != null) {
1227 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001228 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 logWindowList(" ");
1230 }
1231 imPos = tmpRemoveWindowLocked(imPos, imWin);
1232 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001233 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001234 logWindowList(" ");
1235 }
1236 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1237 reAddWindowLocked(imPos, imWin);
1238 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001239 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001240 logWindowList(" ");
1241 }
1242 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1243 } else {
1244 moveInputMethodDialogsLocked(imPos);
1245 }
Romain Guy06882f82009-06-10 13:36:04 -07001246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 } else {
1248 // In this case, the input method windows go in a fixed layer,
1249 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001251 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001252 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253 tmpRemoveWindowLocked(0, imWin);
1254 imWin.mTargetAppToken = null;
1255 reAddWindowToListInOrderLocked(imWin);
1256 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001257 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001258 logWindowList(" ");
1259 }
1260 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1261 } else {
1262 moveInputMethodDialogsLocked(-1);;
1263 }
Romain Guy06882f82009-06-10 13:36:04 -07001264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 }
Romain Guy06882f82009-06-10 13:36:04 -07001266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001267 if (needAssignLayers) {
1268 assignLayersLocked();
1269 }
Romain Guy06882f82009-06-10 13:36:04 -07001270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001271 return true;
1272 }
Romain Guy06882f82009-06-10 13:36:04 -07001273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001274 void adjustInputMethodDialogsLocked() {
1275 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1276 }
Romain Guy06882f82009-06-10 13:36:04 -07001277
Dianne Hackborn25994b42009-09-04 14:21:19 -07001278 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001279 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001280 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1281 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1282 ? wallpaperTarget.mAppToken.animation : null)
1283 + " upper=" + mUpperWallpaperTarget
1284 + " lower=" + mLowerWallpaperTarget);
1285 return (wallpaperTarget != null
1286 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1287 && wallpaperTarget.mAppToken.animation != null)))
1288 || mUpperWallpaperTarget != null
1289 || mLowerWallpaperTarget != null;
1290 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001291
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001292 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1293 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001294
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001295 int adjustWallpaperWindowsLocked() {
1296 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001297
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001298 final int dw = mDisplay.getWidth();
1299 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001300
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001301 // First find top-most window that has asked to be on top of the
1302 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001303 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001304 int N = localmWindows.size();
1305 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001306 WindowState foundW = null;
1307 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001308 WindowState topCurW = null;
1309 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001310 int i = N;
1311 while (i > 0) {
1312 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001313 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001314 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1315 if (topCurW == null) {
1316 topCurW = w;
1317 topCurI = i;
1318 }
1319 continue;
1320 }
1321 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001322 if (w.mAppToken != null) {
1323 // If this window's app token is hidden and not animating,
1324 // it is of no interest to us.
1325 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001326 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001327 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001328 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001329 continue;
1330 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001331 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001332 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001333 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1334 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001335 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001336 && (mWallpaperTarget == w
1337 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001338 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001339 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001340 foundW = w;
1341 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001342 if (w == mWallpaperTarget && ((w.mAppToken != null
1343 && w.mAppToken.animation != null)
1344 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001345 // The current wallpaper target is animating, so we'll
1346 // look behind it for another possible target and figure
1347 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001348 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001349 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001350 continue;
1351 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001352 break;
1353 }
1354 }
1355
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001356 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001357 // If we are currently waiting for an app transition, and either
1358 // the current target or the next target are involved with it,
1359 // then hold off on doing anything with the wallpaper.
1360 // Note that we are checking here for just whether the target
1361 // is part of an app token... which is potentially overly aggressive
1362 // (the app token may not be involved in the transition), but good
1363 // enough (we'll just wait until whatever transition is pending
1364 // executes).
1365 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001366 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001367 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001368 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001369 }
1370 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001371 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001372 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001373 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001374 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001375 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001376
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001377 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001378 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001379 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001380 + " oldTarget: " + mWallpaperTarget);
1381 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001382
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001383 mLowerWallpaperTarget = null;
1384 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001385
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001386 WindowState oldW = mWallpaperTarget;
1387 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001388
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001389 // Now what is happening... if the current and new targets are
1390 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001391 if (foundW != null && oldW != null) {
1392 boolean oldAnim = oldW.mAnimation != null
1393 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1394 boolean foundAnim = foundW.mAnimation != null
1395 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001396 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001397 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001398 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001399 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001400 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001401 int oldI = localmWindows.indexOf(oldW);
1402 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001403 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001404 }
1405 if (oldI >= 0) {
1406 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001407 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001408 + "=" + oldW + "; new#" + foundI
1409 + "=" + foundW);
1410 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001411
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001412 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001413 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001414 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001415 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001416 }
1417 mWallpaperTarget = oldW;
1418 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001419
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001420 // Now set the upper and lower wallpaper targets
1421 // correctly, and make sure that we are positioning
1422 // the wallpaper below the lower.
1423 if (foundI > oldI) {
1424 // The new target is on top of the old one.
1425 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001426 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001427 }
1428 mUpperWallpaperTarget = foundW;
1429 mLowerWallpaperTarget = oldW;
1430 foundW = oldW;
1431 foundI = oldI;
1432 } else {
1433 // The new target is below the old one.
1434 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001435 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001436 }
1437 mUpperWallpaperTarget = oldW;
1438 mLowerWallpaperTarget = foundW;
1439 }
1440 }
1441 }
1442 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001443
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001444 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001445 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001446 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1447 || (mLowerWallpaperTarget.mAppToken != null
1448 && mLowerWallpaperTarget.mAppToken.animation != null);
1449 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1450 || (mUpperWallpaperTarget.mAppToken != null
1451 && mUpperWallpaperTarget.mAppToken.animation != null);
1452 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001453 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001454 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001455 }
1456 mLowerWallpaperTarget = null;
1457 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001458 }
1459 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001460
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001461 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001462 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001463 // The window is visible to the compositor... but is it visible
1464 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001465 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001466 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001467
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001468 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001469 // its layer adjustment. Only do this if we are not transfering
1470 // between two wallpaper targets.
1471 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001472 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001473 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001474
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001475 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1476 * TYPE_LAYER_MULTIPLIER
1477 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001478
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001479 // Now w is the window we are supposed to be behind... but we
1480 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001481 // AND any starting window associated with it, AND below the
1482 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001483 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001484 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001485 if (wb.mBaseLayer < maxLayer &&
1486 wb.mAttachedWindow != foundW &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001487 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001488 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001489 // This window is not related to the previous one in any
1490 // interesting way, so stop here.
1491 break;
1492 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001493 foundW = wb;
1494 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001495 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001496 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001497 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001498 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001499
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001500 if (foundW == null && topCurW != null) {
1501 // There is no wallpaper target, so it goes at the bottom.
1502 // We will assume it is the same place as last time, if known.
1503 foundW = topCurW;
1504 foundI = topCurI+1;
1505 } else {
1506 // Okay i is the position immediately above the wallpaper. Look at
1507 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001508 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001509 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001510
Dianne Hackborn284ac932009-08-28 10:34:25 -07001511 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001512 if (mWallpaperTarget.mWallpaperX >= 0) {
1513 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001514 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001515 }
1516 if (mWallpaperTarget.mWallpaperY >= 0) {
1517 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001518 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001519 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001520 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001521
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001522 // Start stepping backwards from here, ensuring that our wallpaper windows
1523 // are correctly placed.
1524 int curTokenIndex = mWallpaperTokens.size();
1525 while (curTokenIndex > 0) {
1526 curTokenIndex--;
1527 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001528 if (token.hidden == visible) {
1529 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1530 token.hidden = !visible;
1531 // Need to do a layout to ensure the wallpaper now has the
1532 // correct size.
1533 mLayoutNeeded = true;
1534 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001535
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001536 int curWallpaperIndex = token.windows.size();
1537 while (curWallpaperIndex > 0) {
1538 curWallpaperIndex--;
1539 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001540
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001541 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001542 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001543 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001544
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001545 // First, make sure the client has the current visibility
1546 // state.
1547 if (wallpaper.mWallpaperVisible != visible) {
1548 wallpaper.mWallpaperVisible = visible;
1549 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001550 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001551 "Setting visibility of wallpaper " + wallpaper
1552 + ": " + visible);
1553 wallpaper.mClient.dispatchAppVisibility(visible);
1554 } catch (RemoteException e) {
1555 }
1556 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001557
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001558 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001559 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001560 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001561
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001562 // First, if this window is at the current index, then all
1563 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001564 if (wallpaper == foundW) {
1565 foundI--;
1566 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001567 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001568 continue;
1569 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001570
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001571 // The window didn't match... the current wallpaper window,
1572 // wherever it is, is in the wrong place, so make sure it is
1573 // not in the list.
1574 int oldIndex = localmWindows.indexOf(wallpaper);
1575 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001576 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001577 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001578 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001579 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001580 if (oldIndex < foundI) {
1581 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001582 }
1583 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001584
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001585 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001586 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001587 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001588 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001589
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001590 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001591 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001592 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001593 }
1594 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001595
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001596 return changed;
1597 }
1598
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001599 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001600 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001601 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001602 mWallpaperAnimLayerAdjustment = adj;
1603 int curTokenIndex = mWallpaperTokens.size();
1604 while (curTokenIndex > 0) {
1605 curTokenIndex--;
1606 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1607 int curWallpaperIndex = token.windows.size();
1608 while (curWallpaperIndex > 0) {
1609 curWallpaperIndex--;
1610 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1611 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001612 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001613 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001614 }
1615 }
1616 }
1617
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001618 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1619 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001620 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001621 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001622 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001623 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001624 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1625 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1626 changed = wallpaperWin.mXOffset != offset;
1627 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001628 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001629 + wallpaperWin + " x: " + offset);
1630 wallpaperWin.mXOffset = offset;
1631 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001632 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001633 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001634 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001635 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001636 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001637
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001638 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001639 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001640 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1641 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1642 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001643 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001644 + wallpaperWin + " y: " + offset);
1645 changed = true;
1646 wallpaperWin.mYOffset = offset;
1647 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001648 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001649 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001650 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001651 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001652 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001653
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001654 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001655 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001656 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001657 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1658 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001659 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001660 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001661 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001662 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001663 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1664 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001665 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001666 if (mWaitingOnWallpaper != null) {
1667 long start = SystemClock.uptimeMillis();
1668 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1669 < start) {
1670 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001671 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001672 "Waiting for offset complete...");
1673 mWindowMap.wait(WALLPAPER_TIMEOUT);
1674 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001675 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001676 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001677 if ((start+WALLPAPER_TIMEOUT)
1678 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001679 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001680 + wallpaperWin);
1681 mLastWallpaperTimeoutTime = start;
1682 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001683 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001684 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001685 }
1686 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001687 } catch (RemoteException e) {
1688 }
1689 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001690
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001691 return changed;
1692 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001693
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001694 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001695 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001696 if (mWaitingOnWallpaper != null &&
1697 mWaitingOnWallpaper.mClient.asBinder() == window) {
1698 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001699 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001700 }
1701 }
1702 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001703
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001704 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001705 final int dw = mDisplay.getWidth();
1706 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001707
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001708 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001709
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001710 WindowState target = mWallpaperTarget;
1711 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001712 if (target.mWallpaperX >= 0) {
1713 mLastWallpaperX = target.mWallpaperX;
1714 } else if (changingTarget.mWallpaperX >= 0) {
1715 mLastWallpaperX = changingTarget.mWallpaperX;
1716 }
1717 if (target.mWallpaperY >= 0) {
1718 mLastWallpaperY = target.mWallpaperY;
1719 } else if (changingTarget.mWallpaperY >= 0) {
1720 mLastWallpaperY = changingTarget.mWallpaperY;
1721 }
1722 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001723
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001724 int curTokenIndex = mWallpaperTokens.size();
1725 while (curTokenIndex > 0) {
1726 curTokenIndex--;
1727 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1728 int curWallpaperIndex = token.windows.size();
1729 while (curWallpaperIndex > 0) {
1730 curWallpaperIndex--;
1731 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1732 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1733 wallpaper.computeShownFrameLocked();
1734 changed = true;
1735 // We only want to be synchronous with one wallpaper.
1736 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001737 }
1738 }
1739 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001740
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001741 return changed;
1742 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001743
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001744 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001745 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001746 final int dw = mDisplay.getWidth();
1747 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001748
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001749 int curTokenIndex = mWallpaperTokens.size();
1750 while (curTokenIndex > 0) {
1751 curTokenIndex--;
1752 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001753 if (token.hidden == visible) {
1754 token.hidden = !visible;
1755 // Need to do a layout to ensure the wallpaper now has the
1756 // correct size.
1757 mLayoutNeeded = true;
1758 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001759
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001760 int curWallpaperIndex = token.windows.size();
1761 while (curWallpaperIndex > 0) {
1762 curWallpaperIndex--;
1763 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1764 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001765 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001766 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001767
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001768 if (wallpaper.mWallpaperVisible != visible) {
1769 wallpaper.mWallpaperVisible = visible;
1770 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001771 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001772 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001773 + ": " + visible);
1774 wallpaper.mClient.dispatchAppVisibility(visible);
1775 } catch (RemoteException e) {
1776 }
1777 }
1778 }
1779 }
1780 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001782 public int addWindow(Session session, IWindow client,
1783 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001784 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001785 int res = mPolicy.checkAddPermission(attrs);
1786 if (res != WindowManagerImpl.ADD_OKAY) {
1787 return res;
1788 }
Romain Guy06882f82009-06-10 13:36:04 -07001789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001790 boolean reportNewConfig = false;
1791 WindowState attachedWindow = null;
1792 WindowState win = null;
Romain Guy06882f82009-06-10 13:36:04 -07001793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001794 synchronized(mWindowMap) {
1795 // Instantiating a Display requires talking with the simulator,
1796 // so don't do it until we know the system is mostly up and
1797 // running.
1798 if (mDisplay == null) {
1799 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1800 mDisplay = wm.getDefaultDisplay();
Christopher Tateb696aee2010-04-02 19:08:30 -07001801 mInitialDisplayWidth = mDisplay.getWidth();
1802 mInitialDisplayHeight = mDisplay.getHeight();
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001803 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001804 reportNewConfig = true;
1805 }
Romain Guy06882f82009-06-10 13:36:04 -07001806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001807 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001808 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001809 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1810 }
1811
1812 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001813 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001814 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001815 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001816 + attrs.token + ". Aborting.");
1817 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1818 }
1819 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1820 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001821 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001822 + attrs.token + ". Aborting.");
1823 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1824 }
1825 }
1826
1827 boolean addToken = false;
1828 WindowToken token = mTokenMap.get(attrs.token);
1829 if (token == null) {
1830 if (attrs.type >= FIRST_APPLICATION_WINDOW
1831 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001832 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001833 + attrs.token + ". Aborting.");
1834 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1835 }
1836 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001837 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001838 + attrs.token + ". Aborting.");
1839 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1840 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001841 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001842 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001843 + attrs.token + ". Aborting.");
1844 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1845 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001846 token = new WindowToken(attrs.token, -1, false);
1847 addToken = true;
1848 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1849 && attrs.type <= LAST_APPLICATION_WINDOW) {
1850 AppWindowToken atoken = token.appWindowToken;
1851 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001852 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001853 + token + ". Aborting.");
1854 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1855 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001856 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001857 + token + ". Aborting.");
1858 return WindowManagerImpl.ADD_APP_EXITING;
1859 }
1860 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1861 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001862 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001863 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1864 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1865 }
1866 } else if (attrs.type == TYPE_INPUT_METHOD) {
1867 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001868 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001869 + attrs.token + ". Aborting.");
1870 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1871 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001872 } else if (attrs.type == TYPE_WALLPAPER) {
1873 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001874 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001875 + attrs.token + ". Aborting.");
1876 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1877 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001878 }
1879
1880 win = new WindowState(session, client, token,
1881 attachedWindow, attrs, viewVisibility);
1882 if (win.mDeathRecipient == null) {
1883 // Client has apparently died, so there is no reason to
1884 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001885 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001886 + " that is dead, aborting.");
1887 return WindowManagerImpl.ADD_APP_EXITING;
1888 }
1889
1890 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001892 res = mPolicy.prepareAddWindowLw(win, attrs);
1893 if (res != WindowManagerImpl.ADD_OKAY) {
1894 return res;
1895 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001896
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001897 if (outInputChannel != null) {
1898 String name = win.makeInputChannelName();
1899 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1900 win.mInputChannel = inputChannels[0];
1901 inputChannels[1].transferToBinderOutParameter(outInputChannel);
1902
1903 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001904 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001905
1906 // From now on, no exceptions or errors allowed!
1907
1908 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001910 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001912 if (addToken) {
1913 mTokenMap.put(attrs.token, token);
1914 mTokenList.add(token);
1915 }
1916 win.attach();
1917 mWindowMap.put(client.asBinder(), win);
1918
1919 if (attrs.type == TYPE_APPLICATION_STARTING &&
1920 token.appWindowToken != null) {
1921 token.appWindowToken.startingWindow = win;
1922 }
1923
1924 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001926 if (attrs.type == TYPE_INPUT_METHOD) {
1927 mInputMethodWindow = win;
1928 addInputMethodWindowToListLocked(win);
1929 imMayMove = false;
1930 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1931 mInputMethodDialogs.add(win);
1932 addWindowToListInOrderLocked(win, true);
1933 adjustInputMethodDialogsLocked();
1934 imMayMove = false;
1935 } else {
1936 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001937 if (attrs.type == TYPE_WALLPAPER) {
1938 mLastWallpaperTimeoutTime = 0;
1939 adjustWallpaperWindowsLocked();
1940 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001941 adjustWallpaperWindowsLocked();
1942 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001943 }
Romain Guy06882f82009-06-10 13:36:04 -07001944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001945 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001947 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001949 if (mInTouchMode) {
1950 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1951 }
1952 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1953 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1954 }
Romain Guy06882f82009-06-10 13:36:04 -07001955
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001956 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001957 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07001958 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
1959 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001960 imMayMove = false;
1961 }
1962 }
Romain Guy06882f82009-06-10 13:36:04 -07001963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001964 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001965 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001966 }
Romain Guy06882f82009-06-10 13:36:04 -07001967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001968 assignLayersLocked();
1969 // Don't do layout here, the window must call
1970 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07001971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001972 //dump();
1973
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001974 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07001975 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001976 }
Jeff Brown349703e2010-06-22 01:27:15 -07001977
Joe Onorato8a9b2202010-02-26 18:56:32 -08001978 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001979 TAG, "New client " + client.asBinder()
1980 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001981
1982 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
1983 reportNewConfig = true;
1984 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001985 }
1986
1987 // sendNewConfiguration() checks caller permissions so we must call it with
1988 // privilege. updateOrientationFromAppTokens() clears and resets the caller
1989 // identity anyway, so it's safe to just clear & restore around this whole
1990 // block.
1991 final long origId = Binder.clearCallingIdentity();
1992 if (reportNewConfig) {
1993 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001994 }
1995 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07001996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001997 return res;
1998 }
Romain Guy06882f82009-06-10 13:36:04 -07001999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002000 public void removeWindow(Session session, IWindow client) {
2001 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002002 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002003 if (win == null) {
2004 return;
2005 }
2006 removeWindowLocked(session, win);
2007 }
2008 }
Romain Guy06882f82009-06-10 13:36:04 -07002009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002010 public void removeWindowLocked(Session session, WindowState win) {
2011
Joe Onorato8a9b2202010-02-26 18:56:32 -08002012 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002013 TAG, "Remove " + win + " client="
2014 + Integer.toHexString(System.identityHashCode(
2015 win.mClient.asBinder()))
2016 + ", surface=" + win.mSurface);
2017
2018 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002019
2020 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002021
Joe Onorato8a9b2202010-02-26 18:56:32 -08002022 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002023 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2024 + " mExiting=" + win.mExiting
2025 + " isAnimating=" + win.isAnimating()
2026 + " app-animation="
2027 + (win.mAppToken != null ? win.mAppToken.animation : null)
2028 + " inPendingTransaction="
2029 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2030 + " mDisplayFrozen=" + mDisplayFrozen);
2031 // Visibility of the removed window. Will be used later to update orientation later on.
2032 boolean wasVisible = false;
2033 // First, see if we need to run an animation. If we do, we have
2034 // to hold off on removing the window until the animation is done.
2035 // If the display is frozen, just remove immediately, since the
2036 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002037 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002038 // If we are not currently running the exit animation, we
2039 // need to see about starting one.
2040 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002042 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2043 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2044 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2045 }
2046 // Try starting an animation.
2047 if (applyAnimationLocked(win, transit, false)) {
2048 win.mExiting = true;
2049 }
2050 }
2051 if (win.mExiting || win.isAnimating()) {
2052 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002053 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002054 win.mExiting = true;
2055 win.mRemoveOnExit = true;
2056 mLayoutNeeded = true;
2057 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2058 performLayoutAndPlaceSurfacesLocked();
2059 if (win.mAppToken != null) {
2060 win.mAppToken.updateReportedVisibilityLocked();
2061 }
2062 //dump();
2063 Binder.restoreCallingIdentity(origId);
2064 return;
2065 }
2066 }
2067
2068 removeWindowInnerLocked(session, win);
2069 // Removing a visible window will effect the computed orientation
2070 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002071 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002072 != mForcedAppOrientation
2073 && updateOrientationFromAppTokensLocked()) {
2074 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002075 }
2076 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2077 Binder.restoreCallingIdentity(origId);
2078 }
Romain Guy06882f82009-06-10 13:36:04 -07002079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002080 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002081 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002083 if (mInputMethodTarget == win) {
2084 moveInputMethodWindowsIfNeededLocked(false);
2085 }
Romain Guy06882f82009-06-10 13:36:04 -07002086
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002087 if (false) {
2088 RuntimeException e = new RuntimeException("here");
2089 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002090 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002091 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002093 mPolicy.removeWindowLw(win);
2094 win.removeLocked();
2095
2096 mWindowMap.remove(win.mClient.asBinder());
2097 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002098 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002099 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002100
2101 if (mInputMethodWindow == win) {
2102 mInputMethodWindow = null;
2103 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2104 mInputMethodDialogs.remove(win);
2105 }
Romain Guy06882f82009-06-10 13:36:04 -07002106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002107 final WindowToken token = win.mToken;
2108 final AppWindowToken atoken = win.mAppToken;
2109 token.windows.remove(win);
2110 if (atoken != null) {
2111 atoken.allAppWindows.remove(win);
2112 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002113 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002114 TAG, "**** Removing window " + win + ": count="
2115 + token.windows.size());
2116 if (token.windows.size() == 0) {
2117 if (!token.explicit) {
2118 mTokenMap.remove(token.token);
2119 mTokenList.remove(token);
2120 } else if (atoken != null) {
2121 atoken.firstWindowDrawn = false;
2122 }
2123 }
2124
2125 if (atoken != null) {
2126 if (atoken.startingWindow == win) {
2127 atoken.startingWindow = null;
2128 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2129 // If this is the last window and we had requested a starting
2130 // transition window, well there is no point now.
2131 atoken.startingData = null;
2132 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2133 // If this is the last window except for a starting transition
2134 // window, we need to get rid of the starting transition.
2135 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002136 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002137 + ": no more real windows");
2138 }
2139 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2140 mH.sendMessage(m);
2141 }
2142 }
Romain Guy06882f82009-06-10 13:36:04 -07002143
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002144 if (win.mAttrs.type == TYPE_WALLPAPER) {
2145 mLastWallpaperTimeoutTime = 0;
2146 adjustWallpaperWindowsLocked();
2147 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002148 adjustWallpaperWindowsLocked();
2149 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002151 if (!mInLayout) {
2152 assignLayersLocked();
2153 mLayoutNeeded = true;
2154 performLayoutAndPlaceSurfacesLocked();
2155 if (win.mAppToken != null) {
2156 win.mAppToken.updateReportedVisibilityLocked();
2157 }
2158 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002159
2160 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002161 }
2162
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002163 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2164 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2165 + ": " + msg + " / " + w.mAttrs.getTitle();
2166 if (where != null) {
2167 Slog.i(TAG, str, where);
2168 } else {
2169 Slog.i(TAG, str);
2170 }
2171 }
2172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002173 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2174 long origId = Binder.clearCallingIdentity();
2175 try {
2176 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002177 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002178 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002179 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002180 Surface.openTransaction();
2181 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002182 if (SHOW_TRANSACTIONS) logSurface(w,
2183 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002184 w.mSurface.setTransparentRegionHint(region);
2185 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002186 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002187 Surface.closeTransaction();
2188 }
2189 }
2190 }
2191 } finally {
2192 Binder.restoreCallingIdentity(origId);
2193 }
2194 }
2195
2196 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002197 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002198 Rect visibleInsets) {
2199 long origId = Binder.clearCallingIdentity();
2200 try {
2201 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002202 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002203 if (w != null) {
2204 w.mGivenInsetsPending = false;
2205 w.mGivenContentInsets.set(contentInsets);
2206 w.mGivenVisibleInsets.set(visibleInsets);
2207 w.mTouchableInsets = touchableInsets;
2208 mLayoutNeeded = true;
2209 performLayoutAndPlaceSurfacesLocked();
2210 }
2211 }
2212 } finally {
2213 Binder.restoreCallingIdentity(origId);
2214 }
2215 }
Romain Guy06882f82009-06-10 13:36:04 -07002216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002217 public void getWindowDisplayFrame(Session session, IWindow client,
2218 Rect outDisplayFrame) {
2219 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002220 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002221 if (win == null) {
2222 outDisplayFrame.setEmpty();
2223 return;
2224 }
2225 outDisplayFrame.set(win.mDisplayFrame);
2226 }
2227 }
2228
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002229 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2230 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002231 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2232 window.mWallpaperX = x;
2233 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002234 window.mWallpaperXStep = xStep;
2235 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002236 if (updateWallpaperOffsetLocked(window, true)) {
2237 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002238 }
2239 }
2240 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002241
Dianne Hackborn75804932009-10-20 20:15:20 -07002242 void wallpaperCommandComplete(IBinder window, Bundle result) {
2243 synchronized (mWindowMap) {
2244 if (mWaitingOnWallpaper != null &&
2245 mWaitingOnWallpaper.mClient.asBinder() == window) {
2246 mWaitingOnWallpaper = null;
2247 mWindowMap.notifyAll();
2248 }
2249 }
2250 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002251
Dianne Hackborn75804932009-10-20 20:15:20 -07002252 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2253 String action, int x, int y, int z, Bundle extras, boolean sync) {
2254 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2255 || window == mUpperWallpaperTarget) {
2256 boolean doWait = sync;
2257 int curTokenIndex = mWallpaperTokens.size();
2258 while (curTokenIndex > 0) {
2259 curTokenIndex--;
2260 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2261 int curWallpaperIndex = token.windows.size();
2262 while (curWallpaperIndex > 0) {
2263 curWallpaperIndex--;
2264 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2265 try {
2266 wallpaper.mClient.dispatchWallpaperCommand(action,
2267 x, y, z, extras, sync);
2268 // We only want to be synchronous with one wallpaper.
2269 sync = false;
2270 } catch (RemoteException e) {
2271 }
2272 }
2273 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002274
Dianne Hackborn75804932009-10-20 20:15:20 -07002275 if (doWait) {
2276 // XXX Need to wait for result.
2277 }
2278 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002279
Dianne Hackborn75804932009-10-20 20:15:20 -07002280 return null;
2281 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 public int relayoutWindow(Session session, IWindow client,
2284 WindowManager.LayoutParams attrs, int requestedWidth,
2285 int requestedHeight, int viewVisibility, boolean insetsPending,
2286 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002287 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002288 boolean displayed = false;
2289 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002290 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002291 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002293 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002294 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002295 if (win == null) {
2296 return 0;
2297 }
2298 win.mRequestedWidth = requestedWidth;
2299 win.mRequestedHeight = requestedHeight;
2300
2301 if (attrs != null) {
2302 mPolicy.adjustWindowParamsLw(attrs);
2303 }
Romain Guy06882f82009-06-10 13:36:04 -07002304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002305 int attrChanges = 0;
2306 int flagChanges = 0;
2307 if (attrs != null) {
2308 flagChanges = win.mAttrs.flags ^= attrs.flags;
2309 attrChanges = win.mAttrs.copyFrom(attrs);
2310 }
2311
Joe Onorato8a9b2202010-02-26 18:56:32 -08002312 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002313
2314 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2315 win.mAlpha = attrs.alpha;
2316 }
2317
2318 final boolean scaledWindow =
2319 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2320
2321 if (scaledWindow) {
2322 // requested{Width|Height} Surface's physical size
2323 // attrs.{width|height} Size on screen
2324 win.mHScale = (attrs.width != requestedWidth) ?
2325 (attrs.width / (float)requestedWidth) : 1.0f;
2326 win.mVScale = (attrs.height != requestedHeight) ?
2327 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002328 } else {
2329 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002330 }
2331
2332 boolean imMayMove = (flagChanges&(
2333 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2334 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002336 boolean focusMayChange = win.mViewVisibility != viewVisibility
2337 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2338 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002339
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002340 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2341 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002343 win.mRelayoutCalled = true;
2344 final int oldVisibility = win.mViewVisibility;
2345 win.mViewVisibility = viewVisibility;
2346 if (viewVisibility == View.VISIBLE &&
2347 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2348 displayed = !win.isVisibleLw();
2349 if (win.mExiting) {
2350 win.mExiting = false;
2351 win.mAnimation = null;
2352 }
2353 if (win.mDestroying) {
2354 win.mDestroying = false;
2355 mDestroySurface.remove(win);
2356 }
2357 if (oldVisibility == View.GONE) {
2358 win.mEnterAnimationPending = true;
2359 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002360 if (displayed) {
2361 if (win.mSurface != null && !win.mDrawPending
2362 && !win.mCommitDrawPending && !mDisplayFrozen
2363 && mPolicy.isScreenOn()) {
2364 applyEnterAnimationLocked(win);
2365 }
2366 if ((win.mAttrs.flags
2367 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2368 if (DEBUG_VISIBILITY) Slog.v(TAG,
2369 "Relayout window turning screen on: " + win);
2370 win.mTurnOnScreen = true;
2371 }
2372 int diff = 0;
2373 if (win.mConfiguration != mCurConfiguration
2374 && (win.mConfiguration == null
2375 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2376 win.mConfiguration = mCurConfiguration;
2377 if (DEBUG_CONFIGURATION) {
2378 Slog.i(TAG, "Window " + win + " visible with new config: "
2379 + win.mConfiguration + " / 0x"
2380 + Integer.toHexString(diff));
2381 }
2382 outConfig.setTo(mCurConfiguration);
2383 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002384 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002385 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2386 // To change the format, we need to re-build the surface.
2387 win.destroySurfaceLocked();
2388 displayed = true;
2389 }
2390 try {
2391 Surface surface = win.createSurfaceLocked();
2392 if (surface != null) {
2393 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002394 win.mReportDestroySurface = false;
2395 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002396 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002397 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002398 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002399 // For some reason there isn't a surface. Clear the
2400 // caller's object so they see the same state.
2401 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002402 }
2403 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002404 mInputMonitor.updateInputWindowsLw();
2405
Joe Onorato8a9b2202010-02-26 18:56:32 -08002406 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002407 + client + " (" + win.mAttrs.getTitle() + ")",
2408 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002409 Binder.restoreCallingIdentity(origId);
2410 return 0;
2411 }
2412 if (displayed) {
2413 focusMayChange = true;
2414 }
2415 if (win.mAttrs.type == TYPE_INPUT_METHOD
2416 && mInputMethodWindow == null) {
2417 mInputMethodWindow = win;
2418 imMayMove = true;
2419 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002420 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2421 && win.mAppToken != null
2422 && win.mAppToken.startingWindow != null) {
2423 // Special handling of starting window over the base
2424 // window of the app: propagate lock screen flags to it,
2425 // to provide the correct semantics while starting.
2426 final int mask =
2427 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002428 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2429 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002430 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2431 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2432 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002433 } else {
2434 win.mEnterAnimationPending = false;
2435 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002436 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002437 + ": mExiting=" + win.mExiting
2438 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002439 // If we are not currently running the exit animation, we
2440 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002441 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002442 // Try starting an animation; if there isn't one, we
2443 // can destroy the surface right away.
2444 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2445 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2446 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2447 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002448 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002449 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002450 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002451 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002452 } else if (win.isAnimating()) {
2453 // Currently in a hide animation... turn this into
2454 // an exit.
2455 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002456 } else if (win == mWallpaperTarget) {
2457 // If the wallpaper is currently behind this
2458 // window, we need to change both of them inside
2459 // of a transaction to avoid artifacts.
2460 win.mExiting = true;
2461 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002462 } else {
2463 if (mInputMethodWindow == win) {
2464 mInputMethodWindow = null;
2465 }
2466 win.destroySurfaceLocked();
2467 }
2468 }
2469 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002470
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002471 if (win.mSurface == null || (win.getAttrs().flags
2472 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2473 || win.mSurfacePendingDestroy) {
2474 // We are being called from a local process, which
2475 // means outSurface holds its current surface. Ensure the
2476 // surface object is cleared, but we don't want it actually
2477 // destroyed at this point.
2478 win.mSurfacePendingDestroy = false;
2479 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002480 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002481 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002482 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002483 "Keeping surface, will report destroy: " + win);
2484 win.mReportDestroySurface = true;
2485 outSurface.copyFrom(win.mSurface);
2486 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 }
2488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002489 if (focusMayChange) {
2490 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2491 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002492 imMayMove = false;
2493 }
2494 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2495 }
Romain Guy06882f82009-06-10 13:36:04 -07002496
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002497 // updateFocusedWindowLocked() already assigned layers so we only need to
2498 // reassign them at this point if the IM window state gets shuffled
2499 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002501 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002502 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2503 // Little hack here -- we -should- be able to rely on the
2504 // function to return true if the IME has moved and needs
2505 // its layer recomputed. However, if the IME was hidden
2506 // and isn't actually moved in the list, its layer may be
2507 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002508 assignLayers = true;
2509 }
2510 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002511 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002512 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002513 assignLayers = true;
2514 }
2515 }
Romain Guy06882f82009-06-10 13:36:04 -07002516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002517 mLayoutNeeded = true;
2518 win.mGivenInsetsPending = insetsPending;
2519 if (assignLayers) {
2520 assignLayersLocked();
2521 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002522 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002523 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002524 if (displayed && win.mIsWallpaper) {
2525 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002526 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002527 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002528 if (win.mAppToken != null) {
2529 win.mAppToken.updateReportedVisibilityLocked();
2530 }
2531 outFrame.set(win.mFrame);
2532 outContentInsets.set(win.mContentInsets);
2533 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002534 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002535 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002536 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002537 + ", requestedHeight=" + requestedHeight
2538 + ", viewVisibility=" + viewVisibility
2539 + "\nRelayout returning frame=" + outFrame
2540 + ", surface=" + outSurface);
2541
Joe Onorato8a9b2202010-02-26 18:56:32 -08002542 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002543 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2544
2545 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002546
2547 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002548 }
2549
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002550 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002551 sendNewConfiguration();
2552 }
Romain Guy06882f82009-06-10 13:36:04 -07002553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002554 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002556 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2557 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2558 }
2559
2560 public void finishDrawingWindow(Session session, IWindow client) {
2561 final long origId = Binder.clearCallingIdentity();
2562 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002563 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002564 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002565 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2566 adjustWallpaperWindowsLocked();
2567 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568 mLayoutNeeded = true;
2569 performLayoutAndPlaceSurfacesLocked();
2570 }
2571 }
2572 Binder.restoreCallingIdentity(origId);
2573 }
2574
2575 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002576 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002577 + (lp != null ? lp.packageName : null)
2578 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2579 if (lp != null && lp.windowAnimations != 0) {
2580 // If this is a system resource, don't try to load it from the
2581 // application resources. It is nice to avoid loading application
2582 // resources if we can.
2583 String packageName = lp.packageName != null ? lp.packageName : "android";
2584 int resId = lp.windowAnimations;
2585 if ((resId&0xFF000000) == 0x01000000) {
2586 packageName = "android";
2587 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002588 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002589 + packageName);
2590 return AttributeCache.instance().get(packageName, resId,
2591 com.android.internal.R.styleable.WindowAnimation);
2592 }
2593 return null;
2594 }
Romain Guy06882f82009-06-10 13:36:04 -07002595
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002596 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002597 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002598 + packageName + " resId=0x" + Integer.toHexString(resId));
2599 if (packageName != null) {
2600 if ((resId&0xFF000000) == 0x01000000) {
2601 packageName = "android";
2602 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002603 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002604 + packageName);
2605 return AttributeCache.instance().get(packageName, resId,
2606 com.android.internal.R.styleable.WindowAnimation);
2607 }
2608 return null;
2609 }
2610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002611 private void applyEnterAnimationLocked(WindowState win) {
2612 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2613 if (win.mEnterAnimationPending) {
2614 win.mEnterAnimationPending = false;
2615 transit = WindowManagerPolicy.TRANSIT_ENTER;
2616 }
2617
2618 applyAnimationLocked(win, transit, true);
2619 }
2620
2621 private boolean applyAnimationLocked(WindowState win,
2622 int transit, boolean isEntrance) {
2623 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2624 // If we are trying to apply an animation, but already running
2625 // an animation of the same type, then just leave that one alone.
2626 return true;
2627 }
Romain Guy06882f82009-06-10 13:36:04 -07002628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002629 // Only apply an animation if the display isn't frozen. If it is
2630 // frozen, there is no reason to animate and it can cause strange
2631 // artifacts when we unfreeze the display if some different animation
2632 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002633 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002634 int anim = mPolicy.selectAnimationLw(win, transit);
2635 int attr = -1;
2636 Animation a = null;
2637 if (anim != 0) {
2638 a = AnimationUtils.loadAnimation(mContext, anim);
2639 } else {
2640 switch (transit) {
2641 case WindowManagerPolicy.TRANSIT_ENTER:
2642 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2643 break;
2644 case WindowManagerPolicy.TRANSIT_EXIT:
2645 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2646 break;
2647 case WindowManagerPolicy.TRANSIT_SHOW:
2648 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2649 break;
2650 case WindowManagerPolicy.TRANSIT_HIDE:
2651 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2652 break;
2653 }
2654 if (attr >= 0) {
2655 a = loadAnimation(win.mAttrs, attr);
2656 }
2657 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002658 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002659 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2660 + " mAnimation=" + win.mAnimation
2661 + " isEntrance=" + isEntrance);
2662 if (a != null) {
2663 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002664 RuntimeException e = null;
2665 if (!HIDE_STACK_CRAWLS) {
2666 e = new RuntimeException();
2667 e.fillInStackTrace();
2668 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002669 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002670 }
2671 win.setAnimation(a);
2672 win.mAnimationIsEntrance = isEntrance;
2673 }
2674 } else {
2675 win.clearAnimation();
2676 }
2677
2678 return win.mAnimation != null;
2679 }
2680
2681 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2682 int anim = 0;
2683 Context context = mContext;
2684 if (animAttr >= 0) {
2685 AttributeCache.Entry ent = getCachedAnimations(lp);
2686 if (ent != null) {
2687 context = ent.context;
2688 anim = ent.array.getResourceId(animAttr, 0);
2689 }
2690 }
2691 if (anim != 0) {
2692 return AnimationUtils.loadAnimation(context, anim);
2693 }
2694 return null;
2695 }
Romain Guy06882f82009-06-10 13:36:04 -07002696
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002697 private Animation loadAnimation(String packageName, int resId) {
2698 int anim = 0;
2699 Context context = mContext;
2700 if (resId >= 0) {
2701 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2702 if (ent != null) {
2703 context = ent.context;
2704 anim = resId;
2705 }
2706 }
2707 if (anim != 0) {
2708 return AnimationUtils.loadAnimation(context, anim);
2709 }
2710 return null;
2711 }
2712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002713 private boolean applyAnimationLocked(AppWindowToken wtoken,
2714 WindowManager.LayoutParams lp, int transit, boolean enter) {
2715 // Only apply an animation if the display isn't frozen. If it is
2716 // frozen, there is no reason to animate and it can cause strange
2717 // artifacts when we unfreeze the display if some different animation
2718 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002719 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002720 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002721 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002722 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002723 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002724 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002725 } else if (mNextAppTransitionPackage != null) {
2726 a = loadAnimation(mNextAppTransitionPackage, enter ?
2727 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002728 } else {
2729 int animAttr = 0;
2730 switch (transit) {
2731 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2732 animAttr = enter
2733 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2734 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2735 break;
2736 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2737 animAttr = enter
2738 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2739 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2740 break;
2741 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2742 animAttr = enter
2743 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2744 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2745 break;
2746 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2747 animAttr = enter
2748 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2749 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2750 break;
2751 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2752 animAttr = enter
2753 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2754 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2755 break;
2756 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2757 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002758 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002759 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2760 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002761 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002762 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002763 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2764 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002765 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002766 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002767 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002768 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2769 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2770 break;
2771 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2772 animAttr = enter
2773 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2774 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2775 break;
2776 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2777 animAttr = enter
2778 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2779 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002780 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002781 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002782 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002783 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002784 + " anim=" + a
2785 + " animAttr=0x" + Integer.toHexString(animAttr)
2786 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002787 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002788 if (a != null) {
2789 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002790 RuntimeException e = null;
2791 if (!HIDE_STACK_CRAWLS) {
2792 e = new RuntimeException();
2793 e.fillInStackTrace();
2794 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002795 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002796 }
2797 wtoken.setAnimation(a);
2798 }
2799 } else {
2800 wtoken.clearAnimation();
2801 }
2802
2803 return wtoken.animation != null;
2804 }
2805
2806 // -------------------------------------------------------------
2807 // Application Window Tokens
2808 // -------------------------------------------------------------
2809
2810 public void validateAppTokens(List tokens) {
2811 int v = tokens.size()-1;
2812 int m = mAppTokens.size()-1;
2813 while (v >= 0 && m >= 0) {
2814 AppWindowToken wtoken = mAppTokens.get(m);
2815 if (wtoken.removed) {
2816 m--;
2817 continue;
2818 }
2819 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002820 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002821 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2822 }
2823 v--;
2824 m--;
2825 }
2826 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002827 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002828 v--;
2829 }
2830 while (m >= 0) {
2831 AppWindowToken wtoken = mAppTokens.get(m);
2832 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002833 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002834 }
2835 m--;
2836 }
2837 }
2838
2839 boolean checkCallingPermission(String permission, String func) {
2840 // Quick check: if the calling permission is me, it's all okay.
2841 if (Binder.getCallingPid() == Process.myPid()) {
2842 return true;
2843 }
Romain Guy06882f82009-06-10 13:36:04 -07002844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002845 if (mContext.checkCallingPermission(permission)
2846 == PackageManager.PERMISSION_GRANTED) {
2847 return true;
2848 }
2849 String msg = "Permission Denial: " + func + " from pid="
2850 + Binder.getCallingPid()
2851 + ", uid=" + Binder.getCallingUid()
2852 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002853 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002854 return false;
2855 }
Romain Guy06882f82009-06-10 13:36:04 -07002856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002857 AppWindowToken findAppWindowToken(IBinder token) {
2858 WindowToken wtoken = mTokenMap.get(token);
2859 if (wtoken == null) {
2860 return null;
2861 }
2862 return wtoken.appWindowToken;
2863 }
Romain Guy06882f82009-06-10 13:36:04 -07002864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002865 public void addWindowToken(IBinder token, int type) {
2866 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2867 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002868 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002869 }
Romain Guy06882f82009-06-10 13:36:04 -07002870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002871 synchronized(mWindowMap) {
2872 WindowToken wtoken = mTokenMap.get(token);
2873 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002874 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002875 return;
2876 }
2877 wtoken = new WindowToken(token, type, true);
2878 mTokenMap.put(token, wtoken);
2879 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002880 if (type == TYPE_WALLPAPER) {
2881 mWallpaperTokens.add(wtoken);
2882 }
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 public void removeWindowToken(IBinder token) {
2887 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2888 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002889 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002890 }
2891
2892 final long origId = Binder.clearCallingIdentity();
2893 synchronized(mWindowMap) {
2894 WindowToken wtoken = mTokenMap.remove(token);
2895 mTokenList.remove(wtoken);
2896 if (wtoken != null) {
2897 boolean delayed = false;
2898 if (!wtoken.hidden) {
2899 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002901 final int N = wtoken.windows.size();
2902 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002904 for (int i=0; i<N; i++) {
2905 WindowState win = wtoken.windows.get(i);
2906
2907 if (win.isAnimating()) {
2908 delayed = true;
2909 }
Romain Guy06882f82009-06-10 13:36:04 -07002910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002911 if (win.isVisibleNow()) {
2912 applyAnimationLocked(win,
2913 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002914 changed = true;
2915 }
2916 }
2917
2918 if (changed) {
2919 mLayoutNeeded = true;
2920 performLayoutAndPlaceSurfacesLocked();
2921 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2922 }
Romain Guy06882f82009-06-10 13:36:04 -07002923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002924 if (delayed) {
2925 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002926 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2927 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002928 }
2929 }
Romain Guy06882f82009-06-10 13:36:04 -07002930
Jeff Brownc5ed5912010-07-14 18:48:53 -07002931 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002932 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002933 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002934 }
2935 }
2936 Binder.restoreCallingIdentity(origId);
2937 }
2938
2939 public void addAppToken(int addPos, IApplicationToken token,
2940 int groupId, int requestedOrientation, boolean fullscreen) {
2941 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2942 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002943 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002944 }
Jeff Brown349703e2010-06-22 01:27:15 -07002945
2946 // Get the dispatching timeout here while we are not holding any locks so that it
2947 // can be cached by the AppWindowToken. The timeout value is used later by the
2948 // input dispatcher in code that does hold locks. If we did not cache the value
2949 // here we would run the chance of introducing a deadlock between the window manager
2950 // (which holds locks while updating the input dispatcher state) and the activity manager
2951 // (which holds locks while querying the application token).
2952 long inputDispatchingTimeoutNanos;
2953 try {
2954 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
2955 } catch (RemoteException ex) {
2956 Slog.w(TAG, "Could not get dispatching timeout.", ex);
2957 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
2958 }
Romain Guy06882f82009-06-10 13:36:04 -07002959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002960 synchronized(mWindowMap) {
2961 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2962 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002963 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002964 return;
2965 }
2966 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07002967 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002968 wtoken.groupId = groupId;
2969 wtoken.appFullscreen = fullscreen;
2970 wtoken.requestedOrientation = requestedOrientation;
2971 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002972 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002973 mTokenMap.put(token.asBinder(), wtoken);
2974 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002976 // Application tokens start out hidden.
2977 wtoken.hidden = true;
2978 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002980 //dump();
2981 }
2982 }
Romain Guy06882f82009-06-10 13:36:04 -07002983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002984 public void setAppGroupId(IBinder token, int groupId) {
2985 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2986 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002987 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002988 }
2989
2990 synchronized(mWindowMap) {
2991 AppWindowToken wtoken = findAppWindowToken(token);
2992 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002993 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002994 return;
2995 }
2996 wtoken.groupId = groupId;
2997 }
2998 }
Romain Guy06882f82009-06-10 13:36:04 -07002999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003000 public int getOrientationFromWindowsLocked() {
3001 int pos = mWindows.size() - 1;
3002 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003003 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003004 pos--;
3005 if (wtoken.mAppToken != null) {
3006 // We hit an application window. so the orientation will be determined by the
3007 // app window. No point in continuing further.
3008 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3009 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003010 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003011 continue;
3012 }
3013 int req = wtoken.mAttrs.screenOrientation;
3014 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3015 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3016 continue;
3017 } else {
3018 return req;
3019 }
3020 }
3021 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3022 }
Romain Guy06882f82009-06-10 13:36:04 -07003023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003024 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003025 int pos = mAppTokens.size() - 1;
3026 int curGroup = 0;
3027 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3028 boolean findingBehind = false;
3029 boolean haveGroup = false;
3030 boolean lastFullscreen = false;
3031 while (pos >= 0) {
3032 AppWindowToken wtoken = mAppTokens.get(pos);
3033 pos--;
3034 // if we're about to tear down this window and not seek for
3035 // the behind activity, don't use it for orientation
3036 if (!findingBehind
3037 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3038 continue;
3039 }
3040
3041 if (!haveGroup) {
3042 // We ignore any hidden applications on the top.
3043 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003044 continue;
3045 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003046 haveGroup = true;
3047 curGroup = wtoken.groupId;
3048 lastOrientation = wtoken.requestedOrientation;
3049 } else if (curGroup != wtoken.groupId) {
3050 // If we have hit a new application group, and the bottom
3051 // of the previous group didn't explicitly say to use
3052 // the orientation behind it, and the last app was
3053 // full screen, then we'll stick with the
3054 // user's orientation.
3055 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3056 && lastFullscreen) {
3057 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003058 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003059 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003060 int or = wtoken.requestedOrientation;
3061 // If this application is fullscreen, and didn't explicitly say
3062 // to use the orientation behind it, then just take whatever
3063 // orientation it has and ignores whatever is under it.
3064 lastFullscreen = wtoken.appFullscreen;
3065 if (lastFullscreen
3066 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3067 return or;
3068 }
3069 // If this application has requested an explicit orientation,
3070 // then use it.
3071 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3072 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3073 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3074 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3075 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3076 return or;
3077 }
3078 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3079 }
3080 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003081 }
Romain Guy06882f82009-06-10 13:36:04 -07003082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003083 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003084 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003085 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3086 "updateOrientationFromAppTokens()")) {
3087 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3088 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003089
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003090 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003091 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003092
3093 synchronized(mWindowMap) {
3094 if (updateOrientationFromAppTokensLocked()) {
3095 if (freezeThisOneIfNeeded != null) {
3096 AppWindowToken wtoken = findAppWindowToken(
3097 freezeThisOneIfNeeded);
3098 if (wtoken != null) {
3099 startAppFreezingScreenLocked(wtoken,
3100 ActivityInfo.CONFIG_ORIENTATION);
3101 }
3102 }
3103 config = computeNewConfigurationLocked();
3104
3105 } else if (currentConfig != null) {
3106 // No obvious action we need to take, but if our current
3107 // state mismatches the activity maanager's, update it
3108 mTempConfiguration.setToDefaults();
3109 if (computeNewConfigurationLocked(mTempConfiguration)) {
3110 if (currentConfig.diff(mTempConfiguration) != 0) {
3111 mWaitingForConfig = true;
3112 mLayoutNeeded = true;
3113 startFreezingDisplayLocked();
3114 config = new Configuration(mTempConfiguration);
3115 }
3116 }
3117 }
3118 }
3119
Dianne Hackborncfaef692009-06-15 14:24:44 -07003120 Binder.restoreCallingIdentity(ident);
3121 return config;
3122 }
3123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003124 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003125 * Determine the new desired orientation of the display, returning
3126 * a non-null new Configuration if it has changed from the current
3127 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3128 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3129 * SCREEN. This will typically be done for you if you call
3130 * sendNewConfiguration().
3131 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003132 * The orientation is computed from non-application windows first. If none of
3133 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003134 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003135 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3136 * android.os.IBinder)
3137 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003138 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003139 if (mDisplayFrozen) {
3140 // If the display is frozen, some activities may be in the middle
3141 // of restarting, and thus have removed their old window. If the
3142 // window has the flag to hide the lock screen, then the lock screen
3143 // can re-appear and inflict its own orientation on us. Keep the
3144 // orientation stable until this all settles down.
3145 return false;
3146 }
3147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003148 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003149 long ident = Binder.clearCallingIdentity();
3150 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003151 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003153 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003154 mForcedAppOrientation = req;
3155 //send a message to Policy indicating orientation change to take
3156 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003157 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003158 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3159 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3160 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003161 }
3162 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003163
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003164 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003165 } finally {
3166 Binder.restoreCallingIdentity(ident);
3167 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003168 }
Romain Guy06882f82009-06-10 13:36:04 -07003169
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003170 int computeForcedAppOrientationLocked() {
3171 int req = getOrientationFromWindowsLocked();
3172 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3173 req = getOrientationFromAppTokensLocked();
3174 }
3175 return req;
3176 }
Romain Guy06882f82009-06-10 13:36:04 -07003177
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003178 public void setNewConfiguration(Configuration config) {
3179 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3180 "setNewConfiguration()")) {
3181 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3182 }
3183
3184 synchronized(mWindowMap) {
3185 mCurConfiguration = new Configuration(config);
3186 mWaitingForConfig = false;
3187 performLayoutAndPlaceSurfacesLocked();
3188 }
3189 }
3190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003191 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3192 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3193 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003194 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003195 }
Romain Guy06882f82009-06-10 13:36:04 -07003196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003197 synchronized(mWindowMap) {
3198 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3199 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003200 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003201 return;
3202 }
Romain Guy06882f82009-06-10 13:36:04 -07003203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003204 wtoken.requestedOrientation = requestedOrientation;
3205 }
3206 }
Romain Guy06882f82009-06-10 13:36:04 -07003207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003208 public int getAppOrientation(IApplicationToken token) {
3209 synchronized(mWindowMap) {
3210 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3211 if (wtoken == null) {
3212 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3213 }
Romain Guy06882f82009-06-10 13:36:04 -07003214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003215 return wtoken.requestedOrientation;
3216 }
3217 }
Romain Guy06882f82009-06-10 13:36:04 -07003218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003219 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3220 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3221 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003222 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003223 }
3224
3225 synchronized(mWindowMap) {
3226 boolean changed = false;
3227 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003228 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003229 changed = mFocusedApp != null;
3230 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003231 if (changed) {
3232 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003233 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003234 } else {
3235 AppWindowToken newFocus = findAppWindowToken(token);
3236 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003237 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003238 return;
3239 }
3240 changed = mFocusedApp != newFocus;
3241 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003242 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003243 if (changed) {
3244 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003245 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003246 }
3247
3248 if (moveFocusNow && changed) {
3249 final long origId = Binder.clearCallingIdentity();
3250 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3251 Binder.restoreCallingIdentity(origId);
3252 }
3253 }
3254 }
3255
3256 public void prepareAppTransition(int transit) {
3257 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3258 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003259 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003260 }
Romain Guy06882f82009-06-10 13:36:04 -07003261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003262 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003263 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003264 TAG, "Prepare app transition: transit=" + transit
3265 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003266 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003267 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3268 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003269 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003270 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3271 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3272 // Opening a new task always supersedes a close for the anim.
3273 mNextAppTransition = transit;
3274 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3275 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3276 // Opening a new activity always supersedes a close for the anim.
3277 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003278 }
3279 mAppTransitionReady = false;
3280 mAppTransitionTimeout = false;
3281 mStartingIconInTransition = false;
3282 mSkipAppTransitionAnimation = false;
3283 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3284 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3285 5000);
3286 }
3287 }
3288 }
3289
3290 public int getPendingAppTransition() {
3291 return mNextAppTransition;
3292 }
Romain Guy06882f82009-06-10 13:36:04 -07003293
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003294 public void overridePendingAppTransition(String packageName,
3295 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003296 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003297 mNextAppTransitionPackage = packageName;
3298 mNextAppTransitionEnter = enterAnim;
3299 mNextAppTransitionExit = exitAnim;
3300 }
3301 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003303 public void executeAppTransition() {
3304 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3305 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003306 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003307 }
Romain Guy06882f82009-06-10 13:36:04 -07003308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003309 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003310 if (DEBUG_APP_TRANSITIONS) {
3311 RuntimeException e = new RuntimeException("here");
3312 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003313 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003314 + mNextAppTransition, e);
3315 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003316 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003317 mAppTransitionReady = true;
3318 final long origId = Binder.clearCallingIdentity();
3319 performLayoutAndPlaceSurfacesLocked();
3320 Binder.restoreCallingIdentity(origId);
3321 }
3322 }
3323 }
3324
3325 public void setAppStartingWindow(IBinder token, String pkg,
3326 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3327 IBinder transferFrom, boolean createIfNeeded) {
3328 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3329 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003330 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003331 }
3332
3333 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003334 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003335 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3336 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003338 AppWindowToken wtoken = findAppWindowToken(token);
3339 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003340 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003341 return;
3342 }
3343
3344 // If the display is frozen, we won't do anything until the
3345 // actual window is displayed so there is no reason to put in
3346 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003347 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003348 return;
3349 }
Romain Guy06882f82009-06-10 13:36:04 -07003350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003351 if (wtoken.startingData != null) {
3352 return;
3353 }
Romain Guy06882f82009-06-10 13:36:04 -07003354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003355 if (transferFrom != null) {
3356 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3357 if (ttoken != null) {
3358 WindowState startingWindow = ttoken.startingWindow;
3359 if (startingWindow != null) {
3360 if (mStartingIconInTransition) {
3361 // In this case, the starting icon has already
3362 // been displayed, so start letting windows get
3363 // shown immediately without any more transitions.
3364 mSkipAppTransitionAnimation = true;
3365 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003366 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003367 "Moving existing starting from " + ttoken
3368 + " to " + wtoken);
3369 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003371 // Transfer the starting window over to the new
3372 // token.
3373 wtoken.startingData = ttoken.startingData;
3374 wtoken.startingView = ttoken.startingView;
3375 wtoken.startingWindow = startingWindow;
3376 ttoken.startingData = null;
3377 ttoken.startingView = null;
3378 ttoken.startingWindow = null;
3379 ttoken.startingMoved = true;
3380 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003381 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003382 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003383 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003384 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003385 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003386 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003387 ttoken.windows.remove(startingWindow);
3388 ttoken.allAppWindows.remove(startingWindow);
3389 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003391 // Propagate other interesting state between the
3392 // tokens. If the old token is displayed, we should
3393 // immediately force the new one to be displayed. If
3394 // it is animating, we need to move that animation to
3395 // the new one.
3396 if (ttoken.allDrawn) {
3397 wtoken.allDrawn = true;
3398 }
3399 if (ttoken.firstWindowDrawn) {
3400 wtoken.firstWindowDrawn = true;
3401 }
3402 if (!ttoken.hidden) {
3403 wtoken.hidden = false;
3404 wtoken.hiddenRequested = false;
3405 wtoken.willBeHidden = false;
3406 }
3407 if (wtoken.clientHidden != ttoken.clientHidden) {
3408 wtoken.clientHidden = ttoken.clientHidden;
3409 wtoken.sendAppVisibilityToClients();
3410 }
3411 if (ttoken.animation != null) {
3412 wtoken.animation = ttoken.animation;
3413 wtoken.animating = ttoken.animating;
3414 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3415 ttoken.animation = null;
3416 ttoken.animLayerAdjustment = 0;
3417 wtoken.updateLayers();
3418 ttoken.updateLayers();
3419 }
Romain Guy06882f82009-06-10 13:36:04 -07003420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003421 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003422 mLayoutNeeded = true;
3423 performLayoutAndPlaceSurfacesLocked();
3424 Binder.restoreCallingIdentity(origId);
3425 return;
3426 } else if (ttoken.startingData != null) {
3427 // The previous app was getting ready to show a
3428 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003429 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003430 "Moving pending starting from " + ttoken
3431 + " to " + wtoken);
3432 wtoken.startingData = ttoken.startingData;
3433 ttoken.startingData = null;
3434 ttoken.startingMoved = true;
3435 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3436 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3437 // want to process the message ASAP, before any other queued
3438 // messages.
3439 mH.sendMessageAtFrontOfQueue(m);
3440 return;
3441 }
3442 }
3443 }
3444
3445 // There is no existing starting window, and the caller doesn't
3446 // want us to create one, so that's it!
3447 if (!createIfNeeded) {
3448 return;
3449 }
Romain Guy06882f82009-06-10 13:36:04 -07003450
Dianne Hackborn284ac932009-08-28 10:34:25 -07003451 // If this is a translucent or wallpaper window, then don't
3452 // show a starting window -- the current effect (a full-screen
3453 // opaque starting window that fades away to the real contents
3454 // when it is ready) does not work for this.
3455 if (theme != 0) {
3456 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3457 com.android.internal.R.styleable.Window);
3458 if (ent.array.getBoolean(
3459 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3460 return;
3461 }
3462 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003463 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3464 return;
3465 }
3466 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003467 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3468 return;
3469 }
3470 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003472 mStartingIconInTransition = true;
3473 wtoken.startingData = new StartingData(
3474 pkg, theme, nonLocalizedLabel,
3475 labelRes, icon);
3476 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3477 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3478 // want to process the message ASAP, before any other queued
3479 // messages.
3480 mH.sendMessageAtFrontOfQueue(m);
3481 }
3482 }
3483
3484 public void setAppWillBeHidden(IBinder token) {
3485 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3486 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003487 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003488 }
3489
3490 AppWindowToken wtoken;
3491
3492 synchronized(mWindowMap) {
3493 wtoken = findAppWindowToken(token);
3494 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003495 Slog.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003496 return;
3497 }
3498 wtoken.willBeHidden = true;
3499 }
3500 }
Romain Guy06882f82009-06-10 13:36:04 -07003501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003502 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3503 boolean visible, int transit, boolean performLayout) {
3504 boolean delayed = false;
3505
3506 if (wtoken.clientHidden == visible) {
3507 wtoken.clientHidden = !visible;
3508 wtoken.sendAppVisibilityToClients();
3509 }
Romain Guy06882f82009-06-10 13:36:04 -07003510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003511 wtoken.willBeHidden = false;
3512 if (wtoken.hidden == visible) {
3513 final int N = wtoken.allAppWindows.size();
3514 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003515 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003516 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3517 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003519 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003520
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003521 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003522 if (wtoken.animation == sDummyAnimation) {
3523 wtoken.animation = null;
3524 }
3525 applyAnimationLocked(wtoken, lp, transit, visible);
3526 changed = true;
3527 if (wtoken.animation != null) {
3528 delayed = runningAppAnimation = true;
3529 }
3530 }
Romain Guy06882f82009-06-10 13:36:04 -07003531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003532 for (int i=0; i<N; i++) {
3533 WindowState win = wtoken.allAppWindows.get(i);
3534 if (win == wtoken.startingWindow) {
3535 continue;
3536 }
3537
3538 if (win.isAnimating()) {
3539 delayed = true;
3540 }
Romain Guy06882f82009-06-10 13:36:04 -07003541
Joe Onorato8a9b2202010-02-26 18:56:32 -08003542 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003543 //win.dump(" ");
3544 if (visible) {
3545 if (!win.isVisibleNow()) {
3546 if (!runningAppAnimation) {
3547 applyAnimationLocked(win,
3548 WindowManagerPolicy.TRANSIT_ENTER, true);
3549 }
3550 changed = true;
3551 }
3552 } else if (win.isVisibleNow()) {
3553 if (!runningAppAnimation) {
3554 applyAnimationLocked(win,
3555 WindowManagerPolicy.TRANSIT_EXIT, false);
3556 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003557 changed = true;
3558 }
3559 }
3560
3561 wtoken.hidden = wtoken.hiddenRequested = !visible;
3562 if (!visible) {
3563 unsetAppFreezingScreenLocked(wtoken, true, true);
3564 } else {
3565 // If we are being set visible, and the starting window is
3566 // not yet displayed, then make sure it doesn't get displayed.
3567 WindowState swin = wtoken.startingWindow;
3568 if (swin != null && (swin.mDrawPending
3569 || swin.mCommitDrawPending)) {
3570 swin.mPolicyVisibility = false;
3571 swin.mPolicyVisibilityAfterAnim = false;
3572 }
3573 }
Romain Guy06882f82009-06-10 13:36:04 -07003574
Joe Onorato8a9b2202010-02-26 18:56:32 -08003575 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003576 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3577 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003578
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003579 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003580 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003581 if (performLayout) {
3582 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3583 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003584 } else {
3585 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003586 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003587 }
3588 }
3589
3590 if (wtoken.animation != null) {
3591 delayed = true;
3592 }
Romain Guy06882f82009-06-10 13:36:04 -07003593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003594 return delayed;
3595 }
3596
3597 public void setAppVisibility(IBinder token, boolean visible) {
3598 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3599 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003600 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003601 }
3602
3603 AppWindowToken wtoken;
3604
3605 synchronized(mWindowMap) {
3606 wtoken = findAppWindowToken(token);
3607 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003608 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003609 return;
3610 }
3611
3612 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003613 RuntimeException e = null;
3614 if (!HIDE_STACK_CRAWLS) {
3615 e = new RuntimeException();
3616 e.fillInStackTrace();
3617 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003618 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003619 + "): mNextAppTransition=" + mNextAppTransition
3620 + " hidden=" + wtoken.hidden
3621 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3622 }
Romain Guy06882f82009-06-10 13:36:04 -07003623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003624 // If we are preparing an app transition, then delay changing
3625 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003626 if (!mDisplayFrozen && mPolicy.isScreenOn()
3627 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003628 // Already in requested state, don't do anything more.
3629 if (wtoken.hiddenRequested != visible) {
3630 return;
3631 }
3632 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003633
Joe Onorato8a9b2202010-02-26 18:56:32 -08003634 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003635 TAG, "Setting dummy animation on: " + wtoken);
3636 wtoken.setDummyAnimation();
3637 mOpeningApps.remove(wtoken);
3638 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003639 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003640 wtoken.inPendingTransaction = true;
3641 if (visible) {
3642 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003643 wtoken.startingDisplayed = false;
3644 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003645
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003646 // If the token is currently hidden (should be the
3647 // common case), then we need to set up to wait for
3648 // its windows to be ready.
3649 if (wtoken.hidden) {
3650 wtoken.allDrawn = false;
3651 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003652
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003653 if (wtoken.clientHidden) {
3654 // In the case where we are making an app visible
3655 // but holding off for a transition, we still need
3656 // to tell the client to make its windows visible so
3657 // they get drawn. Otherwise, we will wait on
3658 // performing the transition until all windows have
3659 // been drawn, they never will be, and we are sad.
3660 wtoken.clientHidden = false;
3661 wtoken.sendAppVisibilityToClients();
3662 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003663 }
3664 } else {
3665 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003666
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003667 // If the token is currently visible (should be the
3668 // common case), then set up to wait for it to be hidden.
3669 if (!wtoken.hidden) {
3670 wtoken.waitingToHide = true;
3671 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003672 }
3673 return;
3674 }
Romain Guy06882f82009-06-10 13:36:04 -07003675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003676 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003677 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003678 wtoken.updateReportedVisibilityLocked();
3679 Binder.restoreCallingIdentity(origId);
3680 }
3681 }
3682
3683 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3684 boolean unfreezeSurfaceNow, boolean force) {
3685 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003686 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003687 + " force=" + force);
3688 final int N = wtoken.allAppWindows.size();
3689 boolean unfrozeWindows = false;
3690 for (int i=0; i<N; i++) {
3691 WindowState w = wtoken.allAppWindows.get(i);
3692 if (w.mAppFreezing) {
3693 w.mAppFreezing = false;
3694 if (w.mSurface != null && !w.mOrientationChanging) {
3695 w.mOrientationChanging = true;
3696 }
3697 unfrozeWindows = true;
3698 }
3699 }
3700 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003701 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003702 wtoken.freezingScreen = false;
3703 mAppsFreezingScreen--;
3704 }
3705 if (unfreezeSurfaceNow) {
3706 if (unfrozeWindows) {
3707 mLayoutNeeded = true;
3708 performLayoutAndPlaceSurfacesLocked();
3709 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003710 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003711 }
3712 }
3713 }
Romain Guy06882f82009-06-10 13:36:04 -07003714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003715 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3716 int configChanges) {
3717 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003718 RuntimeException e = null;
3719 if (!HIDE_STACK_CRAWLS) {
3720 e = new RuntimeException();
3721 e.fillInStackTrace();
3722 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003723 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003724 + ": hidden=" + wtoken.hidden + " freezing="
3725 + wtoken.freezingScreen, e);
3726 }
3727 if (!wtoken.hiddenRequested) {
3728 if (!wtoken.freezingScreen) {
3729 wtoken.freezingScreen = true;
3730 mAppsFreezingScreen++;
3731 if (mAppsFreezingScreen == 1) {
3732 startFreezingDisplayLocked();
3733 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3734 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3735 5000);
3736 }
3737 }
3738 final int N = wtoken.allAppWindows.size();
3739 for (int i=0; i<N; i++) {
3740 WindowState w = wtoken.allAppWindows.get(i);
3741 w.mAppFreezing = true;
3742 }
3743 }
3744 }
Romain Guy06882f82009-06-10 13:36:04 -07003745
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003746 public void startAppFreezingScreen(IBinder token, int configChanges) {
3747 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3748 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003749 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003750 }
3751
3752 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003753 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003754 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003755 return;
3756 }
Romain Guy06882f82009-06-10 13:36:04 -07003757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003758 AppWindowToken wtoken = findAppWindowToken(token);
3759 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003760 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003761 return;
3762 }
3763 final long origId = Binder.clearCallingIdentity();
3764 startAppFreezingScreenLocked(wtoken, configChanges);
3765 Binder.restoreCallingIdentity(origId);
3766 }
3767 }
Romain Guy06882f82009-06-10 13:36:04 -07003768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003769 public void stopAppFreezingScreen(IBinder token, boolean force) {
3770 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3771 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003772 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003773 }
3774
3775 synchronized(mWindowMap) {
3776 AppWindowToken wtoken = findAppWindowToken(token);
3777 if (wtoken == null || wtoken.appToken == null) {
3778 return;
3779 }
3780 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003781 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003782 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3783 unsetAppFreezingScreenLocked(wtoken, true, force);
3784 Binder.restoreCallingIdentity(origId);
3785 }
3786 }
Romain Guy06882f82009-06-10 13:36:04 -07003787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003788 public void removeAppToken(IBinder token) {
3789 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3790 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003791 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003792 }
3793
3794 AppWindowToken wtoken = null;
3795 AppWindowToken startingToken = null;
3796 boolean delayed = false;
3797
3798 final long origId = Binder.clearCallingIdentity();
3799 synchronized(mWindowMap) {
3800 WindowToken basewtoken = mTokenMap.remove(token);
3801 mTokenList.remove(basewtoken);
3802 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003803 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003804 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003805 wtoken.inPendingTransaction = false;
3806 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003807 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003808 if (mClosingApps.contains(wtoken)) {
3809 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003810 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003811 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003812 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003813 delayed = true;
3814 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003815 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003816 TAG, "Removing app " + wtoken + " delayed=" + delayed
3817 + " animation=" + wtoken.animation
3818 + " animating=" + wtoken.animating);
3819 if (delayed) {
3820 // set the token aside because it has an active animation to be finished
3821 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003822 } else {
3823 // Make sure there is no animation running on this token,
3824 // so any windows associated with it will be removed as
3825 // soon as their animations are complete
3826 wtoken.animation = null;
3827 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003828 }
3829 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003830 if (mLastEnterAnimToken == wtoken) {
3831 mLastEnterAnimToken = null;
3832 mLastEnterAnimParams = null;
3833 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003834 wtoken.removed = true;
3835 if (wtoken.startingData != null) {
3836 startingToken = wtoken;
3837 }
3838 unsetAppFreezingScreenLocked(wtoken, true, true);
3839 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003840 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003841 mFocusedApp = null;
3842 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003843 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003844 }
3845 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003846 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003847 }
Romain Guy06882f82009-06-10 13:36:04 -07003848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003849 if (!delayed && wtoken != null) {
3850 wtoken.updateReportedVisibilityLocked();
3851 }
3852 }
3853 Binder.restoreCallingIdentity(origId);
3854
3855 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003856 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003857 + startingToken + ": app token removed");
3858 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3859 mH.sendMessage(m);
3860 }
3861 }
3862
3863 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3864 final int NW = token.windows.size();
3865 for (int i=0; i<NW; i++) {
3866 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003867 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003868 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003869 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003870 int j = win.mChildWindows.size();
3871 while (j > 0) {
3872 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003873 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003874 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003875 "Tmp removing child window " + cwin);
3876 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003877 }
3878 }
3879 return NW > 0;
3880 }
3881
3882 void dumpAppTokensLocked() {
3883 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003884 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003885 }
3886 }
Romain Guy06882f82009-06-10 13:36:04 -07003887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003888 void dumpWindowsLocked() {
3889 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003890 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003891 }
3892 }
Romain Guy06882f82009-06-10 13:36:04 -07003893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003894 private int findWindowOffsetLocked(int tokenPos) {
3895 final int NW = mWindows.size();
3896
3897 if (tokenPos >= mAppTokens.size()) {
3898 int i = NW;
3899 while (i > 0) {
3900 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07003901 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003902 if (win.getAppToken() != null) {
3903 return i+1;
3904 }
3905 }
3906 }
3907
3908 while (tokenPos > 0) {
3909 // Find the first app token below the new position that has
3910 // a window displayed.
3911 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003912 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003913 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003914 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003915 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003916 "Skipping token -- currently sending to bottom");
3917 tokenPos--;
3918 continue;
3919 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003920 int i = wtoken.windows.size();
3921 while (i > 0) {
3922 i--;
3923 WindowState win = wtoken.windows.get(i);
3924 int j = win.mChildWindows.size();
3925 while (j > 0) {
3926 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003927 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003928 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003929 for (int pos=NW-1; pos>=0; pos--) {
3930 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003931 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003932 "Found child win @" + (pos+1));
3933 return pos+1;
3934 }
3935 }
3936 }
3937 }
3938 for (int pos=NW-1; pos>=0; pos--) {
3939 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003940 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003941 return pos+1;
3942 }
3943 }
3944 }
3945 tokenPos--;
3946 }
3947
3948 return 0;
3949 }
3950
3951 private final int reAddWindowLocked(int index, WindowState win) {
3952 final int NCW = win.mChildWindows.size();
3953 boolean added = false;
3954 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07003955 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003956 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003957 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003958 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003959 mWindows.add(index, win);
3960 index++;
3961 added = true;
3962 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003963 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003964 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003965 mWindows.add(index, cwin);
3966 index++;
3967 }
3968 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003969 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003970 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003971 mWindows.add(index, win);
3972 index++;
3973 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003974 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003975 return index;
3976 }
Romain Guy06882f82009-06-10 13:36:04 -07003977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003978 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3979 final int NW = token.windows.size();
3980 for (int i=0; i<NW; i++) {
3981 index = reAddWindowLocked(index, token.windows.get(i));
3982 }
3983 return index;
3984 }
3985
3986 public void moveAppToken(int index, IBinder token) {
3987 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3988 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003989 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003990 }
3991
3992 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003993 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003994 if (DEBUG_REORDER) dumpAppTokensLocked();
3995 final AppWindowToken wtoken = findAppWindowToken(token);
3996 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003997 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003998 + token + " (" + wtoken + ")");
3999 return;
4000 }
4001 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004002 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004003 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004005 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004006 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004007 if (DEBUG_REORDER) dumpWindowsLocked();
4008 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004009 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004010 if (DEBUG_REORDER) dumpWindowsLocked();
4011 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004012 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004013 if (DEBUG_REORDER) dumpWindowsLocked();
4014 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004015 mLayoutNeeded = true;
4016 performLayoutAndPlaceSurfacesLocked();
4017 }
4018 Binder.restoreCallingIdentity(origId);
4019 }
4020 }
4021
4022 private void removeAppTokensLocked(List<IBinder> tokens) {
4023 // XXX This should be done more efficiently!
4024 // (take advantage of the fact that both lists should be
4025 // ordered in the same way.)
4026 int N = tokens.size();
4027 for (int i=0; i<N; i++) {
4028 IBinder token = tokens.get(i);
4029 final AppWindowToken wtoken = findAppWindowToken(token);
4030 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004031 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004032 + token + " (" + wtoken + ")");
4033 i--;
4034 N--;
4035 }
4036 }
4037 }
4038
Dianne Hackborna8f60182009-09-01 19:01:50 -07004039 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4040 boolean updateFocusAndLayout) {
4041 // First remove all of the windows from the list.
4042 tmpRemoveAppWindowsLocked(wtoken);
4043
4044 // Where to start adding?
4045 int pos = findWindowOffsetLocked(tokenPos);
4046
4047 // And now add them back at the correct place.
4048 pos = reAddAppWindowsLocked(pos, wtoken);
4049
4050 if (updateFocusAndLayout) {
4051 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4052 assignLayersLocked();
4053 }
4054 mLayoutNeeded = true;
4055 performLayoutAndPlaceSurfacesLocked();
4056 }
4057 }
4058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004059 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4060 // First remove all of the windows from the list.
4061 final int N = tokens.size();
4062 int i;
4063 for (i=0; i<N; i++) {
4064 WindowToken token = mTokenMap.get(tokens.get(i));
4065 if (token != null) {
4066 tmpRemoveAppWindowsLocked(token);
4067 }
4068 }
4069
4070 // Where to start adding?
4071 int pos = findWindowOffsetLocked(tokenPos);
4072
4073 // And now add them back at the correct place.
4074 for (i=0; i<N; i++) {
4075 WindowToken token = mTokenMap.get(tokens.get(i));
4076 if (token != null) {
4077 pos = reAddAppWindowsLocked(pos, token);
4078 }
4079 }
4080
Dianne Hackborna8f60182009-09-01 19:01:50 -07004081 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4082 assignLayersLocked();
4083 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004084 mLayoutNeeded = true;
4085 performLayoutAndPlaceSurfacesLocked();
4086
4087 //dump();
4088 }
4089
4090 public void moveAppTokensToTop(List<IBinder> tokens) {
4091 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4092 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004093 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004094 }
4095
4096 final long origId = Binder.clearCallingIdentity();
4097 synchronized(mWindowMap) {
4098 removeAppTokensLocked(tokens);
4099 final int N = tokens.size();
4100 for (int i=0; i<N; i++) {
4101 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4102 if (wt != null) {
4103 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004104 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004105 mToTopApps.remove(wt);
4106 mToBottomApps.remove(wt);
4107 mToTopApps.add(wt);
4108 wt.sendingToBottom = false;
4109 wt.sendingToTop = true;
4110 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004111 }
4112 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004113
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004114 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004115 moveAppWindowsLocked(tokens, mAppTokens.size());
4116 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004117 }
4118 Binder.restoreCallingIdentity(origId);
4119 }
4120
4121 public void moveAppTokensToBottom(List<IBinder> tokens) {
4122 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4123 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004124 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004125 }
4126
4127 final long origId = Binder.clearCallingIdentity();
4128 synchronized(mWindowMap) {
4129 removeAppTokensLocked(tokens);
4130 final int N = tokens.size();
4131 int pos = 0;
4132 for (int i=0; i<N; i++) {
4133 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4134 if (wt != null) {
4135 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004136 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004137 mToTopApps.remove(wt);
4138 mToBottomApps.remove(wt);
4139 mToBottomApps.add(i, wt);
4140 wt.sendingToTop = false;
4141 wt.sendingToBottom = true;
4142 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004143 pos++;
4144 }
4145 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004146
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004147 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004148 moveAppWindowsLocked(tokens, 0);
4149 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004150 }
4151 Binder.restoreCallingIdentity(origId);
4152 }
4153
4154 // -------------------------------------------------------------
4155 // Misc IWindowSession methods
4156 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004157
Jim Miller284b62e2010-06-08 14:27:42 -07004158 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004159 {
Jim Miller284b62e2010-06-08 14:27:42 -07004160 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4161 // called before DevicePolicyManagerService has started.
4162 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4163 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4164 Context.DEVICE_POLICY_SERVICE);
4165 if (dpm != null) {
4166 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4167 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4168 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4169 }
Jim Millerd6b57052010-06-07 17:52:42 -07004170 }
Jim Miller284b62e2010-06-08 14:27:42 -07004171 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004172 }
4173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004174 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004175 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004176 != PackageManager.PERMISSION_GRANTED) {
4177 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4178 }
Jim Millerd6b57052010-06-07 17:52:42 -07004179
Jim Miller284b62e2010-06-08 14:27:42 -07004180 synchronized (mKeyguardTokenWatcher) {
4181 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004182 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004183 }
4184
4185 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004186 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004187 != PackageManager.PERMISSION_GRANTED) {
4188 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4189 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004190
Jim Miller284b62e2010-06-08 14:27:42 -07004191 synchronized (mKeyguardTokenWatcher) {
4192 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004193
Jim Miller284b62e2010-06-08 14:27:42 -07004194 if (!mKeyguardTokenWatcher.isAcquired()) {
4195 // If we are the last one to reenable the keyguard wait until
4196 // we have actually finished reenabling until returning.
4197 // It is possible that reenableKeyguard() can be called before
4198 // the previous disableKeyguard() is handled, in which case
4199 // neither mKeyguardTokenWatcher.acquired() or released() would
4200 // be called. In that case mKeyguardDisabled will be false here
4201 // and we have nothing to wait for.
4202 while (mKeyguardDisabled) {
4203 try {
4204 mKeyguardTokenWatcher.wait();
4205 } catch (InterruptedException e) {
4206 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004207 }
4208 }
4209 }
4210 }
4211 }
4212
4213 /**
4214 * @see android.app.KeyguardManager#exitKeyguardSecurely
4215 */
4216 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004217 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004218 != PackageManager.PERMISSION_GRANTED) {
4219 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4220 }
4221 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4222 public void onKeyguardExitResult(boolean success) {
4223 try {
4224 callback.onKeyguardExitResult(success);
4225 } catch (RemoteException e) {
4226 // Client has died, we don't care.
4227 }
4228 }
4229 });
4230 }
4231
4232 public boolean inKeyguardRestrictedInputMode() {
4233 return mPolicy.inKeyguardRestrictedKeyInputMode();
4234 }
Romain Guy06882f82009-06-10 13:36:04 -07004235
Dianne Hackbornffa42482009-09-23 22:20:11 -07004236 public void closeSystemDialogs(String reason) {
4237 synchronized(mWindowMap) {
4238 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004239 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004240 if (w.mSurface != null) {
4241 try {
4242 w.mClient.closeSystemDialogs(reason);
4243 } catch (RemoteException e) {
4244 }
4245 }
4246 }
4247 }
4248 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004250 static float fixScale(float scale) {
4251 if (scale < 0) scale = 0;
4252 else if (scale > 20) scale = 20;
4253 return Math.abs(scale);
4254 }
Romain Guy06882f82009-06-10 13:36:04 -07004255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004256 public void setAnimationScale(int which, float scale) {
4257 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4258 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004259 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004260 }
4261
4262 if (scale < 0) scale = 0;
4263 else if (scale > 20) scale = 20;
4264 scale = Math.abs(scale);
4265 switch (which) {
4266 case 0: mWindowAnimationScale = fixScale(scale); break;
4267 case 1: mTransitionAnimationScale = fixScale(scale); break;
4268 }
Romain Guy06882f82009-06-10 13:36:04 -07004269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004270 // Persist setting
4271 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4272 }
Romain Guy06882f82009-06-10 13:36:04 -07004273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004274 public void setAnimationScales(float[] scales) {
4275 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4276 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004277 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004278 }
4279
4280 if (scales != null) {
4281 if (scales.length >= 1) {
4282 mWindowAnimationScale = fixScale(scales[0]);
4283 }
4284 if (scales.length >= 2) {
4285 mTransitionAnimationScale = fixScale(scales[1]);
4286 }
4287 }
Romain Guy06882f82009-06-10 13:36:04 -07004288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004289 // Persist setting
4290 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4291 }
Romain Guy06882f82009-06-10 13:36:04 -07004292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004293 public float getAnimationScale(int which) {
4294 switch (which) {
4295 case 0: return mWindowAnimationScale;
4296 case 1: return mTransitionAnimationScale;
4297 }
4298 return 0;
4299 }
Romain Guy06882f82009-06-10 13:36:04 -07004300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004301 public float[] getAnimationScales() {
4302 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4303 }
Romain Guy06882f82009-06-10 13:36:04 -07004304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004305 public int getSwitchState(int sw) {
4306 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4307 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004308 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004309 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004310 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004311 }
Romain Guy06882f82009-06-10 13:36:04 -07004312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004313 public int getSwitchStateForDevice(int devid, int sw) {
4314 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4315 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004316 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004317 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004318 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004319 }
Romain Guy06882f82009-06-10 13:36:04 -07004320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004321 public int getScancodeState(int sw) {
4322 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4323 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004324 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004325 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004326 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004327 }
Romain Guy06882f82009-06-10 13:36:04 -07004328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004329 public int getScancodeStateForDevice(int devid, int sw) {
4330 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4331 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004332 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004333 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004334 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004335 }
Romain Guy06882f82009-06-10 13:36:04 -07004336
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004337 public int getTrackballScancodeState(int sw) {
4338 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4339 "getTrackballScancodeState()")) {
4340 throw new SecurityException("Requires READ_INPUT_STATE permission");
4341 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004342 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004343 }
4344
4345 public int getDPadScancodeState(int sw) {
4346 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4347 "getDPadScancodeState()")) {
4348 throw new SecurityException("Requires READ_INPUT_STATE permission");
4349 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004350 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004351 }
4352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004353 public int getKeycodeState(int sw) {
4354 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4355 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004356 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004357 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004358 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004359 }
Romain Guy06882f82009-06-10 13:36:04 -07004360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004361 public int getKeycodeStateForDevice(int devid, int sw) {
4362 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4363 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004364 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004365 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004366 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004367 }
Romain Guy06882f82009-06-10 13:36:04 -07004368
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004369 public int getTrackballKeycodeState(int sw) {
4370 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4371 "getTrackballKeycodeState()")) {
4372 throw new SecurityException("Requires READ_INPUT_STATE permission");
4373 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004374 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004375 }
4376
4377 public int getDPadKeycodeState(int sw) {
4378 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4379 "getDPadKeycodeState()")) {
4380 throw new SecurityException("Requires READ_INPUT_STATE permission");
4381 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004382 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004383 }
4384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004385 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004386 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004387 }
Romain Guy06882f82009-06-10 13:36:04 -07004388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004389 public void enableScreenAfterBoot() {
4390 synchronized(mWindowMap) {
4391 if (mSystemBooted) {
4392 return;
4393 }
4394 mSystemBooted = true;
4395 }
Romain Guy06882f82009-06-10 13:36:04 -07004396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004397 performEnableScreen();
4398 }
Romain Guy06882f82009-06-10 13:36:04 -07004399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004400 public void enableScreenIfNeededLocked() {
4401 if (mDisplayEnabled) {
4402 return;
4403 }
4404 if (!mSystemBooted) {
4405 return;
4406 }
4407 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4408 }
Romain Guy06882f82009-06-10 13:36:04 -07004409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004410 public void performEnableScreen() {
4411 synchronized(mWindowMap) {
4412 if (mDisplayEnabled) {
4413 return;
4414 }
4415 if (!mSystemBooted) {
4416 return;
4417 }
Romain Guy06882f82009-06-10 13:36:04 -07004418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004419 // Don't enable the screen until all existing windows
4420 // have been drawn.
4421 final int N = mWindows.size();
4422 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004423 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004424 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004425 return;
4426 }
4427 }
Romain Guy06882f82009-06-10 13:36:04 -07004428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004429 mDisplayEnabled = true;
4430 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004431 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004432 StringWriter sw = new StringWriter();
4433 PrintWriter pw = new PrintWriter(sw);
4434 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004435 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004436 }
4437 try {
4438 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4439 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004440 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004441 Parcel data = Parcel.obtain();
4442 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4443 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4444 data, null, 0);
4445 data.recycle();
4446 }
4447 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004448 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004449 }
4450 }
Romain Guy06882f82009-06-10 13:36:04 -07004451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004452 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004454 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004455 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4456 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004457 }
Romain Guy06882f82009-06-10 13:36:04 -07004458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004459 public void setInTouchMode(boolean mode) {
4460 synchronized(mWindowMap) {
4461 mInTouchMode = mode;
4462 }
4463 }
4464
Romain Guy06882f82009-06-10 13:36:04 -07004465 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004466 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004467 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004468 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004469 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004470 }
4471
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004472 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004473 }
Romain Guy06882f82009-06-10 13:36:04 -07004474
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004475 public void setRotationUnchecked(int rotation,
4476 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004477 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004478 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004480 long origId = Binder.clearCallingIdentity();
4481 boolean changed;
4482 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004483 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004484 }
Romain Guy06882f82009-06-10 13:36:04 -07004485
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004486 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004487 sendNewConfiguration();
4488 }
Romain Guy06882f82009-06-10 13:36:04 -07004489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004490 Binder.restoreCallingIdentity(origId);
4491 }
Romain Guy06882f82009-06-10 13:36:04 -07004492
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004493 /**
4494 * Apply a new rotation to the screen, respecting the requests of
4495 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4496 * re-evaluate the desired rotation.
4497 *
4498 * Returns null if the rotation has been changed. In this case YOU
4499 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4500 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004501 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004502 boolean changed;
4503 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4504 rotation = mRequestedRotation;
4505 } else {
4506 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004507 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004508 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004509 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004510 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004511 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004512 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004513 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004515 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004516 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004517 "Rotation changed to " + rotation
4518 + " from " + mRotation
4519 + " (forceApp=" + mForcedAppOrientation
4520 + ", req=" + mRequestedRotation + ")");
4521 mRotation = rotation;
4522 mWindowsFreezingScreen = true;
4523 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4524 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4525 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004526 mWaitingForConfig = true;
4527 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004528 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004529 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004530 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004531 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004532 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004533 }
4534 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004535 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004536 if (w.mSurface != null) {
4537 w.mOrientationChanging = true;
4538 }
4539 }
4540 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4541 try {
4542 mRotationWatchers.get(i).onRotationChanged(rotation);
4543 } catch (RemoteException e) {
4544 }
4545 }
4546 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004548 return changed;
4549 }
Romain Guy06882f82009-06-10 13:36:04 -07004550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004551 public int getRotation() {
4552 return mRotation;
4553 }
4554
4555 public int watchRotation(IRotationWatcher watcher) {
4556 final IBinder watcherBinder = watcher.asBinder();
4557 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4558 public void binderDied() {
4559 synchronized (mWindowMap) {
4560 for (int i=0; i<mRotationWatchers.size(); i++) {
4561 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004562 IRotationWatcher removed = mRotationWatchers.remove(i);
4563 if (removed != null) {
4564 removed.asBinder().unlinkToDeath(this, 0);
4565 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004566 i--;
4567 }
4568 }
4569 }
4570 }
4571 };
Romain Guy06882f82009-06-10 13:36:04 -07004572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004573 synchronized (mWindowMap) {
4574 try {
4575 watcher.asBinder().linkToDeath(dr, 0);
4576 mRotationWatchers.add(watcher);
4577 } catch (RemoteException e) {
4578 // Client died, no cleanup needed.
4579 }
Romain Guy06882f82009-06-10 13:36:04 -07004580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004581 return mRotation;
4582 }
4583 }
4584
4585 /**
4586 * Starts the view server on the specified port.
4587 *
4588 * @param port The port to listener to.
4589 *
4590 * @return True if the server was successfully started, false otherwise.
4591 *
4592 * @see com.android.server.ViewServer
4593 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4594 */
4595 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004596 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004597 return false;
4598 }
4599
4600 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4601 return false;
4602 }
4603
4604 if (port < 1024) {
4605 return false;
4606 }
4607
4608 if (mViewServer != null) {
4609 if (!mViewServer.isRunning()) {
4610 try {
4611 return mViewServer.start();
4612 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004613 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004614 }
4615 }
4616 return false;
4617 }
4618
4619 try {
4620 mViewServer = new ViewServer(this, port);
4621 return mViewServer.start();
4622 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004623 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004624 }
4625 return false;
4626 }
4627
Romain Guy06882f82009-06-10 13:36:04 -07004628 private boolean isSystemSecure() {
4629 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4630 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4631 }
4632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004633 /**
4634 * Stops the view server if it exists.
4635 *
4636 * @return True if the server stopped, false if it wasn't started or
4637 * couldn't be stopped.
4638 *
4639 * @see com.android.server.ViewServer
4640 */
4641 public boolean stopViewServer() {
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 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4647 return false;
4648 }
4649
4650 if (mViewServer != null) {
4651 return mViewServer.stop();
4652 }
4653 return false;
4654 }
4655
4656 /**
4657 * Indicates whether the view server is running.
4658 *
4659 * @return True if the server is running, false otherwise.
4660 *
4661 * @see com.android.server.ViewServer
4662 */
4663 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004664 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004665 return false;
4666 }
4667
4668 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4669 return false;
4670 }
4671
4672 return mViewServer != null && mViewServer.isRunning();
4673 }
4674
4675 /**
4676 * Lists all availble windows in the system. The listing is written in the
4677 * specified Socket's output stream with the following syntax:
4678 * windowHashCodeInHexadecimal windowName
4679 * Each line of the ouput represents a different window.
4680 *
4681 * @param client The remote client to send the listing to.
4682 * @return False if an error occured, true otherwise.
4683 */
4684 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004685 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004686 return false;
4687 }
4688
4689 boolean result = true;
4690
Jeff Browne33348b2010-07-15 23:54:05 -07004691 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004692 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004693 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07004694 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004695 }
4696
4697 BufferedWriter out = null;
4698
4699 // Any uncaught exception will crash the system process
4700 try {
4701 OutputStream clientStream = client.getOutputStream();
4702 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4703
4704 final int count = windows.length;
4705 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004706 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004707 out.write(Integer.toHexString(System.identityHashCode(w)));
4708 out.write(' ');
4709 out.append(w.mAttrs.getTitle());
4710 out.write('\n');
4711 }
4712
4713 out.write("DONE.\n");
4714 out.flush();
4715 } catch (Exception e) {
4716 result = false;
4717 } finally {
4718 if (out != null) {
4719 try {
4720 out.close();
4721 } catch (IOException e) {
4722 result = false;
4723 }
4724 }
4725 }
4726
4727 return result;
4728 }
4729
4730 /**
4731 * Sends a command to a target window. The result of the command, if any, will be
4732 * written in the output stream of the specified socket.
4733 *
4734 * The parameters must follow this syntax:
4735 * windowHashcode extra
4736 *
4737 * Where XX is the length in characeters of the windowTitle.
4738 *
4739 * The first parameter is the target window. The window with the specified hashcode
4740 * will be the target. If no target can be found, nothing happens. The extra parameters
4741 * will be delivered to the target window and as parameters to the command itself.
4742 *
4743 * @param client The remote client to sent the result, if any, to.
4744 * @param command The command to execute.
4745 * @param parameters The command parameters.
4746 *
4747 * @return True if the command was successfully delivered, false otherwise. This does
4748 * not indicate whether the command itself was successful.
4749 */
4750 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004751 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004752 return false;
4753 }
4754
4755 boolean success = true;
4756 Parcel data = null;
4757 Parcel reply = null;
4758
4759 // Any uncaught exception will crash the system process
4760 try {
4761 // Find the hashcode of the window
4762 int index = parameters.indexOf(' ');
4763 if (index == -1) {
4764 index = parameters.length();
4765 }
4766 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004767 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004768
4769 // Extract the command's parameter after the window description
4770 if (index < parameters.length()) {
4771 parameters = parameters.substring(index + 1);
4772 } else {
4773 parameters = "";
4774 }
4775
4776 final WindowManagerService.WindowState window = findWindow(hashCode);
4777 if (window == null) {
4778 return false;
4779 }
4780
4781 data = Parcel.obtain();
4782 data.writeInterfaceToken("android.view.IWindow");
4783 data.writeString(command);
4784 data.writeString(parameters);
4785 data.writeInt(1);
4786 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4787
4788 reply = Parcel.obtain();
4789
4790 final IBinder binder = window.mClient.asBinder();
4791 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4792 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4793
4794 reply.readException();
4795
4796 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004797 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004798 success = false;
4799 } finally {
4800 if (data != null) {
4801 data.recycle();
4802 }
4803 if (reply != null) {
4804 reply.recycle();
4805 }
4806 }
4807
4808 return success;
4809 }
4810
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004811 public void addWindowChangeListener(WindowChangeListener listener) {
4812 synchronized(mWindowMap) {
4813 mWindowChangeListeners.add(listener);
4814 }
4815 }
4816
4817 public void removeWindowChangeListener(WindowChangeListener listener) {
4818 synchronized(mWindowMap) {
4819 mWindowChangeListeners.remove(listener);
4820 }
4821 }
4822
4823 private void notifyWindowsChanged() {
4824 WindowChangeListener[] windowChangeListeners;
4825 synchronized(mWindowMap) {
4826 if(mWindowChangeListeners.isEmpty()) {
4827 return;
4828 }
4829 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4830 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4831 }
4832 int N = windowChangeListeners.length;
4833 for(int i = 0; i < N; i++) {
4834 windowChangeListeners[i].windowsChanged();
4835 }
4836 }
4837
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07004838 private void notifyFocusChanged() {
4839 WindowChangeListener[] windowChangeListeners;
4840 synchronized(mWindowMap) {
4841 if(mWindowChangeListeners.isEmpty()) {
4842 return;
4843 }
4844 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4845 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4846 }
4847 int N = windowChangeListeners.length;
4848 for(int i = 0; i < N; i++) {
4849 windowChangeListeners[i].focusChanged();
4850 }
4851 }
4852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004853 private WindowState findWindow(int hashCode) {
4854 if (hashCode == -1) {
4855 return getFocusedWindow();
4856 }
4857
4858 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07004859 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004860 final int count = windows.size();
4861
4862 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004863 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004864 if (System.identityHashCode(w) == hashCode) {
4865 return w;
4866 }
4867 }
4868 }
4869
4870 return null;
4871 }
4872
4873 /*
4874 * Instruct the Activity Manager to fetch the current configuration and broadcast
4875 * that to config-changed listeners if appropriate.
4876 */
4877 void sendNewConfiguration() {
4878 try {
4879 mActivityManager.updateConfiguration(null);
4880 } catch (RemoteException e) {
4881 }
4882 }
Romain Guy06882f82009-06-10 13:36:04 -07004883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004884 public Configuration computeNewConfiguration() {
4885 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004886 return computeNewConfigurationLocked();
4887 }
4888 }
Romain Guy06882f82009-06-10 13:36:04 -07004889
Dianne Hackbornc485a602009-03-24 22:39:49 -07004890 Configuration computeNewConfigurationLocked() {
4891 Configuration config = new Configuration();
4892 if (!computeNewConfigurationLocked(config)) {
4893 return null;
4894 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004895 return config;
4896 }
Romain Guy06882f82009-06-10 13:36:04 -07004897
Dianne Hackbornc485a602009-03-24 22:39:49 -07004898 boolean computeNewConfigurationLocked(Configuration config) {
4899 if (mDisplay == null) {
4900 return false;
4901 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004902
4903 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07004904
4905 // Use the effective "visual" dimensions based on current rotation
4906 final boolean rotated = (mRotation == Surface.ROTATION_90
4907 || mRotation == Surface.ROTATION_270);
4908 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
4909 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
4910
Dianne Hackbornc485a602009-03-24 22:39:49 -07004911 int orientation = Configuration.ORIENTATION_SQUARE;
4912 if (dw < dh) {
4913 orientation = Configuration.ORIENTATION_PORTRAIT;
4914 } else if (dw > dh) {
4915 orientation = Configuration.ORIENTATION_LANDSCAPE;
4916 }
4917 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004918
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004919 DisplayMetrics dm = new DisplayMetrics();
4920 mDisplay.getMetrics(dm);
4921 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4922
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004923 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004924 // Note we only do this once because at this point we don't
4925 // expect the screen to change in this way at runtime, and want
4926 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004927 int longSize = dw;
4928 int shortSize = dh;
4929 if (longSize < shortSize) {
4930 int tmp = longSize;
4931 longSize = shortSize;
4932 shortSize = tmp;
4933 }
4934 longSize = (int)(longSize/dm.density);
4935 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004936
Dianne Hackborn723738c2009-06-25 19:48:04 -07004937 // These semi-magic numbers define our compatibility modes for
4938 // applications with different screens. Don't change unless you
4939 // make sure to test lots and lots of apps!
4940 if (longSize < 470) {
4941 // This is shorter than an HVGA normal density screen (which
4942 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004943 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
4944 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07004945 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07004946 // What size is this screen screen?
4947 if (longSize >= 800 && shortSize >= 600) {
4948 // SVGA or larger screens at medium density are the point
4949 // at which we consider it to be an extra large screen.
4950 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
4951 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004952 // VGA or larger screens at medium density are the point
4953 // at which we consider it to be a large screen.
4954 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
4955 } else {
4956 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004957
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004958 // If this screen is wider than normal HVGA, or taller
4959 // than FWVGA, then for old apps we want to run in size
4960 // compatibility mode.
4961 if (shortSize > 321 || longSize > 570) {
4962 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
4963 }
4964 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004965
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004966 // Is this a long screen?
4967 if (((longSize*3)/5) >= (shortSize-1)) {
4968 // Anything wider than WVGA (5:3) is considering to be long.
4969 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
4970 } else {
4971 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
4972 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07004973 }
4974 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004975 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004976
Dianne Hackbornc485a602009-03-24 22:39:49 -07004977 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
4978 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
4979 mPolicy.adjustConfigurationLw(config);
4980 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004981 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07004982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004983 // -------------------------------------------------------------
4984 // Input Events and Focus Management
4985 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07004986
Jeff Brown349703e2010-06-22 01:27:15 -07004987 InputMonitor mInputMonitor = new InputMonitor();
4988
4989 /* Tracks the progress of input dispatch and ensures that input dispatch state
4990 * is kept in sync with changes in window focus, visibility, registration, and
4991 * other relevant Window Manager state transitions. */
4992 final class InputMonitor {
4993 // Current window with input focus for keys and other non-touch events. May be null.
4994 private WindowState mInputFocus;
4995
4996 // When true, prevents input dispatch from proceeding until set to false again.
4997 private boolean mInputDispatchFrozen;
4998
4999 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5000 private boolean mInputDispatchEnabled = true;
5001
5002 // Temporary list of windows information to provide to the input dispatcher.
5003 private InputWindowList mTempInputWindows = new InputWindowList();
5004
5005 // Temporary input application object to provide to the input dispatcher.
5006 private InputApplication mTempInputApplication = new InputApplication();
5007
5008 /* Notifies the window manager about a broken input channel.
5009 *
5010 * Called by the InputManager.
5011 */
5012 public void notifyInputChannelBroken(InputChannel inputChannel) {
5013 synchronized (mWindowMap) {
5014 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5015 if (windowState == null) {
5016 return; // irrelevant
5017 }
5018
5019 Slog.i(TAG, "WINDOW DIED " + windowState);
5020 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005021 }
5022 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005023
Jeff Brown349703e2010-06-22 01:27:15 -07005024 /* Notifies the window manager about an input channel that is not responding.
5025 * The method can either cause dispatching to be aborted by returning -2 or
5026 * return a new timeout in nanoseconds.
5027 *
5028 * Called by the InputManager.
5029 */
5030 public long notifyInputChannelANR(InputChannel inputChannel) {
5031 AppWindowToken token;
5032 synchronized (mWindowMap) {
5033 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5034 if (windowState == null) {
5035 return -2; // irrelevant, abort dispatching (-2)
5036 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005037
Jeff Brown349703e2010-06-22 01:27:15 -07005038 Slog.i(TAG, "Input event dispatching timed out sending to "
5039 + windowState.mAttrs.getTitle());
5040 token = windowState.mAppToken;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005041 }
5042
Jeff Brown349703e2010-06-22 01:27:15 -07005043 return notifyANRInternal(token);
5044 }
5045
5046 /* Notifies the window manager about an input channel spontaneously recovering from ANR
5047 * by successfully delivering the event that originally timed out.
5048 *
5049 * Called by the InputManager.
5050 */
5051 public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) {
5052 // Nothing to do just now.
5053 // Just wait for the user to dismiss the ANR dialog.
5054 }
5055
5056 /* Notifies the window manager about an application that is not responding
5057 * in general rather than with respect to a particular input channel.
5058 * The method can either cause dispatching to be aborted by returning -2 or
5059 * return a new timeout in nanoseconds.
5060 *
5061 * Called by the InputManager.
5062 */
5063 public long notifyANR(Object token) {
5064 AppWindowToken appWindowToken = (AppWindowToken) token;
5065
5066 Slog.i(TAG, "Input event dispatching timed out sending to application "
5067 + appWindowToken.stringName);
5068 return notifyANRInternal(appWindowToken);
5069 }
5070
5071 private long notifyANRInternal(AppWindowToken token) {
5072 if (token != null && token.appToken != null) {
5073 try {
5074 // Notify the activity manager about the timeout and let it decide whether
5075 // to abort dispatching or keep waiting.
5076 boolean abort = token.appToken.keyDispatchingTimedOut();
5077 if (! abort) {
5078 // The activity manager declined to abort dispatching.
5079 // Wait a bit longer and timeout again later.
5080 return token.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005081 }
Jeff Brown349703e2010-06-22 01:27:15 -07005082 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005083 }
5084 }
Jeff Brown349703e2010-06-22 01:27:15 -07005085 return -2; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005086 }
5087
Jeff Brown349703e2010-06-22 01:27:15 -07005088 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5089 synchronized (mWindowMap) {
5090 return getWindowStateForInputChannelLocked(inputChannel);
5091 }
5092 }
5093
5094 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5095 int windowCount = mWindows.size();
5096 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005097 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005098 if (windowState.mInputChannel == inputChannel) {
5099 return windowState;
5100 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005101 }
5102
Jeff Brown349703e2010-06-22 01:27:15 -07005103 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005104 }
5105
Jeff Brown349703e2010-06-22 01:27:15 -07005106 /* Updates the cached window information provided to the input dispatcher. */
5107 public void updateInputWindowsLw() {
5108 // Populate the input window list with information about all of the windows that
5109 // could potentially receive input.
5110 // As an optimization, we could try to prune the list of windows but this turns
5111 // out to be difficult because only the native code knows for sure which window
5112 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005113 final ArrayList<WindowState> windows = mWindows;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005114 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005115 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005116 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005117 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005118 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005119 continue;
5120 }
5121
Jeff Brown349703e2010-06-22 01:27:15 -07005122 final int flags = child.mAttrs.flags;
5123 final int type = child.mAttrs.type;
5124
5125 final boolean hasFocus = (child == mInputFocus);
5126 final boolean isVisible = child.isVisibleLw();
5127 final boolean hasWallpaper = (child == mWallpaperTarget)
5128 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
5129
5130 // Add a window to our list of input windows.
5131 final InputWindow inputWindow = mTempInputWindows.add();
5132 inputWindow.inputChannel = child.mInputChannel;
5133 inputWindow.layoutParamsFlags = flags;
5134 inputWindow.layoutParamsType = type;
5135 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5136 inputWindow.visible = isVisible;
5137 inputWindow.hasFocus = hasFocus;
5138 inputWindow.hasWallpaper = hasWallpaper;
5139 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
5140 inputWindow.ownerPid = child.mSession.mPid;
5141 inputWindow.ownerUid = child.mSession.mUid;
5142
5143 final Rect frame = child.mFrame;
5144 inputWindow.frameLeft = frame.left;
5145 inputWindow.frameTop = frame.top;
5146
5147 switch (child.mTouchableInsets) {
5148 default:
5149 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5150 inputWindow.touchableAreaLeft = frame.left;
5151 inputWindow.touchableAreaTop = frame.top;
5152 inputWindow.touchableAreaRight = frame.right;
5153 inputWindow.touchableAreaBottom = frame.bottom;
5154 break;
5155
5156 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5157 Rect inset = child.mGivenContentInsets;
5158 inputWindow.touchableAreaLeft = frame.left + inset.left;
5159 inputWindow.touchableAreaTop = frame.top + inset.top;
5160 inputWindow.touchableAreaRight = frame.right - inset.right;
5161 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5162 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005163 }
Jeff Brown349703e2010-06-22 01:27:15 -07005164
5165 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5166 Rect inset = child.mGivenVisibleInsets;
5167 inputWindow.touchableAreaLeft = frame.left + inset.left;
5168 inputWindow.touchableAreaTop = frame.top + inset.top;
5169 inputWindow.touchableAreaRight = frame.right - inset.right;
5170 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005171 break;
5172 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005173 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005174 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005175
Jeff Brown349703e2010-06-22 01:27:15 -07005176 // Send windows to native code.
5177 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005178
Jeff Brown349703e2010-06-22 01:27:15 -07005179 // Clear the list in preparation for the next round.
5180 // Also avoids keeping InputChannel objects referenced unnecessarily.
5181 mTempInputWindows.clear();
5182 }
5183
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005184 /* Provides feedback for a virtual key down. */
5185 public void virtualKeyDownFeedback() {
5186 synchronized (mWindowMap) {
5187 mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5188 }
5189 }
5190
Jeff Brown349703e2010-06-22 01:27:15 -07005191 /* Notifies that an app switch key (BACK / HOME) has just been pressed.
5192 * This essentially starts a .5 second timeout for the application to process
5193 * subsequent input events while waiting for the app switch to occur. If it takes longer
5194 * than this, the pending events will be dropped.
5195 */
5196 public void notifyAppSwitchComing() {
5197 // TODO Not implemented yet. Should go in the native side.
5198 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005199
5200 /* Notifies that the lid switch changed state. */
5201 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5202 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5203 }
5204
Jeff Brown349703e2010-06-22 01:27:15 -07005205 /* Provides an opportunity for the window manager policy to intercept early key
5206 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005207 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5208 int policyFlags, boolean isScreenOn) {
5209 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5210 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005211 }
5212
5213 /* Provides an opportunity for the window manager policy to process a key before
5214 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005215 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5216 int action, int flags, int keyCode, int metaState, int repeatCount,
5217 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005218 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005219 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5220 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005221 }
5222
5223 /* Called when the current input focus changes.
5224 * Layer assignment is assumed to be complete by the time this is called.
5225 */
5226 public void setInputFocusLw(WindowState newWindow) {
5227 if (DEBUG_INPUT) {
5228 Slog.d(TAG, "Input focus has changed to " + newWindow);
5229 }
5230
5231 if (newWindow != mInputFocus) {
5232 if (newWindow != null && newWindow.canReceiveKeys()) {
5233 // If the new input focus is an error window or appears above the current
5234 // input focus, preempt any pending synchronous dispatch so that we can
5235 // start delivering events to the new input focus as soon as possible.
5236 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
5237 if (DEBUG_INPUT) {
5238 Slog.v(TAG, "New SYSTEM_ERROR window; resetting state");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005239 }
Jeff Brown349703e2010-06-22 01:27:15 -07005240 preemptInputDispatchLw();
5241 } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) {
5242 if (DEBUG_INPUT) {
5243 Slog.v(TAG, "Transferring focus to new window at higher layer: "
5244 + "old win layer=" + mInputFocus.mLayer
5245 + ", new win layer=" + newWindow.mLayer);
5246 }
5247 preemptInputDispatchLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005248 }
Jeff Brown349703e2010-06-22 01:27:15 -07005249
5250 // Displaying a window implicitly causes dispatching to be unpaused.
5251 // This is to protect against bugs if someone pauses dispatching but
5252 // forgets to resume.
5253 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005254 }
Jeff Brown349703e2010-06-22 01:27:15 -07005255
5256 mInputFocus = newWindow;
5257 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005258 }
5259 }
5260
Jeff Brown349703e2010-06-22 01:27:15 -07005261 /* Tells the dispatcher to stop waiting for its current synchronous event targets.
5262 * Essentially, just makes those dispatches asynchronous so a new dispatch cycle
5263 * can begin.
5264 */
5265 private void preemptInputDispatchLw() {
5266 mInputManager.preemptInputDispatch();
5267 }
5268
5269 public void setFocusedAppLw(AppWindowToken newApp) {
5270 // Focused app has changed.
5271 if (newApp == null) {
5272 mInputManager.setFocusedApplication(null);
5273 } else {
5274 mTempInputApplication.name = newApp.toString();
5275 mTempInputApplication.dispatchingTimeoutNanos =
5276 newApp.inputDispatchingTimeoutNanos;
5277 mTempInputApplication.token = newApp;
5278
5279 mInputManager.setFocusedApplication(mTempInputApplication);
5280 }
5281 }
5282
Jeff Brown349703e2010-06-22 01:27:15 -07005283 public void pauseDispatchingLw(WindowToken window) {
5284 if (! window.paused) {
5285 if (DEBUG_INPUT) {
5286 Slog.v(TAG, "Pausing WindowToken " + window);
5287 }
5288
5289 window.paused = true;
5290 updateInputWindowsLw();
5291 }
5292 }
5293
5294 public void resumeDispatchingLw(WindowToken window) {
5295 if (window.paused) {
5296 if (DEBUG_INPUT) {
5297 Slog.v(TAG, "Resuming WindowToken " + window);
5298 }
5299
5300 window.paused = false;
5301 updateInputWindowsLw();
5302 }
5303 }
5304
5305 public void freezeInputDispatchingLw() {
5306 if (! mInputDispatchFrozen) {
5307 if (DEBUG_INPUT) {
5308 Slog.v(TAG, "Freezing input dispatching");
5309 }
5310
5311 mInputDispatchFrozen = true;
5312 updateInputDispatchModeLw();
5313 }
5314 }
5315
5316 public void thawInputDispatchingLw() {
5317 if (mInputDispatchFrozen) {
5318 if (DEBUG_INPUT) {
5319 Slog.v(TAG, "Thawing input dispatching");
5320 }
5321
5322 mInputDispatchFrozen = false;
5323 updateInputDispatchModeLw();
5324 }
5325 }
5326
5327 public void setEventDispatchingLw(boolean enabled) {
5328 if (mInputDispatchEnabled != enabled) {
5329 if (DEBUG_INPUT) {
5330 Slog.v(TAG, "Setting event dispatching to " + enabled);
5331 }
5332
5333 mInputDispatchEnabled = enabled;
5334 updateInputDispatchModeLw();
5335 }
5336 }
5337
5338 private void updateInputDispatchModeLw() {
5339 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5340 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005341 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005343 public void pauseKeyDispatching(IBinder _token) {
5344 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5345 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005346 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005347 }
5348
5349 synchronized (mWindowMap) {
5350 WindowToken token = mTokenMap.get(_token);
5351 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005352 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005353 }
5354 }
5355 }
5356
5357 public void resumeKeyDispatching(IBinder _token) {
5358 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5359 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005360 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005361 }
5362
5363 synchronized (mWindowMap) {
5364 WindowToken token = mTokenMap.get(_token);
5365 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005366 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005367 }
5368 }
5369 }
5370
5371 public void setEventDispatching(boolean enabled) {
5372 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5373 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005374 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005375 }
5376
5377 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005378 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005379 }
5380 }
Romain Guy06882f82009-06-10 13:36:04 -07005381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005382 /**
5383 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005384 * Even when sync is false, this method may block while waiting for current
5385 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005386 *
5387 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005388 * {@link SystemClock#uptimeMillis()} as the timebase.)
5389 * @param sync If true, wait for the event to be completed before returning to the caller.
5390 * @return Returns true if event was dispatched, false if it was dropped for any reason
5391 */
5392 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5393 long downTime = ev.getDownTime();
5394 long eventTime = ev.getEventTime();
5395
5396 int action = ev.getAction();
5397 int code = ev.getKeyCode();
5398 int repeatCount = ev.getRepeatCount();
5399 int metaState = ev.getMetaState();
5400 int deviceId = ev.getDeviceId();
5401 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005402 int source = ev.getSource();
5403
5404 if (source == InputDevice.SOURCE_UNKNOWN) {
5405 source = InputDevice.SOURCE_KEYBOARD;
5406 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005407
5408 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5409 if (downTime == 0) downTime = eventTime;
5410
5411 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005412 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005413
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005414 final int pid = Binder.getCallingPid();
5415 final int uid = Binder.getCallingUid();
5416 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005417
Jeff Brownbbda99d2010-07-28 15:48:59 -07005418 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5419 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5420 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5421 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005422
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005423 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005424 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005425 }
5426
5427 /**
5428 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005429 * Even when sync is false, this method may block while waiting for current
5430 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005431 *
5432 * @param ev A motion event describing the pointer (touch) action. (As noted in
5433 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005434 * {@link SystemClock#uptimeMillis()} as the timebase.)
5435 * @param sync If true, wait for the event to be completed before returning to the caller.
5436 * @return Returns true if event was dispatched, false if it was dropped for any reason
5437 */
5438 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005439 final int pid = Binder.getCallingPid();
5440 final int uid = Binder.getCallingUid();
5441 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005442
Jeff Brownc5ed5912010-07-14 18:48:53 -07005443 MotionEvent newEvent = MotionEvent.obtain(ev);
5444 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5445 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5446 }
5447
Jeff Brownbbda99d2010-07-28 15:48:59 -07005448 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5449 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5450 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5451 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005452
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005453 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005454 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005455 }
Romain Guy06882f82009-06-10 13:36:04 -07005456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005457 /**
5458 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005459 * Even when sync is false, this method may block while waiting for current
5460 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005461 *
5462 * @param ev A motion event describing the trackball action. (As noted in
5463 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005464 * {@link SystemClock#uptimeMillis()} as the timebase.)
5465 * @param sync If true, wait for the event to be completed before returning to the caller.
5466 * @return Returns true if event was dispatched, false if it was dropped for any reason
5467 */
5468 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005469 final int pid = Binder.getCallingPid();
5470 final int uid = Binder.getCallingUid();
5471 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005472
Jeff Brownc5ed5912010-07-14 18:48:53 -07005473 MotionEvent newEvent = MotionEvent.obtain(ev);
5474 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5475 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5476 }
5477
Jeff Brownbbda99d2010-07-28 15:48:59 -07005478 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5479 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5480 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5481 INJECTION_TIMEOUT_MILLIS);
5482
5483 Binder.restoreCallingIdentity(ident);
5484 return reportInjectionResult(result);
5485 }
5486
5487 /**
5488 * Inject an input event into the UI without waiting for dispatch to commence.
5489 * This variant is useful for fire-and-forget input event injection. It does not
5490 * block any longer than it takes to enqueue the input event.
5491 *
5492 * @param ev An input event. (Be sure to set the input source correctly.)
5493 * @return Returns true if event was dispatched, false if it was dropped for any reason
5494 */
5495 public boolean injectInputEventNoWait(InputEvent ev) {
5496 final int pid = Binder.getCallingPid();
5497 final int uid = Binder.getCallingUid();
5498 final long ident = Binder.clearCallingIdentity();
5499
5500 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5501 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5502 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005503
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005504 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005505 return reportInjectionResult(result);
5506 }
5507
5508 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005509 switch (result) {
5510 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5511 Slog.w(TAG, "Input event injection permission denied.");
5512 throw new SecurityException(
5513 "Injecting to another application requires INJECT_EVENTS permission");
5514 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
5515 Slog.v(TAG, "Input event injection succeeded.");
5516 return true;
5517 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5518 Slog.w(TAG, "Input event injection timed out.");
5519 return false;
5520 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5521 default:
5522 Slog.w(TAG, "Input event injection failed.");
5523 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005524 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005525 }
Romain Guy06882f82009-06-10 13:36:04 -07005526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005527 private WindowState getFocusedWindow() {
5528 synchronized (mWindowMap) {
5529 return getFocusedWindowLocked();
5530 }
5531 }
5532
5533 private WindowState getFocusedWindowLocked() {
5534 return mCurrentFocus;
5535 }
Romain Guy06882f82009-06-10 13:36:04 -07005536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005537 public boolean detectSafeMode() {
5538 mSafeMode = mPolicy.detectSafeMode();
5539 return mSafeMode;
5540 }
Romain Guy06882f82009-06-10 13:36:04 -07005541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005542 public void systemReady() {
5543 mPolicy.systemReady();
5544 }
Romain Guy06882f82009-06-10 13:36:04 -07005545
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005546 // -------------------------------------------------------------
5547 // Client Session State
5548 // -------------------------------------------------------------
5549
5550 private final class Session extends IWindowSession.Stub
5551 implements IBinder.DeathRecipient {
5552 final IInputMethodClient mClient;
5553 final IInputContext mInputContext;
5554 final int mUid;
5555 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005556 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005557 SurfaceSession mSurfaceSession;
5558 int mNumWindow = 0;
5559 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07005560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005561 public Session(IInputMethodClient client, IInputContext inputContext) {
5562 mClient = client;
5563 mInputContext = inputContext;
5564 mUid = Binder.getCallingUid();
5565 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005566 StringBuilder sb = new StringBuilder();
5567 sb.append("Session{");
5568 sb.append(Integer.toHexString(System.identityHashCode(this)));
5569 sb.append(" uid ");
5570 sb.append(mUid);
5571 sb.append("}");
5572 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07005573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005574 synchronized (mWindowMap) {
5575 if (mInputMethodManager == null && mHaveInputMethods) {
5576 IBinder b = ServiceManager.getService(
5577 Context.INPUT_METHOD_SERVICE);
5578 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
5579 }
5580 }
5581 long ident = Binder.clearCallingIdentity();
5582 try {
5583 // Note: it is safe to call in to the input method manager
5584 // here because we are not holding our lock.
5585 if (mInputMethodManager != null) {
5586 mInputMethodManager.addClient(client, inputContext,
5587 mUid, mPid);
5588 } else {
5589 client.setUsingInputMethod(false);
5590 }
5591 client.asBinder().linkToDeath(this, 0);
5592 } catch (RemoteException e) {
5593 // The caller has died, so we can just forget about this.
5594 try {
5595 if (mInputMethodManager != null) {
5596 mInputMethodManager.removeClient(client);
5597 }
5598 } catch (RemoteException ee) {
5599 }
5600 } finally {
5601 Binder.restoreCallingIdentity(ident);
5602 }
5603 }
Romain Guy06882f82009-06-10 13:36:04 -07005604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005605 @Override
5606 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
5607 throws RemoteException {
5608 try {
5609 return super.onTransact(code, data, reply, flags);
5610 } catch (RuntimeException e) {
5611 // Log all 'real' exceptions thrown to the caller
5612 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005613 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005614 }
5615 throw e;
5616 }
5617 }
5618
5619 public void binderDied() {
5620 // Note: it is safe to call in to the input method manager
5621 // here because we are not holding our lock.
5622 try {
5623 if (mInputMethodManager != null) {
5624 mInputMethodManager.removeClient(mClient);
5625 }
5626 } catch (RemoteException e) {
5627 }
5628 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005629 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005630 mClientDead = true;
5631 killSessionLocked();
5632 }
5633 }
5634
5635 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005636 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
5637 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
5638 outInputChannel);
5639 }
5640
5641 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005642 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005643 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005644 }
Romain Guy06882f82009-06-10 13:36:04 -07005645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005646 public void remove(IWindow window) {
5647 removeWindow(this, window);
5648 }
Romain Guy06882f82009-06-10 13:36:04 -07005649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005650 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
5651 int requestedWidth, int requestedHeight, int viewFlags,
5652 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005653 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005654 return relayoutWindow(this, window, attrs,
5655 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005656 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005657 }
Romain Guy06882f82009-06-10 13:36:04 -07005658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005659 public void setTransparentRegion(IWindow window, Region region) {
5660 setTransparentRegionWindow(this, window, region);
5661 }
Romain Guy06882f82009-06-10 13:36:04 -07005662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005663 public void setInsets(IWindow window, int touchableInsets,
5664 Rect contentInsets, Rect visibleInsets) {
5665 setInsetsWindow(this, window, touchableInsets, contentInsets,
5666 visibleInsets);
5667 }
Romain Guy06882f82009-06-10 13:36:04 -07005668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005669 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
5670 getWindowDisplayFrame(this, window, outDisplayFrame);
5671 }
Romain Guy06882f82009-06-10 13:36:04 -07005672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005673 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005674 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005675 TAG, "IWindow finishDrawing called for " + window);
5676 finishDrawingWindow(this, window);
5677 }
5678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005679 public void setInTouchMode(boolean mode) {
5680 synchronized(mWindowMap) {
5681 mInTouchMode = mode;
5682 }
5683 }
5684
5685 public boolean getInTouchMode() {
5686 synchronized(mWindowMap) {
5687 return mInTouchMode;
5688 }
5689 }
5690
5691 public boolean performHapticFeedback(IWindow window, int effectId,
5692 boolean always) {
5693 synchronized(mWindowMap) {
5694 long ident = Binder.clearCallingIdentity();
5695 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005696 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005697 windowForClientLocked(this, window, true),
5698 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005699 } finally {
5700 Binder.restoreCallingIdentity(ident);
5701 }
5702 }
5703 }
Romain Guy06882f82009-06-10 13:36:04 -07005704
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005705 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005706 synchronized(mWindowMap) {
5707 long ident = Binder.clearCallingIdentity();
5708 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005709 setWindowWallpaperPositionLocked(
5710 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005711 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005712 } finally {
5713 Binder.restoreCallingIdentity(ident);
5714 }
5715 }
5716 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005717
Dianne Hackborn19382ac2009-09-11 21:13:37 -07005718 public void wallpaperOffsetsComplete(IBinder window) {
5719 WindowManagerService.this.wallpaperOffsetsComplete(window);
5720 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005721
Dianne Hackborn75804932009-10-20 20:15:20 -07005722 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
5723 int z, Bundle extras, boolean sync) {
5724 synchronized(mWindowMap) {
5725 long ident = Binder.clearCallingIdentity();
5726 try {
5727 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005728 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07005729 action, x, y, z, extras, sync);
5730 } finally {
5731 Binder.restoreCallingIdentity(ident);
5732 }
5733 }
5734 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005735
Dianne Hackborn75804932009-10-20 20:15:20 -07005736 public void wallpaperCommandComplete(IBinder window, Bundle result) {
5737 WindowManagerService.this.wallpaperCommandComplete(window, result);
5738 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005740 void windowAddedLocked() {
5741 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005742 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005743 TAG, "First window added to " + this + ", creating SurfaceSession");
5744 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005745 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005746 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005747 mSessions.add(this);
5748 }
5749 mNumWindow++;
5750 }
5751
5752 void windowRemovedLocked() {
5753 mNumWindow--;
5754 killSessionLocked();
5755 }
Romain Guy06882f82009-06-10 13:36:04 -07005756
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005757 void killSessionLocked() {
5758 if (mNumWindow <= 0 && mClientDead) {
5759 mSessions.remove(this);
5760 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005761 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005762 TAG, "Last window removed from " + this
5763 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005764 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005765 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005766 try {
5767 mSurfaceSession.kill();
5768 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005769 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005770 + mSurfaceSession + " in session " + this
5771 + ": " + e.toString());
5772 }
5773 mSurfaceSession = null;
5774 }
5775 }
5776 }
Romain Guy06882f82009-06-10 13:36:04 -07005777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005778 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005779 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
5780 pw.print(" mClientDead="); pw.print(mClientDead);
5781 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005782 }
5783
5784 @Override
5785 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005786 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005787 }
5788 }
5789
5790 // -------------------------------------------------------------
5791 // Client Window State
5792 // -------------------------------------------------------------
5793
5794 private final class WindowState implements WindowManagerPolicy.WindowState {
5795 final Session mSession;
5796 final IWindow mClient;
5797 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07005798 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005799 AppWindowToken mAppToken;
5800 AppWindowToken mTargetAppToken;
5801 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
5802 final DeathRecipient mDeathRecipient;
5803 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07005804 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005805 final int mBaseLayer;
5806 final int mSubLayer;
5807 final boolean mLayoutAttached;
5808 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005809 final boolean mIsWallpaper;
5810 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005811 int mViewVisibility;
5812 boolean mPolicyVisibility = true;
5813 boolean mPolicyVisibilityAfterAnim = true;
5814 boolean mAppFreezing;
5815 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07005816 boolean mReportDestroySurface;
5817 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005818 boolean mAttachedHidden; // is our parent window hidden?
5819 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07005820 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005821 int mRequestedWidth;
5822 int mRequestedHeight;
5823 int mLastRequestedWidth;
5824 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005825 int mLayer;
5826 int mAnimLayer;
5827 int mLastLayer;
5828 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07005829 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07005830 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005831
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005832 int mLayoutSeq = -1;
5833
5834 Configuration mConfiguration = null;
5835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005836 // Actual frame shown on-screen (may be modified by animation)
5837 final Rect mShownFrame = new Rect();
5838 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005840 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08005841 * Set when we have changed the size of the surface, to know that
5842 * we must tell them application to resize (and thus redraw itself).
5843 */
5844 boolean mSurfaceResized;
5845
5846 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005847 * Insets that determine the actually visible area
5848 */
5849 final Rect mVisibleInsets = new Rect();
5850 final Rect mLastVisibleInsets = new Rect();
5851 boolean mVisibleInsetsChanged;
5852
5853 /**
5854 * Insets that are covered by system windows
5855 */
5856 final Rect mContentInsets = new Rect();
5857 final Rect mLastContentInsets = new Rect();
5858 boolean mContentInsetsChanged;
5859
5860 /**
5861 * Set to true if we are waiting for this window to receive its
5862 * given internal insets before laying out other windows based on it.
5863 */
5864 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07005865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005866 /**
5867 * These are the content insets that were given during layout for
5868 * this window, to be applied to windows behind it.
5869 */
5870 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005872 /**
5873 * These are the visible insets that were given during layout for
5874 * this window, to be applied to windows behind it.
5875 */
5876 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005878 /**
5879 * Flag indicating whether the touchable region should be adjusted by
5880 * the visible insets; if false the area outside the visible insets is
5881 * NOT touchable, so we must use those to adjust the frame during hit
5882 * tests.
5883 */
5884 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07005885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005886 // Current transformation being applied.
5887 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
5888 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
5889 float mHScale=1, mVScale=1;
5890 float mLastHScale=1, mLastVScale=1;
5891 final Matrix mTmpMatrix = new Matrix();
5892
5893 // "Real" frame that the application sees.
5894 final Rect mFrame = new Rect();
5895 final Rect mLastFrame = new Rect();
5896
5897 final Rect mContainingFrame = new Rect();
5898 final Rect mDisplayFrame = new Rect();
5899 final Rect mContentFrame = new Rect();
5900 final Rect mVisibleFrame = new Rect();
5901
5902 float mShownAlpha = 1;
5903 float mAlpha = 1;
5904 float mLastAlpha = 1;
5905
5906 // Set to true if, when the window gets displayed, it should perform
5907 // an enter animation.
5908 boolean mEnterAnimationPending;
5909
5910 // Currently running animation.
5911 boolean mAnimating;
5912 boolean mLocalAnimating;
5913 Animation mAnimation;
5914 boolean mAnimationIsEntrance;
5915 boolean mHasTransformation;
5916 boolean mHasLocalTransformation;
5917 final Transformation mTransformation = new Transformation();
5918
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005919 // If a window showing a wallpaper: the requested offset for the
5920 // wallpaper; if a wallpaper window: the currently applied offset.
5921 float mWallpaperX = -1;
5922 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005923
5924 // If a window showing a wallpaper: what fraction of the offset
5925 // range corresponds to a full virtual screen.
5926 float mWallpaperXStep = -1;
5927 float mWallpaperYStep = -1;
5928
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005929 // Wallpaper windows: pixels offset based on above variables.
5930 int mXOffset;
5931 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005933 // This is set after IWindowSession.relayout() has been called at
5934 // least once for the window. It allows us to detect the situation
5935 // where we don't yet have a surface, but should have one soon, so
5936 // we can give the window focus before waiting for the relayout.
5937 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07005938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005939 // This is set after the Surface has been created but before the
5940 // window has been drawn. During this time the surface is hidden.
5941 boolean mDrawPending;
5942
5943 // This is set after the window has finished drawing for the first
5944 // time but before its surface is shown. The surface will be
5945 // displayed when the next layout is run.
5946 boolean mCommitDrawPending;
5947
5948 // This is set during the time after the window's drawing has been
5949 // committed, and before its surface is actually shown. It is used
5950 // to delay showing the surface until all windows in a token are ready
5951 // to be shown.
5952 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07005953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005954 // Set when the window has been shown in the screen the first time.
5955 boolean mHasDrawn;
5956
5957 // Currently running an exit animation?
5958 boolean mExiting;
5959
5960 // Currently on the mDestroySurface list?
5961 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07005962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005963 // Completely remove from window manager after exit animation?
5964 boolean mRemoveOnExit;
5965
5966 // Set when the orientation is changing and this window has not yet
5967 // been updated for the new orientation.
5968 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07005969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005970 // Is this window now (or just being) removed?
5971 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07005972
Dianne Hackborn16064f92010-03-25 00:47:24 -07005973 // For debugging, this is the last information given to the surface flinger.
5974 boolean mSurfaceShown;
5975 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
5976 int mSurfaceLayer;
5977 float mSurfaceAlpha;
5978
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005979 // Input channel
5980 InputChannel mInputChannel;
5981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005982 WindowState(Session s, IWindow c, WindowToken token,
5983 WindowState attachedWindow, WindowManager.LayoutParams a,
5984 int viewVisibility) {
5985 mSession = s;
5986 mClient = c;
5987 mToken = token;
5988 mAttrs.copyFrom(a);
5989 mViewVisibility = viewVisibility;
5990 DeathRecipient deathRecipient = new DeathRecipient();
5991 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005992 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005993 TAG, "Window " + this + " client=" + c.asBinder()
5994 + " token=" + token + " (" + mAttrs.token + ")");
5995 try {
5996 c.asBinder().linkToDeath(deathRecipient, 0);
5997 } catch (RemoteException e) {
5998 mDeathRecipient = null;
5999 mAttachedWindow = null;
6000 mLayoutAttached = false;
6001 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006002 mIsWallpaper = false;
6003 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006004 mBaseLayer = 0;
6005 mSubLayer = 0;
6006 return;
6007 }
6008 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006010 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6011 mAttrs.type <= LAST_SUB_WINDOW)) {
6012 // The multiplier here is to reserve space for multiple
6013 // windows in the same type layer.
6014 mBaseLayer = mPolicy.windowTypeToLayerLw(
6015 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6016 + TYPE_LAYER_OFFSET;
6017 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6018 mAttachedWindow = attachedWindow;
6019 mAttachedWindow.mChildWindows.add(this);
6020 mLayoutAttached = mAttrs.type !=
6021 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6022 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6023 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006024 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6025 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006026 } else {
6027 // The multiplier here is to reserve space for multiple
6028 // windows in the same type layer.
6029 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6030 * TYPE_LAYER_MULTIPLIER
6031 + TYPE_LAYER_OFFSET;
6032 mSubLayer = 0;
6033 mAttachedWindow = null;
6034 mLayoutAttached = false;
6035 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6036 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006037 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6038 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006039 }
6040
6041 WindowState appWin = this;
6042 while (appWin.mAttachedWindow != null) {
6043 appWin = mAttachedWindow;
6044 }
6045 WindowToken appToken = appWin.mToken;
6046 while (appToken.appWindowToken == null) {
6047 WindowToken parent = mTokenMap.get(appToken.token);
6048 if (parent == null || appToken == parent) {
6049 break;
6050 }
6051 appToken = parent;
6052 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006053 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006054 mAppToken = appToken.appWindowToken;
6055
6056 mSurface = null;
6057 mRequestedWidth = 0;
6058 mRequestedHeight = 0;
6059 mLastRequestedWidth = 0;
6060 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006061 mXOffset = 0;
6062 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006063 mLayer = 0;
6064 mAnimLayer = 0;
6065 mLastLayer = 0;
6066 }
6067
6068 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006069 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006070 TAG, "Attaching " + this + " token=" + mToken
6071 + ", list=" + mToken.windows);
6072 mSession.windowAddedLocked();
6073 }
6074
6075 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6076 mHaveFrame = true;
6077
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006078 final Rect container = mContainingFrame;
6079 container.set(pf);
6080
6081 final Rect display = mDisplayFrame;
6082 display.set(df);
6083
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006084 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006085 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006086 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6087 display.intersect(mCompatibleScreenFrame);
6088 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006089 }
6090
6091 final int pw = container.right - container.left;
6092 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006093
6094 int w,h;
6095 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6096 w = mAttrs.width < 0 ? pw : mAttrs.width;
6097 h = mAttrs.height< 0 ? ph : mAttrs.height;
6098 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006099 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6100 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006101 }
Romain Guy06882f82009-06-10 13:36:04 -07006102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006103 final Rect content = mContentFrame;
6104 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006106 final Rect visible = mVisibleFrame;
6107 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006109 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006110 final int fw = frame.width();
6111 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006113 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6114 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6115
6116 Gravity.apply(mAttrs.gravity, w, h, container,
6117 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6118 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6119
6120 //System.out.println("Out: " + mFrame);
6121
6122 // Now make sure the window fits in the overall display.
6123 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006125 // Make sure the content and visible frames are inside of the
6126 // final window frame.
6127 if (content.left < frame.left) content.left = frame.left;
6128 if (content.top < frame.top) content.top = frame.top;
6129 if (content.right > frame.right) content.right = frame.right;
6130 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6131 if (visible.left < frame.left) visible.left = frame.left;
6132 if (visible.top < frame.top) visible.top = frame.top;
6133 if (visible.right > frame.right) visible.right = frame.right;
6134 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006136 final Rect contentInsets = mContentInsets;
6137 contentInsets.left = content.left-frame.left;
6138 contentInsets.top = content.top-frame.top;
6139 contentInsets.right = frame.right-content.right;
6140 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006142 final Rect visibleInsets = mVisibleInsets;
6143 visibleInsets.left = visible.left-frame.left;
6144 visibleInsets.top = visible.top-frame.top;
6145 visibleInsets.right = frame.right-visible.right;
6146 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006147
Dianne Hackborn284ac932009-08-28 10:34:25 -07006148 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6149 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006150 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006151 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006153 if (localLOGV) {
6154 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6155 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006156 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006157 + mRequestedWidth + ", mRequestedheight="
6158 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6159 + "): frame=" + mFrame.toShortString()
6160 + " ci=" + contentInsets.toShortString()
6161 + " vi=" + visibleInsets.toShortString());
6162 //}
6163 }
6164 }
Romain Guy06882f82009-06-10 13:36:04 -07006165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006166 public Rect getFrameLw() {
6167 return mFrame;
6168 }
6169
6170 public Rect getShownFrameLw() {
6171 return mShownFrame;
6172 }
6173
6174 public Rect getDisplayFrameLw() {
6175 return mDisplayFrame;
6176 }
6177
6178 public Rect getContentFrameLw() {
6179 return mContentFrame;
6180 }
6181
6182 public Rect getVisibleFrameLw() {
6183 return mVisibleFrame;
6184 }
6185
6186 public boolean getGivenInsetsPendingLw() {
6187 return mGivenInsetsPending;
6188 }
6189
6190 public Rect getGivenContentInsetsLw() {
6191 return mGivenContentInsets;
6192 }
Romain Guy06882f82009-06-10 13:36:04 -07006193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006194 public Rect getGivenVisibleInsetsLw() {
6195 return mGivenVisibleInsets;
6196 }
Romain Guy06882f82009-06-10 13:36:04 -07006197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006198 public WindowManager.LayoutParams getAttrs() {
6199 return mAttrs;
6200 }
6201
6202 public int getSurfaceLayer() {
6203 return mLayer;
6204 }
Romain Guy06882f82009-06-10 13:36:04 -07006205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006206 public IApplicationToken getAppToken() {
6207 return mAppToken != null ? mAppToken.appToken : null;
6208 }
Jeff Brown349703e2010-06-22 01:27:15 -07006209
6210 public long getInputDispatchingTimeoutNanos() {
6211 return mAppToken != null
6212 ? mAppToken.inputDispatchingTimeoutNanos
6213 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6214 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006215
6216 public boolean hasAppShownWindows() {
6217 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6218 }
6219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006220 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006221 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006222 TAG, "Setting animation in " + this + ": " + anim);
6223 mAnimating = false;
6224 mLocalAnimating = false;
6225 mAnimation = anim;
6226 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6227 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6228 }
6229
6230 public void clearAnimation() {
6231 if (mAnimation != null) {
6232 mAnimating = true;
6233 mLocalAnimating = false;
6234 mAnimation = null;
6235 }
6236 }
Romain Guy06882f82009-06-10 13:36:04 -07006237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006238 Surface createSurfaceLocked() {
6239 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006240 mReportDestroySurface = false;
6241 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006242 mDrawPending = true;
6243 mCommitDrawPending = false;
6244 mReadyToShow = false;
6245 if (mAppToken != null) {
6246 mAppToken.allDrawn = false;
6247 }
6248
6249 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006250 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006251 flags |= Surface.PUSH_BUFFERS;
6252 }
6253
6254 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6255 flags |= Surface.SECURE;
6256 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006257 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006258 TAG, "Creating surface in session "
6259 + mSession.mSurfaceSession + " window " + this
6260 + " w=" + mFrame.width()
6261 + " h=" + mFrame.height() + " format="
6262 + mAttrs.format + " flags=" + flags);
6263
6264 int w = mFrame.width();
6265 int h = mFrame.height();
6266 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6267 // for a scaled surface, we always want the requested
6268 // size.
6269 w = mRequestedWidth;
6270 h = mRequestedHeight;
6271 }
6272
Romain Guy9825ec62009-10-01 00:58:09 -07006273 // Something is wrong and SurfaceFlinger will not like this,
6274 // try to revert to sane values
6275 if (w <= 0) w = 1;
6276 if (h <= 0) h = 1;
6277
Dianne Hackborn16064f92010-03-25 00:47:24 -07006278 mSurfaceShown = false;
6279 mSurfaceLayer = 0;
6280 mSurfaceAlpha = 1;
6281 mSurfaceX = 0;
6282 mSurfaceY = 0;
6283 mSurfaceW = w;
6284 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006285 try {
6286 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006287 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006288 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006289 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006290 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006291 + mSurface + " IN SESSION "
6292 + mSession.mSurfaceSession
6293 + ": pid=" + mSession.mPid + " format="
6294 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006295 + Integer.toHexString(flags)
6296 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006297 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006298 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006299 reclaimSomeSurfaceMemoryLocked(this, "create");
6300 return null;
6301 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006302 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006303 return null;
6304 }
Romain Guy06882f82009-06-10 13:36:04 -07006305
Joe Onorato8a9b2202010-02-26 18:56:32 -08006306 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006307 TAG, "Got surface: " + mSurface
6308 + ", set left=" + mFrame.left + " top=" + mFrame.top
6309 + ", animLayer=" + mAnimLayer);
6310 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006311 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006312 if (SHOW_TRANSACTIONS) logSurface(this,
6313 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6314 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6315 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006316 }
6317 Surface.openTransaction();
6318 try {
6319 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006320 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006321 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006322 mSurface.setPosition(mSurfaceX, mSurfaceY);
6323 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006324 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006325 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006326 mSurface.hide();
6327 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006328 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006329 mSurface.setFlags(Surface.SURFACE_DITHER,
6330 Surface.SURFACE_DITHER);
6331 }
6332 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006333 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006334 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6335 }
6336 mLastHidden = true;
6337 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006338 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006339 Surface.closeTransaction();
6340 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006341 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006342 TAG, "Created surface " + this);
6343 }
6344 return mSurface;
6345 }
Romain Guy06882f82009-06-10 13:36:04 -07006346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006347 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006348 if (mAppToken != null && this == mAppToken.startingWindow) {
6349 mAppToken.startingDisplayed = false;
6350 }
Romain Guy06882f82009-06-10 13:36:04 -07006351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006352 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006353 mDrawPending = false;
6354 mCommitDrawPending = false;
6355 mReadyToShow = false;
6356
6357 int i = mChildWindows.size();
6358 while (i > 0) {
6359 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006360 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006361 c.mAttachedHidden = true;
6362 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006363
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006364 if (mReportDestroySurface) {
6365 mReportDestroySurface = false;
6366 mSurfacePendingDestroy = true;
6367 try {
6368 mClient.dispatchGetNewSurface();
6369 // We'll really destroy on the next time around.
6370 return;
6371 } catch (RemoteException e) {
6372 }
6373 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006375 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006376 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006377 RuntimeException e = null;
6378 if (!HIDE_STACK_CRAWLS) {
6379 e = new RuntimeException();
6380 e.fillInStackTrace();
6381 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006382 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006383 + mSurface + ", session " + mSession, e);
6384 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006385 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006386 RuntimeException e = null;
6387 if (!HIDE_STACK_CRAWLS) {
6388 e = new RuntimeException();
6389 e.fillInStackTrace();
6390 }
6391 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006392 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006393 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006394 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006395 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006396 + " surface " + mSurface + " session " + mSession
6397 + ": " + e.toString());
6398 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006399
Dianne Hackborn16064f92010-03-25 00:47:24 -07006400 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006401 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006402 }
6403 }
6404
6405 boolean finishDrawingLocked() {
6406 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006407 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006408 TAG, "finishDrawingLocked: " + mSurface);
6409 mCommitDrawPending = true;
6410 mDrawPending = false;
6411 return true;
6412 }
6413 return false;
6414 }
6415
6416 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006417 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006418 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006419 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006420 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006421 }
6422 mCommitDrawPending = false;
6423 mReadyToShow = true;
6424 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6425 final AppWindowToken atoken = mAppToken;
6426 if (atoken == null || atoken.allDrawn || starting) {
6427 performShowLocked();
6428 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006429 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006430 }
6431
6432 // This must be called while inside a transaction.
6433 boolean performShowLocked() {
6434 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006435 RuntimeException e = null;
6436 if (!HIDE_STACK_CRAWLS) {
6437 e = new RuntimeException();
6438 e.fillInStackTrace();
6439 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006440 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006441 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6442 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6443 }
6444 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006445 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
6446 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006447 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006448 + " during animation: policyVis=" + mPolicyVisibility
6449 + " attHidden=" + mAttachedHidden
6450 + " tok.hiddenRequested="
6451 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07006452 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006453 + (mAppToken != null ? mAppToken.hidden : false)
6454 + " animating=" + mAnimating
6455 + " tok animating="
6456 + (mAppToken != null ? mAppToken.animating : false));
6457 if (!showSurfaceRobustlyLocked(this)) {
6458 return false;
6459 }
6460 mLastAlpha = -1;
6461 mHasDrawn = true;
6462 mLastHidden = false;
6463 mReadyToShow = false;
6464 enableScreenIfNeededLocked();
6465
6466 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07006467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006468 int i = mChildWindows.size();
6469 while (i > 0) {
6470 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006471 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006472 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006473 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006474 if (c.mSurface != null) {
6475 c.performShowLocked();
6476 // It hadn't been shown, which means layout not
6477 // performed on it, so now we want to make sure to
6478 // do a layout. If called from within the transaction
6479 // loop, this will cause it to restart with a new
6480 // layout.
6481 mLayoutNeeded = true;
6482 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006483 }
6484 }
Romain Guy06882f82009-06-10 13:36:04 -07006485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006486 if (mAttrs.type != TYPE_APPLICATION_STARTING
6487 && mAppToken != null) {
6488 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006489
Dianne Hackborn248b1882009-09-16 16:46:44 -07006490 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006491 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006492 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006493 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07006494 // If this initial window is animating, stop it -- we
6495 // will do an animation to reveal it from behind the
6496 // starting window, so there is no need for it to also
6497 // be doing its own stuff.
6498 if (mAnimation != null) {
6499 mAnimation = null;
6500 // Make sure we clean up the animation.
6501 mAnimating = true;
6502 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006503 mFinishedStarting.add(mAppToken);
6504 mH.sendEmptyMessage(H.FINISHED_STARTING);
6505 }
6506 mAppToken.updateReportedVisibilityLocked();
6507 }
6508 }
6509 return true;
6510 }
Romain Guy06882f82009-06-10 13:36:04 -07006511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006512 // This must be called while inside a transaction. Returns true if
6513 // there is more animation to run.
6514 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006515 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006516 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07006517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006518 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
6519 mHasTransformation = true;
6520 mHasLocalTransformation = true;
6521 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006522 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006523 TAG, "Starting animation in " + this +
6524 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
6525 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
6526 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
6527 mAnimation.setStartTime(currentTime);
6528 mLocalAnimating = true;
6529 mAnimating = true;
6530 }
6531 mTransformation.clear();
6532 final boolean more = mAnimation.getTransformation(
6533 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006534 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006535 TAG, "Stepped animation in " + this +
6536 ": more=" + more + ", xform=" + mTransformation);
6537 if (more) {
6538 // we're not done!
6539 return true;
6540 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006541 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006542 TAG, "Finished animation in " + this +
6543 " @ " + currentTime);
6544 mAnimation = null;
6545 //WindowManagerService.this.dump();
6546 }
6547 mHasLocalTransformation = false;
6548 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006549 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006550 // When our app token is animating, we kind-of pretend like
6551 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
6552 // part of this check means that we will only do this if
6553 // our window is not currently exiting, or it is not
6554 // locally animating itself. The idea being that one that
6555 // is exiting and doing a local animation should be removed
6556 // once that animation is done.
6557 mAnimating = true;
6558 mHasTransformation = true;
6559 mTransformation.clear();
6560 return false;
6561 } else if (mHasTransformation) {
6562 // Little trick to get through the path below to act like
6563 // we have finished an animation.
6564 mAnimating = true;
6565 } else if (isAnimating()) {
6566 mAnimating = true;
6567 }
6568 } else if (mAnimation != null) {
6569 // If the display is frozen, and there is a pending animation,
6570 // clear it and make sure we run the cleanup code.
6571 mAnimating = true;
6572 mLocalAnimating = true;
6573 mAnimation = null;
6574 }
Romain Guy06882f82009-06-10 13:36:04 -07006575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006576 if (!mAnimating && !mLocalAnimating) {
6577 return false;
6578 }
6579
Joe Onorato8a9b2202010-02-26 18:56:32 -08006580 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006581 TAG, "Animation done in " + this + ": exiting=" + mExiting
6582 + ", reportedVisible="
6583 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07006584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006585 mAnimating = false;
6586 mLocalAnimating = false;
6587 mAnimation = null;
6588 mAnimLayer = mLayer;
6589 if (mIsImWindow) {
6590 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006591 } else if (mIsWallpaper) {
6592 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006593 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006594 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006595 + " anim layer: " + mAnimLayer);
6596 mHasTransformation = false;
6597 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006598 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
6599 if (DEBUG_VISIBILITY) {
6600 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
6601 + mPolicyVisibilityAfterAnim);
6602 }
6603 mPolicyVisibility = mPolicyVisibilityAfterAnim;
6604 if (!mPolicyVisibility) {
6605 if (mCurrentFocus == this) {
6606 mFocusMayChange = true;
6607 }
6608 // Window is no longer visible -- make sure if we were waiting
6609 // for it to be displayed before enabling the display, that
6610 // we allow the display to be enabled now.
6611 enableScreenIfNeededLocked();
6612 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08006613 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006614 mTransformation.clear();
6615 if (mHasDrawn
6616 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
6617 && mAppToken != null
6618 && mAppToken.firstWindowDrawn
6619 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006620 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006621 + mToken + ": first real window done animating");
6622 mFinishedStarting.add(mAppToken);
6623 mH.sendEmptyMessage(H.FINISHED_STARTING);
6624 }
Romain Guy06882f82009-06-10 13:36:04 -07006625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006626 finishExit();
6627
6628 if (mAppToken != null) {
6629 mAppToken.updateReportedVisibilityLocked();
6630 }
6631
6632 return false;
6633 }
6634
6635 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006636 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006637 TAG, "finishExit in " + this
6638 + ": exiting=" + mExiting
6639 + " remove=" + mRemoveOnExit
6640 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07006641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006642 final int N = mChildWindows.size();
6643 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07006644 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006645 }
Romain Guy06882f82009-06-10 13:36:04 -07006646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006647 if (!mExiting) {
6648 return;
6649 }
Romain Guy06882f82009-06-10 13:36:04 -07006650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006651 if (isWindowAnimating()) {
6652 return;
6653 }
6654
Joe Onorato8a9b2202010-02-26 18:56:32 -08006655 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006656 TAG, "Exit animation finished in " + this
6657 + ": remove=" + mRemoveOnExit);
6658 if (mSurface != null) {
6659 mDestroySurface.add(this);
6660 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006661 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006662 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006663 try {
6664 mSurface.hide();
6665 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006666 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006667 }
6668 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006669 }
6670 mExiting = false;
6671 if (mRemoveOnExit) {
6672 mPendingRemove.add(this);
6673 mRemoveOnExit = false;
6674 }
6675 }
Romain Guy06882f82009-06-10 13:36:04 -07006676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006677 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
6678 if (dsdx < .99999f || dsdx > 1.00001f) return false;
6679 if (dtdy < .99999f || dtdy > 1.00001f) return false;
6680 if (dtdx < -.000001f || dtdx > .000001f) return false;
6681 if (dsdy < -.000001f || dsdy > .000001f) return false;
6682 return true;
6683 }
Romain Guy06882f82009-06-10 13:36:04 -07006684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006685 void computeShownFrameLocked() {
6686 final boolean selfTransformation = mHasLocalTransformation;
6687 Transformation attachedTransformation =
6688 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
6689 ? mAttachedWindow.mTransformation : null;
6690 Transformation appTransformation =
6691 (mAppToken != null && mAppToken.hasTransformation)
6692 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006693
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006694 // Wallpapers are animated based on the "real" window they
6695 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006696 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07006697 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07006698 if (mWallpaperTarget.mHasLocalTransformation &&
6699 mWallpaperTarget.mAnimation != null &&
6700 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006701 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006702 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006703 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006704 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006705 }
6706 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07006707 mWallpaperTarget.mAppToken.hasTransformation &&
6708 mWallpaperTarget.mAppToken.animation != null &&
6709 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006710 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006711 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006712 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006713 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006714 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006715 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006717 if (selfTransformation || attachedTransformation != null
6718 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07006719 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006720 final Rect frame = mFrame;
6721 final float tmpFloats[] = mTmpFloats;
6722 final Matrix tmpMatrix = mTmpMatrix;
6723
6724 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07006725 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006726 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006727 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006728 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07006729 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006730 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006731 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006732 }
6733 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006734 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006735 }
6736
6737 // "convert" it into SurfaceFlinger's format
6738 // (a 2x2 matrix + an offset)
6739 // Here we must not transform the position of the surface
6740 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006741 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07006742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006743 tmpMatrix.getValues(tmpFloats);
6744 mDsDx = tmpFloats[Matrix.MSCALE_X];
6745 mDtDx = tmpFloats[Matrix.MSKEW_X];
6746 mDsDy = tmpFloats[Matrix.MSKEW_Y];
6747 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006748 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
6749 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006750 int w = frame.width();
6751 int h = frame.height();
6752 mShownFrame.set(x, y, x+w, y+h);
6753
6754 // Now set the alpha... but because our current hardware
6755 // can't do alpha transformation on a non-opaque surface,
6756 // turn it off if we are running an animation that is also
6757 // transforming since it is more important to have that
6758 // animation be smooth.
6759 mShownAlpha = mAlpha;
6760 if (!mLimitedAlphaCompositing
6761 || (!PixelFormat.formatHasAlpha(mAttrs.format)
6762 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
6763 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006764 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006765 if (selfTransformation) {
6766 mShownAlpha *= mTransformation.getAlpha();
6767 }
6768 if (attachedTransformation != null) {
6769 mShownAlpha *= attachedTransformation.getAlpha();
6770 }
6771 if (appTransformation != null) {
6772 mShownAlpha *= appTransformation.getAlpha();
6773 }
6774 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006775 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006776 }
Romain Guy06882f82009-06-10 13:36:04 -07006777
Joe Onorato8a9b2202010-02-26 18:56:32 -08006778 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006779 TAG, "Continuing animation in " + this +
6780 ": " + mShownFrame +
6781 ", alpha=" + mTransformation.getAlpha());
6782 return;
6783 }
Romain Guy06882f82009-06-10 13:36:04 -07006784
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006785 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006786 if (mXOffset != 0 || mYOffset != 0) {
6787 mShownFrame.offset(mXOffset, mYOffset);
6788 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006789 mShownAlpha = mAlpha;
6790 mDsDx = 1;
6791 mDtDx = 0;
6792 mDsDy = 0;
6793 mDtDy = 1;
6794 }
Romain Guy06882f82009-06-10 13:36:04 -07006795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006796 /**
6797 * Is this window visible? It is not visible if there is no
6798 * surface, or we are in the process of running an exit animation
6799 * that will remove the surface, or its app token has been hidden.
6800 */
6801 public boolean isVisibleLw() {
6802 final AppWindowToken atoken = mAppToken;
6803 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6804 && (atoken == null || !atoken.hiddenRequested)
6805 && !mExiting && !mDestroying;
6806 }
6807
6808 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006809 * Like {@link #isVisibleLw}, but also counts a window that is currently
6810 * "hidden" behind the keyguard as visible. This allows us to apply
6811 * things like window flags that impact the keyguard.
6812 * XXX I am starting to think we need to have ANOTHER visibility flag
6813 * for this "hidden behind keyguard" state rather than overloading
6814 * mPolicyVisibility. Ungh.
6815 */
6816 public boolean isVisibleOrBehindKeyguardLw() {
6817 final AppWindowToken atoken = mAppToken;
6818 return mSurface != null && !mAttachedHidden
6819 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006820 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006821 && !mExiting && !mDestroying;
6822 }
6823
6824 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006825 * Is this window visible, ignoring its app token? It is not visible
6826 * if there is no surface, or we are in the process of running an exit animation
6827 * that will remove the surface.
6828 */
6829 public boolean isWinVisibleLw() {
6830 final AppWindowToken atoken = mAppToken;
6831 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6832 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
6833 && !mExiting && !mDestroying;
6834 }
6835
6836 /**
6837 * The same as isVisible(), but follows the current hidden state of
6838 * the associated app token, not the pending requested hidden state.
6839 */
6840 boolean isVisibleNow() {
6841 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07006842 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006843 }
6844
6845 /**
6846 * Same as isVisible(), but we also count it as visible between the
6847 * call to IWindowSession.add() and the first relayout().
6848 */
6849 boolean isVisibleOrAdding() {
6850 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006851 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006852 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
6853 && mPolicyVisibility && !mAttachedHidden
6854 && (atoken == null || !atoken.hiddenRequested)
6855 && !mExiting && !mDestroying;
6856 }
6857
6858 /**
6859 * Is this window currently on-screen? It is on-screen either if it
6860 * is visible or it is currently running an animation before no longer
6861 * being visible.
6862 */
6863 boolean isOnScreen() {
6864 final AppWindowToken atoken = mAppToken;
6865 if (atoken != null) {
6866 return mSurface != null && mPolicyVisibility && !mDestroying
6867 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006868 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006869 } else {
6870 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006871 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006872 }
6873 }
Romain Guy06882f82009-06-10 13:36:04 -07006874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006875 /**
6876 * Like isOnScreen(), but we don't return true if the window is part
6877 * of a transition that has not yet been started.
6878 */
6879 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006880 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006881 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006882 return false;
6883 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006884 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006885 final boolean animating = atoken != null
6886 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006887 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006888 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
6889 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006890 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006891 }
6892
6893 /** Is the window or its container currently animating? */
6894 boolean isAnimating() {
6895 final WindowState attached = mAttachedWindow;
6896 final AppWindowToken atoken = mAppToken;
6897 return mAnimation != null
6898 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07006899 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006900 (atoken.animation != null
6901 || atoken.inPendingTransaction));
6902 }
6903
6904 /** Is this window currently animating? */
6905 boolean isWindowAnimating() {
6906 return mAnimation != null;
6907 }
6908
6909 /**
6910 * Like isOnScreen, but returns false if the surface hasn't yet
6911 * been drawn.
6912 */
6913 public boolean isDisplayedLw() {
6914 final AppWindowToken atoken = mAppToken;
6915 return mSurface != null && mPolicyVisibility && !mDestroying
6916 && !mDrawPending && !mCommitDrawPending
6917 && ((!mAttachedHidden &&
6918 (atoken == null || !atoken.hiddenRequested))
6919 || mAnimating);
6920 }
6921
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006922 /**
6923 * Returns true if the window has a surface that it has drawn a
6924 * complete UI in to.
6925 */
6926 public boolean isDrawnLw() {
6927 final AppWindowToken atoken = mAppToken;
6928 return mSurface != null && !mDestroying
6929 && !mDrawPending && !mCommitDrawPending;
6930 }
6931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006932 public boolean fillsScreenLw(int screenWidth, int screenHeight,
6933 boolean shownFrame, boolean onlyOpaque) {
6934 if (mSurface == null) {
6935 return false;
6936 }
6937 if (mAppToken != null && !mAppToken.appFullscreen) {
6938 return false;
6939 }
6940 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
6941 return false;
6942 }
6943 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006944
6945 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
6946 return frame.left <= mCompatibleScreenFrame.left &&
6947 frame.top <= mCompatibleScreenFrame.top &&
6948 frame.right >= mCompatibleScreenFrame.right &&
6949 frame.bottom >= mCompatibleScreenFrame.bottom;
6950 } else {
6951 return frame.left <= 0 && frame.top <= 0
6952 && frame.right >= screenWidth
6953 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006954 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006955 }
Romain Guy06882f82009-06-10 13:36:04 -07006956
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006957 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07006958 * Return true if the window is opaque and fully drawn. This indicates
6959 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006960 */
6961 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07006962 return (mAttrs.format == PixelFormat.OPAQUE
6963 || mAttrs.type == TYPE_WALLPAPER)
6964 && mSurface != null && mAnimation == null
6965 && (mAppToken == null || mAppToken.animation == null)
6966 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006967 }
6968
6969 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
6970 return
6971 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006972 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
6973 // only if it's visible
6974 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006975 // and only if the application fills the compatible screen
6976 mFrame.left <= mCompatibleScreenFrame.left &&
6977 mFrame.top <= mCompatibleScreenFrame.top &&
6978 mFrame.right >= mCompatibleScreenFrame.right &&
6979 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006980 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006981 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006982 }
6983
6984 boolean isFullscreen(int screenWidth, int screenHeight) {
6985 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006986 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006987 }
6988
6989 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07006990 disposeInputChannel();
6991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006992 if (mAttachedWindow != null) {
6993 mAttachedWindow.mChildWindows.remove(this);
6994 }
6995 destroySurfaceLocked();
6996 mSession.windowRemovedLocked();
6997 try {
6998 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
6999 } catch (RuntimeException e) {
7000 // Ignore if it has already been removed (usually because
7001 // we are doing this as part of processing a death note.)
7002 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007003 }
7004
7005 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007006 if (mInputChannel != null) {
7007 mInputManager.unregisterInputChannel(mInputChannel);
7008
7009 mInputChannel.dispose();
7010 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007011 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007012 }
7013
7014 private class DeathRecipient implements IBinder.DeathRecipient {
7015 public void binderDied() {
7016 try {
7017 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007018 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007019 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007020 if (win != null) {
7021 removeWindowLocked(mSession, win);
7022 }
7023 }
7024 } catch (IllegalArgumentException ex) {
7025 // This will happen if the window has already been
7026 // removed.
7027 }
7028 }
7029 }
7030
7031 /** Returns true if this window desires key events. */
7032 public final boolean canReceiveKeys() {
7033 return isVisibleOrAdding()
7034 && (mViewVisibility == View.VISIBLE)
7035 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7036 }
7037
7038 public boolean hasDrawnLw() {
7039 return mHasDrawn;
7040 }
7041
7042 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007043 return showLw(doAnimation, true);
7044 }
7045
7046 boolean showLw(boolean doAnimation, boolean requestAnim) {
7047 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7048 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007049 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007050 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007051 if (doAnimation) {
7052 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7053 + mPolicyVisibility + " mAnimation=" + mAnimation);
7054 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7055 doAnimation = false;
7056 } else if (mPolicyVisibility && mAnimation == null) {
7057 // Check for the case where we are currently visible and
7058 // not animating; we do not want to do animation at such a
7059 // point to become visible when we already are.
7060 doAnimation = false;
7061 }
7062 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007063 mPolicyVisibility = true;
7064 mPolicyVisibilityAfterAnim = true;
7065 if (doAnimation) {
7066 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7067 }
7068 if (requestAnim) {
7069 requestAnimationLocked(0);
7070 }
7071 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007072 }
7073
7074 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007075 return hideLw(doAnimation, true);
7076 }
7077
7078 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007079 if (doAnimation) {
7080 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7081 doAnimation = false;
7082 }
7083 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007084 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7085 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007086 if (!current) {
7087 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007088 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007089 if (doAnimation) {
7090 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7091 if (mAnimation == null) {
7092 doAnimation = false;
7093 }
7094 }
7095 if (doAnimation) {
7096 mPolicyVisibilityAfterAnim = false;
7097 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007098 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007099 mPolicyVisibilityAfterAnim = false;
7100 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007101 // Window is no longer visible -- make sure if we were waiting
7102 // for it to be displayed before enabling the display, that
7103 // we allow the display to be enabled now.
7104 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007105 if (mCurrentFocus == this) {
7106 mFocusMayChange = true;
7107 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007108 }
7109 if (requestAnim) {
7110 requestAnimationLocked(0);
7111 }
7112 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007113 }
7114
7115 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007116 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7117 pw.print(" mClient="); pw.println(mClient.asBinder());
7118 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7119 if (mAttachedWindow != null || mLayoutAttached) {
7120 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7121 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7122 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007123 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7124 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7125 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007126 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7127 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007128 }
7129 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7130 pw.print(" mSubLayer="); pw.print(mSubLayer);
7131 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7132 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7133 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7134 pw.print("="); pw.print(mAnimLayer);
7135 pw.print(" mLastLayer="); pw.println(mLastLayer);
7136 if (mSurface != null) {
7137 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007138 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7139 pw.print(" layer="); pw.print(mSurfaceLayer);
7140 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7141 pw.print(" rect=("); pw.print(mSurfaceX);
7142 pw.print(","); pw.print(mSurfaceY);
7143 pw.print(") "); pw.print(mSurfaceW);
7144 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007145 }
7146 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7147 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7148 if (mAppToken != null) {
7149 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7150 }
7151 if (mTargetAppToken != null) {
7152 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7153 }
7154 pw.print(prefix); pw.print("mViewVisibility=0x");
7155 pw.print(Integer.toHexString(mViewVisibility));
7156 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007157 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7158 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007159 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7160 pw.print(prefix); pw.print("mPolicyVisibility=");
7161 pw.print(mPolicyVisibility);
7162 pw.print(" mPolicyVisibilityAfterAnim=");
7163 pw.print(mPolicyVisibilityAfterAnim);
7164 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7165 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007166 if (!mRelayoutCalled) {
7167 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7168 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007169 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007170 pw.print(" h="); pw.print(mRequestedHeight);
7171 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007172 if (mXOffset != 0 || mYOffset != 0) {
7173 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7174 pw.print(" y="); pw.println(mYOffset);
7175 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007176 pw.print(prefix); pw.print("mGivenContentInsets=");
7177 mGivenContentInsets.printShortString(pw);
7178 pw.print(" mGivenVisibleInsets=");
7179 mGivenVisibleInsets.printShortString(pw);
7180 pw.println();
7181 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7182 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7183 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7184 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007185 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007186 pw.print(prefix); pw.print("mShownFrame=");
7187 mShownFrame.printShortString(pw);
7188 pw.print(" last="); mLastShownFrame.printShortString(pw);
7189 pw.println();
7190 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7191 pw.print(" last="); mLastFrame.printShortString(pw);
7192 pw.println();
7193 pw.print(prefix); pw.print("mContainingFrame=");
7194 mContainingFrame.printShortString(pw);
7195 pw.print(" mDisplayFrame=");
7196 mDisplayFrame.printShortString(pw);
7197 pw.println();
7198 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7199 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7200 pw.println();
7201 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7202 pw.print(" last="); mLastContentInsets.printShortString(pw);
7203 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7204 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7205 pw.println();
7206 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7207 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7208 pw.print(" mAlpha="); pw.print(mAlpha);
7209 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7210 }
7211 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7212 || mAnimation != null) {
7213 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7214 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7215 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7216 pw.print(" mAnimation="); pw.println(mAnimation);
7217 }
7218 if (mHasTransformation || mHasLocalTransformation) {
7219 pw.print(prefix); pw.print("XForm: has=");
7220 pw.print(mHasTransformation);
7221 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7222 pw.print(" "); mTransformation.printShortString(pw);
7223 pw.println();
7224 }
7225 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7226 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7227 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7228 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7229 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7230 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7231 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7232 pw.print(" mDestroying="); pw.print(mDestroying);
7233 pw.print(" mRemoved="); pw.println(mRemoved);
7234 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007235 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007236 pw.print(prefix); pw.print("mOrientationChanging=");
7237 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007238 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7239 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007240 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007241 if (mHScale != 1 || mVScale != 1) {
7242 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7243 pw.print(" mVScale="); pw.println(mVScale);
7244 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007245 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007246 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7247 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7248 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007249 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7250 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7251 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7252 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007253 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007254
7255 String makeInputChannelName() {
7256 return Integer.toHexString(System.identityHashCode(this))
7257 + " " + mAttrs.getTitle();
7258 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007259
7260 @Override
7261 public String toString() {
7262 return "Window{"
7263 + Integer.toHexString(System.identityHashCode(this))
7264 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7265 }
7266 }
Romain Guy06882f82009-06-10 13:36:04 -07007267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007268 // -------------------------------------------------------------
7269 // Window Token State
7270 // -------------------------------------------------------------
7271
7272 class WindowToken {
7273 // The actual token.
7274 final IBinder token;
7275
7276 // The type of window this token is for, as per WindowManager.LayoutParams.
7277 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007279 // Set if this token was explicitly added by a client, so should
7280 // not be removed when all windows are removed.
7281 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007282
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007283 // For printing.
7284 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007286 // If this is an AppWindowToken, this is non-null.
7287 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007289 // All of the windows associated with this token.
7290 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7291
7292 // Is key dispatching paused for this token?
7293 boolean paused = false;
7294
7295 // Should this token's windows be hidden?
7296 boolean hidden;
7297
7298 // Temporary for finding which tokens no longer have visible windows.
7299 boolean hasVisible;
7300
Dianne Hackborna8f60182009-09-01 19:01:50 -07007301 // Set to true when this token is in a pending transaction where it
7302 // will be shown.
7303 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007304
Dianne Hackborna8f60182009-09-01 19:01:50 -07007305 // Set to true when this token is in a pending transaction where it
7306 // will be hidden.
7307 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007308
Dianne Hackborna8f60182009-09-01 19:01:50 -07007309 // Set to true when this token is in a pending transaction where its
7310 // windows will be put to the bottom of the list.
7311 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007312
Dianne Hackborna8f60182009-09-01 19:01:50 -07007313 // Set to true when this token is in a pending transaction where its
7314 // windows will be put to the top of the list.
7315 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007317 WindowToken(IBinder _token, int type, boolean _explicit) {
7318 token = _token;
7319 windowType = type;
7320 explicit = _explicit;
7321 }
7322
7323 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007324 pw.print(prefix); pw.print("token="); pw.println(token);
7325 pw.print(prefix); pw.print("windows="); pw.println(windows);
7326 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7327 pw.print(" hidden="); pw.print(hidden);
7328 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007329 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7330 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7331 pw.print(" waitingToHide="); pw.print(waitingToHide);
7332 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7333 pw.print(" sendingToTop="); pw.println(sendingToTop);
7334 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007335 }
7336
7337 @Override
7338 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007339 if (stringName == null) {
7340 StringBuilder sb = new StringBuilder();
7341 sb.append("WindowToken{");
7342 sb.append(Integer.toHexString(System.identityHashCode(this)));
7343 sb.append(" token="); sb.append(token); sb.append('}');
7344 stringName = sb.toString();
7345 }
7346 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007347 }
7348 };
7349
7350 class AppWindowToken extends WindowToken {
7351 // Non-null only for application tokens.
7352 final IApplicationToken appToken;
7353
7354 // All of the windows and child windows that are included in this
7355 // application token. Note this list is NOT sorted!
7356 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7357
7358 int groupId = -1;
7359 boolean appFullscreen;
7360 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007361
7362 // The input dispatching timeout for this application token in nanoseconds.
7363 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007365 // These are used for determining when all windows associated with
7366 // an activity have been drawn, so they can be made visible together
7367 // at the same time.
7368 int lastTransactionSequence = mTransactionSequence-1;
7369 int numInterestingWindows;
7370 int numDrawnWindows;
7371 boolean inPendingTransaction;
7372 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007374 // Is this token going to be hidden in a little while? If so, it
7375 // won't be taken into account for setting the screen orientation.
7376 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007378 // Is this window's surface needed? This is almost like hidden, except
7379 // it will sometimes be true a little earlier: when the token has
7380 // been shown, but is still waiting for its app transition to execute
7381 // before making its windows shown.
7382 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007384 // Have we told the window clients to hide themselves?
7385 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007387 // Last visibility state we reported to the app token.
7388 boolean reportedVisible;
7389
7390 // Set to true when the token has been removed from the window mgr.
7391 boolean removed;
7392
7393 // Have we been asked to have this token keep the screen frozen?
7394 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007396 boolean animating;
7397 Animation animation;
7398 boolean hasTransformation;
7399 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007401 // Offset to the window of all layers in the token, for use by
7402 // AppWindowToken animations.
7403 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007405 // Information about an application starting window if displayed.
7406 StartingData startingData;
7407 WindowState startingWindow;
7408 View startingView;
7409 boolean startingDisplayed;
7410 boolean startingMoved;
7411 boolean firstWindowDrawn;
7412
7413 AppWindowToken(IApplicationToken _token) {
7414 super(_token.asBinder(),
7415 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7416 appWindowToken = this;
7417 appToken = _token;
7418 }
Romain Guy06882f82009-06-10 13:36:04 -07007419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007420 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007421 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007422 TAG, "Setting animation in " + this + ": " + anim);
7423 animation = anim;
7424 animating = false;
7425 anim.restrictDuration(MAX_ANIMATION_DURATION);
7426 anim.scaleCurrentDuration(mTransitionAnimationScale);
7427 int zorder = anim.getZAdjustment();
7428 int adj = 0;
7429 if (zorder == Animation.ZORDER_TOP) {
7430 adj = TYPE_LAYER_OFFSET;
7431 } else if (zorder == Animation.ZORDER_BOTTOM) {
7432 adj = -TYPE_LAYER_OFFSET;
7433 }
Romain Guy06882f82009-06-10 13:36:04 -07007434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007435 if (animLayerAdjustment != adj) {
7436 animLayerAdjustment = adj;
7437 updateLayers();
7438 }
7439 }
Romain Guy06882f82009-06-10 13:36:04 -07007440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007441 public void setDummyAnimation() {
7442 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007443 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007444 TAG, "Setting dummy animation in " + this);
7445 animation = sDummyAnimation;
7446 }
7447 }
7448
7449 public void clearAnimation() {
7450 if (animation != null) {
7451 animation = null;
7452 animating = true;
7453 }
7454 }
Romain Guy06882f82009-06-10 13:36:04 -07007455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007456 void updateLayers() {
7457 final int N = allAppWindows.size();
7458 final int adj = animLayerAdjustment;
7459 for (int i=0; i<N; i++) {
7460 WindowState w = allAppWindows.get(i);
7461 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007462 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007463 + w.mAnimLayer);
7464 if (w == mInputMethodTarget) {
7465 setInputMethodAnimLayerAdjustment(adj);
7466 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007467 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007468 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007469 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007470 }
7471 }
Romain Guy06882f82009-06-10 13:36:04 -07007472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007473 void sendAppVisibilityToClients() {
7474 final int N = allAppWindows.size();
7475 for (int i=0; i<N; i++) {
7476 WindowState win = allAppWindows.get(i);
7477 if (win == startingWindow && clientHidden) {
7478 // Don't hide the starting window.
7479 continue;
7480 }
7481 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007482 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007483 "Setting visibility of " + win + ": " + (!clientHidden));
7484 win.mClient.dispatchAppVisibility(!clientHidden);
7485 } catch (RemoteException e) {
7486 }
7487 }
7488 }
Romain Guy06882f82009-06-10 13:36:04 -07007489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007490 void showAllWindowsLocked() {
7491 final int NW = allAppWindows.size();
7492 for (int i=0; i<NW; i++) {
7493 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007494 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007495 "performing show on: " + w);
7496 w.performShowLocked();
7497 }
7498 }
Romain Guy06882f82009-06-10 13:36:04 -07007499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007500 // This must be called while inside a transaction.
7501 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007502 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007503 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007505 if (animation == sDummyAnimation) {
7506 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007507 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007508 // when it is really time to animate, this will be set to
7509 // a real animation and the next call will execute normally.
7510 return false;
7511 }
Romain Guy06882f82009-06-10 13:36:04 -07007512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007513 if ((allDrawn || animating || startingDisplayed) && animation != null) {
7514 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007515 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007516 TAG, "Starting animation in " + this +
7517 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
7518 + " scale=" + mTransitionAnimationScale
7519 + " allDrawn=" + allDrawn + " animating=" + animating);
7520 animation.initialize(dw, dh, dw, dh);
7521 animation.setStartTime(currentTime);
7522 animating = true;
7523 }
7524 transformation.clear();
7525 final boolean more = animation.getTransformation(
7526 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007527 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007528 TAG, "Stepped animation in " + this +
7529 ": more=" + more + ", xform=" + transformation);
7530 if (more) {
7531 // we're done!
7532 hasTransformation = true;
7533 return true;
7534 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007535 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007536 TAG, "Finished animation in " + this +
7537 " @ " + currentTime);
7538 animation = null;
7539 }
7540 } else if (animation != null) {
7541 // If the display is frozen, and there is a pending animation,
7542 // clear it and make sure we run the cleanup code.
7543 animating = true;
7544 animation = null;
7545 }
7546
7547 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07007548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007549 if (!animating) {
7550 return false;
7551 }
7552
7553 clearAnimation();
7554 animating = false;
7555 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
7556 moveInputMethodWindowsIfNeededLocked(true);
7557 }
Romain Guy06882f82009-06-10 13:36:04 -07007558
Joe Onorato8a9b2202010-02-26 18:56:32 -08007559 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007560 TAG, "Animation done in " + this
7561 + ": reportedVisible=" + reportedVisible);
7562
7563 transformation.clear();
7564 if (animLayerAdjustment != 0) {
7565 animLayerAdjustment = 0;
7566 updateLayers();
7567 }
Romain Guy06882f82009-06-10 13:36:04 -07007568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007569 final int N = windows.size();
7570 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007571 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007572 }
7573 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07007574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007575 return false;
7576 }
7577
7578 void updateReportedVisibilityLocked() {
7579 if (appToken == null) {
7580 return;
7581 }
Romain Guy06882f82009-06-10 13:36:04 -07007582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007583 int numInteresting = 0;
7584 int numVisible = 0;
7585 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07007586
Joe Onorato8a9b2202010-02-26 18:56:32 -08007587 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007588 final int N = allAppWindows.size();
7589 for (int i=0; i<N; i++) {
7590 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08007591 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07007592 || win.mViewVisibility != View.VISIBLE
7593 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007594 continue;
7595 }
7596 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007597 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007598 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007599 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007600 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007601 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007602 + " pv=" + win.mPolicyVisibility
7603 + " dp=" + win.mDrawPending
7604 + " cdp=" + win.mCommitDrawPending
7605 + " ah=" + win.mAttachedHidden
7606 + " th="
7607 + (win.mAppToken != null
7608 ? win.mAppToken.hiddenRequested : false)
7609 + " a=" + win.mAnimating);
7610 }
7611 }
7612 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007613 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007614 if (!win.isAnimating()) {
7615 numVisible++;
7616 }
7617 nowGone = false;
7618 } else if (win.isAnimating()) {
7619 nowGone = false;
7620 }
7621 }
Romain Guy06882f82009-06-10 13:36:04 -07007622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007623 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007624 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007625 + numInteresting + " visible=" + numVisible);
7626 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007627 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007628 TAG, "Visibility changed in " + this
7629 + ": vis=" + nowVisible);
7630 reportedVisible = nowVisible;
7631 Message m = mH.obtainMessage(
7632 H.REPORT_APPLICATION_TOKEN_WINDOWS,
7633 nowVisible ? 1 : 0,
7634 nowGone ? 1 : 0,
7635 this);
7636 mH.sendMessage(m);
7637 }
7638 }
Romain Guy06882f82009-06-10 13:36:04 -07007639
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007640 WindowState findMainWindow() {
7641 int j = windows.size();
7642 while (j > 0) {
7643 j--;
7644 WindowState win = windows.get(j);
7645 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
7646 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
7647 return win;
7648 }
7649 }
7650 return null;
7651 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007653 void dump(PrintWriter pw, String prefix) {
7654 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007655 if (appToken != null) {
7656 pw.print(prefix); pw.println("app=true");
7657 }
7658 if (allAppWindows.size() > 0) {
7659 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
7660 }
7661 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007662 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007663 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
7664 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
7665 pw.print(" clientHidden="); pw.print(clientHidden);
7666 pw.print(" willBeHidden="); pw.print(willBeHidden);
7667 pw.print(" reportedVisible="); pw.println(reportedVisible);
7668 if (paused || freezingScreen) {
7669 pw.print(prefix); pw.print("paused="); pw.print(paused);
7670 pw.print(" freezingScreen="); pw.println(freezingScreen);
7671 }
7672 if (numInterestingWindows != 0 || numDrawnWindows != 0
7673 || inPendingTransaction || allDrawn) {
7674 pw.print(prefix); pw.print("numInterestingWindows=");
7675 pw.print(numInterestingWindows);
7676 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
7677 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
7678 pw.print(" allDrawn="); pw.println(allDrawn);
7679 }
7680 if (animating || animation != null) {
7681 pw.print(prefix); pw.print("animating="); pw.print(animating);
7682 pw.print(" animation="); pw.println(animation);
7683 }
7684 if (animLayerAdjustment != 0) {
7685 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
7686 }
7687 if (hasTransformation) {
7688 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
7689 pw.print(" transformation="); transformation.printShortString(pw);
7690 pw.println();
7691 }
7692 if (startingData != null || removed || firstWindowDrawn) {
7693 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
7694 pw.print(" removed="); pw.print(removed);
7695 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
7696 }
7697 if (startingWindow != null || startingView != null
7698 || startingDisplayed || startingMoved) {
7699 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
7700 pw.print(" startingView="); pw.print(startingView);
7701 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
7702 pw.print(" startingMoved"); pw.println(startingMoved);
7703 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007704 }
7705
7706 @Override
7707 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007708 if (stringName == null) {
7709 StringBuilder sb = new StringBuilder();
7710 sb.append("AppWindowToken{");
7711 sb.append(Integer.toHexString(System.identityHashCode(this)));
7712 sb.append(" token="); sb.append(token); sb.append('}');
7713 stringName = sb.toString();
7714 }
7715 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007716 }
7717 }
Romain Guy06882f82009-06-10 13:36:04 -07007718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007719 // -------------------------------------------------------------
7720 // DummyAnimation
7721 // -------------------------------------------------------------
7722
7723 // This is an animation that does nothing: it just immediately finishes
7724 // itself every time it is called. It is used as a stub animation in cases
7725 // where we want to synchronize multiple things that may be animating.
7726 static final class DummyAnimation extends Animation {
7727 public boolean getTransformation(long currentTime, Transformation outTransformation) {
7728 return false;
7729 }
7730 }
7731 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07007732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007733 // -------------------------------------------------------------
7734 // Async Handler
7735 // -------------------------------------------------------------
7736
7737 static final class StartingData {
7738 final String pkg;
7739 final int theme;
7740 final CharSequence nonLocalizedLabel;
7741 final int labelRes;
7742 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07007743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007744 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
7745 int _labelRes, int _icon) {
7746 pkg = _pkg;
7747 theme = _theme;
7748 nonLocalizedLabel = _nonLocalizedLabel;
7749 labelRes = _labelRes;
7750 icon = _icon;
7751 }
7752 }
7753
7754 private final class H extends Handler {
7755 public static final int REPORT_FOCUS_CHANGE = 2;
7756 public static final int REPORT_LOSING_FOCUS = 3;
7757 public static final int ANIMATE = 4;
7758 public static final int ADD_STARTING = 5;
7759 public static final int REMOVE_STARTING = 6;
7760 public static final int FINISHED_STARTING = 7;
7761 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007762 public static final int WINDOW_FREEZE_TIMEOUT = 11;
7763 public static final int HOLD_SCREEN_CHANGED = 12;
7764 public static final int APP_TRANSITION_TIMEOUT = 13;
7765 public static final int PERSIST_ANIMATION_SCALE = 14;
7766 public static final int FORCE_GC = 15;
7767 public static final int ENABLE_SCREEN = 16;
7768 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007769 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007770 public static final int REPORT_WINDOWS_CHANGE = 19;
Romain Guy06882f82009-06-10 13:36:04 -07007771
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007772 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07007773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007774 public H() {
7775 }
Romain Guy06882f82009-06-10 13:36:04 -07007776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007777 @Override
7778 public void handleMessage(Message msg) {
7779 switch (msg.what) {
7780 case REPORT_FOCUS_CHANGE: {
7781 WindowState lastFocus;
7782 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07007783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007784 synchronized(mWindowMap) {
7785 lastFocus = mLastFocus;
7786 newFocus = mCurrentFocus;
7787 if (lastFocus == newFocus) {
7788 // Focus is not changing, so nothing to do.
7789 return;
7790 }
7791 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007792 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007793 // + " to " + newFocus);
7794 if (newFocus != null && lastFocus != null
7795 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007796 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007797 mLosingFocus.add(lastFocus);
7798 lastFocus = null;
7799 }
7800 }
7801
7802 if (lastFocus != newFocus) {
7803 //System.out.println("Changing focus from " + lastFocus
7804 // + " to " + newFocus);
7805 if (newFocus != null) {
7806 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007807 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007808 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
7809 } catch (RemoteException e) {
7810 // Ignore if process has died.
7811 }
7812 }
7813
7814 if (lastFocus != null) {
7815 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007816 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007817 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
7818 } catch (RemoteException e) {
7819 // Ignore if process has died.
7820 }
7821 }
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007822 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007823 }
7824 } break;
7825
7826 case REPORT_LOSING_FOCUS: {
7827 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07007828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007829 synchronized(mWindowMap) {
7830 losers = mLosingFocus;
7831 mLosingFocus = new ArrayList<WindowState>();
7832 }
7833
7834 final int N = losers.size();
7835 for (int i=0; i<N; i++) {
7836 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007837 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007838 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
7839 } catch (RemoteException e) {
7840 // Ignore if process has died.
7841 }
7842 }
7843 } break;
7844
7845 case ANIMATE: {
7846 synchronized(mWindowMap) {
7847 mAnimationPending = false;
7848 performLayoutAndPlaceSurfacesLocked();
7849 }
7850 } break;
7851
7852 case ADD_STARTING: {
7853 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7854 final StartingData sd = wtoken.startingData;
7855
7856 if (sd == null) {
7857 // Animation has been canceled... do nothing.
7858 return;
7859 }
Romain Guy06882f82009-06-10 13:36:04 -07007860
Joe Onorato8a9b2202010-02-26 18:56:32 -08007861 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007862 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07007863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007864 View view = null;
7865 try {
7866 view = mPolicy.addStartingWindow(
7867 wtoken.token, sd.pkg,
7868 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
7869 sd.icon);
7870 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007871 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007872 }
7873
7874 if (view != null) {
7875 boolean abort = false;
7876
7877 synchronized(mWindowMap) {
7878 if (wtoken.removed || wtoken.startingData == null) {
7879 // If the window was successfully added, then
7880 // we need to remove it.
7881 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007882 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007883 "Aborted starting " + wtoken
7884 + ": removed=" + wtoken.removed
7885 + " startingData=" + wtoken.startingData);
7886 wtoken.startingWindow = null;
7887 wtoken.startingData = null;
7888 abort = true;
7889 }
7890 } else {
7891 wtoken.startingView = view;
7892 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007893 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007894 "Added starting " + wtoken
7895 + ": startingWindow="
7896 + wtoken.startingWindow + " startingView="
7897 + wtoken.startingView);
7898 }
7899
7900 if (abort) {
7901 try {
7902 mPolicy.removeStartingWindow(wtoken.token, view);
7903 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007904 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007905 }
7906 }
7907 }
7908 } break;
7909
7910 case REMOVE_STARTING: {
7911 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7912 IBinder token = null;
7913 View view = null;
7914 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007915 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007916 + wtoken + ": startingWindow="
7917 + wtoken.startingWindow + " startingView="
7918 + wtoken.startingView);
7919 if (wtoken.startingWindow != null) {
7920 view = wtoken.startingView;
7921 token = wtoken.token;
7922 wtoken.startingData = null;
7923 wtoken.startingView = null;
7924 wtoken.startingWindow = null;
7925 }
7926 }
7927 if (view != null) {
7928 try {
7929 mPolicy.removeStartingWindow(token, view);
7930 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007931 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007932 }
7933 }
7934 } break;
7935
7936 case FINISHED_STARTING: {
7937 IBinder token = null;
7938 View view = null;
7939 while (true) {
7940 synchronized (mWindowMap) {
7941 final int N = mFinishedStarting.size();
7942 if (N <= 0) {
7943 break;
7944 }
7945 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
7946
Joe Onorato8a9b2202010-02-26 18:56:32 -08007947 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007948 "Finished starting " + wtoken
7949 + ": startingWindow=" + wtoken.startingWindow
7950 + " startingView=" + wtoken.startingView);
7951
7952 if (wtoken.startingWindow == null) {
7953 continue;
7954 }
7955
7956 view = wtoken.startingView;
7957 token = wtoken.token;
7958 wtoken.startingData = null;
7959 wtoken.startingView = null;
7960 wtoken.startingWindow = null;
7961 }
7962
7963 try {
7964 mPolicy.removeStartingWindow(token, view);
7965 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007966 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007967 }
7968 }
7969 } break;
7970
7971 case REPORT_APPLICATION_TOKEN_WINDOWS: {
7972 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7973
7974 boolean nowVisible = msg.arg1 != 0;
7975 boolean nowGone = msg.arg2 != 0;
7976
7977 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007978 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007979 TAG, "Reporting visible in " + wtoken
7980 + " visible=" + nowVisible
7981 + " gone=" + nowGone);
7982 if (nowVisible) {
7983 wtoken.appToken.windowsVisible();
7984 } else {
7985 wtoken.appToken.windowsGone();
7986 }
7987 } catch (RemoteException ex) {
7988 }
7989 } break;
Romain Guy06882f82009-06-10 13:36:04 -07007990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007991 case WINDOW_FREEZE_TIMEOUT: {
7992 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007993 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007994 int i = mWindows.size();
7995 while (i > 0) {
7996 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007997 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007998 if (w.mOrientationChanging) {
7999 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008000 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008001 }
8002 }
8003 performLayoutAndPlaceSurfacesLocked();
8004 }
8005 break;
8006 }
Romain Guy06882f82009-06-10 13:36:04 -07008007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008008 case HOLD_SCREEN_CHANGED: {
8009 Session oldHold;
8010 Session newHold;
8011 synchronized (mWindowMap) {
8012 oldHold = mLastReportedHold;
8013 newHold = (Session)msg.obj;
8014 mLastReportedHold = newHold;
8015 }
Romain Guy06882f82009-06-10 13:36:04 -07008016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008017 if (oldHold != newHold) {
8018 try {
8019 if (oldHold != null) {
8020 mBatteryStats.noteStopWakelock(oldHold.mUid,
8021 "window",
8022 BatteryStats.WAKE_TYPE_WINDOW);
8023 }
8024 if (newHold != null) {
8025 mBatteryStats.noteStartWakelock(newHold.mUid,
8026 "window",
8027 BatteryStats.WAKE_TYPE_WINDOW);
8028 }
8029 } catch (RemoteException e) {
8030 }
8031 }
8032 break;
8033 }
Romain Guy06882f82009-06-10 13:36:04 -07008034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008035 case APP_TRANSITION_TIMEOUT: {
8036 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008037 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008038 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008039 "*** APP TRANSITION TIMEOUT");
8040 mAppTransitionReady = true;
8041 mAppTransitionTimeout = true;
8042 performLayoutAndPlaceSurfacesLocked();
8043 }
8044 }
8045 break;
8046 }
Romain Guy06882f82009-06-10 13:36:04 -07008047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008048 case PERSIST_ANIMATION_SCALE: {
8049 Settings.System.putFloat(mContext.getContentResolver(),
8050 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8051 Settings.System.putFloat(mContext.getContentResolver(),
8052 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8053 break;
8054 }
Romain Guy06882f82009-06-10 13:36:04 -07008055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008056 case FORCE_GC: {
8057 synchronized(mWindowMap) {
8058 if (mAnimationPending) {
8059 // If we are animating, don't do the gc now but
8060 // delay a bit so we don't interrupt the animation.
8061 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8062 2000);
8063 return;
8064 }
8065 // If we are currently rotating the display, it will
8066 // schedule a new message when done.
8067 if (mDisplayFrozen) {
8068 return;
8069 }
8070 mFreezeGcPending = 0;
8071 }
8072 Runtime.getRuntime().gc();
8073 break;
8074 }
Romain Guy06882f82009-06-10 13:36:04 -07008075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008076 case ENABLE_SCREEN: {
8077 performEnableScreen();
8078 break;
8079 }
Romain Guy06882f82009-06-10 13:36:04 -07008080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008081 case APP_FREEZE_TIMEOUT: {
8082 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008083 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008084 int i = mAppTokens.size();
8085 while (i > 0) {
8086 i--;
8087 AppWindowToken tok = mAppTokens.get(i);
8088 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008089 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008090 unsetAppFreezingScreenLocked(tok, true, true);
8091 }
8092 }
8093 }
8094 break;
8095 }
Romain Guy06882f82009-06-10 13:36:04 -07008096
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008097 case SEND_NEW_CONFIGURATION: {
8098 removeMessages(SEND_NEW_CONFIGURATION);
8099 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008100 break;
8101 }
Romain Guy06882f82009-06-10 13:36:04 -07008102
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008103 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008104 if (mWindowsChanged) {
8105 synchronized (mWindowMap) {
8106 mWindowsChanged = false;
8107 }
8108 notifyWindowsChanged();
8109 }
8110 break;
8111 }
8112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008113 }
8114 }
8115 }
8116
8117 // -------------------------------------------------------------
8118 // IWindowManager API
8119 // -------------------------------------------------------------
8120
8121 public IWindowSession openSession(IInputMethodClient client,
8122 IInputContext inputContext) {
8123 if (client == null) throw new IllegalArgumentException("null client");
8124 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008125 Session session = new Session(client, inputContext);
8126 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008127 }
8128
8129 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8130 synchronized (mWindowMap) {
8131 // The focus for the client is the window immediately below
8132 // where we would place the input method window.
8133 int idx = findDesiredInputMethodWindowIndexLocked(false);
8134 WindowState imFocus;
8135 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008136 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008137 if (imFocus != null) {
8138 if (imFocus.mSession.mClient != null &&
8139 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8140 return true;
8141 }
8142 }
8143 }
8144 }
8145 return false;
8146 }
Romain Guy06882f82009-06-10 13:36:04 -07008147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008148 // -------------------------------------------------------------
8149 // Internals
8150 // -------------------------------------------------------------
8151
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008152 final WindowState windowForClientLocked(Session session, IWindow client,
8153 boolean throwOnError) {
8154 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008155 }
Romain Guy06882f82009-06-10 13:36:04 -07008156
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008157 final WindowState windowForClientLocked(Session session, IBinder client,
8158 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008159 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008160 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008161 TAG, "Looking up client " + client + ": " + win);
8162 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008163 RuntimeException ex = new IllegalArgumentException(
8164 "Requested window " + client + " does not exist");
8165 if (throwOnError) {
8166 throw ex;
8167 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008168 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008169 return null;
8170 }
8171 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008172 RuntimeException ex = new IllegalArgumentException(
8173 "Requested window " + client + " is in session " +
8174 win.mSession + ", not " + session);
8175 if (throwOnError) {
8176 throw ex;
8177 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008178 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008179 return null;
8180 }
8181
8182 return win;
8183 }
8184
Dianne Hackborna8f60182009-09-01 19:01:50 -07008185 final void rebuildAppWindowListLocked() {
8186 int NW = mWindows.size();
8187 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008188 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008189 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008190
Dianne Hackborna8f60182009-09-01 19:01:50 -07008191 // First remove all existing app windows.
8192 i=0;
8193 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008194 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008195 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008196 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008197 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008198 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008199 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008200 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008201 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008202 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008203 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8204 && lastWallpaper == i-1) {
8205 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008206 }
8207 i++;
8208 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008209
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008210 // The wallpaper window(s) typically live at the bottom of the stack,
8211 // so skip them before adding app tokens.
8212 lastWallpaper++;
8213 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008214
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008215 // First add all of the exiting app tokens... these are no longer
8216 // in the main app list, but still have windows shown. We put them
8217 // in the back because now that the animation is over we no longer
8218 // will care about them.
8219 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008220 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008221 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8222 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008223
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008224 // And add in the still active app tokens in Z order.
8225 NT = mAppTokens.size();
8226 for (int j=0; j<NT; j++) {
8227 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008228 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008229
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008230 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008231 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008232 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008233 + " windows but added " + i);
8234 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008235 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008237 private final void assignLayersLocked() {
8238 int N = mWindows.size();
8239 int curBaseLayer = 0;
8240 int curLayer = 0;
8241 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008243 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008244 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008245 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8246 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008247 curLayer += WINDOW_LAYER_MULTIPLIER;
8248 w.mLayer = curLayer;
8249 } else {
8250 curBaseLayer = curLayer = w.mBaseLayer;
8251 w.mLayer = curLayer;
8252 }
8253 if (w.mTargetAppToken != null) {
8254 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8255 } else if (w.mAppToken != null) {
8256 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8257 } else {
8258 w.mAnimLayer = w.mLayer;
8259 }
8260 if (w.mIsImWindow) {
8261 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008262 } else if (w.mIsWallpaper) {
8263 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008264 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008265 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008266 + w.mAnimLayer);
8267 //System.out.println(
8268 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8269 }
8270 }
8271
8272 private boolean mInLayout = false;
8273 private final void performLayoutAndPlaceSurfacesLocked() {
8274 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008275 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008276 throw new RuntimeException("Recursive call!");
8277 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008278 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008279 return;
8280 }
8281
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008282 if (mWaitingForConfig) {
8283 // Our configuration has changed (most likely rotation), but we
8284 // don't yet have the complete configuration to report to
8285 // applications. Don't do any window layout until we have it.
8286 return;
8287 }
8288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008289 boolean recoveringMemory = false;
8290 if (mForceRemoves != null) {
8291 recoveringMemory = true;
8292 // Wait a little it for things to settle down, and off we go.
8293 for (int i=0; i<mForceRemoves.size(); i++) {
8294 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008295 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008296 removeWindowInnerLocked(ws.mSession, ws);
8297 }
8298 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008299 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008300 Object tmp = new Object();
8301 synchronized (tmp) {
8302 try {
8303 tmp.wait(250);
8304 } catch (InterruptedException e) {
8305 }
8306 }
8307 }
Romain Guy06882f82009-06-10 13:36:04 -07008308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008309 mInLayout = true;
8310 try {
8311 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008313 int i = mPendingRemove.size()-1;
8314 if (i >= 0) {
8315 while (i >= 0) {
8316 WindowState w = mPendingRemove.get(i);
8317 removeWindowInnerLocked(w.mSession, w);
8318 i--;
8319 }
8320 mPendingRemove.clear();
8321
8322 mInLayout = false;
8323 assignLayersLocked();
8324 mLayoutNeeded = true;
8325 performLayoutAndPlaceSurfacesLocked();
8326
8327 } else {
8328 mInLayout = false;
8329 if (mLayoutNeeded) {
8330 requestAnimationLocked(0);
8331 }
8332 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008333 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008334 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8335 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008336 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008337 } catch (RuntimeException e) {
8338 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008339 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008340 }
8341 }
8342
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008343 private final int performLayoutLockedInner() {
8344 if (!mLayoutNeeded) {
8345 return 0;
8346 }
8347
8348 mLayoutNeeded = false;
8349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008350 final int dw = mDisplay.getWidth();
8351 final int dh = mDisplay.getHeight();
8352
8353 final int N = mWindows.size();
8354 int i;
8355
Joe Onorato8a9b2202010-02-26 18:56:32 -08008356 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008357 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8358
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008359 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008360
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008361 int seq = mLayoutSeq+1;
8362 if (seq < 0) seq = 0;
8363 mLayoutSeq = seq;
8364
8365 // First perform layout of any root windows (not attached
8366 // to another window).
8367 int topAttached = -1;
8368 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008369 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008370
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008371 // Don't do layout of a window if it is not visible, or
8372 // soon won't be visible, to avoid wasting time and funky
8373 // changes while a window is animating away.
8374 final AppWindowToken atoken = win.mAppToken;
8375 final boolean gone = win.mViewVisibility == View.GONE
8376 || !win.mRelayoutCalled
8377 || win.mRootToken.hidden
8378 || (atoken != null && atoken.hiddenRequested)
8379 || win.mAttachedHidden
8380 || win.mExiting || win.mDestroying;
8381
8382 if (!win.mLayoutAttached) {
8383 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8384 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8385 + " mLayoutAttached=" + win.mLayoutAttached);
8386 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8387 + win.mViewVisibility + " mRelayoutCalled="
8388 + win.mRelayoutCalled + " hidden="
8389 + win.mRootToken.hidden + " hiddenRequested="
8390 + (atoken != null && atoken.hiddenRequested)
8391 + " mAttachedHidden=" + win.mAttachedHidden);
8392 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008393
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008394 // If this view is GONE, then skip it -- keep the current
8395 // frame, and let the caller know so they can ignore it
8396 // if they want. (We do the normal layout for INVISIBLE
8397 // windows, since that means "perform layout as normal,
8398 // just don't display").
8399 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008400 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008401 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8402 win.mLayoutSeq = seq;
8403 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8404 + win.mFrame + " mContainingFrame="
8405 + win.mContainingFrame + " mDisplayFrame="
8406 + win.mDisplayFrame);
8407 } else {
8408 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008409 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008410 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008411 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008412
8413 // Now perform layout of attached windows, which usually
8414 // depend on the position of the window they are attached to.
8415 // XXX does not deal with windows that are attached to windows
8416 // that are themselves attached.
8417 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008418 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008419
8420 // If this view is GONE, then skip it -- keep the current
8421 // frame, and let the caller know so they can ignore it
8422 // if they want. (We do the normal layout for INVISIBLE
8423 // windows, since that means "perform layout as normal,
8424 // just don't display").
8425 if (win.mLayoutAttached) {
8426 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8427 + " mHaveFrame=" + win.mHaveFrame
8428 + " mViewVisibility=" + win.mViewVisibility
8429 + " mRelayoutCalled=" + win.mRelayoutCalled);
8430 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8431 || !win.mHaveFrame) {
8432 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8433 win.mLayoutSeq = seq;
8434 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8435 + win.mFrame + " mContainingFrame="
8436 + win.mContainingFrame + " mDisplayFrame="
8437 + win.mDisplayFrame);
8438 }
8439 }
8440 }
Jeff Brown349703e2010-06-22 01:27:15 -07008441
8442 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008443 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008444
8445 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008446 }
Romain Guy06882f82009-06-10 13:36:04 -07008447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008448 private final void performLayoutAndPlaceSurfacesLockedInner(
8449 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04008450 if (mDisplay == null) {
8451 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
8452 return;
8453 }
8454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008455 final long currentTime = SystemClock.uptimeMillis();
8456 final int dw = mDisplay.getWidth();
8457 final int dh = mDisplay.getHeight();
8458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008459 int i;
8460
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008461 if (mFocusMayChange) {
8462 mFocusMayChange = false;
8463 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
8464 }
8465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008466 if (mFxSession == null) {
8467 mFxSession = new SurfaceSession();
8468 }
Romain Guy06882f82009-06-10 13:36:04 -07008469
Joe Onorato8a9b2202010-02-26 18:56:32 -08008470 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008471
8472 // Initialize state of exiting tokens.
8473 for (i=mExitingTokens.size()-1; i>=0; i--) {
8474 mExitingTokens.get(i).hasVisible = false;
8475 }
8476
8477 // Initialize state of exiting applications.
8478 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
8479 mExitingAppTokens.get(i).hasVisible = false;
8480 }
8481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008482 boolean orientationChangeComplete = true;
8483 Session holdScreen = null;
8484 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008485 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008486 boolean focusDisplayed = false;
8487 boolean animating = false;
8488
8489 Surface.openTransaction();
8490 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008491 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008492 int repeats = 0;
8493 int changes = 0;
8494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008495 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008496 repeats++;
8497 if (repeats > 6) {
8498 Slog.w(TAG, "Animation repeat aborted after too many iterations");
8499 mLayoutNeeded = false;
8500 break;
8501 }
8502
8503 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
8504 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
8505 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
8506 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
8507 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
8508 assignLayersLocked();
8509 mLayoutNeeded = true;
8510 }
8511 }
8512 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
8513 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
8514 if (updateOrientationFromAppTokensLocked()) {
8515 mLayoutNeeded = true;
8516 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
8517 }
8518 }
8519 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
8520 mLayoutNeeded = true;
8521 }
8522 }
8523
8524 // FIRST LOOP: Perform a layout, if needed.
8525 if (repeats < 4) {
8526 changes = performLayoutLockedInner();
8527 if (changes != 0) {
8528 continue;
8529 }
8530 } else {
8531 Slog.w(TAG, "Layout repeat skipped after too many iterations");
8532 changes = 0;
8533 }
8534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008535 final int transactionSequence = ++mTransactionSequence;
8536
8537 // Update animations of all applications, including those
8538 // associated with exiting/removed apps
8539 boolean tokensAnimating = false;
8540 final int NAT = mAppTokens.size();
8541 for (i=0; i<NAT; i++) {
8542 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8543 tokensAnimating = true;
8544 }
8545 }
8546 final int NEAT = mExitingAppTokens.size();
8547 for (i=0; i<NEAT; i++) {
8548 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8549 tokensAnimating = true;
8550 }
8551 }
8552
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008553 // SECOND LOOP: Execute animations and update visibility of windows.
8554
Joe Onorato8a9b2202010-02-26 18:56:32 -08008555 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008556 + transactionSequence + " tokensAnimating="
8557 + tokensAnimating);
8558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008559 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008560
8561 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008562 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008563 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008564
8565 mPolicy.beginAnimationLw(dw, dh);
8566
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008567 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008569 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008570 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008571
8572 final WindowManager.LayoutParams attrs = w.mAttrs;
8573
8574 if (w.mSurface != null) {
8575 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008576 if (w.commitFinishDrawingLocked(currentTime)) {
8577 if ((w.mAttrs.flags
8578 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008579 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008580 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008581 wallpaperMayChange = true;
8582 }
8583 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008584
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008585 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008586 if (w.stepAnimationLocked(currentTime, dw, dh)) {
8587 animating = true;
8588 //w.dump(" ");
8589 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008590 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
8591 wallpaperMayChange = true;
8592 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008593
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008594 if (mPolicy.doesForceHide(w, attrs)) {
8595 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008596 if (DEBUG_VISIBILITY) Slog.v(TAG,
8597 "Animation done that could impact force hide: "
8598 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008599 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008600 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008601 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
8602 forceHiding = true;
8603 }
8604 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8605 boolean changed;
8606 if (forceHiding) {
8607 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008608 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8609 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008610 } else {
8611 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008612 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8613 "Now policy shown: " + w);
8614 if (changed) {
8615 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008616 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008617 // Assume we will need to animate. If
8618 // we don't (because the wallpaper will
8619 // stay with the lock screen), then we will
8620 // clean up later.
8621 Animation a = mPolicy.createForceHideEnterAnimation();
8622 if (a != null) {
8623 w.setAnimation(a);
8624 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008625 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008626 if (mCurrentFocus == null ||
8627 mCurrentFocus.mLayer < w.mLayer) {
8628 // We are showing on to of the current
8629 // focus, so re-evaluate focus to make
8630 // sure it is correct.
8631 mFocusMayChange = true;
8632 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008633 }
8634 }
8635 if (changed && (attrs.flags
8636 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8637 wallpaperMayChange = true;
8638 }
8639 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008641 mPolicy.animatingWindowLw(w, attrs);
8642 }
8643
8644 final AppWindowToken atoken = w.mAppToken;
8645 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
8646 if (atoken.lastTransactionSequence != transactionSequence) {
8647 atoken.lastTransactionSequence = transactionSequence;
8648 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
8649 atoken.startingDisplayed = false;
8650 }
8651 if ((w.isOnScreen() || w.mAttrs.type
8652 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
8653 && !w.mExiting && !w.mDestroying) {
8654 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008655 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008656 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008657 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008658 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008659 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008660 + " pv=" + w.mPolicyVisibility
8661 + " dp=" + w.mDrawPending
8662 + " cdp=" + w.mCommitDrawPending
8663 + " ah=" + w.mAttachedHidden
8664 + " th=" + atoken.hiddenRequested
8665 + " a=" + w.mAnimating);
8666 }
8667 }
8668 if (w != atoken.startingWindow) {
8669 if (!atoken.freezingScreen || !w.mAppFreezing) {
8670 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008671 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008672 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008673 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008674 "tokenMayBeDrawn: " + atoken
8675 + " freezingScreen=" + atoken.freezingScreen
8676 + " mAppFreezing=" + w.mAppFreezing);
8677 tokenMayBeDrawn = true;
8678 }
8679 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008680 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008681 atoken.startingDisplayed = true;
8682 }
8683 }
8684 } else if (w.mReadyToShow) {
8685 w.performShowLocked();
8686 }
8687 }
8688
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008689 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008690
8691 if (tokenMayBeDrawn) {
8692 // See if any windows have been drawn, so they (and others
8693 // associated with them) can now be shown.
8694 final int NT = mTokenList.size();
8695 for (i=0; i<NT; i++) {
8696 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
8697 if (wtoken == null) {
8698 continue;
8699 }
8700 if (wtoken.freezingScreen) {
8701 int numInteresting = wtoken.numInterestingWindows;
8702 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008703 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008704 "allDrawn: " + wtoken
8705 + " interesting=" + numInteresting
8706 + " drawn=" + wtoken.numDrawnWindows);
8707 wtoken.showAllWindowsLocked();
8708 unsetAppFreezingScreenLocked(wtoken, false, true);
8709 orientationChangeComplete = true;
8710 }
8711 } else if (!wtoken.allDrawn) {
8712 int numInteresting = wtoken.numInterestingWindows;
8713 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008714 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008715 "allDrawn: " + wtoken
8716 + " interesting=" + numInteresting
8717 + " drawn=" + wtoken.numDrawnWindows);
8718 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008719 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008720
8721 // We can now show all of the drawn windows!
8722 if (!mOpeningApps.contains(wtoken)) {
8723 wtoken.showAllWindowsLocked();
8724 }
8725 }
8726 }
8727 }
8728 }
8729
8730 // If we are ready to perform an app transition, check through
8731 // all of the app tokens to be shown and see if they are ready
8732 // to go.
8733 if (mAppTransitionReady) {
8734 int NN = mOpeningApps.size();
8735 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008736 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008737 "Checking " + NN + " opening apps (frozen="
8738 + mDisplayFrozen + " timeout="
8739 + mAppTransitionTimeout + ")...");
8740 if (!mDisplayFrozen && !mAppTransitionTimeout) {
8741 // If the display isn't frozen, wait to do anything until
8742 // all of the apps are ready. Otherwise just go because
8743 // we'll unfreeze the display when everyone is ready.
8744 for (i=0; i<NN && goodToGo; i++) {
8745 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008746 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008747 "Check opening app" + wtoken + ": allDrawn="
8748 + wtoken.allDrawn + " startingDisplayed="
8749 + wtoken.startingDisplayed);
8750 if (!wtoken.allDrawn && !wtoken.startingDisplayed
8751 && !wtoken.startingMoved) {
8752 goodToGo = false;
8753 }
8754 }
8755 }
8756 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008757 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008758 int transit = mNextAppTransition;
8759 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008760 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008761 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008762 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008763 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008764 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008765 mAppTransitionTimeout = false;
8766 mStartingIconInTransition = false;
8767 mSkipAppTransitionAnimation = false;
8768
8769 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
8770
Dianne Hackborna8f60182009-09-01 19:01:50 -07008771 // If there are applications waiting to come to the
8772 // top of the stack, now is the time to move their windows.
8773 // (Note that we don't do apps going to the bottom
8774 // here -- we want to keep their windows in the old
8775 // Z-order until the animation completes.)
8776 if (mToTopApps.size() > 0) {
8777 NN = mAppTokens.size();
8778 for (i=0; i<NN; i++) {
8779 AppWindowToken wtoken = mAppTokens.get(i);
8780 if (wtoken.sendingToTop) {
8781 wtoken.sendingToTop = false;
8782 moveAppWindowsLocked(wtoken, NN, false);
8783 }
8784 }
8785 mToTopApps.clear();
8786 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008787
Dianne Hackborn25994b42009-09-04 14:21:19 -07008788 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008789
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008790 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008791 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008792
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008793 // The top-most window will supply the layout params,
8794 // and we will determine it below.
8795 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008796 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008797 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008798
Joe Onorato8a9b2202010-02-26 18:56:32 -08008799 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008800 "New wallpaper target=" + mWallpaperTarget
8801 + ", lower target=" + mLowerWallpaperTarget
8802 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07008803 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008804 // Do a first pass through the tokens for two
8805 // things:
8806 // (1) Determine if both the closing and opening
8807 // app token sets are wallpaper targets, in which
8808 // case special animations are needed
8809 // (since the wallpaper needs to stay static
8810 // behind them).
8811 // (2) Find the layout params of the top-most
8812 // application window in the tokens, which is
8813 // what will control the animation theme.
8814 final int NC = mClosingApps.size();
8815 NN = NC + mOpeningApps.size();
8816 for (i=0; i<NN; i++) {
8817 AppWindowToken wtoken;
8818 int mode;
8819 if (i < NC) {
8820 wtoken = mClosingApps.get(i);
8821 mode = 1;
8822 } else {
8823 wtoken = mOpeningApps.get(i-NC);
8824 mode = 2;
8825 }
8826 if (mLowerWallpaperTarget != null) {
8827 if (mLowerWallpaperTarget.mAppToken == wtoken
8828 || mUpperWallpaperTarget.mAppToken == wtoken) {
8829 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008830 }
8831 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008832 if (wtoken.appFullscreen) {
8833 WindowState ws = wtoken.findMainWindow();
8834 if (ws != null) {
8835 // If this is a compatibility mode
8836 // window, we will always use its anim.
8837 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
8838 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008839 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008840 bestAnimLayer = Integer.MAX_VALUE;
8841 } else if (ws.mLayer > bestAnimLayer) {
8842 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008843 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008844 bestAnimLayer = ws.mLayer;
8845 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07008846 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008847 }
8848 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008849
Dianne Hackborn25994b42009-09-04 14:21:19 -07008850 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008851 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008852 "Wallpaper animation!");
8853 switch (transit) {
8854 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
8855 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
8856 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
8857 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
8858 break;
8859 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
8860 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
8861 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
8862 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
8863 break;
8864 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008865 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008866 "New transit: " + transit);
8867 } else if (oldWallpaper != null) {
8868 // We are transitioning from an activity with
8869 // a wallpaper to one without.
8870 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008871 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008872 "New transit away from wallpaper: " + transit);
8873 } else if (mWallpaperTarget != null) {
8874 // We are transitioning from an activity without
8875 // a wallpaper to now showing the wallpaper
8876 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008877 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008878 "New transit into wallpaper: " + transit);
8879 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008880
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008881 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
8882 mLastEnterAnimToken = animToken;
8883 mLastEnterAnimParams = animLp;
8884 } else if (mLastEnterAnimParams != null) {
8885 animLp = mLastEnterAnimParams;
8886 mLastEnterAnimToken = null;
8887 mLastEnterAnimParams = null;
8888 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008889
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008890 // If all closing windows are obscured, then there is
8891 // no need to do an animation. This is the case, for
8892 // example, when this transition is being done behind
8893 // the lock screen.
8894 if (!mPolicy.allowAppAnimationsLw()) {
8895 animLp = null;
8896 }
8897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008898 NN = mOpeningApps.size();
8899 for (i=0; i<NN; i++) {
8900 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008901 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008902 "Now opening app" + wtoken);
8903 wtoken.reportedVisible = false;
8904 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008905 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008906 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008907 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008908 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008909 wtoken.showAllWindowsLocked();
8910 }
8911 NN = mClosingApps.size();
8912 for (i=0; i<NN; i++) {
8913 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008914 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008915 "Now closing app" + wtoken);
8916 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008917 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008918 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008919 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008920 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008921 // Force the allDrawn flag, because we want to start
8922 // this guy's animations regardless of whether it's
8923 // gotten drawn.
8924 wtoken.allDrawn = true;
8925 }
8926
Dianne Hackborn8b571a82009-09-25 16:09:43 -07008927 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008929 mOpeningApps.clear();
8930 mClosingApps.clear();
8931
8932 // This has changed the visibility of windows, so perform
8933 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008934 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008935 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07008936 if (!moveInputMethodWindowsIfNeededLocked(true)) {
8937 assignLayersLocked();
8938 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008939 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008940 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008941 }
8942 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008943
Dianne Hackborn16064f92010-03-25 00:47:24 -07008944 int adjResult = 0;
8945
Dianne Hackborna8f60182009-09-01 19:01:50 -07008946 if (!animating && mAppTransitionRunning) {
8947 // We have finished the animation of an app transition. To do
8948 // this, we have delayed a lot of operations like showing and
8949 // hiding apps, moving apps in Z-order, etc. The app token list
8950 // reflects the correct Z-order, but the window list may now
8951 // be out of sync with it. So here we will just rebuild the
8952 // entire app window list. Fun!
8953 mAppTransitionRunning = false;
8954 // Clear information about apps that were moving.
8955 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008956
Dianne Hackborna8f60182009-09-01 19:01:50 -07008957 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008958 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07008959 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008960 moveInputMethodWindowsIfNeededLocked(false);
8961 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08008962 // Since the window list has been rebuilt, focus might
8963 // have to be recomputed since the actual order of windows
8964 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008965 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008966 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008967
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008968 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008969 // At this point, there was a window with a wallpaper that
8970 // was force hiding other windows behind it, but now it
8971 // is going away. This may be simple -- just animate
8972 // away the wallpaper and its window -- or it may be
8973 // hard -- the wallpaper now needs to be shown behind
8974 // something that was hidden.
8975 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008976 if (mLowerWallpaperTarget != null
8977 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008978 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008979 "wallpaperForceHiding changed with lower="
8980 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008981 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008982 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
8983 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
8984 if (mLowerWallpaperTarget.mAppToken.hidden) {
8985 // The lower target has become hidden before we
8986 // actually started the animation... let's completely
8987 // re-evaluate everything.
8988 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008989 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008990 }
8991 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07008992 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008993 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008994 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008995 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008996 + " NEW: " + mWallpaperTarget
8997 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008998 if (mLowerWallpaperTarget == null) {
8999 // Whoops, we don't need a special wallpaper animation.
9000 // Clear them out.
9001 forceHiding = false;
9002 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009003 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009004 if (w.mSurface != null) {
9005 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009006 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009007 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009008 forceHiding = true;
9009 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9010 if (!w.mAnimating) {
9011 // We set the animation above so it
9012 // is not yet running.
9013 w.clearAnimation();
9014 }
9015 }
9016 }
9017 }
9018 }
9019 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009020
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009021 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009022 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009023 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009024 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009025 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009026
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009027 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009028 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009029 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009030 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009031 assignLayersLocked();
9032 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009033 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009034 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009035 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009036 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009037
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009038 if (mFocusMayChange) {
9039 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009040 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009041 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009042 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009043 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009044 }
9045
9046 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009047 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009048 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009049
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009050 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9051 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009052
Jeff Browne33348b2010-07-15 23:54:05 -07009053 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009054 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009055
9056 // THIRD LOOP: Update the surfaces of all windows.
9057
9058 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9059
9060 boolean obscured = false;
9061 boolean blurring = false;
9062 boolean dimming = false;
9063 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009064 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009065 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009066
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009067 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009069 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009070 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009071
9072 boolean displayed = false;
9073 final WindowManager.LayoutParams attrs = w.mAttrs;
9074 final int attrFlags = attrs.flags;
9075
9076 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009077 // XXX NOTE: The logic here could be improved. We have
9078 // the decision about whether to resize a window separated
9079 // from whether to hide the surface. This can cause us to
9080 // resize a surface even if we are going to hide it. You
9081 // can see this by (1) holding device in landscape mode on
9082 // home screen; (2) tapping browser icon (device will rotate
9083 // to landscape; (3) tap home. The wallpaper will be resized
9084 // in step 2 but then immediately hidden, causing us to
9085 // have to resize and then redraw it again in step 3. It
9086 // would be nice to figure out how to avoid this, but it is
9087 // difficult because we do need to resize surfaces in some
9088 // cases while they are hidden such as when first showing a
9089 // window.
9090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009091 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009092 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009093 TAG, "Placing surface #" + i + " " + w.mSurface
9094 + ": new=" + w.mShownFrame + ", old="
9095 + w.mLastShownFrame);
9096
9097 boolean resize;
9098 int width, height;
9099 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9100 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9101 w.mLastRequestedHeight != w.mRequestedHeight;
9102 // for a scaled surface, we just want to use
9103 // the requested size.
9104 width = w.mRequestedWidth;
9105 height = w.mRequestedHeight;
9106 w.mLastRequestedWidth = width;
9107 w.mLastRequestedHeight = height;
9108 w.mLastShownFrame.set(w.mShownFrame);
9109 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009110 if (SHOW_TRANSACTIONS) logSurface(w,
9111 "POS " + w.mShownFrame.left
9112 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009113 w.mSurfaceX = w.mShownFrame.left;
9114 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009115 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9116 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009117 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009118 if (!recoveringMemory) {
9119 reclaimSomeSurfaceMemoryLocked(w, "position");
9120 }
9121 }
9122 } else {
9123 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9124 width = w.mShownFrame.width();
9125 height = w.mShownFrame.height();
9126 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009127 }
9128
9129 if (resize) {
9130 if (width < 1) width = 1;
9131 if (height < 1) height = 1;
9132 if (w.mSurface != null) {
9133 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009134 if (SHOW_TRANSACTIONS) logSurface(w,
9135 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009136 + w.mShownFrame.top + " SIZE "
9137 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009138 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009139 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009140 w.mSurfaceW = width;
9141 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009142 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009143 w.mSurfaceX = w.mShownFrame.left;
9144 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009145 w.mSurface.setPosition(w.mShownFrame.left,
9146 w.mShownFrame.top);
9147 } catch (RuntimeException e) {
9148 // If something goes wrong with the surface (such
9149 // as running out of memory), don't take down the
9150 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009151 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009152 + "size=(" + width + "x" + height
9153 + "), pos=(" + w.mShownFrame.left
9154 + "," + w.mShownFrame.top + ")", e);
9155 if (!recoveringMemory) {
9156 reclaimSomeSurfaceMemoryLocked(w, "size");
9157 }
9158 }
9159 }
9160 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009161 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009162 w.mContentInsetsChanged =
9163 !w.mLastContentInsets.equals(w.mContentInsets);
9164 w.mVisibleInsetsChanged =
9165 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009166 boolean configChanged =
9167 w.mConfiguration != mCurConfiguration
9168 && (w.mConfiguration == null
9169 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009170 if (DEBUG_CONFIGURATION && configChanged) {
9171 Slog.v(TAG, "Win " + w + " config changed: "
9172 + mCurConfiguration);
9173 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009174 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009175 + ": configChanged=" + configChanged
9176 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009177 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009178 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009179 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009180 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009181 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009182 w.mLastFrame.set(w.mFrame);
9183 w.mLastContentInsets.set(w.mContentInsets);
9184 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009185 // If the screen is currently frozen, then keep
9186 // it frozen until this window draws at its new
9187 // orientation.
9188 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009189 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009190 "Resizing while display frozen: " + w);
9191 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009192 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009193 mWindowsFreezingScreen = true;
9194 // XXX should probably keep timeout from
9195 // when we first froze the display.
9196 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9197 mH.sendMessageDelayed(mH.obtainMessage(
9198 H.WINDOW_FREEZE_TIMEOUT), 2000);
9199 }
9200 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009201 // If the orientation is changing, then we need to
9202 // hold off on unfreezing the display until this
9203 // window has been redrawn; to do that, we need
9204 // to go through the process of getting informed
9205 // by the application when it has finished drawing.
9206 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009207 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009208 "Orientation start waiting for draw in "
9209 + w + ", surface " + w.mSurface);
9210 w.mDrawPending = true;
9211 w.mCommitDrawPending = false;
9212 w.mReadyToShow = false;
9213 if (w.mAppToken != null) {
9214 w.mAppToken.allDrawn = false;
9215 }
9216 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009217 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009218 "Resizing window " + w + " to " + w.mFrame);
9219 mResizingWindows.add(w);
9220 } else if (w.mOrientationChanging) {
9221 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009222 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009223 "Orientation not waiting for draw in "
9224 + w + ", surface " + w.mSurface);
9225 w.mOrientationChanging = false;
9226 }
9227 }
9228 }
9229
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009230 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009231 if (!w.mLastHidden) {
9232 //dump();
9233 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009234 if (SHOW_TRANSACTIONS) logSurface(w,
9235 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009236 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009237 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009238 try {
9239 w.mSurface.hide();
9240 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009241 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009242 }
9243 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009244 }
9245 // If we are waiting for this window to handle an
9246 // orientation change, well, it is hidden, so
9247 // doesn't really matter. Note that this does
9248 // introduce a potential glitch if the window
9249 // becomes unhidden before it has drawn for the
9250 // new orientation.
9251 if (w.mOrientationChanging) {
9252 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009253 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009254 "Orientation change skips hidden " + w);
9255 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009256 } else if (w.mLastLayer != w.mAnimLayer
9257 || w.mLastAlpha != w.mShownAlpha
9258 || w.mLastDsDx != w.mDsDx
9259 || w.mLastDtDx != w.mDtDx
9260 || w.mLastDsDy != w.mDsDy
9261 || w.mLastDtDy != w.mDtDy
9262 || w.mLastHScale != w.mHScale
9263 || w.mLastVScale != w.mVScale
9264 || w.mLastHidden) {
9265 displayed = true;
9266 w.mLastAlpha = w.mShownAlpha;
9267 w.mLastLayer = w.mAnimLayer;
9268 w.mLastDsDx = w.mDsDx;
9269 w.mLastDtDx = w.mDtDx;
9270 w.mLastDsDy = w.mDsDy;
9271 w.mLastDtDy = w.mDtDy;
9272 w.mLastHScale = w.mHScale;
9273 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009274 if (SHOW_TRANSACTIONS) logSurface(w,
9275 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009276 + " matrix=[" + (w.mDsDx*w.mHScale)
9277 + "," + (w.mDtDx*w.mVScale)
9278 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009279 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009280 if (w.mSurface != null) {
9281 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009282 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009283 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009284 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009285 w.mSurface.setLayer(w.mAnimLayer);
9286 w.mSurface.setMatrix(
9287 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9288 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9289 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009290 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009291 if (!recoveringMemory) {
9292 reclaimSomeSurfaceMemoryLocked(w, "update");
9293 }
9294 }
9295 }
9296
9297 if (w.mLastHidden && !w.mDrawPending
9298 && !w.mCommitDrawPending
9299 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009300 if (SHOW_TRANSACTIONS) logSurface(w,
9301 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009302 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009303 + " during relayout");
9304 if (showSurfaceRobustlyLocked(w)) {
9305 w.mHasDrawn = true;
9306 w.mLastHidden = false;
9307 } else {
9308 w.mOrientationChanging = false;
9309 }
9310 }
9311 if (w.mSurface != null) {
9312 w.mToken.hasVisible = true;
9313 }
9314 } else {
9315 displayed = true;
9316 }
9317
9318 if (displayed) {
9319 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009320 if (attrs.width == LayoutParams.MATCH_PARENT
9321 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009322 covered = true;
9323 }
9324 }
9325 if (w.mOrientationChanging) {
9326 if (w.mDrawPending || w.mCommitDrawPending) {
9327 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009328 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009329 "Orientation continue waiting for draw in " + w);
9330 } else {
9331 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009332 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009333 "Orientation change complete in " + w);
9334 }
9335 }
9336 w.mToken.hasVisible = true;
9337 }
9338 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009339 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009340 "Orientation change skips hidden " + w);
9341 w.mOrientationChanging = false;
9342 }
9343
9344 final boolean canBeSeen = w.isDisplayedLw();
9345
9346 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9347 focusDisplayed = true;
9348 }
9349
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009350 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009352 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009353 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009354 if (w.mSurface != null) {
9355 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9356 holdScreen = w.mSession;
9357 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009358 if (!syswin && w.mAttrs.screenBrightness >= 0
9359 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009360 screenBrightness = w.mAttrs.screenBrightness;
9361 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009362 if (!syswin && w.mAttrs.buttonBrightness >= 0
9363 && buttonBrightness < 0) {
9364 buttonBrightness = w.mAttrs.buttonBrightness;
9365 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009366 if (canBeSeen
9367 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9368 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9369 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009370 syswin = true;
9371 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009372 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009373
Dianne Hackborn25994b42009-09-04 14:21:19 -07009374 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9375 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009376 // This window completely covers everything behind it,
9377 // so we want to leave all of them as unblurred (for
9378 // performance reasons).
9379 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009380 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009381 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009382 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009383 obscured = true;
9384 if (mBackgroundFillerSurface == null) {
9385 try {
9386 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009387 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009388 0, dw, dh,
9389 PixelFormat.OPAQUE,
9390 Surface.FX_SURFACE_NORMAL);
9391 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009392 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009393 }
9394 }
9395 try {
9396 mBackgroundFillerSurface.setPosition(0, 0);
9397 mBackgroundFillerSurface.setSize(dw, dh);
9398 // Using the same layer as Dim because they will never be shown at the
9399 // same time.
9400 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9401 mBackgroundFillerSurface.show();
9402 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009403 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009404 }
9405 backgroundFillerShown = true;
9406 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009407 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009408 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009409 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009410 + ": blurring=" + blurring
9411 + " obscured=" + obscured
9412 + " displayed=" + displayed);
9413 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9414 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009415 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009416 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009417 if (mDimAnimator == null) {
9418 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009419 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009420 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009421 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009422 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009423 }
9424 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9425 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009426 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009427 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009428 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009429 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009430 + mBlurSurface + ": CREATE");
9431 try {
Romain Guy06882f82009-06-10 13:36:04 -07009432 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009433 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009434 -1, 16, 16,
9435 PixelFormat.OPAQUE,
9436 Surface.FX_SURFACE_BLUR);
9437 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009438 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009439 }
9440 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009441 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009442 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9443 + mBlurSurface + ": pos=(0,0) (" +
9444 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009445 mBlurSurface.setPosition(0, 0);
9446 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009447 mBlurSurface.setLayer(w.mAnimLayer-2);
9448 if (!mBlurShown) {
9449 try {
9450 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9451 + mBlurSurface + ": SHOW");
9452 mBlurSurface.show();
9453 } catch (RuntimeException e) {
9454 Slog.w(TAG, "Failure showing blur surface", e);
9455 }
9456 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009457 }
9458 }
9459 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009460 }
9461 }
9462 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009463
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009464 if (obscuredChanged && mWallpaperTarget == w) {
9465 // This is the wallpaper target and its obscured state
9466 // changed... make sure the current wallaper's visibility
9467 // has been updated accordingly.
9468 updateWallpaperVisibilityLocked();
9469 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009470 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009471
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009472 if (backgroundFillerShown == false && mBackgroundFillerShown) {
9473 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009474 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009475 try {
9476 mBackgroundFillerSurface.hide();
9477 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009478 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009479 }
9480 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009481
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009482 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009483 animating |= mDimAnimator.updateSurface(dimming, currentTime,
9484 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009485 }
Romain Guy06882f82009-06-10 13:36:04 -07009486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009487 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009488 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009489 + ": HIDE");
9490 try {
9491 mBlurSurface.hide();
9492 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009493 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009494 }
9495 mBlurShown = false;
9496 }
9497
Joe Onorato8a9b2202010-02-26 18:56:32 -08009498 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009499 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009500 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009501 }
9502
Jeff Browne33348b2010-07-15 23:54:05 -07009503 mInputMonitor.updateInputWindowsLw();
9504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009505 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07009506
Joe Onorato8a9b2202010-02-26 18:56:32 -08009507 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009508 "With display frozen, orientationChangeComplete="
9509 + orientationChangeComplete);
9510 if (orientationChangeComplete) {
9511 if (mWindowsFreezingScreen) {
9512 mWindowsFreezingScreen = false;
9513 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9514 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009515 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009516 }
Romain Guy06882f82009-06-10 13:36:04 -07009517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009518 i = mResizingWindows.size();
9519 if (i > 0) {
9520 do {
9521 i--;
9522 WindowState win = mResizingWindows.get(i);
9523 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009524 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
9525 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009526 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009527 boolean configChanged =
9528 win.mConfiguration != mCurConfiguration
9529 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009530 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
9531 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
9532 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009533 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009534 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009535 + " / " + mCurConfiguration + " / 0x"
9536 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009537 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009538 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009539 win.mClient.resized(win.mFrame.width(),
9540 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009541 win.mLastVisibleInsets, win.mDrawPending,
9542 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009543 win.mContentInsetsChanged = false;
9544 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009545 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009546 } catch (RemoteException e) {
9547 win.mOrientationChanging = false;
9548 }
9549 } while (i > 0);
9550 mResizingWindows.clear();
9551 }
Romain Guy06882f82009-06-10 13:36:04 -07009552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009553 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009554 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009555 i = mDestroySurface.size();
9556 if (i > 0) {
9557 do {
9558 i--;
9559 WindowState win = mDestroySurface.get(i);
9560 win.mDestroying = false;
9561 if (mInputMethodWindow == win) {
9562 mInputMethodWindow = null;
9563 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009564 if (win == mWallpaperTarget) {
9565 wallpaperDestroyed = true;
9566 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009567 win.destroySurfaceLocked();
9568 } while (i > 0);
9569 mDestroySurface.clear();
9570 }
9571
9572 // Time to remove any exiting tokens?
9573 for (i=mExitingTokens.size()-1; i>=0; i--) {
9574 WindowToken token = mExitingTokens.get(i);
9575 if (!token.hasVisible) {
9576 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009577 if (token.windowType == TYPE_WALLPAPER) {
9578 mWallpaperTokens.remove(token);
9579 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009580 }
9581 }
9582
9583 // Time to remove any exiting applications?
9584 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9585 AppWindowToken token = mExitingAppTokens.get(i);
9586 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009587 // Make sure there is no animation running on this token,
9588 // so any windows associated with it will be removed as
9589 // soon as their animations are complete
9590 token.animation = null;
9591 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009592 mAppTokens.remove(token);
9593 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009594 if (mLastEnterAnimToken == token) {
9595 mLastEnterAnimToken = null;
9596 mLastEnterAnimParams = null;
9597 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009598 }
9599 }
9600
Dianne Hackborna8f60182009-09-01 19:01:50 -07009601 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009602
Dianne Hackborna8f60182009-09-01 19:01:50 -07009603 if (!animating && mAppTransitionRunning) {
9604 // We have finished the animation of an app transition. To do
9605 // this, we have delayed a lot of operations like showing and
9606 // hiding apps, moving apps in Z-order, etc. The app token list
9607 // reflects the correct Z-order, but the window list may now
9608 // be out of sync with it. So here we will just rebuild the
9609 // entire app window list. Fun!
9610 mAppTransitionRunning = false;
9611 needRelayout = true;
9612 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009613 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009614 // Clear information about apps that were moving.
9615 mToBottomApps.clear();
9616 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009618 if (focusDisplayed) {
9619 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
9620 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009621 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009622 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009623 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009624 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009625 requestAnimationLocked(0);
9626 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009627 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
9628 }
Jeff Browneb857f12010-07-16 10:06:33 -07009629
Jeff Browne33348b2010-07-15 23:54:05 -07009630 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -07009631
Jeff Brown8e03b752010-06-13 19:16:55 -07009632 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009633 if (screenBrightness < 0 || screenBrightness > 1.0f) {
9634 mPowerManager.setScreenBrightnessOverride(-1);
9635 } else {
9636 mPowerManager.setScreenBrightnessOverride((int)
9637 (screenBrightness * Power.BRIGHTNESS_ON));
9638 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009639 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
9640 mPowerManager.setButtonBrightnessOverride(-1);
9641 } else {
9642 mPowerManager.setButtonBrightnessOverride((int)
9643 (buttonBrightness * Power.BRIGHTNESS_ON));
9644 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009645 if (holdScreen != mHoldingScreenOn) {
9646 mHoldingScreenOn = holdScreen;
9647 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
9648 mH.sendMessage(m);
9649 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009650
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009651 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009652 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009653 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
9654 LocalPowerManager.BUTTON_EVENT, true);
9655 mTurnOnScreen = false;
9656 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08009657
9658 // Check to see if we are now in a state where the screen should
9659 // be enabled, because the window obscured flags have changed.
9660 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009661 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009662
9663 /**
9664 * Must be called with the main window manager lock held.
9665 */
9666 void setHoldScreenLocked(boolean holding) {
9667 boolean state = mHoldingScreenWakeLock.isHeld();
9668 if (holding != state) {
9669 if (holding) {
9670 mHoldingScreenWakeLock.acquire();
9671 } else {
9672 mPolicy.screenOnStoppedLw();
9673 mHoldingScreenWakeLock.release();
9674 }
9675 }
9676 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009677
9678 void requestAnimationLocked(long delay) {
9679 if (!mAnimationPending) {
9680 mAnimationPending = true;
9681 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
9682 }
9683 }
Romain Guy06882f82009-06-10 13:36:04 -07009684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009685 /**
9686 * Have the surface flinger show a surface, robustly dealing with
9687 * error conditions. In particular, if there is not enough memory
9688 * to show the surface, then we will try to get rid of other surfaces
9689 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07009690 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009691 * @return Returns true if the surface was successfully shown.
9692 */
9693 boolean showSurfaceRobustlyLocked(WindowState win) {
9694 try {
9695 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009696 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009697 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009698 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009699 if (DEBUG_VISIBILITY) Slog.v(TAG,
9700 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009701 win.mTurnOnScreen = false;
9702 mTurnOnScreen = true;
9703 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009704 }
9705 return true;
9706 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009707 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009708 }
Romain Guy06882f82009-06-10 13:36:04 -07009709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009710 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -07009711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009712 return false;
9713 }
Romain Guy06882f82009-06-10 13:36:04 -07009714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009715 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
9716 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -07009717
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009718 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009719 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07009720
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009721 if (mForceRemoves == null) {
9722 mForceRemoves = new ArrayList<WindowState>();
9723 }
Romain Guy06882f82009-06-10 13:36:04 -07009724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009725 long callingIdentity = Binder.clearCallingIdentity();
9726 try {
9727 // There was some problem... first, do a sanity check of the
9728 // window list to make sure we haven't left any dangling surfaces
9729 // around.
9730 int N = mWindows.size();
9731 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009732 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009733 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009734 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009735 if (ws.mSurface != null) {
9736 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009737 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009738 + ws + " surface=" + ws.mSurface
9739 + " token=" + win.mToken
9740 + " pid=" + ws.mSession.mPid
9741 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009742 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009743 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009744 ws.mSurface = null;
9745 mForceRemoves.add(ws);
9746 i--;
9747 N--;
9748 leakedSurface = true;
9749 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009750 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009751 + ws + " surface=" + ws.mSurface
9752 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009753 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009754 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009755 ws.mSurface = null;
9756 leakedSurface = true;
9757 }
9758 }
9759 }
Romain Guy06882f82009-06-10 13:36:04 -07009760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009761 boolean killedApps = false;
9762 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009763 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009764 SparseIntArray pidCandidates = new SparseIntArray();
9765 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009766 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009767 if (ws.mSurface != null) {
9768 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
9769 }
9770 }
9771 if (pidCandidates.size() > 0) {
9772 int[] pids = new int[pidCandidates.size()];
9773 for (int i=0; i<pids.length; i++) {
9774 pids[i] = pidCandidates.keyAt(i);
9775 }
9776 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -07009777 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009778 killedApps = true;
9779 }
9780 } catch (RemoteException e) {
9781 }
9782 }
9783 }
Romain Guy06882f82009-06-10 13:36:04 -07009784
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009785 if (leakedSurface || killedApps) {
9786 // We managed to reclaim some memory, so get rid of the trouble
9787 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009788 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009789 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009790 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009791 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009792 win.mSurface = null;
9793 }
Romain Guy06882f82009-06-10 13:36:04 -07009794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009795 try {
9796 win.mClient.dispatchGetNewSurface();
9797 } catch (RemoteException e) {
9798 }
9799 }
9800 } finally {
9801 Binder.restoreCallingIdentity(callingIdentity);
9802 }
9803 }
Romain Guy06882f82009-06-10 13:36:04 -07009804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009805 private boolean updateFocusedWindowLocked(int mode) {
9806 WindowState newFocus = computeFocusedWindowLocked();
9807 if (mCurrentFocus != newFocus) {
9808 // This check makes sure that we don't already have the focus
9809 // change message pending.
9810 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
9811 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009812 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009813 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
9814 final WindowState oldFocus = mCurrentFocus;
9815 mCurrentFocus = newFocus;
9816 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07009817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009818 final WindowState imWindow = mInputMethodWindow;
9819 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009820 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009821 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009822 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
9823 mLayoutNeeded = true;
9824 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009825 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
9826 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009827 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
9828 // Client will do the layout, but we need to assign layers
9829 // for handleNewWindowLocked() below.
9830 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009831 }
9832 }
Jeff Brown349703e2010-06-22 01:27:15 -07009833
9834 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
9835 // If we defer assigning layers, then the caller is responsible for
9836 // doing this part.
9837 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009838 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009839 return true;
9840 }
9841 return false;
9842 }
Jeff Brown349703e2010-06-22 01:27:15 -07009843
9844 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009845 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07009846 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009847
9848 private WindowState computeFocusedWindowLocked() {
9849 WindowState result = null;
9850 WindowState win;
9851
9852 int i = mWindows.size() - 1;
9853 int nextAppIndex = mAppTokens.size()-1;
9854 WindowToken nextApp = nextAppIndex >= 0
9855 ? mAppTokens.get(nextAppIndex) : null;
9856
9857 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009858 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009859
Joe Onorato8a9b2202010-02-26 18:56:32 -08009860 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009861 TAG, "Looking for focus: " + i
9862 + " = " + win
9863 + ", flags=" + win.mAttrs.flags
9864 + ", canReceive=" + win.canReceiveKeys());
9865
9866 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07009867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009868 // If this window's application has been removed, just skip it.
9869 if (thisApp != null && thisApp.removed) {
9870 i--;
9871 continue;
9872 }
Romain Guy06882f82009-06-10 13:36:04 -07009873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009874 // If there is a focused app, don't allow focus to go to any
9875 // windows below it. If this is an application window, step
9876 // through the app tokens until we find its app.
9877 if (thisApp != null && nextApp != null && thisApp != nextApp
9878 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
9879 int origAppIndex = nextAppIndex;
9880 while (nextAppIndex > 0) {
9881 if (nextApp == mFocusedApp) {
9882 // Whoops, we are below the focused app... no focus
9883 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -08009884 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009885 TAG, "Reached focused app: " + mFocusedApp);
9886 return null;
9887 }
9888 nextAppIndex--;
9889 nextApp = mAppTokens.get(nextAppIndex);
9890 if (nextApp == thisApp) {
9891 break;
9892 }
9893 }
9894 if (thisApp != nextApp) {
9895 // Uh oh, the app token doesn't exist! This shouldn't
9896 // happen, but if it does we can get totally hosed...
9897 // so restart at the original app.
9898 nextAppIndex = origAppIndex;
9899 nextApp = mAppTokens.get(nextAppIndex);
9900 }
9901 }
9902
9903 // Dispatch to this window if it is wants key events.
9904 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009905 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009906 TAG, "Found focus @ " + i + " = " + win);
9907 result = win;
9908 break;
9909 }
9910
9911 i--;
9912 }
9913
9914 return result;
9915 }
9916
9917 private void startFreezingDisplayLocked() {
9918 if (mDisplayFrozen) {
9919 return;
9920 }
Romain Guy06882f82009-06-10 13:36:04 -07009921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009922 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -07009923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009924 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009925 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009926 if (mFreezeGcPending != 0) {
9927 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009928 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009929 mH.removeMessages(H.FORCE_GC);
9930 Runtime.getRuntime().gc();
9931 mFreezeGcPending = now;
9932 }
9933 } else {
9934 mFreezeGcPending = now;
9935 }
Romain Guy06882f82009-06-10 13:36:04 -07009936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009937 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -07009938
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009939 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -07009940
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009941 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
9942 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009943 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009944 mAppTransitionReady = true;
9945 }
Romain Guy06882f82009-06-10 13:36:04 -07009946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009947 if (PROFILE_ORIENTATION) {
9948 File file = new File("/data/system/frozen");
9949 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
9950 }
9951 Surface.freezeDisplay(0);
9952 }
Romain Guy06882f82009-06-10 13:36:04 -07009953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009954 private void stopFreezingDisplayLocked() {
9955 if (!mDisplayFrozen) {
9956 return;
9957 }
Romain Guy06882f82009-06-10 13:36:04 -07009958
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009959 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
9960 return;
9961 }
9962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009963 mDisplayFrozen = false;
9964 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
9965 if (PROFILE_ORIENTATION) {
9966 Debug.stopMethodTracing();
9967 }
9968 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -07009969
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009970 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009971
Christopher Tateb696aee2010-04-02 19:08:30 -07009972 // While the display is frozen we don't re-compute the orientation
9973 // to avoid inconsistent states. However, something interesting
9974 // could have actually changed during that time so re-evaluate it
9975 // now to catch that.
9976 if (updateOrientationFromAppTokensLocked()) {
9977 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9978 }
9979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009980 // A little kludge: a lot could have happened while the
9981 // display was frozen, so now that we are coming back we
9982 // do a gc so that any remote references the system
9983 // processes holds on others can be released if they are
9984 // no longer needed.
9985 mH.removeMessages(H.FORCE_GC);
9986 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9987 2000);
Romain Guy06882f82009-06-10 13:36:04 -07009988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009989 mScreenFrozenLock.release();
9990 }
Romain Guy06882f82009-06-10 13:36:04 -07009991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009992 @Override
9993 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
9994 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
9995 != PackageManager.PERMISSION_GRANTED) {
9996 pw.println("Permission Denial: can't dump WindowManager from from pid="
9997 + Binder.getCallingPid()
9998 + ", uid=" + Binder.getCallingUid());
9999 return;
10000 }
Romain Guy06882f82009-06-10 13:36:04 -070010001
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010002 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010003 pw.println(" ");
10004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010005 synchronized(mWindowMap) {
10006 pw.println("Current Window Manager state:");
10007 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010008 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010009 pw.print(" Window #"); pw.print(i); pw.print(' ');
10010 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010011 w.dump(pw, " ");
10012 }
10013 if (mInputMethodDialogs.size() > 0) {
10014 pw.println(" ");
10015 pw.println(" Input method dialogs:");
10016 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10017 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010018 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010019 }
10020 }
10021 if (mPendingRemove.size() > 0) {
10022 pw.println(" ");
10023 pw.println(" Remove pending for:");
10024 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10025 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010026 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10027 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010028 w.dump(pw, " ");
10029 }
10030 }
10031 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10032 pw.println(" ");
10033 pw.println(" Windows force removing:");
10034 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10035 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010036 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10037 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010038 w.dump(pw, " ");
10039 }
10040 }
10041 if (mDestroySurface.size() > 0) {
10042 pw.println(" ");
10043 pw.println(" Windows waiting to destroy their surface:");
10044 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10045 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010046 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10047 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010048 w.dump(pw, " ");
10049 }
10050 }
10051 if (mLosingFocus.size() > 0) {
10052 pw.println(" ");
10053 pw.println(" Windows losing focus:");
10054 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10055 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010056 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10057 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010058 w.dump(pw, " ");
10059 }
10060 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010061 if (mResizingWindows.size() > 0) {
10062 pw.println(" ");
10063 pw.println(" Windows waiting to resize:");
10064 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10065 WindowState w = mResizingWindows.get(i);
10066 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10067 pw.print(w); pw.println(":");
10068 w.dump(pw, " ");
10069 }
10070 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010071 if (mSessions.size() > 0) {
10072 pw.println(" ");
10073 pw.println(" All active sessions:");
10074 Iterator<Session> it = mSessions.iterator();
10075 while (it.hasNext()) {
10076 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010077 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010078 s.dump(pw, " ");
10079 }
10080 }
10081 if (mTokenMap.size() > 0) {
10082 pw.println(" ");
10083 pw.println(" All tokens:");
10084 Iterator<WindowToken> it = mTokenMap.values().iterator();
10085 while (it.hasNext()) {
10086 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010087 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010088 token.dump(pw, " ");
10089 }
10090 }
10091 if (mTokenList.size() > 0) {
10092 pw.println(" ");
10093 pw.println(" Window token list:");
10094 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010095 pw.print(" #"); pw.print(i); pw.print(": ");
10096 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010097 }
10098 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010099 if (mWallpaperTokens.size() > 0) {
10100 pw.println(" ");
10101 pw.println(" Wallpaper tokens:");
10102 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10103 WindowToken token = mWallpaperTokens.get(i);
10104 pw.print(" Wallpaper #"); pw.print(i);
10105 pw.print(' '); pw.print(token); pw.println(':');
10106 token.dump(pw, " ");
10107 }
10108 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010109 if (mAppTokens.size() > 0) {
10110 pw.println(" ");
10111 pw.println(" Application tokens in Z order:");
10112 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010113 pw.print(" App #"); pw.print(i); pw.print(": ");
10114 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010115 }
10116 }
10117 if (mFinishedStarting.size() > 0) {
10118 pw.println(" ");
10119 pw.println(" Finishing start of application tokens:");
10120 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10121 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010122 pw.print(" Finished Starting #"); pw.print(i);
10123 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010124 token.dump(pw, " ");
10125 }
10126 }
10127 if (mExitingTokens.size() > 0) {
10128 pw.println(" ");
10129 pw.println(" Exiting tokens:");
10130 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10131 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010132 pw.print(" Exiting #"); pw.print(i);
10133 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010134 token.dump(pw, " ");
10135 }
10136 }
10137 if (mExitingAppTokens.size() > 0) {
10138 pw.println(" ");
10139 pw.println(" Exiting application tokens:");
10140 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10141 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010142 pw.print(" Exiting App #"); pw.print(i);
10143 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010144 token.dump(pw, " ");
10145 }
10146 }
10147 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010148 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10149 pw.print(" mLastFocus="); pw.println(mLastFocus);
10150 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10151 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10152 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010153 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010154 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10155 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10156 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10157 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010158 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10159 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10160 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010161 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10162 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10163 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10164 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010165 if (mDimAnimator != null) {
10166 mDimAnimator.printTo(pw);
10167 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010168 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010169 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010170 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010171 pw.print(mInputMethodAnimLayerAdjustment);
10172 pw.print(" mWallpaperAnimLayerAdjustment=");
10173 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010174 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10175 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010176 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10177 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010178 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10179 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010180 pw.print(" mRotation="); pw.print(mRotation);
10181 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10182 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10183 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10184 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10185 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10186 pw.print(" mNextAppTransition=0x");
10187 pw.print(Integer.toHexString(mNextAppTransition));
10188 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010189 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010190 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010191 if (mNextAppTransitionPackage != null) {
10192 pw.print(" mNextAppTransitionPackage=");
10193 pw.print(mNextAppTransitionPackage);
10194 pw.print(", mNextAppTransitionEnter=0x");
10195 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10196 pw.print(", mNextAppTransitionExit=0x");
10197 pw.print(Integer.toHexString(mNextAppTransitionExit));
10198 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010199 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10200 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010201 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10202 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10203 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10204 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010205 if (mOpeningApps.size() > 0) {
10206 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10207 }
10208 if (mClosingApps.size() > 0) {
10209 pw.print(" mClosingApps="); pw.println(mClosingApps);
10210 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010211 if (mToTopApps.size() > 0) {
10212 pw.print(" mToTopApps="); pw.println(mToTopApps);
10213 }
10214 if (mToBottomApps.size() > 0) {
10215 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10216 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010217 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10218 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010219 }
10220 }
10221
Jeff Brown349703e2010-06-22 01:27:15 -070010222 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010223 public void monitor() {
10224 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010225 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010226 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010227
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010228 /**
10229 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010230 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010231 */
10232 private static class DimAnimator {
10233 Surface mDimSurface;
10234 boolean mDimShown = false;
10235 float mDimCurrentAlpha;
10236 float mDimTargetAlpha;
10237 float mDimDeltaPerMs;
10238 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010239
10240 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010241
10242 DimAnimator (SurfaceSession session) {
10243 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010244 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010245 + mDimSurface + ": CREATE");
10246 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010247 mDimSurface = new Surface(session, 0,
10248 "DimSurface",
10249 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010250 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010010251 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010252 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010253 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010254 }
10255 }
10256 }
10257
10258 /**
10259 * Show the dim surface.
10260 */
10261 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010262 if (!mDimShown) {
10263 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
10264 dw + "x" + dh + ")");
10265 mDimShown = true;
10266 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010267 mLastDimWidth = dw;
10268 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010269 mDimSurface.setPosition(0, 0);
10270 mDimSurface.setSize(dw, dh);
10271 mDimSurface.show();
10272 } catch (RuntimeException e) {
10273 Slog.w(TAG, "Failure showing dim surface", e);
10274 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010275 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
10276 mLastDimWidth = dw;
10277 mLastDimHeight = dh;
10278 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010279 }
10280 }
10281
10282 /**
10283 * Set's the dim surface's layer and update dim parameters that will be used in
10284 * {@link updateSurface} after all windows are examined.
10285 */
10286 void updateParameters(WindowState w, long currentTime) {
10287 mDimSurface.setLayer(w.mAnimLayer-1);
10288
10289 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010290 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010291 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010292 if (mDimTargetAlpha != target) {
10293 // If the desired dim level has changed, then
10294 // start an animation to it.
10295 mLastDimAnimTime = currentTime;
10296 long duration = (w.mAnimating && w.mAnimation != null)
10297 ? w.mAnimation.computeDurationHint()
10298 : DEFAULT_DIM_DURATION;
10299 if (target > mDimTargetAlpha) {
10300 // This is happening behind the activity UI,
10301 // so we can make it run a little longer to
10302 // give a stronger impression without disrupting
10303 // the user.
10304 duration *= DIM_DURATION_MULTIPLIER;
10305 }
10306 if (duration < 1) {
10307 // Don't divide by zero
10308 duration = 1;
10309 }
10310 mDimTargetAlpha = target;
10311 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
10312 }
10313 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010314
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010315 /**
10316 * Updating the surface's alpha. Returns true if the animation continues, or returns
10317 * false when the animation is finished and the dim surface is hidden.
10318 */
10319 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
10320 if (!dimming) {
10321 if (mDimTargetAlpha != 0) {
10322 mLastDimAnimTime = currentTime;
10323 mDimTargetAlpha = 0;
10324 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
10325 }
10326 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010327
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010328 boolean animating = false;
10329 if (mLastDimAnimTime != 0) {
10330 mDimCurrentAlpha += mDimDeltaPerMs
10331 * (currentTime-mLastDimAnimTime);
10332 boolean more = true;
10333 if (displayFrozen) {
10334 // If the display is frozen, there is no reason to animate.
10335 more = false;
10336 } else if (mDimDeltaPerMs > 0) {
10337 if (mDimCurrentAlpha > mDimTargetAlpha) {
10338 more = false;
10339 }
10340 } else if (mDimDeltaPerMs < 0) {
10341 if (mDimCurrentAlpha < mDimTargetAlpha) {
10342 more = false;
10343 }
10344 } else {
10345 more = false;
10346 }
10347
10348 // Do we need to continue animating?
10349 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010350 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010351 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
10352 mLastDimAnimTime = currentTime;
10353 mDimSurface.setAlpha(mDimCurrentAlpha);
10354 animating = true;
10355 } else {
10356 mDimCurrentAlpha = mDimTargetAlpha;
10357 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010358 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010359 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
10360 mDimSurface.setAlpha(mDimCurrentAlpha);
10361 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010362 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010363 + ": HIDE");
10364 try {
10365 mDimSurface.hide();
10366 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010367 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010368 }
10369 mDimShown = false;
10370 }
10371 }
10372 }
10373 return animating;
10374 }
10375
10376 public void printTo(PrintWriter pw) {
10377 pw.print(" mDimShown="); pw.print(mDimShown);
10378 pw.print(" current="); pw.print(mDimCurrentAlpha);
10379 pw.print(" target="); pw.print(mDimTargetAlpha);
10380 pw.print(" delta="); pw.print(mDimDeltaPerMs);
10381 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
10382 }
10383 }
10384
10385 /**
10386 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
10387 * This is used for opening/closing transition for apps in compatible mode.
10388 */
10389 private static class FadeInOutAnimation extends Animation {
10390 int mWidth;
10391 boolean mFadeIn;
10392
10393 public FadeInOutAnimation(boolean fadeIn) {
10394 setInterpolator(new AccelerateInterpolator());
10395 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
10396 mFadeIn = fadeIn;
10397 }
10398
10399 @Override
10400 protected void applyTransformation(float interpolatedTime, Transformation t) {
10401 float x = interpolatedTime;
10402 if (!mFadeIn) {
10403 x = 1.0f - x; // reverse the interpolation for fade out
10404 }
10405 if (x < 0.5) {
10406 // move the window out of the screen.
10407 t.getMatrix().setTranslate(mWidth, 0);
10408 } else {
10409 t.getMatrix().setTranslate(0, 0);// show
10410 t.setAlpha((x - 0.5f) * 2);
10411 }
10412 }
10413
10414 @Override
10415 public void initialize(int width, int height, int parentWidth, int parentHeight) {
10416 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
10417 mWidth = width;
10418 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010419
10420 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070010421 public int getZAdjustment() {
10422 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010423 }
10424 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010425}